]> git.pond.sub.org Git - empserver/blob - src/lib/subs/caploss.c
Update copyright notice.
[empserver] / src / lib / subs / caploss.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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  *  caploss.c: Lose your capital (kiss of death)
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 2000
32  *    
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "nat.h"
38 #include "var.h"
39 #include "sect.h"
40 #include "file.h"
41 #include "xy.h"
42 #include "news.h"
43 #include "path.h"
44 #include "loan.h"
45 #include "commodity.h"
46 #include "prototypes.h"
47 #include "optlist.h"
48
49 void
50 caploss(struct sctstr *sp, natid coun, s_char *msg)
51 {
52     struct natstr *natp;
53     struct lonstr loan;
54     struct comstr comm;
55     long lose;
56     long gain;
57     struct sctstr sect;
58     int n;
59     int loan_num = 0;
60     int comm_num = 0;
61
62     if (coun == 0)
63         return;
64     natp = getnatp(coun);
65     if ((xrel(natp, natp->nat_xcap) != xrel(natp, sp->sct_x)) ||
66         (yrel(natp, natp->nat_ycap) != yrel(natp, sp->sct_y)))
67         return;
68     if (coun == player->cnum) {
69         player->nstat &= ~CAP;
70         return;
71     }
72     /* Ok, has the country owner reset their capital yet after it was last sacked? */
73     if (natp->nat_flags & NF_SACKED)
74         return;                 /* No, so not really the capital yet, so return */
75     pr(msg, natp->nat_cnam);
76     gain = lose = natp->nat_money / 2;
77     if (lose < 3000)
78         lose = 3000;
79     n = roll(6);
80     getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
81     natp->nat_xcap = sect.sct_x;
82     natp->nat_ycap = sect.sct_y;
83     natp->nat_money -= lose;
84     /* Your capital has now been sacked, no more sacking until you reset it */
85     natp->nat_flags |= NF_SACKED;
86     putnat(natp);
87     wu(0, coun, "* %s just sacked your capital! *\n", cname(player->cnum));
88
89     if (gain >= 0) {
90         gain = (0.2 + 0.8 * (sp->sct_effic / 100.0)) * gain;
91         player->dolcost -= gain;
92     } else
93         gain = 0;
94     wu(0, coun, "You lost $%ld and they gained $%ld\n", lose, gain);
95     wu(0, coun,
96        "Your capital has been moved to %s. You must use 'capital' to reset it.\n",
97        xyas(natp->nat_xcap, natp->nat_ycap, coun));
98     wu(0, 0, "%s just took %s's capital and gained $%d\n",
99        cname(player->cnum), cname(coun), -(int)(player->dolcost));
100     if (opt_LOANS) {
101         for (loan_num = 0; getloan(loan_num, &loan); loan_num++) {
102             if (loan.l_ldur != 0 && loan.l_loner == coun) {
103                 loan.l_loner = player->cnum;
104                 putloan(loan_num, &loan);
105                 pr("Loan %d has been transfered over to you\n", loan_num);
106             }
107         }
108     }
109     if (opt_MARKET) {
110         for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) {
111             if (comm.com_owner == coun) {
112                 if (comm.com_owner == comm.com_maxbidder)
113                     comm.com_maxbidder = player->cnum;
114                 comm.com_owner = player->cnum;
115                 putcomm(comm_num, &comm);
116                 pr("You now own commodity #%d.\n", comm_num);
117             }
118         }
119     }
120     nreport(player->cnum, N_SACK_CAP, coun, 1);
121 }