stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src include/player.h include/script.h...


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src include/player.h include/script.h...
Date: 21 Jan 2004 03:44:59 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/21 03:44:58

Modified files:
        src/include    : player.h script.h stratagus.h 
        src/stratagus  : script.c script_player.c stratagus.c 
        src/unit       : unittype.c 

Log message:
        Initial Stratagus.Players interface in META_LUA.

Patches:
Index: stratagus/src/include/player.h
diff -u stratagus/src/include/player.h:1.85 stratagus/src/include/player.h:1.86
--- stratagus/src/include/player.h:1.85 Sat Jan 17 13:12:49 2004
+++ stratagus/src/include/player.h      Wed Jan 21 03:44:56 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: player.h,v 1.85 2004/01/17 02:12:49 wizzard Exp $
+//      $Id: player.h,v 1.86 2004/01/20 16:44:56 nobody_ Exp $
 
 #ifndef __PLAYER_H__
 #define __PLAYER_H__
@@ -541,6 +541,13 @@
 #define PlayersTeamed(a, b) ((Players[a].Allied & (1 << (b))) && 
(Players[b].Allied & (1 << (a))) )
        /// Allowed to select multiple units, maybe not mine
 #define CanSelectMultipleUnits(player) ((player) == ThisPlayer || 
PlayersTeamed(ThisPlayer->Player, (player)->Player))
+
+#ifdef META_LUA
+
+       /// Initialize scripting
+extern void ScriptPlayerInit(void);
+
+#endif
 
 //@}
 
Index: stratagus/src/include/script.h
diff -u stratagus/src/include/script.h:1.54 stratagus/src/include/script.h:1.55
--- stratagus/src/include/script.h:1.54 Tue Jan 20 10:24:38 2004
+++ stratagus/src/include/script.h      Wed Jan 21 03:44:56 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: script.h,v 1.54 2004/01/19 23:24:38 nobody_ Exp $
+//      $Id: script.h,v 1.55 2004/01/20 16:44:56 nobody_ Exp $
 
 #ifndef __SCRIPT_H__
 #define __SCRIPT_H__
@@ -114,6 +114,8 @@
 
        /// Userdata Constructor. Push userdata on the stack.
 extern void ScriptCreateUserdata(lua_State* l, void* object, ScriptProxyType* 
type);
+       /// Init ScriptProxyType with all blockers.
+extern void ScriptProxyTypeInitBlock(ScriptProxyType* type);
        /// Really dumb set function that always goes into an error, with 
string key
 extern int ScriptGetSetStrBlock(void* object, const char* key, lua_State* l);
        /// Really dumb set function that always goes into an error, with int 
index
Index: stratagus/src/include/stratagus.h
diff -u stratagus/src/include/stratagus.h:1.43 
stratagus/src/include/stratagus.h:1.44
--- stratagus/src/include/stratagus.h:1.43      Tue Jan 20 18:03:23 2004
+++ stratagus/src/include/stratagus.h   Wed Jan 21 03:44:56 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: stratagus.h,v 1.43 2004/01/20 07:03:23 jsalmon3 Exp $
+//      $Id: stratagus.h,v 1.44 2004/01/20 16:44:56 nobody_ Exp $
 
 #ifndef __STRATAGUS_H__
 #define __STRATAGUS_H__
@@ -44,7 +44,7 @@
 #define NEW_UNIT_CACHE
 
 // New Lua scripting.
-// #define META_LUA
+//#define META_LUA
 
 // Dynamic loading.
 //#define DYNAMIC_LOAD
Index: stratagus/src/stratagus/script.c
diff -u stratagus/src/stratagus/script.c:1.161 
stratagus/src/stratagus/script.c:1.162
--- stratagus/src/stratagus/script.c:1.161      Tue Jan 20 10:24:40 2004
+++ stratagus/src/stratagus/script.c    Wed Jan 21 03:44:56 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: script.c,v 1.161 2004/01/19 23:24:40 nobody_ Exp $
+//      $Id: script.c,v 1.162 2004/01/20 16:44:56 nobody_ Exp $
 
 //@{
 
@@ -1091,6 +1091,20 @@
 }
 
 /**
+**  Initialize a ScriptProxyType with blockers
+**
+**  @param type     ScriptProxyType
+*/
+extern void ScriptProxyTypeInitBlock(ScriptProxyType* type)
+{
+       type->GetStr = ScriptGetSetStrBlock;
+       type->SetStr = ScriptGetSetStrBlock;
+       type->GetInt = ScriptGetSetIntBlock;
+       type->SetInt = ScriptGetSetIntBlock;
+       type->Collect = 0;
+}
+
+/**
 **  Get a value from the big Stratagus struct.
 */
 local int ScriptStratagusGetValue(lua_State* l)
