]> git.pond.sub.org Git - empserver/commitdiff
(comstr, buy, check_market, display_mark, reset, sell): Change comstr
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 10 Apr 2004 18:48:30 +0000 (18:48 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 10 Apr 2004 18:48:30 +0000 (18:48 +0000)
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.

include/commodity.h
include/prototypes.h
include/trade.h
src/lib/commands/buy.c
src/lib/commands/mark.c
src/lib/commands/rese.c
src/lib/commands/sell.c
src/lib/subs/trdsub.c

index 5fb31a4e674d8a9e9bfaaefc44d0ac170eb02bf6..5826d88caa0e6fee78f616f4a619210db79ef11d 100644 (file)
@@ -40,7 +40,7 @@ struct comstr {
     short ef_type;
     natid com_owner;
     short com_uid;
-    char com_type;
+    int com_type;
     int com_amount;
     float com_price;
     int com_maxbidder;
index da28cf2163dacf7734296cdd24ff9b966e7b8a5e..ea92ef95cf9405a4c61efa73879681564ad02e17 100644 (file)
@@ -65,7 +65,7 @@ extern int check_market(void);
 extern void set_coastal(struct sctstr *);
 extern int sendmessage(struct natstr *, struct natstr *, char *, int);
 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 would_abandon(struct sctstr *, int, int, struct lndstr *);
 extern int nav_map(int, int, int);
index d2ab6d21c41706f0deb3b76fc1256ae0aed32c56..9f4bab776a8c9f7d275665e8c0371872723595d9 100644 (file)
@@ -79,7 +79,6 @@ extern int trade_desc(struct trdstr *, union trdgenstr *);
 extern int trade_getitem(struct trdstr *, union trdgenstr *);
 extern long get_couval(int);
 extern long get_outstand(int);
-extern struct ichrstr *whichitem(char);
 
 #define gettrade(n, p) \
        ef_read(EF_TRADE, n, (caddr_t)p)
index 4e67adaf6089dbfd373fb24403646e034f33f88b..5e1f0104410e29b37b30e660a8b4d7bd74be04de 100644 (file)
@@ -85,7 +85,7 @@ buy(void)
     ip = whatitem(player->argp[1], "Commodity you want to buy: ");
     if (!ip)
        return RET_SYN;
-    display_mark(ip->i_mnem);
+    display_mark(ip->i_vtype, 0);
     pr("\n");
     p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
     if (p == 0)
@@ -99,7 +99,7 @@ buy(void)
        pr("Invalid lot number.\n");
        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");
        return RET_OK;
     }
@@ -162,7 +162,6 @@ buy(void)
        pr("That sector is under construction.\n");
        return RET_FAIL;
     }
-    ip = whichitem(comm.com_type);
     n = sect.sct_item[ip->i_vtype];
     qty = comm.com_amount;
     if (qty + n > ITEM_MAX) {
@@ -212,7 +211,6 @@ check_market(void)
 {
     struct comstr comm;
     struct sctstr *sect;
-    struct ichrstr *ip;
     struct natstr *natp;
     int m;
     int n;
@@ -239,9 +237,10 @@ check_market(void)
            tleft = 0;
        if (tleft > 0.0)
            continue;
-       ip = whichitem(comm.com_type);
+       if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
+           continue;
        sect = getsectp(comm.com_x, comm.com_y);
-       m = sect->sct_item[ip->i_vtype];
+       m = sect->sct_item[comm.com_type];
 
        monleft = 0;
 
@@ -342,16 +341,16 @@ check_market(void)
               "Sale #%d fell through.  Goods remain on the market.\n", n);
            comm.com_maxbidder = comm.com_owner;
        } else {
-           sect->sct_item[ip->i_vtype] = m + comm.com_amount;
+           sect->sct_item[comm.com_type] = m + comm.com_amount;
            putsect(sect);
            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,
-              comm.com_type, gain);
+              ichr[comm.com_type].i_name, gain);
            wu(0, comm.com_maxbidder,
-              "You just bought %d %c's from %s for $%.2f\n",
-              comm.com_amount, comm.com_type, cname(comm.com_owner),
-              gain * buytax);
+              "You just bought %d %s from %s for $%.2f\n",
+              comm.com_amount, ichr[comm.com_type].i_name,
+              cname(comm.com_owner), gain * buytax);
            natp = getnatp(comm.com_owner);
            /* Make sure we subtract the amount that came out in a loan */
            natp->nat_money += (gain - subleft);
index 8b7af97ce6328f094b4b962a0ab88abec06787e9..6cf75e4c8a84ec413070f58f2d39403baa0c8a98 100644 (file)
@@ -60,15 +60,15 @@ mark(void)
        if (!p)
            return RET_SYN;
        if (!strcmp(p, "all"))
