2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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 natp = getnatp(recipient);
81 if (!nat_accepts(natp, player->cnum, REJ_LOAN)) {
82 pr("%s is rejecting your loans.\n", cname(recipient));
85 natp = getnatp(player->cnum);
86 if (natp->nat_money + 100 > MAXLOAN)
89 maxloan = natp->nat_money - 100;
91 pr("You don't have enough money to loan!\n");
94 sprintf(prompt, "Size of loan for country #%d? (max %d) ",
96 amt = onearg(player->argp[3], prompt);
100 pr("You can only loan $%d at a time.\n", MAXLOAN);
104 pr("You can't afford that much.\n");
107 dur = onearg(player->argp[4], "Duration? (days, max 7) ");
112 irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) ");
117 snxtitem_all(&nstr, EF_LOAN);
118 while (nxtitem(&nstr, &loan)) {
119 if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum)
120 && (loan.l_loner == recipient)) {
121 pr("You already owe HIM money - how about repaying your loan?\n");
125 snxtitem_all(&nstr, EF_LOAN);
126 while (nxtitem(&nstr, &loan)) {
127 if (loan.l_status == LS_FREE)
130 ef_blank(EF_LOAN, nstr.cur, &loan);
131 loan.l_loner = player->cnum;
132 loan.l_lonee = recipient;
133 loan.l_status = LS_PROPOSED;
134 loan.l_irate = MIN(irate, 127);
135 loan.l_ldur = MIN(dur, 127);
138 (void)time(&loan.l_lastpay);
139 loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
140 if (!putloan(nstr.cur, &loan)) {
141 logerror("do_loan: can't save loan");
142 pr("Couldn't save loan; get help!\n");
145 pr("You have offered loan %d\n", nstr.cur);
146 wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
147 player->cnum, nstr.cur);