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