BWAPI
SPAR/AIModule/SparAIModule/DecisionMaking/Layer2Actions/Managers/Layer2ManagersBase.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "../../../Utils/SafeMultiset.h"
00003 
00004 // This class is only used to avoid circular references
00005 
00006 class L2TacticalAction;
00007 
00008 class Layer2ManagersBase
00009 {
00010 public:
00011   struct ResourcesRequest;
00012   struct SortByPriorityThenID
00013   {
00014     bool operator()(const ResourcesRequest& rr1, const ResourcesRequest& rr2) const;
00015   };
00016   typedef SafeMultiset<ResourcesRequest, SortByPriorityThenID> ResourcesRequestsType;
00017 
00018   struct ResourcesRequestID
00019   {
00020     ResourcesRequestID(EventHandler1<BWAPI::Unit*>& p_resourcesAllocatedEventHandler)
00021       : eventHandler(p_resourcesAllocatedEventHandler)
00022       , isValid(false)
00023     {}
00024     EventHandler1<BWAPI::Unit*>& eventHandler;
00025     bool isValid;
00026     ResourcesRequestsType::iterator posInContainer;
00027   };
00028 
00029   struct ResourcesRequest
00030   {
00031     ResourcesRequest(unsigned int p_id, unsigned int p_priority, const ActionResources& p_resources, ResourcesRequestID& p_resourcesId)
00032       : id(p_id)
00033       , priority(p_priority)
00034       , actionResources(p_resources)
00035       , resourcesId(p_resourcesId)
00036     {}
00037     unsigned int id;
00038     unsigned int priority;
00039     const ActionResources actionResources;
00040     ResourcesRequestID& resourcesId;
00041   };
00042 
00043   //typedef ResourcesRequestsType::iterator ResourcesRequestID;
00044   //typedef std::list<L2TacticalAction*>::iterator ActionID;
00045 };
00046 
00047 inline bool Layer2ManagersBase::SortByPriorityThenID::operator()(const Layer2ManagersBase::ResourcesRequest& rr1, 
00048                                                            const Layer2ManagersBase::ResourcesRequest& rr2) const
00049 {
00050   return rr1.priority > rr2.priority || (rr1.priority == rr2.priority && rr1.id < rr2.id);
00051 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines