2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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:
57 static int shp_or_lnd[] = { EF_SHIP, EF_LAND, EF_BAD };
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)
84 type = ef_byname_from(p, shp_or_lnd);
86 pr("Ships or land units only! (s, l)\n");
89 sprintf(prompt, "%s(s)? ", ef_nameof(type));
90 p = getstarg(player->argp[2], prompt, buf);
91 if (!snxtitem(&ni, type, p))
94 fuelled_ship = atoi(p);
95 p = getstarg(player->argp[3], "Amount: ", buf);
96 if (p == 0 || *p == 0)
100 pr("Fuel amount must be positive!\n");
104 while (nxtitem(&ni, &item)) {
106 if (type == EF_SHIP) {
107 if (item.ship.shp_own != player->cnum) {
110 if (item.ship.shp_uid != fuelled_ship)
112 natp = getnatp(player->cnum);
113 rel = getrel(natp, item.ship.shp_own);
117 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
119 if (!item.ship.shp_own)
122 if ((sect.sct_type != SCT_HARBR)
123 && (sect.sct_type != SCT_WATER)
124 && (sect.sct_type != SCT_BSPAN)
125 && (!IS_BIG_CITY(sect.sct_type))) {
126 pr("Sector %s is not a harbor, bridge span, or sea.\n",
127 xyas(item.ship.shp_x, item.ship.shp_y,
132 mp = &mchr[(int)item.ship.shp_type];
135 if (sect.sct_type == SCT_HARBR
136 || IS_BIG_CITY(sect.sct_type)) {
138 oil_amt = sect.sct_item[I_OIL];
139 pet_amt = sect.sct_item[I_PETROL];
140 if ((oil_amt + pet_amt) == 0)
143 if (sect.sct_effic < 2) {
144 pr("The harbor at %s is not 2%% efficient yet.\n",
145 xyas(item.ship.shp_x,
146 item.ship.shp_y, player->cnum));
149 if ((sect.sct_own != player->cnum) && sect.sct_own)
153 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
154 pr("%s does not use fuel!\n", prship(&item.ship));
159 ship_fuel = item.ship.shp_fuel;
160 oil_amt = sect.sct_item[I_OIL];
161 pet_amt = sect.sct_item[I_PETROL];
162 max_amt = mp->m_fuelc - ship_fuel;
165 pr("%s already has a full fuel load.\n",
169 tot_fuel = (oil_amt * 50 + pet_amt * 5);
171 pr("No fuel in the harbor at %s!\n",
172 xyas(sect.sct_x, sect.sct_y, player->cnum));
175 move_amt = min(tot_fuel, fuel_amt);
176 move_amt = min(move_amt, max_amt);
181 item.ship.shp_fuel += move_amt;
184 if ((pet_amt * 5) >= move_amt) {
185 extra = ((float)move_amt / 5.0) - (move_amt / 5);
187 sect.sct_item[I_PETROL]
188 = max((pet_amt - move_amt / 5) - 1, 0);
190 sect.sct_item[I_PETROL]
191 = max((pet_amt - move_amt / 5), 0);
193 sect.sct_item[I_PETROL] = 0;
194 move_amt -= pet_amt * 5;
195 extra = ((float)move_amt / 50.0) - (move_amt / 50);
196 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
199 = max((oil_amt - move_amt / 50) - 1, 0);
202 = max((oil_amt - move_amt / 50), 0);
206 if (sect.sct_pstage == PLG_INFECT
207 && item.ship.shp_pstage == PLG_HEALTHY)
208 item.ship.shp_pstage = PLG_EXPOSED;
211 putship(item.ship.shp_uid, &item.ship);
212 } else { /* not in a harbor */
213 if (!player->argp[4])
214 pr("%s is not in a supplied, efficient harbor\n",
216 if (!snxtitem (&tender, EF_SHIP,
217 getstarg(player->argp[4], "Oiler? ", buf)))
220 if (!check_ship_ok(&item.ship))
223 if (!nxtitem(&tender, &item2))
226 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
227 pr("%s is not an oiler!\n", prship(&item2.ship));
230 if (item2.ship.shp_own != player->cnum) {
231 pr("You don't own that oiler!\n");
235 if ((item2.ship.shp_x != item.ship.shp_x) ||
236 (item2.ship.shp_y != item.ship.shp_y)) {
237 pr("Not in the same sector!\n");
240 ship_fuel = item.ship.shp_fuel;
241 oil_amt = item2.ship.shp_item[I_OIL];
242 pet_amt = item2.ship.shp_item[I_PETROL];
243 max_amt = mp->m_fuelc - ship_fuel;
246 pr("%s already has a full fuel load.\n",
250 tot_fuel = oil_amt * 50 + pet_amt * 5;
251 move_amt = min(tot_fuel, fuel_amt);
252 move_amt = min(move_amt, max_amt);
257 item.ship.shp_fuel += move_amt;
260 if ((pet_amt * 5) >= move_amt) {
261 extra = ((float)move_amt / 5.0) - (move_amt / 5);
263 item2.ship.shp_item[I_PETROL]
264 = max((pet_amt - move_amt / 5) - 1, 0);
266 item2.ship.shp_item[I_PETROL]
267 = max((pet_amt - move_amt / 5), 0);
269 item2.ship.shp_item[I_PETROL] = 0;
270 move_amt -= pet_amt * 5;
271 extra = ((float)move_amt / 50.0) - (move_amt / 50);
272 item2.ship.shp_item[I_OIL]
273 = max(oil_amt - (move_amt / 50), 0);
275 item2.ship.shp_item[I_OIL]
276 = max((oil_amt - move_amt / 50) - 1, 0);
278 item2.ship.shp_item[I_OIL]
279 = max((oil_amt - move_amt / 50), 0);
283 if (item2.ship.shp_pstage == PLG_INFECT
284 && item.ship.shp_pstage == PLG_HEALTHY)
285 item.ship.shp_pstage = PLG_EXPOSED;
287 putship(item.ship.shp_uid, &item.ship);
288 /* quick hack -KHS */
289 if (item.ship.shp_uid == item2.ship.shp_uid)
290 item2.ship.shp_fuel = item.ship.shp_fuel;
291 putship(item2.ship.shp_uid, &item2.ship);
293 pr("%s", prship(&item.ship));
295 if (item.land.lnd_own != player->cnum)
298 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
304 lcp = &lchr[(int)item.land.lnd_type];
307 oil_amt = sect.sct_item[I_OIL];
308 pet_amt = sect.sct_item[I_PETROL];
310 if ((oil_amt + pet_amt) == 0)
313 if ((item.land.lnd_fuelu == 0)
314 && (item.land.lnd_own == player->cnum)) {
315 pr("%s does not use fuel!\n", prland(&item.land));
320 land_fuel = item.land.lnd_fuel;
321 oil_amt = sect.sct_item[I_OIL];
322 pet_amt = sect.sct_item[I_PETROL];
323 max_amt = item.land.lnd_fuelc - land_fuel;
326 pr("%s already has a full fuel load.\n",
330 tot_fuel = (oil_amt * 50 + pet_amt * 5);
332 pr("No fuel in the sector at %s!\n",
333 xyas(sect.sct_x, sect.sct_y, player->cnum));
336 move_amt = min(tot_fuel, fuel_amt);
337 move_amt = min(move_amt, max_amt);
342 item.land.lnd_fuel += move_amt;
345 if ((pet_amt * 5) >= move_amt) {
346 extra = ((float)move_amt / 5.0) - (move_amt / 5);
348 sect.sct_item[I_PETROL]
349 = max((pet_amt - move_amt / 5) - 1, 0);
351 sect.sct_item[I_PETROL]
352 = max((pet_amt - move_amt / 5), 0);
354 sect.sct_item[I_PETROL] = 0;
355 move_amt -= pet_amt * 5;
356 extra = ((float)move_amt / 50.0) - (move_amt / 50);
357 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
360 = max((oil_amt - move_amt / 50) - 1, 0);
363 = max((oil_amt - move_amt / 50), 0);
367 if (sect.sct_pstage == PLG_INFECT
368 && item.land.lnd_pstage == PLG_HEALTHY)
369 item.land.lnd_pstage = PLG_EXPOSED;
372 putland(item.land.lnd_uid, &item.land);
373 } else { /* not in a sector */
374 if (!player->argp[4])
375 pr("%s is not in a supplied sector\n",
377 if (!snxtitem(<ender, EF_LAND,
378 getstarg(player->argp[4], "Supply unit? ",
382 if (!check_land_ok(&item.land))
385 if (!nxtitem(<ender, &item2))
388 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
389 pr("%s is not a supply unit!\n", prland(&item2.land));
392 if (item2.land.lnd_own != player->cnum) {
393 pr("You don't own that unit!\n");
397 if ((item2.land.lnd_x != item.land.lnd_x) ||
398 (item2.land.lnd_y != item.land.lnd_y)) {
399 pr("Not in the same sector!\n");
402 land_fuel = item.land.lnd_fuel;
403 oil_amt = item2.land.lnd_item[I_OIL];
404 pet_amt = item2.land.lnd_item[I_PETROL];
405 max_amt = item.land.lnd_fuelc - land_fuel;
408 pr("%s already has a full fuel load.\n",
412 tot_fuel = oil_amt * 50 + pet_amt * 5;
413 move_amt = min(tot_fuel, fuel_amt);
414 move_amt = min(move_amt, max_amt);
419 item.land.lnd_fuel += move_amt;
422 if ((pet_amt * 5) >= move_amt) {
423 extra = ((float)move_amt / 5.0) - (move_amt / 5);
425 item2.land.lnd_item[I_PETROL]
426 = max((pet_amt - move_amt / 5) - 1, 0);
428 item2.land.lnd_item[I_PETROL]
429 = max((pet_amt - move_amt / 5), 0);
431 item2.land.lnd_item[I_PETROL] = 0;
432 move_amt -= pet_amt * 5;
433 extra = ((float)move_amt / 50.0) - (move_amt / 50);
434 item2.land.lnd_item[I_OIL]
435 = max(oil_amt - move_amt / 50, 0);
437 item2.land.lnd_item[I_OIL]
438 = max((oil_amt - move_amt / 50) - 1, 0);
440 item2.land.lnd_item[I_OIL]
441 = max((oil_amt - move_amt / 50), 0);
445 if (item2.land.lnd_pstage == PLG_INFECT
446 && item.land.lnd_pstage == PLG_HEALTHY)
447 item.land.lnd_pstage = PLG_EXPOSED;
449 putland(item.land.lnd_uid, &item.land);
450 /* quick hack -KHS */
451 if (item2.land.lnd_uid == item.land.lnd_uid)
452 item2.land.lnd_fuel = item.land.lnd_fuel;
453 putland(item2.land.lnd_uid, &item2.land);
455 pr("%s", prland(&item.land));
458 pr(" takes on %d fuel in %s\n",
460 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
461 if (player->cnum != item.ship.shp_own)
462 wu(0, item.ship.shp_own,
463 "%s takes on %d fuel in %s courtesy of %s\n",
466 xyas(item.ship.shp_x, item.ship.shp_y,
467 item.ship.shp_own), cname(player->cnum));