[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/game campaign.c game.c intro.c lo...
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/game campaign.c game.c intro.c lo... |
Date: |
Wed, 12 Nov 2003 15:43:23 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/11/12 15:43:23
Modified files:
src/game : campaign.c game.c intro.c loadgame.c savegame.c
trigger.c
Log message:
Started lua support
Patches:
Index: stratagus/src/game/campaign.c
diff -u stratagus/src/game/campaign.c:1.35 stratagus/src/game/campaign.c:1.36
--- stratagus/src/game/campaign.c:1.35 Thu Oct 2 11:39:32 2003
+++ stratagus/src/game/campaign.c Wed Nov 12 15:43:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: campaign.c,v 1.35 2003/10/02 15:39:32 jsalmon3 Exp $
+// $Id: campaign.c,v 1.36 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -151,7 +151,11 @@
if (!CurrentCampaign->Chapters) {
char buf[1024];
filename = LibraryFileName(CurrentCampaign->File, buf);
+#if defined(USE_GUILE) || defined(USE_SIOD)
vload(filename, 0, 1);
+#elif defined(USE_LUA)
+ LuaLoadFile(filename);
+#endif
}
GameIntro.Objectives[0] = strdup(DefaultObjective);
@@ -175,6 +179,7 @@
** @param chapter Chapter.
** @param list List describing show-picture.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void ParseShowPicture(CampaignChapter* chapter, SCM list)
{
SCM value;
@@ -250,6 +255,8 @@
}
}
}
+#elif defined(USE_LUA)
+#endif
/**
** Free campaign chapters.
@@ -293,6 +300,7 @@
**
** @note FIXME: play-video, defeat, draw are missing.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineCampaign(SCM list)
{
char* ident;
@@ -399,12 +407,15 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Set the current campaign chapter
**
** @param num Number of current chapter in current campaign.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetCurrentChapter(SCM num)
{
int i;
@@ -428,12 +439,15 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Set the briefing.
**
** @param list List describing the briefing.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclBriefing(SCM list)
{
SCM value;
@@ -502,15 +516,19 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for campaigns.
*/
global void CampaignCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("define-campaign", CclDefineCampaign);
gh_new_procedure1_0("set-current-chapter!", CclSetCurrentChapter);
gh_new_procedureN("briefing", CclBriefing);
+#endif
}
/**
@@ -523,7 +541,7 @@
int i;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: campaign $Id: campaign.c,v 1.35 2003/10/02
15:39:32 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: campaign $Id: campaign.c,v 1.36 2003/11/12
20:43:22 jsalmon3 Exp $\n\n");
if (!CurrentCampaign) {
return;
}
Index: stratagus/src/game/game.c
diff -u stratagus/src/game/game.c:1.110 stratagus/src/game/game.c:1.111
--- stratagus/src/game/game.c:1.110 Sun Nov 2 21:19:33 2003
+++ stratagus/src/game/game.c Wed Nov 12 15:43:22 2003
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: game.c,v 1.110 2003/11/03 02:19:33 nehalmistry Exp $
+// $Id: game.c,v 1.111 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -98,7 +98,10 @@
}
InitPlayers();
LcmPreventRecurse = 1;
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_load((char*)filename);
+#elif defined(USE_LUA)
+#endif
LcmPreventRecurse = 0;
#if 0
Index: stratagus/src/game/intro.c
diff -u stratagus/src/game/intro.c:1.102 stratagus/src/game/intro.c:1.103
--- stratagus/src/game/intro.c:1.102 Tue Oct 7 20:06:42 2003
+++ stratagus/src/game/intro.c Wed Nov 12 15:43:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: intro.c,v 1.102 2003/10/08 00:06:42 jsalmon3 Exp $
+// $Id: intro.c,v 1.103 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -1373,6 +1373,7 @@
**
** @todo 'comment and 'title are only parsed, but not used.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclCredits(SCM list)
{
SCM value;
@@ -1416,6 +1417,8 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for credits.
@@ -1424,7 +1427,9 @@
{
GameCredits.Background = NULL;
GameCredits.Names = NULL;
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("credits", CclCredits);
+#endif
}
/**
@@ -1434,6 +1439,7 @@
** specifying where in the list it should be added. If no number is
** given it is added at the end.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclAddObjective(SCM list)
{
int i;
@@ -1481,10 +1487,13 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse the remove objective ccl function
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclRemoveObjective(SCM objective)
{
int num;
@@ -1510,10 +1519,13 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Set the objectives
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetObjectives(SCM list)
{
int i;
@@ -1533,10 +1545,13 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Parse the define-ranks ccl function
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineRanks(SCM list)
{
PlayerRanks* rank;
@@ -1583,16 +1598,88 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineRanks(lua_State* l)
+{
+ PlayerRanks* rank;
+ const char* race;
+ int i;
+ int j;
+ int len;
+ int args;
+
+ if (lua_gettop(l) != 2 || !lua_isstring(l, 1) || !lua_istable(l, 2)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ rank = NULL;
+ race = lua_tostring(l, 1);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], race)) {
+ rank = &Ranks[i];
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ lua_pushfstring(l, "Invalid race name: %s", race);
+ lua_error(l);
+ }
+
+ if (rank->Ranks) {
+ for (i = 0; rank->Ranks[i]; ++i) {
+ free(rank->Ranks[i]);
+ }
+ free(rank->Ranks);
+ free(rank->Scores);
+ }
+
+ args = luaL_getn(l, 2);
+ len = args / 2;
+
+ rank->Ranks = (char**)malloc((len + 1) * sizeof(char*));
+ rank->Ranks[len] = NULL;
+ rank->Scores = (int*)malloc(len * sizeof(int));
+
+ i = 0;
+ for (j = 0; j < args; ++j) {
+ lua_rawgeti(l, 2, j + 1);
+ if (!lua_isnumber(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ rank->Scores[i] = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+ ++j;
+ lua_rawgeti(l, 2, j + 1);
+ if (!lua_isstring(l, -1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ rank->Ranks[i] = strdup(lua_tostring(l, -1));
+ lua_pop(l, 1);
+ ++i;
+ }
+
+ return 0;
+}
+#endif
/**
** Register CCL functions for objectives
*/
global void ObjectivesCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_new_procedureN("add-objective", CclAddObjective);
gh_new_procedure1_0("remove-objective", CclRemoveObjective);
gh_new_procedureN("set-objectives!", CclSetObjectives);
gh_new_procedureN("define-ranks", CclDefineRanks);
+#elif defined(USE_LUA)
+// lua_register(Lua, "AddObjective", CclAddObjective);
+// lua_register(Lua, "RemoveObjective", CclRemoveObjective);
+// lua_register(Lua, "SetObjectives", CclSetObjectives);
+ lua_register(Lua, "DefineRanks", CclDefineRanks);
+#endif
}
/**
Index: stratagus/src/game/loadgame.c
diff -u stratagus/src/game/loadgame.c:1.67 stratagus/src/game/loadgame.c:1.68
--- stratagus/src/game/loadgame.c:1.67 Mon Nov 3 06:21:40 2003
+++ stratagus/src/game/loadgame.c Wed Nov 12 15:43:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: loadgame.c,v 1.67 2003/11/03 11:21:40 pludov Exp $
+// $Id: loadgame.c,v 1.68 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -76,7 +76,9 @@
*/
global void CleanModules(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM var;
+#endif
EndReplayLog();
CleanMessages();
@@ -114,8 +116,10 @@
//
// Free our protected objects, AI scripts, unit-type properties.
//
+#if defined(USE_GUILE) || defined(USE_SIOD)
var = gh_symbol2scm("*ccl-protect*");
setvar(var, NIL, NIL);
+#endif
}
/**
@@ -217,18 +221,25 @@
*/
global void LoadGame(char* filename)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
int old_siod_verbose_level;
+#endif
unsigned long game_cycle;
CleanModules();
+#if defined(USE_GUILE) || defined(USE_SIOD)
old_siod_verbose_level = siod_verbose_level;
siod_verbose_level = 4;
CclGarbageCollect(0);
siod_verbose_level = old_siod_verbose_level;
+#endif
InitVisionTable();
+#if defined(USE_GUILE) || defined(USE_SIOD)
gh_load(filename);
CclGarbageCollect(0);
+#elif defined(USE_LUA)
+#endif
game_cycle = GameCycle;
// FIXME: log should be loaded from the save game
Index: stratagus/src/game/savegame.c
diff -u stratagus/src/game/savegame.c:1.36 stratagus/src/game/savegame.c:1.37
--- stratagus/src/game/savegame.c:1.36 Sat Oct 25 14:58:43 2003
+++ stratagus/src/game/savegame.c Wed Nov 12 15:43:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: savegame.c,v 1.36 2003/10/25 18:58:43 n0body Exp $
+// $Id: savegame.c,v 1.37 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -101,7 +101,7 @@
CLprintf(file, ";;;(save-game\n");
CLprintf(file, ";;; 'comment\t\"Generated by Stratagus Version " VERSION
"\"\n");
CLprintf(file, ";;; 'comment\t\"Visit http://Stratagus.Org for more
informations\"\n");
- CLprintf(file, ";;; 'comment\t\"$Id: savegame.c,v 1.36 2003/10/25
18:58:43 n0body Exp $\"\n");
+ CLprintf(file, ";;; 'comment\t\"$Id: savegame.c,v 1.37 2003/11/12
20:43:22 jsalmon3 Exp $\"\n");
CLprintf(file, ";;; 'type\t\"%s\"\n", "single-player");
CLprintf(file, ";;; 'date\t\"%s\"\n", s);
CLprintf(file, ";;; 'map\t\"%s\"\n", TheMap.Description);
@@ -111,6 +111,7 @@
StratagusMajorVersion, StratagusMinorVersion, StratagusPatchLevel);
// Save media type
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM var;
CLprintf(file, ";;; 'media\t'");
@@ -122,6 +123,8 @@
//} else {
CLprintf(file, "nil");
//}
+#elif defined(USE_LUA)
+#endif
}
CLprintf(file, "\n;;; 'preview\t\"%s.pam\"\n", filename);
CLprintf(file, ";;; )\n");
Index: stratagus/src/game/trigger.c
diff -u stratagus/src/game/trigger.c:1.45 stratagus/src/game/trigger.c:1.46
--- stratagus/src/game/trigger.c:1.45 Mon Nov 3 06:21:40 2003
+++ stratagus/src/game/trigger.c Wed Nov 12 15:43:22 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: trigger.c,v 1.45 2003/11/03 11:21:40 pludov Exp $
+// $Id: trigger.c,v 1.46 2003/11/12 20:43:22 jsalmon3 Exp $
//@{
@@ -52,7 +52,10 @@
----------------------------------------------------------------------------*/
/// Get unit-type.
+#if defined(USE_GUILE) || defined(USE_SIOD)
extern UnitType* CclGetUnitType(SCM ptr);
+#elif defined(USE_LUA)
+#endif
#define MAX_SWITCH 256 /// Maximum number of switches
@@ -60,11 +63,17 @@
-- Variables
----------------------------------------------------------------------------*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM Trigger; /// Current trigger
+#elif defined(USE_LUA)
+#endif
global Timer GameTimer; /// The game timer
local unsigned long WaitFrame; /// Frame to wait for
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM WaitScript; /// Script to run after wait is over
local SCM WaitTrigger; /// Old Trigger value during wait
+#elif defined(USE_LUA)
+#endif
local unsigned char Switch[MAX_SWITCH]; /// Switches
/*----------------------------------------------------------------------------
@@ -78,6 +87,7 @@
**
** @return The player number, -1 matches any.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global int TriggerGetPlayer(SCM player)
{
int ret;
@@ -120,6 +130,8 @@
return CclGetUnitType(unit);
}
+#elif defined(USE_LUA)
+#endif
// --------------------------------------------------------------------------
// Conditions
@@ -185,6 +197,7 @@
/**
** Player has the quantity of unit-type.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclIfUnit(SCM player, SCM operation, SCM quantity, SCM unit)
{
int plynr;
@@ -996,12 +1009,15 @@
}
CclGcProtectedAssign(&Trigger, trig);
}
+#elif defined(USE_LUA)
+#endif
/**
** Check trigger each game cycle.
*/
global void TriggersEachCycle(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM pair;
SCM trig;
SCM value;
@@ -1049,6 +1065,8 @@
} else {
CclGcProtectedAssign(&Trigger, NULL);
}
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -1056,6 +1074,7 @@
*/
global void TriggerCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
Trigger = NIL;
WaitScript = NIL;
WaitTrigger = NIL;
@@ -1087,6 +1106,7 @@
gh_new_procedure2_0("action-set-switch", CclActionSetSwitch);
gh_define("*triggers*", NIL);
+#endif
}
/**
@@ -1097,6 +1117,7 @@
** @param exp Expression
** @param f File to print to
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local void PrintTrigger(SCM exp, CLFile* f)
{
#ifdef USE_GUILE
@@ -1179,6 +1200,8 @@
}
#endif
}
+#elif defined(USE_LUA)
+#endif
/**
** Save the trigger module.
@@ -1187,12 +1210,13 @@
*/
global void SaveTriggers(CLFile* file)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM list;
int i;
int trigger;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: trigger $Id: trigger.c,v 1.45 2003/11/03
11:21:40 pludov Exp $\n\n");
+ CLprintf(file, ";;; MODULE: trigger $Id: trigger.c,v 1.46 2003/11/12
20:43:22 jsalmon3 Exp $\n\n");
i = 0;
trigger = -1;
@@ -1218,6 +1242,8 @@
CLprintf(file, "(action-start-timer)\n");
}
}
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -1232,10 +1258,13 @@
// FIXME: choose the triggers for game type
+#if defined(USE_GUILE) || defined(USE_SIOD)
if (gh_null_p(symbol_value(gh_symbol2scm("*triggers*"), NIL))) {
DebugLevel0Fn("Default triggers\n");
gh_apply(symbol_value(gh_symbol2scm("single-player-triggers"), NIL),
NIL);
}
+#elif defined(USE_LUA)
+#endif
memset(Switch, 0, sizeof(Switch));
}
@@ -1245,6 +1274,7 @@
*/
global void CleanTriggers(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM var;
DebugLevel0Fn("FIXME: Cleaning trigger not written\n");
@@ -1253,6 +1283,8 @@
setvar(var, NIL, NIL);
CclGcProtectedAssign(&Trigger, NULL);
+#elif defined(USE_LUA)
+#endif
memset(&GameTimer, 0, sizeof(GameTimer));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/game campaign.c game.c intro.c lo...,
Jimmy Salmon <=