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 * land.c: Land unit post-read and pre-write
29 * Known contributors to this file:
31 * Markus Armbruster, 2004-2008
42 #include "prototypes.h"
46 lnd_postread(int n, void *ptr)
48 struct lndstr *lp = ptr;
50 if (lp->lnd_uid != n) {
51 logerror("lnd_postread: Error - %d != %d, zeroing.\n",
53 memset(lp, 0, sizeof(struct lndstr));
58 player->owner = (player->god || lp->lnd_own == player->cnum);
62 lnd_prewrite(int n, void *old, void *new)
64 struct lndstr *oldlp = old;
65 struct lndstr *lp = new;
66 natid own = lp->lnd_effic < LAND_MINEFF ? 0 : lp->lnd_own;
70 lp->lnd_ship = lp->lnd_land = -1;
72 item_prewrite(lp->lnd_item);
74 if (CANT_HAPPEN(lp->lnd_ship >= 0 && lp->lnd_land >= 0))
76 if (oldlp->lnd_ship != lp->lnd_ship)
77 lnd_carrier_change(lp, EF_SHIP, oldlp->lnd_ship, lp->lnd_ship);
78 if (oldlp->lnd_land != lp->lnd_land)
79 lnd_carrier_change(lp, EF_LAND, oldlp->lnd_land, lp->lnd_land);
81 /* We've avoided assigning to lp->lnd_own, in case oldlp == lp */
82 if (oldlp->lnd_own != own)
83 lost_and_found(EF_LAND, oldlp->lnd_own, own,
84 lp->lnd_uid, lp->lnd_x, lp->lnd_y);
87 if (!own || lp->lnd_x != oldlp->lnd_x || lp->lnd_y != oldlp->lnd_y)
88 unit_update_cargo((struct empobj *)lp);
92 prland(struct lndstr *lp)
94 return prbuf("%s #%d", lchr[(int)lp->lnd_type].l_name, lp->lnd_uid);