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: 23 Dec 2003 11:15:57 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       03/12/23 11:15:56

Modified files:
        src/ai         : ccl_ai.c 

Log message:
        Updates to ai lua scripts

Patches:
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.93 stratagus/src/ai/ccl_ai.c:1.94
--- stratagus/src/ai/ccl_ai.c:1.93      Mon Dec 22 18:52:08 2003
+++ stratagus/src/ai/ccl_ai.c   Tue Dec 23 11:15:56 2003
@@ -10,7 +10,8 @@
 //
 /address@hidden ccl_ai.c - The AI ccl functions. */
 //
-//      (c) Copyright 2000-2002 by Lutz Sammer and Ludovic Pollet
+//      (c) Copyright 2000-2004 by Lutz Sammer, Ludovic Pollet,
+//                                 and Jimmy Salmon
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ccl_ai.c,v 1.93 2003/12/22 07:52:08 wizzard Exp $
+//      $Id: ccl_ai.c,v 1.94 2003/12/23 00:15:56 jsalmon3 Exp $
 
 //@{
 
@@ -963,6 +964,28 @@
        lua_pushvalue(l, 2);
        lua_settable(l, LUA_GLOBALSINDEX);
 
+       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);
+       }
+       lua_pushstring(l, "Script");
+       lua_rawget(l, 2);
+       if (!lua_istable(l, -1)) {
+               lua_error(l);
+       }
+       aiScriptAction->Script = malloc(20);
+       sprintf(aiScriptAction->Script, "_ai_script_%d_", AiScriptActionNum - 
1);
+       lua_pushstring(l, aiScriptAction->Script);
+       lua_rawgeti(l, -2, 3);
+       lua_rawset(l, -4);
+       lua_pop(l, 2);
+
        args = luaL_getn(l, 1);
        for (j = 0; j < args; ++j) {
                lua_rawgeti(l, 1, j + 1);
@@ -2094,21 +2117,25 @@
        int args;
        int j;
 
-       args = lua_gettop(l);
-       j = 0;
-       force = LuaToNumber(l, j + 1);
-       ++j;
+       if (lua_gettop(l) != 2 || !lua_istable(l, 2)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+       }
+       force = LuaToNumber(l, 1);
        if (force < 0 || force >= AI_MAX_FORCES) {
                lua_pushfstring(l, "Force out of range: %d", force);
                lua_error(l);
        }
 
-       for (; j < args; ++j) {
-               lua_pushvalue(l, j + 1);
+       args = luaL_getn(l, 2);
+       for (j = 0; j < args; ++j) {
+               lua_rawgeti(l, 2, j + 1);
                type = CclGetUnitType(l);
                lua_pop(l, 1);
                ++j;
-               count = LuaToNumber(l, j + 1);
+               lua_rawgeti(l, 2, j + 1);
+               count = LuaToNumber(l, -1);
+               lua_pop(l, 1);
 
                if (!type) { // bulletproof
                        continue;




reply via email to

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