]> git.pond.sub.org Git - empserver/commitdiff
(fuel, load, shp_check_nav, retreat_ship1, shp_nav_one_sector)
authorRon Koenderink <rkoenderink@yahoo.ca>
Sat, 21 Jan 2006 20:56:50 +0000 (20:56 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Sat, 21 Jan 2006 20:56:50 +0000 (20:56 +0000)
(shp_check_nav, sail_nav_fleet, bigcity_dchr[], sector_navigation[])
(d_navigation): Add a NEW d_navigation enum NAV_CANAL to
indicate that a sector has canal capability. Add canal determination
logic to shp_check_nav(). Update sector_navigation[] with new
canal navigation enum.  Use shp_check_nav() to determine the
sector can be navigated.

include/prototypes.h
include/sect.h
src/lib/commands/fuel.c
src/lib/commands/load.c
src/lib/global/nsc.c
src/lib/global/sect.c
src/lib/subs/retreat.c
src/lib/subs/shpsub.c
src/lib/update/sail.c

index 56273a992594f50372cba6030018d63ccc1c7aef..6e8294b110fa9cfa79be3d78572f8422d547227c 100644 (file)
@@ -684,7 +684,7 @@ extern int shp_sweep(struct emp_qelem *, int, natid);
 extern s_char *shp_path(int, struct shpstr *, s_char *);
 extern void shp_put(struct emp_qelem *, natid);
 extern void shp_list(struct emp_qelem *);
-extern int shp_check_nav(struct sctstr *);
+extern int shp_check_nav(struct sctstr *, struct shpstr *);
 extern int sect_has_dock(struct sctstr *);
 extern int shp_hardtarget(struct shpstr *);
 extern void shp_view(struct emp_qelem *);
index c654c16a248ba4fcdf38dea09de9badf8357716f..b9103939d9038a6695647c1790b1f178d83e9ce5 100644 (file)
@@ -93,6 +93,7 @@ typedef enum {
     NAV_NONE,  /* ships can't navigate */
     NAVOK,     /* ships can always navigate */
     NAV_02,    /* requires 2% effic to navigate */
+    NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
     NAV_60     /* requires 60% effic to navigate */
 } d_navigation;
 
index 103e5bac9fe4babbffad2f76b89979b7ed728a21..3634d56f091e18de066ab167deeef38fa94b2048 100644 (file)
@@ -121,13 +121,9 @@ fuel(void)
            if (!item.ship.shp_own)
                continue;
 
-           if ((sect.sct_type != SCT_HARBR)
-               && (sect.sct_type != SCT_WATER)
-               && (sect.sct_type != SCT_BSPAN)
-               && (!IS_BIG_CITY(sect.sct_type))) {
-               pr("Sector %s is not a harbor, bridge span, or sea.\n",
-                  xyas(item.ship.shp_x, item.ship.shp_y,
-                       item.ship.shp_own));
+           if (shp_check_nav(&sect, &item.ship) == CN_LANDLOCKED) {
+               pr("%s is landlocked and cannot be fueled.\n",
+                  prship(&item.ship));
                continue;
            }
 
index f4723362d990ba7dba3f25a185d0720c10c6bc93..998d86b9414d3e899246a1045a99f6cb2f4be64b 100644 (file)
@@ -153,8 +153,8 @@ load(void)
            if (noisy)
                pr("Sector %s is not a harbor%s%s.\n",
                   xyas(ship.shp_x, ship.shp_y, player->cnum),
-                  dchr[SCT_CAPIT].d_nav == NAV_02 ? " or a " : "",
-                  dchr[SCT_CAPIT].d_nav == NAV_02 ?
+                  dchr[SCT_CAPIT].d_nav == NAV_CANAL ? " or a " : "",
+                  dchr[SCT_CAPIT].d_nav == NAV_CANAL ?
                    dchr[SCT_CAPIT].d_name : "");
            continue;
        }
index 4c8c4d3d7e420c7146ba9678bbd2327d33c15266..a2807207a2d8c66bba8aa4e661bb06bbfe94e9b0 100644 (file)
@@ -787,6 +787,7 @@ struct symbol sector_navigation[] = { /* for d_nav */
     {NAV_NONE, "land"},
     {NAVOK, "sea"},
     {NAV_02, "harbor"},
+    {NAV_CANAL, "canal"},
     {NAV_60, "bridge"},
     {0, NULL}
 };
index bf90eb37107a36364ec5c6abe4be90694653bf31..21d3dff8fc402c3f26ce7f90120d1cab4851b495 100644 (file)
@@ -44,7 +44,7 @@
 #include "product.h"
 
 struct dchrstr bigcity_dchr = {
-    SCT_CAPIT,   'c',       0, 2,  NAV_02,   UPKG, 1.0, 2.0,   30, 0, 10, 1, 2, 999, "city"
+    SCT_CAPIT,   'c',       0, 2, NAV_CANAL, UPKG, 1.0, 2.0,   30, 0, 10, 1, 2, 999, "city"
 };
 
 struct dchrstr dchr[] = {
index 6b89c94d499f07626e3aad82ae8a1f306522c0ba..17d17380ff7183ec4ccc3fe1a6f0f2949df0b047 100644 (file)
@@ -188,7 +188,7 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig)
     }
 
     getsect(sp->shp_x, sp->shp_y, &sect);
-    switch (shp_check_nav(&sect)) {
+    switch (shp_check_nav(&sect, sp)) {
     case CN_CONSTRUCTION:
        wu(0, sp->shp_own,
           "%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n",
@@ -262,7 +262,7 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig)
        mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost));
 
        getsect(newx, newy, &sect);
