[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/unit ccl_unittype.c
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/unit ccl_unittype.c |
Date: |
Thu, 20 Nov 2003 16:38:52 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/11/20 16:38:51
Modified files:
src/unit : ccl_unittype.c
Log message:
Added DefineUnitStats
Patches:
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.116
stratagus/src/unit/ccl_unittype.c:1.117
--- stratagus/src/unit/ccl_unittype.c:1.116 Thu Nov 20 14:19:25 2003
+++ stratagus/src/unit/ccl_unittype.c Thu Nov 20 16:38:51 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_unittype.c,v 1.116 2003/11/20 19:19:25 jsalmon3 Exp $
+// $Id: ccl_unittype.c,v 1.117 2003/11/20 21:38:51 jsalmon3 Exp $
//@{
@@ -1427,6 +1427,93 @@
return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
+local int CclDefineUnitStats(lua_State* l)
+{
+ const char* value;
+ UnitType* type;
+ UnitStats* stats;
+ int i;
+ int args;
+ int j;
+
+ args = lua_gettop(l);
+ j = 0;
+
+ type = UnitTypeByIdent(LuaToString(l, j + 1));
+ DebugCheck(!type);
+ ++j;
+
+ i = LuaToNumber(l, j + 1);
+ DebugCheck(i >= PlayerMax);
+ ++j;
+
+ stats = &type->Stats[i];
+
+ //
+ // Parse the list: (still everything could be changed!)
+ //
+ for (; j < args; ++j) {
+
+ value = LuaToString(l, j + 1);
+ ++j;
+
+ if (!strcmp(value, "level")) {
+ stats->Level = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "speed")) {
+ stats->Speed = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "attack-range")) {
+ stats->AttackRange = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "sight-range")) {
+ stats->SightRange = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "armor")) {
+ stats->Armor = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "basic-damage")) {
+ stats->BasicDamage = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "piercing-damage")) {
+ stats->PiercingDamage = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "hit-points")) {
+ stats->HitPoints = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "regeneration-rate")) {
+ stats->RegenerationRate = LuaToNumber(l, j + 1);
+ } else if (!strcmp(value, "costs")) {
+ int subargs;
+ int k;
+
+ if (!lua_istable(l, j + 1)) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ subargs = luaL_getn(l, j + 1);
+ for (k = 0; k < subargs; ++k) {
+
+ lua_rawgeti(l, j + 1, k + 1);
+ value = LuaToString(l, -1);
+ lua_pop(l, 1);
+ ++k;
+
+ for (i = 0; i < MaxCosts; ++i) {
+ if (!strcmp(value, DefaultResourceNames[i])) {
+ lua_rawgeti(l, j + 1, k + 1);
+ stats->Costs[i] = LuaToNumber(l, -1);
+ lua_pop(l, 1);
+ break;
+ }
+ }
+ if (i == MaxCosts) {
+ // FIXME: this leaves half initialized stats
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
+ }
+ }
+ } else {
+ // FIXME: this leaves a half initialized unit
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
+ }
+ }
+
+ return 0;
+}
#endif
// ----------------------------------------------------------------------------
@@ -2036,7 +2123,7 @@
gh_new_procedureN("define-animations", CclDefineAnimations);
#elif defined(USE_LUA)
lua_register(Lua, "DefineUnitType", CclDefineUnitType);
-// lua_register(Lua, "DefineUnitStats", CclDefineUnitStats);
+ lua_register(Lua, "DefineUnitStats", CclDefineUnitStats);
lua_register(Lua, "DefineBoolFlags", CclDefineBoolFlags);
// SiodUnitTypeTag = CclMakeSmobType("UnitType");