File tree 5 files changed +35
-2
lines changed
5 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,22 @@ void Hub::AssignVespeneHarvester(const sc2::Unit& refinery_) {
279
279
worker->GatherVespene (refinery_);
280
280
}
281
281
282
+ void Hub::RemoveVespeneHarvester (const sc2::Unit& refinery_) {
283
+ const std::list<Worker>& workers = m_busy_workers ();
284
+ auto vespener = std::find_if (workers.begin (), workers.end (),
285
+ [refinery_](const Worker& worker_) {
286
+ return !worker_.m_unit ->orders .empty () &&
287
+ worker_.m_unit ->orders .front ().target_unit_tag == refinery_.tag &&
288
+ worker_.m_unit ->last_seen_game_loop == gAPI ->observer ().GetGameLoop ();
289
+ });
290
+
291
+ if (vespener == workers.end ())
292
+ return ;
293
+
294
+ // NOTE (impulsecloud): STOP forces OnIdle next frame
295
+ gAPI ->action ().Cast (vespener->ToUnit (), sc2::ABILITY_ID::STOP_STOP);
296
+ }
297
+
282
298
bool Hub::AssignLarva (Order* order_) {
283
299
if (m_larva.Empty ())
284
300
return false ;
Original file line number Diff line number Diff line change 15
15
16
16
template <typename T>
17
17
struct Cache {
18
+ const std::list<T>& operator ()();
19
+
18
20
bool Empty () const ;
19
21
20
22
uint64_t Count () const ;
@@ -37,6 +39,11 @@ struct Cache {
37
39
std::list<T> m_objects;
38
40
};
39
41
42
+ template <typename T>
43
+ const std::list<T>& Cache<T>::operator ()() {
44
+ return m_objects;
45
+ }
46
+
40
47
template <typename T>
41
48
bool Cache<T>::Empty() const {
42
49
return m_objects.empty ();
@@ -145,6 +152,8 @@ struct Hub {
145
152
146
153
void AssignVespeneHarvester (const sc2::Unit& refinery_);
147
154
155
+ void RemoveVespeneHarvester (const sc2::Unit& refinery_);
156
+
148
157
bool AssignLarva (Order* order_);
149
158
150
159
const Cache<GameObject>& GetLarvas () const ;
Original file line number Diff line number Diff line change 6
6
#include " core/API.h"
7
7
8
8
GameObject::GameObject (sc2::Tag tag_): m_tag(tag_) {
9
+ m_unit = gAPI ->observer ().GetUnit (tag_);
9
10
}
10
11
11
- GameObject::GameObject (const sc2::Unit& unit_): m_tag(unit_.tag) {
12
+ GameObject::GameObject (const sc2::Unit& unit_): m_unit(&unit_), m_tag(unit_.tag) {
12
13
}
13
14
14
15
bool GameObject::operator ==(const GameObject& obj_) const {
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ struct GameObject {
24
24
25
25
static sc2::Unit ToUnit (sc2::Tag tag_);
26
26
27
+ const sc2::Unit* m_unit;
28
+
27
29
private:
28
30
sc2::Tag m_tag;
29
31
};
Original file line number Diff line number Diff line change @@ -44,7 +44,12 @@ void SecureVespeneIncome() {
44
44
auto refineries = gAPI ->observer ().GetUnits (IsRefinery ());
45
45
46
46
for (const auto & i : refineries ()) {
47
- if (i->assigned_harvesters >= i->ideal_harvesters )
47
+ if (i->assigned_harvesters > i->ideal_harvesters ) {
48
+ gHub ->RemoveVespeneHarvester (*i);
49
+ continue ;
50
+ }
51
+
52
+ if (i->assigned_harvesters == i->ideal_harvesters )
48
53
continue ;
49
54
50
55
gHub ->AssignVespeneHarvester (*i);
You can’t perform that action at this time.
0 commit comments