]> git.pond.sub.org Git - empserver/commitdiff
Wipe orders when ship, plane, land unit or nuke changes owner
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 14 Sep 2008 23:32:34 +0000 (19:32 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 15 Sep 2008 23:40:44 +0000 (19:40 -0400)
Use new unit_wipe_orders() for violent takeover (takeover_unit() on
behalf of assault, attack, board, lboard, paradrop and pboard), and
peaceful takeover (unit_give_away() on behalf of arm, disarm, load,
unload, lload, lunload, scrap, scuttle, tend, trade).

Before, takeover_unit() cleared only group, mission and ship retreat
orders, and unit_give_away() only group and mission.  Orders that
weren't cleared:

* Mission op area (visible in xdump)

* Ship autonav orders

* Ship sail path including ship to follow and mobility quota

* Plane range limit

* Land unit retreat orders and retreat percentage

include/unit.h
src/lib/commands/trad.c
src/lib/subs/takeover.c
src/lib/subs/unitsub.c

index 34b9c99b18378d74f6a13e31eca499e00b6c276c..df31adca08c9f9176ba621cfaa4393dbc438435f 100644 (file)
@@ -59,3 +59,4 @@ extern void unit_view(struct emp_qelem *);
 extern void unit_update_cargo(struct empobj *);
 extern void unit_drop_cargo(struct empobj *, natid);
 extern void unit_give_away(struct empobj *, natid, natid);
+extern void unit_wipe_orders(struct empobj *);
index d5aea2702e59b6900777a5a75cca32d90a0edfee..c61c9c3a100c458619b8121afb0155e15af2b3ee 100644 (file)
@@ -372,8 +372,6 @@ check_trade(void)
            tg.plane.pln_land = -1;
            break;
        case EF_SHIP:
-           tg.ship.shp_rflags = 0;
-           memset(tg.ship.shp_rpath, 0, sizeof(tg.ship.shp_rpath));
            break;
        case EF_LAND:
            tg.land.lnd_x = trade.trd_x;
index 6037e4bfe979a54474292096d3046efb6446968d..43ffddedde1004bd12a0b0fd1f8c1e1227cd97f6 100644 (file)
@@ -47,6 +47,7 @@
 #include "prototypes.h"
 #include "sect.h"
 #include "ship.h"
+#include "unit.h"
 #include "xy.h"
 
 static void takeover_unit(struct empobj *, natid);
@@ -231,14 +232,11 @@ takeover_unit(struct empobj *unit, natid newown)
     unit->own = newown;
     if (opt_MARKET)
        trdswitchown(unit->ef_type, unit, newown);
-    unit->group = 0;
-    unit->mission = 0;
+    unit_wipe_orders(unit);
 
     switch (unit->ef_type) {
     case EF_SHIP:
        sp = (struct shpstr *)unit;
-       sp->shp_rflags = 0;
-       memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
        break;
     case EF_PLANE:
        pp = (struct plnstr *)unit;
index ebd4d5e1732dc021d282288dfd6c1ec17fc664f9..dff5ecbb971773d2417c4e9ca4f3790749a3c57c 100644 (file)
@@ -37,6 +37,7 @@
 #include "empobj.h"
 #include "file.h"
 #include "player.h"
+#include "optlist.h"
 #include "prototypes.h"
 #include "unit.h"
 
@@ -299,8 +300,7 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver)
     }
 
     unit->own = recipient;
-    unit->mission = 0;
-    unit->group = 0;
+    unit_wipe_orders(unit);
 
     for (type = EF_PLANE; type <= EF_NUKE; type++) {
        snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
@@ -310,3 +310,55 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver)
        }
     }
 }
+
+/*
+ * Wipe orders and such from UNIT.
+ */
+void
+unit_wipe_orders(struct empobj *unit)
+{
+    struct shpstr *sp;
+    struct plnstr *pp;
+    struct lndstr *lp;
+    int i;
+
+    unit->group = 0;
+    unit->opx = unit->opy = 0;
+    unit->mission = 0;
+    unit->radius = 0;
+
+    switch (unit->ef_type) {
+    case EF_SHIP:
+       sp = (struct shpstr *)unit;
+       sp->shp_destx[0] = sp->shp_desty[0] = 0;
+       sp->shp_destx[1] = sp->shp_desty[1] = 0;
+       for (i = 0; i < TMAX; ++i) {
+           sp->shp_tstart[i] = I_NONE;
+           sp->shp_tend[i] = I_NONE;
+           sp->shp_lstart[i] = 0;
+           sp->shp_lend[i] = 0;
+       }
+       sp->shp_autonav = 0;
+       sp->shp_mobquota = 0;
+       sp->shp_path[0] = 0;
+       sp->shp_follow = sp->shp_uid;
+       sp->shp_rflags = 0;
+       sp->shp_rpath[0] = 0;
+       break;
+    case EF_PLANE:
+       pp = (struct plnstr *)unit;
+       pp->pln_range = pln_range_max(pp);
+       break;
+    case EF_LAND:
+       lp = (struct lndstr *)unit;
+       lp->lnd_retreat = morale_base;
+       lp->lnd_rflags = 0;
+       lp->lnd_rpath[0] = 0;
+       lp->lnd_rad_max = 0;
+       break;
+    case EF_NUKE:
+       break;
+    default:
+       CANT_REACH();
+    }
+}