[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src ui/icons.c unit/ccl_unit.c unit/c...
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src ui/icons.c unit/ccl_unit.c unit/c... |
Date: |
Thu, 20 Nov 2003 14:19:26 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/11/20 14:19:25
Modified files:
src/ui : icons.c
src/unit : ccl_unit.c ccl_unittype.c upgrade.c
Log message:
Converted to LuaTo* functions, cleaned up spaces
Patches:
Index: stratagus/src/ui/icons.c
diff -u stratagus/src/ui/icons.c:1.56 stratagus/src/ui/icons.c:1.57
--- stratagus/src/ui/icons.c:1.56 Wed Nov 19 20:58:56 2003
+++ stratagus/src/ui/icons.c Thu Nov 20 14:19:24 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: icons.c,v 1.56 2003/11/20 01:58:56 jsalmon3 Exp $
+// $Id: icons.c,v 1.57 2003/11/20 19:19:24 jsalmon3 Exp $
//@{
@@ -432,7 +432,7 @@
int i;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: icons $Id: icons.c,v 1.56 2003/11/20 01:58:56
jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: icons $Id: icons.c,v 1.57 2003/11/20 19:19:24
jsalmon3 Exp $\n\n");
//
// Mapping the original icon numbers in puds to our internal strings
@@ -555,48 +555,28 @@
// Identifier
- if (!lua_isstring(l, j + 1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- ident = lua_tostring(l, j + 1);
+ ident = LuaToString(l, j + 1);
++j;
//
// Parse the arguments, tagged format.
//
for (; j < args; ++j) {
- if (!lua_isstring(l, j + 1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- value = lua_tostring(l, j + 1);
+ value = LuaToString(l, j + 1);
++j;
if (!strcmp(value, "tileset")) {
- if (!lua_isstring(l, j + 1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- tileset = lua_tostring(l, j + 1);
+ tileset = LuaToString(l, j + 1);
} else if (!strcmp(value, "size")) {
if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
lua_rawgeti(l, j + 1, 1);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- width = lua_tonumber(l, -1);
+ width = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, j + 1, 2);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- height = lua_tonumber(l, -1);
+ height = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "normal")) {
if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
@@ -604,18 +584,10 @@
lua_error(l);
}
lua_rawgeti(l, j + 1, 1);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- index = lua_tonumber(l, -1);
+ index = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, j + 1, 2);
- if (!lua_isstring(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- filename = lua_tostring(l, -1);
+ filename = LuaToString(l, -1);
lua_pop(l, 1);
} else {
lua_pushfstring(l, "Unsupported tag: %s", value);
@@ -653,13 +625,13 @@
#elif defined(USE_LUA)
local int CclDefineIconAlias(lua_State* l)
{
- if (lua_gettop(l) != 2 || !lua_isstring(l, 1) || !lua_isstring(l, 2)) {
+ if (lua_gettop(l) != 2) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
IconAliases = realloc(IconAliases, sizeof(char*) * 2 * (NumIconAliases +
1));
- IconAliases[NumIconAliases * 2 + 0] = strdup(lua_tostring(l, 1));
- IconAliases[NumIconAliases * 2 + 1] = strdup(lua_tostring(l, 2));
+ IconAliases[NumIconAliases * 2 + 0] = strdup(LuaToString(l, 1));
+ IconAliases[NumIconAliases * 2 + 1] = strdup(LuaToString(l, 2));
++NumIconAliases;
return 0;
@@ -722,11 +694,7 @@
}
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++ = strdup(LuaToString(l, j + 1));
}
*cp = NULL;
@@ -751,12 +719,12 @@
#elif defined(USE_LUA)
local int CclSetIconSize(lua_State* l)
{
- if (lua_gettop(l) != 2 || !lua_isnumber(l, 1) || !lua_isnumber(l, 2)) {
+ if (lua_gettop(l) != 2) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
- IconWidth = lua_tonumber(l, 1);
- IconHeight = lua_tonumber(l, 2);
+ IconWidth = LuaToNumber(l, 1);
+ IconHeight = LuaToNumber(l, 2);
return 0;
}
#endif
Index: stratagus/src/unit/ccl_unit.c
diff -u stratagus/src/unit/ccl_unit.c:1.78 stratagus/src/unit/ccl_unit.c:1.79
--- stratagus/src/unit/ccl_unit.c:1.78 Wed Nov 19 20:01:49 2003
+++ stratagus/src/unit/ccl_unit.c Thu Nov 20 14:19:25 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_unit.c,v 1.78 2003/11/20 01:01:49 jsalmon3 Exp $
+// $Id: ccl_unit.c,v 1.79 2003/11/20 19:19:25 jsalmon3 Exp $
//@{
@@ -88,12 +88,12 @@
{
int old;
- if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+ if (lua_gettop(l) != 1) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
old = XpDamage;
- XpDamage = lua_toboolean(l, 1);
+ XpDamage = LuaToBoolean(l, 1);
lua_pushboolean(l, old);
return 1;
@@ -122,12 +122,12 @@
{
int old;
- if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+ if (lua_gettop(l) != 1) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
old = EnableTrainingQueue;
- EnableTrainingQueue = lua_toboolean(l, 1);
+ EnableTrainingQueue = LuaToBoolean(l, 1);
lua_pushboolean(l, old);
return 1;
@@ -156,12 +156,12 @@
{
int old;
- if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+ if (lua_gettop(l) != 1) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
old = EnableBuildingCapture;
- EnableBuildingCapture = lua_toboolean(l, 1);
+ EnableBuildingCapture = LuaToBoolean(l, 1);
lua_pushboolean(l, old);
return 1;
@@ -190,12 +190,12 @@
{
int old;
- if (lua_gettop(l) != 1 || !lua_isboolean(l, 1)) {
+ if (lua_gettop(l) != 1) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
old = RevealAttacker;
- RevealAttacker = lua_toboolean(l, 1);
+ RevealAttacker = LuaToBoolean(l, 1);
lua_pushboolean(l, old);
return 1;
@@ -525,7 +525,7 @@
if (gh_eq_p(value, gh_symbol2scm("unit-none"))) {
unit->Data.Train.What[i] = NULL;
} else {
- char *ident;
+ char* ident;
ident = gh_scm2newstr(value, NULL);
unit->Data.Train.What[i] = UnitTypeByIdent(ident);
free(ident);
@@ -639,13 +639,13 @@
} else if (gh_eq_p(value, gh_symbol2scm("current-sight-range"))) {
unit->CurrentSightRange = gh_scm2int(gh_car(list));
list = gh_cdr(list);
- } else if (gh_eq_p(value, gh_symbol2scm("host-info"))) {
+ } else if (gh_eq_p(value, gh_symbol2scm("host-info"))) {
value = gh_car(list);
list = gh_cdr(list);
MapMarkSight(player, gh_scm2int(gh_car(value)),
gh_scm2int(gh_cadr(value)),
gh_scm2int(gh_cadr(gh_cdr(value))),
gh_scm2int(gh_cadr(gh_cdr(gh_cdr(value)))),
- unit->CurrentSightRange);
+ unit->CurrentSightRange);
} else if (gh_eq_p(value, gh_symbol2scm("tile"))) {
value = gh_car(list);
list = gh_cdr(list);
@@ -915,7 +915,7 @@
if (unit->Removed && unit->Type->Revealer) {
MapMarkUnitSight(unit);
}
-
+
// Place on map
if (!unit->Removed && !unit->Destroyed && !unit->Type->Vanishes) {
unit->Removed = 1;
@@ -928,7 +928,7 @@
}
// Fix Colors for rescued units.
if (unit->RescuedFrom) {
- unit->Colors = &unit->RescuedFrom->UnitColors;
+ unit->Colors = &unit->RescuedFrom->UnitColors;
}
DebugLevel3Fn("unit #%d parsed\n" _C_ slot);
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.115
stratagus/src/unit/ccl_unittype.c:1.116
--- stratagus/src/unit/ccl_unittype.c:1.115 Thu Nov 20 00:39:00 2003
+++ stratagus/src/unit/ccl_unittype.c Thu Nov 20 14:19:25 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_unittype.c,v 1.115 2003/11/20 05:39:00 jsalmon3 Exp $
+// $Id: ccl_unittype.c,v 1.116 2003/11/20 19:19:25 jsalmon3 Exp $
//@{
@@ -65,7 +65,7 @@
#elif defined(USE_LUA)
#endif
-global char **BoolFlagName = NULL; /// Name of user defined flag
+global char** BoolFlagName = NULL; /// Name of user defined flag
global int NumberBoolFlag = 0; /// Number of defined flags.
/*----------------------------------------------------------------------------
@@ -97,11 +97,7 @@
int i;
const char* value;
- if (!lua_isstring(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- value = lua_tostring(l, -1);
+ value = LuaToString(l, -1);
for (i = 0; i < MaxCosts; ++i) {
if (!strcmp(value, DefaultResourceNames[i])) {
return i;
@@ -705,7 +701,7 @@
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);
+ errl("", SCM_UNSPECIFIED);
}
return SCM_UNSPECIFIED;
@@ -730,11 +726,7 @@
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));
+ str = strdup(LuaToString(l, j + 1));
++j;
#ifdef DEBUG
@@ -770,30 +762,18 @@
// 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);
+ value = LuaToString(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));
+ type->Name = strdup(LuaToString(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));
+ type->SameSprite = strdup(LuaToString(l, j + 1));
} else if (!strcmp(value, "files")) {
if (!lua_istable(l, j + 1)) {
lua_pushstring(l, "incorrect argument");
@@ -802,11 +782,7 @@
subargs = luaL_getn(l, j + 1);
for (k = 0; k < subargs; ++k) {
lua_rawgeti(l, j + 1, k + 1);
- if (!lua_isstring(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- value = lua_tostring(l, -1);
+ value = LuaToString(l, -1);
lua_pop(l, 1);
++k;
@@ -829,11 +805,7 @@
free(type->File[i]);
}
lua_rawgeti(l, j + 1, k + 1);
- if (!lua_isstring(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->File[i] = strdup(lua_tostring(l, -1));
+ type->File[i] = strdup(LuaToString(l, -1));
lua_pop(l, 1);
}
} else if (!strcmp(value, "shadow")) {
@@ -868,34 +840,18 @@
lua_error(l);
}
lua_rawgeti(l, j + 1, 1);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->Width = lua_tonumber(l, -1);
+ type->Width = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, j + 1, 2);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->Height = lua_tonumber(l, -1);
+ type->Height = LuaToNumber(l, -1);
lua_pop(l, 1);
} 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));
+ type->Animations = AnimationsByIdent(LuaToString(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.Name = strdup(LuaToString(l, j + 1));
type->Icon.Icon = NULL;
} else if (!strcmp(value, "costs")) {
#if 0
@@ -921,85 +877,37 @@
}
#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));
+ type->Construction = ConstructionByIdent(LuaToString(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);
+ type->_Speed = LuaToNumber(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);
+ type->DrawLevel = LuaToNumber(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);
+ type->MaxOnBoard = LuaToNumber(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);
+ type->_HitPoints = LuaToNumber(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);
+ type->_RegenerationRate = LuaToNumber(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);
+ type->BurnPercent = LuaToNumber(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);
+ type->BurnDamageRate = LuaToNumber(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);
+ type->_MaxMana = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "tile-size")) {
if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
lua_pushstring(l, "incorrect argument");
lua_error(l);
}
lua_rawgeti(l, j + 1, 1);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->TileWidth = lua_tonumber(l, -1);
+ type->TileWidth = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, j + 1, 2);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->TileHeight = lua_tonumber(l, -1);
+ type->TileHeight = LuaToNumber(l, -1);
lua_pop(l, 1);
} 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);
+ value = LuaToString(l, j + 1);
auxtype = UnitTypeByIdent(value);
if (!auxtype) {
DebugLevel0("Build on top of undefined unit \"%s\".\n" _C_ str);
@@ -1029,119 +937,47 @@
lua_error(l);
}
lua_rawgeti(l, j + 1, 1);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->BoxWidth = lua_tonumber(l, -1);
+ type->BoxWidth = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, j + 1, 2);
- if (!lua_isnumber(l, -1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- type->BoxHeight = lua_tonumber(l, -1);
+ type->BoxHeight = LuaToNumber(l, -1);
lua_pop(l, 1);
} 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);
+ type->NumDirections = LuaToNumber(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);
+ type->_SightRange = LuaToNumber(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);
+ type->ReactRangeComputer = LuaToNumber(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);
+ type->ReactRangePerson = LuaToNumber(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);
+ type->_Armor = LuaToNumber(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);
+ type->_BasicDamage = LuaToNumber(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);
+ type->_PiercingDamage = LuaToNumber(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.Name = strdup(LuaToString(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);
+ type->MinAttackRange = LuaToNumber(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);
+ type->_AttackRange = LuaToNumber(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);
+ type->Priority = LuaToNumber(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);
+ type->AnnoyComputerFactor = LuaToNumber(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);
+ type->DecayRate = LuaToNumber(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);
+ type->Points = LuaToNumber(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);
+ type->Demand = LuaToNumber(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);
+ type->Supply = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "corpse")) {
#if 0
sublist = gh_car(list);
@@ -1154,12 +990,8 @@
type->CorpseScript = gh_scm2int(gh_cadr(sublist));
#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 = strdup(lua_tostring(l, j + 1));
+ type->Explosion.Name = strdup(LuaToString(l, j + 1));
type->Explosion.Missile = NULL;
} else if (!strcmp(value, "type-land")) {
type->UnitType = UnitTypeLand;
@@ -1197,17 +1029,9 @@
type->CanAttack = 1;
--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);
+ type->RepairRange = LuaToNumber(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);
+ type->RepairHP = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "repair-costs")) {
#if 0
sublist = gh_car(list);
@@ -1242,11 +1066,7 @@
type->BuilderLost = 1;
--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);
+ type->AutoBuildRate = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "shore-building")) {
type->ShoreBuilding = 1;
--j;
@@ -1260,17 +1080,9 @@
type->SeaUnit = 1;
--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);
+ type->RandomMovementProbability = LuaToNumber(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);
+ type->ClicksToExplode = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "permanent-cloak")) {
type->PermanentCloak = 1;
--j;
@@ -1338,11 +1150,7 @@
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);
+ type->MaxWorkers = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "can-harvest")) {
type->CanHarvest = 1;
--j;
@@ -1507,7 +1315,7 @@
break;
}
}
- if (i != NumberBoolFlag) {
+ if (i != NumberBoolFlag) {
continue;
}
// FIXME: this leaves a half initialized unit-type
@@ -1546,7 +1354,7 @@
type = UnitTypeByIdent(str = gh_scm2newstr(gh_car(list), NULL));
DebugCheck(!type);
-
+
free(str);
list = gh_cdr(list);
i = gh_scm2int(gh_car(list));
@@ -1634,15 +1442,15 @@
// Be kind allow also strings or symbols
if ((str = CclConvertToString(ptr)) != NULL) {
- DebugLevel3("CclGetUnitType: %s\n"_C_ str);
- type = UnitTypeByIdent(str);
- free(str);
- return type;
+ DebugLevel3("CclGetUnitType: %s\n"_C_ str);
+ type = UnitTypeByIdent(str);
+ free(str);
+ return type;
} else if (CclGetSmobType(ptr) == SiodUnitTypeTag) {
- return CclGetSmobData(ptr);
+ return CclGetSmobData(ptr);
} else {
- errl("CclGetUnitType: not an unit-type", ptr);
- return 0;
+ errl("CclGetUnitType: not an unit-type", ptr);
+ return 0;
}
}
#elif defined(USE_LUA)
@@ -1664,13 +1472,13 @@
type = CclGetUnitType(ptr);
if (type) {
- if (type->Ident) {
- sprintf(buf, "#<UnitType %p '%s'>", type, type->Ident);
- } else {
- sprintf(buf, "#<UnitType %p '(null)'>", type);
- }
+ if (type->Ident) {
+ sprintf(buf, "#<UnitType %p '%s'>", type, type->Ident);
+ } else {
+ sprintf(buf, "#<UnitType %p '(null)'>", type);
+ }
} else {
- sprintf(buf, "#<UnitType NULL>");
+ sprintf(buf, "#<UnitType NULL>");
}
gput_st(f,buf);
@@ -1691,16 +1499,16 @@
{
char* str;
UnitType* type;
-
+
str = CclConvertToString(ident);
if (str) {
- type = UnitTypeByIdent(str);
- printf("CclUnitType: '%s' -> '%ld'\n", str, (long)type);
- free(str);
- return CclMakeSmobObj(SiodUnitTypeTag, type);
+ type = UnitTypeByIdent(str);
+ printf("CclUnitType: '%s' -> '%ld'\n", str, (long)type);
+ free(str);
+ return CclMakeSmobObj(SiodUnitTypeTag, type);
} else {
- errl("CclUnitType: no unittype by ident: ", ident);
- return SCM_BOOL_F;
+ errl("CclUnitType: no unittype by ident: ", ident);
+ return SCM_BOOL_F;
}
}
#elif defined(USE_LUA)
@@ -1721,8 +1529,8 @@
array = cons_array(gh_int2scm(UnitTypeMax), NIL);
for (i = 0; i < UnitTypeMax; ++i) {
- value = CclMakeSmobObj(SiodUnitTypeTag, &UnitTypes[i]);
- gh_vector_set_x(array, gh_int2scm(i), value);
+ value = CclMakeSmobObj(SiodUnitTypeTag, &UnitTypes[i]);
+ gh_vector_set_x(array, gh_int2scm(i), value);
}
return array;
}
@@ -1900,11 +1708,7 @@
}
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++ = strdup(LuaToString(l, j + 1));
}
*cp = NULL;
@@ -2037,27 +1841,15 @@
j = 0;
resource = NULL;
- if (!lua_isstring(l, j + 1)) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- str = lua_tostring(l, j + 1);
+ str = LuaToString(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);
+ id = LuaToString(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);
+ resource = LuaToString(l, j + 1);
++j;
}
@@ -2075,32 +1867,16 @@
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);
+ t->Flags = LuaToNumber(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);
+ t->Pixel = LuaToNumber(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);
+ t->Sleep = LuaToNumber(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);
+ i = LuaToNumber(l, -1);
lua_pop(l, 1);
t->Frame = i - frame;
frame = i;
@@ -2176,22 +1952,22 @@
int i;
if (NumberBoolFlag != 0) {
- DebugLevel0("Warning, Redefine Bool flags\n");
+ DebugLevel0("Warning, Redefine Bool flags\n");
}
while (!gh_null_p(list)) {
- str = gh_scm2newstr(gh_car(list), NULL);
- list = gh_cdr(list);
- for (i = 0; i < NumberBoolFlag; ++i) {
- if (!strcmp(str, BoolFlagName[i])) {
- DebugLevel0("Warning, Bool flags already defined\n");
- break;
- }
+ str = gh_scm2newstr(gh_car(list), NULL);
+ list = gh_cdr(list);
+ for (i = 0; i < NumberBoolFlag; ++i) {
+ if (!strcmp(str, BoolFlagName[i])) {
+ DebugLevel0("Warning, Bool flags already defined\n");
+ break;
+ }
}
- if (i != NumberBoolFlag) {
- break;
+ if (i != NumberBoolFlag) {
+ break;
}
- BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) *
sizeof(*BoolFlagName));
- BoolFlagName[NumberBoolFlag++] = str;
+ BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) *
sizeof(*BoolFlagName));
+ BoolFlagName[NumberBoolFlag++] = str;
}
return SCM_UNSPECIFIED;
}
@@ -2204,26 +1980,22 @@
int j;
if (NumberBoolFlag != 0) {
- DebugLevel0("Warning, Redefine Bool flags\n");
+ 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;
- }
+ str = strdup(LuaToString(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;
+ if (i != NumberBoolFlag) {
+ break;
}
- BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) *
sizeof(*BoolFlagName));
- BoolFlagName[NumberBoolFlag++] = str;
+ BoolFlagName = realloc(BoolFlagName, (NumberBoolFlag + 1) *
sizeof(*BoolFlagName));
+ BoolFlagName[NumberBoolFlag++] = str;
}
return 0;
}
@@ -2245,7 +2017,7 @@
#ifndef USE_GUILE
set_print_hooks(SiodUnitTypeTag, CclUnitTypePrin1);
-#endif
+#endif
gh_new_procedure1_0("unit-type", CclUnitType);
gh_new_procedure0_0("unit-type-array", CclUnitTypeArray);
Index: stratagus/src/unit/upgrade.c
diff -u stratagus/src/unit/upgrade.c:1.64 stratagus/src/unit/upgrade.c:1.65
--- stratagus/src/unit/upgrade.c:1.64 Wed Nov 12 15:31:17 2003
+++ stratagus/src/unit/upgrade.c Thu Nov 20 14:19:25 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: upgrade.c,v 1.64 2003/11/12 20:31:17 jsalmon3 Exp $
+// $Id: upgrade.c,v 1.65 2003/11/20 19:19:25 jsalmon3 Exp $
//@{
@@ -544,7 +544,7 @@
int p;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.64 2003/11/12
20:31:17 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.65 2003/11/20
19:19:25 jsalmon3 Exp $\n\n");
/* remove?
//
@@ -987,11 +987,7 @@
}
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++ = strdup(LuaToString(l, j + 1));
}
*cp = NULL;
@@ -1316,7 +1312,7 @@
unit->Type = dst;
unit->Stats = &dst->Stats[player->Player];
// and we have new one...
-
+
UpdateForNewUnit(unit, 1);
if (dst->CanCastSpell) {
unit->Mana = MAGIC_FOR_NEW_UNITS;
@@ -1327,7 +1323,7 @@
unit->CurrentSightRange = dst->Stats[player->Player].SightRange;
MapMarkUnitSight(unit);
}
-
+
CheckUnitToBeDrawn(unit);
//
// Convert trained units to this type.
@@ -1407,7 +1403,7 @@
if (um->ApplyTo[z] == 'X') {
DebugLevel3Fn(" applied to %d\n" _C_ z);
- // upgrade stats
+ // upgrade stats
UnitTypes[z]->Stats[pn].AttackRange += um->Modifier.AttackRange;
UnitTypes[z]->Stats[pn].SightRange += um->Modifier.SightRange;
//If Sight range is upgraded, we need to change EVERY unit
@@ -1415,7 +1411,7 @@
if (um->Modifier.SightRange) {
int numunits;
Unit* sightupgrade[UnitMax];
-
+
numunits = FindUnitsByType(UnitTypes[z], sightupgrade);
numunits--; // Change to 0 Start not 1 start
while (numunits >= 0) {
@@ -1425,7 +1421,7 @@
sightupgrade[numunits]->CurrentSightRange =
UnitTypes[z]->Stats[pn].SightRange;
MapMarkUnitSight(sightupgrade[numunits]);
- }
+ }
--numunits;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src ui/icons.c unit/ccl_unit.c unit/c...,
Jimmy Salmon <=