/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* retreat.c: Retreat subroutines
- *
+ *
* Known contributors to this file:
* Steve McClure, 2000
*/
#include <config.h>
-#include <stdlib.h>
#include "damage.h"
#include "file.h"
#include "land.h"
if (sp->shp_own == 0)
return 0;
- n = 0;
if (sp->shp_effic < SHIP_MINEFF) {
wu(0, sp->shp_own,
"%s %s,\nbut it died in the attack, and so couldn't retreat!\n",
return 0;
}
- n = (-1 * MAX_RETREAT);
+ n = -MAX_RETREAT;
stopping = 0;
while (!stopping && n) {
dx = dy = 0;
mines = sect.sct_mines;
changed = 0;
- if ((mcp->m_flags & M_SWEEP) && sect.sct_type == SCT_WATER) {
+ if (sect.sct_type != SCT_WATER || mines <= 0)
+ continue;
+ if (mcp->m_flags & M_SWEEP) {
max = mcp->m_item[I_SHELL];
shells = sp->shp_item[I_SHELL];
for (m = 0; mines > 0 && m < 5; m++) {
if (sect.sct_mines != mines) {
wu(0, sp->shp_own,
"%s cleared %d mine%s in %s while retreating\n",
- prship(sp), sect.sct_mines-mines, splur(sect.sct_mines-mines),
+ 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;
if (changed)
writemap(sp->shp_own);
}
- if (sect.sct_type == SCT_WATER && mines > 0
- && chance(DMINE_HITCHANCE(mines))) {
+ if (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],
if (lp->lnd_own == 0)
return 0;
- n = 0;
if (lp->lnd_effic < LAND_MINEFF) {
wu(0, lp->lnd_own,
"%s %s,\nbut it died in the attack, and so couldn't retreat!\n",
return 0;
}
- n = (-1 * MAX_RETREAT);
+ n = -MAX_RETREAT;
stopping = 0;
while (!stopping && n) {
dx = dy = 0;
if (stopping)
continue;
- mines = sect.sct_mines;
- if ((lcp->l_flags & L_ENGINEER) && mines > 0 &&
- (sect.sct_oldown != lp->lnd_own)) {
+ mines = SCT_LANDMINES(§);
+ if (mines <= 0 || sect.sct_oldown == lp->lnd_own)
+ continue;
+ if (lcp->l_flags & L_ENGINEER) {
max = lcp->l_item[I_SHELL];
shells = lp->lnd_item[I_SHELL];
for (m = 0; mines > 0 && m < 5; m++) {
lp->lnd_item[I_SHELL] = shells;
putsect(§);
}
- if (mines > 0 && (sect.sct_oldown != lp->lnd_own) &&
- chance(DMINE_LHITCHANCE(mines))) {
+ if (chance(DMINE_LHITCHANCE(mines))) {
wu(0, lp->lnd_own,
"%s %s,\nand hit a mine in %s while retreating!\n",
prland(lp),