]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/cons.c
Update copyright notice
[empserver] / src / lib / commands / cons.c
index 4313a497613ef48a701efc3023fdb9d6d1e99ee6..712fee4c13b63a0fcac465797c43b5973bc9dec3 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  cons.c: Consider a loan or treaty
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
-#include "misc.h"
-#include "player.h"
+#include <config.h>
+
+#include "commands.h"
 #include "loan.h"
-#include "nat.h"
-#include "treaty.h"
 #include "news.h"
-#include "xy.h"
-#include "nsc.h"
-#include "file.h"
-#include "commands.h"
 #include "optlist.h"
+#include "treaty.h"
 
 /*
  * Things common to a loan or treaty.
 struct ltcomstr {
     int type;                  /* EF_LOAN or EF_TREATY */
     int num;                   /* number */
-    s_char *name;              /* "loan" or "treaty" */
-    s_char *Name;              /* "Loan" or "Treaty" */
+    char *name;                        /* "loan" or "treaty" */
+    char *Name;                        /* "Loan" or "Treaty" */
     natid proposer;            /* country offering */
     natid proposee;            /* country offered to */
     natid mailee;              /* who gets mail about it */
-    s_char op;                 /* 'a', 'd', or 'p' */
+    char op;                   /* 'a', 'd', or 'p' */
     union {
        struct lonstr l;        /* the loan */
        struct trtstr t;        /* the treaty */
@@ -110,19 +105,17 @@ cons(void)
 static int
 cons_choose(struct ltcomstr *ltcp)
 {
-    s_char *p;
-    extern int disloan();
-    extern int distrea();
-    int (*dis) ();
+    static int lon_or_trt[] = { EF_LOAN, EF_TREATY, EF_BAD };
+    char *p;
     struct lonstr *lp;
     struct trtstr *tp;
-    s_char prompt[128];
-    s_char buf[1024];
+    char prompt[128];
+    char buf[1024];
 
     memset(ltcp, 0, sizeof(*ltcp));
-    if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0)
+    if (!getstarg(player->argp[1], "loan or treaty? ", buf))
        return RET_SYN;
-    ltcp->type = ef_byname(buf);
+    ltcp->type = ef_byname_from(buf, lon_or_trt);
     switch (ltcp->type) {
     case EF_TREATY:
        if (!opt_TREATIES) {
@@ -131,7 +124,6 @@ cons_choose(struct ltcomstr *ltcp)
        }
        ltcp->name = "treaty";
        ltcp->Name = "Treaty";
-       dis = distrea;
        break;
     case EF_LOAN:
        if (!opt_LOANS) {
@@ -140,7 +132,6 @@ cons_choose(struct ltcomstr *ltcp)
        }
        ltcp->name = "loan";
        ltcp->Name = "Loan";
-       dis = disloan;
        break;
     default:
        pr("You must specify \"loan\" or \"treaty\".\n");
@@ -149,8 +140,10 @@ cons_choose(struct ltcomstr *ltcp)
     sprintf(prompt, "%s number? ", ltcp->Name);
     if ((ltcp->num = onearg(player->argp[2], prompt)) < 0)
        return RET_SYN;
-    if (!ef_read(ltcp->type, ltcp->num, (caddr_t)&ltcp->u) ||
-       !(*dis) (ltcp->num, &ltcp->u)) {
+    if (!ef_read(ltcp->type, ltcp->num, &ltcp->u) ||
+       !(ltcp->type == EF_TREATY
+         ? distrea(ltcp->num, &ltcp->u.t)
+         : disloan(ltcp->num, &ltcp->u.l))) {
        pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num);
        return RET_SYN;
     }
@@ -176,14 +169,8 @@ cons_choose(struct ltcomstr *ltcp)
     }
     ltcp->mailee = (ltcp->proposer == player->cnum)
        ? ltcp->proposee : ltcp->proposer;
-    while ((p =
-           getstarg(player->argp[3], "Accept, decline or postpone? ",
-                    buf)) && *p) {
-       if (*p == 'a' || *p == 'd' || *p == 'p')
-           break;
-       player->argp[3] = 0;
-    }
-    if (p == 0 || *p == 0)
+    p = getstarg(player->argp[3], "Accept, decline or postpone? ", buf);
+    if (!p || (*p != 'a' && *p != 'd' && *p != 'p'))
        return RET_SYN;
     ltcp->op = *p;
     return RET_OK;
@@ -207,9 +194,10 @@ loan_accept(struct ltcomstr *ltcp)
        pr("%s %d is still pending.\n", ltcp->Name, ltcp->num);
        return RET_OK;
     }
