2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * plane.c: Plane post-read and pre-write data massage
29 * Known contributors to this file:
32 * Markus Armbruster, 2006-2008
43 #include "prototypes.h"
47 pln_postread(int n, void *ptr)
49 struct plnstr *pp = ptr;
51 if (pp->pln_uid != n) {
52 logerror("pln_postread: Error - %d != %d, zeroing.\n",
54 memset(pp, 0, sizeof(struct plnstr));
56 player->owner = (player->god || pp->pln_own == player->cnum);
62 pln_prewrite(int n, void *old, void *new)
64 struct plnstr *oldpp = old;
65 struct plnstr *pp = new;
66 natid own = pp->pln_effic < PLANE_MINEFF ? 0 : pp->pln_own;
70 pp->pln_ship = pp->pln_land = -1;
73 if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
75 if (oldpp->pln_ship != pp->pln_ship)
76 pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, pp->pln_ship);
77 if (oldpp->pln_land != pp->pln_land)
78 pln_carrier_change(pp, EF_LAND, oldpp->pln_land, pp->pln_land);
80 /* We've avoided assigning to pp->pln_own, in case oldpp == pp */
81 if (oldpp->pln_own != own)
82 lost_and_found(EF_PLANE, oldpp->pln_own, own,
83 pp->pln_uid, pp->pln_x, pp->pln_y);
86 if (!own || pp->pln_x != oldpp->pln_x || pp->pln_y != oldpp->pln_y)
87 unit_update_cargo((struct empobj *)pp);
93 struct plnstr *pp = ptr;
95 pp->pln_ship = pp->pln_land = -1;
99 prplane(struct plnstr *pp)
101 return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);