diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 2fcb9d990..32b1e4877 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -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 diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index aab24d644..7dbe94c11 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -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)); diff --git a/sc2/src/sc2code/comm/chmmr/chmmrc.c b/sc2/src/sc2code/comm/chmmr/chmmrc.c index e9c051033..0799f9804 100644 --- a/sc2/src/sc2code/comm/chmmr/chmmrc.c +++ b/sc2/src/sc2code/comm/chmmr/chmmrc.c @@ -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; diff --git a/sc2/src/sc2code/encount.c b/sc2/src/sc2code/encount.c index 958544ed4..13ee4f603 100644 --- a/sc2/src/sc2code/encount.c +++ b/sc2/src/sc2code/encount.c @@ -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)); diff --git a/sc2/src/sc2code/globdata.h b/sc2/src/sc2code/globdata.h index 228a18503..2997b5594 100644 --- a/sc2/src/sc2code/globdata.h +++ b/sc2/src/sc2code/globdata.h @@ -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; diff --git a/sc2/src/sc2code/hyper.c b/sc2/src/sc2code/hyper.c index 4e06083cc..c958a6843 100644 --- a/sc2/src/sc2code/hyper.c +++ b/sc2/src/sc2code/hyper.c @@ -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; diff --git a/sc2/src/sc2code/load.c b/sc2/src/sc2code/load.c index ec2e9035f..bf5b8f2d0 100644 --- a/sc2/src/sc2code/load.c +++ b/sc2/src/sc2code/load.c @@ -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); diff --git a/sc2/src/sc2code/planets/solarsys.c b/sc2/src/sc2code/planets/solarsys.c index d429ab24b..9b41007a1 100644 --- a/sc2/src/sc2code/planets/solarsys.c +++ b/sc2/src/sc2code/planets/solarsys.c @@ -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; diff --git a/sc2/src/sc2code/save.c b/sc2/src/sc2code/save.c index 604e74f8c..c6db424a7 100644 --- a/sc2/src/sc2code/save.c +++ b/sc2/src/sc2code/save.c @@ -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 diff --git a/sc2/src/sc2code/ship.c b/sc2/src/sc2code/ship.c index 060b5e225..7dba8e892 100644 --- a/sc2/src/sc2code/ship.c +++ b/sc2/src/sc2code/ship.c @@ -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 = diff --git a/sc2/src/sc2code/sis.c b/sc2/src/sc2code/sis.c index aa69efcf8..5aaffbad3 100644 --- a/sc2/src/sc2code/sis.c +++ b/sc2/src/sc2code/sis.c @@ -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,7 +1636,8 @@ 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); } } diff --git a/sc2/src/sc2code/uqmdebug.c b/sc2/src/sc2code/uqmdebug.c index f5be6c551..a1e417024 100644 --- a/sc2/src/sc2code/uqmdebug.c +++ b/sc2/src/sc2code/uqmdebug.c @@ -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; }