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

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

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sys/types.h>
22#include "VMapFactory.h"
23#include "VMapManager.h"
24
25using namespace G3D;
26
27namespace VMAP
28{
29    extern void chompAndTrim(std::string& str);
30
31    VMapManager *gVMapManager = 0;
32    Table<unsigned int , bool>* iIgnoreSpellIds=0;
33
34    //===============================================
35    // result false, if no more id are found
36
37    bool getNextId(const std::string& pString, unsigned int& pStartPos, unsigned int& pId)
38    {
39        bool result = false;
40        unsigned int i;
41        for(i=pStartPos;i<pString.size(); ++i)
42        {
43            if(pString[i] == ',')
44            {
45                break;
46            }
47        }
48        if(i>pStartPos)
49        {
50            std::string idString = pString.substr(pStartPos, i-pStartPos);
51            pStartPos = i+1;
52            chompAndTrim(idString);
53            pId = atoi(idString.c_str());
54            result = true;
55        }
56        return(result);
57    }
58
59    //===============================================
60    /**
61    parameter: String of map ids. Delimiter = ","
62    */
63
64    void VMapFactory::preventSpellsFromBeingTestedForLoS(const char* pSpellIdString)
65    {
66        if(!iIgnoreSpellIds)
67            iIgnoreSpellIds = new Table<unsigned int , bool>();
68        if(pSpellIdString != NULL)
69        {
70            unsigned int pos =0;
71            unsigned int id;
72            std::string confString(pSpellIdString);
73            chompAndTrim(confString);
74            while(getNextId(confString, pos, id))
75            {
76                iIgnoreSpellIds->set(id, true);
77            }
78        }
79    }
80
81    //===============================================
82
83    bool VMapFactory::checkSpellForLoS(unsigned int pSpellId)
84    {
85        return(!iIgnoreSpellIds->containsKey(pSpellId));
86    }
87
88    //===============================================
89    // just return the instance
90    IVMapManager* VMapFactory::createOrGetVMapManager()
91    {
92        if(gVMapManager == 0)
93            gVMapManager= new VMapManager();                // should be taken from config ... Please change if you like :-)
94        return gVMapManager;
95    }
96
97    //===============================================
98    // delete all internal data structures
99    void VMapFactory::clear()
100    {
101        if(iIgnoreSpellIds)
102            delete iIgnoreSpellIds;
103        if(gVMapManager)
104            delete gVMapManager;
105    }
106}
Note: See TracBrowser for help on using the browser.