]> 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-2014, 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 "file.h"
38 #include "lost.h"
39 #include "misc.h"
40 #include "nuke.h"
41 #include "player.h"
42 #include "prototypes.h"
43
44 void
45 nuk_postread(int n, void *ptr)
46 {
47     struct nukstr *np = ptr;
48
49     if (np->nuk_uid != n) {
50         logerror("nuk_postread: Error - %d != %d, zeroing.\n",
51                  np->nuk_uid, n);
52         memset(np, 0, sizeof(struct nukstr));
53     }
54     player->owner = (player->god || np->nuk_own == player->cnum);
55 }
56
57 void
58 nuk_prewrite(int n, void *old, void *new)
59 {
60     struct nukstr *oldnp = old;
61     struct nukstr *np = new;
62     natid own = np->nuk_effic == 0 ? 0 : np->nuk_own;
63     int plane = np->nuk_plane;
64
65     /* Be careful with writing to *np, in case oldnp == np */
66
67     if (!own) {
68         np->nuk_effic = 0;
69         plane = -1;
70     }
71
72     if (oldnp->nuk_plane != plane)
73         nuk_carrier_change(np, EF_PLANE, oldnp->nuk_plane, plane);
74
75     if (oldnp->nuk_own != own)
76         lost_and_found(EF_NUKE, oldnp->nuk_own, own,
77                        np->nuk_uid, np->nuk_x, np->nuk_y);
78
79     np->nuk_own = own;
80     np->nuk_plane = plane;
81 }
82
83 char *
84 prnuke(struct nukstr *np)
85 {
86     return prbuf("%s warhead #%d",
87                  nchr[(int)np->nuk_type].n_name, np->nuk_uid);
88 }