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