summaryrefslogtreecommitdiffhomepage
path: root/Stars45/CombatGroup.h
blob: 5eb6dde3cfac82880c789a6eab7f4c97b50301e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*  Project Starshatter 4.5
	Destroyer Studios LLC
	Copyright © 1997-2004. All Rights Reserved.

	SUBSYSTEM:    Stars.exe
	FILE:         CombatGroup.h
	AUTHOR:       John DiCamillo


	OVERVIEW
	========
*/

#ifndef CombatGroup_h
#define CombatGroup_h

#include "Types.h"
#include "Geometry.h"
#include "Text.h"
#include "List.h"
#include "Intel.h"

// +--------------------------------------------------------------------+

class Campaign;
class Combatant;
class CombatGroup;
class CombatUnit;
class CombatZone;
class CombatAssignment;

// +--------------------------------------------------------------------+

class CombatGroup
{
public:
	static const char* TYPENAME() { return "CombatGroup"; }

	enum GROUP_TYPE {   
		FORCE = 1,           // Commander In Chief

		WING,                // Air Force
		INTERCEPT_SQUADRON,  // a2a fighter
		FIGHTER_SQUADRON,    // multi-role fighter
		ATTACK_SQUADRON,     // strike / attack
		LCA_SQUADRON,        // landing craft

		FLEET,               // Navy
		DESTROYER_SQUADRON,  // destroyer
		BATTLE_GROUP,        // heavy cruiser(s)
		CARRIER_GROUP,       // fleet carrier

		BATTALION,           // Army
		MINEFIELD,
		BATTERY,
		MISSILE,
		STATION,             // orbital station
		STARBASE,            // planet-side base

		C3I,                 // Command, Control, Communications, Intelligence
		COMM_RELAY,
		EARLY_WARNING,
		FWD_CONTROL_CTR,
		ECM,

		SUPPORT,
		COURIER,
		MEDICAL,
		SUPPLY,
		REPAIR,

		CIVILIAN,            // root for civilian groups

		WAR_PRODUCTION,
		FACTORY,
		REFINERY,
		RESOURCE,

		INFRASTRUCTURE,
		TRANSPORT,
		NETWORK,
		HABITAT,
		STORAGE,

		NON_COM,             // other civilian traffic
		FREIGHT,
		PASSENGER,
		PRIVATE
	};

	CombatGroup(int t, int n, const char* s, int i, int e, CombatGroup* p=0);
	~CombatGroup();

	// comparison operators are used to sort combat groups into a priority list
	// in DESCENDING order, so the sense of the comparison is backwards from
	// usual...
	int operator <  (const CombatGroup& g)  const { return value >  g.value; }
	int operator <= (const CombatGroup& g)  const { return value >= g.value; }
	int operator == (const CombatGroup& g)  const { return this  == &g;      }

	// operations:
	static CombatGroup*  LoadOrderOfBattle(const char* fname, int iff, Combatant* combatant);
	static void          SaveOrderOfBattle(const char* fname, CombatGroup* force);
	static void          MergeOrderOfBattle(BYTE* block, const char* fname, int iff, Combatant* combatant, Campaign* campaign);

	void                 AddComponent(CombatGroup* g);
	CombatGroup*         FindGroup(int t, int n=-1);
	CombatGroup*         Clone(bool deep=true);

	// accessors and mutators:
	const char* GetDescription()           const;
	const char* GetShortDescription()      const;

	void                 SetCombatant(Combatant* c) { combatant = c; }

	Combatant*           GetCombatant()          { return combatant;  }
	CombatGroup*         GetParent()             { return parent;     }
	List<CombatGroup>&   GetComponents()         { return components; }
	List<CombatGroup>&   GetLiveComponents()     { return live_comp;  }
	List<CombatUnit>&    GetUnits()              { return units;      }
	CombatUnit*          GetRandomUnit();
	CombatUnit*          GetFirstUnit();
	CombatUnit*          GetNextUnit();
	CombatUnit*          FindUnit(const char* name);
	CombatGroup*         FindCarrier();

	const Text&    Name()                        const { return name;       }
	int            Type()                        const { return type;       }
	int            CountUnits()                  const;
	int            IntelLevel()                  const { return enemy_intel;}
	int            GetID()                       const { return id;         }
	int            GetIFF()                      const { return iff;        }
	Point          Location()                    const { return location;   }
	void           MoveTo(const Point& loc);
	const Text&    GetRegion()                   const { return region;     }
	void           SetRegion(Text rgn)                 { region = rgn;      }
	void           AssignRegion(Text rgn);
	int            Value()                       const { return value;      }
	int            Sorties()                     const { return sorties;    }
	void           SetSorties(int n)                   { sorties = n;       }
	int            Kills()                       const { return kills;      }
	void           SetKills(int n)                     { kills = n;         }
	int            Points()                      const { return points;     }
	void           SetPoints(int n)                    { points = n;        }
	int            UnitIndex()                   const { return unit_index; }

	double         GetNextJumpTime()             const;

	double         GetPlanValue()                const { return plan_value; }
	void           SetPlanValue(double v)              { plan_value = v;    }

	bool           IsAssignable()                const;
	bool           IsTargetable()                const;
	bool           IsDefensible()                const;
	bool           IsStrikeTarget()              const;
	bool           IsMovable()                   const;
	bool           IsFighterGroup()              const;
	bool           IsStarshipGroup()             const;
	bool           IsReserve()                   const;

	// these two methods return zero terminated arrays of
	// integers identifying the preferred assets for attack
	// or defense in priority order:
	static const int* PreferredAttacker(int type);
	static const int* PreferredDefender(int type);

	bool           IsExpanded()                  const { return expanded; }
	void           SetExpanded(bool e)                 { expanded = e;    }

	const Text&    GetAssignedSystem()           const { return assigned_system; }
	void           SetAssignedSystem(const char* s);
	CombatZone*    GetCurrentZone()              const { return current_zone;  }
	void           SetCurrentZone(CombatZone* z)       { current_zone = z;     }
	CombatZone*    GetAssignedZone()             const { return assigned_zone; }
	void           SetAssignedZone(CombatZone* z);
	void           ClearUnlockedZones();
	bool           IsZoneLocked()                const { return assigned_zone && zone_lock;   }
	void           SetZoneLock(bool lock=true);
	bool           IsSystemLocked()              const { return assigned_system.length() > 0; }

	const Text&    GetStrategicDirection()       const { return strategic_direction; }
	void           SetStrategicDirection(Text dir)     { strategic_direction = dir;  }

	void           SetIntelLevel(int n);
	int            CalcValue();

	List<CombatAssignment>& GetAssignments()           { return assignments; }
	void                    ClearAssignments();

	static int           TypeFromName(const char* name);
	static const char*   NameFromType(int type);

private:        
	const char* GetOrdinal()               const;

	// attributes:
	int                  type;
	int                  id;
	Text                 name;
	int                  iff;
	int                  enemy_intel;

	double               plan_value; // scratch pad for plan modules

	List<CombatUnit>     units;
	List<CombatGroup>    components;
	List<CombatGroup>    live_comp;
	Combatant*           combatant;
	CombatGroup*         parent;
	Text                 region;
	Point                location;
	int                  value;
	int                  unit_index;

	int                  sorties;
	int                  kills;
	int                  points;

	bool                 expanded;   // for tree control

	Text                    assigned_system;
	CombatZone*             current_zone;
	CombatZone*             assigned_zone;
	bool                    zone_lock;
	List<CombatAssignment>  assignments;

	Text                 strategic_direction;
};

#endif CombatGroup_h