BWAPI
SPAR/AIModule/SparAIModule/PerceptualState/Techs/Tech.h
Go to the documentation of this file.
00001 #pragma once
00002 #include <BWAPI.h>
00003 #include <iostream>
00004 
00005 class UnitTypeTech;
00006 class Techs;
00007 
00008 class Tech
00009 {
00010 public:
00011   Tech()
00012     : m_isAcquired(false)
00013   {}
00014   virtual ~Tech() {}
00015   const std::set<Tech*>& getDependencies() const { return m_incomingDependencies; }
00016   bool isAcquired() const 
00017   {
00018     //assert(m_isAcquired == isAcquiredImpl());
00019 #ifdef _DEBUG
00020     bool acquiredImpl = isAcquiredImpl();
00021     if (m_isAcquired != acquiredImpl)
00022     {
00023       SPAR_LOG(LogTypes::GENERAL_ERROR, "Tech \"%s\" is wrongly marked as %s", getObjectDescription(this).c_str(), (m_isAcquired ? "acquired" : "not acquired"));
00024     }
00025 #endif
00026     return m_isAcquired;
00027   }
00028   bool allDependenciesAcquired() const;
00029   friend std::ostream& operator<<(std::ostream& out, const Tech& tech)
00030   {
00031     out << tech.m_name;
00032     return out;
00033   }
00034   void setTechAcquired();
00035 protected:
00036   friend class UnitTypeTech;
00037   virtual bool isAcquiredImpl() const = 0;
00038   virtual void onIncomingDependencyAcquired(Tech* dependency) { unused(dependency); }
00039   virtual void onIncomingDependencyLost(Tech* dependency) { unused(dependency); }
00040   virtual void addDependency(BWAPI::UnitType unitType);
00041   virtual void addDependency(BWAPI::TechType techType);
00042   virtual void addDependency(BWAPI::UpgradeType upgradeType, int level);
00043   void addOutgoingDependency(Tech* tech) { m_outgoingDependencies.insert(tech); }
00044   std::set<Tech*> m_incomingDependencies;
00045   std::set<Tech*> m_outgoingDependencies;
00049   bool m_isAcquired;
00050   std::string m_name;
00051 };
00052 
00053 // Could be separated in UnitTypeTech/BuildingTypeTech
00054 class UnitTypeTech : public virtual Tech
00055 {
00056 public:
00057   UnitTypeTech(BWAPI::UnitType unitType);
00058   BWAPI::UnitType getType() const { return m_unitType; }
00059 protected:
00060   friend class Techs;
00061   virtual void addDependency(BWAPI::UnitType unitType);
00062   void setTechLost();
00063   void onUnitCompleted()
00064   {
00065     if (!m_isAcquired)
00066       setTechAcquired();
00067   }
00068   void onUnitRemoved(size_t nbCompletedUnits)
00069   {
00070     if (m_isAcquired && nbCompletedUnits == 0)
00071     {
00072       setTechLost();
00073     }
00074   }
00075   virtual bool isAcquiredImpl() const;
00076   virtual void onIncomingDependencyAcquired(Tech* dependency);
00077   virtual void onIncomingDependencyLost(Tech* dependency);
00078   const BWAPI::UnitType m_unitType;
00079 };
00080 
00081 // You're welcome to change this hideous class name!
00082 class TechTypeTech : public virtual Tech
00083 {
00084 public:
00085   TechTypeTech(BWAPI::TechType techType);
00086   BWAPI::TechType getTech() const { return m_techType; }
00087 protected:
00088   friend class Techs;
00089   virtual bool isAcquiredImpl() const;
00090   const BWAPI::TechType m_techType;
00091 };
00092 
00093 class UpgradeTypeTech : public virtual Tech
00094 {
00095 public:
00096   UpgradeTypeTech(BWAPI::UpgradeType upgradeType, int level);
00097   UpgradeTypeTech(BWAPI::UpgradeType upgradeType);
00098   BWAPI::UpgradeType getUpgrade() const { return m_upgradeType; }
00099   int getLevel() const { return m_level; }
00100 protected:
00101   friend class Techs;
00102   virtual bool isAcquiredImpl() const;
00103   const BWAPI::UpgradeType m_upgradeType;
00104   const int m_level;
00105 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines