ProtoBot
Loading...
Searching...
No Matches
KitingBehaviors Class Reference

Static Public Member Functions

static void kitingMelee (BWAPI::Unit unit, BWAPI::Position targetPos)
static void kitingRanged (BWAPI::Unit unit, BWAPI::Position targetPos, BWAPI::Position closestCPPosition=BWAPI::Positions::Invalid)

Detailed Description

Definition at line 150 of file SquadStateTypes.h.

Member Function Documentation

◆ kitingMelee()

void KitingBehaviors::kitingMelee ( BWAPI::Unit unit,
BWAPI::Position targetPos )
static

Definition at line 163 of file SquadStateTypes.cpp.

163 {
164 if (!unit) {
165 return;
166 }
167
168 if (BWAPI::Broodwar->getFrameCount() % KITING_FRAME_DELAY != 0) {
169 return;
170 }
171
172 // If unit already had a command assigned to it this frame, ignore
173 if (unit->getLastCommandFrame() >= BWAPI::Broodwar->getFrameCount()) {
174 return;
175 }
176
177 // If unit is already attacking, ignore
178 if (unit->isStartingAttack() || unit->isAttackFrame()) {
179 return;
180 }
181
182 if (unit->getGroundWeaponCooldown() == 0) {
183 unit->attack(targetPos);
184 }
185 else {
186 unit->move(BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation()));
187 }
188}

◆ kitingRanged()

void KitingBehaviors::kitingRanged ( BWAPI::Unit unit,
BWAPI::Position targetPos,
BWAPI::Position closestCPPosition = BWAPI::Positions::Invalid )
static

Definition at line 190 of file SquadStateTypes.cpp.

190 {
191 // If unit or target is invalid, return
192 if (!unit) {
193 return;
194 }
195
196 if (BWAPI::Broodwar->getFrameCount() % KITING_FRAME_DELAY != 0) {
197 return;
198 }
199
200 // If unit already had a command assigned to it this frame, ignore
201 if (unit->getLastCommandFrame() >= BWAPI::Broodwar->getFrameCount()) {
202 return;
203 }
204
205 // If unit is already attacking, ignore
206 if (unit->isStartingAttack() || unit->isAttackFrame()) {
207 return;
208 }
209
210 if (unit->getGroundWeaponCooldown() == 0) {
211 BWAPI::Unit attackingUnit = nullptr;
212 if (unit->isUnderAttack()) {
213 BWAPI::Unitset enemies = unit->getLastAttackingPlayer()->getUnits();
214 for (const auto& enemyUnit : enemies) {
215 if (!enemyUnit->exists()) {
216 continue;
217 }
218
219 if (enemyUnit->getOrderTarget() == unit) {
220 attackingUnit = enemyUnit;
221 break;
222 }
223 }
224 }
225
226 if (attackingUnit != nullptr) {
227 unit->attack(attackingUnit);
228 }
229 else {
230 unit->attack(targetPos);
231 }
232 }
233 else {
234 // If within range of a CP, move forwards (to your DOOM) to give space for army to enter chokepoint
235 constexpr int minDist = 150;
236 if (closestCP != BWAPI::Positions::Invalid && unit->getPosition().getApproxDistance(closestCP) < minDist) {
237 BWAPI::Broodwar->drawCircleMap(closestCP, minDist, BWAPI::Colors::Yellow);
238 unit->move(targetPos);
239 }
240 else {
241 unit->move(BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation()));
242 }
243 }
244}

The documentation for this class was generated from the following files: