]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
Update copyright notice
[empserver] / src / lib / subs / lndsub.c
index 6a52b2385bd34a7466cabd1c13ba32140916526d..11d653f03e4f6dc26c5d847c38eabdf6b80fbecd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2015
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -40,7 +40,6 @@
 #include "combat.h"
 #include "damage.h"
 #include "empobj.h"
-#include "file.h"
 #include "misc.h"
 #include "mission.h"
 #include "news.h"
@@ -85,12 +84,6 @@ attack_val(int combat_mode, struct lndstr *lp)
 
     lcp = &lchr[(int)lp->lnd_type];
 
-/* Spies always count as 1 during assaults.  If they are the only ones
-   in the assault, they get to sneak on anyway. */
-
-    if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
-       return 1;
-
     men = lp->lnd_item[I_MILIT];
     value = men * lnd_att(lp) * lp->lnd_effic / 100.0;
 
@@ -180,20 +173,20 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
     signed char orig;
     int mob;
 
+    if (CANT_HAPPEN(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))
+       return 0;
+
     taken = llp->unit.land.lnd_item[I_MILIT];
-    /* Spies always die */
-    if (lchr[llp->unit.land.lnd_type].l_flags & L_SPY)
-       llp->unit.land.lnd_effic = 0;
-    else {
-       eff_eq = ldround(cas * 100.0 /
-           lchr[llp->unit.land.lnd_type].l_item[I_MILIT], 1);
-       llp->unit.land.lnd_effic -= eff_eq;
-       lnd_submil(&llp->unit.land, cas);
-    }
+    eff_eq = ldround(cas * 100.0 /
+                    lchr[llp->unit.land.lnd_type].l_item[I_MILIT], 1);
+    llp->unit.land.lnd_effic -= eff_eq;
+    lnd_submil(&llp->unit.land, cas);
 
     if (llp->unit.land.lnd_effic < LAND_MINEFF) {
-       sprintf(buf, "dies %s %s!",
-               combat_mode ? att_mode[combat_mode] : "defending",
+       if (llp->unit.land.lnd_own == player->cnum)
+           pr("\n");
+       sprintf(buf, "dies %sing %s!",
+               att_mode[combat_mode],
                xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                     llp->unit.land.lnd_own));
        lnd_print(llp->unit.land.lnd_own, llp, buf);
@@ -220,7 +213,8 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
 
     ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
     if (pct_chance(ret_chance)) {
-       pr("\n");
+       if (llp->unit.land.lnd_own == player->cnum)
+           pr("\n");
        lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
        llp->unit.land.lnd_mission = 0;
        llp->unit.land.lnd_harden = 0;
@@ -370,7 +364,7 @@ intelligence_report(natid destination, struct lndstr *lp, int spy,
            buf2[0] = buf3[0] = 0;
        }
        if (destination == player->cnum)
-           pr("%s%s%s", buf1, buf2, buf3);
+           pr("%s%s%s\n", buf1, buf2, buf3);
        else
            wu(0, destination, "%s%s%s\n", buf1, buf2, buf3);
     }
@@ -489,7 +483,7 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
 }
 
 /*
- * Append LP to LIST.
+ * Append @lp to @list.
  * Return the new list link.
  */
 struct ulist *
@@ -587,11 +581,11 @@ lnd_put_one(struct ulist *llp)
 }
 
 /*
- * Sweep landmines with engineers in LAND_LIST for ACTOR.
- * All land units in LAND_LIST must be in the same sector.
- * If EXPLICIT is non-zero, this is for an explicit sweep command from
+ * Sweep landmines with engineers in @land_list for @actor.
+ * All land units in @land_list must be in the same sector.
+ * If @explicit is non-zero, this is for an explicit sweep command from
  * a player.  Else it's an automatic "on the move" sweep.
- * If TAKEMOB is non-zero, require and charge mobility.
+ * If @takemob is non-zero, require and charge mobility.
  * Return non-zero when the land units should stop.
  */
 int
@@ -711,7 +705,7 @@ lnd_check_mines(struct emp_qelem *land_list)
     return stopping;
 }
 
