(conditions): Give sentinel a legible desc[], just in case.

(findcondition): Oops on hitting the sentinel.

(retreat_ship1, retreat_land1): Don't bother to map code to lower
case, it doesn't occur.
This commit is contained in:
Markus Armbruster 2006-03-26 19:02:28 +00:00
parent 021a91a779
commit cc29b27a67

View file

@ -50,33 +50,31 @@
#include "prototypes.h"
#include "optlist.h"
static int findcondition(s_char);
static int retreat_land1(struct lndstr *, s_char, int);
static int retreat_ship1(struct shpstr *, s_char, int);
static int findcondition(char);
static int retreat_land1(struct lndstr *, char, int);
static int retreat_ship1(struct shpstr *, char, int);
struct ccode {
s_char code;
s_char *desc[2];
} conditions[] = {
{
'i', {
"retreated with a damaged friend", "was damaged",},}, {
't', {
"retreated with a torpedoed ship", "was hit by a torpedo",},}, {
's', {
"retreated with a ship scared by sonar",
"detected a sonar ping",},}, {
'h', {
"retreated with a helpless ship",
"was fired upon with no one able to defend it",},}, {
'b', {
"retreated with a bombed friend", "was bombed",},}, {
'd', {
"retreated with a depth-charged ship", "was depth-charged",},}, {
'u', {
"retreated with a boarded ship", "was boarded",},}, {
0, {
"", ""}},};
char code;
char *desc[2];
};
struct ccode conditions[] = {
{ 'i', { "retreated with a damaged friend",
"was damaged" } },
{ 't', { "retreated with a torpedoed ship",
"was hit by a torpedo" } },
{ 's', { "retreated with a ship scared by sonar",
"detected a sonar ping" } },
{ 'h', { "retreated with a helpless ship",
"was fired upon with no one able to defend it" } },
{ 'b', { "retreated with a bombed friend",
"was bombed" } },
{ 'd', { "retreated with a depth-charged ship",
"was depth-charged" } },
{ 'u', { "retreated with a boarded ship", "was boarded" } },
{ 0, { "panicked", "panicked"} }
};
int
check_retreat_and_do_shipdamage(struct shpstr *sp, int dam)
@ -152,9 +150,6 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig)
if (sp->shp_own == 0)
return 0;
if (isupper(code))
code = tolower(code);
n = 0;
if (sp->shp_effic < SHIP_MINEFF) {
wu(0, sp->shp_own,
@ -341,18 +336,13 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig)
}
static int
findcondition(s_char code)
findcondition(char code)
{
int x;
int i;
x = 0;
while (conditions[x].code) {
if (conditions[x].code == code)
return x;
x++;
}
return x;
for (i = 0; conditions[i].code && conditions[i].code != code; i++) ;
CANT_HAPPEN(!conditions[i].code);
return i;
}
int
@ -427,9 +417,6 @@ retreat_land1(struct lndstr *lp, s_char code, int orig)
if (lp->lnd_own == 0)
return 0;
if (isupper(code))
code = tolower(code);
n = 0;
if (lp->lnd_effic < LAND_MINEFF) {
wu(0, lp->lnd_own,