]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/navi.c
Fix navigate and march not to lay mines free of charge
[empserver] / src / lib / commands / navi.c
index fc496aafa8b14cc64b226f99caaa41bdbe4bd81c..745208e697e2a066b86732014ab23525b24471b8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  navi.c: Navigate ships and such
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995 (rewritten)
  *     Ron Koenderink, 2006-2007
@@ -34,7 +34,6 @@
 
 #include <config.h>
 
-#include <ctype.h>
 #include "commands.h"
 #include "map.h"
 #include "optlist.h"
@@ -54,7 +53,7 @@ navi(void)
     double minmob, maxmob;
     int together;
 
-    if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1]))
+    if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1], NULL))
        return RET_SYN;
     shp_sel(&ni_ship, &ship_list);
     shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
@@ -83,7 +82,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
     char *pt = pathtaken;
     char bmap_flag;
     int ac;
-    short type;
+    int type;
 
     leader = get_leader(ulist);
     leader_uid = leader->uid;
@@ -94,13 +93,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
 
     if (player->argp[2]) {
        strcpy(buf, player->argp[2]);
-       if (type == EF_SHIP) {
-           if (!(cp = shp_path(*together, (struct shpstr *)leader, buf)))
-               cp = player->argp[2];
-       } else {
-           if (!(cp = lnd_path(*together, (struct lndstr *)leader, buf)))
-               cp = player->argp[2];
-       }
+       if (!(cp = unit_path(*together, leader, buf)))
+           cp = player->argp[2];
     }
 
     *pt = '\0';
@@ -136,7 +130,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            else
                skip = 0;
            sprintf(prompt, "<%.1f:%.1f: %s> ", *maxmob,
-                   *minmob, xyas(leader->x, leader->y, player->cnum)); 
+                   *minmob, xyas(leader->x, leader->y, player->cnum));
            cp = getstring(prompt, buf);
            /* Just in case any of our units were shelled while we were
             * at the prompt, we call shp_nav() or lnd_mar() again.
@@ -161,15 +155,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
                stopping = 1;
                continue;
            }
-           if (type == EF_SHIP) {
-               if (!(cp = shp_path(*together, (struct shpstr *)leader,
-                                   buf)))
-                   cp = buf;
-           } else {
-               if (!(cp = lnd_path(*together, (struct lndstr *)leader,
-                                   buf)))
-                   cp = buf;
-           }
+           if (!(cp = unit_path(*together, leader, buf)))
+               cp = buf;
        }
        if (type == EF_SHIP) {
            radmapnopr(leader->x, leader->y, (int)leader->effic,
@@ -196,8 +183,11 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            cp++;
            continue;
        }
-       ac = parse(cp, player->argp, NULL, scanspace, NULL);
-       if (ac <= 1) {
+       ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
+       if (ac <= 0) {
+           player->argp[0] = "";
+           cp = NULL;
+       } else if (ac == 1) {
            sprintf(dp, "%d", leader->uid);
            player->argp[1] = dp;
            cp++;
@@ -212,7 +202,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
             */
        case 'M':
            do_map(bmap_flag, leader->ef_type, player->argp[1],
-               player->argp[2]);
+                  player->argp[2]);
            skip = 1;
            continue;
        case 'f':
@@ -254,8 +244,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            skip = 1;
            continue;
        case 'd':
-           if (ac == 2) {
-               player->argp[2] = player->argp[1];
+           if (ac < 3) {
+               player->argp[2] = ac < 2 ? "1" : player->argp[1];
                sprintf(dp, "%d", leader->uid);
                player->argp[1] = dp;
            }
@@ -263,17 +253,15 @@ do_unit_move(struct emp_qelem *ulist, int *together,
                mine();
            else
                landmine();
+           stopping = 1;
            skip = 1;
            player->btused++;
            continue;
        case 'v':
-           if (leader->ef_type != EF_SHIP)
-               break;
-           shp_view(ulist);
+           unit_view(ulist);
            continue;
        }
-       direrr("`%c' to stop",
-           type == EF_SHIP ? ", `%c' to view" : NULL, NULL);
+       direrr("`%c' to stop", ", `%c' to view", NULL);
        pr(", `i' to list %s, `f' to change %s,\n",
            type == EF_SHIP ? "ships" : "units",
            type == EF_SHIP ? "flagship" : "leader");
@@ -294,13 +282,10 @@ nav_map(int x, int y, int show_designations)
 {
     char *ptr;
     struct nstr_sect ns;
-    struct natstr *np;
     struct sctstr sect;
-    struct range range;
     int i;
     /* Note this is not re-entrant anyway, so we keep the buffers
        around */
-    static unsigned char *bitmap = NULL;
     static char *wmapbuf = NULL;
     static char **wmap = NULL;
     int changed = 0;
@@ -317,17 +302,12 @@ nav_map(int x, int y, int show_designations)
            wmap = NULL;
        }
     }
-    if (!bitmap)
-       bitmap = malloc((WORLD_X * WORLD_Y) / 8);
-    if (!wmapbuf || !wmap || !bitmap) {
+    if (!wmapbuf || !wmap) {
        pr("Memory error, tell the deity.\n");
        logerror("malloc failed in navi\n");
        return RET_FAIL;
     }
-    memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
     snxtsct_dist(&ns, x, y, 1);
-    np = getnatp(player->cnum);
-    xyrelrange(np, &ns.range, &range);
     blankfill(wmapbuf, &ns.range, 1);
     while (nxtsct(&ns, &sect)) {
        ptr = &wmap[ns.dy][ns.dx];
@@ -347,7 +327,7 @@ nav_map(int x, int y, int show_designations)
         * in which case they'll see that.
         * --ts
         */
-       *ptr = player->bmap[sctoff(sect.sct_x, sect.sct_y)];
+       *ptr = player->bmap[sect.sct_uid];
     }
     if (changed)
        writemap(player->cnum);