[7956] Fixed possible runtime crash.
[getmangos.git] / src / shared / vmap / VMapFactory.cpp
blob7a8e68c6c8ce616529ff2e029c8aa0ac98389625
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <sys/types.h>
20 #include "VMapFactory.h"
21 #include "VMapManager.h"
23 using namespace G3D;
25 namespace VMAP
27 extern void chompAndTrim(std::string& str);
29 VMapManager *gVMapManager = 0;
30 Table<unsigned int , bool>* iIgnoreSpellIds=0;
32 //===============================================
33 // result false, if no more id are found
35 bool getNextId(const std::string& pString, unsigned int& pStartPos, unsigned int& pId)
37 bool result = false;
38 unsigned int i;
39 for(i=pStartPos;i<pString.size(); ++i)
41 if(pString[i] == ',')
43 break;
46 if(i>pStartPos)
48 std::string idString = pString.substr(pStartPos, i-pStartPos);
49 pStartPos = i+1;
50 chompAndTrim(idString);
51 pId = atoi(idString.c_str());
52 result = true;
54 return(result);
57 //===============================================
58 /**
59 parameter: String of map ids. Delimiter = ","
62 void VMapFactory::preventSpellsFromBeingTestedForLoS(const char* pSpellIdString)
64 if(!iIgnoreSpellIds)
65 iIgnoreSpellIds = new Table<unsigned int , bool>();
66 if(pSpellIdString != NULL)
68 unsigned int pos =0;
69 unsigned int id;
70 std::string confString(pSpellIdString);
71 chompAndTrim(confString);
72 while(getNextId(confString, pos, id))
74 iIgnoreSpellIds->set(id, true);
79 //===============================================
81 bool VMapFactory::checkSpellForLoS(unsigned int pSpellId)
83 return(!iIgnoreSpellIds->containsKey(pSpellId));
86 //===============================================
87 // just return the instance
88 IVMapManager* VMapFactory::createOrGetVMapManager()
90 if(gVMapManager == 0)
91 gVMapManager= new VMapManager(); // should be taken from config ... Please change if you like :-)
92 return gVMapManager;
95 //===============================================
96 // delete all internal data structures
97 void VMapFactory::clear()
99 if(iIgnoreSpellIds)
101 delete iIgnoreSpellIds;
102 iIgnoreSpellIds = NULL;
104 if(gVMapManager)
106 delete gVMapManager;
107 gVMapManager = NULL;