]> 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-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  caploss.c: Lose your capital (kiss of death)
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 2000
31  *     Markus Armbruster, 2007-2013
32  */
33
34 #include <config.h>
35
36 #include "commodity.h"
37 #include "loan.h"
38 #include "nat.h"
39 #include "news.h"
40 #include "optlist.h"
41 #include "player.h"
42 #include "prototypes.h"
43 #include "sect.h"
44
45 void
46 caploss(struct sctstr *sp, natid coun, char *msg)
47 {
48     struct natstr *natp;
49     struct lonstr loan;
50     struct comstr comm;
51     int lose, gain;
52     char *verb;
53     int loan_num, comm_num;
54
55     CANT_HAPPEN(sp->sct_own && sp->sct_own != player->cnum);
56
57     natp = getnatp(coun);
58     if (natp->nat_stat != STAT_ACTIVE)
59         return;
60     if (sp->sct_x != natp->nat_xcap || sp->sct_y != natp->nat_ycap)
61         return;
62     if (coun == player->cnum)
63         return;
64     if (natp->nat_flags & NF_SACKED)
65         return;                 /* sacked capital, not yet reset */
66     natp->nat_flags |= NF_SACKED; /* no more sacking until player resets */
67
68     pr(msg, natp->nat_cnam);
69     gain = lose = natp->nat_money / 2;
70     if (lose < 3000)
71         lose = 3000;
72     natp->nat_money -= lose;
73     putnat(natp);
74     if (gain >= 0 && sp->sct_own) {
75         gain = (0.2 + 0.8 * (sp->sct_effic / 100.0)) * gain;
76         player->dolcost -= gain;
77     } else
78         gain = 0;
79     verb = sp->sct_own ? "sacked" : "obliterated";
80     wu(0, coun, "* %s just %s your capital! *\n",
81        cname(player->cnum), verb);
82     wu(0, coun, "You lost $%d and they gained $%d\n", lose, gain);
83     wu(0, coun, "You need to use 'capital' to activate a new capital.\n");
84     wu(0, 0, "%s just %s %s's capital and gained $%d\n",
85        cname(player->cnum), verb, cname(coun), gain);
86
87     if (opt_LOANS && sp->sct_own) {
88         for (loan_num = 0; getloan(loan_num, &loan); loan_num++) {
89             if (loan.l_status == LS_SIGNED && loan.l_loner == coun) {
90                 loan.l_loner = player->cnum;
91                 putloan(loan_num, &loan);
92                 pr("Loan %d has been transferred over to you\n", loan_num);
93             }
94         }
95     }
96     if (opt_MARKET && sp->sct_own) {
97         for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) {
98             if (comm.com_owner == 0)
99                 continue;
100             if (comm.com_owner == coun) {
101                 if (comm.com_owner == comm.com_maxbidder)
102                     comm.com_maxbidder = player->cnum;
103                 comm.com_owner = player->cnum;
104                 putcomm(comm_num, &comm);
105                 pr("You now own commodity #%d.\n", comm_num);
106             }
107         }
108     }
109     nreport(player->cnum, N_SACK_CAP, coun, 1);
110 }