update: Reorder ship, plane, land repair code for consistency

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-05 15:00:42 +02:00
parent 6c4874e4d2
commit a5d90c0184
3 changed files with 31 additions and 36 deletions

View file

@ -194,28 +194,27 @@ upd_land(struct lndstr *lp, int etus,
static void static void
landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus) landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
{ {
struct lchrstr *lp = &lchr[(int)land->lnd_type];
int delta; int delta;
struct sctstr *sp; struct sctstr *sp;
struct lchrstr *lp;
int build; int build;
int avail; int avail;
int mult; int mult;
lp = &lchr[(int)land->lnd_type]; if (land->lnd_effic == 100)
return;
sp = getsectp(land->lnd_x, land->lnd_y); sp = getsectp(land->lnd_x, land->lnd_y);
if (sp->sct_off) if (sp->sct_off)
return; return;
if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
return;
mult = 1; mult = 1;
if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85) if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
mult = 2; mult = 2;
if (land->lnd_effic == 100) {
/* land is ok; no repairs needed */
return;
}
if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
return;
if (!player->simulation) if (!player->simulation)
avail = sp->sct_avail * 100; avail = sp->sct_avail * 100;
else else

View file

@ -123,15 +123,22 @@ upd_plane(struct plnstr *pp, int etus,
static void static void
planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus) planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
{ {
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
int build; int build;
struct shpstr *carrier; struct shpstr *carrier;
struct plchrstr *pcp = &plchr[(int)pp->pln_type]; struct sctstr *sp;
struct sctstr *sp = getsectp(pp->pln_x, pp->pln_y);
int delta; int delta;
int mult; int mult;
int avail; int avail;
int used; int used;
if (pp->pln_effic == 100)
return;
sp = getsectp(pp->pln_x, pp->pln_y);
if (sp->sct_off)
return;
carrier = NULL; carrier = NULL;
if (pp->pln_ship >= 0) { if (pp->pln_ship >= 0) {
if (pp->pln_effic >= 80) if (pp->pln_effic >= 80)
@ -148,15 +155,10 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
return; return;
} }
if (sp->sct_off)
return;
mult = 1; mult = 1;
if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85) if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85)
mult = 2; mult = 2;
if (pp->pln_effic == 100)
return;
if (!player->simulation) if (!player->simulation)
avail = sp->sct_avail * 100; avail = sp->sct_avail * 100;
else else

View file

@ -241,21 +241,29 @@ upd_ship(struct shpstr *sp, int etus,
static void static void
shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus) shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
{ {
struct mchrstr *mp = &mchr[(int)ship->shp_type];
int delta; int delta;
struct sctstr *sp; struct sctstr *sp;
struct mchrstr *mp;
int build; int build;
int wf; int wf;
int avail; int avail;
int mult; int mult;
mp = &mchr[(int)ship->shp_type]; if (ship->shp_effic == 100)
return;
sp = getsectp(ship->shp_x, ship->shp_y); sp = getsectp(ship->shp_x, ship->shp_y);
if ((sp->sct_off) && (sp->sct_own == ship->shp_own))
return;
if (sp->sct_own != 0 if (sp->sct_own != 0
&& relations_with(sp->sct_own, ship->shp_own) < FRIENDLY) && relations_with(sp->sct_own, ship->shp_own) < FRIENDLY)
return; return;
mult = 1;
if (np->nat_level[NAT_TLEV] < ship->shp_tech * 0.85)
mult = 2;
/* only military can work on a military boat */ /* only military can work on a military boat */
if (mp->m_glim != 0) if (mp->m_glim != 0)
wf = etus * ship->shp_item[I_MILIT] / 2; wf = etus * ship->shp_item[I_MILIT] / 2;
@ -265,24 +273,10 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
if (sp->sct_type != SCT_HARBR) { if (sp->sct_type != SCT_HARBR) {
wf /= 3; wf /= 3;
avail = wf; avail = wf;
} else { } else if (!player->simulation)
if (!player->simulation) avail = wf + sp->sct_avail * 100;
avail = wf + sp->sct_avail * 100; else
else avail = wf + bp_get_avail(bp, sp) * 100;
avail = wf + bp_get_avail(bp, sp) * 100;
}
if ((sp->sct_off) && (sp->sct_own == ship->shp_own))
return;
mult = 1;
if (np->nat_level[NAT_TLEV] < ship->shp_tech * 0.85)
mult = 2;
if (ship->shp_effic == 100) {
/* ship is ok; no repairs needed */
return;
}
delta = roundavg((double)avail / mp->m_bwork); delta = roundavg((double)avail / mp->m_bwork);
if (delta <= 0) if (delta <= 0)