2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
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.
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.
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/>.
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.
27 * offe.c: Offer a loan
29 * Known contributors to this file:
32 * Markus Armbruster, 2005-2016
41 static int do_loan(void);
48 cp = player->argp[1] ? player->argp[1] : "loan";
52 pr("Loans are not enabled.\n");
57 pr("You must specify \"loan\".\n");
65 int amt, irate, dur, maxloan;
66 struct nstr_item nstr;
73 if ((n = natarg(player->argp[2], "Lend to? ")) < 0)
76 if (recipient == player->cnum) {
77 pr("You can't loan yourself money!\n");
80 if (!nat_accepts(recipient, player->cnum, REJ_LOAN)) {
81 pr("%s is rejecting your loans.\n", cname(recipient));
84 natp = getnatp(player->cnum);
85 if (natp->nat_money + 100 > MAXLOAN)
88 maxloan = natp->nat_money - 100;
90 pr("You don't have enough money to loan!\n");
93 sprintf(prompt, "Size of loan for country #%d? (max %d) ",
95 amt = onearg(player->argp[3], prompt);
99 pr("You can only loan $%d at a time.\n", MAXLOAN);
103 pr("You can't afford that much.\n");
106 dur = onearg(player->argp[4], "Duration? (days, max 7) ");
111 irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) ");
116 snxtitem_all(&nstr, EF_LOAN);
117 while (nxtitem(&nstr, &loan)) {
118 if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum)
119 && (loan.l_loner == recipient)) {
120 pr("You already owe HIM money - how about repaying your loan?\n");
124 snxtitem_all(&nstr, EF_LOAN);
125 while (nxtitem(&nstr, &loan)) {
126 if (loan.l_status == LS_FREE)
129 ef_blank(EF_LOAN, nstr.cur, &loan);
130 loan.l_loner = player->cnum;
131 loan.l_lonee = recipient;
132 loan.l_status = LS_PROPOSED;
133 loan.l_irate = MIN(irate, 127);
134 loan.l_ldur = MIN(dur, 127);
137 (void)time(&loan.l_lastpay);
138 loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
139 if (!putloan(nstr.cur, &loan)) {
140 logerror("do_loan: can't save loan");
141 pr("Couldn't save loan; get help!\n");
144 pr("You have offered loan %d\n", nstr.cur);
145 wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
146 player->cnum, nstr.cur);