BWAPI
|
00001 #pragma once 00002 #include "../UnitBehavior.h" 00003 #include "../BehaviorState.h" 00004 #include "../Arbitrator.h" 00005 #include "../Conditions/ReachedDestination.h" 00006 00007 class ObsScout : public UnitBehavior<ObsScout> 00008 { 00009 protected: 00010 class GoToLocation; 00011 class Reached; 00012 friend class GoToLocation; 00013 friend class Reached; 00014 00015 class RaiseScoutArrived : public TransitionAction 00016 { 00017 public: 00018 RaiseScoutArrived(ObsScout* const fsm) 00019 : m_fsm(fsm){} 00020 00021 void execute() 00022 { 00023 m_fsm->getScoutArrivedEvent().raise(); 00024 } 00025 00026 protected: 00027 ObsScout* const m_fsm; 00028 }; 00029 00030 00031 //State where the scout goes to the requested location 00032 class GoToLocation : public BehaviorState<ObsScout, GoToLocation> 00033 { 00034 public: 00035 GoToLocation(ObsScout& behavior, Location* location); 00036 void onEnterImpl(); 00037 void onExitImpl(){} 00038 00039 void onTimer(); 00040 00041 typedef SCHEDULER_EVENT(GoToLocation, onTimer) TimerEvent; 00042 00043 typedef boost::tuple< 00044 TimerEvent& 00045 > Events; 00046 Events m_events; 00047 00048 typedef boost::tuple< 00049 Transition<GoToLocation, UnitReachedDestination, RaiseScoutArrived, Reached>& 00050 > Transitions; 00051 Transitions m_transitions; 00052 00053 protected: 00054 //Variable 00055 Location* const m_location; 00056 int cpt; 00057 double lastDistance; 00058 00059 // Actions 00060 layer1::MoveAction m_moveAction; 00061 00062 //temp event and transition 00063 TimerEvent m_locationReached; 00064 Transition<GoToLocation, UnitReachedDestination, RaiseScoutArrived, Reached> m_transitionToReached; 00065 }; 00066 00067 class Reached : public BehaviorState<ObsScout, Reached> 00068 { 00069 public: 00070 Reached(ObsScout& behavior); 00071 void onEnterImpl(); 00072 void onExitImpl(){} 00073 00074 typedef boost::tuple<> Events; 00075 Events m_events; 00076 00077 typedef boost::tuple<> Transitions; 00078 Transitions m_transitions; 00079 }; 00080 00081 00082 public: 00083 ObsScout(const Process* parent, unsigned int initialPriority, Location* location, BWAPI::Unit* scoutingUnit) 00084 : UnitBehavior(parent, initialPriority, scoutingUnit) 00085 , IUnitBehavior(parent, initialPriority, scoutingUnit) 00086 , IBehavior(parent, initialPriority) 00087 , IFSM(parent) 00088 , Process(parent) 00089 , m_reachedState(*this) 00090 , m_goToLocationState(*this, location) 00091 , m_location(location) 00092 , m_states(m_goToLocationState, m_reachedState) 00093 { 00094 } 00095 00096 virtual std::string getName() const 00097 { 00098 return "ObsScout (" + getObjectDescription(m_unit) + ")"; 00099 } 00100 00101 typedef boost::tuple< 00102 GoToLocation&, 00103 Reached& 00104 > States; 00105 const States m_states; 00106 00107 DECLARE_EVENT(OnScoutArrived); 00108 OnScoutArrived& getScoutArrivedEvent() const { return m_scoutArrivedEvent; } 00109 00110 protected: 00111 virtual void executeImpl() 00112 { 00113 UnitBehavior::executeImpl(); 00114 m_goToLocationState.onEnter(); 00115 } 00116 00117 // Arguments 00118 00119 // Variables 00120 //BWAPI::Position m_enemyCC; 00121 //BWTA::Region* m_baseRegion; 00122 Location* const m_location; 00123 00124 // Events 00125 EVENT(OnScoutArrived) m_scoutArrivedEvent; 00126 00127 // States 00128 GoToLocation m_goToLocationState; 00129 Reached m_reachedState; 00130 00131 };