]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rese.c
af1824ba7cbb47402e14645ef23416889a29ceb0
[empserver] / src / lib / commands / rese.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  rese.c: Reset (lower) commodity prices
28  *
29  *  Known contributors to this file:
30  *     Jeff Bailey
31  *     Pat Loney, 1992
32  *     Steve McClure, 1996
33  */
34
35 #include <config.h>
36
37 #include "commands.h"
38 #include "commodity.h"
39 #include "item.h"
40 #include "optlist.h"
41
42 int
43 rese(void)
44 {
45     struct comstr comm;
46     struct sctstr sect;
47     int number_set;
48     int m;
49     char *p;
50     float price;
51     time_t now;
52     char buf[1024];
53
54     if (!opt_MARKET) {
55         pr("The market is disabled.\n");
56         return RET_FAIL;
57     }
58     check_market();
59     check_trade();
60     p = getstarg(player->argp[1], "Which lot :  ", buf);
61     if (!p || !*p)
62         return RET_SYN;
63     number_set = atoi(p);
64     getcomm(number_set, &comm);
65     if (comm.com_owner != player->cnum && !player->god) {
66         pr("That's not your lot.\n");
67         return RET_OK;
68     }
69     if (comm.com_maxbidder != player->cnum && !player->god) {
70         pr("Some one already has a bid out on that\n");
71         return RET_OK;
72     }
73     p = getstarg(player->argp[2], "New (lower) price: ", buf);
74     if (!p || !*p)
75         return RET_SYN;
76     if (!check_comm_ok(&comm))
77         return RET_FAIL;
78     price = (float)atof(p);
79     if (price <= 0) {
80         getsect(comm.sell_x, comm.sell_y, &sect);
81         if (!player->owner && !player->god) {
82             pr("The destination sector must be one of yours\n");
83             return RET_OK;
84         }
85         if (player->god) {
86             if (!(p = getstring("Really destroy that lot? ", buf)))
87                 return RET_FAIL;
88             if (!check_comm_ok(&comm))
89                 return RET_FAIL;
90             if (*p == 'Y' || *p == 'y') {
91                 comm.com_owner = 0;
92                 putcomm(number_set, &comm);
93                 pr("Goods destroyed.\n");
94                 return RET_OK;
95             }
96             return RET_FAIL;
97         }
98         if (sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) {
99             pr("That sector is not available for receiving goods.\n");
100             return RET_OK;
101         }
102         if (sect.sct_effic < 60) {
103             pr("The destination sector must be at least 60%% efficient.\n");
104             return RET_OK;
105         }
106         if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX)) {
107             pr("The goods have been eaten by a grue.");
108             return RET_OK;
109         }
110         m = sect.sct_item[comm.com_type];
111         m = m + comm.com_amount;
112         if (m > ITEM_MAX)
113             m = ITEM_MAX;
114         sect.sct_item[comm.com_type] = m;
115         putsect(&sect);
116         comm.com_owner = 0;
117         putcomm(number_set, &comm);
118         pr("The goods have been returned to your trading post.\n");
119         return RET_OK;
120     }
121     if (price >= comm.com_price) {
122         pr("You can only lower the price.\n");
123         return RET_OK;
124     }
125     if (price < 0) {
126         pr("New price must be greater than or equal to zero.\n");
127         return RET_OK;
128     }
129     comm.com_price = price;
130     (void)time(&now);
131     comm.com_markettime = now;
132     if (!putcomm(number_set, &comm)) {
133         pr("Problems with the commodities file, call the Deity\n");
134         return RET_OK;
135     }
136     return RET_OK;
137 }