Exemple #1
0
/*
 * Report deity meddling with sector @sp.
 * Print a message (always), send a bulletin to the sector owner and
 * report news (sometimes).
 * @name names what is being changed in the sector.
 * If @change is zero, the meddling is a no-op (bulletin suppressed).
 * If @change is negative, it's secret (bulletin suppressed).
 * If a bulletin is sent, report N_AIDS news for positive @goodness,
 * N_HURTS news for negative @goodness
 * The bulletin's text is like "@name of sector X,Y changed <how> by an
 * act of <deity>, where <deity> is the deity's name, and <how> comes
 * from formatting printf-style @fmt with optional arguments.
 */
void
divine_sct_change(struct sctstr *sp, char *name,
		  int change, int goodness, char *fmt, ...)
{
    va_list ap;
    char buf[4096];

    va_start(ap, fmt);
    vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);

    if (!change) {
	pr("%s of %s unchanged\n",
	   name, xyas(sp->sct_x, sp->sct_y, player->cnum));
	return;
    }

    pr("%s of %s changed %s\n",
       name, xyas(sp->sct_x, sp->sct_y, player->cnum), buf);
    if (change > 0 && sp->sct_own && sp->sct_own != player->cnum) {
	wu(0, sp->sct_own, "%s of %s changed %s by an act of %s\n",
	   name, xyas(sp->sct_x, sp->sct_y, sp->sct_own),
	   buf, cname(player->cnum));
	nreport_divine_aid(sp->sct_own, goodness);
    }
}
Exemple #2
0
void
takeover_plane(struct plnstr *pp, natid newown)
{
    int n;

    if ((pp->pln_own == newown) || (pp->pln_own == 0))
	return;
    if (pp->pln_flags & PLN_LAUNCHED)
	return;
    if (pp->pln_ship >= 0 || pp->pln_land >= 0)
	return;
    /*
     * XXX If this was done right, planes could escape,
     * flying to a nearby friendly airport.
     */
    n = pp->pln_effic - (29 + roll(100));
    if (n < 0)
	n = 0;
    pp->pln_effic = n;
    if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > 0) {
	pp->pln_effic = 0;
	mpr(newown, "%s blown up by the crew!\n", prplane(pp));
	wu(0, pp->pln_own,
	   "%s blown up by the crew to avoid capture by %s at %s!\n",
	   prplane(pp),
	   cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
    } else {
	mpr(newown, "We have captured %s!\n", prplane(pp));
	wu(0, pp->pln_own,
	   "%s captured by %s at %s!\n",
	   prplane(pp),
	   cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
    }
    takeover_unit((struct empobj *)pp, newown);
}
Exemple #3
0
static void
meltitems(int etus, int fallout, int own, short *vec,
	  int type, int x, int y, int uid)
{
    i_type n;
    int melt;

    for (n = I_NONE + 1; n <= I_MAX; n++) {
	melt = roundavg(vec[n] * etus * (double)fallout
			/ (1000.0 * ichr[n].i_melt_denom));
	if (melt > vec[n])
	    melt = vec[n];
	if (melt > 5 && own) {
	    if (type == EF_SECTOR)
		wu(0, own, "Lost %d %s to radiation in %s.\n",
		   melt, ichr[n].i_name,
		   xyas(x, y, own));
	    else if (type == EF_LAND)
		wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n",
		   uid, melt, ichr[n].i_name,
		   xyas(x, y, own));
	    else if (type == EF_SHIP)
		wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n",
		   uid, melt, ichr[n].i_name,
		   xyas(x, y, own));
	}
	vec[n] -= melt;
    }
}
Exemple #4
0
/*
 * Find out whether planes can fly one-way to X,Y.
 * Offer the player any carriers there.  If he chooses one, read it
 * into TARGET->ship.  Else read the target sector into TARGET->sect.
 * If planes can land there, set required plane flags in *FLAGSP, and
 * return 0.  Else return -1.
 */
int
pln_where_to_land(coord x, coord y,
		  union empobj_storage *target, int *flagsp)
{
    int nships;
    int cno;
    int fl;
    char buf[1024];
    char *p;

