Cleanup of some of the pSolarSysState references

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3379 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-01 17:18:26 +00:00
parent d050f79cb6
commit 9562043687
10 changed files with 144 additions and 110 deletions
+26 -1
View File
@@ -448,7 +448,7 @@ unhyper_transition (ELEMENT *ElementPtr)
switch ((TRANSITION_TYPE) ElementPtr->turn_wait)
{
case RANDOM_ENCOUNTER_TRANSITION:
SaveFlagshipState ();
SaveSisHyperState ();
GLOBAL (CurrentActivity) |= START_ENCOUNTER;
break;
case INTERPLANETARY_TRANSITION:
@@ -880,6 +880,15 @@ getSisElement (void)
hShip = StarShipPtr->hShip;
UnlockStarShip (&race_q[RPG_PLAYER_NUM], hSis);
#ifdef DEBUG
{
ELEMENT *ElementPtr;
LockElement (hShip, &ElementPtr);
assert (ElementPtr->state_flags & PLAYER_SHIP);
UnlockElement (hShip);
}
#endif
return hShip;
}
@@ -1716,3 +1725,19 @@ UnbatchGraphics ();
BatchGraphics ();
}
void
SaveSisHyperState (void)
{
HELEMENT hSisElement;
ELEMENT *ElementPtr;
STARSHIP *StarShipPtr;
// Update 'GLOBAL (ShipFacing)' to the direction the flagship is facing
hSisElement = getSisElement ();
//if (ElementPtr->state_flags & PLAYER_SHIP)
LockElement (hSisElement, &ElementPtr);
GetElementStarShip (ElementPtr, &StarShipPtr);
// XXX: Solar system reentry test depends on ShipFacing != 0
GLOBAL (ShipFacing) = StarShipPtr->ShipFacing + 1;
UnlockElement (hSisElement);
}
+1
View File
@@ -56,6 +56,7 @@ extern void check_hyperspace_encounter (void);
extern BOOLEAN hyper_transition (ELEMENT *ElementPtr);
extern void HyperspaceMenu (void);
extern void SaveSisHyperState (void);
#endif /* _HYPER_H */
+3 -3
View File
@@ -137,7 +137,7 @@ ip_group_preprocess (ELEMENT *ElementPtr)
InitIntersectStartPoint (EPtr);
if (pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc)
if (!playerInInnerSystem ())
flagship_loc = 0;
else
flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc
@@ -676,7 +676,7 @@ flag_ship_preprocess (ELEMENT *ElementPtr)
GetCurrentVelocityComponents (&GLOBAL (velocity), &vdx, &vdy);
if (pSolarSysState->pBaseDesc == pSolarSysState->MoonDesc)
if (playerInInnerSystem ())
{
flagship_loc = (BYTE)(pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 2);
@@ -767,7 +767,7 @@ spawn_flag_ship (void)
LockElement (hFlagShipElement, &FlagShipElementPtr);
FlagShipElementPtr->hit_points = 1;
if (pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc)
if (!playerInInnerSystem ())
FlagShipElementPtr->sys_loc = 1;
else
FlagShipElementPtr->sys_loc =
+15 -12
View File
@@ -26,10 +26,14 @@
#include "../setup.h"
#include "../state.h"
#include "../sis.h"
// for ClearSISRect(), SaveFlagshipState()
// for ClearSISRect()
#include "../grpinfo.h"
#include "../sounds.h"
#include "../util.h"
#include "../hyper.h"
// for SaveSisHyperState()
#include "planets.h"
// for SaveSolarSysLocation() and tests
#include "libs/strlib.h"
@@ -206,11 +210,11 @@ UseCaster (void)
}
if (LOBYTE (GLOBAL (CurrentActivity)) != IN_INTERPLANETARY
|| pSolarSysState == NULL)
|| !playerInSolarSystem ())
return FALSE;
if (pSolarSysState->pOrbitalDesc == &pSolarSysState->PlanetDesc[1]
&& pSolarSysState->MenuState.Initialized == 3
&& playerInPlanetOrbit ()
&& CurStarDescPtr->Index == CHMMR_DEFINED
&& !GET_GAME_STATE (CHMMR_UNLEASHED))
{
@@ -224,7 +228,7 @@ UseCaster (void)
assert (CountLinks (&GLOBAL (npc_built_ship_q)) == 0);
SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7);
SaveFlagshipState ();
SaveSolarSysLocation ();
return TRUE;
}
@@ -267,8 +271,8 @@ UseCaster (void)
SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 5);
}
if (pSolarSysState->MenuState.Initialized >= 3)
SaveFlagshipState ();
if (playerInPlanetOrbit ())
SaveSolarSysLocation ();
return TRUE;
}
}
@@ -300,9 +304,7 @@ DeviceFailed (BYTE which_device)
break;
case SUN_EFFICIENCY_DEVICE:
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY
&& pSolarSysState
&& pSolarSysState->pOrbitalDesc
&& pSolarSysState->MenuState.Initialized == 3)
&& playerInPlanetOrbit ())
{
BYTE fade_buf[1];
@@ -361,6 +363,8 @@ DeviceFailed (BYTE which_device)
SET_GAME_STATE (SHIP_TO_COMPEL, 1);
}
GLOBAL (CurrentActivity) &= ~IN_BATTLE;
SaveSisHyperState ();
}
else
{
@@ -378,10 +382,9 @@ DeviceFailed (BYTE which_device)
{
SET_GAME_STATE (READY_TO_CONFUSE_URQUAN, 1);
}
if (pSolarSysState->MenuState.Initialized < 3)
return (FALSE);
if (playerInPlanetOrbit ())
SaveSolarSysLocation ();
}
SaveFlagshipState ();
return (FALSE);
case AQUA_HELIX_DEVICE:
val = GET_GAME_STATE (ULTRON_CONDITION);
+4
View File
@@ -219,6 +219,9 @@ struct solarsys_state
extern SOLARSYS_STATE *pSolarSysState;
extern MUSIC_REF SpaceMusic;
bool playerInSolarSystem (void);
bool playerInPlanetOrbit (void);
bool playerInInnerSystem (void);
bool worldIsPlanet (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
bool worldIsMoon (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
COUNT planetIndex (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world);
@@ -255,6 +258,7 @@ extern UNICODE* GetNamedPlanetaryBody (void);
extern void GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize);
extern void PlanetOrbitMenu (void);
extern void SaveSolarSysLocation (void);
#endif /* _PLANETS_H */
+1 -1
View File
@@ -736,7 +736,7 @@ PickPlanetSide (MENU_STATE *pMS)
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
}
SaveFlagshipState ();
SaveSolarSysLocation ();
return (FALSE);
}
+74 -17
View File
@@ -142,10 +142,24 @@ matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world,
return true;
}
// TODO: make code outside solarsys.c call a similar external version
static inline bool
inInnerSystem (void)
bool
playerInSolarSystem (void)
{
return pSolarSysState != NULL;
}
bool
playerInPlanetOrbit (void)
{
return playerInSolarSystem () &&
pSolarSysState->MenuState.Initialized >= 3;
// XXX: This test will change eventually
}
bool
playerInInnerSystem (void)
{
assert (playerInSolarSystem ());
assert (pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc
|| pSolarSysState->pBaseDesc == pSolarSysState->MoonDesc);
return pSolarSysState->pBaseDesc != pSolarSysState->PlanetDesc;
@@ -433,10 +447,8 @@ FreeSolarSys (void)
}
pSolarSysState->MenuState.flash_task = 0;
LockMutex (GraphicsLock);
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
SaveFlagshipState ();
UnlockMutex (GraphicsLock);
SaveSolarSysLocation ();
}
LockMutex (GraphicsLock);
@@ -519,7 +531,7 @@ ShowPlanet:
{
PlanetIntersect.IntersectStamp.origin = pCurDesc->image.origin;
PlanetIntersect.EndPoint = PlanetIntersect.IntersectStamp.origin;
if (inInnerSystem ())
if (playerInInnerSystem ())
{
PlanetOffset = pCurDesc->pPrevDesc -
pSolarSysState->PlanetDesc;
@@ -552,7 +564,7 @@ ShowPlanet:
return;
else if (pSolarSysState->WaitIntersect == NewWaitPlanet)
continue;
else if (inInnerSystem ())
else if (playerInInnerSystem ())
goto ShowPlanet;
else if (!just_checking) /* pBaseDesc == PlanetDesc */
{
@@ -768,7 +780,7 @@ ZoomSystem (void)
SetTransitionSource (&r);
BatchGraphics ();
if (inInnerSystem ())
if (playerInInnerSystem ())
DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE);
else
DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE);
@@ -910,7 +922,7 @@ UndrawShip (void)
|| GLOBAL (ShipStamp.origin.y) >= SIS_SCREEN_HEIGHT)
{
// The ship leaves the screen.
if (!inInnerSystem ())
if (!playerInInnerSystem ())
{
if (radius == MAX_ZOOM_RADIUS)
{
@@ -940,7 +952,7 @@ UndrawShip (void)
pSolarSysState->MenuState.flash_rect0.corner.x;
delta_y = GLOBAL (ShipStamp.origin.y) -
pSolarSysState->MenuState.flash_rect0.corner.y;
if (!inInnerSystem ()
if (!playerInInnerSystem ()
&& (radius > MAX_ZOOM_RADIUS
|| (delta_x >= 0 && delta_y >= 0
&& delta_x < pSolarSysState->MenuState.flash_rect0.extent.width
@@ -1106,7 +1118,7 @@ IP_frame (void)
// we have to treat things slightly differently depending on the
// situation (note that DRAW_REFRESH means entered a new system
// not from a load)
startedInInner = inInnerSystem ();
startedInInner = playerInInnerSystem ();
if (startedInInner)
{
SetTransitionSource (NULL);
@@ -1145,13 +1157,13 @@ IP_frame (void)
// Don't redraw if entering/exiting inner system
// this screws up ScreenTransition by leaving an image of the
// ship in the ExtraScreen (which we use for repair)
if (startedInInner == inInnerSystem ())
if (startedInInner == playerInInnerSystem ())
RedrawQueue (FALSE);
}
if (startedInInner)
{
if (!inInnerSystem ())
if (!playerInInnerSystem ())
{
// transition screen if we left inner system (if going
// from outer to inner, ScreenTransition happens elsewhere)
@@ -1186,7 +1198,7 @@ IP_frame (void)
}
// Save the system image if we left inner system, or we forced a redraw
if ((startedInInner && !inInnerSystem ())
if ((startedInInner && !playerInInnerSystem ())
|| (draw_sys_flags & DRAW_REFRESH))
{
LoadIntoExtraScreen (&r);
@@ -1214,7 +1226,7 @@ ValidateOrbits (void)
POINT old_pts[2] = { { 0, 0 }, { 0, 0 } };
PLANET_DESC *pCurDesc;
InnerSystem = inInnerSystem ();
InnerSystem = playerInInnerSystem ();
if (InnerSystem)
{
old_pts[0] = GLOBAL (ShipStamp.origin);
@@ -1623,7 +1635,7 @@ DrawSystem (SIZE radius, BOOLEAN IsInnerSystem)
}
}
if (!inInnerSystem ())
if (!playerInInnerSystem ())
XFormIPLoc (&GLOBAL (ip_location),
&GLOBAL (ShipStamp.origin),
TRUE);
@@ -1918,6 +1930,51 @@ GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize)
}
}
void
SaveSolarSysLocation (void)
{
assert (playerInSolarSystem ());
if (!playerInPlanetOrbit ())
{
// XXX: Solar system reentry test depends on ShipFacing != 0
GLOBAL (ShipFacing) = GetFrameIndex (GLOBAL (ShipStamp.frame)) + 1;
GLOBAL (in_orbit) = 0;
if (!playerInInnerSystem ())
{
GLOBAL (ip_planet) = 0;
}
else
{
// XXX: Is that even correct? pBaseDesc should point to PlanetDesc
GLOBAL (ip_planet) = pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 1;
GLOBAL (ip_location) = pSolarSysState->SunDesc[0].location;
}
}
else
{ // In orbit around a planet.
BYTE moon;
// Update the starinfo.dat file if necessary.
if (GET_GAME_STATE (PLANETARY_CHANGE))
{
PutPlanetInfo ();
SET_GAME_STATE (PLANETARY_CHANGE, 0);
}
// GLOBAL (ip_planet) is already set
moon = 1; /* the planet itself */
// XXX: This test is convoluted, and we should come up with a
// better linking system
if (pSolarSysState->pOrbitalDesc !=
pSolarSysState->pBaseDesc->pPrevDesc)
moon += pSolarSysState->pOrbitalDesc
- pSolarSysState->pBaseDesc + 1;
GLOBAL (in_orbit) = moon;
}
}
static BOOLEAN
DoSolarSysMenu (MENU_STATE *pMS)
{
+20 -2
View File
@@ -21,7 +21,6 @@
#include "save.h"
#include "build.h"
#include "libs/declib.h"
#include "controls.h"
#include "encount.h"
#include "libs/file.h"
@@ -34,9 +33,14 @@
#include "state.h"
#include "grpinfo.h"
#include "util.h"
#include "hyper.h"
// for SaveSisHyperState()
#include "planets/planets.h"
// for SaveSolarSysLocation() and tests
#include "libs/inplib.h"
#include "libs/log.h"
#include "libs/memlib.h"
#include "libs/declib.h"
// XXX: these should handle endian conversions later
@@ -481,7 +485,7 @@ PrepareSummary (SUMMARY_DESC *SummPtr)
sizeof (SummPtr->SS.PlanetName));
if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) == (BYTE)~0)
SummPtr->Activity = IN_STARBASE;
else if (pSolarSysState && pSolarSysState->MenuState.Initialized >= 3)
else if (playerInPlanetOrbit ())
SummPtr->Activity = IN_PLANET_ORBIT;
break;
case IN_LAST_BATTLE:
@@ -617,6 +621,20 @@ SaveProblem (void)
UnlockMutex (GraphicsLock);
}
static void
SaveFlagshipState (void)
{
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
{
// Player is in HyperSpace or QuasiSpace.
SaveSisHyperState ();
}
else if (playerInSolarSystem ())
{
SaveSolarSysLocation ();
}
}
// This function first writes to a memory file, and then writes the whole
// lot to the actual save file at once.
BOOLEAN
-73
View File
@@ -1809,76 +1809,3 @@ SetFlashRect (RECT *pRect)
SetContext (OldContext);
}
void
SaveFlagshipState (void)
{
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
{
// Player is in HyperSpace or QuasiSpace.
// Update 'GLOBAL (ShipFacing)' to the direction the flagship
// is facing.
HELEMENT hElement, hNextElement;
// Find the flagship element.
for (hElement = GetHeadElement ();
hElement != 0; hElement = hNextElement)
{
ELEMENT *ElementPtr;
LockElement (hElement, &ElementPtr);
hNextElement = GetSuccElement (ElementPtr);
if (ElementPtr->state_flags & PLAYER_SHIP)
{
STARSHIP *StarShipPtr;
GetElementStarShip (ElementPtr, &StarShipPtr);
// XXX: Solar system reentry test depends on ShipFacing != 0
GLOBAL (ShipFacing) = StarShipPtr->ShipFacing + 1;
hNextElement = 0;
}
UnlockElement (hElement);
}
}
else if (pSolarSysState)
{
// Player is in a solar system.
if (pSolarSysState->MenuState.Initialized < 3)
{
// XXX: Solar system reentry test depends on ShipFacing != 0
GLOBAL (ShipFacing) = GetFrameIndex (GLOBAL (ShipStamp.frame)) + 1;
GLOBAL (in_orbit) = 0;
if (pSolarSysState->pBaseDesc == pSolarSysState->PlanetDesc)
{
GLOBAL (ip_planet) = 0;
}
else
{
GLOBAL (ip_planet) = pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 1;
GLOBAL (ip_location) = pSolarSysState->SunDesc[0].location;
}
}
else
{
// In orbit around a planet.
BYTE moon;
// Update the starinfo.dat file if necessary.
if (GET_GAME_STATE (PLANETARY_CHANGE))
{
PutPlanetInfo ();
SET_GAME_STATE (PLANETARY_CHANGE, 0);
}
// GLOBAL (ip_planet) is already set
moon = 1; /* the planet itself */
if (pSolarSysState->pOrbitalDesc !=
pSolarSysState->pBaseDesc->pPrevDesc)
moon += pSolarSysState->pOrbitalDesc
- pSolarSysState->pBaseDesc + 1;
GLOBAL (in_orbit) = moon;
}
}
}
-1
View File
@@ -202,7 +202,6 @@ extern void DrawLanders (void);
extern void DrawStorageBays (BOOLEAN Refresh);
extern void GetGaugeRect (RECT *pRect, BOOLEAN IsCrewRect);
extern void DrawFlagshipStats (void);
extern void SaveFlagshipState (void);
void DrawAutoPilotMessage (BOOLEAN Reset);
extern void DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int