-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPathMap.cpp
187 lines (148 loc) · 3.22 KB
/
PathMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
This file is part of W3ZMapEditor (c).
W3ZMapEditor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
W3ZMapEditor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with W3ZMapEditor; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// PathMap.cpp: implementation of the CPathMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "War3TypesAndConstants.h"
#include "PathMap.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPathMap::CPathMap()
{
m_iHeight = 0;
m_iWidth = 0;
m_pbyPathMap = NULL;
}
CPathMap::~CPathMap()
{
if (m_pbyPathMap)
{delete []m_pbyPathMap;}
}
/*
SetSize
*******
Sets path map size.
In:
int width: with of the path map (must be > 0 and < PATH_MAX_WIDTH)
int height: height of the path map (must be > 0 and < PATH_MAX_HEIGHT)
Out:
nothing
Return:
BOOL: TRUE if successfull, FALSE otherwise
*/
BOOL CPathMap::SetSize(int v_iWidth, int v_iHeight)
{
BOOL bRet = TRUE;
if ((v_iWidth > 0) && (v_iHeight > 0)
&& (v_iWidth < PATH_MAX_WIDTH) && (v_iHeight < PATH_MAX_HEIGHT))
{
if ((v_iWidth != m_iWidth) && (v_iHeight != m_iHeight))
{// only if the size has changed
if (NULL != m_pbyPathMap)
{// deletes old path
delete []m_pbyPathMap;
}
m_pbyPathMap = new byte[v_iWidth*v_iHeight];
if (m_pbyPathMap)
{ // memory allocated
m_iHeight = v_iHeight;
m_iWidth = v_iWidth;
memset( m_pbyPathMap, PATH_DEFAULT, v_iWidth*v_iHeight);
}
else
{ // failled to allocate memory
m_iHeight = 0;
m_iWidth = 0;
bRet = FALSE;
}
}
else
{// if the size has not changed, just reset the data
memset( m_pbyPathMap, PATH_DEFAULT, v_iWidth*v_iHeight);
}
}
else
{
bRet = FALSE;
}
return bRet;
}
/*
GetWidth
********
Returns path map width.
In:
nothing
Out:
nothing
Return:
int: path map width.
*/
int CPathMap::GetWidth()
{
return m_iWidth;
}
/*
GetHeight
*********
Returns path map height.
In:
nothing
Out:
nothing
Return:
int: path map height.
*/
int CPathMap::GetHeight()
{
return m_iHeight;
}
/*
GetLength
*********
Retruns the length of the path map (in byte).
In:
nothing
Out:
nothing
Return:
int: path map lenght (0 if size not set or empty path map)
*/
int CPathMap::GetLength()
{
return m_iWidth*m_iHeight;
}
/*
GetGetData
**********
Returns a pointer to the path map (a byte map).
In:
nothing
Out:
nothing
Return:
byte*: a pointer to the path map (byte map), NULL if there is no path map
*/
byte* CPathMap::GetData()
{
return m_pbyPathMap;
}