]> git.pond.sub.org Git - empserver/commitdiff
(cens, desi, dump, do_desi, doland, file_sct_init, grow_continents)
authorRon Koenderink <rkoenderink@yahoo.ca>
Thu, 17 Nov 2005 03:21:32 +0000 (03:21 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Thu, 17 Nov 2005 03:21:32 +0000 (03:21 +0000)
(grow_islands, set_coastal, update_coastal_flag, coast_sea_to_land)
(coast_land_to_sea): Determine sct_coastal flag when the sector type
is set.  Old method only updated the sct_coastal flag when doing
cens() or a dump().  Other uses of sct_coastal could get stale values,
including selector coastal.  Rework set_coastal() into NEW functions
update_coastal_flag(), coast_sea_to_land(), coast_land_to_sea() and
set_coastal().  Fix a bug where the deity designation would not
properly set the coastal flag.  Fix a bug where the one sector lake
would not properly compute coastal flag.  Fix a bug that makes
fairland treat the last sector it adds to an island as non-coastal.

include/prototypes.h
src/lib/commands/cens.c
src/lib/commands/desi.c
src/lib/commands/dump.c
src/lib/commands/edit.c
src/lib/subs/Makefile
src/lib/subs/coastal.c [new file with mode: 0644]
src/util/fairland.c
src/util/files.c

index f2dba1e63be29da6ddd0ae572370263af0cf28a7..ccdd26b0ce71394be7e3adf467c6461e27094f03 100644 (file)
@@ -62,7 +62,6 @@ extern void finish_server(void);
  * src/lib/commands/ *.c 
  */
 extern int check_market(void);
-extern void set_coastal(struct sctstr *);
 extern int sendmessage(struct natstr *, struct natstr *, char *message, int);
 extern void gift(int, int, s_char *, int, s_char *);
 extern int display_mark(i_type, int);
@@ -465,6 +464,8 @@ extern int chkmoney(long, long, s_char *);
 extern int check_cost(int, int, long, int *, s_char *);
 /* cnumb.c */
 extern int cnumb(s_char *);
+/* coastal.c */
+extern void set_coastal(struct sctstr *sp, int des);
 /* control.c */
 extern int military_control(struct sctstr *);
 /* detonate.c */
index a738f24acd3c60aa36dced257f394f29ae3d9b43..d4467f41dd1c4fe43bc77156955ad662eb1e6d9b 100644 (file)
  *     
  */
 
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "nat.h"
+#include "prototypes.h"
 #include "path.h"
-#include "file.h"
 #include "commands.h"
 #include "optlist.h"
 
@@ -110,7 +104,6 @@ cens(void)
        if (opt_FALLOUT) {
            pr("%5d", sect.sct_fallout);
        }
-       set_coastal(&sect);
        if (sect.sct_coastal)
            pr("%4d", sect.sct_coastal);
        pr("\n");
@@ -145,28 +138,3 @@ cens_hdr(void)
     pr("\n");
 }
 
-void
-set_coastal(struct sctstr *sp)
-{
-    int n;
-    struct sctstr sect;
-    u_char start_flags = sp->sct_coastal;
-
-    /* It's already been set, it didn't change (you can't fill
-       in water, even with bridge spans they are still coastal.) */
-    if (sp->sct_coastal)
-       return;
-    for (n = 1; n <= 6; ++n) { /* Directions */
-       getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
-       if (sect.sct_type == SCT_WATER ||
-           sect.sct_type == SCT_BTOWER || sect.sct_type == SCT_BSPAN) {
-           sp->sct_coastal = 1;
-           if (start_flags != sp->sct_coastal)
-               putsect(sp);
-           return;
-       }
-    }
-    sp->sct_coastal = 0;
-    if (start_flags != sp->sct_coastal)
-       putsect(sp);
-}
index 62eb7e5b5c838e68b399d524d011e89bbe6f6665..b3838f595d33d9624396b91e980cd3aef2addb0d 100644 (file)
@@ -169,6 +169,8 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
            }
        }
        if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
+           if (player->god)
+               set_coastal(&sect, des);
            sect.sct_type = des;
            sect.sct_effic = 0;
            changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
index 6e697c6146ede4b63361293298e038e3dae1e760..5ea0036c1e0d6a51656cd46283da4710b2bc8353 100644 (file)
@@ -510,7 +510,6 @@ dump(void)
            pr("%d ", sect.sct_own);
        pr("%d %d", xrel(np, nstr.x), yrel(np, nstr.y));
 
-       set_coastal(&sect);
        n = 0;
        while (field[n]) {
            pr(" ");
index 6a111896f2bb0cc35028c4f6f550bcb493ba8d68..ea4e632649471c8b081629a87d23b6c25d0a48f3 100644 (file)
@@ -651,6 +651,7 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
        pr("Designation for sector %s changed from %c to %c\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           dchr[sect->sct_type].d_mnem, dchr[des].d_mnem);
+       set_coastal(sect, des);
        sect->sct_type = des;
        break;
     case 'S':
index 1594ab656d7995c8955e01da7c822dc8928cc1da..5b99b8e57b92a04d905706f671041111ab91aa95 100644 (file)
@@ -36,7 +36,7 @@ LIB = $(SRCDIR)/lib/libsubs.a
 NTLIB = $(SRCDIR)\lib\libsubs.lib
 
 OBJS = aircombat.o askyn.o aswplnsubs.o attsub.o bigmap.o border.o bsanct.o \
-       caploss.o chkmoney.o cnumb.o control.o detonate.o disloan.o \
+       caploss.o chkmoney.o cnumb.o coastal.o control.o detonate.o disloan.o \
        distrea.o fileinit.o fortdef.o getbit.o getele.o land.o landgun.o \
        list.o lndsub.o lostsub.o mission.o move.o mslsub.o mtch.o natarg.o \
        neigh.o nreport.o nstr.o nuke.o nxtitem.o nxtsct.o paths.o plane.o \
@@ -45,7 +45,7 @@ OBJS = aircombat.o askyn.o aswplnsubs.o attsub.o bigmap.o border.o bsanct.o \
        takeover.o trdsub.o trechk.o whatitem.o wu.o
 
 NTOBJS = aircombat.obj askyn.obj aswplnsubs.obj attsub.obj bigmap.obj \
-       border.obj bsanct.obj caploss.obj chkmoney.obj cnumb.obj \
+       border.obj bsanct.obj caploss.obj chkmoney.obj cnumb.obj coastal.obj \
        control.obj detonate.obj disloan.obj distrea.obj fileinit.obj fortdef.obj \
        getbit.obj getele.obj land.obj landgun.obj list.obj lndsub.obj \
        lostsub.obj mission.obj move.obj mslsub.obj mtch.obj natarg.obj neigh.obj \
diff --git a/src/lib/subs/coastal.c b/src/lib/subs/coastal.c
new file mode 100644 (file)
index 0000000..b233660
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program 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
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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
+ *
+ *  ---
+ *
+ *  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.
+ *
+ *  ---
+ *
+ *  coastal.c: Routines to calculate the coastal flag
+ * 
+ *  Known contributors to this file:
+ *     Ron Koenderink, 2005
+ *     
+ */
+#include "prototypes.h"
+#include "file.h"
+#include "path.h"
+
+static void
+update_coastal_flag(struct sctstr *sp, struct sctstr *sectp)
+{
+    int n;
+    struct sctstr sect;
+
+    for (n = 1; n <= 6; n++) { /* Directions */
+       getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
+       if (sectp && sectp->sct_x == sect.sct_x &&
+           sectp->sct_y == sect.sct_y)
+           continue;
+       if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BTOWER ||
+           sect.sct_type == SCT_BSPAN) {
+           if (!sp->sct_coastal) {
+               sp->sct_coastal = 1;
+               putsect(sp);
+           }
+           return;
+       }
+    }
+    if (sp->sct_coastal) {
+        sp->sct_coastal = 0;
+       putsect(sp);
+    }
+}
+
+static void
+coastal_sea_to_land(struct sctstr *sp, int des)
+{
+    int n;
+    struct sctstr sect;
+
+    update_coastal_flag(sp, NULL);
+
+    for (n = 1; n <= 6; n++) { /* Directions */
+       getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
+       update_coastal_flag(&sect, sp);
+    }
+}
+
+static void
+coastal_land_to_sea(struct sctstr *sp, int des)
+{
+    int n;
+    struct sctstr sect;
+
+    sp->sct_coastal = 1;
+    putsect(sp);
+
+    for (n = 1; n <= 6; ++n) { /* Directions */
+       getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
+       if (!sect.sct_coastal) {
+           sect.sct_coastal = 1;
+           putsect(&sect);
+       }
+    }
+}
+
+void
+set_coastal(struct sctstr *sp, int des)
+{
+    int old_water = 0;
+    int new_water = 0;
+
+    if (sp->sct_type == SCT_WATER || sp->sct_type == SCT_BTOWER ||
+       sp->sct_type == SCT_BSPAN)
+       old_water = 1;
+
+    if (des == SCT_WATER || des == SCT_BTOWER || des== SCT_BSPAN)
+       new_water = 1;
+
+    if (new_water == old_water)
+       return;
+    else if (new_water)
+       coastal_land_to_sea(sp, des);
+    else
+       coastal_sea_to_land(sp, des);
+}
index 149a49d820e6d89fe425accc1b0c9526c7c97ced..74678aefeaed6b16481a47d69e9027b574f40bf5 100644 (file)
@@ -179,6 +179,7 @@ static void translate_continents(void);
 static int map_symbol(int x, int y);
 static void fl_sct_init(coord x, coord y, s_char *ptr,
                        time_t timestamp);
+static void set_coastal_flags(void);
 
 static void print_vars(void);
 static void fl_move(int);
@@ -775,6 +776,9 @@ grow_continents(void)
            grow_one_sector(c);
        }
     }
+    for (c = 0; c < nc; ++c)
+       find_coast(c);
+
     if (fl_status)
        qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
     ctot = nc;
@@ -830,6 +834,7 @@ grow_islands(void)
            ++secs;
            find_coast(c);
        } while (secs < isiz && grow_one_sector(c));
+       find_coast(c);
        qprint(" %d(%d)", c - nc + 1, secs);
        isecs[c] = secs;
        ctot = c;
@@ -1107,6 +1112,7 @@ write_sects(void)
            sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_type = SCT_AIRPT;
            sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_newtype = SCT_AIRPT;
        }
+    set_coastal_flags();
 }
 
 /****************************************************************************
@@ -1275,4 +1281,19 @@ fl_sct_init(coord x, coord y, s_char *ptr, time_t timestamp)
     sp->sct_rail = 0;
     sp->sct_defense = 0;
     sp->sct_timestamp = timestamp;
+    sp->sct_coastal = 1;
+}
+
+static void
+set_coastal_flags(void)
+{
+    int i, j;
+
+    qprint("setting coastal flags...\n");
+    for (i = 0; i < nc; ++i)
+       for (j = 0; j < sc; j++)
+           sects[secty[i][j]][sectx[i][j] / 2].sct_coastal = sectc[i][j];
+    for (i = nc; i < nc + ni; ++i)
+       for (j = 0; j < isecs[i]; j++)
+           sects[secty[i][j]][sectx[i][j] / 2].sct_coastal = sectc[i][j];
 }
index f5de0cd8549dddad48b52f56b4815d1a5e05f085..a021fd9e94e8286dcf8a444f28e526a8db4b4181 100644 (file)
@@ -203,4 +203,6 @@ file_sct_init(coord x, coord y, s_char *ptr, time_t timestamp)
     sp->sct_dist_x = x;
     sp->sct_dist_y = y;
     sp->sct_timestamp = timestamp;
+    sp->sct_newtype = sp->sct_type = SCT_WATER;
+    sp->sct_coastal = 1;
 }