2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * plane.c: Plane post-read and pre-write data massage
30 * Known contributors to this file:
45 #include "prototypes.h"
49 pln_postread(int n, void *ptr)
51 struct plnstr *pp = ptr;
52 struct shpstr theship;
53 struct lndstr theland;
55 if (pp->pln_uid != n) {
56 logerror("pln_postread: Error - %d != %d, zeroing.\n",
58 memset(pp, 0, sizeof(struct plnstr));
61 if (pp->pln_ship >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
62 if (getship(pp->pln_ship, &theship) &&
63 (theship.shp_effic >= SHIP_MINEFF)) {
64 /* wooof! Carriers are a pain */
65 if (pp->pln_mission) {
67 * If the plane is on a mission centered
68 * on it's loc, the op-area travels with
71 if ((pp->pln_opx == pp->pln_x) &&
72 (pp->pln_opy == pp->pln_y)) {
73 pp->pln_opx = theship.shp_x;
74 pp->pln_opy = theship.shp_y;
77 if (pp->pln_x != theship.shp_x || pp->pln_y != theship.shp_y)
78 time(&pp->pln_timestamp);
79 pp->pln_x = theship.shp_x;
80 pp->pln_y = theship.shp_y;
83 if (pp->pln_land >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
84 if (getland(pp->pln_land, &theland) &&
85 (theland.lnd_effic >= LAND_MINEFF)) {
86 /* wooof! Units are a pain, too */
87 if (pp->pln_mission) {
89 * If the plane is on a mission centered
90 * on it's loc, the op-area travels with
93 if ((pp->pln_opx == pp->pln_x) &&
94 (pp->pln_opy == pp->pln_y)) {
95 pp->pln_opx = theland.lnd_x;
96 pp->pln_opy = theland.lnd_y;
99 if (pp->pln_x != theland.lnd_x || pp->pln_y != theland.lnd_y)
100 time(&pp->pln_timestamp);
101 pp->pln_x = theland.lnd_x;
102 pp->pln_y = theland.lnd_y;
105 player->owner = (player->god || pp->pln_own == player->cnum);
111 pln_prewrite(int n, void *old, void *new)
113 struct plnstr *oldpp = old;
114 struct plnstr *pp = new;
115 natid own = pp->pln_own;
119 if (pp->pln_effic < PLANE_MINEFF) {
122 pp->pln_ship = pp->pln_land = -1;
123 for (i = 0; NULL != (np = getnukep(i)); i++) {
124 if (np->nuk_own && np->nuk_plane == n) {
125 mpr(np->nuk_own, "%s lost!\n", prnuke(np));
128 putnuke(np->nuk_uid, np);
133 if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
135 if (oldpp->pln_ship != pp->pln_ship)
136 pln_carrier_change(pp, EF_SHIP, oldpp->pln_ship, pp->pln_ship);
137 if (oldpp->pln_land != pp->pln_land)
138 pln_carrier_change(pp, EF_LAND, oldpp->pln_land, pp->pln_land);
140 /* We've avoided assigning to pp->pln_own, in case oldsp == sp */
141 if (oldpp->pln_own != own)
142 lost_and_found(EF_PLANE, oldpp->pln_own, own,
143 pp->pln_uid, pp->pln_x, pp->pln_y);
149 pln_oninit(void *ptr)
151 struct plnstr *pp = ptr;
153 pp->pln_ship = pp->pln_land = -1;
157 prplane(struct plnstr *pp)
159 return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);