[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/ai ai_local.h ai_rules.c ccl_ai.c...
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/ai ai_local.h ai_rules.c ccl_ai.c... |
Date: |
Wed, 12 Nov 2003 15:35:42 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/11/12 15:35:42
Modified files:
src/ai : ai_local.h ai_rules.c ccl_ai.c new_ai.c
Log message:
Started lua support
Patches:
Index: stratagus/src/ai/ai_local.h
diff -u stratagus/src/ai/ai_local.h:1.41 stratagus/src/ai/ai_local.h:1.42
--- stratagus/src/ai/ai_local.h:1.41 Sun Nov 9 17:13:56 2003
+++ stratagus/src/ai/ai_local.h Wed Nov 12 15:35:41 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_local.h,v 1.41 2003/11/09 22:13:56 n0body Exp $
+// $Id: ai_local.h,v 1.42 2003/11/12 20:35:41 jsalmon3 Exp $
#ifndef __AI_LOCAL_H__
#define __AI_LOCAL_H__
@@ -65,7 +65,10 @@
//unsigned char AllExplored : 1;/// Ai sees unexplored area
//unsigned char AllVisbile : 1;/// Ai sees invisibile area
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM Script; /// Main script (gc-protected!)
+#elif defined(USE_LUA)
+#endif
};
/**
@@ -177,7 +180,10 @@
** AI running script ( with state, ... )
*/
typedef struct _ai_running_script_ {
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM Script; /// Script executed
+#elif defined(USE_LUA)
+#endif
unsigned long SleepCycles; /// Cycles to sleep
char ident[10]; /// Debugging !
int HotSpot_X; /// Hot spot ( for defense,
attack, ... )
@@ -203,8 +209,11 @@
** Linked list.
*/
typedef struct _ai_script_action_ {
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM Action; /// Scheme description, in the
form :
/// '((name evaluate-lambda run-script)
... )
+#elif defined(USE_LUA)
+#endif
int Defensive; /// Is this action usable for
defense
int Offensive; /// Is this action usable for
attack
@@ -465,7 +474,10 @@
// Scripts
//
/// Run a script ( for the current AiPlayer )
+#if defined(USE_GUILE) || defined(USE_SIOD)
extern void AiRunScript(int script, SCM list, int hotSpotX, int hotSpotY, int
hotSpotRay);
+#elif defined(USE_LUA)
+#endif
/// Find a script for defense.
extern void AiFindDefendScript(int attackX, int attackY);
/// Check if attack is possible
@@ -481,7 +493,10 @@
/// Give the value of a specific gauge, for the current RunningScript
extern int AiGetGaugeValue(int gauge);
/// Find a gauge given its identifier.
+#if defined(USE_GUILE) || defined(USE_SIOD)
extern int AiFindGaugeId(SCM id);
+#elif defined(USE_LUA)
+#endif
/// return the force of the unittype.
extern int AiUnittypeForce(UnitType * unitType);
@@ -496,7 +511,10 @@
//
/// Save/Load a PlayerAi structure ( see ccl_helpers.h for details )
+#if defined(USE_GUILE) || defined(USE_SIOD)
extern void IOPlayerAiFullPtr(SCM form, void *binaryform, void *para);
+#elif defined(USE_LUA)
+#endif
//@}
Index: stratagus/src/ai/ai_rules.c
diff -u stratagus/src/ai/ai_rules.c:1.7 stratagus/src/ai/ai_rules.c:1.8
--- stratagus/src/ai/ai_rules.c:1.7 Mon Nov 10 14:25:31 2003
+++ stratagus/src/ai/ai_rules.c Wed Nov 12 15:35:41 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_rules.c,v 1.7 2003/11/10 19:25:31 pludov Exp $
+// $Id: ai_rules.c,v 1.8 2003/11/12 20:35:41 jsalmon3 Exp $
//@{
@@ -522,6 +522,7 @@
** @param symbol the gauge's scheme identifier
** @return the gauge id, or -1 if not found
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
global int AiFindGaugeId(SCM symbol)
{
int gauge;
@@ -542,14 +543,19 @@
free(tmp);
return -1;
}
+#elif defined(USE_LUA)
+#endif
local int AiFindUnusedScript(void)
{
int i;
for (i = 1; i < AI_MAX_RUNNING_SCRIPTS; i++) {
+#if defined(USE_GUILE) || defined(USE_SIOD)
if (gh_null_p(AiPlayer->Scripts[i].Script)) {
return i;
}
+#elif defined(USE_LUA)
+#endif
}
return -1;
}
@@ -563,6 +569,7 @@
** @return -1 if running script now is not possible,
** else a value indicating how long/costly it
would be to become 100% OK
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local int AiEvaluateScript(SCM script)
{
SCM get_need_lambda, rslt, willeval;
@@ -576,6 +583,8 @@
return gh_scm2int(rslt);
}
+#elif defined(USE_LUA)
+#endif
/**
** Evaluate the cost to build a force (time to build + ressources)
@@ -750,6 +759,7 @@
*/
local int AiFindBestScript(int defend, AiScriptAction * *foundBestScriptAction)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
AiScriptAction *aiScriptAction, *bestScriptAction;
int bestValue, curValue;
int i;
@@ -762,7 +772,7 @@
aiScriptAction = AiScriptActions + i;
if ((defend && (aiScriptAction->Defensive))
- || ((!defend) && (aiScriptAction->Offensive))) {
+ || ((!defend) && (aiScriptAction->Offensive))) {
curValue = AiEvaluateScript(aiScriptAction->Action);
DebugLevel3Fn("evaluate script ");
#if 0
@@ -780,6 +790,9 @@
(*foundBestScriptAction) = bestScriptAction;
return bestValue;
+#elif defined(USE_LUA)
+ return 0;
+#endif
}
/**
@@ -826,6 +839,7 @@
local void AiStartScript(AiScriptAction * script, char *ident)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM code;
// Compute force requirements.
@@ -840,6 +854,8 @@
AiPlayer->Force[AiScript->ownForce].PopulateMode = AiForceDontPopulate;
snprintf(AiScript->ident, 10, "%s", ident);
+#elif defined(USE_LUA)
+#endif
}
@@ -863,7 +879,10 @@
return;
}
+#if defined(USE_GUILE) || defined(USE_SIOD)
AiEvaluateScript(bestScriptAction->Action);
+#elif defined(USE_LUA)
+#endif
leftCost = AiEvaluateForceCost(AiScript->ownForce, 0);
totalCost = AiEvaluateForceCost(AiScript->ownForce, 1);
@@ -1085,7 +1104,10 @@
AiPrepareScript(bestActionEvaluation->hotSpotX,
bestActionEvaluation->hotSpotY,
16, 0);
+#if defined(USE_GUILE) || defined(USE_SIOD)
AiEvaluateScript(bestActionEvaluation->aiScriptAction->Action);
+#elif defined(USE_LUA)
+#endif
leftCost = AiEvaluateForceCost(AiScript->ownForce, 0);
totalCost = AiEvaluateForceCost(AiScript->ownForce, 1);
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.79 stratagus/src/ai/ccl_ai.c:1.80
--- stratagus/src/ai/ccl_ai.c:1.79 Mon Nov 10 15:13:05 2003
+++ stratagus/src/ai/ccl_ai.c Wed Nov 12 15:35:41 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_ai.c,v 1.79 2003/11/10 20:13:05 pludov Exp $
+// $Id: ccl_ai.c,v 1.80 2003/11/12 20:35:41 jsalmon3 Exp $
//@{
@@ -49,6 +49,7 @@
#include "ccl_helpers.h"
+#if defined(USE_GUILE) || defined(USE_SIOD)
/*----------------------------------------------------------------------------
-- Forwards
----------------------------------------------------------------------------*/
@@ -1934,12 +1935,15 @@
return SCM_BOOL_F;
}
+#elif defined(USE_LUA)
+#endif
/**
** Define AI mapping from original number to internal symbol
**
** @param list List of all names.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineAiWcNames(SCM list)
{
int i;
@@ -1964,6 +1968,42 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+local int CclDefineAiWcNames(lua_State* l)
+{
+ int i;
+ int j;
+ char** cp;
+
+ if ((cp = AiTypeWcNames)) { // Free all old names
+ while (*cp) {
+ free(*cp++);
+ }
+ free(AiTypeWcNames);
+ }
+
+ //
+ // Get new table.
+ //
+ i = lua_gettop(l);
+ AiTypeWcNames = 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
/**
** Get the default resource number
@@ -2001,6 +2041,7 @@
**
** @param list List of the AI Player.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineAiPlayer(SCM list)
{
//SCM value;
@@ -2019,12 +2060,15 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Register CCL features for unit-type.
*/
global void AiCclRegister(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
// FIXME: Need to save memory here.
// Loading all into memory isn't necessary.
@@ -2099,6 +2143,9 @@
gh_new_procedureN("define-ai-wc-names", CclDefineAiWcNames);
gh_new_procedureN("define-ai-player", CclDefineAiPlayer);
+#elif defined(USE_LUA)
+ lua_register(Lua, "DefineAiWcNames", CclDefineAiWcNames);
+#endif
}
Index: stratagus/src/ai/new_ai.c
diff -u stratagus/src/ai/new_ai.c:1.86 stratagus/src/ai/new_ai.c:1.87
--- stratagus/src/ai/new_ai.c:1.86 Mon Nov 10 15:13:06 2003
+++ stratagus/src/ai/new_ai.c Wed Nov 12 15:35:41 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: new_ai.c,v 1.86 2003/11/10 20:13:06 pludov Exp $
+// $Id: new_ai.c,v 1.87 2003/11/12 20:35:41 jsalmon3 Exp $
//@{
@@ -181,6 +181,7 @@
local void debugForces(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
const AiActionEvaluation * aiaction;
int force, i;
int count[UnitTypeMax+1];
@@ -231,6 +232,8 @@
}
DebugLevel2("\n");
}
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -238,6 +241,7 @@
*/
local void AiExecuteScripts(void)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
int i;
PlayerAi *pai;
SCM value;
@@ -266,6 +270,8 @@
}
}
}
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -664,6 +670,7 @@
*/
local void SaveAiScriptActions(CLFile * file)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
AiScriptAction *aiScriptAction;
int i;
@@ -678,6 +685,8 @@
lprin1CL(aiScriptAction->Action, file);
CLprintf(file, "\n)\n");
}
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -688,6 +697,7 @@
*/
local void SaveAiType(CLFile * file, const AiType * aitype)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
SCM list;
if (aitype->Next) {
@@ -706,6 +716,8 @@
list = gh_cdr(list);
}
CLprintf(file, " ))\n\n");
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -730,6 +742,7 @@
*/
local void SaveAiPlayer(CLFile * file, unsigned plynr, PlayerAi * ai)
{
+#if defined(USE_GUILE) || defined(USE_SIOD)
IOOutFile = file;
IOLoadingMode = 0;
IOTabLevel = 1;
@@ -737,6 +750,8 @@
CLprintf(IOOutFile, "(define-ai-player '");
IOPlayerAiFullPtr(SCM_UNSPECIFIED, &ai, 0);
CLprintf(IOOutFile, ")\n");
+#elif defined(USE_LUA)
+#endif
}
/**
@@ -764,7 +779,7 @@
{
CLprintf(file, "\n;;; -----------------------------------------\n");
CLprintf(file,
- ";;; MODULE: AI $Id: new_ai.c,v 1.86 2003/11/10 20:13:06 pludov Exp
$\n\n");
+ ";;; MODULE: AI $Id: new_ai.c,v 1.87 2003/11/12 20:35:41 jsalmon3 Exp
$\n\n");
SaveAiTypesWcName(file);
SaveAiHelper(file);
@@ -804,8 +819,11 @@
pai->Scripts[i].HotSpot_Ray = -1;
pai->Scripts[i].gauges = 0;
pai->Scripts[i].SleepCycles = 0;
+#if defined(USE_GUILE) || defined(USE_SIOD)
pai->Scripts[i].Script = NIL;
CclGcProtect(&pai->Scripts[i].Script);
+#elif defined(USE_LUA)
+#endif
snprintf(pai->Scripts[i].ident, 10, "Empty");
}
@@ -872,7 +890,10 @@
_C_ ainame _C_ ait->Class);
pai->AiType = ait;
+#if defined(USE_GUILE) || defined(USE_SIOD)
CclGcProtectedAssign(&pai->Scripts[0].Script, ait->Script);
+#elif defined(USE_LUA)
+#endif
pai->Collect[TimeCost] = 0;
pai->Collect[GoldCost] = 50;
@@ -927,7 +948,10 @@
}
for (i = 0; i < AI_MAX_RUNNING_SCRIPTS; ++i) {
+#if defined(USE_GUILE) || defined(USE_SIOD)
CclGcUnprotect(&pai->Scripts[i].Script);
+#elif defined(USE_LUA)
+#endif
}
//
@@ -974,7 +998,10 @@
free(aitype->Class);
// ai-type->Script freed by ccl
+#if defined(USE_GUILE) || defined(USE_SIOD)
CclGcUnprotect(&aitype->Script);
+#elif defined(USE_LUA)
+#endif
temp = aitype->Next;
free(aitype);
@@ -1034,7 +1061,10 @@
// Free script action scm...
for (i = 0; i < AiScriptActionNum; i++) {
+#if defined(USE_GUILE) || defined(USE_SIOD)
CclGcUnprotect(&AiScriptActions[i].Action);
+#elif defined(USE_LUA)
+#endif
}
AiResetUnitTypeEquiv();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/ai ai_local.h ai_rules.c ccl_ai.c...,
Jimmy Salmon <=