]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rese.c
Update copyright notice.
[empserver] / src / lib / commands / rese.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  rese.c: Reset (lower) commodity prices
29  * 
30  *  Known contributors to this file:
31  *     Jeff Bailey
32  *     Pat Loney, 1992
33  *     Steve McClure, 1996
34  */
35
36 #include "misc.h"
37 #include "xy.h"
38 #include "file.h"
39 #include "sect.h"
40 #include "item.h"
41 #include "nsc.h"
42 #include "nat.h"
43 #include "land.h"
44 #include "plane.h"
45 #include "ship.h"
46 #include "commodity.h"
47 #include "player.h"
48 #include "commands.h"
49 #include "optlist.h"
50
51 int
52 rese(void)
53 {
54     struct comstr comm;
55     struct sctstr sect;
56     int number_set;
57     int m;
58     char *p;
59     float price;
60     time_t now;
61     s_char buf[1024];
62
63     if (!opt_MARKET) {
64         pr("The market is disabled.\n");
65         return RET_FAIL;
66     }
67     check_market();
68     check_trade();
69     if ((p = getstarg(player->argp[1], "Which lot :  ", buf)) == 0
70         || *p == 0)
71         return RET_SYN;
72     number_set = atoi(p);
73     getcomm(number_set, &comm);
74     if (comm.com_owner != player->cnum && !player->god) {
75         pr("That's not your lot.\n");
76         return RET_OK;
77     }
78     if (comm.com_maxbidder != player->cnum && !player->god) {
79         pr("Some one already has a bid out on that\n");
80         return RET_OK;
81     }
82     if ((p = getstarg(player->argp[2], "New (lower) price: ", buf)) == 0
83         || *p == 0)
84         return RET_SYN;
85     if (!check_comm_ok(&comm))
86         return RET_FAIL;
87     price = (float)atof(p);
88     if (price <= 0) {
89         getsect(comm.sell_x, comm.sell_y, &sect);
90         if (!player->owner && !player->god) {
91             pr("The destination sector must be one of yours\n");
92             return RET_OK;
93         }
94         if (player->god) {
95             if ((p = getstring("Really destroy that lot? ", buf)) == 0)
96                 return RET_FAIL;
97             if (!check_comm_ok(&comm))
98                 return RET_FAIL;
99             if (*p == 'Y' || *p == 'y') {
100                 comm.com_owner = 0;
101                 putcomm(number_set, &comm);
102                 pr("Goods destroyed.\n");
103                 return RET_OK;
104             }
105             return RET_FAIL;
106         }
107         if (sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) {
108             pr("That sector is not available for receiving goods.\n");
109             return RET_OK;
110         }
111         if (sect.sct_effic < 60) {
112             pr("The destination sector must be at least 60%% efficient.\n");
113             return RET_OK;
114         }
115         if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX)) {
116             pr("The goods have been eaten by a grue.");
117             return RET_OK;
118         }
119         m = sect.sct_item[comm.com_type];
120         m = m + comm.com_amount;
121         if (m > ITEM_MAX)
122             m = ITEM_MAX;
123         sect.sct_item[comm.com_type] = m;
124         putsect(&sect);
125         comm.com_owner = 0;
126         putcomm(number_set, &comm);
127         pr("The goods have been returned to your trading post.\n");
128         return RET_OK;
129     }
130     if (price >= comm.com_price) {
131         pr("You can only lower the price.\n");
132         return RET_OK;
133     }
134     if (price < 0) {
135         pr("New price must be greater than or equal to zero.\n");
136         return RET_OK;
137     }
138     comm.com_price = price;
139     (void)time(&now);
140     comm.com_markettime = now;
141     if (!putcomm(number_set, &comm)) {
142         pr("Problems with the commodities file, Call the Deity\n");
143         return RET_OK;
144     }
145     return RET_OK;
146 }