OregonCore  revision 3611e8a-git
Your Favourite TBC server
VMapFactory.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <sys/types.h>
19 #include "VMapFactory.h"
20 #include "VMapManager2.h"
21 #include "G3D/Table.h"
22 
23 using namespace G3D;
24 
25 namespace VMAP
26 {
27  void chompAndTrim(std::string& str)
28  {
29  while (str.length() > 0)
30  {
31  char lc = str[str.length() - 1];
32  if (lc == '\r' || lc == '\n' || lc == ' ' || lc == '"' || lc == '\'')
33  str = str.substr(0, str.length() - 1);
34  else
35  break;
36  }
37 
38  while (str.length() > 0)
39  {
40  char lc = str[0];
41  if (lc == ' ' || lc == '"' || lc == '\'')
42  str = str.substr(1, str.length() - 1);
43  else
44  break;
45  }
46  }
47 
49  Table<unsigned int , bool>* iIgnoreSpellIds = 0;
50 
51  //===============================================
52  // result false, if no more id are found
53 
54  bool getNextId(const std::string& pString, unsigned int& pStartPos, unsigned int& pId)
55  {
56  bool result = false;
57  unsigned int i;
58  for (i = pStartPos; i < pString.size(); ++i)
59  if (pString[i] == ',')
60  break;
61 
62  if (i > pStartPos)
63  {
64  std::string idString = pString.substr(pStartPos, i - pStartPos);
65  pStartPos = i + 1;
66  chompAndTrim(idString);
67  pId = atoi(idString.c_str());
68  result = true;
69  }
70  return (result);
71  }
72 
73  //===============================================
77  void VMapFactory::preventSpellsFromBeingTestedForLoS(const char* pSpellIdString)
78  {
79  if (!iIgnoreSpellIds)
80  iIgnoreSpellIds = new Table<unsigned int , bool>();
81  if (pSpellIdString != NULL)
82  {
83  unsigned int pos = 0;
84  unsigned int id;
85  std::string confString(pSpellIdString);
86  chompAndTrim(confString);
87  while (getNextId(confString, pos, id))
88  iIgnoreSpellIds->set(id, true);
89  }
90  }
91 
92  //===============================================
93 
94  bool VMapFactory::checkSpellForLoS(unsigned int pSpellId)
95  {
96  return (!iIgnoreSpellIds->containsKey(pSpellId));
97  }
98 
99  //===============================================
100  // just return the instance
101  IVMapManager* VMapFactory::createOrGetVMapManager()
102  {
103  if (gVMapManager == nullptr)
104  gVMapManager = new VMapManager2(); // should be taken from config ... Please change if you like :-)
105  return gVMapManager;
106  }
107 
108  //===============================================
109  // delete all internal data structures
110  void VMapFactory::clear()
111  {
112  delete iIgnoreSpellIds;
113  iIgnoreSpellIds = NULL;
114 
115  delete gVMapManager;
116  gVMapManager = NULL;
117  }
118 }
bool getNextId(const std::string &pString, unsigned int &pStartPos, unsigned int &pId)
Definition: VMapFactory.cpp:54
IVMapManager * gVMapManager
Definition: VMapFactory.cpp:48
Table< unsigned int, bool > * iIgnoreSpellIds
Definition: VMapFactory.cpp:49
void chompAndTrim(std::string &str)
Definition: VMapFactory.cpp:27