]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/coll.c
Update copyright notice
[empserver] / src / lib / commands / coll.c
index 6313ac7b9639741870f9c88f7ffb238b7e748e9e..bbe99ce2c4864f5590f420425d8efa59256c6d18 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *
  *  ---
  *
- *  coll.c: Collet on a loan
+ *  coll.c: Collect on a loan
  *
  *  Known contributors to this file:
  *     Pat Loney, 1992
  *     Steve McClure, 1996-2000
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
 #include "commands.h"
 #include "item.h"
 #include "loan.h"
-#include "lost.h"
 #include "news.h"
 #include "optlist.h"
 
+static double appraise_sect(struct sctstr *);
+
 int
 coll(void)
 {
     int arg;
-    int i;
-    int val;
     time_t now;
     char *p;
     struct lonstr loan;
     struct sctstr sect;
+    struct natstr *lonee_np;
     coord x, y;
     double owed;
     double pay;
@@ -76,6 +77,7 @@ coll(void)
        return RET_FAIL;
     }
 
+    lonee_np = getnatp(loan.l_lonee);
     pr("You are owed $%.2f on that loan.\n", owed);
     p = getstarg(player->argp[2],
                 "What sector do you wish to confiscate? ", buf);
@@ -94,18 +96,20 @@ coll(void)
           xyas(x, y, player->cnum), cname(loan.l_lonee));
        return RET_FAIL;
     }
-    pay = dchr[sect.sct_type].d_value * (sect.sct_effic + 100.0);
-    for (i = 0; ichr[i].i_name; i++) {
-       if (ichr[i].i_value == 0 || ichr[i].i_uid == I_NONE)
-           continue;
-       val = sect.sct_item[ichr[i].i_uid];
-       pay += val * ichr[i].i_value;
-    }
-    pr("That sector (and its contents) is valued at $%.2f\n", pay);
+    pay = appraise_sect(&sect);
     if (pay > owed * 1.2) {
-       pr("That is more than is owed!\n");
+       pr("That sector (and its contents) is valued at more than %.2f.\n",
+          owed);
+       return RET_FAIL;
+    }
+    if (!influx(lonee_np)
+       && sect.sct_x == lonee_np->nat_xcap
+       && sect.sct_y == lonee_np->nat_ycap) {
+       pr("%s's capital cannot be confiscated.\n", cname(loan.l_lonee));
        return RET_FAIL;
     }
+    pr("That sector (and its contents) is valued at $%.2f\n", pay);
+
     sect.sct_item[I_MILIT] = 1;        /* FIXME now where did this guy come from? */
 
     /*
@@ -113,15 +117,11 @@ coll(void)
      * unwanted things, like generate che.
      */
     sect.sct_own = player->cnum;
-
     memset(sect.sct_dist, 0, sizeof(sect.sct_dist));
     memset(sect.sct_del, 0, sizeof(sect.sct_del));
     sect.sct_off = 1;
     sect.sct_dist_x = sect.sct_x;
     sect.sct_dist_y = sect.sct_y;
-
-    if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT)
-       caploss(&sect, loan.l_lonee, "that was %s's capital!\n");
     putsect(&sect);
     nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1);
     owed = loan_owed(&loan, time(&now));
@@ -137,9 +137,9 @@ coll(void)
     } else {
        (void)time(&loan.l_lastpay);
        owed -= pay;
-       loan.l_amtdue = (long)owed;
+       loan.l_amtdue = (int)owed;
        pay += loan.l_amtpaid;
-       loan.l_amtpaid = pay;
+       loan.l_amtpaid = (int)pay;
        wu(0, loan.l_lonee,
           "%s seized %s in partial payment of loan %d.\n",
           cname(player->cnum),
@@ -149,3 +149,29 @@ coll(void)
     putloan(arg, &loan);
     return RET_OK;
 }
+
+static double
+appraise_items(short item[])
+{
+    double total, val;
+    int i;
+
+    total = 0.0;
+    for (i = I_NONE + 1; i <= I_MAX; i++) {
+       val = ichr[i].i_power / 10.0;
+       if (i == I_MILIT || i == I_CIVIL || i == I_UW)
+           val /= 5.0;         /* collect-specific fudge factor */
+       total += item[i] * val;
+    }
+    return total;
+}
+
+static double
+appraise_sect(struct sctstr *sp)
+{
+    struct dchrstr *dcp = &dchr[sp->sct_type];
+    double bld_val = appraise_items(dcp->d_mat) + dcp->d_cost;
+
+    return bld_val * sp->sct_effic / 100.0 + dcp->d_maxpop
+       + appraise_items(sp->sct_item);
+}