]> git.pond.sub.org Git - empserver/blob - src/lib/subs/plane.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / subs / plane.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "var.h"
38 #include "plane.h"
39 #include "ship.h"
40 #include "land.h"
41 #include "xy.h"
42 #include "file.h"
43 #include "nat.h"
44 #include "deity.h"
45 #include "prototypes.h"
46 #include "optlist.h"
47
48 int
49 pln_postread(int n, s_char *ptr)
50 {
51     struct plnstr *pp = (struct plnstr *)ptr;
52     struct shpstr theship;
53     struct lndstr theland;
54
55     if (pp->pln_uid != n) {
56         logerror("pln_postread: Error - %d != %d, zeroing.\n", pp->pln_uid,
57                  n);
58         bzero(ptr, sizeof(struct plnstr));
59     }
60
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) {
66                 /*
67                  *  If the plane is on a mission centered
68                  *  on it's loc, the op-area travels with
69                  *  the plane.
70                  */
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;
75                 }
76             }
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;
81         }
82     }
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) {
88                 /*
89                  *  If the plane is on a mission centered
90                  *  on it's loc, the op-area travels with
91                  *  the plane.
92                  */
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;
97                 }
98             }
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;
103         }
104     }
105     player->owner = (player->god || pp->pln_own == player->cnum);
106     if (opt_MOB_ACCESS)
107         pln_do_upd_mob(pp);
108     return 1;
109 }
110
111 /*ARGSUSED*/
112 int
113 pln_prewrite(int n, s_char *ptr)
114 {
115     struct plnstr *pp = (struct plnstr *)ptr;
116     struct plnstr plane;
117
118     if (pp->pln_effic < PLANE_MINEFF) {
119         if (pp->pln_own)
120             makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
121                      pp->pln_y);
122         pp->pln_own = 0;
123         pp->pln_effic = 0;
124     }
125     pp->ef_type = EF_PLANE;
126     pp->pln_uid = n;
127
128     time(&pp->pln_timestamp);
129
130     getplane(n, &plane);
131
132     return 1;
133 }
134
135 void
136 pln_init(int n, s_char *ptr)
137 {
138     struct plnstr *pp = (struct plnstr *)ptr;
139
140     pp->ef_type = EF_PLANE;
141     pp->pln_uid = n;
142     pp->pln_own = 0;
143 }
144
145 s_char *
146 prplane(struct plnstr *pp)
147 {
148     return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
149 }