From ded0be314e84a720ee8192c402484f9c7e3a8ce3 Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Fri, 10 May 2019 21:09:34 -0400 Subject: [PATCH 1/5] 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); From 3b7bb45e281c55399a9cfd66691a8157ba25498e Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Sat, 11 May 2019 02:15:36 -0400 Subject: [PATCH 2/5] Improved damaged nerfing Limited damage prevention to only at the "low" and "critical" levels, plus added a delay for when damage is first inflicted by rays. This prevents ships with multiple concentrated shots from having a disadvantage, and it helps make rays easier to avoid at the same time (just get out of the ray in time and you don't take damage). Of course, neither of these apply to Classic difficulty, although the ray damage delay does apply to Nightmare difficulty (which, given how unpredictable rays are, I think is quite reasonable). --- src/alien.cpp | 6 +++--- src/defs.h | 2 ++ src/game.cpp | 12 +++++++++++- src/player.cpp | 21 ++++++++++++++++++--- src/player.h | 4 +++- src/ship.cpp | 2 +- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/alien.cpp b/src/alien.cpp index 14ac4e2..7f18683 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -1726,7 +1726,7 @@ void alien_move(Object *alien) { if (alien->classDef == CD_ASTEROID) { - player_damage(alien->shield); + player_damage(alien->shield, 0); alien->shield = 0; audio_playSound(SFX_EXPLOSION, alien->x, alien->y); audio_playSound(SFX_HIT, player.x, player.y); @@ -1734,7 +1734,7 @@ void alien_move(Object *alien) if (alien->classDef == CD_ASTEROID2) { - player_damage(alien->shield); + player_damage(alien->shield, 0); alien->shield = 0; audio_playSound(SFX_EXPLOSION, alien->x, alien->y); audio_playSound(SFX_HIT, player.x, player.y); @@ -1742,7 +1742,7 @@ void alien_move(Object *alien) if (alien->classDef == CD_BARRIER) { - player_damage(1); + player_damage(1, 0); audio_playSound(SFX_HIT, player.x, player.y); } } diff --git a/src/defs.h b/src/defs.h index 6fbe540..6e9e891 100644 --- a/src/defs.h +++ b/src/defs.h @@ -764,4 +764,6 @@ const int maxHoming = 20; const int maxDoubleHoming = 15; const int maxMicroHoming = 10; +const int rayDamageDelay = 10; + #endif diff --git a/src/game.cpp b/src/game.cpp index 5ff3114..4f1db55 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -784,7 +784,7 @@ static void game_doBullets() { old_shield = player.shield; - player_damage(bullet->damage); + player_damage(bullet->damage, 0); if (player.shield > 0) { @@ -2451,6 +2451,16 @@ int game_mainLoop() game_doExplosions(); game_doHud(); + // Start delaying damage again gradually + if (player_resetDamageDelay) + { + LIMIT_ADD(player_damageDelay, -1, 0, 100); + } + else + { + player_resetDamageDelay = 1; + } + WRAP_ADD(engine.eventTimer, -1, 0, 60); if (engine.paused) diff --git a/src/player.cpp b/src/player.cpp index 585f5fc..95fe52e 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -34,6 +34,8 @@ along with this program. If not, see . Object player; int player_chargerFired = 0; +int player_damageDelay = 0; +int player_resetDamageDelay = 0; /* Initialises the player for a new game. @@ -81,13 +83,26 @@ void player_setTarget(int index) engine.targetShield /= aliens[index].shield; } -void player_damage(int amount) +void player_damage(int amount, int delay) { int oldshield = player.shield; + + player_resetDamageDelay = 0; + if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0) && - ((!player.hit) || (game.difficulty == DIFFICULTY_ORIGINAL))) + ((!player.hit) || + (game.difficulty == DIFFICULTY_ORIGINAL) || + ((player.shield != engine.lowShield) && + (player.shield != 1)))) { - player.shield -= amount; + if ((game.difficulty == DIFFICULTY_ORIGINAL) || + (player_damageDelay >= delay)) + { + player.shield -= amount; + } + else + player_damageDelay += amount; + LIMIT(player.shield, 0, player.maxShield); player.hit = 5; // Damage flash timer diff --git a/src/player.h b/src/player.h index 831a39a..b191d0e 100644 --- a/src/player.h +++ b/src/player.h @@ -25,10 +25,12 @@ along with this program. If not, see . extern Object player; extern int player_chargerFired; +extern int player_damageDelay; +extern int player_resetDamageDelay; void player_init(); void player_setTarget(int index); -void player_damage(int amount); +void player_damage(int amount, int delay); void player_checkShockDamage(float x, float y); void player_exit(); void player_flushInput(); diff --git a/src/ship.cpp b/src/ship.cpp index 76991c3..1d9d5f7 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -176,7 +176,7 @@ void ship_fireRay(Object *ship) player.image[0]->h, ray.x, ray.y, ray.w, ray.h) && (!engine.cheatShield) && (engine.missionCompleteTimer == 0)) { - player_damage(1); + player_damage(1, rayDamageDelay); explosion_add(player.x, player.y, SP_SMALL_EXPLOSION); audio_playSound(SFX_HIT, player.x, player.y); From 5cc48d3f9faf159f3ddfebe70873f3a40fbf0c9a Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Sat, 11 May 2019 02:26:37 -0400 Subject: [PATCH 3/5] Tweaked the reduction method of damageDelay. --- src/game.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 4f1db55..e995dfd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2452,13 +2452,16 @@ int game_mainLoop() game_doHud(); // Start delaying damage again gradually - if (player_resetDamageDelay) + if (player_damageDelay > 0) { - LIMIT_ADD(player_damageDelay, -1, 0, 100); - } - else - { - player_resetDamageDelay = 1; + if (player_resetDamageDelay) + { + player_damageDelay--; + } + else + { + player_resetDamageDelay = 1; + } } WRAP_ADD(engine.eventTimer, -1, 0, 60); From e406c8eecd76c75ad6e1f35043f3078da5434937 Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Sat, 11 May 2019 02:38:21 -0400 Subject: [PATCH 4/5] Fixed indentation. --- src/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player.cpp b/src/player.cpp index 95fe52e..854d561 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -91,7 +91,7 @@ void player_damage(int amount, int delay) if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0) && ((!player.hit) || - (game.difficulty == DIFFICULTY_ORIGINAL) || + (game.difficulty == DIFFICULTY_ORIGINAL) || ((player.shield != engine.lowShield) && (player.shield != 1)))) { From c5ee1b3e09bfb0d2aff7277522b302502a3fd071 Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Sat, 11 May 2019 02:49:21 -0400 Subject: [PATCH 5/5] Fixed failure to use player_damage for explosions. Also made one tweak: when shield gets to "low" or "critical", damage delay is reset (so that you get more protection from rays). --- src/player.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 854d561..6184115 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -28,6 +28,7 @@ along with this program. If not, see . #include "game.h" #include "gfx.h" #include "info.h" +#include "player.h" #include "screen.h" #include "weapons.h" #include "window.h" @@ -112,13 +113,19 @@ void player_damage(int amount, int delay) { info_setLine("!!! WARNING: SHIELD LOW !!!", FONT_RED); if (game.difficulty != DIFFICULTY_ORIGINAL) + { player.shield = engine.lowShield; + player_damageDelay = 0; + } } else if ((oldshield > 1) && (player.shield <= 1)) { info_setLine("!!! WARNING: SHIELD CRITICAL !!!", FONT_RED); if (game.difficulty != DIFFICULTY_ORIGINAL) + { player.shield = 1; + player_damageDelay = 0; + } } } } @@ -141,9 +148,7 @@ void player_checkShockDamage(float x, float y) if (distY >= 1) distY /= 5; - player.shield -= (int)(10 - distX); - player.shield -= (int)(10 - distY); - LIMIT(player.shield, 0, player.maxShield); + player_damage((int)((10 - distX) + (10 - distY)), 0); player.hit = 10; } }