]> git.pond.sub.org Git - empserver/commitdiff
Clean up output destinations in attack code
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 20 Jun 2010 08:02:27 +0000 (10:02 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 24 Jul 2010 09:28:33 +0000 (11:28 +0200)
take_def() and ask_move_in() printed both to the current player and to
land unit owner.  Their use of prcom() and xyas() looked particularly
suspicious: they used the current player, then printed the result to
the land unit owner.  Fortunately, current player and land unit owner
are the same, since even even deities can't attack with foreign land
units.  Normalize to current player for consistency.

Switch get_ototal(), get_oland(), kill_land() and move_in_land() to
current player as well.

include/land.h
src/lib/subs/attsub.c
src/lib/subs/lndsub.c

index 93a1fd54e17634634fd98f30a569f8f08794f0e2..eba703ca44afa3b703e6f10394a46b6ed85e8205 100644 (file)
@@ -180,7 +180,7 @@ extern double lnd_mobcost(struct lndstr *, struct sctstr *);
 extern double attack_val(int, struct lndstr *);
 extern double defense_val(struct lndstr *);
 extern int lnd_reaction_range(struct lndstr *);
-extern void lnd_print(struct ulist *, char *);
+extern void lnd_print(natid, struct ulist *, char *);
 extern void lnd_delete(struct ulist *);
 extern int lnd_take_casualty(int, struct ulist *, int);
 extern void lnd_submil(struct lndstr *, int);
index 4738112aa5f00caa51c12fc0da0dd33eb22d2ce6..c0f22deeb20a0c33a35e6cc0164b5206d4ac4cb5 100644 (file)
@@ -1290,7 +1290,8 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
                    w = n;
            }
            if (w < 0) {
-               lnd_print(llp, "is in a sector not owned by you");
+               lnd_print(player->cnum, llp,
+                         "is in a sector not owned by you");
                lnd_delete(llp);
                continue;
            }
@@ -1356,7 +1357,7 @@ get_oland(int combat_mode, struct ulist *llp)
     if (lp->lnd_own != player->cnum) {
        sprintf(buf, "was destroyed and is no longer a part of the %s",
                att_mode[combat_mode]);
-       lnd_print(llp, buf);
+       lnd_print(player->cnum, llp, buf);
        lnd_delete(llp);
        return 0;
     }
@@ -1364,14 +1365,14 @@ get_oland(int combat_mode, struct ulist *llp)
        sprintf(buf,
                "left to fight another battle and is no longer a part of the %s",
                att_mode[combat_mode]);
-       lnd_print(llp, buf);
+       lnd_print(player->cnum, llp, buf);
        lnd_delete(llp);
        return 0;
     }
     if (lp->lnd_effic < llp->eff) {
        sprintf(buf, "damaged from %d%% to %d%%",
                llp->eff, lp->lnd_effic);
-       lnd_print(llp, buf);
+       lnd_print(player->cnum, llp, buf);
     }
 
     llp->eff = llp->unit.land.lnd_effic;
@@ -1388,12 +1389,12 @@ get_dland(struct combat *def, struct ulist *llp)
 
     if (lp->lnd_effic < LAND_MINEFF) {
        sprintf(buf, "was destroyed and is no longer a part of the defense");
-       lnd_print(llp, buf);
+       lnd_print(llp->unit.land.lnd_own, llp, buf);
        lnd_delete(llp);
        return 0;
     }
     if (lp->lnd_x != def->x || lp->lnd_y != def->y) {
-       lnd_print(llp,
+       lnd_print(llp->unit.land.lnd_own, llp,
                  "left to go fight another battle and is no longer a part of the defense");
        lnd_delete(llp);
        return 0;
@@ -1414,7 +1415,8 @@ kill_land(struct emp_qelem *list)
        llp = (struct ulist *)qp;
        if (llp->unit.land.lnd_ship >= 0) {
            llp->unit.land.lnd_effic = 0;
-           lnd_print(llp, "cannot return to the ship, and dies!");
+           lnd_print(player->cnum, llp,
+                     "cannot return to the ship, and dies!");
            lnd_delete(llp);
        }
     }
@@ -2162,7 +2164,7 @@ send_reacting_units_home(struct emp_qelem *list)
                    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_print(llp, buf);
+           lnd_print(llp->unit.land.lnd_own, llp, buf);
            lnd_delete(llp);
        }
     }
