GR - Subsystem Upgrades

Subsystem Upgrades are a combination of Tech Tree information, Upgrade stats information, an Picnums (mesh) information to represent upgrades in elements of a unit. Generally intended for space units in GR

### Modules (SubSystems)

0 : Armour / Shielding

1 : Command (ie front section)

2 : Cargo (optional)

3 : Engines

4 : Weapons

### Levels

0 (Base) / 1 / 2 / 3

Levels are optional, not all will have all levels

### TechTree

Upgrades effect a Unit Class - every unit in class gets upgrade (in resv / new prod)

Using Tech Effect 500 - 755

Upgrade Levels per active unit are stored in CUnitList systemupgrade[] variable

Current maximum upgrade Levels stored in ruupgrades[player][Class/Subsystem]

* Offset = classnum \* 8 + subsystemnum
* Supports up to 8 subsystems/modules, only 5 used at present

Upgrades triggered by research achievement

* Each Unit Class in game supports 8 Upgrade systems (only 5 used)
* Tech Effect increases are additive
* We can upgrade through techs partially, ie 0.3 + 0.3 + 0.6 or through the final tech ie 0.0 + 0.0 + 1.0
* Visual change only happens on whole numbers
* Effect / spec improvements happen on partial upgrades, ie Interceptor Armour improvement by 0.5 will gain 50% of the spec benefit, even though a full level is not visible.
* Improvements above 3.0 (maximum visual) are allowed but have no different effect than the 3.0 level
* *Examples:*
	+ *Effect 500 would be for Infantry - Armour*
	+ *Effect for Space Fighter, Engines would be 22\*8 + 3 = 179 + 500*
	+ *(Class 22, skip 8 elements each class, Engines is entry 3)*

### Affected Stats

Stored in CUpgradeComponents

```
class CUpgradeComponent {
	unsigned short	spottype[2];			// Spot type replacements if non-zero
	union { struct {
	float			groundattackrange;
	float			airattackrange;
	float			surfaceattackrange;		// Also Ballistic Range
	float			subattackrange;			// Also Beam Range
	float			groundattack;
	float			airattack;
	float			navalattack;			// Also Ballistic Attack
	float			subattack;				// Also Beam Attack
	float			grounddefense;			// Also Hull defense
	float			tacairdefense;			// Also Shield defense
	float			indirectdefense;
	float			closedefense;
	float			stealth;
	float			speed;
	float			cargocap;
	float			crew;
	float			fuelcap;
	float			fueluse;
	float			ammocap;
	float			ammouse;
	float			buildspeed;
	float			weight;
	float			carriercap;
	float			initiative;
	float			ugreserved[2];
	}; float upgradecomp[NUMUGCOMPS]; };	// Modifier values (or replacement if bitmask bit set)
	DWORD			ugcompreplacevaluemask;	// BITMASK of columns that are REPLACEMENT values and not modifier values
	DWORD			ugreserveddw[2];
};

```

&& UPGRADECOMPONENT classnum

1-24 : UpgradeComponent class for each upgrade level (0 not used)

* 5 Modules (0 to 4), 3 upgrades levels each (supporting 1/2/3)
* 3 more modules not used (5/6/7), reserved

Each value is a modifier of the original value, similar to tech effects.

* *0.0 would be unchanged; 0.5 would be "increase by 50%"; -0.5 would be "reduce by 50%"*
* If an original Air Attack Range value was 24, and the UpgradeComponent column was 0.5, then the new Air Attack Range would be 36 (ie x 1.5)

There is a BITMASK final column that indicates if the value should **replace** the original instead of being a modifier.

* *If the BITMASK value is 10 (8 + 2), then columns Air Attack range and Sub attack range would **replace** any existing spec.*
* *If the original Air Attack value was 24, and the UpgradeComponent column was 30 with a BITMASK set, then the new Air Attack would be 30.*
* The Replace Bit is **not** supported for ground/air/naval (ballistic/beam) attack values. Only modifiers allowed for those values.

### Implementation:

