]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/desi.c
Update copyright notice
[empserver] / src / lib / commands / desi.c
index 4e2d067c4032533af2e971677104c44934bf7496..c78a9a9ab1a41b7cd80b98a9bd1d588eef507f7f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *      Steve McClure, 1998-2000
  */
 
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "sect.h"
-#include "item.h"
-#include "xy.h"
-#include "path.h"
-#include "nsc.h"
-#include "file.h"
-#include "nat.h"
-#include "optlist.h"
+#include <config.h>
+
 #include "commands.h"
+#include "map.h"
+#include "optlist.h"
+#include "path.h"
 
-static long do_desi(struct natstr *natp, s_char *sects, s_char *deschar,
-                   long int cash, int for_real);
+static long do_desi(struct natstr *natp, char *sects, char *deschar,
+                   long cash, int for_real);
 
 int
 desi(void)
@@ -59,7 +53,7 @@ desi(void)
     if (player->argp[2]) {
        cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
        if (cost < 0)
-           return (int)(-cost);
+           return (int)-cost;
        if (chkmoney(cost, cash, player->argp[3]))
            return RET_SYN;
     }
@@ -67,11 +61,11 @@ desi(void)
 }
 
 static long
-do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
+do_desi(struct natstr *natp, char *sects, char *deschar, long cash,
        int for_real)
 {
-    register int n;
-    s_char *p;
+    int n;
+    char *p;
     int breaksanct;
     int cap_x;
     int cap_y;
@@ -79,8 +73,8 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
     struct nstr_sect nstr;
     struct sctstr sect;
     struct sctstr check;
-    s_char prompt[128];
-    s_char buf[1024];
+    char prompt[128];
+    char buf[1024];
     long cost = 0;
     int changed = 0;
     int warned = 0;
@@ -97,18 +91,8 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
     while (!player->aborted && nxtsct(&nstr, &sect)) {
        if (!player->owner)
            continue;
-       if (!player->god) {
-           if (sect.sct_type == SCT_MOUNT ||
-               sect.sct_type == SCT_BTOWER ||
-               sect.sct_type == SCT_BSPAN ||
-               sect.sct_type == SCT_WASTE ||
-               sect.sct_type == SCT_PLAINS ||
-               (opt_NO_LCMS && sect.sct_type == SCT_LIGHT) ||
-               (opt_NO_HCMS && sect.sct_type == SCT_HEAVY) ||
-               (opt_NO_OIL && sect.sct_type == SCT_OIL) ||
-               (opt_NO_OIL && sect.sct_type == SCT_REFINE))
-               continue;
-       }
+       if (!player->god && dchr[sect.sct_type].d_cost < 0)
+           continue;
        sprintf(prompt, "%s %d%% %s  desig? ",
                xyas(sect.sct_x, sect.sct_y, player->cnum),
                sect.sct_effic, dchr[sect.sct_type].d_name);
@@ -118,28 +102,27 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
        if (!check_sect_ok(&sect))
            continue;
 
-       des = typematch(p, EF_SECTOR);
+       des = sct_typematch(p);
        if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
                        !player->god)) {
-           pr("See \"info Sector-types\"\n");
+           pr("No such designation\n"
+              "See \"info Sector-types\" for possible designations\n");
            if (for_real)
                return (long)RET_FAIL;
            else
                return (long)-RET_FAIL;
        }
        if (!player->god) {
-           if (des == SCT_WATER || des == SCT_MOUNT ||
-               des == SCT_SANCT || des == SCT_PLAINS ||
-               (opt_NO_LCMS && des == SCT_LIGHT) ||
-               (opt_NO_HCMS && des == SCT_HEAVY) ||
-               (opt_NO_OIL && des == SCT_OIL) ||
-               (opt_NO_OIL && des == SCT_REFINE)) {
-               pr("Only %s can make a %s!\n", cname(0), dchr[des].d_name);
+           if (des == SCT_WASTE) {
+               if (for_real)
+                   pr("Only a nuclear device (or %s) can make a %s!\n",
+                      cname(0), dchr[des].d_name);
                continue;
            }
-           if (des == SCT_WASTE) {
-               pr("Only a nuclear device (or %s) can make a %s!\n",
-                  cname(0), dchr[des].d_name);
+           if (dchr[des].d_cost < 0) {
+               if (for_real)
+                   pr("Only %s can make a %s!\n",
+                      cname(0), dchr[des].d_name);
                continue;
            }
        }
@@ -147,7 +130,7 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
            continue;
        if (sect.sct_type == SCT_SANCT)
            breaksanct++;
-       if (des == SCT_HARBR) {
+       if ((des == SCT_HARBR) || (des == SCT_BHEAD)) {
            for (n = 1; n <= 6; n++) {
                getsect(nstr.x + diroff[n][0],
                        nstr.y + diroff[n][1], &check);
@@ -169,33 +152,11 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
                    continue;
            }
        }
-       if (des == SCT_BHEAD) {
-           for (n = 1; n <= 6; n++) {
-               getsect(nstr.x + diroff[n][0],
-                       nstr.y + diroff[n][1], &check);
-               if (check.sct_type == SCT_WATER)
-                   break;
-               if (check.sct_type == SCT_BSPAN)
-                   break;
-               if (check.sct_type == SCT_BTOWER)
-                   break;
-           }
-           if (n > 6) {
-               if (for_real)
-                   pr("%s does not border on water.\n",
-                      xyas(nstr.x, nstr.y, player->cnum));
-               if (player->god) {
-                   if (for_real)
-                       pr("But if it's what you want...\n");
-               } else
-                   continue;
-           }
-       }
        if (sect.sct_type == SCT_SANCT && !player->god)
            continue;
        n = sect.sct_type;
        if ((sect.sct_newtype != des) && (sect.sct_type != des)
-           && dchr[des].d_cost) {
+           && dchr[des].d_cost > 0) {
            if (for_real) {
                if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
                               player->argp[3]))
@@ -205,7 +166,9 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
                continue;
            }
        }
-       if (sect.sct_effic < 5 || player->god) {
+       if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
+           if (player->god)
+               set_coastal(&sect, sect.sct_type, des);
            sect.sct_type = des;
            sect.sct_effic = 0;
            changed += map_set(player->cnum, sect.sct_x, sect.sct_y,