-/* Return whether and why SP would be stuck in SECTP.  */
+/* Return whether and why SP would be stuck in SECTP. */
 enum lnd_stuck
 lnd_check_mar(struct lndstr *lp, struct sctstr *sectp)
 {
@@ -954,8 +948,9 @@ lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
 
 /*
  * Ask user to confirm sector abandonment, if any.
- * All land units in LIST must be in the same sector.
- * If removing the land units in LIST would abandon their sector, ask
+ * All land units in @list must be in the same sector, owned by the
+ * player, and not loaded onto anything.
+ * If removing the land units in @list would abandon their sector, ask
  * the user to confirm.
  * Return zero when abandonment was declined, else non-zero.
  */
@@ -963,21 +958,21 @@ int lnd_abandon_askyn(struct emp_qelem *list)
 {
     struct ulist *llp;
     struct sctstr sect;
+    int abandon;
     struct emp_qelem *qp;
 
     if (QEMPTY(list))
        return 1;
     llp = (struct ulist *)list->q_back;
     getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &sect);
-    if (!abandon_askyn(&sect, I_CIVIL, 0, llp))
-       return 0;
+    abandon = abandon_askyn(&sect, I_CIVIL, 0, llp);
     if (!check_sect_ok(&sect))
        return 0;
     for (qp = list->q_back; qp != list; qp = qp->q_back) {
        if (!check_land_ok(&((struct ulist *)qp)->unit.land))
            return 0;
     }
-    return 1;
+    return abandon;
 }
 
 int
@@ -992,7 +987,7 @@ lnd_mar_dir(struct emp_qelem *list, int dir, natid actor)
     coord newx;
     coord newy;
     int move;
-    int rel;
+    enum relations rel;
     int oldown;
 
     if (CANT_HAPPEN(QEMPTY(list)))
@@ -1098,25 +1093,28 @@ lnd_mar_dir(struct emp_qelem *list, int dir, natid actor)
        }
     }
 
-    return 0;
+    return QEMPTY(list);
 }
 
 int
 lnd_mar_gauntlet(struct emp_qelem *list, int interdict, natid actor)
 {
     struct ulist *mlp = (struct ulist *)list->q_back;
-    coord newx = mlp->unit.land.lnd_x;
-    coord newy = mlp->unit.land.lnd_y;
+    coord newx, newy;
     int stopping, visible;
     struct emp_qelem *qp, *next;
     struct ulist *llp;
 
+    if (CANT_HAPPEN(QEMPTY(list)))
+       return 1;
+    newx = mlp->unit.land.lnd_x;
+    newy = mlp->unit.land.lnd_y;
     stopping = lnd_sweep(list, 0, 1, actor);
     if (QEMPTY(list))
-       return stopping;
+       return 1;
     stopping |= lnd_check_mines(list);
     if (QEMPTY(list))
-       return stopping;
+       return 1;
 
     visible = 0;
     for (qp = list->q_back; qp != list; qp = next) {
@@ -1132,8 +1130,8 @@ lnd_mar_gauntlet(struct emp_qelem *list, int interdict, natid actor)
 }
 
 /*
- * Fire land unit support against VICTIM for ATTACKER, at X,Y.
- * If DEFENDING, this is defensive support, else offensive support.
+ * Fire land unit support against @victim for @attacker, at @x,@y.
+ * If @defending, this is defensive support, else offensive support.
  * Return total damage.
  */
 int
@@ -1192,8 +1190,8 @@ lnd_can_attack(struct lndstr *lp)
 }
 
 /*
- * Increase fortification value of LP.
- * Fortification costs mobility.  Use up to MOB mobility.
+ * Increase fortification value of @lp.
+ * Fortification costs mobility.  Use up to @mob mobility.
  * Return actual fortification increase.
  */
 int
@@ -1226,7 +1224,7 @@ lnd_fortify(struct lndstr *lp, int mob)
 }
 
 /*
- * Is there a engineer unit at X,Y that can help nation CN?
+ * Is there a engineer unit at @x,@y that can help nation @cn?
  */
 static int
 has_helpful_engineer(coord x, coord y, natid cn)
@@ -1246,7 +1244,7 @@ has_helpful_engineer(coord x, coord y, natid cn)
 }
 
 /*
- * Set LP's tech to TLEV along with everything else that depends on it.
+ * Set @lp's tech to @tlev along with everything else that depends on it.
  */
 void
 lnd_set_tech(struct lndstr *lp, int tlev)