]> git.pond.sub.org Git - empserver/blob - src/lib/commands/mark.c
Import of Empire 4.2.12
[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 "deity.h"
41 #include "commodity.h"
42 #include "player.h"
43 #include "file.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 int
48 mark(void)
49 {
50     if (!opt_MARKET) {
51         pr("The market is disabled.\n");
52         return RET_FAIL;
53     }
54     if (player->argp[1] && *(player->argp[1]))
55         return display_mark(player->argp[1]);
56     else
57         return display_mark("   ");
58 }
59
60 void
61 pr_mark(struct comstr *comm)
62 {
63     time_t now;
64     double  tleft;
65     extern int MARK_DELAY;
66     
67     (void) time(&now);
68     tleft = MARK_DELAY / 3600.0 - (now - comm->com_markettime) / 3600.0;
69     if (tleft < 0.0) 
70         tleft = 0.0;
71     pr(" %3d  $%12.2f  %2d  %5.2f hrs  (%3d)   %c    %6d  ",
72        comm->com_uid,
73        comm->com_maxprice,
74        comm->com_maxbidder,
75        tleft,
76        comm->com_owner,
77        comm->com_type,
78        comm->com_amount);
79     if (comm->com_owner == player->cnum || player->god)
80         pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum));
81     pr("\n");
82 }
83
84 int
85 display_mark(s_char *arg)
86 {
87     struct  comstr  comm;
88     struct comstr comm2;
89     int     sellers = 0;
90     int     cnt = 0;
91     char    c;
92     s_char  *p;
93     struct ichrstr      *ip;
94     s_char  buf[1024];
95     int cheapest_items[I_MAX + 2];
96     int i;
97     int all = 0;
98     
99 /* First, we execute all trades, so that we can only buy what is available. */
100     check_market();
101     check_trade();
102
103     p = getstarg(arg, "What commodity (or 'all')? ", buf);
104     c = (char)0;
105     if (p && *p)
106       c = *p;
107     for (ip = &ichr[0]; ip && ip->i_mnem; ip++)
108       if (ip->i_mnem == c)
109         break;
110     c = ip->i_mnem;
111
112     pr("\n     Empire Market Report\n   ");
113     prdate();
114     pr(" lot  high bid/unit  by  time left  owner  item  amount  sector\n");
115     pr(" ---  -------------  --  ---------  -----  ----  ------  ------\n");
116
117     if (arg) {
118         if (strcmp(arg, "all"))
119             all = 1;
120     }
121     if (all && !c) {
122         /* Ok, just printing the lowest of all of them */
123         for (i = 0; i < I_MAX + 2; i++)
124             cheapest_items[i] = -1;
125         for (sellers = 0; getcomm(sellers, &comm); sellers++) {
126             if (comm.com_owner == 0)
127                 continue;
128             for (i = 0, ip = &ichr[0]; ip && ip->i_mnem; ip++, i++)
129                 if (ip->i_mnem == comm.com_type)
130                     break;
131             if (!ip->i_mnem)
132                 continue;
133             if (cheapest_items[i] != -1) {
134                 getcomm(cheapest_items[i], &comm2);
135                 if (comm.com_maxprice < comm2.com_maxprice) {
136                     cheapest_items[i] = sellers;
137                 }
138             } else {
139                 cheapest_items[i] = sellers;
140             }
141         }
142         for (i = 0; i < I_MAX + 2; i++) {
143             if (cheapest_items[i] == -1)
144                 continue;
145             getcomm(cheapest_items[i], &comm);
146             cnt = 1;
147             pr_mark(&comm);
148         }
149     } else {
150         /* Ok, print them all, or all of this type */
151         for (sellers = 0; getcomm(sellers, &comm); sellers++) {
152             if (comm.com_owner == 0)
153                 continue;
154             if (c && comm.com_type != c)
155                 continue;
156             cnt = 1;
157             pr_mark(&comm);
158         }       
159     }
160     if (cnt <= 0)
161         pr("\nHmmmm, the market seems to be empty today.\n");
162     else
163         pr("\nLooks just like Christmas at K-mart, doesn't it!\n");
164     return RET_OK;
165 }