예제 #1
0
파일: sect.c 프로젝트: fstltna/empserver
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;
    }
}
예제 #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);
}
예제 #3
0
int
shark(void)
{
    int arg;
    time_t now;
    char *p;
    struct lonstr loan;
    struct natstr *natp;
    struct natstr *oldie;
    double owed;
    int payment;
    char buf[1024];

    if (!opt_LOANS) {
	pr("Loans are not enabled.\n");
	return RET_FAIL;
    }
    p = getstarg(player->argp[1], "Transfer which loan #: ", buf);
    if (!p)
	return RET_SYN;
    if (*p == 0)
	return RET_SYN;
    arg = atoi(p);
    if (arg < 0)
	return RET_SYN;
    /* Check if it's a valid loan to shark.  That means, is it a valid loan,
       not owed to this player, with a valid duration and it's been signed. */
    if (!getloan(arg, &loan) || (loan.l_loner == player->cnum) ||
	(loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) {
	pr("Invalid loan\n");
	return RET_FAIL;
    }
    /* If we got here, we check to see if it's been defaulted on. */
    owed = loan_owed(&loan, time(&now));
    if (now <= loan.l_duedate) {
	pr("There has been no default on loan %d\n", arg);
	return RET_FAIL;
    }
    pr("That loan is worth $%.2f.\n", owed);
    natp = getnatp(player->cnum);
    payment = (int)ceil(owed * (1.0 + loan.l_irate / 100.0));
    if (payment > natp->nat_money - 100.0) {
	pr("You do not have enough to cover that loan\n");
	return RET_FAIL;
    } else {
	wu(0, loan.l_lonee,
	   "%s bought loan #%d.  You now owe him!\n",
	   cname(player->cnum), arg);
	wu(0, loan.l_loner,
	   "%s bought loan #%d out from under you for %d\n",
	   cname(player->cnum), arg, payment);
	pr("You now own loan #%d.  Go break some legs.\n", arg);
    }
    oldie = getnatp(loan.l_loner);
    oldie->nat_money += payment;
    player->dolcost += payment;
    loan.l_loner = player->cnum;
    putloan(arg, &loan);
    return RET_OK;
}
예제 #4
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;
}
예제 #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;
}
예제 #6
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;
}
예제 #7
0
/*
 * Post-processing after successful declination of loan.
 * Notify the folks involved.
 */
static void
decline(struct ltcomstr *ltcp)
{
    if (ltcp->proposee == player->cnum) {
	wu(0, ltcp->proposer, "%s %d refused by %s\n",
	   ltcp->Name, ltcp->num, cname(player->cnum));
	pr("%s %d refused.\n", ltcp->Name, ltcp->num);
    } else {
	wu(0, ltcp->proposee,
	   "%s offer %d retracted by %s\n",
	   ltcp->Name, ltcp->num, cname(player->cnum));
	pr("%s offer %d retracted.\n", ltcp->Name, ltcp->num);
    }
}
예제 #8
0
static void
upd_plane(struct plnstr *pp, int etus,
	  struct natstr *np, struct bp *bp, int build)
{
    struct plchrstr *pcp = &plchr[(int)pp->pln_type];
    int mult, cost, eff_lost;

