Cleanup of GLOBAL(ShipStamp.frame) abuse; also fixes #1054

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3168 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-07-04 06:18:22 +00:00
parent 86f36b30d5
commit 85191e5541
12 changed files with 59 additions and 51 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.7:
- Cleanup of GLOBAL(ShipStamp.frame) abuse; fixes bug #1054 - Alex
- Game attempts to exit cleanly under normal circustances (bug #52) - Alex
- Fixed Mmrnmhrm's X-Form transformation without energy use (bug #1004) - Alex
- Added missing sleeps in DoInput() functions (bug #893) - Alex
+1 -1
View File
@@ -1440,7 +1440,7 @@ InitCommunication (CONVERSATION which_comm)
DrawSISMessage (NULL);
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
DrawHyperCoords (GLOBAL (ShipStamp.origin));
else if (HIWORD (GLOBAL (ShipStamp.frame)) == 0)
else if (GLOBAL (ip_planet) == 0)
DrawHyperCoords (CurStarDescPtr->star_pt);
else
DrawSISTitle (GLOBAL_SIS (PlanetName));
+4 -1
View File
@@ -155,7 +155,10 @@ ExitConversation (RESPONSE_REF R)
/* transport player to Earth */
GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (SOL_X);
GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (SOL_Y);
GLOBAL (ShipStamp.frame) = (FRAME)MAKE_DWORD (1, EARTH_INDEX + 1);
GLOBAL (ShipFacing) = 1;
/* At Earth or at Starbase */
GLOBAL (ip_planet) = EARTH_INDEX + 1;
GLOBAL (in_orbit) = 0;
/* XXX : this should be unhardcoded eventually */
GLOBAL (ip_location.x) = EARTH_OUTER_X;
GLOBAL (ip_location.y) = EARTH_OUTER_Y;
+1 -1
View File
@@ -501,7 +501,7 @@ UninitEncounter (void)
DrawSISMessage (NULL);
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
DrawHyperCoords (GLOBAL (ShipStamp.origin));
else if (HIWORD (GLOBAL (ShipStamp.frame)) == 0)
else if (GLOBAL (ip_planet) == 0)
DrawHyperCoords (CurStarDescPtr->star_pt);
else
DrawSISTitle(GLOBAL_SIS (PlanetName));
+3
View File
@@ -960,6 +960,9 @@ typedef struct
POINT autopilot;
POINT ip_location;
STAMP ShipStamp;
UWORD ShipFacing;
BYTE ip_planet;
BYTE in_orbit;
VELOCITY_DESC velocity;
DWORD BattleGroupRef;
+4 -2
View File
@@ -446,7 +446,9 @@ unhyper_transition (ELEMENT *ElementPtr)
GLOBAL (CurrentActivity) |= START_ENCOUNTER;
break;
case INTERPLANETARY_TRANSITION:
GLOBAL (ShipStamp.frame) = 0;
GLOBAL (ip_planet) = 0;
GLOBAL (in_orbit) = 0;
GLOBAL (ShipFacing) = 0; /* Not reentering the system */
SET_GAME_STATE (USED_BROADCASTER, 0);
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
{
@@ -505,7 +507,7 @@ unhyper_transition (ELEMENT *ElementPtr)
* or HyperSpace from QuasiSpace through the periodically
* opening portal.
*/
GLOBAL (ShipStamp.frame) = 0;
GLOBAL (ShipFacing) = 0; /* Not reentering the system */
SET_GAME_STATE (USED_BROADCASTER, 0);
GLOBAL (autopilot.x) = ~0;
GLOBAL (autopilot.y) = ~0;
+3 -3
View File
@@ -380,7 +380,6 @@ static void
LoadGameState (GAME_STATE *GSPtr, DECODE_REF fh)
{
BYTE dummy8;
DWORD tmpd;
cread_8 (fh, &dummy8); /* obsolete */
cread_8 (fh, &GSPtr->glob_flags);
@@ -401,8 +400,9 @@ LoadGameState (GAME_STATE *GSPtr, DECODE_REF fh)
/* STAMP ShipStamp */
cread_16 (fh, &GSPtr->ShipStamp.origin.x);
cread_16 (fh, &GSPtr->ShipStamp.origin.y);
cread_32 (fh, &tmpd); /* abused ptr to store DWORD */
GSPtr->ShipStamp.frame = (FRAME)tmpd;
cread_16 (fh, &GSPtr->ShipFacing);
cread_8 (fh, &GSPtr->ip_planet);
cread_8 (fh, &GSPtr->in_orbit);
/* VELOCITY_DESC velocity */
cread_16 (fh, &GSPtr->velocity.TravelAngle);
+8 -9
View File
@@ -224,13 +224,10 @@ LoadSolarSys (void)
};
pSolarSysState->MenuState.CurState = 0;
pSolarSysState->MenuState.Initialized =
HIBYTE (HIWORD (GLOBAL (ShipStamp.frame)));
pSolarSysState->MenuState.Initialized = GLOBAL (in_orbit);
if (pSolarSysState->MenuState.Initialized)
{
GLOBAL (ShipStamp.frame) = (FRAME)MAKE_DWORD (
LOWORD (GLOBAL (ShipStamp.frame)),
LOBYTE (HIWORD (GLOBAL (ShipStamp.frame))));
GLOBAL (in_orbit) = 0;
++pSolarSysState->MenuState.Initialized;
}
else
@@ -324,7 +321,7 @@ LoadSolarSys (void)
sort_array[i + 1];
}
i = LOBYTE (HIWORD (GLOBAL (ShipStamp.frame)));
i = GLOBAL (ip_planet);
if (i == 0)
pSolarSysState->pBaseDesc =
pSolarSysState->pOrbitalDesc = pSolarSysState->PlanetDesc;
@@ -372,7 +369,8 @@ LoadSolarSys (void)
}
else
{
i = LOWORD (GLOBAL (ShipStamp.frame));
i = GLOBAL (ShipFacing);
// XXX: Solar system reentry test depends on ShipFacing != 0
if (i == 0)
++i;
@@ -1433,7 +1431,7 @@ InitSolarSys (void)
pSolarSysState->MenuState.InputFunc = DoFlagshipCommands;
Reentry = (BOOLEAN)(GLOBAL (ShipStamp.frame) != 0);
Reentry = (GLOBAL (ShipFacing) != 0);
if (!Reentry)
{
GLOBAL (autopilot.x) = ~0;
@@ -1540,7 +1538,8 @@ UninitSolarSys (void)
else if ((GLOBAL (CurrentActivity) & START_ENCOUNTER) && EncounterGroup)
{
GetGroupInfo (GLOBAL (BattleGroupRef), EncounterGroup);
if (HIWORD (GLOBAL (ShipStamp.frame)) == 0)
// Generate the encounter location name based on the closest planet
if (GLOBAL (ip_planet) == 0)
{
BYTE i;
DWORD best_dist;
+8 -7
View File
@@ -367,7 +367,10 @@ SaveGameState (const GAME_STATE *GSPtr, DECODE_REF fh)
/* STAMP ShipStamp */
cwrite_16 (fh, GSPtr->ShipStamp.origin.x);
cwrite_16 (fh, GSPtr->ShipStamp.origin.y);
cwrite_32 (fh, (DWORD)GSPtr->ShipStamp.frame); /* abused ptr to store DWORD */
cwrite_16 (fh, GSPtr->ShipFacing);
cwrite_8 (fh, GSPtr->ip_planet);
cwrite_8 (fh, GSPtr->in_orbit);
/* VELOCITY_DESC velocity */
cwrite_16 (fh, GSPtr->velocity.TravelAngle);
cwrite_16 (fh, GSPtr->velocity.vector.width);
@@ -648,7 +651,6 @@ RetrySave:
GAME_STATE_FILE *fp;
DWORD flen;
COUNT num_links;
FRAME frame;
POINT pt;
STAR_DESC SD;
char buf[256], file[PATH_MAX];
@@ -659,9 +661,7 @@ RetrySave:
else
memset (&SD, 0, sizeof (SD));
// XXX: Backup: ShipStamp.frame is abused to store DWORD info
// SaveFlagshipState() overwrites it with a DWORD value
frame = GLOBAL (ShipStamp.frame);
// XXX: Backup: SaveFlagshipState() overwrites ip_location
pt = GLOBAL (ip_location);
SaveFlagshipState ();
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY
@@ -671,9 +671,10 @@ RetrySave:
SaveGameState (&GlobData.Game_state, fh);
// XXX: Restore
GLOBAL (ip_location) = pt;
// XXX: Restore: ShipStamp.frame is abused to store DWORD info
GLOBAL (ShipStamp.frame) = frame;
// Only relevant when loading a game and must be cleaned
GLOBAL (in_orbit) = 0;
SaveRaceQueue (fh, &GLOBAL (avail_race_q));
// START_INTERPLANETARY is only set when saving from Homeworld
+8 -6
View File
@@ -454,15 +454,17 @@ spawn_ship (STARSHIP *StarShipPtr)
{
StarShipPtr->ShipFacing = NORMALIZE_FACING (TFB_Random ());
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
{
COUNT facing;
facing = LOWORD (GLOBAL (ShipStamp.frame));
{ // Only one ship is ever spawned in HyperSpace -- flagship
COUNT facing = GLOBAL (ShipFacing);
// XXX: Solar system reentry test depends on ShipFacing != 0
if (facing > 0)
--facing;
GLOBAL (ShipStamp.frame) = (FRAME)MAKE_DWORD (
StarShipPtr->ShipFacing + 1, 0);
// XXX: This appears to set the facing to a random value
// for when the ship returns from an encounter back
// to HyperSpace. However, it is overwritten later
// in sis.c. See also r1614.
//GLOBAL (ShipFacing) = StarShipPtr->ShipFacing + 1;
StarShipPtr->ShipFacing = facing;
}
ShipElementPtr->current.image.frame =
+14 -19
View File
@@ -1588,7 +1588,7 @@ SaveFlagshipState (void)
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE)
{
// Player is in HyperSpace or QuasiSpace.
// Update 'GLOBAL (ShipStamp.frame)' to the direction the flagship
// Update 'GLOBAL (ShipFacing)' to the direction the flagship
// is facing.
HELEMENT hElement, hNextElement;
@@ -1606,8 +1606,8 @@ SaveFlagshipState (void)
STARSHIP *StarShipPtr;
GetElementStarShip (ElementPtr, &StarShipPtr);
GLOBAL (ShipStamp.frame) = (FRAME)MAKE_DWORD (
StarShipPtr->ShipFacing + 1, 0);
// XXX: Solar system reentry test depends on ShipFacing != 0
GLOBAL (ShipFacing) = StarShipPtr->ShipFacing + 1;
hNextElement = 0;
}
UnlockElement (hElement);
@@ -1616,22 +1616,19 @@ SaveFlagshipState (void)
else if (pSolarSysState)
{
// Player is in a solar system.
UWORD index1, index2;
FRAME frame;
frame = GLOBAL (ShipStamp.frame);
if (pSolarSysState->MenuState.Initialized < 3)
{
index1 = GetFrameIndex (frame) + 1;
// 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)
{
index2 = 0;
GLOBAL (ip_planet) = 0;
}
else
{
index2 = (UWORD)(pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 1);
GLOBAL (ip_planet) = pSolarSysState->pBaseDesc->pPrevDesc
- pSolarSysState->PlanetDesc + 1;
GLOBAL (ip_location) =
pSolarSysState->SunDesc[0].location;
}
@@ -1639,6 +1636,7 @@ SaveFlagshipState (void)
else
{
// In orbit around a planet.
BYTE moon;
// Update the starinfo.dat file if necessary.
if (GET_GAME_STATE (PLANETARY_CHANGE))
@@ -1647,17 +1645,14 @@ SaveFlagshipState (void)
SET_GAME_STATE (PLANETARY_CHANGE, 0);
}
index1 = LOWORD (frame);
index2 = 1;
// GLOBAL (ip_planet) is already set
moon = 1; /* the planet itself */
if (pSolarSysState->pOrbitalDesc !=
pSolarSysState->pBaseDesc->pPrevDesc)
index2 += pSolarSysState->pOrbitalDesc
moon += pSolarSysState->pOrbitalDesc
- pSolarSysState->pBaseDesc + 1;
index2 = MAKE_WORD (HIWORD (frame), index2);
GLOBAL (in_orbit) = moon;
}
GLOBAL (ShipStamp.frame) =
(FRAME)MAKE_DWORD (index1, index2);
}
}
+3 -1
View File
@@ -483,7 +483,9 @@ doInstantMove (void)
GLOBAL (CurrentActivity) &= ~IN_BATTLE;
// Enter IP:
GLOBAL (ShipStamp.frame) = 0;
GLOBAL (ShipFacing) = 0;
GLOBAL (ip_planet) = 0;
GLOBAL (in_orbit) = 0;
// This causes the ship position in IP to be reset.
GLOBAL (CurrentActivity) |= START_INTERPLANETARY;
}