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:
+9
-10
@@ -102,7 +102,8 @@ RedistributeFuel (void)
|
||||
DWORD FuelVolume;
|
||||
RECT r;
|
||||
|
||||
if ((FuelVolume = GLOBAL_SIS (FuelOnBoard)) <= FUEL_RESERVE)
|
||||
FuelVolume = GLOBAL_SIS (FuelOnBoard);
|
||||
if (FuelVolume <= FUEL_RESERVE)
|
||||
return;
|
||||
|
||||
GLOBAL_SIS (FuelOnBoard) = 0;
|
||||
@@ -559,18 +560,17 @@ ChangeFuelQuantity (void)
|
||||
LockMutex (GraphicsLock);
|
||||
SetContext (SpaceContext);
|
||||
if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard)
|
||||
&& GLOBAL_SIS (ResUnits) >=
|
||||
(DWORD)GLOBAL (FuelCost))
|
||||
&& GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (FuelCost))
|
||||
{
|
||||
if (GLOBAL_SIS (FuelOnBoard) >=
|
||||
FUEL_RESERVE - FUEL_TANK_SCALE)
|
||||
if (GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE)
|
||||
{
|
||||
r.extent.width = 3;
|
||||
DrawPoint (&r.corner);
|
||||
r.corner.x += r.extent.width + 1;
|
||||
DrawPoint (&r.corner);
|
||||
r.corner.x -= r.extent.width;
|
||||
SetContextForeGroundColor (SetContextBackGroundColor (BLACK_COLOR));
|
||||
SetContextForeGroundColor (
|
||||
SetContextBackGroundColor (BLACK_COLOR));
|
||||
DrawFilledRectangle (&r);
|
||||
}
|
||||
DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost));
|
||||
@@ -590,10 +590,9 @@ ChangeFuelQuantity (void)
|
||||
SetContext (SpaceContext);
|
||||
if (GLOBAL_SIS (FuelOnBoard))
|
||||
{
|
||||
DeltaSISGauges (0, -FUEL_TANK_SCALE,
|
||||
GLOBAL (FuelCost));
|
||||
if (GLOBAL_SIS (FuelOnBoard)
|
||||
% FUEL_VOLUME_PER_ROW == 0)
|
||||
DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost));
|
||||
if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 &&
|
||||
GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE)
|
||||
{
|
||||
GetFTankCapacity (&r.corner);
|
||||
SetContextForeGroundColor (
|
||||
|
||||
+15
-2
@@ -1418,12 +1418,15 @@ GetFuelTankCapacity (void)
|
||||
// crew pod, where the Nth unit of fuel would be located.
|
||||
// If the unit does not fit, false is returned, and *slotNr and
|
||||
// *compartmentNr are unchanged.
|
||||
// Pre: unitNr >= FUEL_RESERER
|
||||
static bool
|
||||
GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr)
|
||||
{
|
||||
COUNT slotI;
|
||||
DWORD capacity = FUEL_RESERVE;
|
||||
|
||||
assert (unitNr >= FUEL_RESERVE);
|
||||
|
||||
slotI = NUM_MODULE_SLOTS;
|
||||
while (slotI--) {
|
||||
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||
@@ -1447,6 +1450,7 @@ GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr)
|
||||
DWORD
|
||||
GetFTankCapacity (POINT *ppt)
|
||||
{
|
||||
DWORD capacity;
|
||||
DWORD fuelAmount;
|
||||
COUNT slotNr;
|
||||
DWORD compartmentNr;
|
||||
@@ -1457,11 +1461,19 @@ GetFTankCapacity (POINT *ppt)
|
||||
|
||||
static const Color fuelColors[] = FUEL_COLOR_TABLE;
|
||||
|
||||
capacity = GetFuelTankCapacity ();
|
||||
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))
|
||||
{
|
||||
// Fuel does not fit. *ppt is unchanged.
|
||||
return GetFuelTankCapacity ();
|
||||
return capacity;
|
||||
}
|
||||
|
||||
moduleType = GLOBAL_SIS (ModuleSlots[slotNr]);
|
||||
@@ -1475,10 +1487,11 @@ GetFTankCapacity (POINT *ppt)
|
||||
else
|
||||
ppt->y = 30 - rowNr;
|
||||
|
||||
assert (rowNr + 1 < (COUNT) (sizeof fuelColors / sizeof fuelColors[0]));
|
||||
SetContextForeGroundColor (fuelColors[rowNr]);
|
||||
SetContextBackGroundColor (fuelColors[rowNr + 1]);
|
||||
|
||||
return GetFuelTankCapacity ();
|
||||
return capacity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user