2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
28 * offe.c: Offer a loan or treaty
30 * Known contributors to this file:
42 static int do_treaty(void);
43 static int do_loan(void);
51 cp = getstarg(player->argp[1], "loan or treaty? ", buf);
58 pr("Loans are not enabled.\n");
64 pr("Treaties are not enabled.\n");
69 pr("You must specify \"loan\" as there are no treaties.\n");
78 int ourcond, theircond;
81 struct nstr_item nstr;
89 if ((n = natarg(player->argp[2], "Treaty offered to? ")) < 0)
92 if (recipient == player->cnum) {
93 pr("You can't sign a treaty with yourself!\n");
96 natp = getnatp(recipient);
97 if (player->cnum && (getrejects(player->cnum, natp) & REJ_TREA)) {
98 pr("%s is rejecting your treaties.\n", cname(recipient));
101 pr("Terms for %s:\n", cname(recipient));
103 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
104 sprintf(prompt, "%s? ", tfp->name);
105 if (!(cp = getstring(prompt, buf)))
108 theircond |= tfp->value;
110 pr("Terms for you:\n");
112 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
113 sprintf(prompt, "%s? ", tfp->name);
114 if (!(cp = getstring(prompt, buf)))
117 ourcond |= tfp->value;
119 if (ourcond == 0 && theircond == 0) {
120 pr("Treaties with no clauses aren't very useful, boss!\n");
123 cp = getstring("Proposed treaty duration? (days) ", buf);
128 pr("Bad treaty duration.\n");
132 snxtitem_all(&nstr, EF_TREATY);
133 while (nxtitem(&nstr, &trty)) {
134 if (trty.trt_status == TS_FREE) {
138 ef_blank(EF_TREATY, nstr.cur, &trty);
139 trty.trt_acond = ourcond;
140 trty.trt_bcond = theircond;
141 trty.trt_status = TS_PROPOSED;
142 trty.trt_cna = player->cnum;
143 trty.trt_cnb = recipient;
144 trty.trt_exp = j * SECS_PER_DAY + now;
145 if (!puttre(nstr.cur, &trty)) {
146 logerror("do_treaty: can't write treaty");
147 pr("Couldn't save treaty; get help.\n");
150 wu(0, recipient, "Treaty #%d proposed to you by %s\n",
151 nstr.cur, cname(player->cnum));
152 pr("You have proposed treaty #%d\n", nstr.cur);
159 int amt, irate, dur, maxloan;
160 struct nstr_item nstr;
167 if ((n = natarg(player->argp[2], "Lend to? ")) < 0)
170 if (recipient == player->cnum) {
171 pr("You can't loan yourself money!\n");
174 natp = getnatp(recipient);
175 if (player->cnum && (getrejects(player->cnum, natp) & REJ_LOAN)) {
176 pr("%s is rejecting your loans.\n", cname(recipient));
179 natp = getnatp(player->cnum);
180 if (natp->nat_money + 100 > MAXLOAN)
183 maxloan = natp->nat_money - 100;
185 pr("You don't have enough money to loan!\n");
188 sprintf(prompt, "Size of loan for country #%d? (max %d) ",
190 amt = onearg(player->argp[3], prompt);
194 pr("You can only loan $%d at a time.\n", MAXLOAN);
198 pr("You can't afford that much.\n");
201 dur = onearg(player->argp[4], "Duration? (days, max 7) ");
206 irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) ");
211 snxtitem_all(&nstr, EF_LOAN);
212 while (nxtitem(&nstr, &loan)) {
213 if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum)
214 && (loan.l_loner == recipient)) {
215 pr("You already owe HIM money - how about repaying your loan?\n");
219 snxtitem_all(&nstr, EF_LOAN);
220 while (nxtitem(&nstr, &loan)) {
221 if (loan.l_status == LS_FREE)
224 ef_blank(EF_LOAN, nstr.cur, &loan);
225 loan.l_loner = player->cnum;
226 loan.l_lonee = recipient;
227 loan.l_status = LS_PROPOSED;
228 loan.l_irate = MIN(irate, 127);
229 loan.l_ldur = MIN(dur, 127);
232 (void)time(&loan.l_lastpay);
233 loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
234 if (!putloan(nstr.cur, &loan)) {
235 logerror("do_loan: can't save loan");
236 pr("Couldn't save loan; get help!\n");
239 pr("You have offered loan %d\n", nstr.cur);
240 wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
241 player->cnum, nstr.cur);