Fix bounds checking errors relating to the fuel reserve aboard the flagship.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3530 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2010-02-13 22:15:38 +00:00
parent 51c4e84b20
commit 3a10fe65db
2 changed files with 26 additions and 14 deletions
+9 -10
View File
@@ -102,7 +102,8 @@ RedistributeFuel (void)
DWORD FuelVolume; DWORD FuelVolume;
RECT r; RECT r;
if ((FuelVolume = GLOBAL_SIS (FuelOnBoard)) <= FUEL_RESERVE) FuelVolume = GLOBAL_SIS (FuelOnBoard);
if (FuelVolume <= FUEL_RESERVE)
return; return;
GLOBAL_SIS (FuelOnBoard) = 0; GLOBAL_SIS (FuelOnBoard) = 0;
@@ -559,18 +560,17 @@ ChangeFuelQuantity (void)
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetContext (SpaceContext); SetContext (SpaceContext);
if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard)
&& GLOBAL_SIS (ResUnits) >= && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (FuelCost))
(DWORD)GLOBAL (FuelCost))
{ {
if (GLOBAL_SIS (FuelOnBoard) >= if (GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE)
FUEL_RESERVE - FUEL_TANK_SCALE)
{ {
r.extent.width = 3; r.extent.width = 3;
DrawPoint (&r.corner); DrawPoint (&r.corner);
r.corner.x += r.extent.width + 1; r.corner.x += r.extent.width + 1;
DrawPoint (&r.corner); DrawPoint (&r.corner);
r.corner.x -= r.extent.width; r.corner.x -= r.extent.width;
SetContextForeGroundColor (SetContextBackGroundColor (BLACK_COLOR)); SetContextForeGroundColor (
SetContextBackGroundColor (BLACK_COLOR));
DrawFilledRectangle (&r); DrawFilledRectangle (&r);
} }
DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost)); DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost));
@@ -590,10 +590,9 @@ ChangeFuelQuantity (void)
SetContext (SpaceContext); SetContext (SpaceContext);
if (GLOBAL_SIS (FuelOnBoard)) if (GLOBAL_SIS (FuelOnBoard))
{ {
DeltaSISGauges (0, -FUEL_TANK_SCALE, DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost));
GLOBAL (FuelCost)); if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 &&
if (GLOBAL_SIS (FuelOnBoard) GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE)
% FUEL_VOLUME_PER_ROW == 0)
{ {
GetFTankCapacity (&r.corner); GetFTankCapacity (&r.corner);
SetContextForeGroundColor ( SetContextForeGroundColor (
+17 -4
View File
@@ -1418,12 +1418,15 @@ GetFuelTankCapacity (void)
// crew pod, where the Nth unit of fuel would be located. // crew pod, where the Nth unit of fuel would be located.
// If the unit does not fit, false is returned, and *slotNr and // If the unit does not fit, false is returned, and *slotNr and
// *compartmentNr are unchanged. // *compartmentNr are unchanged.
// Pre: unitNr >= FUEL_RESERER
static bool static bool
GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr) GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr)
{ {
COUNT slotI; COUNT slotI;
DWORD capacity = FUEL_RESERVE; DWORD capacity = FUEL_RESERVE;
assert (unitNr >= FUEL_RESERVE);
slotI = NUM_MODULE_SLOTS; slotI = NUM_MODULE_SLOTS;
while (slotI--) { while (slotI--) {
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]); BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
@@ -1447,6 +1450,7 @@ GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr)
DWORD DWORD
GetFTankCapacity (POINT *ppt) GetFTankCapacity (POINT *ppt)
{ {
DWORD capacity;
DWORD fuelAmount; DWORD fuelAmount;
COUNT slotNr; COUNT slotNr;
DWORD compartmentNr; DWORD compartmentNr;
@@ -1454,14 +1458,22 @@ GetFTankCapacity (POINT *ppt)
DWORD volume; DWORD volume;
COUNT rowNr; COUNT rowNr;
static const Color fuelColors[] = FUEL_COLOR_TABLE; static const Color fuelColors[] = FUEL_COLOR_TABLE;
capacity = GetFuelTankCapacity ();
fuelAmount = GetFuelTotal (); fuelAmount = GetFuelTotal ();
if (fuelAmount < FUEL_RESERVE)
{
// Fuel is in the SIS reserve, not in a fuel tank.
// *ppt is unchanged
return capacity;
}
if (!GetFuelTankForFuelUnit (fuelAmount, &slotNr, &compartmentNr)) if (!GetFuelTankForFuelUnit (fuelAmount, &slotNr, &compartmentNr))
{ {
// Fuel does not fit. *ppt is unchanged. // Fuel does not fit. *ppt is unchanged.
return GetFuelTankCapacity (); return capacity;
} }
moduleType = GLOBAL_SIS (ModuleSlots[slotNr]); moduleType = GLOBAL_SIS (ModuleSlots[slotNr]);
@@ -1475,10 +1487,11 @@ GetFTankCapacity (POINT *ppt)
else else
ppt->y = 30 - rowNr; ppt->y = 30 - rowNr;
assert (rowNr + 1 < (COUNT) (sizeof fuelColors / sizeof fuelColors[0]));
SetContextForeGroundColor (fuelColors[rowNr]); SetContextForeGroundColor (fuelColors[rowNr]);
SetContextBackGroundColor (fuelColors[rowNr + 1]); SetContextBackGroundColor (fuelColors[rowNr + 1]);
return GetFuelTankCapacity (); return capacity;
} }