[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/clone ccl.c ccl_helpers.c ccl_pla...
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/clone ccl.c ccl_helpers.c ccl_pla... |
Date: |
Wed, 12 Nov 2003 15:40:27 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/11/12 15:40:26
Modified files:
src/clone : ccl.c ccl_helpers.c ccl_player.c ccl_spell.c
clone.c construct.c groups.c selection.c
spells.c unit.c unit_draw.c
Log message:
Started lua support
Patches:
Index: stratagus/src/clone/ccl.c
diff -u stratagus/src/clone/ccl.c:1.129 stratagus/src/clone/ccl.c:1.130
--- stratagus/src/clone/ccl.c:1.129 Tue Nov 11 11:34:45 2003
+++ stratagus/src/clone/ccl.c Wed Nov 12 15:40:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl.c,v 1.129 2003/11/11 16:34:45 pludov Exp $
+// $Id: ccl.c,v 1.130 2003/11/12 20:40:22 jsalmon3 Exp $
//@{
@@ -38,6 +38,7 @@
#include <string.h>
#include <stdlib.h>
#include <limits.h>
+#include <signal.h>
#include "stratagus.h"
@@ -89,6 +90,10 @@
int siod_verbose_level;
#endif
+#ifdef USE_LUA
+global lua_State* Lua;
+#endif
+
global char* CclStartFile; /// CCL start file
global char* GameName; /// Game Preferences
global int CclInConfigFile; /// True while config file parsing
@@ -119,6 +124,89 @@
-- Functions
----------------------------------------------------------------------------*/
+#ifdef USE_LUA
+local void lstop(lua_State *l, lua_Debug *ar)
+{
+ (void)ar; // unused arg.
+ lua_sethook(l, NULL, 0, 0);
+ luaL_error(l, "interrupted!");
+}
+
+local void laction(int i)
+{
+ // if another SIGINT happens before lstop,
+ // terminate process (default action)
+ signal(i, SIG_DFL);
+ lua_sethook(Lua, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
+}
+
+local void l_message(const char *pname, const char *msg)
+{
+ if (pname) {
+ fprintf(stderr, "%s: ", pname);
+ }
+ fprintf(stderr, "%s\n", msg);
+ exit(1);
+}
+
+local int report(int status)
+{
+ const char* msg;
+
+ if (status) {
+ msg = lua_tostring(Lua, -1);
+ if (msg == NULL) {
+ msg = "(error with no message)";
+ }
+ l_message(NULL, msg);
+ lua_pop(Lua, 1);
+ }
+ return status;
+}
+
+local int lcall(int narg, int clear)
+{
+ int status;
+ int base;
+
+ base = lua_gettop(Lua) - narg; /* function index */
+ lua_pushliteral(Lua, "_TRACEBACK");
+ lua_rawget(Lua, LUA_GLOBALSINDEX); /* get traceback function */
+ lua_insert(Lua, base); /* put it under chunk and args */
+ signal(SIGINT, laction);
+ status = lua_pcall(Lua, narg, (clear ? 0 : LUA_MULTRET), base);
+ signal(SIGINT, SIG_DFL);
+ lua_remove(Lua, base); /* remove traceback function */
+ return status;
+}
+
+local int docall(int status)
+{
+ if (status == 0) {
+ status = lcall(0, 1);
+ }
+ return report(status);
+}
+
+global int LuaLoadFile(const char* file)
+{
+ return docall(luaL_loadfile(Lua, file));
+}
+
+local int CclLoad(lua_State* l)
+{
+ char buf[1024];
+
+ if (lua_gettop(l) != 1 || !lua_isstring(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ LibraryFileName(lua_tostring(l, 1), buf);
+ LuaLoadFile(buf);
+ return 0;
+}
+#endif
+
/**
** Convert a SCM to a string, SCM must be a symbol or string, else 0
** is returned
@@ -128,6 +216,7 @@
** @return a string representing the SCM or 0 in case the conversion
** failed, caller must free() the returned value
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global char* CclConvertToString(SCM scm)
{
#ifdef USE_GUILE
@@ -149,6 +238,8 @@
}
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Return the type of a smob
@@ -157,6 +248,7 @@
**
** @return type id of the smob
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global ccl_smob_type_t CclGetSmobType(SCM smob)
{
#ifdef USE_GUILE
@@ -169,6 +261,8 @@
return TYPE(smob);
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Return the pointer that is stored in a smob
@@ -177,6 +271,7 @@
**
** @return pointer that was inside the smob
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global void* CclGetSmobData(SCM smob)
{
#ifdef USE_GUILE
@@ -185,6 +280,8 @@
return smob->storage_as.cons.cdr;
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Store a pointer inside a SMOB, aka convert a pointer to a SCM
@@ -192,6 +289,7 @@
** @param tag The type of the pointer/smob
** @param ptr the pointer that should be converted to a SCM
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global SCM CclMakeSmobObj(ccl_smob_type_t tag, void* ptr)
{
#ifdef USE_GUILE
@@ -206,6 +304,8 @@
return value;
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Create a tag for a new type.
@@ -214,6 +314,7 @@
**
** @return The newly generated SMOB type
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global ccl_smob_type_t CclMakeSmobType(const char* name)
{
ccl_smob_type_t new_type;
@@ -226,6 +327,8 @@
return new_type;
}
+#elif defined(USE_LUA)
+#endif
#ifdef DEBUG_GC
@@ -306,6 +409,7 @@
**
** @param obj Scheme object
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global void CclGcProtect(SCM * obj)
{
#ifdef DEBUG_GC
@@ -333,12 +437,15 @@
#endif
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Remove a SCM object from garbage collectors protection list.
**
** @param obj Scheme object
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global void CclGcUnprotect(SCM * obj)
{
#ifdef DEBUG_GC
@@ -386,7 +493,10 @@
#endif
#endif
}
+#elif defined(USE_LUA)
+#endif
+#if defined(USE_GUILE) || defined(USE_SIOD)
global void CclGcProtectedAssign(SCM* obj, SCM value)
{
if (*obj == value) {
@@ -410,6 +520,8 @@
(*obj) = value;
#endif // GC_PROTECT_VALUE
}
+#elif defined(USE_LUA)
+#endif
global void CclFlushOutput(void)
{
@@ -427,13 +539,12 @@
*/
global void CclGarbageCollect(int fast)
{
-
-#ifdef USE_GUILE
+#if defined(USE_GUILE)
if (!fast) {
// GUILE handle gc nicely by itself
scm_gc();
}
-#else
+#elif defined(USE_SIOD)
#ifdef SIOD_HEAP_GC
static int cpt=0;
@@ -456,6 +567,7 @@
default_used_cells = new_used_cells;
}
#endif
+#elif defined(USE_LUA)
#endif
}
@@ -468,20 +580,37 @@
**
** @return Current libray path.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclStratagusLibraryPath(void)
{
return gh_str02scm(StratagusLibPath);
}
+#elif defined(USE_LUA)
+local int CclStratagusLibraryPath(lua_State* l)
+{
+ lua_pushstring(l, StratagusLibPath);
+ return 1;
+}
+#endif
/**
** Return the stratagus game-cycle
**
** @return Current game cycle.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGameCycle(void)
{
return gh_int2scm(GameCycle);
}
+#elif defined(USE_LUA)
+local int CclGameCycle(lua_State* l)
+{
+ lua_pushnumber(l, GameCycle);
+ return 1;
+}
+#endif
+
/**
** Return of game name.
**
@@ -489,6 +618,7 @@
**
** @return Old game name.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGameName(SCM gamename)
{
SCM old;
@@ -507,19 +637,61 @@
}
return old;
}
+#elif defined(USE_LUA)
+local int CclSetGameName(lua_State* l)
+{
+ char* old;
+ int args;
+
+ args = lua_gettop(l);
+ if (args > 1 || (args == 1 && (!lua_isnil(l, 1) && !lua_isstring(l, 1)))) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ old = NULL;
+ if (GameName) {
+ old = strdup(GameName);
+ }
+ if (args == 1 && !lua_isnil(l, 1)) {
+ if (GameName) {
+ free(GameName);
+ GameName = NULL;
+ }
+
+ GameName = strdup(lua_tostring(l, 1));
+ }
+
+ lua_pushstring(l, old);
+ free(old);
+ return 1;
+}
+#endif
/**
** Set the stratagus game-cycle
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGameCycle(SCM cycle)
{
GameCycle = gh_scm2int(cycle);
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetGameCycle(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ GameCycle = lua_tonumber(l, 1);
+ return 0;
+}
+#endif
/**
** Set the game paused or unpaused
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGamePaused(SCM paused)
{
if (gh_boolean_p(paused)) {
@@ -529,19 +701,47 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetGamePaused(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || (!lua_isnumber(l, 1) && !lua_isboolean(l, 1))) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ if (lua_isboolean(l, 1)) {
+ GamePaused = lua_toboolean(l, 1);
+ } else {
+ GamePaused = lua_tonumber(l, 1);
+ }
+ return 0;
+}
+#endif
/**
** Set the video sync speed
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetVideoSyncSpeed(SCM speed)
{
VideoSyncSpeed = gh_scm2int(speed);
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetVideoSyncSpeed(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ VideoSyncSpeed = lua_tonumber(l, 1);
+ return 0;
+}
+#endif
/**
** Set the local player name
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetLocalPlayerName(SCM name)
{
char* str;
@@ -551,6 +751,21 @@
LocalPlayerName[sizeof(LocalPlayerName) - 1] = '\0';
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetLocalPlayerName(lua_State* l)
+{
+ const char* str;
+
+ if (lua_gettop(l) != 1 || !lua_isstring(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ str = lua_tostring(l, 1);
+ strncpy(LocalPlayerName, str, sizeof(LocalPlayerName) - 1);
+ LocalPlayerName[sizeof(LocalPlayerName) - 1] = '\0';
+ return 0;
+}
+#endif
/**
** Enable/disable Showing the tips at the start of a level.
@@ -558,6 +773,7 @@
** @param flag True = turn on, false = off.
** @return The old state of tips displayed.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetShowTips(SCM flag)
{
int old;
@@ -567,6 +783,22 @@
return gh_bool2scm(old);
}
+#elif defined(USE_LUA)
+local int CclSetShowTips(lua_State* l)
+{
+ int old;
+
+ if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ old = ShowTips;
+ ShowTips = lua_toboolean(l, 1);
+
+ lua_pushboolean(l, old);
+ return 1;
+}
+#endif
/**
** Set the current tip number.
@@ -574,6 +806,7 @@
** @param tip Tip number.
** @return The old tip number.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetCurrentTip(SCM tip)
{
int old;
@@ -586,6 +819,25 @@
return gh_int2scm(old);
}
+#elif defined(USE_LUA)
+local int CclSetCurrentTip(lua_State* l)
+{
+ lua_Number old;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ old = CurrentTip;
+ CurrentTip = lua_tonumber(l, 1);
+ if (CurrentTip >= MAX_TIPS || Tips[CurrentTip] == NULL) {
+ CurrentTip = 0;
+ }
+
+ lua_pushnumber(l, old);
+ return 1;
+}
+#endif
/**
** Add a new tip to the list of tips.
@@ -595,6 +847,7 @@
** @todo FIXME: Memory for tips is never freed.
** FIXME: Make Tips dynamic.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclAddTip(SCM tip)
{
int i;
@@ -611,6 +864,31 @@
return tip;
}
+#elif defined(USE_LUA)
+local int CclAddTip(lua_State* l)
+{
+ int i;
+ const char* str;
+
+ if (lua_gettop(l) != 1 || !lua_isstring(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ str = lua_tostring(l, 1);
+ for (i = 0; i < MAX_TIPS; ++i) {
+ if (Tips[i] && !strcmp(str, Tips[i])) {
+ break;
+ }
+ if (Tips[i] == NULL) {
+ Tips[i] = strdup(str);
+ break;
+ }
+ }
+
+ lua_pushstring(l, str);
+ return 1;
+}
+#endif
/**
** Set resource harvesting speed.
@@ -618,6 +896,7 @@
** @param resource Name of resource.
** @param speed Speed factor of harvesting resource.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedResourcesHarvest(SCM resource, SCM speed)
{
int i;
@@ -631,6 +910,29 @@
errl("Resource not found", resource);
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetSpeedResourcesHarvest(lua_State* l)
+{
+ int i;
+ const char* resource;
+
+ if (lua_gettop(l) != 2 || !lua_isstring(l, 1) || !lua_isnumber(l, 2)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ resource = lua_tostring(l, 1);
+ for (i = 0; i < MaxCosts; ++i) {
+ if (!strcmp(resource, DefaultResourceNames[i])) {
+ SpeedResourcesHarvest[i] = lua_tonumber(l, 2);
+ return 0;
+ }
+ }
+ lua_pushfstring(l, "Resource not found: %s", resource);
+ lua_error(l);
+
+ return 0;
+}
+#endif
/**
** Set resource returning speed.
@@ -638,6 +940,7 @@
** @param resource Name of resource.
** @param speed Speed factor of returning resource.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedResourcesReturn(SCM resource, SCM speed)
{
int i;
@@ -645,58 +948,136 @@
for (i = 0; i < MaxCosts; ++i) {
if (gh_eq_p(resource, gh_symbol2scm(DefaultResourceNames[i]))) {
SpeedResourcesReturn[i] = gh_scm2int(speed);
- break;
+ return SCM_UNSPECIFIED;
}
}
- if (i == MaxCosts) {
- errl("Resource not found", resource);
+ errl("Resource not found", resource);
+ return SCM_UNSPECIFIED;
+}
+#elif defined(USE_LUA)
+local int CclSetSpeedResourcesReturn(lua_State* l)
+{
+ int i;
+ const char* resource;
+
+ if (lua_gettop(l) != 2 || !lua_isstring(l, 1) || !lua_isnumber(l, 2)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
}
- return speed;
+ resource = lua_tostring(l, 1);
+ for (i = 0; i < MaxCosts; ++i) {
+ if (!strcmp(resource, DefaultResourceNames[i])) {
+ SpeedResourcesReturn[i] = lua_tonumber(l, 2);
+ return 0;
+ }
+ }
+ lua_pushfstring(l, "Resource not found: %s", resource);
+ lua_error(l);
+
+ return 0;
}
+#endif
/**
** For debug increase building speed.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedBuild(SCM speed)
{
SpeedBuild = gh_scm2int(speed);
return speed;
}
+#elif defined(USE_LUA)
+local int CclSetSpeedBuild(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ SpeedBuild = lua_tonumber(l, 1);
+
+ lua_pushnumber(l, SpeedBuild);
+ return 1;
+}
+#endif
/**
** For debug increase training speed.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedTrain(SCM speed)
{
SpeedTrain = gh_scm2int(speed);
return speed;
}
+#elif defined(USE_LUA)
+local int CclSetSpeedTrain(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ SpeedTrain = lua_tonumber(l, 1);
+
+ lua_pushnumber(l, SpeedTrain);
+ return 1;
+}
+#endif
/**
** For debug increase upgrading speed.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedUpgrade(SCM speed)
{
SpeedUpgrade = gh_scm2int(speed);
return speed;
}
+#elif defined(USE_LUA)
+local int CclSetSpeedUpgrade(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ SpeedUpgrade = lua_tonumber(l, 1);
+
+ lua_pushnumber(l, SpeedUpgrade);
+ return 1;
+}
+#endif
/**
** For debug increase researching speed.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeedResearch(SCM speed)
{
SpeedResearch = gh_scm2int(speed);
return speed;
}
+#elif defined(USE_LUA)
+local int CclSetSpeedResearch(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ SpeedResearch = lua_tonumber(l, 1);
+
+ lua_pushnumber(l, SpeedResearch);
+ return 1;
+}
+#endif
/**
** For debug increase all speeds.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSpeeds(SCM speed)
{
int i;
@@ -711,10 +1092,32 @@
return speed;
}
+#elif defined(USE_LUA)
+local int CclSetSpeeds(lua_State* l)
+{
+ int i;
+ lua_Number s;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ s = lua_tonumber(l, 1);
+ for (i = 0; i < MaxCosts; ++i) {
+ SpeedResourcesHarvest[i] = s;
+ SpeedResourcesReturn[i] = s;
+ }
+ SpeedBuild = SpeedTrain = SpeedUpgrade = SpeedResearch = s;
+
+ lua_pushnumber(l, s);
+ return 1;
+}
+#endif
/**
** Define default resources for a new player.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResources(SCM list)
{
int i;
@@ -725,10 +1128,28 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResources(lua_State* l)
+{
+ int i;
+ int args;
+
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isnumber(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResources[i] = lua_tonumber(l, i + 1);
+ }
+ return 0;
+}
+#endif
/**
** Define default resources for a new player with low resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResourcesLow(SCM list)
{
int i;
@@ -739,10 +1160,28 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResourcesLow(lua_State* l)
+{
+ int i;
+ int args;
+
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isnumber(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResourcesLow[i] = lua_tonumber(l, i + 1);
+ }
+ return 0;
+}
+#endif
/**
** Define default resources for a new player with mid resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResourcesMedium(SCM list)
{
int i;
@@ -753,10 +1192,28 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResourcesMedium(lua_State* l)
+{
+ int i;
+ int args;
+
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isnumber(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResourcesMedium[i] = lua_tonumber(l, i + 1);
+ }
+ return 0;
+}
+#endif
/**
** Define default resources for a new player with high resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResourcesHigh(SCM list)
{
int i;
@@ -767,10 +1224,28 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResourcesHigh(lua_State* l)
+{
+ int i;
+ int args;
+
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isnumber(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResourcesHigh[i] = lua_tonumber(l, i + 1);
+ }
+ return 0;
+}
+#endif
/**
** Define default incomes for a new player.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultIncomes(SCM list)
{
int i;
@@ -781,10 +1256,28 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultIncomes(lua_State* l)
+{
+ int i;
+ int args;
+
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isnumber(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultIncomes[i] = lua_tonumber(l, i + 1);
+ }
+ return 0;
+}
+#endif
/**
** Define default action for the resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultActions(SCM list)
{
int i;
@@ -799,10 +1292,32 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultActions(lua_State* l)
+{
+ int i;
+ int args;
+
+ for (i = 0; i < MaxCosts; ++i) {
+ free(DefaultActions[i]);
+ DefaultActions[i] = NULL;
+ }
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isstring(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultActions[i] = strdup(lua_tostring(l, i + 1));
+ }
+ return 0;
+}
+#endif
/**
** Define default names for the resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResourceNames(SCM list)
{
int i;
@@ -817,10 +1332,32 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResourceNames(lua_State* l)
+{
+ int i;
+ int args;
+
+ for (i = 0; i < MaxCosts; ++i) {
+ free(DefaultResourceNames[i]);
+ DefaultResourceNames[i] = NULL;
+ }
+ args = lua_gettop(l);
+ for (i = 0; i < MaxCosts && i < args; ++i) {
+ if (!lua_isstring(l, i + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResourceNames[i] = strdup(lua_tostring(l, i + 1));
+ }
+ return 0;
+}
+#endif
/**
** Define default names for the resources.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineDefaultResourceAmounts(SCM list)
{
int i;
@@ -844,10 +1381,49 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineDefaultResourceAmounts(lua_State* l)
+{
+ int i;
+ int j;
+ const char* value;
+ int args;
+
+ args = lua_gettop(l);
+ if (args & 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ for (j = 0; j < args; ++j) {
+ if (!lua_isstring(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ value = lua_tostring(l, j + 1);
+ for (i = 0; i < MaxCosts; ++i) {
+ if (!strcmp(value, DefaultResourceNames[i])) {
+ ++j;
+ if (!lua_isnumber(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DefaultResourceAmounts[i] = lua_tonumber(l, j + 1);
+ break;
+ }
+ }
+ if (i == MaxCosts) {
+ lua_pushfstring(l, "Resource not found: %s", value);
+ lua_error(l);
+ }
+ }
+ return 0;
+}
+#endif
/**
** Debug unit slots.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclUnits(void)
{
Unit** slot;
@@ -888,10 +1464,13 @@
return gh_int2scm(destroyed);
}
+#elif defined(USE_LUA)
+#endif
/**
** Compiled with sound.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclWithSound(void)
{
#ifdef WITH_SOUND
@@ -900,10 +1479,22 @@
return SCM_BOOL_F;
#endif
}
+#elif defined(USE_LUA)
+local int CclWithSound(lua_State* l)
+{
+#ifdef WITH_SOUND
+ lua_pushboolean(l, 1);
+#else
+ lua_pushboolean(l, 0);
+#endif
+ return 1;
+}
+#endif
/**
** Get Stratagus home path.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGetStratagusHomePath(void)
{
const char* cp;
@@ -919,14 +1510,40 @@
return gh_str02scm(buf);
}
+#elif defined(USE_LUA)
+local int CclGetStratagusHomePath(lua_State* l)
+{
+ const char* cp;
+ char* buf;
+
+ cp = getenv("HOME");
+ buf = alloca(strlen(cp) + strlen(GameName) + sizeof(STRATAGUS_HOME_PATH) +
3);
+ strcpy(buf, cp);
+ strcat(buf, "/");
+ strcat(buf, STRATAGUS_HOME_PATH);
+ strcat(buf, "/");
+ strcat(buf, GameName);
+
+ lua_pushstring(l, buf);
+ return 1;
+}
+#endif
/**
** Get Stratagus library path.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGetStratagusLibraryPath(void)
{
return gh_str02scm(STRATAGUS_LIB_PATH);
}
+#elif defined(USE_LUA)
+local int CclGetStratagusLibraryPath(lua_State* l)
+{
+ lua_pushstring(l, STRATAGUS_LIB_PATH);
+ return 1;
+}
+#endif
/*............................................................................
.. Tables
@@ -939,6 +1556,7 @@
**
** @return FIXME: Nothing.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclLoadPud(SCM file)
{
char* name;
@@ -951,6 +1569,8 @@
// FIXME: LoadPud should return an error
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Load a map. (Try in library path first)
@@ -959,6 +1579,7 @@
**
** @return FIXME: Nothing.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclLoadMap(SCM file)
{
char* name;
@@ -973,6 +1594,8 @@
// FIXME: LoadPud should return an error
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Define a map.
@@ -980,6 +1603,7 @@
** @param width Map width.
** @param height Map height.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineMap(SCM width, SCM height)
{
TheMap.Width = gh_scm2int(width);
@@ -994,6 +1618,8 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/*............................................................................
.. Commands
@@ -1006,6 +1632,7 @@
*/
global void CclCommand(const char* command)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
char msg[80];
#ifndef USE_GUILE
int retval;
@@ -1021,6 +1648,8 @@
DebugLevel3("\n%d=%s\n" _C_ retval _C_ msg);
#endif
SetMessage("%s", msg);
+#elif defined(USE_LUA)
+#endif
}
/*............................................................................
@@ -1032,7 +1661,7 @@
*/
global void InitCcl(void)
{
-#ifdef USE_GUILE
+#if defined(USE_GUILE)
scm_init_guile();
gh_eval_str("(display \"Guile: Enabling debugging...\\n\")"
@@ -1040,7 +1669,7 @@
"(debug-enable 'backtrace)"
"(read-enable 'positions)"
"(define *scheme* 'guile)");
-#else
+#elif defined(USE_SIOD)
char* sargv[5];
char* buf;
char msg[] = "(define *scheme* 'siod)";
@@ -1063,7 +1692,19 @@
siod_init(5, sargv);
repl_c_string(msg, 0, 0, sizeof(msg));
+#elif defined(USE_LUA)
+ Lua = lua_open();
+ luaopen_base(Lua);
+ luaopen_table(Lua);
+ luaopen_io(Lua);
+ luaopen_string(Lua);
+ luaopen_math(Lua);
+ luaopen_debug(Lua);
+ luaopen_loadlib(Lua);
+ lua_settop(Lua, 0); // discard any results
#endif
+
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedure0_0("library-path", CclStratagusLibraryPath);
gh_new_procedure0_0("game-cycle", CclGameCycle);
gh_new_procedure1_0("set-game-name!", CclSetGameName);
@@ -1092,6 +1733,38 @@
gh_new_procedureN("define-default-actions", CclDefineDefaultActions);
gh_new_procedureN("define-default-resource-names",
CclDefineDefaultResourceNames);
gh_new_procedureN("define-default-resource-amounts",
CclDefineDefaultResourceAmounts);
+#elif defined(USE_LUA)
+ lua_register(Lua, "LibraryPath", CclStratagusLibraryPath);
+ lua_register(Lua, "GameCycle", CclGameCycle);
+ lua_register(Lua, "SetGameName", CclSetGameName);
+ lua_register(Lua, "SetGameCycle", CclSetGameCycle);
+ lua_register(Lua, "SetGamePaused", CclSetGamePaused);
+ lua_register(Lua, "SetVideoSyncSpeed", CclSetVideoSyncSpeed);
+ lua_register(Lua, "SetLocalPlayerName", CclSetLocalPlayerName);
+
+ lua_register(Lua, "SetShowTips", CclSetShowTips);
+ lua_register(Lua, "SetCurrentTip", CclSetCurrentTip);
+ lua_register(Lua, "AddTip", CclAddTip);
+
+ lua_register(Lua, "SetSpeedResourcesHarvest", CclSetSpeedResourcesHarvest);
+ lua_register(Lua, "SetSpeedResourcesReturn", CclSetSpeedResourcesReturn);
+ lua_register(Lua, "SetSpeedBuild", CclSetSpeedBuild);
+ lua_register(Lua, "SetSpeedTrain", CclSetSpeedTrain);
+ lua_register(Lua, "SetSpeedUpgrade", CclSetSpeedUpgrade);
+ lua_register(Lua, "SetSpeedResearch", CclSetSpeedResearch);
+ lua_register(Lua, "SetSpeeds", CclSetSpeeds);
+
+ lua_register(Lua, "DefineDefaultResources", CclDefineDefaultResources);
+ lua_register(Lua, "DefineDefaultResourcesLow",
CclDefineDefaultResourcesLow);
+ lua_register(Lua, "DefineDefaultResourcesMedium",
CclDefineDefaultResourcesMedium);
+ lua_register(Lua, "DefineDefaultResourcesHigh",
CclDefineDefaultResourcesHigh);
+ lua_register(Lua, "DefineDefaultIncomes", CclDefineDefaultIncomes);
+ lua_register(Lua, "DefineDefaultActions", CclDefineDefaultActions);
+ lua_register(Lua, "DefineDefaultResourceNames",
CclDefineDefaultResourceNames);
+ lua_register(Lua, "DefineDefaultResourceAmounts",
CclDefineDefaultResourceAmounts);
+
+ lua_register(Lua, "Load", CclLoad);
+#endif
NetworkCclRegister();
IconCclRegister();
@@ -1120,6 +1793,7 @@
EditorCclRegister();
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedure1_0("load-pud", CclLoadPud);
gh_new_procedure1_0("load-map", CclLoadMap);
gh_new_procedure2_0("define-map", CclDefineMap);
@@ -1196,6 +1870,18 @@
#endif
print_welcome();
+#elif defined(USE_LUA)
+// lua_register(Lua, "LoadPud", CclLoadPud);
+// lua_register(Lua, "LoadMap", CclLoadMap);
+// lua_register(Lua, "DefineMap", CclDefineMap);
+
+// lua_register(Lua, "Units", CclUnits);
+
+ lua_register(Lua, "WithSound", CclWithSound);
+ lua_register(Lua, "GetStratagusHomePath", CclGetStratagusHomePath);
+ lua_register(Lua, "GetStratagusLibraryPath",
+ CclGetStratagusLibraryPath);
+#endif
}
/**
@@ -1206,16 +1892,28 @@
FILE* fd;
char buf[1024];
+#if defined(USE_GUILE) || defined(USE_SIOD)
#ifdef USE_WIN32
strcpy(buf, "preferences1.ccl");
#else
sprintf(buf, "%s/%s/preferences1.ccl", getenv("HOME"),
STRATAGUS_HOME_PATH);
#endif
+#elif defined(USE_LUA)
+#ifdef USE_WIN32
+ strcpy(buf, "preferences1.lua");
+#else
+ sprintf(buf, "%s/%s/preferences1.lua", getenv("HOME"),
STRATAGUS_HOME_PATH);
+#endif
+#endif
fd = fopen(buf, "r");
if (fd) {
fclose(fd);
+#if defined(USE_GUILE) || defined(USE_SIOD)
vload(buf, 0, 1);
+#elif defined(USE_LUA)
+ LuaLoadFile(buf);
+#endif
}
}
@@ -1227,17 +1925,30 @@
FILE* fd;
char buf[1024];
+#if defined(USE_GUILE) || defined(USE_SIOD)
#ifdef USE_WIN32
sprintf(buf, "%s/preferences2.ccl", GameName);
#else
sprintf(buf, "%s/%s/%s/preferences2.ccl", getenv("HOME"),
STRATAGUS_HOME_PATH, GameName);
#endif
+#elif defined(USE_LUA)
+#ifdef USE_WIN32
+ sprintf(buf, "%s/preferences2.lua", GameName);
+#else
+ sprintf(buf, "%s/%s/%s/preferences2.lua", getenv("HOME"),
+ STRATAGUS_HOME_PATH, GameName);
+#endif
+#endif
fd = fopen(buf, "r");
if (fd) {
fclose(fd);
+#if defined(USE_GUILE) || defined(USE_SIOD)
vload(buf, 0, 1);
+#elif defined(USE_LUA)
+ LuaLoadFile(buf);
+#endif
}
}
@@ -1254,6 +1965,7 @@
// This file is loaded before stratagus.ccl
//
+#if defined(USE_GUILE) || defined(USE_SIOD)
#ifdef USE_WIN32
strcpy(buf, "preferences1.ccl");
#else
@@ -1268,18 +1980,40 @@
}
fprintf(fd, ";;; -----------------------------------------\n");
- fprintf(fd, ";;; $Id: ccl.c,v 1.129 2003/11/11 16:34:45 pludov Exp $\n");
+ fprintf(fd, ";;; $Id: ccl.c,v 1.130 2003/11/12 20:40:22 jsalmon3 Exp $\n");
fprintf(fd, "(set-video-resolution! %d %d)\n", VideoWidth, VideoHeight);
fclose(fd);
+#elif defined(USE_LUA)
+#ifdef USE_WIN32
+ strcpy(buf, "preferences1.lua");
+#else
+ sprintf(buf, "%s/%s", getenv("HOME"), STRATAGUS_HOME_PATH);
+ mkdir(buf, 0777);
+ strcat(buf, "/preferences1.lua");
+#endif
+ fd = fopen(buf, "w");
+ if (!fd) {
+ return;
+ }
+
+ fprintf(fd, "--[[\n");
+ fprintf(fd, " $Id: ccl.c,v 1.130 2003/11/12 20:40:22 jsalmon3 Exp
$\n");
+ fprintf(fd, "]]\n");
+
+ fprintf(fd, "SetVideoResolution(%d, %d)\n", VideoWidth, VideoHeight);
+
+ fclose(fd);
+#endif
//
// preferences2.ccl
// This file is loaded after stratagus.ccl
//
+#if defined(USE_GUILE) || defined(USE_SIOD)
#ifdef USE_WIN32
sprintf(buf, "%s/preferences2.ccl", GameName);
#else
@@ -1293,7 +2027,7 @@
}
fprintf(fd, ";;; -----------------------------------------\n");
- fprintf(fd, ";;; $Id: ccl.c,v 1.129 2003/11/11 16:34:45 pludov Exp $\n");
+ fprintf(fd, ";;; $Id: ccl.c,v 1.130 2003/11/12 20:40:22 jsalmon3 Exp $\n");
// Global options
if (OriginalFogOfWar) {
@@ -1360,6 +2094,25 @@
}
#endif
#endif
+#elif defined(USE_LUA)
+#ifdef USE_WIN32
+ sprintf(buf, "%s/preferences2.lua", GameName);
+#else
+ sprintf(buf, "%s/%s/%s/preferences2.lua", getenv("HOME"),
+ STRATAGUS_HOME_PATH, GameName);
+#endif
+
+ fd = fopen(buf, "w");
+ if (!fd) {
+ return;
+ }
+
+ fprintf(fd, "--[[\n");
+ fprintf(fd, " $Id: ccl.c,v 1.130 2003/11/12 20:40:22 jsalmon3 Exp
$\n");
+ fprintf(fd, "]]\n");
+
+ fprintf(fd, "SetVideoFullscreen(%s)\n", VideoFullScreen ? "true" :
"false");
+#endif
fclose(fd);
}
@@ -1370,7 +2123,9 @@
global void LoadCcl(void)
{
char* file;
+#if defined(USE_GUILE) || defined(USE_SIOD)
char* s;
+#endif
char buf[1024];
//
@@ -1380,11 +2135,15 @@
file = LibraryFileName(CclStartFile, buf);
ShowLoadProgress("Script %s\n", file);
LoadPreferences1();
+#if defined(USE_GUILE) || defined(USE_SIOD)
if ((s = strrchr(file, '.')) && s[1] == 'C') {
fast_load(gh_str02scm(file), NIL);
} else {
vload(file, 0, 1);
}
+#elif defined(USE_LUA)
+ LuaLoadFile(file);
+#endif
LoadPreferences2();
CclInConfigFile = 0;
CclGarbageCollect(0); // Cleanup memory after load
@@ -1404,7 +2163,7 @@
extern SCM oblistvar;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: CCL $Id: ccl.c,v 1.129 2003/11/11 16:34:45
pludov Exp $\n\n");
+ CLprintf(file, ";;; MODULE: CCL $Id: ccl.c,v 1.130 2003/11/12 20:40:22
jsalmon3 Exp $\n\n");
for (list = oblistvar; gh_list_p(list); list = gh_cdr(list)) {
SCM sym;
Index: stratagus/src/clone/ccl_helpers.c
diff -u stratagus/src/clone/ccl_helpers.c:1.6
stratagus/src/clone/ccl_helpers.c:1.7
--- stratagus/src/clone/ccl_helpers.c:1.6 Mon Nov 3 06:21:38 2003
+++ stratagus/src/clone/ccl_helpers.c Wed Nov 12 15:40:23 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_helpers.c,v 1.6 2003/11/03 11:21:38 pludov Exp $
+// $Id: ccl_helpers.c,v 1.7 2003/11/12 20:40:23 jsalmon3 Exp $
//@{
@@ -43,6 +43,7 @@
#include "ai.h"
#include "ccl_helpers.h"
+#if defined(USE_GUILE) || defined(USE_SIOD)
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
@@ -82,6 +83,7 @@
local void saveData(IOFieldDef * defs, void *data)
{
unsigned int i;
+
while (defs->name) {
if (defs->convertfunc) {
IOPrintTabs();
@@ -712,3 +714,5 @@
CLprintf(IOOutFile, " %d", playerid);
}
}
+#elif defined(USE_LUA)
+#endif
Index: stratagus/src/clone/ccl_player.c
diff -u stratagus/src/clone/ccl_player.c:1.43
stratagus/src/clone/ccl_player.c:1.44
--- stratagus/src/clone/ccl_player.c:1.43 Fri Nov 7 20:08:08 2003
+++ stratagus/src/clone/ccl_player.c Wed Nov 12 15:40:23 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_player.c,v 1.43 2003/11/08 01:08:08 nehalmistry Exp $
+// $Id: ccl_player.c,v 1.44 2003/11/12 20:40:23 jsalmon3 Exp $
//@{
@@ -60,16 +60,20 @@
**
** @return The player pointer
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local Player* CclGetPlayer(SCM value)
{
return &Players[gh_scm2int(value)];
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse the player configuration.
**
** @param list Tagged list of all informations.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlayer(SCM list)
{
SCM value;
@@ -287,6 +291,8 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Change unit owner
@@ -296,6 +302,7 @@
** @param oldplayer old player number
** @param newplayer new player number
**/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclChangeUnitsOwner(SCM pos1, SCM pos2, SCM oldplayer, SCM newplayer)
{
Unit* table[UnitMax];
@@ -315,45 +322,157 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclChangeUnitsOwner(lua_State* l)
+{
+ Unit* table[UnitMax];
+ int n;
+ int oldp;
+ int newp;
+ int x1;
+ int y1;
+ int x2;
+ int y2;
+
+ if (lua_gettop(l) != 4 || !lua_istable(l, 1) || !lua_istable(l, 2) ||
+ !lua_isnumber(l, 3) || !lua_isnumber(l, 4)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ if (luaL_getn(l, 1) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, 1, 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ x1 = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+ lua_rawgeti(l, 1, 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ y1 = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+
+ if (luaL_getn(l, 2) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, 2, 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ x2 = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+ lua_rawgeti(l, 2, 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ y2 = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+
+ n = SelectUnits(x1, y1, x2, y2, table);
+ oldp = lua_tonumber(l, 3);
+ newp = lua_tonumber(l, 4);
+ while (n) {
+ if (table[n - 1]->Player->Player == oldp) {
+ ChangeUnitOwner(table[n - 1], &Players[newp]);
+ }
+ --n;
+ }
+
+ return 0;
+}
+#endif
/**
** Get ThisPlayer.
**
** @return This player number.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGetThisPlayer(void)
{
return gh_int2scm(ThisPlayer - Players);
}
+#elif defined(USE_LUA)
+local int CclGetThisPlayer(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushnumber(l, ThisPlayer - Players);
+ return 1;
+}
+#endif
/**
** Set ThisPlayer.
**
** @param plynr This player number.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetThisPlayer(SCM plynr)
{
ThisPlayer = &Players[gh_scm2int(plynr)];
return plynr;
}
+#elif defined(USE_LUA)
+local int CclSetThisPlayer(lua_State* l)
+{
+ int plynr;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ plynr = lua_tonumber(l, 1);
+ ThisPlayer = &Players[plynr];
+
+ lua_pushnumber(l, plynr);
+ return 1;
+}
+#endif
/**
** Set MaxSelectable
**
** @param Max number of selectable units.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetMaxSelectable(SCM max)
{
MaxSelectable = gh_scm2int(max);
return max;
}
+#elif defined(USE_LUA)
+local int CclSetMaxSelectable(lua_State* l)
+{
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ MaxSelectable = lua_tonumber(l, 1);
+
+ lua_pushnumber(l, MaxSelectable);
+ return 1;
+}
+#endif
/**
** Set player unit limit.
**
** @param limit Unit limit.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetAllPlayersFoodUnitLimit(SCM limit)
{
int i;
@@ -364,12 +483,30 @@
return limit;
}
+#elif defined(USE_LUA)
+local int CclSetAllPlayersFoodUnitLimit(lua_State* l)
+{
+ int i;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ for (i = 0; i < PlayerMax; ++i) {
+ Players[i].FoodUnitLimit = lua_tonumber(l, 1);
+ }
+
+ lua_pushnumber(l, lua_tonumber(l, 1));
+ return 1;
+}
+#endif
/**
** Set player unit limit.
**
** @param limit Unit limit.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetAllPlayersBuildingLimit(SCM limit)
{
int i;
@@ -380,12 +517,30 @@
return limit;
}
+#elif defined(USE_LUA)
+local int CclSetAllPlayersBuildingLimit(lua_State* l)
+{
+ int i;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ for (i = 0; i < PlayerMax; ++i) {
+ Players[i].BuildingLimit = lua_tonumber(l, 1);
+ }
+
+ lua_pushnumber(l, lua_tonumber(l, 1));
+ return 1;
+}
+#endif
/**
** Set player unit limit.
**
** @param limit Unit limit.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetAllPlayersTotalUnitLimit(SCM limit)
{
int i;
@@ -396,6 +551,23 @@
return limit;
}
+#elif defined(USE_LUA)
+local int CclSetAllPlayersTotalUnitLimit(lua_State* l)
+{
+ int i;
+
+ if (lua_gettop(l) != 1 || !lua_isnumber(l, 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ for (i = 0; i < PlayerMax; ++i) {
+ Players[i].TotalUnitLimit = lua_tonumber(l, 1);
+ }
+
+ lua_pushnumber(l, lua_tonumber(l, 1));
+ return 1;
+}
+#endif
/**
** Change the diplomacy from player to another player.
@@ -408,53 +580,57 @@
**
** @todo FIXME: should return old state.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetDiplomacy(SCM player, SCM state, SCM opponent)
{
int plynr;
+ int base;
-#if 0
- Player* base;
-
- base = CclGetPlayer(player);
+ base = gh_scm2int(player);
plynr = gh_scm2int(opponent);
if (gh_eq_p(state, gh_symbol2scm("allied"))) {
- base->Enemy &= ~(1 << plynr);
- base->Allied |= 1 << plynr;
+ SendCommandDiplomacy(base, DiplomacyAllied, plynr);
} else if (gh_eq_p(state, gh_symbol2scm("neutral"))) {
- base->Enemy &= ~(1 << plynr);
- base->Allied &= ~(1 << plynr);
+ SendCommandDiplomacy(base, DiplomacyNeutral, plynr);
} else if (gh_eq_p(state, gh_symbol2scm("crazy"))) {
- base->Enemy |= 1 << plynr;
- base->Allied |= 1 << plynr;
+ SendCommandDiplomacy(base, DiplomacyCrazy, plynr);
} else if (gh_eq_p(state, gh_symbol2scm("enemy"))) {
- base->Enemy |= 1 << plynr;
- base->Allied &= ~(1 << plynr);
+ SendCommandDiplomacy(base, DiplomacyEnemy, plynr);
}
-#else
+ // FIXME: we can return the old state
+ return SCM_UNSPECIFIED;
+}
+#elif defined(USE_LUA)
+local int CclSetDiplomacy(lua_State* l)
+{
+ int plynr;
int base;
+ const char* state;
- base = gh_scm2int(player);
- plynr = gh_scm2int(opponent);
-
- // FIXME: must send over network!!
+ if (lua_gettop(l) != 3 || !lua_isnumber(l, 1) || !lua_isstring(l, 2) ||
+ !lua_isnumber(l, 3)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ base = lua_tonumber(l, 1);
+ plynr = lua_tonumber(l, 3);
+ state = lua_tostring(l, 2);
- if (gh_eq_p(state, gh_symbol2scm("allied"))) {
+ if (!strcmp(state, "allied")) {
SendCommandDiplomacy(base, DiplomacyAllied, plynr);
- } else if (gh_eq_p(state, gh_symbol2scm("neutral"))) {
+ } else if (!strcmp(state, "neutral")) {
SendCommandDiplomacy(base, DiplomacyNeutral, plynr);
- } else if (gh_eq_p(state, gh_symbol2scm("crazy"))) {
+ } else if (!strcmp(state, "crazy")) {
SendCommandDiplomacy(base, DiplomacyCrazy, plynr);
- } else if (gh_eq_p(state, gh_symbol2scm("enemy"))) {
+ } else if (!strcmp(state, "enemy")) {
SendCommandDiplomacy(base, DiplomacyEnemy, plynr);
}
-#endif
-
- // FIXME: we can return the old state
- return SCM_UNSPECIFIED;
+ return 0;
}
+#endif
/**
** Change the diplomacy from ThisPlayer to another player.
@@ -462,10 +638,19 @@
** @param state To which state this should be changed.
** @param player Player number to change.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDiplomacy(SCM state, SCM player)
{
return CclSetDiplomacy(gh_int2scm(ThisPlayer->Player), state, player);
}
+#elif defined(USE_LUA)
+local int CclDiplomacy(lua_State* l)
+{
+ lua_pushnumber(l, ThisPlayer->Player);
+ lua_insert(l, 1);
+ return CclSetDiplomacy(l);
+}
+#endif
/**
** Change the shared vision from player to another player.
@@ -478,6 +663,7 @@
**
** @todo FIXME: should return old state.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSharedVision(SCM player, SCM state, SCM opponent)
{
int plynr;
@@ -493,6 +679,28 @@
// FIXME: we can return the old state
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSetSharedVision(lua_State* l)
+{
+ int plynr;
+ int base;
+ int shared;
+
+ if (lua_gettop(l) != 3 || !lua_isnumber(l, 1) || !lua_isboolean(l, 2) ||
+ !lua_isnumber(l, 3)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ base = lua_tonumber(l, 1);
+ shared = lua_toboolean(l, 2);
+ plynr = lua_tonumber(l, 3);
+
+ SendCommandSharedVision(base, shared, plynr);
+
+ return 0;
+}
+#endif
/**
** Change the shared vision from ThisPlayer to another player.
@@ -500,16 +708,26 @@
** @param state To which state this should be changed.
** @param player Player number to change.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSharedVision(SCM state, SCM player)
{
return CclSetSharedVision(gh_int2scm(ThisPlayer->Player), state, player);
}
+#elif defined(USE_LUA)
+local int CclSharedVision(lua_State* l)
+{
+ lua_pushnumber(l, ThisPlayer->Player);
+ lua_insert(l, 1);
+ return CclSetSharedVision(l);
+}
+#endif
/**
** Define race names
**
** @param list List of all races.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineRaceNames(SCM list)
{
SCM sublist;
@@ -554,16 +772,110 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineRaceNames(lua_State* l)
+{
+ int i;
+ int j;
+ int k;
+ int args;
+ int subargs;
+ const char* value;
+
+ PlayerRaces.Count = 0;
+ args = lua_gettop(l);
+ for (j = 0; j < args; ++j) {
+ if (!lua_isstring(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ value = lua_tostring(l, j + 1);
+ if (!strcmp(value, "race")) {
+ ++j;
+ if (!lua_istable(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ subargs = luaL_getn(l, j + 1);
+ i = PlayerRaces.Count++;
+ PlayerRaces.Race[i] = 0;
+ PlayerRaces.Name[i] = NULL;
+ PlayerRaces.Display[i] = NULL;
+ PlayerRaces.Visible[i] = 0;
+ for (k = 0; k < subargs; ++k) {
+ lua_rawgeti(l, j + 1, k + 1);
+ if (!lua_isstring(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ value = lua_tostring(l, -1);
+ lua_pop(l, 1);
+ if (!strcmp(value, "race")) {
+ ++k;
+ lua_rawgeti(l, j + 1, k + 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ PlayerRaces.Race[i] = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+ } else if (!strcmp(value, "name")) {
+ ++k;
+ lua_rawgeti(l, j + 1, k + 1);
+ if (!lua_isstring(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ PlayerRaces.Name[i] = strdup(lua_tostring(l, -1));
+ lua_pop(l, 1);
+ } else if (!strcmp(value, "display")) {
+ ++k;
+ lua_rawgeti(l, j + 1, k + 1);
+ if (!lua_isstring(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ PlayerRaces.Display[i] = strdup(lua_tostring(l, -1));
+ lua_pop(l, 1);
+ } else if (!strcmp(value, "visible")) {
+ PlayerRaces.Visible[i] = 1;
+ } else {
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
+ }
+ }
+ } else {
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
+ }
+ }
+
+ return 0;
+}
+#endif
/**
** Make new player colors
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclNewPlayerColors(void)
{
SetPlayersPalette();
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclNewPlayerColors(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ SetPlayersPalette();
+
+ return 0;
+}
+#endif
// ----------------------------------------------------------------------------
@@ -575,6 +887,7 @@
**
** @return Player resource
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGetPlayerResource(SCM player, SCM resource)
{
int i;
@@ -598,12 +911,15 @@
free(res);
return ret;
}
+#elif defined(USE_LUA)
+#endif
/**
** Set player resource.
**
** @param list Resource list
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetPlayerResource(SCM list)
{
int i;
@@ -630,6 +946,8 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
// ----------------------------------------------------------------------------
@@ -638,6 +956,7 @@
*/
global void PlayerCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("player", CclPlayer);
gh_new_procedure4_0("change-units-owner", CclChangeUnitsOwner);
gh_new_procedure0_0("get-this-player", CclGetThisPlayer);
@@ -664,6 +983,34 @@
// player member access functions
gh_new_procedure2_0("get-player-resource", CclGetPlayerResource);
gh_new_procedureN("set-player-resource!", CclSetPlayerResource);
+#elif defined(USE_LUA)
+// lua_register(Lua, "Player", CclPlayer);
+ lua_register(Lua, "ChangeUnitsOwner", CclChangeUnitsOwner);
+ lua_register(Lua, "GetThisPlayer", CclGetThisPlayer);
+ lua_register(Lua, "SetThisPlayer", CclSetThisPlayer);
+
+ lua_register(Lua, "SetMaxSelectable", CclSetMaxSelectable);
+
+ lua_register(Lua, "SetAllPlayersFoodUnitLimit",
+ CclSetAllPlayersFoodUnitLimit);
+ lua_register(Lua, "SetAllPlayersBuildingLimit",
+ CclSetAllPlayersBuildingLimit);
+ lua_register(Lua, "SetAllPlayersTotalUnitLimit",
+ CclSetAllPlayersTotalUnitLimit);
+
+ lua_register(Lua, "SetDiplomacy", CclSetDiplomacy);
+ lua_register(Lua, "Diplomacy", CclDiplomacy);
+ lua_register(Lua, "SetSharedVision", CclSetSharedVision);
+ lua_register(Lua, "SharedVision", CclSharedVision);
+
+ lua_register(Lua, "DefineRaceNames", CclDefineRaceNames);
+
+ lua_register(Lua, "NewColors", CclNewPlayerColors);
+
+ // player member access functions
+// lua_register(Lua, "GetPlayerResource", CclGetPlayerResource);
+// lua_register(Lua, "SetPlayerResource", CclSetPlayerResource);
+#endif
}
//@}
Index: stratagus/src/clone/ccl_spell.c
diff -u stratagus/src/clone/ccl_spell.c:1.24
stratagus/src/clone/ccl_spell.c:1.25
--- stratagus/src/clone/ccl_spell.c:1.24 Tue Oct 28 20:55:32 2003
+++ stratagus/src/clone/ccl_spell.c Wed Nov 12 15:40:23 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_spell.c,v 1.24 2003/10/29 01:55:32 n0body Exp $
+// $Id: ccl_spell.c,v 1.25 2003/11/12 20:40:23 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
@@ -60,6 +60,7 @@
** @note This is only here to avoid code duplication. You don't have
** any reason to USE this:)
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void CclSpellMissileLocation(SCM list, SpellActionMissileLocation*
location)
{
SCM value;
@@ -97,6 +98,8 @@
}
}
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse the action for spell.
@@ -104,6 +107,7 @@
** @param list SCM list object, with something like
(action-type params).
** @param spellaction Pointer to spellactopm.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void CclSpellAction(SCM list, SpellActionType* spellaction)
{
char* str;
@@ -306,6 +310,8 @@
errl("Unsupported action type", value);
}
}
+#elif defined(USE_LUA)
+#endif
/**
** Get a condition value from a scm object.
@@ -316,6 +322,7 @@
** @note This is a helper function to make CclSpellCondition shorter
** and easier to understand.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global char Scm2Condition(SCM value)
{
if (gh_eq_p(value, gh_symbol2scm("true"))) {
@@ -329,6 +336,8 @@
return -1;
}
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse the Condition for spell.
@@ -338,6 +347,7 @@
**
** @notes: conditions must be allocated. All data already in is LOST.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void CclSpellCondition(SCM list, ConditionInfo* condition)
{
SCM value;
@@ -420,6 +430,8 @@
}
}
}
+#elif defined(USE_LUA)
+#endif
/*
** Parse the Condition for spell.
@@ -429,6 +441,7 @@
**
** @notes: autocast must be allocated. All data already in is LOST.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void CclSpellAutocast(SCM list, AutoCastInfo* autocast)
{
SCM value;
@@ -456,12 +469,15 @@
}
}
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse Spell.
**
** @param list List describing Spell.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineSpell(SCM list)
{
char* identname;
@@ -587,13 +603,17 @@
}
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for Spell.
*/
global void SpellCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("define-spell", CclDefineSpell);
+#endif
}
/*
Index: stratagus/src/clone/clone.c
diff -u stratagus/src/clone/clone.c:1.223 stratagus/src/clone/clone.c:1.224
--- stratagus/src/clone/clone.c:1.223 Tue Nov 11 07:43:09 2003
+++ stratagus/src/clone/clone.c Wed Nov 12 15:40:24 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: clone.c,v 1.223 2003/11/11 12:43:09 pludov Exp $
+// $Id: clone.c,v 1.224 2003/11/12 20:40:24 jsalmon3 Exp $
//@{
@@ -227,7 +227,10 @@
#include "pathfinder.h"
#ifdef DEBUG
+#if defined(USE_GUILE) || defined(USE_SIOD)
extern SCM CclUnits(void);
+#elif defined(USE_LUA)
+#endif
#endif
/*----------------------------------------------------------------------------
@@ -1321,9 +1324,14 @@
FrameCounter _C_ SlowFrameCounter _C_
(SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1));
UnitCacheStatistic();
+#if defined(USE_GUILE) || defined(USE_SIOD)
CclUnits();
+#endif
CleanModules();
CleanFonts();
+#ifdef USE_LUA
+ lua_close(Lua);
+#endif
#endif
CleanMovie();
@@ -1398,8 +1406,13 @@
#ifndef __APPLE__
StratagusLibPath = STRATAGUS_LIB_PATH;
#endif
+#ifndef USE_LUA
CclStartFile = "ccl/stratagus.ccl";
EditorStartFile = "ccl/editor.ccl";
+#else
+ CclStartFile = "ccl/stratagus.lua";
+ EditorStartFile = "ccl/editor.lua";
+#endif
memset(LocalPlayerName, 0, 16);
strcpy(LocalPlayerName, "Anonymous");
Index: stratagus/src/clone/construct.c
diff -u stratagus/src/clone/construct.c:1.37
stratagus/src/clone/construct.c:1.38
--- stratagus/src/clone/construct.c:1.37 Wed Oct 22 14:02:33 2003
+++ stratagus/src/clone/construct.c Wed Nov 12 15:40:24 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: construct.c,v 1.37 2003/10/22 18:02:33 jsalmon3 Exp $
+// $Id: construct.c,v 1.38 2003/11/12 20:40:24 jsalmon3 Exp $
//@{
@@ -147,7 +147,7 @@
ConstructionFrame* cframe;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: constructions $Id: construct.c,v 1.37
2003/10/22 18:02:33 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: constructions $Id: construct.c,v 1.38
2003/11/12 20:40:24 jsalmon3 Exp $\n\n");
// FIXME: needed?
@@ -313,6 +313,7 @@
**
** @param list List of all names.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineConstructionWcNames(SCM list)
{
int i;
@@ -338,6 +339,42 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineConstructionWcNames(lua_State* l)
+{
+ int i;
+ int j;
+ char** cp;
+
+ if ((cp = ConstructionWcNames)) { // Free all old names
+ while (*cp) {
+ free(*cp++);
+ }
+ free(ConstructionWcNames);
+ }
+
+ //
+ // Get new table.
+ //
+ i = lua_gettop(l);
+ ConstructionWcNames = cp = malloc((i + 1) * sizeof(char*));
+ if (!cp) {
+ fprintf(stderr, "out of memory.\n");
+ ExitFatal(-1);
+ }
+
+ for (j = 0; j < i; ++j) {
+ if (!lua_isstring(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ *cp++ = strdup(lua_tostring(l, j + 1));
+ }
+ *cp = NULL;
+
+ return 0;
+}
+#endif
/**
** Parse the construction.
@@ -346,6 +383,7 @@
**
** @note make this more flexible
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineConstruction(SCM list)
{
SCM value;
@@ -506,6 +544,8 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
// ----------------------------------------------------------------------------
@@ -514,9 +554,14 @@
*/
global void ConstructionCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("define-construction-wc-names",
CclDefineConstructionWcNames);
gh_new_procedureN("define-construction", CclDefineConstruction);
-
+#elif defined(USE_LUA)
+ lua_register(Lua, "DefineConstructionWcNames",
+ CclDefineConstructionWcNames);
+// lua_register(Lua, "DefineConstruction", CclDefineConstruction);
+#endif
}
//@}
Index: stratagus/src/clone/groups.c
diff -u stratagus/src/clone/groups.c:1.25 stratagus/src/clone/groups.c:1.26
--- stratagus/src/clone/groups.c:1.25 Fri Nov 7 20:08:08 2003
+++ stratagus/src/clone/groups.c Wed Nov 12 15:40:24 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: groups.c,v 1.25 2003/11/08 01:08:08 nehalmistry Exp $
+// $Id: groups.c,v 1.26 2003/11/12 20:40:24 jsalmon3 Exp $
//@{
@@ -95,7 +95,7 @@
char* ref;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: groups $Id: groups.c,v 1.25 2003/11/08
01:08:08 nehalmistry Exp $\n\n");
+ CLprintf(file, ";;; MODULE: groups $Id: groups.c,v 1.26 2003/11/12
20:40:24 jsalmon3 Exp $\n\n");
for (g = 0; g < NUM_GROUPS; ++g) {
CLprintf(file, "(group %d %d '(", g, Groups[g].NumUnits);
@@ -239,6 +239,7 @@
** @param num Number of units in group
** @param units Units in group
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclGroup(SCM group, SCM num, SCM units)
{
int i;
@@ -258,13 +259,17 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for groups.
*/
global void GroupCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedure3_0("group", CclGroup);
+#endif
}
//@}
Index: stratagus/src/clone/selection.c
diff -u stratagus/src/clone/selection.c:1.58
stratagus/src/clone/selection.c:1.59
--- stratagus/src/clone/selection.c:1.58 Sun Nov 9 16:19:12 2003
+++ stratagus/src/clone/selection.c Wed Nov 12 15:40:24 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: selection.c,v 1.58 2003/11/09 21:19:12 mr-russ Exp $
+// $Id: selection.c,v 1.59 2003/11/12 20:40:24 jsalmon3 Exp $
//@{
@@ -978,7 +978,7 @@
char* ref;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: selection $Id: selection.c,v 1.58 2003/11/09
21:19:12 mr-russ Exp $\n\n");
+ CLprintf(file, ";;; MODULE: selection $Id: selection.c,v 1.59 2003/11/12
20:40:24 jsalmon3 Exp $\n\n");
CLprintf(file, "(set-group-id! %d)\n", GroupId);
CLprintf(file, "(selection %d '(", NumSelected);
@@ -1010,6 +1010,7 @@
** @param id New group identifier
** @return old value
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGroupId(SCM id)
{
SCM old;
@@ -1019,6 +1020,8 @@
return old;
}
+#elif defined(USE_LUA)
+#endif
/**
** Define the current selection.
@@ -1026,6 +1029,7 @@
** @param num Number of units in selection
** @param units Units in selection
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSelection(SCM num, SCM units)
{
int i;
@@ -1044,14 +1048,18 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for selections.
*/
global void SelectionCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedure1_0("set-group-id!", CclSetGroupId);
gh_new_procedure2_0("selection", CclSelection);
+#endif
}
//@}
Index: stratagus/src/clone/spells.c
diff -u stratagus/src/clone/spells.c:1.124 stratagus/src/clone/spells.c:1.125
--- stratagus/src/clone/spells.c:1.124 Tue Nov 11 03:40:20 2003
+++ stratagus/src/clone/spells.c Wed Nov 12 15:40:25 2003
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: spells.c,v 1.124 2003/11/11 08:40:20 n0body Exp $
+// $Id: spells.c,v 1.125 2003/11/12 20:40:25 jsalmon3 Exp $
/*
** And when we cast our final spell
@@ -1033,6 +1033,7 @@
/**
** FIXME: docu
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global unsigned CclGetSpellByIdent(SCM value)
{
int i;
@@ -1044,6 +1045,8 @@
}
return -1;
}
+#elif defined(USE_LUA)
+#endif
/**
** Get spell-type struct ptr by id
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.334 stratagus/src/clone/unit.c:1.335
--- stratagus/src/clone/unit.c:1.334 Tue Nov 11 04:57:32 2003
+++ stratagus/src/clone/unit.c Wed Nov 12 15:40:25 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.334 2003/11/11 09:57:32 mr-russ Exp $
+// $Id: unit.c,v 1.335 2003/11/12 20:40:25 jsalmon3 Exp $
//@{
@@ -354,6 +354,7 @@
// FIXME: this is not needed for load+save, must move to other place
if (1) { // Call CCL for name generation
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM fun;
fun = gh_symbol2scm("gen-unit-name");
@@ -366,6 +367,8 @@
unit->Name = gh_scm2newstr(value, NULL);
}
}
+#elif defined(USE_LUA)
+#endif
}
unit->Frame = unit->Type->Animations->Still[0].Frame +
@@ -3848,7 +3851,7 @@
int RunStart;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.334 2003/11/11 09:57:32
mr-russ Exp $\n\n");
+ CLprintf(file, ";;; MODULE: units $Id: unit.c,v 1.335 2003/11/12 20:40:25
jsalmon3 Exp $\n\n");
//
// Local variables
Index: stratagus/src/clone/unit_draw.c
diff -u stratagus/src/clone/unit_draw.c:1.179
stratagus/src/clone/unit_draw.c:1.180
--- stratagus/src/clone/unit_draw.c:1.179 Tue Nov 11 04:24:02 2003
+++ stratagus/src/clone/unit_draw.c Wed Nov 12 15:40:26 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_draw.c,v 1.179 2003/11/11 09:24:02 n0body Exp $
+// $Id: unit_draw.c,v 1.180 2003/11/12 20:40:26 jsalmon3 Exp $
//@{
@@ -311,7 +311,8 @@
** @param w Mana width.
** @param h Mana height.
*/
-global SCM CclManaSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
+#if defined(USE_GUILE) || defined(USE_SIOD)
+local SCM CclManaSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
{
free(ManaSprite.File);
@@ -323,6 +324,25 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclManaSprite(lua_State* l)
+{
+ if (lua_gettop(l) != 5 || !lua_isstring(l, 1) || !lua_isnumber(l, 2) ||
+ !lua_isnumber(l, 3) || !lua_isnumber(l, 4) || !lua_isnumber(l, 5)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ free(ManaSprite.File);
+
+ ManaSprite.File = strdup(lua_tostring(l, 1));
+ ManaSprite.HotX = lua_tonumber(l, 2);
+ ManaSprite.HotY = lua_tonumber(l, 3);
+ ManaSprite.Width = lua_tonumber(l, 4);
+ ManaSprite.Height = lua_tonumber(l, 5);
+
+ return 0;
+}
+#endif
/**
** Define health sprite.
@@ -333,7 +353,8 @@
** @param w Health width.
** @param h Health height.
*/
-global SCM CclHealthSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
+#if defined(USE_GUILE) || defined(USE_SIOD)
+local SCM CclHealthSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
{
free(HealthSprite.File);
@@ -345,9 +366,28 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclHealthSprite(lua_State* l)
+{
+ if (lua_gettop(l) != 5 || !lua_isstring(l, 1) || !lua_isnumber(l, 2) ||
+ !lua_isnumber(l, 3) || !lua_isnumber(l, 4) || !lua_isnumber(l, 5)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ free(ManaSprite.File);
+
+ HealthSprite.File = strdup(lua_tostring(l, 1));
+ HealthSprite.HotX = lua_tonumber(l, 2);
+ HealthSprite.HotY = lua_tonumber(l, 3);
+ HealthSprite.Width = lua_tonumber(l, 4);
+ HealthSprite.Height = lua_tonumber(l, 5);
+
+ return 0;
+}
+#endif
/**
-** Define health sprite.
+** Define shadow sprite.
**
** @param file Shadow graphic file.
** @param x Shadow X position.
@@ -355,7 +395,8 @@
** @param w Shadow width.
** @param h Shadow height.
*/
-global SCM CclShadowSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
+#if defined(USE_GUILE) || defined(USE_SIOD)
+local SCM CclShadowSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
{
free(ShadowSprite.File);
@@ -367,9 +408,28 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShadowSprite(lua_State* l)
+{
+ if (lua_gettop(l) != 5 || !lua_isstring(l, 1) || !lua_isnumber(l, 2) ||
+ !lua_isnumber(l, 3) || !lua_isnumber(l, 4) || !lua_isnumber(l, 5)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ free(ManaSprite.File);
+
+ ShadowSprite.File = strdup(lua_tostring(l, 1));
+ ShadowSprite.HotX = lua_tonumber(l, 2);
+ ShadowSprite.HotY = lua_tonumber(l, 3);
+ ShadowSprite.Width = lua_tonumber(l, 4);
+ ShadowSprite.Height = lua_tonumber(l, 5);
+
+ return 0;
+}
+#endif
/**
-** Define health sprite.
+** Define spell sprite.
**
** @param file Spell graphic file.
** @param x Spell X position.
@@ -377,7 +437,8 @@
** @param w Spell width.
** @param h Spell height.
*/
-global SCM CclSpellSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
+#if defined(USE_GUILE) || defined(USE_SIOD)
+local SCM CclSpellSprite(SCM file, SCM x, SCM y, SCM w, SCM h)
{
free(SpellSprite.File);
@@ -389,10 +450,30 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclSpellSprite(lua_State* l)
+{
+ if (lua_gettop(l) != 5 || !lua_isstring(l, 1) || !lua_isnumber(l, 2) ||
+ !lua_isnumber(l, 3) || !lua_isnumber(l, 4) || !lua_isnumber(l, 5)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ free(ManaSprite.File);
+
+ SpellSprite.File = strdup(lua_tostring(l, 1));
+ SpellSprite.HotX = lua_tonumber(l, 2);
+ SpellSprite.HotY = lua_tonumber(l, 3);
+ SpellSprite.Width = lua_tonumber(l, 4);
+ SpellSprite.Height = lua_tonumber(l, 5);
+
+ return 0;
+}
+#endif
/**
** Enable display health as health-bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowHealthBar(void)
{
ShowHealthBar = 1;
@@ -400,10 +481,24 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowHealthBar(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowHealthBar = 1;
+ ShowHealthDot = 0;
+
+ return 0;
+}
+#endif
/**
** Enable display health as health-dot.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowHealthDot(void)
{
ShowHealthBar = 0;
@@ -411,10 +506,24 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowHealthDot(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowHealthBar = 0;
+ ShowHealthDot = 1;
+
+ return 0;
+}
+#endif
/**
** Enable display health as horizontal bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowHealthHorizontal(void)
{
ShowHealthBar = 1;
@@ -423,10 +532,25 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowHealthHorizontal(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowHealthBar = 1;
+ ShowHealthDot = 0;
+ ShowHealthHorizontal = 1;
+
+ return 0;
+}
+#endif
/**
** Enable display health as vertical bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowHealthVertical(void)
{
ShowHealthBar = 1;
@@ -435,10 +559,25 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowHealthVertical(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowHealthBar = 1;
+ ShowHealthDot = 0;
+ ShowHealthHorizontal = 0;
+
+ return 0;
+}
+#endif
/**
** Enable display mana as mana-bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowManaBar(void)
{
ShowManaBar = 1;
@@ -446,10 +585,24 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowManaBar(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowManaBar = 1;
+ ShowManaDot = 0;
+
+ return 0;
+}
+#endif
/**
** Enable display mana as mana-dot.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowManaDot(void)
{
ShowManaBar = 0;
@@ -457,31 +610,71 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowManaDot(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowManaBar = 0;
+ ShowManaDot = 1;
+
+ return 0;
+}
+#endif
/**
** Enable energy bars and dots only for selected units
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowEnergySelected(void)
{
ShowEnergySelectedOnly = 1;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowEnergySelected(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowEnergySelectedOnly = 1;
+
+ return 0;
+}
+#endif
/**
** Enable display of full bars/dots.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowFull(void)
{
ShowNoFull = 0;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowFull(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowNoFull = 0;
+
+ return 0;
+}
+#endif
/**
** Enable display mana as horizontal bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowManaHorizontal(void)
{
ShowManaBar = 1;
@@ -490,10 +683,25 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowManaHorizontal(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowManaBar = 1;
+ ShowManaDot = 0;
+ ShowManaHorizontal = 1;
+
+ return 0;
+}
+#endif
/**
** Enable display mana as vertical bar.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowManaVertical(void)
{
ShowManaBar = 1;
@@ -502,32 +710,73 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowManaVertical(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowManaBar = 1;
+ ShowManaDot = 0;
+ ShowManaHorizontal = 0;
+
+ return 0;
+}
+#endif
/**
** Disable display of full bars/dots.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclShowNoFull(void)
{
ShowNoFull = 1;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclShowNoFull(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ ShowNoFull = 1;
+
+ return 0;
+}
+#endif
/**
** Draw decorations always on top.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDecorationOnTop(void)
{
DecorationOnTop = 1;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDecorationOnTop(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ DecorationOnTop = 1;
+
+ return 0;
+}
+#endif
/**
** Register CCL features for decorations.
*/
global void DecorationCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedure5_0("mana-sprite", CclManaSprite);
gh_new_procedure5_0("health-sprite", CclHealthSprite);
gh_new_procedure5_0("shadow-sprite", CclShadowSprite);
@@ -548,6 +797,28 @@
gh_new_procedure0_0("show-full", CclShowFull);
gh_new_procedure0_0("show-no-full", CclShowNoFull);
gh_new_procedure0_0("decoration-on-top", CclDecorationOnTop);
+#elif defined(USE_LUA)
+ lua_register(Lua, "ManaSprite", CclManaSprite);
+ lua_register(Lua, "HealthSprite", CclHealthSprite);
+ lua_register(Lua, "ShadowSprite", CclShadowSprite);
+ lua_register(Lua, "SpellSprite", CclSpellSprite);
+
+ lua_register(Lua, "ShowHealthBar", CclShowHealthBar);
+ lua_register(Lua, "ShowHealthDot", CclShowHealthDot);
+// adicionado por protoman
+ lua_register(Lua, "ShowHealthVertical", CclShowHealthVertical);
+ lua_register(Lua, "ShowHealthHorizontal", CclShowHealthHorizontal);
+ lua_register(Lua, "ShowManaVertical", CclShowManaVertical);
+ lua_register(Lua, "ShowManaHorizontal", CclShowManaHorizontal);
+// fim
+
+ lua_register(Lua, "ShowManaBar", CclShowManaBar);
+ lua_register(Lua, "ShowManaDot", CclShowManaDot);
+ lua_register(Lua, "ShowEnergySelectedOnly", CclShowEnergySelected);
+ lua_register(Lua, "ShowFull", CclShowFull);
+ lua_register(Lua, "ShowNoFull", CclShowNoFull);
+ lua_register(Lua, "DecorationOnTop", CclDecorationOnTop);
+#endif
}
/**
@@ -583,7 +854,7 @@
global void SaveDecorations(CLFile* file)
{
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.179
2003/11/11 09:24:02 n0body Exp $\n\n");
+ CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.180
2003/11/12 20:40:26 jsalmon3 Exp $\n\n");
CLprintf(file, "(mana-sprite \"%s\" %d %d %d %d)\n",
ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/clone ccl.c ccl_helpers.c ccl_pla...,
Jimmy Salmon <=