[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src game/trigger.c include/trigger.h
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src game/trigger.c include/trigger.h |
Date: |
Tue, 02 Dec 2003 00:39:13 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/12/02 00:39:13
Modified files:
src/game : trigger.c
src/include : trigger.h
Log message:
Started adding lua support for triggers
Patches:
Index: stratagus/src/game/trigger.c
diff -u stratagus/src/game/trigger.c:1.47 stratagus/src/game/trigger.c:1.48
--- stratagus/src/game/trigger.c:1.47 Sun Nov 16 01:49:26 2003
+++ stratagus/src/game/trigger.c Tue Dec 2 00:39:13 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: trigger.c,v 1.47 2003/11/16 06:49:26 mr-russ Exp $
+// $Id: trigger.c,v 1.48 2003/12/02 05:39:13 jsalmon3 Exp $
//@{
@@ -55,6 +55,7 @@
#if defined(USE_GUILE) || defined(USE_SIOD)
extern UnitType* CclGetUnitType(SCM ptr);
#elif defined(USE_LUA)
+extern UnitType* CclGetUnitType(lua_State* l);
#endif
#define MAX_SWITCH 256 /// Maximum number of switches
@@ -108,6 +109,32 @@
return 0;
}
+#elif defined(USE_LUA)
+global int TriggerGetPlayer(lua_State* l)
+{
+ const char* player;
+ int ret;
+
+ if (lua_isnumber(l, -1)) {
+ ret = LuaToNumber(l, -1);
+ if (ret < 0 || ret > PlayerMax) {
+ lua_pushfstring(l, "bad player: %d", ret);
+ lua_error(l);
+ }
+ return ret;
+ }
+ player = LuaToString(l, -1);
+ if (!strcmp(player, "any")) {
+ return -1;
+ } else if (!strcmp(player, "this")) {
+ return ThisPlayer->Player;
+ }
+ lua_pushfstring(l, "bad player: %s", player);
+ lua_error(l);
+
+ return 0;
+}
+#endif
/**
** Get the unit-type.
@@ -116,6 +143,7 @@
**
** @return The unit-type pointer.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global const UnitType* TriggerGetUnitType(SCM unit)
{
if (gh_eq_p(unit, gh_symbol2scm("any"))) {
@@ -131,6 +159,23 @@
return CclGetUnitType(unit);
}
#elif defined(USE_LUA)
+global const UnitType* TriggerGetUnitType(lua_State* l)
+{
+ const char* unit;
+
+ unit = LuaToString(l, -1);
+ if (!strcmp(unit, "any")) {
+ return ANY_UNIT;
+ } else if (!strcmp(unit, "all")) {
+ return ALL_UNITS;
+ } else if (!strcmp(unit, "units")) {
+ return ALL_FOODUNITS;
+ } else if (!strcmp(unit, "buildings")) {
+ return ALL_BUILDINGS;
+ }
+
+ return CclGetUnitType(l);
+}
#endif
// --------------------------------------------------------------------------
@@ -170,6 +215,7 @@
**
** @return Function pointer to the compare function
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local CompareFunction GetCompareFunction(const char* op)
{
if (op[0] == '=') {
@@ -193,6 +239,8 @@
}
return NULL;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has the quantity of unit-type.
@@ -263,12 +311,15 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has the quantity of unit-type at a location.
**
** (if-unit-at {player} {op} {quantity} {unit} {location} {location})
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfUnitAt(SCM list)
{
int plynr;
@@ -340,10 +391,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has the quantity of unit-type near to unit-type.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfNearUnit(SCM player, SCM operation, SCM quantity, SCM unit,
SCM nearunit)
{
@@ -432,10 +486,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has the quantity of rescued unit-type near to unit-type.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfRescuedNearUnit(SCM player, SCM operation, SCM quantity, SCM
unit,
SCM nearunit)
{
@@ -526,10 +583,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has n opponents left.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfOpponents(SCM player, SCM operation, SCM quantity)
{
int plynr;
@@ -577,10 +637,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has the quantity of resource.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfResource(SCM player, SCM operation, SCM quantity, SCM resource)
{
int plynr;
@@ -645,10 +708,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has quantity kills
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfKills(SCM player, SCM operation, SCM quantity)
{
int plynr;
@@ -682,10 +748,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Player has a certain score
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfScore(SCM player, SCM operation, SCM quantity)
{
int plynr;
@@ -719,10 +788,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Number of game cycles elapsed
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfElapsed(SCM operation, SCM quantity)
{
int q;
@@ -743,10 +815,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Check the timer value
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfTimer(SCM operation, SCM quantity)
{
int q;
@@ -771,10 +846,13 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Check the switch value
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfSwitch(SCM number, SCM set)
{
int i;
@@ -799,6 +877,8 @@
}
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
// --------------------------------------------------------------------------
// Actions
@@ -806,6 +886,7 @@
/**
** Action condition player wins.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionVictory(void)
{
GameResult = GameVictory;
@@ -813,10 +894,25 @@
GameRunning = 0;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionVictory(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameResult = GameVictory;
+ GamePaused = 1;
+ GameRunning = 0;
+ return 0;
+}
+#endif
/**
** Action condition player lose.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionDefeat(void)
{
GameResult = GameDefeat;
@@ -824,10 +920,25 @@
GameRunning = 0;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionDefeat(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameResult = GameDefeat;
+ GamePaused = 1;
+ GameRunning = 0;
+ return 0;
+}
+#endif
/**
** Action condition player draw.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionDraw(void)
{
GameResult = GameDraw;
@@ -835,10 +946,25 @@
GameRunning = 0;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionDraw(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameResult = GameDraw;
+ GamePaused = 1;
+ GameRunning = 0;
+ return 0;
+}
+#endif
/**
** Action set timer
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionSetTimer(SCM cycles, SCM increasing)
{
GameTimer.Cycles = gh_scm2int(cycles);
@@ -848,39 +974,97 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionSetTimer(lua_State* l)
+{
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameTimer.Cycles = LuaToNumber(l, 1);
+ GameTimer.Increasing = LuaToNumber(l, 2);
+ GameTimer.Init = 1;
+ GameTimer.LastUpdate = GameCycle;
+
+ return 0;
+}
+#endif
/**
** Action start timer
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionStartTimer(void)
{
GameTimer.Running = 1;
GameTimer.Init = 1;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionStartTimer(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameTimer.Running = 1;
+ GameTimer.Init = 1;
+ return 0;
+}
+#endif
/**
** Action stop timer
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionStopTimer(void)
{
GameTimer.Running = 0;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionStopTimer(lua_State* l)
+{
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ GameTimer.Running = 0;
+ return 0;
+}
+#endif
/**
** Action wait
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionWait(SCM ms)
{
WaitFrame = FrameCounter +
(FRAMES_PER_SECOND * VideoSyncSpeed / 100 * gh_scm2int(ms) + 999) /
1000;
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclActionWait(lua_State* l)
+{
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ WaitFrame = FrameCounter +
+ (FRAMES_PER_SECOND * VideoSyncSpeed / 100 * (int)LuaToNumber(l, 1) +
999) / 1000;
+ return 0;
+}
+#endif
/**
** Action stop timer
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclActionSetSwitch(SCM number, SCM set)
{
int i;
@@ -903,10 +1087,42 @@
Switch[i] = s;
return set;
}
+#elif defined(USE_LUA)
+local int CclActionSetSwitch(lua_State* l)
+{
+ int i;
+ unsigned char s;
+
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+
+ i = LuaToNumber(l, 1);
+ if (i < 0 || i >= MAX_SWITCH) {
+ lua_pushfstring(l, "Invalid switch number: %d", i);
+ lua_error(l);
+ }
+
+ if (lua_isboolean(l, 2)) {
+ s = LuaToBoolean(l, 2);
+ } else {
+ s = LuaToNumber(l, 2);
+ if (s) {
+ s = 1;
+ }
+ }
+
+ Switch[i] = s;
+ lua_pushvalue(l, 2);
+ return 1;
+}
+#endif
/**
** Add a trigger.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclAddTrigger(SCM condition, SCM action)
{
SCM var;
@@ -931,12 +1147,15 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Set the current trigger number
**
** @param number Trigger number
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetTriggerNumber(SCM number)
{
int num;
@@ -963,6 +1182,8 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Execute a trigger action
@@ -971,6 +1192,7 @@
**
** @return 1 if the trigger should be removed
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local int TriggerExecuteAction(SCM script)
{
SCM value;
@@ -992,12 +1214,15 @@
}
return 0;
}
+#elif defined(USE_LUA)
+#endif
/**
** Remove a trigger
**
** @param trig Current trigger
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void TriggerRemoveTrigger(SCM trig)
{
if (!gh_null_p(Trigger)) {
@@ -1106,6 +1331,30 @@
gh_new_procedure2_0("action-set-switch", CclActionSetSwitch);
gh_define("*triggers*", NIL);
+#elif defined(USE_LUA)
+// lua_register(Lua, "AddTrigger", CclAddTrigger);
+// lua_register(Lua, "SetTriggerNumber!", CclSetTriggerNumber);
+ // Conditions
+// lua_register(Lua, "IfUnit", CclIfUnit);
+// lua_register(Lua, "IfUnitAt", CclIfUnitAt);
+// lua_register(Lua, "IfNearUnit", CclIfNearUnit);
+// lua_register(Lua, "IfRescuedNearUnit", CclIfRescuedNearUnit);
+// lua_register(Lua, "IfOpponents", CclIfOpponents);
+// lua_register(Lua, "IfResource", CclIfResource);
+// lua_register(Lua, "IfKills", CclIfKills);
+// lua_register(Lua, "IfScore", CclIfScore);
+// lua_register(Lua, "IfElapsed", CclIfElapsed);
+// lua_register(Lua, "IfTimer", CclIfTimer);
+// lua_register(Lua, "IfSwitch", CclIfSwitch);
+ // Actions
+ lua_register(Lua, "ActionVictory", CclActionVictory);
+ lua_register(Lua, "ActionDefeat", CclActionDefeat);
+ lua_register(Lua, "ActionDraw", CclActionDraw);
+ lua_register(Lua, "ActionSetTimer", CclActionSetTimer);
+ lua_register(Lua, "ActionStartTimer", CclActionStartTimer);
+ lua_register(Lua, "ActionStopTimer", CclActionStopTimer);
+ lua_register(Lua, "ActionWait", CclActionWait);
+ lua_register(Lua, "ActionSetSwitch", CclActionSetSwitch);
#endif
}
@@ -1216,7 +1465,7 @@
int trigger;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: trigger $Id: trigger.c,v 1.47 2003/11/16
06:49:26 mr-russ Exp $\n\n");
+ CLprintf(file, ";;; MODULE: trigger $Id: trigger.c,v 1.48 2003/12/02
05:39:13 jsalmon3 Exp $\n\n");
i = 0;
trigger = -1;
Index: stratagus/src/include/trigger.h
diff -u stratagus/src/include/trigger.h:1.14
stratagus/src/include/trigger.h:1.15
--- stratagus/src/include/trigger.h:1.14 Sun Aug 17 11:57:07 2003
+++ stratagus/src/include/trigger.h Tue Dec 2 00:39:13 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: trigger.h,v 1.14 2003/08/17 15:57:07 n0body Exp $
+// $Id: trigger.h,v 1.15 2003/12/02 05:39:13 jsalmon3 Exp $
#ifndef __TRIGGER_H__
#define __TRIGGER_H__
@@ -69,12 +69,17 @@
-- Functions
----------------------------------------------------------------------------*/
-extern int TriggerGetPlayer(SCM); /// get player number.
-extern const UnitType* TriggerGetUnitType(SCM); /// get the unit-type
+#if defined(USE_GUILE) || defined(USE_SIOD)
+extern int TriggerGetPlayer(SCM player);/// get player number.
+extern const UnitType* TriggerGetUnitType(SCM unit); /// get the unit-type
+#elif defined(USE_LUA)
+extern int TriggerGetPlayer(lua_State* l);/// get player number.
+extern const UnitType* TriggerGetUnitType(lua_State* l); /// get the
unit-type
+#endif
extern void TriggersEachCycle(void); /// test triggers
extern void TriggerCclRegister(void); /// Register ccl features
-extern void SaveTriggers(CLFile*); /// Save the trigger module
+extern void SaveTriggers(CLFile* file); /// Save the trigger module
extern void InitTriggers(void); /// Setup triggers
extern void CleanTriggers(void); /// Cleanup the trigger module
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src game/trigger.c include/trigger.h,
Jimmy Salmon <=