| 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 | #ifdef TARGET_UNIX |
| 20 | #include <unistd.h> |
| 21 | #endif |
| 22 | |
| 23 | #include "varz.h" |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "editship.h" |
| 27 | #include "episodes.h" |
| 28 | #include "joystick.h" |
| 29 | #include "lds_play.h" |
| 30 | #include "loudness.h" |
| 31 | #include "mainint.h" |
| 32 | #include "mouse.h" |
| 33 | #include "mtrand.h" |
| 34 | #include "network.h" |
| 35 | #include "nortsong.h" |
| 36 | #include "nortvars.h" |
| 37 | #include "opentyr.h" |
| 38 | #include "shots.h" |
| 39 | #include "sprite.h" |
| 40 | #include "vga256d.h" |
| 41 | #include "video.h" |
| 42 | |
| 43 | JE_integer tempDat, tempDat2, tempDat3; |
| 44 | |
| 45 | const JE_byte SANextShip[SA + 2] /* [0..SA + 1] */ = { 3, 9, 6, 2, 5, 1, 4, 3, 7 }; // 0 -> 3 -> 2 -> 6 -> 4 -> 5 -> 1 -> 9 -> 7 |
| 46 | const JE_word SASpecialWeapon[SA] /* [1..SA] */ = { 7, 8, 9, 10, 11, 12, 13 }; |
| 47 | const JE_word SASpecialWeaponB[SA] /* [1..SA] */ = {37, 6, 15, 40, 16, 14, 41 }; |
| 48 | const JE_byte SAShip[SA] /* [1..SA] */ = { 3, 1, 5, 10, 2, 11, 12 }; |
| 49 | const JE_word SAWeapon[SA][5] /* [1..SA, 1..5] */ = |
| 50 | { /* R Bl Bk G P */ |
| 51 | { 9, 31, 32, 33, 34 }, /* Stealth Ship */ |
| 52 | { 19, 8, 22, 41, 34 }, /* StormWind */ |
| 53 | { 27, 5, 20, 42, 31 }, /* Techno */ |
| 54 | { 15, 3, 28, 22, 12 }, /* Enemy */ |
| 55 | { 23, 35, 25, 14, 6 }, /* Weird */ |
| 56 | { 2, 5, 21, 4, 7 }, /* Unknown */ |
| 57 | { 40, 38, 37, 41, 36 } /* NortShip Z */ |
| 58 | }; |
| 59 | |
| 60 | const JE_byte specialArcadeWeapon[PORT_NUM] /* [1..Portnum] */ = |
| 61 | { |
| 62 | 17,17,18,0,0,0,10,0,0,0,0,0,44,0,10,0,19,0,0,-0,0,0,0,0,0,0, |
| 63 | -0,0,0,0,45,0,0,0,0,0,0,0,0,0,0,0 |
| 64 | }; |
| 65 | |
| 66 | const JE_byte optionSelect[16][3][2] /* [0..15, 1..3, 1..2] */ = |
| 67 | { /* MAIN OPT FRONT */ |
| 68 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 69 | { { 1, 1},{16,16},{30,30} }, /*Single Shot*/ |
| 70 | { { 2, 2},{29,29},{29,20} }, /*Dual Shot*/ |
| 71 | { { 3, 3},{21,21},{12, 0} }, /*Charge Cannon*/ |
| 72 | { { 4, 4},{18,18},{16,23} }, /*Vulcan*/ |
| 73 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 74 | { { 6, 6},{29,16},{ 0,22} }, /*Super Missile*/ |
| 75 | { { 7, 7},{19,19},{19,28} }, /*Atom Bomb*/ |
| 76 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 77 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 78 | { {10,10},{21,21},{21,27} }, /*Mini Missile*/ |
| 79 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 80 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 81 | { {13,13},{17,17},{13,26} }, /*MicroBomb*/ |
| 82 | { { 0, 0},{ 0, 0},{ 0, 0} }, /**/ |
| 83 | { {15,15},{15,16},{15,16} } /*Post-It*/ |
| 84 | }; |
| 85 | |
| 86 | const JE_word PGR[21] /* [1..21] */ = |
| 87 | { |
| 88 | 4, |
| 89 | 1,2,3, |
| 90 | 41-21,57-21,73-21,89-21,105-21, |
| 91 | 121-21,137-21,153-21, |
| 92 | 151,151,151,151,73-21,73-21,1,2,4 |
| 93 | /*151,151,151*/ |
| 94 | }; |
| 95 | const JE_byte PAni[21] /* [1..21] */ = {1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1}; |
| 96 | |
| 97 | const JE_word linkGunWeapons[38] /* [1..38] */ = |
| 98 | { |
| 99 | 0,0,0,0,0,0,0,0,444,445,446,447,0,448,449,0,0,0,0,0,450,451,0,506,0,564, |
| 100 | 445,446,447,448,449,445,446,447,448,449,450,451 |
| 101 | }; |
| 102 | const JE_word chargeGunWeapons[38] /* [1..38] */ = |
| 103 | { |
| 104 | 0,0,0,0,0,0,0,0,476,458,464,482,0,488,470,0,0,0,0,0,494,500,0,528,0,558, |
| 105 | 458,458,458,458,458,458,458,458,458,458,458,458 |
| 106 | }; |
| 107 | const JE_byte randomEnemyLaunchSounds[3] /* [1..3] */ = {13,6,26}; |
| 108 | |
| 109 | /* YKS: Twiddle cheat sheet: |
| 110 | * 1: UP |
| 111 | * 2: DOWN |
| 112 | * 3: LEFT |
| 113 | * 4: RIGHT |
| 114 | * 5: UP+FIRE |
| 115 | * 6: DOWN+FIRE |
| 116 | * 7: LEFT+FIRE |
| 117 | * 8: RIGHT+FIRE |
| 118 | * 9: Release all keys (directions and fire) |
| 119 | */ |
| 120 | const JE_byte keyboardCombos[26][8] /* [1..26, 1..8] */ = |
| 121 | { |
| 122 | { 2, 1, 2, 5, 137, 0, 0, 0}, /*Invulnerability*/ |
| 123 | { 4, 3, 2, 5, 138, 0, 0, 0}, /*Atom Bomb*/ |
| 124 | { 3, 4, 6, 139, 0, 0, 0, 0}, /*Seeker Bombs*/ |
| 125 | { 2, 5, 142, 0, 0, 0, 0, 0}, /*Ice Blast*/ |
| 126 | { 6, 2, 6, 143, 0, 0, 0, 0}, /*Auto Repair*/ |
| 127 | { 6, 7, 5, 8, 6, 7, 5, 112 }, /*Spin Wave*/ |
| 128 | { 7, 8, 101, 0, 0, 0, 0, 0}, /*Repulsor*/ |
| 129 | { 1, 7, 6, 146, 0, 0, 0, 0}, /*Protron Field*/ |
| 130 | { 8, 6, 7, 1, 120, 0, 0, 0}, /*Minefield*/ |
| 131 | { 3, 6, 8, 5, 121, 0, 0, 0}, /*Post-It Blast*/ |
| 132 | { 1, 2, 7, 8, 119, 0, 0, 0}, /*Drone Ship - TBC*/ |
| 133 | { 3, 4, 3, 6, 123, 0, 0, 0}, /*Repair Player 2*/ |
| 134 | { 6, 7, 5, 8, 124, 0, 0, 0}, /*Super Bomb - TBC*/ |
| 135 | { 1, 6, 125, 0, 0, 0, 0, 0}, /*Hot Dog*/ |
| 136 | { 9, 5, 126, 0, 0, 0, 0, 0}, /*Lightning UP */ |
| 137 | { 1, 7, 127, 0, 0, 0, 0, 0}, /*Lightning UP+LEFT */ |
| 138 | { 1, 8, 128, 0, 0, 0, 0, 0}, /*Lightning UP+RIGHT*/ |
| 139 | { 9, 7, 129, 0, 0, 0, 0, 0}, /*Lightning LEFT */ |
| 140 | { 9, 8, 130, 0, 0, 0, 0, 0}, /*Lightning RIGHT*/ |
| 141 | { 4, 2, 3, 5, 131, 0, 0, 0}, /*Warfly */ |
| 142 | { 3, 1, 2, 8, 132, 0, 0, 0}, /*FrontBlaster */ |
| 143 | { 2, 4, 5, 133, 0, 0, 0, 0}, /*Gerund */ |
| 144 | { 3, 4, 2, 8, 134, 0, 0, 0}, /*FireBomb */ |
| 145 | { 1, 4, 6, 135, 0, 0, 0, 0}, /*Indigo */ |
| 146 | { 1, 3, 6, 137, 0, 0, 0, 0}, /*Invulnerability [easier] */ |
| 147 | { 1, 4, 3, 4, 7, 136, 0, 0} /*D-Media Protron Drone */ |
| 148 | }; |
| 149 | |
| 150 | const JE_byte shipCombosB[21] /* [1..21] */ = |
| 151 | {15,16,17,18,19,20,21,22,23,24, 7, 8, 5,25,14, 4, 6, 3, 9, 2,26}; |
| 152 | /*!! SUPER Tyrian !!*/ |
| 153 | const JE_byte superTyrianSpecials[4] /* [1..4] */ = {1,2,4,5}; |
| 154 | |
| 155 | const JE_byte shipCombos[14][3] /* [0..12, 1..3] */ = |
| 156 | { |
| 157 | { 5, 4, 7}, /*2nd Player ship*/ |
| 158 | { 1, 2, 0}, /*USP Talon*/ |
| 159 | {14, 4, 0}, /*Super Carrot*/ |
| 160 | { 4, 5, 0}, /*Gencore Phoenix*/ |
| 161 | { 6, 5, 0}, /*Gencore Maelstrom*/ |
| 162 | { 7, 8, 0}, /*MicroCorp Stalker*/ |
| 163 | { 7, 9, 0}, /*MicroCorp Stalker-B*/ |
| 164 | {10, 3, 5}, /*Prototype Stalker-C*/ |
| 165 | { 5, 8, 9}, /*Stalker*/ |
| 166 | { 1, 3, 0}, /*USP Fang*/ |
| 167 | { 7,16,17}, /*U-Ship*/ |
| 168 | { 2,11,12}, /*1st Player ship*/ |
| 169 | { 3, 8,10}, /*Nort ship*/ |
| 170 | { 0, 0, 0} // Dummy entry added for Stalker 21.126 |
| 171 | }; |
| 172 | |
| 173 | /*Street-Fighter Commands*/ |
| 174 | JE_byte SFCurrentCode[2][21]; /* [1..2, 1..21] */ |
| 175 | JE_byte SFExecuted[2]; /* [1..2] */ |
| 176 | |
| 177 | /*Special General Data*/ |
| 178 | JE_byte lvlFileNum; |
| 179 | JE_word maxEvent, eventLoc; |
| 180 | /*JE_word maxenemies;*/ |
| 181 | JE_word tempBackMove, explodeMove; /*Speed of background movement*/ |
| 182 | JE_byte levelEnd; |
| 183 | JE_word levelEndFxWait; |
| 184 | JE_shortint levelEndWarp; |
| 185 | JE_boolean endLevel, reallyEndLevel, waitToEndLevel, playerEndLevel, |
| 186 | normalBonusLevelCurrent, bonusLevelCurrent, |
| 187 | smallEnemyAdjust, readyToEndLevel, quitRequested; |
| 188 | |
| 189 | JE_byte newPL[10]; /* [0..9] */ /*Eventsys event 75 parameter*/ |
| 190 | JE_word returnLoc; |
| 191 | JE_boolean returnActive; |
| 192 | JE_word galagaShotFreq; |
| 193 | JE_longint galagaLife; |
| 194 | |
| 195 | JE_boolean debug = false; /*Debug Mode*/ |
| 196 | Uint32 debugTime, lastDebugTime; |
| 197 | JE_longint debugHistCount; |
| 198 | JE_real debugHist; |
| 199 | JE_word curLoc; /*Current Pixel location of background 1*/ |
| 200 | |
| 201 | JE_boolean firstGameOver, gameLoaded, enemyStillExploding; |
| 202 | |
| 203 | /* Destruction Ratio */ |
| 204 | JE_word totalEnemy; |
| 205 | JE_word enemyKilled; |
| 206 | |
| 207 | /* Shape/Map Data - All in one Segment! */ |
| 208 | struct JE_MegaDataType1 megaData1; |
| 209 | struct JE_MegaDataType2 megaData2; |
| 210 | struct JE_MegaDataType3 megaData3; |
| 211 | |
| 212 | /* Secret Level Display */ |
| 213 | JE_byte flash; |
| 214 | JE_shortint flashChange; |
| 215 | JE_byte displayTime; |
| 216 | |
| 217 | /* Demo Stuff */ |
| 218 | bool play_demo = false, record_demo = false, stopped_demo = false; |
| 219 | Uint8 demo_num = 0; |
| 220 | FILE *demo_file = NULL; |
| 221 | |
| 222 | Uint8 demo_keys; |
| 223 | Uint16 demo_keys_wait; |
| 224 | |
| 225 | /* Sound Effects Queue */ |
| 226 | JE_byte soundQueue[8]; /* [0..7] */ |
| 227 | |
| 228 | /*Level Event Data*/ |
| 229 | JE_boolean enemyContinualDamage; |
| 230 | JE_boolean enemiesActive; |
| 231 | JE_boolean forceEvents; |
| 232 | JE_boolean stopBackgrounds; |
| 233 | JE_byte stopBackgroundNum; |
| 234 | JE_byte damageRate; /*Rate at which a player takes damage*/ |
| 235 | JE_boolean background3x1; /*Background 3 enemies use Background 1 X offset*/ |
| 236 | JE_boolean background3x1b; /*Background 3 enemies moved 8 pixels left*/ |
| 237 | |
| 238 | JE_boolean levelTimer; |
| 239 | JE_word levelTimerCountdown; |
| 240 | JE_word levelTimerJumpTo; |
| 241 | JE_boolean randomExplosions; |
| 242 | |
| 243 | JE_boolean editShip1, editShip2; |
| 244 | |
| 245 | JE_boolean globalFlags[10]; /* [1..10] */ |
| 246 | JE_byte levelSong; |
| 247 | |
| 248 | /* DESTRUCT game */ |
| 249 | JE_boolean loadDestruct; |
| 250 | |
| 251 | /* MapView Data */ |
| 252 | JE_word mapOrigin, mapPNum; |
| 253 | JE_byte mapPlanet[5], mapSection[5]; /* [1..5] */ |
| 254 | |
| 255 | /* Interface Constants */ |
| 256 | JE_boolean moveTyrianLogoUp; |
| 257 | JE_boolean skipStarShowVGA; |
| 258 | |
| 259 | /*EnemyData*/ |
| 260 | JE_MultiEnemyType enemy; |
| 261 | JE_EnemyAvailType enemyAvail; /* values: 0: used, 1: free, 2: secret pick-up */ |
| 262 | JE_word enemyOffset; |
| 263 | JE_word enemyOnScreen; |
| 264 | JE_word superEnemy254Jump; |
| 265 | |
| 266 | /*EnemyShotData*/ |
| 267 | JE_boolean fireButtonHeld; |
| 268 | JE_boolean enemyShotAvail[ENEMY_SHOT_MAX]; /* [1..Enemyshotmax] */ |
| 269 | EnemyShotType enemyShot[ENEMY_SHOT_MAX]; /* [1..Enemyshotmax] */ |
| 270 | |
| 271 | /* Player Shot Data */ |
| 272 | JE_byte zinglonDuration; |
| 273 | JE_byte astralDuration; |
| 274 | JE_word flareDuration; |
| 275 | JE_boolean flareStart; |
| 276 | JE_shortint flareColChg; |
| 277 | JE_byte specialWait; |
| 278 | JE_byte nextSpecialWait; |
| 279 | JE_boolean spraySpecial; |
| 280 | JE_byte doIced; |
| 281 | JE_boolean infiniteShot; |
| 282 | |
| 283 | /*PlayerData*/ |
| 284 | JE_boolean allPlayersGone; /*Both players dead and finished exploding*/ |
| 285 | |
| 286 | const uint shadowYDist = 10; |
| 287 | |
| 288 | JE_real optionSatelliteRotate; |
| 289 | |
| 290 | JE_integer optionAttachmentMove; |
| 291 | JE_boolean optionAttachmentLinked, optionAttachmentReturn; |
| 292 | |
| 293 | JE_byte chargeWait, chargeLevel, chargeMax, chargeGr, chargeGrWait; |
| 294 | |
| 295 | JE_word neat; |
| 296 | |
| 297 | /*ExplosionData*/ |
| 298 | explosion_type explosions[MAX_EXPLOSIONS]; /* [1..ExplosionMax] */ |
| 299 | JE_integer explosionFollowAmountX, explosionFollowAmountY; |
| 300 | |
| 301 | /*Repeating Explosions*/ |
| 302 | rep_explosion_type rep_explosions[MAX_REPEATING_EXPLOSIONS]; /* [1..20] */ |
| 303 | |
| 304 | /*SuperPixels*/ |
| 305 | superpixel_type superpixels[MAX_SUPERPIXELS]; /* [0..MaxSP] */ |
| 306 | unsigned int last_superpixel; |
| 307 | |
| 308 | /*Temporary Numbers*/ |
| 309 | JE_byte temp, temp2, temp3; |
| 310 | JE_word tempX, tempY; |
| 311 | JE_word tempW; |
| 312 | |
| 313 | JE_boolean doNotSaveBackup; |
| 314 | |
| 315 | JE_word x, y; |
| 316 | JE_integer b; |
| 317 | |
| 318 | JE_byte **BKwrap1to, **BKwrap2to, **BKwrap3to, |
| 319 | **BKwrap1, **BKwrap2, **BKwrap3; |
| 320 | |
| 321 | JE_shortint specialWeaponFilter, specialWeaponFreq; |
| 322 | JE_word specialWeaponWpn; |
| 323 | JE_boolean linkToPlayer; |
| 324 | |
| 325 | JE_word shipGr, shipGr2; |
| 326 | Sprite2_array *shipGrPtr, *shipGr2ptr; |
| 327 | |
| 328 | void JE_getShipInfo(void) |
| 329 | { |
| 330 | JE_boolean extraShip, extraShip2; |
| 331 | |
| 332 | shipGrPtr = &spriteSheet9; |
| 333 | shipGr2ptr = &spriteSheet9; |
| 334 | |
| 335 | powerAdd = powerSys[player[0].items.generator].power; |
| 336 | |
| 337 | extraShip = player[0].items.ship > 90; |
| 338 | if (extraShip) |
| 339 | { |
| 340 | JE_byte base = (player[0].items.ship - 91) * 15; |
| 341 | shipGr = JE_SGr(player[0].items.ship - 90, &shipGrPtr); |
| 342 | player[0].armor = extraShips[base + 7]; |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | shipGr = ships[player[0].items.ship].shipgraphic; |
| 347 | player[0].armor = ships[player[0].items.ship].dmg; |
| 348 | } |
| 349 | |
| 350 | extraShip2 = player[1].items.ship > 90; |
| 351 | if (extraShip2) |
| 352 | { |
| 353 | JE_byte base2 = (player[1].items.ship - 91) * 15; |
| 354 | shipGr2 = JE_SGr(player[1].items.ship - 90, &shipGr2ptr); |
| 355 | player[1].armor = extraShips[base2 + 7]; /* bug? */ |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | shipGr2 = 0; |
| 360 | player[1].armor = 10; |
| 361 | } |
| 362 | |
| 363 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 364 | { |
| 365 | player[i].initial_armor = player[i].armor; |
| 366 | |
| 367 | uint temp = ((i == 0 && extraShip) || |
| 368 | (i == 1 && extraShip2)) ? 2 : ships[player[i].items.ship].ani; |
| 369 | |
| 370 | if (temp == 0) |
| 371 | { |
| 372 | player[i].shot_hit_area_x = 12; |
| 373 | player[i].shot_hit_area_y = 10; |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | player[i].shot_hit_area_x = 11; |
| 378 | player[i].shot_hit_area_y = 14; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | JE_word JE_SGr(JE_word ship, Sprite2_array **ptr) |
| 384 | { |
| 385 | const JE_word GR[15] /* [1..15] */ = {233, 157, 195, 271, 81, 0, 119, 5, 43, 81, 119, 157, 195, 233, 271}; |
| 386 | |
| 387 | JE_word tempW = extraShips[(ship - 1) * 15]; |
| 388 | if (tempW > 7) |
| 389 | *ptr = extraShapes; |
| 390 | |
| 391 | return GR[tempW-1]; |
| 392 | } |
| 393 | |
| 394 | void JE_drawOptions(void) |
| 395 | { |
| 396 | SDL_Surface *temp_surface = VGAScreen; |
| 397 | VGAScreen = VGAScreenSeg; |
| 398 | |
| 399 | Player *this_player = &player[twoPlayerMode ? 1 : 0]; |
| 400 | |
| 401 | for (uint i = 0; i < COUNTOF(this_player->sidekick); ++i) |
| 402 | { |
| 403 | JE_OptionType *this_option = &options[this_player->items.sidekick[i]]; |
| 404 | |
| 405 | this_player->sidekick[i].ammo = |
| 406 | this_player->sidekick[i].ammo_max = this_option->ammo; |
| 407 | |
| 408 | this_player->sidekick[i].ammo_refill_ticks = |
| 409 | this_player->sidekick[i].ammo_refill_ticks_max = (105 - this_player->sidekick[i].ammo) * 4; |
| 410 | |
| 411 | this_player->sidekick[i].style = this_option->tr; |
| 412 | |
| 413 | this_player->sidekick[i].animation_enabled = (this_option->option == 1); |
| 414 | this_player->sidekick[i].animation_frame = 0; |
| 415 | |
| 416 | this_player->sidekick[i].charge = 0; |
| 417 | this_player->sidekick[i].charge_ticks = 20; |
| 418 | |
| 419 | // draw initial sidekick HUD |
| 420 | const int y = hud_sidekick_y[twoPlayerMode ? 1 : 0][i]; |
| 421 | |
| 422 | fill_rectangle_xy(VGAScreenSeg, 284, y, 284 + 28, y + 15, 0); |
| 423 | if (this_option->icongr > 0) |
| 424 | blit_sprite(VGAScreenSeg, 284, y, OPTION_SHAPES, this_option->icongr - 1); // sidekick HUD icon |
| 425 | draw_segmented_gauge(VGAScreenSeg, 284, y + 13, 112, 2, 2, MAX(1, this_player->sidekick[i].ammo_max / 10), this_player->sidekick[i].ammo); |
| 426 | } |
| 427 | |
| 428 | VGAScreen = temp_surface; |
| 429 | |
| 430 | JE_drawOptionLevel(); |
| 431 | } |
| 432 | |
| 433 | void JE_drawOptionLevel(void) |
| 434 | { |
| 435 | if (twoPlayerMode) |
| 436 | { |
| 437 | for (temp = 1; temp <= 3; temp++) |
| 438 | { |
| 439 | fill_rectangle_xy(VGAScreenSeg, 268, 127 + (temp - 1) * 6, 269, 127 + 3 + (temp - 1) * 6, 193 + ((player[1].items.sidekick_level - 100) == temp) * 11); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | void JE_tyrianHalt(JE_byte code) |
| 445 | { |
| 446 | deinit_audio(); |
| 447 | deinit_video(); |
| 448 | deinit_joysticks(); |
| 449 | |
| 450 | /* TODO: NETWORK */ |
| 451 | |
| 452 | free_main_shape_tables(); |
| 453 | |
| 454 | free_sprite2s(&shopSpriteSheet); |
| 455 | free_sprite2s(&explosionSpriteSheet); |
| 456 | free_sprite2s(&destructSpriteSheet); |
| 457 | |
| 458 | for (int i = 0; i < SOUND_COUNT; i++) |
| 459 | { |
| 460 | free(soundSamples[i]); |
| 461 | } |
| 462 | |
| 463 | if (code != 9) |
| 464 | { |
| 465 | /* |
| 466 | TODO? |
| 467 | JE_drawANSI("exitmsg.bin"); |
| 468 | JE_gotoXY(1,22);*/ |
| 469 | |
| 470 | JE_saveConfiguration(); |
| 471 | } |
| 472 | |
| 473 | /* endkeyboard; */ |
| 474 | |
| 475 | if (code == 9) |
| 476 | { |
| 477 | /* OutputString('call=file0002.EXE' + #0'); TODO? */ |
| 478 | } |
| 479 | |
| 480 | if (code == 5) |
| 481 | { |
| 482 | code = 0; |
| 483 | } |
| 484 | |
| 485 | if (trentWin) |
| 486 | { |
| 487 | printf("\n" |
| 488 | "\n" |
| 489 | "\n" |
| 490 | "\n" |
| 491 | "Sleep well, Trent, you deserve the rest.\n" |
| 492 | "You now have permission to borrow my ship on your next mission.\n" |
| 493 | "\n" |
| 494 | "Also, you might want to try out the YESXMAS parameter.\n" |
| 495 | " Type: File0001 YESXMAS\n" |
| 496 | "\n" |
| 497 | "You'll need the 2.1 patch, though!\n" |
| 498 | "\n"); |
| 499 | } |
| 500 | |
| 501 | SDL_Quit(); |
| 502 | |
| 503 | #ifdef TARGET_UNIX |
| 504 | #define MISSING_TEXT "One or more of the required Tyrian " TYRIAN_VERSION " data files could not be found.\n" \ |
| 505 | "These can be installed using game-data-packager.\n" |
| 506 | if (code == 1) |
| 507 | { |
| 508 | char* argv[6]; |
| 509 | pid_t child_pid; |
| 510 | child_pid = fork(); |
| 511 | if(child_pid == 0) { |
| 512 | argv[0] = "zenity"; |
| 513 | argv[1] = "--error"; |
| 514 | argv[2] = "--text=" MISSING_TEXT; |
| 515 | argv[3] = "--title=Tyrian"; |
| 516 | argv[4] = NULL; |
| 517 | execvp(argv[0], argv); |
| 518 | argv[0] = "yad"; |
| 519 | execvp(argv[0], argv); |
| 520 | argv[0] = "kdialog"; |
| 521 | argv[2] = MISSING_TEXT; |
| 522 | execvp(argv[0], argv); |
| 523 | argv[0] = "xmessage"; |
| 524 | argv[1] = "-center"; |
| 525 | argv[3] = NULL; |
| 526 | execvp(argv[0], argv); |
| 527 | argv[0] = "notify-send"; |
| 528 | argv[1] = "Tyrian"; |
| 529 | argv[3] = "-i"; |
| 530 | argv[4] = "dialog-error"; |
| 531 | argv[5] = NULL; |
| 532 | execvp(argv[0], argv); |
| 533 | } |
| 534 | } |
| 535 | #endif |
| 536 | exit(code); |
| 537 | } |
| 538 | |
| 539 | void JE_specialComplete(JE_byte playerNum, JE_byte specialType) |
| 540 | { |
| 541 | nextSpecialWait = 0; |
| 542 | switch (special[specialType].stype) |
| 543 | { |
| 544 | /*Weapon*/ |
| 545 | case 1: |
| 546 | if (playerNum == 1) |
| 547 | b = player_shot_create(0, SHOT_SPECIAL2, player[0].x, player[0].y, mouseX, mouseY, special[specialType].wpn, playerNum); |
| 548 | else |
| 549 | b = player_shot_create(0, SHOT_SPECIAL2, player[1].x, player[1].y, mouseX, mouseY, special[specialType].wpn, playerNum); |
| 550 | |
| 551 | shotRepeat[SHOT_SPECIAL] = shotRepeat[SHOT_SPECIAL2]; |
| 552 | break; |
| 553 | /*Repulsor*/ |
| 554 | case 2: |
| 555 | for (temp = 0; temp < ENEMY_SHOT_MAX; temp++) |
| 556 | { |
| 557 | if (!enemyShotAvail[temp]) |
| 558 | { |
| 559 | if (player[0].x > enemyShot[temp].sx) |
| 560 | enemyShot[temp].sxm--; |
| 561 | else if (player[0].x < enemyShot[temp].sx) |
| 562 | enemyShot[temp].sxm++; |
| 563 | |
| 564 | if (player[0].y > enemyShot[temp].sy) |
| 565 | enemyShot[temp].sym--; |
| 566 | else if (player[0].y < enemyShot[temp].sy) |
| 567 | enemyShot[temp].sym++; |
| 568 | } |
| 569 | } |
| 570 | break; |
| 571 | /*Zinglon Blast*/ |
| 572 | case 3: |
| 573 | zinglonDuration = 50; |
| 574 | shotRepeat[SHOT_SPECIAL] = 100; |
| 575 | soundQueue[7] = S_SOUL_OF_ZINGLON; |
| 576 | break; |
| 577 | /*Attractor*/ |
| 578 | case 4: |
| 579 | for (temp = 0; temp < 100; temp++) |
| 580 | { |
| 581 | if (enemyAvail[temp] != 1 && enemy[temp].scoreitem && |
| 582 | enemy[temp].evalue != 0) |
| 583 | { |
| 584 | if (player[0].x > enemy[temp].ex) |
| 585 | enemy[temp].exc++; |
| 586 | else if (player[0].x < enemy[temp].ex) |
| 587 | enemy[temp].exc--; |
| 588 | |
| 589 | if (player[0].y > enemy[temp].ey) |
| 590 | enemy[temp].eyc++; |
| 591 | else if (player[0].y < enemy[temp].ey) |
| 592 | enemy[temp].eyc--; |
| 593 | } |
| 594 | } |
| 595 | break; |
| 596 | /*Flare*/ |
| 597 | case 5: |
| 598 | case 6: |
| 599 | case 7: |
| 600 | case 8: |
| 601 | case 9: |
| 602 | case 10: |
| 603 | case 11: |
| 604 | case 16: |
| 605 | if (flareDuration == 0) |
| 606 | flareStart = true; |
| 607 | |
| 608 | specialWeaponWpn = special[specialType].wpn; |
| 609 | linkToPlayer = false; |
| 610 | spraySpecial = false; |
| 611 | switch (special[specialType].stype) |
| 612 | { |
| 613 | case 5: |
| 614 | specialWeaponFilter = 7; |
| 615 | specialWeaponFreq = 2; |
| 616 | flareDuration = 50; |
| 617 | break; |
| 618 | case 6: |
| 619 | specialWeaponFilter = 1; |
| 620 | specialWeaponFreq = 7; |
| 621 | flareDuration = 200 + 25 * player[0].items.weapon[FRONT_WEAPON].power; |
| 622 | break; |
| 623 | case 7: |
| 624 | specialWeaponFilter = 3; |
| 625 | specialWeaponFreq = 3; |
| 626 | flareDuration = 50 + 10 * player[0].items.weapon[FRONT_WEAPON].power; |
| 627 | zinglonDuration = 50; |
| 628 | shotRepeat[SHOT_SPECIAL] = 100; |
| 629 | soundQueue[7] = S_SOUL_OF_ZINGLON; |
| 630 | break; |
| 631 | case 8: |
| 632 | specialWeaponFilter = -99; |
| 633 | specialWeaponFreq = 7; |
| 634 | flareDuration = 10 + player[0].items.weapon[FRONT_WEAPON].power; |
| 635 | break; |
| 636 | case 9: |
| 637 | specialWeaponFilter = -99; |
| 638 | specialWeaponFreq = 8; |
| 639 | flareDuration = 8 + 2 * player[0].items.weapon[FRONT_WEAPON].power; |
| 640 | linkToPlayer = true; |
| 641 | nextSpecialWait = special[specialType].pwr; |
| 642 | break; |
| 643 | case 10: |
| 644 | specialWeaponFilter = -99; |
| 645 | specialWeaponFreq = 8; |
| 646 | flareDuration = 14 + 4 * player[0].items.weapon[FRONT_WEAPON].power; |
| 647 | linkToPlayer = true; |
| 648 | break; |
| 649 | case 11: |
| 650 | specialWeaponFilter = -99; |
| 651 | specialWeaponFreq = special[specialType].pwr; |
| 652 | flareDuration = 10 + 10 * player[0].items.weapon[FRONT_WEAPON].power; |
| 653 | astralDuration = 20 + 10 * player[0].items.weapon[FRONT_WEAPON].power; |
| 654 | break; |
| 655 | case 16: |
| 656 | specialWeaponFilter = -99; |
| 657 | specialWeaponFreq = 8; |
| 658 | flareDuration = temp2 * 16 + 8; |
| 659 | linkToPlayer = true; |
| 660 | spraySpecial = true; |
| 661 | break; |
| 662 | } |
| 663 | break; |
| 664 | case 12: |
| 665 | player[playerNum-1].invulnerable_ticks = temp2 * 10; |
| 666 | |
| 667 | if (superArcadeMode > 0 && superArcadeMode <= SA) |
| 668 | { |
| 669 | shotRepeat[SHOT_SPECIAL] = 250; |
| 670 | b = player_shot_create(0, SHOT_SPECIAL2, player[0].x, player[0].y, mouseX, mouseY, 707, 1); |
| 671 | player[0].invulnerable_ticks = 100; |
| 672 | } |
| 673 | break; |
| 674 | case 13: |
| 675 | player[0].armor += temp2 / 4 + 1; |
| 676 | |
| 677 | soundQueue[3] = S_POWERUP; |
| 678 | break; |
| 679 | case 14: |
| 680 | player[1].armor += temp2 / 4 + 1; |
| 681 | |
| 682 | soundQueue[3] = S_POWERUP; |
| 683 | break; |
| 684 | |
| 685 | case 17: // spawn left or right sidekick |
| 686 | soundQueue[3] = S_POWERUP; |
| 687 | |
| 688 | if (player[0].items.sidekick[LEFT_SIDEKICK] == special[specialType].wpn) |
| 689 | { |
| 690 | player[0].items.sidekick[RIGHT_SIDEKICK] = special[specialType].wpn; |
| 691 | shotMultiPos[RIGHT_SIDEKICK] = 0; |
| 692 | } |
| 693 | else |
| 694 | { |
| 695 | player[0].items.sidekick[LEFT_SIDEKICK] = special[specialType].wpn; |
| 696 | shotMultiPos[LEFT_SIDEKICK] = 0; |
| 697 | } |
| 698 | |
| 699 | JE_drawOptions(); |
| 700 | break; |
| 701 | |
| 702 | case 18: // spawn right sidekick |
| 703 | player[0].items.sidekick[RIGHT_SIDEKICK] = special[specialType].wpn; |
| 704 | |
| 705 | JE_drawOptions(); |
| 706 | |
| 707 | soundQueue[4] = S_POWERUP; |
| 708 | |
| 709 | shotMultiPos[RIGHT_SIDEKICK] = 0; |
| 710 | break; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | void JE_doSpecialShot(JE_byte playerNum, uint *armor, uint *shield) |
| 715 | { |
| 716 | if (player[0].items.special > 0) |
| 717 | { |
| 718 | if (shotRepeat[SHOT_SPECIAL] == 0 && specialWait == 0 && flareDuration < 2 && zinglonDuration < 2) |
| 719 | blit_sprite2(VGAScreen, 47, 4, spriteSheet9, 94); |
| 720 | else |
| 721 | blit_sprite2(VGAScreen, 47, 4, spriteSheet9, 93); |
| 722 | } |
| 723 | |
| 724 | if (shotRepeat[SHOT_SPECIAL] > 0) |
| 725 | { |
| 726 | --shotRepeat[SHOT_SPECIAL]; |
| 727 | } |
| 728 | if (specialWait > 0) |
| 729 | { |
| 730 | specialWait--; |
| 731 | } |
| 732 | temp = SFExecuted[playerNum-1]; |
| 733 | if (temp > 0 && shotRepeat[SHOT_SPECIAL] == 0 && flareDuration == 0) |
| 734 | { |
| 735 | temp2 = special[temp].pwr; |
| 736 | |
| 737 | bool can_afford = true; |
| 738 | |
| 739 | if (temp2 > 0) |
| 740 | { |
| 741 | if (temp2 < 98) // costs some shield |
| 742 | { |
| 743 | if (*shield >= temp2) |
| 744 | *shield -= temp2; |
| 745 | else |
| 746 | can_afford = false; |
| 747 | } |
| 748 | else if (temp2 == 98) // costs all shield |
| 749 | { |
| 750 | if (*shield < 4) |
| 751 | can_afford = false; |
| 752 | temp2 = *shield; |
| 753 | *shield = 0; |
| 754 | } |
| 755 | else if (temp2 == 99) // costs half shield |
| 756 | { |
| 757 | temp2 = *shield / 2; |
| 758 | *shield = temp2; |
| 759 | } |
| 760 | else // costs some armor |
| 761 | { |
| 762 | temp2 -= 100; |
| 763 | if (*armor > temp2) |
| 764 | *armor -= temp2; |
| 765 | else |
| 766 | can_afford = false; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | shotMultiPos[SHOT_SPECIAL] = 0; |
| 771 | shotMultiPos[SHOT_SPECIAL2] = 0; |
| 772 | |
| 773 | if (can_afford) |
| 774 | JE_specialComplete(playerNum, temp); |
| 775 | |
| 776 | SFExecuted[playerNum-1] = 0; |
| 777 | |
| 778 | JE_wipeShieldArmorBars(); |
| 779 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 780 | JE_drawShield(); |
| 781 | JE_drawArmor(); |
| 782 | VGAScreen = game_screen; /* side-effect of game_screen */ |
| 783 | } |
| 784 | |
| 785 | if (playerNum == 1 && player[0].items.special > 0) |
| 786 | { /*Main Begin*/ |
| 787 | |
| 788 | if (superArcadeMode > 0 && (button[2-1] || button[3-1])) |
| 789 | { |
| 790 | fireButtonHeld = false; |
| 791 | } |
| 792 | if (!button[1-1] && !(superArcadeMode != SA_NONE && (button[2-1] || button[3-1]))) |
| 793 | { |
| 794 | fireButtonHeld = false; |
| 795 | } |
| 796 | else if (shotRepeat[SHOT_SPECIAL] == 0 && !fireButtonHeld && !(flareDuration > 0) && specialWait == 0) |
| 797 | { |
| 798 | fireButtonHeld = true; |
| 799 | JE_specialComplete(playerNum, player[0].items.special); |
| 800 | } |
| 801 | |
| 802 | } /*Main End*/ |
| 803 | |
| 804 | if (astralDuration > 0) |
| 805 | astralDuration--; |
| 806 | |
| 807 | shotAvail[MAX_PWEAPON-1] = 0; |
| 808 | if (flareDuration > 1) |
| 809 | { |
| 810 | if (specialWeaponFilter != -99) |
| 811 | { |
| 812 | if (levelFilter == -99 && levelBrightness == -99) |
| 813 | { |
| 814 | filterActive = false; |
| 815 | } |
| 816 | if (!filterActive) |
| 817 | { |
| 818 | levelFilter = specialWeaponFilter; |
| 819 | if (levelFilter == 7) |
| 820 | { |
| 821 | levelBrightness = 0; |
| 822 | } |
| 823 | filterActive = true; |
| 824 | } |
| 825 | |
| 826 | if (mt_rand() % 2 == 0) |
| 827 | flareColChg = -1; |
| 828 | else |
| 829 | flareColChg = 1; |
| 830 | |
| 831 | if (levelFilter == 7) |
| 832 | { |
| 833 | if (levelBrightness < -6) |
| 834 | { |
| 835 | flareColChg = 1; |
| 836 | } |
| 837 | if (levelBrightness > 6) |
| 838 | { |
| 839 | flareColChg = -1; |
| 840 | } |
| 841 | levelBrightness += flareColChg; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | if ((signed)(mt_rand() % 6) < specialWeaponFreq) |
| 846 | { |
| 847 | b = MAX_PWEAPON; |
| 848 | |
| 849 | if (linkToPlayer) |
| 850 | { |
| 851 | if (shotRepeat[SHOT_SPECIAL] == 0) |
| 852 | { |
| 853 | b = player_shot_create(0, SHOT_SPECIAL, player[0].x, player[0].y, mouseX, mouseY, specialWeaponWpn, playerNum); |
| 854 | } |
| 855 | } |
| 856 | else |
| 857 | { |
| 858 | b = player_shot_create(0, SHOT_SPECIAL, mt_rand() % 280, mt_rand() % 180, mouseX, mouseY, specialWeaponWpn, playerNum); |
| 859 | } |
| 860 | |
| 861 | if (spraySpecial && b != MAX_PWEAPON) |
| 862 | { |
| 863 | playerShotData[b].shotXM = (mt_rand() % 5) - 2; |
| 864 | playerShotData[b].shotYM = (mt_rand() % 5) - 2; |
| 865 | if (playerShotData[b].shotYM == 0) |
| 866 | { |
| 867 | playerShotData[b].shotYM++; |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | flareDuration--; |
| 873 | if (flareDuration == 1) |
| 874 | { |
| 875 | specialWait = nextSpecialWait; |
| 876 | } |
| 877 | } |
| 878 | else if (flareStart) |
| 879 | { |
| 880 | flareStart = false; |
| 881 | shotRepeat[SHOT_SPECIAL] = linkToPlayer ? 15 : 200; |
| 882 | flareDuration = 0; |
| 883 | if (levelFilter == specialWeaponFilter) |
| 884 | { |
| 885 | levelFilter = -99; |
| 886 | levelBrightness = -99; |
| 887 | filterActive = false; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | if (zinglonDuration > 1) |
| 892 | { |
| 893 | temp = 25 - abs(zinglonDuration - 25); |
| 894 | |
| 895 | JE_barBright(VGAScreen, player[0].x + 7 - temp, 0, player[0].x + 7 + temp, 184); |
| 896 | JE_barBright(VGAScreen, player[0].x + 7 - temp - 2, 0, player[0].x + 7 + temp + 2, 184); |
| 897 | |
| 898 | zinglonDuration--; |
| 899 | if (zinglonDuration % 5 == 0) |
| 900 | { |
| 901 | shotAvail[MAX_PWEAPON-1] = 1; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | void JE_setupExplosion(signed int x, signed int y, signed int delta_y, unsigned int type, bool fixed_position, bool follow_player) |
| 907 | { |
| 908 | const struct { |
| 909 | JE_word sprite; |
| 910 | JE_byte ttl; |
| 911 | } explosion_data[53] /* [1..53] */ = { |
| 912 | { 144, 7 }, |
| 913 | { 120, 12 }, |
| 914 | { 190, 12 }, |
| 915 | { 209, 12 }, |
| 916 | { 152, 12 }, |
| 917 | { 171, 12 }, |
| 918 | { 133, 7 }, /*White Smoke*/ |
| 919 | { 1, 12 }, |
| 920 | { 20, 12 }, |
| 921 | { 39, 12 }, |
| 922 | { 58, 12 }, |
| 923 | { 110, 3 }, |
| 924 | { 76, 7 }, |
| 925 | { 91, 3 }, |
| 926 | /*15*/ { 227, 3 }, |
| 927 | { 230, 3 }, |
| 928 | { 233, 3 }, |
| 929 | { 252, 3 }, |
| 930 | { 246, 3 }, |
| 931 | /*20*/ { 249, 3 }, |
| 932 | { 265, 3 }, |
| 933 | { 268, 3 }, |
| 934 | { 271, 3 }, |
| 935 | { 236, 3 }, |
| 936 | /*25*/ { 239, 3 }, |
| 937 | { 242, 3 }, |
| 938 | { 261, 3 }, |
| 939 | { 274, 3 }, |
| 940 | { 277, 3 }, |
| 941 | /*30*/ { 280, 3 }, |
| 942 | { 299, 3 }, |
| 943 | { 284, 3 }, |
| 944 | { 287, 3 }, |
| 945 | { 290, 3 }, |
| 946 | /*35*/ { 293, 3 }, |
| 947 | { 165, 8 }, /*Coin Values*/ |
| 948 | { 184, 8 }, |
| 949 | { 203, 8 }, |
| 950 | { 222, 8 }, |
| 951 | { 168, 8 }, |
| 952 | { 187, 8 }, |
| 953 | { 206, 8 }, |
| 954 | { 225, 10 }, |
| 955 | { 169, 10 }, |
| 956 | { 188, 10 }, |
| 957 | { 207, 20 }, |
| 958 | { 226, 14 }, |
| 959 | { 170, 14 }, |
| 960 | { 189, 14 }, |
| 961 | { 208, 14 }, |
| 962 | { 246, 14 }, |
| 963 | { 227, 14 }, |
| 964 | { 265, 14 } |
| 965 | }; |
| 966 | |
| 967 | if (y > -16 && y < 190) |
| 968 | { |
| 969 | for (int i = 0; i < MAX_EXPLOSIONS; i++) |
| 970 | { |
| 971 | if (explosions[i].ttl == 0) |
| 972 | { |
| 973 | explosions[i].x = x; |
| 974 | explosions[i].y = y; |
| 975 | if (type == 6) |
| 976 | { |
| 977 | explosions[i].y += 12; |
| 978 | explosions[i].x += 2; |
| 979 | } |
| 980 | else if (type == 98) |
| 981 | { |
| 982 | type = 6; |
| 983 | } |
| 984 | explosions[i].sprite = explosion_data[type].sprite; |
| 985 | explosions[i].ttl = explosion_data[type].ttl; |
| 986 | explosions[i].follow_player = follow_player; |
| 987 | explosions[i].fixed_position = fixed_position; |
| 988 | explosions[i].delta_x = 0; |
| 989 | explosions[i].delta_y = delta_y; |
| 990 | break; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | void JE_setupExplosionLarge(JE_boolean enemyGround, JE_byte exploNum, JE_integer x, JE_integer y) |
| 997 | { |
| 998 | if (y >= 0) |
| 999 | { |
| 1000 | if (enemyGround) |
| 1001 | { |
| 1002 | JE_setupExplosion(x - 6, y - 14, 0, 2, false, false); |
| 1003 | JE_setupExplosion(x + 6, y - 14, 0, 4, false, false); |
| 1004 | JE_setupExplosion(x - 6, y, 0, 3, false, false); |
| 1005 | JE_setupExplosion(x + 6, y, 0, 5, false, false); |
| 1006 | } |
| 1007 | else |
| 1008 | { |
| 1009 | JE_setupExplosion(x - 6, y - 14, 0, 7, false, false); |
| 1010 | JE_setupExplosion(x + 6, y - 14, 0, 9, false, false); |
| 1011 | JE_setupExplosion(x - 6, y, 0, 8, false, false); |
| 1012 | JE_setupExplosion(x + 6, y, 0, 10, false, false); |
| 1013 | } |
| 1014 | |
| 1015 | bool big; |
| 1016 | |
| 1017 | if (exploNum > 10) |
| 1018 | { |
| 1019 | exploNum -= 10; |
| 1020 | big = true; |
| 1021 | } |
| 1022 | else |
| 1023 | { |
| 1024 | big = false; |
| 1025 | } |
| 1026 | |
| 1027 | if (exploNum) |
| 1028 | { |
| 1029 | for (int i = 0; i < MAX_REPEATING_EXPLOSIONS; i++) |
| 1030 | { |
| 1031 | if (rep_explosions[i].ttl == 0) |
| 1032 | { |
| 1033 | rep_explosions[i].ttl = exploNum; |
| 1034 | rep_explosions[i].delay = 2; |
| 1035 | rep_explosions[i].x = x; |
| 1036 | rep_explosions[i].y = y; |
| 1037 | rep_explosions[i].big = big; |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | void JE_wipeShieldArmorBars(void) |
| 1046 | { |
| 1047 | if (!twoPlayerMode || galagaMode) |
| 1048 | { |
| 1049 | fill_rectangle_xy(VGAScreenSeg, 270, 137, 278, 194 - player[0].shield * 2, 0); |
| 1050 | } |
| 1051 | else |
| 1052 | { |
| 1053 | fill_rectangle_xy(VGAScreenSeg, 270, 60 - 44, 278, 60, 0); |
| 1054 | fill_rectangle_xy(VGAScreenSeg, 270, 194 - 44, 278, 194, 0); |
| 1055 | } |
| 1056 | if (!twoPlayerMode || galagaMode) |
| 1057 | { |
| 1058 | fill_rectangle_xy(VGAScreenSeg, 307, 137, 315, 194 - player[0].armor * 2, 0); |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | fill_rectangle_xy(VGAScreenSeg, 307, 60 - 44, 315, 60, 0); |
| 1063 | fill_rectangle_xy(VGAScreenSeg, 307, 194 - 44, 315, 194, 0); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | JE_byte JE_playerDamage(JE_byte temp, |
| 1068 | Player *this_player) |
| 1069 | { |
| 1070 | int playerDamage = 0; |
| 1071 | soundQueue[7] = S_SHIELD_HIT; |
| 1072 | |
| 1073 | /* Player Damage Routines */ |
| 1074 | if (this_player->shield < temp) |
| 1075 | { |
| 1076 | playerDamage = temp; |
| 1077 | temp -= this_player->shield; |
| 1078 | this_player->shield = 0; |
| 1079 | |
| 1080 | if (temp > 0) |
| 1081 | { |
| 1082 | /*Through Shields - Now Armor */ |
| 1083 | |
| 1084 | if (this_player->armor < temp) |
| 1085 | { |
| 1086 | temp -= this_player->armor; |
| 1087 | this_player->armor = 0; |
| 1088 | |
| 1089 | if (this_player->is_alive && !youAreCheating) |
| 1090 | { |
| 1091 | levelTimer = false; |
| 1092 | this_player->is_alive = false; |
| 1093 | this_player->exploding_ticks = 60; |
| 1094 | levelEnd = 40; |
| 1095 | tempVolume = tyrMusicVolume; |
| 1096 | soundQueue[1] = S_EXPLOSION_22; |
| 1097 | } |
| 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | this_player->armor -= temp; |
| 1102 | soundQueue[7] = S_HULL_HIT; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | this_player->shield -= temp; |
| 1109 | |
| 1110 | JE_setupExplosion(this_player->x - 17, this_player->y - 12, 0, 14, false, !twoPlayerMode); |
| 1111 | JE_setupExplosion(this_player->x - 5 , this_player->y - 12, 0, 15, false, !twoPlayerMode); |
| 1112 | JE_setupExplosion(this_player->x + 7 , this_player->y - 12, 0, 16, false, !twoPlayerMode); |
| 1113 | JE_setupExplosion(this_player->x + 19, this_player->y - 12, 0, 17, false, !twoPlayerMode); |
| 1114 | |
| 1115 | JE_setupExplosion(this_player->x - 17, this_player->y + 2, 0, 18, false, !twoPlayerMode); |
| 1116 | JE_setupExplosion(this_player->x + 19, this_player->y + 2, 0, 19, false, !twoPlayerMode); |
| 1117 | |
| 1118 | JE_setupExplosion(this_player->x - 17, this_player->y + 16, 0, 20, false, !twoPlayerMode); |
| 1119 | JE_setupExplosion(this_player->x - 5 , this_player->y + 16, 0, 21, false, !twoPlayerMode); |
| 1120 | JE_setupExplosion(this_player->x + 7 , this_player->y + 16, 0, 22, false, !twoPlayerMode); |
| 1121 | } |
| 1122 | |
| 1123 | JE_wipeShieldArmorBars(); |
| 1124 | VGAScreen = VGAScreenSeg; /* side-effect of game_screen */ |
| 1125 | JE_drawShield(); |
| 1126 | JE_drawArmor(); |
| 1127 | VGAScreen = game_screen; /* side-effect of game_screen */ |
| 1128 | |
| 1129 | return playerDamage; |
| 1130 | } |
| 1131 | |
| 1132 | JE_word JE_portConfigs(void) |
| 1133 | { |
| 1134 | const uint player_index = twoPlayerMode ? 1 : 0; |
| 1135 | return tempW = weaponPort[player[player_index].items.weapon[REAR_WEAPON].id].opnum; |
| 1136 | } |
| 1137 | |
| 1138 | void JE_drawShield(void) |
| 1139 | { |
| 1140 | if (twoPlayerMode && !galagaMode) |
| 1141 | { |
| 1142 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 1143 | JE_dBar3(VGAScreen, 270, 60 + 134 * i, roundf(player[i].shield * 0.8f), 144); |
| 1144 | } |
| 1145 | else |
| 1146 | { |
| 1147 | JE_dBar3(VGAScreen, 270, 194, player[0].shield, 144); |
| 1148 | if (player[0].shield != player[0].shield_max) |
| 1149 | { |
| 1150 | const uint y = 193 - (player[0].shield_max * 2); |
| 1151 | JE_rectangle(VGAScreen, 270, y, 278, y, 68); /* <MXD> SEGa000 */ |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | void JE_drawArmor(void) |
| 1157 | { |
| 1158 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 1159 | if (player[i].armor > 28) |
| 1160 | player[i].armor = 28; |
| 1161 | |
| 1162 | if (twoPlayerMode && !galagaMode) |
| 1163 | { |
| 1164 | for (uint i = 0; i < COUNTOF(player); ++i) |
| 1165 | JE_dBar3(VGAScreen, 307, 60 + 134 * i, roundf(player[i].armor * 0.8f), 224); |
| 1166 | } |
| 1167 | else |
| 1168 | { |
| 1169 | JE_dBar3(VGAScreen, 307, 194, player[0].armor, 224); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | void JE_doSP(JE_word x, JE_word y, JE_word num, JE_byte explowidth, JE_byte color) /* superpixels */ |
| 1174 | { |
| 1175 | for (temp = 0; temp < num; temp++) |
| 1176 | { |
| 1177 | JE_real tempr = mt_rand_lt1() * (2 * M_PI); |
| 1178 | signed int tempy = roundf(cosf(tempr) * mt_rand_1() * explowidth); |
| 1179 | signed int tempx = roundf(sinf(tempr) * mt_rand_1() * explowidth); |
| 1180 | |
| 1181 | if (++last_superpixel >= MAX_SUPERPIXELS) |
| 1182 | last_superpixel = 0; |
| 1183 | superpixels[last_superpixel].x = tempx + x; |
| 1184 | superpixels[last_superpixel].y = tempy + y; |
| 1185 | superpixels[last_superpixel].delta_x = tempx; |
| 1186 | superpixels[last_superpixel].delta_y = tempy + 1; |
| 1187 | superpixels[last_superpixel].color = color; |
| 1188 | superpixels[last_superpixel].z = 15; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | void JE_drawSP(void) |
| 1193 | { |
| 1194 | for (int i = MAX_SUPERPIXELS; i--; ) |
| 1195 | { |
| 1196 | if (superpixels[i].z) |
| 1197 | { |
| 1198 | superpixels[i].x += superpixels[i].delta_x; |
| 1199 | superpixels[i].y += superpixels[i].delta_y; |
| 1200 | |
| 1201 | if (superpixels[i].x < (unsigned)VGAScreen->w && superpixels[i].y < (unsigned)VGAScreen->h) |
| 1202 | { |
| 1203 | Uint8 *s = (Uint8 *)VGAScreen->pixels; /* screen pointer, 8-bit specific */ |
| 1204 | s += superpixels[i].y * VGAScreen->pitch; |
| 1205 | s += superpixels[i].x; |
| 1206 | |
| 1207 | *s = (((*s & 0x0f) + superpixels[i].z) >> 1) + superpixels[i].color; |
| 1208 | if (superpixels[i].x > 0) |
| 1209 | *(s - 1) = (((*(s - 1) & 0x0f) + (superpixels[i].z >> 1)) >> 1) + superpixels[i].color; |
| 1210 | if (superpixels[i].x < VGAScreen->w - 1u) |
| 1211 | *(s + 1) = (((*(s + 1) & 0x0f) + (superpixels[i].z >> 1)) >> 1) + superpixels[i].color; |
| 1212 | if (superpixels[i].y > 0) |
| 1213 | *(s - VGAScreen->pitch) = (((*(s - VGAScreen->pitch) & 0x0f) + (superpixels[i].z >> 1)) >> 1) + superpixels[i].color; |
| 1214 | if (superpixels[i].y < VGAScreen->h - 1u) |
| 1215 | *(s + VGAScreen->pitch) = (((*(s + VGAScreen->pitch) & 0x0f) + (superpixels[i].z >> 1)) >> 1) + superpixels[i].color; |
| 1216 | } |
| 1217 | |
| 1218 | superpixels[i].z--; |
| 1219 | } |
| 1220 | } |
| 1221 | } |