Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
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
30
ListIter<CombatGroup>
iter = g->
GetComponents
();
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
65
Combatant::~Combatant
()
66
{
67
mission_list.
clear
();
68
target_list.
clear
();
69
defend_list.
clear
();
70
delete
force;
71
}
72
73
// +--------------------------------------------------------------------+
74
75
CombatGroup
*
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
87
Combatant::AddMission
(
Mission
* mission)
88
{
89
mission_list.
append
(mission);
90
}
91
92
// +--------------------------------------------------------------------+
93
94
double
95
Combatant::GetTargetStratFactor
(
int
type)
96
{
97
switch
(type) {
98
case
CombatGroup::FLEET
:
99
case
CombatGroup::CARRIER_GROUP
:
100
case
CombatGroup::BATTLE_GROUP
:
101
case
CombatGroup::DESTROYER_SQUADRON
:
return
target_factor[0];
102
103
case
CombatGroup::WING
:
104
case
CombatGroup::ATTACK_SQUADRON
:
105
case
CombatGroup::INTERCEPT_SQUADRON
:
106
case
CombatGroup::FIGHTER_SQUADRON
:
return
target_factor[1];
107
108
case
CombatGroup::BATTERY
:
109
case
CombatGroup::MISSILE
:
return
target_factor[2];
110
111
case
CombatGroup::BATTALION
:
112
case
CombatGroup::STARBASE
:
113
case
CombatGroup::C3I
:
114
case
CombatGroup::COMM_RELAY
:
115
case
CombatGroup::EARLY_WARNING
:
116
case
CombatGroup::FWD_CONTROL_CTR
:
117
case
CombatGroup::ECM
:
return
target_factor[3];
118
119
case
CombatGroup::SUPPORT
:
120
case
CombatGroup::COURIER
:
121
case
CombatGroup::MEDICAL
:
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
:
136
case
CombatGroup::CARRIER_GROUP
:
137
case
CombatGroup::BATTLE_GROUP
:
138
case
CombatGroup::DESTROYER_SQUADRON
: target_factor[0] = factor;
139
break
;
140
141
case
CombatGroup::WING
:
142
case
CombatGroup::ATTACK_SQUADRON
:
143
case
CombatGroup::INTERCEPT_SQUADRON
:
144
case
CombatGroup::FIGHTER_SQUADRON
: target_factor[1] = factor;
145
break
;
146
147
case
CombatGroup::BATTALION
:
148
case
CombatGroup::STARBASE
:
149
case
CombatGroup::BATTERY
:
150
case
CombatGroup::MISSILE
: target_factor[2] = factor;
151
break
;
152
153
case
CombatGroup::C3I
:
154
case
CombatGroup::COMM_RELAY
:
155
case
CombatGroup::EARLY_WARNING
:
156
case
CombatGroup::FWD_CONTROL_CTR
:
157
case
CombatGroup::ECM
: target_factor[3] = factor;
158
break
;
159
160
case
CombatGroup::SUPPORT
:
161
case
CombatGroup::COURIER
:
162
case
CombatGroup::MEDICAL
:
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
Stars45
Combatant.cpp
Generated on Thu May 31 2012 16:31:04 for Starshatter_Open by
1.8.1