]> git.pond.sub.org Git - empserver/blob - src/lib/commands/diss.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / diss.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  *  diss.c: Dissolve
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "sect.h"
38 #include "ship.h"
39 #include "plane.h"
40 #include "land.h"
41 #include "nat.h"
42 #include "loan.h"
43 #include "treaty.h"
44 #include "news.h"
45 #include "file.h"
46 #include "xy.h"
47 #include "nsc.h"
48 #include "tel.h"
49 #include "nuke.h"
50 #include "trade.h"
51 #include "commands.h"
52
53 int
54 diss(void)
55 {
56         int     quit(void);
57         struct  sctstr sect;
58         struct  lndstr land;
59         struct  shpstr ship;
60         struct  plnstr plane;
61         struct  trtstr treaty;
62         struct  trdstr trade;
63         struct  lonstr loan;
64         struct  nstr_item ni;
65         struct  nstr_sect ns;
66         int     sctnum;
67         int     damage;
68         int     annoyed;
69         int     n;
70         s_char  *p;
71         natid   cn;
72         float   dummy;
73         int     val;
74         s_char  buf[1024];
75         struct natstr *np;
76
77         if (player->cnum == 0) {
78                 /* Dissolve the Deity??? */
79                 /* Probably someone broke in. */
80                 /* Send a tele to deity, and abort the session. */
81                 wu(0, 0, "Diety dissolve attempted!  Session was aborted.\n");
82                 quit();
83         }
84         if (player->argp[1])
85                 *player->argp[1] = 0;
86         p = getstarg(player->argp[1], "Are you SURE you want to do this? (n) ", buf);
87         if (p == 0 || *p != 'y')
88                 return RET_SYN;
89         pr("\nIf you want some problem fixed and hope to force the issue\n");
90         pr("by dissolving, DON'T DO IT.  Even if an earlier version of\n");
91         pr("this game is brought up, YOU WILL BE GONE.\n");
92         pr("Forcing the issue makes it less likely that it will be\n");
93         pr("resolved the way you wish it.\n\n");
94         pr("Be part of the solution, not part of the problem.\n\n");
95         pr("If this is a test game, dissolving will not help the test.\n\n");
96         pr("If you are down to 0 sectors, and a 25% fishing vessel with\n");
97         pr("1 mil on it, well, I can see your point.  Go ahead.\n\n");
98         pr("But at least pay back your loans, if you can.\n\n");
99
100         if (player->argp[1])
101                 *player->argp[1] = 0;
102         p = getstarg(player->argp[1], "Once again, are you SURE you want to do this? (n) ", buf);
103         if (p == 0 || *p != 'y')
104                 return RET_SYN;
105
106         np = getnatp(player->cnum);
107         np->nat_stat = VIS;
108         snxtsct_all(&ns);
109         sctnum = 0;
110         while (nxtsct(&ns, &sect)) {
111                 if (!player->owner)
112                         continue;
113                 annoyed = 75 - (random() % (sect.sct_loyal+40));
114                 if (annoyed <= 0 || sect.sct_oldown != sect.sct_own) {
115                         pr("Populace celebrates in %s\n",
116                                 xyas(sect.sct_x, sect.sct_y, player->cnum));
117                         if (sect.sct_oldown != sect.sct_own) {
118                                 makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
119                                 makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x, sect.sct_y);
120                                 sect.sct_own = sect.sct_oldown;
121                                 if(sect.sct_own != 0)
122                                 wu(0, sect.sct_own,
123                                         "%s reverts back to you!\n",
124                                         xyas(sect.sct_x, sect.sct_y,
125                                         sect.sct_own));
126                         }
127                 } else if (annoyed < 25) {
128                         pr("Populace unmoved in %s\n",
129                                 xyas(sect.sct_x, sect.sct_y, player->cnum));
130                         makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
131                         sect.sct_own = 0;
132                         sect.sct_oldown = 0;
133                 } else {
134                         pr("Rioting breaks out in %s\n",
135                                 xyas(sect.sct_x, sect.sct_y, player->cnum));
136                         sectdamage(&sect, annoyed, 0);
137                         sctnum++;
138                         makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
139                         sect.sct_own = 0;
140                         sect.sct_oldown = 0;
141                 }
142                 putsect(&sect);
143         }
144         snxtitem_all(&ni, EF_LAND);
145         while (nxtitem(&ni, (s_char *)&land)) {
146                 if (!player->owner)
147                         continue;
148
149                 pr("%s disbands!\n", prland(&land));
150                 land.lnd_effic = 0;
151                 putland(land.lnd_uid, &land);
152         }
153         snxtitem_all(&ni, EF_SHIP);
154         while (nxtitem(&ni, (s_char *)&ship)) {
155                 if (!player->owner)
156                         continue;
157                 pr("%s ", prship(&ship));
158                 switch (random() % 3) {
159                 case 0:
160                         pr("scuttled!\n");
161                         ship.shp_effic = 0;
162                         break;
163                 case 1:
164                         pr("abandoned!\n");
165                         putvar(V_MILIT, 0, (s_char *)&ship, EF_SHIP);
166                         putvar(V_CIVIL, 0, (s_char *)&ship, EF_SHIP);
167                         putvar(V_UW, 0, (s_char *)&ship, EF_SHIP);
168                         break;
169                 case 2:
170                 default:
171                         damage = (random() % 80) + 10;
172                         pr("crew has rioted! (%d damage)\n", damage);
173                         shipdamage(&ship, damage);
174                         sctnum++;
175                         break;
176                 }
177                 putship(ship.shp_uid, &ship);
178         }
179         snxtitem_all(&ni, EF_PLANE);
180         while (nxtitem(&ni, (s_char *)&plane)) {
181                 if (!player->owner)
182                         continue;
183                 pr("%s ", prplane(&plane));
184                 switch (random() % 2) {
185                 case 0:
186                         pr("blown up!\n");
187                         plane.pln_effic = 0;
188                         break;
189                 case 1:
190                 default:
191                         damage = (random() % 80) + 10;
192                         pr("crew has rioted! (%d damage)\n", damage);
193                         planedamage(&plane, damage);
194                         sctnum++;
195                         break;
196                 }
197                 putplane(plane.pln_uid, &plane);
198         }
199         snxtitem_all(&ni, EF_TREATY);
200         while (nxtitem(&ni, (s_char *)&treaty)) {
201                 if (treaty.trt_status == TS_FREE)
202                         continue;
203                 if (treaty.trt_cna != player->cnum &&
204                     treaty.trt_cnb != player->cnum)
205                         continue;
206                 cn = treaty.trt_cna == player->cnum ? treaty.trt_cnb : treaty.trt_cna;
207                 pr("No more treaty with %s\n", cname(cn));
208                 wu(0, cn, "Treaty #%d with %s voided\n",
209                         ni.cur, cname(player->cnum));
210                 treaty.trt_status = TS_FREE;
211                 puttre(ni.cur, &treaty);
212         }
213         snxtitem_all(&ni, EF_LOAN);
214         while (nxtitem(&ni, (s_char *)&loan)) {
215                 if (loan.l_status == LS_FREE)
216                         continue;
217                 if (loan.l_loner != player->cnum && loan.l_lonee != player->cnum)
218                         continue;
219                 if (loan.l_loner == player->cnum) {
220                         pr("Loan #%d to %s will never be repaid\n",
221                                 ni.cur, cname(loan.l_lonee));
222                         wu(0, loan.l_lonee,
223                                 "Loan #%d from %s has been voided\n",
224                                         ni.cur, cname(player->cnum));
225                 } else {
226                         pr("Loan #%d from %s will never be repaid\n",
227                                 ni.cur, cname(loan.l_lonee));
228                         wu(0, loan.l_loner,
229                                 "Loan #%d to %s has been voided\n",
230                                 ni.cur, cname(player->cnum));
231                 }
232                 loan.l_status = LS_FREE;
233                 putloan(ni.cur, &loan);
234         }
235         /* clean up commodity and trade for this nation. */
236         commlock();
237         commread();
238         for (n=1; n<I_MAX+1; n++) {
239                 val = commamt(player->cnum, n, &dummy);
240                 commset(player->cnum, n, -val);
241         }
242         commwrite();
243         communlock();
244         snxtitem_all(&ni, EF_TRADE);
245         while (nxtitem(&ni, (s_char *)&trade)) {
246                 if (trade.trd_unitid >= 0 && trade.trd_owner == player->cnum) {
247                         trade.trd_unitid = -1;
248                         (void) puttrade(ni.cur, &trade);
249                 }
250         }
251         while (sctnum > 0) {
252                 n = sctnum > 127 ? 127 : sctnum;
253                 nreport(player->cnum, N_RIOT, 0, n);
254                 sctnum -= n;
255         }
256         filetruncate(mailbox(buf, player->cnum));
257         np->nat_stat = STAT_INUSE;
258         np->nat_btu = 0;
259         player->nstat = VIS;
260         wu(0, 0, "Country #%d (%s) has dissolved\n",
261                 player->cnum, cname(player->cnum));
262         nreport(player->cnum, N_DISS_GOV, 0, 1);
263         putnat(np);
264         return RET_OK;
265 }