-    if (!getloan(ltcp->num, (caddr_t)lp)) {
-       pr("loan_accept: can't read loan; get help!\n");
-       return RET_SYS;
+    if (!getloan(ltcp->num, lp)) {
+       logerror("loan_accept: can't read loan");
+       pr("can't read loan; get help!\n");
+       return RET_FAIL;
     }
     if (lp->l_status == LS_FREE) {     /* other guy retratcted already */
        late(ltcp);
@@ -221,7 +209,7 @@ loan_accept(struct ltcomstr *ltcp)
     }
     /* check to see if a loan already exists */
     snxtitem_all(&nstr, EF_LOAN);
-    while (nxtitem(&nstr, (s_char *)&loan)) {
+    while (nxtitem(&nstr, &loan)) {
        if (loan.l_status == LS_SIGNED && loan.l_lonee == lp->l_loner
            && (loan.l_loner == lp->l_lonee)) {
            pr("He already owes you money - make him repay his loan!\n");
@@ -234,21 +222,21 @@ loan_accept(struct ltcomstr *ltcp)
        pr("%s no longer has the funds.\n", cname(ltcp->proposer));
        if (lp->l_amtdue <= 0)
            return RET_FAIL;
-       pr("You may borrow $%d at the same terms.\n", lp->l_amtdue);
+       pr("You may borrow $%ld at the same terms.\n", lp->l_amtdue);
     }
     lender->nat_money -= lp->l_amtdue;
     putnat(lender);
     player->dolcost -= lp->l_amtdue;
     lp->l_amtpaid = 0;
     (void)time(&lp->l_lastpay);
-    lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay;
+    lp->l_duedate = lp->l_ldur * SECS_PER_DAY + lp->l_lastpay;
     lp->l_status = LS_SIGNED;
-    if (!putloan(ltcp->num, (s_char *)lp)) {
+    if (!putloan(ltcp->num, lp)) {
        pr("Problem writing lp->to disk; get help!\n");
        return RET_FAIL;
     }
     accpt(ltcp);
-    pr("You are now $%d richer (sort of).\n", lp->l_amtdue);
+    pr("You are now $%ld richer (sort of).\n", lp->l_amtdue);
     return RET_OK;
 }
 
@@ -262,8 +250,9 @@ loan_decline(struct ltcomstr *ltcp)
 
     lp = &ltcp->u.l;
     if (!getloan(ltcp->num, lp)) {
-       pr("Decline: can't read loan; get help!\n");
-       return RET_SYS;
+       logerror("loan_decline: can't read loan");
+       pr("can't read loan; get help!\n");
+       return RET_FAIL;
     }
     /* loan got accepted somehow between now and last time we checked */
     if (lp->l_status == LS_SIGNED) {
@@ -272,8 +261,9 @@ loan_decline(struct ltcomstr *ltcp)
     }
     lp->l_status = LS_FREE;
     if (!putloan(ltcp->num, lp)) {
-       pr("loan_decline: can't write loan; get help!\n");
-       return RET_SYS;
+       logerror("loan_decline: can't write loan");
+       pr("can't write loan; get help!\n");
+       return RET_FAIL;
     }
     decline(ltcp);
     return RET_OK;
@@ -293,8 +283,9 @@ treaty_accept(struct ltcomstr *ltcp)
        return RET_OK;
     }
     if (!gettre(ltcp->num, tp)) {
-       pr("Accept: can't read treaty; get help!\n");
-       return RET_SYS;
+       pr("treaty_accept: can't read treaty");
+       pr("can't read treaty; get help!\n");
+       return RET_FAIL;
     }
     if (tp->trt_status == TS_FREE) {   /* treaty offer withdrawn */
        late(ltcp);
@@ -306,8 +297,9 @@ treaty_accept(struct ltcomstr *ltcp)
     }
     tp->trt_status = TS_SIGNED;
     if (!puttre(ltcp->num, tp)) {
+       pr("treaty_accept: can't write treaty");
        pr("Problem saving treaty; get help!\n");
-       return RET_SYS;
+       return RET_FAIL;
     }
     accpt(ltcp);
     pr("Treaty in effect until %s", ctime(&tp->trt_exp));
@@ -324,8 +316,9 @@ treaty_decline(struct ltcomstr *ltcp)
 
     tp = &ltcp->u.t;
     if (!gettre(ltcp->num, tp)) {
-       pr("Decline: can't read treaty; get help!\n");
-       return RET_SYS;
+       logerror("treaty_decline: can't read treaty");
+       pr("can't read treaty; get help!\n");
+       return RET_FAIL;
     }
     /* treaty got signed somehow between now and last time we read it */
     if (tp->trt_status == TS_SIGNED) {
@@ -334,8 +327,9 @@ treaty_decline(struct ltcomstr *ltcp)
     }
     tp->trt_status = TS_FREE;
     if (!puttre(ltcp->num, tp)) {
+       logerror("treaty_decline: can't write treaty");
        pr("Problem saving treaty; get help!\n");
-       return RET_SYS;
+       return RET_FAIL;
     }
     decline(ltcp);
     return RET_OK;