Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Attack first worker-scout, #16 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/objects/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ void Worker::Repair(const sc2::Unit& target_) {
gAPI->action().ToggleAutocast(Tag(), sc2::ABILITY_ID::EFFECT_REPAIR_SCV);
m_job = Job::REPAIRING;
}

void Worker::Attack(const sc2::Unit& target_) {
gAPI->action().Cast(ToUnit(), sc2::ABILITY_ID::SMART, target_);
m_job = Job::ATTACKING;
}
3 changes: 3 additions & 0 deletions src/objects/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum Job {
BUILDING = 2,
BUILDING_REFINERY = 3,
REPAIRING = 4,
ATTACKING = 5,
};

struct Worker: GameObject {
Expand All @@ -24,6 +25,8 @@ struct Worker: GameObject {

void GatherVespene(const sc2::Unit& target_);

void Attack(const sc2::Unit& target_);

void Repair(const sc2::Unit& target_);

private:
Expand Down
19 changes: 19 additions & 0 deletions src/strategies/Strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "Historican.h"
#include "Strategy.h"
#include "Hub.h"
#include "core/API.h"
#include "core/Helpers.h"

Expand Down Expand Up @@ -47,3 +48,21 @@ void Strategy::OnUnitCreated(const sc2::Unit* unit_, Builder*) {

m_units.push_back(unit_);
}

void Strategy::OnUnitEnterVision(const sc2::Unit* unit_, Builder*) {
if (IsCombatUnit()(*unit_))
return;

if (m_attackFirstScout) {
AssignWorkerAttack(*unit_);
m_attackFirstScout = false; // only attack first scout, first time seen
}
}

void Strategy::AssignWorkerAttack(const sc2::Unit& target_) {
Worker* worker = gHub->GetClosestFreeWorker(target_.pos);
if (!worker)
return;

worker->Attack(target_);
}
5 changes: 5 additions & 0 deletions src/strategies/Strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ struct Strategy : Plugin {

void OnUnitCreated(const sc2::Unit* unit_, Builder*) override;

void OnUnitEnterVision(const sc2::Unit* unit_, Builder*) override;

void AssignWorkerAttack(const sc2::Unit& target_);

protected:
bool m_attackFirstScout = true;
Copy link
Owner

@alkurbatov alkurbatov Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no. The issue was about worker rush, not only first scout. This patch helps in some way, but not much.

float m_attack_limit;
sc2::Units m_units;
};