]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rese.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / rese.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "var.h"
40 #include "sect.h"
41 #include "item.h"
42 #include "nsc.h"
43 #include "nat.h"
44 #include "land.h"
45 #include "nuke.h"
46 #include "plane.h"
47 #include "ship.h"
48 #include "trade.h"
49 #include <math.h>               /* bailey@math-cs.kent.edu */
50 #include "commodity.h"
51 #include "player.h"
52 #include "commands.h"
53 #include "optlist.h"
54
55 int
56 rese(void)
57 {
58     struct comstr comm;
59     struct sctstr sect;
60     struct ichrstr *ix;
61     int     number_set;
62     int     m;
63     char        *p;
64     float       price;
65     time_t      now;
66     s_char buf[1024];
67     
68     if (!opt_MARKET) {
69         pr("The market is disabled.\n");
70         return RET_FAIL;
71     }
72     check_market();
73     check_trade();
74     if ((p = getstarg(player->argp[1], "Which lot :  ",buf)) == 0 || *p == 0)
75         return RET_SYN;
76     number_set = atoi(p);
77     getcomm(number_set, &comm);
78     if (comm.com_owner != player->cnum && !player->god) {
79         pr("That's not your lot.\n");
80         return RET_OK;
81     }
82     if (comm.com_maxbidder != player->cnum && !player->god) {
83         pr("Some one already has a bid out on that\n");
84         return RET_OK;
85     }
86     if ((p = getstarg(player->argp[2], "New (lower) price: ",buf)) == 0 || *p == 0)
87         return RET_SYN;
88     if (!check_comm_ok(&comm))
89         return RET_FAIL;
90     price = (float)atof(p);
91     if (price <= 0) {
92         getsect(comm.sell_x, comm.sell_y, &sect);
93         if (!player->owner && !player->god) {
94             pr("The destination sector must be one of yours\n");
95             return RET_OK;
96         }
97         if (player->god) {
98             if ((p = getstring("Really destroy that lot? ", buf)) == 0)
99                 return RET_FAIL;
100             if (!check_comm_ok(&comm))
101                 return RET_FAIL;
102             if (*p == 'Y' || *p == 'y') {
103                 comm.com_owner = 0;
104                 putcomm(number_set, &comm);
105                 pr("Goods destroyed.\n");
106                 return RET_OK;
107             }
108             return RET_FAIL;
109         }
110         if (sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) {
111             pr("That sector is not available for receiving goods.\n");
112             return RET_OK;
113         }
114         if (sect.sct_effic < 60) {
115             pr("The destination sector must be at least 60%% efficient.\n");
116             return RET_OK;
117         }
118         ix = whichitem(comm.com_type);
119         sect.sct_x = comm.sell_x;
120         sect.sct_y = comm.sell_y;
121         m = getvar(ix->i_vtype, (char *)&sect, EF_SECTOR);
122         m = m + comm.com_amount;
123         if (m > 9999)
124             m = 9999;
125         putvar(ix->i_vtype, m, (char *)&sect, EF_SECTOR);
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((int)price < comm.com_maxprice)
144         comm.com_maxprice = (int) price;
145     if(!putcomm(number_set, &comm)){
146         pr("Problems with the commodities file, Call the Deity\n");
147         return RET_OK;
148     }
149     return RET_OK;
150 }