From d94d269769c26e19827d29184ea2254a211263cb Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Tue, 23 Jan 2007 23:51:02 +0000 Subject: [PATCH] (unit_put): New, create by combining shp_put() and lnd_put(). (sail_nav_fleet, shp_nav_one_sector): Replace shp_put() with unit_put(). (lnd_mar_one_sector, att_fight, move_in_land): Replace lnd_put() with unit_put(). (shp_put, lnd_put): Remove. --- include/land.h | 1 - include/prototypes.h | 1 - include/unit.h | 3 ++- src/lib/subs/attsub.c | 4 ++-- src/lib/subs/lndsub.c | 28 +--------------------------- src/lib/subs/shpsub.c | 24 +----------------------- src/lib/subs/unitsub.c | 32 ++++++++++++++++++++++++++++++++ src/lib/update/sail.c | 2 +- 8 files changed, 39 insertions(+), 56 deletions(-) diff --git a/include/land.h b/include/land.h index 8af468b6..8be609a5 100644 --- a/include/land.h +++ b/include/land.h @@ -206,7 +206,6 @@ extern int count_sect_units(struct sctstr *); extern void count_units(struct shpstr *); extern void lnd_count_units(struct lndstr *); 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_mar_one_sector(struct emp_qelem *, int, natid, int); extern int lnd_support(natid, natid, coord, coord, int); diff --git a/include/prototypes.h b/include/prototypes.h index 26fa3193..77078d07 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -665,7 +665,6 @@ extern void shp_sel(struct nstr_item *, struct emp_qelem *); extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid); extern int shp_sweep(struct emp_qelem *, int, int, natid); extern char *shp_path(int, struct shpstr *, char *); -extern void shp_put(struct emp_qelem *, natid); extern int shp_check_nav(struct sctstr *, struct shpstr *); extern int sect_has_dock(struct sctstr *); extern int shp_hardtarget(struct shpstr *); diff --git a/include/unit.h b/include/unit.h index 6209bdce..913532b2 100644 --- a/include/unit.h +++ b/include/unit.h @@ -28,7 +28,7 @@ * unit.h: Generalize unit data structures and functions. * * Known contributors to this file: - * Ron Koenderink, 2006 + * Ron Koenderink, 2006-2007 * Markus Armbruster, 2006 */ @@ -43,3 +43,4 @@ struct ulist { }; extern void unit_list(struct emp_qelem *); +extern void unit_put(struct emp_qelem *list, natid actor); diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 45028d5b..360da15e 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -2017,7 +2017,7 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist, send_reacting_units_home(dlist); /* putland the defending land */ - lnd_put(dlist, 0); + unit_put(dlist, 0); /* putland the attacking land */ put_land(olist); @@ -2394,7 +2394,7 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist, } if (QEMPTY(olist)) return; - lnd_put(olist, 0); + unit_put(olist, 0); } /* diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 00c5cdd3..0b34c97b 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -598,32 +598,6 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp, } } -void -lnd_put(struct emp_qelem *list, natid actor) -{ - struct emp_qelem *qp; - struct emp_qelem *newqp; - struct ulist *llp; - - qp = list->q_back; - while (qp != list) { - llp = (struct ulist *)qp; - if (actor) { - mpr(actor, "%s stopped at %s\n", prland(&llp->unit.land), - xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y, - llp->unit.land.lnd_own)); - if (llp->mobil < -127) - llp->mobil = -127; - llp->unit.land.lnd_mobil = llp->mobil; - } - putland(llp->unit.land.lnd_uid, &llp->unit.land); - newqp = qp->q_back; - emp_remque(qp); - free(qp); - qp = newqp; - } -} - void lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, natid actor) @@ -1014,7 +988,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, int oldown; if (dir <= DIR_STOP || dir >= DIR_VIEW) { - lnd_put(list, actor); + unit_put(list, actor); return 1; } dx = diroff[dir][0]; diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index 679a1195..0d8c48ff 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -186,28 +186,6 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, } } -void -shp_put(struct emp_qelem *list, natid actor) -{ - struct emp_qelem *qp; - struct emp_qelem *newqp; - struct ulist *mlp; - - qp = list->q_back; - while (qp != list) { - mlp = (struct ulist *)qp; - mpr(actor, "%s stopped at %s\n", prship(&mlp->unit.ship), - xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, - mlp->unit.ship.shp_own)); - mlp->unit.ship.shp_mobil = (int)mlp->mobil; - putship(mlp->unit.ship.shp_uid, &mlp->unit.ship); - newqp = qp->q_back; - emp_remque(qp); - free(qp); - qp = newqp; - } -} - int shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor) { @@ -801,7 +779,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor, int navigate; if (dir <= DIR_STOP || dir >= DIR_VIEW) { - shp_put(list, actor); + unit_put(list, actor); return 1; } dx = diroff[dir][0]; diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index e19e9b97..e69459c1 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -94,3 +94,35 @@ unit_list(struct emp_qelem *unit_list) pr("\n"); } } + +void +unit_put(struct emp_qelem *list, natid actor) +{ + struct emp_qelem *qp; + struct emp_qelem *newqp; + struct ulist *ulp; + + qp = list->q_back; + while (qp != list) { + ulp = (struct ulist *)qp; + if (actor) { + mpr(actor, "%s stopped at %s\n", obj_nameof(&ulp->unit.gen), + xyas(ulp->unit.gen.x, ulp->unit.gen.y, + ulp->unit.gen.own)); + if (ulp->unit.ef_type == EF_LAND) { + if (ulp->mobil < -127) + ulp->mobil = -127; + ulp->unit.land.lnd_mobil = ulp->mobil; + } + } + if (ulp->unit.ef_type == EF_SHIP) + ulp->unit.ship.shp_mobil = (int)ulp->mobil; + put_empobj(&ulp->unit.gen); + newqp = qp->q_back; + emp_remque(qp); + free(qp); + qp = newqp; + } +} + + diff --git a/src/lib/update/sail.c b/src/lib/update/sail.c index eb0d3931..9009f414 100644 --- a/src/lib/update/sail.c +++ b/src/lib/update/sail.c @@ -251,7 +251,7 @@ sail_nav_fleet(struct fltheadstr *fltp) fltp->maxmoves = 1; --fltp->maxmoves; } - shp_put(&ship_list, own); + unit_put(&ship_list, own); getship(sp->shp_uid, &ship); fltp->x = ship.shp_x; fltp->y = ship.shp_y;