]> git.pond.sub.org Git - empserver/blob - src/lib/commands/shark.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / shark.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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  *  shark.c: Transfer a loan by buying it out
29  * 
30  *  Known contributors to this file:
31  *     Pat Loney, 1992
32  *     Steve McClure, 1996-2000
33  */
34
35 #include <config.h>
36
37 #include <math.h>
38 #include "misc.h"
39 #include "file.h"
40 #include "loan.h"
41 #include "nat.h"
42 #include "xy.h"
43 #include "player.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 int
48 shark(void)
49 {
50     int arg;
51     time_t now;
52     char *p;
53     struct lonstr loan;
54     struct natstr *natp;
55     struct natstr *oldie;
56     double owed;
57     long payment;
58     char buf[1024];
59
60     if (!opt_LOANS) {
61         pr("Loans are not enabled.\n");
62         return RET_FAIL;
63     }
64     p = getstarg(player->argp[1], "Transfer which loan #: ", buf);
65     if (p == 0)
66         return RET_SYN;
67     if (*p == 0)
68         return RET_SYN;
69     arg = atoi(p);
70     if (arg < 0)
71         return RET_SYN;
72     /* Check if it's a valid loan to shark.  That means, is it a valid loan,
73        not owed to this player, with a valid duration and it's been signed. */
74     if (!getloan(arg, &loan) || (loan.l_loner == player->cnum) ||
75         (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) {
76         pr("Invalid loan\n");
77         return RET_FAIL;
78     }
79     /* If we got here, we check to see if it's been defaulted on. */
80     owed = loan_owed(&loan, time(&now));
81     if (now <= loan.l_duedate) {
82         pr("There has been no default on loan %d\n", arg);
83         return RET_FAIL;
84     }
85     pr("That loan is worth $%.2f.\n", owed);
86     natp = getnatp(player->cnum);
87     payment = (long)ceil(owed * (1.0 + loan.l_irate / 100.0));
88     if (payment > natp->nat_money - 100.0) {
89         pr("You do not have enough to cover that loan\n");
90         return RET_FAIL;
91     } else {
92         wu(0, loan.l_lonee,
93            "%s bought loan #%d.  You now owe him!\n",
94            cname(player->cnum), arg);
95         wu(0, loan.l_loner,
96            "%s bought loan #%d out from under you for %ld\n",
97            cname(player->cnum), arg, payment);
98         pr("You now own loan #%d.  Go break some legs.\n", arg);
99     }
100     oldie = getnatp(loan.l_loner);
101     oldie->nat_money += payment;
102     player->dolcost += payment;
103     loan.l_loner = player->cnum;
104     putloan(arg, &loan);
105     return RET_OK;
106 }