From 7afd322a71c2861c2ccab7c917d28e126490f99a Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sat, 19 Nov 2016 08:34:28 -0500 Subject: [PATCH] Some tweaks to prevent silent errors. --- src/alien.cpp | 17 +++++++++++------ src/game.cpp | 23 +++++++++++++++-------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/alien.cpp b/src/alien.cpp index 4af218a..bec1cb2 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -22,7 +22,8 @@ along with this program. If not, see . object alien_defs[CD_MAX]; object aliens[ALIEN_MAX]; -static const char *chrisKillMessage[] = { +static const int nChrisKillMessage = 15; +static const char *chrisKillMessage[nChrisKillMessage] = { "Take that, robot oppressors!", "Come on, WEAPCO, give me a challenge already!", "Is that all you've got?", @@ -39,7 +40,9 @@ static const char *chrisKillMessage[] = { "How do you like that, WEAPCO?", "Maybe you should change your name to WEEPCO!" }; -static const char *phoebeKillMessage[] = { + +static const int nPhoebeKillMessage = 11; +static const char *phoebeKillMessage[nPhoebeKillMessage] = { "I got another one!", "Target destroyed!", "One more for me!", @@ -52,7 +55,9 @@ static const char *phoebeKillMessage[] = { "We're such a great team!", "I got it!" }; -static const char *ursulaKillMessage[] = { + +static const int nUrsulaKillMessage = 14; +static const char *ursulaKillMessage[nUrsulaKillMessage] = { "Kicked your ass!", "You ain't so tough!", "I was always a better WEAPCO pilot than you!", @@ -1765,7 +1770,7 @@ void alien_destroy(object *alien, object *attacker) game.totalKills++; if (((rand() % 16) == 0) && (alien-> flags & FL_WEAPCO)) { - r = rand() % 15; + r = rand() % nChrisKillMessage; setRadioMessage(FS_CHRIS, chrisKillMessage[r], 0); } } @@ -1774,7 +1779,7 @@ void alien_destroy(object *alien, object *attacker) game.wingMate1Kills++; if (((rand() % 8) == 0) && (alien-> flags & FL_WEAPCO)) { - r = rand() % 11; + r = rand() % nPhoebeKillMessage; setRadioMessage(FS_PHOEBE, phoebeKillMessage[r], 0); } } @@ -1783,7 +1788,7 @@ void alien_destroy(object *alien, object *attacker) game.wingMate2Kills++; if (((rand() % 8) == 0) && (alien-> flags & FL_WEAPCO)) { - r = rand() % 14; + r = rand() % nUrsulaKillMessage; setRadioMessage(FS_URSULA, ursulaKillMessage[r], 0); } } diff --git a/src/game.cpp b/src/game.cpp index 23df6da..45a4b19 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -25,18 +25,25 @@ static Star stars[STARS_NUM]; static Uint32 frameLimit = 0; static int thirds = 0; -static const char *klineInsult[] = { +static const int nKlineInsult = 3; +static const char *klineInsult[nKlineInsult] = { "Pathetic.", "How very disappointing...", "Heroic. And stupid." }; -static const char *klineVenusInsult[] = { + +static const int nKlineVenusInsult = 2; +static const char *klineVenusInsult[nKlineVenusInsult] = { "Fool.", "And now you're nothing but a DEAD hero." }; -static const char *phoebePlayerHitMessage[3] = { + +static const int nPhoebePlayerHitMessage = 3; +static const char *phoebePlayerHitMessage[nPhoebePlayerHitMessage] = { "Oops! Sorry!", "Whoops! Are you OK, Chris?", "Oh, sorry! I didn't see you there!" }; -static const char *ursulaPlayerHitMessage[3] = { + +static const int nUrsulaPlayerHitMessage = 3; +static const char *ursulaPlayerHitMessage[nUrsulaPlayerHitMessage] = { "Get out of the way!", "Don't fly into my missiles!", "Dammit, Chris, you made me miss!" @@ -713,11 +720,11 @@ static void game_doBullets() { if (bullet->owner->classDef == CD_PHOEBE) { - setRadioMessage(FS_PHOEBE, phoebePlayerHitMessage[rand() % 3], 0); + setRadioMessage(FS_PHOEBE, phoebePlayerHitMessage[rand() % nPhoebePlayerHitMessage], 0); } else if (bullet->owner->classDef == CD_URSULA) { - setRadioMessage(FS_URSULA, ursulaPlayerHitMessage[rand() % 3], 0); + setRadioMessage(FS_URSULA, ursulaPlayerHitMessage[rand() % nUrsulaPlayerHitMessage], 0); } } @@ -1452,9 +1459,9 @@ static void game_doPlayer() if (aliens[ALIEN_KLINE].active) { if (game.area == MISN_VENUS) - setRadioMessage(FS_KLINE, klineVenusInsult[rand() % 2], 1); + setRadioMessage(FS_KLINE, klineVenusInsult[rand() % nKlineVenusInsult], 1); else - setRadioMessage(FS_KLINE, klineInsult[rand() % 3], 1); + setRadioMessage(FS_KLINE, klineInsult[rand() % nKlineInsult], 1); } else if ((aliens[ALIEN_BOSS].active) && (aliens[ALIEN_BOSS].classDef == CD_KRASS)) {