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