Exemplo n.º 1
0
void
takeover(struct sctstr *sp, natid newown)
{
    struct plnstr *pp;
    struct lndstr *lp;
    int civ;
    int che_count;
    int oldche;
    int n;
    struct nstr_item ni;
    struct plnstr p;
    struct lndstr land;

    /* Wipe all the distribution info */
    memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
    memset(sp->sct_del, 0, sizeof(sp->sct_del));
    if (sp->sct_own == 0)
	sp->sct_off = 0;
    else
	sp->sct_off = 1;
    sp->sct_dist_x = sp->sct_x;
    sp->sct_dist_y = sp->sct_y;

    pp = &p;
    /* Take over planes */
    snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
    while (nxtitem(&ni, pp)) {
	if (pp->pln_own != sp->sct_own)
	    continue;
	takeover_plane(pp, newown);
    }

    /* Take over land units */
    lp = &land;
    snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
    while (nxtitem(&ni, lp)) {
	if ((lp->lnd_own == newown) || (lp->lnd_own == 0))
	    continue;
	if (lp->lnd_own != sp->sct_own)
	    continue;
	if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
	    continue;
	/* Spies get a chance to hide */
	if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
	    if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
		continue;
	}
	n = lp->lnd_effic - (29 + roll(100));
	if (n < 0)
	    n = 0;
	lp->lnd_effic = n;
	if (lp->lnd_effic < LAND_MINEFF) {
	    lp->lnd_effic = 0;
	    mpr(newown, "%s blown up by the crew!\n", prland(lp));
	    wu(0, lp->lnd_own,
	       "%s blown up by the crew when %s took %s!\n",
	       prland(lp),
	       cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
	} else {
	    mpr(newown, "We have captured %s!\n", prland(lp));
	    wu(0, lp->lnd_own,
	       "%s captured when %s took %s!\n",
	       prland(lp),
	       cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
	}
	takeover_land(lp, newown);
    }

    sp->sct_avail = 0;
    civ = sp->sct_item[I_CIVIL];
    oldche = sp->sct_che;
    /*
     * create guerrillas from civilians
     * how spunky are these guys?
     * n: random number from -25:75 + (50 - loyalty)
     */
    n = (50 - sp->sct_loyal) + (roll(100) - 26);
    if (n > 0 && sp->sct_own == sp->sct_oldown) {
	che_count = (civ * n / 3000) + 5;
	if (che_count * 2 > civ)
	    che_count = civ / 2;
	che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
	if (che_count + oldche > CHE_MAX)
	    che_count = CHE_MAX - oldche;
	if (che_count > 0) {
	    civ -= che_count;
	    che_count += oldche;
	} else
	    che_count = oldche;
    } else
	che_count = oldche;
    sp->sct_che = che_count;
    if (newown != sp->sct_oldown)
	sp->sct_che_target = newown;
    if (sp->sct_che_target == 0)
	sp->sct_che = 0;
    sp->sct_item[I_CIVIL] = civ;
    if (sp->sct_oldown == newown || civ == 0) {
	/*
	 * taking over one of your old sectors
	 */
	sp->sct_loyal = 0;
	sp->sct_oldown = newown;
    } else {
	/*
	 * taking over someone else's sector
	 */
	sp->sct_loyal = 50;
    }
    sp->sct_own = newown;
    if (opt_MOB_ACCESS) {
	game_tick_to_now(&sp->sct_access);
	sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
    } else {
	sp->sct_mobil = 0;
    }
}
Exemplo n.º 2
0
int
sabo(void)
{
    struct nstr_item ni;
    struct lndstr land, tmp;
    struct sctstr sect;
    double odds;
    int dam;

    if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
	return RET_SYN;

    while (nxtitem(&ni, &land)) {
	if (!player->owner)
	    continue;
	if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
	    pr("%s is not a spy.\n", prland(&land));
	    continue;
	}
	if (land.lnd_ship >= 0) {
	    pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
	    continue;
	}
	if (land.lnd_land >= 0) {
	    pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
	    continue;
	}
	if (!getsect(land.lnd_x, land.lnd_y, &sect))
	    continue;
	if (land.lnd_item[I_SHELL] == 0) {
	    pr("%s has no shells.\n", prland(&land));
	    continue;
	}

	odds = LND_SPY_DETECT_CHANCE(land.lnd_effic);
	if (chance(odds)) {
	    wu(0, sect.sct_own,
	       "%s spy shot in %s during sabotage attempt.\n",
	       cname(player->cnum),
	       xyas(sect.sct_x, sect.sct_y, sect.sct_own));
	    pr("%s was shot and killed.\n", prland(&land));
	    land.lnd_effic = 0;
	    putland(land.lnd_uid, &land);
	    continue;
	}

	dam = lnd_sabo(&land, sect.sct_item);
	if (dam < 0)
	    continue;

	pr("Explosion in %s causes %d damage.\n",
	   xyas(land.lnd_x, land.lnd_y, player->cnum), dam);
	if (sect.sct_own) {
	    wu(0, sect.sct_own,
	       "Sabotage in sector %s caused %d damage.\n",
	       xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
	}

	/* hack: hide the spy so it don't gets blasted by sectdamage() */
	tmp = land;
	tmp.lnd_own = 0;
	putland(land.lnd_uid, &tmp);
	land.lnd_seqno = tmp.lnd_seqno;

	sectdamage(&sect, dam);
	putsect(&sect);

	if (chance(odds)) {
	    pr("%s dies in explosion.\n", prland(&land));
	    land.lnd_effic = 0;
	}
	putland(land.lnd_uid, &land);
    }
    return RET_OK;
}
Exemplo n.º 3
0
static void
look_land(struct lndstr *lookland)
{
    struct plnstr *pp;
    struct lndstr *lp;
    double drange;
    int range;
    int vrange;
    int i;
    int dist;

    drange = techfact(lookland->lnd_tech, lchr[lookland->lnd_type].l_spy);
    drange *= lookland->lnd_effic / 100.0;
    range = ldround(drange, 1);

    if (range == 0)
	return;

    for (i = 0; NULL != (lp = getlandp(i)); i++) {
	if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
	    continue;
	if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
	    continue;
	/* Don't always see spies */
	if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
	    /* If it's on a ship or unit, assume it's hidden
	       enough not to be seen */
	    if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
		continue;
	    if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
		continue;
	}
	vrange = ldround((lnd_vis(lp) * range) / 20.0, 1);
	dist = mapdist(lp->lnd_x, lp->lnd_y,
		       lookland->lnd_x, lookland->lnd_y);
	if (dist > vrange)
	    continue;

	pr("%s %s (approx %d mil) @ %s\n",
	   prnatid(lp->lnd_own), prland(lp),
	   roundintby(lp->lnd_item[I_MILIT], 20),
	   xyas(lp->lnd_x, lp->lnd_y, player->cnum));
	if (opt_HIDDEN)
	    setcont(player->cnum, lp->lnd_own, FOUND_LOOK);
    }
    for (i = 0; NULL != (pp = getplanep(i)); i++) {
	if (pp->pln_own == player->cnum || pp->pln_own == 0)
	    continue;
	if (pp->pln_ship >= 0 || pp->pln_land >= 0)
	    continue;
	if (pp->pln_flags & PLN_LAUNCHED)
	    continue;
	vrange = ldround((10 * range) / 20.0, 1);
	dist = mapdist(pp->pln_x, pp->pln_y,
		       lookland->lnd_x, lookland->lnd_y);
	if (dist > vrange)
	    continue;

	pr("%s %s @ %s\n",
	   prnatid(pp->pln_own), prplane(pp),
	   xyas(pp->pln_x, pp->pln_y, player->cnum));
	if (opt_HIDDEN)
	    setcont(player->cnum, pp->pln_own, FOUND_LOOK);
    }
}