]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/navi.c
Fix trailing whitespace
[empserver] / src / lib / commands / navi.c
index af50ba0a5c647299bd39987ae76abb0919ed3766..ddab374868fedfcfd3a31c1628bee7da035fd847 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-2008, 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);
@@ -67,7 +66,7 @@ navi(void)
 }
 
 int
-do_unit_move(struct emp_qelem *unit_list, int *together,
+do_unit_move(struct emp_qelem *ulist, int *together,
             double *minmob, double *maxmob)
 {
     char *cp = NULL;
@@ -85,7 +84,7 @@ do_unit_move(struct emp_qelem *unit_list, int *together,
     int ac;
     short type;
 
-    leader = get_leader(unit_list);
+    leader = get_leader(ulist);
     leader_uid = leader->uid;
     type = leader->ef_type;
     pr("%s is %s\n",
@@ -94,36 +93,30 @@ do_unit_move(struct emp_qelem *unit_list, 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';
-    while (!QEMPTY(unit_list)) {
+    while (!QEMPTY(ulist)) {
        char dp[80];
 
        if (cp == NULL || *cp == '\0' || stopping) {
            stopping = 0;
            if (type == EF_SHIP)
-               shp_nav(unit_list, minmob, maxmob, together, player->cnum);
+               shp_nav(ulist, minmob, maxmob, together, player->cnum);
            else
-               lnd_mar(unit_list, minmob, maxmob, together, player->cnum);
-           if (QEMPTY(unit_list)) {
+               lnd_mar(ulist, minmob, maxmob, together, player->cnum);
+           if (QEMPTY(ulist)) {
                pr("No %s left\n",
                    type == EF_SHIP ? "ships" : "lands");
-               if (strlen(pathtaken) > 0) {
+               if (type == EF_SHIP && strlen(pathtaken) > 1) {
                    pathtaken[strlen(pathtaken) - 1] = '\0';
-                   if (type == EF_SHIP && strlen(pathtaken) > 0)
-                       pr("Path taken: %s\n", pathtaken);
+                   pr("Path taken: %s\n", pathtaken);
                }
                return RET_OK;
            }
-           leader = get_leader(unit_list);
+           leader = get_leader(ulist);
            if (leader->uid != leader_uid) {
                leader_uid = leader->uid;
                pr_leader_change(leader);
@@ -137,41 +130,33 @@ do_unit_move(struct emp_qelem *unit_list, 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.
             */
            if (type == EF_SHIP)
-               shp_nav(unit_list, minmob, maxmob, together, player->cnum);
+               shp_nav(ulist, minmob, maxmob, together, player->cnum);
            else
-               lnd_mar(unit_list, minmob, maxmob, together, player->cnum);
-           if (QEMPTY(unit_list)) {
+               lnd_mar(ulist, minmob, maxmob, together, player->cnum);
+           if (QEMPTY(ulist)) {
                pr("No %s left\n",
                    type == EF_SHIP ? "ships" : "lands");
-               if (strlen(pathtaken) > 0) {
+               if (type == EF_SHIP && strlen(pathtaken) > 1) {
                    pathtaken[strlen(pathtaken) - 1] = '\0';
-                   if (type == EF_SHIP && strlen(pathtaken) > 0)
-                       pr("Path taken: %s\n", pathtaken);
+                   pr("Path taken: %s\n", pathtaken);
                }
                return RET_OK;
            }
-           leader = get_leader(unit_list);
+           leader = get_leader(ulist);
            if (leader->uid != leader_uid) {
                leader_uid = leader->uid;
                pr_leader_change(leader);
                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,
@@ -185,7 +170,7 @@ do_unit_move(struct emp_qelem *unit_list, int *together,
        dir = chkdir(*cp, DIR_STOP, DIR_LAST);
        if (dir >= 0) {
            if (type == EF_SHIP) {
-               stopping |= shp_nav_one_sector(unit_list, dir,
+               stopping |= shp_nav_one_sector(ulist, dir,
                    player->cnum, *together);
                if (stopping != 2) {
                    *pt++ = dirch[dir];
@@ -193,12 +178,12 @@ do_unit_move(struct emp_qelem *unit_list, int *together,
                }
            } else
                stopping |=
-                   lnd_mar_one_sector(unit_list, dir, player->cnum,
+                   lnd_mar_one_sector(ulist, dir, player->cnum,
                        *together);
            cp++;
            continue;
        }
-       ac = parse(cp, player->argp, NULL, scanspace, NULL);
+       ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
        if (ac <= 1) {
            sprintf(dp, "%d", leader->uid);
            player->argp[1] = dp;
@@ -214,32 +199,29 @@ do_unit_move(struct emp_qelem *unit_list, 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':
            if (ac <= 1)
-               switch_leader(unit_list, -1);
+               switch_leader(ulist, -1);
            else
-               switch_leader(unit_list, atoi(player->argp[1]));
-           leader = get_leader(unit_list);
+               switch_leader(ulist, atoi(player->argp[1]));
+           leader = get_leader(ulist);
            if (leader->uid != leader_uid) {
                leader_uid = leader->uid;
                pr_leader_change(leader);
            }
            continue;
        case 'i':
-           if (type == EF_SHIP)
-               shp_list(unit_list);
-           else
-               lnd_list(unit_list);
+           unit_list(ulist);
            continue;
        case 'm':
            if (type == EF_SHIP)
-               stopping |= shp_sweep(unit_list, 1, 1, player->cnum);
+               stopping |= shp_sweep(ulist, 1, 1, player->cnum);
            else {
-               lnd_sweep(unit_list, 1, 1, player->cnum);
-               stopping |= lnd_check_mines(unit_list);
+               lnd_sweep(ulist, 1, 1, player->cnum);
+               stopping |= lnd_check_mines(ulist);
            }
            continue;
        case 'r':
@@ -272,13 +254,10 @@ do_unit_move(struct emp_qelem *unit_list, int *together,
            player->btused++;
            continue;
        case 'v':
-           if (leader->ef_type != EF_SHIP)
-               break;
-           shp_view(unit_list);
+           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");
@@ -287,10 +266,9 @@ do_unit_move(struct emp_qelem *unit_list, int *together,
        pr("`d' to drop mines, and `m' to minesweep\n");
        stopping = 1;
     }
-    if (strlen(pathtaken) > 0) {
+    if (type == EF_SHIP && strlen(pathtaken) > 1) {
        pathtaken[strlen(pathtaken) - 1] = '\0';
-       if (type == EF_SHIP && strlen(pathtaken) > 0)
-           pr("Path taken: %s\n", pathtaken);
+       pr("Path taken: %s\n", pathtaken);
     }
     return RET_OK;
 }
@@ -302,11 +280,9 @@ nav_map(int x, int y, int show_designations)
     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;
@@ -323,17 +299,13 @@ 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];
@@ -353,7 +325,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);