* See Default Picnums
* Base Hull is always single object (submesh) - submesh # 0
* Upgrades can ADD (cumulative) or REPLACE (previous upgrades) on Base Hull object mesh - using *OptionOb* flag (if set T, then replace)
* Upgrade Level Calculation Example:
	+ *Faction has researched three techs with Tech Effect 679 - effect values are 0.4, 0.5, 0.7*
	+ *Effect number 679 minus 500 (base for subsystem upgrades) = 179*
	+ *This is in section for class number 22, Space Fighter (22\*8 = 176, start of upgrade effects for class 22, eight modules per class supported)*
	+ *This is upgrade module 3 (179-176). Per Module chart above, this is the entry for Engines.*
	+ *Total effect value is 1.6 (0.4+0.5+0.7). This means the Upgrade Level to be used is level 1 (zero is base unit). Partial levels are ignored.*
* Unit Stat Upgrades Example:
	+ *Values to upgrade stats are UPGRADECOMPONENT line 3 \* 3 + 1 = 10 (upgrade module 3 for engines, times 3 levels per module, plus level 1 for current Upgrade Level)*
	+ *This will be a stats/specs upgrade using the value in the UPGRADECOMPONENT array*
		- *If value "speed" in the array of specs is 0.2 (20% boost), and the unit's base speed is 50, then the upgraded speed is 50 \* (1.0 + 0.2) = 60*
		- *If value "ammouse" in the array of specs is -0.15 (15% reduction), and the unit's base ammo use is 20, then the upgraded ammo use is 20 \* (1.0 - 0.15) = 17*
		- *Upgrade values are **not cumulative -** at Level 1 the unit will receive Level 1 stat adjustments, at Level 2 the unit will only receive Level 2 adjustments.*
		- *No Partial stat upgrades are done - if the the total upgrade tech effect is 1.6, then Level 1 stats are used. Total upgrade tech effect of 0.9 results in no stat changes (base only)*
		- *If the BITMASK value includes the set bit for the column, then a REPLACEMENT value is used instead of a multiplier.*
			* *Again, replacement values are **not cumulative.** If both level 2 and level 3 are intended to have a replacement value of '30' for a column, then they **both** must include the '30' value and the set bitmask value.*
	+ *This will be a visual upgrade to Level 1 on the unit mesh*
	+ *Unit Mesh Picnum will be drawn with Base Hull mesh, and with SubMesh of Meshtype 43 (first engine level upgrade - module 3 for engines, times 3 levels per module, plus 34 for base submodules Meshtype)*

### UpgradeComponent.csv Definitions

* Column A is the ID for the upgrade type
	+ 1 - Armor Level 1
	+ 2 - Armor Level 2
	+ 3 - Armor Level 3
	+ 4 - Command Level 1
	+ 5 - Command Level 2
	+ (etc. through Armor, Command, Cargo, Engines, Weapons
* Rows begging at B are values for upgrades
	+ B - Spotting Type 1 - *Replaces Spotting Type 1 if not zero*
	+ C - Spotting Type 2 - *Replaces Spotting Type 2 if not zero*
	+ D - Ground Attack Range (bitmask 1)
	+ E - Air Attack Range (bitmask 2)
	+ F - Surface Attack Range (also Ballistic Attack Range) (bitmask 4)
	+ G - Submarine Attack Range (also Beam Attack Range) (bitmask 8)
	+ H - Ground Attack (bitmask 16)
	+ I - Air Attack (bitmask 32)
	+ J - Surface Attack (also Ballistic Attack) (bitmask 64)
	+ K - Submarine Attack (also Beam Attack) (bitmask 128)
	+ L - Ground Defense (also Hull Defense) (bitmask 256)
	+ M - Tactical Air Defense (also Shield Defense) (bitmask 512)
	+ N - Indirect Air Defense (bitmask 1024)
	+ O - Close Combat Defense (bitmask 2048)
	+ P - Stealth (bitmask 4096)
	+ Q - Speed ((bitmask 8192)
	+ R - Cargo Capacity (bitmask 16384)
	+ S - Crew (bitmask 32768)
	+ T - Fuel Capacity (bitmask 65536)
	+ U - Fuel Usage (bitmask 131,072)
	+ V - Ammo Capacity (bitmask 262144)
	+ W - Ammo Usage (bitmask 524288)
	+ X - Build Speed (bitmask 1048576)
	+ Y - Weight (bitmask 2097152)
	+ Z - Carrier Capacity (bitmask 4194304)
	+ AA - Initiative (bitmask 8388608)
	+ AB - Future Spec 1
	+ AC - Future Spec 2
	+ AD - BITMASK to indicate if values D to AA are REPLACEMENT values instead of multipliers