-       if (shp_check_nav(&sect) != CN_NAVIGABLE ||
+       if (shp_check_nav(&sect, sp) != CN_NAVIGABLE ||
            (sect.sct_own && !player->owner &&
             getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) {
            wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
index c1b021142c400a8d3557667a9994f2b77f35ece8..eed7350a8ba1d7ed4dbbf1bd19c2e6bb84423623 100644 (file)
@@ -156,7 +156,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
            shp_mess("was sucked into the sky by a strange looking spaceship", mlp);    /* heh -KHS */
            continue;
        }
-       switch (shp_check_nav(&sect)) {
+       switch (shp_check_nav(&sect, &ship)) {
        case CN_CONSTRUCTION:
            shp_mess("is caught in a construction zone", mlp);
            continue;
@@ -368,12 +368,18 @@ shp_mess(s_char *str, struct mlist *mlp)
 }
 
 int
-shp_check_nav(struct sctstr *sect)
+shp_check_nav(struct sctstr *sect, struct shpstr *shp)
 {
     switch (dchr[sect->sct_type].d_nav) {
     case NAVOK:
        break;
-
+    case NAV_CANAL:
+       if (mchr[(int)shp->shp_type].m_flags & M_CANAL == M_CANAL) {
+           if (sect->sct_effic < 2)
+               return CN_CONSTRUCTION;
+       } else
+           return CN_LANDLOCKED;
+       break;
     case NAV_02:
        if (sect->sct_effic < 2)
            return CN_CONSTRUCTION;
@@ -821,6 +827,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
     double tech;               /* for mapping */
     double tf;                 /* for mapping */
     s_char dp[80];
+    int navigate;
 
     if (dir <= DIR_STOP || dir >= DIR_VIEW) {
        shp_put(list, actor);
@@ -834,27 +841,27 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
        newx = xnorm(mlp->ship.shp_x + dx);
        newy = ynorm(mlp->ship.shp_y + dy);
        getsect(newx, newy, &sect);
-       if (shp_check_nav(&sect) != CN_NAVIGABLE ||
+       navigate = shp_check_nav(&sect, &mlp->ship);
+       if (navigate != CN_NAVIGABLE ||
            (sect.sct_own && actor != sect.sct_own &&
             getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
-           if (together) {
-               mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
-               return 2;
-           } else {
-               sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
-               shp_mess(dp, mlp);
-               continue;
-           }
-       }
-       if (IS_BIG_CITY(sect.sct_type)) {
-           if (!(mlp->mcp->m_flags & M_CANAL)) {
+           if (dchr[sect.sct_type].d_nav == NAV_CANAL &&
+               !(mlp->mcp->m_flags & M_CANAL) &&
+               navigate == CN_LANDLOCKED)
                sprintf(dp,
                        "is too large to fit into the canal system at %s",
                        xyas(newx, newy, actor));
+           else
+               sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
+           if (together) {
+               mpr(actor, "%s\n", dp);
+               return 2;
+           } else {
                shp_mess(dp, mlp);
                continue;
            }
        }
+
        if (mlp->mobil <= 0.0) {
            shp_mess("is out of mobility", mlp);
            continue;
index e74ad2f8c1d5074a49c584ffb2c072583354cc79..38b1839e4219ec6b1f6f8a509ef66f21bbb12809 100644 (file)
@@ -216,7 +216,6 @@ sail_nav_fleet(struct fltheadstr *fltp)
     natid own;
     struct emp_qelem ship_list;
     int dir;
-    int canal = 1;
 
 #ifdef SAILDEBUG
     switch (fltp->real_q) {
@@ -239,6 +238,7 @@ sail_nav_fleet(struct fltheadstr *fltp)
        wu(0, fltp->own, " %d", fe->num);
     wu(0, fltp->own, "\n");
 #endif
+    sectp = getsectp(fltp->x, fltp->y);
     for (fe = fltp->head; fe; fe = fe->next) {
        sp = getshipp(fe->num);
        if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) {
@@ -246,28 +246,22 @@ sail_nav_fleet(struct fltheadstr *fltp)
               "   ship #%d (%s) is crewless and can't go on\n",
               fe->num, cname(fe->own));
            error = 1;
-       } else if (!(mchr[sp->shp_type].m_flags & M_CANAL))
-           canal = 0;
+       }
+        if ((shp_check_nav(sectp, sp) == CN_LANDLOCKED) &&
+           (dchr[sectp->sct_type].d_nav == NAV_CANAL)) {
+           wu(0, fltp->own,
+              "Your ship #%d (%s) is too big to fit through the canal.\n",
+              fe->num, cname(fe->own));
+           error = 1;
+       }
     }
     if (error)
        return 0;
+    sp = getshipp(fltp->leader);
     sectp = getsectp(fltp->x, fltp->y);
-    switch (shp_check_nav(sectp)) {
-    case CN_NAVIGABLE:
-       if (IS_BIG_CITY(sectp->sct_type) && !canal) {
-           wu(0, fltp->own,
-              "Your fleet lead by %d is too big to fit through the canal.\n",
-              fltp->leader);
-           return 0;
-       }
-       break;
-    case CN_CONSTRUCTION:
-    case CN_LANDLOCKED:
-    default:
+    if (shp_check_nav(sectp, sp) != CN_NAVIGABLE)
        wu(0, fltp->own, "Your fleet lead by %d is trapped by land.\n",
           fltp->leader);
-       return 0;
-    }
     sp = getshipp(fltp->leader);
     own = sp->shp_own;
     fltp_to_list(fltp, &ship_list);    /* hack -KHS 1995 */