    /* offer carriers */
    nships = carriersatxy(x, y, player->cnum);
    if (nships) {
	for (;;) {
	    p = getstring("Carrier #? ", buf);
	    if (!p)
		return -1;
	    if (!*p)
		break;
	    cno = atoi(p);
	    if (!getship(cno, &target->ship)
		|| (!player->owner
		    && (relations_with(target->ship.shp_own, player->cnum)
			!= ALLIED))) {
		pr("Not yours\n");
		continue;
	    }
	    if (target->ship.shp_x != x || target->ship.shp_y != y) {
		pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
		continue;
	    }
	    fl = carrier_planes(&target->ship, 0);
	    if (fl == 0) {
		pr("Can't land on %s.\n", prship(&target->ship));
		continue;
	    }
	    /* clear to land on ship#CNO */
	    pr("landing on carrier %d\n", cno);
	    *flagsp |= fl;
	    return 0;
	}
    }

    /* try to land at sector */
    getsect(x, y, &target->sect);
    if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
	pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
	return -1;
    }
    if (target->sect.sct_type == SCT_MOUNT) {
	pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
	return -1;
    }
    /* clear to land at sector */
    if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
	*flagsp |= P_V;
    return 0;
}
Exemple #5
0
static int
load_comm_land(struct sctstr *sectp, struct lndstr *lp,
	       struct ichrstr *ich, int load_unload, int *nunitsp)
{
    i_type item = ich->i_uid;
    struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
    int land_amt, sect_amt, move_amt;
    char prompt[512];
    char *p;
    char buf[1024];

    sprintf(prompt, "Number of %s to %s %s at %s? ",
	    ich->i_name,
	    (load_unload == UNLOAD) ?
	    "unload from" : "load onto",
	    prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
    p = getstarg(player->argp[3], prompt, buf);
    if (!p || !*p)
	return RET_SYN;

    if (!still_ok_land(sectp, lp))
	return RET_SYN;

    land_amt = lp->lnd_item[item];
    sect_amt = sectp->sct_item[item];
    move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
			   load_unload, atoi(p));
    if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
	return RET_OK;
    sectp->sct_item[item] = sect_amt - move_amt;
    lp->lnd_item[item] = land_amt + move_amt;

    /* Did we put mils onto this unit? If so, reset the fortification */
    if (item == I_MILIT && move_amt > 0)
	lp->lnd_harden = 0;

    if (move_amt >= 0) {
	pr("%d %s loaded onto %s at %s\n",
	   move_amt, ich->i_name,
	   prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
	if (lp->lnd_own != player->cnum) {
	    wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
	       cname(player->cnum), move_amt, ich->i_name,
	       prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
	}
    } else {
	pr("%d %s unloaded from %s at %s\n",
	   -move_amt, ich->i_name,
	   prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
	if (sectp->sct_own != player->cnum) {
	    wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
	       cname(player->cnum), -move_amt, ich->i_name,
	       prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
	}
    }
    ++*nunitsp;
    return 0;
}
Exemple #6
0
static int
load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
	       struct ichrstr *ich, int load_unload, int *nshipsp)
{
    i_type item = ich->i_uid;
    struct mchrstr *mcp = &mchr[(int)sp->shp_type];
    int ship_amt, sect_amt, move_amt;
    char prompt[512];
    char *p;
    char buf[1024];

    sprintf(prompt, "Number of %s to %s %s at %s? ",
	    ich->i_name,
	    (load_unload == UNLOAD) ?
	    "unload from" : "load onto",
	    prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
    p = getstarg(player->argp[3], prompt, buf);
    if (!p || !*p)
	return RET_SYN;

    if (!still_ok_ship(sectp, sp))
	return RET_SYN;

    ship_amt = sp->shp_item[item];
    sect_amt = sectp->sct_item[item];
    move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
			   load_unload, atoi(p));
    if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
	return RET_OK;
    if (!abandon_askyn(sectp, item, move_amt, NULL))
	return RET_FAIL;
    if (!still_ok_ship(sectp, sp))
	return RET_SYN;
    sectp->sct_item[item] = sect_amt - move_amt;
    sp->shp_item[item] = ship_amt + move_amt;

