]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
Update copyright notice
[empserver] / src / lib / subs / lndsub.c
index 30630a708c0e6945647fcab12439e2ba0680a0b5..077ea84322ca70204afe40d7c536d54587fc122a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, 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;
@@ -169,7 +169,6 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
     char buf[1024];
     int taken;
     int nowhere_to_go = 0;
-    struct sctstr rsect;
     double mobcost, bmcost;
     signed char orig;
     int mob;
@@ -213,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;
@@ -228,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];
@@ -237,10 +235,9 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
                    continue;
                if (sect.sct_type == SCT_MOUNT)
                    continue;
-               mobcost = lnd_mobcost(&llp->unit.land, &rsect);
+               mobcost = lnd_mobcost(&llp->unit.land, &sect);
                if (mobcost < 0)
                    continue;
-               ++nowned;
                civs = sect.sct_item[I_CIVIL];
                if (civs > biggest) {
                    biggest = civs;
@@ -249,14 +246,13 @@ 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 */
                llp->unit.land.lnd_x = bx;
                llp->unit.land.lnd_y = by;
                /* FIXME landmines */
-               getsect(bx, by, &rsect);
                mob = llp->unit.land.lnd_mobil - (int)bmcost;
                if (mob < -127)
                    mob = -127;
@@ -462,8 +458,8 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
     struct emp_qelem *qp;
     struct emp_qelem *next;
     struct ulist *llp;
+    struct lndstr *lp;
     struct sctstr sect;
-    struct lndstr land;
     coord allx;
     coord ally;
     int first = 1;
@@ -475,59 +471,65 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        llp = (struct ulist *)qp;
-       getland(llp->unit.land.lnd_uid, &land);
-       if (land.lnd_own != actor) {
+       lp = &llp->unit.land;
+       getland(lp->lnd_uid, lp);
+       if (lp->lnd_own != actor) {
            mpr(actor, "%s was disbanded at %s\n",
-               prland(&land), xyas(land.lnd_x, land.lnd_y, actor));
+               prland(lp), xyas(lp->lnd_x, lp->lnd_y, actor));
            emp_remque((struct emp_qelem *)llp);
            free(llp);
            continue;
        }
-       if (land.lnd_ship >= 0) {
+       if (lp->lnd_ship >= 0) {
            lnd_stays(actor, "is on a ship", llp);
            continue;
        }
-       if (land.lnd_land >= 0) {
+       if (lp->lnd_land >= 0) {
            lnd_stays(actor, "is on a unit", llp);
            continue;
        }
-       if (!getsect(land.lnd_x, land.lnd_y, &sect)) {
+       if (!getsect(lp->lnd_x, lp->lnd_y, &sect)) {
            lnd_stays(actor, "was sucked into the sky by a strange looking spaceland", llp);    /* heh -KHS */
            continue;
        }
-       if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
-           !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
-           llp->unit.land.lnd_item[I_MILIT] == 0) {
+       if (!(lchr[lp->lnd_type].l_flags & L_SPY) &&
+           !(lchr[lp->lnd_type].l_flags & L_TRAIN) &&
+           lp->lnd_item[I_MILIT] == 0) {
            lnd_stays(actor, "has no mil on it to guide it", llp);
            continue;
        }
        if (relations_with(sect.sct_own, actor) != ALLIED &&
-           !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
+           !(lchr[lp->lnd_type].l_flags & L_SPY) &&
            sect.sct_own) {
            sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
            lnd_stays(actor, mess, llp);
            continue;
        }
        if (first) {
-           allx = land.lnd_x;
-           ally = land.lnd_y;
+           allx = lp->lnd_x;
+           ally = lp->lnd_y;
            first = 0;
        }
-       if (land.lnd_x != allx || land.lnd_y != ally)
+       if (lp->lnd_x != allx || lp->lnd_y != ally)
            *togetherp = 0;
-       if (land.lnd_mobil + 1 < (int)llp->mobil) {
-           llp->mobil = land.lnd_mobil;
+       if (lp->lnd_mobil + 1 < (int)llp->mobil) {
+           llp->mobil = lp->lnd_mobil;
        }
        if (llp->mobil < *minmobp)
            *minmobp = llp->mobil;
        if (llp->mobil > *maxmobp)
            *maxmobp = llp->mobil;
-       llp->unit.land = land;
     }
 }
 
+/*
+ * 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;
@@ -540,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;
@@ -1102,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)