@@ -1342,7 +1356,7 @@
        }
 
        fprintf(fd, "--- -----------------------------------------\n");
-       fprintf(fd, "--- $Id: script.c,v 1.161 2004/01/19 23:24:40 nobody_ Exp 
$\n");
+       fprintf(fd, "--- $Id: script.c,v 1.162 2004/01/20 16:44:56 nobody_ Exp 
$\n");
 
        fprintf(fd, "SetVideoResolution(%d, %d)\n", VideoWidth, VideoHeight);
        fprintf(fd, "SetGroupKeys(\"");
@@ -1378,7 +1392,7 @@
        }
 
        fprintf(fd, "--- -----------------------------------------\n");
-       fprintf(fd, "--- $Id: script.c,v 1.161 2004/01/19 23:24:40 nobody_ Exp 
$\n");
+       fprintf(fd, "--- $Id: script.c,v 1.162 2004/01/20 16:44:56 nobody_ Exp 
$\n");
 
        // Global options
        if (OriginalFogOfWar) {
@@ -1481,7 +1495,7 @@
        extern SCM oblistvar;
 
        CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: CCL $Id: script.c,v 1.161 2004/01/19 
23:24:40 nobody_ Exp $\n\n");
+       CLprintf(file, ";;; MODULE: CCL $Id: script.c,v 1.162 2004/01/20 
16:44:56 nobody_ Exp $\n\n");
 
        for (list = oblistvar; gh_list_p(list); list = gh_cdr(list)) {
                SCM sym;
Index: stratagus/src/stratagus/script_player.c
diff -u stratagus/src/stratagus/script_player.c:1.55 
stratagus/src/stratagus/script_player.c:1.56
--- stratagus/src/stratagus/script_player.c:1.55        Sat Jan 17 02:17:30 2004
+++ stratagus/src/stratagus/script_player.c     Wed Jan 21 03:44:57 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: script_player.c,v 1.55 2004/01/16 15:17:30 wizzard Exp $
+//      $Id: script_player.c,v 1.56 2004/01/20 16:44:57 nobody_ Exp $
 
 //@{
 
@@ -800,5 +800,208 @@
        lua_register(Lua, "GetPlayerResource", CclGetPlayerResource);
        lua_register(Lua, "SetPlayerResource", CclSetPlayerResource);
 }
+
+#ifdef META_LUA
+
+       /// Proxy type for the Player array
+local ScriptProxyType ScriptProxyPlayerArray;
+       /// Proxy type for Player
+local ScriptProxyType ScriptProxyPlayer;
+       /// Proxy type for Player->Allied
+local ScriptProxyType ScriptProxyPlayerAllied;
+       /// Proxy type for Player->Enemy
+local ScriptProxyType ScriptProxyPlayerEnemy;
+       /// Proxy type for Player->SharedVision
+local ScriptProxyType ScriptProxyPlayerSharedVision;
+       /// Proxy type for Player->UnitTypesCount
+local ScriptProxyType ScriptProxtPlayerUnitTypesCount;
+
+/**
+**     Get function for the big Players namespace, with int index
+*/
+local int ScriptPlayerArrayGetInt(void* object, int index, lua_State* l)
+{
+       if (index < 0 || index >= PlayerMax) {
+               LuaError(l, "Player index out of range");
+       }
+       ScriptCreateUserdata(l, Players + index, &ScriptProxyPlayer);
+       return 1;
+}
+
+/**
+**     Get function for a player userdata.
+*/
+local int ScriptPlayerGet(Player* player, const char* key, lua_State* l)
+{
+       META_GET_INT("Slot", player->Player);
+       META_GET_STRING("Name", player->Name);
+
+       META_GET_INT("TotalNumUnits", player->TotalNumUnits);
+       META_GET_INT("NumBuildings", player->NumBuildings);
+       META_GET_INT("UnitLimit", player->UnitLimit);
+       META_GET_INT("BuildingLimit", player->BuildingLimit);
+       META_GET_INT("TotalUnitLimit", player->TotalUnitLimit);
+       META_GET_INT("Supply", player->Supply);
+       META_GET_INT("Demand", player->Demand);
+
+       META_GET_INT("StartX", player->StartX);
+       META_GET_INT("StartY", player->StartY);
+
+       META_GET_INT("Score", player->Score);
+       META_GET_INT("TotalUnits", player->TotalUnits);
+       META_GET_INT("TotalBuildings", player->TotalBuildings);
+       META_GET_INT("TotalRazings", player->TotalRazings);
+       META_GET_INT("TotalKills", player->TotalKills);
+
+       LuaError(l, "Field \"%s\" is innexistent or write-only (yes, we have 
those).\n" _C_ key);
+}
+
+/**
+**     Set function for a player userdata.
+*/
+local int ScriptPlayerSet(Player* player, const char* key, lua_State* l)
+{
+       META_SET_STRING("Name", player->Name);
+
+       META_SET_INT("TotalNumUnits", player->TotalNumUnits);
+       META_SET_INT("NumBuildings", player->NumBuildings);
+       META_SET_INT("UnitLimit", player->UnitLimit);
+       META_SET_INT("BuildingLimit", player->BuildingLimit);
+       META_SET_INT("TotalUnitLimit", player->TotalUnitLimit);
+       META_SET_INT("Supply", player->Supply);
+       META_SET_INT("Demand", player->Demand);
+
+       META_SET_INT("StartX", player->StartX);
+       META_SET_INT("StartY", player->StartY);
+
+       META_SET_INT("Score", player->Score);
+       META_SET_INT("TotalUnits", player->TotalUnits);
+       META_SET_INT("TotalBuildings", player->TotalBuildings);
+       META_SET_INT("TotalRazings", player->TotalRazings);
+       META_SET_INT("TotalKills", player->TotalKills);
+
+       LuaError(l, "Field \"%s\" is innexistent or read-only.\n" _C_ key);
+}
+
+/**
+**     Get function for Player->Allied
+*/
+local int ScriptPlayerAlliedGet(Player* player, int index, lua_State* l)
+{
+       lua_pushboolean(l, player->Allied & (1 << index));
+       return 1;
+}
+
+/**
+**     Set function for Player->Allied
+*/
+local int ScriptPlayerAlliedSet(Player* player, int index, lua_State* l)
+{
+       if (LuaToBoolean(l, -1)) {
+               player->Allied |= (1 << index);
+       } else {
+               player->Allied &= ~(1 << index);
+       }
+       return 1;
+}
+
+/**
+**     Get function for Player->Enemy
+*/
+local int ScriptPlayerEnemyGet(Player* player, int index, lua_State* l)
+{
+       lua_pushboolean(l, player->Enemy & (1 << index));
+       return 1;
+}
+
+/**
+**     Set function for Player->Enemy
+*/
+local int ScriptPlayerEnemySet(Player* player, int index, lua_State* l)
+{
+       if (LuaToBoolean(l, -1)) {
+               player->Enemy |= (1 << index);
+       } else {
+               player->Enemy &= ~(1 << index);
+       }
+       return 1;
+}
+
+/**
+**     Get function for Player->SharedVision
+*/
+local int ScriptPlayerSharedVisionGet(Player* player, int index, lua_State* l)
+{
+       lua_pushboolean(l, player->SharedVision & (1 << index));
+       return 1;
+}
+
+/**
+**     Set function for Player->SharedVision
+*/
+local int ScriptPlayerSharedVisionSet(Player* player, int index, lua_State* l)
+{
+       CommandSharedVision(player->Player, LuaToBoolean(l, -1), index);
+       return 1;
+}
+
+/**
+**     Get function for Player->UnitTypesCount with string key
+*/
+local int ScriptPlayerUnitTypesCountGetStr(Player* player, const char* key, 
lua_State* l)
+{
+       UnitType* type;
+
+       if ((type = UnitTypeByIdent(key))) {
+               lua_pushnumber(l, player->UnitTypesCount[type->Slot]);
+               return 1;
+       }
+       LuaError(l, "Unit \"%s\" not found." _C_ key);
+}
+
+/**
+**     Get function for Player->UnitTypesCount with int index
+*/
+local int ScriptPlayerUnitTypesCountGetInt(Player* player, int index, 
lua_State* l)
+{
+       if (index < 0 || index >= NumUnitTypes) {
+               LuaError(l, "Unittype index out of range.");
+       }
+
+       lua_pushnumber(l, player->UnitTypesCount[index]);
+       return 1;
+}
+
+/**
+**     Initialize player scripting. The main table is at -1
+*/
+global void ScriptPlayerInit(void)
+{
+       ScriptProxyTypeInitBlock(&ScriptProxyPlayerArray);
+       ScriptProxyPlayerArray.GetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerArrayGetInt;
+
+       ScriptProxyTypeInitBlock(&ScriptProxyPlayer);
+       ScriptProxyPlayer.GetStr = (ScriptGetSetStrFunction *)ScriptPlayerGet;
+       ScriptProxyPlayer.SetStr = (ScriptGetSetStrFunction *)ScriptPlayerSet;
+
+       ScriptProxyTypeInitBlock(&ScriptProxyPlayerAllied);
+       ScriptProxyPlayerAllied.GetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerAlliedGet;
+       ScriptProxyPlayerAllied.SetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerAlliedSet;
+
+       ScriptProxyTypeInitBlock(&ScriptProxyPlayerEnemy);
+       ScriptProxyPlayerEnemy.GetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerEnemyGet;
+       ScriptProxyPlayerEnemy.SetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerEnemySet;
+
+       ScriptProxyTypeInitBlock(&ScriptProxyPlayerSharedVision);
+       ScriptProxyPlayerSharedVision.GetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerSharedVisionGet;
+       ScriptProxyPlayerSharedVision.SetInt = (ScriptGetSetIntFunction 
*)ScriptPlayerSharedVisionSet;
+
+       // Create Stratagus.Players namespace.
+       lua_pushstring(Lua, "Players");
+       ScriptCreateUserdata(Lua, 0, &ScriptProxyPlayerArray);
+       lua_rawset(Lua, -3);
+}
+
+#endif
 
 //@}
Index: stratagus/src/stratagus/stratagus.c
diff -u stratagus/src/stratagus/stratagus.c:1.250 
stratagus/src/stratagus/stratagus.c:1.251
--- stratagus/src/stratagus/stratagus.c:1.250   Sun Jan 18 09:23:27 2004
+++ stratagus/src/stratagus/stratagus.c Wed Jan 21 03:44:57 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: stratagus.c,v 1.250 2004/01/17 22:23:27 nobody_ Exp $
+//      $Id: stratagus.c,v 1.251 2004/01/20 16:44:57 nobody_ Exp $
 
 //@{
 
@@ -254,10 +254,10 @@
 
 global int SpeedResourcesHarvest[MaxCosts]; /// speed factor for harvesting 
resources
 global int SpeedResourcesReturn[MaxCosts];  /// speed factor for returning 
resources
-global int SpeedBuild = SPEED_BUILD;        /// speed factor for building
-global int SpeedTrain = SPEED_TRAIN;        /// speed factor for training
-global int SpeedUpgrade = SPEED_UPGRADE;    /// speed factor for upgrading
-global int SpeedResearch = SPEED_RESEARCH;  /// speed factor for researching
+global int SpeedBuild = 1;        /// speed factor for building
+global int SpeedTrain = 1;        /// speed factor for training
+global int SpeedUpgrade = 1;    /// speed factor for upgrading
+global int SpeedResearch = 1;  /// speed factor for researching
 
 /*============================================================================
 ==  DISPLAY
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.147 stratagus/src/unit/unittype.c:1.148
--- stratagus/src/unit/unittype.c:1.147 Mon Jan 19 09:36:32 2004
+++ stratagus/src/unit/unittype.c       Wed Jan 21 03:44:57 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unittype.c,v 1.147 2004/01/18 22:36:32 nobody_ Exp $
+//      $Id: unittype.c,v 1.148 2004/01/20 16:44:57 nobody_ Exp $
 
 //@{
 
@@ -1187,7 +1187,7 @@
 //     char** sp;
 
        CLprintf(file, "\n--- -----------------------------------------\n");
-       CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.147 
2004/01/18 22:36:32 nobody_ Exp $\n\n");
+       CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.148 
2004/01/20 16:44:57 nobody_ Exp $\n\n");
 #if 0
        // Original number to internal unit-type name.
 
@@ -1234,18 +1234,7 @@
        UnitType* const* type;
 
        type = (UnitType* const*)hash_find(UnitTypeHash, ident);
-       if (type) {
-               return *type;
-       }
-
-#ifdef DEBUG
-       if (!NoWarningUnitType) {
-               DebugLevel0Fn("Name `%s' not found\n" _C_ ident);
-               DebugCheck(1);
-       }
-#endif
-
-       return NULL;
+       return type ? *type : 0;
 }
 
 /**




reply via email to

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