2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * mobility.c: Add mobility to each of the items which accumulate mobility.
29 * Known contributors to this file:
31 * Steve McClure, 1998-1999
32 * Markus Armbruster, 2004-2008
47 static int do_upd_checking;
49 static void do_mob_land(struct lndstr *, int);
50 static void do_mob_plane(struct plnstr *, int);
51 static void do_mob_sect(struct sctstr *sp, int etus);
52 static void do_mob_ship(struct shpstr *, int);
55 sct_do_upd_mob(struct sctstr *sp)
59 if (do_upd_checking || update_running)
63 if (sp->sct_type == SCT_SANCT)
65 etus = game_tick_to_now(&sp->sct_access);
69 do_upd_checking = 1; /* avoid recursion */
70 do_mob_sect(sp, etus);
75 shp_do_upd_mob(struct shpstr *sp)
79 if (do_upd_checking || update_running)
83 etus = game_tick_to_now(&sp->shp_access);
87 do_upd_checking = 1; /* avoid recursion */
88 do_mob_ship(sp, etus);
93 lnd_do_upd_mob(struct lndstr *lp)
97 if (do_upd_checking || update_running)
101 etus = game_tick_to_now(&lp->lnd_access);
105 do_upd_checking = 1; /* avoid recursion */
106 do_mob_land(lp, etus);
111 pln_do_upd_mob(struct plnstr *pp)
115 if (do_upd_checking || update_running)
117 if (pp->pln_own == 0)
119 etus = game_tick_to_now(&pp->pln_access);
123 do_upd_checking = 1; /* avoid recursion */
124 do_mob_plane(pp, etus);
136 for (n = 0; NULL != (sp = getsectid(n)); n++) {
137 sp->sct_timestamp = now;
139 etus = game_reset_tick(&sp->sct_access);
141 etus = etu_per_update;
142 do_mob_sect(sp, etus);
147 do_mob_sect(struct sctstr *sp, int etus)
151 if (CANT_HAPPEN(etus < 0))
154 if (sp->sct_own == 0)
156 if (sp->sct_type == SCT_SANCT)
159 value = sp->sct_mobil + ((float)etus * sect_mob_scale);
160 if (value > sect_mob_max)
161 value = sect_mob_max;
162 sp->sct_mobil = value;
173 for (n = 0; NULL != (sp = getshipp(n)); n++) {
174 sp->shp_timestamp = now;
176 etus = game_reset_tick(&sp->shp_access);
178 etus = etu_per_update;
179 do_mob_ship(sp, etus);
184 do_mob_ship(struct shpstr *sp, int etus)
188 if (CANT_HAPPEN(etus < 0))
191 if (sp->shp_own == 0)
194 value = sp->shp_mobil + (float)etus * ship_mob_scale;
195 if (value > ship_mob_max)
196 value = ship_mob_max;
197 sp->shp_mobil = (signed char)value;
208 for (n = 0; NULL != (lp = getlandp(n)); n++) {
209 lp->lnd_timestamp = now;
211 etus = game_reset_tick(&lp->lnd_access);
213 etus = etu_per_update;
214 do_mob_land(lp, etus);
219 do_mob_land(struct lndstr *lp, int etus)
223 if (CANT_HAPPEN(etus < 0))
226 if (lp->lnd_own == 0)
229 value = lp->lnd_mobil + ((float)etus * land_mob_scale);
230 if (value > land_mob_max) {
231 if (lp->lnd_harden < land_mob_max && !opt_MOB_ACCESS) {
233 * Automatic fortification on excess mobility.
234 * Disabled for MOB_ACCESS, because it leads to
235 * excessively deep recursion and thus miserable
236 * performance as the number of land units grows.
238 * Provide mobility to be used in lnd_fortify()
239 * without overflowing lnd_mobil.
241 lp->lnd_mobil = land_mob_max;
242 lnd_fortify(lp, value - land_mob_max);
244 value = land_mob_max;
246 lp->lnd_mobil = value;
257 for (n = 0; NULL != (pp = getplanep(n)); n++) {
258 pp->pln_timestamp = now;
260 etus = game_reset_tick(&pp->pln_access);
262 etus = etu_per_update;
263 do_mob_plane(pp, etus);
268 do_mob_plane(struct plnstr *pp, int etus)
272 if (CANT_HAPPEN(etus < 0))
275 if (pp->pln_own == 0)
278 value = pp->pln_mobil + ((float)etus * plane_mob_scale);
279 if (value > plane_mob_max)
280 value = plane_mob_max;
281 pp->pln_mobil = value;