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