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
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 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.
28 * fuel.c: fuel ships/land units
30 * Known contributors to this file:
59 union item_u item, item2;
65 int land_fuel, ship_fuel;
66 int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt;
72 int fuelled_ship = -1;
73 struct nstr_item tender, ltender;
78 pr("Option 'FUEL' not enabled\n");
82 getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0)
85 if (type == EF_SECTOR)
87 if (type != EF_SHIP && type != EF_LAND) {
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 ni.flags &= ~(EFF_OWNER);
108 while (nxtitem(&ni, (s_char *)&item)) {
110 if (type == EF_SHIP) {
111 if (item.ship.shp_own != player->cnum) {
114 if (item.ship.shp_uid != fuelled_ship)
116 natp = getnatp(player->cnum);
117 rel = getrel(natp, item.ship.shp_own);
121 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
123 if (!item.ship.shp_own)
126 if ((sect.sct_type != SCT_HARBR)
127 && (sect.sct_type != SCT_WATER)
128 && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY
131 pr("Sector %s is not a harbor, bridge span, or sea.\n",
132 xyas(item.ship.shp_x, item.ship.shp_y,
137 mp = &mchr[(int)item.ship.shp_type];
140 if (sect.sct_type == SCT_HARBR
141 || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)) {
143 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
144 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
145 if ((oil_amt + pet_amt) == 0)
148 if (sect.sct_effic < 2) {
149 pr("The harbor at %s is not 2%% efficient yet.\n",
150 xyas(item.ship.shp_x,
151 item.ship.shp_y, player->cnum));
154 if ((sect.sct_own != player->cnum) && sect.sct_own)
158 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
159 pr("%s does not use fuel!\n", prship(&item.ship));
164 ship_fuel = item.ship.shp_fuel;
165 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
166 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
167 max_amt = mp->m_fuelc - ship_fuel;
170 pr("%s already has a full fuel load.\n",
174 tot_fuel = (oil_amt * 50 + pet_amt * 5);
176 pr("No fuel in the harbor at %s!\n",
177 xyas(sect.sct_x, sect.sct_y, player->cnum));
180 move_amt = min(tot_fuel, fuel_amt);
181 move_amt = min(move_amt, max_amt);
186 item.ship.shp_fuel += move_amt;
189 if ((pet_amt * 5) >= move_amt) {
190 extra = ((float)move_amt / 5.0) - (move_amt / 5);
193 max((pet_amt - (move_amt / 5)) - 1, 0),
194 (s_char *)§, EF_SECTOR);
197 max((pet_amt - (move_amt / 5)), 0),
198 (s_char *)§, EF_SECTOR);
200 putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR);
201 move_amt -= pet_amt * 5;
202 extra = ((float)move_amt / 50.0) - (move_amt / 50);
203 putvar(V_OIL, max(oil_amt - (move_amt / 50), 0),
204 (s_char *)§, EF_SECTOR);
207 max((oil_amt - (move_amt / 50)) - 1, 0),
208 (s_char *)§, EF_SECTOR);
211 max((oil_amt - (move_amt / 50)), 0),
212 (s_char *)§, EF_SECTOR);
216 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) ==
217 PLG_INFECT && getvar(V_PSTAGE,
218 (s_char *)&item.ship,
219 EF_SHIP) == PLG_HEALTHY)
220 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.ship,
224 putship(item.ship.shp_uid, &item.ship);
225 } else { /* not in a harbor */
226 if (!player->argp[4])
227 pr("%s is not in a supplied, efficient harbor\n",
231 getstarg(player->argp[4], "Oiler? ", buf)))
234 if (!check_ship_ok(&item.ship))
237 if (!nxtitem(&tender, (s_char *)&item2))
240 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
241 pr("%s is not an oiler!\n", prship(&item2.ship));
244 if (item2.ship.shp_own != player->cnum) {
245 pr("You don't own that oiler!\n");
249 if ((item2.ship.shp_x != item.ship.shp_x) ||
250 (item2.ship.shp_y != item.ship.shp_y)) {
251 pr("Not in the same sector!\n");
254 ship_fuel = item.ship.shp_fuel;
255 oil_amt = getvar(V_OIL, (s_char *)&item2.ship, EF_SHIP);
256 pet_amt = getvar(V_PETROL, (s_char *)&item2.ship, EF_SHIP);
257 max_amt = mp->m_fuelc - ship_fuel;
260 pr("%s already has a full fuel load.\n",
264 tot_fuel = oil_amt * 50 + pet_amt * 5;
265 move_amt = min(tot_fuel, fuel_amt);
266 move_amt = min(move_amt, max_amt);
271 item.ship.shp_fuel += move_amt;
274 if ((pet_amt * 5) >= move_amt) {
275 extra = ((float)move_amt / 5.0) - (move_amt / 5);
278 max((pet_amt - (move_amt / 5)) - 1, 0),
279 (s_char *)&item2.ship, EF_SHIP);
282 max((pet_amt - (move_amt / 5)), 0),
283 (s_char *)&item2.ship, EF_SHIP);
285 putvar(V_PETROL, 0, (s_char *)&item2.ship, EF_SHIP);
286 move_amt -= pet_amt * 5;
287 extra = ((float)move_amt / 50.0) - (move_amt / 50);
288 putvar(V_OIL, max(oil_amt - (move_amt / 50), 0),
289 (s_char *)&item2.ship, EF_SHIP);
292 max((oil_amt - (move_amt / 50)) - 1, 0),
293 (s_char *)&item2.ship, EF_SHIP);
296 max((oil_amt - (move_amt / 50)), 0),
297 (s_char *)&item2.ship, EF_SHIP);
301 if (getvar(V_PSTAGE, (s_char *)&item2.ship, EF_SHIP) ==
302 PLG_INFECT && getvar(V_PSTAGE,
303 (s_char *)&item.ship,
304 EF_SHIP) == PLG_HEALTHY)
305 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.ship,
308 putship(item.ship.shp_uid, &item.ship);
309 /* quick hack -KHS */
310 if (item.ship.shp_uid == item2.ship.shp_uid)
311 item2.ship.shp_fuel = item.ship.shp_fuel;
312 putship(item2.ship.shp_uid, &item2.ship);
314 pr("%s", prship(&item.ship));
316 if (item.land.lnd_own != player->cnum)
319 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
325 lcp = &lchr[(int)item.land.lnd_type];
328 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
329 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
331 if ((oil_amt + pet_amt) == 0)
334 if ((item.land.lnd_fuelu == 0)
335 && (item.land.lnd_own == player->cnum)) {
336 pr("%s does not use fuel!\n", prland(&item.land));
341 land_fuel = item.land.lnd_fuel;
342 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
343 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
344 max_amt = item.land.lnd_fuelc - land_fuel;
347 pr("%s already has a full fuel load.\n",
351 tot_fuel = (oil_amt * 50 + pet_amt * 5);
353 pr("No fuel in the sector at %s!\n",
354 xyas(sect.sct_x, sect.sct_y, player->cnum));
357 move_amt = min(tot_fuel, fuel_amt);
358 move_amt = min(move_amt, max_amt);
363 item.land.lnd_fuel += move_amt;
366 if ((pet_amt * 5) >= move_amt) {
367 extra = ((float)move_amt / 5.0) - (move_amt / 5);
370 max((pet_amt - (move_amt / 5)) - 1, 0),
371 (s_char *)§, EF_SECTOR);
374 max((pet_amt - (move_amt / 5)), 0),
375 (s_char *)§, EF_SECTOR);
377 putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR);
378 move_amt -= pet_amt * 5;
379 extra = ((float)move_amt / 50.0) - (move_amt / 50);
380 putvar(V_OIL, max(oil_amt - (move_amt / 50), 0),
381 (s_char *)§, EF_SECTOR);
384 max((oil_amt - (move_amt / 50)) - 1, 0),
385 (s_char *)§, EF_SECTOR);
388 max((oil_amt - (move_amt / 50)), 0),
389 (s_char *)§, EF_SECTOR);
393 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) ==
394 PLG_INFECT && getvar(V_PSTAGE,
395 (s_char *)&item.land,
396 EF_LAND) == PLG_HEALTHY)
397 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.land,
401 putland(item.land.lnd_uid, &item.land);
402 } else { /* not in a sector */
403 if (!player->argp[4])
404 pr("%s is not in a supplied sector\n",
406 if (!snxtitem(<ender, EF_LAND,
407 getstarg(player->argp[4], "Supply unit? ",
411 if (!check_land_ok(&item.land))
414 if (!nxtitem(<ender, (s_char *)&item2))
417 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
418 pr("%s is not a supply unit!\n", prland(&item2.land));
421 if (item2.land.lnd_own != player->cnum) {
422 pr("You don't own that unit!\n");
426 if ((item2.land.lnd_x != item.land.lnd_x) ||
427 (item2.land.lnd_y != item.land.lnd_y)) {
428 pr("Not in the same sector!\n");
431 land_fuel = item.land.lnd_fuel;
432 oil_amt = getvar(V_OIL, (s_char *)&item2.land, EF_LAND);
433 pet_amt = getvar(V_PETROL, (s_char *)&item2.land, EF_LAND);
434 max_amt = item.land.lnd_fuelc - land_fuel;
437 pr("%s already has a full fuel load.\n",
441 tot_fuel = oil_amt * 50 + pet_amt * 5;
442 move_amt = min(tot_fuel, fuel_amt);
443 move_amt = min(move_amt, max_amt);
448 item.land.lnd_fuel += move_amt;
451 if ((pet_amt * 5) >= move_amt) {
452 extra = ((float)move_amt / 5.0) - (move_amt / 5);
455 max((pet_amt - (move_amt / 5)) - 1, 0),
456 (s_char *)&item2.land, EF_LAND);
459 max((pet_amt - (move_amt / 5)), 0),
460 (s_char *)&item2.land, EF_LAND);
462 putvar(V_PETROL, 0, (s_char *)&item2.land, EF_LAND);
463 move_amt -= pet_amt * 5;
464 extra = ((float)move_amt / 50.0) - (move_amt / 50);
465 putvar(V_OIL, max(oil_amt - (move_amt / 50), 0),
466 (s_char *)&item2.land, EF_LAND);
469 max((oil_amt - (move_amt / 50)) - 1, 0),
470 (s_char *)&item2.land, EF_LAND);
473 max((oil_amt - (move_amt / 50)), 0),
474 (s_char *)&item2.land, EF_LAND);
478 if (getvar(V_PSTAGE, (s_char *)&item2.land, EF_LAND) ==
479 PLG_INFECT && getvar(V_PSTAGE,
480 (s_char *)&item.land,
481 EF_LAND) == PLG_HEALTHY)
482 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.land,
485 putland(item.land.lnd_uid, &item.land);
486 /* quick hack -KHS */
487 if (item2.land.lnd_uid == item.land.lnd_uid)
488 item2.land.lnd_fuel = item.land.lnd_fuel;
489 putland(item2.land.lnd_uid, &item2.land);
491 pr("%s", prland(&item.land));
494 pr(" takes on %d fuel in %s\n",
496 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
497 if (player->cnum != item.ship.shp_own)
498 wu(0, item.ship.shp_own,
499 "%s takes on %d fuel in %s courtesy of %s\n",
502 xyas(item.ship.shp_x, item.ship.shp_y,
503 item.ship.shp_own), cname(player->cnum));