    if (move_amt >= 0) {
	pr("%d %s loaded onto %s at %s\n",
	   move_amt, ich->i_name,
	   prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
	if (sp->shp_own != player->cnum) {
	    wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
	       cname(player->cnum), move_amt, ich->i_name,
	       prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
	}
    } else {
	pr("%d %s unloaded from %s at %s\n",
	   -move_amt, ich->i_name,
	   prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
	if (sectp->sct_own != player->cnum) {
	    wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
	       cname(player->cnum), -move_amt, ich->i_name,
	       prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
	}
    }
    ++*nshipsp;
    return 0;
}
Exemple #7
0
static char *
unit_move_route(struct empobj *unit, char *buf, size_t bufsz)
{
    coord destx;
    coord desty;
    struct sctstr sect;
    size_t len;
    double c;
    int mtype;

    if (CANT_HAPPEN(unit->ef_type != EF_LAND && unit->ef_type != EF_SHIP))
	return NULL;

    if (!sarg_xy(buf, &destx, &desty))
	return buf;
    if (unit->ef_type == EF_SHIP) {
	c = path_find(unit->x, unit->y, destx, desty,
		      player->cnum, MOB_SAIL);
	if (c < 0 || unit->mobil <= 0) {
	    pr("Can't get to '%s' right now.\n",
	       xyas(destx, desty, player->cnum));
	    return NULL;
	}
    } else {
	getsect(unit->x, unit->y, &sect);
	mtype = lnd_mobtype((struct lndstr *)unit);
	/*
	 * Note: passing sect.sct_own for actor is funny, but works:
	 * its only effect is to confine the search to that nation's
	 * land.  It doesn't affect mobility costs.  The real actor is
	 * different for marching in allied land, and passing it would
	 * break path finding there.
	 */
	c = path_find(unit->x, unit->y, destx, desty, sect.sct_own, mtype);
	if (c < 0) {
	    pr("No owned %s from %s to %s!\n",
	       mtype == MOB_RAIL ? "railway" : "path",
	       xyas(unit->x, unit->y, player->cnum),
	       xyas(destx, desty, player->cnum));
	    return NULL;
	}
    }
    len = path_find_route(buf, bufsz, unit->x, unit->y, destx, desty);
    if (len == 0 || unit->ef_type == EF_LAND) {
	if (len + 1 < bufsz)
	    strcpy(buf + len, "h");
	len++;
    }
    if (len >= bufsz) {
	pr("Can't handle path to %s, it's too long, sorry\n",
	   xyas(destx, desty, player->cnum));
	return NULL;
    }
    pr("Using path '%s'\n", buf);
    return buf;
}
Exemple #8
0
/*
 * threshold <COMM> <SECTS> <THRESH>
 */
int
thre(void)
{
    struct sctstr sect;
    struct nstr_sect nstr;
    int val;
    struct ichrstr *ip;
    char *p;
    int thresh;
    i_type type;
    char prompt[128];
    char buf[128];

    if (!(ip = whatitem(player->argp[1], "What commodity? ")))
	return RET_SYN;
    if (!snxtsct(&nstr, player->argp[2]))
	return RET_SYN;
    type = ip->i_uid;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	val = sect.sct_dist[type];
	if (val > 0)
	    sprintf(prompt, "%s %s  old threshold %d new? ",
		    xyas(nstr.x, nstr.y, player->cnum),
		    dchr[sect.sct_type].d_name, val);
	else
	    sprintf(prompt, "%s %s  threshold? ",
		    xyas(nstr.x, nstr.y, player->cnum),
		    dchr[sect.sct_type].d_name);
	if (!(p = getstarg(player->argp[3], prompt, buf)))
	    return RET_FAIL;
	if (!*p)
	    continue;
	if (!check_sect_ok(&sect))
	    return RET_FAIL;
	thresh = atoi(p);
	if (thresh < 0)
	    return RET_FAIL;
	if (thresh > ITEM_MAX)
	    thresh = ITEM_MAX;
	if ((val > 0) && (val == thresh)) {
	    pr("%s threshold unchanged (left at %d)\n",
	       xyas(nstr.x, nstr.y, player->cnum), val);
	    continue;
	}
	if (val > 0 && player->argp[3] && *player->argp[3])
	    pr("%s old threshold %d\n",
	       xyas(nstr.x, nstr.y, player->cnum), val);
	sect.sct_dist[type] = thresh;
	putsect(&sect);
    }
    return RET_OK;
}
Exemple #9
0
static int
fire_torp(struct shpstr *sp, struct shpstr *targ, int ntargets)
{
    int range, erange, dam;

    if ((mchr[targ->shp_type].m_flags & M_SUB)
	&& (mchr[sp->shp_type].m_flags & M_SUBT) == 0)
	return 0;		/* need sub-torp to torpedo a sub */

    erange = roundrange(torprange(sp));
    range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y);
    if (range > erange)
	return 0;

