Пример #1
0
/* Set the values tracked in BP for sector SP to the values in SP.  */
void
bp_set_from_sect(struct bp *bp, struct sctstr *sp)
{
    bp_put_items(bp, sp, sp->sct_item);
    bp_put_avail(bp, sp, sp->sct_avail);
}
Пример #2
0
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;
}
Пример #3
0
/*
 * Produce for a specific nation
 */
void
produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
{
    struct sctstr *sp;
    struct natstr *np;
    short buf[I_MAX + 1];
    short *vec;
    int work, cost, ecost, pcost, sctwork;
    int n, desig, neweff, amount;

    for (n = 0; NULL != (sp = getsectid(n)); n++) {
	if (sp->sct_type == SCT_WATER)
	    continue;
	if (sp->sct_own != natnum)
	    continue;
	if (sp->sct_updated != 0)
	    continue;

	np = getnatp(natnum);

	if (player->simulation) {
	    /* work on a copy, which will be discarded */
	    memcpy(buf, sp->sct_item, sizeof(buf));
	    vec = buf;
	} else
	    vec = sp->sct_item;

	/* If everybody is dead, the sector reverts to unowned.
	 * This is also checked at the end of the production in
	 * they all starved or were plagued off.
	 */
	if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 &&
	    !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) {
	    if (!player->simulation) {
		makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
		sp->sct_own = 0;
		sp->sct_oldown = 0;
	    }
	    continue;
	}

	sp->sct_updated = 1;
	work = 0;

	sctwork = do_feed(sp, np, vec, &work, etu);
	bp_put_items(bp, sp, vec);

	if (sp->sct_off || np->nat_money < 0)
	    continue;

	neweff = sp->sct_effic;
	amount = 0;
	pcost = cost = ecost = 0;

	desig = sp->sct_type;

	if (dchr[desig].d_maint) {
	    cost = etu * dchr[desig].d_maint;
	    p_sect[SCT_MAINT][0]++;
	    p_sect[SCT_MAINT][1] += cost;
	    if (!player->simulation)
		np->nat_money -= cost;
	}

	if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
	    np->nat_money >= 0) {
	    neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
				  &cost);
	    bp_put_items(bp, sp, vec);
	    p_sect[SCT_EFFIC][0]++;
	    p_sect[SCT_EFFIC][1] += cost;
	    if (!player->simulation) {
		np->nat_money -= cost;
		sp->sct_type = desig;
		sp->sct_effic = neweff;
	    }
	}

	if (desig == SCT_ENLIST && neweff >= 60 &&
	    sp->sct_own == sp->sct_oldown) {
	    p_sect[desig][0] += enlist(vec, etu, &ecost);
	    p_sect[desig][1] += ecost;
	    if (!player->simulation)
		np->nat_money -= ecost;
	    bp_put_items(bp, sp, vec);
	}

	/*
	 * now do the production (if sector effic >= 60%)
	 */

	if (neweff >= 60) {
	    if (np->nat_money >= 0 && dchr[desig].d_prd >= 0)
		work -= produce(np, sp, vec, work, desig, neweff,
				&pcost, &amount);
	    bp_put_items(bp, sp, vec);
	}

	bp_put_avail(bp, sp, work);
	p_sect[desig][0] += amount;
	p_sect[desig][1] += pcost;
	if (!player->simulation) {
	    sp->sct_avail = work;
	    np->nat_money -= pcost;
	}
    }
}