| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "mainint.h" |
| 20 | |
| 21 | #include "backgrnd.h" |
| 22 | #include "config.h" |
| 23 | #include "editship.h" |
| 24 | #include "episodes.h" |
| 25 | #include "file.h" |
| 26 | #include "font.h" |
| 27 | #include "fonthand.h" |
| 28 | #include "helptext.h" |
| 29 | #include "helptext.h" |
| 30 | #include "joystick.h" |
| 31 | #include "keyboard.h" |
| 32 | #include "lds_play.h" |
| 33 | #include "loudness.h" |
| 34 | #include "menus.h" |
| 35 | #include "mouse.h" |
| 36 | #include "mtrand.h" |
| 37 | #include "network.h" |
| 38 | #include "nortsong.h" |
| 39 | #include "nortvars.h" |
| 40 | #include "opentyr.h" |
| 41 | #include "palette.h" |
| 42 | #include "params.h" |
| 43 | #include "pcxmast.h" |
| 44 | #include "picload.h" |
| 45 | #include "player.h" |
| 46 | #include "shots.h" |
| 47 | #include "sndmast.h" |
| 48 | #include "sprite.h" |
| 49 | #include "varz.h" |
| 50 | #include "vga256d.h" |
| 51 | #include "video.h" |
| 52 | |
| 53 | #include <assert.h> |
| 54 | #include <ctype.h> |
| 55 | #include <string.h> |
| 56 | |
| 57 | bool button[4]; |
| 58 | |
| 59 | #define MAX_PAGE 8 |
| 60 | #define TOPICS 6 |
| 61 | const JE_byte topicStart[TOPICS] = { 0, 1, 2, 3, 7, 255 }; |
| 62 | |
| 63 | JE_shortint constantLastX; |
| 64 | JE_word textErase; |
| 65 | JE_word upgradeCost; |
| 66 | JE_word downgradeCost; |
| 67 | JE_boolean performSave; |
| 68 | JE_boolean jumpSection; |
| 69 | JE_boolean useLastBank; /* See if I want to use the last 16 colors for DisplayText */ |
| 70 | |
| 71 | bool pause_pressed = false, ingamemenu_pressed = false; |
| 72 | |
| 73 | /* Draws a message at the bottom text window on the playing screen */ |
| 74 | void JE_drawTextWindow(const char *text) |
| 75 | { |
| 76 | if (textErase > 0) // erase current text |
| 77 | blit_sprite(VGAScreenSeg, 16, 189, OPTION_SHAPES, 36); // in-game text area |
| 78 | |
| 79 | textErase = 100; |
| 80 | JE_outText(VGAScreenSeg, 20, 190, text, 0, 4); |
| 81 | } |
| 82 | |
| 83 | void JE_outCharGlow(JE_word x, JE_word y, const char *s) |
| 84 | { |
| 85 | JE_integer maxloc, loc, z; |
| 86 | JE_shortint glowcol[60]; /* [1..60] */ |
| 87 | JE_shortint glowcolc[60]; /* [1..60] */ |
| 88 | JE_word textloc[60]; /* [1..60] */ |
| 89 | JE_byte bank; |
| 90 | |
| 91 | setDelay2(1); |
| 92 | |
| 93 | bank = (warningRed) ? 7 : ((useLastBank) ? 15 : 14); |
| 94 | |
| 95 | if (s[0] == '\0') |
| 96 | return; |
| 97 | |
| 98 | if (frameCountMax == 0) |
| 99 | { |
| 100 | JE_textShade(VGAScreen, x, y, s, bank, 0, PART_SHADE); |
| 101 | JE_showVGA(); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | maxloc = strlen(s); |
| 106 | for (z = 0; z < 60; z++) |
| 107 | { |
| 108 | glowcol[z] = -8; |
| 109 | glowcolc[z] = 1; |
| 110 | } |
| 111 | |
| 112 | loc = x; |
| 113 | for (z = 0; z < maxloc; z++) |
| 114 | { |
| 115 | textloc[z] = loc; |
| 116 | |
| 117 | int sprite_id = font_ascii[(unsigned char)s[z]]; |
| 118 | |
| 119 | if (s[z] == ' ') |
| 120 | loc += 6; |
| 121 | else if (sprite_id != -1) |
| 122 | loc += sprite(TINY_FONT, sprite_id)->width + 1; |
| 123 | } |
| 124 | |
| 125 | for (loc = 0; (unsigned)loc < strlen(s) + 28; loc++) |
| 126 | { |
| 127 | if (!ESCPressed) |
| 128 | { |
| 129 | setDelay(frameCountMax); |
| 130 | |
| 131 | NETWORK_KEEP_ALIVE(); |
| 132 | |
| 133 | int sprite_id = -1; |
| 134 | |
| 135 | for (z = loc - 28; z <= loc; z++) |
| 136 | { |
| 137 | if (z >= 0 && z < maxloc) |
| 138 | { |
| 139 | sprite_id = font_ascii[(unsigned char)s[z]]; |
| 140 | |
| 141 | if (sprite_id != -1) |
| 142 | { |
| 143 | blit_sprite_hv(VGAScreen, textloc[z], y, TINY_FONT, sprite_id, bank, glowcol[z]); |
| 144 | |
| 145 | glowcol[z] += glowcolc[z]; |
| 146 | if (glowcol[z] > 9) |
| 147 | glowcolc[z] = -1; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | if (sprite_id != -1 && --z < maxloc) |
| 152 | blit_sprite_dark(VGAScreen, textloc[z] + 1, y + 1, TINY_FONT, sprite_id, true); |
| 153 | |
| 154 | if (JE_anyButton()) |
| 155 | frameCountMax = 0; |
| 156 | |
| 157 | do |
| 158 | { |
| 159 | if (levelWarningDisplay) |
| 160 | JE_updateWarning(VGAScreen); |
| 161 | |
| 162 | SDL_Delay(16); |
| 163 | } while (!(getDelayTicks() == 0 || ESCPressed)); |
| 164 | |
| 165 | JE_showVGA(); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void JE_drawPortConfigButtons(void) // rear weapon pattern indicator |
| 172 | { |
| 173 | if (twoPlayerMode) |
| 174 | return; |
| 175 | |
| 176 | if (player[0].weapon_mode == 1) |
| 177 | { |
| 178 | blit_sprite(VGAScreenSeg, 285, 44, OPTION_SHAPES, 18); // lit |
| 179 | blit_sprite(VGAScreenSeg, 302, 44, OPTION_SHAPES, 19); // unlit |
| 180 | } |
| 181 | else // == 2 |
| 182 | { |
| 183 | blit_sprite(VGAScreenSeg, 285, 44, OPTION_SHAPES, 19); // unlit |
| 184 | blit_sprite(VGAScreenSeg, 302, 44, OPTION_SHAPES, 18); // lit |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | static bool helpSystemPage(Uint8 *topic, bool *restart); |
| 189 | |
| 190 | void JE_helpSystem(JE_byte startTopic) |
| 191 | { |
| 192 | if (shopSpriteSheet.data == NULL) |
| 193 | JE_loadCompShapes(&shopSpriteSheet, '1'); // need mouse pointer sprites |
| 194 | |
| 195 | Uint8 topic = startTopic; |
| 196 | |
| 197 | bool restart = true; |
| 198 | |
| 199 | const size_t menuItemsCount = COUNTOF(topicName) - 1; |
| 200 | size_t selectedIndex = 0; |
| 201 | |
| 202 | const int xCenter = 320 / 2; |
| 203 | const int yMenuHeader = 30; |
| 204 | const int yMenuItems = 60; |
| 205 | const int dyMenuItems = 20; |
| 206 | const int hMenuItem = 13; |
| 207 | int wMenuItem[COUNTOF(topicName) - 1] = { 0 }; |
| 208 | |
| 209 | for (; ; ) |
| 210 | { |
| 211 | if (restart) |
| 212 | { |
| 213 | play_song(SONG_MAPVIEW); |
| 214 | |
| 215 | JE_loadPic(VGAScreen2, 2, false); |
| 216 | } |
| 217 | |
| 218 | if (topic > 1) |
| 219 | { |
| 220 | if (!helpSystemPage(&topic, &restart)) |
| 221 | return; |
| 222 | |
| 223 | selectedIndex = (size_t)topic - 1; |
| 224 | topic = 1; |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | // Restore background. |
| 229 | memcpy(VGAScreen->pixels, VGAScreen2->pixels, (size_t)VGAScreen->pitch * VGAScreen->h); |
| 230 | |
| 231 | // Draw header. |
| 232 | draw_font_hv_shadow(VGAScreen, xCenter, yMenuHeader, topicName[0], large_font, centered, 15, -3, false, 2); |
| 233 | |
| 234 | // Draw menu items. |
| 235 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 236 | { |
| 237 | const char *const text = topicName[i + 1]; |
| 238 | |
| 239 | wMenuItem[i] = JE_textWidth(text, normal_font); |
| 240 | const int y = yMenuItems + dyMenuItems * i; |
| 241 | |
| 242 | const bool selected = i == selectedIndex; |
| 243 | |
| 244 | draw_font_hv_shadow(VGAScreen, xCenter, y, text, normal_font, centered, 15, -3 + (selected ? 2 : 0), false, 2); |
| 245 | } |
| 246 | |
| 247 | mouseCursor = MOUSE_POINTER_NORMAL; |
| 248 | |
| 249 | if (restart) |
| 250 | { |
| 251 | fade_palette(colors, 10, 0, 255); |
| 252 | |
| 253 | restart = false; |
| 254 | } |
| 255 | |
| 256 | service_SDL_events(true); |
| 257 | |
| 258 | JE_mouseStart(); |
| 259 | JE_showVGA(); |
| 260 | JE_mouseReplace(); |
| 261 | |
| 262 | bool mouseMoved = false; |
| 263 | do |
| 264 | { |
| 265 | SDL_Delay(16); |
| 266 | |
| 267 | Uint16 oldMouseX = mouse_x; |
| 268 | Uint16 oldMouseY = mouse_y; |
| 269 | |
| 270 | push_joysticks_as_keyboard(); |
| 271 | service_SDL_events(false); |
| 272 | |
| 273 | mouseMoved = mouse_x != oldMouseX || mouse_y != oldMouseY; |
| 274 | } while (!(newkey || newmouse || mouseMoved)); |
| 275 | |
| 276 | // Handle interaction. |
| 277 | |
| 278 | bool action = false; |
| 279 | bool done = false; |
| 280 | |
| 281 | if (mouseMoved || newmouse) |
| 282 | { |
| 283 | // Find menu item that was hovered or clicked. |
| 284 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 285 | { |
| 286 | const int xMenuItem = xCenter - wMenuItem[i] / 2; |
| 287 | if (mouse_x >= xMenuItem && mouse_x < xMenuItem + wMenuItem[i]) |
| 288 | { |
| 289 | const int yMenuItem = yMenuItems + dyMenuItems * i; |
| 290 | if (mouse_y >= yMenuItem && mouse_y < yMenuItem + hMenuItem) |
| 291 | { |
| 292 | if (selectedIndex != i) |
| 293 | { |
| 294 | JE_playSampleNum(S_CURSOR); |
| 295 | |
| 296 | selectedIndex = i; |
| 297 | } |
| 298 | |
| 299 | if (newmouse && lastmouse_but == SDL_BUTTON_LEFT && |
| 300 | lastmouse_x >= xMenuItem && lastmouse_x < xMenuItem + wMenuItem[i] && |
| 301 | lastmouse_y >= yMenuItem && lastmouse_y < yMenuItem + hMenuItem) |
| 302 | { |
| 303 | action = true; |
| 304 | } |
| 305 | |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (newmouse) |
| 313 | { |
| 314 | if (lastmouse_but == SDL_BUTTON_RIGHT) |
| 315 | { |
| 316 | JE_playSampleNum(S_SPRING); |
| 317 | |
| 318 | done = true; |
| 319 | } |
| 320 | } |
| 321 | else if (newkey) |
| 322 | { |
| 323 | switch (lastkey_scan) |
| 324 | { |
| 325 | case SDL_SCANCODE_UP: |
| 326 | { |
| 327 | JE_playSampleNum(S_CURSOR); |
| 328 | |
| 329 | selectedIndex = selectedIndex == 0 |
| 330 | ? menuItemsCount - 1 |
| 331 | : selectedIndex - 1; |
| 332 | break; |
| 333 | } |
| 334 | case SDL_SCANCODE_DOWN: |
| 335 | { |
| 336 | JE_playSampleNum(S_CURSOR); |
| 337 | |
| 338 | selectedIndex = selectedIndex == menuItemsCount - 1 |
| 339 | ? 0 |
| 340 | : selectedIndex + 1; |
| 341 | break; |
| 342 | } |
| 343 | case SDL_SCANCODE_SPACE: |
| 344 | case SDL_SCANCODE_RETURN: |
| 345 | { |
| 346 | action = true; |
| 347 | break; |
| 348 | } |
| 349 | case SDL_SCANCODE_ESCAPE: |
| 350 | { |
| 351 | JE_playSampleNum(S_SPRING); |
| 352 | |
| 353 | done = true; |
| 354 | break; |
| 355 | } |
| 356 | default: |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if (action) |
| 362 | { |
| 363 | JE_playSampleNum(S_SELECT); |
| 364 | |
| 365 | topic = selectedIndex + 2; |
| 366 | |
| 367 | if (selectedIndex == menuItemsCount - 1) |
| 368 | done = true; |
| 369 | } |
| 370 | |
| 371 | if (done) |
| 372 | { |
| 373 | fade_black(15); |
| 374 | |
| 375 | return; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static bool helpSystemPage(Uint8 *topic, bool *restart) |
| 381 | { |
| 382 | Uint8 page = topicStart[*topic - 1]; |
| 383 | |
| 384 | const int xCenter = 320 / 2; |
| 385 | |
| 386 | for (; ; ) |
| 387 | { |
| 388 | if (page == 0) |
| 389 | { |
| 390 | *topic = 1; |
| 391 | return true; |
| 392 | } |
| 393 | else if (page > MAX_PAGE) |
| 394 | { |
| 395 | *topic = COUNTOF(topicName) - 1; |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | for (Uint8 temp = 0; temp < COUNTOF(topicName); ++temp) |
| 400 | { |
| 401 | if (topicStart[temp] <= page) |
| 402 | *topic = temp + 1; |
| 403 | else |
| 404 | break; |
| 405 | } |
| 406 | |
| 407 | // Restore background. |
| 408 | memcpy(VGAScreen->pixels, VGAScreen2->pixels, (size_t)VGAScreen->pitch * VGAScreen->h); |
| 409 | |
| 410 | fill_rectangle_wh(VGAScreen, 0, 192, 320, 8, 0); |
| 411 | |
| 412 | const char *const text = topicName[*topic - 1]; |
| 413 | |
| 414 | // Draw header. |
| 415 | draw_font_hv_shadow(VGAScreen, xCenter, 1, text, normal_font, centered, 15, -3, false, 2); |
| 416 | |
| 417 | // Draw footer. |
| 418 | JE_char buffer[128]; |
| 419 | |
| 420 | snprintf(buffer, sizeof buffer, "%s %d", miscText[24], page - topicStart[*topic - 1] + 1); |
| 421 | draw_font_hv(VGAScreen, 10, 192, buffer, small_font, left_aligned, 13, 5); |
| 422 | |
| 423 | snprintf(buffer, sizeof buffer, "%s %d of %d", miscText[25], page, MAX_PAGE); |
| 424 | draw_font_hv(VGAScreen, 320 - 10, 192, buffer, small_font, right_aligned, 13, 5); |
| 425 | |
| 426 | // Draw text. |
| 427 | |
| 428 | helpBoxBrightness = 3; |
| 429 | verticalHeight = 8; |
| 430 | |
| 431 | switch (page) |
| 432 | { |
| 433 | case 1: /* One-Player Menu */ |
| 434 | JE_HBox(VGAScreen, 10, 20, 2, 60); |
| 435 | JE_HBox(VGAScreen, 10, 50, 5, 60); |
| 436 | JE_HBox(VGAScreen, 10, 80, 21, 60); |
| 437 | JE_HBox(VGAScreen, 10, 110, 1, 60); |
| 438 | JE_HBox(VGAScreen, 10, 140, 28, 60); |
| 439 | break; |
| 440 | case 2: /* Two-Player Menu */ |
| 441 | JE_HBox(VGAScreen, 10, 20, 1, 60); |
| 442 | JE_HBox(VGAScreen, 10, 60, 2, 60); |
| 443 | JE_HBox(VGAScreen, 10, 100, 21, 60); |
| 444 | JE_HBox(VGAScreen, 10, 140, 28, 60); |
| 445 | break; |
| 446 | case 3: /* Upgrade Ship */ |
| 447 | JE_HBox(VGAScreen, 10, 20, 5, 60); |
| 448 | JE_HBox(VGAScreen, 10, 70, 6, 60); |
| 449 | JE_HBox(VGAScreen, 10, 110, 7, 60); |
| 450 | break; |
| 451 | case 4: |
| 452 | JE_HBox(VGAScreen, 10, 20, 8, 60); |
| 453 | JE_HBox(VGAScreen, 10, 55, 9, 60); |
| 454 | JE_HBox(VGAScreen, 10, 87, 10, 60); |
| 455 | JE_HBox(VGAScreen, 10, 120, 11, 60); |
| 456 | JE_HBox(VGAScreen, 10, 170, 13, 60); |
| 457 | break; |
| 458 | case 5: |
| 459 | JE_HBox(VGAScreen, 10, 20, 14, 60); |
| 460 | JE_HBox(VGAScreen, 10, 80, 15, 60); |
| 461 | JE_HBox(VGAScreen, 10, 120, 16, 60); |
| 462 | break; |
| 463 | case 6: |
| 464 | JE_HBox(VGAScreen, 10, 20, 17, 60); |
| 465 | JE_HBox(VGAScreen, 10, 40, 18, 60); |
| 466 | JE_HBox(VGAScreen, 10, 130, 20, 60); |
| 467 | break; |
| 468 | case 7: /* Options */ |
| 469 | JE_HBox(VGAScreen, 10, 20, 21, 60); |
| 470 | JE_HBox(VGAScreen, 10, 70, 22, 60); |
| 471 | JE_HBox(VGAScreen, 10, 110, 23, 60); |
| 472 | JE_HBox(VGAScreen, 10, 140, 24, 60); |
| 473 | break; |
| 474 | case 8: |
| 475 | JE_HBox(VGAScreen, 10, 20, 25, 60); |
| 476 | JE_HBox(VGAScreen, 10, 60, 26, 60); |
| 477 | JE_HBox(VGAScreen, 10, 100, 27, 60); |
| 478 | JE_HBox(VGAScreen, 10, 140, 28, 60); |
| 479 | JE_HBox(VGAScreen, 10, 170, 29, 60); |
| 480 | break; |
| 481 | } |
| 482 | |
| 483 | helpBoxBrightness = 1; |
| 484 | verticalHeight = 7; |
| 485 | |
| 486 | if (*restart) |
| 487 | { |
| 488 | fade_palette(colors, 10, 0, 255); |
| 489 | |
| 490 | *restart = false; |
| 491 | } |
| 492 | |
| 493 | do |
| 494 | { |
| 495 | mouseCursor = mouse_x < xCenter ? MOUSE_POINTER_LEFT : MOUSE_POINTER_RIGHT; |
| 496 | |
| 497 | service_SDL_events(true); |
| 498 | |
| 499 | JE_mouseStart(); |
| 500 | JE_showVGA(); |
| 501 | JE_mouseReplace(); |
| 502 | |
| 503 | SDL_Delay(16); |
| 504 | |
| 505 | push_joysticks_as_keyboard(); |
| 506 | service_SDL_events(false); |
| 507 | } while (!(newkey || newmouse)); |
| 508 | |
| 509 | // Handle interaction. |
| 510 | |
| 511 | bool done = false; |
| 512 | |
| 513 | if (newmouse) |
| 514 | { |
| 515 | switch (lastmouse_but) |
| 516 | { |
| 517 | case SDL_BUTTON_LEFT: |
| 518 | { |
| 519 | JE_playSampleNum(S_CURSOR); |
| 520 | |
| 521 | if (mouse_x < xCenter) |
| 522 | page -= 1; |
| 523 | else |
| 524 | page += 1; |
| 525 | break; |
| 526 | } |
| 527 | case SDL_BUTTON_RIGHT: |
| 528 | { |
| 529 | JE_playSampleNum(S_SPRING); |
| 530 | |
| 531 | done = true; |
| 532 | break; |
| 533 | } |
| 534 | default: |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | else if (newkey) |
| 539 | { |
| 540 | switch (lastkey_scan) |
| 541 | { |
| 542 | case SDL_SCANCODE_LEFT: |
| 543 | { |
| 544 | JE_playSampleNum(S_CURSOR); |
| 545 | |
| 546 | page -= 1; |
| 547 | break; |
| 548 | } |
| 549 | case SDL_SCANCODE_RIGHT: |
| 550 | case SDL_SCANCODE_SPACE: |
| 551 | case SDL_SCANCODE_RETURN: |
| 552 | { |
| 553 | JE_playSampleNum(S_CURSOR); |
| 554 | |
| 555 | page += 1; |
| 556 | break; |
| 557 | } |
| 558 | case SDL_SCANCODE_ESCAPE: |
| 559 | { |
| 560 | JE_playSampleNum(S_SPRING); |
| 561 | |
| 562 | done = true; |
| 563 | break; |
| 564 | } |
| 565 | default: |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (done) |
| 571 | { |
| 572 | fade_black(15); |
| 573 | |
| 574 | return false; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // cost to upgrade a weapon power from power-1 (where power == 0 indicates an unupgraded weapon) |
| 580 | long weapon_upgrade_cost(long base_cost, unsigned int power) |
| 581 | { |
| 582 | assert(power <= 11); |
| 583 | |
| 584 | unsigned int temp = 0; |
| 585 | |
| 586 | // 0 1 3 6 10 15 21 29 ... |
| 587 | for (; power > 0; power--) |
| 588 | temp += power; |
| 589 | |
| 590 | return base_cost * temp; |
| 591 | } |
| 592 | |
| 593 | ulong JE_getCost(JE_byte itemType, JE_word itemNum) |
| 594 | { |
| 595 | long cost = 0; |
| 596 | |
| 597 | switch (itemType) |
| 598 | { |
| 599 | case 2: |
| 600 | cost = (itemNum > 90) ? 100 : ships[itemNum].cost; |
| 601 | break; |
| 602 | case 3: |
| 603 | case 4: |
| 604 | cost = weaponPort[itemNum].cost; |
| 605 | |
| 606 | const uint port = itemType - 3, |
| 607 | item_power = player[0].items.weapon[port].power - 1; |
| 608 | |
| 609 | downgradeCost = weapon_upgrade_cost(cost, item_power); |
| 610 | upgradeCost = weapon_upgrade_cost(cost, item_power + 1); |
| 611 | break; |
| 612 | case 5: |
| 613 | cost = shields[itemNum].cost; |
| 614 | break; |
| 615 | case 6: |
| 616 | cost = powerSys[itemNum].cost; |
| 617 | break; |
| 618 | case 7: |
| 619 | case 8: |
| 620 | cost = options[itemNum].cost; |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | return cost; |
| 625 | } |
| 626 | |
| 627 | bool JE_loadScreen(void) |
| 628 | { |
| 629 | if (shopSpriteSheet.data == NULL) |
| 630 | JE_loadCompShapes(&shopSpriteSheet, '1'); // need mouse pointer and arrow sprites |
| 631 | |
| 632 | bool restart = true; |
| 633 | |
| 634 | size_t playersIndex = 0; |
| 635 | const size_t menuItemsCount = 12; |
| 636 | size_t selectedIndex = 0; |
| 637 | |
| 638 | const int xCenter = 320 / 2; |
| 639 | const int yMenuHeader = 5; |
| 640 | const int xMenuItem = 10; |
| 641 | const int xMenuItemName = xMenuItem; |
| 642 | const int xMenuItemLastLevel = 120; |
| 643 | const int xMenuItemEpisode = 250; |
| 644 | const int wMenuItem = 300; |
| 645 | const int yMenuItems = 30; |
| 646 | const int dyMenuItems = 13; |
| 647 | const int hMenuItem = 8; |
| 648 | const int xLeftControl = 83; |
| 649 | const int xRightControl = 213; |
| 650 | const int wControl = 24; |
| 651 | const int yControls = 179; |
| 652 | |
| 653 | for (; ; ) |
| 654 | { |
| 655 | if (restart) |
| 656 | { |
| 657 | JE_loadPic(VGAScreen2, 2, false); |
| 658 | fill_rectangle_wh(VGAScreen2, 0, 192, 320, 8, 0); |
| 659 | } |
| 660 | |
| 661 | // Restore background. |
| 662 | memcpy(VGAScreen->pixels, VGAScreen2->pixels, (size_t)VGAScreen->pitch * VGAScreen->h); |
| 663 | |
| 664 | // Draw header. |
| 665 | draw_font_hv_shadow(VGAScreen, xCenter, yMenuHeader, miscText[38 + playersIndex], large_font, centered, 15, -3, false, 2); |
| 666 | |
| 667 | // Draw menu items. |
| 668 | |
| 669 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 670 | { |
| 671 | const int y = yMenuItems + dyMenuItems * i; |
| 672 | |
| 673 | const bool selected = i == selectedIndex; |
| 674 | |
| 675 | if (i == menuItemsCount - 1) |
| 676 | { |
| 677 | JE_textShade(VGAScreen, xMenuItemName, y, miscText[33], 13, selected ? 6 : 2, FULL_SHADE); |
| 678 | continue; |
| 679 | } |
| 680 | |
| 681 | const JE_SaveFileType *const saveFile = &saveFiles[playersIndex * 11 + i]; |
| 682 | |
| 683 | const bool disabled = saveFile->level == 0; |
| 684 | |
| 685 | char buffer[22]; |
| 686 | |
| 687 | if (disabled) |
| 688 | { |
| 689 | JE_textShade(VGAScreen, xMenuItemName, y, miscText[2], 13, selected ? 6 : 0, FULL_SHADE); |
| 690 | |
| 691 | snprintf(buffer, sizeof buffer, "%s -----", miscTextB[2]); |
| 692 | JE_textShade(VGAScreen, xMenuItemLastLevel, y, buffer, 5, selected ? 6 : 0, FULL_SHADE); |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | JE_textShade(VGAScreen, xMenuItemName, y, saveFile->name, 13, selected ? 6 : 2, FULL_SHADE); |
| 697 | |
| 698 | snprintf(buffer, sizeof buffer, "%s %s", miscTextB[2], saveFile->levelName); |
| 699 | JE_textShade(VGAScreen, xMenuItemLastLevel, y, buffer, 5, selected ? 6 : 2, FULL_SHADE); |
| 700 | |
| 701 | snprintf(buffer, sizeof buffer, "%s %u", miscTextB[1], saveFile->episode); |
| 702 | JE_textShade(VGAScreen, xMenuItemEpisode, y, buffer, 5, selected ? 6 : 2, FULL_SHADE); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | // Draw paging controls. |
| 707 | |
| 708 | const bool leftControlVisible = playersIndex > 0; |
| 709 | const bool rightControlVisible = playersIndex < 1; |
| 710 | |
| 711 | if (leftControlVisible) |
| 712 | blit_sprite2x2(VGAScreen, xLeftControl, yControls, shopSpriteSheet, 279); |
| 713 | |
| 714 | if (rightControlVisible) |
| 715 | blit_sprite2x2(VGAScreen, xRightControl, yControls, shopSpriteSheet, 281); |
| 716 | |
| 717 | helpBoxColor = 15; |
| 718 | JE_helpBox(VGAScreen, 103, 182, miscText[55], 25); |
| 719 | |
| 720 | if (restart) |
| 721 | { |
| 722 | mouseCursor = MOUSE_POINTER_NORMAL; |
| 723 | |
| 724 | fade_palette(colors, 10, 0, 255); |
| 725 | |
| 726 | restart = false; |
| 727 | } |
| 728 | |
| 729 | service_SDL_events(true); |
| 730 | |
| 731 | JE_mouseStart(); |
| 732 | JE_showVGA(); |
| 733 | JE_mouseReplace(); |
| 734 | |
| 735 | bool mouseMoved = false; |
| 736 | do |
| 737 | { |
| 738 | SDL_Delay(16); |
| 739 | |
| 740 | Uint16 oldMouseX = mouse_x; |
| 741 | Uint16 oldMouseY = mouse_y; |
| 742 | |
| 743 | push_joysticks_as_keyboard(); |
| 744 | service_SDL_events(false); |
| 745 | |
| 746 | mouseMoved = mouse_x != oldMouseX || mouse_y != oldMouseY; |
| 747 | } while (!(newkey || newmouse || mouseMoved)); |
| 748 | |
| 749 | // Handle interaction. |
| 750 | |
| 751 | bool leftAction = false; |
| 752 | bool rightAction = false; |
| 753 | bool action = false; |
| 754 | bool done = false; |
| 755 | |
| 756 | if (mouseMoved || newmouse) |
| 757 | { |
| 758 | if (leftControlVisible && |
| 759 | mouse_y >= yControls && |
| 760 | mouse_x >= xLeftControl && |
| 761 | mouse_x < xLeftControl + wControl) |
| 762 | { |
| 763 | if (newmouse && lastmouse_but == SDL_BUTTON_LEFT) |
| 764 | { |
| 765 | JE_playSampleNum(S_CURSOR); |
| 766 | |
| 767 | leftAction = true; |
| 768 | } |
| 769 | } |
| 770 | else if (rightControlVisible && |
| 771 | mouse_y >= yControls && |
| 772 | mouse_x >= xRightControl && |
| 773 | mouse_x < xRightControl + wControl) |
| 774 | { |
| 775 | if (newmouse && lastmouse_but == SDL_BUTTON_LEFT) |
| 776 | { |
| 777 | JE_playSampleNum(S_CURSOR); |
| 778 | |
| 779 | rightAction = true; |
| 780 | } |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | // Find menu item that was hovered or clicked. |
| 785 | if (mouse_x >= xMenuItem && mouse_x < xMenuItem + wMenuItem) |
| 786 | { |
| 787 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 788 | { |
| 789 | const int yMenuItem = yMenuItems + dyMenuItems * i; |
| 790 | if (mouse_y >= yMenuItem && mouse_y < yMenuItem + hMenuItem) |
| 791 | { |
| 792 | if (selectedIndex != i) |
| 793 | { |
| 794 | JE_playSampleNum(S_CURSOR); |
| 795 | |
| 796 | selectedIndex = i; |
| 797 | } |
| 798 | |
| 799 | if (newmouse && lastmouse_but == SDL_BUTTON_LEFT && |
| 800 | lastmouse_x >= xMenuItem && lastmouse_x < xMenuItem + wMenuItem && |
| 801 | lastmouse_y >= yMenuItem && lastmouse_y < yMenuItem + hMenuItem) |
| 802 | { |
| 803 | action = true; |
| 804 | } |
| 805 | |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | if (newmouse) |
| 814 | { |
| 815 | if (lastmouse_but == SDL_BUTTON_RIGHT) |
| 816 | { |
| 817 | JE_playSampleNum(S_SPRING); |
| 818 | |
| 819 | done = true; |
| 820 | } |
| 821 | } |
| 822 | else if (newkey) |
| 823 | { |
| 824 | switch (lastkey_scan) |
| 825 | { |
| 826 | case SDL_SCANCODE_LEFT: |
| 827 | { |
| 828 | JE_playSampleNum(S_CURSOR); |
| 829 | |
| 830 | leftAction = true; |
| 831 | break; |
| 832 | } |
| 833 | case SDL_SCANCODE_RIGHT: |
| 834 | { |
| 835 | JE_playSampleNum(S_CURSOR); |
| 836 | |
| 837 | rightAction = true; |
| 838 | break; |
| 839 | } |
| 840 | case SDL_SCANCODE_UP: |
| 841 | { |
| 842 | JE_playSampleNum(S_CURSOR); |
| 843 | |
| 844 | selectedIndex = selectedIndex == 0 |
| 845 | ? menuItemsCount - 1 |
| 846 | : selectedIndex - 1; |
| 847 | break; |
| 848 | } |
| 849 | case SDL_SCANCODE_DOWN: |
| 850 | { |
| 851 | JE_playSampleNum(S_CURSOR); |
| 852 | |
| 853 | selectedIndex = selectedIndex == menuItemsCount - 1 |
| 854 | ? 0 |
| 855 | : selectedIndex + 1; |
| 856 | break; |
| 857 | } |
| 858 | case SDL_SCANCODE_SPACE: |
| 859 | case SDL_SCANCODE_RETURN: |
| 860 | { |
| 861 | action = true; |
| 862 | break; |
| 863 | } |
| 864 | case SDL_SCANCODE_ESCAPE: |
| 865 | { |
| 866 | JE_playSampleNum(S_SPRING); |
| 867 | |
| 868 | done = true; |
| 869 | break; |
| 870 | } |
| 871 | default: |
| 872 | break; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | if (leftAction) |
| 877 | { |
| 878 | playersIndex = playersIndex == 0 ? 1 : 0; |
| 879 | } |
| 880 | else if (rightAction) |
| 881 | { |
| 882 | playersIndex = playersIndex == 1 ? 0 : 1; |
| 883 | } |
| 884 | else if (action) |
| 885 | { |
| 886 | if (selectedIndex == menuItemsCount - 1) // "Exit to Main Menu" |
| 887 | { |
| 888 | JE_playSampleNum(S_SELECT); |
| 889 | |
| 890 | done = true; |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | const size_t saveFileIndex = playersIndex * 11 + selectedIndex; |
| 895 | |
| 896 | if (saveFiles[saveFileIndex].level == 0) // "EMPTY SLOT" |
| 897 | { |
| 898 | JE_playSampleNum(S_CLINK); |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | JE_playSampleNum(S_SELECT); |
| 903 | |
| 904 | performSave = false; |
| 905 | JE_operation(saveFileIndex + 1); |
| 906 | |
| 907 | fade_black(15); |
| 908 | |
| 909 | return gameLoaded; |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | if (done) |
| 915 | { |
| 916 | fade_black(15); |
| 917 | |
| 918 | return false; |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | ulong JE_totalScore(const Player *this_player) |
| 924 | { |
| 925 | ulong temp = this_player->cash; |
| 926 | |
| 927 | temp += JE_getValue(2, this_player->items.ship); |
| 928 | temp += JE_getValue(3, this_player->items.weapon[FRONT_WEAPON].id); |
| 929 | temp += JE_getValue(4, this_player->items.weapon[REAR_WEAPON].id); |
| 930 | temp += JE_getValue(5, this_player->items.shield); |
| 931 | temp += JE_getValue(6, this_player->items.generator); |
| 932 | temp += JE_getValue(7, this_player->items.sidekick[LEFT_SIDEKICK]); |
| 933 | temp += JE_getValue(8, this_player->items.sidekick[RIGHT_SIDEKICK]); |
| 934 | |
| 935 | return temp; |
| 936 | } |
| 937 | |
| 938 | JE_longint JE_getValue(JE_byte itemType, JE_word itemNum) |
| 939 | { |
| 940 | long value = 0; |
| 941 | |
| 942 | switch (itemType) |
| 943 | { |
| 944 | case 2: |
| 945 | value = ships[itemNum].cost; |
| 946 | break; |
| 947 | case 3: |
| 948 | case 4:; |
| 949 | const long base_value = weaponPort[itemNum].cost; |
| 950 | |
| 951 | // if two-player, use first player's front and second player's rear weapon |
| 952 | const uint port = itemType - 3; |
| 953 | const uint item_power = player[twoPlayerMode ? port : 0].items.weapon[port].power - 1; |
| 954 | |
| 955 | value = base_value; |
| 956 | for (unsigned int i = 1; i <= item_power; ++i) |
| 957 | value += weapon_upgrade_cost(base_value, i); |
| 958 | break; |
| 959 | case 5: |
| 960 | value = shields[itemNum].cost; |
| 961 | break; |
| 962 | case 6: |
| 963 | value = powerSys[itemNum].cost; |
| 964 | break; |
| 965 | case 7: |
| 966 | case 8: |
| 967 | value = options[itemNum].cost; |
| 968 | break; |
| 969 | } |
| 970 | |
| 971 | return value; |
| 972 | } |
| 973 | |
| 974 | void JE_nextEpisode(void) |
| 975 | { |
| 976 | strcpy(lastLevelName, "Completed"); |
| 977 | |
| 978 | if (episodeNum == initial_episode_num && !gameHasRepeated && episodeNum != EPISODE_AVAILABLE && |
| 979 | !isNetworkGame && !constantPlay) |
| 980 | { |
| 981 | JE_highScoreCheck(); |
| 982 | } |
| 983 | |
| 984 | unsigned int newEpisode = JE_findNextEpisode(); |
| 985 | |
| 986 | if (jumpBackToEpisode1) |
| 987 | { |
| 988 | if (episodeNum > 2 && |
| 989 | !constantPlay) |
| 990 | { |
| 991 | JE_playCredits(); |
| 992 | } |
| 993 | |
| 994 | // randomly give player the SuperCarrot |
| 995 | if ((mt_rand() % 6) == 0) |
| 996 | { |
| 997 | player[0].items.ship = 2; // SuperCarrot |
| 998 | player[0].items.weapon[FRONT_WEAPON].id = 23; // Banana Blast |
| 999 | player[0].items.weapon[REAR_WEAPON].id = 24; // Banana Blast Rear |
| 1000 | |
| 1001 | for (uint i = 0; i < COUNTOF(player[0].items.weapon); ++i) |
| 1002 | player[0].items.weapon[i].power = 1; |
| 1003 | |
| 1004 | player[1].items.weapon[REAR_WEAPON].id = 24; // Banana Blast Rear |
| 1005 | |
| 1006 | player[0].last_items = player[0].items; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | if (newEpisode != episodeNum) |
| 1011 | JE_initEpisode(newEpisode); |
| 1012 | |
| 1013 | gameLoaded = true; |
| 1014 | mainLevel = FIRST_LEVEL; |
| 1015 | saveLevel = FIRST_LEVEL; |
| 1016 | |
| 1017 | play_song(26); |
| 1018 | |
| 1019 | JE_clr256(VGAScreen); |
| 1020 | memcpy(colors, palettes[6-1], sizeof(colors)); |
| 1021 | |
| 1022 | JE_dString(VGAScreen, JE_fontCenter(episode_name[episodeNum], SMALL_FONT_SHAPES), 130, episode_name[episodeNum], SMALL_FONT_SHAPES); |
| 1023 | JE_dString(VGAScreen, JE_fontCenter(miscText[5-1], SMALL_FONT_SHAPES), 185, miscText[5-1], SMALL_FONT_SHAPES); |
| 1024 | |
| 1025 | JE_showVGA(); |
| 1026 | fade_palette(colors, 15, 0, 255); |
| 1027 | |
| 1028 | JE_wipeKey(); |
| 1029 | if (!constantPlay) |
| 1030 | { |
| 1031 | do |
| 1032 | { |
| 1033 | NETWORK_KEEP_ALIVE(); |
| 1034 | |
| 1035 | SDL_Delay(16); |
| 1036 | } while (!JE_anyButton()); |
| 1037 | } |
| 1038 | |
| 1039 | fade_black(15); |
| 1040 | } |
| 1041 | |
| 1042 | void JE_initPlayerData(void) |
| 1043 | { |
| 1044 | /* JE: New Game Items/Data */ |
| 1045 | |
| 1046 | player[0].items.ship = 1; // USP Talon |
| 1047 | player[0].items.weapon[FRONT_WEAPON].id = 1; // Pulse Cannon |
| 1048 | player[0].items.weapon[REAR_WEAPON].id = 0; // None |
| 1049 | player[0].items.shield = 4; // Gencore High Energy Shield |
| 1050 | player[0].items.generator = 2; // Advanced MR-12 |
| 1051 | for (uint i = 0; i < COUNTOF(player[0].items.sidekick); ++i) |
| 1052 | player[0].items.sidekick[i] = 0; // None |
| 1053 | player[0].items.special = 0; // None |
| 1054 | |
| 1055 | player[0].last_items = player[0].items; |
| 1056 | |
| 1057 | player[1].items = player[0].items; |
| 1058 | player[1].items.weapon[REAR_WEAPON].id = 15; // Vulcan Cannon |
| 1059 | player[1].items.sidekick_level = 101; // 101, 102, 103 |
| 1060 | player[1].items.sidekick_series = 0; // None |
| 1061 | |
| 1062 | gameHasRepeated = false; |
| 1063 | onePlayerAction = false; |
| 1064 | superArcadeMode = SA_NONE; |
| 1065 | superTyrian = false; |
| 1066 | twoPlayerMode = false; |
| 1067 | |
| 1068 | secretHint = (mt_rand() % 3) + 1; |
| 1069 | |
| 1070 | for (uint p = 0; p < COUNTOF(player); ++p) |
| 1071 | { |
| 1072 | for (uint i = 0; i < COUNTOF(player->items.weapon); ++i) |
| 1073 | { |
| 1074 | player[p].items.weapon[i].power = 1; |
| 1075 | } |
| 1076 | |
| 1077 | player[p].weapon_mode = 1; |
| 1078 | player[p].armor = ships[player[p].items.ship].dmg; |
| 1079 | |
| 1080 | player[p].is_dragonwing = (p == 1); |
| 1081 | player[p].lives = &player[p].items.weapon[p].power; |
| 1082 | |
| 1083 | } |
| 1084 | |
| 1085 | mainLevel = FIRST_LEVEL; |
| 1086 | saveLevel = FIRST_LEVEL; |
| 1087 | |
| 1088 | strcpy(lastLevelName, miscText[19]); |
| 1089 | } |
| 1090 | |
| 1091 | void JE_sortHighScores(void) |
| 1092 | { |
| 1093 | JE_byte x; |
| 1094 | |
| 1095 | temp = 0; |
| 1096 | for (x = 0; x < 6; x++) |
| 1097 | { |
| 1098 | JE_sort(); |
| 1099 | temp += 3; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | void JE_highScoreScreen(void) |
| 1104 | { |
| 1105 | if (shopSpriteSheet.data == NULL) |
| 1106 | JE_loadCompShapes(&shopSpriteSheet, '1'); // need mouse pointer and arrow sprites |
| 1107 | |
| 1108 | bool restart = true; |
| 1109 | |
| 1110 | size_t episodeIndex = 0; |
| 1111 | // Save file only has space for scores for 3 episodes. |
| 1112 | const size_t episodeCount = 3; |
| 1113 | |
| 1114 | const int xCenter = 320 / 2; |
| 1115 | const int yMenuHeader = 3; |
| 1116 | const int yEpisodeHeader = 30; |
| 1117 | const int xLeftControl = 83; |
| 1118 | const int xRightControl = 213; |
| 1119 | const int wControl = 24; |
| 1120 | const int yControls = 179; |
| 1121 | |
| 1122 | for (; ; ) |
| 1123 | { |
| 1124 | if (restart) |
| 1125 | { |
| 1126 | JE_loadPic(VGAScreen2, 2, false); |
| 1127 | fill_rectangle_wh(VGAScreen2, 0, 192, 320, 8, 0); |
| 1128 | |
| 1129 | // Draw header. |
| 1130 | draw_font_hv_shadow(VGAScreen2, xCenter, yMenuHeader, miscText[50], large_font, centered, 15, -3, false, 2); |
| 1131 | } |
| 1132 | |
| 1133 | // Restore background and header. |
| 1134 | memcpy(VGAScreen->pixels, VGAScreen2->pixels, (size_t)VGAScreen->pitch * VGAScreen->h); |
| 1135 | |
| 1136 | const bool disabled = !episodeAvail[episodeIndex]; |
| 1137 | |
| 1138 | // Draw episode header. |
| 1139 | draw_font_hv_shadow(VGAScreen, xCenter, yEpisodeHeader, episode_name[episodeIndex + 1], normal_font, centered, 15, -3 + (disabled ? -4 : 0), false, 2); |
| 1140 | |
| 1141 | char buffer[29]; |
| 1142 | |
| 1143 | // Draw 1-player scores. |
| 1144 | |
| 1145 | draw_font_hv_shadow(VGAScreen, xCenter, 55, miscText[46], normal_font, centered, 15, -3, false, 2); |
| 1146 | |
| 1147 | for (Uint8 i = 0; i < 3; ++i) |
| 1148 | { |
| 1149 | const int y = 75 + 10 * i; |
| 1150 | |
| 1151 | const JE_SaveFileType *const saveFile = &saveFiles[episodeIndex * 6 + i]; |
| 1152 | const int rank = MIN(saveFile->highScoreDiff, COUNTOF(difficultyNameB) - 1); |
| 1153 | |
| 1154 | snprintf(buffer, sizeof buffer, "~#%d:~ %d", i + 1, saveFile->highScore1); |
| 1155 | JE_textShade(VGAScreen, 20, y, buffer, 15, 0, FULL_SHADE); |
| 1156 | JE_textShade(VGAScreen, 110, y, saveFile->highScoreName, 15, 2, FULL_SHADE); |
| 1157 | JE_textShade(VGAScreen, 250, y, difficultyNameB[rank], 15, rank + (rank == 0 ? 0 : -1), FULL_SHADE); |
| 1158 | } |
| 1159 | |
| 1160 | // Draw 2-player scores. |
| 1161 | |
| 1162 | draw_font_hv_shadow(VGAScreen, xCenter, 120, miscText[47], normal_font, centered, 15, -3, false, 2); |
| 1163 | |
| 1164 | for (Uint8 i = 0; i < 3; ++i) |
| 1165 | { |
| 1166 | const int y = 135 + 10 * i; |
| 1167 | |
| 1168 | const JE_SaveFileType *const saveFile = &saveFiles[episodeIndex * 6 + 3 + i]; |
| 1169 | const int rank = MIN(saveFile->highScoreDiff, COUNTOF(difficultyNameB) - 1); |
| 1170 | |
| 1171 | snprintf(buffer, sizeof buffer, "~#%d:~ %d", i + 1, saveFile->highScore1); |
| 1172 | JE_textShade(VGAScreen, 20, y, buffer, 15, 0, FULL_SHADE); |
| 1173 | JE_textShade(VGAScreen, 110, y, saveFile->highScoreName, 15, 2, FULL_SHADE); |
| 1174 | JE_textShade(VGAScreen, 250, y, difficultyNameB[rank], 15, rank + (rank == 0 ? 0 : -1), FULL_SHADE); |
| 1175 | } |
| 1176 | |
| 1177 | // Draw paging controls. |
| 1178 | |
| 1179 | const bool leftControlVisible = episodeIndex > 0; |
| 1180 | const bool rightControlVisible = episodeIndex < episodeCount - 1; |
| 1181 | |
| 1182 | if (leftControlVisible) |
| 1183 | blit_sprite2x2(VGAScreen, xLeftControl, yControls, shopSpriteSheet, 279); |
| 1184 | |
| 1185 | if (rightControlVisible) |
| 1186 | blit_sprite2x2(VGAScreen, xRightControl, yControls, shopSpriteSheet, 281); |
| 1187 | |
| 1188 | helpBoxColor = 15; |
| 1189 | JE_helpBox(VGAScreen, 103, 182, miscText[56], 25); |
| 1190 | |
| 1191 | if (restart) |
| 1192 | { |
| 1193 | mouseCursor = MOUSE_POINTER_NORMAL; |
| 1194 | |
| 1195 | fade_palette(colors, 10, 0, 255); |
| 1196 | |
| 1197 | restart = false; |
| 1198 | } |
| 1199 | |
| 1200 | do |
| 1201 | { |
| 1202 | service_SDL_events(true); |
| 1203 | |
| 1204 | JE_mouseStart(); |
| 1205 | JE_showVGA(); |
| 1206 | JE_mouseReplace(); |
| 1207 | |
| 1208 | SDL_Delay(16); |
| 1209 | |
| 1210 | push_joysticks_as_keyboard(); |
| 1211 | service_SDL_events(false); |
| 1212 | } while (!(newkey || newmouse)); |
| 1213 | |
| 1214 | // Handle interaction. |
| 1215 | |
| 1216 | bool leftAction = false; |
| 1217 | bool rightAction = false; |
| 1218 | bool done = false; |
| 1219 | |
| 1220 | if (newmouse) |
| 1221 | { |
| 1222 | switch (lastmouse_but) |
| 1223 | { |
| 1224 | case SDL_BUTTON_LEFT: |
| 1225 | { |
| 1226 | if (leftControlVisible && |
| 1227 | mouse_y >= yControls && |
| 1228 | mouse_x >= xLeftControl && |
| 1229 | mouse_x < xLeftControl + wControl) |
| 1230 | { |
| 1231 | JE_playSampleNum(S_CURSOR); |
| 1232 | |
| 1233 | leftAction = true; |
| 1234 | } |
| 1235 | else if (rightControlVisible && |
| 1236 | mouse_y >= yControls && |
| 1237 | mouse_x >= xRightControl && |
| 1238 | mouse_x < xRightControl + wControl) |
| 1239 | { |
| 1240 | JE_playSampleNum(S_CURSOR); |
| 1241 | |
| 1242 | rightAction = true; |
| 1243 | } |
| 1244 | break; |
| 1245 | } |
| 1246 | case SDL_BUTTON_RIGHT: |
| 1247 | { |
| 1248 | JE_playSampleNum(S_SPRING); |
| 1249 | |
| 1250 | done = true; |
| 1251 | break; |
| 1252 | } |
| 1253 | default: |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | else if (newkey) |
| 1258 | { |
| 1259 | switch (lastkey_scan) |
| 1260 | { |
| 1261 | case SDL_SCANCODE_LEFT: |
| 1262 | { |
| 1263 | JE_playSampleNum(S_CURSOR); |
| 1264 | |
| 1265 | leftAction = true; |
| 1266 | break; |
| 1267 | } |
| 1268 | case SDL_SCANCODE_RIGHT: |
| 1269 | { |
| 1270 | JE_playSampleNum(S_CURSOR); |
| 1271 | |
| 1272 | rightAction = true; |
| 1273 | break; |
| 1274 | } |
| 1275 | case SDL_SCANCODE_SPACE: |
| 1276 | case SDL_SCANCODE_RETURN: |
| 1277 | case SDL_SCANCODE_ESCAPE: |
| 1278 | { |
| 1279 | JE_playSampleNum(S_SPRING); |
| 1280 | |
| 1281 | done = true; |
| 1282 | break; |
| 1283 | } |
| 1284 | default: |
| 1285 | break; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | if (leftAction) |
| 1290 | { |
| 1291 | episodeIndex = episodeIndex == 0 |
| 1292 | ? episodeCount - 1 |
| 1293 | : episodeIndex - 1; |
| 1294 | } |
| 1295 | else if (rightAction) |
| 1296 | { |
| 1297 | episodeIndex = episodeIndex == episodeCount - 1 |
| 1298 | ? 0 |
| 1299 | : episodeIndex + 1; |
| 1300 | } |
| 1301 | |
| 1302 | if (done) |
| 1303 | { |
| 1304 | fade_black(15); |
| 1305 | |
| 1306 | return; |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | void JE_gammaCorrect_func(JE_byte *col, JE_real r) |
| 1312 | { |
| 1313 | int temp = roundf(*col * r); |
| 1314 | if (temp > 255) |
| 1315 | { |
| 1316 | temp = 255; |
| 1317 | } |
| 1318 | *col = temp; |
| 1319 | } |
| 1320 | |
| 1321 | void JE_gammaCorrect(Palette *colorBuffer, JE_byte gamma) |
| 1322 | { |
| 1323 | int x; |
| 1324 | JE_real r = 1 + (JE_real)gamma / 10; |
| 1325 | |
| 1326 | for (x = 0; x < 256; x++) |
| 1327 | { |
| 1328 | JE_gammaCorrect_func(&(*colorBuffer)[x].r, r); |
| 1329 | JE_gammaCorrect_func(&(*colorBuffer)[x].g, r); |
| 1330 | JE_gammaCorrect_func(&(*colorBuffer)[x].b, r); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | JE_boolean JE_gammaCheck(void) |
| 1335 | { |
| 1336 | bool temp = keysactive[SDL_SCANCODE_F11] != 0; |
| 1337 | if (temp) |
| 1338 | { |
| 1339 | keysactive[SDL_SCANCODE_F11] = false; |
| 1340 | newkey = false; |
| 1341 | gammaCorrection = (gammaCorrection + 1) % 4; |
| 1342 | memcpy(colors, palettes[pcxpal[3-1]], sizeof(colors)); |
| 1343 | JE_gammaCorrect(&colors, gammaCorrection); |
| 1344 | set_palette(colors, 0, 255); |
| 1345 | } |
| 1346 | return temp; |
| 1347 | } |
| 1348 | |
| 1349 | void JE_doInGameSetup(void) |
| 1350 | { |
| 1351 | mouseSetRelative(false); |
| 1352 | |
| 1353 | haltGame = false; |
| 1354 | |
| 1355 | #ifdef WITH_NETWORK |
| 1356 | if (isNetworkGame) |
| 1357 | { |
| 1358 | network_prepare(PACKET_GAME_MENU); |
| 1359 | network_send(4); // PACKET_GAME_MENU |
| 1360 | |
| 1361 | while (true) |
| 1362 | { |
| 1363 | service_SDL_events(false); |
| 1364 | |
| 1365 | if (packet_in[0] && SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_GAME_MENU) |
| 1366 | { |
| 1367 | network_update(); |
| 1368 | break; |
| 1369 | } |
| 1370 | |
| 1371 | network_update(); |
| 1372 | network_check(); |
| 1373 | |
| 1374 | SDL_Delay(16); |
| 1375 | } |
| 1376 | } |
| 1377 | #endif |
| 1378 | |
| 1379 | if (yourInGameMenuRequest) |
| 1380 | { |
| 1381 | if (JE_inGameSetup()) |
| 1382 | { |
| 1383 | reallyEndLevel = true; |
| 1384 | playerEndLevel = true; |
| 1385 | } |
| 1386 | quitRequested = false; |
| 1387 | |
| 1388 | keysactive[SDL_SCANCODE_ESCAPE] = false; |
| 1389 | |
| 1390 | #ifdef WITH_NETWORK |
| 1391 | if (isNetworkGame) |
| 1392 | { |
| 1393 | if (!playerEndLevel) |
| 1394 | { |
| 1395 | network_prepare(PACKET_WAITING); |
| 1396 | network_send(4); // PACKET_WAITING |
| 1397 | } |
| 1398 | else |
| 1399 | { |
| 1400 | network_prepare(PACKET_GAME_QUIT); |
| 1401 | network_send(4); // PACKET_GAMEQUIT |
| 1402 | } |
| 1403 | } |
| 1404 | #endif |
| 1405 | } |
| 1406 | |
| 1407 | #ifdef WITH_NETWORK |
| 1408 | if (isNetworkGame) |
| 1409 | { |
| 1410 | SDL_Surface *temp_surface = VGAScreen; |
| 1411 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 1412 | |
| 1413 | if (!yourInGameMenuRequest) |
| 1414 | { |
| 1415 | JE_barShade(VGAScreen, 3, 60, 257, 80); /*Help Box*/ |
| 1416 | JE_barShade(VGAScreen, 5, 62, 255, 78); |
| 1417 | JE_dString(VGAScreen, 10, 65, "Other player in options menu.", SMALL_FONT_SHAPES); |
| 1418 | JE_showVGA(); |
| 1419 | |
| 1420 | while (true) |
| 1421 | { |
| 1422 | service_SDL_events(false); |
| 1423 | JE_showVGA(); |
| 1424 | |
| 1425 | if (packet_in[0]) |
| 1426 | { |
| 1427 | if (SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_WAITING) |
| 1428 | { |
| 1429 | network_check(); |
| 1430 | break; |
| 1431 | } |
| 1432 | else if (SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_GAME_QUIT) |
| 1433 | { |
| 1434 | reallyEndLevel = true; |
| 1435 | playerEndLevel = true; |
| 1436 | |
| 1437 | network_check(); |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | network_update(); |
| 1443 | network_check(); |
| 1444 | |
| 1445 | SDL_Delay(16); |
| 1446 | } |
| 1447 | } |
| 1448 | else |
| 1449 | { |
| 1450 | /* |
| 1451 | JE_barShade(3, 160, 257, 180); /-*Help Box*-/ |
| 1452 | JE_barShade(5, 162, 255, 178); |
| 1453 | tempScreenSeg = VGAScreen; |
| 1454 | JE_dString(VGAScreen, 10, 165, "Waiting for other player.", SMALL_FONT_SHAPES); |
| 1455 | JE_showVGA(); |
| 1456 | */ |
| 1457 | } |
| 1458 | |
| 1459 | while (!network_is_sync()) |
| 1460 | { |
| 1461 | service_SDL_events(false); |
| 1462 | |
| 1463 | network_check(); |
| 1464 | SDL_Delay(16); |
| 1465 | } |
| 1466 | |
| 1467 | VGAScreen = temp_surface; /* side-effect of game_screen */ |
| 1468 | } |
| 1469 | #endif |
| 1470 | |
| 1471 | yourInGameMenuRequest = false; |
| 1472 | |
| 1473 | //skipStarShowVGA = true; |
| 1474 | |
| 1475 | mouseSetRelative(true); |
| 1476 | } |
| 1477 | |
| 1478 | JE_boolean JE_inGameSetup(void) |
| 1479 | { |
| 1480 | bool result = false; |
| 1481 | |
| 1482 | SDL_Surface *temp_surface = VGAScreen; |
| 1483 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 1484 | |
| 1485 | enum MenuItemIndex |
| 1486 | { |
| 1487 | MENU_ITEM_MUSIC_VOLUME = 0, |
| 1488 | MENU_ITEM_EFFECTS_VOLUME, |
| 1489 | MENU_ITEM_DETAIL_LEVEL, |
| 1490 | MENU_ITEM_GAME_SPEED, |
| 1491 | MENU_ITEM_RETURN_TO_GAME, |
| 1492 | MENU_ITEM_QUIT, |
| 1493 | }; |
| 1494 | |
| 1495 | const size_t helpIndexes[] = { 14, 14, 27, 28, 25, 26 }; |
| 1496 | |
| 1497 | if (shopSpriteSheet.data == NULL) |
| 1498 | JE_loadCompShapes(&shopSpriteSheet, '1'); // need mouse pointer sprites |
| 1499 | |
| 1500 | bool restart = true; |
| 1501 | |
| 1502 | const size_t menuItemsCount = COUNTOF(inGameText); |
| 1503 | size_t selectedIndex = MENU_ITEM_MUSIC_VOLUME; |
| 1504 | |
| 1505 | const int yMenuItems = 20; |
| 1506 | const int dyMenuItems = 20; |
| 1507 | const int xMenuItem = 10; |
| 1508 | const int xMenuItemName = xMenuItem; |
| 1509 | const int wMenuItemName = 110; |
| 1510 | const int xMenuItemValue = xMenuItemName + wMenuItemName; |
| 1511 | const int wMenuItemValue = 90; |
| 1512 | const int wMenuItem = wMenuItemName + wMenuItemValue; |
| 1513 | const int hMenuItem = 13; |
| 1514 | |
| 1515 | for (bool done = false; !done; ) |
| 1516 | { |
| 1517 | if (restart) |
| 1518 | { |
| 1519 | // Main box |
| 1520 | JE_barShade(VGAScreen, 3, 13, 217, 137); |
| 1521 | JE_barShade(VGAScreen, 5, 15, 215, 135); |
| 1522 | |
| 1523 | // Help box |
| 1524 | JE_barShade(VGAScreen, 3, 143, 257, 157); |
| 1525 | JE_barShade(VGAScreen, 5, 145, 255, 155); |
| 1526 | |
| 1527 | memcpy(VGAScreen2->pixels, VGAScreen->pixels, VGAScreen2->pitch * VGAScreen2->h); |
| 1528 | |
| 1529 | mouseCursor = MOUSE_POINTER_NORMAL; |
| 1530 | |
| 1531 | restart = false; |
| 1532 | } |
| 1533 | |
| 1534 | // Restore background. |
| 1535 | memcpy(VGAScreen->pixels, VGAScreen2->pixels, (size_t)VGAScreen->pitch * VGAScreen->h); |
| 1536 | |
| 1537 | // Draw menu items. |
| 1538 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 1539 | { |
| 1540 | const int y = yMenuItems + dyMenuItems * i; |
| 1541 | |
| 1542 | const char *const name = inGameText[i]; |
| 1543 | |
| 1544 | const bool selected = i == selectedIndex; |
| 1545 | |
| 1546 | draw_font_hv_shadow(VGAScreen, xMenuItemName, y, name, normal_font, left_aligned, 15, -4 + (selected ? 2 : 0), false, 2); |
| 1547 | |
| 1548 | switch (i) |
| 1549 | { |
| 1550 | case MENU_ITEM_MUSIC_VOLUME: |
| 1551 | { |
| 1552 | JE_barDrawShadow(VGAScreen, xMenuItemValue, y, 1, music_disabled ? 12 : 16, (tyrMusicVolume + 6) / 12, 3, 13); |
| 1553 | break; |
| 1554 | } |
| 1555 | case MENU_ITEM_EFFECTS_VOLUME: |
| 1556 | { |
| 1557 | JE_barDrawShadow(VGAScreen, xMenuItemValue, y, 1, samples_disabled ? 12 : 16, (fxVolume + 6) / 12, 3, 13); |
| 1558 | break; |
| 1559 | } |
| 1560 | case MENU_ITEM_DETAIL_LEVEL: |
| 1561 | { |
| 1562 | draw_font_hv_shadow(VGAScreen, xMenuItemValue, y, detailLevel[processorType-1], normal_font, left_aligned, 15, -4 + (selected ? 2 : 0), false, 2); |
| 1563 | break; |
| 1564 | } |
| 1565 | case MENU_ITEM_GAME_SPEED: |
| 1566 | { |
| 1567 | draw_font_hv_shadow(VGAScreen, xMenuItemValue, y, gameSpeedText[gameSpeed-1], normal_font, left_aligned, 15, -4 + (selected ? 2 : 0), false, 2); |
| 1568 | break; |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | // Draw help text. |
| 1574 | JE_outTextAdjust(VGAScreen, 10, 147, mainMenuHelp[helpIndexes[selectedIndex]], 14, 6, TINY_FONT, true); |
| 1575 | |
| 1576 | service_SDL_events(true); |
| 1577 | |
| 1578 | JE_mouseStart(); |
| 1579 | JE_showVGA(); |
| 1580 | JE_mouseReplace(); |
| 1581 | |
| 1582 | bool mouseMoved = false; |
| 1583 | do |
| 1584 | { |
| 1585 | SDL_Delay(16); |
| 1586 | |
| 1587 | Uint16 oldMouseX = mouse_x; |
| 1588 | Uint16 oldMouseY = mouse_y; |
| 1589 | |
| 1590 | push_joysticks_as_keyboard(); |
| 1591 | service_SDL_events(false); |
| 1592 | |
| 1593 | NETWORK_KEEP_ALIVE(); |
| 1594 | |
| 1595 | mouseMoved = mouse_x != oldMouseX || mouse_y != oldMouseY; |
| 1596 | } while (!(newkey || newmouse || mouseMoved)); |
| 1597 | |
| 1598 | // Handle interaction. |
| 1599 | |
| 1600 | bool action = false; |
| 1601 | bool leftAction = false; |
| 1602 | bool rightAction = false; |
| 1603 | |
| 1604 | if (mouseMoved || newmouse) |
| 1605 | { |
| 1606 | // Find menu item that was hovered or clicked. |
| 1607 | if (mouse_x >= xMenuItem && mouse_x < xMenuItem + wMenuItem) |
| 1608 | { |
| 1609 | for (size_t i = 0; i < menuItemsCount; ++i) |
| 1610 | { |
| 1611 | const int yMenuItem = yMenuItems + dyMenuItems * i; |
| 1612 | if (mouse_y >= yMenuItem && mouse_y < yMenuItem + hMenuItem) |
| 1613 | { |
| 1614 | if (selectedIndex != i) |
| 1615 | { |
| 1616 | JE_playSampleNum(S_CURSOR); |
| 1617 | |
| 1618 | selectedIndex = i; |
| 1619 | } |
| 1620 | |
| 1621 | if (newmouse && lastmouse_but == SDL_BUTTON_LEFT && |
| 1622 | lastmouse_x >= xMenuItem && lastmouse_x < xMenuItem + wMenuItem && |
| 1623 | lastmouse_y >= yMenuItem && lastmouse_y < yMenuItem + hMenuItem) |
| 1624 | { |
| 1625 | // Act on menu item via name. |
| 1626 | if (lastmouse_x >= xMenuItemName && lastmouse_x < xMenuItemName + wMenuItemName) |
| 1627 | { |
| 1628 | action = true; |
| 1629 | } |
| 1630 | |
| 1631 | // Act on menu item via value. |
| 1632 | else if (lastmouse_x >= xMenuItemValue && lastmouse_x < xMenuItemValue + wMenuItemValue) |
| 1633 | { |
| 1634 | switch (i) |
| 1635 | { |
| 1636 | case MENU_ITEM_MUSIC_VOLUME: |
| 1637 | { |
| 1638 | JE_playSampleNum(S_CURSOR); |
| 1639 | |
| 1640 | const int w = ((255 + 6) / 12) * (3 + 1) - 1; |
| 1641 | |
| 1642 | int value = (lastmouse_x - xMenuItemValue) * 255 / (w - 1); |
| 1643 | tyrMusicVolume = MIN(MAX(0, value), 255); |
| 1644 | |
| 1645 | set_volume(tyrMusicVolume, fxVolume); |
| 1646 | break; |
| 1647 | } |
| 1648 | case MENU_ITEM_EFFECTS_VOLUME: |
| 1649 | { |
| 1650 | const int w = ((255 + 6) / 12) * (3 + 1) - 1; |
| 1651 | |
| 1652 | int value = (lastmouse_x - xMenuItemValue) * 255 / (w - 1); |
| 1653 | fxVolume = MIN(MAX(0, value), 255); |
| 1654 | |
| 1655 | set_volume(tyrMusicVolume, fxVolume); |
| 1656 | |
| 1657 | JE_playSampleNum(S_CURSOR); |
| 1658 | break; |
| 1659 | } |
| 1660 | case MENU_ITEM_DETAIL_LEVEL: |
| 1661 | case MENU_ITEM_GAME_SPEED: |
| 1662 | { |
| 1663 | rightAction = true; |
| 1664 | break; |
| 1665 | } |
| 1666 | default: |
| 1667 | break; |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | if (newmouse) |
| 1679 | { |
| 1680 | if (lastmouse_but == SDL_BUTTON_RIGHT) |
| 1681 | { |
| 1682 | JE_playSampleNum(S_SPRING); |
| 1683 | |
| 1684 | done = true; |
| 1685 | } |
| 1686 | } |
| 1687 | else if (newkey) |
| 1688 | { |
| 1689 | switch (lastkey_scan) |
| 1690 | { |
| 1691 | case SDL_SCANCODE_UP: |
| 1692 | { |
| 1693 | JE_playSampleNum(S_CURSOR); |
| 1694 | |
| 1695 | selectedIndex = selectedIndex == 0 |
| 1696 | ? menuItemsCount - 1 |
| 1697 | : selectedIndex - 1; |
| 1698 | break; |
| 1699 | } |
| 1700 | case SDL_SCANCODE_DOWN: |
| 1701 | { |
| 1702 | JE_playSampleNum(S_CURSOR); |
| 1703 | |
| 1704 | selectedIndex = selectedIndex == menuItemsCount - 1 |
| 1705 | ? 0 |
| 1706 | : selectedIndex + 1; |
| 1707 | break; |
| 1708 | } |
| 1709 | case SDL_SCANCODE_LEFT: |
| 1710 | { |
| 1711 | leftAction = true; |
| 1712 | break; |
| 1713 | } |
| 1714 | case SDL_SCANCODE_RIGHT: |
| 1715 | { |
| 1716 | rightAction = true; |
| 1717 | break; |
| 1718 | } |
| 1719 | case SDL_SCANCODE_SPACE: |
| 1720 | case SDL_SCANCODE_RETURN: |
| 1721 | { |
| 1722 | action = true; |
| 1723 | break; |
| 1724 | } |
| 1725 | case SDL_SCANCODE_ESCAPE: |
| 1726 | { |
| 1727 | JE_playSampleNum(S_SPRING); |
| 1728 | |
| 1729 | done = true; |
| 1730 | break; |
| 1731 | } |
| 1732 | case SDL_SCANCODE_W: |
| 1733 | { |
| 1734 | if (selectedIndex == MENU_ITEM_DETAIL_LEVEL) |
| 1735 | { |
| 1736 | processorType = 6; |
| 1737 | JE_initProcessorType(); |
| 1738 | } |
| 1739 | break; |
| 1740 | } |
| 1741 | default: |
| 1742 | break; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | if (action) |
| 1747 | { |
| 1748 | switch (selectedIndex) |
| 1749 | { |
| 1750 | case MENU_ITEM_MUSIC_VOLUME: |
| 1751 | { |
| 1752 | JE_playSampleNum(S_SELECT); |
| 1753 | |
| 1754 | music_disabled = !music_disabled; |
| 1755 | break; |
| 1756 | } |
| 1757 | case MENU_ITEM_EFFECTS_VOLUME: |
| 1758 | { |
| 1759 | samples_disabled = !samples_disabled; |
| 1760 | |
| 1761 | JE_playSampleNum(S_SELECT); |
| 1762 | break; |
| 1763 | } |
| 1764 | case MENU_ITEM_RETURN_TO_GAME: |
| 1765 | { |
| 1766 | JE_playSampleNum(S_SELECT); |
| 1767 | |
| 1768 | done = true; |
| 1769 | break; |
| 1770 | } |
| 1771 | case MENU_ITEM_QUIT: |
| 1772 | { |
| 1773 | JE_playSampleNum(S_SELECT); |
| 1774 | |
| 1775 | if (constantPlay) |
| 1776 | JE_tyrianHalt(0); |
| 1777 | |
| 1778 | if (isNetworkGame) |
| 1779 | { |
| 1780 | /*Tell other computer to exit*/ |
| 1781 | haltGame = true; |
| 1782 | playerEndLevel = true; |
| 1783 | } |
| 1784 | |
| 1785 | result = true; |
| 1786 | done = true; |
| 1787 | break; |
| 1788 | } |
| 1789 | default: |
| 1790 | break; |
| 1791 | } |
| 1792 | } |
| 1793 | else if (leftAction) |
| 1794 | { |
| 1795 | switch (selectedIndex) |
| 1796 | { |
| 1797 | case MENU_ITEM_MUSIC_VOLUME: |
| 1798 | { |
| 1799 | JE_playSampleNum(S_CURSOR); |
| 1800 | |
| 1801 | JE_changeVolume(&tyrMusicVolume, -12, &fxVolume, 0); |
| 1802 | break; |
| 1803 | } |
| 1804 | case MENU_ITEM_EFFECTS_VOLUME: |
| 1805 | { |
| 1806 | JE_changeVolume(&tyrMusicVolume, 0, &fxVolume, -12); |
| 1807 | |
| 1808 | JE_playSampleNum(S_CURSOR); |
| 1809 | break; |
| 1810 | } |
| 1811 | case MENU_ITEM_DETAIL_LEVEL: |
| 1812 | { |
| 1813 | JE_playSampleNum(S_CURSOR); |
| 1814 | |
| 1815 | processorType = processorType > 1 ? processorType - 1 : 4; |
| 1816 | JE_initProcessorType(); |
| 1817 | JE_setNewGameSpeed(); |
| 1818 | break; |
| 1819 | } |
| 1820 | case MENU_ITEM_GAME_SPEED: |
| 1821 | { |
| 1822 | JE_playSampleNum(S_CURSOR); |
| 1823 | |
| 1824 | gameSpeed = gameSpeed > 1 ? gameSpeed - 1 : 5; |
| 1825 | JE_initProcessorType(); |
| 1826 | JE_setNewGameSpeed(); |
| 1827 | break; |
| 1828 | } |
| 1829 | default: |
| 1830 | break; |
| 1831 | } |
| 1832 | } |
| 1833 | else if (rightAction) |
| 1834 | { |
| 1835 | switch (selectedIndex) |
| 1836 | { |
| 1837 | case MENU_ITEM_MUSIC_VOLUME: |
| 1838 | { |
| 1839 | JE_playSampleNum(S_CURSOR); |
| 1840 | |
| 1841 | JE_changeVolume(&tyrMusicVolume, 12, &fxVolume, 0); |
| 1842 | break; |
| 1843 | } |
| 1844 | case MENU_ITEM_EFFECTS_VOLUME: |
| 1845 | { |
| 1846 | JE_changeVolume(&tyrMusicVolume, 0, &fxVolume, 12); |
| 1847 | |
| 1848 | JE_playSampleNum(S_CURSOR); |
| 1849 | break; |
| 1850 | } |
| 1851 | case MENU_ITEM_DETAIL_LEVEL: |
| 1852 | { |
| 1853 | JE_playSampleNum(S_CURSOR); |
| 1854 | |
| 1855 | processorType = processorType < 4 ? processorType + 1 : 1; |
| 1856 | JE_initProcessorType(); |
| 1857 | JE_setNewGameSpeed(); |
| 1858 | break; |
| 1859 | } |
| 1860 | case MENU_ITEM_GAME_SPEED: |
| 1861 | { |
| 1862 | JE_playSampleNum(S_CURSOR); |
| 1863 | |
| 1864 | gameSpeed = gameSpeed < 5 ? gameSpeed + 1 : 1; |
| 1865 | JE_initProcessorType(); |
| 1866 | JE_setNewGameSpeed(); |
| 1867 | break; |
| 1868 | } |
| 1869 | default: |
| 1870 | break; |
| 1871 | } |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | VGAScreen = temp_surface; /* side-effect of game_screen */ |
| 1876 | |
| 1877 | return result; |
| 1878 | } |
| 1879 | |
| 1880 | void JE_inGameHelp(void) |
| 1881 | { |
| 1882 | SDL_Surface *temp_surface = VGAScreen; |
| 1883 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 1884 | |
| 1885 | //tempScreenSeg = VGAScreenSeg; |
| 1886 | |
| 1887 | JE_clearKeyboard(); |
| 1888 | JE_wipeKey(); |
| 1889 | |
| 1890 | JE_barShade(VGAScreen, 1, 1, 262, 182); /*Main Box*/ |
| 1891 | JE_barShade(VGAScreen, 3, 3, 260, 180); |
| 1892 | JE_barShade(VGAScreen, 5, 5, 258, 178); |
| 1893 | JE_barShade(VGAScreen, 7, 7, 256, 176); |
| 1894 | fill_rectangle_xy(VGAScreen, 9, 9, 254, 174, 0); |
| 1895 | |
| 1896 | if (twoPlayerMode) // Two-Player Help |
| 1897 | { |
| 1898 | helpBoxColor = 3; |
| 1899 | helpBoxBrightness = 3; |
| 1900 | JE_HBox(VGAScreen, 20, 4, 36, 50); |
| 1901 | |
| 1902 | // weapon help |
| 1903 | blit_sprite(VGAScreenSeg, 2, 21, OPTION_SHAPES, 43); |
| 1904 | helpBoxColor = 5; |
| 1905 | helpBoxBrightness = 3; |
| 1906 | JE_HBox(VGAScreen, 55, 20, 37, 40); |
| 1907 | |
| 1908 | // sidekick help |
| 1909 | blit_sprite(VGAScreenSeg, 5, 36, OPTION_SHAPES, 41); |
| 1910 | helpBoxColor = 5; |
| 1911 | helpBoxBrightness = 3; |
| 1912 | JE_HBox(VGAScreen, 40, 43, 34, 44); |
| 1913 | |
| 1914 | // shield/armor help |
| 1915 | blit_sprite(VGAScreenSeg, 2, 79, OPTION_SHAPES, 42); |
| 1916 | helpBoxColor = 5; |
| 1917 | helpBoxBrightness = 3; |
| 1918 | JE_HBox(VGAScreen, 54, 84, 35, 40); |
| 1919 | |
| 1920 | helpBoxColor = 5; |
| 1921 | helpBoxBrightness = 3; |
| 1922 | JE_HBox(VGAScreen, 5, 126, 38, 55); |
| 1923 | helpBoxColor = 5; |
| 1924 | helpBoxBrightness = 3; |
| 1925 | JE_HBox(VGAScreen, 5, 160, 39, 55); |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | // power bar help |
| 1930 | blit_sprite(VGAScreenSeg, 15, 5, OPTION_SHAPES, 40); |
| 1931 | helpBoxColor = 5; |
| 1932 | helpBoxBrightness = 3; |
| 1933 | JE_HBox(VGAScreen, 40, 10, 31, 45); |
| 1934 | |
| 1935 | // weapon help |
| 1936 | blit_sprite(VGAScreenSeg, 5, 37, OPTION_SHAPES, 39); |
| 1937 | helpBoxColor = 5; |
| 1938 | helpBoxBrightness = 3; |
| 1939 | JE_HBox(VGAScreen, 40, 40, 32, 44); |
| 1940 | helpBoxColor = 5; |
| 1941 | helpBoxBrightness = 3; |
| 1942 | JE_HBox(VGAScreen, 40, 60, 33, 44); |
| 1943 | |
| 1944 | // sidekick help |
| 1945 | blit_sprite(VGAScreenSeg, 5, 98, OPTION_SHAPES, 41); |
| 1946 | helpBoxColor = 5; |
| 1947 | helpBoxBrightness = 3; |
| 1948 | JE_HBox(VGAScreen, 40, 103, 34, 44); |
| 1949 | |
| 1950 | // shield/armor help |
| 1951 | blit_sprite(VGAScreenSeg, 2, 138, OPTION_SHAPES, 42); |
| 1952 | helpBoxColor = 5; |
| 1953 | helpBoxBrightness = 3; |
| 1954 | JE_HBox(VGAScreen, 54, 143, 35, 40); |
| 1955 | } |
| 1956 | |
| 1957 | // "press a key" |
| 1958 | blit_sprite(VGAScreenSeg, 16, 189, OPTION_SHAPES, 36); // in-game text area |
| 1959 | JE_outText(VGAScreenSeg, 120 - JE_textWidth(miscText[5-1], TINY_FONT) / 2 + 20, 190, miscText[5-1], 0, 4); |
| 1960 | |
| 1961 | do |
| 1962 | { |
| 1963 | service_SDL_events(true); |
| 1964 | |
| 1965 | JE_mouseStart(); |
| 1966 | JE_showVGA(); |
| 1967 | JE_mouseReplace(); |
| 1968 | |
| 1969 | SDL_Delay(16); |
| 1970 | |
| 1971 | push_joysticks_as_keyboard(); |
| 1972 | service_SDL_events(false); |
| 1973 | |
| 1974 | NETWORK_KEEP_ALIVE(); |
| 1975 | } while (!(newkey || newmouse)); |
| 1976 | |
| 1977 | textErase = 1; |
| 1978 | |
| 1979 | VGAScreen = temp_surface; |
| 1980 | } |
| 1981 | |
| 1982 | void JE_highScoreCheck(void) |
| 1983 | { |
| 1984 | if (shopSpriteSheet.data == NULL) |
| 1985 | JE_loadCompShapes(&shopSpriteSheet, '1'); // need mouse pointer sprite |
| 1986 | |
| 1987 | Sint32 temp_score; |
| 1988 | |
| 1989 | for (int temp_p = 0; temp_p < (twoPlayerMode ? 2 : 1); ++temp_p) |
| 1990 | { |
| 1991 | JE_sortHighScores(); |
| 1992 | |
| 1993 | int p = temp_p; |
| 1994 | |
| 1995 | if (twoPlayerMode) |
| 1996 | { |
| 1997 | // ask for the highest scorer first |
| 1998 | if (player[0].cash < player[1].cash) |
| 1999 | p = (temp_p == 0) ? 1 : 0; |
| 2000 | |
| 2001 | temp_score = (p == 0) ? player[0].cash : player[1].cash; |
| 2002 | } |
| 2003 | else |
| 2004 | { |
| 2005 | // single player highscore includes cost of upgrades |
| 2006 | temp_score = JE_totalScore(&player[0]); |
| 2007 | } |
| 2008 | |
| 2009 | int slot; |
| 2010 | const int first_slot = (initial_episode_num - 1) * 6 + (twoPlayerMode ? 3 : 0), |
| 2011 | slot_limit = first_slot + 3; |
| 2012 | |
| 2013 | for (slot = first_slot; slot < slot_limit; ++slot) |
| 2014 | { |
| 2015 | if (temp_score > saveFiles[slot].highScore1) |
| 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | // did you get a high score? |
| 2020 | if (slot < slot_limit) |
| 2021 | { |
| 2022 | // shift down old scores |
| 2023 | for (int i = slot_limit - 1; i > slot; --i) |
| 2024 | { |
| 2025 | saveFiles[i].highScore1 = saveFiles[i - 1].highScore1; |
| 2026 | strcpy(saveFiles[i].highScoreName, saveFiles[i - 1].highScoreName); |
| 2027 | } |
| 2028 | |
| 2029 | wait_noinput(false, true, false); |
| 2030 | |
| 2031 | JE_clr256(VGAScreen); |
| 2032 | JE_showVGA(); |
| 2033 | memcpy(colors, palettes[0], sizeof(colors)); |
| 2034 | |
| 2035 | play_song(33); |
| 2036 | |
| 2037 | { |
| 2038 | /* Enter Thy name */ |
| 2039 | |
| 2040 | JE_byte flash = 8 * 16 + 10; |
| 2041 | JE_boolean fadein = true; |
| 2042 | JE_boolean quit = false, cancel = false; |
| 2043 | char stemp[30], tempstr[30]; |
| 2044 | char buffer[256]; |
| 2045 | |
| 2046 | strcpy(stemp, " "); |
| 2047 | temp = 0; |
| 2048 | |
| 2049 | JE_barShade(VGAScreen, 65, 55, 255, 155); |
| 2050 | |
| 2051 | do |
| 2052 | { |
| 2053 | service_SDL_events(true); |
| 2054 | |
| 2055 | JE_dString(VGAScreen, JE_fontCenter(miscText[51], FONT_SHAPES), 3, miscText[51], FONT_SHAPES); |
| 2056 | |
| 2057 | temp3 = twoPlayerMode ? 58 + p : 53; |
| 2058 | |
| 2059 | JE_dString(VGAScreen, JE_fontCenter(miscText[temp3-1], SMALL_FONT_SHAPES), 30, miscText[temp3-1], SMALL_FONT_SHAPES); |
| 2060 | |
| 2061 | blit_sprite(VGAScreenSeg, 50, 50, OPTION_SHAPES, 35); // message box |
| 2062 | |
| 2063 | if (twoPlayerMode) |
| 2064 | { |
| 2065 | sprintf(buffer, "%s %s", miscText[48 + p], miscText[53]); |
| 2066 | JE_textShade(VGAScreen, 60, 55, buffer, 11, 4, FULL_SHADE); |
| 2067 | } |
| 2068 | else |
| 2069 | { |
| 2070 | JE_textShade(VGAScreen, 60, 55, miscText[53], 11, 4, FULL_SHADE); |
| 2071 | } |
| 2072 | |
| 2073 | sprintf(buffer, "%s %d", miscText[37], temp_score); |
| 2074 | JE_textShade(VGAScreen, 70, 70, buffer, 11, 4, FULL_SHADE); |
| 2075 | |
| 2076 | do |
| 2077 | { |
| 2078 | flash = (flash == 8 * 16 + 10) ? 8 * 16 + 2 : 8 * 16 + 10; |
| 2079 | temp3 = (temp3 == 6) ? 2 : 6; |
| 2080 | |
| 2081 | strncpy(tempstr, stemp, temp); |
| 2082 | tempstr[temp] = '\0'; |
| 2083 | JE_outText(VGAScreen, 65, 89, tempstr, 8, 3); |
| 2084 | tempW = 65 + JE_textWidth(tempstr, TINY_FONT); |
| 2085 | JE_barShade(VGAScreen, tempW + 2, 90, tempW + 6, 95); |
| 2086 | fill_rectangle_xy(VGAScreen, tempW + 1, 89, tempW + 5, 94, flash); |
| 2087 | |
| 2088 | for (int i = 0; i < 14; i++) |
| 2089 | { |
| 2090 | setDelay(1); |
| 2091 | |
| 2092 | JE_mouseStart(); |
| 2093 | JE_showVGA(); |
| 2094 | if (fadein) |
| 2095 | { |
| 2096 | fade_palette(colors, 15, 0, 255); |
| 2097 | fadein = false; |
| 2098 | } |
| 2099 | JE_mouseReplace(); |
| 2100 | |
| 2101 | push_joysticks_as_keyboard(); |
| 2102 | service_wait_delay(); |
| 2103 | |
| 2104 | if (newkey || newmouse) |
| 2105 | break; |
| 2106 | } |
| 2107 | |
| 2108 | } while (!newkey && !newmouse && !new_text); |
| 2109 | |
| 2110 | if (!playing) |
| 2111 | play_song(31); |
| 2112 | |
| 2113 | if (mouseButton > 0) |
| 2114 | { |
| 2115 | if (mouseX > 56 && mouseX < 142 && mouseY > 123 && mouseY < 149) |
| 2116 | { |
| 2117 | quit = true; |
| 2118 | } |
| 2119 | else if (mouseX > 151 && mouseX < 237 && mouseY > 123 && mouseY < 149) |
| 2120 | { |
| 2121 | quit = true; |
| 2122 | cancel = true; |
| 2123 | } |
| 2124 | } |
| 2125 | else if (new_text) |
| 2126 | { |
| 2127 | for (size_t ti = 0U; last_text[ti] != '\0'; ++ti) |
| 2128 | { |
| 2129 | const char c = (unsigned char)last_text[ti] <= 127U ? toupper(last_text[ti]) : 0; |
| 2130 | if ((c == ' ' || font_ascii[(unsigned char)c] != -1) && |
| 2131 | temp < 28) |
| 2132 | { |
| 2133 | stemp[temp] = c; |
| 2134 | temp += 1; |
| 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | else if (newkey) |
| 2139 | { |
| 2140 | switch (lastkey_scan) |
| 2141 | { |
| 2142 | case SDL_SCANCODE_BACKSPACE: |
| 2143 | case SDL_SCANCODE_DELETE: |
| 2144 | if (temp) |
| 2145 | { |
| 2146 | temp--; |
| 2147 | stemp[temp] = ' '; |
| 2148 | } |
| 2149 | break; |
| 2150 | case SDL_SCANCODE_ESCAPE: |
| 2151 | quit = true; |
| 2152 | cancel = true; |
| 2153 | break; |
| 2154 | case SDL_SCANCODE_RETURN: |
| 2155 | quit = true; |
| 2156 | break; |
| 2157 | default: |
| 2158 | break; |
| 2159 | } |
| 2160 | } |
| 2161 | } while (!quit); |
| 2162 | |
| 2163 | if (!cancel) |
| 2164 | { |
| 2165 | saveFiles[slot].highScore1 = temp_score; |
| 2166 | strcpy(saveFiles[slot].highScoreName, stemp); |
| 2167 | saveFiles[slot].highScoreDiff = difficultyLevel; |
| 2168 | } |
| 2169 | |
| 2170 | fade_black(15); |
| 2171 | JE_loadPic(VGAScreen, 2, false); |
| 2172 | |
| 2173 | JE_dString(VGAScreen, JE_fontCenter(miscText[50], FONT_SHAPES), 10, miscText[50], FONT_SHAPES); |
| 2174 | JE_dString(VGAScreen, JE_fontCenter(episode_name[episodeNum], SMALL_FONT_SHAPES), 35, episode_name[episodeNum], SMALL_FONT_SHAPES); |
| 2175 | |
| 2176 | for (int i = first_slot; i < slot_limit; ++i) |
| 2177 | { |
| 2178 | if (i != slot) |
| 2179 | { |
| 2180 | sprintf(buffer, "~#%d:~ %d", (i - first_slot + 1), saveFiles[i].highScore1); |
| 2181 | JE_textShade(VGAScreen, 20, ((i - first_slot + 1) * 12) + 65, buffer, 15, 0, FULL_SHADE); |
| 2182 | JE_textShade(VGAScreen, 150, ((i - first_slot + 1) * 12) + 65, saveFiles[i].highScoreName, 15, 2, FULL_SHADE); |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | JE_showVGA(); |
| 2187 | |
| 2188 | fade_palette(colors, 15, 0, 255); |
| 2189 | |
| 2190 | sprintf(buffer, "~#%d:~ %d", (slot - first_slot + 1), saveFiles[slot].highScore1); |
| 2191 | |
| 2192 | frameCountMax = 6; |
| 2193 | textGlowFont = TINY_FONT; |
| 2194 | |
| 2195 | textGlowBrightness = 10; |
| 2196 | JE_outTextGlow(VGAScreenSeg, 20, (slot - first_slot + 1) * 12 + 65, buffer); |
| 2197 | textGlowBrightness = 10; |
| 2198 | JE_outTextGlow(VGAScreenSeg, 150, (slot - first_slot + 1) * 12 + 65, saveFiles[slot].highScoreName); |
| 2199 | textGlowBrightness = 10; |
| 2200 | JE_outTextGlow(VGAScreenSeg, JE_fontCenter(miscText[4], TINY_FONT), 180, miscText[4]); |
| 2201 | |
| 2202 | JE_showVGA(); |
| 2203 | |
| 2204 | if (frameCountMax != 0) |
| 2205 | wait_input(true, true, true); |
| 2206 | |
| 2207 | fade_black(15); |
| 2208 | } |
| 2209 | |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | // increases game difficulty based on player's total score / total of players' scores |
| 2215 | void adjust_difficulty(void) |
| 2216 | { |
| 2217 | const float score_multiplier[10] = |
| 2218 | { |
| 2219 | 0, // Wimp (doesn't exist) |
| 2220 | 0.4f, // Easy |
| 2221 | 0.8f, // Normal |
| 2222 | 1.3f, // Hard |
| 2223 | 1.6f, // Impossible |
| 2224 | 2, // Insanity |
| 2225 | 2, // Suicide |
| 2226 | 3, // Maniacal |
| 2227 | 3, // Zinglon |
| 2228 | 3, // Nortaneous |
| 2229 | }; |
| 2230 | |
| 2231 | assert(initialDifficulty > 0 && initialDifficulty < 10); |
| 2232 | |
| 2233 | const ulong score = twoPlayerMode ? (player[0].cash + player[1].cash) : JE_totalScore(&player[0]), |
| 2234 | adjusted_score = roundf(score * score_multiplier[initialDifficulty]); |
| 2235 | |
| 2236 | uint new_difficulty = 0; |
| 2237 | |
| 2238 | if (twoPlayerMode) |
| 2239 | { |
| 2240 | if (adjusted_score < 10000) |
| 2241 | new_difficulty = DIFFICULTY_EASY; |
| 2242 | else if (adjusted_score < 20000) |
| 2243 | new_difficulty = DIFFICULTY_NORMAL; |
| 2244 | else if (adjusted_score < 50000) |
| 2245 | new_difficulty = DIFFICULTY_HARD; |
| 2246 | else if (adjusted_score < 80000) |
| 2247 | new_difficulty = DIFFICULTY_IMPOSSIBLE; |
| 2248 | else if (adjusted_score < 125000) |
| 2249 | new_difficulty = DIFFICULTY_INSANITY; |
| 2250 | else if (adjusted_score < 200000) |
| 2251 | new_difficulty = DIFFICULTY_SUICIDE; |
| 2252 | else if (adjusted_score < 400000) |
| 2253 | new_difficulty = DIFFICULTY_MANIACAL; |
| 2254 | else if (adjusted_score < 600000) |
| 2255 | new_difficulty = DIFFICULTY_ZINGLON; |
| 2256 | else |
| 2257 | new_difficulty = DIFFICULTY_NORTANEOUS; |
| 2258 | } |
| 2259 | else |
| 2260 | { |
| 2261 | if (adjusted_score < 40000) |
| 2262 | new_difficulty = DIFFICULTY_EASY; |
| 2263 | else if (adjusted_score < 70000) |
| 2264 | new_difficulty = DIFFICULTY_NORMAL; |
| 2265 | else if (adjusted_score < 150000) |
| 2266 | new_difficulty = DIFFICULTY_HARD; |
| 2267 | else if (adjusted_score < 300000) |
| 2268 | new_difficulty = DIFFICULTY_IMPOSSIBLE; |
| 2269 | else if (adjusted_score < 600000) |
| 2270 | new_difficulty = DIFFICULTY_INSANITY; |
| 2271 | else if (adjusted_score < 1000000) |
| 2272 | new_difficulty = DIFFICULTY_SUICIDE; |
| 2273 | else if (adjusted_score < 2000000) |
| 2274 | new_difficulty = DIFFICULTY_MANIACAL; |
| 2275 | else if (adjusted_score < 3000000) |
| 2276 | new_difficulty = DIFFICULTY_ZINGLON; |
| 2277 | else |
| 2278 | new_difficulty = DIFFICULTY_NORTANEOUS; |
| 2279 | } |
| 2280 | |
| 2281 | difficultyLevel = MAX((unsigned)difficultyLevel, new_difficulty); |
| 2282 | } |
| 2283 | |
| 2284 | bool load_next_demo(void) |
| 2285 | { |
| 2286 | if (++demo_num > 5) |
| 2287 | demo_num = 1; |
| 2288 | |
| 2289 | char demo_filename[9]; |
| 2290 | snprintf(demo_filename, sizeof(demo_filename), "demo.%d", demo_num); |
| 2291 | demo_file = dir_fopen_die(data_dir(), demo_filename, "rb"); // TODO: only play demos from existing file (instead of dying) |
| 2292 | |
| 2293 | difficultyLevel = DIFFICULTY_NORMAL; |
| 2294 | bonusLevelCurrent = false; |
| 2295 | |
| 2296 | Uint8 temp; |
| 2297 | fread_u8_die(&temp, 1, demo_file); |
| 2298 | JE_initEpisode(temp); |
| 2299 | |
| 2300 | fread_die(levelName, 1, 10, demo_file); |
| 2301 | levelName[10] = '\0'; |
| 2302 | |
| 2303 | fread_u8_die(&lvlFileNum, 1, demo_file); |
| 2304 | |
| 2305 | fread_u8_die(&player[0].items.weapon[FRONT_WEAPON].id, 1, demo_file); |
| 2306 | fread_u8_die(&player[0].items.weapon[REAR_WEAPON].id, 1, demo_file); |
| 2307 | fread_u8_die(&player[0].items.super_arcade_mode, 1, demo_file); |
| 2308 | fread_u8_die(&player[0].items.sidekick[LEFT_SIDEKICK], 1, demo_file); |
| 2309 | fread_u8_die(&player[0].items.sidekick[RIGHT_SIDEKICK], 1, demo_file); |
| 2310 | fread_u8_die(&player[0].items.generator, 1, demo_file); |
| 2311 | |
| 2312 | fread_u8_die(&player[0].items.sidekick_level, 1, demo_file); // could probably ignore |
| 2313 | fread_u8_die(&player[0].items.sidekick_series, 1, demo_file); // could probably ignore |
| 2314 | |
| 2315 | fread_u8_die(&initial_episode_num, 1, demo_file); // could probably ignore |
| 2316 | |
| 2317 | fread_u8_die(&player[0].items.shield, 1, demo_file); |
| 2318 | fread_u8_die(&player[0].items.special, 1, demo_file); |
| 2319 | fread_u8_die(&player[0].items.ship, 1, demo_file); |
| 2320 | |
| 2321 | for (uint i = 0; i < 2; ++i) |
| 2322 | fread_u8_die(&player[0].items.weapon[i].power, 1, demo_file); |
| 2323 | |
| 2324 | Uint8 unused[3]; |
| 2325 | fread_u8_die(unused, 3, demo_file); |
| 2326 | |
| 2327 | fread_u8_die(&levelSong, 1, demo_file); |
| 2328 | |
| 2329 | demo_keys = 0; |
| 2330 | |
| 2331 | Uint8 temp2[2] = { 0, 0 }; |
| 2332 | fread_u8(temp2, 2, demo_file); |
| 2333 | demo_keys_wait = (temp2[0] << 8) | temp2[1]; |
| 2334 | |
| 2335 | printf("loaded demo '%s'\n", demo_filename); |
| 2336 | |
| 2337 | return true; |
| 2338 | } |
| 2339 | |
| 2340 | bool replay_demo_keys(void) |
| 2341 | { |
| 2342 | while (demo_keys_wait == 0) |
| 2343 | { |
| 2344 | demo_keys = 0; |
| 2345 | fread_u8(&demo_keys, 1, demo_file); |
| 2346 | |
| 2347 | Uint8 temp2[2] = { 0, 0 }; |
| 2348 | fread_u8(temp2, 2, demo_file); |
| 2349 | demo_keys_wait = (temp2[0] << 8) | temp2[1]; |
| 2350 | |
| 2351 | if (feof(demo_file)) |
| 2352 | { |
| 2353 | // no more keys |
| 2354 | return false; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | demo_keys_wait--; |
| 2359 | |
| 2360 | if (demo_keys & (1 << 0)) |
| 2361 | player[0].y -= CURRENT_KEY_SPEED; |
| 2362 | if (demo_keys & (1 << 1)) |
| 2363 | player[0].y += CURRENT_KEY_SPEED; |
| 2364 | |
| 2365 | if (demo_keys & (1 << 2)) |
| 2366 | player[0].x -= CURRENT_KEY_SPEED; |
| 2367 | if (demo_keys & (1 << 3)) |
| 2368 | player[0].x += CURRENT_KEY_SPEED; |
| 2369 | |
| 2370 | button[0] = (bool)(demo_keys & (1 << 4)); |
| 2371 | button[3] = (bool)(demo_keys & (1 << 5)); |
| 2372 | button[1] = (bool)(demo_keys & (1 << 6)); |
| 2373 | button[2] = (bool)(demo_keys & (1 << 7)); |
| 2374 | |
| 2375 | return true; |
| 2376 | } |
| 2377 | |
| 2378 | /*Street Fighter codes*/ |
| 2379 | void JE_SFCodes(JE_byte playerNum_, JE_integer PX_, JE_integer PY_, JE_integer mouseX_, JE_integer mouseY_) |
| 2380 | { |
| 2381 | JE_byte temp, temp2, temp3, temp4, temp5; |
| 2382 | |
| 2383 | uint ship = player[playerNum_-1].items.ship; |
| 2384 | |
| 2385 | /*Get direction*/ |
| 2386 | if (playerNum_ == 2 && ship < 15) |
| 2387 | { |
| 2388 | ship = 0; |
| 2389 | } |
| 2390 | |
| 2391 | if (ship < 15) |
| 2392 | { |
| 2393 | |
| 2394 | temp2 = (mouseY_ > PY_) + /*UP*/ |
| 2395 | (mouseY_ < PY_) + /*DOWN*/ |
| 2396 | (PX_ < mouseX_) + /*LEFT*/ |
| 2397 | (PX_ > mouseX_); /*RIGHT*/ |
| 2398 | temp = (mouseY_ > PY_) * 1 + /*UP*/ |
| 2399 | (mouseY_ < PY_) * 2 + /*DOWN*/ |
| 2400 | (PX_ < mouseX_) * 3 + /*LEFT*/ |
| 2401 | (PX_ > mouseX_) * 4; /*RIGHT*/ |
| 2402 | |
| 2403 | if (temp == 0) // no direction being pressed |
| 2404 | { |
| 2405 | if (!button[0]) // if fire button is released |
| 2406 | { |
| 2407 | temp = 9; |
| 2408 | temp2 = 1; |
| 2409 | } |
| 2410 | else |
| 2411 | { |
| 2412 | temp2 = 0; |
| 2413 | temp = 99; |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | if (temp2 == 1) // if exactly one direction pressed or fire button is released |
| 2418 | { |
| 2419 | temp += button[0] * 4; |
| 2420 | |
| 2421 | temp3 = superTyrian ? 21 : 3; |
| 2422 | for (temp2 = 0; temp2 < temp3; temp2++) |
| 2423 | { |
| 2424 | |
| 2425 | /*Use SuperTyrian ShipCombos or not?*/ |
| 2426 | temp5 = superTyrian ? shipCombosB[temp2] : shipCombos[ship][temp2]; |
| 2427 | |
| 2428 | // temp5 == selected combo in ship |
| 2429 | if (temp5 == 0) /* combo doesn't exists */ |
| 2430 | { |
| 2431 | // mark twiddles as cancelled/finished |
| 2432 | SFCurrentCode[playerNum_-1][temp2] = 0; |
| 2433 | } |
| 2434 | else |
| 2435 | { |
| 2436 | // get next combo key |
| 2437 | temp4 = keyboardCombos[temp5-1][SFCurrentCode[playerNum_-1][temp2]]; |
| 2438 | |
| 2439 | // correct key |
| 2440 | if (temp4 == temp) |
| 2441 | { |
| 2442 | SFCurrentCode[playerNum_-1][temp2]++; |
| 2443 | |
| 2444 | temp4 = keyboardCombos[temp5-1][SFCurrentCode[playerNum_-1][temp2]]; |
| 2445 | if (temp4 > 100 && temp4 <= 100 + SPECIAL_NUM) |
| 2446 | { |
| 2447 | SFCurrentCode[playerNum_-1][temp2] = 0; |
| 2448 | SFExecuted[playerNum_-1] = temp4 - 100; |
| 2449 | } |
| 2450 | } |
| 2451 | else |
| 2452 | { |
| 2453 | if ((temp != 9) && |
| 2454 | (temp4 - 1) % 4 != (temp - 1) % 4 && |
| 2455 | (SFCurrentCode[playerNum_-1][temp2] == 0 || |
| 2456 | keyboardCombos[temp5-1][SFCurrentCode[playerNum_-1][temp2]-1] != temp)) |
| 2457 | { |
| 2458 | SFCurrentCode[playerNum_-1][temp2] = 0; |
| 2459 | } |
| 2460 | } |
| 2461 | } |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | void JE_sort(void) |
| 2469 | { |
| 2470 | JE_byte a, b; |
| 2471 | |
| 2472 | for (a = 0; a < 2; a++) |
| 2473 | { |
| 2474 | for (b = a + 1; b < 3; b++) |
| 2475 | { |
| 2476 | if (saveFiles[temp + a].highScore1 < saveFiles[temp + b].highScore1) |
| 2477 | { |
| 2478 | JE_longint tempLI; |
| 2479 | char tempStr[30]; |
| 2480 | JE_byte tempByte; |
| 2481 | |
| 2482 | tempLI = saveFiles[temp + a].highScore1; |
| 2483 | saveFiles[temp + a].highScore1 = saveFiles[temp + b].highScore1; |
| 2484 | saveFiles[temp + b].highScore1 = tempLI; |
| 2485 | |
| 2486 | strcpy(tempStr, saveFiles[temp + a].highScoreName); |
| 2487 | strcpy(saveFiles[temp + a].highScoreName, saveFiles[temp + b].highScoreName); |
| 2488 | strcpy(saveFiles[temp + b].highScoreName, tempStr); |
| 2489 | |
| 2490 | tempByte = saveFiles[temp + a].highScoreDiff; |
| 2491 | saveFiles[temp + a].highScoreDiff = saveFiles[temp + b].highScoreDiff; |
| 2492 | saveFiles[temp + b].highScoreDiff = tempByte; |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | void JE_playCredits(void) |
| 2499 | { |
| 2500 | enum { lines_max = 131 }; |
| 2501 | enum { line_max_length = 65 }; |
| 2502 | |
| 2503 | char credstr[lines_max][line_max_length + 1]; |
| 2504 | |
| 2505 | int lines = 0; |
| 2506 | |
| 2507 | JE_byte currentpic = 0, fade = 0; |
| 2508 | JE_shortint fadechg = 1; |
| 2509 | JE_byte currentship = 0; |
| 2510 | JE_integer shipx = 0, shipxwait = 0; |
| 2511 | JE_shortint shipxc = 0, shipxca = 0; |
| 2512 | |
| 2513 | load_sprites_file(EXTRA_SHAPES, "estsc.shp"); |
| 2514 | |
| 2515 | setDelay2(1000); |
| 2516 | |
| 2517 | play_song(8); |
| 2518 | |
| 2519 | // load credits text |
| 2520 | FILE *f = dir_fopen_die(data_dir(), "tyrian.cdt", "rb"); |
| 2521 | for (lines = 0; lines < lines_max; ++lines) |
| 2522 | { |
| 2523 | read_encrypted_pascal_string(credstr[lines], sizeof(credstr[lines]), f); |
| 2524 | } |
| 2525 | fclose(f); |
| 2526 | |
| 2527 | memcpy(colors, palettes[6-1], sizeof(colors)); |
| 2528 | JE_clr256(VGAScreen); |
| 2529 | JE_showVGA(); |
| 2530 | fade_palette(colors, 2, 0, 255); |
| 2531 | |
| 2532 | //tempScreenSeg = VGAScreenSeg; |
| 2533 | |
| 2534 | const int ticks_max = lines * 20 * 3; |
| 2535 | for (int ticks = 0; ticks < ticks_max; ++ticks) |
| 2536 | { |
| 2537 | setDelay(1); |
| 2538 | JE_clr256(VGAScreen); |
| 2539 | |
| 2540 | blit_sprite_hv(VGAScreenSeg, 319 - sprite(EXTRA_SHAPES, currentpic)->width, 100 - (sprite(EXTRA_SHAPES, currentpic)->height / 2), EXTRA_SHAPES, currentpic, 0x0, fade - 15); |
| 2541 | |
| 2542 | fade += fadechg; |
| 2543 | if (fade == 0 && fadechg == -1) |
| 2544 | { |
| 2545 | fadechg = 1; |
| 2546 | ++currentpic; |
| 2547 | if (currentpic >= sprite_table[EXTRA_SHAPES].count) |
| 2548 | currentpic = 0; |
| 2549 | } |
| 2550 | if (fade == 15) |
| 2551 | fadechg = 0; |
| 2552 | |
| 2553 | if (getDelayTicks2() == 0) |
| 2554 | { |
| 2555 | fadechg = -1; |
| 2556 | setDelay2(900); |
| 2557 | } |
| 2558 | |
| 2559 | if (ticks % 200 == 0) |
| 2560 | { |
| 2561 | currentship = (mt_rand() % 11) + 1; |
| 2562 | shipxwait = (mt_rand() % 80) + 10; |
| 2563 | if ((mt_rand() % 2) == 1) |
| 2564 | { |
| 2565 | shipx = 1; |
| 2566 | shipxc = 0; |
| 2567 | shipxca = 1; |
| 2568 | } |
| 2569 | else |
| 2570 | { |
| 2571 | shipx = 900; |
| 2572 | shipxc = 0; |
| 2573 | shipxca = -1; |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | shipxwait--; |
| 2578 | if (shipxwait == 0) |
| 2579 | { |
| 2580 | if (shipx == 1 || shipx == 900) |
| 2581 | shipxc = 0; |
| 2582 | shipxca = -shipxca; |
| 2583 | shipxwait = (mt_rand() % 40) + 15; |
| 2584 | } |
| 2585 | shipxc += shipxca; |
| 2586 | shipx += shipxc; |
| 2587 | if (shipx < 1) |
| 2588 | { |
| 2589 | shipx = 1; |
| 2590 | shipxwait = 1; |
| 2591 | } |
| 2592 | if (shipx > 900) |
| 2593 | { |
| 2594 | shipx = 900; |
| 2595 | shipxwait = 1; |
| 2596 | } |
| 2597 | int tmp_unknown = shipxc * shipxc; |
| 2598 | if (450 + tmp_unknown < 0 || 450 + tmp_unknown > 900) |
| 2599 | { |
| 2600 | if (shipxca < 0 && shipxc < 0) |
| 2601 | shipxwait = 1; |
| 2602 | if (shipxca > 0 && shipxc > 0) |
| 2603 | shipxwait = 1; |
| 2604 | } |
| 2605 | |
| 2606 | uint ship_sprite = ships[currentship].shipgraphic; |
| 2607 | if (shipxc < -10) |
| 2608 | ship_sprite -= (shipxc < -20) ? 4 : 2; |
| 2609 | else if (shipxc > 10) |
| 2610 | ship_sprite += (shipxc > 20) ? 4 : 2; |
| 2611 | |
| 2612 | blit_sprite2x2(VGAScreen, shipx / 40, 184 - (ticks % 200), spriteSheet9, ship_sprite); |
| 2613 | |
| 2614 | const int bottom_line = (ticks / 3) / 20; |
| 2615 | int y = 20 - ((ticks / 3) % 20); |
| 2616 | |
| 2617 | for (int line = bottom_line - 10; line < bottom_line; ++line) |
| 2618 | { |
| 2619 | if (line >= 0 && line < lines_max) |
| 2620 | { |
| 2621 | if (strcmp(&credstr[line][0], ".") != 0 && strlen(credstr[line])) |
| 2622 | { |
| 2623 | const Uint8 color = credstr[line][0] - 65; |
| 2624 | const char *text = &credstr[line][1]; |
| 2625 | |
| 2626 | const int x = 110 - JE_textWidth(text, SMALL_FONT_SHAPES) / 2; |
| 2627 | |
| 2628 | JE_outTextAdjust(VGAScreen, x + abs((y / 18) % 4 - 2) - 1, y - 1, text, color, -8, SMALL_FONT_SHAPES, false); |
| 2629 | JE_outTextAdjust(VGAScreen, x, y, text, color, -2, SMALL_FONT_SHAPES, false); |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | y += 20; |
| 2634 | } |
| 2635 | |
| 2636 | fill_rectangle_xy(VGAScreen, 0, 0, 319, 10, 0); |
| 2637 | fill_rectangle_xy(VGAScreen, 0, 190, 319, 199, 0); |
| 2638 | |
| 2639 | if (currentpic == sprite_table[EXTRA_SHAPES].count - 1) |
| 2640 | JE_outTextAdjust(VGAScreen, 5, 180, miscText[54], 2, -2, SMALL_FONT_SHAPES, false); // levels-in-episode |
| 2641 | |
| 2642 | if (bottom_line == lines_max - 8) |
| 2643 | fade_song(); |
| 2644 | |
| 2645 | if (ticks == ticks_max - 1) |
| 2646 | { |
| 2647 | --ticks; |
| 2648 | play_song(9); |
| 2649 | } |
| 2650 | |
| 2651 | NETWORK_KEEP_ALIVE(); |
| 2652 | |
| 2653 | JE_showVGA(); |
| 2654 | |
| 2655 | wait_delay(); |
| 2656 | |
| 2657 | if (JE_anyButton()) |
| 2658 | break; |
| 2659 | } |
| 2660 | |
| 2661 | fade_black(10); |
| 2662 | |
| 2663 | free_sprites(EXTRA_SHAPES); |
| 2664 | } |
| 2665 | |
| 2666 | void JE_endLevelAni(void) |
| 2667 | { |
| 2668 | JE_word x, y; |
| 2669 | JE_byte temp; |
| 2670 | char tempStr[256]; |
| 2671 | |
| 2672 | Sint8 i; |
| 2673 | |
| 2674 | if (!constantPlay) |
| 2675 | { |
| 2676 | // grant shipedit privileges |
| 2677 | |
| 2678 | // special |
| 2679 | if (player[0].items.special < 21) |
| 2680 | saveTemp[SAVE_FILES_SIZE + 81 + player[0].items.special] = 1; |
| 2681 | |
| 2682 | for (uint p = 0; p < COUNTOF(player); ++p) |
| 2683 | { |
| 2684 | // front, rear |
| 2685 | for (uint i = 0; i < COUNTOF(player[p].items.weapon); ++i) |
| 2686 | saveTemp[SAVE_FILES_SIZE + player[p].items.weapon[i].id] = 1; |
| 2687 | |
| 2688 | // options |
| 2689 | for (uint i = 0; i < COUNTOF(player[p].items.sidekick); ++i) |
| 2690 | saveTemp[SAVE_FILES_SIZE + 51 + player[p].items.sidekick[i]] = 1; |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | adjust_difficulty(); |
| 2695 | |
| 2696 | player[0].last_items = player[0].items; |
| 2697 | strcpy(lastLevelName, levelName); |
| 2698 | |
| 2699 | JE_wipeKey(); |
| 2700 | frameCountMax = 4; |
| 2701 | textGlowFont = SMALL_FONT_SHAPES; |
| 2702 | |
| 2703 | SDL_Color white = { 255, 255, 255 }; |
| 2704 | set_colors(white, 254, 254); |
| 2705 | |
| 2706 | if (!levelTimer || levelTimerCountdown > 0 || !(episodeNum == 4)) |
| 2707 | JE_playSampleNum(V_LEVEL_END); |
| 2708 | else |
| 2709 | play_song(21); |
| 2710 | |
| 2711 | if (bonusLevel) |
| 2712 | { |
| 2713 | JE_outTextGlow(VGAScreenSeg, 20, 20, miscText[17-1]); |
| 2714 | } |
| 2715 | else if (all_players_alive()) |
| 2716 | { |
| 2717 | sprintf(tempStr, "%s %s", miscText[27-1], levelName); // "Completed" |
| 2718 | JE_outTextGlow(VGAScreenSeg, 20, 20, tempStr); |
| 2719 | } |
| 2720 | else |
| 2721 | { |
| 2722 | sprintf(tempStr, "%s %s", miscText[62-1], levelName); // "Exiting" |
| 2723 | JE_outTextGlow(VGAScreenSeg, 20, 20, tempStr); |
| 2724 | } |
| 2725 | |
| 2726 | if (twoPlayerMode) |
| 2727 | { |
| 2728 | for (uint i = 0; i < 2; ++i) |
| 2729 | { |
| 2730 | snprintf(tempStr, sizeof(tempStr), "%s %lu", miscText[40 + i], player[i].cash); |
| 2731 | JE_outTextGlow(VGAScreenSeg, 30, 50 + 20 * i, tempStr); |
| 2732 | } |
| 2733 | } |
| 2734 | else |
| 2735 | { |
| 2736 | sprintf(tempStr, "%s %lu", miscText[28-1], player[0].cash); |
| 2737 | JE_outTextGlow(VGAScreenSeg, 30, 50, tempStr); |
| 2738 | } |
| 2739 | |
| 2740 | temp = (totalEnemy == 0) ? 0 : roundf(enemyKilled * 100 / totalEnemy); |
| 2741 | sprintf(tempStr, "%s %d%%", miscText[63-1], temp); |
| 2742 | JE_outTextGlow(VGAScreenSeg, 40, 90, tempStr); |
| 2743 | |
| 2744 | if (!constantPlay) |
| 2745 | editorLevel += temp / 5; |
| 2746 | |
| 2747 | if (!onePlayerAction && !twoPlayerMode) |
| 2748 | { |
| 2749 | JE_outTextGlow(VGAScreenSeg, 30, 120, miscText[4-1]); /*Cubes*/ |
| 2750 | |
| 2751 | if (cubeMax > 0) |
| 2752 | { |
| 2753 | if (cubeMax > 4) |
| 2754 | cubeMax = 4; |
| 2755 | |
| 2756 | if (frameCountMax != 0) |
| 2757 | frameCountMax = 1; |
| 2758 | |
| 2759 | for (temp = 1; temp <= cubeMax; temp++) |
| 2760 | { |
| 2761 | NETWORK_KEEP_ALIVE(); |
| 2762 | |
| 2763 | JE_playSampleNum(S_ITEM); |
| 2764 | x = 20 + 30 * temp; |
| 2765 | y = 135; |
| 2766 | JE_drawCube(VGAScreenSeg, x, y, 9, 0); |
| 2767 | JE_showVGA(); |
| 2768 | |
| 2769 | for (i = -15; i <= 10; i++) |
| 2770 | { |
| 2771 | setDelay(frameCountMax); |
| 2772 | |
| 2773 | blit_sprite_hv(VGAScreenSeg, x, y, OPTION_SHAPES, 25, 0x9, i); |
| 2774 | |
| 2775 | if (JE_anyButton()) |
| 2776 | frameCountMax = 0; |
| 2777 | |
| 2778 | JE_showVGA(); |
| 2779 | |
| 2780 | wait_delay(); |
| 2781 | } |
| 2782 | for (i = 10; i >= 0; i--) |
| 2783 | { |
| 2784 | setDelay(frameCountMax); |
| 2785 | |
| 2786 | blit_sprite_hv(VGAScreenSeg, x, y, OPTION_SHAPES, 25, 0x9, i); |
| 2787 | |
| 2788 | if (JE_anyButton()) |
| 2789 | frameCountMax = 0; |
| 2790 | |
| 2791 | JE_showVGA(); |
| 2792 | |
| 2793 | wait_delay(); |
| 2794 | } |
| 2795 | } |
| 2796 | } |
| 2797 | else |
| 2798 | { |
| 2799 | JE_outTextGlow(VGAScreenSeg, 50, 135, miscText[15-1]); |
| 2800 | } |
| 2801 | |
| 2802 | } |
| 2803 | |
| 2804 | if (frameCountMax != 0) |
| 2805 | { |
| 2806 | frameCountMax = 6; |
| 2807 | temp = 1; |
| 2808 | } |
| 2809 | else |
| 2810 | { |
| 2811 | temp = 0; |
| 2812 | } |
| 2813 | temp2 = twoPlayerMode ? 150 : 160; |
| 2814 | JE_outTextGlow(VGAScreenSeg, 90, temp2, miscText[5-1]); |
| 2815 | |
| 2816 | if (!constantPlay) |
| 2817 | { |
| 2818 | do |
| 2819 | { |
| 2820 | setDelay(1); |
| 2821 | |
| 2822 | NETWORK_KEEP_ALIVE(); |
| 2823 | |
| 2824 | wait_delay(); |
| 2825 | } while (!(JE_anyButton() || (frameCountMax == 0 && temp == 1))); |
| 2826 | } |
| 2827 | |
| 2828 | wait_noinput(false, false, true); // TODO: should up the joystick repeat temporarily instead |
| 2829 | |
| 2830 | fade_black(15); |
| 2831 | JE_clr256(VGAScreen); |
| 2832 | } |
| 2833 | |
| 2834 | void JE_drawCube(SDL_Surface * screen, JE_word x, JE_word y, JE_byte filter, JE_byte brightness) |
| 2835 | { |
| 2836 | blit_sprite_dark(screen, x + 4, y + 4, OPTION_SHAPES, 25, false); |
| 2837 | blit_sprite_dark(screen, x + 3, y + 3, OPTION_SHAPES, 25, false); |
| 2838 | blit_sprite_hv(screen, x, y, OPTION_SHAPES, 25, filter, brightness); |
| 2839 | } |
| 2840 | |
| 2841 | void JE_handleChat(void) |
| 2842 | { |
| 2843 | // STUB(); Annoying piece of crap =P |
| 2844 | } |
| 2845 | |
| 2846 | bool str_pop_int(char *str, int *val) |
| 2847 | { |
| 2848 | bool success = false; |
| 2849 | |
| 2850 | char buf[256]; |
| 2851 | assert(strlen(str) < sizeof(buf)); |
| 2852 | |
| 2853 | // grab the value from str |
| 2854 | char *end; |
| 2855 | *val = strtol(str, &end, 10); |
| 2856 | |
| 2857 | if (end != str) |
| 2858 | { |
| 2859 | success = true; |
| 2860 | |
| 2861 | // shift the rest to the beginning |
| 2862 | strcpy(buf, end); |
| 2863 | strcpy(str, buf); |
| 2864 | } |
| 2865 | |
| 2866 | return success; |
| 2867 | } |
| 2868 | |
| 2869 | void JE_operation(JE_byte slot) |
| 2870 | { |
| 2871 | JE_byte flash; |
| 2872 | char stemp[21]; |
| 2873 | char tempStr[51]; |
| 2874 | |
| 2875 | if (!performSave) |
| 2876 | { |
| 2877 | if (saveFiles[slot-1].level > 0) |
| 2878 | { |
| 2879 | gameJustLoaded = true; |
| 2880 | JE_loadGame(slot); |
| 2881 | gameLoaded = true; |
| 2882 | } |
| 2883 | } |
| 2884 | else if (slot % 11 != 0) |
| 2885 | { |
| 2886 | strcpy(stemp, " "); |
| 2887 | memcpy(stemp, saveFiles[slot-1].name, strlen(saveFiles[slot-1].name)); |
| 2888 | temp = strlen(stemp); |
| 2889 | while (stemp[temp-1] == ' ' && --temp); |
| 2890 | |
| 2891 | flash = 8 * 16 + 10; |
| 2892 | |
| 2893 | wait_noinput(false, true, false); |
| 2894 | |
| 2895 | JE_barShade(VGAScreen, 65, 55, 255, 155); |
| 2896 | |
| 2897 | bool quit = false; |
| 2898 | while (!quit) |
| 2899 | { |
| 2900 | service_SDL_events(true); |
| 2901 | |
| 2902 | blit_sprite(VGAScreen, 50, 50, OPTION_SHAPES, 35); // message box |
| 2903 | |
| 2904 | JE_textShade(VGAScreen, 60, 55, miscText[1-1], 11, 4, DARKEN); |
| 2905 | JE_textShade(VGAScreen, 70, 70, levelName, 11, 4, DARKEN); |
| 2906 | |
| 2907 | do |
| 2908 | { |
| 2909 | flash = (flash == 8 * 16 + 10) ? 8 * 16 + 2 : 8 * 16 + 10; |
| 2910 | temp3 = (temp3 == 6) ? 2 : 6; |
| 2911 | |
| 2912 | strcpy(tempStr, miscText[2-1]); |
| 2913 | strncat(tempStr, stemp, temp); |
| 2914 | JE_outText(VGAScreen, 65, 89, tempStr, 8, 3); |
| 2915 | tempW = 65 + JE_textWidth(tempStr, TINY_FONT); |
| 2916 | JE_barShade(VGAScreen, tempW + 2, 90, tempW + 6, 95); |
| 2917 | fill_rectangle_xy(VGAScreen, tempW + 1, 89, tempW + 5, 94, flash); |
| 2918 | |
| 2919 | int text_x = 54 + 45 - (JE_textWidth(miscText[9], FONT_SHAPES) / 2); |
| 2920 | JE_outTextAdjust(VGAScreen, text_x, 128, miscText[9], 15, -5, FONT_SHAPES, true); |
| 2921 | |
| 2922 | text_x = 149 + 45 - (JE_textWidth(miscText[10], FONT_SHAPES) / 2); |
| 2923 | JE_outTextAdjust(VGAScreen, text_x, 128, miscText[10], 15, -5, FONT_SHAPES, true); |
| 2924 | |
| 2925 | for (int i = 0; i < 14; i++) |
| 2926 | { |
| 2927 | setDelay(1); |
| 2928 | |
| 2929 | push_joysticks_as_keyboard(); |
| 2930 | service_wait_delay(); |
| 2931 | |
| 2932 | JE_mouseStart(); |
| 2933 | JE_showVGA(); |
| 2934 | JE_mouseReplace(); |
| 2935 | |
| 2936 | if (newkey || newmouse || new_text) |
| 2937 | break; |
| 2938 | } |
| 2939 | } while (!newkey && !newmouse && !new_text); |
| 2940 | |
| 2941 | if (mouseButton > 0) |
| 2942 | { |
| 2943 | if (lastmouse_x > 56 && lastmouse_x < 142 && lastmouse_y > 123 && lastmouse_y < 149) |
| 2944 | { |
| 2945 | quit = true; |
| 2946 | JE_saveGame(slot, stemp); |
| 2947 | JE_playSampleNum(S_SELECT); |
| 2948 | } |
| 2949 | else if (lastmouse_x > 151 && lastmouse_x < 237 && lastmouse_y > 123 && lastmouse_y < 149) |
| 2950 | { |
| 2951 | quit = true; |
| 2952 | JE_playSampleNum(S_SPRING); |
| 2953 | } |
| 2954 | } |
| 2955 | else if (new_text) |
| 2956 | { |
| 2957 | for (size_t ti = 0U; last_text[ti] != '\0'; ++ti) |
| 2958 | { |
| 2959 | const char c = (unsigned char)last_text[ti] <= 127U ? toupper(last_text[ti]) : 0; |
| 2960 | if ((c == ' ' || font_ascii[(unsigned char)c] != -1) && |
| 2961 | temp < 14) |
| 2962 | { |
| 2963 | JE_playSampleNum(S_CURSOR); |
| 2964 | stemp[temp] = c; |
| 2965 | temp += 1; |
| 2966 | } |
| 2967 | } |
| 2968 | } |
| 2969 | else if (newkey) |
| 2970 | { |
| 2971 | switch (lastkey_scan) |
| 2972 | { |
| 2973 | case SDL_SCANCODE_BACKSPACE: |
| 2974 | case SDL_SCANCODE_DELETE: |
| 2975 | if (temp) |
| 2976 | { |
| 2977 | temp--; |
| 2978 | stemp[temp] = ' '; |
| 2979 | JE_playSampleNum(S_CLICK); |
| 2980 | } |
| 2981 | break; |
| 2982 | case SDL_SCANCODE_ESCAPE: |
| 2983 | quit = true; |
| 2984 | JE_playSampleNum(S_SPRING); |
| 2985 | break; |
| 2986 | case SDL_SCANCODE_RETURN: |
| 2987 | quit = true; |
| 2988 | JE_saveGame(slot, stemp); |
| 2989 | JE_playSampleNum(S_SELECT); |
| 2990 | break; |
| 2991 | default: |
| 2992 | break; |
| 2993 | } |
| 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | wait_noinput(false, true, false); |
| 2999 | } |
| 3000 | |
| 3001 | void JE_inGameDisplays(void) |
| 3002 | { |
| 3003 | char stemp[21]; |
| 3004 | char tempstr[256]; |
| 3005 | |
| 3006 | for (uint i = 0; i < ((twoPlayerMode && !galagaMode) ? 2 : 1); ++i) |
| 3007 | { |
| 3008 | snprintf(tempstr, sizeof(tempstr), "%lu", player[i].cash); |
| 3009 | JE_textShade(VGAScreen, 30 + 200 * i, 175, tempstr, 2, 4, FULL_SHADE); |
| 3010 | } |
| 3011 | |
| 3012 | /*Special Weapon?*/ |
| 3013 | if (player[0].items.special > 0) |
| 3014 | blit_sprite2x2(VGAScreen, 25, 1, spriteSheet10, special[player[0].items.special].itemgraphic); |
| 3015 | |
| 3016 | /*Lives Left*/ |
| 3017 | if (onePlayerAction || twoPlayerMode) |
| 3018 | { |
| 3019 | for (int temp = 0; temp < (onePlayerAction ? 1 : 2); temp++) |
| 3020 | { |
| 3021 | const uint extra_lives = *player[temp].lives - 1; |
| 3022 | |
| 3023 | int y = (temp == 0 && player[0].items.special > 0) ? 35 : 15; |
| 3024 | tempW = (temp == 0) ? 30: 270; |
| 3025 | |
| 3026 | if (extra_lives >= 5) |
| 3027 | { |
| 3028 | blit_sprite2(VGAScreen, tempW, y, spriteSheet9, 285); |
| 3029 | tempW = (temp == 0) ? 45 : 250; |
| 3030 | sprintf(tempstr, "%d", extra_lives); |
| 3031 | JE_textShade(VGAScreen, tempW, y + 3, tempstr, 15, 1, FULL_SHADE); |
| 3032 | } |
| 3033 | else if (extra_lives >= 1) |
| 3034 | { |
| 3035 | for (uint i = 0; i < extra_lives; ++i) |
| 3036 | { |
| 3037 | blit_sprite2(VGAScreen, tempW, y, spriteSheet9, 285); |
| 3038 | |
| 3039 | tempW += (temp == 0) ? 12 : -12; |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | strcpy(stemp, (temp == 0) ? miscText[49-1] : miscText[50-1]); |
| 3044 | if (isNetworkGame) |
| 3045 | { |
| 3046 | strcpy(stemp, JE_getName(temp+1)); |
| 3047 | } |
| 3048 | |
| 3049 | tempW = (temp == 0) ? 28 : (285 - JE_textWidth(stemp, TINY_FONT)); |
| 3050 | JE_textShade(VGAScreen, tempW, y - 7, stemp, 2, 6, FULL_SHADE); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | /*Super Bombs!!*/ |
| 3055 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 3056 | { |
| 3057 | int x = (i == 0) ? 30 : 270; |
| 3058 | |
| 3059 | for (uint j = player[i].superbombs; j > 0; --j) |
| 3060 | { |
| 3061 | blit_sprite2(VGAScreen, x, 160, spriteSheet9, 304); |
| 3062 | x += (i == 0) ? 12 : -12; |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | if (youAreCheating) |
| 3067 | { |
| 3068 | JE_outText(VGAScreen, 90, 170, "Cheaters always prosper.", 3, 4); |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | void JE_mainKeyboardInput(void) |
| 3073 | { |
| 3074 | JE_gammaCheck(); |
| 3075 | |
| 3076 | /* { Network Request Commands } */ |
| 3077 | |
| 3078 | if (!isNetworkGame) |
| 3079 | { |
| 3080 | /* { Edited Ships } for Player 1 */ |
| 3081 | if (extraAvail && keysactive[SDL_SCANCODE_TAB] && !isNetworkGame && !superTyrian) |
| 3082 | { |
| 3083 | for (x = SDL_SCANCODE_1; x <= SDL_SCANCODE_0; x++) |
| 3084 | { |
| 3085 | if (keysactive[x]) |
| 3086 | { |
| 3087 | int z = x - SDL_SCANCODE_1 + 1; |
| 3088 | player[0].items.ship = 90 + z; /*Ships*/ |
| 3089 | z = (z - 1) * 15; |
| 3090 | player[0].items.weapon[FRONT_WEAPON].id = extraShips[z + 1]; |
| 3091 | player[0].items.weapon[REAR_WEAPON].id = extraShips[z + 2]; |
| 3092 | player[0].items.special = extraShips[z + 3]; |
| 3093 | player[0].items.sidekick[LEFT_SIDEKICK] = extraShips[z + 4]; |
| 3094 | player[0].items.sidekick[RIGHT_SIDEKICK] = extraShips[z + 5]; |
| 3095 | player[0].items.generator = extraShips[z + 6]; |
| 3096 | /*Armor*/ |
| 3097 | player[0].items.shield = extraShips[z + 8]; |
| 3098 | memset(shotMultiPos, 0, sizeof(shotMultiPos)); |
| 3099 | |
| 3100 | if (player[0].weapon_mode > JE_portConfigs()) |
| 3101 | player[0].weapon_mode = 1; |
| 3102 | |
| 3103 | tempW = player[0].armor; |
| 3104 | JE_getShipInfo(); |
| 3105 | if (player[0].armor > tempW && editShip1) |
| 3106 | player[0].armor = tempW; |
| 3107 | else |
| 3108 | editShip1 = true; |
| 3109 | |
| 3110 | SDL_Surface *temp_surface = VGAScreen; |
| 3111 | VGAScreen = VGAScreenSeg; |
| 3112 | JE_wipeShieldArmorBars(); |
| 3113 | JE_drawArmor(); |
| 3114 | JE_drawShield(); |
| 3115 | VGAScreen = temp_surface; |
| 3116 | JE_drawOptions(); |
| 3117 | |
| 3118 | keysactive[x] = false; |
| 3119 | } |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | /* for Player 2 */ |
| 3124 | if (extraAvail && keysactive[SDL_SCANCODE_CAPSLOCK] && !isNetworkGame && !superTyrian) |
| 3125 | { |
| 3126 | for (x = SDL_SCANCODE_1; x <= SDL_SCANCODE_0; x++) |
| 3127 | { |
| 3128 | if (keysactive[x]) |
| 3129 | { |
| 3130 | int z = x - SDL_SCANCODE_1 + 1; |
| 3131 | player[1].items.ship = 90 + z; |
| 3132 | z = (z - 1) * 15; |
| 3133 | player[1].items.weapon[FRONT_WEAPON].id = extraShips[z + 1]; |
| 3134 | player[1].items.weapon[REAR_WEAPON].id = extraShips[z + 2]; |
| 3135 | player[1].items.special = extraShips[z + 3]; |
| 3136 | player[1].items.sidekick[LEFT_SIDEKICK] = extraShips[z + 4]; |
| 3137 | player[1].items.sidekick[RIGHT_SIDEKICK] = extraShips[z + 5]; |
| 3138 | player[1].items.generator = extraShips[z + 6]; |
| 3139 | /*Armor*/ |
| 3140 | player[1].items.shield = extraShips[z + 8]; |
| 3141 | memset(shotMultiPos, 0, sizeof(shotMultiPos)); |
| 3142 | |
| 3143 | if (player[1].weapon_mode > JE_portConfigs()) |
| 3144 | player[1].weapon_mode = 1; |
| 3145 | |
| 3146 | tempW = player[1].armor; |
| 3147 | JE_getShipInfo(); |
| 3148 | if (player[1].armor > tempW && editShip2) |
| 3149 | player[1].armor = tempW; |
| 3150 | else |
| 3151 | editShip2 = true; |
| 3152 | |
| 3153 | SDL_Surface *temp_surface = VGAScreen; |
| 3154 | VGAScreen = VGAScreenSeg; |
| 3155 | JE_wipeShieldArmorBars(); |
| 3156 | JE_drawArmor(); |
| 3157 | JE_drawShield(); |
| 3158 | VGAScreen = temp_surface; |
| 3159 | JE_drawOptions(); |
| 3160 | |
| 3161 | keysactive[x] = false; |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | /* { In-Game Help } */ |
| 3168 | if (keysactive[SDL_SCANCODE_F1]) |
| 3169 | { |
| 3170 | if (isNetworkGame) |
| 3171 | { |
| 3172 | helpRequest = true; |
| 3173 | } |
| 3174 | else |
| 3175 | { |
| 3176 | JE_inGameHelp(); |
| 3177 | skipStarShowVGA = true; |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | /* {!Activate Nort Ship!} */ |
| 3182 | if (keysactive[SDL_SCANCODE_F2] && keysactive[SDL_SCANCODE_F4] && keysactive[SDL_SCANCODE_F6] && keysactive[SDL_SCANCODE_F7] && |
| 3183 | keysactive[SDL_SCANCODE_F9] && keysactive[SDL_SCANCODE_BACKSLASH] && keysactive[SDL_SCANCODE_SLASH]) |
| 3184 | { |
| 3185 | if (isNetworkGame) |
| 3186 | { |
| 3187 | nortShipRequest = true; |
| 3188 | } |
| 3189 | else |
| 3190 | { |
| 3191 | player[0].items.ship = 12; // Nort Ship |
| 3192 | player[0].items.special = 13; // Astral Zone |
| 3193 | player[0].items.weapon[FRONT_WEAPON].id = 36; // NortShip Super Pulse |
| 3194 | player[0].items.weapon[REAR_WEAPON].id = 37; // NortShip Spreader |
| 3195 | shipGr = 1; |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | /* {Cheating} */ |
| 3200 | if (!isNetworkGame && !twoPlayerMode && !superTyrian && superArcadeMode == SA_NONE) |
| 3201 | { |
| 3202 | if (keysactive[SDL_SCANCODE_F2] && keysactive[SDL_SCANCODE_F3] && keysactive[SDL_SCANCODE_F6]) |
| 3203 | { |
| 3204 | youAreCheating = !youAreCheating; |
| 3205 | keysactive[SDL_SCANCODE_F2] = false; |
| 3206 | } |
| 3207 | |
| 3208 | if (keysactive[SDL_SCANCODE_F2] && keysactive[SDL_SCANCODE_F3] && (keysactive[SDL_SCANCODE_F4] || keysactive[SDL_SCANCODE_F5])) |
| 3209 | { |
| 3210 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 3211 | player[i].armor = 0; |
| 3212 | |
| 3213 | youAreCheating = !youAreCheating; |
| 3214 | JE_drawTextWindow(miscText[63-1]); |
| 3215 | } |
| 3216 | |
| 3217 | if (constantPlay && keysactive[SDL_SCANCODE_C]) |
| 3218 | { |
| 3219 | youAreCheating = !youAreCheating; |
| 3220 | keysactive[SDL_SCANCODE_C] = false; |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | if (superTyrian) |
| 3225 | { |
| 3226 | youAreCheating = false; |
| 3227 | } |
| 3228 | |
| 3229 | /* {Personal Commands} */ |
| 3230 | |
| 3231 | /* {DEBUG} */ |
| 3232 | if (keysactive[SDL_SCANCODE_F10] && keysactive[SDL_SCANCODE_BACKSPACE]) |
| 3233 | { |
| 3234 | keysactive[SDL_SCANCODE_F10] = false; |
| 3235 | debug = !debug; |
| 3236 | |
| 3237 | debugHist = 1; |
| 3238 | debugHistCount = 1; |
| 3239 | |
| 3240 | /* YKS: clock ticks since midnight replaced by SDL_GetTicks */ |
| 3241 | lastDebugTime = SDL_GetTicks(); |
| 3242 | } |
| 3243 | |
| 3244 | /* {CHEAT-SKIP LEVEL} */ |
| 3245 | if (keysactive[SDL_SCANCODE_F2] && keysactive[SDL_SCANCODE_F6] && (keysactive[SDL_SCANCODE_F7] || keysactive[SDL_SCANCODE_F8]) && !keysactive[SDL_SCANCODE_F9] && |
| 3246 | !superTyrian && superArcadeMode == SA_NONE) |
| 3247 | { |
| 3248 | if (isNetworkGame) |
| 3249 | { |
| 3250 | skipLevelRequest = true; |
| 3251 | } |
| 3252 | else |
| 3253 | { |
| 3254 | levelTimer = true; |
| 3255 | levelTimerCountdown = 0; |
| 3256 | endLevel = true; |
| 3257 | levelEnd = 40; |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | /* pause game */ |
| 3262 | pause_pressed = pause_pressed || keysactive[SDL_SCANCODE_P]; |
| 3263 | |
| 3264 | /* in-game setup */ |
| 3265 | ingamemenu_pressed = ingamemenu_pressed || keysactive[SDL_SCANCODE_ESCAPE]; |
| 3266 | |
| 3267 | if (keysactive[SDL_SCANCODE_BACKSPACE]) |
| 3268 | { |
| 3269 | /* toggle screenshot pause */ |
| 3270 | if (keysactive[SDL_SCANCODE_NUMLOCKCLEAR]) |
| 3271 | superPause = !superPause; |
| 3272 | |
| 3273 | /* {SMOOTHIES} */ |
| 3274 | if (keysactive[SDL_SCANCODE_F12] && keysactive[SDL_SCANCODE_SCROLLLOCK]) |
| 3275 | { |
| 3276 | for (temp = SDL_SCANCODE_2; temp <= SDL_SCANCODE_9; temp++) |
| 3277 | if (keysactive[temp]) |
| 3278 | smoothies[temp-SDL_SCANCODE_2] = !smoothies[temp-SDL_SCANCODE_2]; |
| 3279 | if (keysactive[SDL_SCANCODE_0]) |
| 3280 | smoothies[8] = !smoothies[8]; |
| 3281 | } |
| 3282 | else |
| 3283 | |
| 3284 | /* {CYCLE THROUGH FILTER COLORS} */ |
| 3285 | if (keysactive[SDL_SCANCODE_MINUS]) |
| 3286 | { |
| 3287 | if (levelFilter == -99) |
| 3288 | { |
| 3289 | levelFilter = 0; |
| 3290 | } |
| 3291 | else |
| 3292 | { |
| 3293 | levelFilter++; |
| 3294 | if (levelFilter == 16) |
| 3295 | levelFilter = -99; |
| 3296 | } |
| 3297 | } |
| 3298 | else |
| 3299 | |
| 3300 | /* {HYPER-SPEED} */ |
| 3301 | if (keysactive[SDL_SCANCODE_1]) |
| 3302 | { |
| 3303 | fastPlay++; |
| 3304 | if (fastPlay > 2) |
| 3305 | fastPlay = 0; |
| 3306 | keysactive[SDL_SCANCODE_1] = false; |
| 3307 | JE_setNewGameSpeed(); |
| 3308 | } |
| 3309 | |
| 3310 | /* {IN-GAME RANDOM MUSIC SELECTION} */ |
| 3311 | if (keysactive[SDL_SCANCODE_SCROLLLOCK]) |
| 3312 | play_song(mt_rand() % MUSIC_NUM); |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | void JE_pauseGame(void) |
| 3317 | { |
| 3318 | mouseSetRelative(false); |
| 3319 | |
| 3320 | JE_boolean done = false; |
| 3321 | JE_word mouseX, mouseY; |
| 3322 | |
| 3323 | SDL_Surface *temp_surface = VGAScreen; |
| 3324 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 3325 | |
| 3326 | //tempScreenSeg = VGAScreenSeg; // sega000 |
| 3327 | if (!superPause) |
| 3328 | { |
| 3329 | JE_dString(VGAScreenSeg, 120, 90, miscText[22], FONT_SHAPES); |
| 3330 | |
| 3331 | VGAScreen = VGAScreenSeg; |
| 3332 | JE_showVGA(); |
| 3333 | } |
| 3334 | |
| 3335 | set_volume(tyrMusicVolume / 2, fxVolume); |
| 3336 | |
| 3337 | #ifdef WITH_NETWORK |
| 3338 | if (isNetworkGame) |
| 3339 | { |
| 3340 | network_prepare(PACKET_GAME_PAUSE); |
| 3341 | network_send(4); // PACKET_GAME_PAUSE |
| 3342 | |
| 3343 | while (true) |
| 3344 | { |
| 3345 | service_SDL_events(false); |
| 3346 | |
| 3347 | if (packet_in[0] && SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_GAME_PAUSE) |
| 3348 | { |
| 3349 | network_update(); |
| 3350 | break; |
| 3351 | } |
| 3352 | |
| 3353 | network_update(); |
| 3354 | network_check(); |
| 3355 | |
| 3356 | SDL_Delay(16); |
| 3357 | } |
| 3358 | } |
| 3359 | #endif |
| 3360 | |
| 3361 | wait_noinput(false, false, true); // TODO: should up the joystick repeat temporarily instead |
| 3362 | |
| 3363 | do |
| 3364 | { |
| 3365 | setDelay(2); |
| 3366 | |
| 3367 | push_joysticks_as_keyboard(); |
| 3368 | service_SDL_events(true); |
| 3369 | |
| 3370 | if ((newkey && lastkey_scan != SDL_SCANCODE_LCTRL && lastkey_scan != SDL_SCANCODE_RCTRL && lastkey_scan != SDL_SCANCODE_LALT && lastkey_scan != SDL_SCANCODE_RALT) || |
| 3371 | JE_mousePosition(&mouseX, &mouseY) > 0) |
| 3372 | { |
| 3373 | #ifdef WITH_NETWORK |
| 3374 | if (isNetworkGame) |
| 3375 | { |
| 3376 | network_prepare(PACKET_WAITING); |
| 3377 | network_send(4); // PACKET_WAITING |
| 3378 | } |
| 3379 | #endif |
| 3380 | done = true; |
| 3381 | } |
| 3382 | |
| 3383 | #ifdef WITH_NETWORK |
| 3384 | if (isNetworkGame) |
| 3385 | { |
| 3386 | network_check(); |
| 3387 | |
| 3388 | if (packet_in[0] && SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_WAITING) |
| 3389 | { |
| 3390 | network_check(); |
| 3391 | |
| 3392 | done = true; |
| 3393 | } |
| 3394 | } |
| 3395 | #endif |
| 3396 | |
| 3397 | wait_delay(); |
| 3398 | } while (!done); |
| 3399 | |
| 3400 | #ifdef WITH_NETWORK |
| 3401 | if (isNetworkGame) |
| 3402 | { |
| 3403 | while (!network_is_sync()) |
| 3404 | { |
| 3405 | service_SDL_events(false); |
| 3406 | |
| 3407 | network_check(); |
| 3408 | SDL_Delay(16); |
| 3409 | } |
| 3410 | } |
| 3411 | #endif |
| 3412 | |
| 3413 | set_volume(tyrMusicVolume, fxVolume); |
| 3414 | |
| 3415 | //skipStarShowVGA = true; |
| 3416 | |
| 3417 | VGAScreen = temp_surface; /* side-effect of game_screen */ |
| 3418 | |
| 3419 | mouseSetRelative(true); |
| 3420 | } |
| 3421 | |
| 3422 | void JE_playerMovement(Player *this_player, |
| 3423 | JE_byte inputDevice, |
| 3424 | JE_byte playerNum_, |
| 3425 | JE_word shipGr_, |
| 3426 | Sprite2_array *shipGrPtr_, |
| 3427 | JE_word *mouseX_, JE_word *mouseY_) |
| 3428 | { |
| 3429 | JE_integer mouseXC, mouseYC; |
| 3430 | JE_integer accelXC, accelYC; |
| 3431 | |
| 3432 | if (playerNum_ == 2 || !twoPlayerMode) |
| 3433 | { |
| 3434 | tempW = weaponPort[this_player->items.weapon[REAR_WEAPON].id].opnum; |
| 3435 | |
| 3436 | if (this_player->weapon_mode > tempW) |
| 3437 | this_player->weapon_mode = 1; |
| 3438 | } |
| 3439 | |
| 3440 | #ifdef WITH_NETWORK |
| 3441 | if (isNetworkGame && thisPlayerNum == playerNum_) |
| 3442 | { |
| 3443 | network_state_prepare(); |
| 3444 | memset(&packet_state_out[0]->data[4], 0, 10); |
| 3445 | } |
| 3446 | #endif |
| 3447 | |
| 3448 | redo: |
| 3449 | |
| 3450 | if (isNetworkGame) |
| 3451 | { |
| 3452 | inputDevice = 0; |
| 3453 | } |
| 3454 | |
| 3455 | mouseXC = 0; |
| 3456 | mouseYC = 0; |
| 3457 | accelXC = 0; |
| 3458 | accelYC = 0; |
| 3459 | |
| 3460 | bool link_gun_analog = false; |
| 3461 | float link_gun_angle = 0; |
| 3462 | |
| 3463 | /* Draw Player */ |
| 3464 | if (!this_player->is_alive) |
| 3465 | { |
| 3466 | if (this_player->exploding_ticks > 0) |
| 3467 | { |
| 3468 | --this_player->exploding_ticks; |
| 3469 | |
| 3470 | if (levelEndFxWait > 0) |
| 3471 | { |
| 3472 | levelEndFxWait--; |
| 3473 | } |
| 3474 | else |
| 3475 | { |
| 3476 | levelEndFxWait = (mt_rand() % 6) + 3; |
| 3477 | if ((mt_rand() % 3) == 1) |
| 3478 | soundQueue[6] = S_EXPLOSION_9; |
| 3479 | else |
| 3480 | soundQueue[5] = S_EXPLOSION_11; |
| 3481 | } |
| 3482 | |
| 3483 | int explosion_x = this_player->x + (mt_rand() % 32) - 16; |
| 3484 | int explosion_y = this_player->y + (mt_rand() % 32) - 16; |
| 3485 | JE_setupExplosionLarge(false, 0, explosion_x, explosion_y + 7); |
| 3486 | JE_setupExplosionLarge(false, 0, this_player->x, this_player->y + 7); |
| 3487 | |
| 3488 | if (levelEnd > 0) |
| 3489 | levelEnd--; |
| 3490 | } |
| 3491 | else |
| 3492 | { |
| 3493 | if (twoPlayerMode || onePlayerAction) // if arcade mode |
| 3494 | { |
| 3495 | if (*this_player->lives > 1) // respawn if any extra lives |
| 3496 | { |
| 3497 | --(*this_player->lives); |
| 3498 | |
| 3499 | reallyEndLevel = false; |
| 3500 | shotMultiPos[playerNum_-1] = 0; |
| 3501 | calc_purple_balls_needed(this_player); |
| 3502 | twoPlayerLinked = false; |
| 3503 | if (galagaMode) |
| 3504 | twoPlayerMode = false; |
| 3505 | this_player->y = 160; |
| 3506 | this_player->invulnerable_ticks = 100; |
| 3507 | this_player->is_alive = true; |
| 3508 | endLevel = false; |
| 3509 | |
| 3510 | if (galagaMode || episodeNum == 4) |
| 3511 | this_player->armor = this_player->initial_armor; |
| 3512 | else |
| 3513 | this_player->armor = this_player->initial_armor / 2; |
| 3514 | |
| 3515 | if (galagaMode) |
| 3516 | this_player->shield = 0; |
| 3517 | else |
| 3518 | this_player->shield = this_player->shield_max / 2; |
| 3519 | |
| 3520 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 3521 | JE_drawArmor(); |
| 3522 | JE_drawShield(); |
| 3523 | VGAScreen = game_screen; /* side-effect of game_screen */ |
| 3524 | goto redo; |
| 3525 | } |
| 3526 | else |
| 3527 | { |
| 3528 | if (galagaMode) |
| 3529 | twoPlayerMode = false; |
| 3530 | if (allPlayersGone && isNetworkGame) |
| 3531 | reallyEndLevel = true; |
| 3532 | } |
| 3533 | |
| 3534 | } |
| 3535 | } |
| 3536 | } |
| 3537 | else if (constantDie) |
| 3538 | { |
| 3539 | // finished exploding? start dying again |
| 3540 | if (this_player->exploding_ticks == 0) |
| 3541 | { |
| 3542 | this_player->shield = 0; |
| 3543 | |
| 3544 | if (this_player->armor > 0) |
| 3545 | { |
| 3546 | --this_player->armor; |
| 3547 | } |
| 3548 | else |
| 3549 | { |
| 3550 | this_player->is_alive = false; |
| 3551 | this_player->exploding_ticks = 60; |
| 3552 | levelEnd = 40; |
| 3553 | } |
| 3554 | |
| 3555 | JE_wipeShieldArmorBars(); |
| 3556 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 3557 | JE_drawArmor(); |
| 3558 | VGAScreen = game_screen; /* side-effect of game_screen */ |
| 3559 | |
| 3560 | // as if instant death weren't enough, player also gets infinite lives in order to enjoy an infinite number of deaths -_- |
| 3561 | if (*player[0].lives < 11) |
| 3562 | ++(*player[0].lives); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | if (!this_player->is_alive) |
| 3567 | { |
| 3568 | explosionFollowAmountX = explosionFollowAmountY = 0; |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | if (!endLevel) |
| 3573 | { |
| 3574 | *mouseX_ = this_player->x; |
| 3575 | *mouseY_ = this_player->y; |
| 3576 | button[1-1] = false; |
| 3577 | button[2-1] = false; |
| 3578 | button[3-1] = false; |
| 3579 | button[4-1] = false; |
| 3580 | |
| 3581 | /* --- Movement Routine Beginning --- */ |
| 3582 | |
| 3583 | if (!isNetworkGame || playerNum_ == thisPlayerNum) |
| 3584 | { |
| 3585 | if (endLevel) |
| 3586 | { |
| 3587 | this_player->y -= 2; |
| 3588 | } |
| 3589 | else |
| 3590 | { |
| 3591 | if (record_demo || play_demo) |
| 3592 | inputDevice = 1; // keyboard is required device for demo recording |
| 3593 | |
| 3594 | // demo playback input |
| 3595 | if (play_demo) |
| 3596 | { |
| 3597 | if (!replay_demo_keys()) |
| 3598 | { |
| 3599 | endLevel = true; |
| 3600 | levelEnd = 40; |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | /* joystick input */ |
| 3605 | if ((inputDevice == 0 || inputDevice >= 3) && joysticks > 0) |
| 3606 | { |
| 3607 | int j = inputDevice == 0 ? 0 : inputDevice - 3; |
| 3608 | int j_max = inputDevice == 0 ? joysticks : inputDevice - 3 + 1; |
| 3609 | for (; j < j_max; j++) |
| 3610 | { |
| 3611 | poll_joystick(j); |
| 3612 | |
| 3613 | if (joystick[j].analog) |
| 3614 | { |
| 3615 | mouseXC += joystick_axis_reduce(j, joystick[j].x); |
| 3616 | mouseYC += joystick_axis_reduce(j, joystick[j].y); |
| 3617 | |
| 3618 | link_gun_analog = joystick_analog_angle(j, &link_gun_angle); |
| 3619 | } |
| 3620 | else |
| 3621 | { |
| 3622 | this_player->x += (joystick[j].direction[3] ? -CURRENT_KEY_SPEED : 0) + (joystick[j].direction[1] ? CURRENT_KEY_SPEED : 0); |
| 3623 | this_player->y += (joystick[j].direction[0] ? -CURRENT_KEY_SPEED : 0) + (joystick[j].direction[2] ? CURRENT_KEY_SPEED : 0); |
| 3624 | } |
| 3625 | |
| 3626 | button[0] |= joystick[j].action[0]; |
| 3627 | button[1] |= joystick[j].action[2]; |
| 3628 | button[2] |= joystick[j].action[3]; |
| 3629 | button[3] |= joystick[j].action_pressed[1]; |
| 3630 | |
| 3631 | ingamemenu_pressed |= joystick[j].action_pressed[4]; |
| 3632 | pause_pressed |= joystick[j].action_pressed[5]; |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | service_SDL_events(false); |
| 3637 | |
| 3638 | /* mouse input */ |
| 3639 | if ((inputDevice == 0 || inputDevice == 2) && has_mouse) |
| 3640 | { |
| 3641 | button[0] |= mouse_pressed[0]; |
| 3642 | button[1] |= mouse_pressed[1]; |
| 3643 | button[2] |= mouse_has_three_buttons ? mouse_pressed[2] : mouse_pressed[1]; |
| 3644 | |
| 3645 | Sint32 mouseXR; |
| 3646 | Sint32 mouseYR; |
| 3647 | mouseGetRelativePosition(&mouseXR, &mouseYR); |
| 3648 | mouseXC += mouseXR; |
| 3649 | mouseYC += mouseYR; |
| 3650 | } |
| 3651 | |
| 3652 | /* keyboard input */ |
| 3653 | if ((inputDevice == 0 || inputDevice == 1) && !play_demo) |
| 3654 | { |
| 3655 | if (keysactive[keySettings[KEY_SETTING_UP]]) |
| 3656 | this_player->y -= CURRENT_KEY_SPEED; |
| 3657 | if (keysactive[keySettings[KEY_SETTING_DOWN]]) |
| 3658 | this_player->y += CURRENT_KEY_SPEED; |
| 3659 | |
| 3660 | if (keysactive[keySettings[KEY_SETTING_LEFT]]) |
| 3661 | this_player->x -= CURRENT_KEY_SPEED; |
| 3662 | if (keysactive[keySettings[KEY_SETTING_RIGHT]]) |
| 3663 | this_player->x += CURRENT_KEY_SPEED; |
| 3664 | |
| 3665 | button[0] = button[0] || keysactive[keySettings[KEY_SETTING_FIRE]]; |
| 3666 | button[3] = button[3] || keysactive[keySettings[KEY_SETTING_CHANGE_FIRE]]; |
| 3667 | button[1] = button[1] || keysactive[keySettings[KEY_SETTING_LEFT_SIDEKICK]]; |
| 3668 | button[2] = button[2] || keysactive[keySettings[KEY_SETTING_RIGHT_SIDEKICK]]; |
| 3669 | |
| 3670 | if (constantPlay) |
| 3671 | { |
| 3672 | for (unsigned int i = 0; i < 4; i++) |
| 3673 | button[i] = true; |
| 3674 | |
| 3675 | ++this_player->y; |
| 3676 | this_player->x += constantLastX; |
| 3677 | } |
| 3678 | |
| 3679 | // TODO: check if demo recording still works |
| 3680 | if (record_demo) |
| 3681 | { |
| 3682 | bool new_input = false; |
| 3683 | |
| 3684 | for (unsigned int i = 0; i < 8; i++) |
| 3685 | { |
| 3686 | bool temp = demo_keys & (1 << i); |
| 3687 | if (temp != keysactive[keySettings[i]]) |
| 3688 | new_input = true; |
| 3689 | } |
| 3690 | |
| 3691 | demo_keys_wait++; |
| 3692 | |
| 3693 | if (new_input) |
| 3694 | { |
| 3695 | Uint8 temp2[2] = { demo_keys_wait >> 8, demo_keys_wait }; |
| 3696 | fwrite_u8(temp2, 2, demo_file); |
| 3697 | |
| 3698 | demo_keys = 0; |
| 3699 | for (unsigned int i = 0; i < 8; i++) |
| 3700 | demo_keys |= keysactive[keySettings[i]] ? (1 << i) : 0; |
| 3701 | |
| 3702 | fwrite_u8(&demo_keys, 1, demo_file); |
| 3703 | |
| 3704 | demo_keys_wait = 0; |
| 3705 | } |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | if (smoothies[9-1]) |
| 3710 | { |
| 3711 | *mouseY_ = this_player->y - (*mouseY_ - this_player->y); |
| 3712 | mouseYC = -mouseYC; |
| 3713 | } |
| 3714 | |
| 3715 | accelXC += this_player->x - *mouseX_; |
| 3716 | accelYC += this_player->y - *mouseY_; |
| 3717 | |
| 3718 | if (mouseXC > 30) |
| 3719 | mouseXC = 30; |
| 3720 | else if (mouseXC < -30) |
| 3721 | mouseXC = -30; |
| 3722 | if (mouseYC > 30) |
| 3723 | mouseYC = 30; |
| 3724 | else if (mouseYC < -30) |
| 3725 | mouseYC = -30; |
| 3726 | |
| 3727 | if (mouseXC > 0) |
| 3728 | this_player->x += (mouseXC + 3) / 4; |
| 3729 | else if (mouseXC < 0) |
| 3730 | this_player->x += (mouseXC - 3) / 4; |
| 3731 | if (mouseYC > 0) |
| 3732 | this_player->y += (mouseYC + 3) / 4; |
| 3733 | else if (mouseYC < 0) |
| 3734 | this_player->y += (mouseYC - 3) / 4; |
| 3735 | |
| 3736 | if (mouseXC > 3) |
| 3737 | accelXC++; |
| 3738 | else if (mouseXC < -2) |
| 3739 | accelXC--; |
| 3740 | if (mouseYC > 2) |
| 3741 | accelYC++; |
| 3742 | else if (mouseYC < -2) |
| 3743 | accelYC--; |
| 3744 | |
| 3745 | } /*endLevel*/ |
| 3746 | |
| 3747 | #ifdef WITH_NETWORK |
| 3748 | if (isNetworkGame && playerNum_ == thisPlayerNum) |
| 3749 | { |
| 3750 | Uint16 buttons = 0; |
| 3751 | for (int i = 4 - 1; i >= 0; i--) |
| 3752 | { |
| 3753 | buttons <<= 1; |
| 3754 | buttons |= button[i]; |
| 3755 | } |
| 3756 | |
| 3757 | SDLNet_Write16(this_player->x - *mouseX_, &packet_state_out[0]->data[4]); |
| 3758 | SDLNet_Write16(this_player->y - *mouseY_, &packet_state_out[0]->data[6]); |
| 3759 | SDLNet_Write16(accelXC, &packet_state_out[0]->data[8]); |
| 3760 | SDLNet_Write16(accelYC, &packet_state_out[0]->data[10]); |
| 3761 | SDLNet_Write16(buttons, &packet_state_out[0]->data[12]); |
| 3762 | |
| 3763 | this_player->x = *mouseX_; |
| 3764 | this_player->y = *mouseY_; |
| 3765 | |
| 3766 | button[0] = false; |
| 3767 | button[1] = false; |
| 3768 | button[2] = false; |
| 3769 | button[3] = false; |
| 3770 | |
| 3771 | accelXC = 0; |
| 3772 | accelYC = 0; |
| 3773 | } |
| 3774 | #endif |
| 3775 | } /*isNetworkGame*/ |
| 3776 | |
| 3777 | /* --- Movement Routine Ending --- */ |
| 3778 | |
| 3779 | moveOk = true; |
| 3780 | |
| 3781 | #ifdef WITH_NETWORK |
| 3782 | if (isNetworkGame && !network_state_is_reset()) |
| 3783 | { |
| 3784 | if (playerNum_ != thisPlayerNum) |
| 3785 | { |
| 3786 | if (thisPlayerNum == 2) |
| 3787 | difficultyLevel = SDLNet_Read16(&packet_state_in[0]->data[16]); |
| 3788 | |
| 3789 | Uint16 buttons = SDLNet_Read16(&packet_state_in[0]->data[12]); |
| 3790 | for (int i = 0; i < 4; i++) |
| 3791 | { |
| 3792 | button[i] = buttons & 1; |
| 3793 | buttons >>= 1; |
| 3794 | } |
| 3795 | |
| 3796 | this_player->x += (Sint16)SDLNet_Read16(&packet_state_in[0]->data[4]); |
| 3797 | this_player->y += (Sint16)SDLNet_Read16(&packet_state_in[0]->data[6]); |
| 3798 | accelXC = (Sint16)SDLNet_Read16(&packet_state_in[0]->data[8]); |
| 3799 | accelYC = (Sint16)SDLNet_Read16(&packet_state_in[0]->data[10]); |
| 3800 | } |
| 3801 | else |
| 3802 | { |
| 3803 | Uint16 buttons = SDLNet_Read16(&packet_state_out[network_delay]->data[12]); |
| 3804 | for (int i = 0; i < 4; i++) |
| 3805 | { |
| 3806 | button[i] = buttons & 1; |
| 3807 | buttons >>= 1; |
| 3808 | } |
| 3809 | |
| 3810 | this_player->x += (Sint16)SDLNet_Read16(&packet_state_out[network_delay]->data[4]); |
| 3811 | this_player->y += (Sint16)SDLNet_Read16(&packet_state_out[network_delay]->data[6]); |
| 3812 | accelXC = (Sint16)SDLNet_Read16(&packet_state_out[network_delay]->data[8]); |
| 3813 | accelYC = (Sint16)SDLNet_Read16(&packet_state_out[network_delay]->data[10]); |
| 3814 | } |
| 3815 | } |
| 3816 | #endif |
| 3817 | |
| 3818 | /*Street-Fighter codes*/ |
| 3819 | JE_SFCodes(playerNum_, this_player->x, this_player->y, *mouseX_, *mouseY_); |
| 3820 | |
| 3821 | if (moveOk) |
| 3822 | { |
| 3823 | /* END OF MOVEMENT ROUTINES */ |
| 3824 | |
| 3825 | /*Linking Routines*/ |
| 3826 | |
| 3827 | if (twoPlayerMode && !twoPlayerLinked && this_player->x == *mouseX_ && this_player->y == *mouseY_ && |
| 3828 | abs(player[0].x - player[1].x) < 8 && abs(player[0].y - player[1].y) < 8 && |
| 3829 | player[0].is_alive && player[1].is_alive && !galagaMode) |
| 3830 | { |
| 3831 | twoPlayerLinked = true; |
| 3832 | } |
| 3833 | |
| 3834 | if (playerNum_ == 1 && (button[3-1] || button[2-1]) && !galagaMode) |
| 3835 | twoPlayerLinked = false; |
| 3836 | |
| 3837 | if (twoPlayerMode && twoPlayerLinked && playerNum_ == 2 && |
| 3838 | (this_player->x != *mouseX_ || this_player->y != *mouseY_)) |
| 3839 | { |
| 3840 | if (button[0]) |
| 3841 | { |
| 3842 | if (link_gun_analog) |
| 3843 | { |
| 3844 | linkGunDirec = link_gun_angle; |
| 3845 | } |
| 3846 | else |
| 3847 | { |
| 3848 | JE_real tempR; |
| 3849 | |
| 3850 | if (abs(this_player->x - *mouseX_) > abs(this_player->y - *mouseY_)) |
| 3851 | tempR = (this_player->x - *mouseX_ > 0) ? M_PI_2 : (M_PI + M_PI_2); |
| 3852 | else |
| 3853 | tempR = (this_player->y - *mouseY_ > 0) ? 0 : M_PI; |
| 3854 | |
| 3855 | if (fabsf(linkGunDirec - tempR) < 0.3f) |
| 3856 | linkGunDirec = tempR; |
| 3857 | else if (linkGunDirec < tempR && linkGunDirec - tempR > -3.24f) |
| 3858 | linkGunDirec += 0.2f; |
| 3859 | else if (linkGunDirec - tempR < M_PI) |
| 3860 | linkGunDirec -= 0.2f; |
| 3861 | else |
| 3862 | linkGunDirec += 0.2f; |
| 3863 | } |
| 3864 | |
| 3865 | if (linkGunDirec >= (2 * M_PI)) |
| 3866 | linkGunDirec -= (2 * M_PI); |
| 3867 | else if (linkGunDirec < 0) |
| 3868 | linkGunDirec += (2 * M_PI); |
| 3869 | } |
| 3870 | else if (!galagaMode) |
| 3871 | { |
| 3872 | twoPlayerLinked = false; |
| 3873 | } |
| 3874 | } |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | if (levelEnd > 0 && all_players_dead()) |
| 3879 | reallyEndLevel = true; |
| 3880 | |
| 3881 | /* End Level Fade-Out */ |
| 3882 | if (this_player->is_alive && endLevel) |
| 3883 | { |
| 3884 | if (levelEnd == 0) |
| 3885 | { |
| 3886 | reallyEndLevel = true; |
| 3887 | } |
| 3888 | else |
| 3889 | { |
| 3890 | this_player->y -= levelEndWarp; |
| 3891 | if (this_player->y < -200) |
| 3892 | reallyEndLevel = true; |
| 3893 | |
| 3894 | int trail_spacing = 1; |
| 3895 | int trail_y = this_player->y; |
| 3896 | int num_trails = abs(41 - levelEnd); |
| 3897 | if (num_trails > 20) |
| 3898 | num_trails = 20; |
| 3899 | |
| 3900 | for (int i = 0; i < num_trails; i++) |
| 3901 | { |
| 3902 | trail_y += trail_spacing; |
| 3903 | trail_spacing++; |
| 3904 | } |
| 3905 | |
| 3906 | for (int i = 1; i < num_trails; i++) |
| 3907 | { |
| 3908 | trail_y -= trail_spacing; |
| 3909 | trail_spacing--; |
| 3910 | |
| 3911 | if (trail_y > 0 && trail_y < 170) |
| 3912 | { |
| 3913 | if (shipGr_ == 0) |
| 3914 | { |
| 3915 | blit_sprite2x2(VGAScreen, this_player->x - 17, trail_y - 7, *shipGrPtr_, 13); |
| 3916 | blit_sprite2x2(VGAScreen, this_player->x + 7 , trail_y - 7, *shipGrPtr_, 51); |
| 3917 | } |
| 3918 | else if (shipGr_ == 1) |
| 3919 | { |
| 3920 | blit_sprite2x2(VGAScreen, this_player->x - 17, trail_y - 7, *shipGrPtr_, 220); |
| 3921 | blit_sprite2x2(VGAScreen, this_player->x + 7 , trail_y - 7, *shipGrPtr_, 222); |
| 3922 | } |
| 3923 | else |
| 3924 | { |
| 3925 | blit_sprite2x2(VGAScreen, this_player->x - 5, trail_y - 7, *shipGrPtr_, shipGr_); |
| 3926 | } |
| 3927 | } |
| 3928 | } |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | if (play_demo) |
| 3933 | JE_dString(VGAScreen, 115, 10, miscText[7], SMALL_FONT_SHAPES); // insert coin |
| 3934 | |
| 3935 | if (this_player->is_alive && !endLevel) |
| 3936 | { |
| 3937 | if (!twoPlayerLinked || playerNum_ < 2) |
| 3938 | { |
| 3939 | if (!twoPlayerMode || shipGr2 != 0) // if not dragonwing |
| 3940 | { |
| 3941 | if (this_player->sidekick[LEFT_SIDEKICK].style == 0) |
| 3942 | { |
| 3943 | this_player->sidekick[LEFT_SIDEKICK].x = *mouseX_ - 14; |
| 3944 | this_player->sidekick[LEFT_SIDEKICK].y = *mouseY_; |
| 3945 | } |
| 3946 | |
| 3947 | if (this_player->sidekick[RIGHT_SIDEKICK].style == 0) |
| 3948 | { |
| 3949 | this_player->sidekick[RIGHT_SIDEKICK].x = *mouseX_ + 16; |
| 3950 | this_player->sidekick[RIGHT_SIDEKICK].y = *mouseY_; |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | if (this_player->x_friction_ticks > 0) |
| 3955 | { |
| 3956 | --this_player->x_friction_ticks; |
| 3957 | } |
| 3958 | else |
| 3959 | { |
| 3960 | this_player->x_friction_ticks = 1; |
| 3961 | |
| 3962 | if (this_player->x_velocity < 0) |
| 3963 | ++this_player->x_velocity; |
| 3964 | else if (this_player->x_velocity > 0) |
| 3965 | --this_player->x_velocity; |
| 3966 | } |
| 3967 | |
| 3968 | if (this_player->y_friction_ticks > 0) |
| 3969 | { |
| 3970 | --this_player->y_friction_ticks; |
| 3971 | } |
| 3972 | else |
| 3973 | { |
| 3974 | this_player->y_friction_ticks = 2; |
| 3975 | |
| 3976 | if (this_player->y_velocity < 0) |
| 3977 | ++this_player->y_velocity; |
| 3978 | else if (this_player->y_velocity > 0) |
| 3979 | --this_player->y_velocity; |
| 3980 | } |
| 3981 | |
| 3982 | this_player->x_velocity += accelXC; |
| 3983 | this_player->y_velocity += accelYC; |
| 3984 | |
| 3985 | this_player->x_velocity = MIN(MAX(-4, this_player->x_velocity), 4); |
| 3986 | this_player->y_velocity = MIN(MAX(-4, this_player->y_velocity), 4); |
| 3987 | |
| 3988 | this_player->x += this_player->x_velocity; |
| 3989 | this_player->y += this_player->y_velocity; |
| 3990 | |
| 3991 | // if player moved, add new ship x, y history entry |
| 3992 | if (this_player->x - *mouseX_ != 0 || this_player->y - *mouseY_ != 0) |
| 3993 | { |
| 3994 | for (uint i = 1; i < COUNTOF(player->old_x); ++i) |
| 3995 | { |
| 3996 | this_player->old_x[i - 1] = this_player->old_x[i]; |
| 3997 | this_player->old_y[i - 1] = this_player->old_y[i]; |
| 3998 | } |
| 3999 | this_player->old_x[COUNTOF(player->old_x) - 1] = this_player->x; |
| 4000 | this_player->old_y[COUNTOF(player->old_x) - 1] = this_player->y; |
| 4001 | } |
| 4002 | } |
| 4003 | else /*twoPlayerLinked*/ |
| 4004 | { |
| 4005 | if (shipGr_ == 0) |
| 4006 | this_player->x = player[0].x - 1; |
| 4007 | else |
| 4008 | this_player->x = player[0].x; |
| 4009 | this_player->y = player[0].y + 8; |
| 4010 | |
| 4011 | this_player->x_velocity = player[0].x_velocity; |
| 4012 | this_player->y_velocity = 4; |
| 4013 | |
| 4014 | // turret direction marker/shield |
| 4015 | shotMultiPos[SHOT_MISC] = 0; |
| 4016 | b = player_shot_create(0, SHOT_MISC, this_player->x + 1 + roundf(sinf(linkGunDirec + 0.2f) * 26), this_player->y + roundf(cosf(linkGunDirec + 0.2f) * 26), *mouseX_, *mouseY_, 148, playerNum_); |
| 4017 | shotMultiPos[SHOT_MISC] = 0; |
| 4018 | b = player_shot_create(0, SHOT_MISC, this_player->x + 1 + roundf(sinf(linkGunDirec - 0.2f) * 26), this_player->y + roundf(cosf(linkGunDirec - 0.2f) * 26), *mouseX_, *mouseY_, 148, playerNum_); |
| 4019 | shotMultiPos[SHOT_MISC] = 0; |
| 4020 | b = player_shot_create(0, SHOT_MISC, this_player->x + 1 + roundf(sinf(linkGunDirec) * 26), this_player->y + roundf(cosf(linkGunDirec) * 26), *mouseX_, *mouseY_, 147, playerNum_); |
| 4021 | |
| 4022 | if (shotRepeat[SHOT_REAR] > 0) |
| 4023 | { |
| 4024 | --shotRepeat[SHOT_REAR]; |
| 4025 | } |
| 4026 | else if (button[1-1]) |
| 4027 | { |
| 4028 | shotMultiPos[SHOT_REAR] = 0; |
| 4029 | b = player_shot_create(0, SHOT_REAR, this_player->x + 1 + roundf(sinf(linkGunDirec) * 20), this_player->y + roundf(cosf(linkGunDirec) * 20), *mouseX_, *mouseY_, linkGunWeapons[this_player->items.weapon[REAR_WEAPON].id-1], playerNum_); |
| 4030 | player_shot_set_direction(b, this_player->items.weapon[REAR_WEAPON].id, linkGunDirec); |
| 4031 | } |
| 4032 | } |
| 4033 | } |
| 4034 | |
| 4035 | if (!endLevel) |
| 4036 | { |
| 4037 | if (this_player->x > 256) |
| 4038 | { |
| 4039 | this_player->x = 256; |
| 4040 | constantLastX = -constantLastX; |
| 4041 | } |
| 4042 | if (this_player->x < 40) |
| 4043 | { |
| 4044 | this_player->x = 40; |
| 4045 | constantLastX = -constantLastX; |
| 4046 | } |
| 4047 | |
| 4048 | if (isNetworkGame && playerNum_ == 1) |
| 4049 | { |
| 4050 | if (this_player->y > 154) |
| 4051 | this_player->y = 154; |
| 4052 | } |
| 4053 | else |
| 4054 | { |
| 4055 | if (this_player->y > 160) |
| 4056 | this_player->y = 160; |
| 4057 | } |
| 4058 | |
| 4059 | if (this_player->y < 10) |
| 4060 | this_player->y = 10; |
| 4061 | |
| 4062 | // Determines the ship banking sprite to display, depending on horizontal velocity and acceleration |
| 4063 | int ship_banking = this_player->x_velocity / 2 + (this_player->x - *mouseX_) / 6; |
| 4064 | ship_banking = MAX(-2, MIN(ship_banking, 2)); |
| 4065 | |
| 4066 | int ship_sprite = ship_banking * 2 + shipGr_; |
| 4067 | |
| 4068 | explosionFollowAmountX = this_player->x - this_player->last_x_explosion_follow; |
| 4069 | explosionFollowAmountY = this_player->y - this_player->last_y_explosion_follow; |
| 4070 | |
| 4071 | if (explosionFollowAmountY < 0) |
| 4072 | explosionFollowAmountY = 0; |
| 4073 | |
| 4074 | this_player->last_x_explosion_follow = this_player->x; |
| 4075 | this_player->last_y_explosion_follow = this_player->y; |
| 4076 | |
| 4077 | if (shipGr_ == 0) |
| 4078 | { |
| 4079 | if (background2) |
| 4080 | { |
| 4081 | blit_sprite2x2_darken(VGAScreen, this_player->x - 17 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite + 13); |
| 4082 | blit_sprite2x2_darken(VGAScreen, this_player->x + 7 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite + 51); |
| 4083 | if (superWild) |
| 4084 | { |
| 4085 | blit_sprite2x2_darken(VGAScreen, this_player->x - 16 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite + 13); |
| 4086 | blit_sprite2x2_darken(VGAScreen, this_player->x + 6 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite + 51); |
| 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | else if (shipGr_ == 1) |
| 4091 | { |
| 4092 | if (background2) |
| 4093 | { |
| 4094 | blit_sprite2x2_darken(VGAScreen, this_player->x - 17 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, 220); |
| 4095 | blit_sprite2x2_darken(VGAScreen, this_player->x + 7 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, 222); |
| 4096 | } |
| 4097 | } |
| 4098 | else |
| 4099 | { |
| 4100 | if (background2) |
| 4101 | { |
| 4102 | blit_sprite2x2_darken(VGAScreen, this_player->x - 5 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite); |
| 4103 | if (superWild) |
| 4104 | { |
| 4105 | blit_sprite2x2_darken(VGAScreen, this_player->x - 4 - mapX2Ofs + 30, this_player->y - 7 + shadowYDist, *shipGrPtr_, ship_sprite); |
| 4106 | } |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | if (this_player->invulnerable_ticks > 0) |
| 4111 | { |
| 4112 | --this_player->invulnerable_ticks; |
| 4113 | |
| 4114 | if (shipGr_ == 0) |
| 4115 | { |
| 4116 | blit_sprite2x2_blend(VGAScreen, this_player->x - 17, this_player->y - 7, *shipGrPtr_, ship_sprite + 13); |
| 4117 | blit_sprite2x2_blend(VGAScreen, this_player->x + 7 , this_player->y - 7, *shipGrPtr_, ship_sprite + 51); |
| 4118 | } |
| 4119 | else if (shipGr_ == 1) |
| 4120 | { |
| 4121 | blit_sprite2x2_blend(VGAScreen, this_player->x - 17, this_player->y - 7, *shipGrPtr_, 220); |
| 4122 | blit_sprite2x2_blend(VGAScreen, this_player->x + 7 , this_player->y - 7, *shipGrPtr_, 222); |
| 4123 | } |
| 4124 | else |
| 4125 | blit_sprite2x2_blend(VGAScreen, this_player->x - 5, this_player->y - 7, *shipGrPtr_, ship_sprite); |
| 4126 | } |
| 4127 | else |
| 4128 | { |
| 4129 | if (shipGr_ == 0) |
| 4130 | { |
| 4131 | blit_sprite2x2(VGAScreen, this_player->x - 17, this_player->y - 7, *shipGrPtr_, ship_sprite + 13); |
| 4132 | blit_sprite2x2(VGAScreen, this_player->x + 7, this_player->y - 7, *shipGrPtr_, ship_sprite + 51); |
| 4133 | } |
| 4134 | else if (shipGr_ == 1) |
| 4135 | { |
| 4136 | blit_sprite2x2(VGAScreen, this_player->x - 17, this_player->y - 7, *shipGrPtr_, 220); |
| 4137 | blit_sprite2x2(VGAScreen, this_player->x + 7, this_player->y - 7, *shipGrPtr_, 222); |
| 4138 | |
| 4139 | int ship_banking = 0; |
| 4140 | switch (ship_sprite) |
| 4141 | { |
| 4142 | case 5: |
| 4143 | blit_sprite2(VGAScreen, this_player->x - 17, this_player->y + 7, *shipGrPtr_, 40); |
| 4144 | tempW = this_player->x - 7; |
| 4145 | ship_banking = -2; |
| 4146 | break; |
| 4147 | case 3: |
| 4148 | blit_sprite2(VGAScreen, this_player->x - 17, this_player->y + 7, *shipGrPtr_, 39); |
| 4149 | tempW = this_player->x - 7; |
| 4150 | ship_banking = -1; |
| 4151 | break; |
| 4152 | case 1: |
| 4153 | ship_banking = 0; |
| 4154 | break; |
| 4155 | case -1: |
| 4156 | blit_sprite2(VGAScreen, this_player->x + 19, this_player->y + 7, *shipGrPtr_, 58); |
| 4157 | tempW = this_player->x + 9; |
| 4158 | ship_banking = 1; |
| 4159 | break; |
| 4160 | case -3: |
| 4161 | blit_sprite2(VGAScreen, this_player->x + 19, this_player->y + 7, *shipGrPtr_, 59); |
| 4162 | tempW = this_player->x + 9; |
| 4163 | ship_banking = 2; |
| 4164 | break; |
| 4165 | } |
| 4166 | if (ship_banking != 0) // NortSparks |
| 4167 | { |
| 4168 | if (shotRepeat[SHOT_NORTSPARKS] > 0) |
| 4169 | { |
| 4170 | --shotRepeat[SHOT_NORTSPARKS]; |
| 4171 | } |
| 4172 | else |
| 4173 | { |
| 4174 | b = player_shot_create(0, SHOT_NORTSPARKS, tempW + (mt_rand() % 8) - 4, this_player->y + (mt_rand() % 8) - 4, *mouseX_, *mouseY_, 671, 1); |
| 4175 | shotRepeat[SHOT_NORTSPARKS] = abs(ship_banking) - 1; |
| 4176 | } |
| 4177 | } |
| 4178 | } |
| 4179 | else |
| 4180 | { |
| 4181 | blit_sprite2x2(VGAScreen, this_player->x - 5, this_player->y - 7, *shipGrPtr_, ship_sprite); |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | /*Options Location*/ |
| 4186 | if (playerNum_ == 2 && shipGr_ == 0) // if dragonwing |
| 4187 | { |
| 4188 | if (this_player->sidekick[LEFT_SIDEKICK].style == 0) |
| 4189 | { |
| 4190 | this_player->sidekick[LEFT_SIDEKICK].x = this_player->x - 14 + ship_banking * 2; |
| 4191 | this_player->sidekick[LEFT_SIDEKICK].y = this_player->y; |
| 4192 | } |
| 4193 | |
| 4194 | if (this_player->sidekick[RIGHT_SIDEKICK].style == 0) |
| 4195 | { |
| 4196 | this_player->sidekick[RIGHT_SIDEKICK].x = this_player->x + 17 + ship_banking * 2; |
| 4197 | this_player->sidekick[RIGHT_SIDEKICK].y = this_player->y; |
| 4198 | } |
| 4199 | } |
| 4200 | } // !endLevel |
| 4201 | |
| 4202 | if (moveOk) |
| 4203 | { |
| 4204 | if (this_player->is_alive) |
| 4205 | { |
| 4206 | if (!endLevel) |
| 4207 | { |
| 4208 | this_player->delta_x_shot_move = this_player->x - this_player->last_x_shot_move; |
| 4209 | this_player->delta_y_shot_move = this_player->y - this_player->last_y_shot_move; |
| 4210 | |
| 4211 | /* PLAYER SHOT Change */ |
| 4212 | if (button[4-1]) |
| 4213 | { |
| 4214 | portConfigChange = true; |
| 4215 | if (portConfigDone) |
| 4216 | { |
| 4217 | shotMultiPos[SHOT_REAR] = 0; |
| 4218 | |
| 4219 | if (superArcadeMode != SA_NONE && superArcadeMode <= SA_NORTSHIPZ) |
| 4220 | { |
| 4221 | shotMultiPos[SHOT_SPECIAL] = 0; |
| 4222 | shotMultiPos[SHOT_SPECIAL2] = 0; |
| 4223 | if (player[0].items.special == SASpecialWeapon[superArcadeMode-1]) |
| 4224 | { |
| 4225 | player[0].items.special = SASpecialWeaponB[superArcadeMode-1]; |
| 4226 | this_player->weapon_mode = 2; |
| 4227 | } |
| 4228 | else |
| 4229 | { |
| 4230 | player[0].items.special = SASpecialWeapon[superArcadeMode-1]; |
| 4231 | this_player->weapon_mode = 1; |
| 4232 | } |
| 4233 | } |
| 4234 | else if (++this_player->weapon_mode > JE_portConfigs()) |
| 4235 | this_player->weapon_mode = 1; |
| 4236 | |
| 4237 | JE_drawPortConfigButtons(); |
| 4238 | portConfigDone = false; |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | /* PLAYER SHOT Creation */ |
| 4243 | |
| 4244 | /*SpecialShot*/ |
| 4245 | if (!galagaMode) |
| 4246 | JE_doSpecialShot(playerNum_, &this_player->armor, &this_player->shield); |
| 4247 | |
| 4248 | /*Normal Main Weapons*/ |
| 4249 | if (!(twoPlayerLinked && playerNum_ == 2)) |
| 4250 | { |
| 4251 | int min, max; |
| 4252 | |
| 4253 | if (!twoPlayerMode) |
| 4254 | min = 1, max = 2; |
| 4255 | else |
| 4256 | min = max = playerNum_; |
| 4257 | |
| 4258 | for (temp = min - 1; temp < max; temp++) |
| 4259 | { |
| 4260 | const uint item = this_player->items.weapon[temp].id; |
| 4261 | |
| 4262 | if (item > 0) |
| 4263 | { |
| 4264 | if (shotRepeat[temp] > 0) |
| 4265 | { |
| 4266 | --shotRepeat[temp]; |
| 4267 | } |
| 4268 | else if (button[1-1]) |
| 4269 | { |
| 4270 | const uint item_power = galagaMode ? 0 : this_player->items.weapon[temp].power - 1, |
| 4271 | item_mode = (temp == REAR_WEAPON) ? this_player->weapon_mode - 1 : 0; |
| 4272 | |
| 4273 | b = player_shot_create(item, temp, this_player->x, this_player->y, *mouseX_, *mouseY_, weaponPort[item].op[item_mode][item_power], playerNum_); |
| 4274 | } |
| 4275 | } |
| 4276 | } |
| 4277 | } |
| 4278 | |
| 4279 | /*Super Charge Weapons*/ |
| 4280 | if (playerNum_ == 2) |
| 4281 | { |
| 4282 | |
| 4283 | if (!twoPlayerLinked) |
| 4284 | blit_sprite2(VGAScreen, this_player->x + (shipGr_ == 0) + 1, this_player->y - 13, spriteSheet10, 77 + chargeLevel + chargeGr * 19); |
| 4285 | |
| 4286 | if (chargeGrWait > 0) |
| 4287 | { |
| 4288 | chargeGrWait--; |
| 4289 | } |
| 4290 | else |
| 4291 | { |
| 4292 | chargeGr++; |
| 4293 | if (chargeGr == 4) |
| 4294 | chargeGr = 0; |
| 4295 | chargeGrWait = 3; |
| 4296 | } |
| 4297 | |
| 4298 | if (chargeLevel > 0) |
| 4299 | { |
| 4300 | fill_rectangle_xy(VGAScreenSeg, 269, 107 + (chargeLevel - 1) * 3, 275, 108 + (chargeLevel - 1) * 3, 193); |
| 4301 | } |
| 4302 | |
| 4303 | if (chargeWait > 0) |
| 4304 | { |
| 4305 | chargeWait--; |
| 4306 | } |
| 4307 | else |
| 4308 | { |
| 4309 | if (chargeLevel < chargeMax) |
| 4310 | chargeLevel++; |
| 4311 | |
| 4312 | chargeWait = 28 - this_player->items.weapon[REAR_WEAPON].power * 2; |
| 4313 | if (difficultyLevel > DIFFICULTY_HARD) |
| 4314 | chargeWait -= 5; |
| 4315 | } |
| 4316 | |
| 4317 | if (chargeLevel > 0) |
| 4318 | fill_rectangle_xy(VGAScreenSeg, 269, 107 + (chargeLevel - 1) * 3, 275, 108 + (chargeLevel - 1) * 3, 204); |
| 4319 | |
| 4320 | if (shotRepeat[SHOT_P2_CHARGE] > 0) |
| 4321 | { |
| 4322 | --shotRepeat[SHOT_P2_CHARGE]; |
| 4323 | } |
| 4324 | else if (button[1-1] && (!twoPlayerLinked || chargeLevel > 0)) |
| 4325 | { |
| 4326 | shotMultiPos[SHOT_P2_CHARGE] = 0; |
| 4327 | b = player_shot_create(16, SHOT_P2_CHARGE, this_player->x, this_player->y, *mouseX_, *mouseY_, chargeGunWeapons[player[1].items.weapon[REAR_WEAPON].id-1] + chargeLevel, playerNum_); |
| 4328 | |
| 4329 | if (chargeLevel > 0) |
| 4330 | fill_rectangle_xy(VGAScreenSeg, 269, 107 + (chargeLevel - 1) * 3, 275, 108 + (chargeLevel - 1) * 3, 193); |
| 4331 | |
| 4332 | chargeLevel = 0; |
| 4333 | chargeWait = 30 - this_player->items.weapon[REAR_WEAPON].power * 2; |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | /*SUPER BOMB*/ |
| 4338 | temp = playerNum_; |
| 4339 | if (temp == 0) |
| 4340 | temp = 1; /*Get whether player 1 or 2*/ |
| 4341 | |
| 4342 | if (player[temp-1].superbombs > 0) |
| 4343 | { |
| 4344 | if (shotRepeat[SHOT_P1_SUPERBOMB + temp-1] > 0) |
| 4345 | { |
| 4346 | --shotRepeat[SHOT_P1_SUPERBOMB + temp-1]; |
| 4347 | } |
| 4348 | else if (button[3-1] || button[2-1]) |
| 4349 | { |
| 4350 | --player[temp-1].superbombs; |
| 4351 | shotMultiPos[SHOT_P1_SUPERBOMB + temp-1] = 0; |
| 4352 | b = player_shot_create(16, SHOT_P1_SUPERBOMB + temp-1, this_player->x, this_player->y, *mouseX_, *mouseY_, 535, playerNum_); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | // sidekicks |
| 4357 | |
| 4358 | if (this_player->sidekick[LEFT_SIDEKICK].style == 4 && this_player->sidekick[RIGHT_SIDEKICK].style == 4) |
| 4359 | optionSatelliteRotate += 0.2f; |
| 4360 | else if (this_player->sidekick[LEFT_SIDEKICK].style == 4 || this_player->sidekick[RIGHT_SIDEKICK].style == 4) |
| 4361 | optionSatelliteRotate += 0.15f; |
| 4362 | |
| 4363 | switch (this_player->sidekick[LEFT_SIDEKICK].style) |
| 4364 | { |
| 4365 | case 1: // trailing |
| 4366 | case 3: |
| 4367 | this_player->sidekick[LEFT_SIDEKICK].x = this_player->old_x[COUNTOF(player->old_x) / 2 - 1]; |
| 4368 | this_player->sidekick[LEFT_SIDEKICK].y = this_player->old_y[COUNTOF(player->old_x) / 2 - 1]; |
| 4369 | break; |
| 4370 | case 2: // front-mounted |
| 4371 | this_player->sidekick[LEFT_SIDEKICK].x = this_player->x; |
| 4372 | this_player->sidekick[LEFT_SIDEKICK].y = MAX(10, this_player->y - 20); |
| 4373 | break; |
| 4374 | case 4: // orbiting |
| 4375 | this_player->sidekick[LEFT_SIDEKICK].x = this_player->x + roundf(sinf(optionSatelliteRotate) * 20); |
| 4376 | this_player->sidekick[LEFT_SIDEKICK].y = this_player->y + roundf(cosf(optionSatelliteRotate) * 20); |
| 4377 | break; |
| 4378 | } |
| 4379 | |
| 4380 | switch (this_player->sidekick[RIGHT_SIDEKICK].style) |
| 4381 | { |
| 4382 | case 4: // orbiting |
| 4383 | this_player->sidekick[RIGHT_SIDEKICK].x = this_player->x - roundf(sinf(optionSatelliteRotate) * 20); |
| 4384 | this_player->sidekick[RIGHT_SIDEKICK].y = this_player->y - roundf(cosf(optionSatelliteRotate) * 20); |
| 4385 | break; |
| 4386 | case 1: // trailing |
| 4387 | case 3: |
| 4388 | this_player->sidekick[RIGHT_SIDEKICK].x = this_player->old_x[0]; |
| 4389 | this_player->sidekick[RIGHT_SIDEKICK].y = this_player->old_y[0]; |
| 4390 | break; |
| 4391 | case 2: // front-mounted |
| 4392 | if (!optionAttachmentLinked) |
| 4393 | { |
| 4394 | this_player->sidekick[RIGHT_SIDEKICK].y += optionAttachmentMove / 2; |
| 4395 | if (optionAttachmentMove >= -2) |
| 4396 | { |
| 4397 | if (optionAttachmentReturn) |
| 4398 | temp = 2; |
| 4399 | else |
| 4400 | temp = 0; |
| 4401 | |
| 4402 | if (this_player->sidekick[RIGHT_SIDEKICK].y > (this_player->y - 20) + 5) |
| 4403 | { |
| 4404 | temp = 2; |
| 4405 | optionAttachmentMove -= 1 + optionAttachmentReturn; |
| 4406 | } |
| 4407 | else if (this_player->sidekick[RIGHT_SIDEKICK].y > (this_player->y - 20) - 0) |
| 4408 | { |
| 4409 | temp = 3; |
| 4410 | if (optionAttachmentMove > 0) |
| 4411 | optionAttachmentMove--; |
| 4412 | else |
| 4413 | optionAttachmentMove++; |
| 4414 | } |
| 4415 | else if (this_player->sidekick[RIGHT_SIDEKICK].y > (this_player->y - 20) - 5) |
| 4416 | { |
| 4417 | temp = 2; |
| 4418 | optionAttachmentMove++; |
| 4419 | } |
| 4420 | else if (optionAttachmentMove < 2 + optionAttachmentReturn * 4) |
| 4421 | { |
| 4422 | optionAttachmentMove += 1 + optionAttachmentReturn; |
| 4423 | } |
| 4424 | |
| 4425 | if (optionAttachmentReturn) |
| 4426 | temp = temp * 2; |
| 4427 | if (abs(this_player->sidekick[RIGHT_SIDEKICK].x - this_player->x) < temp) |
| 4428 | temp = 1; |
| 4429 | |
| 4430 | if (this_player->sidekick[RIGHT_SIDEKICK].x > this_player->x) |
| 4431 | this_player->sidekick[RIGHT_SIDEKICK].x -= temp; |
| 4432 | else if (this_player->sidekick[RIGHT_SIDEKICK].x < this_player->x) |
| 4433 | this_player->sidekick[RIGHT_SIDEKICK].x += temp; |
| 4434 | |
| 4435 | if (abs(this_player->sidekick[RIGHT_SIDEKICK].y - (this_player->y - 20)) + abs(this_player->sidekick[RIGHT_SIDEKICK].x - this_player->x) < 8) |
| 4436 | { |
| 4437 | optionAttachmentLinked = true; |
| 4438 | soundQueue[2] = S_CLINK; |
| 4439 | } |
| 4440 | |
| 4441 | if (button[3-1]) |
| 4442 | optionAttachmentReturn = true; |
| 4443 | } |
| 4444 | else // sidekick needs to catch up to player |
| 4445 | { |
| 4446 | optionAttachmentMove += 1 + optionAttachmentReturn; |
| 4447 | JE_setupExplosion(this_player->sidekick[RIGHT_SIDEKICK].x + 1, this_player->sidekick[RIGHT_SIDEKICK].y + 10, 0, 0, false, false); |
| 4448 | } |
| 4449 | } |
| 4450 | else |
| 4451 | { |
| 4452 | this_player->sidekick[RIGHT_SIDEKICK].x = this_player->x; |
| 4453 | this_player->sidekick[RIGHT_SIDEKICK].y = this_player->y - 20; |
| 4454 | if (button[3-1]) |
| 4455 | { |
| 4456 | optionAttachmentLinked = false; |
| 4457 | optionAttachmentReturn = false; |
| 4458 | optionAttachmentMove = -20; |
| 4459 | soundQueue[3] = S_WEAPON_26; |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | if (this_player->sidekick[RIGHT_SIDEKICK].y < 10) |
| 4464 | this_player->sidekick[RIGHT_SIDEKICK].y = 10; |
| 4465 | break; |
| 4466 | } |
| 4467 | |
| 4468 | if (playerNum_ == 2 || !twoPlayerMode) // if player has sidekicks |
| 4469 | { |
| 4470 | for (uint i = 0; i < COUNTOF(player->items.sidekick); ++i) |
| 4471 | { |
| 4472 | uint shot_i = (i == 0) ? SHOT_LEFT_SIDEKICK : SHOT_RIGHT_SIDEKICK; |
| 4473 | |
| 4474 | JE_OptionType *this_option = &options[this_player->items.sidekick[i]]; |
| 4475 | |
| 4476 | // fire/refill sidekick |
| 4477 | if (this_option->wport > 0) |
| 4478 | { |
| 4479 | if (shotRepeat[shot_i] > 0) |
| 4480 | { |
| 4481 | --shotRepeat[shot_i]; |
| 4482 | } |
| 4483 | else |
| 4484 | { |
| 4485 | const int ammo_max = this_player->sidekick[i].ammo_max; |
| 4486 | |
| 4487 | if (ammo_max > 0) // sidekick has limited ammo |
| 4488 | { |
| 4489 | if (this_player->sidekick[i].ammo_refill_ticks > 0) |
| 4490 | { |
| 4491 | --this_player->sidekick[i].ammo_refill_ticks; |
| 4492 | } |
| 4493 | else // refill one ammo |
| 4494 | { |
| 4495 | this_player->sidekick[i].ammo_refill_ticks = this_player->sidekick[i].ammo_refill_ticks_max; |
| 4496 | |
| 4497 | if (this_player->sidekick[i].ammo < ammo_max) |
| 4498 | ++this_player->sidekick[i].ammo; |
| 4499 | |
| 4500 | // draw sidekick refill ammo gauge |
| 4501 | const int y = hud_sidekick_y[twoPlayerMode ? 1 : 0][i] + 13; |
| 4502 | draw_segmented_gauge(VGAScreenSeg, 284, y, 112, 2, 2, MAX(1, ammo_max / 10), this_player->sidekick[i].ammo); |
| 4503 | } |
| 4504 | |
| 4505 | if (button[1 + i] && this_player->sidekick[i].ammo > 0) |
| 4506 | { |
| 4507 | b = player_shot_create(this_option->wport, shot_i, this_player->sidekick[i].x, this_player->sidekick[i].y, *mouseX_, *mouseY_, this_option->wpnum + this_player->sidekick[i].charge, playerNum_); |
| 4508 | |
| 4509 | --this_player->sidekick[i].ammo; |
| 4510 | if (this_player->sidekick[i].charge > 0) |
| 4511 | { |
| 4512 | shotMultiPos[shot_i] = 0; |
| 4513 | this_player->sidekick[i].charge = 0; |
| 4514 | } |
| 4515 | this_player->sidekick[i].charge_ticks = 20; |
| 4516 | this_player->sidekick[i].animation_enabled = true; |
| 4517 | |
| 4518 | // draw sidekick discharge ammo gauge |
| 4519 | const int y = hud_sidekick_y[twoPlayerMode ? 1 : 0][i] + 13; |
| 4520 | fill_rectangle_xy(VGAScreenSeg, 284, y, 312, y + 2, 0); |
| 4521 | draw_segmented_gauge(VGAScreenSeg, 284, y, 112, 2, 2, MAX(1, ammo_max / 10), this_player->sidekick[i].ammo); |
| 4522 | } |
| 4523 | } |
| 4524 | else // has infinite ammo |
| 4525 | { |
| 4526 | if (button[0] || button[1 + i]) |
| 4527 | { |
| 4528 | b = player_shot_create(this_option->wport, shot_i, this_player->sidekick[i].x, this_player->sidekick[i].y, *mouseX_, *mouseY_, this_option->wpnum + this_player->sidekick[i].charge, playerNum_); |
| 4529 | |
| 4530 | if (this_player->sidekick[i].charge > 0) |
| 4531 | { |
| 4532 | shotMultiPos[shot_i] = 0; |
| 4533 | this_player->sidekick[i].charge = 0; |
| 4534 | } |
| 4535 | this_player->sidekick[i].charge_ticks = 20; |
| 4536 | this_player->sidekick[i].animation_enabled = true; |
| 4537 | } |
| 4538 | } |
| 4539 | } |
| 4540 | } |
| 4541 | } |
| 4542 | } // end of if player has sidekicks |
| 4543 | } // !endLevel |
| 4544 | } // this_player->is_alive |
| 4545 | } // moveOK |
| 4546 | |
| 4547 | // draw sidekicks |
| 4548 | if ((playerNum_ == 2 || !twoPlayerMode) && !endLevel) |
| 4549 | { |
| 4550 | for (uint i = 0; i < COUNTOF(this_player->sidekick); ++i) |
| 4551 | { |
| 4552 | JE_OptionType *this_option = &options[this_player->items.sidekick[i]]; |
| 4553 | |
| 4554 | if (this_option->option > 0) |
| 4555 | { |
| 4556 | if (this_player->sidekick[i].animation_enabled) |
| 4557 | { |
| 4558 | if (++this_player->sidekick[i].animation_frame >= this_option->ani) |
| 4559 | { |
| 4560 | this_player->sidekick[i].animation_frame = 0; |
| 4561 | this_player->sidekick[i].animation_enabled = (this_option->option == 1); |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | const int x = this_player->sidekick[i].x, |
| 4566 | y = this_player->sidekick[i].y; |
| 4567 | const uint sprite = this_option->gr[this_player->sidekick[i].animation_frame] + this_player->sidekick[i].charge; |
| 4568 | |
| 4569 | if (this_player->sidekick[i].style == 1 || this_player->sidekick[i].style == 2) |
| 4570 | blit_sprite2x2(VGAScreen, x - 6, y, spriteSheet10, sprite); |
| 4571 | else |
| 4572 | blit_sprite2(VGAScreen, x, y, spriteSheet9, sprite); |
| 4573 | } |
| 4574 | |
| 4575 | if (--this_player->sidekick[i].charge_ticks == 0) |
| 4576 | { |
| 4577 | if (this_player->sidekick[i].charge < this_option->pwr) |
| 4578 | ++this_player->sidekick[i].charge; |
| 4579 | this_player->sidekick[i].charge_ticks = 20; |
| 4580 | } |
| 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | void JE_mainGamePlayerFunctions(void) |
| 4586 | { |
| 4587 | /*PLAYER MOVEMENT/MOUSE ROUTINES*/ |
| 4588 | |
| 4589 | if (endLevel && levelEnd > 0) |
| 4590 | { |
| 4591 | levelEnd--; |
| 4592 | levelEndWarp++; |
| 4593 | } |
| 4594 | |
| 4595 | /*Reset Street-Fighter commands*/ |
| 4596 | memset(SFExecuted, 0, sizeof(SFExecuted)); |
| 4597 | |
| 4598 | portConfigChange = false; |
| 4599 | |
| 4600 | if (twoPlayerMode) |
| 4601 | { |
| 4602 | JE_playerMovement(&player[0], |
| 4603 | !galagaMode ? inputDevice[0] : 0, 1, shipGr, shipGrPtr, |
| 4604 | &mouseX, &mouseY); |
| 4605 | JE_playerMovement(&player[1], |
| 4606 | !galagaMode ? inputDevice[1] : 0, 2, shipGr2, shipGr2ptr, |
| 4607 | &mouseXB, &mouseYB); |
| 4608 | } |
| 4609 | else |
| 4610 | { |
| 4611 | JE_playerMovement(&player[0], |
| 4612 | 0, 1, shipGr, shipGrPtr, |
| 4613 | &mouseX, &mouseY); |
| 4614 | } |
| 4615 | |
| 4616 | /* == Parallax Map Scrolling == */ |
| 4617 | if (twoPlayerMode) |
| 4618 | tempX = (player[0].x + player[1].x) / 2; |
| 4619 | else |
| 4620 | tempX = player[0].x; |
| 4621 | |
| 4622 | tempW = floorf((260.0f - (tempX - 36.0f)) / (260.0f - 36.0f) * (24.0f * 3.0f) - 1.0f); |
| 4623 | mapX3Ofs = tempW; |
| 4624 | mapX3Pos = mapX3Ofs % 24; |
| 4625 | mapX3bpPos = 1 - (mapX3Ofs / 24); |
| 4626 | |
| 4627 | mapX2Ofs = (tempW * 2) / 3; |
| 4628 | mapX2Pos = mapX2Ofs % 24; |
| 4629 | mapX2bpPos = 1 - (mapX2Ofs / 24); |
| 4630 | |
| 4631 | oldMapXOfs = mapXOfs; |
| 4632 | mapXOfs = mapX2Ofs / 2; |
| 4633 | mapXPos = mapXOfs % 24; |
| 4634 | mapXbpPos = 1 - (mapXOfs / 24); |
| 4635 | |
| 4636 | if (background3x1) |
| 4637 | { |
| 4638 | mapX3Ofs = mapXOfs; |
| 4639 | mapX3Pos = mapXPos; |
| 4640 | mapX3bpPos = mapXbpPos - 1; |
| 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | const char *JE_getName(JE_byte pnum) |
| 4645 | { |
| 4646 | if (pnum == thisPlayerNum && network_player_name[0] != '\0') |
| 4647 | return network_player_name; |
| 4648 | else if (network_opponent_name[0] != '\0') |
| 4649 | return network_opponent_name; |
| 4650 | |
| 4651 | return miscText[47 + pnum]; |
| 4652 | } |
| 4653 | |
| 4654 | void JE_playerCollide(Player *this_player, JE_byte playerNum_) |
| 4655 | { |
| 4656 | char tempStr[256]; |
| 4657 | |
| 4658 | for (int z = 0; z < 100; z++) |
| 4659 | { |
| 4660 | if (enemyAvail[z] != 1) |
| 4661 | { |
| 4662 | int enemy_screen_x = enemy[z].ex + enemy[z].mapoffset; |
| 4663 | |
| 4664 | if (abs(this_player->x - enemy_screen_x) < 12 && abs(this_player->y - enemy[z].ey) < 14) |
| 4665 | { /*Collide*/ |
| 4666 | int evalue = enemy[z].evalue; |
| 4667 | if (evalue > 29999) |
| 4668 | { |
| 4669 | if (evalue == 30000) // spawn dragonwing in galaga mode, otherwise just a purple ball |
| 4670 | { |
| 4671 | this_player->cash += 100; |
| 4672 | |
| 4673 | if (!galagaMode) |
| 4674 | { |
| 4675 | handle_got_purple_ball(this_player); |
| 4676 | } |
| 4677 | else |
| 4678 | { |
| 4679 | // spawn the dragonwing? |
| 4680 | if (twoPlayerMode) |
| 4681 | this_player->cash += 2400; |
| 4682 | twoPlayerMode = true; |
| 4683 | twoPlayerLinked = true; |
| 4684 | player[1].items.weapon[REAR_WEAPON].power = 1; |
| 4685 | player[1].armor = 10; |
| 4686 | player[1].is_alive = true; |
| 4687 | } |
| 4688 | enemyAvail[z] = 1; |
| 4689 | soundQueue[7] = S_POWERUP; |
| 4690 | } |
| 4691 | else if (superArcadeMode != SA_NONE && evalue > 30000) |
| 4692 | { |
| 4693 | shotMultiPos[SHOT_FRONT] = 0; |
| 4694 | shotRepeat[SHOT_FRONT] = 10; |
| 4695 | |
| 4696 | tempW = SAWeapon[superArcadeMode-1][evalue - 30000-1]; |
| 4697 | |
| 4698 | // if picked up already-owned weapon, power weapon up |
| 4699 | if (tempW == player[0].items.weapon[FRONT_WEAPON].id) |
| 4700 | { |
| 4701 | this_player->cash += 1000; |
| 4702 | power_up_weapon(this_player, FRONT_WEAPON); |
| 4703 | } |
| 4704 | // else weapon also gives purple ball |
| 4705 | else |
| 4706 | { |
| 4707 | handle_got_purple_ball(this_player); |
| 4708 | } |
| 4709 | |
| 4710 | player[0].items.weapon[FRONT_WEAPON].id = tempW; |
| 4711 | this_player->cash += 200; |
| 4712 | soundQueue[7] = S_POWERUP; |
| 4713 | enemyAvail[z] = 1; |
| 4714 | } |
| 4715 | else if (evalue > 32100) |
| 4716 | { |
| 4717 | if (playerNum_ == 1) |
| 4718 | { |
| 4719 | this_player->cash += 250; |
| 4720 | player[0].items.special = evalue - 32100; |
| 4721 | shotMultiPos[SHOT_SPECIAL] = 0; |
| 4722 | shotRepeat[SHOT_SPECIAL] = 10; |
| 4723 | shotMultiPos[SHOT_SPECIAL2] = 0; |
| 4724 | shotRepeat[SHOT_SPECIAL2] = 0; |
| 4725 | |
| 4726 | if (isNetworkGame) |
| 4727 | sprintf(tempStr, "%s %s %s", JE_getName(1), miscTextB[4-1], special[evalue - 32100].name); |
| 4728 | else if (twoPlayerMode) |
| 4729 | sprintf(tempStr, "%s %s", miscText[43-1], special[evalue - 32100].name); |
| 4730 | else |
| 4731 | sprintf(tempStr, "%s %s", miscText[64-1], special[evalue - 32100].name); |
| 4732 | JE_drawTextWindow(tempStr); |
| 4733 | soundQueue[7] = S_POWERUP; |
| 4734 | enemyAvail[z] = 1; |
| 4735 | } |
| 4736 | } |
| 4737 | else if (evalue > 32000) |
| 4738 | { |
| 4739 | if (playerNum_ == 2) |
| 4740 | { |
| 4741 | enemyAvail[z] = 1; |
| 4742 | if (isNetworkGame) |
| 4743 | sprintf(tempStr, "%s %s %s", JE_getName(2), miscTextB[4-1], options[evalue - 32000].name); |
| 4744 | else |
| 4745 | sprintf(tempStr, "%s %s", miscText[44-1], options[evalue - 32000].name); |
| 4746 | JE_drawTextWindow(tempStr); |
| 4747 | |
| 4748 | // if picked up a different sidekick than player already has, then reset sidekicks to least powerful, else power them up |
| 4749 | if (evalue - 32000u != player[1].items.sidekick_series) |
| 4750 | { |
| 4751 | player[1].items.sidekick_series = evalue - 32000; |
| 4752 | player[1].items.sidekick_level = 101; |
| 4753 | } |
| 4754 | else if (player[1].items.sidekick_level < 103) |
| 4755 | { |
| 4756 | ++player[1].items.sidekick_level; |
| 4757 | } |
| 4758 | |
| 4759 | uint temp = player[1].items.sidekick_level - 100 - 1; |
| 4760 | for (uint i = 0; i < COUNTOF(player[1].items.sidekick); ++i) |
| 4761 | player[1].items.sidekick[i] = optionSelect[player[1].items.sidekick_series][temp][i]; |
| 4762 | |
| 4763 | shotMultiPos[SHOT_LEFT_SIDEKICK] = 0; |
| 4764 | shotMultiPos[SHOT_RIGHT_SIDEKICK] = 0; |
| 4765 | JE_drawOptions(); |
| 4766 | soundQueue[7] = S_POWERUP; |
| 4767 | } |
| 4768 | else if (onePlayerAction) |
| 4769 | { |
| 4770 | enemyAvail[z] = 1; |
| 4771 | sprintf(tempStr, "%s %s", miscText[64-1], options[evalue - 32000].name); |
| 4772 | JE_drawTextWindow(tempStr); |
| 4773 | |
| 4774 | for (uint i = 0; i < COUNTOF(player[0].items.sidekick); ++i) |
| 4775 | player[0].items.sidekick[i] = evalue - 32000; |
| 4776 | shotMultiPos[SHOT_LEFT_SIDEKICK] = 0; |
| 4777 | shotMultiPos[SHOT_RIGHT_SIDEKICK] = 0; |
| 4778 | |
| 4779 | JE_drawOptions(); |
| 4780 | soundQueue[7] = S_POWERUP; |
| 4781 | } |
| 4782 | if (enemyAvail[z] == 1) |
| 4783 | this_player->cash += 250; |
| 4784 | } |
| 4785 | else if (evalue > 31000) |
| 4786 | { |
| 4787 | this_player->cash += 250; |
| 4788 | if (playerNum_ == 2) |
| 4789 | { |
| 4790 | if (isNetworkGame) |
| 4791 | sprintf(tempStr, "%s %s %s", JE_getName(2), miscTextB[4-1], weaponPort[evalue - 31000].name); |
| 4792 | else |
| 4793 | sprintf(tempStr, "%s %s", miscText[44-1], weaponPort[evalue - 31000].name); |
| 4794 | JE_drawTextWindow(tempStr); |
| 4795 | player[1].items.weapon[REAR_WEAPON].id = evalue - 31000; |
| 4796 | shotMultiPos[SHOT_REAR] = 0; |
| 4797 | enemyAvail[z] = 1; |
| 4798 | soundQueue[7] = S_POWERUP; |
| 4799 | } |
| 4800 | else if (onePlayerAction) |
| 4801 | { |
| 4802 | sprintf(tempStr, "%s %s", miscText[64-1], weaponPort[evalue - 31000].name); |
| 4803 | JE_drawTextWindow(tempStr); |
| 4804 | player[0].items.weapon[REAR_WEAPON].id = evalue - 31000; |
| 4805 | shotMultiPos[SHOT_REAR] = 0; |
| 4806 | enemyAvail[z] = 1; |
| 4807 | soundQueue[7] = S_POWERUP; |
| 4808 | |
| 4809 | if (player[0].items.weapon[REAR_WEAPON].power == 0) // does this ever happen? |
| 4810 | player[0].items.weapon[REAR_WEAPON].power = 1; |
| 4811 | } |
| 4812 | } |
| 4813 | else if (evalue > 30000) |
| 4814 | { |
| 4815 | if (playerNum_ == 1 && twoPlayerMode) |
| 4816 | { |
| 4817 | if (isNetworkGame) |
| 4818 | sprintf(tempStr, "%s %s %s", JE_getName(1), miscTextB[4-1], weaponPort[evalue - 30000].name); |
| 4819 | else |
| 4820 | sprintf(tempStr, "%s %s", miscText[43-1], weaponPort[evalue - 30000].name); |
| 4821 | JE_drawTextWindow(tempStr); |
| 4822 | player[0].items.weapon[FRONT_WEAPON].id = evalue - 30000; |
| 4823 | shotMultiPos[SHOT_FRONT] = 0; |
| 4824 | enemyAvail[z] = 1; |
| 4825 | soundQueue[7] = S_POWERUP; |
| 4826 | } |
| 4827 | else if (onePlayerAction) |
| 4828 | { |
| 4829 | sprintf(tempStr, "%s %s", miscText[64-1], weaponPort[evalue - 30000].name); |
| 4830 | JE_drawTextWindow(tempStr); |
| 4831 | player[0].items.weapon[FRONT_WEAPON].id = evalue - 30000; |
| 4832 | shotMultiPos[SHOT_FRONT] = 0; |
| 4833 | enemyAvail[z] = 1; |
| 4834 | soundQueue[7] = S_POWERUP; |
| 4835 | } |
| 4836 | |
| 4837 | if (enemyAvail[z] == 1) |
| 4838 | { |
| 4839 | player[0].items.special = specialArcadeWeapon[evalue - 30000-1]; |
| 4840 | if (player[0].items.special > 0) |
| 4841 | { |
| 4842 | shotMultiPos[SHOT_SPECIAL] = 0; |
| 4843 | shotRepeat[SHOT_SPECIAL] = 0; |
| 4844 | shotMultiPos[SHOT_SPECIAL2] = 0; |
| 4845 | shotRepeat[SHOT_SPECIAL2] = 0; |
| 4846 | } |
| 4847 | this_player->cash += 250; |
| 4848 | } |
| 4849 | |
| 4850 | } |
| 4851 | } |
| 4852 | else if (evalue > 20000) |
| 4853 | { |
| 4854 | if (twoPlayerLinked) |
| 4855 | { |
| 4856 | // share the armor evenly between linked players |
| 4857 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 4858 | { |
| 4859 | player[i].armor += (evalue - 20000) / COUNTOF(player); |
| 4860 | if (player[i].armor > 28) |
| 4861 | player[i].armor = 28; |
| 4862 | } |
| 4863 | } |
| 4864 | else |
| 4865 | { |
| 4866 | this_player->armor += evalue - 20000; |
| 4867 | if (this_player->armor > 28) |
| 4868 | this_player->armor = 28; |
| 4869 | } |
| 4870 | enemyAvail[z] = 1; |
| 4871 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 4872 | JE_drawArmor(); |
| 4873 | VGAScreen = game_screen; /* side-effect of game_screen */ |
| 4874 | soundQueue[7] = S_POWERUP; |
| 4875 | } |
| 4876 | else if (evalue > 10000 && enemyAvail[z] == 2) |
| 4877 | { |
| 4878 | if (!bonusLevel) |
| 4879 | { |
| 4880 | play_song(30); /*Zanac*/ |
| 4881 | bonusLevel = true; |
| 4882 | nextLevel = evalue - 10000; |
| 4883 | enemyAvail[z] = 1; |
| 4884 | displayTime = 150; |
| 4885 | } |
| 4886 | } |
| 4887 | else if (enemy[z].scoreitem) |
| 4888 | { |
| 4889 | enemyAvail[z] = 1; |
| 4890 | soundQueue[7] = S_ITEM; |
| 4891 | if (evalue == 1) |
| 4892 | { |
| 4893 | cubeMax++; |
| 4894 | soundQueue[3] = V_DATA_CUBE; |
| 4895 | } |
| 4896 | else if (evalue == -1) // got front weapon powerup |
| 4897 | { |
| 4898 | if (isNetworkGame) |
| 4899 | sprintf(tempStr, "%s %s %s", JE_getName(1), miscTextB[4-1], miscText[45-1]); |
| 4900 | else if (twoPlayerMode) |
| 4901 | sprintf(tempStr, "%s %s", miscText[43-1], miscText[45-1]); |
| 4902 | else |
| 4903 | strcpy(tempStr, miscText[45-1]); |
| 4904 | JE_drawTextWindow(tempStr); |
| 4905 | |
| 4906 | power_up_weapon(&player[0], FRONT_WEAPON); |
| 4907 | soundQueue[7] = S_POWERUP; |
| 4908 | } |
| 4909 | else if (evalue == -2) // got rear weapon powerup |
| 4910 | { |
| 4911 | if (isNetworkGame) |
| 4912 | sprintf(tempStr, "%s %s %s", JE_getName(2), miscTextB[4-1], miscText[46-1]); |
| 4913 | else if (twoPlayerMode) |
| 4914 | sprintf(tempStr, "%s %s", miscText[44-1], miscText[46-1]); |
| 4915 | else |
| 4916 | strcpy(tempStr, miscText[46-1]); |
| 4917 | JE_drawTextWindow(tempStr); |
| 4918 | |
| 4919 | power_up_weapon(twoPlayerMode ? &player[1] : &player[0], REAR_WEAPON); |
| 4920 | soundQueue[7] = S_POWERUP; |
| 4921 | } |
| 4922 | else if (evalue == -3) |
| 4923 | { |
| 4924 | // picked up orbiting asteroid killer |
| 4925 | shotMultiPos[SHOT_MISC] = 0; |
| 4926 | b = player_shot_create(0, SHOT_MISC, this_player->x, this_player->y, mouseX, mouseY, 104, playerNum_); |
| 4927 | shotAvail[z] = 0; |
| 4928 | } |
| 4929 | else if (evalue == -4) |
| 4930 | { |
| 4931 | if (player[playerNum_-1].superbombs < 10) |
| 4932 | ++player[playerNum_-1].superbombs; |
| 4933 | } |
| 4934 | else if (evalue == -5) |
| 4935 | { |
| 4936 | player[0].items.weapon[FRONT_WEAPON].id = 25; // HOT DOG! |
| 4937 | player[0].items.weapon[REAR_WEAPON].id = 26; |
| 4938 | player[1].items.weapon[REAR_WEAPON].id = 26; |
| 4939 | |
| 4940 | player[0].last_items = player[0].items; |
| 4941 | |
| 4942 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 4943 | player[i].weapon_mode = 1; |
| 4944 | |
| 4945 | memset(shotMultiPos, 0, sizeof(shotMultiPos)); |
| 4946 | } |
| 4947 | else if (twoPlayerLinked) |
| 4948 | { |
| 4949 | // players get equal share of pick-up cash when linked |
| 4950 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 4951 | player[i].cash += evalue / COUNTOF(player); |
| 4952 | } |
| 4953 | else |
| 4954 | { |
| 4955 | this_player->cash += evalue; |
| 4956 | } |
| 4957 | JE_setupExplosion(enemy_screen_x, enemy[z].ey, 0, enemyDat[enemy[z].enemytype].explosiontype, true, false); |
| 4958 | } |
| 4959 | else if (this_player->invulnerable_ticks == 0 && enemyAvail[z] == 0 && |
| 4960 | (enemyDat[enemy[z].enemytype].explosiontype & 1) == 0) // explosiontype & 1 == 0: not ground enemy |
| 4961 | { |
| 4962 | int armorleft = enemy[z].armorleft; |
| 4963 | if (armorleft > damageRate) |
| 4964 | armorleft = damageRate; |
| 4965 | |
| 4966 | JE_playerDamage(armorleft, this_player); |
| 4967 | |
| 4968 | // player ship gets push-back from collision |
| 4969 | if (enemy[z].armorleft > 0) |
| 4970 | { |
| 4971 | this_player->x_velocity += (enemy[z].exc * enemy[z].armorleft) / 2; |
| 4972 | this_player->y_velocity += (enemy[z].eyc * enemy[z].armorleft) / 2; |
| 4973 | } |
| 4974 | |
| 4975 | int armorleft2 = enemy[z].armorleft; |
| 4976 | if (armorleft2 == 255) |
| 4977 | armorleft2 = 30000; |
| 4978 | |
| 4979 | temp = enemy[z].linknum; |
| 4980 | if (temp == 0) |
| 4981 | temp = 255; |
| 4982 | |
| 4983 | b = z; |
| 4984 | |
| 4985 | if (armorleft2 > armorleft) |
| 4986 | { |
| 4987 | // damage enemy |
| 4988 | if (enemy[z].armorleft != 255) |
| 4989 | enemy[z].armorleft -= armorleft; |
| 4990 | soundQueue[5] = S_ENEMY_HIT; |
| 4991 | } |
| 4992 | else |
| 4993 | { |
| 4994 | // kill enemy |
| 4995 | for (temp2 = 0; temp2 < 100; temp2++) |
| 4996 | { |
| 4997 | if (enemyAvail[temp2] != 1) |
| 4998 | { |
| 4999 | temp3 = enemy[temp2].linknum; |
| 5000 | if (temp2 == b || |
| 5001 | (temp != 255 && |
| 5002 | (temp == temp3 || temp - 100 == temp3 || |
| 5003 | (temp3 > 40 && temp3 / 20 == temp / 20 && temp3 <= temp)))) |
| 5004 | { |
| 5005 | int enemy_screen_x = enemy[temp2].ex + enemy[temp2].mapoffset; |
| 5006 | |
| 5007 | enemy[temp2].linknum = 0; |
| 5008 | |
| 5009 | enemyAvail[temp2] = 1; |
| 5010 | |
| 5011 | if (enemyDat[enemy[temp2].enemytype].esize == 1) |
| 5012 | { |
| 5013 | JE_setupExplosionLarge(enemy[temp2].enemyground, enemy[temp2].explonum, enemy_screen_x, enemy[temp2].ey); |
| 5014 | soundQueue[6] = S_EXPLOSION_9; |
| 5015 | } |
| 5016 | else |
| 5017 | { |
| 5018 | JE_setupExplosion(enemy_screen_x, enemy[temp2].ey, 0, 1, false, false); |
| 5019 | soundQueue[5] = S_EXPLOSION_4; |
| 5020 | } |
| 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | enemyAvail[z] = 1; |
| 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | } |
| 5030 | } |
| 5031 | } |