]> 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-2009, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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  *     Markus Armbruster, 2007-2008
33  */
34
35 #include <config.h>
36
37 #include "commodity.h"
38 #include "file.h"
39 #include "loan.h"
40 #include "nat.h"
41 #include "news.h"
42 #include "optlist.h"
43 #include "player.h"
44 #include "prototypes.h"
45 #include "sect.h"
46
47 void
48 caploss(struct sctstr *sp, natid coun, char *msg)
49 {
50     struct natstr *natp;
51     struct lonstr loan;
52     struct comstr comm;
53     long lose;
54     long gain;
55     char *verb;
56     int loan_num, comm_num;
57
58     CANT_HAPPEN(sp->sct_own && sp->sct_own != player->cnum);
59
60     natp = getnatp(coun);
61     if (natp->nat_stat != STAT_ACTIVE)
62         return;
63     if (sp->sct_x != natp->nat_xcap || sp->sct_y != natp->nat_ycap)
64         return;
65     if (coun == player->cnum)
66         return;
67     if (natp->nat_flags & NF_SACKED)
68         return;                 /* sacked capital, not yet reset */
69     natp->nat_flags |= NF_SACKED; /* no more sacking until player resets */
70
71     pr(msg, natp->nat_cnam);
72     gain = lose = natp->nat_money / 2;
73     if (lose < 3000)
74         lose = 3000;
75     natp->nat_money -= lose;
76     putnat(natp);
77     if (gain >= 0 && sp->sct_own) {
78         gain = (0.2 + 0.8 * (sp->sct_effic / 100.0)) * gain;
79         player->dolcost -= gain;
80     } else
81         gain = 0;
82     verb = sp->sct_own ? "sacked" : "obliterated";
83     wu(0, coun, "* %s just %s your capital! *\n",
84        cname(player->cnum), verb);
85     wu(0, coun, "You lost $%ld and they gained $%ld\n", lose, gain);
86     wu(0, coun, "You need to use 'capital' to activate a new capital.\n");
87     wu(0, 0, "%s just %s %s's capital and gained $%ld\n",
88        cname(player->cnum), verb, cname(coun), gain);
89
90     if (opt_LOANS && sp->sct_own) {
91         for (loan_num = 0; getloan(loan_num, &loan); loan_num++) {
92             if (loan.l_status == LS_SIGNED && loan.l_loner == coun) {
93                 loan.l_loner = player->cnum;
94                 putloan(loan_num, &loan);
95                 pr("Loan %d has been transfered over to you\n", loan_num);
96             }
97         }
98     }
99     if (opt_MARKET && sp->sct_own) {
100         for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) {
101             if (comm.com_owner == 0)
102                 continue;
103             if (comm.com_owner == coun) {
104                 if (comm.com_owner == comm.com_maxbidder)
105                     comm.com_maxbidder = player->cnum;
106                 comm.com_owner = player->cnum;
107                 putcomm(comm_num, &comm);
108                 pr("You now own commodity #%d.\n", comm_num);
109             }
110         }
111     }
112     nreport(player->cnum, N_SACK_CAP, coun, 1);
113 }