Exemple #1
0
/*
 * Choose whether we want to accept, decline, or postpone a
 * loan.  Put all the goodies in ltcp, and return
 * RET_OK if all goes well, and anything else on error.
 */
static int
cons_choose(struct ltcomstr *ltcp)
{
    static int lon_or_trt[] = { EF_LOAN, EF_BAD };
    char *p;
    struct lonstr *lp;
    char prompt[128];
    char buf[1024];

    memset(ltcp, 0, sizeof(*ltcp));
    p = player->argp[1] ? player->argp[1] : "loan";
    ltcp->type = ef_byname_from(p, lon_or_trt);
    switch (ltcp->type) {
    case EF_LOAN:
	if (!opt_LOANS) {
	    pr("Loans are not enabled.\n");
	    return RET_FAIL;
	}
	ltcp->name = "loan";
	ltcp->Name = "Loan";
	break;
    default:
	pr("You must specify \"loan\".\n");
	return RET_SYN;
    }
    sprintf(prompt, "%s number? ", ltcp->Name);
    if ((ltcp->num = onearg(player->argp[2], prompt)) < 0)
	return RET_SYN;
    if (!ef_read(ltcp->type, ltcp->num, &ltcp->u) || !cons_display(ltcp)) {
	pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num);
	return RET_SYN;
    }
    switch (ltcp->type) {
    case EF_LOAN:
	lp = &ltcp->u.l;
	if (lp->l_status == LS_SIGNED) {
	    pr("That loan has already been accepted!\n");
	    return RET_FAIL;
	}
	ltcp->proposer = lp->l_loner;
	ltcp->proposee = lp->l_lonee;
	break;
    }
    ltcp->mailee = (ltcp->proposer == player->cnum)
	? ltcp->proposee : ltcp->proposer;
    p = getstarg(player->argp[3], "Accept, decline or postpone? ", buf);
    if (!p || (*p != 'a' && *p != 'd' && *p != 'p'))
	return RET_SYN;
    ltcp->op = *p;
    return RET_OK;
}
Exemple #2
0
int
sate(void)
{
    static int sct_shp_or_lnd[] = { EF_SECTOR, EF_SHIP, EF_LAND, EF_BAD };
    double tech;
    int pln_uid;
    struct plnstr plane;
    int type = EF_BAD;

    if (!player->argp[1] ||
	!*player->argp[1] ||
	!isdigit(*player->argp[1]) ||
	(pln_uid = atoi(player->argp[1])) < 0)
	return RET_SYN;

    if (!getplane(pln_uid, &plane)) {
	pr("No such plane\n");
	return RET_FAIL;
    }

    if (plane.pln_own != player->cnum && !player->god) {
	pr("You don't own plane #%d\n", pln_uid);
	return RET_FAIL;
    }

    if (!pln_is_in_orbit(&plane)) {
	pr("%s isn't in orbit\n", prplane(&plane));
	return RET_FAIL;
    }
    if (plane.pln_mobil < plane_mob_max) {
	pr("%s doesn't have enough mobility (needs %d)\n",
	   prplane(&plane), plane_mob_max);
	return RET_FAIL;
    }
    if (player->argp[2]) {
	type = ef_byname_from(player->argp[2], sct_shp_or_lnd);
	if (type < 0) {
	    return RET_SYN;
	}
    }

    if (plchr[(int)plane.pln_type].pl_flags & P_S)
	pr("Satellite Spy Report:\n");
    else
	pr("Satellite Map Report:\n");
    pr("%s at ", prplane(&plane));
    tech = techfact(plane.pln_tech, 20.0);
    return satmap(plane.pln_x, plane.pln_y, plane.pln_effic,
		  (int)tech, plchr[(int)plane.pln_type].pl_flags, type);
}
Exemple #3
0
/*
 * format: set <type> <SHIP/NUKE> <PRICE>
 */
int
set(void)
{
    static int ef_saleable[] = { EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD };
    char *p;
    int type;
    int price;
    char prompt[80];
    struct trdstr trade;
    struct nstr_item ni;
    struct nstr_item ni_trade;
    union empobj_storage item;
    struct sctstr sect;
    int freeslot;
    int foundslot;
    int id;
    time_t now;
    char buf[1024];

    if (!opt_MARKET) {
	pr("The market is disabled.\n");
	return RET_FAIL;
    }
    check_market();
    check_trade();

    p = getstarg(player->argp[1], "Ship, plane, land unit or nuke? ", buf);
    if (!p)
	return RET_SYN;
    if ((type = ef_byname_from(p, ef_saleable)) < 0) {
	pr("You can sell only ships, planes, land units or nukes\n");
	return RET_SYN;
    }
    if (!snxtitem(&ni, type, player->argp[2], NULL))
	return RET_SYN;
    while (nxtitem(&ni, &item)) {
	if (!player->owner && !player->god)
	    continue;
	getsect(item.gen.x, item.gen.y, &sect);
	if (!military_control(&sect)) {
	    pr("Military control required to sell goods.\n");
	    return RET_FAIL;
	}
	trade.trd_type = type;
	sprintf(prompt, "%s #%d; price? ",
		trade_nameof(&trade, &item.gen), ni.cur);
	if (!(p = getstarg(player->argp[3], prompt, buf)))
	    return RET_FAIL;
	if (!check_obj_ok(&item.gen))
	    return RET_FAIL;
	if ((price = atoi(p)) < 0)
	    continue;
	foundslot = -1;
	freeslot = -1;
	snxtitem_all(&ni_trade, EF_TRADE);
	while (nxtitem(&ni_trade, &trade)) {
	    if (trade.trd_owner == 0)
		freeslot = ni_trade.cur;
	    if (trade.trd_unitid == ni.cur && trade.trd_type == type) {
		foundslot = ni_trade.cur;
		break;
	    }
	}
	if (price <= 0) {
	    if (foundslot >= 0) {
		pr("%s #%d (lot #%d) removed from trading\n",
		   trade_nameof(&trade, &item.gen), ni.cur, foundslot);
		trade.trd_owner = 0;
		puttrade(ni_trade.cur, &trade);
	    }
	} else {
	    if (trade_has_unsalable_cargo(&item.gen, 1))
		return RET_FAIL;
	    if (foundslot >= 0)
		id = foundslot;
	    else if (freeslot >= 0)
		id = freeslot;
	    else
		id = ni_trade.cur;
	    ef_blank(EF_TRADE, id, &trade);
	    trade.trd_x = 1;
	    trade.trd_y = 0;
	    trade.trd_type = type;
	    trade.trd_owner = player->cnum;
	    trade.trd_unitid = ni.cur;
	    trade.trd_price = price;
	    (void)time(&now);
	    trade.trd_markettime = now;
	    trade.trd_maxbidder = player->cnum;
	    puttrade(id, &trade);
	    pr("%s #%d (lot #%d) price %s to $%d\n",
	       trade_nameof(&trade, &item.gen), ni.cur,
	       id, foundslot >= 0 ? "reset" : "set", price);
	}
    }
    return RET_OK;
}