summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Combatant.cpp
blob: b6d8794214dc1dfd0bf0e7297bed68e464e90411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    One side in a military conflict
*/

#include "Combatant.h"
#include "CombatGroup.h"
#include "Mission.h"

#include "Game.h"

// +--------------------------------------------------------------------+

static void SetCombatant(CombatGroup* g, Combatant* c)
{
    if (!g) return;

    g->SetCombatant(c);

    ListIter<CombatGroup> iter = g->GetComponents();
    while (++iter)
    SetCombatant(iter.value(), c);
}

// +--------------------------------------------------------------------+

Combatant::Combatant(const char* com_name, const char* fname, int team)
    : name(com_name), iff(team), score(0), force(0)
{
    for (int i = 0; i < 6; i++)
    target_factor[i] = 1;

    target_factor[2] = 1000;

    if (fname)
    force = CombatGroup::LoadOrderOfBattle(fname, iff, this);
}

Combatant::Combatant(const char* com_name, CombatGroup* f)
    : name(com_name), iff(0), score(0), force(f)
{
    for (int i = 0; i < 6; i++)
    target_factor[i] = 1;

    target_factor[2] = 1000;

    if (force) {
        SetCombatant(force, this);
        iff = force->GetIFF();
    }
}

// +--------------------------------------------------------------------+

Combatant::~Combatant()
{
    mission_list.clear();
    target_list.clear();
    defend_list.clear();
    delete force;
}

// +--------------------------------------------------------------------+

CombatGroup*
Combatant::FindGroup(int type, int id)
{
    if (force)
    return force->FindGroup(type, id);

    return 0;
}

// +--------------------------------------------------------------------+

void
Combatant::AddMission(Mission* mission)
{
    mission_list.append(mission);
}

// +--------------------------------------------------------------------+

double
Combatant::GetTargetStratFactor(int type)
{
    switch (type) {
    case CombatGroup::FLEET:
    case CombatGroup::CARRIER_GROUP:
    case CombatGroup::BATTLE_GROUP:
    case CombatGroup::DESTROYER_SQUADRON:   return target_factor[0];

    case CombatGroup::WING:
    case CombatGroup::ATTACK_SQUADRON:
    case CombatGroup::INTERCEPT_SQUADRON:
    case CombatGroup::FIGHTER_SQUADRON:     return target_factor[1];

    case CombatGroup::BATTERY:
    case CombatGroup::MISSILE:              return target_factor[2];

    case CombatGroup::BATTALION:
    case CombatGroup::STARBASE:
    case CombatGroup::C3I:
    case CombatGroup::COMM_RELAY:
    case CombatGroup::EARLY_WARNING:
    case CombatGroup::FWD_CONTROL_CTR:
    case CombatGroup::ECM:                  return target_factor[3];

    case CombatGroup::SUPPORT:
    case CombatGroup::COURIER:
    case CombatGroup::MEDICAL:
    case CombatGroup::SUPPLY:
    case CombatGroup::REPAIR:               return target_factor[4];
    }

    return target_factor[5];
}

// +--------------------------------------------------------------------+

void
Combatant::SetTargetStratFactor(int type, double factor)
{
    switch (type) {
    case CombatGroup::FLEET:
    case CombatGroup::CARRIER_GROUP:
    case CombatGroup::BATTLE_GROUP:
    case CombatGroup::DESTROYER_SQUADRON:  target_factor[0] = factor;
        break;

    case CombatGroup::WING:
    case CombatGroup::ATTACK_SQUADRON:
    case CombatGroup::INTERCEPT_SQUADRON:
    case CombatGroup::FIGHTER_SQUADRON:    target_factor[1] = factor;
        break;

    case CombatGroup::BATTALION:
    case CombatGroup::STARBASE:
    case CombatGroup::BATTERY:
    case CombatGroup::MISSILE:             target_factor[2] = factor;
        break;

    case CombatGroup::C3I:
    case CombatGroup::COMM_RELAY:
    case CombatGroup::EARLY_WARNING:
    case CombatGroup::FWD_CONTROL_CTR:
    case CombatGroup::ECM:                 target_factor[3] = factor;
        break;

    case CombatGroup::SUPPORT:
    case CombatGroup::COURIER:
    case CombatGroup::MEDICAL:
    case CombatGroup::SUPPLY:
    case CombatGroup::REPAIR:              target_factor[4] = factor;
        break;

    default:                               target_factor[5] = factor;
        break;
    }
}