subs: Factor shp_insque() out of shp_sel(), shp_missdef(), ...
... nav_ship(), fltp_to_list(). Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
da400d4fe7
commit
fe42e6e8dd
4 changed files with 23 additions and 27 deletions
|
@ -31,7 +31,7 @@
|
||||||
* Thomas Ruschak, 1992
|
* Thomas Ruschak, 1992
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1998
|
* Steve McClure, 1998
|
||||||
* Markus Armbruster, 2004-2013
|
* Markus Armbruster, 2004-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SHIP_H
|
#ifndef SHIP_H
|
||||||
|
@ -183,6 +183,7 @@ extern double shp_torp_hitchance(struct shpstr *, int);
|
||||||
|
|
||||||
/* src/lib/subs/shpsub.c */
|
/* src/lib/subs/shpsub.c */
|
||||||
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 void shp_nav(struct emp_qelem *, double *, double *, int *, natid);
|
extern void shp_nav(struct emp_qelem *, double *, double *, int *, 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 *);
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1996-2000
|
* Steve McClure, 1996-2000
|
||||||
* Markus Armbruster, 2006-2013
|
* Markus Armbruster, 2006-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -61,8 +61,6 @@ void
|
||||||
shp_sel(struct nstr_item *ni, struct emp_qelem *list)
|
shp_sel(struct nstr_item *ni, struct emp_qelem *list)
|
||||||
{
|
{
|
||||||
struct shpstr ship;
|
struct shpstr ship;
|
||||||
struct mchrstr *mcp;
|
|
||||||
struct ulist *mlp;
|
|
||||||
|
|
||||||
emp_initque(list);
|
emp_initque(list);
|
||||||
while (nxtitem(ni, &ship)) {
|
while (nxtitem(ni, &ship)) {
|
||||||
|
@ -73,7 +71,6 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list)
|
||||||
*/
|
*/
|
||||||
if (!ship.shp_own || ship.shp_own != player->cnum)
|
if (!ship.shp_own || ship.shp_own != player->cnum)
|
||||||
continue;
|
continue;
|
||||||
mcp = &mchr[(int)ship.shp_type];
|
|
||||||
if (opt_MARKET) {
|
if (opt_MARKET) {
|
||||||
if (ontradingblock(EF_SHIP, &ship)) {
|
if (ontradingblock(EF_SHIP, &ship)) {
|
||||||
pr("ship #%d inelligible - it's for sale.\n",
|
pr("ship #%d inelligible - it's for sale.\n",
|
||||||
|
@ -85,14 +82,26 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list)
|
||||||
ship.shp_rflags = 0;
|
ship.shp_rflags = 0;
|
||||||
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
|
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
|
||||||
putship(ship.shp_uid, &ship);
|
putship(ship.shp_uid, &ship);
|
||||||
mlp = malloc(sizeof(struct ulist));
|
shp_insque(&ship, list);
|
||||||
mlp->chrp = (struct empobj_chr *)mcp;
|
|
||||||
mlp->unit.ship = ship;
|
|
||||||
mlp->mobil = ship.shp_mobil;
|
|
||||||
emp_insque(&mlp->queue, list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append SP to LIST.
|
||||||
|
* Return the new list link.
|
||||||
|
*/
|
||||||
|
struct ulist *
|
||||||
|
shp_insque(struct shpstr *sp, struct emp_qelem *list)
|
||||||
|
{
|
||||||
|
struct ulist *mlp = malloc(sizeof(struct ulist));
|
||||||
|
|
||||||
|
mlp->chrp = (struct empobj_chr *)&mchr[sp->shp_type];
|
||||||
|
mlp->unit.ship = *sp;
|
||||||
|
mlp->mobil = sp->shp_mobil;
|
||||||
|
emp_insque(&mlp->queue, list);
|
||||||
|
return mlp;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function assumes that the list was created by shp_sel */
|
/* This function assumes that the list was created by shp_sel */
|
||||||
void
|
void
|
||||||
shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
|
shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
|
||||||
|
@ -912,12 +921,7 @@ shp_missdef(struct shpstr *sp, natid victim)
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
emp_initque(&list);
|
emp_initque(&list);
|
||||||
|
mlp = shp_insque(sp, &list);
|
||||||
mlp = malloc(sizeof(struct ulist));
|
|
||||||
mlp->chrp = (struct empobj_chr *)&mchr[(int)sp->shp_type];
|
|
||||||
mlp->unit.ship = *sp;
|
|
||||||
mlp->mobil = sp->shp_mobil;
|
|
||||||
emp_insque(&mlp->queue, &list);
|
|
||||||
sprintf(buf, "%s", prship(&mlp->unit.ship));
|
sprintf(buf, "%s", prship(&mlp->unit.ship));
|
||||||
|
|
||||||
eff = sp->shp_effic;
|
eff = sp->shp_effic;
|
||||||
|
|
|
@ -256,12 +256,8 @@ nav_ship(struct shpstr *sp)
|
||||||
|
|
||||||
/* Make a list of one ships so we can use the navi.c code */
|
/* Make a list of one ships so we can use the navi.c code */
|
||||||
emp_initque(&ship_list);
|
emp_initque(&ship_list);
|
||||||
mlp = malloc(sizeof(struct ulist));
|
mlp = shp_insque(sp, &ship_list);
|
||||||
mlp->chrp = (struct empobj_chr *)(mchr + sp->shp_type);
|
|
||||||
mlp->unit.ship = *sp;
|
|
||||||
ef_mark_fresh(EF_SHIP, &mlp->unit.ship);
|
ef_mark_fresh(EF_SHIP, &mlp->unit.ship);
|
||||||
mlp->mobil = sp->shp_mobil;
|
|
||||||
emp_insque(&mlp->queue, &ship_list);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ((sp->shp_mobil > 0) && (!(sp->shp_autonav & AN_LOADING)) &&
|
if ((sp->shp_mobil > 0) && (!(sp->shp_autonav & AN_LOADING)) &&
|
||||||
|
|
|
@ -337,16 +337,11 @@ fltp_to_list(struct fltheadstr *fltp, struct emp_qelem *list)
|
||||||
{
|
{
|
||||||
struct fltelemstr *fe;
|
struct fltelemstr *fe;
|
||||||
struct ulist *mlp;
|
struct ulist *mlp;
|
||||||
struct shpstr *sp;
|
|
||||||
|
|
||||||
emp_initque(list);
|
emp_initque(list);
|
||||||
for (fe = fltp->head; fe; fe = fe->next) {
|
for (fe = fltp->head; fe; fe = fe->next) {
|
||||||
mlp = malloc(sizeof(struct ulist));
|
mlp = shp_insque(getshipp(fe->num), list);
|
||||||
sp = getshipp(fe->num);
|
|
||||||
mlp->chrp = (struct empobj_chr *)(mchr + sp->shp_type);
|
|
||||||
mlp->unit.ship = *sp;
|
|
||||||
ef_mark_fresh(EF_SHIP, &mlp->unit.ship);
|
ef_mark_fresh(EF_SHIP, &mlp->unit.ship);
|
||||||
mlp->mobil = fe->mobil;
|
mlp->mobil = fe->mobil;
|
||||||
emp_insque(&mlp->queue, list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue