retreat: Don't charge mobility for retreating in direction 'h'
Obscure feature: 'h' in a retreat path stops the current retreat. The code treats that as entering the current sector again, thus charges mobility for staying put. It also reports "could not retreat to" for a ship or land unit that can retreat out of, but could not retreat into its current sector, e.g. a ship in an unfriendly harbor. Fix by cleaning up the tortuous control flow. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
98cb83302c
commit
b3453efdfc
3 changed files with 14 additions and 40 deletions
|
@ -129,7 +129,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
|||
/* Is this the originally scared ship, or a follower */
|
||||
{
|
||||
struct sctstr sect;
|
||||
int n;
|
||||
int i;
|
||||
int m;
|
||||
int max;
|
||||
int dir;
|
||||
|
@ -137,7 +137,6 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
|||
coord newy;
|
||||
coord dx;
|
||||
coord dy;
|
||||
int stopping;
|
||||
int mines;
|
||||
int shells;
|
||||
double mobcost;
|
||||
|
@ -192,14 +191,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
|||
return 0;
|
||||
}
|
||||
|
||||
n = -MAX_RETREAT;
|
||||
stopping = 0;
|
||||
while (!stopping && n) {
|
||||
dx = dy = 0;
|
||||
if (sp->shp_rpath[0] == 0) {
|
||||
stopping = 1;
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < MAX_RETREAT && sp->shp_rpath[0]; i++) {
|
||||
if (sp->shp_mobil <= 0.0) {
|
||||
wu(0, sp->shp_own,
|
||||
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
||||
|
@ -213,12 +205,9 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
|||
if (dir < 0)
|
||||
continue;
|
||||
if (dir == DIR_STOP)
|
||||
stopping++;
|
||||
else {
|
||||
break;
|
||||
dx = diroff[dir][0];
|
||||
dy = diroff[dir][1];
|
||||
}
|
||||
n++;
|
||||
|
||||
mcp = &mchr[(int)sp->shp_type];
|
||||
newx = xnorm(sp->shp_x + dx);
|
||||
|
@ -240,8 +229,6 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
|||
sp->shp_y = newy;
|
||||
sp->shp_mobil -= mobcost;
|
||||
sp->shp_mission = 0;
|
||||
if (stopping)
|
||||
continue;
|
||||
|
||||
mines = sect.sct_mines;
|
||||
changed = 0;
|
||||
|
@ -366,7 +353,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
|||
/* Is this the originally scared unit, or a follower */
|
||||
{
|
||||
struct sctstr sect;
|
||||
int n;
|
||||
int i;
|
||||
int m;
|
||||
int max;
|
||||
int dir;
|
||||
|
@ -374,7 +361,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
|||
coord newy;
|
||||
coord dx;
|
||||
coord dy;
|
||||
int stopping;
|
||||
int mines;
|
||||
int shells;
|
||||
double mobcost;
|
||||
|
@ -389,14 +375,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
|||
return 0;
|
||||
}
|
||||
|
||||
n = -MAX_RETREAT;
|
||||
stopping = 0;
|
||||
while (!stopping && n) {
|
||||
dx = dy = 0;
|
||||
if (lp->lnd_rpath[0] == 0) {
|
||||
stopping = 1;
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < MAX_RETREAT && lp->lnd_rpath[0]; i++) {
|
||||
if (lp->lnd_mobil <= 0.0) {
|
||||
wu(0, lp->lnd_own,
|
||||
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
||||
|
@ -410,12 +389,9 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
|||
if (dir < 0)
|
||||
continue;
|
||||
if (dir == DIR_STOP)
|
||||
stopping++;
|
||||
else {
|
||||
break;
|
||||
dx = diroff[dir][0];
|
||||
dy = diroff[dir][1];
|
||||
}
|
||||
n++;
|
||||
|
||||
lcp = &lchr[(int)lp->lnd_type];
|
||||
newx = xnorm(lp->lnd_x + dx);
|
||||
|
@ -438,8 +414,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
|||
lp->lnd_y = newy;
|
||||
lp->lnd_mobil -= mobcost;
|
||||
lp->lnd_mission = 0;
|
||||
if (stopping)
|
||||
continue;
|
||||
|
||||
mines = SCT_LANDMINES(§);
|
||||
if (mines <= 0 || sect.sct_oldown == lp->lnd_own)
|
||||
|
|
|
@ -157,7 +157,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius fleet xstar
|
|||
7 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () ""
|
||||
8 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () ""
|
||||
9 2 -4 -2 17 60 127 0 70 0 0 none 0 "a" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 38 1 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 9 "" -3 1 1 () ""
|
||||
10 2 4 4 2 83 22 0 20 0 0 none 0 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 10 "" -3 1 1 () ""
|
||||
10 2 4 4 2 83 53 0 20 0 0 none 0 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 10 "" -3 1 1 () ""
|
||||
11 2 1 3 2 91 99 0 20 0 0 none 0 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 11 "" -3 1 1 () ""
|
||||
12 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () ""
|
||||
13 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () ""
|
||||
|
@ -363,7 +363,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h
|
|||
7 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
8 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
9 2 1 1 7 93 119 0 50 0 0 none 0 "" -1 127 42 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
10 2 4 0 0 61 45 0 50 0 0 none 0 "" -1 127 42 () "" 0 6 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
10 2 4 0 0 61 61 0 50 0 0 none 0 "" -1 127 42 () "" 0 6 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
11 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
12 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
13 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
|
||||
|
|
|
@ -1484,7 +1484,7 @@
|
|||
Play#0 command ship
|
||||
Play#0 output Play#0 1 own shp# ship type x,y fl eff civ mil uw fd pn he xl ln mob tech
|
||||
Play#0 output Play#0 1 1 2 cs cargo ship -3,1 91% 0 9 0 0 0 0 0 0 115 20
|
||||
Play#0 output Play#0 1 2 10 cs cargo ship 4,4 83% 0 8 0 0 0 0 0 0 22 20
|
||||
Play#0 output Play#0 1 2 10 cs cargo ship 4,4 83% 0 8 0 0 0 0 0 0 53 20
|
||||
Play#0 output Play#0 1 2 11 cs cargo ship 1,3 91% 0 9 0 0 0 0 0 0 99 20
|
||||
Play#0 output Play#0 1 2 20 cs cargo ship -3,1 95% 0 9 0 0 0 0 0 0 121 20
|
||||
Play#0 output Play#0 1 2 31 cs cargo ship 0,2 94% 0 10 0 0 0 0 0 0 119 20
|
||||
|
@ -1580,7 +1580,7 @@
|
|||
Play#0 output Play#0 1 own # unit type x,y a eff mil frt mu fd tch retr xl ln carry
|
||||
Play#0 output Play#0 1 1 2 inf infantry -3,1 89% 9 127 113 0 50 42% 0 0
|
||||
Play#0 output Play#0 1 2 9 tra train 1,1 93% 10 127 119 0 50 42% 0 1
|
||||
Play#0 output Play#0 1 2 10 cav cavalry 4,0 61% 6 127 45 0 50 42% 0 0
|
||||
Play#0 output Play#0 1 2 10 cav cavalry 4,0 61% 6 127 61 0 50 42% 0 0
|
||||
Play#0 output Play#0 1 2 31 cav cavalry 0,2 99% 10 127 126 0 50 42% 0 0 35S
|
||||
Play#0 output Play#0 1 2 32 cav cavalry 3,1 83% 0 127 96 0 50 42% 0 0
|
||||
Play#0 output Play#0 1 2 33 cav cavalry 1,1 85% 8 127 97 0 50 42% 0 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue