From 7b94794365ffb56f742bdbc179e3fde30cfb6831 Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Thu, 17 Nov 2005 03:21:32 +0000 Subject: [PATCH] (cens, desi, dump, do_desi, doland, file_sct_init, grow_continents) (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 | 3 +- src/lib/commands/cens.c | 34 +----------- src/lib/commands/desi.c | 2 + src/lib/commands/dump.c | 1 - src/lib/commands/edit.c | 1 + src/lib/subs/Makefile | 4 +- src/lib/subs/coastal.c | 115 ++++++++++++++++++++++++++++++++++++++++ src/util/fairland.c | 21 ++++++++ src/util/files.c | 2 + 9 files changed, 146 insertions(+), 37 deletions(-) create mode 100644 src/lib/subs/coastal.c diff --git a/include/prototypes.h b/include/prototypes.h index f2dba1e63..ccdd26b0c 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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 */ diff --git a/src/lib/commands/cens.c b/src/lib/commands/cens.c index a738f24ac..d4467f41d 100644 --- a/src/lib/commands/cens.c +++ b/src/lib/commands/cens.c @@ -32,14 +32,8 @@ * */ -#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(§); 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], §); - 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); -} diff --git a/src/lib/commands/desi.c b/src/lib/commands/desi.c index 62eb7e5b5..b3838f595 100644 --- a/src/lib/commands/desi.c +++ b/src/lib/commands/desi.c @@ -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(§, des); sect.sct_type = des; sect.sct_effic = 0; changed += map_set(player->cnum, sect.sct_x, sect.sct_y, diff --git a/src/lib/commands/dump.c b/src/lib/commands/dump.c index 6e697c614..5ea0036c1 100644 --- a/src/lib/commands/dump.c +++ b/src/lib/commands/dump.c @@ -510,7 +510,6 @@ dump(void) pr("%d ", sect.sct_own); pr("%d %d", xrel(np, nstr.x), yrel(np, nstr.y)); - set_coastal(§); n = 0; while (field[n]) { pr(" "); diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 6a111896f..ea4e63264 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -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': diff --git a/src/lib/subs/Makefile b/src/lib/subs/Makefile index 1594ab656..5b99b8e57 100644 --- a/src/lib/subs/Makefile +++ b/src/lib/subs/Makefile @@ -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 index 000000000..b23366059 --- /dev/null +++ b/src/lib/subs/coastal.c @@ -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], §); + 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], §); + update_coastal_flag(§, 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], §); + if (!sect.sct_coastal) { + sect.sct_coastal = 1; + putsect(§); + } + } +} + +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); +} diff --git a/src/util/fairland.c b/src/util/fairland.c index 149a49d82..74678aefe 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -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]; } diff --git a/src/util/files.c b/src/util/files.c index f5de0cd85..a021fd9e9 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -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; } -- 2.43.0