2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 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");
81 if ((p = 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) && (sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)){
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 || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)){
137 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
138 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
139 if ((oil_amt+pet_amt) == 0)
142 if (sect.sct_effic < 2) {
143 pr("The harbor at %s is not 2%% efficient yet.\n",
144 xyas(item.ship.shp_x,
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)); continue;
158 ship_fuel = item.ship.shp_fuel;
159 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
160 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
161 max_amt = mp->m_fuelc-ship_fuel;
164 pr("%s already has a full fuel load.\n",prship(&item.ship));
167 tot_fuel = (oil_amt*50 + pet_amt*5);
169 pr("No fuel in the harbor at %s!\n",
170 xyas(sect.sct_x,sect.sct_y,
174 move_amt = min(tot_fuel, fuel_amt);
175 move_amt = min(move_amt, max_amt);
180 item.ship.shp_fuel += move_amt;
183 if ((pet_amt*5) >= move_amt){
184 extra = ((float)move_amt/5.0)-(move_amt/5);
187 max((pet_amt-(move_amt/5))-1,0),
188 (s_char *)§, EF_SECTOR);
191 max((pet_amt-(move_amt/5)),0),
192 (s_char *)§, EF_SECTOR);
194 putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR);
195 move_amt -= pet_amt*5;
196 extra = ((float)move_amt/50.0)-(move_amt/50);
197 putvar(V_OIL, max(oil_amt-(move_amt/50), 0),
198 (s_char *)§, EF_SECTOR);
201 max((oil_amt-(move_amt/50))-1,0),
202 (s_char *)§, EF_SECTOR);
205 max((oil_amt-(move_amt/50)),0),
206 (s_char *)§, EF_SECTOR);
210 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) ==
211 PLG_INFECT && getvar(V_PSTAGE,
212 (s_char *)&item.ship, EF_SHIP) == PLG_HEALTHY)
213 putvar(V_PSTAGE, PLG_EXPOSED,
214 (s_char *)&item.ship, EF_SHIP);
217 putship(item.ship.shp_uid, &item.ship);
219 else{ /* not in a harbor */
220 if (!player->argp[4])
221 pr("%s is not in a supplied, efficient harbor\n", prship(&item.ship));
222 if (!snxtitem(&tender, EF_SHIP, getstarg(player->argp[4], "Oiler? ", buf)))
225 if (!check_ship_ok(&item.ship))
228 if (!nxtitem(&tender, (s_char *)&item2))
231 if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)){
232 pr("%s is not an oiler!\n",
233 prship(&item2.ship));
236 if (item2.ship.shp_own != player->cnum){
237 pr("You don't own that oiler!\n");
241 if ((item2.ship.shp_x != item.ship.shp_x) ||
242 (item2.ship.shp_y != item.ship.shp_y)){
243 pr("Not in the same sector!\n");
246 ship_fuel = item.ship.shp_fuel;
247 oil_amt = getvar(V_OIL, (s_char *)&item2.ship, EF_SHIP);
248 pet_amt = getvar(V_PETROL, (s_char *)&item2.ship, EF_SHIP);
249 max_amt = mp->m_fuelc-ship_fuel;
252 pr("%s already has a full fuel load.\n", prship(&item.ship));
255 tot_fuel = oil_amt*50 + pet_amt*5;
256 move_amt = min(tot_fuel, fuel_amt);
257 move_amt = min(move_amt, max_amt);
262 item.ship.shp_fuel += move_amt;
265 if ((pet_amt*5) >= move_amt){
266 extra = ((float)move_amt/5.0)-(move_amt/5);
269 max((pet_amt-(move_amt/5))-1,0),
270 (s_char *)&item2.ship, EF_SHIP);
273 max((pet_amt-(move_amt/5)),0),
274 (s_char *)&item2.ship, EF_SHIP);
276 putvar(V_PETROL, 0, (s_char *)&item2.ship, EF_SHIP);
277 move_amt -= pet_amt*5;
278 extra = ((float)move_amt/50.0)-(move_amt/50);
279 putvar(V_OIL, max(oil_amt-(move_amt/50), 0),
280 (s_char *)&item2.ship, EF_SHIP);
283 max((oil_amt-(move_amt/50))-1,0),
284 (s_char *)&item2.ship, EF_SHIP);
287 max((oil_amt-(move_amt/50)),0),
288 (s_char *)&item2.ship, EF_SHIP);
292 if (getvar(V_PSTAGE, (s_char *)&item2.ship, EF_SHIP) ==
293 PLG_INFECT && getvar(V_PSTAGE,
294 (s_char *)&item.ship, EF_SHIP) == PLG_HEALTHY)
295 putvar(V_PSTAGE, PLG_EXPOSED,
296 (s_char *)&item.ship, EF_SHIP);
298 putship(item.ship.shp_uid, &item.ship);
299 /* quick hack -KHS */
300 if (item.ship.shp_uid == item2.ship.shp_uid)
301 item2.ship.shp_fuel = item.ship.shp_fuel;
302 putship(item2.ship.shp_uid, &item2.ship);
304 pr("%s",prship(&item.ship));
307 if (item.land.lnd_own != player->cnum)
310 if (!getsect(item.land.lnd_x, item.land.lnd_y, §))
316 lcp = &lchr[(int)item.land.lnd_type];
319 oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR);
320 pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR);
322 if ((oil_amt+pet_amt) == 0)
325 if ((item.land.lnd_fuelu == 0) && (item.land.lnd_own == player->cnum)){
326 pr("%s does not use fuel!\n", prland(&item.land));
331 land_fuel = item.land.lnd_fuel;
332 oil_amt = getvar(V_OIL, (s_char *)§,
334 pet_amt = getvar(V_PETROL, (s_char *)§,
336 max_amt = item.land.lnd_fuelc-land_fuel;
339 pr("%s already has a full fuel load.\n", prland(&item.land));
342 tot_fuel = (oil_amt*50 + pet_amt*5);
344 pr("No fuel in the sector at %s!\n",
345 xyas(sect.sct_x,sect.sct_y,
349 move_amt = min(tot_fuel, fuel_amt);
350 move_amt = min(move_amt, max_amt);
355 item.land.lnd_fuel += move_amt;
358 if ((pet_amt*5) >= move_amt){
359 extra = ((float)move_amt/5.0)-(move_amt/5);
362 max((pet_amt-(move_amt/5))-1,0),
363 (s_char *)§, EF_SECTOR);
366 max((pet_amt-(move_amt/5)),0),
367 (s_char *)§, EF_SECTOR);
369 putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR);
370 move_amt -= pet_amt*5;
371 extra = ((float)move_amt/50.0)-(move_amt/50);
372 putvar(V_OIL, max(oil_amt-(move_amt/50), 0),
373 (s_char *)§, EF_SECTOR);
376 max((oil_amt-(move_amt/50))-1,0),
377 (s_char *)§, EF_SECTOR);
380 max((oil_amt-(move_amt/50)),0),
381 (s_char *)§, EF_SECTOR);
385 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) ==
386 PLG_INFECT && getvar(V_PSTAGE,
387 (s_char *)&item.land, EF_LAND) == PLG_HEALTHY)
388 putvar(V_PSTAGE, PLG_EXPOSED,
389 (s_char *)&item.land, EF_LAND);
392 putland(item.land.lnd_uid, &item.land);
394 else{ /* not in a sector */
395 if (!player->argp[4])
396 pr("%s is not in a supplied sector\n",
398 if (!snxtitem(<ender, EF_LAND,
399 getstarg(player->argp[4], "Supply unit? ", buf)))
402 if (!check_land_ok(&item.land))
405 if (!nxtitem(<ender, (s_char *)&item2))
408 if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)){
409 pr("%s is not a supply unit!\n",
410 prland(&item2.land));
413 if (item2.land.lnd_own != player->cnum){
414 pr("You don't own that unit!\n");
418 if ((item2.land.lnd_x != item.land.lnd_x) ||
419 (item2.land.lnd_y != item.land.lnd_y)){
420 pr("Not in the same sector!\n");
423 land_fuel = item.land.lnd_fuel;
424 oil_amt = getvar(V_OIL, (s_char *)&item2.land, EF_LAND);
425 pet_amt = getvar(V_PETROL, (s_char *)&item2.land, EF_LAND);
426 max_amt = item.land.lnd_fuelc-land_fuel;
429 pr("%s already has a full fuel load.\n", prland(&item.land));
432 tot_fuel = oil_amt*50 + pet_amt*5;
433 move_amt = min(tot_fuel, fuel_amt);
434 move_amt = min(move_amt, max_amt);
439 item.land.lnd_fuel += move_amt;
442 if ((pet_amt*5) >= move_amt){
443 extra = ((float)move_amt/5.0)-(move_amt/5);
446 max((pet_amt-(move_amt/5))-1,0),
447 (s_char *)&item2.land, EF_LAND);
450 max((pet_amt-(move_amt/5)),0),
451 (s_char *)&item2.land, EF_LAND);
453 putvar(V_PETROL, 0, (s_char *)&item2.land, EF_LAND);
454 move_amt -= pet_amt*5;
455 extra = ((float)move_amt/50.0)-(move_amt/50);
456 putvar(V_OIL, max(oil_amt-(move_amt/50), 0),
457 (s_char *)&item2.land, EF_LAND);
460 max((oil_amt-(move_amt/50))-1,0),
461 (s_char *)&item2.land, EF_LAND);
464 max((oil_amt-(move_amt/50)),0),
465 (s_char *)&item2.land, EF_LAND);
469 if (getvar(V_PSTAGE, (s_char *)&item2.land, EF_LAND) ==
470 PLG_INFECT && getvar(V_PSTAGE,
471 (s_char *)&item.land, EF_LAND) == PLG_HEALTHY)
472 putvar(V_PSTAGE, PLG_EXPOSED,
473 (s_char *)&item.land, EF_LAND);
475 putland(item.land.lnd_uid, &item.land);
476 /* quick hack -KHS */
477 if (item2.land.lnd_uid == item.land.lnd_uid)
478 item2.land.lnd_fuel = item.land.lnd_fuel;
479 putland(item2.land.lnd_uid, &item2.land);
481 pr("%s",prland(&item.land));
484 pr(" takes on %d fuel in %s\n",
486 xyas(item.ship.shp_x, item.ship.shp_y , player->cnum));
487 if (player->cnum != item.ship.shp_own)
488 wu(0, item.ship.shp_own,
489 "%s takes on %d fuel in %s courtesy of %s\n",
492 xyas(item.ship.shp_x, item.ship.shp_y ,
494 cname(player->cnum));