*
* Known contributors to this file:
* Ron Koenderink, 2006
- * Markus Armbruster, 2006-2011
+ * Markus Armbruster, 2006-2014
*/
#ifndef EMPOBJ_H
struct trdstr trade;
};
-struct empobj_chr;
-
#define get_empobj(type, n, p) ef_read((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)))
struct emp_qelem queue; /* list of units */
double mobil; /* moving: how much the unit has left
ground combat: how much to charge */
- struct empobj_chr *chrp; /* pointer to characteristics unit */
union empobj_storage unit; /* unit */
/* Rest used only by ground combat (attsub.c) */
coord x, y; /* x,y it came from */
llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *a_spyp)
*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;
if (def->type == EF_SHIP && ++count >= maxland)
break;
* Set mobcost to basic assault cost, moblim to maximum
* 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;
moblim = 0;
} else {
mobcost = MAX(mobcost, mob - moblim);
break;
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;
else
mobcost = 40;
taken = llp->unit.land.lnd_item[I_MILIT];
/* 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;
else {
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;
lnd_submil(&llp->unit.land, cas);
}
/* nowhere to go.. take more casualties */
llp->unit.land.lnd_effic -= 10;
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) {
lnd_print(llp->unit.land.lnd_own, llp,
"has nowhere to retreat, and dies!");
{
struct ulist *mlp = malloc(sizeof(struct ulist));
- mlp->chrp = (struct empobj_chr *)&lchr[lp->lnd_type];
mlp->unit.land = *lp;
mlp->mobil = lp->lnd_mobil;
emp_insque(&mlp->queue, list);
for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back;
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)
mpr(actor, "%s is not an engineer!\n",
prland(&llp->unit.land));
putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (!(mines = sect.sct_mines))
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];
sshells = sect.sct_item[I_SHELL];
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");
mines--;
if (lshells < max)
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
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 0;
{
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);
for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back;
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)
mpr(actor, "%s doesn't have minesweeping capability!\n",
prship(&mlp->unit.ship));
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
if (!(mines = sect.sct_mines))
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];
for (m = 0; mines > 0 && m < 5; m++) {
if (chance(0.66)) {
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
++count;
}
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
shp_damage_one(mlp, dam);
}
if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
continue;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
return 1;
}
mlp = (struct ulist *)qp;
if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue;
- if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
+ if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
continue;
- if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
- !((struct mchrstr *)mlp->chrp)->m_nchoppers &&
- ((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
- !((struct mchrstr *)mlp->chrp)->m_nplanes &&
- !((struct mchrstr *)mlp->chrp)->m_nland)
+ if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
+ !mchr[mlp->unit.ship.shp_type].m_nchoppers &&
+ mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
+ !mchr[mlp->unit.ship.shp_type].m_nplanes &&
+ !mchr[mlp->unit.ship.shp_type].m_nland)
continue;
if (!mvs) {
mvs = mlp;
continue;
}
- if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
- ((struct mchrstr *)mvs->chrp)->m_cost * mvs->unit.ship.shp_effic)
+ if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
+ mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
mvs = mlp;
}
return mvs;
next = qp->q_back;
mlp = (struct ulist *)qp;
if (wantflags &&
- (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
+ (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
continue;
if (nowantflags &&
- ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
+ mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
continue;
hard = shp_hardtarget(&mlp->unit.ship);
if (hard < easiest)
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
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;
if (natp->nat_flags & NF_COASTWATCH)
wu(0, sectp->sct_own,
rad_map_set(mlp->unit.ship.shp_own,
mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
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))
return stopping;
continue;
getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
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);
- 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("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),