    if (build == 1) {
	if (!pp->pln_off && np->nat_money >= 0)
	    planerepair(pp, np, bp, etus);
	if (!player->simulation)
	    pp->pln_off = 0;
    } else {
	mult = 1;
	if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85)
	    mult = 2;
	cost = -(mult * etus * MIN(0.0, pcp->pl_cost * money_plane));
	if (np->nat_money < cost && !player->simulation) {
	    eff_lost = etus / 5;
	    if (pp->pln_effic - eff_lost < PLANE_MINEFF)
		eff_lost = pp->pln_effic - PLANE_MINEFF;
	    if (eff_lost > 0) {
		wu(0, pp->pln_own, "%s lost %d%% to lack of maintenance\n",
		   prplane(pp), eff_lost);
		pp->pln_effic -= eff_lost;
	    }
	} else {
	    np->nat_money -= cost;
	}
	/* flight pay is 5x the pay received by other military */
	np->nat_money += etus * pcp->pl_crew * money_mil * 5;
    }
}
예제 #9
0
void
gift(natid givee, natid giver, void *ptr, char *mesg)
{
    if (giver != givee)
	wu(0, givee, "%s %s %s\n", cname(giver), unit_nameof(ptr), mesg);
    unit_give_away(ptr, givee, 0);
}
예제 #10
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);
    }
}
예제 #11
0
static void
fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
{
    int range, erange, dam;

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

    if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0) {
	/* Return fire to a torpedo boat */
	if (mchr[sp->shp_type].m_flags & M_SUB)
	    return;		/* sub deck gun can't return fire */
	dam = shp_fire(sp);
	putship(sp->shp_uid, sp);
	if (dam < 0)
	    return;
	if (ntargets > 2)
	    dam /= ntargets / 2;

	pr_beep();
	pr("Kaboom!!! Incoming shells!\n");
	if (sp->shp_own != 0)
	    wu(0, sp->shp_own,
	       "%s fired at %s\n", prship(sp), prship(targ));
	pr_beep();
	pr("BLAM! %d damage!\n", dam);
    } else {
	/* Return fire to a submarine */
	dam = shp_dchrg(sp);
	putship(sp->shp_uid, sp);
	if (dam < 0)
	    return;
	if (ntargets > 2)
	    dam /= ntargets / 2;

	pr("\nCAPTAIN!  !!Depth charges!!...\n");
	if (sp->shp_own != 0)
	    wu(0, sp->shp_own,
	       "%s depth charged %s\n", prship(sp), prsub(targ));
	pr("click...WHAM!  %d damage!\n", dam);
    }
    shipdamage(targ, dam);
    putship(targ->shp_uid, targ);
}
예제 #12
0
파일: plnsub.c 프로젝트: fstltna/empserver
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;
	}
    }
}
예제 #13
0
void
report_god_gives(char *prefix, char *what, natid to)
{
    if (to && to != player->cnum) {
	wu(0, to, "%s%s given to you by an act of %s!\n",
	   prefix, what, cname(player->cnum));
	nreport_divine_aid(to, 1);
    }
}
예제 #14
0
void
report_god_takes(char *prefix, char *what, natid from)
{
    if (from && from != player->cnum) {
	wu(0, from, "%s%s taken from you by an act of %s!\n",
	   prefix, what, cname(player->cnum));
	nreport_divine_aid(from, -1);
    }
}
예제 #15
0
static int
cons_postpone(struct ltcomstr *ltcp)
{
    pr("%s %d is still pending.\n", ltcp->Name, ltcp->num);
    if (ltcp->proposee == player->cnum)
	wu(0, ltcp->proposer, "%s %d considered by %s\n",
	   ltcp->name, ltcp->num, cname(player->cnum));
    return RET_OK;
}
예제 #16
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;
    }
}
예제 #17
0
/*
 * Post-processing after successful acceptance of loan.
 * Notify the press, and the folks involved.
 * (Weird spelling is to avoid accept(2)).
 */
static void
accpt(struct ltcomstr *ltcp)
{
    switch (ltcp->type) {
    case EF_LOAN:
	nreport(ltcp->proposer, N_MAKE_LOAN, player->cnum, 1);
	break;
    default:
	CANT_REACH();
    }
    wu(0, ltcp->mailee, "%s #%d accepted by %s\n",
       ltcp->Name, ltcp->num, cname(player->cnum));
}
예제 #18
0
 void KVRecordStoreCapped::temp_cappedTruncateAfter(OperationContext* txn,
                                                    RecordId end,
                                                    bool inclusive) {
     WriteUnitOfWork wu( txn );
     // Not very efficient, but it should only be used by tests.
     for (boost::scoped_ptr<RecordIterator> iter(KVRecordStore::getIterator(txn, end)); !iter->isEOF(); ) {
         RecordId loc = iter->getNext();
         if (!inclusive && loc == end) {
             continue;
         }
         deleteRecord(txn, loc);
     }
     wu.commit();
 }
