stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/ai ccl_ai.c


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src/ai ccl_ai.c
Date: 16 Dec 2003 16:55:38 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       03/12/16 16:55:38

Modified files:
        src/ai         : ccl_ai.c 

Log message:
        Updates to lua

Patches:
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.89 stratagus/src/ai/ccl_ai.c:1.90
--- stratagus/src/ai/ccl_ai.c:1.89      Sun Dec 14 01:50:57 2003
+++ stratagus/src/ai/ccl_ai.c   Tue Dec 16 16:55:37 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_ai.c,v 1.89 2003/12/13 14:50:57 jsalmon3 Exp $
+//      $Id: ccl_ai.c,v 1.90 2003/12/16 05:55:37 jsalmon3 Exp $
 
 //@{
 
@@ -1002,11 +1002,11 @@
 #ifdef DEBUG
     const AiType* ait;
 #endif
-    int args;
-    int j;
 
-    args = lua_gettop(l);
-    j = 0;
+    if (lua_gettop(l) != 4 || !lua_isfunction(l, 4)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
 
     aitype = malloc(sizeof(AiType));
     aitype->Next = AiTypes;
@@ -1015,8 +1015,7 @@
     //
     //  AI Name
     //
-    aitype->Name = strdup(LuaToString(l, j + 1));
-    ++j;
+    aitype->Name = strdup(LuaToString(l, 1));
     DebugLevel3Fn("%s\n" _C_ aitype->Name);
 
 #ifdef DEBUG
@@ -1031,8 +1030,7 @@
     //
     //  AI Race
     //
-    value = LuaToString(l, j + 1);
-    ++j;
+    value = LuaToString(l, 2);
     DebugLevel3Fn("%s\n" _C_ value);
     if (*value != '*') {
        aitype->Race = strdup(value);
@@ -1043,14 +1041,31 @@
     //
     //  AI Class
     //
-    aitype->Class = strdup(LuaToString(l, j + 1));
-    ++j;
+    aitype->Class = strdup(LuaToString(l, 3));
     DebugLevel3Fn("%s\n" _C_ aitype->Class);
 
     //
     //  AI Script
     //
-//    aitype->Script = value;
+    lua_pushstring(l, "_ai_scripts_");
+    lua_gettable(l, LUA_GLOBALSINDEX);
+    if (lua_isnil(l, -1)) {
+       lua_pop(l, 1);
+       lua_pushstring(l, "_ai_scripts_");
+       lua_newtable(l);
+       lua_settable(l, LUA_GLOBALSINDEX);
+       lua_pushstring(l, "_ai_scripts_");
+       lua_gettable(l, LUA_GLOBALSINDEX);
+    }
+    aitype->Script = malloc(strlen(aitype->Name) +
+       (aitype->Race ? strlen(aitype->Race) : 0) +
+       strlen(aitype->Class) + 1);
+    sprintf(aitype->Script, "%s%s%s", aitype->Name,
+       (aitype->Race ? aitype->Race : ""), aitype->Class);
+    lua_pushstring(l, aitype->Script);
+    lua_pushvalue(l, 4);
+    lua_rawset(l, 5);
+    lua_pop(l, 1);
 
     return 0;
 }
@@ -3032,7 +3047,7 @@
     lua_newtable(l);
     for (i = 0; i < MaxCosts; ++i) {
        lua_pushnumber(l, AiPlayer->Reserve[i]);
-       lua_rawseti(l, -1, i + 1);
+       lua_rawseti(l, -2, i + 1);
     }
     for (i = 0; i < MaxCosts; ++i) {
        lua_rawgeti(l, 1, i + 1);
@@ -3520,8 +3535,8 @@
 //    lua_register(Lua, "AiRestart", CclAiRestart);
 
     lua_register(Lua, "AiPlayer", CclAiPlayer);
-    lua_register(Lua, "AiSetReserve!", CclAiSetReserve);
-    lua_register(Lua, "AiSetCollect!", CclAiSetCollect);
+    lua_register(Lua, "AiSetReserve", CclAiSetReserve);
+    lua_register(Lua, "AiSetCollect", CclAiSetCollect);
     lua_register(Lua, "AiSetAutoAttack", CclAiSetAutoAttack);
 
     lua_register(Lua, "AiDump", CclAiDump);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]