stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src/stratagus script.c stratagus.c


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src/stratagus script.c stratagus.c
Date: 23 Jan 2004 04:07:31 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/23 04:07:30

Modified files:
        src/stratagus  : script.c stratagus.c 

Log message:
        Stratagus.SyncRand() and Stratagus.MyRand()

Patches:
Index: stratagus/src/stratagus/script.c
diff -u stratagus/src/stratagus/script.c:1.165 
stratagus/src/stratagus/script.c:1.166
--- stratagus/src/stratagus/script.c:1.165      Thu Jan 22 08:03:18 2004
+++ stratagus/src/stratagus/script.c    Fri Jan 23 04:07:28 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: script.c,v 1.165 2004/01/21 21:03:18 jsalmon3 Exp $
+//      $Id: script.c,v 1.166 2004/01/22 17:07:28 nobody_ Exp $
 
 //@{
 
@@ -1113,6 +1113,30 @@
 }
 
 /**
+**     Get a value from the Stratagus syncronized random number generator.
+*/
+local int ScriptSyncRand(lua_State* l)
+{
+       if (lua_gettop(l) != 1) {
+               LuaError(l, "Wrong argument count, %d got %d expected" _C_ 
lua_gettop(l) _C_ 1);
+       }
+       lua_pushnumber(l, SyncRand() % (int)LuaToNumber(l, -1));
+       return 1;
+}
+
+/**
+**     Get a value from the Stratagus truly"" random number generator.
+*/
+local int ScriptMyRand(lua_State* l)
+{
+       if (lua_gettop(l)){
+               LuaError(l, "Wrong arguments");
+       }
+       lua_pushnumber(l, MyRand());
+       return 1;
+}
+
+/**
 **  Get a value from the big Stratagus struct.
 */
 local int ScriptStratagusGetValue(lua_State* l)
@@ -1157,6 +1181,20 @@
 }
 
 /**
+**     Initialize the main Stratagus namespace.
+*/
+local void ScriptStratagusInit(void)
+{
+       lua_pushstring(Lua, "SyncRand");
+       lua_pushcfunction(Lua, ScriptSyncRand);
+       lua_rawset(Lua, -3);
+
+       lua_pushstring(Lua, "MyRand");
+       lua_pushcfunction(Lua, ScriptMyRand);
+       lua_rawset(Lua, -3);
+}
+
+/**
 **  Initialize metatables and the main stratagus table.
 */
 local void InitScript(void)
@@ -1199,6 +1237,7 @@
        lua_setmetatable(Lua, -2);
        
        // Add all our namespaces and stuff.
+       ScriptStratagusInit();
        ScriptSpellInit();
        ScriptMissileTypesInit();
        ScriptPlayerInit();
@@ -1328,7 +1367,7 @@
        }
 
        fprintf(fd, "--- -----------------------------------------\n");
-       fprintf(fd, "--- $Id: script.c,v 1.165 2004/01/21 21:03:18 jsalmon3 Exp 
$\n");
+       fprintf(fd, "--- $Id: script.c,v 1.166 2004/01/22 17:07:28 nobody_ Exp 
$\n");
 
        fprintf(fd, "SetVideoResolution(%d, %d)\n", VideoWidth, VideoHeight);
 
@@ -1352,7 +1391,7 @@
        }
 
        fprintf(fd, "--- -----------------------------------------\n");
-       fprintf(fd, "--- $Id: script.c,v 1.165 2004/01/21 21:03:18 jsalmon3 Exp 
$\n");
+       fprintf(fd, "--- $Id: script.c,v 1.166 2004/01/22 17:07:28 nobody_ Exp 
$\n");
 
        // Global options
        if (OriginalFogOfWar) {
Index: stratagus/src/stratagus/stratagus.c
diff -u stratagus/src/stratagus/stratagus.c:1.254 
stratagus/src/stratagus/stratagus.c:1.255
--- stratagus/src/stratagus/stratagus.c:1.254   Wed Jan 21 15:57:15 2004
+++ stratagus/src/stratagus/stratagus.c Fri Jan 23 04:07:28 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: stratagus.c,v 1.254 2004/01/21 04:57:15 jsalmon3 Exp $
+//      $Id: stratagus.c,v 1.255 2004/01/22 17:07:28 nobody_ Exp $
 
 //@{
 
@@ -1092,6 +1092,9 @@
                MapName = argv[optind];
                --argc;
        }
+
+       // Init the random number generator.
+       InitSyncRand();
 
        // Init CCL and load configurations!
        InitCcl();




reply via email to

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