retreat: Clean up interface between retreat_FOO(), retreat_FOO1()
Move clearing of retreat flags from retreat_ship(), retreat_land() to retreat_ship1(), retreat_land1(), so it's where the retreat path is shortened. Move putship(), putland() from retreat_ship1(), retreat_land1() to retreat_ship(), retreat_land(), so it's where the nxtitem() is, and doesn't need a "if (!orig)" guard. Requires making retreat_ship1() and retreat_land() return non-zero when they modified their argument. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
ff826d2582
commit
8f5c600f71
1 changed files with 28 additions and 48 deletions
|
@ -103,22 +103,15 @@ retreat_ship(struct shpstr *sp, char code)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
retreat_ship1(sp, code, 1);
|
retreat_ship1(sp, code, 1);
|
||||||
if (sp->shp_rpath[0] == 0)
|
|
||||||
sp->shp_rflags = 0;
|
|
||||||
|
|
||||||
if (sp->shp_rflags & RET_GROUP) {
|
if (sp->shp_rflags & RET_GROUP) {
|
||||||
snxtitem_group(&ni, EF_SHIP, sp->shp_fleet);
|
snxtitem_group(&ni, EF_SHIP, sp->shp_fleet);
|
||||||
while (nxtitem(&ni, &ship))
|
while (nxtitem(&ni, &ship)) {
|
||||||
if (ship.shp_own == sp->shp_own) {
|
if (ship.shp_own != sp->shp_own || ship.shp_uid == sp->shp_uid)
|
||||||
if (ship.shp_uid != sp->shp_uid) {
|
continue;
|
||||||
retreat_ship1(&ship, code, 0);
|
if (retreat_ship1(&ship, code, 0))
|
||||||
getship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
if (ship.shp_rpath[0] == 0) {
|
}
|
||||||
ship.shp_rflags = 0;
|
|
||||||
putship(ship.shp_uid, &ship);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,14 +189,14 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
wu(0, sp->shp_own,
|
wu(0, sp->shp_own,
|
||||||
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
||||||
prship(sp), conditions[findcondition(code)].desc[orig]);
|
prship(sp), conditions[findcondition(code)].desc[orig]);
|
||||||
if (!orig)
|
return 1;
|
||||||
putship(sp->shp_uid, sp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
dir = chkdir(sp->shp_rpath[0], DIR_STOP, DIR_LAST);
|
dir = chkdir(sp->shp_rpath[0], DIR_STOP, DIR_LAST);
|
||||||
if (dir == DIR_STOP || CANT_HAPPEN(dir < 0)) {
|
if (dir == DIR_STOP || CANT_HAPPEN(dir < 0)) {
|
||||||
memmove(sp->shp_rpath, sp->shp_rpath + 1,
|
memmove(sp->shp_rpath, sp->shp_rpath + 1,
|
||||||
sizeof(sp->shp_rpath) - 1);
|
sizeof(sp->shp_rpath) - 1);
|
||||||
|
if (sp->shp_rpath[0] == 0)
|
||||||
|
sp->shp_rflags = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dx = diroff[dir][0];
|
dx = diroff[dir][0];
|
||||||
|
@ -221,9 +214,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
|
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
|
||||||
prship(sp), conditions[findcondition(code)].desc[orig],
|
prship(sp), conditions[findcondition(code)].desc[orig],
|
||||||
xyas(newx, newy, sp->shp_own));
|
xyas(newx, newy, sp->shp_own));
|
||||||
if (!orig)
|
return 1;
|
||||||
putship(sp->shp_uid, sp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
sp->shp_x = newx;
|
sp->shp_x = newx;
|
||||||
sp->shp_y = newy;
|
sp->shp_y = newy;
|
||||||
|
@ -231,6 +222,8 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
sp->shp_mission = 0;
|
sp->shp_mission = 0;
|
||||||
memmove(sp->shp_rpath, sp->shp_rpath + 1,
|
memmove(sp->shp_rpath, sp->shp_rpath + 1,
|
||||||
sizeof(sp->shp_rpath) - 1);
|
sizeof(sp->shp_rpath) - 1);
|
||||||
|
if (sp->shp_rpath[0] == 0)
|
||||||
|
sp->shp_rflags = 0;
|
||||||
|
|
||||||
mines = sect.sct_mines;
|
mines = sect.sct_mines;
|
||||||
changed = 0;
|
changed = 0;
|
||||||
|
@ -273,9 +266,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
writemap(sp->shp_own);
|
writemap(sp->shp_own);
|
||||||
sect.sct_mines = mines;
|
sect.sct_mines = mines;
|
||||||
putsect(§);
|
putsect(§);
|
||||||
if (!orig)
|
return 1;
|
||||||
putship(sp->shp_uid, sp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,8 +280,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
conditions[findcondition(code)].desc[orig],
|
conditions[findcondition(code)].desc[orig],
|
||||||
xyas(sp->shp_x, sp->shp_y, sp->shp_own));
|
xyas(sp->shp_x, sp->shp_y, sp->shp_own));
|
||||||
}
|
}
|
||||||
if (!orig)
|
|
||||||
putship(sp->shp_uid, sp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,22 +319,15 @@ retreat_land(struct lndstr *lp, char code)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
retreat_land1(lp, code, 1);
|
retreat_land1(lp, code, 1);
|
||||||
if (lp->lnd_rpath[0] == 0)
|
|
||||||
lp->lnd_rflags = 0;
|
|
||||||
|
|
||||||
if (lp->lnd_rflags & RET_GROUP) {
|
if (lp->lnd_rflags & RET_GROUP) {
|
||||||
snxtitem_group(&ni, EF_LAND, lp->lnd_army);
|
snxtitem_group(&ni, EF_LAND, lp->lnd_army);
|
||||||
while (nxtitem(&ni, &land))
|
while (nxtitem(&ni, &land)) {
|
||||||
if (land.lnd_own == lp->lnd_own) {
|
if (land.lnd_own != lp->lnd_own || land.lnd_uid == lp->lnd_uid)
|
||||||
if (land.lnd_uid != lp->lnd_uid) {
|
continue;
|
||||||
retreat_land1(&land, code, 0);
|
if (retreat_land1(&land, code, 0))
|
||||||
getland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
if (land.lnd_rpath[0] == 0) {
|
}
|
||||||
land.lnd_rflags = 0;
|
|
||||||
putland(land.lnd_uid, &land);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,14 +365,14 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
wu(0, lp->lnd_own,
|
wu(0, lp->lnd_own,
|
||||||
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
"%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n",
|
||||||
prland(lp), conditions[findcondition(code)].desc[orig]);
|
prland(lp), conditions[findcondition(code)].desc[orig]);
|
||||||
if (!orig)
|
return 1;
|
||||||
putland(lp->lnd_uid, lp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
dir = chkdir(lp->lnd_rpath[0], DIR_STOP, DIR_LAST);
|
dir = chkdir(lp->lnd_rpath[0], DIR_STOP, DIR_LAST);
|
||||||
if (dir == DIR_STOP || CANT_HAPPEN(dir < 0)) {
|
if (dir == DIR_STOP || CANT_HAPPEN(dir < 0)) {
|
||||||
memmove(lp->lnd_rpath, lp->lnd_rpath + 1,
|
memmove(lp->lnd_rpath, lp->lnd_rpath + 1,
|
||||||
sizeof(lp->lnd_rpath) - 1);
|
sizeof(lp->lnd_rpath) - 1);
|
||||||
|
if (lp->lnd_rpath[0] == 0)
|
||||||
|
lp->lnd_rflags = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dx = diroff[dir][0];
|
dx = diroff[dir][0];
|
||||||
|
@ -408,9 +391,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
prland(lp),
|
prland(lp),
|
||||||
conditions[findcondition(code)].desc[orig],
|
conditions[findcondition(code)].desc[orig],
|
||||||
xyas(newx, newy, lp->lnd_own));
|
xyas(newx, newy, lp->lnd_own));
|
||||||
if (!orig)
|
return 1;
|
||||||
putland(lp->lnd_uid, lp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
lp->lnd_x = newx;
|
lp->lnd_x = newx;
|
||||||
lp->lnd_y = newy;
|
lp->lnd_y = newy;
|
||||||
|
@ -418,6 +399,8 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
lp->lnd_mission = 0;
|
lp->lnd_mission = 0;
|
||||||
memmove(lp->lnd_rpath, lp->lnd_rpath + 1,
|
memmove(lp->lnd_rpath, lp->lnd_rpath + 1,
|
||||||
sizeof(lp->lnd_rpath) - 1);
|
sizeof(lp->lnd_rpath) - 1);
|
||||||
|
if (lp->lnd_rpath[0] == 0)
|
||||||
|
lp->lnd_rflags = 0;
|
||||||
|
|
||||||
mines = SCT_LANDMINES(§);
|
mines = SCT_LANDMINES(§);
|
||||||
if (mines <= 0 || sect.sct_oldown == lp->lnd_own)
|
if (mines <= 0 || sect.sct_oldown == lp->lnd_own)
|
||||||
|
@ -449,9 +432,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
mines--;
|
mines--;
|
||||||
sect.sct_mines = mines;
|
sect.sct_mines = mines;
|
||||||
putsect(§);
|
putsect(§);
|
||||||
if (!orig)
|
return 1;
|
||||||
putland(lp->lnd_uid, lp);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +447,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
conditions[findcondition(code)].desc[orig],
|
conditions[findcondition(code)].desc[orig],
|
||||||
xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
|
xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
|
||||||
}
|
}
|
||||||
if (!orig)
|
|
||||||
putland(lp->lnd_uid, lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue