From 49fad13971bb5989063259e67dc83afa15a35a2c Mon Sep 17 00:00:00 2001
From: jarod42 <>
Date: Thu, 14 Oct 2004 14:58:08 +0000
Subject: [PATCH] CleanUp

---
 src/include/upgrade_structs.h |  5 +---
 src/unit/upgrade.cpp          | 45 +++++++++++++++++++----------------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/include/upgrade_structs.h b/src/include/upgrade_structs.h
index 5186113dd..b41f6e332 100644
--- a/src/include/upgrade_structs.h
+++ b/src/include/upgrade_structs.h
@@ -138,7 +138,6 @@ typedef struct _unit_stats_ {
 **  The main useable upgrades.
 */
 typedef struct _upgrade_ {
-	const void* OType;                      ///< object type (future extensions)
 	char*       Ident;                      ///< identifier
 	int         Costs[MaxCosts];            ///< costs for the upgrade
 		// TODO: not used by buttons
@@ -185,8 +184,7 @@ typedef struct _upgrade_modifier_ {
 	char ChangeUpgrades[UpgradeMax];    ///< allow/forbid upgrades
 	char ApplyTo[UnitTypeMax];          ///< which unit types are affected
 
-	// TODO: void* cshould be UnitType*
-	void* ConvertTo;                    ///< convert to this unit-type.
+	struct _unit_type_* ConvertTo;      ///< convert to this unit-type.
 
 } UpgradeModifier;
 
@@ -226,7 +224,6 @@ typedef struct _upgrade_timers_ {
 --  Variables
 ----------------------------------------------------------------------------*/
 
-extern const char UpgradeType[];            ///< upgrade type
 extern Upgrade Upgrades[UpgradeMax];        ///< the main user usable upgrades
 
 //@}
diff --git a/src/unit/upgrade.cpp b/src/unit/upgrade.cpp
index 9b5f32dcb..be65e140f 100644
--- a/src/unit/upgrade.cpp
+++ b/src/unit/upgrade.cpp
@@ -60,7 +60,7 @@
 struct _unit_type_;
 
 static int AddUpgradeModifierBase(int, int, int, int, int, int, int, int,
-	int*, const int[UnitTypeMax], const char*, const char*, struct _unit_type_*);
+	int*, const int[UnitTypeMax], const char*, const char*, UnitType*);
 
 static void AllowUnitId(Player* player, int id, int units);
 static void AllowUpgradeId(Player* player, int id, char af);
@@ -69,11 +69,6 @@ static void AllowUpgradeId(Player* player, int id, char af);
 --  Variables
 ----------------------------------------------------------------------------*/
 
-/**
-**  upgrade type definition
-*/
-const char UpgradeType[] = "upgrade";
-
 Upgrade Upgrades[UpgradeMax];                ///< The main user useable upgrades
 static int NumUpgrades;                      ///< Number of upgrades used
 
@@ -132,7 +127,6 @@ static Upgrade* AddUpgrade(const char* ident, const char* icon,
 		free(upgrade->Icon.Name);
 	} else {
 		upgrade = Upgrades + NumUpgrades++;
-		upgrade->OType = UpgradeType;
 		upgrade->Ident = strdup(ident);
 		*(Upgrade**)hash_add(UpgradeHash, upgrade->Ident) = upgrade;
 	}
@@ -236,6 +230,8 @@ void CleanUpgrades(void)
 	}
 }
 
+#if 1 // must be removed when new format available : pud functions
+
 /**
 ** Parse ALOW area from puds.
 **
@@ -538,6 +534,8 @@ void ParsePudUGRD(const char* ugrd, int length __attribute__((unused)))
 	}
 }
 
+#endif // Pud functions.
+
 /**
 **  Save state of the dependencies to file.
 **
@@ -977,7 +975,7 @@ static int AddUpgradeModifierBase(int uid, int attack_range, int sight_range,
 	return NumUpgradeModifiers++;
 }
 
-#if 0
+#if 0  // Not used.
 /**
 ** returns upgrade modifier id or -1 for error (actually this id is
 ** useless, just error checking)
@@ -1078,7 +1076,7 @@ static int AddUpgradeModifier(int uid, int attack_range, int sight_range,
 */
 int UnitTypeIdByIdent(const char* ident)
 {
-	UnitType* type;
+	const UnitType* type;
 
 	if ((type = UnitTypeByIdent(ident))) {
 		return type->Slot;
@@ -1095,7 +1093,7 @@ int UnitTypeIdByIdent(const char* ident)
 */
 int UpgradeIdByIdent(const char* ident)
 {
-	Upgrade* upgrade;
+	const Upgrade* upgrade;
 
 	upgrade = UpgradeByIdent(ident);
 	if (upgrade) {
@@ -1260,7 +1258,7 @@ static void ApplyUpgradeModifier(Player* player, const UpgradeModifier* um)
 			UnitTypes[z]->Stats[pn].Level++;
 
 			if (um->ConvertTo) {
-				((UnitType*)um->ConvertTo)->Stats[pn].Level++;
+				um->ConvertTo->Stats[pn].Level++;
 				ConvertUnitTypeTo(player,UnitTypes[z], um->ConvertTo);
 			}
 		}
@@ -1278,7 +1276,7 @@ void UpgradeAcquire(Player* player, const Upgrade* upgrade)
 	int z;
 	int id;
 
-	id = upgrade-Upgrades;
+	id = upgrade - Upgrades;
 	player->UpgradeTimers.Upgrades[id] = upgrade->Costs[TimeCost];
 	AllowUpgradeId(player, id, 'R');  // research done
 
@@ -1296,6 +1294,7 @@ void UpgradeAcquire(Player* player, const Upgrade* upgrade)
 	}
 }
 
+#if 0 // UpgradeLost not implemented.
 /**
 **  for now it will be empty?
 **  perhaps acquired upgrade can be lost if (for example) a building is lost
@@ -1304,12 +1303,11 @@ void UpgradeAcquire(Player* player, const Upgrade* upgrade)
 */
 void UpgradeLost(Player* player, int id)
 {
-	return; // FIXME: remove this if implemented below
-
 	player->UpgradeTimers.Upgrades[id] = 0;
 	AllowUpgradeId(player, id, 'A'); // research is lost i.e. available
 	// FIXME: here we should reverse apply upgrade...
 }
+#endif
 
 /*----------------------------------------------------------------------------
 --  Allow(s)
@@ -1343,24 +1341,29 @@ static void AllowUpgradeId(Player* player, int id, char af)
 }
 
 /**
-**  FIXME: docu
+**  Return the allow state of the unit.
+**
+**  @param player   Check state of this player.
+**  @param id       Unit identifier.
+**
+**  @return the allow state of the unit.
 */
 int UnitIdAllowed(const Player* player, int id)
 {
-	// JOHNS: Don't be kind, the people should code correct!
 	Assert(id >= 0 && id < UnitTypeMax);
-	if (id < 0 || id >= UnitTypeMax) {
-		return 0;
-	}
 	return player->Allow.Units[id];
 }
 
 /**
-**  FIXME: docu
+**  Return the allow state of an upgrade.
+**
+**  @param player  Check state for this player.
+**  @param id      Upgrade identifier.
+**
+**  @return the allow state of the upgrade.
 */
 char UpgradeIdAllowed(const Player* player, int id)
 {
-	// JOHNS: Don't be kind, the people should code correct!
 	Assert(id >= 0 && id < UpgradeMax);
 	return player->Allow.Upgrades[id];
 }