Cleanups; separate model from view in some functions.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3356 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -194,7 +194,7 @@ ChangeSelection:
|
|||||||
t.pStr = GLOBAL_SIS (CommanderName);
|
t.pStr = GLOBAL_SIS (CommanderName);
|
||||||
t.CharCount = (COUNT)~0;
|
t.CharCount = (COUNT)~0;
|
||||||
crew_level = GLOBAL_SIS (CrewEnlisted);
|
crew_level = GLOBAL_SIS (CrewEnlisted);
|
||||||
max_crew = GetCPodCapacity (NULL);
|
max_crew = GetCrewPodCapacity ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ ShowRemainingCapacity (void)
|
|||||||
SetContextFont (TinyFont);
|
SetContextFont (TinyFont);
|
||||||
|
|
||||||
sprintf (rt_amount_buf, "%u",
|
sprintf (rt_amount_buf, "%u",
|
||||||
GetSBayCapacity (NULL)
|
GetStorageBayCapacity () - GLOBAL_SIS (TotalElementMass));
|
||||||
- GLOBAL_SIS (TotalElementMass));
|
|
||||||
rt.baseline.x = 59;
|
rt.baseline.x = 59;
|
||||||
rt.baseline.y = 113;
|
rt.baseline.y = 113;
|
||||||
rt.align = ALIGN_RIGHT;
|
rt.align = ALIGN_RIGHT;
|
||||||
|
|||||||
@@ -1917,8 +1917,7 @@ PlanetSide (POINT planetLoc)
|
|||||||
else
|
else
|
||||||
PSD.FireChance = FireChanceTab[7];
|
PSD.FireChance = FireChanceTab[7];
|
||||||
|
|
||||||
PSD.ElementLevel = GetSBayCapacity (NULL)
|
PSD.ElementLevel = GetStorageBayCapacity () - GLOBAL_SIS (TotalElementMass);
|
||||||
- GLOBAL_SIS (TotalElementMass);
|
|
||||||
PSD.MaxElementLevel = MAX_SCROUNGED;
|
PSD.MaxElementLevel = MAX_SCROUNGED;
|
||||||
if (GET_GAME_STATE (IMPROVED_LANDER_CARGO))
|
if (GET_GAME_STATE (IMPROVED_LANDER_CARGO))
|
||||||
PSD.MaxElementLevel <<= 1;
|
PSD.MaxElementLevel <<= 1;
|
||||||
@@ -2127,7 +2126,7 @@ InitLander (BYTE LanderFlags)
|
|||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_space = GetSBayCapacity (NULL) - GLOBAL_SIS (TotalElementMass);
|
free_space = GetStorageBayCapacity () - GLOBAL_SIS (TotalElementMass);
|
||||||
if ((int)free_space < (int)(MAX_SCROUNGED << capacity_shift))
|
if ((int)free_space < (int)(MAX_SCROUNGED << capacity_shift))
|
||||||
{
|
{
|
||||||
r.corner.x = 1;
|
r.corner.x = 1;
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ DoModifyRoster (MENU_STATE *pMS)
|
|||||||
}
|
}
|
||||||
else if (down)
|
else if (down)
|
||||||
{
|
{
|
||||||
if (GLOBAL_SIS (CrewEnlisted) < GetCPodCapacity (NULL))
|
if (GLOBAL_SIS (CrewEnlisted) < GetCrewPodCapacity ())
|
||||||
delta = -1;
|
delta = -1;
|
||||||
else
|
else
|
||||||
failed = TRUE;
|
failed = TRUE;
|
||||||
|
|||||||
+313
-120
@@ -868,6 +868,38 @@ DrawPC_SIS (void)
|
|||||||
font_DrawText (&t);
|
font_DrawText (&t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre: GraphicsLock is unlocked
|
||||||
|
static void
|
||||||
|
DrawSupportShips (void)
|
||||||
|
{
|
||||||
|
HSHIPFRAG hStarShip;
|
||||||
|
HSHIPFRAG hNextShip;
|
||||||
|
const POINT *pship_pos;
|
||||||
|
const POINT ship_pos[MAX_BUILT_SHIPS] =
|
||||||
|
{
|
||||||
|
SUPPORT_SHIP_PTS
|
||||||
|
};
|
||||||
|
|
||||||
|
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)),
|
||||||
|
pship_pos = ship_pos;
|
||||||
|
hStarShip; hStarShip = hNextShip, ++pship_pos)
|
||||||
|
{
|
||||||
|
SHIP_FRAGMENT *StarShipPtr;
|
||||||
|
STAMP s;
|
||||||
|
|
||||||
|
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
hNextShip = _GetSuccLink (StarShipPtr);
|
||||||
|
|
||||||
|
s.origin = *pship_pos;
|
||||||
|
s.frame = StarShipPtr->icons;
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
|
DrawStamp (&s);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
|
|
||||||
|
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
||||||
{
|
{
|
||||||
@@ -887,7 +919,8 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
{
|
{
|
||||||
COUNT i;
|
COUNT i;
|
||||||
|
|
||||||
s.origin.x = s.origin.y = 0;
|
s.origin.x = 0;
|
||||||
|
s.origin.y = 0;
|
||||||
s.frame = FlagStatFrame;
|
s.frame = FlagStatFrame;
|
||||||
DrawStamp (&s);
|
DrawStamp (&s);
|
||||||
if (optWhichFonts == OPT_PC)
|
if (optWhichFonts == OPT_PC)
|
||||||
@@ -909,6 +942,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
|
|
||||||
s.origin.y -= 3;
|
s.origin.y -= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
s.origin.y = 0;
|
s.origin.y = 0;
|
||||||
for (i = 0; i < NUM_JET_SLOTS; ++i)
|
for (i = 0; i < NUM_JET_SLOTS; ++i)
|
||||||
{
|
{
|
||||||
@@ -939,35 +973,9 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
s.origin.y -= 3;
|
s.origin.y -= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
HSHIPFRAG hStarShip, hNextShip;
|
|
||||||
POINT *pship_pos;
|
|
||||||
POINT ship_pos[MAX_BUILT_SHIPS] =
|
|
||||||
{
|
|
||||||
SUPPORT_SHIP_PTS
|
|
||||||
};
|
|
||||||
|
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)),
|
DrawSupportShips ();
|
||||||
pship_pos = ship_pos;
|
|
||||||
hStarShip; hStarShip = hNextShip, ++pship_pos)
|
|
||||||
{
|
|
||||||
SHIP_FRAGMENT *StarShipPtr;
|
|
||||||
|
|
||||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
hNextShip = _GetSuccLink (StarShipPtr);
|
|
||||||
|
|
||||||
s.origin.x = pship_pos->x;
|
|
||||||
s.origin.y = pship_pos->y;
|
|
||||||
s.frame = StarShipPtr->icons;
|
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
DrawStamp (&s);
|
|
||||||
UnlockMutex (GraphicsLock);
|
|
||||||
|
|
||||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
}
|
|
||||||
LockMutex (GraphicsLock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.baseline.x = STATUS_WIDTH >> 1;
|
t.baseline.x = STATUS_WIDTH >> 1;
|
||||||
@@ -984,10 +992,14 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
if (crew_delta < 0
|
if (crew_delta < 0
|
||||||
&& GLOBAL_SIS (CrewEnlisted) <= (COUNT)-crew_delta)
|
&& GLOBAL_SIS (CrewEnlisted) <= (COUNT)-crew_delta)
|
||||||
GLOBAL_SIS (CrewEnlisted) = 0;
|
GLOBAL_SIS (CrewEnlisted) = 0;
|
||||||
else if ((GLOBAL_SIS (CrewEnlisted) += crew_delta) >
|
else
|
||||||
(CrewCapacity = GetCPodCapacity (NULL)))
|
{
|
||||||
|
GLOBAL_SIS (CrewEnlisted) += crew_delta;
|
||||||
|
CrewCapacity = GetCrewPodCapacity ();
|
||||||
|
if (GLOBAL_SIS (CrewEnlisted) > CrewCapacity)
|
||||||
GLOBAL_SIS (CrewEnlisted) = CrewCapacity;
|
GLOBAL_SIS (CrewEnlisted) = CrewCapacity;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sprintf (buf, "%u", GLOBAL_SIS (CrewEnlisted));
|
sprintf (buf, "%u", GLOBAL_SIS (CrewEnlisted));
|
||||||
GetGaugeRect (&r, TRUE);
|
GetGaugeRect (&r, TRUE);
|
||||||
@@ -1002,7 +1014,8 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
|
|
||||||
if (fuel_delta != 0)
|
if (fuel_delta != 0)
|
||||||
{
|
{
|
||||||
COUNT old_coarse_fuel, new_coarse_fuel;
|
COUNT old_coarse_fuel;
|
||||||
|
COUNT new_coarse_fuel;
|
||||||
|
|
||||||
if (fuel_delta == UNDEFINED_DELTA)
|
if (fuel_delta == UNDEFINED_DELTA)
|
||||||
old_coarse_fuel = (COUNT)~0;
|
old_coarse_fuel = (COUNT)~0;
|
||||||
@@ -1018,7 +1031,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD FuelCapacity = GetFTankCapacity (NULL);
|
DWORD FuelCapacity = GetFuelTankCapacity ();
|
||||||
GLOBAL_SIS (FuelOnBoard) += fuel_delta;
|
GLOBAL_SIS (FuelOnBoard) += fuel_delta;
|
||||||
if (GLOBAL_SIS (FuelOnBoard) > FuelCapacity)
|
if (GLOBAL_SIS (FuelOnBoard) > FuelCapacity)
|
||||||
GLOBAL_SIS (FuelOnBoard) = FuelCapacity;
|
GLOBAL_SIS (FuelOnBoard) = FuelCapacity;
|
||||||
@@ -1079,143 +1092,323 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
|||||||
SetContext (OldContext);
|
SetContext (OldContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Crew
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Get the total amount of crew aboard the SIS.
|
||||||
COUNT
|
COUNT
|
||||||
GetCrewCount (void)
|
GetCrewCount (void)
|
||||||
{
|
{
|
||||||
return (GLOBAL_SIS (CrewEnlisted));
|
return GLOBAL_SIS (CrewEnlisted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the number of crew which fit in a module of a specified type.
|
||||||
|
COUNT
|
||||||
|
GetModuleCrewCapacity (BYTE moduleType)
|
||||||
|
{
|
||||||
|
if (moduleType == CREW_POD)
|
||||||
|
return CREW_POD_CAPACITY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the amount of crew which currently fit in the ship's crew pods.
|
||||||
|
COUNT
|
||||||
|
GetCrewPodCapacity (void)
|
||||||
|
{
|
||||||
|
COUNT capacity = 0;
|
||||||
|
COUNT slotI;
|
||||||
|
|
||||||
|
for (slotI = 0; slotI < NUM_MODULE_SLOTS; slotI++)
|
||||||
|
{
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
capacity += GetModuleCrewCapacity (moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the slot number of the crew pod and "seat" number in that crew pod,
|
||||||
|
// where the Nth crew member would be located.
|
||||||
|
// If the crew member does not fit, false is returned, and *slotNr and
|
||||||
|
// *seatNr are unchanged.
|
||||||
|
static bool
|
||||||
|
GetCrewPodForCrewMember (COUNT crewNr, COUNT *slotNr, COUNT *seatNr)
|
||||||
|
{
|
||||||
|
COUNT slotI;
|
||||||
|
COUNT capacity = 0;
|
||||||
|
|
||||||
|
slotI = NUM_MODULE_SLOTS;
|
||||||
|
while (slotI--) {
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
COUNT moduleCapacity = GetModuleCrewCapacity (moduleType);
|
||||||
|
|
||||||
|
if (crewNr < capacity + moduleCapacity)
|
||||||
|
{
|
||||||
|
*slotNr = slotI;
|
||||||
|
*seatNr = crewNr - capacity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
capacity += moduleCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the point where to draw the next crew member,
|
||||||
|
// set the foreground color to the color for that crew member,
|
||||||
|
// and return GetCrewPodCapacity ().
|
||||||
|
// TODO: Split of the parts of this function into separate functions.
|
||||||
COUNT
|
COUNT
|
||||||
GetCPodCapacity (POINT *ppt)
|
GetCPodCapacity (POINT *ppt)
|
||||||
{
|
{
|
||||||
COORD x;
|
COUNT crewCount;
|
||||||
COUNT slot, capacity;
|
COUNT slotNr;
|
||||||
|
COUNT seatNr;
|
||||||
|
|
||||||
x = 207;
|
COUNT rowNr;
|
||||||
capacity = 0;
|
COUNT colNr;
|
||||||
slot = NUM_MODULE_SLOTS - 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (GLOBAL_SIS (ModuleSlots[slot]) == CREW_POD)
|
|
||||||
{
|
|
||||||
if (ppt
|
|
||||||
&& capacity <= GLOBAL_SIS (CrewEnlisted)
|
|
||||||
&& capacity + CREW_POD_CAPACITY >
|
|
||||||
GLOBAL_SIS (CrewEnlisted))
|
|
||||||
{
|
|
||||||
COUNT pod_remainder, which_row;
|
|
||||||
static const COLOR crew_rows[] = PC_CREW_COLOR_TABLE;
|
|
||||||
|
|
||||||
pod_remainder = GLOBAL_SIS (CrewEnlisted) - capacity;
|
static const COLOR crewRows[] = PC_CREW_COLOR_TABLE;
|
||||||
|
|
||||||
ppt->x = x - ((pod_remainder % CREW_PER_ROW) << 1);
|
crewCount = GetCrewCount ();
|
||||||
which_row = pod_remainder / CREW_PER_ROW;
|
if (!GetCrewPodForCrewMember (crewCount, &slotNr, &seatNr))
|
||||||
ppt->y = 34 - (which_row << 1);
|
{
|
||||||
|
// Crew does not fit. *ppt is unchanged.
|
||||||
|
return GetCrewPodCapacity ();
|
||||||
|
}
|
||||||
|
|
||||||
|
rowNr = seatNr / CREW_PER_ROW;
|
||||||
|
colNr = seatNr % CREW_PER_ROW;
|
||||||
|
|
||||||
if (optWhichFonts == OPT_PC)
|
if (optWhichFonts == OPT_PC)
|
||||||
SetContextForeGroundColor (crew_rows[which_row]);
|
SetContextForeGroundColor (crewRows[rowNr]);
|
||||||
else
|
else
|
||||||
SetContextForeGroundColor (THREEDO_CREW_COLOR);
|
SetContextForeGroundColor (THREEDO_CREW_COLOR);
|
||||||
|
|
||||||
|
ppt->x = 27 + (slotNr * SHIP_PIECE_OFFSET) - (colNr * 2);
|
||||||
|
ppt->y = 34 - (rowNr * 2);
|
||||||
|
|
||||||
|
return GetCrewPodCapacity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
capacity += CREW_POD_CAPACITY;
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Storage bays
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Get the total amount of minerals aboard the SIS.
|
||||||
|
COUNT
|
||||||
|
GetElementMass (void)
|
||||||
|
{
|
||||||
|
return GLOBAL_SIS (TotalElementMass);
|
||||||
}
|
}
|
||||||
|
|
||||||
x -= SHIP_PIECE_OFFSET;
|
// Get the number of crew which fit in a module of a specified type.
|
||||||
} while (slot--);
|
COUNT
|
||||||
|
GetModuleStorageCapacity (BYTE moduleType)
|
||||||
|
{
|
||||||
|
if (moduleType == STORAGE_BAY)
|
||||||
|
return STORAGE_BAY_CAPACITY;
|
||||||
|
|
||||||
return (capacity);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets the amount of minerals which currently fit in the ship's storage.
|
||||||
|
COUNT
|
||||||
|
GetStorageBayCapacity (void)
|
||||||
|
{
|
||||||
|
COUNT capacity = 0;
|
||||||
|
COUNT slotI;
|
||||||
|
|
||||||
|
for (slotI = 0; slotI < NUM_MODULE_SLOTS; slotI++)
|
||||||
|
{
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
capacity += GetModuleStorageCapacity (moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the slot number of the storage bay and "storage cell" number in that
|
||||||
|
// storage bay, where the N-1th mineral unit would be located.
|
||||||
|
// If the mineral unit does not fit, false is returned, and *slotNr and
|
||||||
|
// *cellNr are unchanged.
|
||||||
|
static bool
|
||||||
|
GetStorageCellForMineralUnit (COUNT unitNr, COUNT *slotNr, COUNT *cellNr)
|
||||||
|
{
|
||||||
|
COUNT slotI;
|
||||||
|
COUNT capacity = 0;
|
||||||
|
|
||||||
|
slotI = NUM_MODULE_SLOTS;
|
||||||
|
while (slotI--) {
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
COUNT moduleCapacity = GetModuleStorageCapacity (moduleType);
|
||||||
|
|
||||||
|
if (unitNr <= capacity + moduleCapacity)
|
||||||
|
{
|
||||||
|
*slotNr = slotI;
|
||||||
|
*cellNr = unitNr - capacity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
capacity += moduleCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the point where to draw the next mineral unit,
|
||||||
|
// set the foreground color to the color for that mineral unit,
|
||||||
|
// and return GetStorageBayCapacity ().
|
||||||
|
// TODO: Split of the parts of this function into separate functions.
|
||||||
COUNT
|
COUNT
|
||||||
GetSBayCapacity (POINT *ppt)
|
GetSBayCapacity (POINT *ppt)
|
||||||
{
|
{
|
||||||
COORD x;
|
COUNT massCount;
|
||||||
COUNT slot, capacity;
|
COUNT slotNr;
|
||||||
|
COUNT cellNr;
|
||||||
|
|
||||||
x = 207 - 8;
|
COUNT rowNr;
|
||||||
capacity = 0;
|
COUNT colNr;
|
||||||
slot = NUM_MODULE_SLOTS - 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (GLOBAL_SIS (ModuleSlots[slot]) == STORAGE_BAY)
|
|
||||||
{
|
|
||||||
if (ppt
|
|
||||||
&& capacity < GLOBAL_SIS (TotalElementMass)
|
|
||||||
&& capacity + STORAGE_BAY_CAPACITY >=
|
|
||||||
GLOBAL_SIS (TotalElementMass))
|
|
||||||
{
|
|
||||||
COUNT bay_remainder, which_row;
|
|
||||||
static const COLOR color_bars[] = STORAGE_BAY_COLOR_TABLE;
|
|
||||||
|
|
||||||
bay_remainder = GLOBAL_SIS (TotalElementMass) - capacity;
|
static const COLOR colorBars[] = STORAGE_BAY_COLOR_TABLE;
|
||||||
which_row = bay_remainder / SBAY_MASS_PER_ROW;
|
|
||||||
if (which_row == 0)
|
massCount = GetElementMass ();
|
||||||
|
if (!GetStorageCellForMineralUnit (massCount, &slotNr, &cellNr))
|
||||||
|
{
|
||||||
|
// Crew does not fit. *ppt is unchanged.
|
||||||
|
return GetStorageBayCapacity ();
|
||||||
|
}
|
||||||
|
|
||||||
|
rowNr = cellNr / SBAY_MASS_PER_ROW;
|
||||||
|
colNr = cellNr % SBAY_MASS_PER_ROW;
|
||||||
|
|
||||||
|
if (rowNr == 0)
|
||||||
SetContextForeGroundColor (BLACK_COLOR);
|
SetContextForeGroundColor (BLACK_COLOR);
|
||||||
else
|
else
|
||||||
SetContextForeGroundColor (color_bars[--which_row]);
|
{
|
||||||
|
rowNr--;
|
||||||
ppt->x = x;
|
SetContextForeGroundColor (colorBars[rowNr]);
|
||||||
ppt->y = 34 - (which_row << 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
capacity += STORAGE_BAY_CAPACITY;
|
ppt->x = 19 + (slotNr * SHIP_PIECE_OFFSET);
|
||||||
|
ppt->y = 34 - (rowNr * 2);
|
||||||
|
|
||||||
|
return GetStorageBayCapacity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
x -= SHIP_PIECE_OFFSET;
|
|
||||||
} while (slot--);
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Fuel tanks
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Get the total amount of fuel aboard the SIS.
|
||||||
|
DWORD
|
||||||
|
GetFuelTotal (void)
|
||||||
|
{
|
||||||
|
return GLOBAL_SIS (FuelOnBoard);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the amount of fuel which fits in a module of a specified type.
|
||||||
|
DWORD
|
||||||
|
GetModuleFuelCapacity (BYTE moduleType)
|
||||||
|
{
|
||||||
|
if (moduleType == FUEL_TANK)
|
||||||
|
return FUEL_TANK_CAPACITY;
|
||||||
|
|
||||||
|
if (moduleType == HIGHEFF_FUELSYS)
|
||||||
|
return HEFUEL_TANK_CAPACITY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the amount of fuel which currently fits in the ship's fuel tanks.
|
||||||
|
DWORD
|
||||||
|
GetFuelTankCapacity (void)
|
||||||
|
{
|
||||||
|
DWORD capacity = FUEL_RESERVE;
|
||||||
|
COUNT slotI;
|
||||||
|
|
||||||
|
for (slotI = 0; slotI < NUM_MODULE_SLOTS; slotI++)
|
||||||
|
{
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
capacity += GetModuleFuelCapacity (moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the slot number of the fuel cell and "compartment" number in that
|
||||||
|
// 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.
|
||||||
|
static bool
|
||||||
|
GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr)
|
||||||
|
{
|
||||||
|
COUNT slotI;
|
||||||
|
DWORD capacity = FUEL_RESERVE;
|
||||||
|
|
||||||
|
slotI = NUM_MODULE_SLOTS;
|
||||||
|
while (slotI--) {
|
||||||
|
BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]);
|
||||||
|
|
||||||
|
capacity += GetModuleFuelCapacity (moduleType);
|
||||||
|
if (unitNr < capacity)
|
||||||
|
{
|
||||||
|
*slotNr = slotI;
|
||||||
|
*compartmentNr = capacity - unitNr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the point where to draw the next fuel unit,
|
||||||
|
// set the foreground color to the color for that unit,
|
||||||
|
// and return GetFuelTankCapacity ().
|
||||||
|
// TODO: Split of the parts of this function into separate functions.
|
||||||
DWORD
|
DWORD
|
||||||
GetFTankCapacity (POINT *ppt)
|
GetFTankCapacity (POINT *ppt)
|
||||||
{
|
{
|
||||||
COORD x;
|
DWORD fuelAmount;
|
||||||
COUNT slot;
|
COUNT slotNr;
|
||||||
DWORD capacity;
|
DWORD compartmentNr;
|
||||||
|
BYTE moduleType;
|
||||||
|
DWORD volume;
|
||||||
|
|
||||||
x = 200;
|
COUNT rowNr;
|
||||||
capacity = FUEL_RESERVE;
|
|
||||||
slot = NUM_MODULE_SLOTS - 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (GLOBAL_SIS (ModuleSlots[slot]) == FUEL_TANK
|
|
||||||
|| GLOBAL_SIS (ModuleSlots[slot]) == HIGHEFF_FUELSYS)
|
|
||||||
{
|
|
||||||
COUNT volume;
|
|
||||||
|
|
||||||
volume = GLOBAL_SIS (ModuleSlots[slot]) == FUEL_TANK
|
static const COLOR fuelColors[] = FUEL_COLOR_TABLE;
|
||||||
? FUEL_TANK_CAPACITY : HEFUEL_TANK_CAPACITY;
|
|
||||||
if (ppt
|
|
||||||
&& capacity <= GLOBAL_SIS (FuelOnBoard)
|
|
||||||
&& capacity + volume >
|
|
||||||
GLOBAL_SIS (FuelOnBoard))
|
|
||||||
{
|
|
||||||
COUNT which_row;
|
|
||||||
static const COLOR fuel_colors[] = FUEL_COLOR_TABLE;
|
|
||||||
|
|
||||||
which_row = (COUNT)(
|
fuelAmount = GetFuelTotal ();
|
||||||
(GLOBAL_SIS (FuelOnBoard) - capacity)
|
if (!GetFuelTankForFuelUnit (fuelAmount, &slotNr, &compartmentNr))
|
||||||
* MAX_FUEL_BARS / HEFUEL_TANK_CAPACITY);
|
{
|
||||||
ppt->x = x + 1;
|
// Fuel does not fit. *ppt is unchanged.
|
||||||
|
return GetFuelTankCapacity ();
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleType = GLOBAL_SIS (ModuleSlots[slotNr]);
|
||||||
|
volume = GetModuleFuelCapacity (moduleType);
|
||||||
|
|
||||||
|
rowNr = ((volume - compartmentNr) * MAX_FUEL_BARS / HEFUEL_TANK_CAPACITY);
|
||||||
|
|
||||||
|
ppt->x = 21 + (slotNr * SHIP_PIECE_OFFSET);
|
||||||
if (volume == FUEL_TANK_CAPACITY)
|
if (volume == FUEL_TANK_CAPACITY)
|
||||||
ppt->y = 27 - which_row;
|
ppt->y = 27 - rowNr;
|
||||||
else
|
else
|
||||||
ppt->y = 30 - which_row;
|
ppt->y = 30 - rowNr;
|
||||||
|
|
||||||
SetContextForeGroundColor (fuel_colors[which_row]);
|
SetContextForeGroundColor (fuelColors[rowNr]);
|
||||||
SetContextBackGroundColor (fuel_colors[which_row + 1]);
|
SetContextBackGroundColor (fuelColors[rowNr + 1]);
|
||||||
|
|
||||||
|
return GetFuelTankCapacity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
capacity += volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
x -= SHIP_PIECE_OFFSET;
|
////////////////////////////////////////////////////////////////////////////
|
||||||
} while (slot--);
|
|
||||||
|
|
||||||
return capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
COUNT
|
COUNT
|
||||||
CountSISPieces (BYTE piece_type)
|
CountSISPieces (BYTE piece_type)
|
||||||
|
|||||||
+9
-1
@@ -207,11 +207,19 @@ void DrawAutoPilotMessage (BOOLEAN Reset);
|
|||||||
|
|
||||||
extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int
|
extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int
|
||||||
resunit_delta);
|
resunit_delta);
|
||||||
|
|
||||||
extern COUNT GetCrewCount (void);
|
extern COUNT GetCrewCount (void);
|
||||||
|
extern COUNT GetModuleCrewCapacity (BYTE moduleType);
|
||||||
|
|
||||||
|
extern COUNT GetCrewPodCapacity (void);
|
||||||
extern COUNT GetCPodCapacity (POINT *ppt);
|
extern COUNT GetCPodCapacity (POINT *ppt);
|
||||||
extern COUNT GetLBayCapacity (POINT *ppt);
|
|
||||||
|
extern COUNT GetStorageBayCapacity (void);
|
||||||
extern COUNT GetSBayCapacity (POINT *ppt);
|
extern COUNT GetSBayCapacity (POINT *ppt);
|
||||||
|
|
||||||
|
extern DWORD GetFuelTankCapacity (void);
|
||||||
extern DWORD GetFTankCapacity (POINT *ppt);
|
extern DWORD GetFTankCapacity (POINT *ppt);
|
||||||
|
|
||||||
extern COUNT CountSISPieces (BYTE piece_type);
|
extern COUNT CountSISPieces (BYTE piece_type);
|
||||||
|
|
||||||
extern void DrawFlagshipName (BOOLEAN InStatusArea);
|
extern void DrawFlagshipName (BOOLEAN InStatusArea);
|
||||||
|
|||||||
Reference in New Issue
Block a user