@@ -2236,13 +2238,13 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
            if (def->type == EF_SHIP) {
                llp->unit.land.lnd_ship = def->shp_uid;
                sprintf(buf, "boards %s", prcom(0, def));
-               lnd_print(llp, buf);
+               lnd_print(player->cnum, llp, buf);
                delete_me = llp;
            } else {
                llp->unit.land.lnd_ship = -1;
                sprintf(buf, "moves in to occupy %s",
                        xyas(def->x, def->y, player->cnum));
-               lnd_print(llp, buf);
+               lnd_print(player->cnum, llp, buf);
                lnd_delete(llp);
            }
        }
@@ -2324,7 +2326,7 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
        sprintf(buf, "stays in %s",
                xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                     player->cnum));
-       lnd_print(llp, buf);
+       lnd_print(player->cnum, llp, buf);
        lnd_delete(llp);
     }
     if (QEMPTY(olist))
@@ -2338,7 +2340,7 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
            sprintf(buf, "stays in %s",
                    xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                         player->cnum));
-           lnd_print(llp, buf);
+           lnd_print(player->cnum, llp, buf);
            lnd_delete(llp);
        }
        return;
@@ -2389,7 +2391,7 @@ move_in_land(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 ulist *)qp;
-       lnd_print(llp, buf);
+       lnd_print(player->cnum, llp, buf);
     }
     if (QEMPTY(olist))
        return;
index 2c14f7fe2a6383444077a332758328017fa06ae2..565fd91233df74bce6879e6ed56fbd760a04581b 100644 (file)
@@ -136,12 +136,12 @@ lnd_reaction_range(struct lndstr *lp)
 }
 
 void
-lnd_print(struct ulist *llp, char *s)
+lnd_print(natid actor, struct ulist *llp, char *s)
 {
-    if (llp->unit.land.lnd_own == player->cnum)
+    if (actor == player->cnum)
        pr("%s %s\n", prland(&llp->unit.land), s);
     else
-       wu(0, llp->unit.land.lnd_own, "%s %s\n", prland(&llp->unit.land), s);
+       wu(0, actor, "%s %s\n", prland(&llp->unit.land), s);
 }
 
 void
@@ -190,7 +190,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
                combat_mode ? att_mode[combat_mode] : "defending",
                xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                     llp->unit.land.lnd_own));
-       lnd_print(llp, buf);
+       lnd_print(llp->unit.land.lnd_own, llp, buf);
        lnd_delete(llp);
        /* Since we killed the unit, we killed all the mil on it */
        return taken;
@@ -215,7 +215,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
     ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
     if (roll(100) < ret_chance) {
        pr("\n");
-       lnd_print(llp, "fails morale check!");
+       lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
        llp->unit.land.lnd_mission = 0;
        llp->unit.land.lnd_harden = 0;
        if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
@@ -267,7 +267,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
                sprintf(buf, "retreats at %d%% efficiency to %s!",
                        llp->unit.land.lnd_effic,
                        xyas(bx, by, llp->unit.land.lnd_own));
-               lnd_print(llp, buf);
+               lnd_print(llp->unit.land.lnd_own, llp, buf);
                lnd_delete(llp);
            }
        } else {                /* attacking from a sector */
@@ -278,7 +278,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
            else
                llp->unit.land.lnd_mobil -= (int)llp->mobil;
            llp->mobil = 0.0;
-           lnd_print(llp, buf);
+           lnd_print(llp->unit.land.lnd_own, llp, buf);
            lnd_delete(llp);
        }
     }
@@ -288,10 +288,11 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
        lnd_submil(&llp->unit.land,
                   ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
        if (llp->unit.land.lnd_effic < LAND_MINEFF) {
-           lnd_print(llp, "has nowhere to retreat, and dies!");
+           lnd_print(llp->unit.land.lnd_own, llp,
+                     "has nowhere to retreat, and dies!");
            lnd_delete(llp);
        } else
-           lnd_print(llp,
+           lnd_print(llp->unit.land.lnd_own, llp,
                      "has nowhere to retreat and takes extra losses!");
     }