2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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:
58 union item_u item, item2;
64 int land_fuel, ship_fuel;
65 int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt;
71 int fuelled_ship = -1;
72 struct nstr_item tender, ltender;
77 pr("Option 'FUEL' not enabled\n");
81 getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0)
84 if (type == EF_SECTOR)
86 if (type != EF_SHIP && type != EF_LAND) {
87 pr("Ships or land units only! (s, l)\n");
90 sprintf(prompt, "%s(s)? ", ef_nameof(type));
91 p = getstarg(player->argp[2], prompt, buf);
92 if (!snxtitem(&ni, type, p))
95 fuelled_ship = atoi(p);
96 p = getstarg(player->argp[3], "Amount: ", buf);
97 if (p == 0 || *p == 0)
101 pr("Fuel amount must be positive!\n");
105 ni.flags &= ~(EFF_OWNER);
107 while (nxtitem(&ni, (s_char *)&item)) {
109 if (type == EF_SHIP) {
110 if (item.ship.shp_own != player->cnum) {
113 if (item.ship.shp_uid != fuelled_ship)
115 natp = getnatp(player->cnum);
116 rel = getrel(natp, item.ship.shp_own);
120 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
122 if (!item.ship.shp_own)
125 if ((sect.sct_type != SCT_HARBR)
126 && (sect.sct_type != SCT_WATER)
127 && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY
130 pr("Sector %s is not a harbor, bridge span, or sea.\n",
131 xyas(item.ship.shp_x, item.ship.shp_y,
136 mp = &mchr[(int)item.ship.shp_type];
139 if (sect.sct_type == SCT_HARBR
140 || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)) {
142 oil_amt = sect.sct_item[I_OIL];
143 pet_amt = sect.sct_item[I_PETROL];
144 if ((oil_amt + pet_amt) == 0)
147 if (sect.sct_effic < 2) {
148 pr("The harbor at %s is not 2%% efficient yet.\n",
149 xyas(item.ship.shp_x,
150 item.ship.shp_y, player->cnum));
153 if ((sect.sct_own != player->cnum) && sect.sct_own)
157 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
158 pr("%s does not use fuel!\n", prship(&item.ship));
163 ship_fuel = item.ship.shp_fuel;
164 oil_amt = sect.sct_item[I_OIL];
165 pet_amt = sect.sct_item[I_PETROL];
166 max_amt = mp->m_fuelc - ship_fuel;
169 pr("%s already has a full fuel load.\n",
173 tot_fuel = (oil_amt * 50 + pet_amt * 5);
175 pr("No fuel in the harbor at %s!\n",
176 xyas(sect.sct_x, sect.sct_y, player->cnum));
179 move_amt = min(tot_fuel, fuel_amt);
180 move_amt = min(move_amt, max_amt);
185 item.ship.shp_fuel += move_amt;
188 if ((pet_amt * 5) >= move_amt) {
189 extra = ((float)move_amt / 5.0) - (move_amt / 5);
191 sect.sct_item[I_PETROL]
192 = max((pet_amt - move_amt / 5) - 1, 0);
194 sect.sct_item[I_PETROL]
195 = max((pet_amt - move_amt / 5), 0);
197 sect.sct_item[I_PETROL] = 0;
198 move_amt -= pet_amt * 5;
199 extra = ((float)move_amt / 50.0) - (move_amt / 50);
200 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
203 = max((oil_amt - move_amt / 50) - 1, 0);
206 = max((oil_amt - move_amt / 50), 0);
210 if (sect.sct_pstage == PLG_INFECT
211 && item.ship.shp_pstage == PLG_HEALTHY)
212 item.ship.shp_pstage = PLG_EXPOSED;
215 putship(item.ship.shp_uid, &item.ship);
216 } else { /* not in a harbor */
217 if (!player->argp[4])
218 pr("%s is not in a supplied, efficient harbor\n",
220 if (!snxtitem (&tender, EF_SHIP,
221 getstarg(player->argp[4], "Oiler? ", buf)))
224 if (!check_ship_ok(&item.ship))
227 if (!nxtitem(&tender, (s_char *)&item2))
230 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
231 pr("%s is not an oiler!\n", prship(&item2.ship));
234 if (item2.ship.shp_own != player->cnum) {
235 pr("You don't own that oiler!\n");
239 if ((item2.ship.shp_x != item.ship.shp_x) ||
240 (item2.ship.shp_y != item.ship.shp_y)) {
241 pr("Not in the same sector!\n");
244 ship_fuel = item.ship.shp_fuel;
245 oil_amt = item2.ship.shp_item[I_OIL];
246 pet_amt = item2.ship.shp_item[I_PETROL];
247 max_amt = mp->m_fuelc - ship_fuel;
250 pr("%s already has a full fuel load.\n",
254 tot_fuel = oil_amt * 50 + pet_amt * 5;
255 move_amt = min(tot_fuel, fuel_amt);
256 move_amt = min(move_amt, max_amt);
261 item.ship.shp_fuel += move_amt;
264 if ((pet_amt * 5) >= move_amt) {
265 extra = ((float)move_amt / 5.0) - (move_amt / 5);
267 item2.ship.shp_item[I_PETROL]
268 = max((pet_amt - move_amt / 5) - 1, 0);
270 item2.ship.shp_item[I_PETROL]
271 = max((pet_amt - move_amt / 5), 0);
273 item2.ship.shp_item[I_PETROL] = 0;
274 move_amt -= pet_amt * 5;
275 extra = ((float)move_amt / 50.0) - (move_amt / 50);
276 item2.ship.shp_item[I_OIL]
277 = max(oil_amt - (move_amt / 50), 0);
279 item2.ship.shp_item[I_OIL]
280 = max((oil_amt - move_amt / 50) - 1, 0);
282 item2.ship.shp_item[I_OIL]
283 = max((oil_amt - move_amt / 50), 0);
287 if (item2.ship.shp_pstage == PLG_INFECT
288 && item.ship.shp_pstage == PLG_HEALTHY)
289 item.ship.shp_pstage = PLG_EXPOSED;
291 putship(item.ship.shp_uid, &item.ship);
292 /* quick hack -KHS */
293 if (item.ship.shp_uid == item2.ship.shp_uid)
294 item2.ship.shp_fuel = item.ship.shp_fuel;
295 putship(item2.ship.shp_uid, &item2.ship);
297 pr("%s", prship(&item.ship));
299 if (item.land.lnd_own != player->cnum)
302 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
308 lcp = &lchr[(int)item.land.lnd_type];
311 oil_amt = sect.sct_item[I_OIL];
312 pet_amt = sect.sct_item[I_PETROL];
314 if ((oil_amt + pet_amt) == 0)
317 if ((item.land.lnd_fuelu == 0)
318 && (item.land.lnd_own == player->cnum)) {
319 pr("%s does not use fuel!\n", prland(&item.land));
324 land_fuel = item.land.lnd_fuel;
325 oil_amt = sect.sct_item[I_OIL];
326 pet_amt = sect.sct_item[I_PETROL];
327 max_amt = item.land.lnd_fuelc - land_fuel;
330 pr("%s already has a full fuel load.\n",
334 tot_fuel = (oil_amt * 50 + pet_amt * 5);
336 pr("No fuel in the sector at %s!\n",
337 xyas(sect.sct_x, sect.sct_y, player->cnum));
340 move_amt = min(tot_fuel, fuel_amt);
341 move_amt = min(move_amt, max_amt);
346 item.land.lnd_fuel += move_amt;
349 if ((pet_amt * 5) >= move_amt) {
350 extra = ((float)move_amt / 5.0) - (move_amt / 5);
352 sect.sct_item[I_PETROL]
353 = max((pet_amt - move_amt / 5) - 1, 0);
355 sect.sct_item[I_PETROL]
356 = max((pet_amt - move_amt / 5), 0);
358 sect.sct_item[I_PETROL] = 0;
359 move_amt -= pet_amt * 5;
360 extra = ((float)move_amt / 50.0) - (move_amt / 50);
361 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
364 = max((oil_amt - move_amt / 50) - 1, 0);
367 = max((oil_amt - move_amt / 50), 0);
371 if (sect.sct_pstage == PLG_INFECT
372 && item.land.lnd_pstage == PLG_HEALTHY)
373 item.land.lnd_pstage = PLG_EXPOSED;
376 putland(item.land.lnd_uid, &item.land);
377 } else { /* not in a sector */
378 if (!player->argp[4])
379 pr("%s is not in a supplied sector\n",
381 if (!snxtitem(<ender, EF_LAND,
382 getstarg(player->argp[4], "Supply unit? ",
386 if (!check_land_ok(&item.land))
389 if (!nxtitem(<ender, (s_char *)&item2))
392 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
393 pr("%s is not a supply unit!\n", prland(&item2.land));
396 if (item2.land.lnd_own != player->cnum) {
397 pr("You don't own that unit!\n");
401 if ((item2.land.lnd_x != item.land.lnd_x) ||
402 (item2.land.lnd_y != item.land.lnd_y)) {
403 pr("Not in the same sector!\n");
406 land_fuel = item.land.lnd_fuel;
407 oil_amt = item2.land.lnd_item[I_OIL];
408 pet_amt = item2.land.lnd_item[I_PETROL];
409 max_amt = item.land.lnd_fuelc - land_fuel;
412 pr("%s already has a full fuel load.\n",
416 tot_fuel = oil_amt * 50 + pet_amt * 5;
417 move_amt = min(tot_fuel, fuel_amt);
418 move_amt = min(move_amt, max_amt);
423 item.land.lnd_fuel += move_amt;
426 if ((pet_amt * 5) >= move_amt) {
427 extra = ((float)move_amt / 5.0) - (move_amt / 5);
429 item2.land.lnd_item[I_PETROL]
430 = max((pet_amt - move_amt / 5) - 1, 0);
432 item2.land.lnd_item[I_PETROL]
433 = max((pet_amt - move_amt / 5), 0);
435 item2.land.lnd_item[I_PETROL] = 0;
436 move_amt -= pet_amt * 5;
437 extra = ((float)move_amt / 50.0) - (move_amt / 50);
438 item2.land.lnd_item[I_OIL]
439 = max(oil_amt - move_amt / 50, 0);
441 item2.land.lnd_item[I_OIL]
442 = max((oil_amt - move_amt / 50) - 1, 0);
444 item2.land.lnd_item[I_OIL]
445 = max((oil_amt - move_amt / 50), 0);
449 if (item2.land.lnd_pstage == PLG_INFECT
450 && item.land.lnd_pstage == PLG_HEALTHY)
451 item.land.lnd_pstage = PLG_EXPOSED;
453 putland(item.land.lnd_uid, &item.land);
454 /* quick hack -KHS */
455 if (item2.land.lnd_uid == item.land.lnd_uid)
456 item2.land.lnd_fuel = item.land.lnd_fuel;
457 putland(item2.land.lnd_uid, &item2.land);
459 pr("%s", prland(&item.land));
462 pr(" takes on %d fuel in %s\n",
464 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
465 if (player->cnum != item.ship.shp_own)
466 wu(0, item.ship.shp_own,
467 "%s takes on %d fuel in %s courtesy of %s\n",
470 xyas(item.ship.shp_x, item.ship.shp_y,
471 item.ship.shp_own), cname(player->cnum));