-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOffensiveFightGroup.cpp
106 lines (89 loc) · 2.99 KB
/
OffensiveFightGroup.cpp
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
#include "OffensiveFightGroup.h"
void OffensiveFightGroup::Initialize(MAP_RECT guardedRect, std::vector<Unit> vehicleFactories, const std::vector<TargetTankCount>& targetTankCounts)
{
FightGroupOverlay::Initialize(guardedRect, vehicleFactories);
SetTankCounts(targetTankCounts);
}
void OffensiveFightGroup::CreateTank(map_id type, map_id turret)
{
if (GetFightGroupCount() == targetCount) {
return;
}
auto& vehicleFactory = vehicleFactories[TethysGame::GetRand(vehicleFactories.size())];
if (vehicleFactory.IsLive() && !vehicleFactory.isEMPed()) {
Unit tank;
TethysGame::CreateUnit(tank, type, vehicleFactory.Location(), aiPlayerNum, turret, 0);
tank.DoSetLights(true);
GetFightGroup().TakeUnit(tank);
}
}
void OffensiveFightGroup::Attack(const std::vector<TargetTankCount>& targetCounts)
{
TaskFightGroup(GetFightGroup());
Initialize(GetGuardedRect(), vehicleFactories, targetCounts);
}
void OffensiveFightGroup::TaskFightGroup(FightGroup& fightGroup)
{
int choice = TethysGame::GetRand(4);
switch (choice)
{
case 0: // General Attack
BasicAttack();
return;
case 1: // Attack Command Center / Structure Factory / Vehicle Factory
AttackBuilding(fightGroup, std::vector<map_id>{ map_id::mapCommandCenter, mapStructureFactory, mapVehicleFactory });
return;
case 2: // Attack MiningBuilding
AttackBuilding(fightGroup, std::vector<map_id>{
mapCommonOreSmelter, mapRareOreSmelter, mapCommonOreMine, mapRareOreMine});
return;
case 3: // Spaceport / Advanced Lab
AttackBuilding(fightGroup, std::vector<map_id> { mapSpaceport, mapAdvancedLab});
return;
}
}
void OffensiveFightGroup::AttackBuilding(FightGroup& fightGroup, const std::vector<map_id>& buildingTypes)
{
std::vector<Unit> buildings;
GetHumanBuildings(buildings, buildingTypes);
if (buildings.empty())
{
BasicAttack();
return;
}
Unit building = buildings[TethysGame::GetRand(buildings.size())];
MAP_RECT mapRect(
building.Location().x - 5, building.Location().y - 5,
building.Location().x + 5, building.Location().y + 5
);
fightGroup.SetRect(mapRect);
fightGroupsWithTarget.push_back(FightGroupTarget{ fightGroup, building });
}
void OffensiveFightGroup::GetHumanBuildings(std::vector<Unit>& buildingsOut, const std::vector<map_id>& buildingTypes)
{
for (map_id buildingType : buildingTypes) {
GetHumanBuildings(buildingsOut, buildingType);
}
}
void OffensiveFightGroup::GetHumanBuildings(std::vector<Unit>& buildingsOut, map_id buildingType)
{
Unit building;
for (std::size_t i = 0; i < humanPlayerCount; ++i)
{
PlayerBuildingEnum playerBuildingEnum(i, buildingType);
while (playerBuildingEnum.GetNext(building))
{
buildingsOut.push_back(building);
}
}
}
void OffensiveFightGroup::UpdateTaskedFightGroups()
{
for (int i = fightGroupsWithTarget.size(); i-- > 0; ) {
if (!fightGroupsWithTarget[i].building.IsLive()) {
FightGroupTarget fightGroupTarget = fightGroupsWithTarget[i];
fightGroupsWithTarget.erase(fightGroupsWithTarget.begin() + i);
TaskFightGroup(fightGroupTarget.fightGroup);
}
}
}