- 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",
- prship(sp), conditions[findcondition(code)].desc[orig]);
- return 1;
- }
- dir = chkdir(sp->shp_rpath[0], DIR_STOP, DIR_LAST);
- if (dir == DIR_STOP || CANT_HAPPEN(dir < 0)) {
- memmove(sp->shp_rpath, sp->shp_rpath + 1,
- sizeof(sp->shp_rpath) - 1);
- if (sp->shp_rpath[0] == 0)
- sp->shp_rflags = 0;
- break;
- }
- dx = diroff[dir][0];
- dy = diroff[dir][1];
-
- mcp = &mchr[(int)sp->shp_type];
- newx = xnorm(sp->shp_x + dx);
- newy = ynorm(sp->shp_y + dy);
- mobcost = shp_mobcost(sp);
-
- getsect(newx, newy, §);
- if (shp_check_nav(sp, §) != SHP_STUCK_NOT ||
- (sect.sct_own
- && relations_with(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],
- xyas(newx, newy, sp->shp_own));
- return 1;
- }
- sp->shp_x = newx;
- sp->shp_y = newy;
- sp->shp_mobil -= mobcost;
- sp->shp_mission = 0;
- memmove(sp->shp_rpath, sp->shp_rpath + 1,
- sizeof(sp->shp_rpath) - 1);
- if (sp->shp_rpath[0] == 0)
- sp->shp_rflags = 0;
-
- mines = sect.sct_mines;
- changed = 0;
- 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 (chance(0.66)) {
- mines--;
- shells = MIN(max, shells + 1);
- changed |= map_set(sp->shp_own, sp->shp_x, sp->shp_y,
- 'X', 0);
- }
- }
- 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),
- xyas(newx, newy, sp->shp_own));
- sect.sct_mines = mines;
- sp->shp_item[I_SHELL] = shells;
- putsect(§);
- }
- if (changed)
- writemap(sp->shp_own);
- }
- 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],
- xyas(newx, newy, sp->shp_own));
- nreport(sp->shp_own, N_HIT_MINE, 0, 1);
- m = MINE_DAMAGE();
- shipdamage(sp, m);
- mines--;
- if (map_set(sp->shp_own, sp->shp_x, sp->shp_y, 'X', 0))
- writemap(sp->shp_own);
- sect.sct_mines = mines;
- putsect(§);
- return 1;
- }
- }