2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, 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 or treaty
29 * Known contributors to this file:
41 static int do_treaty(void);
42 static int do_loan(void);
50 cp = getstarg(player->argp[1], "loan or treaty? ", buf);
57 pr("Loans are not enabled.\n");
63 pr("Treaties are not enabled.\n");
68 pr("You must specify \"loan\" as there are no treaties.\n");
77 int ourcond, theircond;
80 struct nstr_item nstr;
88 if ((n = natarg(player->argp[2], "Treaty offered to? ")) < 0)
91 if (recipient == player->cnum) {
92 pr("You can't sign a treaty with yourself!\n");
95 natp = getnatp(recipient);
96 if (player->cnum && (getrejects(player->cnum, natp) & REJ_TREA)) {
97 pr("%s is rejecting your treaties.\n", cname(recipient));
100 pr("Terms for %s:\n", cname(recipient));
102 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
103 sprintf(prompt, "%s? ", tfp->name);
104 if (!(cp = getstring(prompt, buf)))
107 theircond |= tfp->value;
109 pr("Terms for you:\n");
111 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
112 sprintf(prompt, "%s? ", tfp->name);
113 if (!(cp = getstring(prompt, buf)))
116 ourcond |= tfp->value;
118 if (ourcond == 0 && theircond == 0) {
119 pr("Treaties with no clauses aren't very useful, boss!\n");
122 cp = getstring("Proposed treaty duration? (days) ", buf);
127 pr("Bad treaty duration.\n");
131 snxtitem_all(&nstr, EF_TREATY);
132 while (nxtitem(&nstr, &trty)) {
133 if (trty.trt_status == TS_FREE) {
137 ef_blank(EF_TREATY, nstr.cur, &trty);
138 trty.trt_acond = ourcond;
139 trty.trt_bcond = theircond;
140 trty.trt_status = TS_PROPOSED;
141 trty.trt_cna = player->cnum;
142 trty.trt_cnb = recipient;
143 trty.trt_exp = j * SECS_PER_DAY + now;
144 if (!puttre(nstr.cur, &trty)) {
145 logerror("do_treaty: can't write treaty");
146 pr("Couldn't save treaty; get help.\n");
149 wu(0, recipient, "Treaty #%d proposed to you by %s\n",
150 nstr.cur, cname(player->cnum));
151 pr("You have proposed treaty #%d\n", nstr.cur);
158 int amt, irate, dur, maxloan;
159 struct nstr_item nstr;
166 if ((n = natarg(player->argp[2], "Lend to? ")) < 0)
169 if (recipient == player->cnum) {
170 pr("You can't loan yourself money!\n");
173 natp = getnatp(recipient);
174 if (player->cnum && (getrejects(player->cnum, natp) & REJ_LOAN)) {
175 pr("%s is rejecting your loans.\n", cname(recipient));
178 natp = getnatp(player->cnum);
179 if (natp->nat_money + 100 > MAXLOAN)
182 maxloan = natp->nat_money - 100;
184 pr("You don't have enough money to loan!\n");
187 sprintf(prompt, "Size of loan for country #%d? (max %d) ",
189 amt = onearg(player->argp[3], prompt);
193 pr("You can only loan $%d at a time.\n", MAXLOAN);
197 pr("You can't afford that much.\n");
200 dur = onearg(player->argp[4], "Duration? (days, max 7) ");
205 irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) ");
210 snxtitem_all(&nstr, EF_LOAN);
211 while (nxtitem(&nstr, &loan)) {
212 if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum)
213 && (loan.l_loner == recipient)) {
214 pr("You already owe HIM money - how about repaying your loan?\n");
218 snxtitem_all(&nstr, EF_LOAN);
219 while (nxtitem(&nstr, &loan)) {
220 if (loan.l_status == LS_FREE)
223 ef_blank(EF_LOAN, nstr.cur, &loan);
224 loan.l_loner = player->cnum;
225 loan.l_lonee = recipient;
226 loan.l_status = LS_PROPOSED;
227 loan.l_irate = MIN(irate, 127);
228 loan.l_ldur = MIN(dur, 127);
231 (void)time(&loan.l_lastpay);
232 loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
233 if (!putloan(nstr.cur, &loan)) {
234 logerror("do_loan: can't save loan");
235 pr("Couldn't save loan; get help!\n");
238 pr("You have offered loan %d\n", nstr.cur);
239 wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
240 player->cnum, nstr.cur);