WeaponType.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include <map>
00003 #include <set>
00004 #include <WeaponType.h>
00005 
00006 namespace FastEcslent
00007 {
00008   bool initializingWeaponType = true;
00009   class WeaponTypeInternal
00010   {
00011     public:
00012       WeaponTypeInternal() {valid = false;}
00013       void set(const char* name, int damageAmount, int damageBonus, int damageCooldown, int damageFactor, ExplosionType explosionType, int minRange, int maxRange, int innerSplashRadius, int medianSplashRadius, int outerSplashRadius, bool targetsAir, bool targetsGround, bool targetsOwn)
00014       {
00015         if (initializingWeaponType)
00016         {
00017           this->name               = name;
00018           this->damageAmount       = damageAmount;
00019           this->damageBonus        = damageBonus;
00020           this->damageCooldown     = damageCooldown;
00021           this->damageFactor       = damageFactor;
00022           this->explosionType      = explosionType;
00023           this->minRange           = minRange;
00024           this->maxRange           = maxRange;
00025           this->innerSplashRadius  = innerSplashRadius;
00026           this->medianSplashRadius = medianSplashRadius;
00027           this->outerSplashRadius  = outerSplashRadius;
00028           this->targetsAir         = targetsAir;
00029           this->targetsGround      = targetsGround;
00030           this->targetsOwn         = targetsOwn;
00031           this->valid              = true;
00032         }
00033       }
00034       std::string name;
00035 
00036       int damageAmount;
00037       int damageBonus;
00038       int damageCooldown;
00039       int damageFactor;
00040       ExplosionType explosionType;
00041       int minRange;
00042       int maxRange;
00043       int innerSplashRadius;
00044       int medianSplashRadius;
00045       int outerSplashRadius;
00046       bool targetsAir;
00047       bool targetsGround;
00048       bool targetsOwn;
00049       bool valid;
00050   };
00051   WeaponTypeInternal weaponTypeData[6];
00052   std::map<std::string, WeaponType> weaponTypeMap;
00053   std::set< WeaponType > weaponTypeSet;
00054   std::set< WeaponType > specialWeaponTypeSet;
00055   std::set< WeaponType > normalWeaponTypeSet;
00056   namespace WeaponTypes
00057   {
00058         const WeaponType Fusion_Cutter(0);
00059     const WeaponType Rifle(1);
00060     const WeaponType Hellfire(2);
00061     const WeaponType Cannon(3);
00062     const WeaponType None(4);
00063     const WeaponType Unknown(5);
00064 
00065     void init()
00066     {
00067       weaponTypeData[Fusion_Cutter.getID()].set("Fusion_Cutter", 10,  1, 15, 1, ExplosionTypes::Normal,            0, 100, 0, 0, 0,   0, 1, 0); //SCV
00068       weaponTypeData[Rifle.getID()]        .set("Rifle",         15,  1, 15, 1, ExplosionTypes::Normal,            0, 180, 0, 0, 0,   1, 1, 0);        //Marine
00069       weaponTypeData[Hellfire.getID()]     .set("Hellfire",      25,  1, 22, 1, ExplosionTypes::Enemy_Line_Splash, 0, 200, 200,0, 300, 0, 1, 0);    //Hellion
00070       weaponTypeData[Cannon.getID()]       .set("Cannon",        30,  3, 37, 1, ExplosionTypes::Enemy_Splash,      0, 300, 50,70,100, 0, 1, 0);      //Tank
00071       weaponTypeData[None.getID()]         .set("None",          0,   0, 0,  0, ExplosionTypes::None,              0, 0,   0, 0, 0,   0, 0, 0);
00072       weaponTypeData[Unknown.getID()]      .set("Unknown",       0,   0, 0,  0, ExplosionTypes::None,              0, 0,   0, 0, 0,   0, 0, 0);
00073 
00074       weaponTypeSet.insert(Fusion_Cutter);
00075       weaponTypeSet.insert(Rifle);
00076       weaponTypeSet.insert(Hellfire);
00077       weaponTypeSet.insert(Cannon);
00078 
00079       for(std::set<WeaponType>::iterator i= weaponTypeSet.begin();i!= weaponTypeSet.end();i++){
00080         std::string name = i->getName();
00081         weaponTypeMap.insert(std::make_pair(name, *i));
00082       }
00083       initializingWeaponType = false;
00084     }
00085   }
00086   WeaponType::WeaponType()
00087   {
00088     this->id = WeaponTypes::None.id;
00089   }
00090   WeaponType::WeaponType(int id)
00091   {
00092     this->id = id;
00093     if (!initializingWeaponType && (id < 0 || id >= 6 || !weaponTypeData[id].valid))
00094       this->id = WeaponTypes::Unknown.id;
00095   }
00096   WeaponType::WeaponType(const WeaponType& other)
00097   {
00098     this->id = other.id;
00099   }
00100   WeaponType& WeaponType::operator=(const WeaponType& other)
00101   {
00102     this->id = other.id;
00103     return *this;
00104   }
00105   bool WeaponType::operator==(const WeaponType& other) const
00106   {
00107     return this->id == other.id;
00108   }
00109   bool WeaponType::operator!=(const WeaponType& other) const
00110   {
00111     return this->id != other.id;
00112   }
00113   bool WeaponType::operator<(const WeaponType& other) const
00114   {
00115     return this->id < other.id;
00116   }
00117   int WeaponType::getID() const
00118   {
00119     return this->id;
00120   }
00121   std::string WeaponType::getName() const
00122   {
00123     return weaponTypeData[this->id].name;
00124   }
00125   int WeaponType::damageAmount() const
00126   {
00127     return weaponTypeData[this->id].damageAmount;
00128   }
00129   int WeaponType::damageBonus() const
00130   {
00131     return weaponTypeData[this->id].damageBonus;
00132   }
00133   int WeaponType::damageCooldown() const
00134   {
00135     return weaponTypeData[this->id].damageCooldown;
00136   }
00137   int WeaponType::damageFactor() const
00138   {
00139     return weaponTypeData[this->id].damageFactor;
00140   }
00141 
00142   ExplosionType WeaponType::explosionType() const
00143   {
00144     return weaponTypeData[this->id].explosionType;
00145   }
00146   int WeaponType::minRange() const
00147   {
00148     return weaponTypeData[this->id].minRange;
00149   }
00150   int WeaponType::maxRange() const
00151   {
00152     return weaponTypeData[this->id].maxRange;
00153   }
00154   int WeaponType::innerSplashRadius() const
00155   {
00156     return weaponTypeData[this->id].innerSplashRadius;
00157   }
00158   int WeaponType::medianSplashRadius() const
00159   {
00160     return weaponTypeData[this->id].medianSplashRadius;
00161   }
00162   int WeaponType::outerSplashRadius() const
00163   {
00164     return weaponTypeData[this->id].outerSplashRadius;
00165   }
00166   bool WeaponType::targetsAir() const
00167   {
00168     return weaponTypeData[this->id].targetsAir;
00169   }
00170   bool WeaponType::targetsGround() const
00171   {
00172     return weaponTypeData[this->id].targetsGround;
00173   }
00174   bool WeaponType::targetsOwn() const
00175   {
00176     return weaponTypeData[this->id].targetsOwn;
00177   }
00178   WeaponType WeaponTypes::getWeaponType(std::string name)
00179   {
00180     std::map<std::string, WeaponType>::iterator i = weaponTypeMap.find(name);
00181     if (i == weaponTypeMap.end())
00182       return WeaponTypes::Unknown;
00183     return (*i).second;
00184   }
00185   std::set<WeaponType>& WeaponTypes::allWeaponTypes()
00186   {
00187     return weaponTypeSet;
00188   }
00189   std::set<WeaponType>& WeaponTypes::normalWeaponTypes()
00190   {
00191     return weaponTypeSet;
00192   }
00193   std::set<WeaponType>& WeaponTypes::specialWeaponTypes()
00194   {
00195     return weaponTypeSet;
00196   }
00197 }

Generated on Fri Dec 13 14:54:19 2013 for FastECSLent by  doxygen 1.5.4