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