BWAPI
SPAR/AIModule/SparAIModule/PerceptualState/Locations/Static/Chokepoint.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "PrimitiveLocation.h"
00003 
00004 class Map;
00005 class Region;
00006 
00007 class Chokepoint : public virtual PrimitiveLocation
00008 {
00009 public:
00010   template <class LocationTypes>
00011   Chokepoint(LocationTypes*, BWTA::Chokepoint* chokepoint, Region* firstRegion, Region* secondRegion, Map* parent)
00012     : PrimitiveLocation(parent)
00013     , StaticLocation(parent)
00014     , m_chokepoint(chokepoint)
00015     , m_firstRegion(firstRegion)
00016     , m_secondRegion(secondRegion)
00017   {
00018   }
00019 
00020   Map* getParent();
00021   const Map* getParent() const;
00022 
00023   virtual BWAPI::Position getCurrentCenter() const
00024   {
00025     return m_chokepoint->getCenter();
00026   }
00027 
00028   virtual bool isInLocation(BWAPI::Position position) const
00029   {
00030     // TODO: improve this: should be only the tiles crossed by the chokepoint line segment
00031 
00032     const std::pair<BWAPI::Position, BWAPI::Position>& sides = m_chokepoint->getSides();
00033 
00034     return (sides.first.x() <= position.x() && position.x() <= sides.second.x()) &&
00035            (sides.first.y() <= position.y() && position.y() <= sides.second.y());
00036   }
00037 
00038   std::pair<Region*, Region*> getRegions() 
00039   {
00040     return std::make_pair(m_firstRegion, m_secondRegion);
00041   }
00042   std::pair<const Region*, const Region*> getRegions() const
00043   {
00044     return std::make_pair(m_firstRegion, m_secondRegion);
00045   }
00046 
00047   const BWTA::Chokepoint* getChokepoint() const
00048   {
00049     return m_chokepoint;
00050   }
00051 
00052 protected:
00053   friend class Map;
00054 
00055   virtual void output(std::ostream& out) const
00056   {
00057     out << "Chokepoint " << m_chokepoint->getCenter();
00058   }
00059 
00060   BWTA::Chokepoint* const m_chokepoint;
00061   Region* const m_firstRegion;
00062   Region* const m_secondRegion;
00063 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines