BWAPI
|
00001 #pragma once 00002 #include <boost/shared_ptr.hpp> 00003 #ifndef GOAL_SMART_POINTER 00004 #define GOAL_SMART_POINTER 00005 class Goal; 00006 typedef boost::shared_ptr<Goal> pGoal; 00007 #endif 00008 #include "Subgoal.h" 00009 #ifndef SUBGOAL_SMART_POINTER 00010 #define SUBGOAL_SMART_POINTER 00011 class Subgoal; 00012 typedef boost::shared_ptr<Subgoal> pSubgoal; 00013 #endif 00014 class UnitsGroup; 00015 #include "Macro/Arbitrator.h" 00016 #include "Micro/UnitsGroup.h" 00017 #include "Micro/Goals/GoalManager.h" 00018 #include "Defines.h" 00019 #include <BWAPI.h> 00020 #include <BWTA.h> 00021 #include <list> 00022 #include <map> 00023 00024 00025 00026 typedef enum 00027 { 00028 GS_WAIT_PRECONDITION = 0, 00029 GS_IN_PROGRESS = 1, 00030 GS_IN_CANCEL = 2, 00031 GS_CANCELED = 3, 00032 GS_ACHIEVED = 4 00033 } GoalStatus; 00034 00035 /*** 00036 * Simple Goal class without canceling check in check() 00037 * neededUnits/preconditions should perhaps be moved into a special Subgoal 00038 */ 00039 class Goal : public Arbitrator::Controller<BWAPI::Unit*, double> 00040 { 00041 //friend class UnitsGroup; 00042 friend class GoalManager; 00043 protected: 00045 UnitsGroup _unitsGroup; 00046 std::list<BWAPI::Unit*> _incompleteUnits; 00048 std::map<BWAPI::UnitType, int> _neededUnits; 00049 std::set<BWAPI::Unit*> _biddedOn; 00050 int _priority; 00051 int _firstFrame; 00052 int _firstActive; 00054 std::list<pSubgoal> _subgoals; 00056 GoalStatus _status; 00057 void bidOnUnitType(const BWAPI::UnitType& ut); 00058 void bidOnMilitaryUnits(); 00059 void bidOnUnit(BWAPI::Unit* u); 00060 public: 00061 Goal(int priority = 50, int firstFrame = 0); 00062 Goal(pSubgoal s, int priority = 50, int firstFrame = 0); 00063 Goal(const std::map<BWAPI::UnitType, int>& nU, pSubgoal s, 00064 int priority = 50, int firstFrame = 0); 00065 Goal(const std::map<BWAPI::UnitType, int>& nU, 00066 int priority = 50, int firstFrame = 0); 00067 virtual ~Goal(); 00068 00070 virtual void onOffer(std::set<BWAPI::Unit*> objects); 00071 virtual void onRevoke(BWAPI::Unit* u, double bid); 00072 virtual std::string getName() const; 00073 virtual std::string getShortName() const; 00074 virtual void update(); 00075 00076 virtual void onUnitDestroy(BWAPI::Unit* unit); 00077 00078 virtual void achieve(); 00079 virtual void check(); 00080 virtual void cancel(); // Does nothing, to be overwritten in cancelable goals 00081 00082 void addSubgoal(pSubgoal s); 00083 void addNeededUnits(const std::map<BWAPI::UnitType, int>& neededUnits); 00084 void setFirstFrame(int firstFrame); 00085 void setPriority(int priority); 00086 void setStatus(GoalStatus s); 00087 GoalStatus getStatus() const; 00088 };