-           return display_mark(0);
+           return display_mark(I_NONE, 0);
        else {
            ip = item_by_name(p);
            if (!ip)
                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
@@ -85,20 +85,19 @@ pr_mark(struct comstr *comm)
        comm->com_uid,
        comm->com_price,
        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)
        pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
     pr("\n");
 }
 
 int
-display_mark(int what)
+display_mark(int only_itype, int only_cheapest)
 {
     struct comstr comm;
     struct comstr comm2;
     int sellers = 0;
     int cnt = 0;
-    struct ichrstr *ip;
     int cheapest_items[I_MAX + 1];
     int i;
 
@@ -111,27 +110,24 @@ display_mark(int what)
     pr(" lot  high bid/unit  by  time left  owner  item  amount  sector\n");
     pr(" ---  -------------  --  ---------  -----  ----  ------  ------\n");
 
-    if (what == -1) {
-       /* Ok, just printing the lowest of all of them */
+    if (only_cheapest) {
        for (i = 0; i < I_MAX + 1; i++)
            cheapest_items[i] = -1;
        for (sellers = 0; getcomm(sellers, &comm); sellers++) {
            if (comm.com_owner == 0)
                continue;
-           for (i = 0, ip = &ichr[0]; ip && ip->i_mnem; ip++, i++)
-               if (ip->i_mnem == comm.com_type)
-                   break;
-           if (!ip->i_mnem)
+           if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
                continue;
-           if (cheapest_items[i] != -1) {
-               getcomm(cheapest_items[i], &comm2);
+           if (cheapest_items[comm.com_type] != -1) {
+               getcomm(cheapest_items[comm.com_type], &comm2);
                if (comm.com_price < comm2.com_price) {
-                   cheapest_items[i] = sellers;
+                   cheapest_items[comm.com_type] = sellers;
                }
            } 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++) {
            if (cheapest_items[i] == -1)
                continue;
@@ -140,11 +136,10 @@ display_mark(int what)
            pr_mark(&comm);
        }
     } else {
-       /* Ok, print them all, or all of this type */
        for (sellers = 0; getcomm(sellers, &comm); sellers++) {
            if (comm.com_owner == 0)
                continue;
-           if (what && comm.com_type != what)
+           if (only_itype != I_NONE && comm.com_type != only_itype)
                continue;
            cnt = 1;
            pr_mark(&comm);
index b76ae7b7f727cab29f2c7f115be8741aa70241c8..90e603a649faa386a949cfe652921bb6fdad2325 100644 (file)
@@ -57,7 +57,6 @@ rese(void)
 {
     struct comstr comm;
     struct sctstr sect;
-    struct ichrstr *ix;
     int number_set;
     int m;
     char *p;
@@ -117,18 +116,19 @@ rese(void)
            pr("The destination sector must be at least 60%% efficient.\n");
            return RET_OK;
        }
-       ix = whichitem(comm.com_type);
-       sect.sct_x = comm.sell_x;
-       sect.sct_y = comm.sell_y;
-       m = sect.sct_item[ix->i_vtype];
+       if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX)) {
+           pr("The goods have been eaten by a grue.");
+           return RET_OK;
+       }
+       m = sect.sct_item[comm.com_type];
        m = m + comm.com_amount;
        if (m > ITEM_MAX)
            m = ITEM_MAX;
-       sect.sct_item[ix->i_vtype] = m;
+       sect.sct_item[comm.com_type] = m;
        putsect(&sect);
        comm.com_owner = 0;
        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;
     }
     if (price >= comm.com_price) {
index e77715bf1bc04b1d72be1eb50b602ce933c856ad..572e76faa3cb53ebf1423e85ffa890f11dfe19bc 100644 (file)
@@ -73,7 +73,6 @@ sell(void)
     int com;
     char *p;
     float price;
-    char cc;
     time_t now;
     int ii = 0;
     coord x, y;
@@ -85,8 +84,7 @@ sell(void)
     }
     check_market();
     check_trade();
-    if ((ip =
-        whatitem(player->argp[1], "Commodity you want to sell: ")) == 0)
+    if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
        return RET_SYN;
     if (ip->i_sell == 0) {
        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,
        xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
     sect.sct_item[ip->i_vtype] = amt;
-    cc = ip->i_mnem;
     putsect(&sect);
     if (totalcom > 0) {
        for (ii = 0; getcomm(ii, &comm); ii++) {
@@ -175,7 +172,7 @@ sell(void)
        if (getcomm(ii, &comm) == 0)
            ef_extend(EF_COMM, 1);
        (void)time(&now);
-       comm.com_type = ip->i_mnem;
+       comm.com_type = ip->i_vtype;
        comm.com_owner = player->cnum;
        comm.com_price = price;
        comm.com_maxbidder = player->cnum;
index 8512fc032a2a67e79093a459c1cf1741d2709f9b..e9990a435f73622d2757f63832da219d148579d9 100644 (file)
@@ -282,17 +282,3 @@ get_outstand(int cnum)
     }
     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;
-}