Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Combatant.cpp
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: Combatant.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  One side in a military conflict
13 */
14 
15 #include "MemDebug.h"
16 #include "Combatant.h"
17 #include "CombatGroup.h"
18 #include "Mission.h"
19 
20 #include "Game.h"
21 
22 // +--------------------------------------------------------------------+
23 
24 static void SetCombatant(CombatGroup* g, Combatant* c)
25 {
26  if (!g) return;
27 
28  g->SetCombatant(c);
29 
31  while (++iter)
32  SetCombatant(iter.value(), c);
33 }
34 
35 // +--------------------------------------------------------------------+
36 
37 Combatant::Combatant(const char* com_name, const char* fname, int team)
38 : name(com_name), iff(team), score(0), force(0)
39 {
40  for (int i = 0; i < 6; i++)
41  target_factor[i] = 1;
42 
43  target_factor[2] = 1000;
44 
45  if (fname)
46  force = CombatGroup::LoadOrderOfBattle(fname, iff, this);
47 }
48 
49 Combatant::Combatant(const char* com_name, CombatGroup* f)
50 : name(com_name), iff(0), score(0), force(f)
51 {
52  for (int i = 0; i < 6; i++)
53  target_factor[i] = 1;
54 
55  target_factor[2] = 1000;
56 
57  if (force) {
58  SetCombatant(force, this);
59  iff = force->GetIFF();
60  }
61 }
62 
63 // +--------------------------------------------------------------------+
64 
66 {
67  mission_list.clear();
68  target_list.clear();
69  defend_list.clear();
70  delete force;
71 }
72 
73 // +--------------------------------------------------------------------+
74 
76 Combatant::FindGroup(int type, int id)
77 {
78  if (force)
79  return force->FindGroup(type, id);
80 
81  return 0;
82 }
83 
84 // +--------------------------------------------------------------------+
85 
86 void
88 {
89  mission_list.append(mission);
90 }
91 
92 // +--------------------------------------------------------------------+
93 
94 double
96 {
97  switch (type) {
98  case CombatGroup::FLEET:
101  case CombatGroup::DESTROYER_SQUADRON: return target_factor[0];
102 
103  case CombatGroup::WING:
106  case CombatGroup::FIGHTER_SQUADRON: return target_factor[1];
107 
109  case CombatGroup::MISSILE: return target_factor[2];
110 
113  case CombatGroup::C3I:
117  case CombatGroup::ECM: return target_factor[3];
118 
122  case CombatGroup::SUPPLY:
123  case CombatGroup::REPAIR: return target_factor[4];
124  }
125 
126  return target_factor[5];
127 }
128 
129 // +--------------------------------------------------------------------+
130 
131 void
132 Combatant::SetTargetStratFactor(int type, double factor)
133 {
134  switch (type) {
135  case CombatGroup::FLEET:
138  case CombatGroup::DESTROYER_SQUADRON: target_factor[0] = factor;
139  break;
140 
141  case CombatGroup::WING:
144  case CombatGroup::FIGHTER_SQUADRON: target_factor[1] = factor;
145  break;
146 
150  case CombatGroup::MISSILE: target_factor[2] = factor;
151  break;
152 
153  case CombatGroup::C3I:
157  case CombatGroup::ECM: target_factor[3] = factor;
158  break;
159 
163  case CombatGroup::SUPPLY:
164  case CombatGroup::REPAIR: target_factor[4] = factor;
165  break;
166 
167  default: target_factor[5] = factor;
168  break;
169  }
170 }
171 
172