]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
Update copyright notice
[empserver] / src / lib / subs / lndsub.c
index c5774bae29595da2fa392d450183124f47299503..077ea84322ca70204afe40d7c536d54587fc122a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2010
+ *     Markus Armbruster, 2004-2012
  */
 
 #include <config.h>
 
 #include <math.h>
 #include <stdlib.h>
+#include "chance.h"
 #include "combat.h"
 #include "damage.h"
 #include "empobj.h"
@@ -161,7 +162,6 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
     int n;
     int biggest;
     int civs;
-    int nowned;
     coord ret_x, ret_y;
     coord bx, by;
     struct sctstr sect;
@@ -212,7 +212,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
     /* Have to make a retreat check */
 
     ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
-    if (roll(100) < ret_chance) {
+    if (pct_chance(ret_chance)) {
        pr("\n");
        lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
        llp->unit.land.lnd_mission = 0;
@@ -227,7 +227,6 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
             * owner. Charge mob..
             */
            biggest = -1;
-           nowned = 0;
            for (n = 1; n <= 6; ++n) {
                ret_x = llp->unit.land.lnd_x + diroff[n][0];
                ret_y = llp->unit.land.lnd_y + diroff[n][1];
@@ -239,7 +238,6 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
                mobcost = lnd_mobcost(&llp->unit.land, &sect);
                if (mobcost < 0)
                    continue;
-               ++nowned;
                civs = sect.sct_item[I_CIVIL];
                if (civs > biggest) {
                    biggest = civs;
@@ -248,7 +246,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
                    bmcost = mobcost;
                }
            }
-           if (!nowned)
+           if (biggest < 0)
                nowhere_to_go = 1;
            else {
                /* retreat to bx,by */
@@ -524,8 +522,14 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
     }
 }
 
+/*
+ * Sweep landmines with engineers in LAND_LIST for ACTOR.
+ * 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.
+ */
 void
-lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
+lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
          natid actor)
 {
     struct emp_qelem *qp;
@@ -538,26 +542,21 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
        next = qp->q_back;
        llp = (struct ulist *)qp;
        if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
-           if (verbose)
+           if (explicit)
                mpr(actor, "%s is not an engineer!\n",
                    prland(&llp->unit.land));
            continue;
        }
        if (takemob && llp->mobil < 0.0) {
-           if (verbose)
+           if (explicit)
                lnd_stays(actor, "is out of mobility", llp);
            continue;
        }
        getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &sect);
-       if (sect.sct_oldown == llp->unit.land.lnd_own) {
-           if (verbose)
-               mpr(actor,
-                   "%s is in a sector completely owned by you.  Don't bother digging up mines there!\n",
-                   prland(&llp->unit.land));
+       if (!explicit && relations_with(sect.sct_oldown, actor) == ALLIED)
            continue;
-       }
        if (SCT_MINES_ARE_SEAMINES(&sect)) {
-           if (verbose)
+           if (explicit)
                mpr(actor, "%s is in a %s sector.  No landmines there!\n",
                    prland(&llp->unit.land), dchr[sect.sct_type].d_name);
            continue;
@@ -1100,7 +1099,7 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
            nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
        else
            nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
-       if (roll(100) < lnd_acc(&land))
+       if (pct_chance(lnd_acc(&land) - 1))
            dam2 /= 2;
        dam += dam2;
        if (land.lnd_own != attacker)