Skip to content

Commit

Permalink
davechurchill#34 Add support for BWAPI 4.3.0
Browse files Browse the repository at this point in the history
Copy the whole Source folder from BWAPI_420 (I didn't modify anything).
  • Loading branch information
chriscoxe committed Mar 3, 2019
1 parent cf783de commit 108a76c
Show file tree
Hide file tree
Showing 6 changed files with 801 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/tournamentmodule/BWAPI_430/Source/AutoObserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "AutoObserver.h"

AutoObserver::AutoObserver()
: _unitFollowFrames(0)
, _cameraLastMoved(0)
, _observerFollowingUnit(NULL)
{

}

void AutoObserver::onFrame()
{
bool pickUnitToFollow = !_observerFollowingUnit || !_observerFollowingUnit->exists() || (BWAPI::Broodwar->getFrameCount() - _cameraLastMoved > _unitFollowFrames);

if (pickUnitToFollow)
{
for (BWAPI::UnitInterface * unit : BWAPI::Broodwar->getAllUnits())
{
if (unit->isUnderAttack() || unit->isAttacking())
{
_cameraLastMoved = BWAPI::Broodwar->getFrameCount();
_unitFollowFrames = 6;
_observerFollowingUnit = unit;
pickUnitToFollow = false;
break;
}
}
}

if (pickUnitToFollow)
{
for (BWAPI::UnitInterface * unit : BWAPI::Broodwar->getAllUnits())
{
if (unit->isBeingConstructed() && (unit->getRemainingBuildTime() < 12))
{
_cameraLastMoved = BWAPI::Broodwar->getFrameCount();
_unitFollowFrames = 24;
_observerFollowingUnit = unit;
pickUnitToFollow = false;
break;
}
}
}

if (_observerFollowingUnit && _observerFollowingUnit->exists())
{
BWAPI::Broodwar->setScreenPosition(_observerFollowingUnit->getPosition() - BWAPI::Position(320, 180));
}
}
15 changes: 15 additions & 0 deletions src/tournamentmodule/BWAPI_430/Source/AutoObserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "BWAPI.h"

class AutoObserver
{
int _cameraLastMoved;
int _unitFollowFrames;
BWAPI::UnitInterface * _observerFollowingUnit;

public:

AutoObserver();
void onFrame();
};
20 changes: 20 additions & 0 deletions src/tournamentmodule/BWAPI_430/Source/Dll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <BWAPI.h>

#include "ExampleTournamentModule.h"

extern "C" __declspec(dllexport) void gameInit(BWAPI::Game* game) { BWAPI::BroodwarPtr = game; }

BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID)
{
return TRUE;
}

extern "C" __declspec(dllexport) BWAPI::AIModule* newTournamentAI()
{
return new ExampleTournamentAI();
}

extern "C" __declspec(dllexport) BWAPI::TournamentModule* newTournamentModule()
{
return new ExampleTournamentModule();
}
Loading

0 comments on commit 108a76c

Please sign in to comment.