예제 #19
0
static void
divine_load_unload(struct empobj *unit, int type, int uid, char *act)
{
    if (uid < 0)
	return;

    pr("%s %s %s #%d\n",
       unit_nameof(unit), act, ef_nameof(type), uid);
    if (unit->own && unit->own != player->cnum)
	wu(0, unit->own,
	   "%s %s %s #%d by an act of %s!\n",
	   unit_nameof(unit), act, ef_nameof(type), uid,
	   cname(player->cnum));
    /* carrier owner could differ; can't be bothered to report to him */
}
예제 #20
0
    void RocksRecordStore::temp_cappedTruncateAfter( OperationContext* txn,
                                                     DiskLoc end,
                                                     bool inclusive ) {
        boost::scoped_ptr<RecordIterator> iter(
                getIterator( txn, maxDiskLoc, false, CollectionScanParams::BACKWARD ) );

        while( !iter->isEOF() ) {
            WriteUnitOfWork wu( txn );
            DiskLoc loc = iter->getNext();
            if ( loc < end || ( !inclusive && loc == end))
                return;

            deleteRecord( txn, loc );
            wu.commit();
        }
    }
예제 #21
0
/*
 * Print complete lines to country @cn similar to printf().
 * Use printf-style @format with the optional arguments.  @format must
 * end with '\n'.
 * If @cn is zero, don't print anything.
 * Else, if @cn is the current player and we're not in the update,
 * print just like pr().  Else print into a bulletin.
 * Because printing like pr() requires normal text, and bulletins
 * require user text, only plain ASCII is allowed.
 */
void
mpr(int cn, char *format, ...)
{
    char buf[4096];
    va_list ap;

    CANT_HAPPEN(!format[0] || format[strlen(format) - 1] != '\n');
    if (!cn)
	return;
    va_start(ap, format);
    (void)vsprintf(buf, format, ap);
    va_end(ap);
    if (update_running || cn != player->cnum)
	wu(0, cn, "%s", buf);
    else
	pr_player(player, C_DATA, buf);
}
예제 #22
0
vector<WorkUnit> WorkUnit::available_wus() {
    fs::path data_path(_data_dir);
    std::vector<WorkUnit> wus;

    if (fs::exists(data_path)) {
        if (fs::is_directory(data_path)) {
            for (auto p = fs::directory_iterator(data_path); p != fs::directory_iterator(); ++p) {
                if (fs::is_directory(p->path())) {
                    WorkUnit wu(p->path());
                    wus.push_back(wu);
                }
            }
        } else
            throw std::runtime_error(boost::str(boost::format("%1% exists, but is not a directory.") % data_path));
    } else
        throw std::runtime_error(boost::str(boost::format("%1% does not exist.") % data_path));

    return wus;

}
TEST_F(WiredTigerRecoveryUnitTestFixture, CreateAndCheckForCachePressure) {
    int time = 1;

    // Reconfigure the size of the cache to be very small so that building cache pressure is fast.
    WiredTigerKVEngine* engine = harnessHelper->getEngine();
    std::string cacheSizeReconfig = "cache_size=1MB";
    ASSERT_EQ(engine->reconfigure(cacheSizeReconfig.c_str()), 0);

    OperationContext* opCtx = clientAndCtx1.second.get();
    std::unique_ptr<RecordStore> rs(harnessHelper->createRecordStore(opCtx, "a.b"));

    // Insert one document so that we can then update it in a loop to create cache pressure.
    // Note: inserts will not create cache pressure.
    WriteUnitOfWork wu(opCtx);
    ASSERT_OK(ru1->setTimestamp(Timestamp(time++)));
    std::string str = str::stream() << "foobarbaz";
    StatusWith<RecordId> ress = rs->insertRecord(opCtx, str.c_str(), str.size() + 1, Timestamp());
    ASSERT_OK(ress.getStatus());
    auto recordId = ress.getValue();
    wu.commit();

    for (int j = 0; j < 1000; ++j) {
        // Once we hit the cache pressure threshold, i.e. have successfully created cache pressure
        // that is detectable, we are done.
        if (engine->isCacheUnderPressure(opCtx)) {
            invariant(j != 0);
            break;
        }

        try {
            WriteUnitOfWork wuow(opCtx);
            ASSERT_OK(ru1->setTimestamp(Timestamp(time++)));
            std::string s = str::stream()
                << "abcbcdcdedefefgfghghihijijkjklklmlmnmnomopopqpqrqrsrststutuv" << j;
            ASSERT_OK(rs->updateRecord(opCtx, recordId, s.c_str(), s.size() + 1));
            wuow.commit();
        } catch (const DBException& ex) {
            invariant(ex.toStatus().code() == ErrorCodes::WriteConflict);
        }
    }
}
예제 #24
0
파일: move_sat.c 프로젝트: gefla/empserver
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;
}
예제 #25
0
/*
 * Report deity meddling with @np.
 * Just like divine_sct_change(), only for nations.
 */
