From 462bc9e7b2e9f969874fae708a3b05eea45ef550 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 5 Apr 2006 08:51:50 +0000 Subject: [PATCH] (owned_and_navigable): Rework rev. 1.18: do check the real sector, but only if it's owned or allied. Check it before the bmap, and do it just like shp_check_nav() does (should use common code). --- src/lib/common/bestpath.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/lib/common/bestpath.c b/src/lib/common/bestpath.c index 66f188a2..2356a1bb 100644 --- a/src/lib/common/bestpath.c +++ b/src/lib/common/bestpath.c @@ -52,7 +52,7 @@ #include "common.h" #include "optlist.h" -static int owned_and_navigable(s_char *, int, int, s_char *, int); +static int owned_and_navigable(char *, int, int, char *, int); #define MAXROUTE 100 /* return '?' if path longer than this */ #define valid(x,y) (((x^y)&1)==0) @@ -235,10 +235,11 @@ bestownedpath(s_char *bpath, /* return TRUE if sector is passable */ static int -owned_and_navigable(s_char *map, int x, int y, s_char *terrain, int own) +owned_and_navigable(char *bigmap, int x, int y, char *terrain, int own) { - s_char *t; - s_char mapspot; /* What this spot on the bmap is */ + char *t; + char mapspot; /* What this spot on the bmap is */ + struct sctstr sect; int negate; /* No terrain to check? Everything is navigable! (this @@ -246,11 +247,31 @@ owned_and_navigable(s_char *map, int x, int y, s_char *terrain, int own) if (!*terrain) return 1; - /* Are we checking this map? */ - if (map) { + /* Owned or allied sector? Check the real sector. */ + getsect(x, y, §); + if (sect.sct_own == own + || (sect.sct_own && getrel(getnatp(sect.sct_own), own) == ALLIED)) { + /* FIXME duplicates shp_check_nav() logic */ + switch (dchr[sect.sct_type].d_nav) { + case NAVOK: + return 1; + case NAV_CANAL: + /* FIXME return 1 when all ships have M_CANAL */ + return 0; + case NAV_02: + return sect.sct_effic >= 2; + case NAV_60: + return sect.sct_effic >= 60; + default: + return 0; + } + } + + /* Can only check bigmap */ + if (bigmap) { /* Do we know what this sector is? If not, we assume it's ok, since otherwise we'll never venture anywhere */ - mapspot = map[sctoff(x, y)]; + mapspot = bigmap[sctoff(x, y)]; if (mapspot == ' ' || mapspot == 0) return 1;