]> git.pond.sub.org Git - empserver/blob - src/lib/subs/land.c
Import of Empire 4.2.12
[empserver] / src / lib / subs / land.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  *  land.c: Land unit post-read and pre-write
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 1996
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "file.h"
38 #include "land.h"
39 #include "ship.h"
40 #include "xy.h"
41 #include "nat.h"
42 #include "deity.h"
43 #include "nsc.h"
44 #include "plane.h"
45 #include "prototypes.h"
46 #include "optlist.h"
47
48 int
49 lnd_postread(int n, s_char *ptr)
50 {
51     struct      lndstr *llp = (struct lndstr *) ptr;
52     struct      shpstr theship;
53     struct  lndstr theland;
54     
55         if (llp->lnd_uid != n) {
56                 logerror("lnd_postread: Error - %d != %d, zeroing.\n", llp->lnd_uid, n);
57                 bzero(ptr, sizeof(struct lndstr));
58         }
59     if (llp->lnd_ship >= 0 && llp->lnd_own && llp->lnd_effic >= LAND_MINEFF) {
60                 if (getship(llp->lnd_ship, &theship) &&
61                         (theship.shp_effic >= SHIP_MINEFF)) {
62                         /* wooof!  Carriers are a pain */
63                         if (llp->lnd_mission){
64                                 /*
65                                  *  If the unit is on a mission centered
66                                  *  on it's loc, the op-area travels with
67                                  *  the unit.
68                                  */
69                                 if ((llp->lnd_opx == llp->lnd_x) &&
70                                         (llp->lnd_opy == llp->lnd_y)) {
71                                         llp->lnd_opx = theship.shp_x;
72                                         llp->lnd_opy = theship.shp_y;
73                                 }
74                         }
75                         if (llp->lnd_x != theship.shp_x || llp->lnd_y != theship.shp_y)
76                                 time(&llp->lnd_timestamp);
77                         llp->lnd_x = theship.shp_x;
78                         llp->lnd_y = theship.shp_y;
79                 }
80     }
81     if (llp->lnd_land >= 0 && llp->lnd_own && llp->lnd_effic >= LAND_MINEFF) {
82                 if (getland(llp->lnd_land, &theland) &&
83                         (theland.lnd_effic >= LAND_MINEFF)) {
84                         /* wooof!  Carriers are a pain */
85                         if (llp->lnd_mission){
86                                 /*
87                                  *  If the unit is on a mission centered
88                                  *  on it's loc, the op-area travels with
89                                  *  the unit.
90                                  */
91                                 if ((llp->lnd_opx == llp->lnd_x) &&
92                                         (llp->lnd_opy == llp->lnd_y)){
93                                         llp->lnd_opx = theland.lnd_x;
94                                         llp->lnd_opy = theland.lnd_y;
95                                 }
96                         }
97                         if (llp->lnd_x != theland.lnd_x || llp->lnd_y != theland.lnd_y)
98                                 time(&llp->lnd_timestamp);
99                         llp->lnd_x = theland.lnd_x;
100                         llp->lnd_y = theland.lnd_y;
101                 }
102     }
103     if (opt_MOB_ACCESS)
104                 lnd_do_upd_mob(llp);
105     
106     player->owner = (player->god || llp->lnd_own == player->cnum);
107     return 1;
108 }
109
110 /*ARGSUSED*/
111 int
112 lnd_prewrite(int n, s_char *ptr)
113 {
114     struct      lndstr *llp = (struct lndstr *) ptr;
115     struct      lndstr land;
116     struct lndstr *lp;
117     struct plnstr *pp;
118     int i;
119     
120     llp->ef_type = EF_LAND;
121     llp->lnd_uid = n;
122     
123     time(&llp->lnd_timestamp);
124
125     if (llp->lnd_own && llp->lnd_effic < LAND_MINEFF) {
126                 makelost(EF_LAND, llp->lnd_own, llp->lnd_uid, llp->lnd_x, llp->lnd_y);
127                 llp->lnd_own = 0;
128                 
129                 getland(n, &land);
130                 
131                 for (i = 0; NULL != (lp = getlandp(i)); i++) {
132                         if (lp->lnd_own && lp->lnd_land == n) {
133                                 mpr(lp->lnd_own, "%s MIA!\n", prland(lp));
134                                 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
135                                 lp->lnd_own = 0;
136                                 lp->lnd_effic = 0;
137                                 lp->lnd_ship = -1;
138                                 lp->lnd_land = -1;
139                                 putland(lp->lnd_uid, lp);
140                         }
141                 }
142                 for (i = 0; NULL != (pp = getplanep(i)); i++) {
143                         if (pp->pln_own && pp->pln_land == n) {
144                                 mpr(pp->pln_own, "%s MIA!\n", prplane(pp));
145                                 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
146                                 pp->pln_own = 0;
147                                 pp->pln_effic = 0;
148                                 pp->pln_ship = -1;
149                                 pp->pln_land = -1;
150                                 putplane(pp->pln_uid, pp);
151                         }
152                 }
153     } else
154                 getland(n, &land);
155     
156     return 1;
157 }
158
159 void
160 lnd_init(int n, s_char *ptr)
161 {
162         struct  lndstr *lp = (struct lndstr *) ptr;
163
164         lp->ef_type = EF_LAND;
165         lp->lnd_uid = n;
166         lp->lnd_own = 0;
167 }
168
169 s_char *
170 prland(struct lndstr *lp)
171 {
172         return prbuf("%s #%d", lchr[(int)lp->lnd_type].l_name, lp->lnd_uid);
173 }