BWAPI
|
00001 #pragma once 00002 #include "../../../Utils/Component.h" 00003 #include "LowLevelAction.h" 00004 #include <BWAPI.h> 00005 00009 class ArbitratorUnitData : public virtual UnitData 00010 { 00011 // 00012 // Problem: Right now only the highest potential successor action is kept. If the issuing 00013 // behavior gets terminated after having issued the action, it is possible that 00014 // no action is available for arbitration (since other potential actions were discarded). 00015 // 00016 00017 public: 00018 ArbitratorUnitData(BWAPI::Unit* unit) 00019 : UnitData(unit) 00020 {} 00021 00026 struct ActionImportance 00027 { 00028 ActionImportance() 00029 { 00030 } 00031 00032 template <class State> 00033 ActionImportance(State& state) 00034 : m_priority(state.getBehavior().getCurrentPriority()) 00035 { 00036 } 00037 00038 ActionImportance& operator= (const ActionImportance& importance) 00039 { 00040 m_priority = importance.m_priority; 00041 return *this; 00042 } 00043 00044 ActionImportance& operator= (const int importance) 00045 { 00046 m_priority = importance; 00047 return *this; 00048 } 00049 00050 unsigned int m_priority; 00051 00052 friend bool operator< (const ActionImportance& importance1, const ActionImportance& importance2) 00053 { 00054 return importance1.m_priority < importance2.m_priority; 00055 } 00056 00057 friend bool operator> (const ActionImportance& importance1, const ActionImportance& importance2) 00058 { 00059 return importance1.m_priority > importance2.m_priority; 00060 } 00061 }; 00062 00063 00064 //~ArbitratorUnitData(); 00065 00067 // * @brief Adds a new potential action for this unit. 00068 // * @param action the action to add. 00069 // * @param importance the importance of the action to add. 00070 // */ 00071 //void addSubmittedAction(const LowLevelAction &action, ActionImportance importance); 00072 00074 // * @brief Chooses the action that this unit will accomplish, given a history of commands. 00075 // * @return the chosen action, possibly NULL. 00076 // */ 00077 //const LowLevelAction* arbitrate(); 00078 00079 protected: 00080 //class ActionData : public Component 00081 //{ 00082 //public: 00083 // ActionData() 00084 // : m_action(NULL), m_eventHandler(*this) 00085 // { 00086 // } 00087 00088 // const LowLevelAction* getAction() const 00089 // { 00090 // return m_action; 00091 // } 00092 00093 // //ActionImportance getImportance() const 00094 // //{ 00095 // // return m_importance; 00096 // //} 00097 00098 // bool propose(const LowLevelAction& action, ActionImportance importance); 00099 00100 // bool propose(ActionData& data); 00101 00102 // void clear(); 00103 00104 // void onActionTerminate(void* data); 00105 00106 // friend bool operator> (const ActionData& data1, const ActionData& data2) 00107 // { 00108 // // It is possible that a previously issued action was cancelled by the 00109 // // subsequent termination of the issuing behavior, hence checking for NULL. 00110 00111 // return (data1.m_action != NULL && 00112 // (data2.m_action == NULL || data1.m_importance > data2.m_importance)); 00113 // } 00114 00115 //protected: 00116 // const LowLevelAction* m_action; 00117 // ActionImportance m_importance; 00118 // LowLevelAction::OnActionEnded::SubscriberID m_id; 00119 // EVENT_HANDLER(ActionData, onActionTerminate) m_eventHandler; 00120 //}; 00121 00123 // * @brief The highest importance action that began executing previously at some point in time. 00124 // * @remarks Points to an element of m_actions. 00125 // */ 00126 //ActionData* m_highestImportanceAction; 00128 // * @brief The highest importance successor action, which may begin executing 00129 // * when a call to arbitrate() takes place. 00130 // * @remarks Points to an element of m_actions. 00131 // */ 00132 //ActionData* m_possibleSuccessorAction; 00133 00135 // * @brief Buffer for possible actions. 00136 // */ 00137 //ActionData m_actions[2]; 00138 };