]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/conv.c
Update copyright notice
[empserver] / src / lib / commands / conv.c
index 89e5117996b8684945aa56c6586ce1f71b702aa1..d442e9abbbcb702b4210729c96d26871a8ce9536 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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,
@@ -14,8 +14,7 @@
  *  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/>.
  *
  *  ---
  *
@@ -26,7 +25,7 @@
  *  ---
  *
  *  conv.c: Convert conquered populace into uw's
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "sect.h"
-#include "nat.h"
-#include "xy.h"
-#include "nsc.h"
-#include "file.h"
-#include "land.h"
 #include "commands.h"
-
-static long do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real);
+#include "land.h"
 
 int
 conv(void)
 {
     struct natstr *natp;
-    long cash;
-    long cost;
+    struct sctstr sect;
     struct nstr_sect nstr;
-    int uwtoconvert;
+    int uwtoconvert, newuw, totaluw, uw;
+    int maxpop, civ, mil, adj_mob, mob;
+    double security_extra = 1.0;
+    struct lndstr land;
+    struct nstr_item ni;
 
-    natp = getnatp(player->cnum);
-    cash = natp->nat_money;
     if (!snxtsct(&nstr, player->argp[1]))
        return RET_SYN;
     uwtoconvert = onearg(player->argp[2], "Number to convert: ");
     if (uwtoconvert < 0)
        return RET_SYN;
-    cost = do_conv(nstr, uwtoconvert, 0);
-    if (chkmoney(cost, cash, player->argp[3]))
-       return RET_SYN;
-    return (int)do_conv(nstr, uwtoconvert, 1);
-}
-
-static long
-do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
-{
-    struct natstr *natp;
-    struct sctstr sect;
-    int newuw, totaluw, uw;
-    int maxpop, civ, mil, adj_mob, mob;
-    double security_extra = 1.0;
-    struct lndstr land;
-    struct nstr_item ni;
-    long cost = 0;
 
     totaluw = 0;
     while (nxtsct(&nstr, &sect)) {
@@ -89,19 +63,19 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
            continue;
        if (sect.sct_oldown == player->cnum)
            continue;
-        natp = getnatp(sect.sct_own);
+       natp = getnatp(sect.sct_own);
        maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
        civ = sect.sct_item[I_CIVIL];
        mil = sect.sct_item[I_MILIT];
 
        /*
         * Military units count according to the number of
-        * mil in them. (i.e. attack/defense modified don't
+        * mil in them. (i.e. attack/defense modifier don't
         * count.
         */
        snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
        while (nxtitem(&ni, &land)) {
-           mil += lnd_getmil(&land);
+           mil += land.lnd_item[I_MILIT];
 
            /* Anti-terrorist units count double */
            if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
@@ -113,9 +87,7 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
                 */
                security_extra += .1;
                land.lnd_mobil -= 10;
-               if (for_real)
-                   putland(land.lnd_uid, &land);
-               mil += lnd_getmil(&land);
+               mil += land.lnd_item[I_MILIT];
            }
        }
        /*
@@ -145,9 +117,10 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
            newuw = adj_mob;
        if (newuw <= 0)
            continue;
-       if (!for_real) {
-           cost += newuw * 1.5;
-           continue;
+       if (player->dolcost + newuw * 1.5 > natp->nat_money) {
+           pr("You can't afford to convert %d civilians in %s!\n",
+              newuw, xyas(sect.sct_x, sect.sct_y, player->cnum));
+           break;
        }
        player->btused += (newuw - 1) / 100 + 1;
        player->dolcost += newuw * 1.5;
@@ -170,8 +143,6 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
        putsect(&sect);
        totaluw += newuw;
     }
-    if (!for_real)
-       return cost;
     pr("Total civilians converted: %d\n", totaluw);
     pr("Paperwork at conversion places ... %d\n", player->btused);
     return RET_OK;