static void planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus) { int build; int mvec[I_MAX + 1]; struct shpstr *carrier; struct plchrstr *pcp = &plchr[(int)pp->pln_type]; struct sctstr *sp = getsectp(pp->pln_x, pp->pln_y); int delta; int mult; int avail; int w_p_eff; int used; carrier = NULL; if (pp->pln_ship >= 0) { if (pp->pln_effic >= 80) return; carrier = getshipp(pp->pln_ship); if (CANT_HAPPEN(!carrier)) return; if (carrier->shp_off) return; if (relations_with(carrier->shp_own, pp->pln_own) != ALLIED) return; } else { if (relations_with(sp->sct_own, pp->pln_own) != ALLIED) return; } if (sp->sct_off) return; mult = 1; if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85) mult = 2; if (pp->pln_effic == 100) return; if (!player->simulation) avail = sp->sct_avail * 100; else avail = bp_get_avail(bp, sp) * 100; if (carrier) avail += etus * carrier->shp_item[I_MILIT] / 2; w_p_eff = PLN_BLD_WORK(pcp->pl_lcm, pcp->pl_hcm); delta = roundavg((double)avail / w_p_eff); if (delta <= 0) return; if (delta > (int)((float)etus * plane_grow_scale)) delta = (int)((float)etus * plane_grow_scale); if (delta > 100 - pp->pln_effic) delta = 100 - pp->pln_effic; memset(mvec, 0, sizeof(mvec)); mvec[I_MILIT] = pcp->pl_crew; mvec[I_LCM] = pcp->pl_lcm; mvec[I_HCM] = pcp->pl_hcm; build = get_materials(sp, bp, mvec, delta); if (carrier) build = delta; used = build * w_p_eff; /* * I didn't use roundavg here, because I want to * penalize the player with a large number of planes. */ if (!player->simulation) avail = (sp->sct_avail * 100 - used) / 100; else avail = (bp_get_avail(bp, sp) * 100 - used) / 100; if (avail < 0) avail = 0; if (!player->simulation) sp->sct_avail = avail; else bp_put_avail(bp, sp, avail); if (sp->sct_type != SCT_AIRPT) build /= 3; if (carrier) { if ((pp->pln_effic + build) > 80) build = 80 - pp->pln_effic; } np->nat_money -= mult * build * pcp->pl_cost / 100.0; if (!player->simulation) pp->pln_effic += (signed char)build; }
static int pupgr(void) { struct sctstr sect; struct natstr *natp; struct nstr_item ni; struct plnstr plane; struct plchrstr *pp; int n; int tlev; int avail, cost; int cash; if (!snxtitem(&ni, EF_PLANE, player->argp[2], NULL)) return RET_SYN; natp = getnatp(player->cnum); cash = natp->nat_money; tlev = (int)natp->nat_level[NAT_TLEV]; n = 0; while (nxtitem(&ni, &plane)) { if (plane.pln_own == 0) continue; getsect(plane.pln_x, plane.pln_y, §); if (sect.sct_own != player->cnum) continue; if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60) continue; if (relations_with(plane.pln_own, sect.sct_own) < FRIENDLY) { pr("You are not on friendly terms with the owner of plane %d!\n", plane.pln_uid); continue; } if (pln_is_in_orbit(&plane)) { pr("Plane %s is in orbit!\n", prplane(&plane)); continue; } if (plane.pln_flags & PLN_LAUNCHED) continue; n++; pp = &plchr[(int)plane.pln_type]; avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100; if (sect.sct_avail < avail) { pr("Not enough available work in %s to upgrade a %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name); pr(" (%d available work required)\n", avail); continue; } if (plane.pln_effic < 60) { pr("%s is too damaged to upgrade!\n", prplane(&plane)); continue; } if (plane.pln_tech >= tlev) { pr("%s tech: %d, yours is only %d\n", prplane(&plane), plane.pln_tech, tlev); continue; } cost = pp->pl_cost * UPGR_COST / 100; if (cost + player->dolcost > cash) { pr("You don't have enough money to upgrade %s!\n", prplane(&plane)); continue; } sect.sct_avail -= avail; plane.pln_effic -= UPGR_EFF; pln_set_tech(&plane, tlev); plane.pln_harden = 0; plane.pln_mission = 0; putplane(plane.pln_uid, &plane); putsect(§); player->dolcost += cost; pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane), plane.pln_tech, cost); if (plane.pln_own != player->cnum) wu(0, plane.pln_own, "%s upgraded by %s to tech %d, at a cost of %d\n", prplane(&plane), cname(player->cnum), plane.pln_tech, cost); } if (n == 0) { pr("No planes.\n"); return RET_SYN; } return RET_OK; }