#include <config.h>#include "commands.h"#include "loan.h"#include "news.h"#include "optlist.h"#include "treaty.h"Include dependency graph for cons.c:

Go to the source code of this file.
Data Structures | |
| struct | ltcomstr |
Functions | |
| static int | cons_choose (struct ltcomstr *ltcp) |
| static int | treaty_accept (struct ltcomstr *ltcp) |
| static int | treaty_decline (struct ltcomstr *ltcp) |
| static int | loan_accept (struct ltcomstr *ltcp) |
| static int | loan_decline (struct ltcomstr *ltcp) |
| static int | postpone (struct ltcomstr *ltcp) |
| static void | accpt (struct ltcomstr *ltcp) |
| static void | decline (struct ltcomstr *ltcp) |
| static void | late (struct ltcomstr *ltcp) |
| static void | prev_signed (struct ltcomstr *ltcp) |
| int | cons (void) |
| static void accpt | ( | struct ltcomstr * | ltcp | ) | [static] |
Definition at line 391 of file cons.c.
References cname(), EF_LOAN, ltcomstr::mailee, N_MAKE_LOAN, N_SIGN_TRE, ltcomstr::Name, nreport(), ltcomstr::num, ltcomstr::proposer, ltcomstr::type, and wu().
Referenced by loan_accept(), and treaty_accept().
00392 { 00393 if (ltcp->type == EF_LOAN) 00394 nreport(ltcp->proposer, N_MAKE_LOAN, player->cnum, 1); 00395 else 00396 nreport(player->cnum, N_SIGN_TRE, ltcp->mailee, 1); 00397 wu(0, ltcp->mailee, "%s #%d accepted by %s\n", 00398 ltcp->Name, ltcp->num, cname(player->cnum)); 00399 }
Here is the call graph for this function:

| int cons | ( | void | ) |
Definition at line 72 of file cons.c.
References cons_choose(), EF_TREATY, loan_accept(), loan_decline(), ltcomstr::op, postpone(), pr(), RET_OK, treaty_accept(), treaty_decline(), and ltcomstr::type.
Referenced by ring_from_file(), ring_peek(), and ring_to_file().
00073 { 00074 int rv; 00075 struct ltcomstr ltc; 00076 00077 rv = cons_choose(<c); 00078 if (rv != RET_OK) 00079 return rv; 00080 00081 switch (ltc.op) { 00082 case 'a': 00083 rv = (ltc.type == EF_TREATY) ? treaty_accept(<c) 00084 : loan_accept(<c); 00085 break; 00086 case 'd': 00087 rv = (ltc.type == EF_TREATY) ? treaty_decline(<c) 00088 : loan_decline(<c); 00089 break; 00090 case 'p': 00091 rv = postpone(<c); 00092 break; 00093 default: 00094 pr("Bad operation %c from cons_choose; get help!\n", ltc.op); 00095 break; 00096 }; 00097 00098 return rv; 00099 }
Here is the call graph for this function:

Definition at line 107 of file cons.c.
References disloan(), distrea(), EF_BAD, ef_byname_from(), EF_LOAN, ef_read(), EF_TREATY, getstarg(), lonstr::l_lonee, lonstr::l_loner, lonstr::l_status, LS_SIGNED, onearg(), opt_LOANS, opt_TREATIES, pr(), prompt(), RET_FAIL, RET_OK, RET_SYN, trtstr::trt_cna, trtstr::trt_cnb, trtstr::trt_status, and TS_SIGNED.
Referenced by cons().
00108 { 00109 static int lon_or_trt[] = { EF_LOAN, EF_TREATY, EF_BAD }; 00110 char *p; 00111 struct lonstr *lp; 00112 struct trtstr *tp; 00113 char prompt[128]; 00114 char buf[1024]; 00115 00116 memset(ltcp, 0, sizeof(*ltcp)); 00117 if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0) 00118 return RET_SYN; 00119 ltcp->type = ef_byname_from(buf, lon_or_trt); 00120 switch (ltcp->type) { 00121 case EF_TREATY: 00122 if (!opt_TREATIES) { 00123 pr("Treaties are not enabled.\n"); 00124 return RET_FAIL; 00125 } 00126 ltcp->name = "treaty"; 00127 ltcp->Name = "Treaty"; 00128 break; 00129 case EF_LOAN: 00130 if (!opt_LOANS) { 00131 pr("Loans are not enabled.\n"); 00132 return RET_FAIL; 00133 } 00134 ltcp->name = "loan"; 00135 ltcp->Name = "Loan"; 00136 break; 00137 default: 00138 pr("You must specify \"loan\" or \"treaty\".\n"); 00139 return RET_SYN; 00140 } 00141 sprintf(prompt, "%s number? ", ltcp->Name); 00142 if ((ltcp->num = onearg(player->argp[2], prompt)) < 0) 00143 return RET_SYN; 00144 if (!ef_read(ltcp->type, ltcp->num, <cp->u) || 00145 !(ltcp->type == EF_TREATY 00146 ? distrea(ltcp->num, <cp->u.t) 00147 : disloan(ltcp->num, <cp->u.l))) { 00148 pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num); 00149 return RET_SYN; 00150 } 00151 switch (ltcp->type) { 00152 case EF_LOAN: 00153 lp = <cp->u.l; 00154 if (lp->l_status == LS_SIGNED) { 00155 pr("That loan has already been accepted!\n"); 00156 return RET_FAIL; 00157 } 00158 ltcp->proposer = lp->l_loner; 00159 ltcp->proposee = lp->l_lonee; 00160 break; 00161 case EF_TREATY: 00162 tp = <cp->u.t; 00163 if (tp->trt_status == TS_SIGNED) { 00164 pr("That treaty has already been accepted!\n"); 00165 return RET_FAIL; 00166 } 00167 ltcp->proposer = tp->trt_cna; 00168 ltcp->proposee = tp->trt_cnb; 00169 break; 00170 } 00171 ltcp->mailee = (ltcp->proposer == player->cnum) 00172 ? ltcp->proposee : ltcp->proposer; 00173 p = getstarg(player->argp[3], "Accept, decline or postpone? ", buf); 00174 if (!p || (*p != 'a' && *p != 'd' && *p != 'p')) 00175 return RET_SYN; 00176 ltcp->op = *p; 00177 return RET_OK; 00178 }
Here is the call graph for this function:

| static void decline | ( | struct ltcomstr * | ltcp | ) | [static] |
Definition at line 371 of file cons.c.
References cname(), ltcomstr::Name, ltcomstr::num, pr(), ltcomstr::proposee, ltcomstr::proposer, and wu().
Referenced by loan_decline(), and treaty_decline().
00372 { 00373 if (ltcp->proposee == player->cnum) { 00374 wu(0, ltcp->proposer, "%s %d refused by %s\n", 00375 ltcp->Name, ltcp->num, cname(player->cnum)); 00376 pr("%s %d refused.\n", ltcp->Name, ltcp->num); 00377 } else { 00378 wu(0, ltcp->proposee, 00379 "%s offer %d retracted by %s\n", 00380 ltcp->Name, ltcp->num, cname(player->cnum)); 00381 pr("%s offer %d retracted.\n", ltcp->Name, ltcp->num); 00382 } 00383 }
Here is the call graph for this function:

| static void late | ( | struct ltcomstr * | ltcp | ) | [static] |
Definition at line 350 of file cons.c.
References ltcomstr::name, ltcomstr::op, and pr().
Referenced by loan_accept(), loan_decline(), treaty_accept(), and treaty_decline().
00351 { 00352 pr("Too late; that %s %s!\n", ltcp->name, 00353 (ltcp->op == 'a') ? "is no longer being offered" 00354 : "has already been accepted"); 00355 }
Here is the call graph for this function:

Definition at line 186 of file cons.c.
References accpt(), cname(), EF_LOAN, getloan, getnatp, ltcomstr::l, lonstr::l_lonee, lonstr::l_loner, lonstr::l_status, late(), LS_FREE, LS_SIGNED, ltcomstr::Name, natstr::nat_money, ltcomstr::num, nxtitem(), pr(), prev_signed(), ltcomstr::proposee, ltcomstr::proposer, putloan, putnat, RET_FAIL, RET_OK, RET_SYS, snxtitem_all(), and ltcomstr::u.
Referenced by cons().
00187 { 00188 struct lonstr *lp; 00189 struct natstr *lender; 00190 struct nstr_item nstr; 00191 struct lonstr loan; 00192 00193 lp = <cp->u.l; 00194 if (ltcp->proposee != player->cnum) { 00195 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); 00196 return RET_OK; 00197 } 00198 if (!getloan(ltcp->num, lp)) { 00199 pr("loan_accept: can't read loan; get help!\n"); 00200 return RET_SYS; 00201 } 00202 if (lp->l_status == LS_FREE) { /* other guy retratcted already */ 00203 late(ltcp); 00204 return RET_OK; 00205 } 00206 if (lp->l_status == LS_SIGNED) { /* already signed somehow */ 00207 prev_signed(ltcp); 00208 return RET_OK; 00209 } 00210 /* check to see if a loan already exists */ 00211 snxtitem_all(&nstr, EF_LOAN); 00212 while (nxtitem(&nstr, &loan)) { 00213 if (loan.l_status == LS_SIGNED && loan.l_lonee == lp->l_loner 00214 && (loan.l_loner == lp->l_lonee)) { 00215 pr("He already owes you money - make him repay his loan!\n"); 00216 return RET_OK; 00217 } 00218 } 00219 lender = getnatp(ltcp->proposer); 00220 if (lender->nat_money < lp->l_amtdue) { /* other guy is poor */ 00221 lp->l_amtdue = lender->nat_money - 100; 00222 pr("%s no longer has the funds.\n", cname(ltcp->proposer)); 00223 if (lp->l_amtdue <= 0) 00224 return RET_FAIL; 00225 pr("You may borrow $%ld at the same terms.\n", lp->l_amtdue); 00226 } 00227 lender->nat_money -= lp->l_amtdue; 00228 putnat(lender); 00229 player->dolcost -= lp->l_amtdue; 00230 lp->l_amtpaid = 0; 00231 (void)time(&lp->l_lastpay); 00232 lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay; 00233 lp->l_status = LS_SIGNED; 00234 if (!putloan(ltcp->num, lp)) { 00235 pr("Problem writing lp->to disk; get help!\n"); 00236 return RET_FAIL; 00237 } 00238 accpt(ltcp); 00239 pr("You are now $%ld richer (sort of).\n", lp->l_amtdue); 00240 return RET_OK; 00241 }
Here is the call graph for this function:

