[go: up one dir, main page]

Menu

[r15]: / engine / map.cpp  Maximize  Restore  History

Download this file

325 lines (269 with data), 6.8 kB

  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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//
// Map manipulation routines
//
#include "core.hpp"
#include "gamedata.h"
#include "map.hpp"
#include "object.hpp"
#include "ithelib.h"
/*
* isSolid - return TRUE if the map square of interest is impassible
*/
int isSolid(int x,int y)
{
OBJECT *temp;
if(IsTileSolid(x,y)) // Is the tile solid?
return 1;
if(x>=mapx && y>=mapy) // Check for a big object
if(x<mapx+VSW) // If onscreen
if(y<mapy+VSH)
{
if(solidmap[VIEWDIST+x-mapx][VIEWDIST+y-mapy])
return 1;
return 0;
}
temp = curmap->objmap[ytab[y]+x]; // Now look at object map
for(;temp;temp=temp->next)
if(temp->flags & IS_SOLID)
if(temp->flags & IS_ON)
return 1;
return 0;
}
/*
* GetSolidMap - return TRUE if the map square of interest is impassible
*/
OBJECT *GetSolidMap(int x,int y)
{
if(x>=mapx && y>=mapy) // Check for a big object
if(x<mapx+VSW) // If onscreen
if(y<mapy+VSH)
return solidmap[VIEWDIST+x-mapx][VIEWDIST+y-mapy];
return NULL;
}
/*
* blocksLight - return TRUE if the map square of interest blocks light
*/
int BlocksLight(int x,int y)
{
TILE *tile;
OBJECT *object;
if(x>=curmap->w || y>=curmap->h || x<0 || y<0)
return 1; // Out of the map area
tile = GetTile(x,y); // Look at tiles first
if(tile->flags & DOES_BLOCKLIGHT)
return 1;
object = GetObjectBase(x,y);
for(;object;object=object->next)
{
if(object->flags & DOES_BLOCKLIGHT)
if(object->flags & IS_ON)
return 1;
}
return 0;
}
/*
* AlwaysSolid - return TRUE if the map square of interest is impassible
* but FALSE if it is only impassible sometimes (doors etc)
*/
int AlwaysSolid(int x,int y)
{
TILE *tile;
OBJECT *temp;
tile = GetTile(x,y); // Look at tiles first
if(tile->flags & IS_SOLID)
return 1;
if(x>=mapx && y>=mapy) // Check for a big object
if(x<mapx+VSW) // If onscreen
if(y<mapy+VSH)
{
temp=largemap[VIEWDIST+x-mapx][VIEWDIST+y-mapy];
if(temp)
if(temp->flags & IS_SOLID)
{
if(temp->flags & CAN_OPEN /*|| temp->flags & IS_PERSON*/)
return 0;
else
{
temp=solidmap[VIEWDIST+x-mapx][VIEWDIST+y-mapy];
if(temp)
{
if((temp->flags & CAN_OPEN)
// || temp->flags.person
|| (temp->flags & IS_ON) == 0)
return 0;
else
return 1;
}
else
return 0;
}
}
}
temp = curmap->objmap[ytab[y]+x]; // Now look at object map
for(;temp;temp=temp->next)
if(temp->flags & IS_SOLID)
if(temp->flags & IS_ON)
{
if(temp->flags & CAN_OPEN)
return 0;
// if(temp->flags & IS_PERSON)
// return 0;
// if(solidmap
return 1;
}
return 0;
}
/*
* isDecor - return TRUE if the map square of interest has a Decor object
*/
int isDecor(int x,int y)
{
OBJECT *temp;
temp = curmap->objmap[ytab[y]+x]; // Now look at object map
if(temp)
{
for(;temp->next;temp=temp->next); // seek to end
if(temp->flags & IS_DECOR)
return 1;
}
return 0;
}
/*
* CentreMap - Centre the map's position around an object
*/
void CentreMap(OBJECT *focus)
{
if(!focus)
return;
if(focus->flags & IS_LARGE)
{
focus->mw = focus->w>>5;
if(focus->w & 0xf || !focus->mw)
focus->mw++;
focus->mh = focus->h>>5;
if(focus->h & 0xf || !focus->mh)
focus->mh++;
mapx = (focus->x-VSMIDX)+(focus->mw>>1);
mapy = (focus->y-VSMIDY)+(focus->mh>>1);
}
else
{
mapx = focus->x-VSMIDX;
mapy = focus->y-VSMIDY;
}
if(mapx<0)
mapx=0;
if(mapy<0)
mapy=0;
mapx2 = mapx+VSW-1;
mapy2 = mapy+VSH-1;
}
/*
* GetTile - return a pointer to the kind of tile in this position
*/
TILE *GetTile(int x,int y)
{
unsigned int i;
i = curmap->physmap[MAP_POS(x,y)];
if(i == RANDOM_TILE) // Oh God!
return &TIlist[0]; //Resort to trickery
return &TIlist[i];
}
/*
* IsTileSolid - return whether the tile in this square is solid
*/
int IsTileSolid(int x,int y)
{
TILE *t;
OBJECT *temp;
if(x>=curmap->w)
return 1;
if(y>=curmap->h)
return 1;
// Examine the tile
//t = &TIlist[curmap->physmap[MAP_POS(x,y)]];
t = GetTile(x,y);
// If it's water, look for a bridge or boat over it
if(t->flags & IS_WATER)
{
for(temp=GetObject(x,y);temp;temp=temp->next)
if(temp->flags & IS_WATER)
return 0;
}
// Otherwise..
if(t->flags & IS_SOLID)
return 1;
return 0;
}
/*
* GetTileCost - return movement cost for the tile at x,y
*/
int GetTileCost(int x,int y)
{
TILE *t;
OBJECT *temp;
if(x>=curmap->w)
return -1; // Wall
if(y>=curmap->h)
return -1; // Wall
// Examine the tile. If it's water, look for a bridge over it
t = GetTile(x,y);
if(t->flags & IS_WATER)
{
for(temp=GetObject(x,y);temp;temp=temp->next)
if(temp->flags & IS_WATER)
return t->cost;
}
// Is it solid?
if(t->flags & IS_SOLID)
return -1;
// Otherwise..
return t->cost;
}
/*
* IsTileWater - return whether the tile in this square is water
*/
int IsTileWater(int x,int y)
{
if(TIlist[curmap->physmap[MAP_POS(x,y)]].flags & IS_WATER)
return 1;
return 0;
}
/*
* Check if the given X,Y coordinates intersect a given large object
*/
int LargeIntersect(OBJECT *temp, int x, int y)
{
int blockx,blocky,blockw,blockh;
if(!temp)
return 0;
if(!(temp->flags & IS_SOLID))
return 0;
if(temp->curdir > CHAR_D) //(U,D,L,R) > D = L,R
{
blockx=temp->hblock[BLK_X];
blocky=temp->hblock[BLK_Y];
blockw=temp->hblock[BLK_W]-1;
blockh=temp->hblock[BLK_H]-1;
}
else
{
blockx=temp->vblock[BLK_X];
blocky=temp->vblock[BLK_Y];
blockw=temp->vblock[BLK_W]-1;
blockh=temp->vblock[BLK_H]-1;
}
// Convert solid region to map coordinates
blockx+=temp->x;
blocky+=temp->y;
blockw+=blockx;
blockh+=blocky;
// Only return the large object if it matches the solid area
if(x>=blockx && x<=blockw)
if(y>=blocky && y<=blockh)
{
// ilog_printf("%s %d,%d intersects %d-%d,%d-%d\n",temp->name,x,y,blockx,blockw,blocky,blockh);
return 1;
}
return 0;
}