[Freeciv-Dev] Re: (PR#4372) Missile carriers with limited fuel always cr
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#4372) Missile carriers with limited fuel always crash |
From: |
"Cameron Morland" <cameron@xxxxxxxxxx> |
Date: |
Tue, 10 Jun 2003 12:18:13 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
On Tue, Jun 10, 2003 at 10:09:08AM -0700, Per I. Mathisen wrote:
> The problem is that we use punit->fuel variable temporarily for carrier
> refuelling of aircraft and missiles, assuming stupidly that a fuel limited
> unit can never itself be a carrier.
>
> I think the fix is wrong. Adding a variable to the unit struct for
> something will only be used inside one function and then be thrown away is
> a waste of good memory. Instead, for each of pplayer->units, if punit is a
> carrier, find and refuel as many air units stacked with you as you have
> carrier capacity.
Right. This patch uses local variables instead.
The one bug I've noticed but haven't fixed yet is that a carrier,
carrying a fighter modified to carry missiles, will leave behind the
missiles which are considered to be carried by the fighter, if those
missiles are in sentry mode. (A carrier with 1 fighter and 9 missiles
will leave 2 behind when it moves.) I'm working on that part now.
--
+-----------------------------------------------------------------
| PGP http://www.eng.uwaterloo.ca/student/cjmorlan/public-key.pgp
| Cameron Morland ---- Cameron@xxxxxxxxxx
|
| The reason that every major university maintains a
| department of mathematics is that it's cheaper than
| institutionalizing all those people.
+-----------------------------------------------------------------
Index: unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.225
diff -u -3 -p -r1.225 unittools.c
--- unittools.c 2003/06/04 20:05:40 1.225
+++ unittools.c 2003/06/10 19:15:14
@@ -318,57 +318,43 @@ static void refuel_air_units_from_carrie
unit_list_init(&carriers);
unit_list_init(&missile_carriers);
- /* Temporarily use 'fuel' on Carriers and Subs to keep track
- of numbers of supported Air Units: --dwp */
-
+ /* get a list of all missile carriers and [aircraft] carriers. */
unit_list_iterate(pplayer->units, punit) {
if (unit_flag(punit, F_CARRIER)) {
unit_list_insert(&carriers, punit);
- punit->fuel = unit_type(punit)->transport_capacity;
} else if (unit_flag(punit, F_MISSILE_CARRIER)) {
unit_list_insert(&missile_carriers, punit);
- punit->fuel = unit_type(punit)->transport_capacity;
}
} unit_list_iterate_end;
/* Now iterate through missile_carriers and
* refuel as many missiles as possible */
-
unit_list_iterate(missile_carriers, punit) {
- while(punit->fuel > 0) {
- punit_to_refuel= find_best_air_unit_to_refuel(
+ int cargo_fuel = unit_type(punit)->transport_capacity;
+ while(cargo_fuel > 0) {
+ punit_to_refuel = find_best_air_unit_to_refuel(
pplayer, punit->x, punit->y, TRUE /*missile */);
if (!punit_to_refuel)
break; /* Didn't find any */
punit_to_refuel->fuel = unit_type(punit_to_refuel)->fuel;
- punit->fuel--;
+ cargo_fuel--;
}
} unit_list_iterate_end;
/* Now refuel air units from carriers (also not yet refuelled missiles) */
-
unit_list_iterate(carriers, punit) {
- while(punit->fuel > 0) {
- punit_to_refuel= find_best_air_unit_to_refuel(
+ int cargo_fuel = unit_type(punit)->transport_capacity;
+ while(cargo_fuel > 0) {
+ punit_to_refuel = find_best_air_unit_to_refuel(
pplayer, punit->x, punit->y, FALSE /* any */);
if (!punit_to_refuel)
break;
punit_to_refuel->fuel = unit_type(punit_to_refuel)->fuel;
- punit->fuel--;
+ cargo_fuel--;
}
} unit_list_iterate_end;
- /* Clean up temporary use of 'fuel' on Carriers and Subs: */
- unit_list_iterate(carriers, punit) {
- punit->fuel = 0;
- } unit_list_iterate_end;
-
unit_list_unlink_all(&carriers);
-
- unit_list_iterate(missile_carriers, punit) {
- punit->fuel = 0;
- } unit_list_iterate_end;
-
unit_list_unlink_all(&missile_carriers);
}
pgpowsW57R2yz.pgp
Description: PGP signature
|
|