BWAPI
Skynet/Skynet/UnitTracker.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "Interface.h"
00004 
00005 #include "Singleton.h"
00006 #include "Unit.h"
00007 #include "UnitGroup.h"
00008 
00009 class UnitTrackerClass
00010 {
00011 public:
00012         UnitTrackerClass();
00013 
00014         void pumpUnitEvents();
00015         void update();
00016 
00017         void onUnitDiscover(BWAPI::Unit* unit);
00018         void onUnitDestroy(BWAPI::Unit* unit);
00019 
00020         Unit getUnit(BWAPI::Unit* unit);
00021         UnitGroup getUnitGroup(std::set<BWAPI::Unit*> units);
00022 
00023         const UnitGroup &getGeysers() { return mPlayerToTypeToUnits[BWAPI::Broodwar->neutral()][BWAPI::UnitTypes::Resource_Vespene_Geyser]; }
00024         const UnitGroup &getMinerals() { return mPlayerToTypeToUnits[BWAPI::Broodwar->neutral()][BWAPI::UnitTypes::Resource_Mineral_Field]; }
00025 
00026         const UnitGroup &getSupplyProviders() const { return mMySupplyProviders; }
00027 
00028         UnitGroup getUnitsOnTile(int x, int y);
00029 
00030         const UnitGroup &getAllUnits() { return mAllUnits; }
00031         const UnitGroup &selectAllUnits(BWAPI::UnitType type, Player player = BWAPI::Broodwar->self()) { return mPlayerToTypeToUnits[player][type]; }
00032         const UnitGroup &selectAllUnits(Player player = BWAPI::Broodwar->self()) { return mPlayerToUnits[player]; }
00033         UnitGroup selectAllEnemy(Player player = BWAPI::Broodwar->self());
00034         UnitGroup selectAllEnemy(BWAPI::UnitType type, Player player = BWAPI::Broodwar->self());
00035 
00036         void onDiscover(Unit unit);
00037         void onMorphRenegade(Unit unit);
00038         void onDestroy(Unit unit);
00039 
00040 private:
00041         std::map<BWAPI::Unit*, Unit> mUnits;
00042 
00043         std::map<Unit, Player> mUnitToPlayer;
00044         std::map<Unit, BWAPI::UnitType> mUnitToType;
00045 
00046         std::map<Player, std::map<BWAPI::UnitType, UnitGroup>> mPlayerToTypeToUnits;
00047         std::map<Player, UnitGroup> mPlayerToUnits;
00048         
00049         UnitGroup mAllUnits;
00050 
00051         UnitGroup mMySupplyProviders;
00052 
00053         bool mOnBeginCalled;
00054 
00055         void checkUnit(Unit unit);
00056 };
00057 
00058 typedef Singleton<UnitTrackerClass> UnitTracker;
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines