Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CombatGroup.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: CombatGroup.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12 */
13 
14 #ifndef CombatGroup_h
15 #define CombatGroup_h
16 
17 #include "Types.h"
18 #include "Geometry.h"
19 #include "Text.h"
20 #include "List.h"
21 #include "Intel.h"
22 
23 // +--------------------------------------------------------------------+
24 
25 class Campaign;
26 class Combatant;
27 class CombatGroup;
28 class CombatUnit;
29 class CombatZone;
30 class CombatAssignment;
31 
32 // +--------------------------------------------------------------------+
33 
35 {
36 public:
37  static const char* TYPENAME() { return "CombatGroup"; }
38 
39  enum GROUP_TYPE {
40  FORCE = 1, // Commander In Chief
41 
42  WING, // Air Force
43  INTERCEPT_SQUADRON, // a2a fighter
44  FIGHTER_SQUADRON, // multi-role fighter
45  ATTACK_SQUADRON, // strike / attack
46  LCA_SQUADRON, // landing craft
47 
48  FLEET, // Navy
49  DESTROYER_SQUADRON, // destroyer
50  BATTLE_GROUP, // heavy cruiser(s)
51  CARRIER_GROUP, // fleet carrier
52 
53  BATTALION, // Army
57  STATION, // orbital station
58  STARBASE, // planet-side base
59 
60  C3I, // Command, Control, Communications, Intelligence
64  ECM,
65 
71 
72  CIVILIAN, // root for civilian groups
73 
78 
84 
85  NON_COM, // other civilian traffic
89  };
90 
91  CombatGroup(int t, int n, const char* s, int i, int e, CombatGroup* p=0);
92  ~CombatGroup();
93 
94  // comparison operators are used to sort combat groups into a priority list
95  // in DESCENDING order, so the sense of the comparison is backwards from
96  // usual...
97  int operator < (const CombatGroup& g) const { return value > g.value; }
98  int operator <= (const CombatGroup& g) const { return value >= g.value; }
99  int operator == (const CombatGroup& g) const { return this == &g; }
100 
101  // operations:
102  static CombatGroup* LoadOrderOfBattle(const char* fname, int iff, Combatant* combatant);
103  static void SaveOrderOfBattle(const char* fname, CombatGroup* force);
104  static void MergeOrderOfBattle(BYTE* block, const char* fname, int iff, Combatant* combatant, Campaign* campaign);
105 
106  void AddComponent(CombatGroup* g);
107  CombatGroup* FindGroup(int t, int n=-1);
108  CombatGroup* Clone(bool deep=true);
109 
110  // accessors and mutators:
111  const char* GetDescription() const;
112  const char* GetShortDescription() const;
113 
114  void SetCombatant(Combatant* c) { combatant = c; }
115 
116  Combatant* GetCombatant() { return combatant; }
117  CombatGroup* GetParent() { return parent; }
118  List<CombatGroup>& GetComponents() { return components; }
119  List<CombatGroup>& GetLiveComponents() { return live_comp; }
120  List<CombatUnit>& GetUnits() { return units; }
124  CombatUnit* FindUnit(const char* name);
126 
127  const Text& Name() const { return name; }
128  int Type() const { return type; }
129  int CountUnits() const;
130  int IntelLevel() const { return enemy_intel;}
131  int GetID() const { return id; }
132  int GetIFF() const { return iff; }
133  Point Location() const { return location; }
134  void MoveTo(const Point& loc);
135  const Text& GetRegion() const { return region; }
136  void SetRegion(Text rgn) { region = rgn; }
137  void AssignRegion(Text rgn);
138  int Value() const { return value; }
139  int Sorties() const { return sorties; }
140  void SetSorties(int n) { sorties = n; }
141  int Kills() const { return kills; }
142  void SetKills(int n) { kills = n; }
143  int Points() const { return points; }
144  void SetPoints(int n) { points = n; }
145  int UnitIndex() const { return unit_index; }
146 
147  double GetNextJumpTime() const;
148 
149  double GetPlanValue() const { return plan_value; }
150  void SetPlanValue(double v) { plan_value = v; }
151 
152  bool IsAssignable() const;
153  bool IsTargetable() const;
154  bool IsDefensible() const;
155  bool IsStrikeTarget() const;
156  bool IsMovable() const;
157  bool IsFighterGroup() const;
158  bool IsStarshipGroup() const;
159  bool IsReserve() const;
160 
161  // these two methods return zero terminated arrays of
162  // integers identifying the preferred assets for attack
163  // or defense in priority order:
164  static const int* PreferredAttacker(int type);
165  static const int* PreferredDefender(int type);
166 
167  bool IsExpanded() const { return expanded; }
168  void SetExpanded(bool e) { expanded = e; }
169 
170  const Text& GetAssignedSystem() const { return assigned_system; }
171  void SetAssignedSystem(const char* s);
172  CombatZone* GetCurrentZone() const { return current_zone; }
173  void SetCurrentZone(CombatZone* z) { current_zone = z; }
174  CombatZone* GetAssignedZone() const { return assigned_zone; }
175  void SetAssignedZone(CombatZone* z);
176  void ClearUnlockedZones();
177  bool IsZoneLocked() const { return assigned_zone && zone_lock; }
178  void SetZoneLock(bool lock=true);
179  bool IsSystemLocked() const { return assigned_system.length() > 0; }
180 
181  const Text& GetStrategicDirection() const { return strategic_direction; }
182  void SetStrategicDirection(Text dir) { strategic_direction = dir; }
183 
184  void SetIntelLevel(int n);
185  int CalcValue();
186 
187  List<CombatAssignment>& GetAssignments() { return assignments; }
188  void ClearAssignments();
189 
190  static int TypeFromName(const char* name);
191  static const char* NameFromType(int type);
192 
193 private:
194  const char* GetOrdinal() const;
195 
196  // attributes:
197  int type;
198  int id;
199  Text name;
200  int iff;
201  int enemy_intel;
202 
203  double plan_value; // scratch pad for plan modules
204 
205  List<CombatUnit> units;
206  List<CombatGroup> components;
207  List<CombatGroup> live_comp;
208  Combatant* combatant;
209  CombatGroup* parent;
210  Text region;
211  Point location;
212  int value;
213  int unit_index;
214 
215  int sorties;
216  int kills;
217  int points;
218 
219  bool expanded; // for tree control
220 
221  Text assigned_system;
222  CombatZone* current_zone;
223  CombatZone* assigned_zone;
224  bool zone_lock;
225  List<CombatAssignment> assignments;
226 
227  Text strategic_direction;
228 };
229 
230 #endif CombatGroup_h
231