2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * fuel.c: fuel ships/land units
30 * Known contributors to this file:
45 static int shp_or_lnd[] = { EF_SHIP, EF_LAND, EF_BAD };
47 union empobj_storage item, item2;
53 int land_fuel, ship_fuel;
54 int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt;
60 int fuelled_ship = -1;
61 struct nstr_item tender, ltender;
66 pr("Option 'FUEL' not enabled\n");
70 getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0)
72 type = ef_byname_from(p, shp_or_lnd);
74 pr("Ships or land units only! (s, l)\n");
77 sprintf(prompt, "%s(s)? ", ef_nameof(type));
78 p = getstarg(player->argp[2], prompt, buf);
79 if (!snxtitem(&ni, type, p))
82 fuelled_ship = atoi(p);
83 p = getstarg(player->argp[3], "Amount: ", buf);
84 if (p == 0 || *p == 0)
88 pr("Fuel amount must be positive!\n");
92 while (nxtitem(&ni, &item)) {
94 if (type == EF_SHIP) {
95 if (item.ship.shp_own != player->cnum) {
98 if (item.ship.shp_uid != fuelled_ship)
100 natp = getnatp(player->cnum);
101 rel = getrel(natp, item.ship.shp_own);
105 if (!getsect(item.ship.shp_x, item.ship.shp_y, §))
107 if (!item.ship.shp_own)
110 if (shp_check_nav(§, &item.ship) == CN_LANDLOCKED) {
111 pr("%s is landlocked and cannot be fueled.\n",
116 mp = &mchr[(int)item.ship.shp_type];
119 if (sect_has_dock(§)) {
121 oil_amt = sect.sct_item[I_OIL];
122 pet_amt = sect.sct_item[I_PETROL];
123 if ((oil_amt + pet_amt) == 0)
126 if (sect.sct_effic < 2) {
127 pr("The harbor at %s is not 2%% efficient yet.\n",
128 xyas(item.ship.shp_x, item.ship.shp_y,
132 if ((sect.sct_own != player->cnum) && sect.sct_own)
136 if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) {
137 pr("%s does not use fuel!\n", prship(&item.ship));
142 ship_fuel = item.ship.shp_fuel;
143 oil_amt = sect.sct_item[I_OIL];
144 pet_amt = sect.sct_item[I_PETROL];
145 max_amt = mp->m_fuelc - ship_fuel;
148 pr("%s already has a full fuel load.\n",
152 tot_fuel = (oil_amt * 50 + pet_amt * 5);
154 pr("No fuel in the harbor at %s!\n",
155 xyas(sect.sct_x, sect.sct_y, player->cnum));
158 move_amt = MIN(tot_fuel, fuel_amt);
159 move_amt = MIN(move_amt, max_amt);
164 item.ship.shp_fuel += move_amt;
167 if ((pet_amt * 5) >= move_amt) {
168 extra = move_amt / 5.0 - move_amt / 5;
170 sect.sct_item[I_PETROL]
171 = MAX((pet_amt - move_amt / 5) - 1, 0);
173 sect.sct_item[I_PETROL]
174 = MAX((pet_amt - move_amt / 5), 0);
176 sect.sct_item[I_PETROL] = 0;
177 move_amt -= pet_amt * 5;
178 extra = move_amt / 50.0 - move_amt / 50;
179 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
182 = MAX((oil_amt - move_amt / 50) - 1, 0);
185 = MAX((oil_amt - move_amt / 50), 0);
189 if (sect.sct_pstage == PLG_INFECT
190 && item.ship.shp_pstage == PLG_HEALTHY)
191 item.ship.shp_pstage = PLG_EXPOSED;
194 putship(item.ship.shp_uid, &item.ship);
195 } else { /* not in a harbor */
196 if (!player->argp[4])
197 pr("%s is not in a supplied, efficient harbor\n",
199 if (!snxtitem(&tender, EF_SHIP,
200 getstarg(player->argp[4], "Oiler? ", buf)))
203 if (!check_ship_ok(&item.ship))
206 if (!nxtitem(&tender, &item2))
209 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) {
210 pr("%s is not an oiler!\n", prship(&item2.ship));
213 if (item2.ship.shp_own != player->cnum) {
214 pr("You don't own that oiler!\n");
218 if ((item2.ship.shp_x != item.ship.shp_x) ||
219 (item2.ship.shp_y != item.ship.shp_y)) {
220 pr("Not in the same sector!\n");
223 ship_fuel = item.ship.shp_fuel;
224 oil_amt = item2.ship.shp_item[I_OIL];
225 pet_amt = item2.ship.shp_item[I_PETROL];
226 max_amt = mp->m_fuelc - ship_fuel;
229 pr("%s already has a full fuel load.\n",
233 tot_fuel = oil_amt * 50 + pet_amt * 5;
234 move_amt = MIN(tot_fuel, fuel_amt);
235 move_amt = MIN(move_amt, max_amt);
240 item.ship.shp_fuel += move_amt;
243 if ((pet_amt * 5) >= move_amt) {
244 extra = move_amt / 5.0 - move_amt / 5;
246 item2.ship.shp_item[I_PETROL]
247 = MAX((pet_amt - move_amt / 5) - 1, 0);
249 item2.ship.shp_item[I_PETROL]
250 = MAX((pet_amt - move_amt / 5), 0);
252 item2.ship.shp_item[I_PETROL] = 0;
253 move_amt -= pet_amt * 5;
254 extra = move_amt / 50.0 - move_amt / 50;
255 item2.ship.shp_item[I_OIL]
256 = MAX(oil_amt - (move_amt / 50), 0);
258 item2.ship.shp_item[I_OIL]
259 = MAX((oil_amt - move_amt / 50) - 1, 0);
261 item2.ship.shp_item[I_OIL]
262 = MAX((oil_amt - move_amt / 50), 0);
266 if (item2.ship.shp_pstage == PLG_INFECT
267 && item.ship.shp_pstage == PLG_HEALTHY)
268 item.ship.shp_pstage = PLG_EXPOSED;
270 putship(item.ship.shp_uid, &item.ship);
271 /* quick hack -KHS */
272 if (item.ship.shp_uid == item2.ship.shp_uid)
273 item2.ship.shp_fuel = item.ship.shp_fuel;
274 putship(item2.ship.shp_uid, &item2.ship);
276 pr("%s", prship(&item.ship));
278 if (item.land.lnd_own != player->cnum)
281 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
287 lcp = &lchr[(int)item.land.lnd_type];
290 oil_amt = sect.sct_item[I_OIL];
291 pet_amt = sect.sct_item[I_PETROL];
293 if ((oil_amt + pet_amt) == 0)
296 if ((item.land.lnd_fuelu == 0)
297 && (item.land.lnd_own == player->cnum)) {
298 pr("%s does not use fuel!\n", prland(&item.land));
303 land_fuel = item.land.lnd_fuel;
304 oil_amt = sect.sct_item[I_OIL];
305 pet_amt = sect.sct_item[I_PETROL];
306 max_amt = item.land.lnd_fuelc - land_fuel;
309 pr("%s already has a full fuel load.\n",
313 tot_fuel = (oil_amt * 50 + pet_amt * 5);
315 pr("No fuel in the sector at %s!\n",
316 xyas(sect.sct_x, sect.sct_y, player->cnum));
319 move_amt = MIN(tot_fuel, fuel_amt);
320 move_amt = MIN(move_amt, max_amt);
325 item.land.lnd_fuel += move_amt;
328 if ((pet_amt * 5) >= move_amt) {
329 extra = move_amt / 5.0 - move_amt / 5;
331 sect.sct_item[I_PETROL]
332 = MAX((pet_amt - move_amt / 5) - 1, 0);
334 sect.sct_item[I_PETROL]
335 = MAX((pet_amt - move_amt / 5), 0);
337 sect.sct_item[I_PETROL] = 0;
338 move_amt -= pet_amt * 5;
339 extra = move_amt / 50.0 - move_amt / 50;
340 sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
343 = MAX((oil_amt - move_amt / 50) - 1, 0);
346 = MAX((oil_amt - move_amt / 50), 0);
350 if (sect.sct_pstage == PLG_INFECT
351 && item.land.lnd_pstage == PLG_HEALTHY)
352 item.land.lnd_pstage = PLG_EXPOSED;
355 putland(item.land.lnd_uid, &item.land);
356 } else { /* not in a sector */
357 if (!player->argp[4])
358 pr("%s is not in a supplied sector\n",
360 if (!snxtitem(<ender, EF_LAND,
361 getstarg(player->argp[4], "Supply unit? ",
365 if (!check_land_ok(&item.land))
368 if (!nxtitem(<ender, &item2))
371 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) {
372 pr("%s is not a supply unit!\n", prland(&item2.land));
375 if (item2.land.lnd_own != player->cnum) {
376 pr("You don't own that unit!\n");
380 if ((item2.land.lnd_x != item.land.lnd_x) ||
381 (item2.land.lnd_y != item.land.lnd_y)) {
382 pr("Not in the same sector!\n");
385 land_fuel = item.land.lnd_fuel;
386 oil_amt = item2.land.lnd_item[I_OIL];
387 pet_amt = item2.land.lnd_item[I_PETROL];
388 max_amt = item.land.lnd_fuelc - land_fuel;
391 pr("%s already has a full fuel load.\n",
395 tot_fuel = oil_amt * 50 + pet_amt * 5;
396 move_amt = MIN(tot_fuel, fuel_amt);
397 move_amt = MIN(move_amt, max_amt);
402 item.land.lnd_fuel += move_amt;
405 if ((pet_amt * 5) >= move_amt) {
406 extra = move_amt / 5.0 - move_amt / 5;
408 item2.land.lnd_item[I_PETROL]
409 = MAX((pet_amt - move_amt / 5) - 1, 0);
411 item2.land.lnd_item[I_PETROL]
412 = MAX((pet_amt - move_amt / 5), 0);
414 item2.land.lnd_item[I_PETROL] = 0;
415 move_amt -= pet_amt * 5;
416 extra = move_amt / 50.0 - move_amt / 50;
417 item2.land.lnd_item[I_OIL]
418 = MAX(oil_amt - move_amt / 50, 0);
420 item2.land.lnd_item[I_OIL]
421 = MAX((oil_amt - move_amt / 50) - 1, 0);
423 item2.land.lnd_item[I_OIL]
424 = MAX((oil_amt - move_amt / 50), 0);
428 if (item2.land.lnd_pstage == PLG_INFECT
429 && item.land.lnd_pstage == PLG_HEALTHY)
430 item.land.lnd_pstage = PLG_EXPOSED;
432 putland(item.land.lnd_uid, &item.land);
433 /* quick hack -KHS */
434 if (item2.land.lnd_uid == item.land.lnd_uid)
435 item2.land.lnd_fuel = item.land.lnd_fuel;
436 putland(item2.land.lnd_uid, &item2.land);
438 pr("%s", prland(&item.land));
441 pr(" takes on %d fuel in %s\n",
443 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
444 if (player->cnum != item.ship.shp_own)
445 wu(0, item.ship.shp_own,
446 "%s takes on %d fuel in %s courtesy of %s\n",
449 xyas(item.ship.shp_x, item.ship.shp_y,
450 item.ship.shp_own), cname(player->cnum));