Remove AI class names.

Originally, a map author could define a separate AI script for each
(class, race) combination.  Each of those scripts also required a
unique name.  Because support for races has been removed, AI class
names are no longer useful.

Remove CAiType::Class; use CAiType::Name instead.  Remove the class
parameter of DefineAi; it was called only from RegisterAi, which
passed the same string as name and class.

Remove CAiType::Script and PlayerAi::Script; use CAiType::Name
instead.  Ignore the "script" tag of DefineAiPlayer when loading
a game, and do not generate it when saving.

This commit does not require any changes in individual AI scripts.
This commit is contained in:
kon 2011-07-08 21:23:29 +00:00
parent 06be930584
commit d923dca483
3 changed files with 15 additions and 27 deletions

View file

@ -154,11 +154,11 @@ PlayerAi *AiPlayer; /// Current AI player
*/
static void AiExecuteScript()
{
if (!AiPlayer->Script.empty())
if (AiPlayer->AiType != NULL)
{
lua_pushstring(Lua, "_ai_scripts_");
lua_gettable(Lua, LUA_GLOBALSINDEX);
lua_pushstring(Lua, AiPlayer->Script.c_str());
lua_pushstring(Lua, AiPlayer->AiType->Name.c_str());
lua_rawget(Lua, -2);
LuaCall(0, 1);
lua_pop(Lua, 1);
@ -278,7 +278,6 @@ static void SaveAiPlayer(CFile *file, int plynr, PlayerAi *ai)
file->printf("DefineAiPlayer(%d,\n", plynr);
file->printf(" \"ai-type\", \"%s\",\n", ai->AiType->Name.c_str());
file->printf(" \"script\", \"%s\",\n", ai->Script.c_str());
file->printf(" \"script-debug\", %s,\n", ai->ScriptDebug ? "true" : "false");
file->printf(" \"sleep-cycles\", %lu,\n", ai->SleepCycles);
@ -428,9 +427,10 @@ void AiInit(CPlayer *player)
pai->Player = player;
ait = NULL;
DebugPrint("%d - %p - looking for class %s\n" _C_
player->Index _C_ player _C_ player->AiName.c_str());
//MAPTODO print the player name (player->Name) instead of the pointer
DebugPrint("Player %d (%s) looking for \"%s\"\n" _C_
player->Index _C_
player->Name.c_str() _C_
player->AiName.c_str());
//
// Search correct AI type.
@ -444,7 +444,7 @@ void AiInit(CPlayer *player)
for (i = 0; i < AiTypes.size(); ++i)
{
ait = AiTypes[i];
if (!player->AiName.empty() && ait->Class != player->AiName)
if (!player->AiName.empty() && ait->Name != player->AiName)
{
continue;
}
@ -461,11 +461,9 @@ void AiInit(CPlayer *player)
DebugPrint("AI: not found!!!!!!!!!!\n");
DebugPrint("AI: Using fallback:\n");
}
DebugPrint("AI: %s:%s\n" _C_ player->AiName.c_str() _C_ ait->Class.c_str());
DebugPrint("AI: %s\n" _C_ ait->Name.c_str());
pai->AiType = ait;
pai->Script = ait->Script;
player->Ai = pai;
}

View file

@ -56,9 +56,6 @@ public:
CAiType() {}
std::string Name; /// Name of this ai
std::string Class; /// class of this ai
std::string Script; /// Main script
};
/**
@ -183,7 +180,6 @@ public:
CPlayer *Player; /// Engine player structure
CAiType *AiType; /// AI type of this player AI
// controller
std::string Script; /// Script executed
bool ScriptDebug; /// Flag script debuging on/off
unsigned long SleepCycles; /// Cycles to sleep

View file

@ -284,8 +284,8 @@ static int CclDefineAi(lua_State *l)
const CAiType *ait;
#endif
LuaCheckArgs(l, 3);
if (!lua_isfunction(l, 3))
LuaCheckArgs(l, 2);
if (!lua_isfunction(l, 2))
{
LuaError(l, "incorrect argument");
}
@ -309,11 +309,6 @@ static int CclDefineAi(lua_State *l)
}
#endif
//
// AI Class
//
aitype->Class = LuaToString(l, 2);
//
// AI Script
//
@ -328,10 +323,9 @@ static int CclDefineAi(lua_State *l)
lua_pushstring(l, "_ai_scripts_");
lua_gettable(l, LUA_GLOBALSINDEX);
}
aitype->Script = aitype->Name + aitype->Class;
lua_pushstring(l, aitype->Script.c_str());
lua_pushvalue(l, 3);
lua_rawset(l, 4);
lua_pushstring(l, aitype->Name.c_str());
lua_pushvalue(l, 2);
lua_rawset(l, -3);
lua_pop(l, 1);
return 0;
@ -881,11 +875,11 @@ static int CclDefineAiPlayer(lua_State *l)
lua_pushfstring(l, "ai-type not found: %s", value);
}
ai->AiType = ait;
ai->Script = ait->Script;
}
else if (!strcmp(value, "script"))
{
ai->Script = LuaToString(l, j + 1);
// Ignore, for compatibility with games saved
// by earlier versions.
}
else if (!strcmp(value, "script-debug"))
{