2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 * cons.c: Consider a loan or treaty
30 * Known contributors to this file:
47 * Things common to a loan or treaty.
50 int type; /* EF_LOAN or EF_TREATY */
52 s_char *name; /* "loan" or "treaty" */
53 s_char *Name; /* "Loan" or "Treaty" */
54 natid proposer; /* country offering */
55 natid proposee; /* country offered to */
56 natid mailee; /* who gets mail about it */
57 s_char op; /* 'a', 'd', or 'p' */
59 struct lonstr l; /* the loan */
60 struct trtstr t; /* the treaty */
64 static int cons_choose(struct ltcomstr *ltcp);
65 static int treaty_accept(struct ltcomstr *ltcp);
66 static int treaty_decline(struct ltcomstr *ltcp);
67 static int loan_accept(struct ltcomstr *ltcp);
68 static int loan_decline(struct ltcomstr *ltcp);
69 static int postpone(struct ltcomstr *ltcp);
70 static void accpt(struct ltcomstr *ltcp);
71 static void decline(struct ltcomstr *ltcp);
72 static void late(struct ltcomstr *ltcp);
73 static void prev_signed(struct ltcomstr *ltcp);
81 rv = cons_choose(<c);
87 rv = (ltc.type == EF_TREATY) ? treaty_accept(<c)
91 rv = (ltc.type == EF_TREATY) ? treaty_decline(<c)
98 pr("Bad operation %c from cons_choose; get help!\n", ltc.op);
106 * Choose whether we want to accept, decline, or postpone a
107 * loan or treaty. Put all the goodies in ltcp, and return
108 * RET_OK if all goes well, and anything else on error.
111 cons_choose(struct ltcomstr *ltcp)
119 memset(ltcp, 0, sizeof(*ltcp));
120 if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0)
122 ltcp->type = ef_byname(buf);
123 switch (ltcp->type) {
126 pr("Treaties are not enabled.\n");
129 ltcp->name = "treaty";
130 ltcp->Name = "Treaty";
135 pr("Loans are not enabled.\n");
143 pr("You must specify \"loan\" or \"treaty\".\n");
146 sprintf(prompt, "%s number? ", ltcp->Name);
147 if ((ltcp->num = onearg(player->argp[2], prompt)) < 0)
149 if (!ef_read(ltcp->type, ltcp->num, (caddr_t)<cp->u) ||
150 !(ltcp->type == EF_TREATY
151 ? distrea(ltcp->num, ltcp->u.t)
152 : disloan(ltcp->num, ltcp->u.l))) {
153 pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num);
156 switch (ltcp->type) {
159 if (lp->l_status == LS_SIGNED) {
160 pr("That loan has already been accepted!\n");
163 ltcp->proposer = lp->l_loner;
164 ltcp->proposee = lp->l_lonee;
168 if (tp->trt_status == TS_SIGNED) {
169 pr("That treaty has already been accepted!\n");
172 ltcp->proposer = tp->trt_cna;
173 ltcp->proposee = tp->trt_cnb;
176 ltcp->mailee = (ltcp->proposer == player->cnum)
177 ? ltcp->proposee : ltcp->proposer;
179 getstarg(player->argp[3], "Accept, decline or postpone? ",
181 if (*p == 'a' || *p == 'd' || *p == 'p')
185 if (p == 0 || *p == 0)
192 * Accept a loan. If the offering country has too little money,
193 * leave him $100 left and offer the rest. Return RET_OK on
194 * success, anything else on error.
197 loan_accept(struct ltcomstr *ltcp)
200 struct natstr *lender;
201 struct nstr_item nstr;
205 if (ltcp->proposee != player->cnum) {
206 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num);
209 if (!getloan(ltcp->num, (caddr_t)lp)) {
210 pr("loan_accept: can't read loan; get help!\n");
213 if (lp->l_status == LS_FREE) { /* other guy retratcted already */
217 if (lp->l_status == LS_SIGNED) { /* already signed somehow */
221 /* check to see if a loan already exists */
222 snxtitem_all(&nstr, EF_LOAN);
223 while (nxtitem(&nstr, (s_char *)&loan)) {
224 if (loan.l_status == LS_SIGNED && loan.l_lonee == lp->l_loner
225 && (loan.l_loner == lp->l_lonee)) {
226 pr("He already owes you money - make him repay his loan!\n");
230 lender = getnatp(ltcp->proposer);
231 if (lender->nat_money < lp->l_amtdue) { /* other guy is poor */
232 lp->l_amtdue = lender->nat_money - 100;
233 pr("%s no longer has the funds.\n", cname(ltcp->proposer));
234 if (lp->l_amtdue <= 0)
236 pr("You may borrow $%d at the same terms.\n", lp->l_amtdue);
238 lender->nat_money -= lp->l_amtdue;
240 player->dolcost -= lp->l_amtdue;
242 (void)time(&lp->l_lastpay);
243 lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay;
244 lp->l_status = LS_SIGNED;
245 if (!putloan(ltcp->num, (s_char *)lp)) {
246 pr("Problem writing lp->to disk; get help!\n");
250 pr("You are now $%d richer (sort of).\n", lp->l_amtdue);
255 * Declne a loan. Return RET_OK on success, anything else on error.
258 loan_decline(struct ltcomstr *ltcp)
263 if (!getloan(ltcp->num, lp)) {
264 pr("Decline: can't read loan; get help!\n");
267 /* loan got accepted somehow between now and last time we checked */
268 if (lp->l_status == LS_SIGNED) {
272 lp->l_status = LS_FREE;
273 if (!putloan(ltcp->num, lp)) {
274 pr("loan_decline: can't write loan; get help!\n");
282 * Accept a treaty. Return RET_OK on success, anything else on error.
285 treaty_accept(struct ltcomstr *ltcp)
290 if (ltcp->proposee != player->cnum) {
291 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num);
294 if (!gettre(ltcp->num, tp)) {
295 pr("Accept: can't read treaty; get help!\n");
298 if (tp->trt_status == TS_FREE) { /* treaty offer withdrawn */
302 if (tp->trt_status == TS_SIGNED) { /* somehow got accepted */
306 tp->trt_status = TS_SIGNED;
307 if (!puttre(ltcp->num, tp)) {
308 pr("Problem saving treaty; get help!\n");
312 pr("Treaty in effect until %s", ctime(&tp->trt_exp));
317 * Decline a treaty. Return RET_OK on success, anything else on error.
320 treaty_decline(struct ltcomstr *ltcp)
325 if (!gettre(ltcp->num, tp)) {
326 pr("Decline: can't read treaty; get help!\n");
329 /* treaty got signed somehow between now and last time we read it */
330 if (tp->trt_status == TS_SIGNED) {
334 tp->trt_status = TS_FREE;
335 if (!puttre(ltcp->num, tp)) {
336 pr("Problem saving treaty; get help!\n");
344 * Postpone a treaty; always succeeds.
347 postpone(struct ltcomstr *ltcp)
349 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num);
350 if (ltcp->proposee == player->cnum)
351 wu(0, ltcp->proposer, "%s %d considered by %s\n",
352 ltcp->name, ltcp->num, cname(player->cnum));
357 * Somebody tried to accept a loan/treaty that was retracted,
358 * or to decline a loan/treaty they already signed.
361 late(struct ltcomstr *ltcp)
363 pr("Too late; that %s %s!\n", ltcp->name,
364 (ltcp->op == 'a') ? "is no longer being offered"
365 : "has already been accepted");
369 * Loan or treaty was previously signed.
372 prev_signed(struct ltcomstr *ltcp)
374 pr("%s #%d is already in effect.\n", ltcp->Name, ltcp->num);
378 * Post-processing after successful declination of loan or treaty.
379 * Notify the folks involved.
382 decline(struct ltcomstr *ltcp)
384 if (ltcp->proposee == player->cnum) {
385 wu(0, ltcp->proposer, "%s %d refused by %s\n",
386 ltcp->Name, ltcp->num, cname(player->cnum));
387 pr("%s %d refused.\n", ltcp->Name, ltcp->num);
389 wu(0, ltcp->proposee,
390 "%s offer %d retracted by %s\n",
391 ltcp->Name, ltcp->num, cname(player->cnum));
392 pr("%s offer %d retracted.\n", ltcp->Name, ltcp->num);
397 * Post-processing after successful acceptance of loan or treaty.
398 * Notify the press, and the folks involved.
399 * (Weird spelling is to avoid accept(2)).
402 accpt(struct ltcomstr *ltcp)
404 if (ltcp->type == EF_LOAN)
405 nreport(ltcp->proposer, N_MAKE_LOAN, player->cnum, 1);
407 nreport(player->cnum, N_SIGN_TRE, ltcp->mailee, 1);
408 wu(0, ltcp->mailee, "%s #%d accepted by %s\n",
409 ltcp->Name, ltcp->num, cname(player->cnum));