Definition at line 247 of file cons.c.
References decline(), getloan, ltcomstr::l, lonstr::l_status, late(), LS_FREE, LS_SIGNED, ltcomstr::num, pr(), putloan, RET_OK, RET_SYS, and ltcomstr::u.
Referenced by cons().
00248 { 00249 struct lonstr *lp; 00250 00251 lp = <cp->u.l; 00252 if (!getloan(ltcp->num, lp)) { 00253 pr("Decline: can't read loan; get help!\n"); 00254 return RET_SYS; 00255 } 00256 /* loan got accepted somehow between now and last time we checked */ 00257 if (lp->l_status == LS_SIGNED) { 00258 late(ltcp); 00259 return RET_OK; 00260 } 00261 lp->l_status = LS_FREE; 00262 if (!putloan(ltcp->num, lp)) { 00263 pr("loan_decline: can't write loan; get help!\n"); 00264 return RET_SYS; 00265 } 00266 decline(ltcp); 00267 return RET_OK; 00268 }
Here is the call graph for this function:

Definition at line 336 of file cons.c.
References cname(), ltcomstr::name, ltcomstr::Name, ltcomstr::num, pr(), ltcomstr::proposee, ltcomstr::proposer, RET_OK, and wu().
Referenced by cons().
00337 { 00338 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); 00339 if (ltcp->proposee == player->cnum) 00340 wu(0, ltcp->proposer, "%s %d considered by %s\n", 00341 ltcp->name, ltcp->num, cname(player->cnum)); 00342 return RET_OK; 00343 }
Here is the call graph for this function:

| static void prev_signed | ( | struct ltcomstr * | ltcp | ) | [static] |
Definition at line 361 of file cons.c.
References ltcomstr::Name, ltcomstr::num, and pr().
Referenced by loan_accept(), and treaty_accept().
Here is the call graph for this function:

Definition at line 274 of file cons.c.
References accpt(), gettre, late(), ltcomstr::Name, ltcomstr::num, pr(), prev_signed(), ltcomstr::proposee, puttre, RET_OK, RET_SYS, ltcomstr::t, trtstr::trt_exp, trtstr::trt_status, TS_FREE, TS_SIGNED, and ltcomstr::u.
Referenced by cons().
00275 { 00276 struct trtstr *tp; 00277 00278 tp = <cp->u.t; 00279 if (ltcp->proposee != player->cnum) { 00280 pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); 00281 return RET_OK; 00282 } 00283 if (!gettre(ltcp->num, tp)) { 00284 pr("Accept: can't read treaty; get help!\n"); 00285 return RET_SYS; 00286 } 00287 if (tp->trt_status == TS_FREE) { /* treaty offer withdrawn */ 00288 late(ltcp); 00289 return RET_OK; 00290 } 00291 if (tp->trt_status == TS_SIGNED) { /* somehow got accepted */ 00292 prev_signed(ltcp); 00293 return RET_OK; 00294 } 00295 tp->trt_status = TS_SIGNED; 00296 if (!puttre(ltcp->num, tp)) { 00297 pr("Problem saving treaty; get help!\n"); 00298 return RET_SYS; 00299 } 00300 accpt(ltcp); 00301 pr("Treaty in effect until %s", ctime(&tp->trt_exp)); 00302 return RET_OK; 00303 }
Here is the call graph for this function:

Definition at line 309 of file cons.c.
References decline(), gettre, late(), ltcomstr::num, pr(), puttre, RET_OK, RET_SYS, ltcomstr::t, trtstr::trt_status, TS_FREE, TS_SIGNED, and ltcomstr::u.
Referenced by cons().
00310 { 00311 struct trtstr *tp; 00312 00313 tp = <cp->u.t; 00314 if (!gettre(ltcp->num, tp)) { 00315 pr("Decline: can't read treaty; get help!\n"); 00316 return RET_SYS; 00317 } 00318 /* treaty got signed somehow between now and last time we read it */ 00319 if (tp->trt_status == TS_SIGNED) { 00320 late(ltcp); 00321 return RET_OK; 00322 } 00323 tp->trt_status = TS_FREE; 00324 if (!puttre(ltcp->num, tp)) { 00325 pr("Problem saving treaty; get help!\n"); 00326 return RET_SYS; 00327 } 00328 decline(ltcp); 00329 return RET_OK; 00330 }
Here is the call graph for this function:

1.5.2