From 3c381dbb3d99044200bb6caf8e852533b02fb19a Mon Sep 17 00:00:00 2001 From: jarod42 <> Date: Tue, 12 Oct 2004 14:38:00 +0000 Subject: [PATCH] Remove Speed attribute from UnitType (and so UnitStat). (its only effect was to be shown in panel) --- src/action/action_attack.cpp | 6 +++--- src/action/action_follow.cpp | 2 +- src/action/action_patrol.cpp | 2 +- src/action/action_still.cpp | 4 ++-- src/ai/ai.cpp | 4 ++-- src/include/unittype.h | 25 +++++++++---------------- src/include/upgrade_structs.h | 2 -- src/unit/script_unittype.cpp | 10 +--------- src/unit/unit.cpp | 2 +- src/unit/unittype.cpp | 2 -- src/unit/upgrade.cpp | 18 ++++-------------- 11 files changed, 24 insertions(+), 53 deletions(-) diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index 9bc36c797..2bc906295 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -271,7 +271,7 @@ static void MoveToTarget(Unit* unit) unit->Stats->AttackRange) { // Reached another unit, now attacking it unit->State = 0; - if (unit->Stats->Speed) { + if (!unit->Type->Building) { UnitHeadingFromDeltaXY(unit, goal->X + (goal->Type->TileWidth - 1) / 2 - unit->X, goal->Y + (goal->Type->TileHeight - 1) / 2 - unit->Y); @@ -288,7 +288,7 @@ static void MoveToTarget(Unit* unit) unit->Stats->AttackRange) { // Reached wall or ground, now attacking it unit->State = 0; - if (unit->Stats->Speed) { + if (!unit->Type->Building) { UnitHeadingFromDeltaXY(unit, unit->Orders[0].X - unit->X, unit->Orders[0].Y - unit->Y); } @@ -485,7 +485,7 @@ static void AttackTarget(Unit* unit) // // Turn always to target // - if (unit->Stats->Speed && goal) { + if (!unit->Type->Building && goal) { UnitHeadingFromDeltaXY(unit, goal->X + (goal->Type->TileWidth - 1) / 2 - unit->X, goal->Y + (goal->Type->TileHeight - 1) / 2 - unit->Y); diff --git a/src/action/action_follow.cpp b/src/action/action_follow.cpp index 846656eab..f1eaffe18 100644 --- a/src/action/action_follow.cpp +++ b/src/action/action_follow.cpp @@ -231,7 +231,7 @@ void HandleActionFollow(Unit* unit) // If don't set the goal, the unit can than choose a // better goal if moving nearer to enemy. // - if (unit->Type->CanAttack && unit->Stats->Speed && + if (unit->Type->CanAttack && (!goal || goal->Orders[0].Action == UnitActionAttack || goal->Orders[0].Action == UnitActionStill)) { goal = AttackUnitsInReactRange(unit); diff --git a/src/action/action_patrol.cpp b/src/action/action_patrol.cpp index 2326ca651..60d827500 100644 --- a/src/action/action_patrol.cpp +++ b/src/action/action_patrol.cpp @@ -89,7 +89,7 @@ void HandleActionPatrol(Unit* unit) // If don't set the goal, the unit can than choose a // better goal if moving nearer to enemy. // - if (unit->Type->CanAttack && unit->Stats->Speed) { + if (unit->Type->CanAttack) { goal = AttackUnitsInReactRange(unit); if (goal) { DebugPrint("Patrol attack %d\n" _C_ UnitNumber(goal)); diff --git a/src/action/action_still.cpp b/src/action/action_still.cpp index 2fbd3ff8d..9afa622da 100644 --- a/src/action/action_still.cpp +++ b/src/action/action_still.cpp @@ -187,7 +187,7 @@ void ActionStillGeneric(Unit* unit, int ground) // Normal units react in reaction range. // Removed units can only attack in AttackRange, from bunker // - if (unit->Stats->Speed && !unit->Removed && !ground) { + if (!type->Building && !unit->Removed && !ground) { if ((goal = AttackUnitsInReactRange(unit))) { // Weak goal, can choose other unit, come back after attack CommandAttack(unit, goal->X, goal->Y, NULL, FlushCommands); @@ -218,7 +218,7 @@ void ActionStillGeneric(Unit* unit, int ground) unit->Reset = 0; unit->State = 0; unit->SubAction = 1; // Mark attacking. - if (type->Stats[unit->Player->Player].Speed) { + if (!type->Building) { UnitHeadingFromDeltaXY(unit, goal->X + (goal->Type->TileWidth - 1) / 2 - unit->X, goal->Y + (goal->Type->TileHeight - 1) / 2 - unit->Y); diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index a28de5072..8a7f4981d 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -1392,8 +1392,8 @@ static void AiMoveUnitInTheWay(Unit* unit) continue; } - - if (!blockertype->_Speed || blockertype->Building) { + // FIXME : check movement from animation + if (blockertype->Building) { continue; } diff --git a/src/include/unittype.h b/src/include/unittype.h index 85caf549a..86426384e 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -135,10 +135,6 @@ struct lua_State; ** Index into corpse animation script. Used if unit-types share ** the same corpse but have different animations. ** -** UnitType::_Speed -** -** Non upgraded movement speed. -** @note Until now we didn't support speed upgrades. ** ** @todo continue this documentation ** @@ -651,16 +647,15 @@ typedef struct _variable_type_ { #define SUPPLY_INDEX 12 #define DEMAND_INDEX 13 #define ARMOR_INDEX 14 -#define SPEED_INDEX 15 -#define SIGHTRANGE_INDEX 16 -#define ATTACKRANGE_INDEX 17 -#define PIERCINGDAMAGE_INDEX 18 -#define BASICDAMAGE_INDEX 19 -#define DAMAGE_INDEX 20 -#define EXTRADAMAGE_INDEX 21 -#define POSX_INDEX 22 -#define POSY_INDEX 23 -#define SLOT_INDEX 24 +#define SIGHTRANGE_INDEX 15 +#define ATTACKRANGE_INDEX 16 +#define PIERCINGDAMAGE_INDEX 17 +#define BASICDAMAGE_INDEX 18 +#define DAMAGE_INDEX 19 +#define EXTRADAMAGE_INDEX 20 +#define POSX_INDEX 21 +#define POSY_INDEX 22 +#define SLOT_INDEX 23 #define NVARALREADYDEFINED SLOT_INDEX + 1 // Hardcoded variables @@ -817,8 +812,6 @@ struct _unit_type_ { UnitType* CorpseType; ///< Corpse unit-type int CorpseScript; ///< Corpse script start - int _Speed; ///< Movement speed - // this is taken from the UDTA section struct _construction_* Construction; ///< What is shown in construction phase int _SightRange; ///< Sight range diff --git a/src/include/upgrade_structs.h b/src/include/upgrade_structs.h index 2173a202d..5186113dd 100644 --- a/src/include/upgrade_structs.h +++ b/src/include/upgrade_structs.h @@ -128,7 +128,6 @@ typedef struct _unit_stats_ { int Armor; ///< armor strength int BasicDamage; ///< weapon basic damage int PiercingDamage; ///< weapon piercing damage - int Speed; ///< movement speed int HitPoints; ///< hit points int RegenerationRate; ///< HP regeration rate in HP int Costs[MaxCosts]; ///< current costs of the unit @@ -161,7 +160,6 @@ typedef struct _modifiers_ { int BasicDamage; ///< basic damage modifier int PiercingDamage; ///< piercing damage modifier int Armor; ///< armor modifier - int Speed; ///< speed modifier (FIXME: not working) int HitPoints; ///< hit points modifier int RegenerationRate; ///< HP regeneration rate modifier diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index 8d3f84677..35ad159c5 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -420,8 +420,6 @@ static int CclDefineUnitType(lua_State* l) } else if (!strcmp(value, "Construction")) { // FIXME: What if constructions aren't yet loaded? type->Construction = ConstructionByIdent(LuaToString(l, -1)); - } else if (!strcmp(value, "Speed")) { - type->_Speed = LuaToNumber(l, -1); } else if (!strcmp(value, "DrawLevel")) { type->DrawLevel = LuaToNumber(l, -1); } else if (!strcmp(value, "MaxOnBoard")) { @@ -1049,8 +1047,6 @@ static int CclDefineUnitStats(lua_State* l) if (!strcmp(value, "level")) { stats->Level = LuaToNumber(l, j + 1); - } else if (!strcmp(value, "speed")) { - stats->Speed = LuaToNumber(l, j + 1); } else if (!strcmp(value, "attack-range")) { stats->AttackRange = LuaToNumber(l, j + 1); } else if (!strcmp(value, "sight-range")) { @@ -1788,10 +1784,6 @@ void UpdateUnitVariables(const Unit* unit) unit->Variable[ARMOR_INDEX].Value = unit->Type->_Armor; unit->Variable[ARMOR_INDEX].Max = unit->Stats->Armor; - // Speed - unit->Variable[SPEED_INDEX].Value = unit->Type->_Speed; - unit->Variable[SPEED_INDEX].Max = unit->Stats->Speed; - // SightRange unit->Variable[SIGHTRANGE_INDEX].Value = unit->Type->_SightRange; unit->Variable[SIGHTRANGE_INDEX].Max = unit->Stats->SightRange; @@ -1848,7 +1840,7 @@ void InitDefinedVariables() { const char* var[NVARALREADYDEFINED] = {"HitPoints", "Build", "Mana", "Transport", "Research", "Training", "UpgradeTo", "GiveResource", "CarryResource", - "Xp", "Level", "Kill", "Supply", "Demand", "Armor", "Speed", "SightRange", + "Xp", "Level", "Kill", "Supply", "Demand", "Armor", "SightRange", "AttackRange", "PiercingDamage", "BasicDamage", "Damage", "ExtraDamage", "PosX", "PosY", "Slot" }; // names of the variable. diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index 37fa5caee..4baa6c4b1 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -3184,7 +3184,7 @@ void HitUnit(Unit* attacker, Unit* target, int damage) // Attack units in range (which or the attacker?) // if (attacker && !type->Coward) { - if (type->CanAttack && target->Stats->Speed) { + if (type->CanAttack && !target->Type->Building) { if (RevealAttacker && CanTarget(target->Type, attacker->Type)) { // Reveal Unit that is attacking goal = attacker; diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index c964fee18..eb1a397e8 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -172,7 +172,6 @@ void UpdateStats(int reset) stats->Armor = type->_Armor; stats->BasicDamage = type->_BasicDamage; stats->PiercingDamage = type->_PiercingDamage; - stats->Speed = type->_Speed; stats->HitPoints = type->_HitPoints; for (i = 0; i < MaxCosts; ++i) { stats->Costs[i] = type->_Costs[i]; @@ -557,7 +556,6 @@ static void SaveUnitStats(const UnitStats* stats, const char* ident, int plynr, Assert(plynr < PlayerMax); CLprintf(file, "DefineUnitStats(\"%s\", %d,\n ", ident, plynr); CLprintf(file, "\"level\", %d, ", stats->Level); - CLprintf(file, "\"speed\", %d, ", stats->Speed); CLprintf(file, "\"attack-range\", %d, ", stats->AttackRange); CLprintf(file, "\"sight-range\", %d,\n ", stats->SightRange); CLprintf(file, "\"armor\", %d, ", stats->Armor); diff --git a/src/unit/upgrade.cpp b/src/unit/upgrade.cpp index d2c6f040a..9b5f32dcb 100644 --- a/src/unit/upgrade.cpp +++ b/src/unit/upgrade.cpp @@ -59,7 +59,7 @@ struct _unit_type_; -static int AddUpgradeModifierBase(int, int, int, int, int, int, int, int, int, +static int AddUpgradeModifierBase(int, int, int, int, int, int, int, int, int*, const int[UnitTypeMax], const char*, const char*, struct _unit_type_*); static void AllowUnitId(Player* player, int id, int units); @@ -597,7 +597,6 @@ static int CclDefineModifier(lua_State* l) int basic_damage; int piercing_damage; int armor; - int speed; int regeneration_rate; int hit_points; int costs[MaxCosts]; @@ -616,7 +615,6 @@ static int CclDefineModifier(lua_State* l) basic_damage = 0; piercing_damage = 0; armor = 0; - speed = 0; hit_points = 0; regeneration_rate = 0; memset(costs, 0, sizeof(costs)); @@ -656,10 +654,6 @@ static int CclDefineModifier(lua_State* l) lua_rawgeti(l, j + 1, 2); armor = LuaToNumber(l, -1); lua_pop(l, 1); - } else if (!strcmp(temp, "speed")) { - lua_rawgeti(l, j + 1, 2); - speed = LuaToNumber(l, -1); - lua_pop(l, 1); } else if (!strcmp(temp, "hit-points")) { lua_rawgeti(l, j + 1, 2); hit_points = LuaToNumber(l, -1); @@ -726,7 +720,7 @@ static int CclDefineModifier(lua_State* l) } AddUpgradeModifierBase(uid, attack_range, sight_range, basic_damage, - piercing_damage, armor, speed, hit_points, regeneration_rate, costs, + piercing_damage, armor, hit_points, regeneration_rate, costs, units, upgrades, apply_to,convert_to); return 0; @@ -932,7 +926,6 @@ void UpgradesCclRegister(void) ** @param basic_damage Basic damage modification. ** @param piercing_damage Piercing damage modification. ** @param armor Armor modification. -** @param speed Speed modification (Currently not possible). ** @param hit_points Hitpoint modification. ** @param regeneration_rate Regenerations modification. ** @param costs Costs modification. @@ -945,7 +938,7 @@ void UpgradesCclRegister(void) ** (actually this id is useless, just error checking) */ static int AddUpgradeModifierBase(int uid, int attack_range, int sight_range, - int basic_damage, int piercing_damage, int armor, int speed, + int basic_damage, int piercing_damage, int armor, int hit_points, int regeneration_rate, int* costs, const int units[UnitTypeMax], const char* af_upgrades, const char* apply_to, UnitType* convert_to) @@ -966,7 +959,6 @@ static int AddUpgradeModifierBase(int uid, int attack_range, int sight_range, um->Modifier.BasicDamage = basic_damage; um->Modifier.PiercingDamage = piercing_damage; um->Modifier.Armor = armor; - um->Modifier.Speed = speed; um->Modifier.HitPoints = hit_points; um->Modifier.RegenerationRate = regeneration_rate; @@ -991,7 +983,7 @@ static int AddUpgradeModifierBase(int uid, int attack_range, int sight_range, ** useless, just error checking) */ static int AddUpgradeModifier(int uid, int attack_range, int sight_range, - int basic_damage, int piercing_damage, int armor, int speed, + int basic_damage, int piercing_damage, int armor, int hit_points, int* costs, const int units[UnitTypeMax], // following are comma separated list of required string id's @@ -1017,7 +1009,6 @@ static int AddUpgradeModifier(int uid, int attack_range, int sight_range, um->Modifier.BasicDamage = basic_damage; um->Modifier.PiercingDamage = piercing_damage; um->Modifier.Armor = armor; - um->Modifier.Speed = speed; um->Modifier.HitPoints = hit_points; for (i = 0; i < MaxCosts; ++i) { @@ -1258,7 +1249,6 @@ static void ApplyUpgradeModifier(Player* player, const UpgradeModifier* um) UnitTypes[z]->Stats[pn].BasicDamage += um->Modifier.BasicDamage; UnitTypes[z]->Stats[pn].PiercingDamage += um->Modifier.PiercingDamage; UnitTypes[z]->Stats[pn].Armor += um->Modifier.Armor; - UnitTypes[z]->Stats[pn].Speed += um->Modifier.Speed; UnitTypes[z]->Stats[pn].HitPoints += um->Modifier.HitPoints; UnitTypes[z]->Stats[pn].RegenerationRate += um->Modifier.RegenerationRate;