Exemple #1
0
void EventDispatcher::dispatchEvent(BWAPI::Event* e)
{
    switch(e->type)
	{
	case BWAPI::EventType::MatchStart:
		onMatchStart();
		break;
	case BWAPI::EventType::MatchEnd:
		onMatchEnd(e->isWinner);
		break;
    case BWAPI::EventType::MatchFrame:
        onMatchFrame();
        break;
    case BWAPI::EventType::MenuFrame:
        onMenuFrame();
        break;
    case BWAPI::EventType::SendText:
		onSendText(e->text);
        break;
    case BWAPI::EventType::ReceiveText:
		onReceiveText(e->player, e->text);
        break;
    case BWAPI::EventType::PlayerLeft:
        onPlayerLeft(e->player);
        break;
    case BWAPI::EventType::NukeDetect:
		onNukeDetect(e->position);
        break;
    case BWAPI::EventType::UnitDiscover:
        onUnitDiscover(e->unit);
        break;
    case BWAPI::EventType::UnitEvade:
        onUnitEvade(e->unit);
        break;
    case BWAPI::EventType::UnitShow:
        onUnitShow(e->unit);
        break;
    case BWAPI::EventType::UnitHide:
        onUnitHide(e->unit);
        break;
    case BWAPI::EventType::UnitCreate:
        onUnitCreate(e->unit);
        break;
    case BWAPI::EventType::UnitDestroy:
        onUnitDestroy(e->unit);
        break;
    case BWAPI::EventType::UnitMorph:
        onUnitMorph(e->unit);
        break;
    case BWAPI::EventType::UnitRenegade:
        onUnitRenegade(e->unit);
        break;
    case BWAPI::EventType::SaveGame:
        onSaveGame(e->text);
        break;
    case BWAPI::EventType::None:
        break;
    default:
        printf("error: Unknown event");
        break;
	}
}
Exemple #2
0
	void AIModule::onStart()
	{
		// some game, debug and info settings
		debug = false;
		autocam = true;
		gui = true;

		saveMatchResult = false;

		// some informations on start
		game->printf("Dementor bot is alive");

		std::string mapName = game->mapName();
		std::set<BWAPI::TilePosition> startLocations = game->getStartLocations();
		game->printf("The map is %s, a %d player map", mapName.c_str(), startLocations.size());

		game->printf("Enabled UserInput flag.");
		game->enableFlag(BWAPI::Flag::UserInput);

		onSendText("gsfs");

		// reading and analyzing map
		BWTA::readMap();
		BWTA::analyze();

		// managers creation and registering
		workerManager = new WorkerManager(&arbitrator);
		registerController(WorkerManagerType, workerManager);

		buildManager = new BuildManager(&arbitrator);
		registerController(BuildManagerType, buildManager);

		techManager = new TechManager(&arbitrator);
		registerController(TechManagerType, techManager);

		upgradeManager = new UpgradeManager(&arbitrator);
		registerController(UpgradeManagerType, upgradeManager);

		supplyManager = new SupplyManager();
		registerController(SupplyManagerType, supplyManager);

		baseManager = new BaseManager();
		registerController(BaseManagerType, baseManager);

		buildOrderManager = new BuildOrderManager(buildManager, techManager, upgradeManager, workerManager, supplyManager);
		registerController(BuildOrderManagerType, buildOrderManager);

		agentManager = new AgentManager(this);
		registerController(AgentManagerType, agentManager);

		repairManager = new RepairManager(this);
		registerController(RepairManagerType, repairManager);

		BWAPI::Position startPosition = BWAPI::Position(game->self()->getStartLocation());
		baseGuardManager = new BaseGuardManager(this, startPosition);
		registerController(BaseGuardManagerType, baseGuardManager);

		mapStateManager = new MapStateManager(this);
		registerController(MapStateManagerType, mapStateManager);

		unitGroupManager = UnitGroupManager::create();
		registerController(UnitGroupManagerType, unitGroupManager);

		borderManager = BorderManager::create();
		registerController(BorderManagerType, borderManager);

		InformationManager::create();
		
		// setting managers parameters
		workerManager->enableAutoBuild();
		workerManager->setBaseManager(baseManager);
		workerManager->setBuildOrderManager(buildOrderManager);

		supplyManager->setBuildManager(buildManager);
		supplyManager->setBuildOrderManager(buildOrderManager);

		techManager->setBuildingPlacer(buildManager->getBuildingPlacer());
		upgradeManager->setBuildingPlacer(buildManager->getBuildingPlacer());

		baseManager->setBuildOrderManager(buildOrderManager);
		baseManager->setBorderManager(borderManager);

		buildOrderManager->setDebugMode(debug);

		baseManager->setRefineryBuildPriority(50);

		// creating commander
		commander = new Commander(this);
	}