]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/mark.c
Update copyright notice
[empserver] / src / lib / commands / mark.c
index 94b326c554c3b7494d6fbcd061a9448ef161c197..742f02e0fd2b456d87915d5c1f76ece4f900417f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  mark.c: Display report for commodities
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Pat Loney, 1992
  *     Steve McClure, 1996
  */
 
-#include "misc.h"
-#include "nat.h"
-#include "var.h"
-#include "item.h"
-#include "commodity.h"
-#include "player.h"
-#include "file.h"
+#include <config.h>
+
 #include "commands.h"
+#include "commodity.h"
+#include "item.h"
 #include "optlist.h"
 
 int
 mark(void)
 {
+    char buf[1024];
+    char *p;
+    struct ichrstr *ip;
+
     if (!opt_MARKET) {
        pr("The market is disabled.\n");
        return RET_FAIL;
     }
-    if (player->argp[1] && *(player->argp[1]))
-       return display_mark(player->argp[1]);
-    else
-       return display_mark("   ");
+
+    if (player->argp[1] && player->argp[1]) {
+       p = getstarg(player->argp[1], "What commodity (or 'all')? ", buf);
+       if (!p)
+           return RET_SYN;
+       if (!strcmp(p, "all"))
+           return display_mark(I_NONE, 0);
+       else {
+           ip = item_by_name(p);
+           if (!ip)
+               return RET_SYN;
+           return display_mark(ip->i_uid, 0);
+       }
+    }
+    return display_mark(I_NONE, 1);
 }
 
 static void
@@ -67,74 +79,51 @@ pr_mark(struct comstr *comm)
     if (tleft < 0.0)
        tleft = 0.0;
     pr(" %3d  $%12.2f  %2d  %5.2f hrs  (%3d)   %c    %6d  ",
-       comm->com_uid,
-       comm->com_maxprice,
-       comm->com_maxbidder,
-       tleft, comm->com_owner, comm->com_type, comm->com_amount);
+       comm->com_uid, comm->com_price, comm->com_maxbidder, 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(s_char *arg)
+display_mark(i_type only_itype, int only_cheapest)
 {
     struct comstr comm;
     struct comstr comm2;
     int sellers = 0;
     int cnt = 0;
-    char c;
-    s_char *p;
-    struct ichrstr *ip;
-    s_char buf[1024];
-    int cheapest_items[I_MAX + 2];
-    int i;
-    int all = 0;
+    int cheapest_items[I_MAX + 1];
+    i_type i;
 
-/* First, we execute all trades, so that we can only buy what is available. */
+    /* Execute trades so report lists only lots that are still available.  */
     check_market();
     check_trade();
 
-    p = getstarg(arg, "What commodity (or 'all')? ", buf);
-    c = (char)0;
-    if (p && *p)
-       c = *p;
-    for (ip = &ichr[0]; ip && ip->i_mnem; ip++)
-       if (ip->i_mnem == c)
-           break;
-    c = ip->i_mnem;
-
     pr("\n     Empire Market Report\n   ");
     prdate();
     pr(" lot  high bid/unit  by  time left  owner  item  amount  sector\n");
     pr(" ---  -------------  --  ---------  -----  ----  ------  ------\n");
 
-    if (arg) {
-       if (strcmp(arg, "all"))
-           all = 1;
-    }
-    if (all && !c) {
-       /* Ok, just printing the lowest of all of them */
-       for (i = 0; i < I_MAX + 2; i++)
+    if (only_cheapest) {
+       for (i = I_NONE + 1; i <= I_MAX; 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(comm.com_type <= I_NONE || comm.com_type > I_MAX))
                continue;
-           if (cheapest_items[i] != -1) {
-               getcomm(cheapest_items[i], &comm2);
-               if (comm.com_maxprice < comm2.com_maxprice) {
-                   cheapest_items[i] = sellers;
+           if (cheapest_items[comm.com_type] != -1) {
+               getcomm(cheapest_items[comm.com_type], &comm2);
+               if (comm.com_price < comm2.com_price) {
+                   cheapest_items[comm.com_type] = sellers;
                }
            } else {
-               cheapest_items[i] = sellers;
+               cheapest_items[comm.com_type] = sellers;
            }
        }
-       for (i = 0; i < I_MAX + 2; i++) {
+       CANT_HAPPEN(only_itype != I_NONE); /* not implemented */
+       for (i = I_NONE + 1; i <= I_MAX; i++) {
            if (cheapest_items[i] == -1)
                continue;
            getcomm(cheapest_items[i], &comm);
@@ -142,11 +131,10 @@ display_mark(s_char *arg)
            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 (c && comm.com_type != c)
+           if (only_itype != I_NONE && comm.com_type != only_itype)
                continue;
            cnt = 1;
            pr_mark(&comm);