Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Campaign.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2006. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: Campaign.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Campaign defines a strategic military scenario. This class
13  owns (or generates) the Mission list that defines the action
14  in the campaign.
15 */
16 
17 #ifndef Campaign_h
18 #define Campaign_h
19 
20 #include "Types.h"
21 #include "Bitmap.h"
22 #include "Geometry.h"
23 #include "Text.h"
24 #include "Term.h"
25 #include "List.h"
26 
27 // +--------------------------------------------------------------------+
28 
29 class Campaign;
30 class CampaignPlan;
31 class Combatant;
32 class CombatAction;
33 class CombatEvent;
34 class CombatGroup;
35 class CombatUnit;
36 class CombatZone;
37 class DataLoader;
38 class Mission;
39 class MissionTemplate;
40 class StarSystem;
41 
42 // +--------------------------------------------------------------------+
43 
45 {
46 public:
47  static const char* TYPENAME() { return "MissionInfo"; }
48 
49  MissionInfo();
50  ~MissionInfo();
51 
52  int operator == (const MissionInfo& m) const { return id == m.id; }
53  int operator < (const MissionInfo& m) const { return id < m.id; }
54  int operator <= (const MissionInfo& m) const { return id <= m.id; }
55 
56  bool IsAvailable();
57 
58  int id;
65  int start;
66  int type;
67 
68  int min_rank;
69  int max_rank;
70  int action_id;
72  int exec_once;
75 
77 };
78 
80 {
81 public:
82  static const char* TYPENAME() { return "TemplateList"; }
83 
84  TemplateList();
85  ~TemplateList();
86 
89  int index;
91 };
92 
93 // +--------------------------------------------------------------------+
94 
95 class Campaign
96 {
97 public:
98  static const char* TYPENAME() { return "Campaign"; }
99 
100  enum CONSTANTS {
107 
109  };
110 
111  enum STATUS {
116  };
117 
118  Campaign(int id, const char* name=0);
119  Campaign(int id, const char* name, const char* path);
120  virtual ~Campaign();
121 
122  int operator == (const Campaign& s) const { return name == s.name; }
123  int operator < (const Campaign& s) const { return campaign_id < s.campaign_id; }
124 
125  // operations:
126  virtual void Load();
127  virtual void Prep();
128  virtual void Start();
129  virtual void ExecFrame();
130  virtual void Unload();
131 
132  virtual void Clear();
133  virtual void CommitExpiredActions();
134  virtual void LockoutEvents(int seconds);
135  virtual void CheckPlayerGroup();
136  void CreatePlanners();
137 
138  // accessors:
139  const char* Name() const { return name; }
140  const char* Description() const { return description; }
141  const char* Path() const { return path; }
142 
143  const char* Situation() const { return situation; }
144  const char* Orders() const { return orders; }
145 
146  void SetSituation(const char* s) { situation = s; }
147  void SetOrders(const char* o) { orders = o; }
148 
149  int GetPlayerTeamScore();
157 
158  CombatAction* FindAction(int id);
159 
160  int CountNewEvents() const;
161 
162  int GetPlayerIFF();
164  void SetPlayerGroup(CombatGroup* pg);
166  void SetPlayerUnit(CombatUnit* pu);
167 
168  Combatant* GetCombatant(const char* name);
169  CombatGroup* FindGroup(int iff, int type, int id);
170  CombatGroup* FindGroup(int iff, int type, CombatGroup* near_group=0);
171  CombatGroup* FindStrikeTarget(int iff, CombatGroup* strike_group);
172 
173  StarSystem* GetSystem(const char* sys);
174  CombatZone* GetZone(const char* rgn);
176  void DeleteMission(int id);
177  Mission* GetMission();
178  Mission* GetMission(int id);
179  Mission* GetMissionByFile(const char* filename);
180  MissionInfo* GetMissionInfo(int id);
182  void ReloadMission(int id);
183  void LoadNetMission(int id, const char* net_mission);
184  void StartMission();
185  void RollbackMission();
186 
187  void SetCampaignId(int id);
188  int GetCampaignId() const { return campaign_id; }
189  void SetMissionId(int id);
190  int GetMissionId() const { return mission_id; }
191  Bitmap* GetImage(int n) { return &image[n]; }
192  double GetTime() const { return time; }
193  double GetStartTime() const { return startTime; }
194  void SetStartTime(double t) { startTime = t; }
195  double GetLoadTime() const { return loadTime; }
196  void SetLoadTime(double t) { loadTime = t; }
197  double GetUpdateTime() const { return updateTime; }
198  void SetUpdateTime(double t) { updateTime = t; }
199 
200  bool InCutscene() const;
201  bool IsDynamic() const;
202  bool IsTraining() const;
203  bool IsScripted() const;
204  bool IsSequential() const;
205  bool IsSaveGame() const { return loaded_from_savegame; }
206  void SetSaveGame(bool s) { loaded_from_savegame = s; }
207 
208  bool IsActive() const { return status == CAMPAIGN_ACTIVE; }
209  bool IsComplete() const { return status == CAMPAIGN_SUCCESS; }
210  bool IsFailed() const { return status == CAMPAIGN_FAILED; }
211  void SetStatus(int s);
212  int GetStatus() const { return status; }
213 
214  int GetAllCombatUnits(int iff, List<CombatUnit>& units);
215 
216  static void Initialize();
217  static void Close();
218  static Campaign* GetCampaign();
219  static List<Campaign>&
220  GetAllCampaigns();
221  static int GetLastCampaignId();
222  static Campaign* SelectCampaign(const char* name);
223  static Campaign* CreateCustomCampaign(const char* name, const char* path);
224 
225  static double Stardate();
226 
227 protected:
228  void LoadCampaign(DataLoader* loader, bool full=false);
229  void LoadTemplateList(DataLoader* loader);
230  void LoadMissionList(DataLoader* loader);
231  void LoadCustomMissions(DataLoader* loader);
232  void ParseGroup(TermStruct* val,
233  CombatGroup* force,
234  CombatGroup* clone,
235  const char* filename);
236  void ParseAction(TermStruct* val,
237  const char* filename);
239  CombatGroup* clone,
240  CombatGroup* group);
241  void SelectDefaultPlayerGroup(CombatGroup* g, int type);
242  TemplateList* GetTemplateList(int msn_type, int grp_type);
243 
244  // attributes:
246  int status;
247  char filename[64];
248  char path[64];
254 
255  bool scripted;
258 
269 
273 
274  double time;
275  double loadTime;
276  double startTime;
277  double updateTime;
278  int lockout;
279 };
280 
281 #endif Campaign_h
282