subs: Split unit_put() into shp_put() and lnd_put() again

Commit d94d269 combined them into unit_put(), but that has turned out
not to be useful.  Split them again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-01-25 15:41:58 +01:00
parent 62b9399cdf
commit b5ffc1ca49
8 changed files with 52 additions and 41 deletions

View file

@ -187,6 +187,7 @@ extern void lnd_takemob(struct emp_qelem *, double);
extern int lnd_spyval(struct lndstr *); extern int lnd_spyval(struct lndstr *);
extern void intelligence_report(int, struct lndstr *, int, char *); extern void intelligence_report(int, struct lndstr *, int, char *);
extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid); extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid);
extern void lnd_put(struct emp_qelem *, natid);
extern int lnd_hardtarget(struct lndstr *); extern int lnd_hardtarget(struct lndstr *);
extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int); extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
extern int lnd_support(natid, natid, coord, coord, int); extern int lnd_support(natid, natid, coord, coord, int);

View file

@ -185,6 +185,7 @@ extern double shp_torp_hitchance(struct shpstr *, int);
extern void shp_sel(struct nstr_item *, struct emp_qelem *); extern void shp_sel(struct nstr_item *, struct emp_qelem *);
extern struct ulist *shp_insque(struct shpstr *, struct emp_qelem *); extern struct ulist *shp_insque(struct shpstr *, struct emp_qelem *);
extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid); extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid);
extern void shp_put(struct emp_qelem *, natid);
extern int shp_sweep(struct emp_qelem *, int, int, natid); extern int shp_sweep(struct emp_qelem *, int, int, natid);
extern enum d_navigation shp_check_nav(struct shpstr *, struct sctstr *); extern enum d_navigation shp_check_nav(struct shpstr *, struct sctstr *);
extern int sect_has_dock(struct sctstr *); extern int sect_has_dock(struct sctstr *);

View file

@ -58,7 +58,6 @@ extern void unit_onresize(int);
extern char *unit_nameof(struct empobj *); extern char *unit_nameof(struct empobj *);
extern void unit_list(struct emp_qelem *); extern void unit_list(struct emp_qelem *);
extern void unit_put(struct emp_qelem *list, natid actor);
extern char *unit_path(int, struct empobj *, char *, size_t); extern char *unit_path(int, struct empobj *, char *, size_t);
extern void unit_view(struct emp_qelem *); extern void unit_view(struct emp_qelem *);
extern void unit_teleport(struct empobj *, coord, coord); extern void unit_teleport(struct empobj *, coord, coord);

View file

@ -1959,7 +1959,7 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
send_reacting_units_home(dlist); send_reacting_units_home(dlist);
/* putland the defending land */ /* putland the defending land */
unit_put(dlist, 0); lnd_put(dlist, 0);
/* putland the attacking land */ /* putland the attacking land */
put_oland(olist); put_oland(olist);
@ -2340,7 +2340,7 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
} }
if (QEMPTY(olist)) if (QEMPTY(olist))
return; return;
unit_put(olist, 0); lnd_put(olist, 0);
} }
/* /*

View file

@ -531,6 +531,30 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
} }
} }
void
lnd_put(struct emp_qelem *list, natid actor)
{
struct emp_qelem *qp, *next;
struct ulist *llp;
struct lndstr *lp;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
llp = (struct ulist *)qp;
lp = &llp->unit.land;
if (actor) {
mpr(actor, "%s stopped at %s\n",
prland(lp), xyas(lp->lnd_x, lp->lnd_y, actor));
if (llp->mobil < -127)
llp->mobil = -127;
lp->lnd_mobil = llp->mobil;
}
putland(lp->lnd_uid, lp);
emp_remque(qp);
free(qp);
}
}
/* /*
* Sweep landmines with engineers in LAND_LIST for ACTOR. * Sweep landmines with engineers in LAND_LIST for ACTOR.
* If EXPLICIT is non-zero, this is for an explicit sweep command from * If EXPLICIT is non-zero, this is for an explicit sweep command from
@ -927,7 +951,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
int oldown; int oldown;
if (dir <= DIR_STOP || dir >= DIR_VIEW) { if (dir <= DIR_STOP || dir >= DIR_VIEW) {
unit_put(list, actor); lnd_put(list, actor);
return 1; return 1;
} }
dx = diroff[dir][0]; dx = diroff[dir][0];

View file

@ -180,6 +180,26 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
} }
} }
void
shp_put(struct emp_qelem *list, natid actor)
{
struct emp_qelem *qp, *next;
struct ulist *mlp;
struct shpstr *sp;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
mlp = (struct ulist *)qp;
sp = &mlp->unit.ship;
mpr(actor, "%s stopped at %s\n",
prship(sp), xyas(sp->shp_x, sp->shp_y, actor));
sp->shp_mobil = (int)mlp->mobil;
putship(sp->shp_uid, sp);
emp_remque(qp);
free(qp);
}
}
int int
shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor) shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
{ {
@ -759,7 +779,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
int navigate; int navigate;
if (dir <= DIR_STOP || dir >= DIR_VIEW) { if (dir <= DIR_STOP || dir >= DIR_VIEW) {
unit_put(list, actor); shp_put(list, actor);
return 1; return 1;
} }
dx = diroff[dir][0]; dx = diroff[dir][0];

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Ron Koenderink, 2007 * Ron Koenderink, 2007
* Markus Armbruster, 2009-2013 * Markus Armbruster, 2009-2014
*/ */
#include <config.h> #include <config.h>
@ -116,40 +116,6 @@ unit_list(struct emp_qelem *unit_list)
} }
} }
void
unit_put(struct emp_qelem *list, natid actor)
{
struct emp_qelem *qp;
struct emp_qelem *newqp;
struct ulist *ulp;
struct empobj *unit;
qp = list->q_back;
while (qp != list) {
ulp = (struct ulist *)qp;
unit = &ulp->unit.gen;
if (CANT_HAPPEN(unit->ef_type != EF_LAND
&& unit->ef_type != EF_SHIP))
continue;
if (actor) {
mpr(actor, "%s stopped at %s\n", unit_nameof(unit),
xyas(unit->x, unit->y, actor));
if (unit->ef_type == EF_LAND) {
if (ulp->mobil < -127)
ulp->mobil = -127;
unit->mobil = ulp->mobil;
}
}
if (unit->ef_type == EF_SHIP)
unit->mobil = (int)ulp->mobil;
put_empobj(unit->ef_type, unit->uid, unit);
newqp = qp->q_back;
emp_remque(qp);
free(qp);
qp = newqp;
}
}
char * char *
unit_path(int together, struct empobj *unit, char *buf, size_t bufsz) unit_path(int together, struct empobj *unit, char *buf, size_t bufsz)
{ {

View file

@ -270,7 +270,7 @@ sail_nav_fleet(struct fltheadstr *fltp)
fltp->maxmoves = 1; fltp->maxmoves = 1;
--fltp->maxmoves; --fltp->maxmoves;
} }
unit_put(&ship_list, own); shp_put(&ship_list, own);
getship(sp->shp_uid, &ship); getship(sp->shp_uid, &ship);
fltp->x = ship.shp_x; fltp->x = ship.shp_x;
fltp->y = ship.shp_y; fltp->y = ship.shp_y;