BWAPI
SPAR/AIModule/SparAIModule/DecisionMaking/Layer3Tactical/Script/Tasks/ProgressTechTask.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "Layer3Task.h"
00003 #include "../../Interface/TechSet.h"
00004 #include "../../../../PerceptualState/Techs/Techs.h"
00005 
00006 //
00007 // Input: techs to acquire
00008 //
00009 
00010 class ProgressTechTask : public Layer3Task
00011 {
00012 private:
00013   struct TechActionWrapper
00014   {
00015     TechActionWrapper(TacticalAction* techAction)
00016       : m_techAction(techAction)
00017     {}
00018     TacticalAction* const m_techAction;
00019     std::map<Tech*, TechActionWrapper>::const_iterator m_posInContainer;
00020   };
00021   struct transform_to_pair : std::unary_function<std::pair<Tech*, TechActionWrapper>, std::pair<const Tech*, const TacticalAction*>>
00022   {
00023     result_type operator()(const argument_type& wrapper) const
00024     {
00025       return std::make_pair(wrapper.first, wrapper.second.m_techAction);
00026     }
00027   };
00028 
00029 public:
00030   ProgressTechTask(Layer3Script& layer3Script)
00031     : Layer3Task(layer3Script)
00032     , m_techActionTerminateEventHandler(*this)
00033   {
00034   }
00035 
00036   ~ProgressTechTask()
00037   {
00038     for (std::map<Tech*, TechActionWrapper>::const_iterator it = m_currentTechActions.begin(); it != m_currentTechActions.end(); ++it)
00039     {
00040       delete it->second.m_techAction;
00041     }
00042   }
00043 
00044   void setTargetTechs(const TechSet& targetTechs)
00045   {
00046     m_currentTechTargets = targetTechs;
00047   }
00048 
00049   void run();
00050 
00051   virtual void runV()
00052   {
00053     run();
00054   }
00055 
00056   void onTechActionTerminate(void* data);
00057 
00059   // GUI //
00061   const TechSet& getTargetTechs() const
00062   {
00063     return m_currentTechTargets;
00064   }
00065   typedef boost::transform_iterator<transform_to_pair, std::map<Tech*, TechActionWrapper>::const_iterator> TechActionIterator;
00066   std::pair<TechActionIterator, TechActionIterator> getCurrentTechActions() const
00067   {
00068     return std::make_pair(boost::make_transform_iterator(m_currentTechActions.begin(), transform_to_pair()),
00069                           boost::make_transform_iterator(m_currentTechActions.end(), transform_to_pair()));
00070   }
00071 
00072 private:
00073   static size_t getRootTechsToAcquire(Tech* target, std::set<Tech*>& result);
00074   bool shouldResearchTech(Tech* tech) const;
00075 
00076   EVENT_HANDLER(ProgressTechTask, onTechActionTerminate) m_techActionTerminateEventHandler;
00077 
00078   TechSet m_currentTechTargets;
00079   std::map<Tech*, TechActionWrapper> m_currentTechActions;
00080 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines