* 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);
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 */
*
*/
-#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"
if (opt_FALLOUT) {
pr("%5d", sect.sct_fallout);
}
- set_coastal(§);
if (sect.sct_coastal)
pr("%4d", sect.sct_coastal);
pr("\n");
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);
-}
}
}
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,
pr("%d ", sect.sct_own);
pr("%d %d", xrel(np, nstr.x), yrel(np, nstr.y));
- set_coastal(§);
n = 0;
while (field[n]) {
pr(" ");
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':
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 \
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 \
--- /dev/null
+/*
+ * 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);
+}
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);
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;
++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;
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();
}
/****************************************************************************
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];
}
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;
}