    if (!line_of_sight(NULL, sp->shp_x, sp->shp_y,
		       targ->shp_x, targ->shp_y))
	return 0;
    dam = shp_torp(sp, 1);
    putship(sp->shp_uid, sp);
    if (dam < 0)
	return 0;

    pr("Captain! Torpedoes sighted!\n");

    if (chance(shp_torp_hitchance(sp, range))) {
	pr("BOOM!...\n");
	if (!(mchr[targ->shp_type].m_flags & M_SUB)) {
	    if (mchr[sp->shp_type].m_flags & M_SUB)
		nreport(targ->shp_own, N_TORP_SHIP, 0, 1);
	    else
		nreport(targ->shp_own, N_SHIP_TORP, sp->shp_own, 1);
	}
	if (sp->shp_own != 0)
	    wu(0, sp->shp_own, "%s @ %s torpedoed %s\n",
	       prship(sp),
	       xyas(sp->shp_x, sp->shp_y, sp->shp_own), prsub(targ));
	if (ntargets > 2)
	    dam /= ntargets / 2;

	shipdamage(targ, dam);
	putship(targ->shp_uid, targ);

    } else {
	pr("Missed!\n");
	if (sp->shp_own != 0)
	    wu(0, sp->shp_own,
	       "%s missed %s with a torpedo at %s\n",
	       prship(sp), prsub(targ),
	       xyas(sp->shp_x, sp->shp_y, sp->shp_own));
    }

    return 1;
}
Exemple #10
0
void
divine_load(struct empobj *unit, int type, int uid)
{
    union empobj_storage carrier;

    divine_load_unload(unit, type, uid, "loaded onto");
    if (get_empobj(type, uid, &carrier)
	&& (unit->x != carrier.gen.x || unit->y != carrier.gen.y)) {
	pr("%s teleported from %s to %s!",
	   unit_nameof(unit), xyas(unit->x, unit->y, player->cnum),
	   xyas(carrier.gen.x, carrier.gen.y, player->cnum));
	unit_teleport(unit, carrier.gen.x, carrier.gen.y);
    }
}
Exemple #11
0
void
bsanct(void)
{
    int count;
    struct sctstr s;
    struct nstr_sect nstr;

    if (player->god)
	return;
    count = 0;
    snxtsct_all(&nstr);
    while (nxtsct(&nstr, &s)) {
	if (!player->owner)
	    continue;
	if (s.sct_type != SCT_SANCT)
	    continue;
	pr("%s is no longer a sanctuary.\n",
	   xyas(s.sct_x, s.sct_y, player->cnum));
	if (s.sct_newtype == SCT_SANCT)
	    s.sct_newtype = SCT_CAPIT;
	s.sct_type = s.sct_newtype;
	game_tick_to_now(&s.sct_access);
	(void)putsect(&s);
	count++;
    }
    if (count > 0) {
	game_note_bsanct();
	nreport(player->cnum, N_BROKE_SANCT, 0, 1);
    }
}
Exemple #12
0
/*
 * Drop cargo of @unit.
 * Give it to @newown, unless it's zero.
 */
void
unit_drop_cargo(struct empobj *unit, natid newown)
{
    int type;
    struct nstr_item ni;
    union empobj_storage cargo;

    for (type = EF_PLANE; type <= EF_NUKE; type++) {
	snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
	while (nxtitem(&ni, &cargo)) {
	    switch (type) {
	    case EF_PLANE:
		cargo.plane.pln_ship = cargo.plane.pln_land = -1;
		break;
	    case EF_LAND:
		cargo.land.lnd_ship = cargo.land.lnd_land = -1;
		break;
	    case EF_NUKE:
		cargo.nuke.nuk_plane = -1;
		break;
	    }
	    mpr(cargo.gen.own, "%s transferred off %s %d to %s\n",
		unit_nameof(&cargo.gen),
		ef_nameof(unit->ef_type), unit->uid,
		xyas(cargo.gen.x, cargo.gen.y, cargo.gen.own));
	    if (newown)
		unit_give_away(&cargo.gen, newown, cargo.gen.own);
	    put_empobj(type, cargo.gen.uid, &cargo.gen);
	}
    }
}
Exemple #13
0
static char *
unit_move_getpath(struct emp_qelem *list, int suppress_map, char *path)
{
    struct empobj *leader = get_leader(list);
    double minmob, maxmob;
    struct emp_qelem *qp;
    struct ulist *ulp;
    char prompt[64];

    minmob = HUGE_VAL;
    maxmob = -HUGE_VAL;
    for (qp = list->q_back; qp != list; qp = qp->q_back) {
	ulp = (struct ulist *)qp;
	if (ulp->mobil < minmob)
	    minmob = ulp->mobil;
	if (ulp->mobil > maxmob)
	    maxmob = ulp->mobil;
    }
    if (!suppress_map)
	nav_map(leader->x, leader->y,
		leader->ef_type == EF_SHIP
		? !(mchr[leader->type].m_flags & M_SUB) : 1);
    snprintf(prompt, sizeof(prompt), "<%.1f:%.1f: %s> ",
	     maxmob, minmob,
	     xyas(leader->x, leader->y, player->cnum));
    return getstring(prompt, path);
}
Exemple #14
0
static void
unit_view(struct emp_qelem *list)
{
    struct sctstr sect;
    struct emp_qelem *qp;
    struct emp_qelem *next;
    struct ulist *ulp;

    for (qp = list->q_back; qp != list; qp = next) {
	next = qp->q_back;
	ulp = (struct ulist *)qp;
	if (CANT_HAPPEN(!(ef_flags(ulp->unit.gen.ef_type) & EFF_XY)))
	    continue;
	getsect(ulp->unit.gen.x, ulp->unit.gen.y, &sect);
	if (ulp->unit.gen.ef_type == EF_SHIP) {
	    if (mchr[ulp->unit.ship.shp_type].m_flags & M_FOOD)
		pr("[fert:%d] ", sect.sct_fertil);
	    if (mchr[ulp->unit.ship.shp_type].m_flags & M_OIL)
		pr("[oil:%d] ", sect.sct_oil);
	}
	pr("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),
	   xyas(ulp->unit.gen.x, ulp->unit.gen.y, player->cnum),
	   sect.sct_effic, dchr[sect.sct_type].d_name);
    }
}
Exemple #15
0
void
pln_mine(struct emp_qelem *list, coord tx, coord ty)
{
    struct emp_qelem *qp;
    struct plist *plp;
    int amt;
    struct sctstr sect;

    amt = 0;
    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
	plp = (struct plist *)qp;
	amt += plp->load;

    }
    if (amt > 0) {
	getsect(tx, ty, &sect);
	if (sect.sct_type != SCT_WATER) {
	    pr("Your seamines have no effect here.\n");
	    return;
	}
	sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
	pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
	if (map_set(player->cnum, tx, ty, 'X', 0))
	    writemap(player->cnum);
	putsect(&sect);
    }
}
Exemple #16
0
/*
 * silly to be sure.
 */
