-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildingManager.h
More file actions
141 lines (87 loc) · 3.83 KB
/
BuildingManager.h
File metadata and controls
141 lines (87 loc) · 3.83 KB
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
#pragma once
#ifndef BUILDING_MANAGER_H
#define BUILDING_MANAGER_H
#include <sc2api/sc2_api.h>
#include <iostream>
#include <vector>
#include "sc2utils/sc2_manage_process.h"
class Bot;
using namespace sc2;
enum CONSTRUCTION_STATE { INEXISTANT, IN_CONSTRUCTION, BUILT };
class Building {
ABILITY_ID construction_id_; // Id of the action to construct.
int minerals_to_build_;
int width_;
int height_;
int construction_duration_; // Time of construction in second.
int GetNumberOfBuildingOfThisType(const ObservationInterface *observation);
int GetNumberOfBuildingOfThisTypeInConstruction(const ObservationInterface *observation);
bool DependenciesCompleted(const ObservationInterface *observation);
bool DependenciesInConstruction(const ObservationInterface *observation);
public:
std::vector<Building*> dependencies_;
UNIT_TYPEID id_;
Building();
Building(UNIT_TYPEID id, ABILITY_ID constructionId, int mineralsToBuild, int width, int height, int constructionDuration);
//<Getter>
int GetCostToBuildInMinerals();
ABILITY_ID GetIdOfActionToBuild();
int GetWidth();
//</Getter>
CONSTRUCTION_STATE GetDependenciesConstructionState(const ObservationInterface *observation);
std::vector<Building*> GetUnbuiltDependencies(const ObservationInterface *observation);
};
class Build {
Point2D position_;
bool core_building_; // Is part of the preselected strat's build order.
bool rebuild_if_destroyed_;
public:
Building * building_; // Do not modify it except if you want to modify this for every other class using it.
Build();
Build(Building *building, Point2D position, bool core_building = false, bool rebuild_if_destroyed = false);
//<Getter>
const Point2D GetPosition() const;
//</Getter>
};
class BuildRafinery : public Build {
const Unit* vespene_geyser_;
public:
BuildRafinery();
BuildRafinery(Building *building, const Unit* vespene_geyser = nullptr, bool core_building = false, bool rebuild_if_destroyed = false);
const Unit* GetGeyser();
};
// TODO, The differents buildings should be interface for the parameters not changings.
class BuildOrder {
int number_of_bases_ = 1;
// Determine which building to build, and when. Also has a build order at start.
public:
std::vector<Build*> builds_pile_;
BuildOrder();
BuildOrder(std::vector<Build*> builds_pile);
bool is_empty();
void DetermineNextBuilding(Bot *bot);
// TODO add function to determine what to build next in function of game observation and current buildings_pile.
// FOR EXAMPLE : if supply_max < 200 and buildings_pile doesn't contain 2 supply_max per barracks + command center : add one.
};
class BuildingManager {
// Tells the building what to produce, and when.
BuildOrder *build_order_;
void TryBuilding(Bot *bot);
void BuildBuilding(Bot *bot, const Build* building_to_build, Vector2D target_position);
void BuildBuilding(Bot *bot, const Build* building_to_build, const Unit* target_geyser);
const Unit* FindNearestGeyser(Bot *bot, const Point2D& start);
const Unit* GetBuilder(const ObservationInterface *observation, const Build* building_to_build);
// TODO :: Find a better name : InexistantDependencies do not reflect well we are talking about unbuilt + not in construction.
// TODO :: Find why we can't have a const Building* as argument for this function (doesn't work for getUnbuiltDependencies call
void AddInexistantDependenciesToPile(const ObservationInterface *observation, Building* building_to_build);
// TODO :: EXIST IN MULTIPLE CLASS, SRP BROKEN!
Point2D BuildingManager::TransformPoint2D(Point2D point, int x_shift, int y_shift);
public:
BuildingManager();
BuildingManager(BuildOrder* openingBuildOrder);
BuildingManager(std::vector<Build*> buildings_pile);
void Update(Bot *bot);
};
#endif // !BUILDING_MANAGER_H
// TODO If dependency not complete, build it.
// TODO Ajouter "if destroyed -> rebuild if rebuildIfDestroyed".