]> git.pond.sub.org Git - empserver/blob - src/lib/subs/land.c
Update copyright notice
[empserver] / src / lib / subs / land.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program 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 2 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  land.c: Land unit post-read and pre-write
29  *
30  *  Known contributors to this file:
31  *     Steve McClure, 1996
32  *     Markus Armbruster, 2004-2008
33  */
34
35 #include <config.h>
36
37 #include "file.h"
38 #include "land.h"
39 #include "lost.h"
40 #include "misc.h"
41 #include "optlist.h"
42 #include "player.h"
43 #include "prototypes.h"
44 #include "unit.h"
45
46 void
47 lnd_postread(int n, void *ptr)
48 {
49     struct lndstr *lp = ptr;
50
51     if (lp->lnd_uid != n) {
52         logerror("lnd_postread: Error - %d != %d, zeroing.\n",
53                  lp->lnd_uid, n);
54         memset(lp, 0, sizeof(struct lndstr));
55     }
56
57     if (opt_MOB_ACCESS)
58         lnd_do_upd_mob(lp);
59     player->owner = (player->god || lp->lnd_own == player->cnum);
60 }
61
62 void
63 lnd_prewrite(int n, void *old, void *new)
64 {
65     struct lndstr *oldlp = old;
66     struct lndstr *lp = new;
67     natid own = lp->lnd_effic < LAND_MINEFF ? 0 : lp->lnd_own;
68
69     if (!own) {
70         lp->lnd_effic = 0;
71         lp->lnd_ship = lp->lnd_land = -1;
72     }
73     item_prewrite(lp->lnd_item);
74
75     if (CANT_HAPPEN(lp->lnd_ship >= 0 && lp->lnd_land >= 0))
76         lp->lnd_land = -1;
77     if (oldlp->lnd_ship != lp->lnd_ship)
78         lnd_carrier_change(lp, EF_SHIP, oldlp->lnd_ship, lp->lnd_ship);
79     if (oldlp->lnd_land != lp->lnd_land)
80         lnd_carrier_change(lp, EF_LAND, oldlp->lnd_land, lp->lnd_land);
81
82     /* We've avoided assigning to lp->lnd_own, in case oldlp == lp */
83     if (oldlp->lnd_own != own)
84         lost_and_found(EF_LAND, oldlp->lnd_own, own,
85                        lp->lnd_uid, lp->lnd_x, lp->lnd_y);
86
87     lp->lnd_own = own;
88     if (!own || lp->lnd_x != oldlp->lnd_x || lp->lnd_y != oldlp->lnd_y)
89         unit_update_cargo((struct empobj *)lp);
90 }
91
92 void
93 lnd_oninit(void *ptr)
94 {
95     struct lndstr *lp = ptr;
96
97     lp->lnd_ship = lp->lnd_land = -1;
98 }
99
100 char *
101 prland(struct lndstr *lp)
102 {
103     return prbuf("%s #%d", lchr[(int)lp->lnd_type].l_name, lp->lnd_uid);
104 }