[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/ai ccl_ai.c
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/ai ccl_ai.c |
Date: |
Tue, 02 Dec 2003 21:02:28 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/12/02 21:02:28
Modified files:
src/ai : ccl_ai.c
Log message:
Started DefineAi
Patches:
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.85 stratagus/src/ai/ccl_ai.c:1.86
--- stratagus/src/ai/ccl_ai.c:1.85 Tue Nov 25 06:46:02 2003
+++ stratagus/src/ai/ccl_ai.c Tue Dec 2 21:02:28 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_ai.c,v 1.85 2003/11/25 11:46:02 pludov Exp $
+// $Id: ccl_ai.c,v 1.86 2003/12/03 02:02:28 jsalmon3 Exp $
//@{
@@ -137,9 +137,9 @@
sizeof (AiUnitType),
-1,
{
- {"'next", 0, &((AiUnitType *) 0)->Next,
0},
- {"type", &IOUnitTypePtr, &((AiUnitType *) 0)->Type,
0},
- {"want", &IOInt, &((AiUnitType *) 0)->Want,
0},
+ {"'next", 0, &((AiUnitType*) 0)->Next,
0},
+ {"type", &IOUnitTypePtr, &((AiUnitType*) 0)->Type,
0},
+ {"want", &IOInt, &((AiUnitType*) 0)->Want,
0},
{0, 0, 0, 0}
}
};
@@ -221,7 +221,7 @@
/// Description of the UpgradeToRequests table in PlayerAi
static IOStructDef UpgradeToRequestsTableDef = {
"UpgradeToRequests",
- sizeof (UnitType *),
+ sizeof (UnitType*),
-1,
{
{"`ptr", 0, &((PlayerAi *)
0)->UpgradeToRequests, 0},
@@ -307,7 +307,7 @@
----------------------------------------------------------------------------*/
/**
-** Handle saving/loading a reference to an AiType ( AiType * ).
+** Handle saving/loading a reference to an AiType ( AiType* ).
** The null case is handled.
**
** @param scmform When loading, the scm data to load
@@ -520,7 +520,7 @@
** @param tablep Pointer to table with elements.
** @param base Base type to insert into table.
*/
-local void AiHelperInsert(AiUnitTypeTable ** tablep, UnitType * base)
+local void AiHelperInsert(AiUnitTypeTable ** tablep, UnitType* base)
{
int i;
int n;
@@ -548,7 +548,7 @@
//
// Append new base unit-type to units.
//
- table = *tablep = realloc(table, sizeof (AiUnitTypeTable) + sizeof
(UnitType *) * n);
+ table = *tablep = realloc(table, sizeof (AiUnitTypeTable) + sizeof
(UnitType*) * n);
table->Count = n + 1;
table->Table[n] = base;
}
@@ -575,8 +575,8 @@
SCM value;
int what;
char *str;
- UnitType *base;
- UnitType *type;
+ UnitType* base;
+ UnitType* type;
Upgrade *upgrade;
int cost;
@@ -734,10 +734,13 @@
return SCM_UNSPECIFIED;
}
+#elif defined(USE_LUA)
+#endif
/**
** Define an AI engine.
*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineAi(SCM list)
{
SCM value;
@@ -747,7 +750,7 @@
const AiType *ait;
#endif
- aitype = malloc(sizeof (AiType));
+ aitype = malloc(sizeof(AiType));
aitype->Next = AiTypes;
AiTypes = aitype;
@@ -804,13 +807,75 @@
return list;
}
+#elif defined(USE_LUA)
+local int CclDefineAi(lua_State* l)
+{
+ const char* value;
+ AiType *aitype;
+#ifdef DEBUG
+ const AiType *ait;
+#endif
+ int args;
+ int j;
+
+ args = lua_gettop(l);
+ j = 0;
+
+ aitype = malloc(sizeof(AiType));
+ aitype->Next = AiTypes;
+ AiTypes = aitype;
+
+ //
+ // AI Name
+ //
+ aitype->Name = strdup(LuaToString(l, j + 1));
+ ++j;
+ DebugLevel3Fn("%s\n" _C_ aitype->Name);
+
+#ifdef DEBUG
+ for (ait = AiTypes->Next; ait; ait = ait->Next) {
+ if (!strcmp(aitype->Name, ait->Name)) {
+ DebugLevel0Fn("Warning two or more AI's with the same name '%s'\n"
_C_ ait->
+ Name);
+ }
+ }
+#endif
+
+ //
+ // AI Race
+ //
+ value = LuaToString(l, j + 1);
+ ++j;
+ DebugLevel3Fn("%s\n" _C_ value);
+ if (*value != '*') {
+ aitype->Race = strdup(value);
+ } else {
+ aitype->Race = NULL;
+ }
+
+ //
+ // AI Class
+ //
+ aitype->Class = strdup(LuaToString(l, j + 1));
+ ++j;
+ DebugLevel3Fn("%s\n" _C_ aitype->Class);
+
+ //
+ // AI Script
+ //
+// aitype->Script = value;
+
+ return 0;
+}
+#endif
/*----------------------------------------------------------------------------
-- AI script functions
----------------------------------------------------------------------------*/
+#if defined(USE_GUILE) || defined(USE_SIOD)
/// Get unit-type.
-extern UnitType *CclGetUnitType(SCM ptr);
+extern UnitType* CclGetUnitType(SCM ptr);
/**
** Append unit-type to request table.
@@ -818,7 +883,7 @@
** @param type Unit-type to be appended.
** @param count How many unit-types to build.
*/
-local void InsertUnitTypeRequests(UnitType * type, int count)
+local void InsertUnitTypeRequests(UnitType* type, int count)
{
int n;
@@ -840,7 +905,7 @@
**
** @param type Unit-type to be found.
*/
-local AiUnitTypeTable *FindInUnitTypeRequests(const UnitType * type)
+local AiUnitTypeTable *FindInUnitTypeRequests(const UnitType* type)
{
int i;
int n;
@@ -859,7 +924,7 @@
**
** @param type Unit-type to be found.
*/
-local int FindInUpgradeToRequests(const UnitType * type)
+local int FindInUpgradeToRequests(const UnitType* type)
{
int i;
int n;
@@ -878,7 +943,7 @@
**
** @param type Unit-type to be appended.
*/
-local void InsertUpgradeToRequests(UnitType * type)
+local void InsertUpgradeToRequests(UnitType* type)
{
int n;
@@ -899,7 +964,7 @@
**
** @param upgrade Upgrade to be appended.
*/
-local void InsertResearchRequests(Upgrade * upgrade)
+local void InsertResearchRequests(Upgrade* upgrade)
{
int n;
@@ -1014,7 +1079,7 @@
local SCM CclAiSet(SCM value, SCM count)
{
AiUnitTypeTable *autt;
- UnitType *type;
+ UnitType* type;
type = CclGetUnitType(value);
if ((autt = FindInUnitTypeRequests(type))) {
@@ -1035,7 +1100,7 @@
local SCM CclAiWait(SCM value)
{
const AiUnitTypeTable *autt;
- const UnitType *type;
+ const UnitType* type;
const int *unit_types_count;
int j;
int n;
@@ -1121,7 +1186,7 @@
{
int force;
SCM rslt;
- AiUnitType *aiut;
+ AiUnitType* aiut;
force = gh_scm2int(list);
if (force < 0 || force >= AI_MAX_FORCES) {
@@ -1164,7 +1229,7 @@
int want[3];
int *unittypes;
int unittypecount;
- UnitType *unittype;
+ UnitType* unittype;
char *str;
int i;
int rslt;
@@ -1240,9 +1305,9 @@
*/
local SCM CclAiForce(SCM list)
{
- AiUnitType **prev;
- AiUnitType *aiut;
- UnitType *type;
+ AiUnitType* *prev;
+ AiUnitType* aiut;
+ UnitType* type;
int count;
int force;
@@ -1391,7 +1456,7 @@
int i;
Unit *unit;
int transporterplace;
- UnitType * transporter;
+ UnitType* transporter;
AiUnit * aiunit;
if ((AiScript->HotSpot_X == -1) || (AiScript->HotSpot_Y == -1)
@@ -1661,7 +1726,7 @@
*/
local SCM CclAiUpgradeTo(SCM value)
{
- UnitType *type;
+ UnitType* type;
type = CclGetUnitType(value);
InsertUpgradeToRequests(type);
@@ -1702,7 +1767,7 @@
local SCM CclGetUnitTypeForce(SCM value)
{
- UnitType *unitType;
+ UnitType* unitType;
unitType = CclGetUnitType(value);
@@ -1838,7 +1903,7 @@
{
int i;
int n;
- const AiUnitType *aut;
+ const AiUnitType* aut;
const AiBuildQueue *queue;
//
@@ -2105,6 +2170,9 @@
gh_new_procedureN("define-ai-player", CclDefineAiPlayer);
#elif defined(USE_LUA)
+// lua_register(Lua, "DefineAiHelper", CclDefineAiHelper);
+ lua_register(Lua, "DefineAi", CclDefineAi);
+
lua_register(Lua, "DefineAiWcNames", CclDefineAiWcNames);
#endif
}
- [Stratagus-CVS] stratagus/src/ai ccl_ai.c,
Jimmy Salmon <=