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