2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * nuke.c: Nuke post-read and pre-write data massage
30 * Known contributors to this file:
45 #include "prototypes.h"
49 nuk_postread(int n, s_char *ptr)
51 struct nukstr *np = (struct nukstr *)ptr;
53 if (np->nuk_uid != n) {
54 logerror("nuk_postread: Error - %d != %d, zeroing.\n", np->nuk_uid,
56 memset(np, 0, sizeof(struct nukstr));
58 player->owner = (player->god || np->nuk_own == player->cnum);
64 nuk_prewrite(int n, s_char *ptr)
66 struct nukstr *np = (struct nukstr *)ptr;
69 np->ef_type = EF_NUKE;
72 time(&np->nuk_timestamp);
80 nuk_init(int n, s_char *ptr)
82 struct nukstr *np = (struct nukstr *)ptr;
84 np->ef_type = EF_NUKE;
90 nuk_add(coord x, coord y, int type, int num)
98 /* getsect in case of world wraparound */
100 if (!(own = sect.sct_own))
106 * either find a stockpile in x,y or add a new one
109 for (n = 0; getnuke(n, &nuke); n++) {
110 if (nuke.nuk_own == own) {
111 if (nuke.nuk_x == x && nuke.nuk_y == y) {
115 } else if (nuke.nuk_own == 0 && nuk_uid == -1)
120 if (getnuke(nuk_uid, &nuke) == 0) {
121 ef_extend(EF_NUKE, 10);
122 memset(&nuke, 0, sizeof(struct nukstr));
123 nuke.nuk_uid = nuk_uid;
125 if (nuke.nuk_own == 0) {
130 makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x,
133 nuke.nuk_types[type] += num;
136 if (!putnuke(nuke.nuk_uid, &nuke))
137 pr("Problem with the nuclear stockpiles, tell the deity.\n");
142 nuk_delete(struct nukstr *np, int type, int num)
144 if (np->nuk_types[type] < num)
145 num = np->nuk_types[type];
146 np->nuk_types[type] -= num;
148 if (np->nuk_n <= 0) {
149 makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
152 putnuke(np->nuk_uid, np);