]> git.pond.sub.org Git - empserver/blob - src/lib/subs/nuke.c
10b7d23070b774f69157c71b6b56c46b4f36ab13
[empserver] / src / lib / subs / nuke.c
1 /*
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
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-2008
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
64     if (!own) {
65         np->nuk_effic = 0;
66         np->nuk_plane = -1;
67     }
68
69     if (oldnp->nuk_plane != np->nuk_plane)
70         nuk_carrier_change(np, EF_PLANE, oldnp->nuk_plane, np->nuk_plane);
71
72     /* We've avoided assigning to np->nuk_own, in case oldnp == np */
73     if (oldnp->nuk_own != own)
74         lost_and_found(EF_NUKE, oldnp->nuk_own, own,
75                        np->nuk_uid, np->nuk_x, np->nuk_y);
76
77     np->nuk_own = own;
78 }
79
80 char *
81 prnuke(struct nukstr *np)
82 {
83     return prbuf("%s warhead #%d",
84                  nchr[(int)np->nuk_type].n_name, np->nuk_uid);
85 }