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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
|
// passage.c
// Egoboo, Copyright (C) 2000 Aaron Bishop
#include "egoboo.h"
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
int open_passage(int passage)
{
// ZZ> This function makes a passage passable
int x, y;
unsigned int fan;
int useful;
useful = FALSE;
if(passage < numpassage)
{
useful = (passopen[passage]==FALSE);
passopen[passage] = TRUE;
y = passtly[passage];
while(y <= passbry[passage])
{
x = passtlx[passage];
while(x <= passbrx[passage])
{
fan = meshfanstart[y]+x;
meshfx[fan] = meshfx[fan]&(255-MESHFXWALL-MESHFXIMPASS-MESHFXSLIPPY);
x++;
}
y++;
}
}
return useful;
}
//--------------------------------------------------------------------------------------------
int break_passage(int passage, unsigned short starttile, unsigned short frames,
unsigned short become, unsigned char meshfxor)
{
// ZZ> This function breaks the tiles of a passage if there is a character standing
// on 'em... Turns the tiles into damage terrain if it reaches last frame.
int x, y;
unsigned short tile, endtile;
unsigned int fan;
int useful, character;
endtile = starttile+frames-1;
useful = FALSE;
if(passage < numpassage)
{
character = 0;
while(character < MAXCHR)
{
if(chron[character] && !chrinpack[character])
{
if(chrweight[character] > 20 && chrflyheight[character] == 0 && chrzpos[character] < (chrlevel[character]+20) && chrattachedto[character]==MAXCHR)
{
x = chrxpos[character]; x = x>>7;
if(x>=passtlx[passage] && x<=passbrx[passage])
{
y = chrypos[character]; y = y>>7;
if(y>=passtly[passage] && y<=passbry[passage])
{
// The character is in the passage, so might need to break...
fan = meshfanstart[y]+x;
tile = meshtile[fan];
if(tile >= starttile && tile < endtile)
{
// Remember where the hit occured...
valuetmpx = chrxpos[character];
valuetmpy = chrypos[character];
useful = TRUE;
// Change the tile
tile++;
if(tile == endtile)
{
meshfx[fan]|=meshfxor;
if(become != 0)
{
tile = become;
}
}
meshtile[fan] = tile;
}
}
}
}
}
character++;
}
}
return useful;
}
//--------------------------------------------------------------------------------------------
void flash_passage(int passage, unsigned char color)
{
// ZZ> This function makes a passage flash white
int x, y, cnt, numvert;
unsigned int fan, vert;
if(passage < numpassage)
{
y = passtly[passage];
while(y <= passbry[passage])
{
x = passtlx[passage];
while(x <= passbrx[passage])
{
fan = meshfanstart[y]+x;
vert = meshvrtstart[fan];
cnt = 0;
numvert = meshcommandnumvertices[meshtype[fan]];
while(cnt < numvert)
{
meshvrta[vert] = color;
vert++;
cnt++;
}
x++;
}
y++;
}
}
}
//--------------------------------------------------------------------------------------------
unsigned char find_tile_in_passage(int passage, int tiletype)
{
// ZZ> This function finds the next tile in the passage, valuetmpx and valuetmpy
// must be set first, and are set on a find... Returns TRUE or FALSE
// depending on if it finds one or not
int x, y;
unsigned int fan;
if(passage < numpassage)
{
// Do the first row
x = valuetmpx >> 7;
y = valuetmpy >> 7;
if(x < passtlx[passage]) x = passtlx[passage];
if(y < passtly[passage]) y = passtly[passage];
if(y < passbry[passage])
{
while(x <= passbrx[passage])
{
fan = meshfanstart[y]+x;
if(meshtile[fan] == tiletype)
{
valuetmpx = (x << 7) + 64;
valuetmpy = (y << 7) + 64;
return TRUE;
}
x++;
}
y++;
}
// Do all remaining rows
while(y <= passbry[passage])
{
x = passtlx[passage];
while(x <= passbrx[passage])
{
fan = meshfanstart[y]+x;
if(meshtile[fan] == tiletype)
{
valuetmpx = (x << 7) + 64;
valuetmpy = (y << 7) + 64;
return TRUE;
}
x++;
}
y++;
}
}
return FALSE;
}
//--------------------------------------------------------------------------------------------
unsigned short who_is_blocking_passage(int passage)
{
// ZZ> This function returns MAXCHR if there is no character in the passage,
// otherwise the index of the first character found is returned...
// Finds living ones, then items and corpses
float tlx, tly, brx, bry;
unsigned short character, foundother;
float bumpsize;
// Passage area
tlx = (passtlx[passage]<<7)-CLOSETOLERANCE;
tly = (passtly[passage]<<7)-CLOSETOLERANCE;
brx = ((passbrx[passage]+1)<<7)+CLOSETOLERANCE;
bry = ((passbry[passage]+1)<<7)+CLOSETOLERANCE;
// Look at each character
foundother = MAXCHR;
character = 0;
while(character < MAXCHR)
{
if(chron[character])
{
bumpsize = chrbumpsize[character];
if((!chrinpack[character]) && chrattachedto[character]==MAXCHR && bumpsize!=0)
{
if(chrxpos[character]>tlx-bumpsize && chrxpos[character]<brx+bumpsize)
{
if(chrypos[character]>tly-bumpsize && chrypos[character]<bry+bumpsize)
{
if(chralive[character] && chrisitem[character]==FALSE)
{
// Found a live one
return character;
}
else
{
// Found something else
foundother = character;
}
}
}
}
}
character++;
}
// No characters found
return foundother;
}
//--------------------------------------------------------------------------------------------
unsigned short who_is_blocking_passage_ID(int passage, unsigned int idsz)
{
// ZZ> This function returns MAXCHR if there is no character in the passage who
// have an item with the given ID. Otherwise, the index of the first character
// found is returned... Only finds living characters...
float tlx, tly, brx, bry;
unsigned short character, sTmp;
float bumpsize;
// Passage area
tlx = (passtlx[passage]<<7)-CLOSETOLERANCE;
tly = (passtly[passage]<<7)-CLOSETOLERANCE;
brx = ((passbrx[passage]+1)<<7)+CLOSETOLERANCE;
bry = ((passbry[passage]+1)<<7)+CLOSETOLERANCE;
// Look at each character
character = 0;
while(character < MAXCHR)
{
if(chron[character])
{
bumpsize = chrbumpsize[character];
if((!chrisitem[character]) && bumpsize!=0 && chrinpack[character]==0)
{
if(chrxpos[character]>tlx-bumpsize && chrxpos[character]<brx+bumpsize)
{
if(chrypos[character]>tly-bumpsize && chrypos[character]<bry+bumpsize)
{
if(chralive[character])
{
// Found a live one... Does it have a matching item?
// Check the pack
sTmp = chrnextinpack[character];
while(sTmp != MAXCHR)
{
if(capidsz[chrmodel[sTmp]][IDSZPARENT]==idsz || capidsz[chrmodel[sTmp]][IDSZTYPE]==idsz)
{
// It has the item...
return character;
}
sTmp = chrnextinpack[sTmp];
}
// Check left hand
sTmp = chrholdingwhich[character][0];
if(sTmp != MAXCHR)
{
sTmp = chrmodel[sTmp];
if(capidsz[sTmp][IDSZPARENT]==idsz || capidsz[sTmp][IDSZTYPE]==idsz)
{
// It has the item...
return character;
}
}
// Check right hand
sTmp = chrholdingwhich[character][1];
if(sTmp != MAXCHR)
{
sTmp = chrmodel[sTmp];
if(capidsz[sTmp][IDSZPARENT]==idsz || capidsz[sTmp][IDSZTYPE]==idsz)
{
// It has the item...
return character;
}
}
}
}
}
}
}
character++;
}
// No characters found
return MAXCHR;
}
//--------------------------------------------------------------------------------------------
int close_passage(int passage)
{
// ZZ> This function makes a passage impassable, and returns TRUE if it isn't blocked
int x, y, cnt;
float tlx, tly, brx, bry;
unsigned int fan;
unsigned short character;
float bumpsize;
unsigned short numcrushed;
unsigned short crushedcharacters[MAXCHR];
if((passmask[passage]&(MESHFXIMPASS|MESHFXWALL)))
{
// Make sure it isn't blocked
tlx = (passtlx[passage]<<7)-CLOSETOLERANCE;
tly = (passtly[passage]<<7)-CLOSETOLERANCE;
brx = ((passbrx[passage]+1)<<7)+CLOSETOLERANCE;
bry = ((passbry[passage]+1)<<7)+CLOSETOLERANCE;
numcrushed = 0;
character = 0;
while(character < MAXCHR)
{
bumpsize = chrbumpsize[character];
if(chron[character]&&(!chrinpack[character])&&chrattachedto[character]==MAXCHR&&chrbumpsize[character]!=0)
{
if(chrxpos[character]>tlx-bumpsize && chrxpos[character]<brx+bumpsize)
{
if(chrypos[character]>tly-bumpsize && chrypos[character]<bry+bumpsize)
{
if(chrcanbecrushed[character]==FALSE)
{
return FALSE;
}
else
{
crushedcharacters[numcrushed] = character;
numcrushed++;
}
}
}
}
character++;
}
// Crush any unfortunate characters
cnt = 0;
while(cnt < numcrushed)
{
character = crushedcharacters[cnt];
chralert[character] |= ALERTIFCRUSHED;
cnt++;
}
}
// Close it off
if(passage < numpassage)
{
passopen[passage] = FALSE;
y = passtly[passage];
while(y <= passbry[passage])
{
x = passtlx[passage];
while(x <= passbrx[passage])
{
fan = meshfanstart[y]+x;
meshfx[fan] = meshfx[fan]|passmask[passage];
x++;
}
y++;
}
}
return TRUE;
}
//--------------------------------------------------------------------------------------------
void clear_passages()
{
// ZZ> This function clears the passage list ( for doors )
numpassage = 0;
numshoppassage = 0;
}
//--------------------------------------------------------------------------------------------
void add_shop_passage(int owner, int passage)
{
// ZZ> This function creates a shop passage
if(passage < numpassage && numshoppassage < MAXPASS)
{
// The passage exists...
shoppassage[numshoppassage] = passage;
shopowner[numshoppassage] = owner; // Assume the owner is alive
numshoppassage++;
}
}
//--------------------------------------------------------------------------------------------
void add_passage(int tlx, int tly, int brx, int bry, unsigned char open, unsigned char mask)
{
// ZZ> This function creates a passage area
if(tlx < 0) tlx = 0;
if(tlx > meshsizex-1) tlx = meshsizex-1;
if(tly < 0) tly = 0;
if(tly > meshsizey-1) tly = meshsizey-1;
if(brx < 0) brx = 0;
if(brx > meshsizex-1) brx = meshsizex-1;
if(bry < 0) bry = 0;
if(bry > meshsizey-1) bry = meshsizey-1;
if(numpassage < MAXPASS)
{
passtlx[numpassage] = tlx;
passtly[numpassage] = tly;
passbrx[numpassage] = brx;
passbry[numpassage] = bry;
passmask[numpassage] = mask;
passtracktype[numpassage] = IGNOTRACK; // Interactive music
passtrackcount[numpassage] = 1; // Interactive music
numpassage++;
if(open)
passopen[numpassage-1]=TRUE;
else
passopen[numpassage-1]=FALSE;
}
}
//--------------------------------------------------------------------------------------------
void setup_passage(char *modname)
{
// ZZ> This function reads the passage file
char newloadname[256];
unsigned char cTmp;
int tlx, tly, brx, bry;
unsigned char open, mask;
FILE *fileread;
// Reset all of the old passages
clear_passages();
// Load the file
make_newloadname(modname, FILENAME("/gamedat/passage.txt"), newloadname);
fileread = fopen(newloadname, "r");
if(fileread)
{
while(goto_colon_yesno(fileread))
{
fscanf(fileread, "%d%d%d%d", &tlx, &tly, &brx, &bry);
cTmp = get_first_letter(fileread);
open = FALSE;
if(cTmp == 'T' || cTmp == 't') open = TRUE;
cTmp = get_first_letter(fileread);
mask = MESHFXIMPASS|MESHFXWALL;
if(cTmp == 'T' || cTmp == 't') mask = MESHFXIMPASS;
cTmp = get_first_letter(fileread);
if(cTmp == 'T' || cTmp == 't') mask = MESHFXSLIPPY;
add_passage(tlx, tly, brx, bry, open, mask);
}
fclose(fileread);
}
}
|