]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
Fix automatic supply of defending and reacting units
[empserver] / src / lib / subs / attsub.c
index b44128bdfe5f7f796069823dd4d039f6198ec8f4..7f47f1323057d6073e0e1e00d7fc6b30027250fb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  attsub.c: Attack subroutines
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
+ *     Markus Armbruster, 2006-2008
  */
 
+#include <config.h>
+
+#include <ctype.h>
 #include <math.h>
-#include "misc.h"
-#include "player.h"
+#include "combat.h"
 #include "file.h"
-#include "var.h"
-#include "sect.h"
-#include "ship.h"
-#include "path.h"
-#include "news.h"
-#include "treaty.h"
-#include "nat.h"
-#include "xy.h"
-#include "land.h"
-#include "nsc.h"
+#include "map.h"
+#include "misc.h"
 #include "mission.h"
-#include "combat.h"
-#include "item.h"
+#include "nsc.h"
 #include "optlist.h"
+#include "path.h"
+#include "plague.h"
+#include "player.h"
 #include "prototypes.h"
+#include "xy.h"
+#include "empobj.h"
+#include "unit.h"
 
 #define CASUALTY_LUMP  1       /* How big casualty chunks should be */
 
 static void ask_olist(int combat_mode, struct combat *off,
                      struct combat *def, struct emp_qelem *olist,
-                     s_char *land_answer, int *a_spyp, int *a_engineerp);
-static void take_move_in_mob(int combat_mode, struct llist *llp,
+                     char *land_answer, int *a_spyp, int *a_engineerp);
+static void take_move_in_mob(int combat_mode, struct ulist *llp,
                             struct combat *off, struct combat *def);
 static void move_in_land(int combat_mode, struct combat *off,
                         struct emp_qelem *olist, struct combat *def);
@@ -69,12 +69,13 @@ static int board_abort(struct combat *off, struct combat *def);
 static int land_board_abort(struct combat *off, struct combat *def);
 static int ask_off(int combat_mode, struct combat *off,
                   struct combat *def);
-static int get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
-                    int *d_spyp);
+static void get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
+                     int *d_spyp);
 static int get_ototal(int combat_mode, struct combat *off,
                      struct emp_qelem *olist, double osupport, int check);
 static int get_dtotal(struct combat *def, struct emp_qelem *list,
                      double dsupport, int check);
+static double att_calcodds(int, int);
 static int take_casualty(int combat_mode, struct combat *off,
                         struct emp_qelem *olist);
 
@@ -83,9 +84,9 @@ static int take_def(int combat_mode, struct emp_qelem *list,
                    struct combat *off, struct combat *def);
 
 static int get_land(int combat_mode, struct combat *def, int uid,
-                   struct llist *llp, int victim_land);
+                   struct ulist *llp, int victim_land);
 
-s_char *att_mode[] = {
+char *att_mode[] = {
     /* must match combat types in combat.h */
     "defend", "attack", "assault", "paradrop", "board", "lboard"
 };
@@ -100,7 +101,7 @@ s_char *att_mode[] = {
  * the type of the object is determined by combat->type which can take the
  * values EF_SECTOR, EF_SHIP, EF_PLANE, or EF_BAD.  Another important parameter
  * which is often passed to these functions is combat_mode.  This can take
- * the value A_DEFENSE, A_ATTACK, A_ASSAULT, A_PARA, A_BOARD and A_LBOARD.
+ * the value A_DEFEND, A_ATTACK, A_ASSAULT, A_PARA, A_BOARD and A_LBOARD.
  * As these six modes of being in combat affect things like mobcost and combat
  * value, there are often switches made on combat_mode.  Note that in all cases
  * no mobility is taken from sectors, ships, or land units until the player
@@ -125,7 +126,7 @@ att_combat_init(struct combat *com, int type)
 
 /* print a combat object with optional preposition */
 
-static s_char *
+static char *
 pr_com(int inon, struct combat *com, natid who)
 {
     if (com->type == EF_SECTOR) {
@@ -133,16 +134,10 @@ pr_com(int inon, struct combat *com, natid who)
                     inon ? inon == 1 ? "in " : "into " : "",
                     xyas(com->x, com->y, who));
     } else if (com->type == EF_SHIP) {
-       if (opt_SHIPNAMES) {
-           return prbuf("%s%s %s(#%d)",
-                        inon ? inon == 1 ? "on " : "onto " : "",
-                        com->shp_mcp->m_name, com->shp_name,
-                        com->shp_uid);
-       } else {
-           return prbuf("%s%s #%d",
-                        inon ? inon == 1 ? "on " : "onto " : "",
-                        com->shp_mcp->m_name, com->shp_uid);
-       }
+       return prbuf("%s%s %s(#%d)",
+                    inon ? inon == 1 ? "on " : "onto " : "",
+                    com->shp_mcp->m_name, com->shp_name,
+                    com->shp_uid);
     } else if (com->type == EF_LAND) {
        return prbuf("%s%s #%d",
                     inon ? inon == 1 ? "on " : "onto " : "",
@@ -152,48 +147,15 @@ pr_com(int inon, struct combat *com, natid who)
     }
 }
 
-static s_char *
+static char *
 prcom(int inon, struct combat *com)
 {
     return pr_com(inon, com, player->cnum);
 }
 
-/* Doing a sneak attack */
-static void
-do_sneak(struct combat *def, int success)
-{
-    struct sctstr sect;
-    struct natstr *natp = getnatp(player->cnum);
-    int issneak = getrel(natp, def->own);
-
-    if (def->type != EF_SECTOR)
-       return;
-
-    getsect(def->x, def->y, &sect);
-
-    if (issneak == AT_WAR || !def->own || sect.sct_oldown == player->cnum)
-       return;
-
-    if (success)
-       pr("Your sneak attack was successful\nBut ");
-    else
-       pr("Your sneak attack was unsuccessful\nAnd ");
-
-    pr("it will cost you $5000\n");
-    pr("War has been declared!!!!\n");
-    wu(0, def->own, "Country %s (#%d) has Sneak Attacked!!\n",
-       cname(player->cnum), player->cnum);
-    wu(0, def->own, "Country %s (#%d) has Declared WAR on you!!\n",
-       cname(player->cnum), player->cnum);
-    player->dolcost += 5000;
-    issneak = min(issneak, MOBILIZATION);
-    nreport(player->cnum, N_DECL_WAR, def->own, 1);
-    setrel(player->cnum, def->own, issneak);
-}
-
 /*
  * This is the combat object "type" based integrity check.  It basically
- * splits along three divisions: ship/sector, attacker/defender, 
+ * splits along three divisions: ship/sector, attacker/defender,
  * first time/not first time.
  */
 
@@ -227,7 +189,7 @@ att_get_combat(struct combat *com, int isdef)
        y = com->y;
        break;
     case EF_LAND:
-       if (!getland(com->lnd_uid, &land)) {
+       if (!getland(com->lnd_uid, &land) || !land.lnd_own) {
            if (isdef)
                pr("Land unit #%d is not in the same sector!\n",
                   com->lnd_uid);
@@ -256,7 +218,7 @@ att_get_combat(struct combat *com, int isdef)
        }
        if (opt_MARKET) {
            if (isdef && player->owner &&
-               ontradingblock(EF_SHIP, (int *)&ship)) {
+               ontradingblock(EF_SHIP, &ship)) {
                pr("%s is on the trading block.\n", prcom(0, com));
                return att_combat_init(com, EF_BAD);
            }
@@ -266,8 +228,7 @@ att_get_combat(struct combat *com, int isdef)
            return att_combat_init(com, EF_BAD);
        }
        com->shp_mcp = &mchr[(int)ship.shp_type];
-       if (opt_SHIPNAMES)
-           strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
+       strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN);
        if (!isdef && !player->owner) {
            if (com->set)
                pr("%s was just sunk!\n", prcom(0, com));
@@ -300,7 +261,7 @@ att_get_combat(struct combat *com, int isdef)
            else if (mil == 1)
                pr("Only 1 mil %s\n", prcom(1, com));
            /* don't abandon attacking sectors or ships */
-           com->troops = max(0, mil - 1);
+           com->troops = MAX(0, mil - 1);
        }
        com->plague = pstage == PLG_INFECT;
     } else {                   /* not first time */
@@ -311,11 +272,12 @@ att_get_combat(struct combat *com, int isdef)
            }
            if (owner != com->own) {
                if (owner) {
-                   pr("WARNING: The ownership of %s just changed from %s to %s!\n", prcom(0, com), cname(com->own), cname(owner));
+                   pr("WARNING: The ownership of %s just changed from %s to %s!\n",
+                      prcom(0, com), cname(com->own), cname(owner));
                } else if (com->type == EF_SECTOR) {
                    pr("WARNING: %s just abandoned sector %s!\n",
-                      cname(com->own), xyas(com->x, com->y,
-                                            player->cnum));
+                      cname(com->own),
+                      xyas(com->x, com->y, player->cnum));
                }
            }
            if (com->mil != mil)
@@ -325,18 +287,23 @@ att_get_combat(struct combat *com, int isdef)
                   mil);
            com->troops = mil;
        } else {                /* attacker */
-           if (owner != player->cnum && getrel(getnatp(owner), player->cnum) != ALLIED) {      /* must be EF_SECTOR */
+           if (owner != player->cnum && getrel(getnatp(owner), player->cnum) != ALLIED) {
+               /* must be EF_SECTOR */
                if (com->mil)
-                   pr("WARNING: Your %d mil in %s were destroyed because %s just took the sector!\n", com->mil, xyas(com->x, com->y, player->cnum), cname(owner));
+                   pr("WARNING: Your %d mil in %s were destroyed because %s just took the sector!\n",
+                      com->mil, xyas(com->x, com->y, player->cnum),
+                      cname(owner));
                else
                    pr("You no longer own %s\n",
                       xyas(com->x, com->y, player->cnum));
                return att_combat_init(com, EF_BAD);
            }
            if (com->troops && com->troops + 1 > mil) {
-               if (com->own == owner && player->cnum == owner) /* not a takeover */
-                   pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0, mil - 1));
-               com->troops = max(0, mil - 1);
+               if (com->own == owner && player->cnum == owner)
+                   /* not a takeover */
+                   pr("WARNING: Your mil %s has been reduced from %d to %d!\n",
+                      prcom(1, com), com->troops, MAX(0, mil - 1));
+               com->troops = MAX(0, mil - 1);
            }
        }
     }
@@ -370,9 +337,9 @@ put_combat(struct combat *com)
        sect.sct_type = com->sct_type;
        deff = sect.sct_effic - com->eff;
        if (deff > 0) {
-           sect.sct_road -= (sect.sct_road * deff / 100.0);
-           sect.sct_rail -= (sect.sct_rail * deff / 100.0);
-           sect.sct_defense -= (sect.sct_defense * deff / 100.0);
+           sect.sct_road -= sect.sct_road * deff / 100.0;
+           sect.sct_rail -= sect.sct_rail * deff / 100.0;
+           sect.sct_defense -= sect.sct_defense * deff / 100.0;
            if (sect.sct_road <= 0)
                sect.sct_road = 0;
            if (sect.sct_rail <= 0)
@@ -381,8 +348,6 @@ put_combat(struct combat *com)
                sect.sct_defense = 0;
        }
        sect.sct_effic = com->eff;
-       if (!opt_DEFENSE_INFRA)
-           sect.sct_defense = sect.sct_effic;
        if (com->mobcost) {
            if (opt_MOB_ACCESS) {
                if ((com->mob - com->mobcost) < -127)
@@ -396,8 +361,6 @@ put_combat(struct combat *com)
                    sect.sct_mobil = (short)(com->mob - com->mobcost);
            }
        }
-       makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
-       makenotlost(EF_SECTOR, com->own, 0, sect.sct_x, sect.sct_y);
        sect.sct_own = com->own;
        if (com->plague) {
            if (sect.sct_pstage == PLG_HEALTHY)
@@ -414,20 +377,15 @@ put_combat(struct combat *com)
            if (com->mob - com->mobcost < -127)
                land.lnd_mobil = -127;
            else
-               land.lnd_mobil = (s_char)(com->mob - com->mobcost);
+               land.lnd_mobil = (signed char)(com->mob - com->mobcost);
        }
-       makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
-                land.lnd_y);
        land.lnd_own = com->own;
-       makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
-                   land.lnd_y);
        if (com->plague) {
            if (land.lnd_pstage == PLG_HEALTHY)
                land.lnd_pstage = PLG_EXPOSED;
        }
        if (!(com->lnd_lcp->l_flags & L_SPY))
            land.lnd_item[I_MILIT] = com->mil;
-       lnd_count_units(&land);
        if (com->own == player->cnum) {
            land.lnd_mission = 0;
            land.lnd_rflags = 0;
@@ -442,19 +400,14 @@ put_combat(struct combat *com)
            if (com->mob - com->mobcost < -127)
                ship.shp_mobil = -127;
            else
-               ship.shp_mobil = (s_char)(com->mob - com->mobcost);
+               ship.shp_mobil = (signed char)(com->mob - com->mobcost);
        }
-       makelost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
-                ship.shp_y);
        ship.shp_own = com->own;
-       makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
-                   ship.shp_y);
        if (com->plague) {
            if (ship.shp_pstage == PLG_HEALTHY)
                ship.shp_pstage = PLG_EXPOSED;
        }
        ship.shp_item[I_MILIT] = com->mil;
