]> git.pond.sub.org Git - empserver/blob - src/lib/commands/mark.c
(genitem, ship, plane, land): Remove unused member sell & equivalents.
[empserver] / src / lib / commands / mark.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  mark.c: Display report for commodities
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Pat Loney, 1992
33  *     Steve McClure, 1996
34  */
35
36 #include "misc.h"
37 #include "nat.h"
38 #include "var.h"
39 #include "item.h"
40 #include "commodity.h"
41 #include "player.h"
42 #include "file.h"
43 #include "commands.h"
44 #include "optlist.h"
45
46 int
47 mark(void)
48 {
49     if (!opt_MARKET) {
50         pr("The market is disabled.\n");
51         return RET_FAIL;
52     }
53     if (player->argp[1] && *(player->argp[1]))
54         return display_mark(player->argp[1]);
55     else
56         return display_mark("   ");
57 }
58
59 static void
60 pr_mark(struct comstr *comm)
61 {
62     time_t now;
63     double tleft;
64
65     (void)time(&now);
66     tleft = MARK_DELAY / 3600.0 - (now - comm->com_markettime) / 3600.0;
67     if (tleft < 0.0)
68         tleft = 0.0;
69     pr(" %3d  $%12.2f  %2d  %5.2f hrs  (%3d)   %c    %6d  ",
70        comm->com_uid,
71        comm->com_price,
72        comm->com_maxbidder,
73        tleft, comm->com_owner, comm->com_type, comm->com_amount);
74     if (comm->com_owner == player->cnum || player->god)
75         pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
76     pr("\n");
77 }
78
79 int
80 display_mark(s_char *arg)
81 {
82     struct comstr comm;
83     struct comstr comm2;
84     int sellers = 0;
85     int cnt = 0;
86     char c;
87     s_char *p;
88     struct ichrstr *ip;
89     s_char buf[1024];
90     int cheapest_items[I_MAX + 2];
91     int i;
92     int all = 0;
93
94 /* First, we execute all trades, so that we can only buy what is available. */
95     check_market();
96     check_trade();
97
98     p = getstarg(arg, "What commodity (or 'all')? ", buf);
99     c = (char)0;
100     if (p && *p)
101         c = *p;
102     for (ip = &ichr[0]; ip && ip->i_mnem; ip++)
103         if (ip->i_mnem == c)
104             break;
105     c = ip->i_mnem;
106
107     pr("\n     Empire Market Report\n   ");
108     prdate();
109     pr(" lot  high bid/unit  by  time left  owner  item  amount  sector\n");
110     pr(" ---  -------------  --  ---------  -----  ----  ------  ------\n");
111
112     if (arg) {
113         if (strcmp(arg, "all"))
114             all = 1;
115     }
116     if (all && !c) {
117         /* Ok, just printing the lowest of all of them */
118         for (i = 0; i < I_MAX + 2; i++)
119             cheapest_items[i] = -1;
120         for (sellers = 0; getcomm(sellers, &comm); sellers++) {
121             if (comm.com_owner == 0)
122                 continue;
123             for (i = 0, ip = &ichr[0]; ip && ip->i_mnem; ip++, i++)
124                 if (ip->i_mnem == comm.com_type)
125                     break;
126             if (!ip->i_mnem)
127                 continue;
128             if (cheapest_items[i] != -1) {
129                 getcomm(cheapest_items[i], &comm2);
130                 if (comm.com_price < comm2.com_price) {
131                     cheapest_items[i] = sellers;
132                 }
133             } else {
134                 cheapest_items[i] = sellers;
135             }
136         }
137         for (i = 0; i < I_MAX + 2; i++) {
138             if (cheapest_items[i] == -1)
139                 continue;
140             getcomm(cheapest_items[i], &comm);
141             cnt = 1;
142             pr_mark(&comm);
143         }
144     } else {
145         /* Ok, print them all, or all of this type */
146         for (sellers = 0; getcomm(sellers, &comm); sellers++) {
147             if (comm.com_owner == 0)
148                 continue;
149             if (c && comm.com_type != c)
150                 continue;
151             cnt = 1;
152             pr_mark(&comm);
153         }
154     }
155     if (cnt <= 0)
156         pr("\nHmmmm, the market seems to be empty today.\n");
157     else
158         pr("\nLooks just like Christmas at K-mart, doesn't it!\n");
159     return RET_OK;
160 }