]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/navi.c
Rename obj_nameof() to unit_nameof() and move to unitsub.c
[empserver] / src / lib / commands / navi.c
index 1e2ec5d702db7f050e07896c09f47f0e22b9cb95..fec4bb8c0c75fa901d7e80c304d8a07e3960a119 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire 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
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  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
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -30,6 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995 (rewritten)
  *     Ron Koenderink, 2006-2007
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
@@ -38,7 +38,6 @@
 #include "map.h"
 #include "optlist.h"
 #include "path.h"
-#include "empobj.h"
 #include "unit.h"
 
 static void pr_leader_change(struct empobj *leader);
@@ -82,19 +81,18 @@ 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;
     type = leader->ef_type;
     pr("%s is %s\n",
        type == EF_SHIP ? "Flagship" : "Leader",
-       obj_nameof(leader));
+       unit_nameof(leader));
 
     if (player->argp[2]) {
        strcpy(buf, player->argp[2]);
-       if (!(cp = unit_path(*together, leader, buf)))
-           cp = player->argp[2];
+       cp = unit_path(*together, leader, buf);
     }
 
     *pt = '\0';
@@ -108,8 +106,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            else
                lnd_mar(ulist, minmob, maxmob, together, player->cnum);
            if (QEMPTY(ulist)) {
-               pr("No %s left\n",
-                   type == EF_SHIP ? "ships" : "lands");
+               pr("No %s left\n", type == EF_SHIP ? "ships" : "lands");
                if (type == EF_SHIP && strlen(pathtaken) > 1) {
                    pathtaken[strlen(pathtaken) - 1] = '\0';
                    pr("Path taken: %s\n", pathtaken);
@@ -125,8 +122,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            }
            if (!skip)
                nav_map(leader->x, leader->y,
-                       type == EF_SHIP ?
-                           !(mchr[(int)leader->type].m_flags & M_SUB) : 1);
+                       type == EF_SHIP
+                       ? !(mchr[(int)leader->type].m_flags & M_SUB) : 1);
            else
                skip = 0;
            sprintf(prompt, "<%.1f:%.1f: %s> ", *maxmob,
@@ -140,8 +137,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            else
                lnd_mar(ulist, minmob, maxmob, together, player->cnum);
            if (QEMPTY(ulist)) {
-               pr("No %s left\n",
-                   type == EF_SHIP ? "ships" : "lands");
+               pr("No %s left\n", type == EF_SHIP ? "ships" : "lands");
                if (type == EF_SHIP && strlen(pathtaken) > 1) {
                    pathtaken[strlen(pathtaken) - 1] = '\0';
                    pr("Path taken: %s\n", pathtaken);
@@ -155,15 +151,12 @@ do_unit_move(struct emp_qelem *ulist, int *together,
                stopping = 1;
                continue;
            }
-           if (!(cp = unit_path(*together, leader, buf)))
-               cp = buf;
+           if (cp)
+               cp = unit_path(*together, leader, cp);
        }
        if (type == EF_SHIP) {
-           radmapnopr(leader->x, leader->y, (int)leader->effic,
-                      (int)techfact(leader->tech,
-                                    mchr[(int)leader->type].m_vrnge),
-                      (mchr[(int)leader->type].m_flags & M_SONAR)
-                      ? techfact(leader->tech, 1.0) : 0.0);
+           rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
+                       leader->tech, mchr[leader->type].m_vrnge);
        }
        if (cp == NULL || *cp == '\0')
            cp = &dirch[DIR_STOP];
@@ -171,7 +164,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
        if (dir >= 0) {
            if (type == EF_SHIP) {
                stopping |= shp_nav_one_sector(ulist, dir,
-                   player->cnum, *together);
+                                              player->cnum, *together);
                if (stopping != 2) {
                    *pt++ = dirch[dir];
                    *pt = '\0';
@@ -179,12 +172,15 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            } else
                stopping |=
                    lnd_mar_one_sector(ulist, dir, player->cnum,
-                       *together);
+                                      *together);
            cp++;
            continue;
        }
        ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
-       if (ac <= 1) {
+       if (ac <= 0) {
+           player->argp[0] = "";
+           cp = NULL;
+       } else if (ac == 1) {
            sprintf(dp, "%d", leader->uid);
            player->argp[1] = dp;
            cp++;
@@ -198,8 +194,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
             * fall through
             */
        case 'M':
-           do_map(bmap_flag, leader->ef_type, player->argp[1],
-                  player->argp[2]);
+           display_region_map(bmap_flag, type, leader->x, leader->y,
+                              player->argp[1], player->argp[2]);
            skip = 1;
            continue;
        case 'f':
@@ -241,8 +237,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;
            }
@@ -250,6 +246,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
                mine();
            else
                landmine();
+           stopping = 1;
            skip = 1;
            player->btused++;
            continue;
@@ -278,7 +275,6 @@ nav_map(int x, int y, int show_designations)
 {
     char *ptr;
     struct nstr_sect ns;
-    struct natstr *np;
     struct sctstr sect;
     int i;
     /* Note this is not re-entrant anyway, so we keep the buffers
@@ -305,7 +301,6 @@ nav_map(int x, int y, int show_designations)
        return RET_FAIL;
     }
     snxtsct_dist(&ns, x, y, 1);
-    np = getnatp(player->cnum);
     blankfill(wmapbuf, &ns.range, 1);
     while (nxtsct(&ns, &sect)) {
        ptr = &wmap[ns.dy][ns.dx];
@@ -339,7 +334,7 @@ pr_leader_change(struct empobj *leader)
 {
     pr("Changing %s to %s\n",
        leader->ef_type == EF_SHIP ? "flagship" : "leader",
-       obj_nameof(leader));
+       unit_nameof(leader));
 }
 
 static struct empobj *
@@ -359,11 +354,11 @@ switch_leader(struct emp_qelem *list, int uid)
 
     save = qp = list->q_back;
     do {
-        emp_remque(qp);
-        emp_insque(qp, list);
-        qp = list->q_back;
-        ulp = (struct ulist *)qp;
-        if (ulp->unit.gen.uid == uid || uid == -1)
-            break;
+       emp_remque(qp);
+       emp_insque(qp, list);
+       qp = list->q_back;
+       ulp = (struct ulist *)qp;
+       if (ulp->unit.gen.uid == uid || uid == -1)
+           break;
     } while (list->q_back != save);
 }