(prod_plane): Simplify carrier repair code. Oops on bad carrier.

This commit is contained in:
Markus Armbruster 2006-05-14 18:09:33 +00:00
parent f60efaca4e
commit 917d715c8c

View file

@ -65,7 +65,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
int mil_needed; int mil_needed;
int mvec[I_MAX + 1]; int mvec[I_MAX + 1];
int n, k = 0; int n, k = 0;
struct shpstr *shp; struct shpstr *carrier;
struct sctstr *sp; struct sctstr *sp;
int delta; int delta;
int mult; int mult;
@ -74,7 +74,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
int avail; int avail;
int w_p_eff; int w_p_eff;
int used; int used;
int start_money, onship; int start_money;
for (n = 0; NULL != (pp = getplanep(n)); n++) { for (n = 0; NULL != (pp = getplanep(n)); n++) {
if (pp->pln_own == 0) if (pp->pln_own == 0)
@ -95,23 +95,14 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
continue; continue;
} }
onship = 0; carrier = NULL;
shp = NULL;
if (pp->pln_ship >= 0 && (buildem == 1)) { if (pp->pln_ship >= 0 && (buildem == 1)) {
if (pp->pln_effic >= 80) if (pp->pln_effic >= 80)
continue; continue;
onship = 1; carrier = getshipp(pp->pln_ship);
shp = getshipp(pp->pln_ship); if (CANT_HAPPEN(!carrier || carrier->shp_own != pp->pln_own))
if (shp == 0 || shp->shp_own != pp->pln_own) {
/* nplane is unsigned... */
if (shp->shp_nplane > 0)
shp->shp_nplane--;
makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
pp->pln_x, pp->pln_y);
pp->pln_own = 0;
continue; continue;
} }
}
np = getnatp(pp->pln_own); np = getnatp(pp->pln_own);
pcp = &plchr[(int)pp->pln_type]; pcp = &plchr[(int)pp->pln_type];
sp = getsectp(pp->pln_x, pp->pln_y); sp = getsectp(pp->pln_x, pp->pln_y);
@ -165,10 +156,8 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
else else
avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
if (pp->pln_ship >= 0) { if (carrier)
shp = getshipp(pp->pln_ship); avail += etus * carrier->shp_item[I_MILIT] / 2;
avail += (etus * shp->shp_item[I_MILIT] / 2);
}
w_p_eff = PLN_BLD_WORK(pcp->pl_lcm, pcp->pl_hcm); w_p_eff = PLN_BLD_WORK(pcp->pl_lcm, pcp->pl_hcm);
delta = roundavg((double)avail / w_p_eff); delta = roundavg((double)avail / w_p_eff);
if (delta <= 0) if (delta <= 0)
@ -213,7 +202,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
get_materials(sp, bp, mvec, 1); get_materials(sp, bp, mvec, 1);
if (onship) if (carrier)
build = delta; build = delta;
used = build * w_p_eff; used = build * w_p_eff;
@ -235,7 +224,7 @@ prod_plane(int etus, int natnum, int *bp, int buildem)
if (sp->sct_type != SCT_AIRPT) if (sp->sct_type != SCT_AIRPT)
build /= 3; build /= 3;
if (onship) { if (carrier) {
if ((pp->pln_effic + build) > 80) if ((pp->pln_effic + build) > 80)
build = 80 - pp->pln_effic; build = 80 - pp->pln_effic;
} }