2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * fuel.c: fuel ships/land units
30 * Known contributors to this file:
59 static int shp_or_lnd[] = { EF_SHIP, EF_LAND, EF_BAD };
61 union item_u item, item2;
67 int land_fuel, ship_fuel;
68 int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt;
74 int fuelled_ship = -1;
75 struct nstr_item tender, ltender;
80 pr("Option 'FUEL' not enabled\n");
84 getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0)
86 type = ef_byname_from(p, shp_or_lnd);
88 pr("Ships or land units only! (s, l)\n");
91 sprintf(prompt, "%s(s)? ", ef_nameof(type));
92 p = getstarg(player->argp[2], prompt, buf);
93 if (!snxtitem(&ni, type, p))
96 fuelled_ship = atoi(p);
97 p = getstarg(player->argp[3], "Amount: ", buf);
98 if (p == 0 || *p == 0)
102 pr("Fuel amount must be positive!\n");
106 while (nxtitem(&ni, &item)) {
108 if (type == EF_SHIP) {
109 if (item.ship.shp_own != player->cnum) {
112 if (item.ship.shp_uid != fuelled_ship)
114 natp = getnatp(player->cnum);
115 rel = getrel(natp, item.ship.shp_own);
119 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
121 if (!item.ship.shp_own)
124 if (shp_check_nav(§, &item.ship) == CN_LANDLOCKED) {
125 pr("%s is landlocked and cannot be fueled.\n",
130 mp = &mchr[(int)item.ship.shp_type];
133 if (sect_has_dock(§)) {
135 oil_amt = sect.sct_item[I_OIL];
136 pet_amt = sect.sct_item[I_PETROL];
137 if ((oil_amt + pet_amt) == 0)
140 if (sect.sct_effic < 2) {
141 pr("The harbor at %s is not 2%% efficient yet.\n",
142 xyas(item.ship.shp_x,
143 item.ship.shp_y, player->cnum));
146 if ((sect.sct_own != player->cnum) && sect.sct_own)
150 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
151 pr("%s does not use fuel!\n", prship(&item.ship));
156 ship_fuel = item.ship.shp_fuel;
157 oil_amt = sect.sct_item[I_OIL];
158 pet_amt = sect.sct_item[I_PETROL];
159 max_amt = mp->m_fuelc - ship_fuel;
162 pr("%s already has a full fuel load.\n",
166 tot_fuel = (oil_amt * 50 + pet_amt * 5);
168 pr("No fuel in the harbor at %s!\n",
169 xyas(sect.sct_x, sect.sct_y, player->cnum));
172 move_amt = MIN(tot_fuel, fuel_amt);
173 move_amt = MIN(move_amt, max_amt);
178 item.ship.shp_fuel += move_amt;
181 if ((pet_amt * 5) >= move_amt) {
182 extra = ((float)move_amt / 5.0) - (move_amt / 5);
184 sect.sct_item[I_PETROL]
185 = MAX((pet_amt - move_amt / 5) - 1, 0);
187 sect.sct_item[I_PETROL]
188 = MAX((pet_amt - move_amt / 5), 0);
190 sect.sct_item[I_PETROL] = 0;
191 move_amt -= pet_amt * 5;
192 extra = ((float)move_amt / 50.0) - (move_amt / 50);
193 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
196 = MAX((oil_amt - move_amt / 50) - 1, 0);
199 = MAX((oil_amt - move_amt / 50), 0);
203 if (sect.sct_pstage == PLG_INFECT
204 && item.ship.shp_pstage == PLG_HEALTHY)
205 item.ship.shp_pstage = PLG_EXPOSED;
208 putship(item.ship.shp_uid, &item.ship);
209 } else { /* not in a harbor */
210 if (!player->argp[4])
211 pr("%s is not in a supplied, efficient harbor\n",
213 if (!snxtitem (&tender, EF_SHIP,
214 getstarg(player->argp[4], "Oiler? ", buf)))
217 if (!check_ship_ok(&item.ship))
220 if (!nxtitem(&tender, &item2))
223 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
224 pr("%s is not an oiler!\n", prship(&item2.ship));
227 if (item2.ship.shp_own != player->cnum) {
228 pr("You don't own that oiler!\n");
232 if ((item2.ship.shp_x != item.ship.shp_x) ||
233 (item2.ship.shp_y != item.ship.shp_y)) {
234 pr("Not in the same sector!\n");
237 ship_fuel = item.ship.shp_fuel;
238 oil_amt = item2.ship.shp_item[I_OIL];
239 pet_amt = item2.ship.shp_item[I_PETROL];
240 max_amt = mp->m_fuelc - ship_fuel;
243 pr("%s already has a full fuel load.\n",
247 tot_fuel = oil_amt * 50 + pet_amt * 5;
248 move_amt = MIN(tot_fuel, fuel_amt);
249 move_amt = MIN(move_amt, max_amt);
254 item.ship.shp_fuel += move_amt;
257 if ((pet_amt * 5) >= move_amt) {
258 extra = ((float)move_amt / 5.0) - (move_amt / 5);
260 item2.ship.shp_item[I_PETROL]
261 = MAX((pet_amt - move_amt / 5) - 1, 0);
263 item2.ship.shp_item[I_PETROL]
264 = MAX((pet_amt - move_amt / 5), 0);
266 item2.ship.shp_item[I_PETROL] = 0;
267 move_amt -= pet_amt * 5;
268 extra = ((float)move_amt / 50.0) - (move_amt / 50);
269 item2.ship.shp_item[I_OIL]
270 = MAX(oil_amt - (move_amt / 50), 0);
272 item2.ship.shp_item[I_OIL]
273 = MAX((oil_amt - move_amt / 50) - 1, 0);
275 item2.ship.shp_item[I_OIL]
276 = MAX((oil_amt - move_amt / 50), 0);
280 if (item2.ship.shp_pstage == PLG_INFECT
281 && item.ship.shp_pstage == PLG_HEALTHY)
282 item.ship.shp_pstage = PLG_EXPOSED;
284 putship(item.ship.shp_uid, &item.ship);
285 /* quick hack -KHS */
286 if (item.ship.shp_uid == item2.ship.shp_uid)
287 item2.ship.shp_fuel = item.ship.shp_fuel;
288 putship(item2.ship.shp_uid, &item2.ship);
290 pr("%s", prship(&item.ship));
292 if (item.land.lnd_own != player->cnum)
295 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
301 lcp = &lchr[(int)item.land.lnd_type];
304 oil_amt = sect.sct_item[I_OIL];
305 pet_amt = sect.sct_item[I_PETROL];
307 if ((oil_amt + pet_amt) == 0)
310 if ((item.land.lnd_fuelu == 0)
311 && (item.land.lnd_own == player->cnum)) {
312 pr("%s does not use fuel!\n", prland(&item.land));
317 land_fuel = item.land.lnd_fuel;
318 oil_amt = sect.sct_item[I_OIL];
319 pet_amt = sect.sct_item[I_PETROL];
320 max_amt = item.land.lnd_fuelc - land_fuel;
323 pr("%s already has a full fuel load.\n",
327 tot_fuel = (oil_amt * 50 + pet_amt * 5);
329 pr("No fuel in the sector at %s!\n",
330 xyas(sect.sct_x, sect.sct_y, player->cnum));
333 move_amt = MIN(tot_fuel, fuel_amt);
334 move_amt = MIN(move_amt, max_amt);
339 item.land.lnd_fuel += move_amt;
342 if ((pet_amt * 5) >= move_amt) {
343 extra = ((float)move_amt / 5.0) - (move_amt / 5);
345 sect.sct_item[I_PETROL]
346 = MAX((pet_amt - move_amt / 5) - 1, 0);
348 sect.sct_item[I_PETROL]
349 = MAX((pet_amt - move_amt / 5), 0);
351 sect.sct_item[I_PETROL] = 0;
352 move_amt -= pet_amt * 5;
353 extra = ((float)move_amt / 50.0) - (move_amt / 50);
354 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
357 = MAX((oil_amt - move_amt / 50) - 1, 0);
360 = MAX((oil_amt - move_amt / 50), 0);
364 if (sect.sct_pstage == PLG_INFECT
365 && item.land.lnd_pstage == PLG_HEALTHY)
366 item.land.lnd_pstage = PLG_EXPOSED;
369 putland(item.land.lnd_uid, &item.land);
370 } else { /* not in a sector */
371 if (!player->argp[4])
372 pr("%s is not in a supplied sector\n",
374 if (!snxtitem(<ender, EF_LAND,
375 getstarg(player->argp[4], "Supply unit? ",
379 if (!check_land_ok(&item.land))
382 if (!nxtitem(<ender, &item2))
385 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
386 pr("%s is not a supply unit!\n", prland(&item2.land));
389 if (item2.land.lnd_own != player->cnum) {
390 pr("You don't own that unit!\n");
394 if ((item2.land.lnd_x != item.land.lnd_x) ||
395 (item2.land.lnd_y != item.land.lnd_y)) {
396 pr("Not in the same sector!\n");
399 land_fuel = item.land.lnd_fuel;
400 oil_amt = item2.land.lnd_item[I_OIL];
401 pet_amt = item2.land.lnd_item[I_PETROL];
402 max_amt = item.land.lnd_fuelc - land_fuel;
405 pr("%s already has a full fuel load.\n",
409 tot_fuel = oil_amt * 50 + pet_amt * 5;
410 move_amt = MIN(tot_fuel, fuel_amt);
411 move_amt = MIN(move_amt, max_amt);
416 item.land.lnd_fuel += move_amt;
419 if ((pet_amt * 5) >= move_amt) {
420 extra = ((float)move_amt / 5.0) - (move_amt / 5);
422 item2.land.lnd_item[I_PETROL]
423 = MAX((pet_amt - move_amt / 5) - 1, 0);
425 item2.land.lnd_item[I_PETROL]
426 = MAX((pet_amt - move_amt / 5), 0);
428 item2.land.lnd_item[I_PETROL] = 0;
429 move_amt -= pet_amt * 5;
430 extra = ((float)move_amt / 50.0) - (move_amt / 50);
431 item2.land.lnd_item[I_OIL]
432 = MAX(oil_amt - move_amt / 50, 0);
434 item2.land.lnd_item[I_OIL]
435 = MAX((oil_amt - move_amt / 50) - 1, 0);
437 item2.land.lnd_item[I_OIL]
438 = MAX((oil_amt - move_amt / 50), 0);
442 if (item2.land.lnd_pstage == PLG_INFECT
443 && item.land.lnd_pstage == PLG_HEALTHY)
444 item.land.lnd_pstage = PLG_EXPOSED;
446 putland(item.land.lnd_uid, &item.land);
447 /* quick hack -KHS */
448 if (item2.land.lnd_uid == item.land.lnd_uid)
449 item2.land.lnd_fuel = item.land.lnd_fuel;
450 putland(item2.land.lnd_uid, &item2.land);
452 pr("%s", prland(&item.land));
455 pr(" takes on %d fuel in %s\n",
457 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
458 if (player->cnum != item.ship.shp_own)
459 wu(0, item.ship.shp_own,
460 "%s takes on %d fuel in %s courtesy of %s\n",
463 xyas(item.ship.shp_x, item.ship.shp_y,
464 item.ship.shp_own), cname(player->cnum));