root/trunk/src/shared/vmap/VMapFactory.cpp @ 13

Revision 2, 3.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <sys/types.h>
20#include "VMapFactory.h"
21#include "VMapManager.h"
22
23using namespace G3D;
24
25namespace VMAP
26{
27    extern void chompAndTrim(std::string& str);
28
29    VMapManager *gVMapManager = 0;
30    Table<unsigned int , bool>* iIgnoreSpellIds=0;
31
32    //===============================================
33    // result false, if no more id are found
34
35    bool getNextId(const std::string& pString, unsigned int& pStartPos, unsigned int& pId)
36    {
37        bool result = false;
38        unsigned int i;
39        for(i=pStartPos;i<pString.size(); ++i)
40        {
41            if(pString[i] == ',')
42            {
43                break;
44            }
45        }
46        if(i>pStartPos)
47        {
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;
53        }
54        return(result);
55    }
56
57    //===============================================
58    /**
59    parameter: String of map ids. Delimiter = ","
60    */
61
62    void VMapFactory::preventSpellsFromBeingTestedForLoS(const char* pSpellIdString)
63    {
64        if(!iIgnoreSpellIds)
65            iIgnoreSpellIds = new Table<unsigned int , bool>();
66        if(pSpellIdString != NULL)
67        {
68            unsigned int pos =0;
69            unsigned int id;
70            std::string confString(pSpellIdString);
71            chompAndTrim(confString);
72            while(getNextId(confString, pos, id))
73            {
74                iIgnoreSpellIds->set(id, true);
75            }
76        }
77    }
78
79    //===============================================
80
81    bool VMapFactory::checkSpellForLoS(unsigned int pSpellId)
82    {
83        return(!iIgnoreSpellIds->containsKey(pSpellId));
84    }
85
86    //===============================================
87    // just return the instance
88    IVMapManager* VMapFactory::createOrGetVMapManager()
89    {
90        if(gVMapManager == 0)
91            gVMapManager= new VMapManager();                // should be taken from config ... Please change if you like :-)
92        return gVMapManager;
93    }
94
95    //===============================================
96    // delete all internal data structures
97    void VMapFactory::clear()
98    {
99        if(iIgnoreSpellIds)
100            delete iIgnoreSpellIds;
101        if(gVMapManager)
102            delete gVMapManager;
103    }
104}
Note: See TracBrowser for help on using the browser.