]> git.pond.sub.org Git - empserver/blob - src/lib/subs/nuke.c
Update copyright notice
[empserver] / src / lib / subs / nuke.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2018, 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  *  nuke.c: Nuke 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-2011
33  */
34
35 #include <config.h>
36
37 #include "lost.h"
38 #include "misc.h"
39 #include "nuke.h"
40 #include "player.h"
41 #include "prototypes.h"
42
43 void
44 nuk_postread(int n, void *ptr)
45 {
46     struct nukstr *np = ptr;
47
48     if (np->nuk_uid != n) {
49         logerror("nuk_postread: Error - %d != %d, zeroing.\n",
50                  np->nuk_uid, n);
51         memset(np, 0, sizeof(struct nukstr));
52     }
53     player->owner = (player->god || np->nuk_own == player->cnum);
54 }
55
56 void
57 nuk_prewrite(int n, void *old, void *new)
58 {
59     struct nukstr *oldnp = old;
60     struct nukstr *np = new;
61     natid own = np->nuk_effic == 0 ? 0 : np->nuk_own;
62     int plane = np->nuk_plane;
63
64     /* Be careful with writing to *np, in case oldnp == np */
65
66     if (!own) {
67         np->nuk_effic = 0;
68         plane = -1;
69     }
70
71     if (oldnp->nuk_plane != plane)
72         nuk_carrier_change(np, EF_PLANE, oldnp->nuk_plane, plane);
73
74     if (oldnp->nuk_own != own)
75         lost_and_found(EF_NUKE, oldnp->nuk_own, own,
76                        np->nuk_uid, np->nuk_x, np->nuk_y);
77
78     np->nuk_own = own;
79     np->nuk_plane = plane;
80 }
81
82 char *
83 prnuke(struct nukstr *np)
84 {
85     return prbuf("%s warhead #%d",
86                  nchr[(int)np->nuk_type].n_name, np->nuk_uid);
87 }