void
divine_nat_change(struct natstr *np, 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, prnat(np));
	return;
    }

    pr("%s of %s changed %s\n", name, prnat(np), buf);
    if (change > 0 && np->nat_cnum != player->cnum) {
	wu(0, np->nat_cnum, "%s changed %s by an act of %s!\n",
	   name, buf, cname(player->cnum));
	nreport_divine_aid(np->nat_cnum, goodness);
    }
}
예제 #26
0
/*
 * Report deity meddling with @unit.
 * Just like divine_sct_change(), only for ships, planes, land units,
 * nukes.
 */
void
divine_unit_change(struct empobj *unit, 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, unit_nameof(unit));
	return;
    }

    pr("%s of %s changed %s\n", name, unit_nameof(unit), buf);
    if (change > 0 && unit->own && unit->own != player->cnum) {
	wu(0, unit->own, "%s of %s changed %s by an act of %s\n",
	   name, unit_nameof(unit), buf, cname(player->cnum));
	nreport_divine_aid(unit->own, goodness);
    }
}
예제 #27
0
/* load a specific ship given its
 * location and what field to modify.
 * new autonav code
 * Chad Zabel 6/1/94
 */
int
load_it(struct shpstr *sp, struct sctstr *psect, int i)
{
    int shipown, amount, ship_amt, sect_amt;
    int abs_max, max_amt, transfer;
    i_type comm;
    struct mchrstr *vship;

    amount = sp->shp_lend[i];
    shipown = sp->shp_own;
    comm = sp->shp_tend[i];
    if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX))
	return 0;

    ship_amt = sp->shp_item[comm];
    sect_amt = psect->sct_item[comm];

    /* check for disloyal civilians */
    if (psect->sct_oldown != shipown && comm == I_CIVIL) {
	wu(0, shipown,
	   "Ship #%d - unable to load disloyal civilians at %s.",
	   sp->shp_uid, xyas(psect->sct_x, psect->sct_y, shipown));
	return 0;
    }
    if (comm == I_CIVIL || comm == I_MILIT)
	sect_amt--;		/* leave 1 civ or mil to hold the sector. */
    vship = &mchr[(int)sp->shp_type];
    abs_max = max_amt = vship->m_item[comm];

    if (!abs_max)
	return 0;		/* can't load the ship, skip to the end. */

    max_amt = MIN(sect_amt, max_amt - ship_amt);
    if (max_amt <= 0 && (ship_amt != abs_max)) {
	sp->shp_autonav |= AN_LOADING;
	return 0;
    }


    transfer = amount - ship_amt;
    if (transfer > sect_amt) {	/* not enough in the   */
	transfer = sect_amt;	/* sector to fill the  */
	sp->shp_autonav |= AN_LOADING;	/* ship, set load flag */
    }
    if (ship_amt + transfer > abs_max)	/* Do not load more    */
	transfer = abs_max - ship_amt;	/* then the max alowed */
    /* on the ship.        */

    if (transfer <= 0)
	return 0;		/* nothing to move */


    sp->shp_item[comm] = ship_amt + transfer;
    if (comm == I_CIVIL || comm == I_MILIT)
	sect_amt++;		/*adjustment */
    psect->sct_item[comm] = sect_amt - transfer;

    /* deal with the plague */
    if (psect->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
	sp->shp_pstage = PLG_EXPOSED;
    if (sp->shp_pstage == PLG_INFECT && psect->sct_pstage == PLG_HEALTHY)
	psect->sct_pstage = PLG_EXPOSED;

    return 1;			/* we did someloading return 1 to keep */
    /* our loop happy in nav_ship()        */

}
예제 #28
0
int
sona(void)
{
    struct nstr_item ni, nit;
    struct sctstr sect;
    struct shpstr ship;
    struct shpstr targ;
    struct natstr *natp;
    struct mchrstr *mcp;
    struct mchrstr *tmcp;
    struct nstr_sect ns;
    int range;
    int visib, pingrange;
    int srange;
    int vrange;
    int dist;
    int x, y;
    int cx, cy;
    int changed = 0;
    int row;
    /* Where these are used are non-re-entrant, so we keep 'em around */
    static char **rad = NULL;
    static char *radbuf = NULL;
    static signed char **vis = NULL;
    static signed char *visbuf = NULL;

    if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
	return RET_SYN;
    if (!radbuf)
	radbuf = malloc(WORLD_Y * MAPWIDTH(1));
    if (!visbuf)
	visbuf = malloc(WORLD_Y * MAPWIDTH(1));
    if (!rad && radbuf) {
	rad = malloc(WORLD_Y * sizeof(char *));
	if (rad) {
	    for (x = 0; x < WORLD_Y; x++) {
		rad[x] = &radbuf[(WORLD_X + 1) * x];
	    }
	}
    }
    if (!vis && visbuf) {
	vis = malloc(WORLD_Y * sizeof(signed char *));
	if (vis) {
	    for (x = 0; x < WORLD_Y; x++) {
		vis[x] = &visbuf[(WORLD_X + 1) * x];
	    }
	}
    }
    if (!radbuf || !visbuf || !rad || !vis) {
	pr("Memory error, tell the deity.\n");
	logerror("malloc failed in sona\n");
	return RET_FAIL;
    }
    while (nxtitem(&ni, &ship)) {
	if (!player->owner)
	    continue;
	mcp = &mchr[(int)ship.shp_type];
	if (!(mcp->m_flags & M_SONAR))
	    continue;
	getsect(ship.shp_x, ship.shp_y, &sect);
	if (sect.sct_type != SCT_WATER)
	    continue;
	range = (int)techfact(ship.shp_tech, mcp->m_vrnge);
	srange = MIN(7, 7 * range * ship.shp_effic / 200);
	pr("%s at %s efficiency %d%%, max range %d\n",
	   prship(&ship),
	   xyas(ship.shp_x, ship.shp_y, player->cnum),
	   ship.shp_effic, srange);
	snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange);
	blankfill(radbuf, &ns.range, 1);
	while (nxtsct(&ns, &sect)) {
	    if (player->owner || sect.sct_type == SCT_WATER)
		rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
	    else {
		rad[ns.dy][ns.dx] = '?';
	    }
	}
	snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange);
	cx = deltx(&ns.range, ship.shp_x);
	cy = delty(&ns.range, ship.shp_y);
	while (nxtsct(&ns, &sect)) {
	    if (!line_of_sight(rad, cx, cy, ns.dx, ns.dy)) {
		rad[ns.dy][ns.dx] = ' ';
		continue;
	    }
	    if (ship.shp_tech >= 310 && sect.sct_type == SCT_WATER) {
		if (sect.sct_mines) {
		    pr("Sonar detects %d mines in %s!\n",
		       sect.sct_mines,
		       xyas(sect.sct_x, sect.sct_y, player->cnum));
		    rad[ns.dy][ns.dx] = 'X';
		}
	    }
	    changed |= map_set(player->cnum, sect.sct_x, sect.sct_y,
			       rad[ns.dy][ns.dx], 0);

	}
	memset(visbuf, 0, (WORLD_Y * (WORLD_X + 1)));
	snxtitem_dist(&nit, EF_SHIP, ship.shp_x, ship.shp_y, range);
	while (nxtitem(&nit, &targ)) {
	    if (targ.shp_own == player->cnum || targ.shp_own == 0)
		continue;
	    tmcp = &mchr[(int)targ.shp_type];
	    visib = shp_visib(&targ);
	    pingrange = MIN(7, MAX(visib, 10) * range / 10);
	    vrange = pingrange * ship.shp_effic / 200;
	    dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y);
	    pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100;
	    if (dist > pingrange)
		continue;
	    if (tmcp->m_flags & M_SONAR && targ.shp_own) {
		natp = getnatp(targ.shp_own);
		if (natp->nat_flags & NF_SONAR)
		    wu(0, targ.shp_own,
		       "Sonar ping from %s detected by %s!\n",
		       xyas(ship.shp_x, ship.shp_y,
			    targ.shp_own), prship(&targ));
		if (targ.shp_rflags & RET_SONARED)
		    retreat_ship(&targ, targ.shp_own, 's');
	    }
	    if (dist > vrange)
		continue;
	    x = deltx(&ns.range, (int)targ.shp_x);
	    y = delty(&ns.range, (int)targ.shp_y);
	    if (rad[y][x] != dchr[SCT_WATER].d_mnem && rad[y][x] != 'X')
		continue;
	    if (tmcp->m_flags & M_SUB &&
		relations_with(targ.shp_own, player->cnum) < FRIENDLY) {
		if (mcp->m_vrnge + visib < 8)
		    pr("Sonar detects sub #%d @ %s\n",
		       targ.shp_uid,
		       xyas(targ.shp_x, targ.shp_y, player->cnum));
		else if (mcp->m_vrnge + visib < 10)
		    pr("Sonar detects %s @ %s\n",
		       prship(&targ),
		       xyas(targ.shp_x, targ.shp_y, player->cnum));
		else
		    pr("Sonar detects %s %s @ %s\n",
		       cname(targ.shp_own), prship(&targ),
		       xyas(targ.shp_x, targ.shp_y, player->cnum));
	    } else
		pr("Sonar detects %s %s @ %s\n",
		   cname(targ.shp_own), prship(&targ),
		   xyas(targ.shp_x, targ.shp_y, player->cnum));

	    if (visib > vis[y][x]) {
		vis[y][x] = visib;
		/* &~0x20 makes it a cap letter */
		rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20;
	    }
	}
	if (!player->argp[2]) {
	    rad[cy][cx] = '0';
	    for (row = 0; row < ns.range.height; row++)
		if (!blankrow(rad[row]))
		    pr("%s\n", rad[row]);
	}
	pr("\n");

    }
    if (changed)
	writemap(player->cnum);
    return RET_OK;
}
예제 #29
0
void
plane_sona(struct emp_qelem *plane_list, int x, int y,
	   struct shiplist **head)
{
    struct plnstr *pp;
    struct plchrstr *pcp;
    struct mchrstr *tmcp;
    struct shpstr *targ, s;
    struct natstr *natp;
    struct emp_qelem *qp;
    struct emp_qelem *next;
    struct plist *ip;
    struct sctstr sect;
    int found = 0;
    int range, i, vis;
    int pingrange;
    int vrange;
    int dist;

