From ded0be314e84a720ee8192c402484f9c7e3a8ce3 Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Fri, 10 May 2019 21:09:34 -0400 Subject: [PATCH] Added a damage-control mechanic. Limits the damage you take somewhat. Basically, this is intended to prevent sudden deaths; if it doesn't look like you're dying, you probably won't suddenly get axed. Of course, this is disabled in Classic difficulty. --- configure.ac | 2 +- src/alien.cpp | 12 +++--------- src/game.cpp | 13 +++---------- src/player.cpp | 28 ++++++++++++++++++++++++++++ src/player.h | 1 + src/ship.cpp | 9 +-------- 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 140d73a..466dc64 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ # information. This file is offered as-is, without any warranty. AC_PREREQ([2.69]) -AC_INIT([Project: Starfighter], [1.7.1-dev], [onpon4@riseup.net], [starfighter]) +AC_INIT([Project: Starfighter], [1.8-dev], [onpon4@riseup.net], [starfighter]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_CONFIG_SRCDIR([src/Starfighter.cpp]) AC_CONFIG_HEADERS([config.h]) diff --git a/src/alien.cpp b/src/alien.cpp index 8077b75..14ac4e2 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -1726,29 +1726,23 @@ void alien_move(Object *alien) { if (alien->classDef == CD_ASTEROID) { - if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0)) - player.shield -= alien->shield; + player_damage(alien->shield); alien->shield = 0; audio_playSound(SFX_EXPLOSION, alien->x, alien->y); - player.hit = 5; audio_playSound(SFX_HIT, player.x, player.y); } if (alien->classDef == CD_ASTEROID2) { - if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0)) - player.shield -= alien->shield; + player_damage(alien->shield); alien->shield = 0; audio_playSound(SFX_EXPLOSION, alien->x, alien->y); - player.hit = 5; audio_playSound(SFX_HIT, player.x, player.y); } if (alien->classDef == CD_BARRIER) { - if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0)) - player.shield--; - player.hit = 5; + player_damage(1); audio_playSound(SFX_HIT, player.x, player.y); } } diff --git a/src/game.cpp b/src/game.cpp index a97c5e1..5ff3114 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -784,16 +784,7 @@ static void game_doBullets() { old_shield = player.shield; - if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0)) - { - if ((player.shield > engine.lowShield) && - (player.shield - bullet->damage <= engine.lowShield)) - info_setLine("!!! WARNING: SHIELD LOW !!!", FONT_RED); - - player.shield -= bullet->damage; - LIMIT(player.shield, 0, player.maxShield); - player.hit = 5; - } + player_damage(bullet->damage); if (player.shield > 0) { @@ -1531,6 +1522,8 @@ static void game_doPlayer() } else { + // Player is dead. At this point, the shield counts down to + // -100 and does death and explosion stuff along the way. player.active = 0; player.shield--; if (player.shield == -1) diff --git a/src/player.cpp b/src/player.cpp index d07b6cf..585f5fc 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . #include "engine.h" #include "game.h" #include "gfx.h" +#include "info.h" #include "screen.h" #include "weapons.h" #include "window.h" @@ -80,6 +81,33 @@ void player_setTarget(int index) engine.targetShield /= aliens[index].shield; } +void player_damage(int amount) +{ + int oldshield = player.shield; + if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0) && + ((!player.hit) || (game.difficulty == DIFFICULTY_ORIGINAL))) + { + player.shield -= amount; + LIMIT(player.shield, 0, player.maxShield); + player.hit = 5; // Damage flash timer + + // Damage tiers (not in Classic mode) + if ((oldshield > engine.lowShield) && + (player.shield <= engine.lowShield)) + { + info_setLine("!!! WARNING: SHIELD LOW !!!", FONT_RED); + if (game.difficulty != DIFFICULTY_ORIGINAL) + player.shield = engine.lowShield; + } + else if ((oldshield > 1) && (player.shield <= 1)) + { + info_setLine("!!! WARNING: SHIELD CRITICAL !!!", FONT_RED); + if (game.difficulty != DIFFICULTY_ORIGINAL) + player.shield = 1; + } + } +} + void player_checkShockDamage(float x, float y) { float distX = fabsf(x - player.x); diff --git a/src/player.h b/src/player.h index 0548c44..831a39a 100644 --- a/src/player.h +++ b/src/player.h @@ -28,6 +28,7 @@ extern int player_chargerFired; void player_init(); void player_setTarget(int index); +void player_damage(int amount); void player_checkShockDamage(float x, float y); void player_exit(); void player_flushInput(); diff --git a/src/ship.cpp b/src/ship.cpp index 115191e..76991c3 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -176,14 +176,7 @@ void ship_fireRay(Object *ship) player.image[0]->h, ray.x, ray.y, ray.w, ray.h) && (!engine.cheatShield) && (engine.missionCompleteTimer == 0)) { - if (player.shield > engine.lowShield) - { - if (player.shield - 1 <= engine.lowShield) - { - info_setLine("!!! WARNING: SHIELD LOW !!!", FONT_RED); - } - } - player.shield--; + player_damage(1); explosion_add(player.x, player.y, SP_SMALL_EXPLOSION); audio_playSound(SFX_HIT, player.x, player.y);