root/trunk/src/game/CellImpl.h @ 37

Revision 2, 4.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#ifndef MANGOS_CELLIMPL_H
20#define MANGOS_CELLIMPL_H
21
22#include "Cell.h"
23#include "Map.h"
24#include <cmath>
25
26inline Cell::Cell(CellPair const& p)
27{
28    data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
29    data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
30    data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
31    data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
32    data.Part.nocreate = 0;
33    data.Part.reserved = 0;
34}
35
36template<class LOCK_TYPE,class T, class CONTAINER>
37inline void
38Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
39{
40    const CellPair &standing_cell = l.i_cellPair;
41    if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
42        return;
43
44    uint16 district = (District)this->data.Part.reserved;
45    if(district == CENTER_DISTRICT)
46    {
47        m.Visit(l, visitor);
48        return;
49    }
50
51    // set up the cell range based on the district
52    // the overloaded operators handle range checking
53    CellPair begin_cell = standing_cell;
54    CellPair end_cell = standing_cell;
55
56    switch( district )
57    {
58        case ALL_DISTRICT:
59        {
60            begin_cell << 1; begin_cell -= 1;               // upper left
61            end_cell >> 1; end_cell += 1;                   // lower right
62            break;
63        }
64        case UPPER_LEFT_DISTRICT:
65        {
66            begin_cell << 1; begin_cell -= 1;               // upper left
67            break;
68        }
69        case UPPER_RIGHT_DISTRICT:
70        {
71            begin_cell -= 1;                                // up
72            end_cell >> 1;                                  // right
73            break;
74        }
75        case LOWER_LEFT_DISTRICT:
76        {
77            begin_cell << 1;                                // left
78            end_cell += 1;                                  // down
79            break;
80        }
81        case LOWER_RIGHT_DISTRICT:
82        {
83            end_cell >> 1; end_cell += 1;                   // lower right
84            break;
85        }
86        case LEFT_DISTRICT:
87        {
88            begin_cell -= 1;                                // up
89            end_cell >> 1; end_cell += 1;                   // lower right
90            break;
91        }
92        case RIGHT_DISTRICT:
93        {
94            begin_cell << 1; begin_cell -= 1;               // upper left
95            end_cell += 1;                                  // down
96            break;
97        }
98        case UPPER_DISTRICT:
99        {
100            begin_cell << 1; begin_cell -= 1;               // upper left
101            end_cell >> 1;                                  // right
102            break;
103        }
104        case LOWER_DISTRICT:
105        {
106            begin_cell << 1;                                // left
107            end_cell >> 1; end_cell += 1;                   // lower right
108            break;
109        }
110        default:
111        {
112            assert( false );
113            break;
114        }
115    }
116
117    // loop the cell range
118    for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++)
119    {
120        for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; y++)
121        {
122            CellPair cell_pair(x,y);
123            Cell r_zone(cell_pair);
124            r_zone.data.Part.nocreate = l->data.Part.nocreate;
125            CellLock<LOCK_TYPE> lock(r_zone, cell_pair);
126            m.Visit(lock, visitor);
127        }
128    }
129}
130#endif
Note: See TracBrowser for help on using the browser.