stratagus-cvs
[Top][All Lists]
Advanced

[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: Wed, 19 Nov 2003 19:56:13 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/11/19 19:56:13

Modified files:
        src/unit       : ccl_unittype.c 

Log message:
        Added DefineAnimations, DefineBoolFlags, and started DefineUnitType

Patches:
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.113 
stratagus/src/unit/ccl_unittype.c:1.114
--- stratagus/src/unit/ccl_unittype.c:1.113     Mon Nov 17 14:14:43 2003
+++ stratagus/src/unit/ccl_unittype.c   Wed Nov 19 19:56:13 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.113 2003/11/17 19:14:43 nehalmistry Exp $
+//     $Id: ccl_unittype.c,v 1.114 2003/11/20 00:56:13 jsalmon3 Exp $
 
 //@{
 
@@ -91,6 +91,27 @@
     errl("Unsupported resource tag", value);
     return 0xABCDEF;
 }
+#elif defined(USE_LUA)
+global unsigned CclGetResourceByName(lua_State* l)
+{
+    int i;
+    const char* value;
+
+    if (!lua_isstring(l, -1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    value = lua_tostring(l, -1);
+    for (i = 0; i < MaxCosts; ++i) {
+       if (!strcmp(value, DefaultResourceNames[i])) {
+           return i;
+       }
+    }
+    lua_pushfstring(l, "Unsupported resource tag: %s", value);
+    lua_error(l);
+    return 0xABCDEF;
+}
+#endif
 
 /**
 **     Parse unit-type.
@@ -99,6 +120,7 @@
 **
 **     @param list     List describing the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineUnitType(SCM list)
 {
     SCM value;
@@ -367,10 +389,714 @@
        } else if (gh_eq_p(value, gh_symbol2scm("demand"))) {
            type->Demand = gh_scm2int(gh_car(list));
            list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("supply"))) {
-           type->Supply = gh_scm2int(gh_car(list));
+       } else if (gh_eq_p(value, gh_symbol2scm("supply"))) {
+           type->Supply = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("corpse"))) {
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           if (redefine) {
+               free(type->CorpseName);
+           }
+           type->CorpseName = gh_scm2newstr(gh_car(sublist), NULL);
+           type->CorpseType = NULL;
+           type->CorpseScript = gh_scm2int(gh_cadr(sublist));
+       } else if (gh_eq_p(value, gh_symbol2scm("explode-when-killed"))) {
+           type->ExplodeWhenKilled = 1;
+           type->Explosion.Name = gh_scm2newstr(gh_car(list), NULL);
+           type->Explosion.Missile = NULL;
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("type-land"))) {
+           type->UnitType = UnitTypeLand;
+       } else if (gh_eq_p(value, gh_symbol2scm("type-fly"))) {
+           type->UnitType = UnitTypeFly;
+       } else if (gh_eq_p(value, gh_symbol2scm("type-naval"))) {
+           type->UnitType = UnitTypeNaval;
+
+       } else if (gh_eq_p(value, gh_symbol2scm("right-none"))) {
+           type->MouseAction = MouseActionNone;
+       } else if (gh_eq_p(value, gh_symbol2scm("right-attack"))) {
+           type->MouseAction = MouseActionAttack;
+       } else if (gh_eq_p(value, gh_symbol2scm("right-move"))) {
+           type->MouseAction = MouseActionMove;
+       } else if (gh_eq_p(value, gh_symbol2scm("right-harvest"))) {
+           type->MouseAction = MouseActionHarvest;
+       } else if (gh_eq_p(value, gh_symbol2scm("right-spell-cast"))) {
+           type->MouseAction = MouseActionSpellCast;
+       } else if (gh_eq_p(value, gh_symbol2scm("right-sail"))) {
+           type->MouseAction = MouseActionSail;
+
+       } else if (gh_eq_p(value, gh_symbol2scm("can-ground-attack"))) {
+           type->GroundAttack = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-attack"))) {
+           type->CanAttack = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("repair-range"))) {
+           type->RepairRange = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("repair-hp"))) {
+           type->RepairHP = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("repair-costs"))) {
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type->RepairCosts[CclGetResourceByName(value)] = 
gh_scm2int(gh_car(sublist));
+               sublist = gh_cdr(sublist);
+           }
+       } else if (gh_eq_p(value, gh_symbol2scm("can-target-land"))) {
+           type->CanTarget |= CanTargetLand;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-target-sea"))) {
+           type->CanTarget |= CanTargetSea;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-target-air"))) {
+           type->CanTarget |= CanTargetAir;
+
+       } else if (gh_eq_p(value, gh_symbol2scm("building"))) {
+           type->Building = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("visible-under-fog"))) {
+           type->VisibleUnderFog = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("builder-outside"))) {
+           type->BuilderOutside = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("builder-lost"))) {
+           type->BuilderLost = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("auto-build-rate"))) {
+           type->AutoBuildRate = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("shore-building"))) {
+           type->ShoreBuilding = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("land-unit"))) {
+           type->LandUnit = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("air-unit"))) {
+           type->AirUnit = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("sea-unit"))) {
+           type->SeaUnit = 1;
+       } else if (gh_eq_p(value, 
gh_symbol2scm("random-movement-probability"))) {
+           type->RandomMovementProbability = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("clicks-to-explode"))) {
+           type->ClicksToExplode = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("permanent-cloak"))) {
+           type->PermanentCloak = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("detect-cloak"))) {
+           type->DetectCloak = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("transporter"))) {
+           type->Transporter = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("coward"))) {
+           type->Coward = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-gather-resource"))) {
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           res = (ResourceInfo*)malloc(sizeof(ResourceInfo));
+           memset(res, 0, sizeof(ResourceInfo));
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               if (gh_eq_p(value, gh_symbol2scm("resource-id"))) {
+                   res->ResourceId = CclGetResourceByName(gh_car(sublist));
+                   type->ResInfo[res->ResourceId] = res;
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("resource-step"))) {
+                   res->ResourceStep = gh_scm2int(gh_car(sublist));
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("final-resource"))) {
+                   res->FinalResource = CclGetResourceByName(gh_car(sublist));
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("wait-at-resource"))) {
+                   res->WaitAtResource = gh_scm2int(gh_car(sublist));
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("wait-at-depot"))) {
+                   res->WaitAtDepot = gh_scm2int(gh_car(sublist));
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("resource-capacity"))) {
+                   res->ResourceCapacity = gh_scm2int(gh_car(sublist));
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("terrain-harvester"))) {
+                   res->TerrainHarvester = 1;
+               } else if (gh_eq_p(value, gh_symbol2scm("lose-resources"))) {
+                   res->LoseResources = 1;
+               } else if (gh_eq_p(value, 
gh_symbol2scm("harvest-from-outside"))) {
+                   res->HarvestFromOutside = 1;
+               } else if (gh_eq_p(value, gh_symbol2scm("file-when-empty"))) {
+                   res->FileWhenEmpty = gh_scm2newstr(gh_car(sublist),0);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("file-when-loaded"))) {
+                   res->FileWhenLoaded = gh_scm2newstr(gh_car(sublist),0);
+                   sublist = gh_cdr(sublist);
+               } else {
+                  printf("\n%s\n",type->Name);
+                  errl("Unsupported tag", value);
+                  DebugCheck(1);
+               }
+           }
+           type->Harvester = 1;
+           if (!res->FinalResource) {
+               res->FinalResource = res->ResourceId;
+           }
+           DebugCheck(!res->ResourceId);
+       } else if (gh_eq_p(value, gh_symbol2scm("gives-resource"))) {
+           type->GivesResource = CclGetResourceByName(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("max-workers"))) {
+           type->MaxWorkers = gh_scm2int(gh_car(list));
+           list = gh_cdr(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("can-harvest"))) {
+           type->CanHarvest = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-store"))) {
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               type->CanStore[CclGetResourceByName(gh_car(sublist))] = 1;
+               sublist = gh_cdr(sublist);
+           }
+       } else if (gh_eq_p(value, gh_symbol2scm("vanishes"))) {
+           type->Vanishes = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("can-cast-spell"))) {
+           //
+           //    Warning: can-cast-spell should only be used AFTER all spells
+           //    have been defined. FIXME: MaxSpellType=500 or something?
+           //
+           if (!type->CanCastSpell) {
+               type->CanCastSpell = malloc(SpellTypeCount);
+               memset(type->CanCastSpell, 0, SpellTypeCount);
+           }
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           type->Magic = 0;
+           while (!gh_null_p(sublist)) {
+               int id;
+               id = CclGetSpellByIdent(gh_car(sublist));
+               DebugLevel3Fn("%d \n" _C_ id);
+               if (id == -1) {
+                   errl("Unknown spell type", gh_car(sublist));
+               }
+               type->CanCastSpell[id] = 1;
+               sublist = gh_cdr(sublist);
+               type->Magic = 1;
+           }
+       } else if (gh_eq_p(value, gh_symbol2scm("can-target-flag"))) {
+           //
+           //    Warning: can-target-flag should only be used AFTER all bool 
flags
+           //    have been defined.
+           //
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               for (i = 0; i < NumberBoolFlag; i++) {
+                   if (gh_eq_p(value, gh_symbol2scm(BoolFlagName[i]))) {
+                       type->CanTargetFlag[i] = Scm2Condition(gh_car(sublist));
+                       sublist = gh_cdr(sublist);
+                       break;
+                   }
+               }
+               if (i != NumberBoolFlag) {
+                   continue;
+               }
+               printf("\n%s\n", type->Name);
+               errl("Unsupported flag tag for can-target-flag", value);
+           }
+       } else if (gh_eq_p(value, gh_symbol2scm("selectable-by-rectangle"))) {
+           type->SelectableByRectangle = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("teleporter"))) {
+           type->Teleporter = 1;
+       } else if (gh_eq_p(value, gh_symbol2scm("sounds"))) {
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+
+               if (gh_eq_p(value, gh_symbol2scm("selected"))) {
+                   if (redefine) {
+                       free(type->Sound.Selected.Name);
+                   }
+                   type->Sound.Selected.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("acknowledge"))) {
+                   if (redefine) {
+                       free(type->Sound.Acknowledgement.Name);
+                   }
+                   type->Sound.Acknowledgement.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("ready"))) {
+                   if (redefine) {
+                       free(type->Sound.Ready.Name);
+                   }
+                   type->Sound.Ready.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("repair"))) {
+                   if (redefine) {
+                       free(type->Sound.Repair.Name);
+                   }
+                   type->Sound.Repair.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("harvest"))) {
+                   int res;
+                   char* name;
+
+                   name = gh_scm2newstr(gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+                   for (res = 0; res < MaxCosts; ++res) {
+                       if (!strcmp(name, DefaultResourceNames[res])) {
+                           break;
+                       }
+                   }
+                   if (res == MaxCosts) {
+                       errl("Resource not found", value);
+                   }
+                   free(name);
+                   if (redefine) {
+                       free(type->Sound.Harvest[res].Name);
+                   }
+                   type->Sound.Harvest[res].Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("help"))) {
+                   if (redefine) {
+                       free(type->Sound.Help.Name);
+                   }
+                   type->Sound.Help.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("dead"))) {
+                   if (redefine) {
+                       free(type->Sound.Dead.Name);
+                   }
+                   type->Sound.Dead.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else if (gh_eq_p(value, gh_symbol2scm("attack"))) {
+                   if (redefine) {
+                       free(type->Weapon.Attack.Name);
+                   }
+                   type->Weapon.Attack.Name = gh_scm2newstr(
+                       gh_car(sublist), NULL);
+                   sublist = gh_cdr(sublist);
+               } else {
+                   errl("Unsupported sound tag", value);
+               }
+           }
+       } else {
+           for (i = 0; i < NumberBoolFlag; i++) { // User defined bool flags
+               if (gh_eq_p(value, gh_symbol2scm(BoolFlagName[i]))) {
+                   type->BoolFlag[i] = 1;
+                   break;
+               }
+           }
+           if (i != NumberBoolFlag) {
+               continue;
+           }
+           // FIXME: this leaves a half initialized unit-type
+           printf("\n%s\n",type->Name);
+           errl("Unsupported tag", value);
+           DebugCheck(1);
+       }
+    }
+
+    // FIXME: try to simplify/combine the flags instead
+    if (type->MouseAction == MouseActionAttack && !type->CanAttack) {
+       printf("Unit-type `%s': right-attack is set, but can-attack is not\n", 
type->Name);
+       // ugly way to show the line number
+       errl("", SCM_UNSPECIFIED); 
+    }
+
+    return SCM_UNSPECIFIED;
+}
+#elif defined(USE_LUA)
+local int CclDefineUnitType(lua_State* l)
+{
+    const char* value;
+//    SCM sublist;
+    UnitType* type;
+    UnitType* auxtype;
+    ResourceInfo* res;
+    char* str;
+    int i;
+    int redefine;
+    int args;
+    int j;
+
+    args = lua_gettop(l);
+    j = 0;
+
+    // Slot identifier
+    if (!lua_isstring(l, j + 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    str = strdup(lua_tostring(l, j + 1));
+    ++j;
+
+#ifdef DEBUG
+    i = NoWarningUnitType;
+    NoWarningUnitType = 1;
+#endif
+    type = UnitTypeByIdent(str);
+#ifdef DEBUG
+    NoWarningUnitType = i;
+#endif
+    if (type) {
+       DebugLevel3Fn("Redefining unit-type `%s'\n" _C_ str);
+       free(str);
+       redefine = 1;
+    } else {
+       DebugLevel3Fn("Defining unit-type `%s'\n" _C_ str);
+       type = NewUnitTypeSlot(str);
+       redefine = 0;
+       //Set some default values
+       type->_RegenerationRate = 0;
+       type->Selectable = 1;
+    }
+    type->BoolFlag = realloc(type->BoolFlag, NumberBoolFlag * sizeof 
(*type->BoolFlag));
+    memset(type->BoolFlag, 0, NumberBoolFlag * sizeof (*type->BoolFlag));
+    type->CanTargetFlag = realloc(type->CanTargetFlag, NumberBoolFlag * sizeof 
(*type->CanTargetFlag));
+    memset(type->CanTargetFlag, 0, NumberBoolFlag * sizeof 
(*type->CanTargetFlag));
+
+    type->NumDirections = 8;
+
+//    type->Property = SCM_UNSPECIFIED;
+
+    //
+    // Parse the list: (still everything could be changed!)
+    //
+    for (; j < args; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       value = lua_tostring(l, j + 1);
+       ++j;
+       if (!strcmp(value, "name")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           if (redefine) {
+               free(type->Name);
+           }
+           type->Name = strdup(lua_tostring(l, j + 1));
+       } else if (!strcmp(value, "use")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           if (redefine) {
+               free(type->SameSprite);
+           }
+           type->SameSprite = strdup(lua_tostring(l, j + 1));
+       } else if (!strcmp(value, "files")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               char* str;
+
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+
+               // FIXME: use a general get tileset function here!
+               str = gh_scm2newstr(value, NULL);
+               i = 0;
+               if (strcmp(str, "default")) {
+                   for (; i < NumTilesets; ++i) {
+                       if (!strcmp(str,Tilesets[i]->Ident) ||
+                               !strcmp(str,Tilesets[i]->Class)) {
+                           break;
+                       }
+                   }
+                   if (i == NumTilesets) {
+                      // FIXME: this leaves half initialized unit-type
+                      errl("Unsupported tileset tag", value);
+                   }
+               }
+               free(str);
+               if (redefine) {
+                   free(type->File[i]);
+               }
+               type->File[i] = gh_scm2newstr(gh_car(sublist), NULL);
+               sublist = gh_cdr(sublist);
+           }
+#endif
+       } else if (!strcmp(value, "shadow")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+
+               if (gh_eq_p(value, "file")) {
+                   if (redefine) {
+                       free(type->ShadowFile);
+                   }
+                   type->ShadowFile = gh_scm2newstr(gh_car(sublist), NULL);
+               } else if (gh_eq_p(value, "size")) {
+                   type->ShadowWidth = gh_scm2int(gh_car(gh_car(sublist)));
+                   type->ShadowHeight = 
gh_scm2int(gh_car(gh_cdr(gh_car(sublist))));
+               } else if (gh_eq_p(value, "height")) {
+               } else if (gh_eq_p(value, "offset")) {
+                   type->ShadowOffsetX = gh_scm2int(gh_car(gh_car(sublist)));
+                   type->ShadowOffsetY = 
gh_scm2int(gh_car(gh_cdr(gh_car(sublist))));
+               } else {
+                   errl("Unsupported shadow tag", value);
+               }
+               sublist = gh_cdr(sublist);
+           }
+#endif
+       } else if (!strcmp(value, "size")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           type->Width = gh_scm2int(gh_car(sublist));
+           type->Height = gh_scm2int(gh_cadr(sublist));
+#endif
+       } else if (!strcmp(value, "animations")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Animations = AnimationsByIdent(lua_tostring(l, j + 1));
+       } else if (!strcmp(value, "icon")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           if (redefine) {
+               free(type->Icon.Name);
+           }
+           type->Icon.Name = strdup(lua_tostring(l, j + 1));
+           type->Icon.Icon = NULL;
+       } else if (!strcmp(value, "costs")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type->_Costs[CclGetResourceByName(value)] = 
gh_scm2int(gh_car(sublist));
+               sublist = gh_cdr(sublist);
+           }
+#endif
+       } else if (!strcmp(value, "improve-production")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           while (!gh_null_p(sublist)) {
+               value = gh_car(sublist);
+               sublist = gh_cdr(sublist);
+               type->ImproveIncomes[CclGetResourceByName(value)] =
+                       DefaultIncomes[CclGetResourceByName(value)] + 
gh_scm2int(gh_car(sublist));
+               sublist = gh_cdr(sublist);
+           }
+#endif
+       } else if (!strcmp(value, "construction")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           // FIXME: What if constructions aren't yet loaded?
+           type->Construction = ConstructionByIdent(lua_tostring(l, j + 1));
+       } else if (!strcmp(value, "speed")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_Speed = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "draw-level")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->DrawLevel = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "max-on-board")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->MaxOnBoard = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "hit-points")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_HitPoints = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "regeneration-rate")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_RegenerationRate = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "burn-percent")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->BurnPercent = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "burn-damage-rate")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->BurnDamageRate = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "max-mana")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_MaxMana = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "tile-size")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+           type->TileWidth = gh_scm2int(gh_car(sublist));
+           type->TileHeight = gh_scm2int(gh_cadr(sublist));
+#endif
+       } else if (!strcmp(value, "must-build-on-top")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           value = lua_tostring(l, j + 1);
+           auxtype = UnitTypeByIdent(value);
+           if (!auxtype) {
+               DebugLevel0("Build on top of undefined unit \"%s\".\n" _C_ str);
+               DebugCheck(1);
+           }
+           type->MustBuildOnTop = auxtype;
+       } else if (!strcmp(value, "not-selectable")) {
+           type->Selectable = 0;
+           --j;
+       } else if (!strcmp(value, "neutral-minimap-color")) {
+#if 0
+           sublist = gh_car(list);
+           list = gh_cdr(list);
+#ifdef USE_SDL_SURFACE
+           type->NeutralMinimapColorRGB.r = gh_scm2int(gh_car(sublist));
+           type->NeutralMinimapColorRGB.g = 
gh_scm2int(gh_car(gh_cdr(sublist)));
+           type->NeutralMinimapColorRGB.b = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(sublist))));
+#else
+           type->NeutralMinimapColorRGB.D24.a = gh_scm2int(gh_car(sublist));
+           type->NeutralMinimapColorRGB.D24.b = 
gh_scm2int(gh_car(gh_cdr(sublist)));
+           type->NeutralMinimapColorRGB.D24.c = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(sublist))));
+#endif
+#endif
+       } else if (!strcmp(value, "box-size")) {
+#if 0
+           sublist = gh_car(list);
            list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("corpse"))) {
+           type->BoxWidth = gh_scm2int(gh_car(sublist));
+           type->BoxHeight = gh_scm2int(gh_cadr(sublist));
+#endif
+       } else if (!strcmp(value, "num-directions")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->NumDirections = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "revealer")) {
+           type->Revealer = 1;
+           --j;
+       } else if (!strcmp(value, "sight-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_SightRange = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "computer-reaction-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->ReactRangeComputer = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "person-reaction-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->ReactRangePerson = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "armor")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_Armor = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "basic-damage")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_BasicDamage = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "piercing-damage")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_PiercingDamage = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "missile")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Missile.Name = strdup(lua_tostring(l, j + 1));
+           type->Missile.Missile = NULL;
+       } else if (!strcmp(value, "min-attack-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->MinAttackRange = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "max-attack-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->_AttackRange = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "priority")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Priority = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "annoy-computer-factor")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->AnnoyComputerFactor = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "decay-rate")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->DecayRate = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "points")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Points = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "demand")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Demand = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "supply")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->Supply = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "corpse")) {
+#if 0
            sublist = gh_car(list);
            list = gh_cdr(list);
            if (redefine) {
@@ -379,42 +1105,64 @@
            type->CorpseName = gh_scm2newstr(gh_car(sublist), NULL);
            type->CorpseType = NULL;
            type->CorpseScript = gh_scm2int(gh_cadr(sublist));
-       } else if (gh_eq_p(value, gh_symbol2scm("explode-when-killed"))) {
+#endif
+       } else if (!strcmp(value, "explode-when-killed")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
            type->ExplodeWhenKilled = 1;
-           type->Explosion.Name = gh_scm2newstr(gh_car(list), NULL);
+           type->Explosion.Name = strdup(lua_tostring(l, j + 1));
            type->Explosion.Missile = NULL;
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("type-land"))) {
+       } else if (!strcmp(value, "type-land")) {
            type->UnitType = UnitTypeLand;
-       } else if (gh_eq_p(value, gh_symbol2scm("type-fly"))) {
+           --j;
+       } else if (!strcmp(value, "type-fly")) {
            type->UnitType = UnitTypeFly;
-       } else if (gh_eq_p(value, gh_symbol2scm("type-naval"))) {
+           --j;
+       } else if (!strcmp(value, "type-naval")) {
            type->UnitType = UnitTypeNaval;
+           --j;
 
-       } else if (gh_eq_p(value, gh_symbol2scm("right-none"))) {
+       } else if (!strcmp(value, "right-none")) {
            type->MouseAction = MouseActionNone;
-       } else if (gh_eq_p(value, gh_symbol2scm("right-attack"))) {
+           --j;
+       } else if (!strcmp(value, "right-attack")) {
            type->MouseAction = MouseActionAttack;
-       } else if (gh_eq_p(value, gh_symbol2scm("right-move"))) {
+           --j;
+       } else if (!strcmp(value, "right-move")) {
            type->MouseAction = MouseActionMove;
-       } else if (gh_eq_p(value, gh_symbol2scm("right-harvest"))) {
+           --j;
+       } else if (!strcmp(value, "right-harvest")) {
            type->MouseAction = MouseActionHarvest;
-       } else if (gh_eq_p(value, gh_symbol2scm("right-spell-cast"))) {
+           --j;
+       } else if (!strcmp(value, "right-spell-cast")) {
            type->MouseAction = MouseActionSpellCast;
-       } else if (gh_eq_p(value, gh_symbol2scm("right-sail"))) {
+           --j;
+       } else if (!strcmp(value, "right-sail")) {
            type->MouseAction = MouseActionSail;
+           --j;
 
-       } else if (gh_eq_p(value, gh_symbol2scm("can-ground-attack"))) {
+       } else if (!strcmp(value, "can-ground-attack")) {
            type->GroundAttack = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-attack"))) {
+           --j;
+       } else if (!strcmp(value, "can-attack")) {
            type->CanAttack = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("repair-range"))) {
-           type->RepairRange = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("repair-hp"))) {
-           type->RepairHP = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("repair-costs"))) {
+           --j;
+       } else if (!strcmp(value, "repair-range")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->RepairRange = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "repair-hp")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->RepairHP = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "repair-costs")) {
+#if 0
            sublist = gh_car(list);
            list = gh_cdr(list);
            while (!gh_null_p(sublist)) {
@@ -423,83 +1171,107 @@
                type->RepairCosts[CclGetResourceByName(value)] = 
gh_scm2int(gh_car(sublist));
                sublist = gh_cdr(sublist);
            }
-       } else if (gh_eq_p(value, gh_symbol2scm("can-target-land"))) {
+#endif
+       } else if (!strcmp(value, "can-target-land")) {
            type->CanTarget |= CanTargetLand;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-target-sea"))) {
+           --j;
+       } else if (!strcmp(value, "can-target-sea")) {
            type->CanTarget |= CanTargetSea;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-target-air"))) {
+           --j;
+       } else if (!strcmp(value, "can-target-air")) {
            type->CanTarget |= CanTargetAir;
+           --j;
 
-       } else if (gh_eq_p(value, gh_symbol2scm("building"))) {
+       } else if (!strcmp(value, "building")) {
            type->Building = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("visible-under-fog"))) {
+           --j;
+       } else if (!strcmp(value, "visible-under-fog")) {
            type->VisibleUnderFog = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("builder-outside"))) {
+           --j;
+       } else if (!strcmp(value, "builder-outside")) {
            type->BuilderOutside = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("builder-lost"))) {
+           --j;
+       } else if (!strcmp(value, "builder-lost")) {
            type->BuilderLost = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("auto-build-rate"))) {
-           type->AutoBuildRate = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("shore-building"))) {
+           --j;
+       } else if (!strcmp(value, "auto-build-rate")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->AutoBuildRate = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "shore-building")) {
            type->ShoreBuilding = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("land-unit"))) {
+           --j;
+       } else if (!strcmp(value, "land-unit")) {
            type->LandUnit = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("air-unit"))) {
+           --j;
+       } else if (!strcmp(value, "air-unit")) {
            type->AirUnit = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("sea-unit"))) {
+           --j;
+       } else if (!strcmp(value, "sea-unit")) {
            type->SeaUnit = 1;
-       } else if (gh_eq_p(value, 
gh_symbol2scm("random-movement-probability"))) {
-           type->RandomMovementProbability = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("clicks-to-explode"))) {
-           type->ClicksToExplode = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("permanent-cloak"))) {
+           --j;
+       } else if (!strcmp(value, "random-movement-probability")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->RandomMovementProbability = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "clicks-to-explode")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->ClicksToExplode = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "permanent-cloak")) {
            type->PermanentCloak = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("detect-cloak"))) {
+           --j;
+       } else if (!strcmp(value, "detect-cloak")) {
            type->DetectCloak = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("transporter"))) {
+           --j;
+       } else if (!strcmp(value, "transporter")) {
            type->Transporter = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("coward"))) {
+           --j;
+       } else if (!strcmp(value, "coward")) {
            type->Coward = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-gather-resource"))) {
-           sublist = gh_car(list);
-           list = gh_cdr(list);
+           --j;
+       } else if (!strcmp(value, "can-gather-resource")) {
            res = (ResourceInfo*)malloc(sizeof(ResourceInfo));
            memset(res, 0, sizeof(ResourceInfo));
+#if 0
            while (!gh_null_p(sublist)) {
                value = gh_car(sublist);
                sublist = gh_cdr(sublist);
-               if (gh_eq_p(value, gh_symbol2scm("resource-id"))) {
+               if (!strcmp(value, "resource-id")) {
                    res->ResourceId = CclGetResourceByName(gh_car(sublist));
                    type->ResInfo[res->ResourceId] = res;
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("resource-step"))) {
+               } else if (!strcmp(value, "resource-step")) {
                    res->ResourceStep = gh_scm2int(gh_car(sublist));
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("final-resource"))) {
+               } else if (!strcmp(value, "final-resource")) {
                    res->FinalResource = CclGetResourceByName(gh_car(sublist));
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("wait-at-resource"))) {
+               } else if (!strcmp(value, "wait-at-resource")) {
                    res->WaitAtResource = gh_scm2int(gh_car(sublist));
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("wait-at-depot"))) {
+               } else if (!strcmp(value, "wait-at-depot")) {
                    res->WaitAtDepot = gh_scm2int(gh_car(sublist));
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("resource-capacity"))) {
+               } else if (!strcmp(value, "resource-capacity")) {
                    res->ResourceCapacity = gh_scm2int(gh_car(sublist));
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("terrain-harvester"))) {
+               } else if (!strcmp(value, "terrain-harvester")) {
                    res->TerrainHarvester = 1;
-               } else if (gh_eq_p(value, gh_symbol2scm("lose-resources"))) {
+               } else if (!strcmp(value, "lose-resources")) {
                    res->LoseResources = 1;
-               } else if (gh_eq_p(value, 
gh_symbol2scm("harvest-from-outside"))) {
+               } else if (!strcmp(value, "harvest-from-outside")) {
                    res->HarvestFromOutside = 1;
-               } else if (gh_eq_p(value, gh_symbol2scm("file-when-empty"))) {
+               } else if (!strcmp(value, "file-when-empty")) {
                    res->FileWhenEmpty = gh_scm2newstr(gh_car(sublist),0);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("file-when-loaded"))) {
+               } else if (!strcmp(value, "file-when-loaded")) {
                    res->FileWhenLoaded = gh_scm2newstr(gh_car(sublist),0);
                    sublist = gh_cdr(sublist);
                } else {
@@ -513,24 +1285,34 @@
                res->FinalResource = res->ResourceId;
            }
            DebugCheck(!res->ResourceId);
-       } else if (gh_eq_p(value, gh_symbol2scm("gives-resource"))) {
-           type->GivesResource = CclGetResourceByName(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("max-workers"))) {
-           type->MaxWorkers = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("can-harvest"))) {
+#endif
+       } else if (!strcmp(value, "gives-resource")) {
+           lua_pushvalue(l, j + 1);
+           type->GivesResource = CclGetResourceByName(l);
+           lua_pop(l, 1);
+       } else if (!strcmp(value, "max-workers")) {
+           if (!lua_isnumber(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           type->MaxWorkers = lua_tonumber(l, j + 1);
+       } else if (!strcmp(value, "can-harvest")) {
            type->CanHarvest = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-store"))) {
+           --j;
+       } else if (!strcmp(value, "can-store")) {
+#if 0
            sublist = gh_car(list);
            list = gh_cdr(list);
            while (!gh_null_p(sublist)) {
                type->CanStore[CclGetResourceByName(gh_car(sublist))] = 1;
                sublist = gh_cdr(sublist);
            }
-       } else if (gh_eq_p(value, gh_symbol2scm("vanishes"))) {
+#endif
+       } else if (!strcmp(value, "vanishes")) {
            type->Vanishes = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("can-cast-spell"))) {
+           --j;
+       } else if (!strcmp(value, "can-cast-spell")) {
+#if 0
            //
            //    Warning: can-cast-spell should only be used AFTER all spells
            //    have been defined. FIXME: MaxSpellType=500 or something?
@@ -553,7 +1335,9 @@
                sublist = gh_cdr(sublist);
                type->Magic = 1;
            }
-       } else if (gh_eq_p(value, gh_symbol2scm("can-target-flag"))) {
+#endif
+       } else if (!strcmp(value, "can-target-flag")) {
+#if 0
            //
            //    Warning: can-target-flag should only be used AFTER all bool 
flags
            //    have been defined.
@@ -564,7 +1348,7 @@
                value = gh_car(sublist);
                sublist = gh_cdr(sublist);
                for (i = 0; i < NumberBoolFlag; i++) {
-                   if (gh_eq_p(value, gh_symbol2scm(BoolFlagName[i]))) {
+                   if (!strcmp(value, BoolFlagName[i]))) {
                        type->CanTargetFlag[i] = Scm2Condition(gh_car(sublist));
                        sublist = gh_cdr(sublist);
                        break;
@@ -576,11 +1360,15 @@
                printf("\n%s\n", type->Name);
                errl("Unsupported flag tag for can-target-flag", value);
            }
-       } else if (gh_eq_p(value, gh_symbol2scm("selectable-by-rectangle"))) {
+#endif
+       } else if (!strcmp(value, "selectable-by-rectangle")) {
            type->SelectableByRectangle = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("teleporter"))) {
+           --j;
+       } else if (!strcmp(value, "teleporter")) {
            type->Teleporter = 1;
-       } else if (gh_eq_p(value, gh_symbol2scm("sounds"))) {
+           --j;
+       } else if (!strcmp(value, "sounds")) {
+#if 0
            sublist = gh_car(list);
            list = gh_cdr(list);
            while (!gh_null_p(sublist)) {
@@ -588,35 +1376,35 @@
                value = gh_car(sublist);
                sublist = gh_cdr(sublist);
 
-               if (gh_eq_p(value, gh_symbol2scm("selected"))) {
+               if (!strcmp(value, "selected")) {
                    if (redefine) {
                        free(type->Sound.Selected.Name);
                    }
                    type->Sound.Selected.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("acknowledge"))) {
+               } else if (!strcmp(value, "acknowledge")) {
                    if (redefine) {
                        free(type->Sound.Acknowledgement.Name);
                    }
                    type->Sound.Acknowledgement.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("ready"))) {
+               } else if (!strcmp(value, "ready")) {
                    if (redefine) {
                        free(type->Sound.Ready.Name);
                    }
                    type->Sound.Ready.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("repair"))) {
+               } else if (!strcmp(value, "repair")) {
                    if (redefine) {
                        free(type->Sound.Repair.Name);
                    }
                    type->Sound.Repair.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("harvest"))) {
+               } else if (!strcmp(value, "harvest")) {
                    int res;
                    char* name;
 
@@ -637,21 +1425,21 @@
                    type->Sound.Harvest[res].Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("help"))) {
+               } else if (!strcmp(value, "help")) {
                    if (redefine) {
                        free(type->Sound.Help.Name);
                    }
                    type->Sound.Help.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("dead"))) {
+               } else if (!strcmp(value, "dead")) {
                    if (redefine) {
                        free(type->Sound.Dead.Name);
                    }
                    type->Sound.Dead.Name = gh_scm2newstr(
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
-               } else if (gh_eq_p(value, gh_symbol2scm("attack"))) {
+               } else if (!strcmp(value, "attack")) {
                    if (redefine) {
                        free(type->Weapon.Attack.Name);
                    }
@@ -659,41 +1447,46 @@
                        gh_car(sublist), NULL);
                    sublist = gh_cdr(sublist);
                } else {
-                   errl("Unsupported sound tag", value);
+                   lua_pushfstring(l, "Unsupported sound tag: %s", value);
+                   lua_error(l);
                }
            }
+#endif
        } else {
-            for (i = 0; i < NumberBoolFlag; i++) { // User defined bool flags
-                if (gh_eq_p(value, gh_symbol2scm(BoolFlagName[i]))) {
-                    type->BoolFlag[i] = 1;
-                    break;
-               }
-            }
+           for (i = 0; i < NumberBoolFlag; ++i) { // User defined bool flags
+               if (!strcmp(value, BoolFlagName[i])) {
+                   type->BoolFlag[i] = 1;
+                   --j;
+                   break;
+               }
+           }
             if (i != NumberBoolFlag) {
-                continue;
+               continue;
            }
-          // FIXME: this leaves a half initialized unit-type
-          printf("\n%s\n",type->Name);
-          errl("Unsupported tag", value);
-          DebugCheck(1);
+           // FIXME: this leaves a half initialized unit-type
+           printf("\n%s\n",type->Name);
+           lua_pushfstring(l, "Unsupported tag: %s", value);
+           lua_error(l);
+           DebugCheck(1);
        }
     }
 
     // FIXME: try to simplify/combine the flags instead
     if (type->MouseAction == MouseActionAttack && !type->CanAttack) {
-       printf("Unit-type `%s': right-attack is set, but can-attack is not\n", 
type->Name);
-       // ugly way to show the line number
-       errl("", SCM_UNSPECIFIED); 
+       lua_pushfstring(l, "Unit-type `%s': right-attack is set, but can-attack 
is not\n", type->Name);
+       lua_error(l);
     }
 
-    return SCM_UNSPECIFIED;
+    return 0;
 }
+#endif
 
 /**
 **     Parse unit-stats.
 **
 **     @param list     List describing the unit-stats.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineUnitStats(SCM list)
 {
     SCM value;
@@ -778,12 +1571,15 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+#endif
 
 // ----------------------------------------------------------------------------
 
 /**
 **     Access unit-type object
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 global UnitType* CclGetUnitType(SCM ptr)
 {
     char* str;
@@ -802,6 +1598,8 @@
         return 0;
     }
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Print the unit-type object
@@ -809,6 +1607,7 @@
 **     @param ptr      Scheme object.
 **     @param f        Output structure.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local void CclUnitTypePrin1(SCM ptr, struct gen_printio* f)
 {
 #ifndef USE_GUILE
@@ -830,6 +1629,8 @@
     gput_st(f,buf);
 #endif
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Get unit-type structure.
@@ -838,6 +1639,7 @@
 **
 **     @return         Unit-type structure.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclUnitType(SCM ident)
 {
     char* str;
@@ -854,12 +1656,15 @@
         return SCM_BOOL_F;
     }
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Get all unit-type structures.
 **
 **     @return         An array of all unit-type structures.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclUnitTypeArray(void)
 {
     SCM array;
@@ -874,6 +1679,8 @@
     }
     return array;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Get the ident of the unit-type structure.
@@ -882,6 +1689,7 @@
 **
 **     @return         The identifier of the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclGetUnitTypeIdent(SCM ptr)
 {
     const UnitType* type;
@@ -891,6 +1699,8 @@
     value = gh_str02scm(type->Ident);
     return value;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Get the name of the unit-type structure.
@@ -899,6 +1709,7 @@
 **
 **     @return         The name of the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclGetUnitTypeName(SCM ptr)
 {
     const UnitType* type;
@@ -908,6 +1719,8 @@
     value = gh_str02scm(type->Name);
     return value;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Set the name of the unit-type structure.
@@ -917,6 +1730,7 @@
 **
 **     @return         The name of the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetUnitTypeName(SCM ptr, SCM name)
 {
     UnitType* type;
@@ -927,6 +1741,8 @@
 
     return name;
 }
+#elif defined(USE_LUA)
+#endif
 
 // FIXME: write the missing access functions
 
@@ -937,6 +1753,7 @@
 **
 **     @return         The property of the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclGetUnitTypeProperty(SCM ptr)
 {
     const UnitType* type;
@@ -944,6 +1761,8 @@
     type = CclGetUnitType(ptr);
     return type->Property;
 }
+#elif defined(USE_LUA)
+#endif
 
 /**
 **     Set the property of the unit-type structure.
@@ -953,6 +1772,7 @@
 **
 **     @return         The property of the unit-type.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclSetUnitTypeProperty(SCM ptr, SCM property)
 {
     UnitType* type;
@@ -1068,7 +1888,7 @@
     resource = NULL;
     str = gh_scm2newstr(gh_car(list), NULL);
     list = gh_cdr(list);
-    anims = calloc(1,sizeof(Animations));
+    anims = calloc(1, sizeof(Animations));
 
     while (!gh_null_p(list)) {
        id = gh_car(list);
@@ -1128,7 +1948,7 @@
                }
            }
            if (res == MaxCosts) {
-               errl("Resource not found", value);
+               errl("Resource not found", resource);
            }
            free(name);
            if (anims->Harvest[res]) {
@@ -1150,12 +1970,159 @@
 
     return SCM_UNSPECIFIED;
 }
+#elif defined(USE_LUA)
+local int CclDefineAnimations(lua_State* l)
+{
+    const char* str;
+    const char* id;
+    const char* resource;
+    Animations* anims;
+    Animation* anim;
+    Animation* t;
+    int i;
+    int frame;
+    int args;
+    int j;
+    int subargs;
+    int k;
+
+    args = lua_gettop(l);
+    j = 0;
+
+    resource = NULL;
+    if (!lua_isstring(l, j + 1)) {
+       lua_pushstring(l, "incorrect argument");
+       lua_error(l);
+    }
+    str = lua_tostring(l, j + 1);
+    ++j;
+    anims = calloc(1, sizeof(Animations));
+
+    for (; j < args; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       id = lua_tostring(l, j + 1);
+       ++j;
+       if (!strcmp(id, "harvest")) {
+           if (!lua_isstring(l, j + 1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           resource = lua_tostring(l, j + 1);
+           ++j;
+       }
+
+       if (!lua_istable(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+       subargs = luaL_getn(l, j + 1);
+       t = anim = malloc(subargs * sizeof(Animation));
+       frame = 0;
+       for (k = 0; k < subargs; ++k) {
+           lua_rawgeti(l, j + 1, k + 1);
+           if (!lua_istable(l, -1) || luaL_getn(l, -1) != 4) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           lua_rawgeti(l, -1, 1);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           t->Flags = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, -1, 2);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           t->Pixel = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, -1, 3);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           t->Sleep = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           lua_rawgeti(l, -1, 4);
+           if (!lua_isnumber(l, -1)) {
+               lua_pushstring(l, "incorrect argument");
+               lua_error(l);
+           }
+           i = lua_tonumber(l, -1);
+           lua_pop(l, 1);
+           t->Frame = i - frame;
+           frame = i;
+           if (t->Flags & AnimationRestart) {
+               frame = 0;
+           }
+           ++t;
+           lua_pop(l, 1);
+       }
+       t[-1].Flags |= 0x80;            // Marks end of list
+
+       if (!strcmp(id, "still")) {
+           if (anims->Still) {
+               free(anims->Still);
+           }
+           anims->Still = anim;
+       } else if (!strcmp(id, "move")) {
+           if (anims->Move) {
+               free(anims->Move);
+           }
+           anims->Move = anim;
+       } else if (!strcmp(id, "attack")) {
+           if (anims->Attack) {
+               free(anims->Attack);
+           }
+           anims->Attack = anim;
+       } else if (!strcmp(id, "repair")) {
+           if (anims->Repair) {
+               free(anims->Repair);
+           }
+           anims->Repair = anim;
+       } else if (!strcmp(id, "harvest")) {
+           int res;
+
+           for (res = 0; res < MaxCosts; ++res) {
+               if (!strcmp(resource, DefaultResourceNames[res])) {
+                   break;
+               }
+           }
+           if (res == MaxCosts) {
+               lua_pushfstring(l, "Resource not found: %s", resource);
+               lua_error(l);
+           }
+           if (anims->Harvest[res]) {
+               free(anims->Harvest[res]);
+           }
+           anims->Harvest[res] = anim;
+       } else if (!strcmp(id, "die")) {
+           if (anims->Die) {
+               free(anims->Die);
+           }
+           anims->Die = anim;
+       } else {
+           lua_pushfstring(l, "Unsupported tag: %s", id);
+           lua_error(l);
+       }
+    }
+
+    *(Animations**)hash_add(AnimationsHash, str) = anims;
+    return 0;
+}
+#endif
 
 /*
 **     Define boolean flag.
 **
 **     @param list : list of flags' name.
 */
+#if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineBoolFlags(SCM list)
 {
     char* str;
@@ -1167,7 +2134,7 @@
     while (!gh_null_p(list)) {
         str = gh_scm2newstr(gh_car(list), NULL);
         list = gh_cdr(list);
-        for (i = 0; i < NumberBoolFlag; i++) {
+        for (i = 0; i < NumberBoolFlag; ++i) {
             if (!strcmp(str, BoolFlagName[i])) {
                 DebugLevel0("Warning, Bool flags already defined\n");
                 break;
@@ -1176,12 +2143,43 @@
         if (i != NumberBoolFlag) {
             break;
        }
-        BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) * sizeof 
(*BoolFlagName));
+        BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) * 
sizeof(*BoolFlagName));
         BoolFlagName[NumberBoolFlag++] = str;
     }
     return SCM_UNSPECIFIED;
 }
 #elif defined(USE_LUA)
+local int CclDefineBoolFlags(lua_State* l)
+{
+    char* str;
+    int i;
+    int args;
+    int j;
+
+    if (NumberBoolFlag != 0) {
+        DebugLevel0("Warning, Redefine Bool flags\n");
+    }
+    args = lua_gettop(l);
+    for (j = 0; j < args; ++j) {
+       if (!lua_isstring(l, j + 1)) {
+           lua_pushstring(l, "incorrect argument");
+           lua_error(l);
+       }
+        str = strdup(lua_tostring(l, j + 1));
+        for (i = 0; i < NumberBoolFlag; ++i) {
+            if (!strcmp(str, BoolFlagName[i])) {
+                DebugLevel0("Warning, Bool flags already defined\n");
+                break;
+            }
+       }
+        if (i != NumberBoolFlag) {
+            break;
+       }
+        BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) * 
sizeof(*BoolFlagName));
+        BoolFlagName[NumberBoolFlag++] = str;
+    }
+    return 0;
+}
 #endif
 
 // ----------------------------------------------------------------------------
@@ -1218,9 +2216,9 @@
 
     gh_new_procedureN("define-animations", CclDefineAnimations);
 #elif defined(USE_LUA)
-//    lua_register(Lua, "DefineUnitType", CclDefineUnitType);
+    lua_register(Lua, "DefineUnitType", CclDefineUnitType);
 //    lua_register(Lua, "DefineUnitStats", CclDefineUnitStats);
-//    lua_register(Lua, "DefineBoolFlags", CclDefineBoolFlags);
+    lua_register(Lua, "DefineBoolFlags", CclDefineBoolFlags);
 
 //    SiodUnitTypeTag = CclMakeSmobType("UnitType");
 
@@ -1238,7 +2236,7 @@
 
     lua_register(Lua, "DefineUnitTypeWcNames", CclDefineUnitTypeWcNames);
 
-//    lua_register(Lua, "DefineAnimations", CclDefineAnimations);
+    lua_register(Lua, "DefineAnimations", CclDefineAnimations);
 
 #endif
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]