| 1 |
/** |
| 2 |
* FreeDink game-specific code |
| 3 |
|
| 4 |
* Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson |
| 5 |
* Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2012, 2014, 2015 Sylvain Beucler |
| 6 |
|
| 7 |
* This file is part of GNU FreeDink |
| 8 |
|
| 9 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 10 |
* modify it under the terms of the GNU General Public License as |
| 11 |
* published by the Free Software Foundation; either version 3 of the |
| 12 |
* License, or (at your option) any later version. |
| 13 |
|
| 14 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 15 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
* General Public License for more details. |
| 18 |
|
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see |
| 21 |
* <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifdef HAVE_CONFIG_H |
| 25 |
#include <config.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include "freedink.h" |
| 29 |
|
| 30 |
#include <stdio.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include "fastfile.h" |
| 35 |
|
| 36 |
#include "IOGfxPrimitives.h" |
| 37 |
#include "IOGfxDisplay.h" |
| 38 |
#include "ImageLoader.h" |
| 39 |
#include "gfx.h" |
| 40 |
#include "gfx_fonts.h" |
| 41 |
#include "gfx_palette.h" |
| 42 |
#include "gfx_sprites.h" |
| 43 |
#include "gfx_tiles.h" |
| 44 |
#include "bgm.h" |
| 45 |
#include "sfx.h" |
| 46 |
#include "update_frame.h" |
| 47 |
#include "io_util.h" |
| 48 |
#include "paths.h" |
| 49 |
#include "input.h" |
| 50 |
#include "log.h" |
| 51 |
|
| 52 |
#include "game_engine.h" |
| 53 |
#include "live_sprites_manager.h" |
| 54 |
#include "live_screen.h" |
| 55 |
#include "DMod.h" |
| 56 |
#include "meminfo.h" |
| 57 |
#include "dinkc_console.h" |
| 58 |
#include "game_choice.h" |
| 59 |
#include "text.h" |
| 60 |
|
| 61 |
|
| 62 |
Uint32 but_timer = 0; |
| 63 |
|
| 64 |
/* Fadedown/fadeup counter */ |
| 65 |
static int process_count = 0; |
| 66 |
|
| 67 |
struct show_bmp showb; |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* Check if the sprite can pass or should be blocked |
| 72 |
* |
| 73 |
* Returns 0 = can pass, <>0 = should be blocked |
| 74 |
*/ |
| 75 |
int check_if_move_is_legal(int u) |
| 76 |
{ |
| 77 |
if ((dversion >= 108) /* move_nohard is active for all movements, not just active moves */ |
| 78 |
|| (/* dversion == 107 && */ spr[u].move_active)) |
| 79 |
if (spr[u].move_nohard == 1) |
| 80 |
return(0); |
| 81 |
|
| 82 |
if (u == 1 && in_this_base(spr[1].seq, dink_base_push)) |
| 83 |
return(0); |
| 84 |
|
| 85 |
int hardness = 0; |
| 86 |
if (spr[u].moveman > 0) |
| 87 |
{ |
| 88 |
int i; |
| 89 |
for (i = 1; i <= spr[u].moveman; i++) |
| 90 |
{ |
| 91 |
hardness = get_hard(spr[u].lpx[i]-20, spr[u].lpy[i], screenlock); |
| 92 |
if (hardness == 2 && spr[u].flying) |
| 93 |
{ |
| 94 |
spr[u].moveman = 0; |
| 95 |
if (dversion >= 108) |
| 96 |
return 0; |
| 97 |
else |
| 98 |
return 2; |
| 99 |
} |
| 100 |
if (hardness > 0) |
| 101 |
{ |
| 102 |
spr[u].x = spr[u].lpx[i-1]; |
| 103 |
spr[u].y = spr[u].lpy[i-1]; |
| 104 |
spr[u].moveman = 0; |
| 105 |
|
| 106 |
if (push_active) |
| 107 |
{ |
| 108 |
if (u == 1 && hardness != 2 && play.push_active == false) |
| 109 |
{ |
| 110 |
if ((spr[u].dir == 2) | (spr[u].dir == 4) | (spr[u].dir == 6) | (spr[u].dir == 8)) |
| 111 |
{ |
| 112 |
//he (dink) is definatly pushing on something |
| 113 |
play.push_active = true; |
| 114 |
play.push_dir = spr[u].dir; |
| 115 |
play.push_timer = thisTickCount; |
| 116 |
} |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
if (play.push_dir != spr[1].dir) play.push_active = false; |
| 121 |
} |
| 122 |
} |
| 123 |
return(hardness); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
if (u == 1) play.push_active = false; |
| 129 |
return(0); |
| 130 |
} |
| 131 |
|
| 132 |
int did_player_cross_screen() |
| 133 |
{ |
| 134 |
if (walk_off_screen == 1) |
| 135 |
return 0; |
| 136 |
|
| 137 |
int ret = 0; |
| 138 |
// DO MATH TO SEE IF THEY HAVE CROSSED THE SCREEN, IF SO LOAD NEW ONE |
| 139 |
if (spr[1].x < playl) |
| 140 |
{ |
| 141 |
if ((*pplayer_map-1) >= 1 && g_dmod.map.loc[*pplayer_map-1] > 0 && screenlock == 0) |
| 142 |
{ |
| 143 |
//move one map to the left |
| 144 |
update_screen_time(); |
| 145 |
grab_trick(4); |
| 146 |
*pplayer_map -= 1; |
| 147 |
game_load_screen(g_dmod.map.loc[*pplayer_map]); |
| 148 |
if (g_dmod.map.indoor[*pplayer_map] == 0) |
| 149 |
play.last_map = *pplayer_map; |
| 150 |
|
| 151 |
draw_screen_game(); |
| 152 |
// compatibility: update Dink position *after* screen change |
| 153 |
spr[1].x = 619; |
| 154 |
spr[1].y = spr[1].lpy[0]; |
| 155 |
ret = 1; |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
spr[1].x = playl; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
else if (spr[1].x > 619) |
| 164 |
{ |
| 165 |
if ((*pplayer_map+1) <= 24*32 && g_dmod.map.loc[*pplayer_map+1] > 0 && screenlock == 0) |
| 166 |
{ |
| 167 |
//move one map to the right |
| 168 |
update_screen_time(); |
| 169 |
grab_trick(6); |
| 170 |
*pplayer_map += 1; |
| 171 |
game_load_screen(g_dmod.map.loc[*pplayer_map]); |
| 172 |
if (g_dmod.map.indoor[*pplayer_map] == 0) |
| 173 |
play.last_map = *pplayer_map; |
| 174 |
|
| 175 |
draw_screen_game(); |
| 176 |
// compatibility: update Dink position *after* screen change |
| 177 |
spr[1].x = playl; |
| 178 |
spr[1].y = spr[1].lpy[0]; |
| 179 |
ret = 1; |
| 180 |
} |
| 181 |
else |
| 182 |
{ |
| 183 |
spr[1].x = 619; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
else if (spr[1].y < 0) |
| 188 |
{ |
| 189 |
if ((*pplayer_map-32) >= 1 && g_dmod.map.loc[*pplayer_map-32] > 0 && screenlock == 0) |
| 190 |
{ |
| 191 |
//move one map up |
| 192 |
update_screen_time(); |
| 193 |
grab_trick(8); |
| 194 |
*pplayer_map -= 32; |
| 195 |
game_load_screen(g_dmod.map.loc[*pplayer_map]); |
| 196 |
if (g_dmod.map.indoor[*pplayer_map] == 0) |
| 197 |
play.last_map = *pplayer_map; |
| 198 |
|
| 199 |
// compatibility: update Dink X position *before* screen change |
| 200 |
// (shouldn't matter when though, since it's an Y motion) |
| 201 |
spr[1].x = spr[1].lpx[0]; |
| 202 |
draw_screen_game(); |
| 203 |
// compatibility: update Dink Y position *after* screen change |
| 204 |
spr[1].y = 399; |
| 205 |
ret = 1; |
| 206 |
} |
| 207 |
else |
| 208 |
{ |
| 209 |
spr[1].y = 0; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
else if (spr[1].y > 399) |
| 215 |
{ |
| 216 |
if ((*pplayer_map+32) <= 24*32 && g_dmod.map.loc[*pplayer_map+32] > 0 && screenlock == 0) |
| 217 |
{ |
| 218 |
//move one map down |
| 219 |
update_screen_time(); |
| 220 |
grab_trick(2); |
| 221 |
*pplayer_map += 32; |
| 222 |
game_load_screen(g_dmod.map.loc[*pplayer_map]); |
| 223 |
if (g_dmod.map.indoor[*pplayer_map] == 0) |
| 224 |
play.last_map = *pplayer_map; |
| 225 |
|
| 226 |
draw_screen_game(); |
| 227 |
// compatibility: update Dink position *after* screen change |
| 228 |
spr[1].y = 0; |
| 229 |
spr[1].x = spr[1].lpx[0]; |
| 230 |
ret = 1; |
| 231 |
} |
| 232 |
else |
| 233 |
{ |
| 234 |
spr[1].y = 399; |
| 235 |
} |
| 236 |
} |
| 237 |
return ret; |
| 238 |
} |
| 239 |
|
| 240 |
/*bool*/int run_through_tag_list_talk(int h) |
| 241 |
{ |
| 242 |
rect box; |
| 243 |
int amount, amounty; |
| 244 |
int i; |
| 245 |
|
| 246 |
for (i = 1; i <= last_sprite_created; i++) |
| 247 |
{ |
| 248 |
|
| 249 |
if (spr[i].active) if (i != h) if (spr[i].brain != 8) |
| 250 |
{ |
| 251 |
|
| 252 |
|
| 253 |
rect_copy(&box, &k[getpic(i)].hardbox); |
| 254 |
rect_offset(&box, spr[i].x, spr[i].y); |
| 255 |
|
| 256 |
rect_inflate(&box, 10,10); |
| 257 |
|
| 258 |
amount = 50; |
| 259 |
amounty = 35; |
| 260 |
if (spr[h].dir == 6) |
| 261 |
{ |
| 262 |
box.left -= amount; |
| 263 |
} |
| 264 |
|
| 265 |
if (spr[h].dir == 4) |
| 266 |
{ |
| 267 |
box.right += amount; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
if (spr[h].dir == 2) |
| 272 |
{ |
| 273 |
box.top -= amounty; |
| 274 |
} |
| 275 |
|
| 276 |
if (spr[h].dir == 8) |
| 277 |
{ |
| 278 |
box.bottom += amounty; |
| 279 |
} |
| 280 |
|
| 281 |
// draw_box(box, 33); |
| 282 |
|
| 283 |
if (inside_box(spr[h].x, spr[h].y, box)) |
| 284 |
{ |
| 285 |
//Msg("Talking to sprite %d", i); |
| 286 |
if (spr[i].script > 0) |
| 287 |
{ |
| 288 |
//if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7)) |
| 289 |
//Msg("trying to find TALK in script %d", spr[i].script); |
| 290 |
if (locate(spr[i].script, "TALK")) |
| 291 |
{ |
| 292 |
kill_returning_stuff(spr[i].script); |
| 293 |
|
| 294 |
run_script(spr[i].script); |
| 295 |
return(/*true*/1); |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
return(/*false*/0); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
/** |
| 315 |
* Trigger a warp (teleport) |
| 316 |
* block: the warp editor sprite |
| 317 |
*/ |
| 318 |
int special_block(int block) |
| 319 |
{ |
| 320 |
if (cur_ed_screen.sprite[block].is_warp == 1) |
| 321 |
{ |
| 322 |
//they touched a warp |
| 323 |
if (cur_ed_screen.sprite[block].sound == 0) |
| 324 |
SoundPlayEffect(7, 12000, 0, 0, 0); |
| 325 |
else |
| 326 |
SoundPlayEffect(cur_ed_screen.sprite[block].sound, 22050, 0, 0, 0); |
| 327 |
|
| 328 |
if (cur_ed_screen.sprite[block].parm_seq != 0) |
| 329 |
{ |
| 330 |
// we'll also play an animation here |
| 331 |
int sprite = find_sprite(block); |
| 332 |
if (sprite > 0) |
| 333 |
{ |
| 334 |
spr[sprite].seq = cur_ed_screen.sprite[block].parm_seq; |
| 335 |
process_warp = block; |
| 336 |
} |
| 337 |
return 1; |
| 338 |
} |
| 339 |
process_warp = block; |
| 340 |
return 1; // redraw screen with fade |
| 341 |
} |
| 342 |
return 0; |
| 343 |
} |
| 344 |
|
| 345 |
/* fade_down() - fade to black */ |
| 346 |
void CyclePalette() |
| 347 |
{ |
| 348 |
if (!truecolor) |
| 349 |
{ |
| 350 |
SDL_Color palette[256]; |
| 351 |
int kk; |
| 352 |
|
| 353 |
gfx_palette_get_phys(palette); |
| 354 |
|
| 355 |
for (kk = 1; kk < 256; kk++) /* skipping index 0 because it's |
| 356 |
already (and always) black ;) */ |
| 357 |
{ |
| 358 |
if (dversion >= 108) |
| 359 |
{ |
| 360 |
/* Use time-based rather than absolute increments; |
| 361 |
avoids incomplete fades on slow computers */ |
| 362 |
/* dt / 2 == dt * 256 / 512 == complete fade in 512ms */ |
| 363 |
int lValue = (thisTickCount - lastTickCount) / 2; |
| 364 |
if (palette[kk].b != 0) |
| 365 |
{ |
| 366 |
if (palette[kk].b > lValue) |
| 367 |
palette[kk].b -= lValue; |
| 368 |
else |
| 369 |
palette[kk].b = 0; |
| 370 |
} |
| 371 |
if (palette[kk].g != 0) |
| 372 |
{ |
| 373 |
if (palette[kk].g > lValue) |
| 374 |
palette[kk].g -= lValue; |
| 375 |
else |
| 376 |
palette[kk].g = 0; |
| 377 |
} |
| 378 |
if (palette[kk].r != 0) |
| 379 |
{ |
| 380 |
if (palette[kk].r > lValue) |
| 381 |
palette[kk].r -= lValue; |
| 382 |
else |
| 383 |
palette[kk].r = 0; |
| 384 |
} |
| 385 |
} |
| 386 |
else |
| 387 |
{ |
| 388 |
if (palette[kk].b != 0) |
| 389 |
{ |
| 390 |
if (palette[kk].b > 10) |
| 391 |
palette[kk].b -= 10; |
| 392 |
else |
| 393 |
palette[kk].b--; |
| 394 |
} |
| 395 |
if (palette[kk].g != 0) |
| 396 |
{ |
| 397 |
if (palette[kk].g > 10) |
| 398 |
palette[kk].g -= 10; |
| 399 |
else |
| 400 |
palette[kk].g--; |
| 401 |
} |
| 402 |
if (palette[kk].r != 0) |
| 403 |
{ |
| 404 |
if (palette[kk].r > 10) |
| 405 |
palette[kk].r -= 10; |
| 406 |
else |
| 407 |
palette[kk].r--; |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
gfx_palette_set_phys(palette); |
| 413 |
} |
| 414 |
else |
| 415 |
{ |
| 416 |
/* truecolor */ |
| 417 |
if (truecolor_fade_lasttick == 0) |
| 418 |
{ |
| 419 |
truecolor_fade_lasttick = game_GetTicks(); |
| 420 |
//truecolor_fade_brightness -= 256*.3; |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
int delta = game_GetTicks() - truecolor_fade_lasttick; |
| 425 |
/* Complete fade in 400ms */ |
| 426 |
truecolor_fade_lasttick = game_GetTicks(); |
| 427 |
g_display->brightness -= delta * 256 / 400.0; |
| 428 |
} |
| 429 |
if (g_display->brightness <= 0) |
| 430 |
g_display->brightness = 0; |
| 431 |
|
| 432 |
} |
| 433 |
|
| 434 |
if (process_downcycle) |
| 435 |
{ |
| 436 |
if (thisTickCount > cycle_clock) |
| 437 |
{ |
| 438 |
process_downcycle = /*false*/0; |
| 439 |
truecolor_fade_lasttick = 0; |
| 440 |
|
| 441 |
if (cycle_script != 0) |
| 442 |
{ |
| 443 |
int junk = cycle_script; |
| 444 |
cycle_script = 0; |
| 445 |
run_script(junk); |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
/* fade_up() */ |
| 452 |
void up_cycle(void) |
| 453 |
{ |
| 454 |
int donethistime = 1; |
| 455 |
|
| 456 |
if (!truecolor) |
| 457 |
{ |
| 458 |
SDL_Color palette[256]; |
| 459 |
int kk; |
| 460 |
|
| 461 |
gfx_palette_get_phys(palette); |
| 462 |
|
| 463 |
for (kk = 1; kk < 256; kk++) |
| 464 |
{ |
| 465 |
int tmp = -1; |
| 466 |
|
| 467 |
tmp = palette[kk].b; // 'int' to avoid 'char' overflow |
| 468 |
if (tmp != GFX_ref_pal[kk].b) |
| 469 |
{ |
| 470 |
donethistime = 0; |
| 471 |
if (tmp > 246) |
| 472 |
tmp++; |
| 473 |
else |
| 474 |
tmp += 10; |
| 475 |
} |
| 476 |
if (tmp > GFX_ref_pal[kk].b) |
| 477 |
tmp = GFX_ref_pal[kk].b; |
| 478 |
palette[kk].b = tmp; |
| 479 |
|
| 480 |
tmp = palette[kk].g; // 'int' to avoid 'char' overflow |
| 481 |
if (tmp != GFX_ref_pal[kk].g) |
| 482 |
{ |
| 483 |
donethistime = 0; |
| 484 |
if (tmp > 246) |
| 485 |
tmp++; |
| 486 |
else |
| 487 |
tmp += 10; |
| 488 |
} |
| 489 |
if (tmp > GFX_ref_pal[kk].g) |
| 490 |
tmp = GFX_ref_pal[kk].g; |
| 491 |
palette[kk].g = tmp; |
| 492 |
|
| 493 |
tmp = palette[kk].r; // 'int' to avoid 'char' overflow |
| 494 |
if (tmp != GFX_ref_pal[kk].r) |
| 495 |
{ |
| 496 |
donethistime = 0; |
| 497 |
if (tmp > 246) |
| 498 |
tmp++; |
| 499 |
else |
| 500 |
tmp += 10; |
| 501 |
} |
| 502 |
if (tmp > GFX_ref_pal[kk].r) |
| 503 |
tmp = GFX_ref_pal[kk].r; |
| 504 |
palette[kk].r = tmp; |
| 505 |
} |
| 506 |
|
| 507 |
gfx_palette_set_phys(palette); |
| 508 |
} |
| 509 |
else |
| 510 |
{ |
| 511 |
/* truecolor */ |
| 512 |
donethistime = 0; |
| 513 |
if (truecolor_fade_lasttick == 0) |
| 514 |
{ |
| 515 |
truecolor_fade_lasttick = game_GetTicks(); |
| 516 |
//truecolor_fade_brightness += 256*.3; |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
int delta = game_GetTicks() - truecolor_fade_lasttick; |
| 521 |
/* Complete fade in 400ms */ |
| 522 |
truecolor_fade_lasttick = game_GetTicks(); |
| 523 |
g_display->brightness += delta * 256 / 400.0; |
| 524 |
} |
| 525 |
if (g_display->brightness >= 256) |
| 526 |
{ |
| 527 |
g_display->brightness = 256; |
| 528 |
donethistime = 1; |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
if (process_upcycle) |
| 533 |
if (donethistime == 1) |
| 534 |
{ |
| 535 |
process_upcycle = 0; |
| 536 |
truecolor_fade_lasttick = 0; |
| 537 |
|
| 538 |
if (cycle_script != 0) |
| 539 |
{ |
| 540 |
int junk = cycle_script; |
| 541 |
cycle_script = 0; |
| 542 |
run_script(junk); |
| 543 |
} |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
int hurt_thing(int h, int damage, int special) |
| 549 |
{ |
| 550 |
//lets hurt this sprite but good |
| 551 |
if (damage < 1) return(0); |
| 552 |
int num = damage - spr[h].defense; |
| 553 |
|
| 554 |
// Msg("num is %d.. defense was %d.of sprite %d", num, spr[h].defense, h); |
| 555 |
if (num < 1) num = 0; |
| 556 |
|
| 557 |
if (num == 0) |
| 558 |
{ |
| 559 |
if ((rand() % 2)+1 == 1) num = 1; |
| 560 |
} |
| 561 |
|
| 562 |
spr[h].damage += num; |
| 563 |
return(num); |
| 564 |
//draw blood here |
| 565 |
} |
| 566 |
|
| 567 |
/** |
| 568 |
* Check which sprites are affected by an attack from 'h', the |
| 569 |
* attacker. |
| 570 |
*/ |
| 571 |
void run_through_tag_list(int h, int strength) |
| 572 |
{ |
| 573 |
rect box; |
| 574 |
int amount, amounty; |
| 575 |
int i; |
| 576 |
|
| 577 |
for (i = 1; i <= last_sprite_created; i++) |
| 578 |
{ |
| 579 |
if (spr[i].active) if (i != h) if |
| 580 |
(! ( (spr[i].nohit == 1) && (spr[i].script == 0)) ) |
| 581 |
{ |
| 582 |
|
| 583 |
rect_copy(&box, &k[getpic(i)].hardbox); |
| 584 |
rect_offset(&box, spr[i].x, spr[i].y); |
| 585 |
|
| 586 |
//InflateRect(&box, 10,10); |
| 587 |
|
| 588 |
box.right += 5; |
| 589 |
box.left -= 5; |
| 590 |
box.top -= 5; |
| 591 |
box.bottom += 10; |
| 592 |
if (spr[h].range == 0) |
| 593 |
amount = 28; else amount = spr[h].range; |
| 594 |
|
| 595 |
if (spr[h].range == 0) |
| 596 |
|
| 597 |
amounty = 36; else amounty = (spr[h].range + (spr[h].range / 6)); |
| 598 |
|
| 599 |
int range_amount = spr[h].range / 8; |
| 600 |
|
| 601 |
if (spr[h].dir == 6) |
| 602 |
{ |
| 603 |
box.top -= 10; |
| 604 |
box.bottom += 10; |
| 605 |
if (spr[h].range != 0) box.top -= range_amount; |
| 606 |
if (spr[h].range != 0) box.bottom += range_amount; |
| 607 |
|
| 608 |
|
| 609 |
box.left -= amount; |
| 610 |
} |
| 611 |
|
| 612 |
if (spr[h].dir == 4) |
| 613 |
{ |
| 614 |
box.right += amount; |
| 615 |
|
| 616 |
box.top -= 10; |
| 617 |
box.bottom += 10; |
| 618 |
if (spr[h].range != 0) box.top -= range_amount; |
| 619 |
if (spr[h].range != 0) box.bottom += range_amount; |
| 620 |
|
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
if (spr[h].dir == 2) |
| 625 |
{ |
| 626 |
box.right += 10; |
| 627 |
box.left -= 10; |
| 628 |
box.top -= amounty; |
| 629 |
|
| 630 |
if (spr[h].range != 0) box.right += range_amount; |
| 631 |
if (spr[h].range != 0) box.left -= range_amount; |
| 632 |
|
| 633 |
} |
| 634 |
|
| 635 |
if (spr[h].dir == 8) |
| 636 |
{ |
| 637 |
box.right += 10; |
| 638 |
box.left -= 10; |
| 639 |
box.bottom += amounty; |
| 640 |
|
| 641 |
if (spr[h].range != 0) box.right += range_amount; |
| 642 |
if (spr[h].range != 0) box.right -= range_amount; |
| 643 |
|
| 644 |
} |
| 645 |
|
| 646 |
if (debug_mode) { |
| 647 |
SDL_Rect r = {box.left, box.top, box.right-box.left, box.bottom-box.top}; |
| 648 |
IOGFX_backbuffer->fillRect(&r, 222, 173, 255); |
| 649 |
} |
| 650 |
|
| 651 |
if (inside_box(spr[h].x, spr[h].y, box)) |
| 652 |
{ |
| 653 |
// addition for fixing missle_source problems |
| 654 |
if (dversion >= 108) |
| 655 |
*pmissle_source = h; |
| 656 |
|
| 657 |
if (spr[i].nohit == 1) |
| 658 |
{ |
| 659 |
if (spr[i].script > 0) |
| 660 |
{ |
| 661 |
//if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7)) |
| 662 |
*penemy_sprite = h; |
| 663 |
|
| 664 |
if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0)) |
| 665 |
spr[i].target = h; |
| 666 |
|
| 667 |
if (locate(spr[i].script, "HIT")) |
| 668 |
{ |
| 669 |
kill_returning_stuff(spr[i].script); |
| 670 |
run_script(spr[i].script); |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
} else |
| 678 |
{ |
| 679 |
//hit this personb/thing |
| 680 |
if (spr[h].attack_hit_sound == 0) |
| 681 |
{ |
| 682 |
SoundPlayEffect( 9,22050, 0 ,0,0); |
| 683 |
} else |
| 684 |
{ |
| 685 |
SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0); |
| 686 |
} |
| 687 |
if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0)) |
| 688 |
spr[i].target = h; |
| 689 |
if (spr[h].strength == 0) |
| 690 |
{ |
| 691 |
|
| 692 |
} else |
| 693 |
{ |
| 694 |
if ( (spr[i].hitpoints > 0) || (i == 1) ) |
| 695 |
{ |
| 696 |
|
| 697 |
spr[i].last_hit = h; |
| 698 |
if ( hurt_thing(i, (spr[h].strength / 2) + ((rand() % ((spr[h].strength+1) / 2))+1), 0) > 0) |
| 699 |
random_blood(spr[i].x, spr[i].y-40, i); |
| 700 |
} |
| 701 |
|
| 702 |
} |
| 703 |
if (spr[i].script > 0) |
| 704 |
{ |
| 705 |
//if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7)) |
| 706 |
spr[i].last_hit = h; |
| 707 |
*penemy_sprite = h; |
| 708 |
if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0)) |
| 709 |
spr[i].target = h; |
| 710 |
|
| 711 |
if (locate(spr[i].script, "HIT")) |
| 712 |
{ |
| 713 |
kill_returning_stuff(spr[i].script); |
| 714 |
run_script(spr[i].script); |
| 715 |
} |
| 716 |
|
| 717 |
} |
| 718 |
|
| 719 |
} |
| 720 |
|
| 721 |
} |
| 722 |
|
| 723 |
} |
| 724 |
|
| 725 |
} |
| 726 |
|
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
void run_through_touch_damage_list(int h) |
| 732 |
{ |
| 733 |
rect box; |
| 734 |
int i; |
| 735 |
|
| 736 |
for (i = 1; i <= last_sprite_created; i++) |
| 737 |
{ |
| 738 |
if (spr[i].active) if (i != h) if |
| 739 |
((spr[i].touch_damage != 0) ) |
| 740 |
{ |
| 741 |
|
| 742 |
if (spr[i].touch_damage != -1) if (spr[h].notouch) return; |
| 743 |
rect_copy(&box, &k[getpic(i)].hardbox); |
| 744 |
rect_offset(&box, spr[i].x, spr[i].y); |
| 745 |
|
| 746 |
//InflateRect(&box, 10,10); |
| 747 |
|
| 748 |
box.right += 2; |
| 749 |
box.left -= 2; |
| 750 |
box.top -= 2; |
| 751 |
box.bottom += 2; |
| 752 |
if (debug_mode) { |
| 753 |
SDL_Rect r = {box.left, box.top, box.right-box.left, box.bottom-box.top}; |
| 754 |
IOGFX_backbuffer->fillRect(&r, 222, 173, 255); |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
if (inside_box(spr[h].x, spr[h].y, box)) |
| 759 |
{ |
| 760 |
|
| 761 |
if ((spr[i].touch_damage == -1) && (spr[i].script != 0)) |
| 762 |
{ |
| 763 |
if (locate(spr[i].script, "TOUCH")) run_script(spr[i].script); |
| 764 |
} else |
| 765 |
{ |
| 766 |
if (spr[i].touch_damage == -1) |
| 767 |
{ |
| 768 |
log_error("Sprites touch damage is set to -1 but there is no script set!"); |
| 769 |
} else |
| 770 |
{ |
| 771 |
//lets hurt the guy |
| 772 |
|
| 773 |
spr[h].notouch = /*true*/1; |
| 774 |
spr[h].notouch_timer = thisTickCount+400; |
| 775 |
spr[h].last_hit = i; |
| 776 |
if (spr[i].script != 0) |
| 777 |
if (locate(spr[i].script, "TOUCH")) run_script(spr[i].script); |
| 778 |
if (hurt_thing(h, spr[i].touch_damage, 0) > 0) |
| 779 |
random_blood(spr[h].x, spr[h].y-40, h); |
| 780 |
|
| 781 |
|
| 782 |
} |
| 783 |
|
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
} |
| 792 |
|
| 793 |
} |
| 794 |
|
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
void process_warp_man(void) |
| 801 |
{ |
| 802 |
int sprite = find_sprite(process_warp); |
| 803 |
|
| 804 |
/* warp sprite doesn't exist (e.g. merged background sprite), or |
| 805 |
warp anim is finished */ |
| 806 |
/* Cf. http://www.dinknetwork.com/forum.cgi?MID=168476 */ |
| 807 |
if (sprite == 0 || spr[sprite].seq == 0) |
| 808 |
{ |
| 809 |
process_count++; |
| 810 |
CyclePalette(); |
| 811 |
/* Wait 5 CyclePalette before blanking the screen and |
| 812 |
warp. Truecolor more: the fade algorithm is a bit different |
| 813 |
and requires a few more cycles to get the same effect; unlike |
| 814 |
v1.08, we don't wait for a full fadedown, which is long and |
| 815 |
can be not very smooth on old computers. */ |
| 816 |
if ((!truecolor && process_count > 5) |
| 817 |
|| (truecolor && g_display->brightness <= 180)) |
| 818 |
{ |
| 819 |
IOGFX_backbuffer->fillRect(NULL, 0,0,0); |
| 820 |
g_display->flipStretch(IOGFX_backbuffer); |
| 821 |
|
| 822 |
process_count = 0; |
| 823 |
int block = process_warp; |
| 824 |
update_screen_time(); |
| 825 |
spr[1].x = cur_ed_screen.sprite[block].warp_x; |
| 826 |
spr[1].y = cur_ed_screen.sprite[block].warp_y; |
| 827 |
*pplayer_map = cur_ed_screen.sprite[block].warp_map; |
| 828 |
|
| 829 |
// update map indicator |
| 830 |
if (g_dmod.map.indoor[cur_ed_screen.sprite[block].warp_map] == 0) |
| 831 |
play.last_map = cur_ed_screen.sprite[block].warp_map; |
| 832 |
|
| 833 |
game_load_screen(g_dmod.map.loc[cur_ed_screen.sprite[block].warp_map]); |
| 834 |
draw_screen_game(); |
| 835 |
|
| 836 |
process_upcycle = 1; |
| 837 |
process_warp = 0; |
| 838 |
} |
| 839 |
} |
| 840 |
else /* warp anim didn't finish yet */ |
| 841 |
{ |
| 842 |
process_count = 0; |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
void process_show_bmp( void ) |
| 847 |
{ |
| 848 |
IOGFX_backbuffer->blit(IOGFX_tmp1, NULL, NULL); |
| 849 |
|
| 850 |
if (showb.showdot) |
| 851 |
{ |
| 852 |
//let's display a nice dot to mark where they are on the map |
| 853 |
int x = play.last_map - 1; |
| 854 |
int mseq = 165; |
| 855 |
|
| 856 |
showb.picframe++; |
| 857 |
if (showb.picframe > seq[mseq].len) showb.picframe = 1; |
| 858 |
int mframe = showb.picframe; |
| 859 |
|
| 860 |
SDL_Rect dst; |
| 861 |
// convert map# to a (x,y) position on a FreeDinkedit minimap |
| 862 |
dst.x = (x % 32) * 20; |
| 863 |
dst.y = (x / 32) * 20; |
| 864 |
IOGFX_backbuffer->blit(GFX_k[seq[mseq].frame[mframe]].k, NULL, &dst); |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
if ((sjoy.button[ACTION_ATTACK]) |
| 869 |
|| (sjoy.button[ACTION_TALK]) |
| 870 |
|| (sjoy.button[ACTION_MAGIC]) |
| 871 |
|| (sjoy.button[ACTION_INVENTORY]) |
| 872 |
|| (sjoy.button[ACTION_MENU]) |
| 873 |
|| (sjoy.button[ACTION_MAP])) |
| 874 |
{ |
| 875 |
showb.active = /*false*/0; |
| 876 |
if (showb.script != 0) |
| 877 |
run_script(showb.script); |
| 878 |
showb.stime = thisTickCount+2000; |
| 879 |
but_timer = thisTickCount + 200; |
| 880 |
|
| 881 |
int sprite = say_text_xy("", 1, 440, 0); |
| 882 |
spr[sprite].noclip = 1; |
| 883 |
|
| 884 |
|
| 885 |
// Return to canonical game palette |
| 886 |
gfx_palette_set_phys(GFX_ref_pal); |
| 887 |
// The main flip_it() will be called, skip it - lpDDSBack is |
| 888 |
// not matching the palette anymore, it needs to be redrawn |
| 889 |
// first. |
| 890 |
abort_this_flip = /*true*/1; |
| 891 |
} |
| 892 |
} |