From aee2bc78e2b2b771d673950d2be0f4877c8d348d Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Wed, 24 Jan 2007 23:24:37 +0000 Subject: [PATCH] (unit_path): New, create by combining shp_path() and lnd_path(). (do_unit_move): Replace shp_path() and lnd_path() with unit_path(). (shp_path, lnd_path): Remove shp_path() and lnd_path(), not used any more. --- include/land.h | 1 - include/prototypes.h | 1 - include/unit.h | 1 + src/lib/commands/navi.c | 20 ++++------------- src/lib/subs/lndsub.c | 35 ----------------------------- src/lib/subs/shpsub.c | 29 ------------------------ src/lib/subs/unitsub.c | 50 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 55 insertions(+), 82 deletions(-) diff --git a/include/land.h b/include/land.h index 8be609a5..58a8837c 100644 --- a/include/land.h +++ b/include/land.h @@ -191,7 +191,6 @@ extern int lnd_check_mines(struct emp_qelem *); extern double lnd_pathcost(struct lndstr *, double); extern int lnd_mobtype(struct lndstr *); extern double lnd_mobcost(struct lndstr *, struct sctstr *); -extern char *lnd_path(int, struct lndstr *, char *); extern double attack_val(int, struct lndstr *); extern double defense_val(struct lndstr *); diff --git a/include/prototypes.h b/include/prototypes.h index 77078d07..71d2b917 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -664,7 +664,6 @@ extern void show_news(int); 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 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 913532b2..7f21b9a6 100644 --- a/include/unit.h +++ b/include/unit.h @@ -44,3 +44,4 @@ struct ulist { 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 *); diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index fc496aaf..b017a054 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -94,13 +94,8 @@ do_unit_move(struct emp_qelem *ulist, int *together, if (player->argp[2]) { strcpy(buf, player->argp[2]); - if (type == EF_SHIP) { - if (!(cp = shp_path(*together, (struct shpstr *)leader, buf))) - cp = player->argp[2]; - } else { - if (!(cp = lnd_path(*together, (struct lndstr *)leader, buf))) - cp = player->argp[2]; - } + if (!(cp = unit_path(*together, leader, buf))) + cp = player->argp[2]; } *pt = '\0'; @@ -161,15 +156,8 @@ do_unit_move(struct emp_qelem *ulist, int *together, stopping = 1; continue; } - if (type == EF_SHIP) { - if (!(cp = shp_path(*together, (struct shpstr *)leader, - buf))) - cp = buf; - } else { - if (!(cp = lnd_path(*together, (struct lndstr *)leader, - buf))) - cp = buf; - } + if (!(cp = unit_path(*together, leader, buf))) + cp = buf; } if (type == EF_SHIP) { radmapnopr(leader->x, leader->y, (int)leader->effic, diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 0b34c97b..2db626d0 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -1205,41 +1205,6 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending) } return (int)dam; } - -char * -lnd_path(int together, struct lndstr *lp, char *buf) -{ - coord destx; - coord desty; - struct sctstr d_sect, sect; - char *cp; - double dummy; - int mtype; - - if (!sarg_xy(buf, &destx, &desty)) - return 0; - if (!together) { - pr("Cannot go to a destination sector if not all starting in the same sector\n"); - return 0; - } - if (!getsect(destx, desty, &d_sect)) { - pr("%d,%d is not a sector\n", destx, desty); - return 0; - } - getsect(lp->lnd_x, lp->lnd_y, §); - mtype = lnd_mobtype(lp); - cp = BestLandPath(buf, §, &d_sect, &dummy, mtype); - if (!cp) { - pr("No owned %s from %s to %s!\n", - mtype == MOB_RAIL ? "railway" : "path", - xyas(lp->lnd_x, lp->lnd_y, player->cnum), - xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); - return 0; - } - pr("Using path '%s'\n", cp); - return cp; -} - int lnd_can_attack(struct lndstr *lp) { diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index 0d8c48ff..cc990f33 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -950,35 +950,6 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget) return 0; /* all attempts failed */ } -char * -shp_path(int together, struct shpstr *shp, char *buf) -{ - coord destx; - coord desty; - struct sctstr d_sect; - char *cp; - - if (!sarg_xy(buf, &destx, &desty)) - return 0; - if (!together) { - mpr(shp->shp_own, - "Cannot go to a destination sector if not all starting in the same sector\n"); - return 0; - } - if (!getsect(destx, desty, &d_sect)) { - mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty); - return 0; - } - - cp = BestShipPath(buf, shp->shp_x, shp->shp_y, - d_sect.sct_x, d_sect.sct_y, player->cnum); - if (!cp || shp->shp_mobil <= 0) { - mpr(shp->shp_own, "Can't get to '%s' right now.\n", - xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); - return 0; - } - return cp; -} /* Fire missiles at a ship which has fired shells */ void diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index e69459c1..3afed19c 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -35,6 +35,7 @@ #include "empobj.h" #include "file.h" +#include "player.h" #include "prototypes.h" #include "unit.h" @@ -125,4 +126,53 @@ unit_put(struct emp_qelem *list, natid actor) } } +char * +unit_path(int together, struct empobj *unit, char *buf) +{ + coord destx; + coord desty; + struct sctstr d_sect, sect; + char *cp; + double dummy; + int mtype; + if (!sarg_xy(buf, &destx, &desty)) + return 0; + if (!together) { + if (unit->ef_type == EF_SHIP) + mpr(unit->own, + "Cannot go to a destination sector if not all starting in the same sector\n"); + else + pr("Cannot go to a destination sector if not all starting in the same sector\n"); + return 0; + } + if (!getsect(destx, desty, &d_sect)) { + if (unit->ef_type == EF_SHIP) + mpr(unit->own, "%d,%d is not a sector\n", destx, desty); + else + pr("%d,%d is not a sector\n", destx, desty); + return 0; + } + if (unit->ef_type == EF_SHIP) { + cp = BestShipPath(buf, unit->x, unit->y, + d_sect.sct_x, d_sect.sct_y, player->cnum); + if (!cp || unit->mobil <= 0) { + mpr(unit->own, "Can't get to '%s' right now.\n", + xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); + return 0; + } + } else { + getsect(unit->x, unit->y, §); + mtype = lnd_mobtype((struct lndstr *)unit); + cp = BestLandPath(buf, §, &d_sect, &dummy, mtype); + if (!cp) { + pr("No owned %s from %s to %s!\n", + mtype == MOB_RAIL ? "railway" : "path", + xyas(unit->x, unit->y, player->cnum), + xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); + return 0; + } + pr("Using path '%s'\n", cp); + } + return cp; +}