]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/plane.c
Update copyright notice
[empserver] / src / lib / subs / plane.c
index 29cb6523760c99603511634663b32e2863aa508e..eed46fc6644602bf33eb29a970084921a9c17818 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-2017, 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:
  *     Dave Pare, 1989
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2008
+ *     Markus Armbruster, 2006-2016
  */
 
 #include <config.h>
 
-#include "file.h"
 #include "lost.h"
 #include "misc.h"
 #include "optlist.h"
@@ -42,6 +41,7 @@
 #include "player.h"
 #include "prototypes.h"
 #include "unit.h"
+#include "update.h"
 
 void
 pln_postread(int n, void *ptr)
@@ -53,9 +53,11 @@ pln_postread(int n, void *ptr)
                 pp->pln_uid, n);
        memset(pp, 0, sizeof(struct plnstr));
     }
+
     player->owner = (player->god || pp->pln_own == player->cnum);
-    if (opt_MOB_ACCESS)
-       pln_do_upd_mob(pp);
+
+    if (opt_MOB_ACCESS && pp->pln_own && !update_running)
+       mob_inc_plane(pp, game_tick_to_now(&pp->pln_access));
 }
 
 void
@@ -64,25 +66,33 @@ pln_prewrite(int n, void *old, void *new)
     struct plnstr *oldpp = old;
     struct plnstr *pp = new;
     natid own = pp->pln_effic < PLANE_MINEFF ? 0 : pp->pln_own;
+    int ship = pp->pln_ship;
+    int land = pp->pln_land;
+
+    /* Be careful with writing to *pp, in case oldpp == pp */
 
     if (!own) {
        pp->pln_effic = 0;
-       pp->pln_ship = pp->pln_land = -1;
+       ship = land = -1;
     }
 
-    if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
-       pp->pln_land = -1;
-    if (oldpp->pln_ship != pp->pln_ship)
-       pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, pp->pln_ship);
-    if (oldpp->pln_land != pp->pln_land)
-       pln_carrier_change(pp, EF_LAND, oldpp->pln_land, pp->pln_land);
+    if (CANT_HAPPEN(ship >= 0 && land >= 0))
+       land = -1;
+    if (oldpp->pln_ship != ship)
+       pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, ship);
+    if (oldpp->pln_land != land)
+       pln_carrier_change(pp, EF_LAND, oldpp->pln_land, land);
 
-    /* We've avoided assigning to pp->pln_own, in case oldpp == pp */
-    if (oldpp->pln_own != own)
+    if (oldpp->pln_own != own) {
        lost_and_found(EF_PLANE, oldpp->pln_own, own,
                       pp->pln_uid, pp->pln_x, pp->pln_y);
+       CANT_HAPPEN(!oldpp->pln_own
+                   && unit_update_cargo((struct empobj *)oldpp));
+    }
 
     pp->pln_own = own;
+    pp->pln_ship = ship;
+    pp->pln_land = land;
     if (!own || pp->pln_x != oldpp->pln_x || pp->pln_y != oldpp->pln_y)
        unit_update_cargo((struct empobj *)pp);
 }