diff --git a/sc2/src/uqm/Makeinfo b/sc2/src/uqm/Makeinfo index 4b224fac0..da2a64879 100644 --- a/sc2/src/uqm/Makeinfo +++ b/sc2/src/uqm/Makeinfo @@ -3,13 +3,17 @@ 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 load.c - load_legacy.c + cons_res.c grpinfo.c hyper.c init.c intel.c intro.c ipdisp.c loadship.c master.c menu.c misc.c oscill.c outfit.c pickship.c - plandata.c process.c restart.c save.c settings.c setup.c setupmenu.c + plandata.c process.c restart.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" + velocity.c weapon.c + " + #save.c + #load.c + #load_legacy.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 @@ -21,4 +25,7 @@ uqm_HFILES="battlecontrols.h battle.h build.h clock.h cnctdlg.h coderes.h sis.h sounds.h starbase.h starcon.h state.h status.h tactrans.h starmap.h units.h uqmdebug.h util.h velocity.h weapon.h" - +uqm_CXXFILES=" + gamestate-modern.cpp + load-modern.cpp + " diff --git a/sc2/src/uqm/comm.c b/sc2/src/uqm/comm.c index ff2818c43..0d8b9685e 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 (GLOBAL_SIS (PlanetName)); + DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); } } @@ -1332,7 +1332,7 @@ InitCommunication (CONVERSATION which_comm) else if (GLOBAL (ip_planet) == 0) DrawHyperCoords (CurStarDescPtr->star_pt); else - DrawSISTitle (GLOBAL_SIS (PlanetName)); + DrawSISTitle (GET_GAME_STATE_STRING (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)) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) { GLOBAL (CurrentActivity) = WON_LAST_BATTLE; } @@ -1481,7 +1481,7 @@ RaceCommunication (void) InitCommunication (ILWRATH_CONVERSATION); else InitCommunication (CHMMR_CONVERSATION); - if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + if (GET_GAME_STATE (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 1b35fc0d3..bf9c5d49b 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); - GLOBAL_SIS (ResUnits) = 1000000L; + SET_GAME_STATE (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 */ - GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; - GLOBAL_SIS (CrewEnlisted) = 0; - GLOBAL_SIS (TotalElementMass) = 0; + SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); + SET_GAME_STATE (SIS.CrewEnlisted, 0); + SET_GAME_STATE (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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), i_am_captain1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 57df233be..7a7c75daa 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), name_41, (UNICODE*)NULL); @@ -265,7 +265,7 @@ NoRadioactives (RESPONSE_REF R) else Response (i_lost_my_lander, NoRadioactives); } - if (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GET_GAME_STATE (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 (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GET_GAME_STATE (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 (GLOBAL_SIS (FuelOnBoard) < 2 * FUEL_TANK_SCALE) + if (GET_GAME_STATE (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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 9a082c115..7028b7bcc 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) - GLOBAL (CrewCost) += (22 - 7); + SET_GAME_STATE (CrewCost, GET_GAME_STATE(CrewCost) + 22 - 7); else - GLOBAL (CrewCost) += 22; + SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) + 22); } else if (SlaveryCount > 100 && PreviousSlaves <= 100) - GLOBAL (CrewCost) += 7; + SET_GAME_STATE (CrewCost, GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < SHIP_CREW_COST) + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < ARTIFACT_CREW_COST) + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < FUEL_CREW_COST) + if (GET_GAME_STATE (SIS.CrewEnlisted) < FUEL_CREW_COST) NPCPhrase (NOT_ENOUGH_CREW); else { @@ -453,7 +453,7 @@ DoTransaction (RESPONSE_REF R) capacity += volume; } } while (slot--); - capacity -= GLOBAL_SIS (FuelOnBoard); + capacity -= GET_GAME_STATE (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 00b6a0727..b8fddf588 100644 --- a/sc2/src/uqm/comm/melnorm/melnorm.c +++ b/sc2/src/uqm/comm/melnorm/melnorm.c @@ -236,32 +236,36 @@ 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 - int subtype; // Subtype of the technology - int info; // Supplemental information + 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 } 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_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 }, + 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 ), }; const size_t NUM_TECHNOLOGIES = ARRAY_SIZE (tech_data_table); @@ -282,35 +286,15 @@ 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 (int stateId) +HasStateTech (const char *const 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; + return getGameState_json(stateId); } static void -GrantStateTech (int stateId, BYTE value) +GrantStateTech (const char *const stateId) { - 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; - } + setGameState_json(stateId, true); } static bool @@ -320,16 +304,7 @@ HasTech (TechId_t techId) if (!techData) return false; - 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; + return HasStateTech(techData->subtype); } static void @@ -339,21 +314,8 @@ GrantTech (TechId_t techId) if (!techData) return; - 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; - } + + GrantStateTech (techData->subtype); } @@ -507,7 +469,7 @@ ShipWorth (void) } crew_pods = -(SBYTE)( - (GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) + (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1) / CREW_POD_CAPACITY ); for (i = 0; i < NUM_MODULE_SLOTS; ++i) @@ -582,7 +544,7 @@ StripShip (COUNT fuel_required) SET_GAME_STATE (MELNORME_RESCUE_REFUSED, 0); crew_pods = -(SBYTE)( - (GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) + (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1) / CREW_POD_CAPACITY ); if (fuel_required == 0) @@ -597,8 +559,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 (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) - GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE) + SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); GLOBAL_SIS (TotalBioMass) = 0; GLOBAL_SIS (TotalElementMass) = 0; for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i) @@ -1007,7 +969,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 - GLOBAL_SIS (FuelOnBoard) + needed_credit = (capacity - GET_GAME_STATE (SIS.FuelOnBoard) + FUEL_TANK_SCALE - 1) / FUEL_TANK_SCALE; @@ -1021,7 +983,7 @@ DoBuy (RESPONSE_REF R) } else { - if (GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE + if (GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE + needed_credit > capacity / FUEL_TANK_SCALE) { NPCPhrase (NO_ROOM_FOR_FUEL); @@ -1047,7 +1009,7 @@ DoBuy (RESPONSE_REF R) if (needed_credit) { DeltaCredit (-needed_credit); - if (GLOBAL_SIS (FuelOnBoard) >= capacity) + if (GET_GAME_STATE (SIS.FuelOnBoard) >= capacity) goto BuyBuyBuy; } TryFuelAgain: @@ -1158,7 +1120,7 @@ TryFuelAgain: NPCPhrase (WHAT_TO_BUY); BuyBuyBuy: - if (GLOBAL_SIS (FuelOnBoard) < capacity) + if (GET_GAME_STATE (SIS.FuelOnBoard) < capacity) Response (buy_fuel, DoBuy); if (GetNextTechForSale ()) Response (buy_technology, DoBuy); @@ -1321,7 +1283,7 @@ NatureOfConversation (RESPONSE_REF R) rainbow_mask >>= 1; } - if (GLOBAL_SIS (FuelOnBoard) > 0 + if (GET_GAME_STATE (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 72076a67a..35f4d1f91 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 5db575d4a..6dadfd5f3 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 e76d8d0a6..40781550c 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), i_am_captain1, buf, i_am_captain2, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 80cb83979..d3634060c 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_us1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 190e3bb38..053154258 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 5f25a2dba..b78eb426a 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 - && GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY - && GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY + && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY + && GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < CREW_POD_CAPACITY) + if (GET_GAME_STATE (SIS.CrewEnlisted) < CREW_POD_CAPACITY) NPCPhrase (NEED_CREW_1); - if (GLOBAL_SIS (FuelOnBoard) < FUEL_TANK_CAPACITY) + if (GET_GAME_STATE (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 (GLOBAL_SIS (ResUnits) >= 3000) + if (GET_GAME_STATE (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 - && GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY * 3 - && GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY * 3 - && GLOBAL_SIS (NumLanders) >= 3 + && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY * 3 + && GET_GAME_STATE (SIS.FuelOnBoard) >= FUEL_TANK_CAPACITY * 3 + && GET_GAME_STATE (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 (GLOBAL_SIS (ResUnits) >= 3000) + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) < CREW_POD_CAPACITY * 3) + if (GET_GAME_STATE (SIS.CrewEnlisted) < CREW_POD_CAPACITY * 3) NPCPhrase (NEED_CREW_2); - if (GLOBAL_SIS (FuelOnBoard) < FUEL_TANK_CAPACITY * 3) + if (GET_GAME_STATE (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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 e169cbab7..931b41f0d 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 8884ad6b0..3ca05e093 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_are_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 ce59011b7..473389e7c 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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 1be8a1e4a..d11fbe1f0 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (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 d9debd540..2bd9333b6 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), we_vindicator1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 53bacbb26..dc70e0dbb 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (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 c1860bf16..3e46530d9 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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), i_demand_you_ally_homeworld1, buf, i_demand_you_ally_homeworld2, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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, - GLOBAL_SIS (CommanderName), + GET_GAME_STATE_STRING (SIS.CommanderName), i_demand_you_ally_space1, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (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 d09a7f7bb..727116ce8 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, - GLOBAL_SIS (ShipName), + GET_GAME_STATE_STRING (SIS.ShipName), we_are_vindicator2, (UNICODE*)NULL); } diff --git a/sc2/src/uqm/commglue.c b/sc2/src/uqm/commglue.c index a7b514ccb..b30e07a9a 100644 --- a/sc2/src/uqm/commglue.c +++ b/sc2/src/uqm/commglue.c @@ -35,18 +35,21 @@ static int NPCNumberPhrase (int number, const char *fmt, UNICODE **ptrack); void NPCPhrase_cb (int index, CallbackFunction cb) { - UNICODE *pStr, buf[400]; + UNICODE *pStr; + UNICODE buf[400]; void *pClip, *pTimeStamp; switch (index) { case GLOBAL_PLAYER_NAME: - pStr = GLOBAL_SIS (CommanderName); + strcpy (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); + pStr = buf; pClip = 0; pTimeStamp = 0; break; case GLOBAL_SHIP_NAME: - pStr = GLOBAL_SIS (ShipName); + strcpy (buf, GET_GAME_STATE_STRING (SIS.ShipName)); + pStr = buf; pClip = 0; pTimeStamp = 0; break; @@ -66,7 +69,7 @@ NPCPhrase_cb (int index, CallbackFunction cb) S = SetAbsStringTableIndex (CommData.ConversationPhrases, (index - 1) + i); strcpy (buf, (UNICODE *)GetStringAddress (S)); if (i == 3) - strcat (buf, GLOBAL_SIS (CommanderName)); + strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); pStr = buf; pClip = 0; @@ -252,7 +255,7 @@ GetAllianceName (UNICODE *buf, RESPONSE_REF name_1) strcpy (buf, (UNICODE *)GetStringAddress (S)); if (i == 3) { - strcat (buf, GLOBAL_SIS (CommanderName)); + strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName)); strcat (buf, (UNICODE *)GetStringAddress (SetRelStringTableIndex (S, 1))); } } @@ -329,7 +332,7 @@ setSegue (Segue segue) break; case Segue_defeat: SET_GAME_STATE (BATTLE_SEGUE, 0); - GLOBAL_SIS(CrewEnlisted) = (COUNT)~0; + SET_GAME_STATE(SIS.CrewEnlisted, (COUNT)~0); GLOBAL(CurrentActivity) |= CHECK_RESTART; break; } @@ -339,7 +342,7 @@ Segue getSegue (void) { if (GET_GAME_STATE(BATTLE_SEGUE) == 0) { - if (GLOBAL_SIS(CrewEnlisted) == (COUNT)~0 && + if (GET_GAME_STATE(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 9ab75c5a1..18373147e 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 = GLOBAL_SIS (PlanetName); + t.pStr = GET_GAME_STATE_STRING (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)) - || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 + || GET_GAME_STATE (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(GLOBAL_SIS (PlanetName)); + DrawSISTitle(GET_GAME_STATE_STRING (SIS.PlanetName)); SetContext (SpaceContext); if (VictoryState) @@ -822,7 +822,7 @@ EncounterBattle (void) GameSounds = 0; if (GLOBAL (CurrentActivity) & CHECK_ABORT) - GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; + SET_GAME_STATE (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 352bafc93..b04493369 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); - GLOBAL (CrewCost) -= 2; + SET_GAME_STATE (CrewCost, GET_GAME_STATE (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; - GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; + SET_GAME_STATE (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 ba42a3b1e..5429824f2 100644 --- a/sc2/src/uqm/gameopt.c +++ b/sc2/src/uqm/gameopt.c @@ -315,7 +315,8 @@ NameCaptainOrShip (bool nameCaptain) { UNICODE buf[MAX_NAME_SIZE] = ""; TEXTENTRY_STATE tes; - UNICODE *Setting; + const UNICODE *Setting; + const UNICODE *Old; SetContext (StatusContext); SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect); @@ -326,14 +327,15 @@ NameCaptainOrShip (bool nameCaptain) if (nameCaptain) { - Setting = GLOBAL_SIS (CommanderName); - tes.MaxSize = sizeof (GLOBAL_SIS (CommanderName)); + Setting = "SIS.CommanderName"; + tes.MaxSize = SIS_NAME_SIZE; } else { - Setting = GLOBAL_SIS (ShipName); - tes.MaxSize = sizeof (GLOBAL_SIS (ShipName)); + Setting = "SIS.ShipName"; + tes.MaxSize = SIS_NAME_SIZE; } + Old= getGameState_string_json( Setting ); // text entry setup tes.Initialized = FALSE; @@ -344,9 +346,12 @@ NameCaptainOrShip (bool nameCaptain) tes.FrameCallback = 0; if (DoTextEntry (&tes)) - utf8StringCopy (Setting, tes.MaxSize, buf); + { + buf[ tes.MaxSize ]= '\0'; + setGameState_string_json( Setting, buf ); + } else - utf8StringCopy (buf, sizeof (buf), Setting); + utf8StringCopy (buf, sizeof (buf), Old); SetFlashRect (SFR_MENU_3DO); @@ -731,6 +736,11 @@ 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; @@ -934,6 +944,7 @@ 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 new file mode 100644 index 000000000..ec9501b25 --- /dev/null +++ b/sc2/src/uqm/gamestate-modern.cpp @@ -0,0 +1,110 @@ +#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 4bf14f8da..37df6db16 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; - GLOBAL_SIS (CrewEnlisted) = CREW_POD_CAPACITY; + SET_GAME_STATE (SIS.CrewEnlisted, CREW_POD_CAPACITY); GLOBAL_SIS (ModuleSlots[8]) = STORAGE_BAY; GLOBAL_SIS (ModuleSlots[1]) = FUEL_TANK; - GLOBAL_SIS (FuelOnBoard) = 10 * FUEL_TANK_SCALE; + SET_GAME_STATE (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; - GLOBAL_SIS (ResUnits) = 0; - GLOBAL (CrewCost) = 3; - GLOBAL (FuelCost) = 20; + SET_GAME_STATE (SIS.ResUnits, 0); + SET_GAME_STATE (CrewCost, 3); + SET_GAME_STATE (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,11 +346,8 @@ InitGameStructures (void) GLOBAL_SIS (NumLanders) = 1; - 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)); + SET_GAME_STATE_STRING (SIS.ShipName, GAME_STRING (NAMING_STRING_BASE + 2)); + SET_GAME_STATE_STRING (SIS.CommanderName, GAME_STRING (NAMING_STRING_BASE + 3)); SetRaceAllied (HUMAN_SHIP, TRUE); CloneShipFragment (HUMAN_SHIP, &GLOBAL (built_ship_q), 0); @@ -372,7 +369,7 @@ InitGameStructures (void) const int equipment[]= { - FUEL_TANK, + HIGHEFF_FUELSYS, HIGHEFF_FUELSYS, SHIVA_FURNACE, @@ -380,10 +377,10 @@ InitGameStructures (void) DYNAMO_UNIT, DYNAMO_UNIT, - SHIVA_FURNACE, - SHIVA_FURNACE, - SHIVA_FURNACE, - SHIVA_FURNACE, + STORAGE_BAY, + CREW_POD, + CREW_POD, + CREW_POD, TRACKING_SYSTEM, @@ -397,8 +394,8 @@ InitGameStructures (void) const int ck_[ sizeof( equipment ) / sizeof( int ) == 16 ? 1 : -1 ]; (void) ck_; - GLOBAL_SIS( CrewEnlisted )= 0; - GLOBAL_SIS( FuelOnBoard )= 10 * FUEL_TANK_SCALE; + SET_GAME_STATE( SIS.CrewEnlisted, 0 ); + SET_GAME_STATE( SIS.FuelOnBoard, 10 * FUEL_TANK_SCALE); for( int i= 0; i < 16; ++i ) { const int module= equipment[ i ]; @@ -406,15 +403,15 @@ InitGameStructures (void) if( false ) {} else if( module == CREW_POD ) { - GLOBAL_SIS( CrewEnlisted )+= CREW_POD_CAPACITY; + SET_GAME_STATE( SIS.CrewEnlisted, GET_GAME_STATE( SIS.CrewEnlisted ) + CREW_POD_CAPACITY ); } else if( module == FUEL_TANK ) { - GLOBAL_SIS( FuelOnBoard )+= FUEL_TANK_CAPACITY; + SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE( SIS.FuelOnBoard ) + FUEL_TANK_CAPACITY ); } else if( module == HIGHEFF_FUELSYS ) { - GLOBAL_SIS( FuelOnBoard )+= HEFUEL_TANK_CAPACITY; + SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE( SIS.FuelOnBoard ) + HEFUEL_TANK_CAPACITY ); } } diff --git a/sc2/src/uqm/globdata.h b/sc2/src/uqm/globdata.h index 216cadf11..3c6df21dc 100644 --- a/sc2/src/uqm/globdata.h +++ b/sc2/src/uqm/globdata.h @@ -27,7 +27,11 @@ #include "velocity.h" #include "commanim.h" +#include + #if defined(__cplusplus) +#include + extern "C" { #endif @@ -172,10 +176,44 @@ 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) @@ -253,7 +291,7 @@ START_GAME_STATE * 9 means completely open. */ - ADD_GAME_STATE (LANDER_SHIELDS, 4) + // ADD_GAME_STATE (LANDER_SHIELDS, 4) // Lander shields are individual bits, now. ADD_GAME_STATE (MET_MELNORME, 1) ADD_GAME_STATE (MELNORME_RESCUE_REFUSED, 1) @@ -881,6 +919,22 @@ 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: @@ -922,7 +976,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]; @@ -958,7 +1012,9 @@ 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 @@ -1006,32 +1062,61 @@ extern void setGameState (BYTE *state, int startBit, int endBit, BYTE val ); extern void copyGameState (BYTE *dest, DWORD target, BYTE *src, DWORD begin, DWORD end); -#define GET_GAME_STATE(SName) getGameState (GLOBAL(GameState), (SName), (END_##SName)) +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)) #ifdef STATE_DEBUG -# define SET_GAME_STATE(SName, val) \ +# define xSET_GAME_STATE(SName, val) \ setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName) #else -# define SET_GAME_STATE(SName, val) \ +# define xSET_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 GET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) +#define xGET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) #ifdef STATE_DEBUG -# define SET_GAME_STATE_32(SName, val) \ +# define xSET_GAME_STATE_32(SName, val) \ setGameState32 (GLOBAL(GameState), (SName), (val), #SName) #else -# define SET_GAME_STATE_32(SName, val) \ +# define xSET_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 9ef55a91f..01662093b 100644 --- a/sc2/src/uqm/hyper.c +++ b/sc2/src/uqm/hyper.c @@ -122,7 +122,7 @@ MoveSIS (SIZE *pdx, SIZE *pdy) } } - if (GLOBAL_SIS (FuelOnBoard) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + if (GET_GAME_STATE (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 - && (GLOBAL_SIS (FuelOnBoard) == 0 + && (GET_GAME_STATE (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)) - || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) + || GET_GAME_STATE (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 new file mode 100644 index 000000000..ab48c612e --- /dev/null +++ b/sc2/src/uqm/load-modern.cpp @@ -0,0 +1,119 @@ +//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 17c78d38f..ce3d4a0da 100644 --- a/sc2/src/uqm/load_legacy.c +++ b/sc2/src/uqm/load_legacy.c @@ -199,6 +199,7 @@ 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, @@ -214,6 +215,7 @@ 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 fc46e3b4c..ddac758a0 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), - GLOBAL (CrewCost)); + GET_GAME_STATE (CrewCost)); if (beg_index == PM_FUEL) snprintf (pm_fuel_str, sizeof pm_fuel_str, "%s(%d)", GAME_STRING (MAINMENU_STRING_BASE + PM_FUEL), - GLOBAL (FuelCost)); + GET_GAME_STATE (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", GLOBAL (CrewCost)); + snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (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", GLOBAL (FuelCost)); + snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (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 458dfa00c..591d89078 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 = GLOBAL_SIS (FuelOnBoard); + const DWORD FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard); const CONTEXT OldContext = SetContext (SpaceContext); RECT r; r.extent.height = 1; // Loop through all the rows to draw BatchGraphics (); - for (GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; - GLOBAL_SIS (FuelOnBoard) < GetFTankCapacity (&r.corner); - GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) + 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)) { // If we're less than the fuel level, draw fuel. - if (GLOBAL_SIS (FuelOnBoard) < FuelVolume) + if (GET_GAME_STATE (SIS.FuelOnBoard) < FuelVolume) { r.extent.width = 3; DrawPoint (&r.corner); @@ -132,7 +132,7 @@ RedistributeFuel (void) UnbatchGraphics (); SetContext (OldContext); - GLOBAL_SIS (FuelOnBoard) = FuelVolume; + SET_GAME_STATE (SIS.FuelOnBoard, FuelVolume); } #define LANDER_X 24 @@ -247,7 +247,7 @@ DoInstallModule (MENU_STATE *pMS) { if (new_slot_piece < EMPTY_SLOT) { - if (GLOBAL_SIS (ResUnits) < + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) > CREW_POD_CAPACITY + if (((int)GET_GAME_STATE (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 (GLOBAL_SIS (FuelOnBoard) > volume + FUEL_RESERVE) + if (GET_GAME_STATE (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 () - GLOBAL_SIS (FuelOnBoard); - const int maxAfford = GLOBAL_SIS (ResUnits) / GLOBAL (FuelCost); - const int minFit = - (int) GLOBAL_SIS (FuelOnBoard); + 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); if (incr > maxFit) incr = maxFit; // All we can hold. @@ -578,7 +578,7 @@ ChangeFuelQuantity (void) } else { - const int cost = (incr / FUEL_TANK_SCALE) * GLOBAL (FuelCost); + const int cost = (incr / FUEL_TANK_SCALE) * GET_GAME_STATE (FuelCost); PreUpdateFlashRect (); DeltaSISGauges (0, incr, -cost); PostUpdateFlashRect (); @@ -670,22 +670,18 @@ 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 (ShieldFlags & (1 << EARTHQUAKE_DISASTER)) + if (GET_GAME_STATE (LANDER_SHIELD_QUAKE)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (ShieldFlags & (1 << BIOLOGICAL_DISASTER)) + if (GET_GAME_STATE (LANDER_SHIELD_BIO)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (ShieldFlags & (1 << LIGHTNING_DISASTER)) + if (GET_GAME_STATE (LANDDER_SHIELD_LIGHTNING)) DrawStamp (&s); s.frame = IncFrameIndex (s.frame); - if (ShieldFlags & (1 << LAVASPOT_DISASTER)) + if (GET_GAME_STATE (LANDER_SHIELD_HEAT)) DrawStamp (&s); } @@ -700,10 +696,10 @@ DoOutfit (MENU_STATE *pMS) SetFlashRect (SFR_MENU_3DO); - GLOBAL_SIS (FuelOnBoard) = - (GLOBAL_SIS (FuelOnBoard) - + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE; - GLOBAL_SIS (FuelOnBoard) *= FUEL_TANK_SCALE; + 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); } SetContext (StatusContext); diff --git a/sc2/src/uqm/pickship.c b/sc2/src/uqm/pickship.c index 3dcced0d5..53e98ecb5 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 = GLOBAL_SIS (CommanderName); + t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName); t.CharCount = (COUNT)~0; - crew_level = GLOBAL_SIS (CrewEnlisted); + crew_level = GET_GAME_STATE (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 - GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; + SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0); } else { // Player ran away - if (GLOBAL_SIS (FuelOnBoard) > RUN_AWAY_FUEL_COST) - GLOBAL_SIS (FuelOnBoard) -= RUN_AWAY_FUEL_COST; + if (GET_GAME_STATE (SIS.FuelOnBoard) > RUN_AWAY_FUEL_COST) + SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) - RUN_AWAY_FUEL_COST); else - GLOBAL_SIS (FuelOnBoard) = 0; + SET_GAME_STATE (SIS.FuelOnBoard, 0); } } return 0; @@ -397,6 +397,7 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect) TEXT t; CONTEXT OldContext; FRAME PickFrame; + UNICODE buf[ SIS_NAME_SIZE ]; OldContext = SetContext (SpaceContext); @@ -435,7 +436,8 @@ 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 = GLOBAL_SIS (ShipName); + t.pStr = buf; + strncpy(buf, GET_GAME_STATE_STRING (SIS.ShipName), SIS_NAME_SIZE); 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 eca79a1f4..fc5f94c9b 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; - GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; + SET_GAME_STATE (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 () - && GLOBAL_SIS (FuelOnBoard) >= PORTAL_FUEL_COST) + && GET_GAME_STATE (SIS.FuelOnBoard) >= PORTAL_FUEL_COST) { /* No DeltaSISGauges because the flagship picture * is currently obscured. */ - GLOBAL_SIS (FuelOnBoard) -= PORTAL_FUEL_COST; + SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0 + if (GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0 && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { ClearSISRect (DRAW_SIS_DISPLAY); if (!GET_GAME_STATE (PORTAL_COUNTER) && !(GLOBAL (CurrentActivity) & START_ENCOUNTER) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + && GET_GAME_STATE (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 a88b89cb7..ee7117582 100644 --- a/sc2/src/uqm/planets/generate/gendefault.c +++ b/sc2/src/uqm/planets/generate/gendefault.c @@ -106,8 +106,11 @@ GenerateDefault_generateName (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world) { COUNT i = planetIndex (solarSys, world); - utf8StringCopy (GLOBAL_SIS (PlanetName), sizeof (GLOBAL_SIS (PlanetName)), + UNICODE buf[ SIS_NAME_SIZE ]; + utf8StringCopy (buf, SIS_NAME_SIZE, 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 f6db88e40..0815053a2 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 int SelectMelnormeRefVar(); + static std::string SelectMelnormeRefVar(); static DWORD GetMelnormeRef(); static void SetMelnormeRef( DWORD Ref ); }; @@ -81,26 +81,26 @@ GenerateMelnorme::initNpcs( SolarSystem *const solarSys ) } -int +std::string GenerateMelnorme::SelectMelnormeRefVar() { const auto arg_p= CurStarDescPtr->supArg; const std::string arg= arg_p ? arg_p : ""; - static const std::map< std::string, int > lookups + static const std::map< std::string, std::string > 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 ) ) return -1; + if( not lookups.count( arg ) ) throw std::runtime_error{ "Invalid Melnorme system" }; return lookups.at( arg ); } @@ -108,26 +108,26 @@ GenerateMelnorme::SelectMelnormeRefVar() DWORD GenerateMelnorme::GetMelnormeRef() { - int RefVar = SelectMelnormeRefVar (); - if (RefVar < 0) - { - log_add (log_Warning, "GetMelnormeRef(): reference unknown"); - return 0; - } + const auto RefVar = SelectMelnormeRefVar (); + //if (RefVar < 0) + //{ + //log_add (log_Warning, "GetMelnormeRef(): reference unknown"); + //return 0; + //} - return GET_GAME_STATE_32 (RefVar); + return getGameState_json( RefVar.c_str() ); } void GenerateMelnorme::SetMelnormeRef( DWORD Ref ) { - int RefVar = SelectMelnormeRefVar (); - if (RefVar < 0) - { - log_add (log_Warning, "SetMelnormeRef(): reference unknown"); - return; - } + const auto RefVar = SelectMelnormeRefVar (); + //if (RefVar < 0) + //{ + //log_add (log_Warning, "SetMelnormeRef(): reference unknown"); + //return; + //} - SET_GAME_STATE_32 (RefVar, Ref); + setGameState_json (RefVar.c_str(), Ref); } diff --git a/sc2/src/uqm/planets/generate/genpet-modern.cpp b/sc2/src/uqm/planets/generate/genpet-modern.cpp index f60fa7335..5abadac75 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 (GLOBAL_SIS (FuelOnBoard) < 5 * FUEL_TANK_SCALE) + if (GET_GAME_STATE (SIS.FuelOnBoard) < 5 * FUEL_TANK_SCALE) { dx = ((5 + ((COUNT)TFB_Random () % 5)) * FUEL_TANK_SCALE) - - (SIZE)GLOBAL_SIS (FuelOnBoard); + - (SIZE)GET_GAME_STATE (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 1d4c36e8d..2e750a2d1 100644 --- a/sc2/src/uqm/planets/generate/gensol-modern.cpp +++ b/sc2/src/uqm/planets/generate/gensol-modern.cpp @@ -340,28 +340,26 @@ GenerateSol::generateName (const SolarSystem *const solarSys, if( matchWorld( solarSys, world, 3, 0 ) ) { fprintf( stderr, "ADAM: Trying to set Phobos\n" ); - utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), - "Phobos" ); + setGameState_string_json( "SIS.PlanetName", "Phobos" ); } else if( matchWorld( solarSys, world, 3, 1 ) ) { fprintf( stderr, "ADAM: Trying to set Deimos\n" ); - utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), - "Deimos" ); + setGameState_string_json( "SIS.PlanetName", "Deimos" ); } else if( matchWorld( solarSys, world, 4, MATCH_PLANET ) ) { fprintf( stderr, "ADAM: Trying to set Ceres\n" ); - utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), - "Ceres" ); + setGameState_string_json( "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; - utf8StringCopy (GLOBAL_SIS (PlanetName), sizeof (GLOBAL_SIS (PlanetName)), - GAME_STRING (PLANET_NUMBER_BASE + xPlanetNr)); + 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() ); } 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 17aad8fe5..5276de8f1 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) - && GLOBAL_SIS (CrewEnlisted); ++num_crew) + && GET_GAME_STATE (SIS.CrewEnlisted); ++num_crew) { animationInterframe (&TimeIn, 1); diff --git a/sc2/src/uqm/planets/planets.c b/sc2/src/uqm/planets/planets.c index c76c2bbe6..d85f53d1c 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 (GLOBAL_SIS (PlanetName)); + DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName)); DrawStarBackGround (); DrawPlanetSurfaceBorder (); } @@ -369,7 +369,7 @@ DoPlanetOrbit (MENU_STATE *pMS) BOOLEAN handled; if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) - || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) + || GET_GAME_STATE (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 adf368514..efdec3532 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)GLOBAL_SIS (FuelOnBoard) << 1)) + && (diameter = (long)GET_GAME_STATE (SIS.FuelOnBoard) << 1)) { Color OldColor; diff --git a/sc2/src/uqm/planets/roster.c b/sc2/src/uqm/planets/roster.c index 663ac2836..b95d89f9b 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 (GLOBAL_SIS (CrewEnlisted)) + if (GET_GAME_STATE (SIS.CrewEnlisted)) delta = 1; else failed = TRUE; } else if (down) { - if (GLOBAL_SIS (CrewEnlisted) < GetCrewPodCapacity ()) + if (GET_GAME_STATE (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 3d5d9fd7b..57ff661f5 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 (GLOBAL_SIS (FuelOnBoard) < fuel_required + if (GET_GAME_STATE (SIS.FuelOnBoard) < fuel_required || GLOBAL_SIS (NumLanders) == 0 - || GLOBAL_SIS (CrewEnlisted) == 0) + || GET_GAME_STATE (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 d351181a3..35dd76fdd 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 (GLOBAL_SIS (PlanetName)); + DrawSISTitle (GET_GAME_STATE_STRING (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)) || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 + START_ENCOUNTER)) || GET_GAME_STATE (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)) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + && GET_GAME_STATE (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, GLOBAL_SIS (PlanetName)); + utf8StringCopy (buf, bufsize, GET_GAME_STATE_STRING (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)) - || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) + || GET_GAME_STATE (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)) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0); + && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0); } diff --git a/sc2/src/uqm/restart.c b/sc2/src/uqm/restart.c index f52e753b4..524b1dc71 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 (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 + if (GET_GAME_STATE (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 28852b8ae..457496953 100644 --- a/sc2/src/uqm/save.h +++ b/sc2/src/uqm/save.h @@ -65,11 +65,11 @@ typedef struct extern ACTIVITY NextActivity; -extern BOOLEAN LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); -extern BOOLEAN LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc); +extern bool LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); +extern bool LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc); extern void SaveProblem (void); -extern BOOLEAN SaveGame (COUNT which_game, SUMMARY_DESC *summary_desc, const char *name); +extern bool 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 fd24115eb..f1983a207 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) - || (GLOBAL_SIS (FuelOnBoard) == 0 + || (GET_GAME_STATE (SIS.FuelOnBoard) == 0 && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)) { AccelerateDirection = -1; @@ -314,7 +314,7 @@ LeaveAutoPilot: } GetCurrentVelocityComponents (&ElementPtr->velocity, &dx, &dy); - if ((GLOBAL_SIS (FuelOnBoard) + if ((GET_GAME_STATE (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 = GLOBAL_SIS (CrewEnlisted) + 1; + new_sis_desc.ship_info.crew_level = GET_GAME_STATE (SIS.CrewEnlisted) + 1; new_sis_desc.ship_info.ship_flags |= PLAYER_CAPTAIN; } @@ -1045,9 +1045,9 @@ uninit_sis (RACE_DESC *pRaceDesc) { if (!inHQSpace ()) { - GLOBAL_SIS (CrewEnlisted) = pRaceDesc->ship_info.crew_level; + SET_GAME_STATE (SIS.CrewEnlisted, pRaceDesc->ship_info.crew_level); if (pRaceDesc->ship_info.ship_flags & PLAYER_CAPTAIN) - GLOBAL_SIS (CrewEnlisted)--; + SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) - 1); } SetCustomShipData (pRaceDesc, NULL); diff --git a/sc2/src/uqm/shipstat.c b/sc2/src/uqm/shipstat.c index 040542660..4ff25a1e0 100644 --- a/sc2/src/uqm/shipstat.c +++ b/sc2/src/uqm/shipstat.c @@ -56,14 +56,16 @@ DrawCrewFuelString (COORD y, SIZE state) } static void -DrawShipNameString (UNICODE *pStr, COUNT CharCount, COORD y) +DrawShipNameString (const 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 = pStr; + Text.pStr = buf; Text.CharCount = CharCount; Text.align = ALIGN_CENTER; @@ -277,7 +279,7 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) else if (StarShipPtr->playerNr == RPG_PLAYER_NUM) { // This is SIS DrawCrewFuelString (y, 0); - DrawShipNameString (GLOBAL_SIS (ShipName), (COUNT)~0, y); + DrawShipNameString (GET_GAME_STATE_STRING (SIS.ShipName), (COUNT)~0, y); } { diff --git a/sc2/src/uqm/shipyard.c b/sc2/src/uqm/shipyard.c index f317ba338..64cff79b8 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) { - GLOBAL (CrewCost) += 2; + SET_GAME_STATE (CrewCost, GET_GAME_STATE (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) { - GLOBAL (CrewCost) -= 2; + SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) - 2); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW); } } @@ -724,7 +724,7 @@ DMS_HireFlagShipCrew (void) return 0; } - if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + if (GET_GAME_STATE (SIS.ResUnits) < (DWORD)GET_GAME_STATE (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, -GLOBAL (CrewCost)); + DeltaSISGauges (1, 0, -GET_GAME_STATE (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, GLOBAL (CrewCost) - + DeltaSISGauges (-1, 0, GET_GAME_STATE (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 (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) + if (GET_GAME_STATE (SIS.ResUnits) < (DWORD)GET_GAME_STATE (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, -GLOBAL (CrewCost)); + DeltaSISGauges (0, 0, -GET_GAME_STATE (CrewCost)); } else { @@ -855,7 +855,7 @@ DMS_DismissEscortShipCrew (SHIP_FRAGMENT *StarShipPtr) GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED1)); - DeltaSISGauges (0, 0, GLOBAL (CrewCost) + DeltaSISGauges (0, 0, GET_GAME_STATE (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 (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index] + if (GET_GAME_STATE (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 = GLOBAL_SIS (CrewEnlisted); - GLOBAL_SIS (CrewEnlisted) = 0; + num_frames = GET_GAME_STATE (SIS.CrewEnlisted); + SET_GAME_STATE (SIS.CrewEnlisted, 0); while (num_frames--) { @@ -1328,7 +1328,7 @@ DrawBluePrint (MENU_STATE *pMS) GetCPodCapacity (&pt); DrawPoint (&pt); - ++GLOBAL_SIS (CrewEnlisted); + SET_GAME_STATE( SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + 1 ); } } { @@ -1351,13 +1351,13 @@ DrawBluePrint (MENU_STATE *pMS) num_frames -= m; } } - if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) + if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE) { DWORD FuelVolume; RECT r; - FuelVolume = GLOBAL_SIS (FuelOnBoard) - FUEL_RESERVE; - GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; + FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard) - FUEL_RESERVE; + SET_GAME_STATE (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; - GLOBAL_SIS (FuelOnBoard) += m; + SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + m ); FuelVolume -= m; } } diff --git a/sc2/src/uqm/sis.c b/sc2/src/uqm/sis.c index f5c0af784..4abb3a96f 100644 --- a/sc2/src/uqm/sis.c +++ b/sc2/src/uqm/sis.c @@ -123,16 +123,18 @@ ClearSISRect (BYTE ClearFlags) // right hand side, containing the coordinates in HyperSpace, or the planet // name in IP. void -DrawSISTitle (UNICODE *pStr) +DrawSISTitle (const 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 = pStr; + t.pStr = buf; t.CharCount = (COUNT)~0; OldContext = SetContext (OffScreenContext); @@ -398,7 +400,7 @@ DrawStatusMessage (const UNICODE *pStr) { if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 2) { - snprintf (buf, sizeof buf, "%u %s", GLOBAL_SIS (ResUnits), + snprintf (buf, sizeof buf, "%u %s", GET_GAME_STATE (SIS.ResUnits), GAME_STRING (STATUS_STRING_BASE + 1)); // "RU" } else @@ -466,7 +468,7 @@ DrawCaptainsName (void) t.baseline.x = (STATUS_WIDTH >> 1) - 1; t.baseline.y = r.corner.y + 6; t.align = ALIGN_CENTER; - t.pStr = GLOBAL_SIS (CommanderName); + t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName); t.CharCount = (COUNT)~0; SetContextForeGroundColor (CAPTAIN_NAME_TEXT_COLOR); font_DrawText (&t); @@ -497,7 +499,7 @@ DrawFlagshipName (BOOLEAN InStatusArea) r.extent.width = SHIP_NAME_WIDTH; r.extent.height = SHIP_NAME_HEIGHT; - t.pStr = GLOBAL_SIS (ShipName); + t.pStr = GET_GAME_STATE_STRING (SIS.ShipName); } else { @@ -511,7 +513,7 @@ DrawFlagshipName (BOOLEAN InStatusArea) t.pStr = buf; snprintf (buf, sizeof buf, "%s %s", - GAME_STRING (NAMING_STRING_BASE + 1), GLOBAL_SIS (ShipName)); + GAME_STRING (NAMING_STRING_BASE + 1), GET_GAME_STATE_STRING (SIS.ShipName)); // XXX: this will not work with UTF-8 strings strupr (buf); } @@ -989,14 +991,14 @@ DeltaSISGauges_crewDelta (SIZE crew_delta) COUNT CrewCapacity; if (crew_delta < 0 - && GLOBAL_SIS (CrewEnlisted) <= (COUNT)-crew_delta) - GLOBAL_SIS (CrewEnlisted) = 0; + && GET_GAME_STATE (SIS.CrewEnlisted) <= (COUNT)-crew_delta) + SET_GAME_STATE (SIS.CrewEnlisted, 0); else { - GLOBAL_SIS (CrewEnlisted) += crew_delta; + SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + crew_delta); CrewCapacity = GetCrewPodCapacity (); - if (GLOBAL_SIS (CrewEnlisted) > CrewCapacity) - GLOBAL_SIS (CrewEnlisted) = CrewCapacity; + if (GET_GAME_STATE (SIS.CrewEnlisted) > CrewCapacity) + SET_GAME_STATE(SIS.CrewEnlisted, CrewCapacity); } } @@ -1005,7 +1007,7 @@ DeltaSISGauges_crewDelta (SIZE crew_delta) UNICODE buf[60]; RECT r; - snprintf (buf, sizeof buf, "%u", GLOBAL_SIS (CrewEnlisted)); + snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (SIS.CrewEnlisted)); GetGaugeRect (&r, TRUE); @@ -1038,23 +1040,23 @@ DeltaSISGauges_fuelDelta (SIZE fuel_delta) { old_coarse_fuel = (COUNT)( - GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE); + GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE); if (fuel_delta < 0 - && GLOBAL_SIS (FuelOnBoard) <= (DWORD)-fuel_delta) + && GET_GAME_STATE (SIS.FuelOnBoard) <= (DWORD)-fuel_delta) { - GLOBAL_SIS (FuelOnBoard) = 0; + SET_GAME_STATE (SIS.FuelOnBoard, 0); } else { DWORD FuelCapacity = GetFuelTankCapacity (); - GLOBAL_SIS (FuelOnBoard) += fuel_delta; - if (GLOBAL_SIS (FuelOnBoard) > FuelCapacity) - GLOBAL_SIS (FuelOnBoard) = FuelCapacity; + 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); } } new_coarse_fuel = (COUNT)( - GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE); + GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE); if (new_coarse_fuel != old_coarse_fuel) { TEXT t; @@ -1088,10 +1090,10 @@ DeltaSISGauges_resunitDelta (SIZE resunit_delta) if (resunit_delta != UNDEFINED_DELTA) { if (resunit_delta < 0 - && GLOBAL_SIS (ResUnits) <= (DWORD)-resunit_delta) - GLOBAL_SIS (ResUnits) = 0; + && GET_GAME_STATE (SIS.ResUnits) <= (DWORD)-resunit_delta) + SET_GAME_STATE (SIS.ResUnits, 0); else - GLOBAL_SIS (ResUnits) += resunit_delta; + SET_GAME_STATE (SIS.ResUnits, GET_GAME_STATE (SIS.ResUnits) + resunit_delta); assert (curMsgMode == SMM_RES_UNITS); } @@ -1169,7 +1171,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta) COUNT GetCrewCount (void) { - return GLOBAL_SIS (CrewEnlisted); + return GET_GAME_STATE (SIS.CrewEnlisted); } // Get the number of crew which fit in a module of a specified type. @@ -1376,7 +1378,7 @@ GetSBayCapacity (POINT *ppt) static DWORD GetFuelTotal (void) { - return GLOBAL_SIS (FuelOnBoard); + return GET_GAME_STATE (SIS.FuelOnBoard); } // Get the amount of fuel which fits in a module of a specified type. @@ -1544,7 +1546,7 @@ DrawAutoPilotMessage (BOOLEAN Reset) } OnAutoPilot = (GLOBAL (autopilot.x) != ~0 && GLOBAL (autopilot.y) != ~0) - || GLOBAL_SIS (FuelOnBoard) == 0; + || GET_GAME_STATE (SIS.FuelOnBoard) == 0; if (OnAutoPilot || LastPilot) { @@ -1556,13 +1558,13 @@ DrawAutoPilotMessage (BOOLEAN Reset) else if (GetTimeCounter () >= NextTime) { if (!(GLOBAL (CurrentActivity) & CHECK_ABORT) - && GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) + && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0) { CONTEXT OldContext; OldContext = SetContext (OffScreenContext); SetContextForeGroundColor (cycle_tab[cycle_index]); - if (GLOBAL_SIS (FuelOnBoard) == 0) + if (GET_GAME_STATE (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 4af573cfb..4ae3304bc 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,9 +149,11 @@ 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) @@ -170,7 +172,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 (UNICODE *pStr); +extern void DrawSISTitle (const 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 26cf0185e..4ad1bfed0 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 (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 + if (GET_GAME_STATE (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 (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) + if (GET_GAME_STATE (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 5903e6860..cbd51512d 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 - || GLOBAL_SIS (CrewEnlisted) == (COUNT)~0)) + || GET_GAME_STATE (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 6a588a893..12e633c80 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 = GLOBAL_SIS (CommanderName); + t.pStr = GET_GAME_STATE_STRING (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 9dc0d4e52..90e436142 100644 --- a/sc2/src/uqm/uqmdebug.c +++ b/sc2/src/uqm/uqmdebug.c @@ -284,11 +284,10 @@ equipShip (void) GLOBAL_SIS (JetSlots[i]) = TURNING_JETS; // Shields: - SET_GAME_STATE (LANDER_SHIELDS, - (1 << EARTHQUAKE_DISASTER) | - (1 << BIOLOGICAL_DISASTER) | - (1 << LIGHTNING_DISASTER) | - (1 << LAVASPOT_DISASTER)); + 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); // Lander upgrades: SET_GAME_STATE (IMPROVED_LANDER_SPEED, 1); SET_GAME_STATE (IMPROVED_LANDER_CARGO, 1); @@ -335,19 +334,19 @@ equipShip (void) assert (i <= NUM_MODULE_SLOTS); // Fill the fuel and crew compartments to the maximum. - GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; - GLOBAL_SIS (CrewEnlisted) = 0; + SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE); + SET_GAME_STATE (SIS.CrewEnlisted, 0); for (i = 0; i < NUM_MODULE_SLOTS; i++) { switch (GLOBAL_SIS (ModuleSlots[i])) { case CREW_POD: - GLOBAL_SIS (CrewEnlisted) += CREW_POD_CAPACITY; + SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY); break; case FUEL_TANK: - GLOBAL_SIS (FuelOnBoard) += FUEL_TANK_CAPACITY; + SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + FUEL_TANK_CAPACITY); break; case HIGHEFF_FUELSYS: - GLOBAL_SIS (FuelOnBoard) += HEFUEL_TANK_CAPACITY; + SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + HEFUEL_TANK_CAPACITY); break; } } @@ -984,7 +983,7 @@ void dumpPlanet (FILE *out, const PLANET_DESC *planet) { (*pSolarSysState->genFuncs->generateName) (pSolarSysState, planet); - fprintf (out, "- %-37s %s\n", GLOBAL_SIS (PlanetName), + fprintf (out, "- %-37s %s\n", GET_GAME_STATE_STRING (SIS.PlanetName), planetTypeString (planet->data_index & ~PLANET_SHIELDED)); dumpWorld (out, planet); }