unit: Drop ulist member chrp
Commit cd8d742
mechanically combined struct mlist's mcp and struct
llist's llp into struct ulist's chrp, adding type casts to every use.
Not necessary, simply use mchr[] and lchr[] directly.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
eb903207a4
commit
1702349e3d
6 changed files with 33 additions and 38 deletions
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ron Koenderink, 2006
|
* Ron Koenderink, 2006
|
||||||
* Markus Armbruster, 2006-2011
|
* Markus Armbruster, 2006-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EMPOBJ_H
|
#ifndef EMPOBJ_H
|
||||||
|
@ -90,8 +90,6 @@ union empobj_storage {
|
||||||
struct trdstr trade;
|
struct trdstr trade;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct empobj_chr;
|
|
||||||
|
|
||||||
#define get_empobj(type, n, p) ef_read((type), (n), (p))
|
#define get_empobj(type, n, p) ef_read((type), (n), (p))
|
||||||
#define put_empobj(type, n, p) ef_write((type), (n), (p))
|
#define put_empobj(type, n, p) ef_write((type), (n), (p))
|
||||||
#define get_empobjp(type, n) ((struct empobj *)ef_ptr((type), (n)))
|
#define get_empobjp(type, n) ((struct empobj *)ef_ptr((type), (n)))
|
||||||
|
|
|
@ -40,7 +40,6 @@ struct ulist {
|
||||||
struct emp_qelem queue; /* list of units */
|
struct emp_qelem queue; /* list of units */
|
||||||
double mobil; /* moving: how much the unit has left
|
double mobil; /* moving: how much the unit has left
|
||||||
ground combat: how much to charge */
|
ground combat: how much to charge */
|
||||||
struct empobj_chr *chrp; /* pointer to characteristics unit */
|
|
||||||
union empobj_storage unit; /* unit */
|
union empobj_storage unit; /* unit */
|
||||||
/* Rest used only by ground combat (attsub.c) */
|
/* Rest used only by ground combat (attsub.c) */
|
||||||
coord x, y; /* x,y it came from */
|
coord x, y; /* x,y it came from */
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
|
||||||
llp->eff = llp->unit.land.lnd_effic;
|
llp->eff = llp->unit.land.lnd_effic;
|
||||||
if (lnd_spyval(&land) > *a_spyp)
|
if (lnd_spyval(&land) > *a_spyp)
|
||||||
*a_spyp = lnd_spyval(&land);
|
*a_spyp = lnd_spyval(&land);
|
||||||
if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
|
if (lchr[land.lnd_type].l_flags & L_ENGINEER)
|
||||||
++*a_engineerp;
|
++*a_engineerp;
|
||||||
if (def->type == EF_SHIP && ++count >= maxland)
|
if (def->type == EF_SHIP && ++count >= maxland)
|
||||||
break;
|
break;
|
||||||
|
@ -2488,7 +2488,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
|
||||||
* Set mobcost to basic assault cost, moblim to maximum
|
* Set mobcost to basic assault cost, moblim to maximum
|
||||||
* mobility to keep when assaulting from non-landing ship
|
* mobility to keep when assaulting from non-landing ship
|
||||||
*/
|
*/
|
||||||
if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) {
|
if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE) {
|
||||||
mobcost = gain / 2.0;
|
mobcost = gain / 2.0;
|
||||||
moblim = 0;
|
moblim = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2500,7 +2500,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
|
||||||
mobcost = MAX(mobcost, mob - moblim);
|
mobcost = MAX(mobcost, mob - moblim);
|
||||||
break;
|
break;
|
||||||
case A_BOARD:
|
case A_BOARD:
|
||||||
if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
|
if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE)
|
||||||
mobcost = 10;
|
mobcost = 10;
|
||||||
else
|
else
|
||||||
mobcost = 40;
|
mobcost = 40;
|
||||||
|
|
|
@ -167,11 +167,11 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
|
||||||
|
|
||||||
taken = llp->unit.land.lnd_item[I_MILIT];
|
taken = llp->unit.land.lnd_item[I_MILIT];
|
||||||
/* Spies always die */
|
/* Spies always die */
|
||||||
if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
|
if (lchr[llp->unit.land.lnd_type].l_flags & L_SPY)
|
||||||
llp->unit.land.lnd_effic = 0;
|
llp->unit.land.lnd_effic = 0;
|
||||||
else {
|
else {
|
||||||
eff_eq = ldround(cas * 100.0 /
|
eff_eq = ldround(cas * 100.0 /
|
||||||
((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
|
lchr[llp->unit.land.lnd_type].l_item[I_MILIT], 1);
|
||||||
llp->unit.land.lnd_effic -= eff_eq;
|
llp->unit.land.lnd_effic -= eff_eq;
|
||||||
lnd_submil(&llp->unit.land, cas);
|
lnd_submil(&llp->unit.land, cas);
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
|
||||||
/* nowhere to go.. take more casualties */
|
/* nowhere to go.. take more casualties */
|
||||||
llp->unit.land.lnd_effic -= 10;
|
llp->unit.land.lnd_effic -= 10;
|
||||||
lnd_submil(&llp->unit.land,
|
lnd_submil(&llp->unit.land,
|
||||||
((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
|
lchr[llp->unit.land.lnd_type].l_item[I_MILIT] / 10);
|
||||||
if (llp->unit.land.lnd_effic < LAND_MINEFF) {
|
if (llp->unit.land.lnd_effic < LAND_MINEFF) {
|
||||||
lnd_print(llp->unit.land.lnd_own, llp,
|
lnd_print(llp->unit.land.lnd_own, llp,
|
||||||
"has nowhere to retreat, and dies!");
|
"has nowhere to retreat, and dies!");
|
||||||
|
@ -444,7 +444,6 @@ lnd_insque(struct lndstr *lp, struct emp_qelem *list)
|
||||||
{
|
{
|
||||||
struct ulist *mlp = malloc(sizeof(struct ulist));
|
struct ulist *mlp = malloc(sizeof(struct ulist));
|
||||||
|
|
||||||
mlp->chrp = (struct empobj_chr *)&lchr[lp->lnd_type];
|
|
||||||
mlp->unit.land = *lp;
|
mlp->unit.land = *lp;
|
||||||
mlp->mobil = lp->lnd_mobil;
|
mlp->mobil = lp->lnd_mobil;
|
||||||
emp_insque(&mlp->queue, list);
|
emp_insque(&mlp->queue, list);
|
||||||
|
@ -595,7 +594,7 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
|
||||||
for (qp = land_list->q_back; qp != land_list; qp = next) {
|
for (qp = land_list->q_back; qp != land_list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
|
if (!(lchr[llp->unit.land.lnd_type].l_flags & L_ENGINEER)) {
|
||||||
if (explicit)
|
if (explicit)
|
||||||
mpr(actor, "%s is not an engineer!\n",
|
mpr(actor, "%s is not an engineer!\n",
|
||||||
prland(&llp->unit.land));
|
prland(&llp->unit.land));
|
||||||
|
@ -623,11 +622,11 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
|
||||||
putland(llp->unit.land.lnd_uid, &llp->unit.land);
|
putland(llp->unit.land.lnd_uid, &llp->unit.land);
|
||||||
if (!(mines = sect.sct_mines))
|
if (!(mines = sect.sct_mines))
|
||||||
continue;
|
continue;
|
||||||
max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
|
max = lchr[llp->unit.land.lnd_type].l_item[I_SHELL];
|
||||||
lshells = llp->unit.land.lnd_item[I_SHELL];
|
lshells = llp->unit.land.lnd_item[I_SHELL];
|
||||||
sshells = sect.sct_item[I_SHELL];
|
sshells = sect.sct_item[I_SHELL];
|
||||||
for (m = 0; mines > 0 && m < max * 2; m++) {
|
for (m = 0; mines > 0 && m < max * 2; m++) {
|
||||||
if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
|
if (chance(0.5 * lchr[llp->unit.land.lnd_type].l_att)) {
|
||||||
mpr(actor, "Sweep...\n");
|
mpr(actor, "Sweep...\n");
|
||||||
mines--;
|
mines--;
|
||||||
if (lshells < max)
|
if (lshells < max)
|
||||||
|
@ -654,7 +653,7 @@ contains_engineer(struct emp_qelem *list)
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
|
if (lchr[llp->unit.land.lnd_type].l_flags & L_ENGINEER)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -96,7 +96,6 @@ shp_insque(struct shpstr *sp, struct emp_qelem *list)
|
||||||
{
|
{
|
||||||
struct ulist *mlp = malloc(sizeof(struct ulist));
|
struct ulist *mlp = malloc(sizeof(struct ulist));
|
||||||
|
|
||||||
mlp->chrp = (struct empobj_chr *)&mchr[sp->shp_type];
|
|
||||||
mlp->unit.ship = *sp;
|
mlp->unit.ship = *sp;
|
||||||
mlp->mobil = sp->shp_mobil;
|
mlp->mobil = sp->shp_mobil;
|
||||||
emp_insque(&mlp->queue, list);
|
emp_insque(&mlp->queue, list);
|
||||||
|
@ -207,7 +206,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
|
||||||
for (qp = ship_list->q_back; qp != ship_list; qp = next) {
|
for (qp = ship_list->q_back; qp != ship_list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
if (!(((struct mchrstr *)mlp->chrp)->m_flags & M_SWEEP)) {
|
if (!(mchr[mlp->unit.ship.shp_type].m_flags & M_SWEEP)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
mpr(actor, "%s doesn't have minesweeping capability!\n",
|
mpr(actor, "%s doesn't have minesweeping capability!\n",
|
||||||
prship(&mlp->unit.ship));
|
prship(&mlp->unit.ship));
|
||||||
|
@ -233,7 +232,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
|
||||||
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
|
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
|
||||||
if (!(mines = sect.sct_mines))
|
if (!(mines = sect.sct_mines))
|
||||||
continue;
|
continue;
|
||||||
max = ((struct mchrstr *)mlp->chrp)->m_item[I_SHELL];
|
max = mchr[mlp->unit.ship.shp_type].m_item[I_SHELL];
|
||||||
shells = mlp->unit.ship.shp_item[I_SHELL];
|
shells = mlp->unit.ship.shp_item[I_SHELL];
|
||||||
for (m = 0; mines > 0 && m < 5; m++) {
|
for (m = 0; mines > 0 && m < 5; m++) {
|
||||||
if (chance(0.66)) {
|
if (chance(0.66)) {
|
||||||
|
@ -371,10 +370,10 @@ shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
|
||||||
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
||||||
continue;
|
continue;
|
||||||
if (wantflags &&
|
if (wantflags &&
|
||||||
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
|
(mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
|
||||||
continue;
|
continue;
|
||||||
if (nowantflags &&
|
if (nowantflags &&
|
||||||
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
|
mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
|
||||||
continue;
|
continue;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
@ -414,10 +413,10 @@ shp_damage(struct emp_qelem *list, int totdam, int wantflags,
|
||||||
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
||||||
continue;
|
continue;
|
||||||
if (wantflags &&
|
if (wantflags &&
|
||||||
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
|
(mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
|
||||||
continue;
|
continue;
|
||||||
if (nowantflags &&
|
if (nowantflags &&
|
||||||
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
|
mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
|
||||||
continue;
|
continue;
|
||||||
shp_damage_one(mlp, dam);
|
shp_damage_one(mlp, dam);
|
||||||
}
|
}
|
||||||
|
@ -439,10 +438,10 @@ shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
|
||||||
if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
|
if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
|
||||||
continue;
|
continue;
|
||||||
if (wantflags &&
|
if (wantflags &&
|
||||||
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
|
(mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
|
||||||
continue;
|
continue;
|
||||||
if (nowantflags &&
|
if (nowantflags &&
|
||||||
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
|
mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
|
||||||
continue;
|
continue;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -462,20 +461,20 @@ most_valuable_ship(struct emp_qelem *list, coord x, coord y)
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
|
||||||
continue;
|
continue;
|
||||||
if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
|
if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
|
||||||
continue;
|
continue;
|
||||||
if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
|
if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
|
||||||
!((struct mchrstr *)mlp->chrp)->m_nchoppers &&
|
!mchr[mlp->unit.ship.shp_type].m_nchoppers &&
|
||||||
((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
|
mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
|
||||||
!((struct mchrstr *)mlp->chrp)->m_nplanes &&
|
!mchr[mlp->unit.ship.shp_type].m_nplanes &&
|
||||||
!((struct mchrstr *)mlp->chrp)->m_nland)
|
!mchr[mlp->unit.ship.shp_type].m_nland)
|
||||||
continue;
|
continue;
|
||||||
if (!mvs) {
|
if (!mvs) {
|
||||||
mvs = mlp;
|
mvs = mlp;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
|
if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
|
||||||
((struct mchrstr *)mvs->chrp)->m_cost * mvs->unit.ship.shp_effic)
|
mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
|
||||||
mvs = mlp;
|
mvs = mlp;
|
||||||
}
|
}
|
||||||
return mvs;
|
return mvs;
|
||||||
|
@ -495,10 +494,10 @@ shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
if (wantflags &&
|
if (wantflags &&
|
||||||
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
|
(mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
|
||||||
continue;
|
continue;
|
||||||
if (nowantflags &&
|
if (nowantflags &&
|
||||||
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
|
mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
|
||||||
continue;
|
continue;
|
||||||
hard = shp_hardtarget(&mlp->unit.ship);
|
hard = shp_hardtarget(&mlp->unit.ship);
|
||||||
if (hard < easiest)
|
if (hard < easiest)
|
||||||
|
@ -584,7 +583,7 @@ notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
|
if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
|
||||||
continue;
|
continue;
|
||||||
if (natp->nat_flags & NF_COASTWATCH)
|
if (natp->nat_flags & NF_COASTWATCH)
|
||||||
wu(0, sectp->sct_own,
|
wu(0, sectp->sct_own,
|
||||||
|
@ -840,7 +839,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor)
|
||||||
rad_map_set(mlp->unit.ship.shp_own,
|
rad_map_set(mlp->unit.ship.shp_own,
|
||||||
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
|
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
|
||||||
mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
|
mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
|
||||||
((struct mchrstr *)mlp->chrp)->m_vrnge);
|
mchr[mlp->unit.ship.shp_type].m_vrnge);
|
||||||
}
|
}
|
||||||
if (QEMPTY(list))
|
if (QEMPTY(list))
|
||||||
return stopping;
|
return stopping;
|
||||||
|
|
|
@ -188,9 +188,9 @@ unit_view(struct emp_qelem *list)
|
||||||
continue;
|
continue;
|
||||||
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
|
||||||
if (ulp->unit.gen.ef_type == EF_SHIP) {
|
if (ulp->unit.gen.ef_type == EF_SHIP) {
|
||||||
if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
|
if (mchr[ulp->unit.ship.shp_type].m_flags & M_FOOD)
|
||||||
pr("[fert:%d] ", sect.sct_fertil);
|
pr("[fert:%d] ", sect.sct_fertil);
|
||||||
if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
|
if (mchr[ulp->unit.ship.shp_type].m_flags & M_OIL)
|
||||||
pr("[oil:%d] ", sect.sct_oil);
|
pr("[oil:%d] ", sect.sct_oil);
|
||||||
}
|
}
|
||||||
pr("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),
|
pr("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue