]> git.pond.sub.org Git - empserver/blob - src/lib/subs/plane.c
Update copyright notice
[empserver] / src / lib / subs / plane.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
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.
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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
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.
24  *
25  *  ---
26  *
27  *  plane.c: Plane post-read and pre-write data massage
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1989
31  *     Steve McClure, 1996
32  *     Markus Armbruster, 2006-2018
33  */
34
35 #include <config.h>
36
37 #include "lost.h"
38 #include "misc.h"
39 #include "optlist.h"
40 #include "plane.h"
41 #include "player.h"
42 #include "prototypes.h"
43 #include "unit.h"
44 #include "update.h"
45
46 void
47 pln_postread(int n, void *ptr)
48 {
49     struct plnstr *pp = ptr;
50
51     if (pp->pln_uid != n) {
52         logerror("pln_postread: Error - %d != %d, zeroing.\n",
53                  pp->pln_uid, n);
54         memset(pp, 0, sizeof(struct plnstr));
55     }
56
57     player->owner = (player->god || pp->pln_own == player->cnum);
58
59     if (opt_MOB_ACCESS && pp->pln_own && !update_running)
60         mob_inc_plane(pp, game_tick_to_now(&pp->pln_access));
61 }
62
63 void
64 pln_prewrite(int n, void *old, void *new)
65 {
66     struct plnstr *oldpp = old;
67     struct plnstr *pp = new;
68     natid own = pp->pln_effic < PLANE_MINEFF ? 0 : pp->pln_own;
69     int ship = pp->pln_ship;
70     int land = pp->pln_land;
71
72     /* Be careful with writing to *pp, in case oldpp == pp */
73
74     if (!own) {
75         pp->pln_effic = 0;
76         ship = land = -1;
77     }
78
79     if (CANT_HAPPEN(ship >= 0 && land >= 0))
80         land = -1;
81     if (oldpp->pln_ship != ship)
82         pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, ship);
83     if (oldpp->pln_land != land)
84         pln_carrier_change(pp, EF_LAND, oldpp->pln_land, land);
85
86     if (oldpp->pln_own != own) {
87         lost_and_found(EF_PLANE, oldpp->pln_own, own,
88                        pp->pln_uid, pp->pln_x, pp->pln_y);
89         CANT_HAPPEN(!oldpp->pln_own
90                     && unit_update_cargo((struct empobj *)oldpp));
91     }
92
93     pp->pln_own = own;
94     pp->pln_ship = ship;
95     pp->pln_land = land;
96     if (!own || pp->pln_x != oldpp->pln_x || pp->pln_y != oldpp->pln_y)
97         unit_update_cargo((struct empobj *)pp);
98     if (ship >= 0 || land >= 0)
99         pp->pln_harden = 0;
100 }
101
102 char *
103 prplane(struct plnstr *pp)
104 {
105     return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
106 }