#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];
+};
+
+static 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)
}
void
-retreat_ship(struct shpstr *sp, s_char code)
+retreat_ship(struct shpstr *sp, char code)
{
struct nstr_item ni;
struct shpstr ship;
- s_char buf[2];
if (sp->shp_rflags & RET_GROUP) {
- buf[0] = sp->shp_fleet;
- buf[1] = 0;
- snxtitem(&ni, EF_SHIP, buf);
+ snxtitem_group(&ni, EF_SHIP, sp->shp_fleet);
while (nxtitem(&ni, &ship))
- if ((ship.shp_fleet == buf[0]) &&
- (ship.shp_own == sp->shp_own)) {
+ if (ship.shp_own == sp->shp_own) {
if (ship.shp_uid == sp->shp_uid) {
retreat_ship1(sp, code, 1);
if (sp->shp_rpath[0] == 0)
}
static int
-retreat_ship1(struct shpstr *sp, s_char code, int orig)
+retreat_ship1(struct shpstr *sp, char code, int orig)
/* Is this the originally scared ship, or a follower */
int shells;
double mobcost;
struct mchrstr *mcp;
- int time_to_stop;
int changed;
sp->shp_mission = 0;
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,
n = (-1 * MAX_RETREAT);
stopping = 0;
- time_to_stop = 0;
while (!stopping && n) {
dx = dy = 0;
if (sp->shp_rpath[0] == 0) {
mcp = &mchr[(int)sp->shp_type];
newx = xnorm(sp->shp_x + dx);
newy = ynorm(sp->shp_y + dy);
- mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
- mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost));
+ mobcost = shp_mobcost(sp);
getsect(newx, newy, §);
if (shp_check_nav(§, sp) != CN_NAVIGABLE ||
- (sect.sct_own && !player->owner &&
+ (sect.sct_own && sect.sct_own != sp->shp_own &&
getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) {
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
prship(sp), conditions[findcondition(code)].desc[orig],
mines = sect.sct_mines;
changed = 0;
- if ((mcp->m_flags & M_SWEEP) && mines > 0 && !player->owner) {
+ if ((mcp->m_flags & M_SWEEP) && sect.sct_type == SCT_WATER) {
+ sp->shp_mobil -= mobcost;
max = mcp->m_item[I_SHELL];
shells = sp->shp_item[I_SHELL];
for (m = 0; mines > 0 && m < 5; m++) {
mines--;
shells = MIN(max, shells + 1);
changed |= map_set(sp->shp_own, sp->shp_x, sp->shp_y,
- 'X', 0);
+ 'X', 0);
}
}
if (sect.sct_mines != mines) {
"%s cleared %d mine%s in %s while retreating\n",
prship(sp), sect.sct_mines-mines, splur(sect.sct_mines-mines),
xyas(newx, newy, sp->shp_own));
+ sect.sct_mines = mines;
+ sp->shp_item[I_SHELL] = shells;
+ putsect(§);
}
- sect.sct_mines = mines;
- sect.sct_item[I_SHELL] = shells;
- putsect(§);
if (changed)
writemap(sp->shp_own);
}
- if (mines > 0 && !player->owner && chance(DMINE_HITCHANCE(mines))) {
+ if (sect.sct_type == SCT_WATER && mines > 0
+ && chance(DMINE_HITCHANCE(mines))) {
wu(0, sp->shp_own,
"%s %s,\nand hit a mine in %s while retreating!\n",
prship(sp), conditions[findcondition(code)].desc[orig],
writemap(sp->shp_own);
sect.sct_mines = mines;
putsect(§);
- if (sp->shp_effic < SHIP_MINEFF)
- time_to_stop = 1;
if (!orig)
putship(sp->shp_uid, sp);
return 0;
}
- if (time_to_stop)
- stopping = 1;
}
if (orig) {
- wu(0, sp->shp_own, "%s %s, and retreated to %s\n", prship(sp),
- conditions[findcondition(code)].desc[orig],
+ wu(0, sp->shp_own, "%s %s, and retreated to %s\n",
+ prship(sp), conditions[findcondition(code)].desc[orig],
xyas(sp->shp_x, sp->shp_y, sp->shp_own));
} else {
wu(0, sp->shp_own, "%s %s, and ended up at %s\n",
}
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
}
void
-retreat_land(struct lndstr *lp, s_char code)
+retreat_land(struct lndstr *lp, char code)
{
struct nstr_item ni;
struct lndstr land;
- s_char buf[2];
if (lp->lnd_rflags & RET_GROUP) {
- buf[0] = lp->lnd_army;
- buf[1] = 0;
- snxtitem(&ni, EF_SHIP, buf);
+ snxtitem_group(&ni, EF_SHIP, lp->lnd_army);
while (nxtitem(&ni, &land))
- if ((land.lnd_army == buf[0]) && (land.lnd_own == lp->lnd_own)) {
+ if (land.lnd_own == lp->lnd_own) {
if (land.lnd_uid == lp->lnd_uid) {
retreat_land1(lp, code, 1);
if (lp->lnd_rpath[0] == 0)
}
static int
-retreat_land1(struct lndstr *lp, s_char code, int orig)
+retreat_land1(struct lndstr *lp, char code, int orig)
/* Is this the originally scared unit, or a follower */
int shells;
double mobcost;
struct lchrstr *lcp;
- int time_to_stop;
lp->lnd_mission = 0;
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,
n = (-1 * MAX_RETREAT);
stopping = 0;
- time_to_stop = 0;
while (!stopping && n) {
dx = dy = 0;
if (lp->lnd_rpath[0] == 0) {
newy = ynorm(lp->lnd_y + dy);
getsect(newx, newy, §);
- if ((sect.sct_type == SCT_WATER) ||
- (sect.sct_type == SCT_MOUNT) ||
- (sect.sct_type == SCT_SANCT) ||
- (sect.sct_type == SCT_WASTE) ||
- (sect.sct_own != lp->lnd_own)) {
+ mobcost = lnd_mobcost(lp, §);
+ if (mobcost < 0
+ || sect.sct_type == SCT_MOUNT
+ || sect.sct_own != lp->lnd_own) {
wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n",
prland(lp),
conditions[findcondition(code)].desc[orig],
putland(lp->lnd_uid, lp);
return 0;
}
- mobcost = lnd_mobcost(lp, §, MOB_ROAD);
lp->lnd_x = newx;
lp->lnd_y = newy;
lp->lnd_mobil -= mobcost;
putsect(§);
}
if (mines > 0 && (sect.sct_oldown != lp->lnd_own) &&
- chance(DMINE_HITCHANCE(mines))) {
+ chance(DMINE_LHITCHANCE(mines))) {
wu(0, lp->lnd_own,
"%s %s,\nand hit a mine in %s while retreating!\n",
prland(lp),
mines--;
sect.sct_mines = mines;
putsect(§);
- if (lp->lnd_effic < LAND_MINEFF)
- time_to_stop = 1;
if (!orig)
putland(lp->lnd_uid, lp);
return 0;
}
- if (time_to_stop)
- stopping = 1;
}
if (orig) {