ExplosionType.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include <map>
00003 #include <set>
00004 #include <ExplosionType.h>
00005 
00006 namespace FastEcslent
00007 {
00008   bool initializingExplosionType = true;
00009   std::string explosionTypeName[9];
00010   std::map<std::string, ExplosionType> explosionTypeMap;
00011   std::set< ExplosionType > explosionTypeSet;
00012   namespace ExplosionTypes
00013   {
00014     const ExplosionType None(0);
00015     const ExplosionType Normal(1);;
00016     const ExplosionType Radial_Splash(2);
00017     const ExplosionType Enemy_Splash(3);
00018     const ExplosionType Enemy_Line_Splash(4);
00019     const ExplosionType Nuclear_Missile(5);
00020     const ExplosionType EMP_Shockwave(6);
00021     const ExplosionType Air_Splash(7);
00022     const ExplosionType Unknown(8);
00023 
00024     void init()
00025     {
00026       explosionTypeName[None.getID()]              = "None";
00027       explosionTypeName[Normal.getID()]            = "Normal";
00028       explosionTypeName[Radial_Splash.getID()]     = "Radial_Splash";
00029       explosionTypeName[Enemy_Splash.getID()]      = "Enemy_Splash";
00030       explosionTypeName[Enemy_Line_Splash.getID()] = "Enemy_Line_Splash";
00031       explosionTypeName[Nuclear_Missile.getID()]   = "Nuclear_Missile";
00032       explosionTypeName[EMP_Shockwave.getID()]     = "EMP_Shockwave";
00033       explosionTypeName[Air_Splash.getID()]        = "Air_Splash";
00034       explosionTypeName[Unknown.getID()]           = "Unknown";
00035 
00036       explosionTypeSet.insert(None);
00037       explosionTypeSet.insert(Normal);
00038       explosionTypeSet.insert(Radial_Splash);
00039       explosionTypeSet.insert(Enemy_Splash);
00040       explosionTypeSet.insert(Enemy_Line_Splash);
00041       explosionTypeSet.insert(Nuclear_Missile);
00042       explosionTypeSet.insert(EMP_Shockwave);
00043       explosionTypeSet.insert(Air_Splash);
00044       explosionTypeSet.insert(Unknown);
00045 
00046       for(std::set< ExplosionType >::iterator i= explosionTypeSet.begin();i!= explosionTypeSet.end();i++){
00047         std::string name = i->getName();
00048         explosionTypeMap.insert(std::make_pair(name, *i));
00049       }
00050       initializingExplosionType = false;
00051     }
00052   }
00053   ExplosionType::ExplosionType()
00054   {
00055     this->id = ExplosionTypes::None.id;
00056   }
00057   ExplosionType::ExplosionType(int id)
00058   {
00059     this->id = id;
00060     if (!initializingExplosionType && (id < 0 || id >= 9))
00061       this->id = ExplosionTypes::Unknown.id;
00062   }
00063   ExplosionType::ExplosionType(const ExplosionType& other)
00064   {
00065     this->id = other.id;
00066   }
00067   ExplosionType& ExplosionType::operator=(const ExplosionType& other)
00068   {
00069     this->id = other.id;
00070     return *this;
00071   }
00072   bool ExplosionType::operator==(const ExplosionType& other) const
00073   {
00074     return this->id == other.id;
00075   }
00076   bool ExplosionType::operator!=(const ExplosionType& other) const
00077   {
00078     return this->id != other.id;
00079   }
00080   bool ExplosionType::operator<(const ExplosionType& other) const
00081   {
00082     return this->id < other.id;
00083   }
00084   int ExplosionType::getID() const
00085   {
00086     return this->id;
00087   }
00088   std::string ExplosionType::getName() const
00089   {
00090     return explosionTypeName[this->id];
00091   }
00092 
00093   ExplosionType ExplosionTypes::getExplosionType(std::string name)
00094   {
00095     std::map<std::string, ExplosionType>::iterator i = explosionTypeMap.find(name);
00096     if (i == explosionTypeMap.end())
00097       return ExplosionTypes::Unknown;
00098     return (*i).second;
00099   }
00100   std::set<ExplosionType>& ExplosionTypes::allExplosionTypes()
00101   {
00102     return explosionTypeSet;
00103   }
00104 }

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