    getsect(x, y, &sect);
    if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
	return;
    for (qp = plane_list->q_forw; qp != plane_list; qp = next) {
	next = qp->q_forw;
	ip = (struct plist *)qp;
	pp = &ip->plane;
	pcp = ip->pcp;
	if (!(pcp->pl_flags & P_A))	/* if it isn't an ASW plane */
	    continue;
	range = (int)techfact(pp->pln_tech, (100.0 - pln_acc(pp)) / 10.0);
	for (i = 0; getship(i, &s); i++) {
	    targ = &s;
	    if (targ->shp_own == pp->pln_own || targ->shp_own == 0)
		continue;
	    if (on_shiplist(targ->shp_uid, *head))
		continue;
	    tmcp = &mchr[(int)targ->shp_type];
	    if (!(tmcp->m_flags & M_SUB))
		continue;
	    if (!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
					    EF_SHIP)))
		continue;
	    vis = shp_visib(targ);
	    pingrange = MAX(vis, 10) * range / 10;
	    vrange = pingrange * (pp->pln_effic / 200.0);
	    dist = mapdist(targ->shp_x, targ->shp_y, x, y);
	    pingrange = (MAX(pingrange, 2) * targ->shp_effic);
	    pingrange = roundavg(pingrange / 100.0);
	    if (dist > pingrange)
		continue;
	    if (tmcp->m_flags & M_SONAR && targ->shp_own) {
		natp = getnatp(targ->shp_own);
		if (natp->nat_flags & NF_SONAR)
		    wu(0, targ->shp_own,
		       "Sonar ping from %s detected by %s!\n",
		       xyas(x, y, targ->shp_own), prship(targ));
	    }
	    if ((dist > vrange))
		continue;
	    add_shiplist(targ->shp_uid, head);
	    if (!found) {
		pr("Sonar contact in %s\n", xyas(x, y, player->cnum));
		found = 1;
	    }
	    if (relations_with(targ->shp_own, pp->pln_own) < FRIENDLY &&
		!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
					    EF_SHIP)))
		if (!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
						EF_SHIP)))
		    pr("sub #%d %s\n", targ->shp_uid,
		       xyas(targ->shp_x, targ->shp_y, player->cnum));
		else
		    pr("%s %s\n", prship(targ),
		       xyas(targ->shp_x, targ->shp_y, player->cnum));
	    else
		pr("%s %s @ %s\n", cname(targ->shp_own), prship(targ),
		   xyas(targ->shp_x, targ->shp_y, player->cnum));
	}
    }
    if (found)
	pr("\n");
}
예제 #30
0
파일: repa.c 프로젝트: gefla/empserver
int
repa(void)
{
    struct lonstr loan;
    struct natstr *natp;
    struct natstr *loaner;
    int loan_num;
    int payment;
    int newdue;
    char *cp;
    time_t now;
    char buf[1024];

    if (!opt_LOANS) {
	pr("Loans are not enabled.\n");
	return RET_FAIL;
    }
    natp = getnatp(player->cnum);
    cp = getstarg(player->argp[1], "Repay loan #? ", buf);
    if (!cp)
	return RET_SYN;
    loan_num = atoi(cp);
    if (loan_num < 0)
	return RET_SYN;
    if (!getloan(loan_num, &loan) || loan.l_lonee != player->cnum
	|| loan.l_status != LS_SIGNED) {
	pr("You don't owe anything on that loan.\n");
	return RET_FAIL;
    }
    if (!(cp = getstarg(player->argp[2], "amount? ", buf)))
	return RET_SYN;
    if (!check_loan_ok(&loan))
	return RET_FAIL;
    payment = atoi(cp);
    if (payment <= 0)
	return RET_SYN;

    newdue = (int)ceil(loan_owed(&loan, time(&now)) - payment);
    if (newdue < 0) {
	pr("You don't owe that much.\n");
	return RET_FAIL;
    }
    if (natp->nat_money < payment) {
	pr("You only have $%d.\n", natp->nat_money);
	return RET_FAIL;
    }
    player->dolcost += payment;
    loaner = getnatp(loan.l_loner);
    loaner->nat_money += payment;
    putnat(loaner);
    loan.l_lastpay = now;
    if (newdue == 0) {
	wu(0, loan.l_loner, "Country #%d paid off loan #%d with $%d\n",
	   player->cnum, loan_num, payment);
	nreport(player->cnum, N_REPAY_LOAN, loan.l_loner, 1);
	loan.l_status = LS_FREE;
	loan.l_ldur = 0;
	pr("Congratulations, you've paid off the loan!\n");
    } else {
	wu(0, loan.l_loner,
	   "Country #%d paid $%d on loan %d\n",
	   player->cnum, payment, loan_num);
	loan.l_amtdue = newdue;
	loan.l_amtpaid += payment;
    }
    if (!putloan(loan_num, &loan)) {
	logerror("repa: can't write loan");
	pr("Can't save loan; get help!\n");
	return RET_FAIL;
    }
    return RET_OK;
}