1 /* $Id: tuner.c,v 1.12 2002/01/18 22:34:26 kimiko Exp $
2  *
3  * XPilot, a multiplayer gravity war game.  Copyright (C) 1991-2001 by
4  *
5  *      Bj�rn Stabell        <bjoern@xpilot.org>
6  *      Ken Ronny Schouten   <ken@xpilot.org>
7  *      Bert Gijsbers        <bert@xpilot.org>
8  *      Dick Balaska         <dick@xpilot.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 #define	SERVER
26 #include <stdlib.h>
27 #include <time.h>
28 #include "serverconst.h"
29 #include "global.h"
30 #include "proto.h"
31 #include "error.h"
32 #include "commonproto.h"
33 
34 
35 extern time_t gameOverTime;
36 
37 
tuner_plock(void)38 void tuner_plock(void)
39 {
40     pLockServer = (plock_server(pLockServer) == 1) ? true : false;
41 }
42 
tuner_shotsmax(void)43 void tuner_shotsmax(void)
44 {
45     int i;
46 
47     for (i = 0; i < NumPlayers; i++) {
48 	Players[i]->shot_max = ShotsMax;
49     }
50 }
51 
tuner_shipmass(void)52 void tuner_shipmass(void)
53 {
54     int i;
55 
56     for (i = 0; i < NumPlayers; i++) {
57 	Players[i]->emptymass = ShipMass;
58     }
59 }
60 
tuner_ballmass(void)61 void tuner_ballmass(void)
62 {
63     int i;
64 
65     for (i = 0; i < NumObjs; i++) {
66 	if (BIT(Obj[i]->type, OBJ_BALL)) {
67 	    Obj[i]->mass = ballMass;
68 	}
69     }
70 }
71 
tuner_maxrobots(void)72 void tuner_maxrobots(void)
73 {
74     if (maxRobots < 0) {
75 	maxRobots = World.NumBases;
76     }
77 
78     if (maxRobots < minRobots) {
79 	minRobots = maxRobots;
80     }
81 
82     while (maxRobots < NumRobots) {
83 	Robot_delete(-1, true);
84     }
85 }
86 
tuner_minrobots(void)87 void tuner_minrobots(void)
88 {
89     if (minRobots < 0) {
90 	minRobots = maxRobots;
91     }
92 
93     if (maxRobots < minRobots) {
94 	maxRobots = minRobots;
95     }
96 }
97 
tuner_playershielding(void)98 void tuner_playershielding(void)
99 {
100     int i;
101 
102     Set_world_rules();
103 
104     if (playerShielding) {
105 	SET_BIT(DEF_HAVE, HAS_SHIELD);
106 
107 	for (i = 0; i < NumPlayers; i++) {
108 	    if (!IS_TANK_PTR(Players[i])) {
109 		if (!BIT(Players[i]->used, HAS_SHOT))
110 		    SET_BIT(Players[i]->used, HAS_SHIELD);
111 
112 		SET_BIT(Players[i]->have, HAS_SHIELD);
113 		Players[i]->shield_time = 0;
114 	    }
115 	}
116     }
117     else {
118 	CLR_BIT(DEF_HAVE, HAS_SHIELD);
119 
120 	for (i = 0; i < NumPlayers; i++) {
121 	    Players[i]->shield_time = 2 * FPS;
122 	    /* 2 seconds to get to safety */
123 	}
124     }
125 }
126 
tuner_playerstartsshielded(void)127 void tuner_playerstartsshielded(void)
128 {
129     if (playerShielding) {
130 	playerStartsShielded = true;	/* Doesn't make sense
131 					   to turn off when
132 					   shields are on. */
133     }
134 }
135 
tuner_worldlives(void)136 void tuner_worldlives(void)
137 {
138     if (worldLives < 0)
139 	worldLives = 0;
140 
141     Set_world_rules();
142 
143     if (BIT(World.rules->mode, LIMITED_LIVES)) {
144 	Reset_all_players();
145 	if (gameDuration == -1)
146 	    gameDuration = 0;
147     }
148 }
149 
tuner_cannonsmartness(void)150 void tuner_cannonsmartness(void)
151 {
152     LIMIT(cannonSmartness, 0, 3);
153 }
154 
tuner_teamcannons(void)155 void tuner_teamcannons(void)
156 {
157     int i;
158     int team;
159 
160     if (teamCannons) {
161 	for (i = 0; i < World.NumCannons; i++) {
162 	    team = Find_closest_team(World.cannon[i].blk_pos.x,
163 				     World.cannon[i].blk_pos.y);
164 	    if (team == TEAM_NOT_SET) {
165 		error("Couldn't find a matching team for the cannon.");
166 	    }
167 	    World.cannon[i].team = team;
168 	}
169     }
170     else {
171 	for (i = 0; i < World.NumCannons; i++)
172 	    World.cannon[i].team = TEAM_NOT_SET;
173     }
174 }
175 
tuner_cannonsuseitems(void)176 void tuner_cannonsuseitems(void)
177 {
178     int i, j;
179     cannon_t *c;
180 
181     Move_init();
182 
183     for (i = 0; i < World.NumCannons; i++) {
184 	c = World.cannon + i;
185 	for (j = 0; j < NUM_ITEMS; j++) {
186 	    c->item[j] = 0;
187 
188 	    if (cannonsUseItems)
189 		Cannon_add_item(i, j,
190 				(int)(rfrac() * (World.items[j].initial + 1)));
191 	}
192     }
193 }
194 
tuner_wormtime(void)195 void tuner_wormtime(void)
196 {
197     int i;
198 
199     if (wormTime < 0)
200 	wormTime = 0;
201 
202     if (wormTime) {
203 	for (i = 0; i < World.NumWormholes; i++) {
204 	    World.wormHoles[i].countdown = wormTime;
205 	}
206     }
207     else {
208 	for (i = 0; i < World.NumWormholes; i++) {
209 	    if (World.wormHoles[i].temporary)
210 		remove_temp_wormhole(i);
211 	    else
212 		World.wormHoles[i].countdown = WORMCOUNT;
213 	}
214     }
215 }
216 
tuner_modifiers(void)217 void tuner_modifiers(void)
218 {
219     int i;
220 
221     Set_world_rules();
222 
223     for (i = 0; i < NumPlayers; i++) {
224 	filter_mods(&Players[i]->mods);
225     }
226 }
227 
tuner_minelife(void)228 void tuner_minelife(void)
229 {
230     int i;
231     int life;
232 
233     if (mineLife < 0)
234 	mineLife = 0;
235 
236     for (i = 0; i < NumObjs; i++) {
237 	if (Obj[i]->type != OBJ_MINE)
238 	    continue;
239 
240 	if (!BIT(Obj[i]->status, FROMCANNON)) {
241 	    life =
242 		(mineLife ? mineLife : MINE_LIFETIME) / (Obj[i]->mods.mini +
243 							 1);
244 
245 	    Obj[i]->life = (int)(rfrac() * life);
246 	    /* We wouldn't want all the mines
247 	       to explode simultaneously, now
248 	       would we? */
249 	}
250     }
251 }
252 
tuner_missilelife(void)253 void tuner_missilelife(void)
254 {
255     int i;
256     int life;
257 
258     if (missileLife < 0)
259 	missileLife = 0;
260 
261     for (i = 0; i < NumObjs; i++) {
262 	if (Obj[i]->type != OBJ_SMART_SHOT &&
263 	    Obj[i]->type != OBJ_HEAT_SHOT && Obj[i]->type != OBJ_TORPEDO)
264 	    continue;
265 
266 	if (!BIT(Obj[i]->status, FROMCANNON)) {
267 	    life =
268 		(mineLife ? mineLife : MISSILE_LIFETIME) / (Obj[i]->mods.mini +
269 							    1);
270 
271 	    Obj[i]->life = (int)(rfrac() * life);
272 	    /* Maybe all the missiles are full
273 	       nukes. Going off together might
274 	       not be such a good idea. */
275 	}
276     }
277 }
278 
tuner_gameduration(void)279 void tuner_gameduration(void)
280 {
281     if (gameDuration <= 0.0) {
282 	gameOverTime = time((time_t *) NULL);
283     }
284 
285     else
286 	gameOverTime = (time_t) (gameDuration * 60) + time((time_t *) NULL);
287 }
288 
tuner_racelaps(void)289 void tuner_racelaps(void)
290 {
291     if (BIT(World.rules->mode, TIMING)) {
292 	Reset_all_players();
293 	if (gameDuration == -1)
294 	    gameDuration = 0;
295     }
296 }
297 
tuner_allowalliances(void)298 void tuner_allowalliances(void)
299 {
300     if (BIT(World.rules->mode, TEAM_PLAY)) {
301 	CLR_BIT(World.rules->mode, ALLIANCES);
302     }
303     if (!BIT(World.rules->mode, ALLIANCES) && NumAlliances > 0) {
304 	Dissolve_all_alliances();
305     }
306 }
307 
tuner_announcealliances(void)308 void tuner_announcealliances(void)
309 {
310     updateScores = true;
311 }
312