-       count_units(&ship);
        if (com->own == player->cnum) {
            ship.shp_mission = 0;
            ship.shp_rflags = 0;
@@ -483,8 +436,8 @@ int
 att_abort(int combat_mode, struct combat *off, struct combat *def)
 {
     struct sctstr sect;
-    int issneak;
-    s_char y_or_n[512];
+    int rel;
+    char y_or_n[512];
     struct natstr *natp;
 
     if (player->aborted)
@@ -496,6 +449,7 @@ att_abort(int combat_mode, struct combat *off, struct combat *def)
        if (att_get_combat(off, 0) < 0)
            return abort_attack();
        if (off->type == EF_SHIP &&
+           !(off->x == def->x && off->y == def->y) &&
            (!getsect(off->x, off->y, &sect) ||
             sect.sct_type != SCT_WATER)) {
            pr("%s can not %s from that far inland!\n",
@@ -547,9 +501,9 @@ att_abort(int combat_mode, struct combat *off, struct combat *def)
        return land_board_abort(off, def);
     }
 
-    if (off && def->sct_dcp->d_mcst <= 0) {
-       pr("You can't %s a %s sector!\n", att_mode[combat_mode],
-          def->sct_dcp->d_name);
+    if (off && def->sct_dcp->d_mob0 < 0) {
+       pr("You can't %s a %s sector!\n",
+          att_mode[combat_mode], def->sct_dcp->d_name);
        return abort_attack();
     }
     if (!off || off->relations_checked)
@@ -562,40 +516,19 @@ att_abort(int combat_mode, struct combat *off, struct combat *def)
     }
     if (opt_SLOW_WAR && def->own != player->cnum) {
        natp = getnatp(player->cnum);
-       issneak = getrel(natp, def->own);
+       rel = getrel(natp, def->own);
 
-       if (issneak == ALLIED) {
+       if (rel == ALLIED) {
            sprintf(y_or_n, "Sector is owned by %s, your ally, %s [yn]? ",
                    cname(def->own), att_mode[combat_mode]);
            if (!confirm(y_or_n))
                return abort_attack();
 
        }
-       if (opt_SNEAK_ATTACK) {
-           getsect(def->x, def->y, &sect);
-           if ((issneak != AT_WAR) && (def->own)
-               && (def->own != player->cnum)
-               && (sect.sct_oldown != player->cnum)
-               && (issneak != SITZKRIEG) && (issneak != MOBILIZATION)) {
-               pr("You're not at war with them!\n");
-               if (!confirm("Do you really want to sneak attack (it will cost you $5000) [yn]? ")) {
-                   pr("Sneak attack cancelled!\n");
-                   return abort_attack();
-               }
-           }
-           if ((issneak != AT_WAR) && (def->own)
-               && (def->own != player->cnum)
-               && (sect.sct_oldown != player->cnum)
-               && ((issneak == MOBILIZATION) || (issneak == SITZKRIEG))) {
-               pr("You're not at war with them!\n");
-               return abort_attack();
-           }
-       } else {
-           if ((issneak != AT_WAR) && (def->own) &&
-               (sect.sct_oldown != player->cnum)) {
-               pr("You're not at war with them!\n");
-               return abort_attack();
-           }
+       if ((rel != AT_WAR) && (def->own) &&
+           (sect.sct_oldown != player->cnum)) {
+           pr("You're not at war with them!\n");
+           return abort_attack();
        }
     }
     return 0;
@@ -632,9 +565,8 @@ board_abort(struct combat *off, struct combat *def)
        }
        getship(off->shp_uid, &aship);
        getship(def->shp_uid, &dship);
-       if (techfact(aship.shp_tech, 1.0) *
-           aship.shp_speed * off->eff <=
-           techfact(dship.shp_tech, 1.0) * dship.shp_speed * def->eff) {
+       if (techfact(aship.shp_tech, shp_speed(&aship)) * off->eff
+           <= techfact(dship.shp_tech, shp_speed(&dship)) * def->eff) {
            pr("Victim ship moves faster than you do!\n");
            if (def->own)
                wu(0, def->own,
@@ -707,7 +639,7 @@ att_approach(struct combat *off, struct combat *def)
     }
     if (off->type == EF_SECTOR) {
        getsect(off->x, off->y, &sect);
-       sectdamage(&sect, dam, 0);
+       sectdamage(&sect, dam);
        putsect(&sect);
        pr("Enemy fleet at %s does %d damage to %s\n",
           xyas(def->x, def->y, player->cnum), dam, prcom(0, off));
@@ -762,14 +694,14 @@ int
 att_ask_support(int offset, int *fortp, int *shipp, int *landp,
                int *planep)
 {
-    s_char buf[1024];
-    s_char *p;
+    char buf[1024];
+    char *p;
     *fortp = *shipp = *landp = *planep = 1;
 
-    if (player->argp[offset] != (s_char *)0) {
-       if ((player->argp[offset + 1] == (s_char *)0) ||
-           (player->argp[offset + 2] == (s_char *)0) ||
-           (player->argp[offset + 3] == (s_char *)0)) {
+    if (player->argp[offset] != NULL) {
+       if ((player->argp[offset + 1] == NULL) ||
+           (player->argp[offset + 2] == NULL) ||
+           (player->argp[offset + 3] == NULL)) {
            pr("If any support arguments are used, all must be!\n");
            return RET_SYN;
        }
@@ -820,7 +752,7 @@ att_ask_offense(int combat_mode, struct combat *off, struct combat *def,
                struct emp_qelem *olist, int *a_spyp, int *a_engineerp)
 {
     int n;
-    s_char land_answer[1024];
+    char land_answer[256];
 
     emp_initque(olist);
     if (att_abort(combat_mode, off, def))
@@ -838,22 +770,51 @@ att_ask_offense(int combat_mode, struct combat *off, struct combat *def,
     return 0;
 }
 
+/*
+ * Return path cost for ATTACKER to enter sector given by DEF.
+ * MOBTYPE is a mobility type accepted by sector_mcost().
+ */
+static double
+att_mobcost(natid attacker, struct combat *def, int mobtype)
+{
+    struct sctstr sect;
+    int ok;
+
+    if (CANT_HAPPEN(def->type != EF_SECTOR))
+       return -1.0;
+    ok = getsect(def->x, def->y, &sect);
+    if (CANT_HAPPEN(!ok))
+       return -1.0;
+
+    /*
+     * We want the cost to move/march into the sector.  If we just
+     * called sector_mcost(), we'd get the defender's cost.  The
+     * attacker's cost is higher unless he's the old-owner.  Note: if
+     * there are no civilians, a victorious attacker will become the
+     * old-owner.  But he isn't now.
+     */
+    sect.sct_own = attacker;
+    sect.sct_mobil = 0;
+    return sector_mcost(&sect, mobtype);
+}
+
 /* How many mil is off allowed to attack with when it attacks def? */
 
 static int
 get_mob_support(int combat_mode, struct combat *off, struct combat *def)
 {
     int mob_support;
+    double mobcost;
 
     switch (combat_mode) {
     case A_ATTACK:
-       mob_support = off->mob / sector_mcost(getsectp(def->x, def->y),
-                                             MOB_ROAD);
-       if (mob_support < 0)
-           mob_support = 0;
-/*             mob_support = off->mob / sector_mcost(def->sct_type, def->eff);*/
+       mobcost = att_mobcost(off->own, def, MOB_MOVE);
+       if (mobcost < 0 || off->mob <= 0)
+           return 0;
+       mob_support = off->mob / mobcost;
        if (mob_support < off->troops)
-           pr("Sector %s has %d mobility which can only support %d mil,\n", xyas(off->x, off->y, player->cnum), off->mob, mob_support);
+           pr("Sector %s has %d mobility which can only support %d mil,\n",
+              xyas(off->x, off->y, player->cnum), off->mob, mob_support);
        else
            mob_support = off->troops;
        return mob_support;
@@ -868,8 +829,7 @@ get_mob_support(int combat_mode, struct combat *off, struct combat *def)
     case A_BOARD:
        if (off->type == EF_SECTOR && off->mob <= 0)
            return 0;
-       mob_support = vl_find(V_MILIT, def->shp_mcp->m_vtype,
-                             def->shp_mcp->m_vamt, def->shp_mcp->m_nv);
+       mob_support = def->shp_mcp->m_item[I_MILIT];
        if (mob_support < off->troops)
            pr("The size of the ship you are trying to board limits your party to %d mil,\n", mob_support);
        else
@@ -880,8 +840,7 @@ get_mob_support(int combat_mode, struct combat *off, struct combat *def)
            return 0;
        if (def->lnd_lcp->l_flags & L_SPY)
            return 1;
-       mob_support = vl_find(V_MILIT, def->lnd_lcp->l_vtype,
-                             def->lnd_lcp->l_vamt, def->lnd_lcp->l_nv);
+       mob_support = def->lnd_lcp->l_item[I_MILIT];
        if (mob_support < off->troops)
            pr("The size of the unit you are trying to board limits your party to %d mil,\n", mob_support);
        else
@@ -908,23 +867,22 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
        return;
     switch (combat_mode) {
     case A_ATTACK:
-       off->mobcost +=
-           max(1,
-               (int)(attacking_mil *
-                     sector_mcost(getsectp(def->x, def->y), MOB_ROAD)));
+       off->mobcost += MAX(1,
+                           (int)(attacking_mil
+                                 * att_mobcost(off->own, def, MOB_MOVE)));
        break;
     case A_LBOARD:
-       off->mobcost += max(1, attacking_mil / 5);
+       off->mobcost += MAX(1, attacking_mil / 5);
        break;
     case A_BOARD:
        switch (off->type) {
        case EF_SECTOR:
-           off->mobcost += max(1, attacking_mil / 5);
+           off->mobcost += MAX(1, attacking_mil / 5);
            break;
        case EF_SHIP:
            /* the 2 in the formula below is a fudge factor */
            getship(def->shp_uid, &ship);
-           off->mobcost += (def->eff / 100) * (ship.shp_speed / 2);
+           off->mobcost += (def->eff / 100) * (shp_speed(&ship) / 2);
        }
     }
 }
@@ -936,7 +894,7 @@ ask_off(int combat_mode, struct combat *off, struct combat *def)
 {
     int attacking_mil;
     int mob_support;
-    s_char prompt[512];
+    char prompt[512];
 
     if (att_get_combat(off, 0) <= 0)
        return 0;
@@ -961,7 +919,7 @@ ask_off(int combat_mode, struct combat *off, struct combat *def)
     if (att_get_combat(off, 0) <= 0)
        return 0;
     if ((attacking_mil =
-        min(attacking_mil, min(mob_support, off->troops))) <= 0)
+        MIN(attacking_mil, MIN(mob_support, off->troops))) <= 0)
        return 0;
 
     calc_mobcost(combat_mode, off, def, attacking_mil);
@@ -972,50 +930,51 @@ ask_off(int combat_mode, struct combat *off, struct combat *def)
  * Which units would you like to attack with or move in with [ynYNq?]
  */
 
-static s_char
-att_prompt(s_char *prompt, s_char army)
+static char
+att_prompt(char *prompt, char army)
 {
-    s_char buf[1024];
-    s_char *p = buf;
+    char buf[1024];
+    char *p;
 
-    if (army == ' ')
+    if (!army)
        army = '~';
-    *buf = -2;
-    while (!p || (*p != 'y' && *p != 'n' && *p != 'Y' && *p != 'N')) {
-       if (p && *p == 'q') {
+    for (;;) {
+       p = getstring(prompt, buf);
+       if (!p || *p == 'q') {
            abort_attack();
            return 'N';
        }
-       if (!p || !*p)
+       if (!*p)
            return 'n';
-       if (p && *p != -2)
-           pr("y - yes this unit\nn - no this unit\nY - yes to all units in army '%c'\nN - no to all units in army '%c'\nq - quit\n? - this help message\n\n", army, army);
-       p = getstring(prompt, buf);
-       if (player->aborted) {
-           buf[0] = 'N';
-           p = buf;
-       }
+       if (tolower(*p) == 'y' || tolower(*p) == 'n')
+           return *p;
+       pr("y - yes this unit\n"
+          "n - no this unit\n"
+          "Y - yes to all units in army '%c'\n"
+          "N - no to all units in army '%c'\n"
+          "q - quit\n? - this help message\n\n",
+          army, army);
     }
-    return *p;
 }
 
 /* Ask the attacker which units they want to attack/assault/board with */
 
 static void
 ask_olist(int combat_mode, struct combat *off, struct combat *def,
-         struct emp_qelem *olist, s_char *land_answer, int *a_spyp,
+         struct emp_qelem *olist, char *land_answer, int *a_spyp,
          int *a_engineerp)
 {
     struct nstr_item ni;
     struct lndstr land;
-    double mobcost;
-    struct llist *llp;
+    double pathcost, mobcost;
+    int reqmob;
+    struct ulist *llp;
     struct lchrstr *lcp;
-    int att_val;
+    double att_val;
     int count = 0;
     int maxland = 0;
     int first_time = 1;
-    s_char prompt[512];
+    char prompt[512];
 
     if (def->type == EF_LAND)
        return;
@@ -1023,7 +982,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        maxland = def->shp_mcp->m_nland;
 
     snxtitem_xy(&ni, EF_LAND, off->x, off->y);
-    while (nxtitem(&ni, (s_char *)&land)) {
+    while (nxtitem(&ni, &land)) {
        if (land.lnd_own != player->cnum)
            continue;
        if (land.lnd_effic < LAND_MINEFF)
@@ -1038,6 +997,12 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
            pr("Land units are not able to board this kind of ship\n");
            return;
        }
+       if (def->type == EF_SHIP
+           && (def->shp_mcp->m_flags & (M_SUPPLY | M_SUB)) != M_SUPPLY
+           && !(lcp->l_flags & L_LIGHT)) {
+           pr("Only light land units can board this kind of ship\n");
+           continue;
+       }
        if (land.lnd_mobil <= 0) {
            pr("%s is out of mobility, and cannot %s\n",
               prland(&land), att_mode[combat_mode]);
@@ -1045,7 +1010,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        }
 
        if (opt_MARKET) {
-           if (ontradingblock(EF_LAND, (int *)&land)) {
+           if (ontradingblock(EF_LAND, &land)) {
                pr("%s is on the trading block, and cannot %s\n",
                   prland(&land), att_mode[combat_mode]);
                continue;
@@ -1066,12 +1031,30 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        }
        switch (combat_mode) {
        case A_ATTACK:
-           mobcost =
-               lnd_mobcost(&land, getsectp(def->x, def->y), MOB_NONE);
-           if (land.lnd_mobil < mobcost) {
-               pr("%s does not have enough mobility (%d needed)\n",
-                  prland(&land), (int)ceil(mobcost));
-               continue;
+           /*
+            * We used to let land units attack only if they have the
+            * mobility consumed by the attack, not counting combat
+            * and moving in to occupy.  Making sure your land units
+            * reach attack positions with enough mobility left is a
+            * pain in the neck.  We now require positive mobility,
+            * just like for marching.  Except we don't allow rushing
+            * of high-mobility sectors (mountains): for those we
+            * still require attack mobility.
+            */
+           pathcost = att_mobcost(off->own, def, lnd_mobtype(&land));
+           mobcost = lnd_pathcost(&land, pathcost);
+           if (pathcost < 1.0) {
+               if (land.lnd_mobil <= 0) {
+                   pr("%s is out of mobility\n", prland(&land));
+                   continue;
+               }
+           } else {
+               reqmob = MIN(land_mob_max, (int)ceil(mobcost));
+               if (land.lnd_mobil < reqmob) {
+                   pr("%s does not have enough mobility (%d needed)\n",
+                      prland(&land), reqmob);
+                   continue;
+               }
            }
            break;
        case A_ASSAULT:
@@ -1079,15 +1062,19 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
            mobcost = 0;
            if (!(lcp->l_flags & L_ASSAULT))
                continue;
+           break;
+       default:
+           CANT_REACH();
+           return;
        }
        att_val = attack_val(combat_mode, &land);
-       if (!att_val) {
+       if (att_val < 1.0) {
            pr("%s has no offensive strength\n", prland(&land));
            continue;
        }
        resupply_all(&land);
        putland(land.lnd_uid, &land);
-       if (!has_supply(&land)) {
+       if (!lnd_in_supply(&land)) {
            pr("%s is out of supply, and cannot %s\n",
               prland(&land), att_mode[combat_mode]);
            continue;
@@ -1096,7 +1083,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
            first_time = 0;
            pr("You may board with a maximum of %d land units\n", maxland);
        }
-       pr("%s has a base %s value of %d\n",
+       pr("%s has a base %s value of %.0f\n",
           prland(&land), att_mode[combat_mode], att_val);
        if (land_answer[(int)land.lnd_army] != 'Y') {
            sprintf(prompt,
@@ -1104,7 +1091,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
                    att_mode[combat_mode],
                    prland(&land),
                    prcom(1, off),
-                   land.lnd_army == ' ' ? '~' : land.lnd_army,
+                   land.lnd_army ? land.lnd_army : '~',
                    land.lnd_effic);
            land_answer[(int)land.lnd_army] =
                att_prompt(prompt, land.lnd_army);
@@ -1114,20 +1101,20 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
                land_answer[(int)land.lnd_army] != 'Y')
                continue;
        }
-       if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) {
+       if (!(llp = malloc(sizeof(struct ulist)))) {
            logerror("Malloc failed in attack!\n");
            abort_attack();
            return;
        }
-       memset(llp, 0, sizeof(struct llist));
+       memset(llp, 0, sizeof(struct ulist));
        emp_insque(&llp->queue, olist);
        llp->mobil = mobcost;
        if (!get_land(combat_mode, def, land.lnd_uid, llp, 0))
            continue;
        if (lnd_spyval(&land) > *a_spyp)
            *a_spyp = lnd_spyval(&land);
-       if (llp->lcp->l_flags & L_ENGINEER)
-           ++(*a_engineerp);
+       if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
+           ++*a_engineerp;
        if (def->type == EF_SHIP && ++count >= maxland)
            break;
     }
@@ -1146,30 +1133,21 @@ att_combat_eff(struct combat *com)
        eff = com->eff / 100.0;
        if (com->own == player->cnum) {
            str = com->sct_dcp->d_ostr;
-           eff = 1.0 + ((str - 1.0) * eff);
+           eff = 1.0 + (str - 1.0) * eff;
        } else
            eff = sector_strength(getsectp(com->x, com->y));
-/*                     str = com->sct_dcp->d_dstr;*/
     } else if (com->type == EF_SHIP && com->own != player->cnum) {
        getship(com->shp_uid, &ship);
-       eff = (1.0 + ship.shp_armor / 100.0);
+       eff = 1.0 + shp_armor(&ship) / 100.0;
     }
     return eff;
 }
 
-/*
- * Estimate the defense strength and give the attacker a chance to abort
- * if the odds are less than 50%
- */
-
 int
-att_estimate_defense(int combat_mode, struct combat *off,
-                    struct emp_qelem *olist, struct combat *def,
-                    int a_spy)
+att_get_offense(int combat_mode, struct combat *off,
+               struct emp_qelem *olist, struct combat *def)
 {
     int ototal;
-    int estimate;
-    int odds;
 
     /*
      * Get the attacker units & mil again in case they changed while the
@@ -1182,30 +1160,6 @@ att_estimate_defense(int combat_mode, struct combat *off,
     if (combat_mode == A_PARA)
        return ototal;
     pr("\n             Initial attack strength: %8d\n", ototal);
-
-    estimate = att_combat_eff(def) * roundintby(def->troops, 10);
-    estimate += att_combat_eff(def) * get_dlist(def, 0, a_spy, 0);
-
-    /*
-     * Calculate the initial (pre-support) attack odds.  If they're less
-     * than 50%, ask for a confirmation.
-     */
-
-    odds = (int)(att_calcodds(ototal, estimate) * 100);
-
-/*
-       if (odds < 50) {
-               pr("          Estimated defense strength: %8d\n", estimate);
-               pr("                      Estimated odds: %8d%%\n\n",odds);
-               sprintf(prompt, "Are you sure you want to %s [yn]? ",
-                       att_mode[combat_mode]);
-               if (!confirm(prompt))
-                       return abort_attack();
-               ototal = get_ototal(combat_mode, off, olist,1.0,1);
-               if (att_empty_attack(combat_mode, ototal, def))
-                       return abort_attack();
-       }
- */
     return ototal;
 }
 
@@ -1216,7 +1170,7 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
 {
     int d_spy = 0;
     struct emp_qelem *qp;
-    struct llist *llp;
+    struct ulist *llp;
     int dtotal;
     int old_dtotal;
 
@@ -1232,8 +1186,8 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
        att_reacting_units(def, dlist, a_spy, &d_spy, ototal);
 
     for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
-       llp = (struct llist *)qp;
-       intelligence_report(def->own, &llp->land, d_spy,
+       llp = (struct ulist *)qp;
+       intelligence_report(def->own, &llp->unit.land, d_spy,
                            "Scouts report attacking unit:");
     }
 
@@ -1247,20 +1201,19 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
 
 /* Get the defensive land units in the sector or on the ship */
 
-static int
+static void
 get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
          int *d_spyp)
 {
     struct nstr_item ni;
-    struct llist *llp;
+    struct ulist *llp;
     struct lndstr land;
-    int estimate = 0;
 
 /* In here is where you need to take out spies and trains from the defending
    lists.  Spies try to hide, trains get trapped and can be boarded. */
 
     snxtitem_xy(&ni, EF_LAND, def->x, def->y);
-    while (nxtitem(&ni, (s_char *)&land)) {
+    while (nxtitem(&ni, &land)) {
        if (!land.lnd_own)
            continue;
        if (land.lnd_own != def->own)
@@ -1273,26 +1226,23 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
            continue;
        if (def->type == EF_LAND && land.lnd_land != def->lnd_uid)
            continue;
-       if (!list) {            /* Just estimating the enemy strength */
-           estimate += intelligence_report(player->cnum,
-                                           &land, a_spy,
-                                           "Scouts report defending unit:");
-           continue;
-       }
-       if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) {
+       intelligence_report(player->cnum, &land, a_spy,
+                           "Scouts report defending unit:");
+       if (!(llp = malloc(sizeof(struct ulist)))) {
            logerror("Malloc failed in attack!\n");
            abort_attack();
-           return 0;
+           return;
        }
-       memset(llp, 0, sizeof(struct llist));
+       memset(llp, 0, sizeof(struct ulist));
        emp_insque(&llp->queue, list);
-       llp->supplied = has_supply(&land);
+       resupply_all(&land);
+       putland(land.lnd_uid, &land);
+       llp->supplied = lnd_in_supply(&land);
        if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
            continue;
        if (lnd_spyval(&land) > *d_spyp)
            *d_spyp = lnd_spyval(&land);
     }
-    return estimate;
 }
 
 /* Calculate the total offensive strength */
@@ -1303,7 +1253,7 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
 {
     double ototal = 0.0;
     struct emp_qelem *qp, *next;
-    struct llist *llp;
+    struct ulist *llp;
     int n, w;
 
     /*
@@ -1324,26 +1274,26 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
 
     for (qp = olist->q_forw; qp != olist; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       if (check && !get_land(combat_mode, 0, llp->land.lnd_uid, llp, 0))
+       llp = (struct ulist *)qp;
+       if (check && !get_land(combat_mode, 0, llp->unit.land.lnd_uid, llp, 0))
            continue;
        if (combat_mode == A_ATTACK) {
            w = -1;
            for (n = 0; n <= off->last; ++n) {
                if (off[n].type == EF_BAD)
                    continue;
-               if ((off[n].x == llp->land.lnd_x) &&
-                   (off[n].y == llp->land.lnd_y))
+               if ((off[n].x == llp->unit.land.lnd_x) &&
+                   (off[n].y == llp->unit.land.lnd_y))
                    w = n;
            }
            if (w < 0) {
                lnd_delete(llp, "is in a sector not owned by you");
                continue;
            }
-           ototal += attack_val(combat_mode, &llp->land) *
+           ototal += attack_val(combat_mode, &llp->unit.land) *
                att_combat_eff(off + w);
        } else {
-           ototal += attack_val(combat_mode, &llp->land);
+           ototal += attack_val(combat_mode, &llp->unit.land);
        }
     }
     ototal *= osupport;
@@ -1359,7 +1309,7 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
 {
     double dtotal = 0.0, eff = 1.0, d_unit;
     struct emp_qelem *qp, *next;
-    struct llist *llp;
+    struct ulist *llp;
 
     if (check && att_get_combat(def, 1) < 0)
        return 0;
@@ -1373,13 +1323,12 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
 
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       d_unit = 0.0;
-       if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1))
+       llp = (struct ulist *)qp;
+       if (check && !get_land(A_DEFEND, def, llp->unit.land.lnd_uid, llp, 1))
            continue;
-       d_unit = defense_val(&llp->land);
+       d_unit = defense_val(&llp->unit.land);
        if (!llp->supplied)
-           d_unit = ((double)defense_val(&llp->land) / 2.0);
+           d_unit /= 2.0;
        dtotal += d_unit * eff;
     }
 
@@ -1394,18 +1343,18 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
  */
 
 static int
-get_land(int combat_mode, struct combat *def, int uid, struct llist *llp,
+get_land(int combat_mode, struct combat *def, int uid, struct ulist *llp,
         int victim_land)
 {
-    struct lndstr *lp = &llp->land;
-    s_char buf[512];
+    struct lndstr *lp = &llp->unit.land;
+    char buf[512];
 
     getland(uid, lp);
 
-    if (!llp->lcp) {           /* first time */
-       llp->x = llp->land.lnd_x;
-       llp->y = llp->land.lnd_y;
-       llp->lcp = &lchr[(int)llp->land.lnd_type];
+    if (!llp->chrp) {          /* first time */
+       llp->x = llp->unit.land.lnd_x;
+       llp->y = llp->unit.land.lnd_y;
+       llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
     } else {                   /* not first time */
        if (lp->lnd_effic < LAND_MINEFF) {
            sprintf(buf, "was destroyed and is no longer a part of the %s",
@@ -1441,7 +1390,7 @@ get_land(int combat_mode, struct combat *def, int uid, struct llist *llp,
            }
        }
     }
-    llp->eff = llp->land.lnd_effic;
+    llp->eff = llp->unit.land.lnd_effic;
 
     return 1;
 }
@@ -1457,13 +1406,13 @@ static void
 kill_land(struct emp_qelem *list)
 {
     struct emp_qelem *qp, *next;
-    struct llist *llp;
+    struct ulist *llp;
 
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       if (llp->land.lnd_ship >= 0) {
-           llp->land.lnd_effic = 0;
+       llp = (struct ulist *)qp;
+       if (llp->unit.land.lnd_ship >= 0) {
+           llp->unit.land.lnd_effic = 0;
            lnd_delete(llp, "cannot return to the ship, and dies!");
        }
     }
@@ -1473,15 +1422,15 @@ static void
 att_infect_units(struct emp_qelem *list, int plague)
 {
     struct emp_qelem *qp, *next;
-    struct llist *llp;
+    struct ulist *llp;
 
     if (!plague)
        return;
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       if (llp->land.lnd_pstage == PLG_HEALTHY)
-           llp->land.lnd_pstage = PLG_EXPOSED;
+       llp = (struct ulist *)qp;
+       if (llp->unit.land.lnd_pstage == PLG_HEALTHY)
+           llp->unit.land.lnd_pstage = PLG_EXPOSED;
     }
 }
 
@@ -1489,21 +1438,21 @@ static void
 put_land(struct emp_qelem *list)
 {
     struct emp_qelem *qp, *next;
-    struct llist *llp;
+    struct ulist *llp;
 
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       llp->land.lnd_mission = 0;
-       llp->land.lnd_harden = 0;
-       llp->land.lnd_mobil -= (int)llp->mobil;
+       llp = (struct ulist *)qp;
+       llp->unit.land.lnd_mission = 0;
+       llp->unit.land.lnd_harden = 0;
+       llp->unit.land.lnd_mobil -= (int)llp->mobil;
        llp->mobil = 0.0;
-       putland(llp->land.lnd_uid, &llp->land);
-       if (llp->land.lnd_own != player->cnum) {
+       putland(llp->unit.land.lnd_uid, &llp->unit.land);
+       if (llp->unit.land.lnd_own != player->cnum) {
            emp_remque((struct emp_qelem *)llp);
-           free((s_char *)llp);
+           free(llp);
        } else
-           get_land(A_ATTACK, 0, llp->land.lnd_uid, llp, 0);
+           get_land(A_ATTACK, 0, llp->unit.land.lnd_uid, llp, 0);
     }
 }
 
@@ -1512,45 +1461,31 @@ put_land(struct emp_qelem *list)
  * Note that the "strength" command also calls this routine.
  */
 
-int
+double
 att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
                   int *d_spyp, int ototal)
 {
     struct nstr_item ni;
     struct lndstr land;
     struct sctstr sect, dsect;
-    struct llist *llp;
+    struct ulist *llp;
     int dtotal;
-    int new_land = 0;
+    double new_land = 0;
     double mobcost;
-    double move_cost;
-    int supply_state;
-    int dist;
-    int radius;
+    double pathcost;
     int origx, origy;
     double eff = att_combat_eff(def);
-    s_char *p;
-    s_char buf[1024];
-
-    /*
-     *
-     * All units that are within their reaction radius and not damaged
-     * below their morale value now get to react to the threatened sect.
-     * Once we've sent enough to counter the threat, stop sending them.
-     *
-     * Not anymore.  All units get to react. :)
-     */
+    char buf[1024];
 
     if (list)
        dtotal = get_dtotal(def, list, 1.0, 1);
     else
        dtotal = 0;
     snxtitem_all(&ni, EF_LAND);
-    while (nxtitem(&ni, (s_char *)&land) &&
-          (dtotal + new_land * eff < (int)(1.2 * (float)ototal))) {
+    while (nxtitem(&ni, &land) && dtotal + new_land * eff < 1.2 * ototal) {
        if (!land.lnd_own)
            continue;
-       if (!land.lnd_rad_max)
+       if (land.lnd_mission != MI_RESERVE)
            continue;
        if ((land.lnd_x == def->x) && (land.lnd_y == def->y))
            continue;
@@ -1558,44 +1493,34 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
            continue;
        if (land.lnd_ship >= 0)
            continue;
-       if (!defense_val(&land))
+       if (land.lnd_land >= 0)
+           continue;
+       if (defense_val(&land) < 1.0)
            continue;
-/*
-               if (land.lnd_effic <= land.lnd_retreat)
-                       continue;
- */
        if (!lnd_can_attack(&land))
            continue;
 
        /* Only supplied units can react */
-       if (!(supply_state = has_supply(&land)))
-           continue;
-
-       dist = mapdist(land.lnd_x, land.lnd_y, def->x, def->y);
-
-       getsect(land.lnd_x, land.lnd_y, &sect);
-       /* Units on efficient headquarters can react 1 farther */
-       if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60))
-           radius = land.lnd_rad_max + 1;
-       else
-           radius = land.lnd_rad_max;
-
-       if (land.lnd_mission == MI_RESERVE)
-           radius += 2;
+       if (list) {
+           resupply_all(&land);
+           putland(land.lnd_uid, &land);
+           if (!lnd_in_supply(&land))
+               continue;
+       } else {
+           if (!lnd_could_be_supplied(&land))
+               continue;
+       }
 
-       if (dist > radius)
+       if (!in_oparea((struct empobj *)&land, def->x, def->y))
            continue;
 
+       getsect(land.lnd_x, land.lnd_y, &sect);
        getsect(def->x, def->y, &dsect);
-       if (!(p = BestLandPath(buf, &sect, &dsect, &move_cost, MOB_ROAD)))
+       if (!BestLandPath(buf, &sect, &dsect, &pathcost,
+                         lnd_mobtype(&land)))
            continue;
 
-       mobcost = land.lnd_effic * 0.01 * lchr[(int)land.lnd_type].l_spd;
-       if (mobcost < 0.01)
-           mobcost = 0.01;
-       mobcost = 480.0 / (mobcost + techfact(land.lnd_tech, mobcost));
-       mobcost *= (move_cost * 5.0);
-
+       mobcost = lnd_pathcost(&land, pathcost);
        if (land.lnd_mobil < mobcost)
            continue;
 
@@ -1614,15 +1539,14 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
        wu(0, land.lnd_own, "%s reacts to %s.\n",
           prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
 
-       llp = (struct llist *)
-           malloc(sizeof(struct llist));
+       llp = malloc(sizeof(struct ulist));
 
-       memset(llp, 0, sizeof(struct llist));
-       llp->supplied = supply_state;
+       memset(llp, 0, sizeof(struct ulist));
+       llp->supplied = 1;
        llp->x = origx;
        llp->y = origy;
-       llp->lcp = &lchr[(int)land.lnd_type];
-       llp->land = land;
+       llp->chrp = (struct empobj_chr *)&lchr[(int)land.lnd_type];
+       llp->unit.land = land;
        emp_insque(&llp->queue, list);
        if (lnd_spyval(&land) > *d_spyp)
            *d_spyp = lnd_spyval(&land);
@@ -1636,7 +1560,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
 /* Pop off shells and fly bombing missions to get your attack multiplier up */
 
 static double
-get_osupport(s_char *outs, struct combat *def, int fort_sup, int ship_sup,
+get_osupport(char *outs, struct combat *def, int fort_sup, int ship_sup,
             int land_sup, int plane_sup)
 {
     double osupport = 1.0;
@@ -1646,25 +1570,25 @@ get_osupport(s_char *outs, struct combat *def, int fort_sup, int ship_sup,
     af = as = au = ap = 0.0;
     if (fort_sup) {
        dam = dd(def->own, player->cnum, def->x, def->y, 0, 0);
-       af = ((double)dam / 100.0);
+       af = dam / 100.0;
        osupport += af;
     }
     if (ship_sup) {
        dam = sd(def->own, player->cnum, def->x, def->y, 0, 0, 0);
 
-       as = ((double)dam / 100.0);
+       as = dam / 100.0;
        osupport += as;
     }
 
     if (land_sup) {
-       dam = lnd_support(def->own, player->cnum, def->x, def->y);
-       au = ((double)dam / 100.0);
+       dam = lnd_support(def->own, player->cnum, def->x, def->y, 0);
+       au = dam / 100.0;
        osupport += au;
     }
 
     if (plane_sup) {
        dam = off_support(def->x, def->y, def->own, player->cnum);
-       ap = (((double)dam) / 100.0);
+       ap = dam / 100.0;
        osupport += ap;
     }
     sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n", af, as, au,
@@ -1675,7 +1599,7 @@ get_osupport(s_char *outs, struct combat *def, int fort_sup, int ship_sup,
 /* Pop off shells and fly bombing missions to get your defense multiplier up */
 
 static double
-get_dsupport(s_char *outs, struct emp_qelem *list, struct combat *def,
+get_dsupport(char *outs, struct emp_qelem *list, struct combat *def,
             int ototal, int dtotal)
 {
     double dsupport = 1.0;
@@ -1690,25 +1614,25 @@ get_dsupport(s_char *outs, struct emp_qelem *list, struct combat *def,
        good = 1;
     } else {
        dam = dd(player->cnum, def->own, def->x, def->y, 0, 1);
-       df = ((double)dam / 100.0);
+       df = dam / 100.0;
        dsupport += df;
 
        dtotal = get_dtotal(def, list, dsupport, 0);
        if (dtotal < 1.2 * ototal) {
            dam = sd(player->cnum, def->own, def->x, def->y, 0, 1, 0);
-           ds = ((double)dam / 100.0);
+           ds = dam / 100.0;
            dsupport += ds;
            dtotal = get_dtotal(def, list, dsupport, 0);
        }
        if (dtotal < 1.2 * ototal) {
-           dam = lnd_support(player->cnum, def->own, def->x, def->y);
-           du = ((double)dam / 100.0);
+           dam = lnd_support(player->cnum, def->own, def->x, def->y, 1);
+           du = dam / 100.0;
            dsupport += du;
            dtotal = get_dtotal(def, list, dsupport, 1);
        }
        if (dtotal < 1.2 * ototal) {
            dam = def_support(def->x, def->y, player->cnum, def->own);
-           dp = (((double)dam) / 100.0);
+           dp = dam / 100.0;
            dsupport += dp;
        }
     }
@@ -1742,9 +1666,9 @@ get_mine_dsupport(struct combat *def, int a_engineer)
     getsect(def->x, def->y, &sect);
 
     if (sect.sct_oldown != player->cnum) {
-       mines = min(sect.sct_mines, 20);
+       mines = MIN(sect.sct_mines, 20);
        if (a_engineer)
-           mines = ldround(((double)mines / 2.0), 1);
+           mines = ldround(mines / 2.0, 1);
        if (mines > 0) {
            if (def->own)
                wu(0, def->own, "Defending mines add %1.2f\n",
@@ -1764,8 +1688,8 @@ att_get_support(int combat_mode, int ofort, int oship, int oland,
                double *osupportp, double *dsupportp, int a_engineer)
 {
     int ototal, dtotal;
-    s_char osupports[512];
-    s_char dsupports[512];
+    char osupports[512];
+    char dsupports[512];
 
     if (combat_mode == A_PARA)
        *osupports = '\0';
@@ -1775,8 +1699,8 @@ att_get_support(int combat_mode, int ofort, int oship, int oland,
 
     /*
      * I need to put a 1 at the end of the next four total_stren calls
-     * becauase units & mil may have been damaged by collateral damage or
-     * neclear warheads from the offensive & defensive support.
+     * because units & mil may have been damaged by collateral damage or
+     * nuclear warheads from the offensive & defensive support.
      */
 
     ototal = get_ototal(combat_mode, off, olist, *osupportp, 1);
@@ -1826,13 +1750,13 @@ count_bodies(struct combat *off, struct emp_qelem *list)
     int n;
     int bodies = 0;
     struct emp_qelem *qp;
-    struct llist *llp;
+    struct ulist *llp;
 
     for (n = 0; n <= off->last; ++n)
        bodies += off[n].troops;
     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
-       llp = (struct llist *)qp;
-       bodies += total_mil(&llp->land);
+       llp = (struct ulist *)qp;
+       bodies += llp->unit.land.lnd_item[I_MILIT];
     }
     return bodies;
 }
@@ -1857,7 +1781,8 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
     int news_item;
     int recalctime;
     double odds;
-    s_char *action;
+    int newmob;
+    char *action;
 
     ototal = get_ototal(combat_mode, off, olist, osupport,
                        combat_mode != A_PARA);
@@ -1918,7 +1843,8 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
     att_infect_units(olist, off->plague);
     att_infect_units(dlist, def->plague);
 
-    /* Fighting is slightly random.  There is always that last little 
+    /*
+     * Fighting is slightly random.  There is always that last little
      * effort you see people put in.  Or the stray bullet that takes out
      * an officer and the rest go into chaos.  Things like that.
      * Thus, we have added a very slight random factor that will sometimes
@@ -1926,8 +1852,9 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
      * (either +- 5%) to account for this randomness.  We also only
      * recalculate the odds every 8-50 casualties, not every cacsualty,
      * since a single dead guy normally wouldn't cause a commander to
-     * rethink his strategies, but 50 dead guys might. */
-    odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
+     * rethink his strategies, but 50 dead guys might.
+     */
+    odds += (random() % 11 - 5) / 100.0;
     if (odds < 0.0)
        odds = 0.1;
     if (odds > 1.0)
@@ -1950,7 +1877,7 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
        if (recalctime-- <= 0) {
            recalctime = 8 + (random() % 43);
            odds = att_calcodds(ototal, dtotal);
-           odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
+           odds += (random() % 11 - 5) / 100.0;
            if (odds < 0.0)
                odds = 0.1;
            if (odds > 1.0)
@@ -1963,12 +1890,12 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
        def->mil = 0;
     else {
        if (def->type == EF_SECTOR && d_mil && d_cas) {
-           int tmob;
-
-           /* Make sure we use a positive mobility here */
-           tmob = ((def->mob < 0) ? -(def->mob) : (def->mob));
-           def->mobcost =
-               min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
+           if (def->mob < 0)
+               def->mobcost = 0;
+           else {
+               newmob = damage(def->mob, 100 * d_cas / d_mil);
+               def->mobcost = MIN(20, def->mob - newmob);
+           }
        }
        def->mil = def->troops;
     }
@@ -1976,14 +1903,14 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
     /* update attack mobility & mil */
     for (n = 0; n <= off->last; ++n)
        if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) {
-           if (off[n].type == EF_SECTOR && off[n].mil)
-               off[n].mobcost +=
-                   min(20,
-                       min(1,
-                           off[n].mob - damage(off[n].mob,
-                                               100 * (a_troops[n] -
-                                                      off[n].troops) /
-                                               off[n].mil)));
+           if (off[n].type == EF_SECTOR && off[n].mil) {
+               if (!CANT_HAPPEN(off[n].mob < 0)) {
+                   newmob = damage(off[n].mob,
+                                   100 * (a_troops[n] - off[n].troops)
+                                   / off[n].mil);
+                   off[n].mobcost += MIN(20, off[n].mob - newmob);
+               }
+           }
            off[n].mil -= a_troops[n] - off[n].troops;
        }
 
@@ -2028,6 +1955,10 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
            pr("We have boarded %s, sir!\n", prcom(0, def));
            action = "boarding";
            break;
+       default:
+           CANT_REACH();
+           news_item = 0;
+           action = "defeating";
        }
     } else {
        switch (combat_mode) {
@@ -2059,6 +1990,10 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
            kill_land(olist);
            action = "trying to board";
            break;
+       default:
+           CANT_REACH();
+           news_item = 0;
+           action = "fighting";
        }
     }
     nreport(player->cnum, news_item, def->own, 1);
@@ -2069,14 +2004,10 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
           action, pr_com(0, def, def->own), d_cas);
     }
 
-    if (opt_SNEAK_ATTACK) {
-       do_sneak(def, success);
-    }
-
     send_reacting_units_home(dlist);
 
     /* putland the defending land */
-    lnd_put(dlist, 0);
+    unit_put(dlist, 0);
 
     /* putland the attacking land */
     put_land(olist);
@@ -2112,7 +2043,7 @@ att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist,
 
 /* What percentage of the combat forces going head-to-head are we? */
 
-double
+static double
 att_calcodds(int ototal, int dtotal)
 {
     double odds;
@@ -2123,7 +2054,7 @@ att_calcodds(int ototal, int dtotal)
     else if (dtotal <= 0)
        odds = 1.0;
     else
-       odds = ((double)ototal) / (dtotal + ototal);
+       odds = (double)ototal / (dtotal + ototal);
 
     return odds;
 }
@@ -2137,7 +2068,7 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
     int biggest_troops = 0, index = -1;
     int n, tot_troops = 0, biggest_mil, cas;
     struct emp_qelem *qp, *biggest;
-    struct llist *llp;
+    struct ulist *llp;
 
     for (n = 0; n <= off->last; ++n) {
        if (off[n].type != EF_BAD) {
@@ -2184,29 +2115,29 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
     }
 
     if (QEMPTY(olist))
-       return (CASUALTY_LUMP - to_take);
+       return CASUALTY_LUMP - to_take;
 
     /*
      *  Need to take some casualties from attacking units
      *  Procedure: find the biggest unit remaining (in
      *  terms of mil) and give it the casualties.
      */
-    biggest = (struct emp_qelem *)0;
+    biggest = NULL;
     biggest_mil = -1;
     for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
-       llp = (struct llist *)qp;
+       llp = (struct ulist *)qp;
 
-       if (total_mil(&llp->land) > biggest_mil) {
-           biggest_mil = total_mil(&llp->land);
+       if (llp->unit.land.lnd_item[I_MILIT] > biggest_mil) {
+           biggest_mil = llp->unit.land.lnd_item[I_MILIT];
            biggest = qp;
        }
     }
-    if (biggest == (struct emp_qelem *)0)
-       return (CASUALTY_LUMP - to_take);
+    if (biggest == NULL)
+       return CASUALTY_LUMP - to_take;
 
-    llp = (struct llist *)biggest;
+    llp = (struct ulist *)biggest;
     cas = lnd_take_casualty(combat_mode, llp, to_take);
-    return (CASUALTY_LUMP - (to_take - cas));
+    return CASUALTY_LUMP - (to_take - cas);
 }
 
 /* Send reacting defense units back to where they came from (at no mob cost) */
@@ -2215,17 +2146,18 @@ static void
 send_reacting_units_home(struct emp_qelem *list)
 {
     struct emp_qelem *qp, *next;
-    struct llist *llp;
-    s_char buf[1024];
+    struct ulist *llp;
+    char buf[1024];
 
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       if ((llp->land.lnd_x != llp->x) || (llp->land.lnd_y != llp->y)) {
+       llp = (struct ulist *)qp;
+       if ((llp->unit.land.lnd_x != llp->x) ||
+           (llp->unit.land.lnd_y != llp->y)) {
            sprintf(buf, "returns to %s",
-                   xyas(llp->x, llp->y, llp->land.lnd_own));
-           llp->land.lnd_x = llp->x;
-           llp->land.lnd_y = llp->y;
+                   xyas(llp->x, llp->y, llp->unit.land.lnd_own));
+           llp->unit.land.lnd_x = llp->x;
+           llp->unit.land.lnd_y = llp->y;
            lnd_delete(llp, buf);
        }
     }
@@ -2260,8 +2192,8 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
 {
     int n;
     int occuppied = 0;
-    struct llist *llp, *delete_me = 0;
-    s_char buf[1024];
+    struct ulist *llp, *delete_me = 0;
+    char buf[1024];
     struct sctstr sect;
     struct shpstr ship;
     struct lndstr land;
@@ -2292,16 +2224,16 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
                   pr_com(2, def, def->own));
            return 0;
        } else {
-           llp = (struct llist *)list->q_forw;
-           llp->land.lnd_x = def->x;
-           llp->land.lnd_y = def->y;
+           llp = (struct ulist *)list->q_forw;
+           llp->unit.land.lnd_x = def->x;
+           llp->unit.land.lnd_y = def->y;
            take_move_in_mob(combat_mode, llp, off, def);
            if (def->type == EF_SHIP) {
-               llp->land.lnd_ship = def->shp_uid;
+               llp->unit.land.lnd_ship = def->shp_uid;
                sprintf(buf, "boards %s", prcom(0, def));
                delete_me = llp;
            } else {
-               llp->land.lnd_ship = -1;
+               llp->unit.land.lnd_ship = -1;
                sprintf(buf, "moves in to occupy %s",
                        xyas(def->x, def->y, player->cnum));
                lnd_delete(llp, buf);
@@ -2318,11 +2250,11 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
        putsect(&sect);
     } else if (def->type == EF_SHIP) {
        getship(def->shp_uid, &ship);
-       takeover_ship(&ship, player->cnum, 1);
+       takeover_ship(&ship, player->cnum);
        putship(ship.shp_uid, &ship);
     } else if (def->type == EF_LAND) {
        getland(def->lnd_uid, &land);
-       takeover_land(&land, player->cnum, 1);
+       takeover_land(&land, player->cnum);
        putland(land.lnd_uid, &land);
     }
     if (delete_me)
@@ -2342,11 +2274,11 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
 {
     int n;
     struct emp_qelem *qp, *next;
-    struct llist *llp;
-    s_char buf[512];
-    s_char prompt[512];
-    s_char land_answer[1024];
-    s_char *answerp;
+    struct ulist *llp;
+    char buf[512];
+    char prompt[512];
+    char land_answer[256];
+    char *answerp;
 
     for (n = 0; n <= off->last; ++n)
        if (off[n].type != EF_BAD && off[n].troops > 0)
@@ -2361,29 +2293,30 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
     memset(land_answer, 0, sizeof(land_answer));
     for (qp = olist->q_forw; qp != olist; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       answerp = &land_answer[(int)llp->land.lnd_army];
+       llp = (struct ulist *)qp;
+       answerp = &land_answer[(int)llp->unit.land.lnd_army];
        if (player->aborted || att_get_combat(def, 0) < 0)
            *answerp = 'N';
        if (*answerp == 'Y')
            continue;
        if (*answerp != 'N') {
-           if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
+           if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
                continue;
            sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ",
-                   prland(&llp->land),
-                   llp->land.lnd_army == ' ' ? '~' : llp->land.lnd_army,
-                   llp->land.lnd_effic);
-           *answerp = att_prompt(prompt, llp->land.lnd_army);
+                   prland(&llp->unit.land),
+                   llp->unit.land.lnd_army ? llp->unit.land.lnd_army : '~',
+                   llp->unit.land.lnd_effic);
+           *answerp = att_prompt(prompt, llp->unit.land.lnd_army);
            if (player->aborted || att_get_combat(def, 0) < 0)
                *answerp = 'N';
-           if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
+           if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
                continue;
        }
        if (*answerp == 'y' || *answerp == 'Y')
            continue;
        sprintf(buf, "stays in %s",
-               xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum));
+               xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+                    player->cnum));
        lnd_delete(llp, buf);
     }
     if (QEMPTY(olist))
@@ -2391,11 +2324,12 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
     if (att_get_combat(def, 0) < 0) {
        for (qp = olist->q_forw; qp != olist; qp = next) {
            next = qp->q_forw;
-           llp = (struct llist *)qp;
-           if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0))
+           llp = (struct ulist *)qp;
+           if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
                continue;
            sprintf(buf, "stays in %s",
-                   xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum));
+                   xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+                        player->cnum));
            lnd_delete(llp, buf);
        }
        return;
@@ -2412,23 +2346,23 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
             struct combat *def)
 {
     struct emp_qelem *qp, *next;
-    struct llist *llp;
-    s_char buf[512];
+    struct ulist *llp;
+    char buf[512];
 
     if (QEMPTY(olist))
        return;
     for (qp = olist->q_forw; qp != olist; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
-       if (!get_land(combat_mode, def, llp->land.lnd_uid, llp, 0))
+       llp = (struct ulist *)qp;
+       if (!get_land(combat_mode, def, llp->unit.land.lnd_uid, llp, 0))
            continue;
        take_move_in_mob(combat_mode, llp, off, def);
-       llp->land.lnd_x = def->x;
-       llp->land.lnd_y = def->y;
+       llp->unit.land.lnd_x = def->x;
+       llp->unit.land.lnd_y = def->y;
        if (def->type == EF_SHIP)
-           llp->land.lnd_ship = def->shp_uid;
+           llp->unit.land.lnd_ship = def->shp_uid;
        else
-           llp->land.lnd_ship = -1;
+           llp->unit.land.lnd_ship = -1;
     }
     if (QEMPTY(olist))
        return;
@@ -2445,12 +2379,12 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
        return;
     for (qp = olist->q_forw; qp != olist; qp = next) {
        next = qp->q_forw;
-       llp = (struct llist *)qp;
+       llp = (struct ulist *)qp;
        lnd_print(llp, buf);
     }
     if (QEMPTY(olist))
        return;
-    lnd_put(olist, 0);
+    unit_put(olist, 0);
 }
 
 /*
@@ -2464,8 +2398,8 @@ att_move_in_off(int combat_mode, struct combat *off,
 {
     struct sctstr sect;
     struct shpstr ship;
-    int troops;
-    int n, lunchbox = 0;
+    int troops, n;
+    int lunchbox = 0;
 
     move_in_land(combat_mode, off, olist, def);
 
@@ -2478,29 +2412,29 @@ att_move_in_off(int combat_mode, struct combat *off,
        def->mil += troops;
        put_combat(off + n);
        if (combat_mode == A_ASSAULT) {
-           if (off[n].type != EF_SHIP || def->type != EF_SECTOR) {
-               logerror("att_move_in_off: strange assault");
+           if (CANT_HAPPEN(off[n].type != EF_SHIP))
                continue;
-           }
            getship(off[n].shp_uid, &ship);
            lunchbox += (int)((troops + 1) * ship.shp_item[I_FOOD]
                              / (ship.shp_item[I_MILIT] + troops
                                 + ship.shp_item[I_CIVIL] + 0.5));
+
            ship.shp_item[I_FOOD] -= lunchbox;
            putship(ship.shp_uid, &ship);
        }
     }
+
     put_combat(def);
-    if (!lunchbox)
-       return;
-    if (def->type != EF_SECTOR) {
-       pr("Please tell the deity that you got the 'hungry mole' error\n");
-       logerror("att_move_in_off: hungry mole");
-       return;
+
+    if (combat_mode == A_ASSAULT) {
+       if (CANT_HAPPEN(def->type != EF_SECTOR))
+           return;
+       getsect(def->x, def->y, &sect);
+       if (lunchbox > ITEM_MAX - sect.sct_item[I_FOOD])
+           lunchbox = ITEM_MAX - sect.sct_item[I_FOOD];
+       sect.sct_item[I_FOOD] += lunchbox;
+       putsect(&sect);
     }
-    getsect(def->x, def->y, &sect);
-    sect.sct_item[I_FOOD] += lunchbox;
-    putsect(&sect);
 }
 
 
@@ -2512,9 +2446,9 @@ ask_move_in_off(struct combat *off, struct combat *def)
     int mob_support;
     int num_mil, dam = 0, left;
     double d, weight;
-    s_char prompt[512];
-    s_char buf[1024];
-    s_char *p;
+    char prompt[512];
+    char buf[1024];
+    char *p;
 
     if (att_get_combat(off, 0) <= 0)
        return;
@@ -2522,15 +2456,13 @@ ask_move_in_off(struct combat *off, struct combat *def)
        return;
     if (off->own != player->cnum)
        return;
-    d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD);
-    if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0)
+    d = att_mobcost(off->own, def, MOB_MOVE);
+    if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
        return;
     sprintf(prompt, "How many mil to move in from %s (%d max)? ",
            xyas(off->x, off->y, player->cnum), mob_support);
-    if (!(p = getstring(prompt, buf)) || !*p || (num_mil = atoi(p)) <= 0) {
-       num_mil = 0;
+    if (!(p = getstring(prompt, buf)) || !*p || (num_mil = atoi(p)) <= 0)
        return;
-    }
 /* Make sure we don't move in more than we can support mobility-wise */
     if (num_mil > mob_support)
        num_mil = mob_support;
@@ -2538,18 +2470,18 @@ ask_move_in_off(struct combat *off, struct combat *def)
        return;
     if (att_get_combat(def, 0) < 0)
        return;
-    if ((num_mil = min(off->troops, num_mil)) <= 0) {
+    if ((num_mil = MIN(off->troops, num_mil)) <= 0) {
        pr("No mil moved in from %s\n",
           xyas(off->x, off->y, player->cnum));
        return;
     }
-    mob_support = max(1, (int)(num_mil * d));
-    off->mob -= min(off->mob, mob_support);
+    mob_support = MAX(1, (int)(num_mil * d));
+    off->mob -= MIN(off->mob, mob_support);
     off->mil -= num_mil;
     off->troops -= num_mil;
     put_combat(off);
     left = num_mil;
-    weight = num_mil * ichr[I_MILIT].i_lbs;
+    weight = (double)num_mil * ichr[I_MILIT].i_lbs;
     if (opt_INTERDICT_ATT && chance(weight / 200.0)) {
        if (chance(weight / 100.0))
            dam +=
@@ -2558,7 +2490,7 @@ ask_move_in_off(struct combat *off, struct combat *def)
     }
 
     if (dam) {
-       left = commdamage(num_mil, dam, V_MILIT);
+       left = commdamage(num_mil, dam, I_MILIT);
        if (left < num_mil) {
            if (left) {
                pr("%d of the mil you were moving were destroyed!\nOnly %d mil made it to %s\n", num_mil - left, left, xyas(def->x, def->y, player->cnum));
@@ -2578,52 +2510,57 @@ ask_move_in_off(struct combat *off, struct combat *def)
 /* Charge land units for moving into a sector or onto a ship */
 
 static void
-take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off,
+take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
                 struct combat *def)
 {
-    int mobcost;
-    int new;
+    double mob = llp->unit.land.lnd_mobil;
+    double gain = etu_per_update * land_mob_scale;
+    double mobcost, moblim;
 
     switch (combat_mode) {
     case A_ATTACK:
-       mobcost =
-           lnd_mobcost(&llp->land, getsectp(def->x, def->y), MOB_NONE);
-       new = llp->land.lnd_mobil - mobcost;
-       if (new < -127)
-           new = -127;
-       llp->land.lnd_mobil = new;
+       mobcost = lnd_pathcost(&llp->unit.land,
+                              att_mobcost(off->own, def,
+                                          lnd_mobtype(&llp->unit.land)));
        break;
     case A_ASSAULT:
-       if (off->shp_mcp->m_flags & M_LAND) {
-           if (llp->lcp->l_flags & L_MARINE)
-               llp->land.lnd_mobil -=
-                   ((float)etu_per_update * land_mob_scale * 0.5);
-           else
-               llp->land.lnd_mobil -= ((float)etu_per_update
-                                       * land_mob_scale);
+       /*
+        * Set mobcost to basic assault cost, moblim to maximum
+        * mobility to keep when assaulting from non-landing ship
+        */
+       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) {
+           mobcost = gain / 2.0;
+           moblim = 0;
        } else {
-           if (llp->lcp->l_flags & L_MARINE)
-               llp->land.lnd_mobil = 0;
-           else
-               llp->land.lnd_mobil = (((float)etu_per_update
-                                       * land_mob_scale) * (-1));
+           mobcost = gain;
+           moblim = -gain;
        }
+       if (!(off->shp_mcp->m_flags & M_LAND))
+           /* Not a landing ship, ensure we go to or below moblim */
+           mobcost = MAX(mobcost, mob - moblim);
        break;
     case A_BOARD:
-       /* I arbitrarily chose the numbers 10 and 40 below -KHS */
-       if (llp->lcp->l_flags & L_MARINE)
-           llp->land.lnd_mobil -= 10;
+       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
+           mobcost = 10;
        else
-           llp->land.lnd_mobil -= 40;
+           mobcost = 40;
        break;
+    default:
+       CANT_REACH();
+       mobcost = 0;
     }
-    llp->land.lnd_harden = 0;
+
+    mob -= mobcost;
+    if (mob < -127.0)
+       mob = -127.0;
+    llp->unit.land.lnd_mobil = (signed char)mob;
+    llp->unit.land.lnd_harden = 0;
 }
 
 static void
 free_list(struct emp_qelem *list)
 {
-    register struct emp_qelem *qp, *next;
+    struct emp_qelem *qp, *next;
 
     if (!list || QEMPTY(list))
        return;
@@ -2648,25 +2585,19 @@ att_free_lists(struct emp_qelem *olist, struct emp_qelem *dlist)
 /*
  * sector_strength - Everyone starts at 1.  You can get up to a max
  *                   of d_dstr, depending on how much you build up the
- *                   defenses of the sector. 
+ *                   defenses of the sector.
  */
 
 double
 sector_strength(struct sctstr *sp)
 {
-    double d;
-
-    d = 1.0;
-
-    if (sp->sct_type == SCT_MOUNT)
-       d = 2.0;
-
-    d = d + ((double)(dchr[sp->sct_type].d_dstr - d) *
-            ((double)sp->sct_defense / 100.0));
+    double def = SCT_DEFENSE(sp) / 100.0;
+    double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
+    double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
 
     if (d > dchr[sp->sct_type].d_dstr)
        d = dchr[sp->sct_type].d_dstr;
-    if (d < 0.1)
-       d = 0.1;
+    if (d < base)
+       d = base;
     return d;
 }