BWAPI
|
00001 #pragma once 00002 #include "../../PerceptualState/Techs/Techs.h" 00003 #include "../Layer3Tactical.h" 00004 #include "Layer3ScriptTypes.h" 00005 #include "Locations/Common.h" 00006 #include "Techs/L3Tech.h" 00007 #include "Tasks/BuildCannonsTask.h" 00008 #include "Tasks/BuildExpansionsTask.h" 00009 #include "Tasks/BuildGatewaysTask.h" 00010 #include "Tasks/BuildPylonsTask.h" 00011 #include "Tasks/ManageArmyTask.h" 00012 #include "Tasks/ManageResourcesTask.h" 00013 #include "Tasks/ProgressTechTask.h" 00014 #include "Tasks/RecruitArmyTask.h" 00015 #include "Tasks/ScoutTask.h" 00016 00017 class Layer3Script : public Layer3Tactical<Layer3TacticalRecognition<Layer2Cueing<Layer1GameState>>, Layer2Managers>, 00018 public Layer3ScriptTypes 00019 { 00020 public: 00021 00022 #pragma region Types_Matching 00023 00024 template <class LocationType> 00025 struct LocationTypes {}; 00026 template <> 00027 struct LocationTypes<AirLocation> { 00028 typedef L3AirLocation Type; 00029 }; 00030 template <> 00031 struct LocationTypes<BaseLocation> { 00032 typedef L3BaseLocation Type; 00033 }; 00034 template <> 00035 struct LocationTypes<Chokepoint> { 00036 typedef L3Chokepoint Type; 00037 }; 00038 template <> 00039 struct LocationTypes<Region> { 00040 typedef L3Region Type; 00041 }; 00042 template <> 00043 struct LocationTypes<RegionLocation> { 00044 typedef L3RegionLocation Type; 00045 }; 00046 template <> 00047 struct LocationTypes<Map> { 00048 typedef L3Map Type; 00049 }; 00050 00051 class L3UnitData : public virtual UnitData 00052 { 00053 public: 00054 L3UnitData(BWAPI::Unit* unit) 00055 : UnitData(unit) 00056 { 00057 } 00058 }; 00059 00060 template <class TechType> 00061 struct TechTypes {}; 00062 template <> 00063 struct TechTypes<UnitTypeTech> { 00064 typedef L3UnitTypeTech Type; 00065 }; 00066 template <> 00067 struct TechTypes<TechTypeTech> { 00068 typedef L3TechTypeTech Type; 00069 }; 00070 template <> 00071 struct TechTypes<UpgradeTypeTech> { 00072 typedef L3UpgradeTypeTech Type; 00073 }; 00074 00075 #pragma endregion Types_Matching 00076 00077 static Layer3Script& getInstance() 00078 { 00079 return *s_instance; 00080 } 00081 00082 Layer3Script(Layer3TacticalRecognition<Layer2Cueing<Layer1GameState>>& layer3TacticalRecognition, Layer2Managers& layer2Managers); 00083 ~Layer3Script(); 00084 void onStart(); 00085 void onFrame(); 00086 void onEnd(); 00087 void onSendText(std::string text) {} 00088 00089 // 00090 // Action-dependent events 00091 // 00092 void onAttackMoveEnded(void* data); 00093 00094 // 00095 // Action-independent events 00096 // 00097 void onUnitReleased(void* data, BWAPI::Unit* unit, const layer2::GroupTacticalAction* action); 00098 00099 void onUnitRecruited(BWAPI::Unit* unit, StaticLocation* location); 00100 void onDependentTechsUpdate(); 00101 00102 Layer2Managers& getLayer2() const { return m_layer2Actions; } 00103 L3BaseLocation* getMainBase() const { return m_mainBase; } 00104 int countSupplyForOneRoundTroops() const; 00105 ResourcesSaturation countProbesSaturationRatio() const; 00106 L3BaseLocation* getNearestOwnMiningBaseLocation(BWAPI::Position position) const; 00107 00109 // LEVEL 4 - INTERFACE // 00111 void setTargetTechs(const TechSet& targetTechs) 00112 { 00113 m_progressTech.setTargetTechs(targetTechs); 00114 // Techs needed will vary according to game flow (when something is finished/when something gets destroyed...) 00115 00116 updateResourcesRatio(); 00117 } 00118 00119 void setTargetArmyComposition(const ArmyComposition& targetArmyComposition) 00120 { 00121 m_recruitArmy.setTargetArmyComposition(targetArmyComposition); 00122 00123 updateResourcesRatio(); 00124 } 00125 00127 // GUI // 00129 const ArmyComposition& getTargetArmyComposition() const 00130 { 00131 return m_recruitArmy.getTargetArmyComposition(); 00132 } 00133 const TechSet& getTargetTechs() const 00134 { 00135 return m_progressTech.getTargetTechs(); 00136 } 00137 const ProgressTechTask* getProgressTechTask() const 00138 { 00139 return &m_progressTech; 00140 } 00141 00142 protected: 00143 static Layer3Script* s_instance; 00144 00145 ResourcesAcquisitionRatio computeResourcesAcquisitionRatio() const; 00146 void updateResourcesRatio() 00147 { 00148 m_manageResources.updateResourcesRatio(computeResourcesAcquisitionRatio()); 00149 } 00150 00151 // Action-independent events 00152 EVENT_HANDLER2(Layer3Script, onUnitReleased, BWAPI::Unit*, const layer2::GroupTacticalAction*) m_unitReleasedEventHandler; 00153 00154 // Periodic tasks 00155 ManageResourcesTask m_manageResources; 00156 BuildPylonsTask m_buildPylons; 00157 BuildGatewaysTask m_buildGateways; 00158 BuildExpansionsTask m_buildExpansions; 00159 ProgressTechTask m_progressTech; 00160 RecruitArmyTask m_recruitArmy; 00161 ManageArmyTask m_manageArmy; 00162 ScoutTask m_scout; 00163 BuildCannonsTask m_buildCannons; 00164 00165 L3BaseLocation* m_mainBase; 00166 };