static void
kaboom(int x, int y, int rad)
{
    pr("\n\nK A B O O ");
    while (rad-- > 1)
        pr("O O ");
    pr("M ! in %s\n\n", xyas(x, y, player->cnum));
}
Exemple #17
0
/* unload_it
 * A guess alot of this looks like load_it but because of its location
 * in the autonav code I had to split the 2 procedures up.
 * unload_it dumps all the goods from the ship to the harbor.
 * ONLY goods in the trade fields will be unloaded.
 * new autonav code
 * Chad Zabel 6/1/94
 */
void
unload_it(struct shpstr *sp)
{
    struct sctstr *sectp;
    int i;
    int landowner;
    int shipown;
    i_type comm;
    int sect_amt;
    int ship_amt;
    int max_amt;

    sectp = getsectp(sp->shp_x, sp->shp_y);

    landowner = sectp->sct_own;
    shipown = sp->shp_own;

    for (i = 0; i < TMAX; ++i) {
	if (sp->shp_tend[i] == I_NONE || sp->shp_lend[i] == 0)
	    continue;
	if (landowner == 0)
	    continue;
	if (sectp->sct_type != SCT_HARBR)
	    continue;

	comm = sp->shp_tend[i];
	if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX))
	    continue;
	ship_amt = sp->shp_item[comm];
	sect_amt = sectp->sct_item[comm];

	/* check for disloyal civilians */
	if (sectp->sct_oldown != shipown && comm == I_CIVIL) {
	    wu(0, sp->shp_own,
	       "Ship #%d - unable to unload civilians into a disloyal sector at %s.",
	       sp->shp_uid, xyas(sectp->sct_x, sectp->sct_y, sp->shp_own));
	    continue;
	}
	if (comm == I_CIVIL)
	    ship_amt--;		/* This leaves 1 civs on board the ship */

	max_amt = MIN(ship_amt, ITEM_MAX - sect_amt);
	if (max_amt <= 0)
	    continue;

	sp->shp_item[comm] = ship_amt - max_amt;
	sectp->sct_item[comm] = sect_amt + max_amt;

	if (sectp->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
	    sp->shp_pstage = PLG_EXPOSED;
	if (sp->shp_pstage == PLG_INFECT && sectp->sct_pstage == PLG_HEALTHY)
	    sectp->sct_pstage = PLG_EXPOSED;
    }
}
Exemple #18
0
int
msl_asat_intercept(struct plnstr *msl, coord x, coord y)
{
    struct sctstr sect;
    struct emp_qelem irvlist;

    getsect(x, y, &sect);
    mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
	cname(msl->pln_own), xyas(x, y, sect.sct_own));
    msl_sel(&irvlist, x, y, msl->pln_own, P_O, 0, 0);
    return msl_intercept(msl, &sect, 0,
			 &irvlist, "satellite", "a-sat missile",
			 N_SAT_KILL);
}
Exemple #19
0
static void
pr_mark(struct comstr *comm)
{
    time_t now, tleft;

    (void)time(&now);
    tleft = comm->com_markettime + MARK_DELAY - now;
    if (tleft < 0)
	tleft = 0;
    pr(" %3d  $%12.2f  %2d  %5.2f hrs  (%3d)   %c    %6d  ",
       comm->com_uid, comm->com_price, comm->com_maxbidder, tleft / 3600.0,
       comm->com_owner, ichr[comm->com_type].i_mnem, comm->com_amount);
    if (comm->com_owner == player->cnum || player->god)
	pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
    pr("\n");
}
Exemple #20
0
void
pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
{
    struct emp_qelem *qp;
    struct plist *plp;
    struct shpstr ship;
    struct sctstr sect;

    if (cno >= 0)
	getship(cno, &ship);
    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
	plp = (struct plist *)qp;
	if (cno >= 0) {
	    if (!could_be_on_ship(&plp->plane, &ship))
		pr("\t%s cannot land on ship #%d! %s aborts!\n",
		   prplane(&plp->plane), cno, prplane(&plp->plane));
	    else if (!put_plane_on_ship(&plp->plane, &ship))
		pr("\tNo room on ship #%d! %s aborts!\n",
		   cno, prplane(&plp->plane));
	    else {
		if (plp->plane.pln_own != ship.shp_own) {
		    wu(0, ship.shp_own, "%s %s lands on your %s\n",
		       cname(player->cnum), prplane(&plp->plane),
		       prship(&ship));
		}
		if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
		    && ship.shp_pstage == PLG_HEALTHY)
		    ship.shp_pstage = PLG_EXPOSED;
	    }
	} else {
	    plp->plane.pln_x = tx;
	    plp->plane.pln_y = ty;
	    getsect(tx, ty, &sect);
	    if (plp->plane.pln_own != sect.sct_own) {
		wu(0, sect.sct_own,
		   "%s %s lands at your sector %s\n",
		   cname(player->cnum),
		   prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
	    }
	    if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
		&& sect.sct_pstage == PLG_HEALTHY)
		sect.sct_pstage = PLG_EXPOSED;
	    plp->plane.pln_ship = cno;
	}
    }
}
Exemple #21
0
void
pln_put1(struct plist *plp)
{
    struct plnstr *pp;
    struct shpstr ship;
    struct sctstr sect;

    pp = &plp->plane;

    if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
		    && (plchr[pp->pln_type].pl_flags & P_M)
		    && pp->pln_effic >= PLANE_MINEFF))
	pp->pln_effic = 0;   /* bug: missile launched but not used up */

    if (!(pp->pln_flags & PLN_LAUNCHED))
	;			/* never took off */
    else if (pp->pln_effic < PLANE_MINEFF) {
	;			/* destroyed */
    } else if (pp->pln_ship >= 0) {
	/* It is landing on a carrier */
	getship(pp->pln_ship, &ship);
	/* We should do more, like make sure it's really
	   a carrier, etc. but for now just make sure it's
	   not sunk. */
	if (ship.shp_effic < SHIP_MINEFF) {
	    mpr(pp->pln_own,
		"Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
		"splashes into the sea.\n",
		pp->pln_ship, pp->pln_uid);
	    pp->pln_effic = 0;
	}
    } else {
	/* Presume we are landing back in a sector. */
	getsect(pp->pln_x, pp->pln_y, &sect);
	if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
	    mpr(pp->pln_own,
		"Nowhere to land at %s, plane #%d crashes and burns...\n",
		xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
	    pp->pln_effic = 0;
	}
    }
    pp->pln_flags &= ~PLN_LAUNCHED;
    putplane(pp->pln_uid, pp);
    emp_remque(&plp->queue);
    free(plp);
}
Exemple #22
0
int
orig(void)
{
    char *p;
    coord x, y;
    char buf[1024];
    int cnum;
    struct natstr *np;

    p = getstarg(player->argp[1], "New origin (sector or country) : ", buf);
    if (!p || !*p)
        return RET_SYN;
    if (!isalpha(*p) && strchr(p, ',')) {
        /* sector */
        if (!sarg_xy(p, &x, &y)) {
            pr("Bad sector designation.\n");
            return RET_SYN;
        }
    } else if (*p == '~') {
        /* reset */
        if (!player->god) {
            pr("Only deities can reset their origin.\n");
            return RET_FAIL;
        }
        x = y = 0;
    } else {
        /* country */
        cnum = natarg(p, NULL);
        if (!(np = getnatp(cnum)))
            return RET_SYN;
        if (!player->god && relations_with(cnum, player->cnum) != ALLIED) {
            pr("Country %s is not allied with you!\n", np->nat_cnam);
            return RET_FAIL;
        }
        x = np->nat_xorg;
        y = np->nat_yorg;
    }
    pr("Origin at %s (old system) is now at 0,0 (new system).\n",
       xyas(x, y, player->cnum));
    np = getnatp(player->cnum);
    np->nat_xorg = x;
    np->nat_yorg = y;
    putnat(np);
    return RET_OK;
}
Exemple #23
0
int
wipe(void)
{
    struct sctstr sect;
    struct nstr_sect nstr;

    if (!snxtsct(&nstr, player->argp[1]))
	return RET_SYN;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	memset(sect.sct_dist, 0, sizeof(sect.sct_dist));
	pr("Distribution thresholds wiped from %s\n",
	   xyas(nstr.x, nstr.y, player->cnum));
	putsect(&sect);
    }
    return RET_OK;
}
Exemple #24
0
void
plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
{
    struct plnstr *pp;
    struct plchrstr *pcp;
    struct emp_qelem *qp;
    struct emp_qelem *next;
    struct plist *ip;
    struct sctstr sect;
    int mines_there;
    int found = 0;

    getsect(x, y, &sect);
    mines_there = sect.sct_mines;

    if (mines_there == 0)
	return;

    if (sect.sct_type != SCT_WATER)
	return;

    for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
	 qp = next) {
	next = qp->q_forw;
	ip = (struct plist *)qp;
	pp = &ip->plane;
	pcp = ip->pcp;
	if (!(pcp->pl_flags & P_SWEEP))	/* if it isn't an sweep plane */
	    continue;

	if (chance((100.0 - pln_acc(pp)) / 100.0)) {
	    pr("Sweep! in %s\n",
	       xyas(sect.sct_x, sect.sct_y, player->cnum));
	    mines_there--;
	    found = 1;
	}
    }

    if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
	writemap(player->cnum);
    sect.sct_mines = mines_there;
    putsect(&sect);
}
Exemple #25
0
int
check_lmines(coord x, coord y, double weight)
{
    struct sctstr sect;
    int dam = 0;

    getsect(x, y, &sect);
    if (SCT_LANDMINES(&sect) > 0 &&
	sect.sct_oldown != player->cnum &&
	chance(DMINE_LHITCHANCE(sect.sct_mines)) && chance(weight / 100.0)) {
	pr_beep();
	pr("Blammo! Landmines detected! in %s  ",
	   xyas(sect.sct_x, sect.sct_y, player->cnum));
	dam = roll(20);
	--sect.sct_mines;
	putsect(&sect);
	pr("%d damage sustained.\n", dam);
    }
    return dam;
}
Exemple #26
0
int
load_comm_ok(struct sctstr *sectp, natid unit_own,
	     i_type item, int move_amt)
{
    if (!move_amt)
	return 0;
    if (move_amt < 0 && !player->god && unit_own != player->cnum)
	return 0;
    if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
	return 0;
    if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
	pr("%s civilians refuse to %s at %s!\n",
	   (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
	   ? "Your" : "Foreign",
	   move_amt < 0 ? "disembark" : "board",
	   xyas(sectp->sct_x, sectp->sct_y, player->cnum));
	return 0;
    }
    return 1;
}
Exemple #27
0
void
move_sat(struct plnstr *pp)
{
    coord x1, y1, x2, y2;
    coord dx, dy;
    float newtheta;
    struct sctstr sect;

    newtheta = pp->pln_theta + .05;

    if (newtheta >= 1.0) {
	newtheta -= 1.0;
    }

    x1 = (coord)(2 * pp->pln_theta * WORLD_X);
    x1 = xnorm(x1);
    y1 = (coord)(sin(6 * PI * pp->pln_theta) * (WORLD_Y / 4));
    x2 = (coord)(2 * newtheta * WORLD_X);
    x2 = xnorm(x2);
    y2 = (coord)(sin(6 * PI * newtheta) * (WORLD_Y / 4));
    dx = x1 - pp->pln_x;
    dy = y1 - pp->pln_y;
    x2 -= dx;
    y2 -= dy;

    if ((x2 + y2) & 1) {
	x2++;
    }

    pp->pln_x = xnorm(x2);
    pp->pln_y = ynorm(y2);
    pp->pln_theta = newtheta;
    getsect(pp->pln_x, pp->pln_y, &sect);
    if (sect.sct_own)
	if (pp->pln_own != sect.sct_own)
	    wu(0, sect.sct_own, "%s satellite spotted over %s\n",
	       cname(pp->pln_own), xyas(pp->pln_x, pp->pln_y,
					sect.sct_own));
    return;
}
Exemple #28
0
void look_at_sect(struct sctstr *sp, int mult)
{
    int civ, mil;
    int ours = player->god || sp->sct_own == player->cnum;

    pr("%s %s",
       sp->sct_own == player->cnum ? "Your" : prnatid(sp->sct_own),
       dchr[sp->sct_type].d_name);
    pr(" %d%% efficient ",
       ours ? sp->sct_effic : roundintby(sp->sct_effic, mult));
    civ = sp->sct_item[I_CIVIL];
    mil = sp->sct_item[I_MILIT];
    if (civ)
	pr("with %s%d civ ",
	   ours ? "" : "approx ",
	   ours ? civ : roundintby(civ, mult));
    if (mil)
	pr("with %s%d mil ",
	   ours ? "" : "approx ",
	   ours ? mil : roundintby(mil, mult));
    pr("@ %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
}
Exemple #29
0
static int
showsat(struct sky **skypp, int x, int y)
{
    struct sky *skyp;
    struct sky *todelete = NULL;
    struct sky **prev;
    int nsat = 0;

    prev = NULL;
    skyp = *skypp;
    prev = skypp;
    do {
	/* we delete it, we free it. */
	if (todelete) {
	    free(todelete);
	    todelete = NULL;
	}
	if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) {
	    prev = &(*prev)->s_next;
	    continue;
	}
	pr(" %12.12s (#%3d) %s @ %s\n",
	   cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own,
	   prplane(&skyp->s_sat), xyas(x, y, player->cnum));
	if (opt_HIDDEN) {
	    /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */
	    setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST);
	}
	*prev = skyp->s_next;
	todelete = skyp;
	nsat++;
    } while (NULL != (skyp = skyp->s_next));
    /* check that last one! */
    if (todelete)
	free(todelete);
    return nsat;
}
Exemple #30
0
static int
showship(struct coast **cpp, int x, int y)
{
    struct coast *cp;
    struct coast *todelete = NULL;
    struct coast **prev;
    int nship = 0;

    prev = NULL;
    cp = *cpp;
    prev = cpp;
    do {
	/* we delete it, we free it. */
	if (todelete) {
	    free(todelete);
	    todelete = NULL;
	}
	if (cp->c_shp.shp_x != x || cp->c_shp.shp_y != y) {
	    prev = &(*prev)->c_next;
	    continue;
	}
	pr(" %12.12s (#%3d) %s @ %s\n",
	   cname(cp->c_shp.shp_own), cp->c_shp.shp_own,
	   prship(&cp->c_shp), xyas(x, y, player->cnum));
	if (opt_HIDDEN) {
	    setcont(player->cnum, cp->c_shp.shp_own, FOUND_COAST);
	}
	*prev = cp->c_next;
	todelete = cp;
	nship++;
    } while (NULL != (cp = cp->c_next));
    /* check that last one! */
    if (todelete)
	free(todelete);
    return nship;
}