stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src missile/missile.c stratagus/ccl_p...


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src missile/missile.c stratagus/ccl_p...
Date: 3 Jan 2004 09:53:30 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/03 09:53:30

Modified files:
        src/missile    : missile.c 
        src/stratagus  : ccl_player.c player.c 

Log message:
        Load/Save updates

Patches:
Index: stratagus/src/missile/missile.c
diff -u stratagus/src/missile/missile.c:1.121 
stratagus/src/missile/missile.c:1.122
--- stratagus/src/missile/missile.c:1.121       Sun Dec 21 20:44:37 2003
+++ stratagus/src/missile/missile.c     Sat Jan  3 09:53:28 2004
@@ -10,7 +10,7 @@
 //
 /address@hidden missile.c - The missiles. */
 //
-//      (c) Copyright 1998-2003 by Lutz Sammer and Jimmy Salmon
+//      (c) Copyright 1998-2004 by Lutz Sammer 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 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: missile.c,v 1.121 2003/12/21 09:44:37 wizzard Exp $
+//      $Id: missile.c,v 1.122 2004/01/02 22:53:28 jsalmon3 Exp $
 
 //@{
 
@@ -1338,13 +1338,14 @@
 */
 global void SaveMissileTypes(CLFile* file)
 {
+#if 0
        MissileType* mtype;
        char** sp;
        int i;
 
        DebugCheck(file == NULL);
        CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.121 
2003/12/21 09:44:37 wizzard Exp $\n\n");
+       CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.122 
2004/01/02 22:53:28 jsalmon3 Exp $\n\n");
 
        //
        // Original number to internal missile-type name.
@@ -1385,7 +1386,7 @@
                        CLprintf(file, "\n ");
                }
                CLprintf(file, " 'class '%s", MissileClassNames[mtype->Class]);
-               if (mtype->Class==MissileClassPointToPointBounce) {
+               if (mtype->Class == MissileClassPointToPointBounce) {
                        CLprintf(file," 'num-bounces %d",mtype->NumBounces);
                }
                CLprintf(file, " 'class '%s", MissileClassNames[mtype->Class]);
@@ -1412,44 +1413,47 @@
                }
                CLprintf(file, ")\n");
        }
