extern void lnd_put(struct emp_qelem *);
extern void lnd_put_one(struct ulist *);
extern int lnd_hardtarget(struct lndstr *);
+extern int lnd_abandon_askyn(struct emp_qelem *);
extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
extern int lnd_support(natid, natid, coord, coord, int);
extern int lnd_can_attack(struct lndstr *);
extern void set_coastal(struct sctstr *, int, int);
/* control.c */
extern int military_control(struct sctstr *);
-extern int want_to_abandon(struct sctstr *, i_type, int, struct lndstr *);
-extern int would_abandon(struct sctstr *, i_type, int, struct lndstr *);
+extern int abandon_askyn(struct sctstr *, i_type, int, struct ulist *);
+extern int would_abandon(struct sctstr *, i_type, int, struct ulist *);
/* damage.c */
extern void landdamage(struct lndstr *, int);
extern void ship_damage(struct shpstr *, int);
pr("Only exploring with %d.\n", amount);
}
- if (!want_to_abandon(§, vtype, amount, NULL)) {
+ if (!abandon_askyn(§, vtype, amount, NULL)) {
pr("Explore cancelled.\n");
return RET_FAIL;
}
* David Sharnoff, 1987
* Ken Stevens, 1995 (rewritten)
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2013
+ * Markus Armbruster, 2004-2014
*/
#include <config.h>
load_unload, atoi(p));
if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
return RET_OK;
- if (!want_to_abandon(sectp, item, move_amt, NULL))
+ if (!abandon_askyn(sectp, item, move_amt, NULL))
return RET_FAIL;
if (!still_ok_ship(sectp, sp))
return RET_SYN;
}
}
- if (!istest && !want_to_abandon(§, vtype, amount, NULL)) {
+ if (!istest && !abandon_askyn(§, vtype, amount, NULL)) {
pr("Move cancelled.\n");
return RET_FAIL;
}
int dir;
int stopping = 0;
int skip = 0;
+ int moved = 0;
char buf[1024];
char prompt[128];
char bmap_flag;
if (type == EF_SHIP)
stopping |= shp_nav_one_sector(ulist, dir,
player->cnum, *together);
- else
+ else {
+ if (!moved && !lnd_abandon_askyn(ulist))
+ return RET_FAIL;
stopping |=
lnd_mar_one_sector(ulist, dir, player->cnum,
*together);
+ }
+ moved = 1;
cp++;
continue;
}
*
* Known contributors to this file:
* Dave Pare, 1986
+ * Markus Armbruster, 2014
*/
#include <config.h>
#include "player.h"
#include "prototypes.h"
#include "sect.h"
+#include "unit.h"
/*
* Does the player->owner have military control of this sector?
return 1;
}
+/*
+ * Ask user to confirm abandonment of sector SP, if any.
+ * If removing AMNT commodities of type VTYPE and the land units in
+ * LIST would abandon their sector, ask the user to confirm.
+ * All land units in LIST must be in this sector. LIST may be null.
+ * Return zero when abandonment was declined, else non-zero.
+ */
int
-want_to_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
+abandon_askyn(struct sctstr *sp, i_type vtype, int amnt,
+ struct ulist *land_list)
{
char prompt[80];
* First, would we be abandoning it? If not, just return that
* it's ok to move out.
*/
- if (!would_abandon(sp, vtype, amnt, lp))
+ if (!would_abandon(sp, vtype, amnt, land_list))
return 1;
sprintf(prompt, "Do you really want to abandon %s [yn]? ",
return askyn(prompt);
}
+/*
+ * Would removing this stuff from SP abandon it?
+ * Consider removal of AMNT commodities of type VTYPE and the land
+ * units in LIST.
+ * All land units in LIST must be in this sector. LIST may be null.
+ */
int
-would_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
+would_abandon(struct sctstr *sp, i_type vtype, int amnt,
+ struct ulist *land_list)
{
- int mil, civs;
+ int mil, civs, nland;
if (vtype != I_CIVIL && vtype != I_MILIT)
return 0;
if (vtype == I_CIVIL)
civs -= amnt;
- return sp->sct_own != 0 && civs <= 0 && mil <= 0
- && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, lp);
+ if (!sp->sct_own || civs > 0 || mil > 0)
+ return 0;
+ nland = unitsatxy(sp->sct_x, sp->sct_y, 0, 0, 1);
+ if (land_list)
+ nland -= emp_quelen(&land_list->queue);
+ return nland <= 0;
}
return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
}
+/*
+ * Ask user to confirm sector abandonment, if any.
+ * All land units in LIST must be in the same sector.
+ * If removing the land units in LIST would abandon their sector, ask
+ * the user to confirm.
+ * Return zero when abandonment was declined, else non-zero.
+ */
+int lnd_abandon_askyn(struct emp_qelem *list)
+{
+ struct ulist *llp;
+ struct sctstr sect;
+ struct emp_qelem *qp;
+
+ if (QEMPTY(list))
+ return 1;
+ llp = (struct ulist *)list->q_back;
+ getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
+ if (!abandon_askyn(§, I_CIVIL, 0, llp))
+ return 0;
+ if (!check_sect_ok(§))
+ return 0;
+ for (qp = list->q_back; qp != list; qp = qp->q_back) {
+ if (!check_land_ok(&((struct ulist *)qp)->unit.land))
+ return 0;
+ }
+ return 1;
+}
+
int
lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
int together)
{
struct sctstr sect, osect;
struct emp_qelem *qp;
- struct emp_qelem *qp2;
struct emp_qelem *next;
struct ulist *llp;
struct emp_qelem cur, done;
enum lnd_stuck stuck;
int stopping = 0;
int visible;
- int stop;
char dp[80];
int rel;
int oldown;
}
}
}
- /* Note we check would_abandon first because we don't want
- to always have to do these checks */
- if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
- stop = 0;
- if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
- stop = 1;
- }
- /* now check stuff */
- if (!check_sect_ok(§))
- return 1;
- if (!check_sect_ok(&osect))
- return 1;
- for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
- if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
- return 1;
- }
- if (stop) {
- lnd_stays(actor, "stops", llp);
- continue;
- }
- }
if (llp->mobil <= 0.0) {
lnd_stays(actor, "is out of mobility", llp);
continue;
h
march 78/79 yj
n
-h
-| TODO empty sector at march prompt
| run out of mob, change leader
march 84/83/80/81/82
jjun
75 1 0 4 7 100 127 0 40 0 0 none 0 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
76 1 2 6 0 100 104 0 30 1 7 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
77 1 2 6 0 100 104 0 30 1 7 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
-78 1 4 6 0 100 104 0 30 3 7 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
+78 1 3 7 0 100 127 0 30 3 7 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
79 1 3 7 0 100 127 0 30 3 7 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
80 1 9 5 0 100 60 0 30 3 5 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
81 1 9 5 0 100 60 0 30 3 5 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
Play#1 output Play#1 1 Leader is cav cavalry #78
Play#1 output Play#1 4 Do you really want to abandon 3,7 [yn]?
Play#1 input n
- Play#1 output Play#1 1 cav cavalry #79 stops & stays in 3,7
- Play#1 output Play#1 1 + m
- Play#1 output Play#1 1 m m m
- Play#1 output Play#1 1 m m
- Play#1 output Play#1 4 <104.7:104.7: 4,6>
- Play#1 input h
- Play#1 output Play#1 1 cav cavalry #78 stopped at 4,6
+ Play#1 output Play#1 1 command failed
Play#1 output Play#1 6 0 567
Play#1 input march 84/83/80/81/82
Play#1 command march
Play#0 output Play#0 1 1 75 tra train 0,4 100% 5 0 127 0 40 42% 0 0
Play#0 output Play#0 1 1 76 cav cavalry 2,6 100% 5 0 104 0 30 42% 0 0
Play#0 output Play#0 1 1 77 cav cavalry 2,6 100% 5 0 104 0 30 42% 0 0
- Play#0 output Play#0 1 1 78 cav cavalry 4,6 100% 5 0 104 0 30 42% 0 0
+ Play#0 output Play#0 1 1 78 cav cavalry 3,7 100% 5 0 127 0 30 42% 0 0
Play#0 output Play#0 1 1 79 cav cavalry 3,7 100% 5 0 127 0 30 42% 0 0
Play#0 output Play#0 1 1 80 cav cavalry 9,5 100% 5 0 60 0 30 42% 0 0
Play#0 output Play#0 1 1 81 cav cavalry 9,5 100% 5 0 60 0 30 42% 0 0