Ejemplo n.º 1
0
/*
 * Give @unit and its cargo to @recipient.
 * No action if @recipient already owns @unit.
 * If @giver is non-zero, inform @recipient and @giver of the transaction.
 * Clears mission and group on the units given away.
 */
void
unit_give_away(struct empobj *unit, natid recipient, natid giver)
{
    int type;
    struct nstr_item ni;
    union empobj_storage cargo;

    if (unit->own == recipient)
	return;

    if (giver) {
	mpr(unit->own, "%s given to %s\n",
	    unit_nameof(unit), cname(recipient));
	mpr(recipient, "%s given to you by %s\n",
	    unit_nameof(unit), cname(giver));
    }

    unit->own = recipient;
    unit_wipe_orders(unit);
    put_empobj(unit->ef_type, unit->uid, unit);

    for (type = EF_PLANE; type <= EF_NUKE; type++) {
	snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
	while (nxtitem(&ni, &cargo))
	    unit_give_away(&cargo.gen, recipient, giver);
    }
}
Ejemplo n.º 2
0
static void
takeover_unit(struct empobj *unit, natid newown)
{
    struct shpstr *sp;
    struct plnstr *pp;
    struct lndstr *lp;
    struct nukstr *np;
    int type;
    struct nstr_item ni;
    union empobj_storage cargo;

    unit->own = newown;
    if (opt_MARKET)
	trdswitchown(unit->ef_type, unit, newown);
    unit_wipe_orders(unit);

    switch (unit->ef_type) {
    case EF_SHIP:
	sp = (struct shpstr *)unit;
	sp->shp_off = 1;
	break;
    case EF_PLANE:
	pp = (struct plnstr *)unit;
	if (pp->pln_mobil > 0)
	    pp->pln_mobil = 0;
	pp->pln_off = 1;
	break;
    case EF_LAND:
	lp = (struct lndstr *)unit;
	if (lp->lnd_mobil > 0)
	    lp->lnd_mobil = 0;
	lp->lnd_off = 1;
	lp->lnd_harden = 0;
	break;
    case EF_NUKE:
	np = (struct nukstr *)unit;
	np->nuk_off = 1;
	break;
    default:
	CANT_REACH();
    }

    put_empobj(unit->ef_type, unit->uid, unit);

    for (type = EF_PLANE; type <= EF_NUKE; type++) {
	snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
	while (nxtitem(&ni, &cargo)) {
	    if (cargo.gen.own == newown)
		continue;
	    if (type == EF_PLANE)
		cargo.plane.pln_effic = PLANE_MINEFF;
	    takeover_unit(&cargo.gen, newown);
	}
    }
}