Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
CampaignPlanAssignment.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: CampaignPlanAssignment.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
CampaignPlanAssignment creates combat assignments for
13
assets within each combat zone as the third step in
14
force tasking.
15
*/
16
17
#include "
MemDebug.h
"
18
#include "
CampaignPlanAssignment.h
"
19
#include "
Campaign.h
"
20
#include "
Combatant.h
"
21
#include "
CombatAssignment.h
"
22
#include "
CombatGroup.h
"
23
#include "
CombatUnit.h
"
24
#include "
CombatZone.h
"
25
#include "
Mission.h
"
26
27
// +--------------------------------------------------------------------+
28
29
void
30
CampaignPlanAssignment::ExecFrame
()
31
{
32
if
(
campaign
&&
campaign
->
IsActive
()) {
33
// once every few minutes is plenty:
34
if
(
Campaign::Stardate
() -
exec_time
< 300)
35
return
;
36
37
ListIter<Combatant>
iter =
campaign
->
GetCombatants
();
38
while
(++iter) {
39
ProcessCombatant
(iter.
value
());
40
}
41
42
exec_time
=
Campaign::Stardate
();
43
}
44
}
45
46
// +--------------------------------------------------------------------+
47
48
void
49
CampaignPlanAssignment::ProcessCombatant
(
Combatant
* c)
50
{
51
CombatGroup
* force = c->
GetForce
();
52
if
(force) {
53
force->
CalcValue
();
54
force->
ClearAssignments
();
55
}
56
57
ListIter<CombatZone>
zone =
campaign
->
GetZones
();
58
while
(++zone) {
59
ProcessZone
(c, zone.
value
());
60
}
61
}
62
63
// +--------------------------------------------------------------------+
64
65
void
66
CampaignPlanAssignment::BuildZoneList
(
CombatGroup
* g,
CombatZone
* zone,
List<CombatGroup>
& groups)
67
{
68
if
(!g)
69
return
;
70
71
if
(g->
GetAssignedZone
() == zone)
72
groups.
append
(g);
73
74
ListIter<CombatGroup>
iter = g->
GetComponents
();
75
while
(++iter)
76
BuildZoneList
(iter.
value
(), zone, groups);
77
}
78
79
// +--------------------------------------------------------------------+
80
81
void
82
CampaignPlanAssignment::BuildAssetList
(
const
int
* pref,
83
List<CombatGroup>
& groups,
84
List<CombatGroup>
& assets)
85
{
86
if
(!pref)
87
return
;
88
89
while
(*pref) {
90
ListIter<CombatGroup>
g = groups;
91
while
(++g) {
92
if
(g->
Type
() == *pref && g->
CountUnits
() > 0)
93
assets.
append
(g.
value
());
94
}
95
96
pref++;
97
}
98
}
99
100
// +--------------------------------------------------------------------+
101
102
void
103
CampaignPlanAssignment::ProcessZone
(
Combatant
* c,
CombatZone
* zone)
104
{
105
List<CombatGroup>
groups;
106
BuildZoneList
(c->
GetForce
(), zone, groups);
107
108
ZoneForce
* force = zone->
FindForce
(c->
GetIFF
());
109
110
// defensive assignments:
111
ListIter<CombatGroup>
def = force->GetDefendList();
112
while
(++def) {
113
List<CombatGroup>
assets;
114
BuildAssetList
(
CombatGroup::PreferredDefender
(def->
Type
()), groups, assets);
115
116
ListIter<CombatGroup>
g = assets;
117
while
(++g) {
118
CombatAssignment
* a =
new
(__FILE__,__LINE__)
119
CombatAssignment
(
Mission::DEFEND
,
120
def.
value
(),
121
g.
value
());
122
123
if
(a)
124
g->
GetAssignments
().
append
(a);
125
}
126
}
127
128
// offensive assignments:
129
ListIter<CombatGroup>
tgt = force->GetTargetList();
130
while
(++tgt) {
131
CombatGroup
* target = tgt.
value
();
132
133
List<CombatGroup>
assets;
134
BuildAssetList
(
CombatGroup::PreferredAttacker
(tgt->
Type
()), groups, assets);
135
136
ListIter<CombatGroup>
g = assets;
137
while
(++g) {
138
CombatGroup
* asset = g.
value
();
139
int
mtype =
Mission::ASSAULT
;
140
141
if
(target->
IsStrikeTarget
())
142
mtype =
Mission::STRIKE
;
143
144
else
if
(target->
IsFighterGroup
())
145
mtype =
Mission::SWEEP
;
146
147
else
if
(target->
Type
() ==
CombatGroup::LCA_SQUADRON
)
148
mtype =
Mission::INTERCEPT
;
149
150
CombatAssignment
* a =
new
(__FILE__,__LINE__)
151
CombatAssignment
(mtype, target, asset);
152
153
if
(a)
154
g->
GetAssignments
().
append
(a);
155
}
156
}
157
}
158
Stars45
CampaignPlanAssignment.cpp
Generated on Tue Jun 5 2012 20:46:46 for Starshatter_Open by
1.8.1