(comstr, buy, check_market, display_mark, reset, sell): Change comstr
member com_type from mnemo character to item type. (whichitem): Unused, remove. (check_market): Use full item name instead of mnemo in telegrams. (display_mark): Separate arguments for item type and cheapest only. Cheapest only of specific item type is not implemented. (rese): Guard against bad com_type. Delete some code that had no effect.
This commit is contained in:
parent
988f9a8be7
commit
ca80c373bf
8 changed files with 35 additions and 59 deletions
|
@ -40,7 +40,7 @@ struct comstr {
|
||||||
short ef_type;
|
short ef_type;
|
||||||
natid com_owner;
|
natid com_owner;
|
||||||
short com_uid;
|
short com_uid;
|
||||||
char com_type;
|
int com_type;
|
||||||
int com_amount;
|
int com_amount;
|
||||||
float com_price;
|
float com_price;
|
||||||
int com_maxbidder;
|
int com_maxbidder;
|
||||||
|
|
|
@ -65,7 +65,7 @@ extern int check_market(void);
|
||||||
extern void set_coastal(struct sctstr *);
|
extern void set_coastal(struct sctstr *);
|
||||||
extern int sendmessage(struct natstr *, struct natstr *, char *, int);
|
extern int sendmessage(struct natstr *, struct natstr *, char *, int);
|
||||||
extern void gift(int, int, s_char *, int, s_char *);
|
extern void gift(int, int, s_char *, int, s_char *);
|
||||||
extern int display_mark(int what);
|
extern int display_mark(int, int);
|
||||||
extern int want_to_abandon(struct sctstr *, int, int, struct lndstr *);
|
extern int want_to_abandon(struct sctstr *, int, int, struct lndstr *);
|
||||||
extern int would_abandon(struct sctstr *, int, int, struct lndstr *);
|
extern int would_abandon(struct sctstr *, int, int, struct lndstr *);
|
||||||
extern int nav_map(int, int, int);
|
extern int nav_map(int, int, int);
|
||||||
|
|
|
@ -79,7 +79,6 @@ extern int trade_desc(struct trdstr *, union trdgenstr *);
|
||||||
extern int trade_getitem(struct trdstr *, union trdgenstr *);
|
extern int trade_getitem(struct trdstr *, union trdgenstr *);
|
||||||
extern long get_couval(int);
|
extern long get_couval(int);
|
||||||
extern long get_outstand(int);
|
extern long get_outstand(int);
|
||||||
extern struct ichrstr *whichitem(char);
|
|
||||||
|
|
||||||
#define gettrade(n, p) \
|
#define gettrade(n, p) \
|
||||||
ef_read(EF_TRADE, n, (caddr_t)p)
|
ef_read(EF_TRADE, n, (caddr_t)p)
|
||||||
|
|
|
@ -85,7 +85,7 @@ buy(void)
|
||||||
ip = whatitem(player->argp[1], "Commodity you want to buy: ");
|
ip = whatitem(player->argp[1], "Commodity you want to buy: ");
|
||||||
if (!ip)
|
if (!ip)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
display_mark(ip->i_mnem);
|
display_mark(ip->i_vtype, 0);
|
||||||
pr("\n");
|
pr("\n");
|
||||||
p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
|
p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
|
@ -99,7 +99,7 @@ buy(void)
|
||||||
pr("Invalid lot number.\n");
|
pr("Invalid lot number.\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
if (comm.com_type != ip->i_mnem) {
|
if (comm.com_type != ip->i_vtype) {
|
||||||
pr("That lot is not of the type you specified.\n");
|
pr("That lot is not of the type you specified.\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,6 @@ buy(void)
|
||||||
pr("That sector is under construction.\n");
|
pr("That sector is under construction.\n");
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
ip = whichitem(comm.com_type);
|
|
||||||
n = sect.sct_item[ip->i_vtype];
|
n = sect.sct_item[ip->i_vtype];
|
||||||
qty = comm.com_amount;
|
qty = comm.com_amount;
|
||||||
if (qty + n > ITEM_MAX) {
|
if (qty + n > ITEM_MAX) {
|
||||||
|
@ -212,7 +211,6 @@ check_market(void)
|
||||||
{
|
{
|
||||||
struct comstr comm;
|
struct comstr comm;
|
||||||
struct sctstr *sect;
|
struct sctstr *sect;
|
||||||
struct ichrstr *ip;
|
|
||||||
struct natstr *natp;
|
struct natstr *natp;
|
||||||
int m;
|
int m;
|
||||||
int n;
|
int n;
|
||||||
|
@ -239,9 +237,10 @@ check_market(void)
|
||||||
tleft = 0;
|
tleft = 0;
|
||||||
if (tleft > 0.0)
|
if (tleft > 0.0)
|
||||||
continue;
|
continue;
|
||||||
ip = whichitem(comm.com_type);
|
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
|
||||||
|
continue;
|
||||||
sect = getsectp(comm.com_x, comm.com_y);
|
sect = getsectp(comm.com_x, comm.com_y);
|
||||||
m = sect->sct_item[ip->i_vtype];
|
m = sect->sct_item[comm.com_type];
|
||||||
|
|
||||||
monleft = 0;
|
monleft = 0;
|
||||||
|
|
||||||
|
@ -342,16 +341,16 @@ check_market(void)
|
||||||
"Sale #%d fell through. Goods remain on the market.\n", n);
|
"Sale #%d fell through. Goods remain on the market.\n", n);
|
||||||
comm.com_maxbidder = comm.com_owner;
|
comm.com_maxbidder = comm.com_owner;
|
||||||
} else {
|
} else {
|
||||||
sect->sct_item[ip->i_vtype] = m + comm.com_amount;
|
sect->sct_item[comm.com_type] = m + comm.com_amount;
|
||||||
putsect(sect);
|
putsect(sect);
|
||||||
nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
|
nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
|
||||||
wu(0, comm.com_owner, "%s bought %d %c's from you for $%.2f\n",
|
wu(0, comm.com_owner, "%s bought %d %s from you for $%.2f\n",
|
||||||
cname(comm.com_maxbidder), comm.com_amount,
|
cname(comm.com_maxbidder), comm.com_amount,
|
||||||
comm.com_type, gain);
|
ichr[comm.com_type].i_name, gain);
|
||||||
wu(0, comm.com_maxbidder,
|
wu(0, comm.com_maxbidder,
|
||||||
"You just bought %d %c's from %s for $%.2f\n",
|
"You just bought %d %s from %s for $%.2f\n",
|
||||||
comm.com_amount, comm.com_type, cname(comm.com_owner),
|
comm.com_amount, ichr[comm.com_type].i_name,
|
||||||
gain * buytax);
|
cname(comm.com_owner), gain * buytax);
|
||||||
natp = getnatp(comm.com_owner);
|
natp = getnatp(comm.com_owner);
|
||||||
/* Make sure we subtract the amount that came out in a loan */
|
/* Make sure we subtract the amount that came out in a loan */
|
||||||
natp->nat_money += (gain - subleft);
|
natp->nat_money += (gain - subleft);
|
||||||
|
|
|
@ -60,15 +60,15 @@ mark(void)
|
||||||
if (!p)
|
if (!p)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
if (!strcmp(p, "all"))
|
if (!strcmp(p, "all"))
|
||||||
return display_mark(0);
|
return display_mark(I_NONE, 0);
|
||||||
else {
|
else {
|
||||||
ip = item_by_name(p);
|
ip = item_by_name(p);
|
||||||
if (!ip)
|
if (!ip)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
return display_mark(ip->i_mnem);
|
return display_mark(ip->i_vtype, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return display_mark(-1);
|
return display_mark(I_NONE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -85,20 +85,19 @@ pr_mark(struct comstr *comm)
|
||||||
comm->com_uid,
|
comm->com_uid,
|
||||||
comm->com_price,
|
comm->com_price,
|
||||||
comm->com_maxbidder,
|
comm->com_maxbidder,
|
||||||
tleft, comm->com_owner, comm->com_type, comm->com_amount);
|
tleft, comm->com_owner, ichr[comm->com_type].i_mnem, comm->com_amount);
|
||||||
if (comm->com_owner == player->cnum || player->god)
|
if (comm->com_owner == player->cnum || player->god)
|
||||||
pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
|
pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
|
||||||
pr("\n");
|
pr("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
display_mark(int what)
|
display_mark(int only_itype, int only_cheapest)
|
||||||
{
|
{
|
||||||
struct comstr comm;
|
struct comstr comm;
|
||||||
struct comstr comm2;
|
struct comstr comm2;
|
||||||
int sellers = 0;
|
int sellers = 0;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
struct ichrstr *ip;
|
|
||||||
int cheapest_items[I_MAX + 1];
|
int cheapest_items[I_MAX + 1];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -111,27 +110,24 @@ display_mark(int what)
|
||||||
pr(" lot high bid/unit by time left owner item amount sector\n");
|
pr(" lot high bid/unit by time left owner item amount sector\n");
|
||||||
pr(" --- ------------- -- --------- ----- ---- ------ ------\n");
|
pr(" --- ------------- -- --------- ----- ---- ------ ------\n");
|
||||||
|
|
||||||
if (what == -1) {
|
if (only_cheapest) {
|
||||||
/* Ok, just printing the lowest of all of them */
|
|
||||||
for (i = 0; i < I_MAX + 1; i++)
|
for (i = 0; i < I_MAX + 1; i++)
|
||||||
cheapest_items[i] = -1;
|
cheapest_items[i] = -1;
|
||||||
for (sellers = 0; getcomm(sellers, &comm); sellers++) {
|
for (sellers = 0; getcomm(sellers, &comm); sellers++) {
|
||||||
if (comm.com_owner == 0)
|
if (comm.com_owner == 0)
|
||||||
continue;
|
continue;
|
||||||
for (i = 0, ip = &ichr[0]; ip && ip->i_mnem; ip++, i++)
|
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
|
||||||
if (ip->i_mnem == comm.com_type)
|
|
||||||
break;
|
|
||||||
if (!ip->i_mnem)
|
|
||||||
continue;
|
continue;
|
||||||
if (cheapest_items[i] != -1) {
|
if (cheapest_items[comm.com_type] != -1) {
|
||||||
getcomm(cheapest_items[i], &comm2);
|
getcomm(cheapest_items[comm.com_type], &comm2);
|
||||||
if (comm.com_price < comm2.com_price) {
|
if (comm.com_price < comm2.com_price) {
|
||||||
cheapest_items[i] = sellers;
|
cheapest_items[comm.com_type] = sellers;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cheapest_items[i] = sellers;
|
cheapest_items[comm.com_type] = sellers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CANT_HAPPEN(only_itype != I_NONE); /* not implemented */
|
||||||
for (i = 0; i < I_MAX + 1; i++) {
|
for (i = 0; i < I_MAX + 1; i++) {
|
||||||
if (cheapest_items[i] == -1)
|
if (cheapest_items[i] == -1)
|
||||||
continue;
|
continue;
|
||||||
|
@ -140,11 +136,10 @@ display_mark(int what)
|
||||||
pr_mark(&comm);
|
pr_mark(&comm);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Ok, print them all, or all of this type */
|
|
||||||
for (sellers = 0; getcomm(sellers, &comm); sellers++) {
|
for (sellers = 0; getcomm(sellers, &comm); sellers++) {
|
||||||
if (comm.com_owner == 0)
|
if (comm.com_owner == 0)
|
||||||
continue;
|
continue;
|
||||||
if (what && comm.com_type != what)
|
if (only_itype != I_NONE && comm.com_type != only_itype)
|
||||||
continue;
|
continue;
|
||||||
cnt = 1;
|
cnt = 1;
|
||||||
pr_mark(&comm);
|
pr_mark(&comm);
|
||||||
|
|
|
@ -57,7 +57,6 @@ rese(void)
|
||||||
{
|
{
|
||||||
struct comstr comm;
|
struct comstr comm;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
struct ichrstr *ix;
|
|
||||||
int number_set;
|
int number_set;
|
||||||
int m;
|
int m;
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -117,18 +116,19 @@ rese(void)
|
||||||
pr("The destination sector must be at least 60%% efficient.\n");
|
pr("The destination sector must be at least 60%% efficient.\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
ix = whichitem(comm.com_type);
|
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX)) {
|
||||||
sect.sct_x = comm.sell_x;
|
pr("The goods have been eaten by a grue.");
|
||||||
sect.sct_y = comm.sell_y;
|
return RET_OK;
|
||||||
m = sect.sct_item[ix->i_vtype];
|
}
|
||||||
|
m = sect.sct_item[comm.com_type];
|
||||||
m = m + comm.com_amount;
|
m = m + comm.com_amount;
|
||||||
if (m > ITEM_MAX)
|
if (m > ITEM_MAX)
|
||||||
m = ITEM_MAX;
|
m = ITEM_MAX;
|
||||||
sect.sct_item[ix->i_vtype] = m;
|
sect.sct_item[comm.com_type] = m;
|
||||||
putsect(§);
|
putsect(§);
|
||||||
comm.com_owner = 0;
|
comm.com_owner = 0;
|
||||||
putcomm(number_set, &comm);
|
putcomm(number_set, &comm);
|
||||||
pr("The goods have been returned to your trading post\n");
|
pr("The goods have been returned to your trading post.\n");
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
if (price >= comm.com_price) {
|
if (price >= comm.com_price) {
|
||||||
|
|
|
@ -73,7 +73,6 @@ sell(void)
|
||||||
int com;
|
int com;
|
||||||
char *p;
|
char *p;
|
||||||
float price;
|
float price;
|
||||||
char cc;
|
|
||||||
time_t now;
|
time_t now;
|
||||||
int ii = 0;
|
int ii = 0;
|
||||||
coord x, y;
|
coord x, y;
|
||||||
|
@ -85,8 +84,7 @@ sell(void)
|
||||||
}
|
}
|
||||||
check_market();
|
check_market();
|
||||||
check_trade();
|
check_trade();
|
||||||
if ((ip =
|
if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
|
||||||
whatitem(player->argp[1], "Commodity you want to sell: ")) == 0)
|
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
if (ip->i_sell == 0) {
|
if (ip->i_sell == 0) {
|
||||||
pr("You can't sell %s\n", ip->i_name);
|
pr("You can't sell %s\n", ip->i_name);
|
||||||
|
@ -165,7 +163,6 @@ sell(void)
|
||||||
pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
|
pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
|
||||||
xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
|
xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
|
||||||
sect.sct_item[ip->i_vtype] = amt;
|
sect.sct_item[ip->i_vtype] = amt;
|
||||||
cc = ip->i_mnem;
|
|
||||||
putsect(§);
|
putsect(§);
|
||||||
if (totalcom > 0) {
|
if (totalcom > 0) {
|
||||||
for (ii = 0; getcomm(ii, &comm); ii++) {
|
for (ii = 0; getcomm(ii, &comm); ii++) {
|
||||||
|
@ -175,7 +172,7 @@ sell(void)
|
||||||
if (getcomm(ii, &comm) == 0)
|
if (getcomm(ii, &comm) == 0)
|
||||||
ef_extend(EF_COMM, 1);
|
ef_extend(EF_COMM, 1);
|
||||||
(void)time(&now);
|
(void)time(&now);
|
||||||
comm.com_type = ip->i_mnem;
|
comm.com_type = ip->i_vtype;
|
||||||
comm.com_owner = player->cnum;
|
comm.com_owner = player->cnum;
|
||||||
comm.com_price = price;
|
comm.com_price = price;
|
||||||
comm.com_maxbidder = player->cnum;
|
comm.com_maxbidder = player->cnum;
|
||||||
|
|
|
@ -282,17 +282,3 @@ get_outstand(int cnum)
|
||||||
}
|
}
|
||||||
return loantot;
|
return loantot;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ichrstr *
|
|
||||||
whichitem(char p)
|
|
||||||
{
|
|
||||||
register int i;
|
|
||||||
|
|
||||||
if (p == 0)
|
|
||||||
return 0;
|
|
||||||
for (i = 1; ichr[i].i_mnem != 0; i++)
|
|
||||||
if (p == ichr[i].i_mnem)
|
|
||||||
return (struct ichrstr *)(&ichr[i]);
|
|
||||||
pr("Unrecognized item \"%c\"\n", p);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue