]> git.pond.sub.org Git - empserver/blob - src/lib/subs/plane.c
Update copyright notice.
[empserver] / src / lib / subs / plane.c
1 /*
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
5  *
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.
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, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  plane.c: Plane post-read and pre-write data massage
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  *     Steve McClure, 1996
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "plane.h"
38 #include "ship.h"
39 #include "land.h"
40 #include "file.h"
41 #include "prototypes.h"
42 #include "optlist.h"
43
44 int
45 pln_postread(int n, s_char *ptr)
46 {
47     struct plnstr *pp = (struct plnstr *)ptr;
48     struct shpstr theship;
49     struct lndstr theland;
50
51     if (pp->pln_uid != n) {
52         logerror("pln_postread: Error - %d != %d, zeroing.\n", pp->pln_uid,
53                  n);
54         memset(pp, 0, sizeof(struct plnstr));
55     }
56
57     if (pp->pln_ship >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
58         if (getship(pp->pln_ship, &theship) &&
59             (theship.shp_effic >= SHIP_MINEFF)) {
60             /* wooof!  Carriers are a pain */
61             if (pp->pln_mission) {
62                 /*
63                  *  If the plane is on a mission centered
64                  *  on it's loc, the op-area travels with
65                  *  the plane.
66                  */
67                 if ((pp->pln_opx == pp->pln_x) &&
68                     (pp->pln_opy == pp->pln_y)) {
69                     pp->pln_opx = theship.shp_x;
70                     pp->pln_opy = theship.shp_y;
71                 }
72             }
73             if (pp->pln_x != theship.shp_x || pp->pln_y != theship.shp_y)
74                 time(&pp->pln_timestamp);
75             pp->pln_x = theship.shp_x;
76             pp->pln_y = theship.shp_y;
77         }
78     }
79     if (pp->pln_land >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) {
80         if (getland(pp->pln_land, &theland) &&
81             (theland.lnd_effic >= LAND_MINEFF)) {
82             /* wooof!  Units are a pain, too */
83             if (pp->pln_mission) {
84                 /*
85                  *  If the plane is on a mission centered
86                  *  on it's loc, the op-area travels with
87                  *  the plane.
88                  */
89                 if ((pp->pln_opx == pp->pln_x) &&
90                     (pp->pln_opy == pp->pln_y)) {
91                     pp->pln_opx = theland.lnd_x;
92                     pp->pln_opy = theland.lnd_y;
93                 }
94             }
95             if (pp->pln_x != theland.lnd_x || pp->pln_y != theland.lnd_y)
96                 time(&pp->pln_timestamp);
97             pp->pln_x = theland.lnd_x;
98             pp->pln_y = theland.lnd_y;
99         }
100     }
101     player->owner = (player->god || pp->pln_own == player->cnum);
102     if (opt_MOB_ACCESS)
103         pln_do_upd_mob(pp);
104     return 1;
105 }
106
107 /*ARGSUSED*/
108 int
109 pln_prewrite(int n, s_char *ptr)
110 {
111     struct plnstr *pp = (struct plnstr *)ptr;
112     struct plnstr plane;
113
114     if (pp->pln_effic < PLANE_MINEFF) {
115         if (pp->pln_own)
116             makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
117                      pp->pln_y);
118         pp->pln_own = 0;
119         pp->pln_effic = 0;
120     }
121     pp->ef_type = EF_PLANE;
122     pp->pln_uid = n;
123
124     time(&pp->pln_timestamp);
125
126     getplane(n, &plane);
127
128     return 1;
129 }
130
131 void
132 pln_init(int n, s_char *ptr)
133 {
134     struct plnstr *pp = (struct plnstr *)ptr;
135
136     pp->ef_type = EF_PLANE;
137     pp->pln_uid = n;
138     pp->pln_own = 0;
139 }
140
141 s_char *
142 prplane(struct plnstr *pp)
143 {
144     return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
145 }