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:
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 while (nxtitem(&ni, &item)) {
107 if (type == EF_SHIP) {
108 if (item.ship.shp_own != player->cnum) {
111 if (item.ship.shp_uid != fuelled_ship)
113 natp = getnatp(player->cnum);
114 rel = getrel(natp, item.ship.shp_own);
118 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
120 if (!item.ship.shp_own)
123 if ((sect.sct_type != SCT_HARBR)
124 && (sect.sct_type != SCT_WATER)
125 && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY
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.sct_type == SCT_HARBR
138 || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)) {
140 oil_amt = sect.sct_item[I_OIL];
141 pet_amt = sect.sct_item[I_PETROL];
142 if ((oil_amt + pet_amt) == 0)
145 if (sect.sct_effic < 2) {
146 pr("The harbor at %s is not 2%% efficient yet.\n",
147 xyas(item.ship.shp_x,
148 item.ship.shp_y, player->cnum));
151 if ((sect.sct_own != player->cnum) && sect.sct_own)
155 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
156 pr("%s does not use fuel!\n", prship(&item.ship));
161 ship_fuel = item.ship.shp_fuel;
162 oil_amt = sect.sct_item[I_OIL];
163 pet_amt = sect.sct_item[I_PETROL];
164 max_amt = mp->m_fuelc - ship_fuel;
167 pr("%s already has a full fuel load.\n",
171 tot_fuel = (oil_amt * 50 + pet_amt * 5);
173 pr("No fuel in the harbor at %s!\n",
174 xyas(sect.sct_x, sect.sct_y, player->cnum));
177 move_amt = min(tot_fuel, fuel_amt);
178 move_amt = min(move_amt, max_amt);
183 item.ship.shp_fuel += move_amt;
186 if ((pet_amt * 5) >= move_amt) {
187 extra = ((float)move_amt / 5.0) - (move_amt / 5);
189 sect.sct_item[I_PETROL]
190 = max((pet_amt - move_amt / 5) - 1, 0);
192 sect.sct_item[I_PETROL]
193 = max((pet_amt - move_amt / 5), 0);
195 sect.sct_item[I_PETROL] = 0;
196 move_amt -= pet_amt * 5;
197 extra = ((float)move_amt / 50.0) - (move_amt / 50);
198 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
201 = max((oil_amt - move_amt / 50) - 1, 0);
204 = max((oil_amt - move_amt / 50), 0);
208 if (sect.sct_pstage == PLG_INFECT
209 && item.ship.shp_pstage == PLG_HEALTHY)
210 item.ship.shp_pstage = PLG_EXPOSED;
213 putship(item.ship.shp_uid, &item.ship);
214 } else { /* not in a harbor */
215 if (!player->argp[4])
216 pr("%s is not in a supplied, efficient harbor\n",
218 if (!snxtitem (&tender, EF_SHIP,
219 getstarg(player->argp[4], "Oiler? ", buf)))
222 if (!check_ship_ok(&item.ship))
225 if (!nxtitem(&tender, &item2))
228 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
229 pr("%s is not an oiler!\n", prship(&item2.ship));
232 if (item2.ship.shp_own != player->cnum) {
233 pr("You don't own that oiler!\n");
237 if ((item2.ship.shp_x != item.ship.shp_x) ||
238 (item2.ship.shp_y != item.ship.shp_y)) {
239 pr("Not in the same sector!\n");
242 ship_fuel = item.ship.shp_fuel;
243 oil_amt = item2.ship.shp_item[I_OIL];
244 pet_amt = item2.ship.shp_item[I_PETROL];
245 max_amt = mp->m_fuelc - ship_fuel;
248 pr("%s already has a full fuel load.\n",
252 tot_fuel = oil_amt * 50 + pet_amt * 5;
253 move_amt = min(tot_fuel, fuel_amt);
254 move_amt = min(move_amt, max_amt);
259 item.ship.shp_fuel += move_amt;
262 if ((pet_amt * 5) >= move_amt) {
263 extra = ((float)move_amt / 5.0) - (move_amt / 5);
265 item2.ship.shp_item[I_PETROL]
266 = max((pet_amt - move_amt / 5) - 1, 0);
268 item2.ship.shp_item[I_PETROL]
269 = max((pet_amt - move_amt / 5), 0);
271 item2.ship.shp_item[I_PETROL] = 0;
272 move_amt -= pet_amt * 5;
273 extra = ((float)move_amt / 50.0) - (move_amt / 50);
274 item2.ship.shp_item[I_OIL]
275 = max(oil_amt - (move_amt / 50), 0);
277 item2.ship.shp_item[I_OIL]
278 = max((oil_amt - move_amt / 50) - 1, 0);
280 item2.ship.shp_item[I_OIL]
281 = max((oil_amt - move_amt / 50), 0);
285 if (item2.ship.shp_pstage == PLG_INFECT
286 && item.ship.shp_pstage == PLG_HEALTHY)
287 item.ship.shp_pstage = PLG_EXPOSED;
289 putship(item.ship.shp_uid, &item.ship);
290 /* quick hack -KHS */
291 if (item.ship.shp_uid == item2.ship.shp_uid)
292 item2.ship.shp_fuel = item.ship.shp_fuel;
293 putship(item2.ship.shp_uid, &item2.ship);
295 pr("%s", prship(&item.ship));
297 if (item.land.lnd_own != player->cnum)
300 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
306 lcp = &lchr[(int)item.land.lnd_type];
309 oil_amt = sect.sct_item[I_OIL];
310 pet_amt = sect.sct_item[I_PETROL];
312 if ((oil_amt + pet_amt) == 0)
315 if ((item.land.lnd_fuelu == 0)
316 && (item.land.lnd_own == player->cnum)) {
317 pr("%s does not use fuel!\n", prland(&item.land));
322 land_fuel = item.land.lnd_fuel;
323 oil_amt = sect.sct_item[I_OIL];
324 pet_amt = sect.sct_item[I_PETROL];
325 max_amt = item.land.lnd_fuelc - land_fuel;
328 pr("%s already has a full fuel load.\n",
332 tot_fuel = (oil_amt * 50 + pet_amt * 5);
334 pr("No fuel in the sector at %s!\n",
335 xyas(sect.sct_x, sect.sct_y, player->cnum));
338 move_amt = min(tot_fuel, fuel_amt);
339 move_amt = min(move_amt, max_amt);
344 item.land.lnd_fuel += move_amt;
347 if ((pet_amt * 5) >= move_amt) {
348 extra = ((float)move_amt / 5.0) - (move_amt / 5);
350 sect.sct_item[I_PETROL]
351 = max((pet_amt - move_amt / 5) - 1, 0);
353 sect.sct_item[I_PETROL]
354 = max((pet_amt - move_amt / 5), 0);
356 sect.sct_item[I_PETROL] = 0;
357 move_amt -= pet_amt * 5;
358 extra = ((float)move_amt / 50.0) - (move_amt / 50);
359 sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
362 = max((oil_amt - move_amt / 50) - 1, 0);
365 = max((oil_amt - move_amt / 50), 0);
369 if (sect.sct_pstage == PLG_INFECT
370 && item.land.lnd_pstage == PLG_HEALTHY)
371 item.land.lnd_pstage = PLG_EXPOSED;
374 putland(item.land.lnd_uid, &item.land);
375 } else { /* not in a sector */
376 if (!player->argp[4])
377 pr("%s is not in a supplied sector\n",
379 if (!snxtitem(<ender, EF_LAND,
380 getstarg(player->argp[4], "Supply unit? ",
384 if (!check_land_ok(&item.land))
387 if (!nxtitem(<ender, &item2))
390 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
391 pr("%s is not a supply unit!\n", prland(&item2.land));
394 if (item2.land.lnd_own != player->cnum) {
395 pr("You don't own that unit!\n");
399 if ((item2.land.lnd_x != item.land.lnd_x) ||
400 (item2.land.lnd_y != item.land.lnd_y)) {
401 pr("Not in the same sector!\n");
404 land_fuel = item.land.lnd_fuel;
405 oil_amt = item2.land.lnd_item[I_OIL];
406 pet_amt = item2.land.lnd_item[I_PETROL];
407 max_amt = item.land.lnd_fuelc - land_fuel;
410 pr("%s already has a full fuel load.\n",
414 tot_fuel = oil_amt * 50 + pet_amt * 5;
415 move_amt = min(tot_fuel, fuel_amt);
416 move_amt = min(move_amt, max_amt);
421 item.land.lnd_fuel += move_amt;
424 if ((pet_amt * 5) >= move_amt) {
425 extra = ((float)move_amt / 5.0) - (move_amt / 5);
427 item2.land.lnd_item[I_PETROL]
428 = max((pet_amt - move_amt / 5) - 1, 0);
430 item2.land.lnd_item[I_PETROL]
431 = max((pet_amt - move_amt / 5), 0);
433 item2.land.lnd_item[I_PETROL] = 0;
434 move_amt -= pet_amt * 5;
435 extra = ((float)move_amt / 50.0) - (move_amt / 50);
436 item2.land.lnd_item[I_OIL]
437 = max(oil_amt - move_amt / 50, 0);
439 item2.land.lnd_item[I_OIL]
440 = max((oil_amt - move_amt / 50) - 1, 0);
442 item2.land.lnd_item[I_OIL]
443 = max((oil_amt - move_amt / 50), 0);
447 if (item2.land.lnd_pstage == PLG_INFECT
448 && item.land.lnd_pstage == PLG_HEALTHY)
449 item.land.lnd_pstage = PLG_EXPOSED;
451 putland(item.land.lnd_uid, &item.land);
452 /* quick hack -KHS */
453 if (item2.land.lnd_uid == item.land.lnd_uid)
454 item2.land.lnd_fuel = item.land.lnd_fuel;
455 putland(item2.land.lnd_uid, &item2.land);
457 pr("%s", prland(&item.land));
460 pr(" takes on %d fuel in %s\n",
462 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
463 if (player->cnum != item.ship.shp_own)
464 wu(0, item.ship.shp_own,
465 "%s takes on %d fuel in %s courtesy of %s\n",
468 xyas(item.ship.shp_x, item.ship.shp_y,
469 item.ship.shp_own), cname(player->cnum));