2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * offe.c: Offer a loan or treaty
30 * Known contributors to this file:
46 static int do_treaty(void);
47 static int do_loan(void);
55 if (!(cp = getstarg(player->argp[1], "loan or treaty? ", buf)) || !*cp)
61 pr("Loans are not enabled.\n");
67 pr("Treaties are not enabled.\n");
72 pr("You must specify \"loan\" as there are no treaties.\n");
82 register int theircond;
86 struct nstr_item nstr;
94 if ((n = natarg(player->argp[2], "Treaty offered to? ")) < 0)
97 if (recipient == player->cnum) {
98 pr("You can't sign a treaty with yourself!\n");
101 natp = getnatp(recipient);
102 if (player->cnum && (getrejects(player->cnum, natp) & REJ_TREA)) {
103 pr("%s is rejecting your treaties.\n", cname(recipient));
106 pr("Terms for %s:\n", cname(recipient));
108 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
109 sprintf(prompt, "%s? ", tfp->name);
110 if ((cp = getstring(prompt, buf)) == 0)
113 theircond |= tfp->value;
115 pr("Terms for you:\n");
117 for (tfp = treaty_flags; tfp && tfp->name; tfp++) {
118 sprintf(prompt, "%s? ", tfp->name);
119 if ((cp = getstring(prompt, buf)) == 0)
122 ourcond |= tfp->value;
124 if (ourcond == 0 && theircond == 0) {
125 pr("Treaties with no clauses aren't very useful, boss!\n");
128 cp = getstring("Proposed treaty duration? (days) ", buf);
133 pr("Bad treaty duration.\n");
137 snxtitem_all(&nstr, EF_TREATY);
138 while (nxtitem(&nstr, &trty)) {
139 if (trty.trt_status == TS_FREE) {
143 trty.ef_type = EF_TREATY;
144 trty.trt_uid = nstr.cur;
145 trty.trt_acond = ourcond;
146 trty.trt_bcond = theircond;
147 trty.trt_status = TS_PROPOSED;
148 trty.trt_cna = player->cnum;
149 trty.trt_cnb = recipient;
150 trty.trt_exp = j * SECS_PER_DAY + now;
151 if (!puttre(nstr.cur, &trty)) {
152 pr("Couldn't save treaty; get help.\n");
155 wu(0, recipient, "Treaty #%d proposed to you by %s\n",
156 nstr.cur, cname(player->cnum));
157 pr("You have proposed treaty #%d\n", nstr.cur);
164 register int amt, irate, dur, maxloan;
165 struct nstr_item nstr;
172 if ((n = natarg(player->argp[2], "Lend to? ")) < 0)
175 if (recipient == player->cnum) {
176 pr("You can't loan yourself money!\n");
179 natp = getnatp(recipient);
180 if (player->cnum && (getrejects(player->cnum, natp) & REJ_LOAN)) {
181 pr("%s is rejecting your loans.\n", cname(recipient));
184 natp = getnatp(player->cnum);
185 if (natp->nat_money + 100 > MAXLOAN)
188 maxloan = natp->nat_money - 100;
190 pr("You don't have enough money to loan!\n");
193 sprintf(prompt, "Size of loan for country #%d? (max %d) ",
195 amt = onearg(player->argp[3], prompt);
199 pr("You can only loan $%d at a time.\n", MAXLOAN);
203 pr("You can't afford that much.\n");
206 dur = onearg(player->argp[4], "Duration? (days, max 7) ");
211 irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) ");
216 snxtitem_all(&nstr, EF_LOAN);
217 while (nxtitem(&nstr, &loan)) {
218 if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum)
219 && (loan.l_loner == recipient)) {
220 pr("You already owe HIM money - how about repaying your loan?\n");
224 snxtitem_all(&nstr, EF_LOAN);
225 while (nxtitem(&nstr, &loan)) {
226 if (loan.l_status == LS_FREE)
229 loan.l_loner = player->cnum;
230 loan.l_lonee = recipient;
231 loan.l_status = LS_PROPOSED;
232 loan.l_irate = min(irate, 127);
233 loan.l_ldur = min(dur, 127);
236 (void)time(&loan.l_lastpay);
237 loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
238 loan.l_uid = nstr.cur;
239 if (!putloan(nstr.cur, &loan)) {
240 pr("Couldn't save loan; get help!\n");
243 pr("You have offered loan %d\n", nstr.cur);
244 wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
245 player->cnum, nstr.cur);