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 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 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 ((sect.sct_type != SCT_HARBR)
125 && (sect.sct_type != SCT_WATER)
126 && (sect.sct_type != SCT_BSPAN)
127 && (!IS_BIG_CITY(sect.sct_type))) {
128 pr("Sector %s is not a harbor, bridge span, or sea.\n",
129 xyas(item.ship.shp_x, item.ship.shp_y,
134 mp = &mchr[(int)item.ship.shp_type];
137 if (sect_has_dock(§)) {
139 oil_amt = sect.sct_item[I_OIL];
140 pet_amt = sect.sct_item[I_PETROL];
141 if ((oil_amt + pet_amt) == 0)
144 if (sect.sct_effic < 2) {
145 pr("The harbor at %s is not 2%% efficient yet.\n",
146 xyas(item.ship.shp_x,
147 item.ship.shp_y, player->cnum));
150 if ((sect.sct_own != player->cnum) && sect.sct_own)
154 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
155 pr("%s does not use fuel!\n", prship(&item.ship));
160 ship_fuel = item.ship.shp_fuel;
161 oil_amt = sect.sct_item[I_OIL];
162 pet_amt = sect.sct_item[I_PETROL];
163 max_amt = mp->m_fuelc - ship_fuel;
166 pr("%s already has a full fuel load.\n",
170 tot_fuel = (oil_amt * 50 + pet_amt * 5);
172 pr("No fuel in the harbor at %s!\n",
173 xyas(sect.sct_x, sect.sct_y, player->cnum));
176 move_amt = MIN(tot_fuel, fuel_amt);
177 move_amt = MIN(move_amt, max_amt);
182 item.ship.shp_fuel += move_amt;
185 if ((pet_amt * 5) >= move_amt) {
186 extra = ((float)move_amt / 5.0) - (move_amt / 5);
188 sect.sct_item[I_PETROL]
189 = MAX((pet_amt - move_amt / 5) - 1, 0);
191 sect.sct_item[I_PETROL]
192 = MAX((pet_amt - move_amt / 5), 0);
194 sect.sct_item[I_PETROL] = 0;
195 move_amt -= pet_amt * 5;
196 extra = ((float)move_amt / 50.0) - (move_amt / 50);
197 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
200 = MAX((oil_amt - move_amt / 50) - 1, 0);
203 = MAX((oil_amt - move_amt / 50), 0);
207 if (sect.sct_pstage == PLG_INFECT
208 && item.ship.shp_pstage == PLG_HEALTHY)
209 item.ship.shp_pstage = PLG_EXPOSED;
212 putship(item.ship.shp_uid, &item.ship);
213 } else { /* not in a harbor */
214 if (!player->argp[4])
215 pr("%s is not in a supplied, efficient harbor\n",
217 if (!snxtitem (&tender, EF_SHIP,
218 getstarg(player->argp[4], "Oiler? ", buf)))
221 if (!check_ship_ok(&item.ship))
224 if (!nxtitem(&tender, &item2))
227 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
228 pr("%s is not an oiler!\n", prship(&item2.ship));
231 if (item2.ship.shp_own != player->cnum) {
232 pr("You don't own that oiler!\n");
236 if ((item2.ship.shp_x != item.ship.shp_x) ||
237 (item2.ship.shp_y != item.ship.shp_y)) {
238 pr("Not in the same sector!\n");
241 ship_fuel = item.ship.shp_fuel;
242 oil_amt = item2.ship.shp_item[I_OIL];
243 pet_amt = item2.ship.shp_item[I_PETROL];
244 max_amt = mp->m_fuelc - ship_fuel;
247 pr("%s already has a full fuel load.\n",
251 tot_fuel = oil_amt * 50 + pet_amt * 5;
252 move_amt = MIN(tot_fuel, fuel_amt);
253 move_amt = MIN(move_amt, max_amt);
258 item.ship.shp_fuel += move_amt;
261 if ((pet_amt * 5) >= move_amt) {
262 extra = ((float)move_amt / 5.0) - (move_amt / 5);
264 item2.ship.shp_item[I_PETROL]
265 = MAX((pet_amt - move_amt / 5) - 1, 0);
267 item2.ship.shp_item[I_PETROL]
268 = MAX((pet_amt - move_amt / 5), 0);
270 item2.ship.shp_item[I_PETROL] = 0;
271 move_amt -= pet_amt * 5;
272 extra = ((float)move_amt / 50.0) - (move_amt / 50);
273 item2.ship.shp_item[I_OIL]
274 = MAX(oil_amt - (move_amt / 50), 0);
276 item2.ship.shp_item[I_OIL]
277 = MAX((oil_amt - move_amt / 50) - 1, 0);
279 item2.ship.shp_item[I_OIL]
280 = MAX((oil_amt - move_amt / 50), 0);
284 if (item2.ship.shp_pstage == PLG_INFECT
285 && item.ship.shp_pstage == PLG_HEALTHY)
286 item.ship.shp_pstage = PLG_EXPOSED;
288 putship(item.ship.shp_uid, &item.ship);
289 /* quick hack -KHS */
290 if (item.ship.shp_uid == item2.ship.shp_uid)
291 item2.ship.shp_fuel = item.ship.shp_fuel;
292 putship(item2.ship.shp_uid, &item2.ship);
294 pr("%s", prship(&item.ship));
296 if (item.land.lnd_own != player->cnum)
299 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
305 lcp = &lchr[(int)item.land.lnd_type];
308 oil_amt = sect.sct_item[I_OIL];
309 pet_amt = sect.sct_item[I_PETROL];
311 if ((oil_amt + pet_amt) == 0)
314 if ((item.land.lnd_fuelu == 0)
315 && (item.land.lnd_own == player->cnum)) {
316 pr("%s does not use fuel!\n", prland(&item.land));
321 land_fuel = item.land.lnd_fuel;
322 oil_amt = sect.sct_item[I_OIL];
323 pet_amt = sect.sct_item[I_PETROL];
324 max_amt = item.land.lnd_fuelc - land_fuel;
327 pr("%s already has a full fuel load.\n",
331 tot_fuel = (oil_amt * 50 + pet_amt * 5);
333 pr("No fuel in the sector at %s!\n",
334 xyas(sect.sct_x, sect.sct_y, player->cnum));
337 move_amt = MIN(tot_fuel, fuel_amt);
338 move_amt = MIN(move_amt, max_amt);
343 item.land.lnd_fuel += move_amt;
346 if ((pet_amt * 5) >= move_amt) {
347 extra = ((float)move_amt / 5.0) - (move_amt / 5);
349 sect.sct_item[I_PETROL]
350 = MAX((pet_amt - move_amt / 5) - 1, 0);
352 sect.sct_item[I_PETROL]
353 = MAX((pet_amt - move_amt / 5), 0);
355 sect.sct_item[I_PETROL] = 0;
356 move_amt -= pet_amt * 5;
357 extra = ((float)move_amt / 50.0) - (move_amt / 50);
358 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
361 = MAX((oil_amt - move_amt / 50) - 1, 0);
364 = MAX((oil_amt - move_amt / 50), 0);
368 if (sect.sct_pstage == PLG_INFECT
369 && item.land.lnd_pstage == PLG_HEALTHY)
370 item.land.lnd_pstage = PLG_EXPOSED;
373 putland(item.land.lnd_uid, &item.land);
374 } else { /* not in a sector */
375 if (!player->argp[4])
376 pr("%s is not in a supplied sector\n",
378 if (!snxtitem(<ender, EF_LAND,
379 getstarg(player->argp[4], "Supply unit? ",
383 if (!check_land_ok(&item.land))
386 if (!nxtitem(<ender, &item2))
389 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
390 pr("%s is not a supply unit!\n", prland(&item2.land));
393 if (item2.land.lnd_own != player->cnum) {
394 pr("You don't own that unit!\n");
398 if ((item2.land.lnd_x != item.land.lnd_x) ||
399 (item2.land.lnd_y != item.land.lnd_y)) {
400 pr("Not in the same sector!\n");
403 land_fuel = item.land.lnd_fuel;
404 oil_amt = item2.land.lnd_item[I_OIL];
405 pet_amt = item2.land.lnd_item[I_PETROL];
406 max_amt = item.land.lnd_fuelc - land_fuel;
409 pr("%s already has a full fuel load.\n",
413 tot_fuel = oil_amt * 50 + pet_amt * 5;
414 move_amt = MIN(tot_fuel, fuel_amt);
415 move_amt = MIN(move_amt, max_amt);
420 item.land.lnd_fuel += move_amt;
423 if ((pet_amt * 5) >= move_amt) {
424 extra = ((float)move_amt / 5.0) - (move_amt / 5);
426 item2.land.lnd_item[I_PETROL]
427 = MAX((pet_amt - move_amt / 5) - 1, 0);
429 item2.land.lnd_item[I_PETROL]
430 = MAX((pet_amt - move_amt / 5), 0);
432 item2.land.lnd_item[I_PETROL] = 0;
433 move_amt -= pet_amt * 5;
434 extra = ((float)move_amt / 50.0) - (move_amt / 50);
435 item2.land.lnd_item[I_OIL]
436 = MAX(oil_amt - move_amt / 50, 0);
438 item2.land.lnd_item[I_OIL]
439 = MAX((oil_amt - move_amt / 50) - 1, 0);
441 item2.land.lnd_item[I_OIL]
442 = MAX((oil_amt - move_amt / 50), 0);
446 if (item2.land.lnd_pstage == PLG_INFECT
447 && item.land.lnd_pstage == PLG_HEALTHY)
448 item.land.lnd_pstage = PLG_EXPOSED;
450 putland(item.land.lnd_uid, &item.land);
451 /* quick hack -KHS */
452 if (item2.land.lnd_uid == item.land.lnd_uid)
453 item2.land.lnd_fuel = item.land.lnd_fuel;
454 putland(item2.land.lnd_uid, &item2.land);
456 pr("%s", prland(&item.land));
459 pr(" takes on %d fuel in %s\n",
461 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
462 if (player->cnum != item.ship.shp_own)
463 wu(0, item.ship.shp_own,
464 "%s takes on %d fuel in %s courtesy of %s\n",
467 xyas(item.ship.shp_x, item.ship.shp_y,
468 item.ship.shp_own), cname(player->cnum));