diff --git a/sc2/src/uqm/Makeinfo b/sc2/src/uqm/Makeinfo index aaee0cc99..92081201a 100644 --- a/sc2/src/uqm/Makeinfo +++ b/sc2/src/uqm/Makeinfo @@ -3,17 +3,13 @@ uqm_CFILES="battle.c battlecontrols.c border.c build.c cleanup.c clock.c cnctdlg.c collide.c comm.c commanim.c commglue.c confirm.c credits.c cyborg.c demo.c displist.c dummy.c encount.c flash.c fmv.c galaxy.c gameev.c gameinp.c gameopt.c gendef.c getchar.c globdata.c gravity.c - cons_res.c grpinfo.c hyper.c init.c intel.c intro.c ipdisp.c + cons_res.c grpinfo.c hyper.c init.c intel.c intro.c ipdisp.c load.c + load_legacy.c loadship.c master.c menu.c misc.c oscill.c outfit.c pickship.c - plandata.c process.c restart.c - settings.c setup.c setupmenu.c + plandata.c process.c restart.c save.c settings.c setup.c setupmenu.c ship.c shipstat.c shipyard.c sis.c sounds.c starbase.c starcon.c starmap.c state.c status.c tactrans.c trans.c uqmdebug.c util.c - velocity.c weapon.c - " - #save.c - #load.c - #load_legacy.c + velocity.c weapon.c" uqm_HFILES="battlecontrols.h battle.h build.h clock.h cnctdlg.h coderes.h collide.h colors.h commanim.h commglue.h comm.h cons_res.h controls.h corecode.h credits.h demo.h displist.h dummy.h element.h encount.h @@ -26,7 +22,5 @@ uqm_HFILES="battlecontrols.h battle.h build.h clock.h cnctdlg.h coderes.h starmap.h units.h uqmdebug.h util.h velocity.h weapon.h" uqm_CXXFILES=" - gamestate-modern.cpp - load-modern.cpp cxxlist.cpp " diff --git a/sc2/src/uqm/comm.c b/sc2/src/uqm/comm.c index 0d8b9685e..ff2818c43 100644 --- a/sc2/src/uqm/comm.c +++ b/sc2/src/uqm/comm.c @@ -1257,7 +1257,7 @@ HailAlien (void) else { // Default titles: star name + planet name DrawSISMessage (NULL); - DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); + DrawSISTitle (GLOBAL_SIS (PlanetName)); } } @@ -1332,7 +1332,7 @@ InitCommunication (CONVERSATION which_comm) else if (GLOBAL (ip_planet) == 0) DrawHyperCoords (CurStarDescPtr->star_pt); else - DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); + DrawSISTitle (GLOBAL_SIS (PlanetName)); } } @@ -1459,7 +1459,7 @@ RaceCommunication (void) CloneShipFragment (SAMATRA_SHIP, &GLOBAL (npc_built_ship_q), 0); InitCommunication (TALKING_PET_CONVERSATION); if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) { GLOBAL (CurrentActivity) = WON_LAST_BATTLE; } @@ -1481,7 +1481,7 @@ RaceCommunication (void) InitCommunication (ILWRATH_CONVERSATION); else InitCommunication (CHMMR_CONVERSATION); - if (GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) + if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) { NextActivity = GLOBAL (CurrentActivity) & ~START_ENCOUNTER; if (LOBYTE (NextActivity) == IN_INTERPLANETARY) diff --git a/sc2/src/uqm/comm/chmmr/chmmrc.c b/sc2/src/uqm/comm/chmmr/chmmrc.c index bf9c5d49b..1b35fc0d3 100644 --- a/sc2/src/uqm/comm/chmmr/chmmrc.c +++ b/sc2/src/uqm/comm/chmmr/chmmrc.c @@ -140,7 +140,7 @@ ExitConversation (RESPONSE_REF R) SET_GAME_STATE (CHMMR_STACK, 0); SET_GAME_STATE (CHMMR_BOMB_STATE, 2); SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 0); - SET_GAME_STATE (SIS.ResUnits, 1000000L); + GLOBAL_SIS (ResUnits) = 1000000L; GLOBAL_SIS (NumLanders) = 0; GLOBAL (ModuleCost[PLANET_LANDER]) = 0; @@ -167,9 +167,9 @@ ExitConversation (RESPONSE_REF R) if (GET_GAME_STATE (STARBASE_AVAILABLE)) { /* Normal game mode - you are transported to Starbase */ - SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); - SET_GAME_STATE (SIS.CrewEnlisted, 0); - SET_GAME_STATE (SIS.TotalElementMass, 0); + GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + GLOBAL_SIS (CrewEnlisted) = 0; + GLOBAL_SIS (TotalElementMass) = 0; GLOBAL (ModuleCost[STORAGE_BAY]) = 0; /* disable Storage Bay */ for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i) GLOBAL_SIS (ElementAmounts[i]) = 0; @@ -593,9 +593,9 @@ Intro (void) construct_response (shared_phrase_buf, i_am_captain0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), i_am_captain1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), i_am_captain2, (UNICODE*)NULL); DoResponsePhrase (i_am_captain0, ChmmrFree, shared_phrase_buf); diff --git a/sc2/src/uqm/comm/comandr/comandr.c b/sc2/src/uqm/comm/comandr/comandr.c index 7a7c75daa..57df233be 100644 --- a/sc2/src/uqm/comm/comandr/comandr.c +++ b/sc2/src/uqm/comm/comandr/comandr.c @@ -145,7 +145,7 @@ ByeBye (RESPONSE_REF R) construct_response (shared_phrase_buf, name_40, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), name_41, (UNICODE*)NULL); @@ -265,7 +265,7 @@ NoRadioactives (RESPONSE_REF R) else Response (i_lost_my_lander, NoRadioactives); } - if (GET_GAME_STATE (SIS.FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) { if (GET_GAME_STATE (GIVEN_FUEL_BEFORE)) Response (need_fuel_again, NoRadioactives); @@ -330,7 +330,7 @@ AskAfterRadios (RESPONSE_REF R) else Response (i_lost_my_lander, AskAfterRadios); } - if (GET_GAME_STATE (SIS.FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) { if (GET_GAME_STATE (GIVEN_FUEL_BEFORE)) Response (need_fuel_again, AskAfterRadios); @@ -431,7 +431,7 @@ TellMoonBase (RESPONSE_REF R) else Response (i_lost_my_lander, TellMoonBase); } - if (GET_GAME_STATE (SIS.FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) { if (GET_GAME_STATE (GIVEN_FUEL_BEFORE)) Response (need_fuel_again, TellMoonBase); @@ -538,9 +538,9 @@ RevealSelf (RESPONSE_REF R) { construct_response (shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); DoResponsePhrase (we_are_vindicator0, RevealSelf, shared_phrase_buf); @@ -639,7 +639,7 @@ Intro (void) construct_response ( shared_phrase_buf, no_but_well_help0, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), no_but_well_help1, (UNICODE*)NULL); DoResponsePhrase (no_but_well_help0, NoRadioactives, shared_phrase_buf); diff --git a/sc2/src/uqm/comm/druuge/druugec.c b/sc2/src/uqm/comm/druuge/druugec.c index 7028b7bcc..9a082c115 100644 --- a/sc2/src/uqm/comm/druuge/druugec.c +++ b/sc2/src/uqm/comm/druuge/druugec.c @@ -182,12 +182,12 @@ ExitConversation (RESPONSE_REF R) if (SlaveryCount > 250 && PreviousSlaves <= 250) { if (PreviousSlaves > 100) - SET_GAME_STATE (CrewCost, GET_GAME_STATE(CrewCost) + 22 - 7); + GLOBAL (CrewCost) += (22 - 7); else - SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) + 22); + GLOBAL (CrewCost) += 22; } else if (SlaveryCount > 100 && PreviousSlaves <= 100) - SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) + 7); + GLOBAL (CrewCost) += 7; SET_GAME_STATE (CREW_SOLD_TO_DRUUGE0, LOBYTE (SlaveryCount)); SET_GAME_STATE (CREW_SOLD_TO_DRUUGE1, HIBYTE (SlaveryCount)); @@ -238,7 +238,7 @@ Buy (RESPONSE_REF R) else if (PLAYER_SAID (R, buy_druuge_ship)) { #define SHIP_CREW_COST 100 - if (GET_GAME_STATE (SIS.CrewEnlisted) < SHIP_CREW_COST) + if (GLOBAL_SIS (CrewEnlisted) < SHIP_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else if (EscortFeasibilityStudy (DRUUGE_SHIP) == 0) NPCPhrase (NOT_ENOUGH_ROOM); @@ -254,7 +254,7 @@ Buy (RESPONSE_REF R) #define ARTIFACT_CREW_COST 100 else if (PLAYER_SAID (R, buy_rosy_sphere)) { - if (GET_GAME_STATE (SIS.CrewEnlisted) < ARTIFACT_CREW_COST) + if (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else { @@ -268,7 +268,7 @@ Buy (RESPONSE_REF R) } else if (PLAYER_SAID (R, buy_art_1)) { - if (GET_GAME_STATE (SIS.CrewEnlisted) < ARTIFACT_CREW_COST) + if (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else { @@ -281,7 +281,7 @@ Buy (RESPONSE_REF R) } else if (PLAYER_SAID (R, buy_art_2)) { - if (GET_GAME_STATE (SIS.CrewEnlisted) < ARTIFACT_CREW_COST) + if (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else { @@ -295,7 +295,7 @@ Buy (RESPONSE_REF R) else if (PLAYER_SAID (R, buy_fuel)) { #define FUEL_CREW_COST 10 - if (GET_GAME_STATE (SIS.CrewEnlisted) < FUEL_CREW_COST) + if (GLOBAL_SIS (CrewEnlisted) < FUEL_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else { @@ -453,7 +453,7 @@ DoTransaction (RESPONSE_REF R) capacity += volume; } } while (slot--); - capacity -= GET_GAME_STATE (SIS.FuelOnBoard); + capacity -= GLOBAL_SIS (FuelOnBoard); f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); while (capacity > 0x3FFFL) diff --git a/sc2/src/uqm/comm/melnorm/melnorm.c b/sc2/src/uqm/comm/melnorm/melnorm.c index b8fddf588..00b6a0727 100644 --- a/sc2/src/uqm/comm/melnorm/melnorm.c +++ b/sc2/src/uqm/comm/melnorm/melnorm.c @@ -236,36 +236,32 @@ typedef enum // Define the information specifying a particular technology typedef struct { - TechId_t id; // ID of the technology - TechType_t type; // Type of the technology - const char *subtype; // Subtype of the technology - int info; // Supplemental information + TechId_t id; // ID of the technology + TechType_t type; // Type of the technology + int subtype; // Subtype of the technology + int info; // Supplemental information } TechData; -#define TECH_DATA( id, type, subtype, info ) { id, type, "HaveTech"#subtype, info } - // A table of the available technologies. // This should really be an associative map of TechIds to tech data records, // but implementing that would be excessive. static const TechData tech_data_table[] = { - // TODO: Scoop the prices out of here, and make the rest of the game start respecting the - // string-based game states. (I think prices even should go in there, eventually.) // Tech ID Tech Type, Supplemental info - TECH_DATA( TECH_MODULE_BLASTER, TECH_TYPE_MODULE, BLASTER_WEAPON, 4000 ), - TECH_DATA( TECH_LANDER_SPEED, TECH_TYPE_STATE, IMPROVED_LANDER_SPEED, 1 ), - TECH_DATA( TECH_MODULE_ANTIMISSILE, TECH_TYPE_MODULE, ANTIMISSILE_DEFENSE, 4000 ), - TECH_DATA( TECH_LANDER_SHIELD_BIO, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_BIO, -1 ), - TECH_DATA( TECH_LANDER_CARGO, TECH_TYPE_STATE, IMPROVED_LANDER_CARGO, 1 ), - TECH_DATA( TECH_MODULE_BIGFUELTANK, TECH_TYPE_MODULE, HIGHEFF_FUELSYS, 1000 ), - TECH_DATA( TECH_LANDER_RAPIDFIRE, TECH_TYPE_STATE, IMPROVED_LANDER_SHOT, 1 ), - TECH_DATA( TECH_LANDER_SHIELD_QUAKE, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_QUAKE, -1 ), - TECH_DATA( TECH_MODULE_TRACKING, TECH_TYPE_MODULE, TRACKING_SYSTEM, 5000 ), - TECH_DATA( TECH_LANDER_SHIELD_LIGHTNING, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_LIGHTNING, -1 ), - TECH_DATA( TECH_LANDER_SHIELD_HEAT, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_HEAT, -1 ), - TECH_DATA( TECH_MODULE_CANNON, TECH_TYPE_MODULE, CANNON_WEAPON, 6000 ), - TECH_DATA( TECH_MODULE_FURNACE, TECH_TYPE_MODULE, SHIVA_FURNACE, 4000 ), + { TECH_MODULE_BLASTER, TECH_TYPE_MODULE, BLASTER_WEAPON, 4000 }, + { TECH_LANDER_SPEED, TECH_TYPE_STATE, IMPROVED_LANDER_SPEED, 1 }, + { TECH_MODULE_ANTIMISSILE, TECH_TYPE_MODULE, ANTIMISSILE_DEFENSE, 4000 }, + { TECH_LANDER_SHIELD_BIO, TECH_TYPE_LANDER_SHIELD, BIOLOGICAL_DISASTER, -1 }, + { TECH_LANDER_CARGO, TECH_TYPE_STATE, IMPROVED_LANDER_CARGO, 1 }, + { TECH_MODULE_BIGFUELTANK, TECH_TYPE_MODULE, HIGHEFF_FUELSYS, 1000 }, + { TECH_LANDER_RAPIDFIRE, TECH_TYPE_STATE, IMPROVED_LANDER_SHOT, 1 }, + { TECH_LANDER_SHIELD_QUAKE, TECH_TYPE_LANDER_SHIELD, EARTHQUAKE_DISASTER, -1 }, + { TECH_MODULE_TRACKING, TECH_TYPE_MODULE, TRACKING_SYSTEM, 5000 }, + { TECH_LANDER_SHIELD_LIGHTNING, TECH_TYPE_LANDER_SHIELD, LIGHTNING_DISASTER, -1 }, + { TECH_LANDER_SHIELD_HEAT, TECH_TYPE_LANDER_SHIELD, LAVASPOT_DISASTER, -1 }, + { TECH_MODULE_CANNON, TECH_TYPE_MODULE, CANNON_WEAPON, 6000 }, + { TECH_MODULE_FURNACE, TECH_TYPE_MODULE, SHIVA_FURNACE, 4000 }, }; const size_t NUM_TECHNOLOGIES = ARRAY_SIZE (tech_data_table); @@ -286,15 +282,35 @@ GetTechData (TechId_t techId) // We have to explicitly switch on the state ID because the xxx_GAME_STATE // macros use preprocessor stringizing. static bool -HasStateTech (const char *const stateId) +HasStateTech (int stateId) { - return getGameState_json(stateId); + switch (stateId) + { + case IMPROVED_LANDER_SPEED: + return GET_GAME_STATE (IMPROVED_LANDER_SPEED); + case IMPROVED_LANDER_CARGO: + return GET_GAME_STATE (IMPROVED_LANDER_CARGO); + case IMPROVED_LANDER_SHOT: + return GET_GAME_STATE (IMPROVED_LANDER_SHOT); + } + return false; } static void -GrantStateTech (const char *const stateId) +GrantStateTech (int stateId, BYTE value) { - setGameState_json(stateId, true); + switch (stateId) + { + case IMPROVED_LANDER_SPEED: + SET_GAME_STATE (IMPROVED_LANDER_SPEED, value); + return; + case IMPROVED_LANDER_CARGO: + SET_GAME_STATE (IMPROVED_LANDER_CARGO, value); + return; + case IMPROVED_LANDER_SHOT: + SET_GAME_STATE (IMPROVED_LANDER_SHOT, value); + return; + } } static bool @@ -304,7 +320,16 @@ HasTech (TechId_t techId) if (!techData) return false; - return HasStateTech(techData->subtype); + switch (techData->type) + { + case TECH_TYPE_MODULE: + return GLOBAL (ModuleCost[techData->subtype]) != 0; + case TECH_TYPE_LANDER_SHIELD: + return (GET_GAME_STATE (LANDER_SHIELDS) & (1 << techData->subtype)) != 0; + case TECH_TYPE_STATE: + return HasStateTech (techData->subtype); + } + return false; } static void @@ -314,8 +339,21 @@ GrantTech (TechId_t techId) if (!techData) return; - - GrantStateTech (techData->subtype); + switch (techData->type) + { + case TECH_TYPE_MODULE: + GLOBAL (ModuleCost[techData->subtype]) = techData->info / MODULE_COST_SCALE; + return; + case TECH_TYPE_LANDER_SHIELD: + { + COUNT state = GET_GAME_STATE (LANDER_SHIELDS) | (1 << techData->subtype); + SET_GAME_STATE (LANDER_SHIELDS, state); + return; + } + case TECH_TYPE_STATE: + GrantStateTech (techData->subtype, techData->info); + return; + } } @@ -469,7 +507,7 @@ ShipWorth (void) } crew_pods = -(SBYTE)( - (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1) + (GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) / CREW_POD_CAPACITY ); for (i = 0; i < NUM_MODULE_SLOTS; ++i) @@ -544,7 +582,7 @@ StripShip (COUNT fuel_required) SET_GAME_STATE (MELNORME_RESCUE_REFUSED, 0); crew_pods = -(SBYTE)( - (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1) + (GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) / CREW_POD_CAPACITY ); if (fuel_required == 0) @@ -559,8 +597,8 @@ StripShip (COUNT fuel_required) GLOBAL_SIS (DriveSlots[i]) = EMPTY_SLOT + 0; for (i = 0; i < NUM_JET_SLOTS; ++i) GLOBAL_SIS (JetSlots[i]) = EMPTY_SLOT + 1; - if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE) - SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); + if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) + GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; GLOBAL_SIS (TotalBioMass) = 0; GLOBAL_SIS (TotalElementMass) = 0; for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i) @@ -969,7 +1007,7 @@ DoBuy (RESPONSE_REF R) else if (PLAYER_SAID (R, buy_25_fuel)) needed_credit = 25; else if (PLAYER_SAID (R, fill_me_up)) - needed_credit = (capacity - GET_GAME_STATE (SIS.FuelOnBoard) + needed_credit = (capacity - GLOBAL_SIS (FuelOnBoard) + FUEL_TANK_SCALE - 1) / FUEL_TANK_SCALE; @@ -983,7 +1021,7 @@ DoBuy (RESPONSE_REF R) } else { - if (GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE + if (GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE + needed_credit > capacity / FUEL_TANK_SCALE) { NPCPhrase (NO_ROOM_FOR_FUEL); @@ -1009,7 +1047,7 @@ DoBuy (RESPONSE_REF R) if (needed_credit) { DeltaCredit (-needed_credit); - if (GET_GAME_STATE (SIS.FuelOnBoard) >= capacity) + if (GLOBAL_SIS (FuelOnBoard) >= capacity) goto BuyBuyBuy; } TryFuelAgain: @@ -1120,7 +1158,7 @@ TryFuelAgain: NPCPhrase (WHAT_TO_BUY); BuyBuyBuy: - if (GET_GAME_STATE (SIS.FuelOnBoard) < capacity) + if (GLOBAL_SIS (FuelOnBoard) < capacity) Response (buy_fuel, DoBuy); if (GetNextTechForSale ()) Response (buy_technology, DoBuy); @@ -1283,7 +1321,7 @@ NatureOfConversation (RESPONSE_REF R) rainbow_mask >>= 1; } - if (GET_GAME_STATE (SIS.FuelOnBoard) > 0 + if (GLOBAL_SIS (FuelOnBoard) > 0 || GLOBAL_SIS (TotalBioMass) || Credit || num_new_rainbows) diff --git a/sc2/src/uqm/comm/orz/orzc.c b/sc2/src/uqm/comm/orz/orzc.c index 35f4d1f91..72076a67a 100644 --- a/sc2/src/uqm/comm/orz/orzc.c +++ b/sc2/src/uqm/comm/orz/orzc.c @@ -542,9 +542,9 @@ OrzNeutral (RESPONSE_REF R) { construct_response (shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); pStr[1] = we_are_vindicator0; diff --git a/sc2/src/uqm/comm/pkunk/pkunkc.c b/sc2/src/uqm/comm/pkunk/pkunkc.c index 6dadfd5f3..5db575d4a 100644 --- a/sc2/src/uqm/comm/pkunk/pkunkc.c +++ b/sc2/src/uqm/comm/pkunk/pkunkc.c @@ -623,9 +623,9 @@ PkunkHome (RESPONSE_REF R) { construct_response (shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); DoResponsePhrase (we_are_vindicator0, OfferAlliance, shared_phrase_buf); diff --git a/sc2/src/uqm/comm/shofixt/shofixt.c b/sc2/src/uqm/comm/shofixt/shofixt.c index 40781550c..e76d8d0a6 100644 --- a/sc2/src/uqm/comm/shofixt/shofixt.c +++ b/sc2/src/uqm/comm/shofixt/shofixt.c @@ -351,11 +351,11 @@ RealizeMistake (RESPONSE_REF R) construct_response ( shared_phrase_buf, i_am_captain0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), i_am_captain1, buf, i_am_captain2, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), i_am_captain3, (UNICODE*)NULL); } diff --git a/sc2/src/uqm/comm/slyhome/slyhome.c b/sc2/src/uqm/comm/slyhome/slyhome.c index d3634060c..80cb83979 100644 --- a/sc2/src/uqm/comm/slyhome/slyhome.c +++ b/sc2/src/uqm/comm/slyhome/slyhome.c @@ -757,9 +757,9 @@ HomeWorld (RESPONSE_REF R) case 0: construct_response (shared_phrase_buf, we_are_us0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_us1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_us2, (UNICODE*)NULL); pStr[0] = we_are_us0; diff --git a/sc2/src/uqm/comm/spahome/spahome.c b/sc2/src/uqm/comm/spahome/spahome.c index 053154258..190e3bb38 100644 --- a/sc2/src/uqm/comm/spahome/spahome.c +++ b/sc2/src/uqm/comm/spahome/spahome.c @@ -883,9 +883,9 @@ SpathiPassword (RESPONSE_REF R) { construct_response (shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); DoResponsePhrase (we_are_vindicator0, ExitConversation, shared_phrase_buf); diff --git a/sc2/src/uqm/comm/starbas/starbas.c b/sc2/src/uqm/comm/starbas/starbas.c index b78eb426a..5f25a2dba 100644 --- a/sc2/src/uqm/comm/starbas/starbas.c +++ b/sc2/src/uqm/comm/starbas/starbas.c @@ -664,8 +664,8 @@ AnalyzeCondition (void) num_guns += 2; HasMinimum = (num_thrusters >= 7 && num_jets >= 5 - && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY - && GET_GAME_STATE (SIS.FuelOnBoard) >= FUEL_TANK_CAPACITY + && GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY + && GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY && num_bays >= 1 && GLOBAL_SIS (NumLanders) && num_batts >= 1 && num_guns >= 2); NPCPhrase (LETS_SEE); @@ -678,9 +678,9 @@ AnalyzeCondition (void) NPCPhrase (NEED_TURN_1); if (num_guns < 2) NPCPhrase (NEED_GUNS_1); - if (GET_GAME_STATE (SIS.CrewEnlisted) < CREW_POD_CAPACITY) + if (GLOBAL_SIS (CrewEnlisted) < CREW_POD_CAPACITY) NPCPhrase (NEED_CREW_1); - if (GET_GAME_STATE (SIS.FuelOnBoard) < FUEL_TANK_CAPACITY) + if (GLOBAL_SIS (FuelOnBoard) < FUEL_TANK_CAPACITY) NPCPhrase (NEED_FUEL_1); if (num_bays < 1) NPCPhrase (NEED_STORAGE_1); @@ -689,7 +689,7 @@ AnalyzeCondition (void) if (num_batts < 1) NPCPhrase (NEED_DYNAMOS_1); - if (GET_GAME_STATE (SIS.ResUnits) >= 3000) + if (GLOBAL_SIS (ResUnits) >= 3000) NPCPhrase (IMPROVE_FLAGSHIP_WITH_RU); else NPCPhrase (GO_GET_MINERALS); @@ -709,9 +709,9 @@ AnalyzeCondition (void) HasMaximum = (num_thrusters == NUM_DRIVE_SLOTS && num_jets == NUM_JET_SLOTS - && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY * 3 - && GET_GAME_STATE (SIS.FuelOnBoard) >= FUEL_TANK_CAPACITY * 3 - && GET_GAME_STATE (SIS.NumLanders) >= 3 + && GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY * 3 + && GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY * 3 + && GLOBAL_SIS (NumLanders) >= 3 && num_batts >= 4 && num_guns >= 7 && num_defense >= 2); if (!HasMaximum && GET_GAME_STATE (CHMMR_BOMB_STATE) < 2) NPCPhrase (GOT_OK_FLAGSHIP); @@ -739,7 +739,7 @@ AnalyzeCondition (void) NPCPhrase (MADE_SOME_ALLIES); if (FleetStrength < 6000) { - if (GET_GAME_STATE (SIS.ResUnits) >= 3000) + if (GLOBAL_SIS (ResUnits) >= 3000) NPCPhrase (BUY_COMBAT_SHIPS); else NPCPhrase (GET_SHIPS_BY_MINING_OR_ALLIANCE); @@ -756,9 +756,9 @@ AnalyzeCondition (void) NPCPhrase (NEED_TURN_2); if (num_guns < 7) NPCPhrase (NEED_GUNS_2); - if (GET_GAME_STATE (SIS.CrewEnlisted) < CREW_POD_CAPACITY * 3) + if (GLOBAL_SIS (CrewEnlisted) < CREW_POD_CAPACITY * 3) NPCPhrase (NEED_CREW_2); - if (GET_GAME_STATE (SIS.FuelOnBoard) < FUEL_TANK_CAPACITY * 3) + if (GLOBAL_SIS (FuelOnBoard) < FUEL_TANK_CAPACITY * 3) NPCPhrase (NEED_FUEL_2); if (GLOBAL_SIS (NumLanders) < 3) NPCPhrase (NEED_LANDERS_1); @@ -953,7 +953,7 @@ TellStarBase (RESPONSE_REF R) construct_response ( buf0, tell_me_about_modules0, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), tell_me_about_modules1, (UNICODE*)NULL); pstack[0] = tell_me_about_modules0; @@ -968,7 +968,7 @@ TellStarBase (RESPONSE_REF R) construct_response ( shared_phrase_buf, tell_me_about_fuel0, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), tell_me_about_fuel1, (UNICODE*)NULL); pstack[1] = tell_me_about_fuel0; diff --git a/sc2/src/uqm/comm/supox/supoxc.c b/sc2/src/uqm/comm/supox/supoxc.c index 931b41f0d..e169cbab7 100644 --- a/sc2/src/uqm/comm/supox/supoxc.c +++ b/sc2/src/uqm/comm/supox/supoxc.c @@ -424,7 +424,7 @@ NeutralSupox (RESPONSE_REF R) case 0: construct_response (shared_phrase_buf, i_am0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), i_am1, (UNICODE*)NULL); pStr[0] = i_am0; @@ -433,7 +433,7 @@ NeutralSupox (RESPONSE_REF R) case 1: construct_response (shared_phrase_buf, my_ship0, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), my_ship1, (UNICODE*)NULL); pStr[0] = my_ship0; diff --git a/sc2/src/uqm/comm/syreen/syreenc.c b/sc2/src/uqm/comm/syreen/syreenc.c index 3ca05e093..8884ad6b0 100644 --- a/sc2/src/uqm/comm/syreen/syreenc.c +++ b/sc2/src/uqm/comm/syreen/syreenc.c @@ -793,9 +793,9 @@ Intro (void) { construct_response (shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); Response (we_are_vice_squad, InitialSyreen); diff --git a/sc2/src/uqm/comm/talkpet/talkpet.c b/sc2/src/uqm/comm/talkpet/talkpet.c index 473389e7c..ce59011b7 100644 --- a/sc2/src/uqm/comm/talkpet/talkpet.c +++ b/sc2/src/uqm/comm/talkpet/talkpet.c @@ -520,7 +520,7 @@ CompelPlayer (RESPONSE_REF R) construct_response ( shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator1, (UNICODE*)NULL); pStr[2] = we_are_vindicator0; diff --git a/sc2/src/uqm/comm/thradd/thraddc.c b/sc2/src/uqm/comm/thradd/thraddc.c index d11fbe1f0..1be8a1e4a 100644 --- a/sc2/src/uqm/comm/thradd/thraddc.c +++ b/sc2/src/uqm/comm/thradd/thraddc.c @@ -489,7 +489,7 @@ ThraddCulture (RESPONSE_REF R) construct_response ( shared_phrase_buf, the_slave_empire0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), the_slave_empire1, (UNICODE*)NULL); diff --git a/sc2/src/uqm/comm/umgah/umgahc.c b/sc2/src/uqm/comm/umgah/umgahc.c index 2bd9333b6..d9debd540 100644 --- a/sc2/src/uqm/comm/umgah/umgahc.c +++ b/sc2/src/uqm/comm/umgah/umgahc.c @@ -368,9 +368,9 @@ Zombies (RESPONSE_REF R) { construct_response (shared_phrase_buf, we_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_vindicator2, (UNICODE*)NULL); pStr[1] = we_vindicator0; diff --git a/sc2/src/uqm/comm/utwig/utwigc.c b/sc2/src/uqm/comm/utwig/utwigc.c index dc70e0dbb..53bacbb26 100644 --- a/sc2/src/uqm/comm/utwig/utwigc.c +++ b/sc2/src/uqm/comm/utwig/utwigc.c @@ -558,7 +558,7 @@ NeutralUtwig (RESPONSE_REF R) construct_response ( shared_phrase_buf, we_are_vindicator0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), we_are_vindicator1, buf, we_are_vindicator2, diff --git a/sc2/src/uqm/comm/yehat/yehatc.c b/sc2/src/uqm/comm/yehat/yehatc.c index 3e46530d9..c1860bf16 100644 --- a/sc2/src/uqm/comm/yehat/yehatc.c +++ b/sc2/src/uqm/comm/yehat/yehatc.c @@ -379,11 +379,11 @@ YehatHome (RESPONSE_REF R) construct_response ( shared_phrase_buf, i_demand_you_ally_homeworld0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), i_demand_you_ally_homeworld1, buf, i_demand_you_ally_homeworld2, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), i_demand_you_ally_homeworld3, (UNICODE*)NULL); DoResponsePhrase (i_demand_you_ally_homeworld0, @@ -505,9 +505,9 @@ YehatSpace (RESPONSE_REF R) construct_response ( shared_phrase_buf, i_demand_you_ally_space0, - GET_GAME_STATE_STRING (SIS.CommanderName), + GLOBAL_SIS (CommanderName), i_demand_you_ally_space1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), i_demand_you_ally_space2, buf, i_demand_you_ally_space3, diff --git a/sc2/src/uqm/comm/zoqfot/zoqfotc.c b/sc2/src/uqm/comm/zoqfot/zoqfotc.c index 727116ce8..d09a7f7bb 100644 --- a/sc2/src/uqm/comm/zoqfot/zoqfotc.c +++ b/sc2/src/uqm/comm/zoqfot/zoqfotc.c @@ -427,7 +427,7 @@ AquaintZoqFot (RESPONSE_REF R) we_are_vindicator0, buf, we_are_vindicator1, - GET_GAME_STATE_STRING (SIS.ShipName), + GLOBAL_SIS (ShipName), we_are_vindicator2, (UNICODE*)NULL); } diff --git a/sc2/src/uqm/commglue.c b/sc2/src/uqm/commglue.c index b30e07a9a..a7b514ccb 100644 --- a/sc2/src/uqm/commglue.c +++ b/sc2/src/uqm/commglue.c @@ -35,21 +35,18 @@ static int NPCNumberPhrase (int number, const char *fmt, UNICODE **ptrack); void NPCPhrase_cb (int index, CallbackFunction cb) { - UNICODE *pStr; - UNICODE buf[400]; + UNICODE *pStr, buf[400]; void *pClip, *pTimeStamp; switch (index) { case GLOBAL_PLAYER_NAME: - strcpy (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); - pStr = buf; + pStr = GLOBAL_SIS (CommanderName); pClip = 0; pTimeStamp = 0; break; case GLOBAL_SHIP_NAME: - strcpy (buf, GET_GAME_STATE_STRING (SIS.ShipName)); - pStr = buf; + pStr = GLOBAL_SIS (ShipName); pClip = 0; pTimeStamp = 0; break; @@ -69,7 +66,7 @@ NPCPhrase_cb (int index, CallbackFunction cb) S = SetAbsStringTableIndex (CommData.ConversationPhrases, (index - 1) + i); strcpy (buf, (UNICODE *)GetStringAddress (S)); if (i == 3) - strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); + strcat (buf, GLOBAL_SIS (CommanderName)); pStr = buf; pClip = 0; @@ -255,7 +252,7 @@ GetAllianceName (UNICODE *buf, RESPONSE_REF name_1) strcpy (buf, (UNICODE *)GetStringAddress (S)); if (i == 3) { - strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); + strcat (buf, GLOBAL_SIS (CommanderName)); strcat (buf, (UNICODE *)GetStringAddress (SetRelStringTableIndex (S, 1))); } } @@ -332,7 +329,7 @@ setSegue (Segue segue) break; case Segue_defeat: SET_GAME_STATE (BATTLE_SEGUE, 0); - SET_GAME_STATE(SIS.CrewEnlisted, (COUNT)~0); + GLOBAL_SIS(CrewEnlisted) = (COUNT)~0; GLOBAL(CurrentActivity) |= CHECK_RESTART; break; } @@ -342,7 +339,7 @@ Segue getSegue (void) { if (GET_GAME_STATE(BATTLE_SEGUE) == 0) { - if (GET_GAME_STATE(SIS.CrewEnlisted) == (COUNT)~0 && + if (GLOBAL_SIS(CrewEnlisted) == (COUNT)~0 && (GLOBAL(CurrentActivity) & CHECK_RESTART)) { return Segue_defeat; } else { diff --git a/sc2/src/uqm/encount.c b/sc2/src/uqm/encount.c index 18373147e..9ab75c5a1 100644 --- a/sc2/src/uqm/encount.c +++ b/sc2/src/uqm/encount.c @@ -322,7 +322,7 @@ InitEncounter (void) t.CharCount = (COUNT)~0; font_DrawText (&t); t.baseline.y += 12; - t.pStr = GET_GAME_STATE_STRING (SIS.PlanetName); + t.pStr = GLOBAL_SIS (PlanetName); t.CharCount = (COUNT)~0; font_DrawText (&t); } @@ -482,7 +482,7 @@ UninitEncounter (void) free_gravity_well (); if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0 + || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 || LOBYTE (GLOBAL (CurrentActivity)) == IN_LAST_BATTLE || LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE) goto ExitUninitEncounter; @@ -572,7 +572,7 @@ UninitEncounter (void) else if (GLOBAL (ip_planet) == 0) DrawHyperCoords (CurStarDescPtr->star_pt); else - DrawSISTitle(GET_GAME_STATE_STRING (SIS.PlanetName)); + DrawSISTitle(GLOBAL_SIS (PlanetName)); SetContext (SpaceContext); if (VictoryState) @@ -822,7 +822,7 @@ EncounterBattle (void) GameSounds = 0; if (GLOBAL (CurrentActivity) & CHECK_ABORT) - SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0); + GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; if (GLOBAL (glob_flags) & CYBORG_ENABLED) { diff --git a/sc2/src/uqm/gameev.c b/sc2/src/uqm/gameev.c index b04493369..352bafc93 100644 --- a/sc2/src/uqm/gameev.c +++ b/sc2/src/uqm/gameev.c @@ -120,7 +120,7 @@ EventHandler (BYTE selector) break; case SHOFIXTI_RETURN_EVENT: SetRaceAllied (SHOFIXTI_SHIP, TRUE); - SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) - 2); + GLOBAL (CrewCost) -= 2; /* crew is not an issue anymore */ SET_GAME_STATE (CREW_PURCHASED0, 0); SET_GAME_STATE (CREW_PURCHASED1, 0); @@ -369,7 +369,7 @@ black_urquan_genocide (void) { // All spheres of influence are gone - game over. GLOBAL (CurrentActivity) &= ~IN_BATTLE; - SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0); + GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; SET_GAME_STATE (KOHR_AH_KILLED_ALL, 1); } diff --git a/sc2/src/uqm/gameopt.c b/sc2/src/uqm/gameopt.c index 5429824f2..ba42a3b1e 100644 --- a/sc2/src/uqm/gameopt.c +++ b/sc2/src/uqm/gameopt.c @@ -315,8 +315,7 @@ NameCaptainOrShip (bool nameCaptain) { UNICODE buf[MAX_NAME_SIZE] = ""; TEXTENTRY_STATE tes; - const UNICODE *Setting; - const UNICODE *Old; + UNICODE *Setting; SetContext (StatusContext); SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect); @@ -327,15 +326,14 @@ NameCaptainOrShip (bool nameCaptain) if (nameCaptain) { - Setting = "SIS.CommanderName"; - tes.MaxSize = SIS_NAME_SIZE; + Setting = GLOBAL_SIS (CommanderName); + tes.MaxSize = sizeof (GLOBAL_SIS (CommanderName)); } else { - Setting = "SIS.ShipName"; - tes.MaxSize = SIS_NAME_SIZE; + Setting = GLOBAL_SIS (ShipName); + tes.MaxSize = sizeof (GLOBAL_SIS (ShipName)); } - Old= getGameState_string_json( Setting ); // text entry setup tes.Initialized = FALSE; @@ -346,12 +344,9 @@ NameCaptainOrShip (bool nameCaptain) tes.FrameCallback = 0; if (DoTextEntry (&tes)) - { - buf[ tes.MaxSize ]= '\0'; - setGameState_string_json( Setting, buf ); - } + utf8StringCopy (Setting, tes.MaxSize, buf); else - utf8StringCopy (buf, sizeof (buf), Old); + utf8StringCopy (buf, sizeof (buf), Setting); SetFlashRect (SFR_MENU_3DO); @@ -736,11 +731,6 @@ DrawSavegameCargo (SIS_STATE *sisState) static void DrawSavegameSummary (PICK_GAME_STATE *pickState, COUNT gameIndex) { - return; -// FIXME(ADAM): This needs to be totally rewritten once the new JSON -// save format is ready. It makes more sense to get everything into JSON -// and then just rewrite this. -#if 0 SUMMARY_DESC *pSD = pickState->summary + gameIndex; RECT r; STAMP s; @@ -944,7 +934,6 @@ DrawSavegameSummary (PICK_GAME_STATE *pickState, COUNT gameIndex) } UnbatchGraphics (); -#endif } static void diff --git a/sc2/src/uqm/gamestate-modern.cpp b/sc2/src/uqm/gamestate-modern.cpp deleted file mode 100644 index ec9501b25..000000000 --- a/sc2/src/uqm/gamestate-modern.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#define COMPILING_GLOBDATA -#include "uqm/globdata.h" -#undef COMPILING_GLOBDATA - -#include - -#include -#include - -namespace GameState -{ - namespace - { - // TODO: Convert all this to a true JSON map in memory? - auto & - gameState() - { - static std::map< std::string, std::uint32_t > rv; - - return rv; - } - - auto & - gameStateString() - { - static std::map< std::string, std::string > rv; - - return rv; - } - } - - void - create( const std::string &name ) - { - std::ignore= gameState()[ name ]; - } - - void - createString( const std::string &name ) - { - std::ignore= gameStateString()[ name ]; - } - - std::uint32_t & - get( const std::string &name ) - { - return gameState().at( name ); - } - - std::string & - getString( const std::string &name ) - { - return gameStateString().at( name ); - } -} - -const std::map< std::string, std::uint32_t > & -GameState::getFullGameState() -{ - return gameState(); -} - -const std::map< std::string, std::string > & -GameState::getFullGameStateString() -{ - return gameStateString(); -} - -extern "C" -{ - void - addGameState_json( const char *const stateName ) - { - GameState::create( stateName ); - } - - std::uint32_t - getGameState_json( const char *const stateName ) - { - return GameState::get( stateName ); - } - - void - setGameState_json( const char *const stateName, - const std::uint32_t val ) - { - GameState::get( stateName )= val; - } - - - void - addGameState_string_json( const char *const stateName ) - { - GameState::createString( stateName ); - } - - const char * - getGameState_string_json( const char *const stateName ) - { - return GameState::getString( stateName ).c_str(); - } - - void - setGameState_string_json( const char *const stateName, - const char *const val ) - { - GameState::getString( stateName )= val; - } -} - diff --git a/sc2/src/uqm/globdata.c b/sc2/src/uqm/globdata.c index 37df6db16..4bf14f8da 100644 --- a/sc2/src/uqm/globdata.c +++ b/sc2/src/uqm/globdata.c @@ -317,10 +317,10 @@ InitGameStructures (void) GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2; GLOBAL_SIS (ModuleSlots[15]) = GUN_WEAPON; GLOBAL_SIS (ModuleSlots[2]) = CREW_POD; - SET_GAME_STATE (SIS.CrewEnlisted, CREW_POD_CAPACITY); + GLOBAL_SIS (CrewEnlisted) = CREW_POD_CAPACITY; GLOBAL_SIS (ModuleSlots[8]) = STORAGE_BAY; GLOBAL_SIS (ModuleSlots[1]) = FUEL_TANK; - SET_GAME_STATE (SIS.FuelOnBoard, 10 * FUEL_TANK_SCALE); + GLOBAL_SIS (FuelOnBoard) = 10 * FUEL_TANK_SCALE; InitQueue (&GLOBAL (built_ship_q), MAX_BUILT_SHIPS, sizeof (SHIP_FRAGMENT)); @@ -332,9 +332,9 @@ InitGameStructures (void) GLOBAL (CurrentActivity) = IN_INTERPLANETARY | START_INTERPLANETARY; - SET_GAME_STATE (SIS.ResUnits, 0); - SET_GAME_STATE (CrewCost, 3); - SET_GAME_STATE (FuelCost, 20); + GLOBAL_SIS (ResUnits) = 0; + GLOBAL (CrewCost) = 3; + GLOBAL (FuelCost) = 20; GLOBAL (ModuleCost[PLANET_LANDER]) = 500 / MODULE_COST_SCALE; GLOBAL (ModuleCost[FUSION_THRUSTER]) = 500 / MODULE_COST_SCALE; GLOBAL (ModuleCost[TURNING_JETS]) = 500 / MODULE_COST_SCALE; @@ -346,8 +346,11 @@ InitGameStructures (void) GLOBAL_SIS (NumLanders) = 1; - SET_GAME_STATE_STRING (SIS.ShipName, GAME_STRING (NAMING_STRING_BASE + 2)); - SET_GAME_STATE_STRING (SIS.CommanderName, GAME_STRING (NAMING_STRING_BASE + 3)); + utf8StringCopy (GLOBAL_SIS (ShipName), sizeof (GLOBAL_SIS (ShipName)), + GAME_STRING (NAMING_STRING_BASE + 2)); + utf8StringCopy (GLOBAL_SIS (CommanderName), + sizeof (GLOBAL_SIS (CommanderName)), + GAME_STRING (NAMING_STRING_BASE + 3)); SetRaceAllied (HUMAN_SHIP, TRUE); CloneShipFragment (HUMAN_SHIP, &GLOBAL (built_ship_q), 0); @@ -369,7 +372,7 @@ InitGameStructures (void) const int equipment[]= { - HIGHEFF_FUELSYS, + FUEL_TANK, HIGHEFF_FUELSYS, SHIVA_FURNACE, @@ -377,10 +380,10 @@ InitGameStructures (void) DYNAMO_UNIT, DYNAMO_UNIT, - STORAGE_BAY, - CREW_POD, - CREW_POD, - CREW_POD, + SHIVA_FURNACE, + SHIVA_FURNACE, + SHIVA_FURNACE, + SHIVA_FURNACE, TRACKING_SYSTEM, @@ -394,8 +397,8 @@ InitGameStructures (void) const int ck_[ sizeof( equipment ) / sizeof( int ) == 16 ? 1 : -1 ]; (void) ck_; - SET_GAME_STATE( SIS.CrewEnlisted, 0 ); - SET_GAME_STATE( SIS.FuelOnBoard, 10 * FUEL_TANK_SCALE); + GLOBAL_SIS( CrewEnlisted )= 0; + GLOBAL_SIS( FuelOnBoard )= 10 * FUEL_TANK_SCALE; for( int i= 0; i < 16; ++i ) { const int module= equipment[ i ]; @@ -403,15 +406,15 @@ InitGameStructures (void) if( false ) {} else if( module == CREW_POD ) { - SET_GAME_STATE( SIS.CrewEnlisted, GET_GAME_STATE( SIS.CrewEnlisted ) + CREW_POD_CAPACITY ); + GLOBAL_SIS( CrewEnlisted )+= CREW_POD_CAPACITY; } else if( module == FUEL_TANK ) { - SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE( SIS.FuelOnBoard ) + FUEL_TANK_CAPACITY ); + GLOBAL_SIS( FuelOnBoard )+= FUEL_TANK_CAPACITY; } else if( module == HIGHEFF_FUELSYS ) { - SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE( SIS.FuelOnBoard ) + HEFUEL_TANK_CAPACITY ); + GLOBAL_SIS( FuelOnBoard )+= HEFUEL_TANK_CAPACITY; } } diff --git a/sc2/src/uqm/globdata.h b/sc2/src/uqm/globdata.h index b9b183f56..3d582cfdb 100644 --- a/sc2/src/uqm/globdata.h +++ b/sc2/src/uqm/globdata.h @@ -29,11 +29,7 @@ #include "locdata.h" #include "cxxlist.h" -#include - #if defined(__cplusplus) -#include - extern "C" { #endif @@ -178,44 +174,10 @@ enum #define YEARS_TO_KOHRAH_VICTORY 4 -#ifdef COMPILING_GLOBDATA -//#error FOUND IT! -#endif - -#ifdef USE_OLD_STATE - #define START_GAME_STATE enum { #define ADD_GAME_STATE(SName,NumBits) SName, END_##SName = SName + NumBits - 1, #define END_GAME_STATE NUM_GAME_STATE_BITS }; -#elif defined( COMPILING_GLOBDATA ) - -#ifndef __cplusplus -#error You must only be in C++! -#endif - -extern "C" void addGameState_json( const char * ); -extern "C" void addGameState_string_json( const char * ); - -#define START_GAME_STATE \ - static auto initGameState_= []() -> int \ - { -#define ADD_GAME_STATE( name, legacySize ) \ - addGameState_json( #name ); - -#define ADD_GAME_STATE_STRING( name ) \ - addGameState_string_json( #name ); - -#define END_GAME_STATE \ - return 0xDEADBEEF; \ - }(); -#else -#define START_GAME_STATE -#define ADD_GAME_STATE( ... ) -#define ADD_GAME_STATE_STRING( ... ) -#define END_GAME_STATE -#endif - START_GAME_STATE /* Shofixti states */ ADD_GAME_STATE (SHOFIXTI_VISITS, 3) @@ -293,7 +255,7 @@ START_GAME_STATE * 9 means completely open. */ - // ADD_GAME_STATE (LANDER_SHIELDS, 4) // Lander shields are individual bits, now. + ADD_GAME_STATE (LANDER_SHIELDS, 4) ADD_GAME_STATE (MET_MELNORME, 1) ADD_GAME_STATE (MELNORME_RESCUE_REFUSED, 1) @@ -921,22 +883,6 @@ START_GAME_STATE ADD_GAME_STATE (SAMATRA_GRPOFFS2, 8) ADD_GAME_STATE (SAMATRA_GRPOFFS3, 8) - ADD_GAME_STATE (LANDER_SHIELD_BIO, 0) - ADD_GAME_STATE (LANDER_SHIELD_QUAKE, 0) - ADD_GAME_STATE (LANDER_SHIELD_LIGHTNING, 0) - ADD_GAME_STATE (LANDER_SHIELD_HEAT, 0) - - ADD_GAME_STATE (CrewCost, 0) - ADD_GAME_STATE (FuelCost, 0) - - ADD_GAME_STATE (SIS.ResUnits, 0) - ADD_GAME_STATE (SIS.FuelOnBoard, 0) - ADD_GAME_STATE (SIS.CrewEnlisted, 0) - - ADD_GAME_STATE_STRING (SIS.ShipName) - ADD_GAME_STATE_STRING (SIS.CommanderName) - ADD_GAME_STATE_STRING (SIS.PlanetName) - END_GAME_STATE // Values for GAME_STATE.glob_flags: @@ -978,7 +924,7 @@ typedef struct BYTE glob_flags; // See above for the meaning of the bits. - //BYTE CrewCost, FuelCost; + BYTE CrewCost, FuelCost; BYTE ModuleCost[NUM_MODULES]; BYTE ElementWorth[NUM_ELEMENT_CATEGORIES]; @@ -1015,9 +961,7 @@ typedef struct /* List of SIS escort ships; * queue element is SHIP_FRAGMENT */ -#ifdef USE_OLD_STATE BYTE GameState[(NUM_GAME_STATE_BITS + 7) >> 3]; -#endif } GAME_STATE; typedef struct @@ -1065,61 +1009,32 @@ extern void setGameState (BYTE *state, int startBit, int endBit, BYTE val ); extern void copyGameState (BYTE *dest, DWORD target, BYTE *src, DWORD begin, DWORD end); -extern uint32_t getGameState_json( const char *name ); -extern void setGameState_json( const char *name, uint32_t val ); - -extern const char *getGameState_string_json( const char *name ); -extern void setGameState_string_json( const char *name, const char *val ); - -#ifdef __cplusplus -extern "C++" -{ -#include -#include -#include - namespace GameState - { - const std::map< std::string, uint32_t > &getFullGameState(); - const std::map< std::string, std::string > &getFullGameStateString(); - } -} -#endif - -#define xGET_GAME_STATE(SName) getGameState (GLOBAL(GameState), (SName), (END_##SName)) +#define GET_GAME_STATE(SName) getGameState (GLOBAL(GameState), (SName), (END_##SName)) #ifdef STATE_DEBUG -# define xSET_GAME_STATE(SName, val) \ +# define SET_GAME_STATE(SName, val) \ setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName) #else -# define xSET_GAME_STATE(SName, val) \ +# define SET_GAME_STATE(SName, val) \ setGameState (GLOBAL(GameState), (SName), (END_##SName), (val)) #endif -#define GET_GAME_STATE(SName) ( getGameState_json( (#SName) ) ) -#define SET_GAME_STATE(SName, val) ( setGameState_json( (#SName), val ) ) - extern DWORD getGameState32 (BYTE *state, int startBit); extern void setGameState32 (BYTE *state, int startBit, DWORD val - #ifdef STATE_DEBUG , const char *name #endif ); -#define xGET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) +#define GET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) #ifdef STATE_DEBUG -# define xSET_GAME_STATE_32(SName, val) \ +# define SET_GAME_STATE_32(SName, val) \ setGameState32 (GLOBAL(GameState), (SName), (val), #SName) #else -# define xSET_GAME_STATE_32(SName, val) \ +# define SET_GAME_STATE_32(SName, val) \ setGameState32 (GLOBAL(GameState), (SName), (val)) #endif -#define GET_GAME_STATE_32(SName) ( getGameState_json( #SName ) ) -#define SET_GAME_STATE_32(SName, val) ( setGameState_json( #SName, val ) ) - -#define GET_GAME_STATE_STRING(SName) ( getGameState_string_json( #SName ) ) -#define SET_GAME_STATE_STRING(SName, val) ( setGameState_string_json( #SName, val ) ) - + extern CONTEXT RadarContext; extern void FreeSC2Data (void); diff --git a/sc2/src/uqm/hyper.c b/sc2/src/uqm/hyper.c index 01662093b..9ef55a91f 100644 --- a/sc2/src/uqm/hyper.c +++ b/sc2/src/uqm/hyper.c @@ -122,7 +122,7 @@ MoveSIS (SIZE *pdx, SIZE *pdy) } } - if (GET_GAME_STATE (SIS.FuelOnBoard) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + if (GLOBAL_SIS (FuelOnBoard) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) { COUNT cur_fuel_ticks; COUNT hyper_dist; @@ -215,7 +215,7 @@ check_hyperspace_encounter (void) percent *= GET_GAME_STATE (SLYLANDRO_MULTIPLIER); } else if (Type == MELNORME_SHIP - && (GET_GAME_STATE (SIS.FuelOnBoard) == 0 + && (GLOBAL_SIS (FuelOnBoard) == 0 || GET_GAME_STATE (USED_BROADCASTER)) && GET_GAME_STATE (MELNORME_ANGER) < 3) { @@ -1626,7 +1626,7 @@ DoHyperspaceMenu (MENU_STATE *pMS) BOOLEAN handled; if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0) + || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) return FALSE; handled = DoMenuChooser (pMS, PM_STARMAP); diff --git a/sc2/src/uqm/load-modern.cpp b/sc2/src/uqm/load-modern.cpp deleted file mode 100644 index ab48c612e..000000000 --- a/sc2/src/uqm/load-modern.cpp +++ /dev/null @@ -1,119 +0,0 @@ -//Copyright ADAM David Alan Martin. 2024 -// Adapted from code by: -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "save.h" - -#include -#include -#include - -#include "libs/json/single_include/nlohmann/json.hpp" - -namespace SaveGames -{ - namespace - { - namespace JSONlib= nlohmann; - - inline namespace impl - { - bool loadGame( int which, SUMMARY_DESC *sPtr ); - bool saveGame( int which, SUMMARY_DESC *sPtr, const std::string &name ); - } - } -} - -extern "C" -{ - ACTIVITY NextActivity; - - bool - LoadGame( const COUNT which_game, SUMMARY_DESC *const SummPtr ) - { - return SaveGames::loadGame( which_game, SummPtr ); - } - - bool - SaveGame( const COUNT which, SUMMARY_DESC *const SummPtr, const char *name ) - { - return SaveGames::saveGame( which, SummPtr, name ); - } - - void - SaveProblem() - { - throw std::runtime_error{ "Save Problem" }; - } -} - -bool -SaveGames::impl::saveGame( const int which, SUMMARY_DESC *const, const std::string &name ) -{ - // TODO: Resource dir as a C++ string; this is a hack for now. - std::filesystem::path saveDir= "/home/adam/.uqm/save"; - - std::ostringstream suffix; - suffix << std::setw( 2 ) << std::setfill( '0' ) << which; - - const auto fpath= saveDir / ( "uqmsave." + suffix.str() ); - std::ofstream out{ fpath.string() }; - - auto state= GameState::getFullGameState(); - - JSONlib::json json; - json[ "GameState" ]= GameState::getFullGameState(); - for( const auto &[ name, val ]: GameState::getFullGameStateString() ) - { - json[ "GameState" ][ name ]= val; - } - json[ "SaveGameName" ]= name; - std::cerr << "I want to save the save game name value as: `" << name << "`" << std::endl; - - out << std::setw( 4 ) << json; - - return true; -} - -bool -SaveGames::impl::loadGame( const int which, SUMMARY_DESC *const sPtr ) -{ - // TODO: Resource dir as a C++ string; this is a hack for now. - std::filesystem::path saveDir= "/home/adam/.uqm/save"; - - std::ostringstream suffix; - suffix << std::setw( 2 ) << std::setfill( '0' ) << which; - - - const auto fpath= saveDir / ( "uqmsave." + suffix.str() ); - std::ifstream in{ fpath.string() }; - - if( not in ) { return false; } - - JSONlib::json json; - - in >> json; - - // TODO: Do the rest of the loading... which should just - // be setting the main std::map. - std::cerr << "I loaded this JSON: \n" - << std::setw( 4 ) << json << std::endl; - - return false; -} diff --git a/sc2/src/uqm/load_legacy.c b/sc2/src/uqm/load_legacy.c index ce3d4a0da..17c78d38f 100644 --- a/sc2/src/uqm/load_legacy.c +++ b/sc2/src/uqm/load_legacy.c @@ -199,7 +199,6 @@ static DWORD old_defgrp_offsets[] = { 0, 52, 84, 116, 148, 180, 212, 244, 276, 308, 340, 372, 451, 879, 931 }; static DWORD new_defgrp_offsets[] = { -#if 0 0, SHOFIXTI_GRPOFFS0, ZOQFOT_GRPOFFS0, @@ -215,7 +214,6 @@ static DWORD new_defgrp_offsets[] = { URQUAN_PROBE_GRPOFFS0, COLONY_GRPOFFS0, SAMATRA_GRPOFFS0 -#endif }; static void diff --git a/sc2/src/uqm/menu.c b/sc2/src/uqm/menu.c index ddac758a0..fc46e3b4c 100644 --- a/sc2/src/uqm/menu.c +++ b/sc2/src/uqm/menu.c @@ -513,11 +513,11 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState) if (beg_index == PM_CREW) snprintf (pm_crew_str, sizeof pm_crew_str, "%s(%d)", GAME_STRING (MAINMENU_STRING_BASE + PM_CREW), - GET_GAME_STATE (CrewCost)); + GLOBAL (CrewCost)); if (beg_index == PM_FUEL) snprintf (pm_fuel_str, sizeof pm_fuel_str, "%s(%d)", GAME_STRING (MAINMENU_STRING_BASE + PM_FUEL), - GET_GAME_STATE (FuelCost)); + GLOBAL (FuelCost)); if (beg_index == PM_SOUND_ON) { end_index = beg_index + 5; @@ -578,7 +578,7 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState) t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; t.pStr = buf; - snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (CrewCost)); + snprintf (buf, sizeof buf, "%u", GLOBAL (CrewCost)); SetContextFont (TinyFont); SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR); font_DrawText (&t); @@ -589,7 +589,7 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState) t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; t.pStr = buf; - snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (FuelCost)); + snprintf (buf, sizeof buf, "%u", GLOBAL (FuelCost)); SetContextFont (TinyFont); SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR); font_DrawText (&t); diff --git a/sc2/src/uqm/outfit.c b/sc2/src/uqm/outfit.c index 591d89078..458dfa00c 100644 --- a/sc2/src/uqm/outfit.c +++ b/sc2/src/uqm/outfit.c @@ -99,19 +99,19 @@ DrawModuleStrings (MENU_STATE *pMS, BYTE NewModule) static void RedistributeFuel (void) { - const DWORD FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard); + const DWORD FuelVolume = GLOBAL_SIS (FuelOnBoard); const CONTEXT OldContext = SetContext (SpaceContext); RECT r; r.extent.height = 1; // Loop through all the rows to draw BatchGraphics (); - for (SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); - GET_GAME_STATE (SIS.FuelOnBoard) < GetFTankCapacity (&r.corner); - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + FUEL_VOLUME_PER_ROW)) + for (GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + GLOBAL_SIS (FuelOnBoard) < GetFTankCapacity (&r.corner); + GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) { // If we're less than the fuel level, draw fuel. - if (GET_GAME_STATE (SIS.FuelOnBoard) < FuelVolume) + if (GLOBAL_SIS (FuelOnBoard) < FuelVolume) { r.extent.width = 3; DrawPoint (&r.corner); @@ -132,7 +132,7 @@ RedistributeFuel (void) UnbatchGraphics (); SetContext (OldContext); - SET_GAME_STATE (SIS.FuelOnBoard, FuelVolume); + GLOBAL_SIS (FuelOnBoard) = FuelVolume; } #define LANDER_X 24 @@ -247,7 +247,7 @@ DoInstallModule (MENU_STATE *pMS) { if (new_slot_piece < EMPTY_SLOT) { - if (GET_GAME_STATE (SIS.ResUnits) < + if (GLOBAL_SIS (ResUnits) < (DWORD)(GLOBAL (ModuleCost[new_slot_piece]) * MODULE_COST_SCALE)) { // not enough RUs to build @@ -259,7 +259,7 @@ DoInstallModule (MENU_STATE *pMS) { if (old_slot_piece == CREW_POD) { - if (((int)GET_GAME_STATE (SIS.CrewEnlisted) )> CREW_POD_CAPACITY + if (GLOBAL_SIS (CrewEnlisted) > CREW_POD_CAPACITY * (CountSISPieces (CREW_POD) - 1)) { // crew pod still needed for crew recruited PlayMenuSound (MENU_SOUND_FAILURE); @@ -277,7 +277,7 @@ DoInstallModule (MENU_STATE *pMS) * HEFUEL_TANK_CAPACITY; volume -= (old_slot_piece == FUEL_TANK ? FUEL_TANK_CAPACITY : HEFUEL_TANK_CAPACITY); - if (GET_GAME_STATE (SIS.FuelOnBoard) > volume + FUEL_RESERVE) + if (GLOBAL_SIS (FuelOnBoard) > volume + FUEL_RESERVE) { // fuel tank still needed for the fuel on board PlayMenuSound (MENU_SOUND_FAILURE); return (TRUE); @@ -557,9 +557,9 @@ ChangeFuelQuantity (void) // Clamp incr to what we can afford/hold/have. { - const int maxFit = GetFuelTankCapacity () - GET_GAME_STATE (SIS.FuelOnBoard); - const int maxAfford = GET_GAME_STATE (SIS.ResUnits) / GET_GAME_STATE (FuelCost); - const int minFit = - (int) GET_GAME_STATE (SIS.FuelOnBoard); + const int maxFit = GetFuelTankCapacity () - GLOBAL_SIS (FuelOnBoard); + const int maxAfford = GLOBAL_SIS (ResUnits) / GLOBAL (FuelCost); + const int minFit = - (int) GLOBAL_SIS (FuelOnBoard); if (incr > maxFit) incr = maxFit; // All we can hold. @@ -578,7 +578,7 @@ ChangeFuelQuantity (void) } else { - const int cost = (incr / FUEL_TANK_SCALE) * GET_GAME_STATE (FuelCost); + const int cost = (incr / FUEL_TANK_SCALE) * GLOBAL (FuelCost); PreUpdateFlashRect (); DeltaSISGauges (0, incr, -cost); PostUpdateFlashRect (); @@ -670,18 +670,22 @@ DoOutfit (MENU_STATE *pMS) DisplayLanders (pMS); if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3) { + BYTE ShieldFlags; + + ShieldFlags = GET_GAME_STATE (LANDER_SHIELDS); + s.frame = SetAbsFrameIndex (pMS->ModuleFrame, GetFrameCount (pMS->ModuleFrame) - 5); - if (GET_GAME_STATE (LANDER_SHIELD_QUAKE)) + if (ShieldFlags & (1 << EARTHQUAKE_DISASTER)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (GET_GAME_STATE (LANDER_SHIELD_BIO)) + if (ShieldFlags & (1 << BIOLOGICAL_DISASTER)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (GET_GAME_STATE (LANDDER_SHIELD_LIGHTNING)) + if (ShieldFlags & (1 << LIGHTNING_DISASTER)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (GET_GAME_STATE (LANDER_SHIELD_HEAT)) + if (ShieldFlags & (1 << LAVASPOT_DISASTER)) DrawStamp (&s); } @@ -696,10 +700,10 @@ DoOutfit (MENU_STATE *pMS) SetFlashRect (SFR_MENU_3DO); - SET_GAME_STATE (SIS.FuelOnBoard, - (GET_GAME_STATE (SIS.FuelOnBoard) - + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) * FUEL_TANK_SCALE); + GLOBAL_SIS (FuelOnBoard) = + (GLOBAL_SIS (FuelOnBoard) + + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE; + GLOBAL_SIS (FuelOnBoard) *= FUEL_TANK_SCALE; } SetContext (StatusContext); diff --git a/sc2/src/uqm/pickship.c b/sc2/src/uqm/pickship.c index 53e98ecb5..3dcced0d5 100644 --- a/sc2/src/uqm/pickship.c +++ b/sc2/src/uqm/pickship.c @@ -190,9 +190,9 @@ ChangeSelection: StarShipPtr = LockStarShip (&race_q[0], hBattleShip); if (StarShipPtr->captains_name_index == 0) { - t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName); + t.pStr = GLOBAL_SIS (CommanderName); t.CharCount = (COUNT)~0; - crew_level = GET_GAME_STATE (SIS.CrewEnlisted); + crew_level = GLOBAL_SIS (CrewEnlisted); max_crew = GetCrewPodCapacity (); } else @@ -344,14 +344,14 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player) #define RUN_AWAY_FUEL_COST (5 * FUEL_TANK_SCALE) if (LastStarShipPtr->crew_level == 0) { // Died in the line of duty - SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0); + GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; } else { // Player ran away - if (GET_GAME_STATE (SIS.FuelOnBoard) > RUN_AWAY_FUEL_COST) - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) - RUN_AWAY_FUEL_COST); + if (GLOBAL_SIS (FuelOnBoard) > RUN_AWAY_FUEL_COST) + GLOBAL_SIS (FuelOnBoard) -= RUN_AWAY_FUEL_COST; else - SET_GAME_STATE (SIS.FuelOnBoard, 0); + GLOBAL_SIS (FuelOnBoard) = 0; } } return 0; @@ -397,7 +397,6 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect) TEXT t; CONTEXT OldContext; FRAME PickFrame; - UNICODE buf[ SIS_NAME_SIZE ]; OldContext = SetContext (SpaceContext); @@ -436,8 +435,7 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect) t.baseline.x = pick_r.corner.x + (pick_r.extent.width >> 1); t.baseline.y = pick_r.corner.y + pick_r.extent.height - 5; t.align = ALIGN_CENTER; - t.pStr = buf; - strncpy(buf, GET_GAME_STATE_STRING (SIS.ShipName), SIS_NAME_SIZE); + t.pStr = GLOBAL_SIS (ShipName); t.CharCount = (COUNT)~0; SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x12, 0x12, 0x12), 0x17)); diff --git a/sc2/src/uqm/planets/devices.c b/sc2/src/uqm/planets/devices.c index fc5f94c9b..eca79a1f4 100644 --- a/sc2/src/uqm/planets/devices.c +++ b/sc2/src/uqm/planets/devices.c @@ -356,7 +356,7 @@ InvokeDevice (BYTE which_device) case UTWIG_BOMB_DEVICE: SET_GAME_STATE (UTWIG_BOMB, 0); GLOBAL (CurrentActivity) &= ~IN_BATTLE; - SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0); + GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; return DEVICE_SUCCESS; case ULTRON_0_DEVICE: break; @@ -444,12 +444,12 @@ InvokeDevice (BYTE which_device) case PORTAL_SPAWNER_DEVICE: #define PORTAL_FUEL_COST (10 * FUEL_TANK_SCALE) if (inHyperSpace () - && GET_GAME_STATE (SIS.FuelOnBoard) >= PORTAL_FUEL_COST) + && GLOBAL_SIS (FuelOnBoard) >= PORTAL_FUEL_COST) { /* No DeltaSISGauges because the flagship picture * is currently obscured. */ - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) - PORTAL_FUEL_COST); + GLOBAL_SIS (FuelOnBoard) -= PORTAL_FUEL_COST; SET_GAME_STATE (PORTAL_COUNTER, 1); return DEVICE_SUCCESS; } @@ -674,14 +674,14 @@ DevicesMenu (void) SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - if (GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0 + if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0 && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { ClearSISRect (DRAW_SIS_DISPLAY); if (!GET_GAME_STATE (PORTAL_COUNTER) && !(GLOBAL (CurrentActivity) & START_ENCOUNTER) - && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) return TRUE; } diff --git a/sc2/src/uqm/planets/generate/gendefault.c b/sc2/src/uqm/planets/generate/gendefault.c index ee7117582..a88b89cb7 100644 --- a/sc2/src/uqm/planets/generate/gendefault.c +++ b/sc2/src/uqm/planets/generate/gendefault.c @@ -106,11 +106,8 @@ GenerateDefault_generateName (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world) { COUNT i = planetIndex (solarSys, world); - UNICODE buf[ SIS_NAME_SIZE ]; - utf8StringCopy (buf, SIS_NAME_SIZE, + utf8StringCopy (GLOBAL_SIS (PlanetName), sizeof (GLOBAL_SIS (PlanetName)), GAME_STRING (PLANET_NUMBER_BASE + (9 + 7) + i)); - - SET_GAME_STATE_STRING (SIS.PlanetName, buf); SET_GAME_STATE (BATTLE_PLANET, world->data_index); return true; diff --git a/sc2/src/uqm/planets/generate/genmel-modern.cpp b/sc2/src/uqm/planets/generate/genmel-modern.cpp index 0815053a2..f6db88e40 100644 --- a/sc2/src/uqm/planets/generate/genmel-modern.cpp +++ b/sc2/src/uqm/planets/generate/genmel-modern.cpp @@ -51,7 +51,7 @@ namespace { void initNpcs( SolarSystem *solarSys ) override; - static std::string SelectMelnormeRefVar(); + static int SelectMelnormeRefVar(); static DWORD GetMelnormeRef(); static void SetMelnormeRef( DWORD Ref ); }; @@ -81,26 +81,26 @@ GenerateMelnorme::initNpcs( SolarSystem *const solarSys ) } -std::string +int GenerateMelnorme::SelectMelnormeRefVar() { const auto arg_p= CurStarDescPtr->supArg; const std::string arg= arg_p ? arg_p : ""; - static const std::map< std::string, std::string > lookups + static const std::map< std::string, int > lookups { - { "0"s, "MELNORME0_GRPOFFS0" }, - { "1"s, "MELNORME1_GRPOFFS0" }, - { "2"s, "MELNORME2_GRPOFFS0" }, - { "3"s, "MELNORME3_GRPOFFS0" }, - { "4"s, "MELNORME4_GRPOFFS0" }, - { "5"s, "MELNORME5_GRPOFFS0" }, - { "6"s, "MELNORME6_GRPOFFS0" }, - { "7"s, "MELNORME7_GRPOFFS0" }, - { "8"s, "MELNORME8_GRPOFFS0" }, + { "0"s, MELNORME0_GRPOFFS0 }, + { "1"s, MELNORME1_GRPOFFS0 }, + { "2"s, MELNORME2_GRPOFFS0 }, + { "3"s, MELNORME3_GRPOFFS0 }, + { "4"s, MELNORME4_GRPOFFS0 }, + { "5"s, MELNORME5_GRPOFFS0 }, + { "6"s, MELNORME6_GRPOFFS0 }, + { "7"s, MELNORME7_GRPOFFS0 }, + { "8"s, MELNORME8_GRPOFFS0 }, }; - if( not lookups.count( arg ) ) throw std::runtime_error{ "Invalid Melnorme system" }; + if( not lookups.count( arg ) ) return -1; return lookups.at( arg ); } @@ -108,26 +108,26 @@ GenerateMelnorme::SelectMelnormeRefVar() DWORD GenerateMelnorme::GetMelnormeRef() { - const auto RefVar = SelectMelnormeRefVar (); - //if (RefVar < 0) - //{ - //log_add (log_Warning, "GetMelnormeRef(): reference unknown"); - //return 0; - //} + int RefVar = SelectMelnormeRefVar (); + if (RefVar < 0) + { + log_add (log_Warning, "GetMelnormeRef(): reference unknown"); + return 0; + } - return getGameState_json( RefVar.c_str() ); + return GET_GAME_STATE_32 (RefVar); } void GenerateMelnorme::SetMelnormeRef( DWORD Ref ) { - const auto RefVar = SelectMelnormeRefVar (); - //if (RefVar < 0) - //{ - //log_add (log_Warning, "SetMelnormeRef(): reference unknown"); - //return; - //} + int RefVar = SelectMelnormeRefVar (); + if (RefVar < 0) + { + log_add (log_Warning, "SetMelnormeRef(): reference unknown"); + return; + } - setGameState_json (RefVar.c_str(), Ref); + SET_GAME_STATE_32 (RefVar, Ref); } diff --git a/sc2/src/uqm/planets/generate/genpet-modern.cpp b/sc2/src/uqm/planets/generate/genpet-modern.cpp index 5abadac75..f60fa7335 100644 --- a/sc2/src/uqm/planets/generate/genpet-modern.cpp +++ b/sc2/src/uqm/planets/generate/genpet-modern.cpp @@ -241,10 +241,10 @@ GenerateTalkingPet::ZapToUrquanEncounter() + (FUEL_TANK_SCALE >> 1); DeltaSISGauges (0, -dx, 0); - if (GET_GAME_STATE (SIS.FuelOnBoard) < 5 * FUEL_TANK_SCALE) + if (GLOBAL_SIS (FuelOnBoard) < 5 * FUEL_TANK_SCALE) { dx = ((5 + ((COUNT)TFB_Random () % 5)) * FUEL_TANK_SCALE) - - (SIZE)GET_GAME_STATE (SIS.FuelOnBoard); + - (SIZE)GLOBAL_SIS (FuelOnBoard); DeltaSISGauges (0, dx, 0); } DrawSISMessage (NULL); diff --git a/sc2/src/uqm/planets/generate/gensol-modern.cpp b/sc2/src/uqm/planets/generate/gensol-modern.cpp index 2e750a2d1..1d4c36e8d 100644 --- a/sc2/src/uqm/planets/generate/gensol-modern.cpp +++ b/sc2/src/uqm/planets/generate/gensol-modern.cpp @@ -340,26 +340,28 @@ GenerateSol::generateName (const SolarSystem *const solarSys, if( matchWorld( solarSys, world, 3, 0 ) ) { fprintf( stderr, "ADAM: Trying to set Phobos\n" ); - setGameState_string_json( "SIS.PlanetName", "Phobos" ); + utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), + "Phobos" ); } else if( matchWorld( solarSys, world, 3, 1 ) ) { fprintf( stderr, "ADAM: Trying to set Deimos\n" ); - setGameState_string_json( "SIS.PlanetName", "Deimos" ); + utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), + "Deimos" ); } else if( matchWorld( solarSys, world, 4, MATCH_PLANET ) ) { fprintf( stderr, "ADAM: Trying to set Ceres\n" ); - setGameState_string_json( "SIS.PlanetName", "Ceres" ); + utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), + "Ceres" ); } else { fprintf( stderr, "ADAM: Trying to set from default to: %s\n", GAME_STRING( PLANET_NUMBER_BASE + planetNr ) ); COUNT xPlanetNr= planetNr; if( xPlanetNr > 4 ) xPlanetNr-= 1; - std::string tmp= GAME_STRING (PLANET_NUMBER_BASE + xPlanetNr); - if( tmp.size() > SIS_NAME_SIZE ) tmp= tmp.substr( 0, SIS_NAME_SIZE ); - setGameState_string_json( "SIS.PlanetName", tmp.c_str() ); + utf8StringCopy (GLOBAL_SIS (PlanetName), sizeof (GLOBAL_SIS (PlanetName)), + GAME_STRING (PLANET_NUMBER_BASE + xPlanetNr)); } SET_GAME_STATE (BATTLE_PLANET, solarSys->PlanetDesc[planetNr].data_index); diff --git a/sc2/src/uqm/planets/lander.c b/sc2/src/uqm/planets/lander.c index 5276de8f1..17aad8fe5 100644 --- a/sc2/src/uqm/planets/lander.c +++ b/sc2/src/uqm/planets/lander.c @@ -1328,7 +1328,7 @@ AnimateLanderWarmup (void) animationInterframe (&TimeIn, 2); for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS) - && GET_GAME_STATE (SIS.CrewEnlisted); ++num_crew) + && GLOBAL_SIS (CrewEnlisted); ++num_crew) { animationInterframe (&TimeIn, 1); diff --git a/sc2/src/uqm/planets/planets.c b/sc2/src/uqm/planets/planets.c index d85f53d1c..c76c2bbe6 100644 --- a/sc2/src/uqm/planets/planets.c +++ b/sc2/src/uqm/planets/planets.c @@ -198,7 +198,7 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode) DrawSISFrame (); DrawSISMessage (NULL); - DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); + DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawStarBackGround (); DrawPlanetSurfaceBorder (); } @@ -369,7 +369,7 @@ DoPlanetOrbit (MENU_STATE *pMS) BOOLEAN handled; if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0) + || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) return FALSE; // XXX: pMS actually refers to pSolarSysState->MenuState diff --git a/sc2/src/uqm/planets/pstarmap.c b/sc2/src/uqm/planets/pstarmap.c index efdec3532..adf368514 100644 --- a/sc2/src/uqm/planets/pstarmap.c +++ b/sc2/src/uqm/planets/pstarmap.c @@ -342,7 +342,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect) // Draw the fuel range circle if (race_update == 0 && which_space < 2 - && (diameter = (long)GET_GAME_STATE (SIS.FuelOnBoard) << 1)) + && (diameter = (long)GLOBAL_SIS (FuelOnBoard) << 1)) { Color OldColor; diff --git a/sc2/src/uqm/planets/roster.c b/sc2/src/uqm/planets/roster.c index b95d89f9b..663ac2836 100644 --- a/sc2/src/uqm/planets/roster.c +++ b/sc2/src/uqm/planets/roster.c @@ -275,14 +275,14 @@ DoModifyRoster (MENU_STATE *pMS) if (up) { - if (GET_GAME_STATE (SIS.CrewEnlisted)) + if (GLOBAL_SIS (CrewEnlisted)) delta = 1; else failed = TRUE; } else if (down) { - if (GET_GAME_STATE (SIS.CrewEnlisted) < GetCrewPodCapacity ()) + if (GLOBAL_SIS (CrewEnlisted) < GetCrewPodCapacity ()) delta = -1; else failed = TRUE; diff --git a/sc2/src/uqm/planets/scan.c b/sc2/src/uqm/planets/scan.c index 57ff661f5..3d5d9fd7b 100644 --- a/sc2/src/uqm/planets/scan.c +++ b/sc2/src/uqm/planets/scan.c @@ -1059,9 +1059,9 @@ DoScan (MENU_STATE *pMS) } fuel_required = getLandingFuelNeeded (); - if (GET_GAME_STATE (SIS.FuelOnBoard) < fuel_required + if (GLOBAL_SIS (FuelOnBoard) < fuel_required || GLOBAL_SIS (NumLanders) == 0 - || GET_GAME_STATE (SIS.CrewEnlisted) == 0) + || GLOBAL_SIS (CrewEnlisted) == 0) { PlayMenuSound (MENU_SOUND_FAILURE); return TRUE; diff --git a/sc2/src/uqm/planets/solarsys.c b/sc2/src/uqm/planets/solarsys.c index 35dd76fdd..d351181a3 100644 --- a/sc2/src/uqm/planets/solarsys.c +++ b/sc2/src/uqm/planets/solarsys.c @@ -1207,7 +1207,7 @@ DrawInnerSystem (void) { ValidateInnerOrbits (); DrawSystem (pSolarSysState->pOrbitalDesc->radius, TRUE); - DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); + DrawSISTitle (GLOBAL_SIS (PlanetName)); } static void @@ -1279,7 +1279,7 @@ EnterPlanetOrbit (void) pSolarSysState->pOrbitalDesc); LastActivity &= ~(CHECK_LOAD | CHECK_RESTART); if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD | - START_ENCOUNTER)) || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0 + START_ENCOUNTER)) || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2) return; @@ -1298,7 +1298,7 @@ EnterPlanetOrbit (void) // Could also have blown self up with Utwig Bomb if (!(GLOBAL (CurrentActivity) & (START_ENCOUNTER | CHECK_ABORT | CHECK_LOAD)) - && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) { // Reload the system and return to the inner view PLANET_DESC *orbital = LoadSolarSys (); assert (!orbital); @@ -1857,7 +1857,7 @@ GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize) } // Either not named or we already have a name - utf8StringCopy (buf, bufsize, GET_GAME_STATE_STRING (SIS.PlanetName)); + utf8StringCopy (buf, bufsize, GLOBAL_SIS (PlanetName)); if (!playerInSolarSystem () || !playerInInnerSystem () || worldIsPlanet (pSolarSysState, pSolarSysState->pOrbitalDesc)) @@ -1923,7 +1923,7 @@ DoSolarSysMenu (MENU_STATE *pMS) BOOLEAN handled; if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0) + || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) return FALSE; handled = DoMenuChooser (pMS, PM_STARMAP); @@ -2038,5 +2038,5 @@ DoIpFlight (SOLARSYS_STATE *pSS) return (!(GLOBAL (CurrentActivity) & (START_ENCOUNTER | END_INTERPLANETARY | CHECK_ABORT | CHECK_LOAD)) - && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0); + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0); } diff --git a/sc2/src/uqm/restart.c b/sc2/src/uqm/restart.c index 524b1dc71..f52e753b4 100644 --- a/sc2/src/uqm/restart.c +++ b/sc2/src/uqm/restart.c @@ -260,7 +260,7 @@ RestartMenu (MENU_STATE *pMS) SetContext (ScreenContext); GLOBAL (CurrentActivity) |= CHECK_ABORT; - if (GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0 + if (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 && GET_GAME_STATE (UTWIG_BOMB_ON_SHIP) && !GET_GAME_STATE (UTWIG_BOMB)) { // player blew himself up with Utwig bomb diff --git a/sc2/src/uqm/save.h b/sc2/src/uqm/save.h index 457496953..28852b8ae 100644 --- a/sc2/src/uqm/save.h +++ b/sc2/src/uqm/save.h @@ -65,11 +65,11 @@ typedef struct extern ACTIVITY NextActivity; -extern bool LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); -extern bool LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc); +extern BOOLEAN LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); +extern BOOLEAN LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc); extern void SaveProblem (void); -extern bool SaveGame (COUNT which_game, SUMMARY_DESC *summary_desc, const char *name); +extern BOOLEAN SaveGame (COUNT which_game, SUMMARY_DESC *summary_desc, const char *name); #if defined(__cplusplus) } diff --git a/sc2/src/uqm/ships/sis_ship/sis_ship.c b/sc2/src/uqm/ships/sis_ship/sis_ship.c index f1983a207..fd24115eb 100644 --- a/sc2/src/uqm/ships/sis_ship/sis_ship.c +++ b/sc2/src/uqm/ships/sis_ship/sis_ship.c @@ -243,7 +243,7 @@ LeaveAutoPilot: (GLOBAL (autopilot)).x = (GLOBAL (autopilot)).y = ~0; if (!(StarShipPtr->cur_status_flags & THRUST) - || (GET_GAME_STATE (SIS.FuelOnBoard) == 0 + || (GLOBAL_SIS (FuelOnBoard) == 0 && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)) { AccelerateDirection = -1; @@ -314,7 +314,7 @@ LeaveAutoPilot: } GetCurrentVelocityComponents (&ElementPtr->velocity, &dx, &dy); - if ((GET_GAME_STATE (SIS.FuelOnBoard) + if ((GLOBAL_SIS (FuelOnBoard) || GET_GAME_STATE (ARILOU_SPACE_SIDE) > 1) && (int)facing == (int)StarShipPtr->ShipFacing) { @@ -1029,7 +1029,7 @@ init_sis (void) { // Count the captain too. new_sis_desc.ship_info.max_crew++; - new_sis_desc.ship_info.crew_level = GET_GAME_STATE (SIS.CrewEnlisted) + 1; + new_sis_desc.ship_info.crew_level = GLOBAL_SIS (CrewEnlisted) + 1; new_sis_desc.ship_info.ship_flags |= PLAYER_CAPTAIN; } @@ -1045,9 +1045,9 @@ uninit_sis (RACE_DESC *pRaceDesc) { if (!inHQSpace ()) { - SET_GAME_STATE (SIS.CrewEnlisted, pRaceDesc->ship_info.crew_level); + GLOBAL_SIS (CrewEnlisted) = pRaceDesc->ship_info.crew_level; if (pRaceDesc->ship_info.ship_flags & PLAYER_CAPTAIN) - SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) - 1); + GLOBAL_SIS (CrewEnlisted)--; } SetCustomShipData (pRaceDesc, NULL); diff --git a/sc2/src/uqm/shipstat.c b/sc2/src/uqm/shipstat.c index 4ff25a1e0..040542660 100644 --- a/sc2/src/uqm/shipstat.c +++ b/sc2/src/uqm/shipstat.c @@ -56,16 +56,14 @@ DrawCrewFuelString (COORD y, SIZE state) } static void -DrawShipNameString (const UNICODE *pStr, COUNT CharCount, COORD y) +DrawShipNameString (UNICODE *pStr, COUNT CharCount, COORD y) { TEXT Text; FONT OldFont; - UNICODE buf[ SIS_NAME_SIZE ]; - strncpy( buf, pStr, SIS_NAME_SIZE ); OldFont = SetContextFont (StarConFont); - Text.pStr = buf; + Text.pStr = pStr; Text.CharCount = CharCount; Text.align = ALIGN_CENTER; @@ -279,7 +277,7 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) else if (StarShipPtr->playerNr == RPG_PLAYER_NUM) { // This is SIS DrawCrewFuelString (y, 0); - DrawShipNameString (GET_GAME_STATE_STRING (SIS.ShipName), (COUNT)~0, y); + DrawShipNameString (GLOBAL_SIS (ShipName), (COUNT)~0, y); } { diff --git a/sc2/src/uqm/shipyard.c b/sc2/src/uqm/shipyard.c index 64cff79b8..f317ba338 100644 --- a/sc2/src/uqm/shipyard.c +++ b/sc2/src/uqm/shipyard.c @@ -522,7 +522,7 @@ CrewTransaction (SIZE crew_delta) if (crew_bought >= CREW_EXPENSE_THRESHOLD && crew_bought - crew_delta < CREW_EXPENSE_THRESHOLD) { - SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) + 2); + GLOBAL (CrewCost) += 2; DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); } } @@ -531,7 +531,7 @@ CrewTransaction (SIZE crew_delta) if (crew_bought < CREW_EXPENSE_THRESHOLD && crew_bought - crew_delta >= CREW_EXPENSE_THRESHOLD) { - SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) - 2); + GLOBAL (CrewCost) -= 2; DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); } } @@ -724,7 +724,7 @@ DMS_HireFlagShipCrew (void) return 0; } - if (GET_GAME_STATE (SIS.ResUnits) < (DWORD)GET_GAME_STATE (CrewCost)) + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) { // Not enough RUs. return 0; @@ -736,7 +736,7 @@ DMS_HireFlagShipCrew (void) // Update the crew counter and RU. Note that the crew counter is // flashing. PreUpdateFlashRect (); - DeltaSISGauges (1, 0, -GET_GAME_STATE (CrewCost)); + DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); PostUpdateFlashRect (); return 1; @@ -765,7 +765,7 @@ DMS_DismissFlagShipCrew (void) // Update the crew counter and RU. Note that the crew counter is // flashing. PreUpdateFlashRect (); - DeltaSISGauges (-1, 0, GET_GAME_STATE (CrewCost) - + DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); PostUpdateFlashRect (); @@ -797,7 +797,7 @@ DMS_HireEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); } - if (GET_GAME_STATE (SIS.ResUnits) < (DWORD)GET_GAME_STATE (CrewCost)) + if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) { // Not enough money to hire a crew member. return 0; @@ -817,7 +817,7 @@ DMS_HireEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) if (StarShipPtr->crew_level > 0) { - DeltaSISGauges (0, 0, -GET_GAME_STATE (CrewCost)); + DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); } else { @@ -855,7 +855,7 @@ DMS_DismissEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED1)); - DeltaSISGauges (0, 0, GET_GAME_STATE (CrewCost) + DeltaSISGauges (0, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); } else @@ -956,7 +956,7 @@ DMS_TryAddEscortShip (MENU_STATE *pMS) LOBYTE (pMS->delta_item)); COUNT Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), shipInfo); - if (GET_GAME_STATE (SIS.ResUnits) >= (DWORD)ShipCost[Index] + if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1)) { ShowCombatShip (pMS, pMS->CurState, NULL); @@ -1318,8 +1318,8 @@ DrawBluePrint (MENU_STATE *pMS) } { - num_frames = GET_GAME_STATE (SIS.CrewEnlisted); - SET_GAME_STATE (SIS.CrewEnlisted, 0); + num_frames = GLOBAL_SIS (CrewEnlisted); + GLOBAL_SIS (CrewEnlisted) = 0; while (num_frames--) { @@ -1328,7 +1328,7 @@ DrawBluePrint (MENU_STATE *pMS) GetCPodCapacity (&pt); DrawPoint (&pt); - SET_GAME_STATE( SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + 1 ); + ++GLOBAL_SIS (CrewEnlisted); } } { @@ -1351,13 +1351,13 @@ DrawBluePrint (MENU_STATE *pMS) num_frames -= m; } } - if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE) + if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) { DWORD FuelVolume; RECT r; - FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard) - FUEL_RESERVE; - SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); + FuelVolume = GLOBAL_SIS (FuelOnBoard) - FUEL_RESERVE; + GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; r.extent.width = 3; r.extent.height = 1; @@ -1375,7 +1375,7 @@ DrawBluePrint (MENU_STATE *pMS) DrawFilledRectangle (&r); m = FuelVolume < FUEL_VOLUME_PER_ROW ? (COUNT)FuelVolume : FUEL_VOLUME_PER_ROW; - SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + m ); + GLOBAL_SIS (FuelOnBoard) += m; FuelVolume -= m; } } diff --git a/sc2/src/uqm/sis.c b/sc2/src/uqm/sis.c index 4abb3a96f..f5c0af784 100644 --- a/sc2/src/uqm/sis.c +++ b/sc2/src/uqm/sis.c @@ -123,18 +123,16 @@ ClearSISRect (BYTE ClearFlags) // right hand side, containing the coordinates in HyperSpace, or the planet // name in IP. void -DrawSISTitle (const UNICODE *pStr) +DrawSISTitle (UNICODE *pStr) { TEXT t; CONTEXT OldContext; RECT r; - UNICODE buf[ SIS_NAME_SIZE ]; - strncpy( buf, pStr, SIS_NAME_SIZE ); t.baseline.x = SIS_TITLE_WIDTH >> 1; t.baseline.y = SIS_TITLE_HEIGHT - 2; t.align = ALIGN_CENTER; - t.pStr = buf; + t.pStr = pStr; t.CharCount = (COUNT)~0; OldContext = SetContext (OffScreenContext); @@ -400,7 +398,7 @@ DrawStatusMessage (const UNICODE *pStr) { if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 2) { - snprintf (buf, sizeof buf, "%u %s", GET_GAME_STATE (SIS.ResUnits), + snprintf (buf, sizeof buf, "%u %s", GLOBAL_SIS (ResUnits), GAME_STRING (STATUS_STRING_BASE + 1)); // "RU" } else @@ -468,7 +466,7 @@ DrawCaptainsName (void) t.baseline.x = (STATUS_WIDTH >> 1) - 1; t.baseline.y = r.corner.y + 6; t.align = ALIGN_CENTER; - t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName); + t.pStr = GLOBAL_SIS (CommanderName); t.CharCount = (COUNT)~0; SetContextForeGroundColor (CAPTAIN_NAME_TEXT_COLOR); font_DrawText (&t); @@ -499,7 +497,7 @@ DrawFlagshipName (BOOLEAN InStatusArea) r.extent.width = SHIP_NAME_WIDTH; r.extent.height = SHIP_NAME_HEIGHT; - t.pStr = GET_GAME_STATE_STRING (SIS.ShipName); + t.pStr = GLOBAL_SIS (ShipName); } else { @@ -513,7 +511,7 @@ DrawFlagshipName (BOOLEAN InStatusArea) t.pStr = buf; snprintf (buf, sizeof buf, "%s %s", - GAME_STRING (NAMING_STRING_BASE + 1), GET_GAME_STATE_STRING (SIS.ShipName)); + GAME_STRING (NAMING_STRING_BASE + 1), GLOBAL_SIS (ShipName)); // XXX: this will not work with UTF-8 strings strupr (buf); } @@ -991,14 +989,14 @@ DeltaSISGauges_crewDelta (SIZE crew_delta) COUNT CrewCapacity; if (crew_delta < 0 - && GET_GAME_STATE (SIS.CrewEnlisted) <= (COUNT)-crew_delta) - SET_GAME_STATE (SIS.CrewEnlisted, 0); + && GLOBAL_SIS (CrewEnlisted) <= (COUNT)-crew_delta) + GLOBAL_SIS (CrewEnlisted) = 0; else { - SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + crew_delta); + GLOBAL_SIS (CrewEnlisted) += crew_delta; CrewCapacity = GetCrewPodCapacity (); - if (GET_GAME_STATE (SIS.CrewEnlisted) > CrewCapacity) - SET_GAME_STATE(SIS.CrewEnlisted, CrewCapacity); + if (GLOBAL_SIS (CrewEnlisted) > CrewCapacity) + GLOBAL_SIS (CrewEnlisted) = CrewCapacity; } } @@ -1007,7 +1005,7 @@ DeltaSISGauges_crewDelta (SIZE crew_delta) UNICODE buf[60]; RECT r; - snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (SIS.CrewEnlisted)); + snprintf (buf, sizeof buf, "%u", GLOBAL_SIS (CrewEnlisted)); GetGaugeRect (&r, TRUE); @@ -1040,23 +1038,23 @@ DeltaSISGauges_fuelDelta (SIZE fuel_delta) { old_coarse_fuel = (COUNT)( - GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE); + GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE); if (fuel_delta < 0 - && GET_GAME_STATE (SIS.FuelOnBoard) <= (DWORD)-fuel_delta) + && GLOBAL_SIS (FuelOnBoard) <= (DWORD)-fuel_delta) { - SET_GAME_STATE (SIS.FuelOnBoard, 0); + GLOBAL_SIS (FuelOnBoard) = 0; } else { DWORD FuelCapacity = GetFuelTankCapacity (); - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + fuel_delta); - if (GET_GAME_STATE (SIS.FuelOnBoard) > FuelCapacity) - SET_GAME_STATE (SIS.FuelOnBoard, FuelCapacity); + GLOBAL_SIS (FuelOnBoard) += fuel_delta; + if (GLOBAL_SIS (FuelOnBoard) > FuelCapacity) + GLOBAL_SIS (FuelOnBoard) = FuelCapacity; } } new_coarse_fuel = (COUNT)( - GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE); + GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE); if (new_coarse_fuel != old_coarse_fuel) { TEXT t; @@ -1090,10 +1088,10 @@ DeltaSISGauges_resunitDelta (SIZE resunit_delta) if (resunit_delta != UNDEFINED_DELTA) { if (resunit_delta < 0 - && GET_GAME_STATE (SIS.ResUnits) <= (DWORD)-resunit_delta) - SET_GAME_STATE (SIS.ResUnits, 0); + && GLOBAL_SIS (ResUnits) <= (DWORD)-resunit_delta) + GLOBAL_SIS (ResUnits) = 0; else - SET_GAME_STATE (SIS.ResUnits, GET_GAME_STATE (SIS.ResUnits) + resunit_delta); + GLOBAL_SIS (ResUnits) += resunit_delta; assert (curMsgMode == SMM_RES_UNITS); } @@ -1171,7 +1169,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta) COUNT GetCrewCount (void) { - return GET_GAME_STATE (SIS.CrewEnlisted); + return GLOBAL_SIS (CrewEnlisted); } // Get the number of crew which fit in a module of a specified type. @@ -1378,7 +1376,7 @@ GetSBayCapacity (POINT *ppt) static DWORD GetFuelTotal (void) { - return GET_GAME_STATE (SIS.FuelOnBoard); + return GLOBAL_SIS (FuelOnBoard); } // Get the amount of fuel which fits in a module of a specified type. @@ -1546,7 +1544,7 @@ DrawAutoPilotMessage (BOOLEAN Reset) } OnAutoPilot = (GLOBAL (autopilot.x) != ~0 && GLOBAL (autopilot.y) != ~0) - || GET_GAME_STATE (SIS.FuelOnBoard) == 0; + || GLOBAL_SIS (FuelOnBoard) == 0; if (OnAutoPilot || LastPilot) { @@ -1558,13 +1556,13 @@ DrawAutoPilotMessage (BOOLEAN Reset) else if (GetTimeCounter () >= NextTime) { if (!(GLOBAL (CurrentActivity) & CHECK_ABORT) - && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) + && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) { CONTEXT OldContext; OldContext = SetContext (OffScreenContext); SetContextForeGroundColor (cycle_tab[cycle_index]); - if (GET_GAME_STATE (SIS.FuelOnBoard) == 0) + if (GLOBAL_SIS (FuelOnBoard) == 0) { DrawSISMessageEx (GAME_STRING (NAVIGATION_STRING_BASE + 2), -1, -1, DSME_MYCOLOR); // "OUT OF FUEL" diff --git a/sc2/src/uqm/sis.h b/sc2/src/uqm/sis.h index 4ae3304bc..4af573cfb 100644 --- a/sc2/src/uqm/sis.h +++ b/sc2/src/uqm/sis.h @@ -133,10 +133,10 @@ typedef struct { SDWORD log_x, log_y; - //DWORD ResUnits; + DWORD ResUnits; - //DWORD FuelOnBoard; - //COUNT CrewEnlisted; + DWORD FuelOnBoard; + COUNT CrewEnlisted; // Number of crew on board, not counting the captain. // Set to (COUNT) ~0 to indicate game over. COUNT TotalElementMass, TotalBioMass; @@ -149,11 +149,9 @@ typedef struct COUNT ElementAmounts[NUM_ELEMENT_CATEGORIES]; -/* UNICODE ShipName[SIS_NAME_SIZE]; UNICODE CommanderName[SIS_NAME_SIZE]; UNICODE PlanetName[SIS_NAME_SIZE]; -*/ } SIS_STATE; #define OVERRIDE_LANDER_FLAGS (1 << 7) @@ -172,7 +170,7 @@ extern void ContinueFlash (void); #define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_ANY ((RECT*)~1L) extern void DrawHyperCoords (POINT puniverse); -extern void DrawSISTitle (const UNICODE *pStr); +extern void DrawSISTitle (UNICODE *pStr); // Flags for DrawSISMessageEx (may be OR'ed): #define DSME_NONE 0 diff --git a/sc2/src/uqm/starbase.c b/sc2/src/uqm/starbase.c index 4ad1bfed0..26cf0185e 100644 --- a/sc2/src/uqm/starbase.c +++ b/sc2/src/uqm/starbase.c @@ -474,7 +474,7 @@ VisitStarBase (void) UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip); InitCommunication (ILWRATH_CONVERSATION); - if (GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0 + if (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 || (GLOBAL (CurrentActivity) & CHECK_ABORT)) return; // Killed by Ilwrath @@ -496,7 +496,7 @@ VisitStarBase (void) // Starbase becomes available for the first time, or after Chmmr // install the bomb. DoTimePassage (); - if (GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0) + if (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) return; // You are now dead! Thank you! (killed by Kohr-Ah) SetCommIntroMode (CIM_FADE_IN_SCREEN, ONE_SECOND * 2); diff --git a/sc2/src/uqm/starcon.c b/sc2/src/uqm/starcon.c index cbd51512d..5903e6860 100644 --- a/sc2/src/uqm/starcon.c +++ b/sc2/src/uqm/starcon.c @@ -292,7 +292,7 @@ while (--ac > 0) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) && (LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE // if died for some reason - || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0)) + || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0)) { if (GET_GAME_STATE (KOHR_AH_KILLED_ALL)) InitCommunication (BLACKURQ_CONVERSATION); diff --git a/sc2/src/uqm/status.c b/sc2/src/uqm/status.c index 12e633c80..6a588a893 100644 --- a/sc2/src/uqm/status.c +++ b/sc2/src/uqm/status.c @@ -270,7 +270,7 @@ DrawCaptainsWindow (STARSHIP *StarShipPtr) t.baseline.x = STATUS_WIDTH >> 1; t.baseline.y = y + 6; t.align = ALIGN_CENTER; - t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName); + t.pStr = GLOBAL_SIS (CommanderName); t.CharCount = (COUNT)~0; SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02)); diff --git a/sc2/src/uqm/uqmdebug.c b/sc2/src/uqm/uqmdebug.c index 90e436142..9dc0d4e52 100644 --- a/sc2/src/uqm/uqmdebug.c +++ b/sc2/src/uqm/uqmdebug.c @@ -284,10 +284,11 @@ equipShip (void) GLOBAL_SIS (JetSlots[i]) = TURNING_JETS; // Shields: - SET_GAME_STATE (LANDER_SHIELD_BIO, 1); - SET_GAME_STATE (LANDER_SHIELD_QUAKE, 1); - SET_GAME_STATE (LANDER_SHIELD_LIGHTNING, 1); - SET_GAME_STATE (LANDER_SHIELD_HEAT, 1); + SET_GAME_STATE (LANDER_SHIELDS, + (1 << EARTHQUAKE_DISASTER) | + (1 << BIOLOGICAL_DISASTER) | + (1 << LIGHTNING_DISASTER) | + (1 << LAVASPOT_DISASTER)); // Lander upgrades: SET_GAME_STATE (IMPROVED_LANDER_SPEED, 1); SET_GAME_STATE (IMPROVED_LANDER_CARGO, 1); @@ -334,19 +335,19 @@ equipShip (void) assert (i <= NUM_MODULE_SLOTS); // Fill the fuel and crew compartments to the maximum. - SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); - SET_GAME_STATE (SIS.CrewEnlisted, 0); + GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + GLOBAL_SIS (CrewEnlisted) = 0; for (i = 0; i < NUM_MODULE_SLOTS; i++) { switch (GLOBAL_SIS (ModuleSlots[i])) { case CREW_POD: - SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY); + GLOBAL_SIS (CrewEnlisted) += CREW_POD_CAPACITY; break; case FUEL_TANK: - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + FUEL_TANK_CAPACITY); + GLOBAL_SIS (FuelOnBoard) += FUEL_TANK_CAPACITY; break; case HIGHEFF_FUELSYS: - SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + HEFUEL_TANK_CAPACITY); + GLOBAL_SIS (FuelOnBoard) += HEFUEL_TANK_CAPACITY; break; } } @@ -983,7 +984,7 @@ void dumpPlanet (FILE *out, const PLANET_DESC *planet) { (*pSolarSysState->genFuncs->generateName) (pSolarSysState, planet); - fprintf (out, "- %-37s %s\n", GET_GAME_STATE_STRING (SIS.PlanetName), + fprintf (out, "- %-37s %s\n", GLOBAL_SIS (PlanetName), planetTypeString (planet->data_index & ~PLANET_SHIELDED)); dumpWorld (out, planet); }