+#endif
 }
 
 /**
 **  Save the state of a missile to file.
 **
-**  @param missile  FIXME: docu
+**  @param missile  Missile object to save.
 **  @param file     Output file.
 */
 local void SaveMissile(const Missile* missile, CLFile* file)
 {
        char* s1;
 
-       DebugCheck(missile == NULL);
-       DebugCheck(missile->Type == NULL);
-       DebugCheck(file == NULL);
-       CLprintf(file, "(missile 'type '%s", missile->Type->Ident);
-       CLprintf(file, " 'pos '(%d %d) 'origin-pos '(%d %d) 'goal '(%d %d)",
+       CLprintf(file, "Missile(\"type\", \"%s\",", missile->Type->Ident);
+       CLprintf(file, " \"pos\", {%d, %d}, \"origin-pos\", {%d, %d}, \"goal\", 
{%d, %d},",
                missile->X, missile->Y, missile->SourceX, missile->SourceY, 
missile->DX, missile->DY);
-       CLprintf(file, " '%s", missile->Local ? "local" : "global");
-       CLprintf(file, "\n  'frame %d 'state %d 'wait %d 'delay %d\n ",
-               missile->SpriteFrame, missile->State, missile->Wait, 
missile->Delay);
+       CLprintf(file, "\n  \"frame\", %d, \"state\", %d, \"anim-wait\", %d, 
\"wait\", %d, \"delay\", %d,\n ",
+               missile->SpriteFrame, missile->State, missile->AnimWait, 
missile->Wait, missile->Delay);
 
        if (missile->SourceUnit) {
-               CLprintf(file, " 'source '%s", s1 = 
UnitReference(missile->SourceUnit));
+               CLprintf(file, " \"source\", \"%s\",", s1 = 
UnitReference(missile->SourceUnit));
                free(s1);
        }
        if (missile->TargetUnit) {
-               CLprintf(file, " 'target '%s", s1 = 
UnitReference(missile->TargetUnit));
+               CLprintf(file, " \"target\", \"%s\",", s1 = 
UnitReference(missile->TargetUnit));
                free(s1);
        }
-       CLprintf(file, " 'damage %d", missile->Damage);
-       CLprintf(file, " 'ttl %d",              missile->TTL);
+
+       CLprintf(file, " \"damage\", %d,", missile->Damage);
+
+       CLprintf(file, " \"ttl\", %d,",         missile->TTL);
        if (missile->Hidden) {
-               CLprintf(file, " 'hidden ");
+               CLprintf(file, " \"hidden\", ");
        }
-       CLprintf(file, " 'step '(%d %d)",
-               missile->CurrentStep,
-               missile->TotalStep);
+
+       CLprintf(file, " \"step\", {%d, %d},",
+               missile->CurrentStep, missile->TotalStep);
+
+       CLprintf(file, " \"%s\",", missile->Local ? "local" : "global");
+       // MissileSlot filled in during init
+
        CLprintf(file, ")\n");
 }
 
@@ -1462,9 +1466,8 @@
 {
        Missile* const* missiles;
 
-       DebugCheck(file == NULL);
-       CLprintf(file,"\n;;; -----------------------------------------\n");
-       CLprintf(file,";;; MODULE: missiles $Id: missile.c,v 1.121 2003/12/21 
09:44:37 wizzard Exp $\n\n");
+       CLprintf(file,"\n--- -----------------------------------------\n");
+       CLprintf(file,"--- MODULE: missiles $Id: missile.c,v 1.122 2004/01/02 
22:53:28 jsalmon3 Exp $\n\n");
 
        for (missiles = GlobalMissiles; *missiles; ++missiles) {
                SaveMissile(*missiles, file);
Index: stratagus/src/stratagus/ccl_player.c
diff -u stratagus/src/stratagus/ccl_player.c:1.52 
stratagus/src/stratagus/ccl_player.c:1.53
--- stratagus/src/stratagus/ccl_player.c:1.52   Fri Jan  2 08:24:14 2004
+++ stratagus/src/stratagus/ccl_player.c        Sat Jan  3 09:53:29 2004
@@ -5,12 +5,12 @@
 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
 //             \/                  \/          \//_____/            \/
 //  ______________________                           ______________________
-//                       T H E   W A R   B E G I N S
-//        Stratagus - A free fantasy real time strategy game engine
+//                        T H E   W A R   B E G I N S
+//         Stratagus - A free fantasy real time strategy game engine
 //
-/address@hidden ccl_player.c   -       The player ccl functions. */
+/address@hidden ccl_player.c - The player ccl functions. */
 //
-//     (c) Copyright 2001-2003 by Lutz Sammer
+//      (c) Copyright 2001-2004 by Lutz Sammer 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 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_player.c,v 1.52 2004/01/01 21:24:14 jsalmon3 Exp $
+//      $Id: ccl_player.c,v 1.53 2004/01/02 22:53:29 jsalmon3 Exp $
 
 //@{
 
@@ -203,6 +203,31 @@
                                        lua_error(l);
                                }
                        }
+               } else if (!strcmp(value, "last-resources")) {
+                       if (!lua_istable(l, j + 1)) {
+                               lua_pushstring(l, "incorrect argument");
+                               lua_error(l);
+                       }
+                       subargs = luaL_getn(l, j + 1);
+                       for (k = 0; k < subargs; ++k) {
+                               lua_rawgeti(l, j + 1, k + 1);
+                               value = LuaToString(l, -1);
+                               lua_pop(l, 1);
+                               ++k;
+
+                               for (i = 0; i < MaxCosts; ++i) {
+                                       if (!strcmp(value, 
DefaultResourceNames[i])) {
+                                               lua_rawgeti(l, j + 1, k + 1);
+                                               player->LastResources[i] = 
LuaToNumber(l, -1);
+                                               lua_pop(l, 1);
+                                               break;
+                                       }
+                               }
+                               if (i == MaxCosts) {
+                                       lua_pushfstring(l, "Unsupported tag: 
%s", value);
+                                       lua_error(l);
+                               }
+                       }
                } else if (!strcmp(value, "incomes")) {
                        if (!lua_istable(l, j + 1)) {
                                lua_pushstring(l, "incorrect argument");
@@ -218,7 +243,32 @@
                                for (i = 0; i < MaxCosts; ++i) {
                                        if (!strcmp(value, 
DefaultResourceNames[i])) {
                                                lua_rawgeti(l, j + 1, k + 1);
-                                               player->Resources[i] = 
LuaToNumber(l, -1);
+                                               player->Incomes[i] = 
LuaToNumber(l, -1);
+                                               lua_pop(l, 1);
+                                               break;
+                                       }
+                               }
+                               if (i == MaxCosts) {
+                                       lua_pushfstring(l, "Unsupported tag: 
%s", value);
+                                       lua_error(l);
+                               }
+                       }
+               } else if (!strcmp(value, "revenue")) {
+                       if (!lua_istable(l, j + 1)) {
+                               lua_pushstring(l, "incorrect argument");
+                               lua_error(l);
+                       }
+                       subargs = luaL_getn(l, j + 1);
+                       for (k = 0; k < subargs; ++k) {
+                               lua_rawgeti(l, j + 1, k + 1);
+                               value = LuaToString(l, -1);
+                               lua_pop(l, 1);
+                               ++k;
+
+                               for (i = 0; i < MaxCosts; ++i) {
+                                       if (!strcmp(value, 
DefaultResourceNames[i])) {
+                                               lua_rawgeti(l, j + 1, k + 1);
+                                               player->Revenue[i] = 
LuaToNumber(l, -1);
                                                lua_pop(l, 1);
                                                break;
                                        }
Index: stratagus/src/stratagus/player.c
diff -u stratagus/src/stratagus/player.c:1.106 
stratagus/src/stratagus/player.c:1.107
--- stratagus/src/stratagus/player.c:1.106      Sat Dec 20 16:33:18 2003
+++ stratagus/src/stratagus/player.c    Sat Jan  3 09:53:29 2004
@@ -5,12 +5,12 @@
 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
 //             \/                  \/          \//_____/            \/
 //  ______________________                           ______________________
-//                       T H E   W A R   B E G I N S
-//        Stratagus - A free fantasy real time strategy game engine
+//                        T H E   W A R   B E G I N S
+//         Stratagus - A free fantasy real time strategy game engine
 //
-/address@hidden player.c       -       The players. */
+/address@hidden player.c - The players. */
 //
-//     (c) Copyright 1998-2003 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
+//      (c) Copyright 1998-2004 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
 //
 //      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 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: player.c,v 1.106 2003/12/20 05:33:18 jsalmon3 Exp $
+//      $Id: player.c,v 1.107 2004/01/02 22:53:29 jsalmon3 Exp $
 
 //@{
 
@@ -208,22 +208,23 @@
 }
 
 /**
-**             Save state of players to file.
+**  Save state of players to file.
 **
-**             @param file             Output file.
+**  @param file  Output file.
 **
-**             @note FIXME: Not complete saved.
+**  @note FIXME: Not completely saved.
 */
 global void SavePlayers(CLFile* file)
 {
        int i;
        int j;
 
-       CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.106 2003/12/20 
05:33:18 jsalmon3 Exp $\n\n");
+       CLprintf(file, "\n--- -----------------------------------------\n");
+       CLprintf(file, "--- MODULE: players $Id: player.c,v 1.107 2004/01/02 
22:53:29 jsalmon3 Exp $\n\n");
 
+#if 0
        //
-       //              Dump table wc2 race numbers -> internal symbol.
+       //  Dump table wc2 race numbers -> internal symbol.
        //
        if (PlayerRaces.Count) {
                CLprintf(file, "(define-race-names");
@@ -241,7 +242,7 @@
        }
 
        //
-       //              Dump table wc2 race numbers -> internal symbol.
+       //  Dump table wc2 race numbers -> internal symbol.
        //
        if (PlayerRaces.Count) {
                CLprintf(file, "(define-race-names");
@@ -257,44 +258,45 @@
                }
                CLprintf(file, ")\n\n");
        }
+#endif
 
        //
-       //              Dump all players
+       //  Dump all players
        //
        for (i = 0; i < NumPlayers; ++i) {
-               CLprintf(file, "(player %d\n", i);
-               CLprintf(file, "  'name \"%s\"\n", Players[i].Name);
-               CLprintf(file, "  'type ");
+               CLprintf(file, "Player(%d,\n", i);
+               CLprintf(file, "  \"name\", \"%s\",\n", Players[i].Name);
+               CLprintf(file, "  \"type\", ");
                switch (Players[i].Type) {
-                       case PlayerNeutral:                       
CLprintf(file, "'neutral");           break;
-                       case PlayerNobody:                        
CLprintf(file, "'nobody");            break;
-                       case PlayerComputer:      CLprintf(file, "'computer");  
        break;
-                       case PlayerPerson:                        
CLprintf(file, "'person");            break;
-                       case PlayerRescuePassive: CLprintf(file, 
"'rescue-passive");break;
-                       case PlayerRescueActive:  CLprintf(file, 
"'rescue-active");             break;
-                       default:                                          
CLprintf(file, "%d",Players[i].Type); break;
-               }
-               CLprintf(file, " 'race \"%s\"", Players[i].RaceName);
-               CLprintf(file, " 'ai %d\n", Players[i].AiNum);
-               CLprintf(file, "  'team %d", Players[i].Team);
+                       case PlayerNeutral:       CLprintf(file, 
"\"neutral\",");         break;
+                       case PlayerNobody:        CLprintf(file, 
"\"nobody\",");          break;
+                       case PlayerComputer:      CLprintf(file, 
"\"computer\",");        break;
+                       case PlayerPerson:        CLprintf(file, 
"\"person\",");          break;
+                       case PlayerRescuePassive: CLprintf(file, 
"\"rescue-passive\",");break;
+                       case PlayerRescueActive:  CLprintf(file, 
"\"rescue-active\","); break;
+                       default:                  CLprintf(file, 
"%d,",Players[i].Type);break;
+               }
+               CLprintf(file, " \"race\", \"%s\",", Players[i].RaceName);
+               CLprintf(file, " \"ai\", %d,\n", Players[i].AiNum);
+               CLprintf(file, "  \"team\", %d,", Players[i].Team);
 
-               CLprintf(file, " 'enemy \"");
+               CLprintf(file, " \"enemy\", \"");
                for (j = 0; j < PlayerMax; ++j) {
-                       CLprintf(file, "%c",(Players[i].Enemy&(1<<j)) ? 'X' : 
'_');
+                       CLprintf(file, "%c",(Players[i].Enemy & (1 << j)) ? 'X' 
: '_');
                }
-               CLprintf(file, "\" 'allied \"");
+               CLprintf(file, "\", \"allied\", \"");
                for (j = 0; j < PlayerMax; ++j) {
                        CLprintf(file, "%c", (Players[i].Allied & (1 << j)) ? 
'X' : '_');
                }
-               CLprintf(file, "\" 'shared-vision \"");
+               CLprintf(file, "\", \"shared-vision\", \"");
                for (j = 0; j < PlayerMax; ++j) {
                        CLprintf(file, "%c", (Players[i].SharedVision & (1 << 
j)) ? 'X' : '_');
                }
-               CLprintf(file, "\"\n  'start '(%d %d)\n", Players[i].StartX,
+               CLprintf(file, "\",\n  \"start\", {%d, %d},\n", 
Players[i].StartX,
                        Players[i].StartY);
 
                // Resources
-               CLprintf(file, "  'resources '(");
+               CLprintf(file, "  \"resources\", {");
                for (j = 0; j < MaxCosts; ++j) {
                        if (j) {
                                if (j == MaxCosts / 2) {
@@ -303,11 +305,24 @@
                                        CLprintf(file, " ");
                                }
                        }
-                       CLprintf(file, "%s %d", DefaultResourceNames[j],
+                       CLprintf(file, "\"%s\", %d,", DefaultResourceNames[j],
                                Players[i].Resources[j]);
                }
+               // Last Resources
+               CLprintf(file, "},\n  \"last-resources\", {");
+               for (j = 0; j < MaxCosts; ++j) {
+                       if (j) {
+                               if (j == MaxCosts / 2) {
+                                       CLprintf(file, "\n      ");
+                               } else {
+                                       CLprintf(file, " ");
+                               }
+                       }
+                       CLprintf(file, "\"%s\", %d,", DefaultResourceNames[j],
+                               Players[i].LastResources[j]);
+               }
                // Incomes
-               CLprintf(file, ")\n  'incomes '(");
+               CLprintf(file, "},\n  \"incomes\", {");
                for (j = 0; j < MaxCosts; ++j) {
                        if (j) {
                                if (j == MaxCosts / 2) {
@@ -316,57 +331,77 @@
                                        CLprintf(file, " ");
                                }
                        }
-                       CLprintf(file, "%s %d", DefaultResourceNames[j],
+                       CLprintf(file, "\"%s\", %d,", DefaultResourceNames[j],
                                Players[i].Incomes[j]);
                }
-               CLprintf(file, ";;FIXME: new members must be saved\n");
+               // Revenue
+               CLprintf(file, "},\n  \"revenue\", {");
+               for (j = 0; j < MaxCosts; ++j) {
+                       if (j) {
+                               if (j == MaxCosts / 2) {
+                                       CLprintf(file, "\n      ");
+                               } else {
+                                       CLprintf(file, " ");
+                               }
+                       }
+                       CLprintf(file, "\"%s\", %d,", DefaultResourceNames[j],
+                               Players[i].Revenue[j]);
+               }
 
                // UnitTypesCount done by load units.
 
-               CLprintf(file, ")\n  '%s\n",Players[i].AiEnabled ?
+               CLprintf(file, "},\n  \"%s\",\n", Players[i].AiEnabled ?
                        "ai-enabled" : "ai-disabled");
 
                // Ai done by load ais.
-
-               CLprintf(file, " 'supply %d", Players[i].Supply);
-               CLprintf(file, " 'demand %d", Players[i].Demand);
-               CLprintf(file, " 'building-limit %d", Players[i].BuildingLimit);
-               CLprintf(file, " 'unit-limit %d", Players[i].UnitLimit);
-               CLprintf(file, " 'total-unit-limit %d", 
Players[i].TotalUnitLimit);
-
-               CLprintf(file, "\n  'score %d", Players[i].Score);
-               CLprintf(file, "\n  'total-units %d", Players[i].TotalUnits);
-               CLprintf(file, "\n  'total-buildings %d", 
Players[i].TotalBuildings);
-               CLprintf(file, "\n  'total-razings %d", 
Players[i].TotalRazings);
-               CLprintf(file, "\n  'total-kills %d", Players[i].TotalKills);
-               CLprintf(file, "\n  'total-resources '(");
+               // Units done by load units.
+               // TotalNumUnits done by load units.
+               // NumBuildings done by load units.
+
+               CLprintf(file, " \"supply\", %d,", Players[i].Supply);
+               CLprintf(file, " \"demand\", %d,", Players[i].Demand);
+
+               CLprintf(file, " \"unit-limit\", %d,", Players[i].UnitLimit);
+               CLprintf(file, " \"building-limit\", %d,", 
Players[i].BuildingLimit);
+               CLprintf(file, " \"total-unit-limit\", %d,", 
Players[i].TotalUnitLimit);
+
+               CLprintf(file, "\n  \"score\", %d,", Players[i].Score);
+               CLprintf(file, "\n  \"total-units\", %d,", 
Players[i].TotalUnits);
+               CLprintf(file, "\n  \"total-buildings\", %d,", 
Players[i].TotalBuildings);
+               CLprintf(file, "\n  \"total-resources\", {");
                for (j = 0; j < MaxCosts; ++j) {
-                       CLprintf(file, "%d ", Players[i].TotalResources[j]);
+                       if (j) {
+                               CLprintf(file, " ");
+                       }
+                       CLprintf(file, "%d,", Players[i].TotalResources[j]);
                }
-               CLprintf(file, ")");
+               CLprintf(file, "},");
+               CLprintf(file, "\n  \"total-razings\", %d,", 
Players[i].TotalRazings);
+               CLprintf(file, "\n  \"total-kills\", %d,", 
Players[i].TotalKills);
 
-               // Colors done by init code.
+               // Color done by init code.
+               // UnitColors done by init code.
 
                // Allow saved by allow.
 
-               CLprintf(file, "\n  'timers '(");
+               CLprintf(file, "\n  \"timers\", {");
                for (j = 0; j < UpgradeMax; ++j) {
                        if (j) {
                                CLprintf(file, " ");
                        }
-                       CLprintf(file, 
"%d",Players[i].UpgradeTimers.Upgrades[j]);
+                       CLprintf(file, "%d,", 
Players[i].UpgradeTimers.Upgrades[j]);
                }
-               CLprintf(file, ")");
+               CLprintf(file, "},");
 
                CLprintf(file, ")\n\n");
        }
 
-       DebugLevel0Fn("FIXME: must unit-stats?\n");
+       DebugLevel0Fn("FIXME: must save unit-stats?\n");
 
        //
-       //              Dump local variables
+       //  Dump local variables
        //
-       CLprintf(file, "(set-this-player! %d)\n\n", ThisPlayer->Player);
+       CLprintf(file, "SetThisPlayer(%d)\n\n", ThisPlayer->Player);
 }
 
 /**
@@ -850,20 +885,20 @@
 }
 
 /**
-**             Handle AI of a player each second.
+**  Handle AI of a player each second.
 **
-**       @param player                 the player to update AI
+**  @param player  the player to update AI
 */
 global void PlayersEachSecond(int player)
 {
        int res;
 
        if ((GameCycle / CYCLES_PER_SECOND) % 10 == 0) {
-               for (res = 0; res < MaxCosts; res++) {
+               for (res = 0; res < MaxCosts; ++res) {
                        Players[player].Revenue[res] =
                                Players[player].Resources[res] -
                                Players[player].LastResources[res];
-                       Players[player].Revenue[res] *= 6;              // 
estimate per minute
+                       Players[player].Revenue[res] *= 6;  // estimate per 
minute
                        Players[player].LastResources[res] =
                                Players[player].Resources[res];
                }




reply via email to

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