Exemplo n.º 1
0
/*
 * Record item @id of @type changed owner from @exown to @own at @x,@y.
 */
void
lost_and_found(int type, natid exown, natid own, int id, coord x, coord y)
{
    if (exown == own)
        return;
    if (exown)
        makelost(type, exown, id, x, y);
    if (own)
        makenotlost(type, own, id, x, y);
}
Exemplo n.º 2
0
int
prod_plane(int etus, int natnum, struct bp *bp, int buildem)
		 /* Build = 1, maintain =0 */
{
    struct plnstr *pp;
    struct natstr *np;
    int n, k = 0;
    int start_money;

    for (n = 0; NULL != (pp = getplanep(n)); n++) {
	if (pp->pln_own == 0)
	    continue;
	if (pp->pln_own != natnum)
	    continue;
	if (pp->pln_effic < PLANE_MINEFF) {
	    makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
		     pp->pln_x, pp->pln_y);
	    pp->pln_own = 0;
	    continue;
	}

	if (pln_is_in_orbit(pp)) {
	    if (!player->simulation && buildem == 0
		&& !(pp->pln_flags & PLN_SYNCHRONOUS))
		move_sat(pp);
	    continue;
	}

	np = getnatp(pp->pln_own);
	start_money = np->nat_money;
	upd_plane(pp, etus, np, bp, buildem);
	air_money[pp->pln_own] += np->nat_money - start_money;
	if (buildem == 0 || np->nat_money != start_money)
	    k++;
	if (player->simulation)
	    np->nat_money = start_money;
    }

    return k;
}
Exemplo n.º 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;
	}
    }
}
Exemplo n.º 4
0
void
do_plague(struct sctstr *sp, struct natstr *np, int etu)
{
    int pstage, ptime;
    int n;

    if (opt_NO_PLAGUE)		/* no plague nothing to do */
	return;

    pstage = sp->sct_pstage;
    ptime = sp->sct_ptime;

    if (pstage == PLG_HEALTHY) {
	pstage = infect_people(np, sp);
	ptime = 0;
    } else {
	n = plague_people(np, sp->sct_item, &pstage, &ptime, etu);
	switch (n) {
	case PLG_DYING:
	    wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n",
	       ownxy(sp));
	    nreport(sp->sct_own, N_DIE_PLAGUE, 0, 1);
	    break;
	case PLG_INFECT:
	    wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
	    break;
	case PLG_INCUBATE:
	    /* Are we still incubating? */
	    if (n == pstage) {
		/* Yes. Will it turn "infectious" next time? */
		if (ptime <= etu) {
		    /* Yes.  Report an outbreak. */
		    wu(0, sp->sct_own,
		       "Outbreak of PLAGUE in %s!\n", ownxy(sp));
		    nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
		}
	    } else {
		/* It has already moved on to "infectious" */
		wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp));
	    }
	    break;
	case PLG_EXPOSED:
	    /* Has the plague moved to "incubation" yet? */
	    if (n != pstage) {
		/* Yes. Will it turn "infectious" next time? */
		if (ptime <= etu) {
		    /* Yes.  Report an outbreak. */
		    wu(0, sp->sct_own,
		       "Outbreak of PLAGUE in %s!\n", ownxy(sp));
		    nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1);
		}
	    }
	    break;
	default:
	    break;
	}
    }
    if (sp->sct_item[I_CIVIL] == 0 && sp->sct_item[I_MILIT] == 0
	&& !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) {
	makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
	sp->sct_own = 0;
	sp->sct_oldown = 0;
    }
    sp->sct_pstage = pstage;
    sp->sct_ptime = ptime;
}