JSONized a lot of the game state.

The core of it was in the byte array, but...

Much of it was in some global task-specific C structs.  I'll
wind up making the macro mess a bit worse, just to get everything
into the JSON fold... then I can go make a pass that makes things
C++ and reduces the complexity down.
This commit is contained in:
2024-04-29 02:38:45 -04:00
parent df807525c7
commit dd54bd09b7
55 changed files with 662 additions and 362 deletions
+12 -5
View File
@@ -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 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 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 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 cons_res.c grpinfo.c hyper.c init.c intel.c intro.c ipdisp.c
load_legacy.c
loadship.c master.c menu.c misc.c oscill.c outfit.c pickship.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 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 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 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 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 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 sis.h sounds.h starbase.h starcon.h state.h status.h tactrans.h
starmap.h starmap.h
units.h uqmdebug.h util.h velocity.h weapon.h" units.h uqmdebug.h util.h velocity.h weapon.h"
uqm_CXXFILES="
gamestate-modern.cpp
load-modern.cpp
"
+4 -4
View File
@@ -1257,7 +1257,7 @@ HailAlien (void)
else else
{ // Default titles: star name + planet name { // Default titles: star name + planet name
DrawSISMessage (NULL); 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) else if (GLOBAL (ip_planet) == 0)
DrawHyperCoords (CurStarDescPtr->star_pt); DrawHyperCoords (CurStarDescPtr->star_pt);
else 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); CloneShipFragment (SAMATRA_SHIP, &GLOBAL (npc_built_ship_q), 0);
InitCommunication (TALKING_PET_CONVERSATION); InitCommunication (TALKING_PET_CONVERSATION);
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0)
{ {
GLOBAL (CurrentActivity) = WON_LAST_BATTLE; GLOBAL (CurrentActivity) = WON_LAST_BATTLE;
} }
@@ -1481,7 +1481,7 @@ RaceCommunication (void)
InitCommunication (ILWRATH_CONVERSATION); InitCommunication (ILWRATH_CONVERSATION);
else else
InitCommunication (CHMMR_CONVERSATION); InitCommunication (CHMMR_CONVERSATION);
if (GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) if (GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0)
{ {
NextActivity = GLOBAL (CurrentActivity) & ~START_ENCOUNTER; NextActivity = GLOBAL (CurrentActivity) & ~START_ENCOUNTER;
if (LOBYTE (NextActivity) == IN_INTERPLANETARY) if (LOBYTE (NextActivity) == IN_INTERPLANETARY)
+6 -6
View File
@@ -140,7 +140,7 @@ ExitConversation (RESPONSE_REF R)
SET_GAME_STATE (CHMMR_STACK, 0); SET_GAME_STATE (CHMMR_STACK, 0);
SET_GAME_STATE (CHMMR_BOMB_STATE, 2); SET_GAME_STATE (CHMMR_BOMB_STATE, 2);
SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 0); SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 0);
GLOBAL_SIS (ResUnits) = 1000000L; SET_GAME_STATE (SIS.ResUnits, 1000000L);
GLOBAL_SIS (NumLanders) = 0; GLOBAL_SIS (NumLanders) = 0;
GLOBAL (ModuleCost[PLANET_LANDER]) = 0; GLOBAL (ModuleCost[PLANET_LANDER]) = 0;
@@ -167,9 +167,9 @@ ExitConversation (RESPONSE_REF R)
if (GET_GAME_STATE (STARBASE_AVAILABLE)) if (GET_GAME_STATE (STARBASE_AVAILABLE))
{ /* Normal game mode - you are transported to Starbase */ { /* Normal game mode - you are transported to Starbase */
GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE);
GLOBAL_SIS (CrewEnlisted) = 0; SET_GAME_STATE (SIS.CrewEnlisted, 0);
GLOBAL_SIS (TotalElementMass) = 0; SET_GAME_STATE (SIS.TotalElementMass, 0);
GLOBAL (ModuleCost[STORAGE_BAY]) = 0; /* disable Storage Bay */ GLOBAL (ModuleCost[STORAGE_BAY]) = 0; /* disable Storage Bay */
for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i) for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i)
GLOBAL_SIS (ElementAmounts[i]) = 0; GLOBAL_SIS (ElementAmounts[i]) = 0;
@@ -593,9 +593,9 @@ Intro (void)
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
i_am_captain0, i_am_captain0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
i_am_captain1, i_am_captain1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
i_am_captain2, i_am_captain2,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (i_am_captain0, ChmmrFree, shared_phrase_buf); DoResponsePhrase (i_am_captain0, ChmmrFree, shared_phrase_buf);
+7 -7
View File
@@ -145,7 +145,7 @@ ByeBye (RESPONSE_REF R)
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
name_40, name_40,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
name_41, name_41,
(UNICODE*)NULL); (UNICODE*)NULL);
@@ -265,7 +265,7 @@ NoRadioactives (RESPONSE_REF R)
else else
Response (i_lost_my_lander, NoRadioactives); 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)) if (GET_GAME_STATE (GIVEN_FUEL_BEFORE))
Response (need_fuel_again, NoRadioactives); Response (need_fuel_again, NoRadioactives);
@@ -330,7 +330,7 @@ AskAfterRadios (RESPONSE_REF R)
else else
Response (i_lost_my_lander, AskAfterRadios); 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)) if (GET_GAME_STATE (GIVEN_FUEL_BEFORE))
Response (need_fuel_again, AskAfterRadios); Response (need_fuel_again, AskAfterRadios);
@@ -431,7 +431,7 @@ TellMoonBase (RESPONSE_REF R)
else else
Response (i_lost_my_lander, TellMoonBase); 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)) if (GET_GAME_STATE (GIVEN_FUEL_BEFORE))
Response (need_fuel_again, TellMoonBase); Response (need_fuel_again, TellMoonBase);
@@ -538,9 +538,9 @@ RevealSelf (RESPONSE_REF R)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (we_are_vindicator0, RevealSelf, shared_phrase_buf); DoResponsePhrase (we_are_vindicator0, RevealSelf, shared_phrase_buf);
@@ -639,7 +639,7 @@ Intro (void)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
no_but_well_help0, no_but_well_help0,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
no_but_well_help1, no_but_well_help1,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (no_but_well_help0, NoRadioactives, shared_phrase_buf); DoResponsePhrase (no_but_well_help0, NoRadioactives, shared_phrase_buf);
+9 -9
View File
@@ -182,12 +182,12 @@ ExitConversation (RESPONSE_REF R)
if (SlaveryCount > 250 && PreviousSlaves <= 250) if (SlaveryCount > 250 && PreviousSlaves <= 250)
{ {
if (PreviousSlaves > 100) if (PreviousSlaves > 100)
GLOBAL (CrewCost) += (22 - 7); SET_GAME_STATE (CrewCost, GET_GAME_STATE(CrewCost) + 22 - 7);
else else
GLOBAL (CrewCost) += 22; SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) + 22);
} }
else if (SlaveryCount > 100 && PreviousSlaves <= 100) 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_DRUUGE0, LOBYTE (SlaveryCount));
SET_GAME_STATE (CREW_SOLD_TO_DRUUGE1, HIBYTE (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)) else if (PLAYER_SAID (R, buy_druuge_ship))
{ {
#define SHIP_CREW_COST 100 #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); NPCPhrase (NOT_ENOUGH_CREW);
else if (EscortFeasibilityStudy (DRUUGE_SHIP) == 0) else if (EscortFeasibilityStudy (DRUUGE_SHIP) == 0)
NPCPhrase (NOT_ENOUGH_ROOM); NPCPhrase (NOT_ENOUGH_ROOM);
@@ -254,7 +254,7 @@ Buy (RESPONSE_REF R)
#define ARTIFACT_CREW_COST 100 #define ARTIFACT_CREW_COST 100
else if (PLAYER_SAID (R, buy_rosy_sphere)) 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); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
@@ -268,7 +268,7 @@ Buy (RESPONSE_REF R)
} }
else if (PLAYER_SAID (R, buy_art_1)) 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); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
@@ -281,7 +281,7 @@ Buy (RESPONSE_REF R)
} }
else if (PLAYER_SAID (R, buy_art_2)) 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); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
@@ -295,7 +295,7 @@ Buy (RESPONSE_REF R)
else if (PLAYER_SAID (R, buy_fuel)) else if (PLAYER_SAID (R, buy_fuel))
{ {
#define FUEL_CREW_COST 10 #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); NPCPhrase (NOT_ENOUGH_CREW);
else else
{ {
@@ -453,7 +453,7 @@ DoTransaction (RESPONSE_REF R)
capacity += volume; capacity += volume;
} }
} while (slot--); } while (slot--);
capacity -= GLOBAL_SIS (FuelOnBoard); capacity -= GET_GAME_STATE (SIS.FuelOnBoard);
f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE); f = (COUNT)((capacity + (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE);
while (capacity > 0x3FFFL) while (capacity > 0x3FFFL)
+33 -71
View File
@@ -238,30 +238,34 @@ typedef struct
{ {
TechId_t id; // ID of the technology TechId_t id; // ID of the technology
TechType_t type; // Type of the technology TechType_t type; // Type of the technology
int subtype; // Subtype of the technology const char *subtype; // Subtype of the technology
int info; // Supplemental information int info; // Supplemental information
} TechData; } TechData;
#define TECH_DATA( id, type, subtype, info ) { id, type, "HaveTech"#subtype, info }
// A table of the available technologies. // A table of the available technologies.
// This should really be an associative map of TechIds to tech data records, // This should really be an associative map of TechIds to tech data records,
// but implementing that would be excessive. // but implementing that would be excessive.
static const TechData tech_data_table[] = 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 ID Tech Type, Supplemental info
{ TECH_MODULE_BLASTER, TECH_TYPE_MODULE, BLASTER_WEAPON, 4000 }, TECH_DATA( TECH_MODULE_BLASTER, TECH_TYPE_MODULE, BLASTER_WEAPON, 4000 ),
{ TECH_LANDER_SPEED, TECH_TYPE_STATE, IMPROVED_LANDER_SPEED, 1 }, TECH_DATA( TECH_LANDER_SPEED, TECH_TYPE_STATE, IMPROVED_LANDER_SPEED, 1 ),
{ TECH_MODULE_ANTIMISSILE, TECH_TYPE_MODULE, ANTIMISSILE_DEFENSE, 4000 }, TECH_DATA( TECH_MODULE_ANTIMISSILE, TECH_TYPE_MODULE, ANTIMISSILE_DEFENSE, 4000 ),
{ TECH_LANDER_SHIELD_BIO, TECH_TYPE_LANDER_SHIELD, BIOLOGICAL_DISASTER, -1 }, TECH_DATA( TECH_LANDER_SHIELD_BIO, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_BIO, -1 ),
{ TECH_LANDER_CARGO, TECH_TYPE_STATE, IMPROVED_LANDER_CARGO, 1 }, TECH_DATA( TECH_LANDER_CARGO, TECH_TYPE_STATE, IMPROVED_LANDER_CARGO, 1 ),
{ TECH_MODULE_BIGFUELTANK, TECH_TYPE_MODULE, HIGHEFF_FUELSYS, 1000 }, TECH_DATA( TECH_MODULE_BIGFUELTANK, TECH_TYPE_MODULE, HIGHEFF_FUELSYS, 1000 ),
{ TECH_LANDER_RAPIDFIRE, TECH_TYPE_STATE, IMPROVED_LANDER_SHOT, 1 }, TECH_DATA( TECH_LANDER_RAPIDFIRE, TECH_TYPE_STATE, IMPROVED_LANDER_SHOT, 1 ),
{ TECH_LANDER_SHIELD_QUAKE, TECH_TYPE_LANDER_SHIELD, EARTHQUAKE_DISASTER, -1 }, TECH_DATA( TECH_LANDER_SHIELD_QUAKE, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_QUAKE, -1 ),
{ TECH_MODULE_TRACKING, TECH_TYPE_MODULE, TRACKING_SYSTEM, 5000 }, TECH_DATA( TECH_MODULE_TRACKING, TECH_TYPE_MODULE, TRACKING_SYSTEM, 5000 ),
{ TECH_LANDER_SHIELD_LIGHTNING, TECH_TYPE_LANDER_SHIELD, LIGHTNING_DISASTER, -1 }, TECH_DATA( TECH_LANDER_SHIELD_LIGHTNING, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_LIGHTNING, -1 ),
{ TECH_LANDER_SHIELD_HEAT, TECH_TYPE_LANDER_SHIELD, LAVASPOT_DISASTER, -1 }, TECH_DATA( TECH_LANDER_SHIELD_HEAT, TECH_TYPE_LANDER_SHIELD, LANDER_SHIELD_HEAT, -1 ),
{ TECH_MODULE_CANNON, TECH_TYPE_MODULE, CANNON_WEAPON, 6000 }, TECH_DATA( TECH_MODULE_CANNON, TECH_TYPE_MODULE, CANNON_WEAPON, 6000 ),
{ TECH_MODULE_FURNACE, TECH_TYPE_MODULE, SHIVA_FURNACE, 4000 }, TECH_DATA( TECH_MODULE_FURNACE, TECH_TYPE_MODULE, SHIVA_FURNACE, 4000 ),
}; };
const size_t NUM_TECHNOLOGIES = ARRAY_SIZE (tech_data_table); 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 // We have to explicitly switch on the state ID because the xxx_GAME_STATE
// macros use preprocessor stringizing. // macros use preprocessor stringizing.
static bool static bool
HasStateTech (int stateId) HasStateTech (const char *const stateId)
{ {
switch (stateId) return getGameState_json(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 static void
GrantStateTech (int stateId, BYTE value) GrantStateTech (const char *const stateId)
{ {
switch (stateId) setGameState_json(stateId, true);
{
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 static bool
@@ -320,17 +304,8 @@ HasTech (TechId_t techId)
if (!techData) if (!techData)
return false; 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 HasStateTech(techData->subtype);
} }
return false;
}
static void static void
GrantTech (TechId_t techId) GrantTech (TechId_t techId)
@@ -339,21 +314,8 @@ GrantTech (TechId_t techId)
if (!techData) if (!techData)
return; return;
switch (techData->type)
{ GrantStateTech (techData->subtype);
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;
}
} }
@@ -507,7 +469,7 @@ ShipWorth (void)
} }
crew_pods = -(SBYTE)( crew_pods = -(SBYTE)(
(GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1)
/ CREW_POD_CAPACITY / CREW_POD_CAPACITY
); );
for (i = 0; i < NUM_MODULE_SLOTS; ++i) for (i = 0; i < NUM_MODULE_SLOTS; ++i)
@@ -582,7 +544,7 @@ StripShip (COUNT fuel_required)
SET_GAME_STATE (MELNORME_RESCUE_REFUSED, 0); SET_GAME_STATE (MELNORME_RESCUE_REFUSED, 0);
crew_pods = -(SBYTE)( crew_pods = -(SBYTE)(
(GLOBAL_SIS (CrewEnlisted) + CREW_POD_CAPACITY - 1) (GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY - 1)
/ CREW_POD_CAPACITY / CREW_POD_CAPACITY
); );
if (fuel_required == 0) if (fuel_required == 0)
@@ -597,8 +559,8 @@ StripShip (COUNT fuel_required)
GLOBAL_SIS (DriveSlots[i]) = EMPTY_SLOT + 0; GLOBAL_SIS (DriveSlots[i]) = EMPTY_SLOT + 0;
for (i = 0; i < NUM_JET_SLOTS; ++i) for (i = 0; i < NUM_JET_SLOTS; ++i)
GLOBAL_SIS (JetSlots[i]) = EMPTY_SLOT + 1; GLOBAL_SIS (JetSlots[i]) = EMPTY_SLOT + 1;
if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE)
GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE);
GLOBAL_SIS (TotalBioMass) = 0; GLOBAL_SIS (TotalBioMass) = 0;
GLOBAL_SIS (TotalElementMass) = 0; GLOBAL_SIS (TotalElementMass) = 0;
for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i) for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i)
@@ -1007,7 +969,7 @@ DoBuy (RESPONSE_REF R)
else if (PLAYER_SAID (R, buy_25_fuel)) else if (PLAYER_SAID (R, buy_25_fuel))
needed_credit = 25; needed_credit = 25;
else if (PLAYER_SAID (R, fill_me_up)) 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 - 1)
/ FUEL_TANK_SCALE; / FUEL_TANK_SCALE;
@@ -1021,7 +983,7 @@ DoBuy (RESPONSE_REF R)
} }
else else
{ {
if (GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE if (GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE
+ needed_credit > capacity / FUEL_TANK_SCALE) + needed_credit > capacity / FUEL_TANK_SCALE)
{ {
NPCPhrase (NO_ROOM_FOR_FUEL); NPCPhrase (NO_ROOM_FOR_FUEL);
@@ -1047,7 +1009,7 @@ DoBuy (RESPONSE_REF R)
if (needed_credit) if (needed_credit)
{ {
DeltaCredit (-needed_credit); DeltaCredit (-needed_credit);
if (GLOBAL_SIS (FuelOnBoard) >= capacity) if (GET_GAME_STATE (SIS.FuelOnBoard) >= capacity)
goto BuyBuyBuy; goto BuyBuyBuy;
} }
TryFuelAgain: TryFuelAgain:
@@ -1158,7 +1120,7 @@ TryFuelAgain:
NPCPhrase (WHAT_TO_BUY); NPCPhrase (WHAT_TO_BUY);
BuyBuyBuy: BuyBuyBuy:
if (GLOBAL_SIS (FuelOnBoard) < capacity) if (GET_GAME_STATE (SIS.FuelOnBoard) < capacity)
Response (buy_fuel, DoBuy); Response (buy_fuel, DoBuy);
if (GetNextTechForSale ()) if (GetNextTechForSale ())
Response (buy_technology, DoBuy); Response (buy_technology, DoBuy);
@@ -1321,7 +1283,7 @@ NatureOfConversation (RESPONSE_REF R)
rainbow_mask >>= 1; rainbow_mask >>= 1;
} }
if (GLOBAL_SIS (FuelOnBoard) > 0 if (GET_GAME_STATE (SIS.FuelOnBoard) > 0
|| GLOBAL_SIS (TotalBioMass) || GLOBAL_SIS (TotalBioMass)
|| Credit || Credit
|| num_new_rainbows) || num_new_rainbows)
+2 -2
View File
@@ -542,9 +542,9 @@ OrzNeutral (RESPONSE_REF R)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[1] = we_are_vindicator0; pStr[1] = we_are_vindicator0;
+2 -2
View File
@@ -623,9 +623,9 @@ PkunkHome (RESPONSE_REF R)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (we_are_vindicator0, OfferAlliance, shared_phrase_buf); DoResponsePhrase (we_are_vindicator0, OfferAlliance, shared_phrase_buf);
+2 -2
View File
@@ -351,11 +351,11 @@ RealizeMistake (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
i_am_captain0, i_am_captain0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
i_am_captain1, i_am_captain1,
buf, buf,
i_am_captain2, i_am_captain2,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
i_am_captain3, i_am_captain3,
(UNICODE*)NULL); (UNICODE*)NULL);
} }
+2 -2
View File
@@ -757,9 +757,9 @@ HomeWorld (RESPONSE_REF R)
case 0: case 0:
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_us0, we_are_us0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_us1, we_are_us1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_us2, we_are_us2,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[0] = we_are_us0; pStr[0] = we_are_us0;
+2 -2
View File
@@ -883,9 +883,9 @@ SpathiPassword (RESPONSE_REF R)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (we_are_vindicator0, ExitConversation, shared_phrase_buf); DoResponsePhrase (we_are_vindicator0, ExitConversation, shared_phrase_buf);
+13 -13
View File
@@ -664,8 +664,8 @@ AnalyzeCondition (void)
num_guns += 2; num_guns += 2;
HasMinimum = (num_thrusters >= 7 && num_jets >= 5 HasMinimum = (num_thrusters >= 7 && num_jets >= 5
&& GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY
&& GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY && GET_GAME_STATE (SIS.FuelOnBoard) >= FUEL_TANK_CAPACITY
&& num_bays >= 1 && GLOBAL_SIS (NumLanders) && num_bays >= 1 && GLOBAL_SIS (NumLanders)
&& num_batts >= 1 && num_guns >= 2); && num_batts >= 1 && num_guns >= 2);
NPCPhrase (LETS_SEE); NPCPhrase (LETS_SEE);
@@ -678,9 +678,9 @@ AnalyzeCondition (void)
NPCPhrase (NEED_TURN_1); NPCPhrase (NEED_TURN_1);
if (num_guns < 2) if (num_guns < 2)
NPCPhrase (NEED_GUNS_1); NPCPhrase (NEED_GUNS_1);
if (GLOBAL_SIS (CrewEnlisted) < CREW_POD_CAPACITY) if (GET_GAME_STATE (SIS.CrewEnlisted) < CREW_POD_CAPACITY)
NPCPhrase (NEED_CREW_1); NPCPhrase (NEED_CREW_1);
if (GLOBAL_SIS (FuelOnBoard) < FUEL_TANK_CAPACITY) if (GET_GAME_STATE (SIS.FuelOnBoard) < FUEL_TANK_CAPACITY)
NPCPhrase (NEED_FUEL_1); NPCPhrase (NEED_FUEL_1);
if (num_bays < 1) if (num_bays < 1)
NPCPhrase (NEED_STORAGE_1); NPCPhrase (NEED_STORAGE_1);
@@ -689,7 +689,7 @@ AnalyzeCondition (void)
if (num_batts < 1) if (num_batts < 1)
NPCPhrase (NEED_DYNAMOS_1); NPCPhrase (NEED_DYNAMOS_1);
if (GLOBAL_SIS (ResUnits) >= 3000) if (GET_GAME_STATE (SIS.ResUnits) >= 3000)
NPCPhrase (IMPROVE_FLAGSHIP_WITH_RU); NPCPhrase (IMPROVE_FLAGSHIP_WITH_RU);
else else
NPCPhrase (GO_GET_MINERALS); NPCPhrase (GO_GET_MINERALS);
@@ -709,9 +709,9 @@ AnalyzeCondition (void)
HasMaximum = (num_thrusters == NUM_DRIVE_SLOTS HasMaximum = (num_thrusters == NUM_DRIVE_SLOTS
&& num_jets == NUM_JET_SLOTS && num_jets == NUM_JET_SLOTS
&& GLOBAL_SIS (CrewEnlisted) >= CREW_POD_CAPACITY * 3 && GET_GAME_STATE (SIS.CrewEnlisted) >= CREW_POD_CAPACITY * 3
&& GLOBAL_SIS (FuelOnBoard) >= FUEL_TANK_CAPACITY * 3 && GET_GAME_STATE (SIS.FuelOnBoard) >= FUEL_TANK_CAPACITY * 3
&& GLOBAL_SIS (NumLanders) >= 3 && GET_GAME_STATE (SIS.NumLanders) >= 3
&& num_batts >= 4 && num_guns >= 7 && num_defense >= 2); && num_batts >= 4 && num_guns >= 7 && num_defense >= 2);
if (!HasMaximum && GET_GAME_STATE (CHMMR_BOMB_STATE) < 2) if (!HasMaximum && GET_GAME_STATE (CHMMR_BOMB_STATE) < 2)
NPCPhrase (GOT_OK_FLAGSHIP); NPCPhrase (GOT_OK_FLAGSHIP);
@@ -739,7 +739,7 @@ AnalyzeCondition (void)
NPCPhrase (MADE_SOME_ALLIES); NPCPhrase (MADE_SOME_ALLIES);
if (FleetStrength < 6000) if (FleetStrength < 6000)
{ {
if (GLOBAL_SIS (ResUnits) >= 3000) if (GET_GAME_STATE (SIS.ResUnits) >= 3000)
NPCPhrase (BUY_COMBAT_SHIPS); NPCPhrase (BUY_COMBAT_SHIPS);
else else
NPCPhrase (GET_SHIPS_BY_MINING_OR_ALLIANCE); NPCPhrase (GET_SHIPS_BY_MINING_OR_ALLIANCE);
@@ -756,9 +756,9 @@ AnalyzeCondition (void)
NPCPhrase (NEED_TURN_2); NPCPhrase (NEED_TURN_2);
if (num_guns < 7) if (num_guns < 7)
NPCPhrase (NEED_GUNS_2); 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); 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); NPCPhrase (NEED_FUEL_2);
if (GLOBAL_SIS (NumLanders) < 3) if (GLOBAL_SIS (NumLanders) < 3)
NPCPhrase (NEED_LANDERS_1); NPCPhrase (NEED_LANDERS_1);
@@ -953,7 +953,7 @@ TellStarBase (RESPONSE_REF R)
construct_response ( construct_response (
buf0, buf0,
tell_me_about_modules0, tell_me_about_modules0,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
tell_me_about_modules1, tell_me_about_modules1,
(UNICODE*)NULL); (UNICODE*)NULL);
pstack[0] = tell_me_about_modules0; pstack[0] = tell_me_about_modules0;
@@ -968,7 +968,7 @@ TellStarBase (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
tell_me_about_fuel0, tell_me_about_fuel0,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
tell_me_about_fuel1, tell_me_about_fuel1,
(UNICODE*)NULL); (UNICODE*)NULL);
pstack[1] = tell_me_about_fuel0; pstack[1] = tell_me_about_fuel0;
+2 -2
View File
@@ -424,7 +424,7 @@ NeutralSupox (RESPONSE_REF R)
case 0: case 0:
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
i_am0, i_am0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
i_am1, i_am1,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[0] = i_am0; pStr[0] = i_am0;
@@ -433,7 +433,7 @@ NeutralSupox (RESPONSE_REF R)
case 1: case 1:
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
my_ship0, my_ship0,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
my_ship1, my_ship1,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[0] = my_ship0; pStr[0] = my_ship0;
+2 -2
View File
@@ -793,9 +793,9 @@ Intro (void)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
Response (we_are_vice_squad, InitialSyreen); Response (we_are_vice_squad, InitialSyreen);
+1 -1
View File
@@ -520,7 +520,7 @@ CompelPlayer (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator1, we_are_vindicator1,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[2] = we_are_vindicator0; pStr[2] = we_are_vindicator0;
+1 -1
View File
@@ -489,7 +489,7 @@ ThraddCulture (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
the_slave_empire0, the_slave_empire0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
the_slave_empire1, the_slave_empire1,
(UNICODE*)NULL); (UNICODE*)NULL);
+2 -2
View File
@@ -368,9 +368,9 @@ Zombies (RESPONSE_REF R)
{ {
construct_response (shared_phrase_buf, construct_response (shared_phrase_buf,
we_vindicator0, we_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_vindicator1, we_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_vindicator2, we_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
pStr[1] = we_vindicator0; pStr[1] = we_vindicator0;
+1 -1
View File
@@ -558,7 +558,7 @@ NeutralUtwig (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
we_are_vindicator0, we_are_vindicator0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
we_are_vindicator1, we_are_vindicator1,
buf, buf,
we_are_vindicator2, we_are_vindicator2,
+4 -4
View File
@@ -379,11 +379,11 @@ YehatHome (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
i_demand_you_ally_homeworld0, i_demand_you_ally_homeworld0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
i_demand_you_ally_homeworld1, i_demand_you_ally_homeworld1,
buf, buf,
i_demand_you_ally_homeworld2, i_demand_you_ally_homeworld2,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
i_demand_you_ally_homeworld3, i_demand_you_ally_homeworld3,
(UNICODE*)NULL); (UNICODE*)NULL);
DoResponsePhrase (i_demand_you_ally_homeworld0, DoResponsePhrase (i_demand_you_ally_homeworld0,
@@ -505,9 +505,9 @@ YehatSpace (RESPONSE_REF R)
construct_response ( construct_response (
shared_phrase_buf, shared_phrase_buf,
i_demand_you_ally_space0, i_demand_you_ally_space0,
GLOBAL_SIS (CommanderName), GET_GAME_STATE_STRING (SIS.CommanderName),
i_demand_you_ally_space1, i_demand_you_ally_space1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
i_demand_you_ally_space2, i_demand_you_ally_space2,
buf, buf,
i_demand_you_ally_space3, i_demand_you_ally_space3,
+1 -1
View File
@@ -427,7 +427,7 @@ AquaintZoqFot (RESPONSE_REF R)
we_are_vindicator0, we_are_vindicator0,
buf, buf,
we_are_vindicator1, we_are_vindicator1,
GLOBAL_SIS (ShipName), GET_GAME_STATE_STRING (SIS.ShipName),
we_are_vindicator2, we_are_vindicator2,
(UNICODE*)NULL); (UNICODE*)NULL);
} }
+10 -7
View File
@@ -35,18 +35,21 @@ static int NPCNumberPhrase (int number, const char *fmt, UNICODE **ptrack);
void void
NPCPhrase_cb (int index, CallbackFunction cb) NPCPhrase_cb (int index, CallbackFunction cb)
{ {
UNICODE *pStr, buf[400]; UNICODE *pStr;
UNICODE buf[400];
void *pClip, *pTimeStamp; void *pClip, *pTimeStamp;
switch (index) switch (index)
{ {
case GLOBAL_PLAYER_NAME: case GLOBAL_PLAYER_NAME:
pStr = GLOBAL_SIS (CommanderName); strcpy (buf, GET_GAME_STATE_STRING (SIS.CommanderName));
pStr = buf;
pClip = 0; pClip = 0;
pTimeStamp = 0; pTimeStamp = 0;
break; break;
case GLOBAL_SHIP_NAME: case GLOBAL_SHIP_NAME:
pStr = GLOBAL_SIS (ShipName); strcpy (buf, GET_GAME_STATE_STRING (SIS.ShipName));
pStr = buf;
pClip = 0; pClip = 0;
pTimeStamp = 0; pTimeStamp = 0;
break; break;
@@ -66,7 +69,7 @@ NPCPhrase_cb (int index, CallbackFunction cb)
S = SetAbsStringTableIndex (CommData.ConversationPhrases, (index - 1) + i); S = SetAbsStringTableIndex (CommData.ConversationPhrases, (index - 1) + i);
strcpy (buf, (UNICODE *)GetStringAddress (S)); strcpy (buf, (UNICODE *)GetStringAddress (S));
if (i == 3) if (i == 3)
strcat (buf, GLOBAL_SIS (CommanderName)); strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName));
pStr = buf; pStr = buf;
pClip = 0; pClip = 0;
@@ -252,7 +255,7 @@ GetAllianceName (UNICODE *buf, RESPONSE_REF name_1)
strcpy (buf, (UNICODE *)GetStringAddress (S)); strcpy (buf, (UNICODE *)GetStringAddress (S));
if (i == 3) if (i == 3)
{ {
strcat (buf, GLOBAL_SIS (CommanderName)); strcat (buf, GET_GAME_STATE_STRING (SIS.CommanderName));
strcat (buf, (UNICODE *)GetStringAddress (SetRelStringTableIndex (S, 1))); strcat (buf, (UNICODE *)GetStringAddress (SetRelStringTableIndex (S, 1)));
} }
} }
@@ -329,7 +332,7 @@ setSegue (Segue segue)
break; break;
case Segue_defeat: case Segue_defeat:
SET_GAME_STATE (BATTLE_SEGUE, 0); SET_GAME_STATE (BATTLE_SEGUE, 0);
GLOBAL_SIS(CrewEnlisted) = (COUNT)~0; SET_GAME_STATE(SIS.CrewEnlisted, (COUNT)~0);
GLOBAL(CurrentActivity) |= CHECK_RESTART; GLOBAL(CurrentActivity) |= CHECK_RESTART;
break; break;
} }
@@ -339,7 +342,7 @@ Segue
getSegue (void) getSegue (void)
{ {
if (GET_GAME_STATE(BATTLE_SEGUE) == 0) { 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)) { (GLOBAL(CurrentActivity) & CHECK_RESTART)) {
return Segue_defeat; return Segue_defeat;
} else { } else {
+4 -4
View File
@@ -322,7 +322,7 @@ InitEncounter (void)
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
font_DrawText (&t); font_DrawText (&t);
t.baseline.y += 12; t.baseline.y += 12;
t.pStr = GLOBAL_SIS (PlanetName); t.pStr = GET_GAME_STATE_STRING (SIS.PlanetName);
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
font_DrawText (&t); font_DrawText (&t);
} }
@@ -482,7 +482,7 @@ UninitEncounter (void)
free_gravity_well (); free_gravity_well ();
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) 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)) == IN_LAST_BATTLE
|| LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE) || LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE)
goto ExitUninitEncounter; goto ExitUninitEncounter;
@@ -572,7 +572,7 @@ UninitEncounter (void)
else if (GLOBAL (ip_planet) == 0) else if (GLOBAL (ip_planet) == 0)
DrawHyperCoords (CurStarDescPtr->star_pt); DrawHyperCoords (CurStarDescPtr->star_pt);
else else
DrawSISTitle(GLOBAL_SIS (PlanetName)); DrawSISTitle(GET_GAME_STATE_STRING (SIS.PlanetName));
SetContext (SpaceContext); SetContext (SpaceContext);
if (VictoryState) if (VictoryState)
@@ -822,7 +822,7 @@ EncounterBattle (void)
GameSounds = 0; GameSounds = 0;
if (GLOBAL (CurrentActivity) & CHECK_ABORT) if (GLOBAL (CurrentActivity) & CHECK_ABORT)
GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0);
if (GLOBAL (glob_flags) & CYBORG_ENABLED) if (GLOBAL (glob_flags) & CYBORG_ENABLED)
{ {
+2 -2
View File
@@ -120,7 +120,7 @@ EventHandler (BYTE selector)
break; break;
case SHOFIXTI_RETURN_EVENT: case SHOFIXTI_RETURN_EVENT:
SetRaceAllied (SHOFIXTI_SHIP, TRUE); SetRaceAllied (SHOFIXTI_SHIP, TRUE);
GLOBAL (CrewCost) -= 2; SET_GAME_STATE (CrewCost, GET_GAME_STATE (CrewCost) - 2);
/* crew is not an issue anymore */ /* crew is not an issue anymore */
SET_GAME_STATE (CREW_PURCHASED0, 0); SET_GAME_STATE (CREW_PURCHASED0, 0);
SET_GAME_STATE (CREW_PURCHASED1, 0); SET_GAME_STATE (CREW_PURCHASED1, 0);
@@ -369,7 +369,7 @@ black_urquan_genocide (void)
{ {
// All spheres of influence are gone - game over. // All spheres of influence are gone - game over.
GLOBAL (CurrentActivity) &= ~IN_BATTLE; GLOBAL (CurrentActivity) &= ~IN_BATTLE;
GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0);
SET_GAME_STATE (KOHR_AH_KILLED_ALL, 1); SET_GAME_STATE (KOHR_AH_KILLED_ALL, 1);
} }
+18 -7
View File
@@ -315,7 +315,8 @@ NameCaptainOrShip (bool nameCaptain)
{ {
UNICODE buf[MAX_NAME_SIZE] = ""; UNICODE buf[MAX_NAME_SIZE] = "";
TEXTENTRY_STATE tes; TEXTENTRY_STATE tes;
UNICODE *Setting; const UNICODE *Setting;
const UNICODE *Old;
SetContext (StatusContext); SetContext (StatusContext);
SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect); SetFlashRect (nameCaptain ? &captainNameRect : &shipNameRect);
@@ -326,14 +327,15 @@ NameCaptainOrShip (bool nameCaptain)
if (nameCaptain) if (nameCaptain)
{ {
Setting = GLOBAL_SIS (CommanderName); Setting = "SIS.CommanderName";
tes.MaxSize = sizeof (GLOBAL_SIS (CommanderName)); tes.MaxSize = SIS_NAME_SIZE;
} }
else else
{ {
Setting = GLOBAL_SIS (ShipName); Setting = "SIS.ShipName";
tes.MaxSize = sizeof (GLOBAL_SIS (ShipName)); tes.MaxSize = SIS_NAME_SIZE;
} }
Old= getGameState_string_json( Setting );
// text entry setup // text entry setup
tes.Initialized = FALSE; tes.Initialized = FALSE;
@@ -344,9 +346,12 @@ NameCaptainOrShip (bool nameCaptain)
tes.FrameCallback = 0; tes.FrameCallback = 0;
if (DoTextEntry (&tes)) if (DoTextEntry (&tes))
utf8StringCopy (Setting, tes.MaxSize, buf); {
buf[ tes.MaxSize ]= '\0';
setGameState_string_json( Setting, buf );
}
else else
utf8StringCopy (buf, sizeof (buf), Setting); utf8StringCopy (buf, sizeof (buf), Old);
SetFlashRect (SFR_MENU_3DO); SetFlashRect (SFR_MENU_3DO);
@@ -731,6 +736,11 @@ DrawSavegameCargo (SIS_STATE *sisState)
static void static void
DrawSavegameSummary (PICK_GAME_STATE *pickState, COUNT gameIndex) 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; SUMMARY_DESC *pSD = pickState->summary + gameIndex;
RECT r; RECT r;
STAMP s; STAMP s;
@@ -934,6 +944,7 @@ DrawSavegameSummary (PICK_GAME_STATE *pickState, COUNT gameIndex)
} }
UnbatchGraphics (); UnbatchGraphics ();
#endif
} }
static void static void
+110
View File
@@ -0,0 +1,110 @@
#define COMPILING_GLOBDATA
#include "uqm/globdata.h"
#undef COMPILING_GLOBDATA
#include <cstdint>
#include <map>
#include <string>
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;
}
}
+17 -20
View File
@@ -317,10 +317,10 @@ InitGameStructures (void)
GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2; GLOBAL_SIS (ModuleSlots[i]) = EMPTY_SLOT + 2;
GLOBAL_SIS (ModuleSlots[15]) = GUN_WEAPON; GLOBAL_SIS (ModuleSlots[15]) = GUN_WEAPON;
GLOBAL_SIS (ModuleSlots[2]) = CREW_POD; 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[8]) = STORAGE_BAY;
GLOBAL_SIS (ModuleSlots[1]) = FUEL_TANK; 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), InitQueue (&GLOBAL (built_ship_q),
MAX_BUILT_SHIPS, sizeof (SHIP_FRAGMENT)); MAX_BUILT_SHIPS, sizeof (SHIP_FRAGMENT));
@@ -332,9 +332,9 @@ InitGameStructures (void)
GLOBAL (CurrentActivity) = IN_INTERPLANETARY | START_INTERPLANETARY; GLOBAL (CurrentActivity) = IN_INTERPLANETARY | START_INTERPLANETARY;
GLOBAL_SIS (ResUnits) = 0; SET_GAME_STATE (SIS.ResUnits, 0);
GLOBAL (CrewCost) = 3; SET_GAME_STATE (CrewCost, 3);
GLOBAL (FuelCost) = 20; SET_GAME_STATE (FuelCost, 20);
GLOBAL (ModuleCost[PLANET_LANDER]) = 500 / MODULE_COST_SCALE; GLOBAL (ModuleCost[PLANET_LANDER]) = 500 / MODULE_COST_SCALE;
GLOBAL (ModuleCost[FUSION_THRUSTER]) = 500 / MODULE_COST_SCALE; GLOBAL (ModuleCost[FUSION_THRUSTER]) = 500 / MODULE_COST_SCALE;
GLOBAL (ModuleCost[TURNING_JETS]) = 500 / MODULE_COST_SCALE; GLOBAL (ModuleCost[TURNING_JETS]) = 500 / MODULE_COST_SCALE;
@@ -346,11 +346,8 @@ InitGameStructures (void)
GLOBAL_SIS (NumLanders) = 1; GLOBAL_SIS (NumLanders) = 1;
utf8StringCopy (GLOBAL_SIS (ShipName), sizeof (GLOBAL_SIS (ShipName)), SET_GAME_STATE_STRING (SIS.ShipName, GAME_STRING (NAMING_STRING_BASE + 2));
GAME_STRING (NAMING_STRING_BASE + 2)); SET_GAME_STATE_STRING (SIS.CommanderName, GAME_STRING (NAMING_STRING_BASE + 3));
utf8StringCopy (GLOBAL_SIS (CommanderName),
sizeof (GLOBAL_SIS (CommanderName)),
GAME_STRING (NAMING_STRING_BASE + 3));
SetRaceAllied (HUMAN_SHIP, TRUE); SetRaceAllied (HUMAN_SHIP, TRUE);
CloneShipFragment (HUMAN_SHIP, &GLOBAL (built_ship_q), 0); CloneShipFragment (HUMAN_SHIP, &GLOBAL (built_ship_q), 0);
@@ -372,7 +369,7 @@ InitGameStructures (void)
const int equipment[]= const int equipment[]=
{ {
FUEL_TANK, HIGHEFF_FUELSYS,
HIGHEFF_FUELSYS, HIGHEFF_FUELSYS,
SHIVA_FURNACE, SHIVA_FURNACE,
@@ -380,10 +377,10 @@ InitGameStructures (void)
DYNAMO_UNIT, DYNAMO_UNIT,
DYNAMO_UNIT, DYNAMO_UNIT,
SHIVA_FURNACE, STORAGE_BAY,
SHIVA_FURNACE, CREW_POD,
SHIVA_FURNACE, CREW_POD,
SHIVA_FURNACE, CREW_POD,
TRACKING_SYSTEM, TRACKING_SYSTEM,
@@ -397,8 +394,8 @@ InitGameStructures (void)
const int ck_[ sizeof( equipment ) / sizeof( int ) == 16 ? 1 : -1 ]; const int ck_[ sizeof( equipment ) / sizeof( int ) == 16 ? 1 : -1 ];
(void) ck_; (void) ck_;
GLOBAL_SIS( CrewEnlisted )= 0; SET_GAME_STATE( SIS.CrewEnlisted, 0 );
GLOBAL_SIS( FuelOnBoard )= 10 * FUEL_TANK_SCALE; SET_GAME_STATE( SIS.FuelOnBoard, 10 * FUEL_TANK_SCALE);
for( int i= 0; i < 16; ++i ) for( int i= 0; i < 16; ++i )
{ {
const int module= equipment[ i ]; const int module= equipment[ i ];
@@ -406,15 +403,15 @@ InitGameStructures (void)
if( false ) {} if( false ) {}
else if( module == CREW_POD ) 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 ) 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 ) else if( module == HIGHEFF_FUELSYS )
{ {
GLOBAL_SIS( FuelOnBoard )+= HEFUEL_TANK_CAPACITY; SET_GAME_STATE( SIS.FuelOnBoard, GET_GAME_STATE( SIS.FuelOnBoard ) + HEFUEL_TANK_CAPACITY );
} }
} }
+93 -8
View File
@@ -27,7 +27,11 @@
#include "velocity.h" #include "velocity.h"
#include "commanim.h" #include "commanim.h"
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
#include <string>
extern "C" { extern "C" {
#endif #endif
@@ -172,10 +176,44 @@ enum
#define YEARS_TO_KOHRAH_VICTORY 4 #define YEARS_TO_KOHRAH_VICTORY 4
#ifdef COMPILING_GLOBDATA
//#error FOUND IT!
#endif
#ifdef USE_OLD_STATE
#define START_GAME_STATE enum { #define START_GAME_STATE enum {
#define ADD_GAME_STATE(SName,NumBits) SName, END_##SName = SName + NumBits - 1, #define ADD_GAME_STATE(SName,NumBits) SName, END_##SName = SName + NumBits - 1,
#define END_GAME_STATE NUM_GAME_STATE_BITS }; #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 START_GAME_STATE
/* Shofixti states */ /* Shofixti states */
ADD_GAME_STATE (SHOFIXTI_VISITS, 3) ADD_GAME_STATE (SHOFIXTI_VISITS, 3)
@@ -253,7 +291,7 @@ START_GAME_STATE
* 9 means completely open. * 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 (MET_MELNORME, 1)
ADD_GAME_STATE (MELNORME_RESCUE_REFUSED, 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_GRPOFFS2, 8)
ADD_GAME_STATE (SAMATRA_GRPOFFS3, 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 END_GAME_STATE
// Values for GAME_STATE.glob_flags: // Values for GAME_STATE.glob_flags:
@@ -922,7 +976,7 @@ typedef struct
BYTE glob_flags; BYTE glob_flags;
// See above for the meaning of the bits. // See above for the meaning of the bits.
BYTE CrewCost, FuelCost; //BYTE CrewCost, FuelCost;
BYTE ModuleCost[NUM_MODULES]; BYTE ModuleCost[NUM_MODULES];
BYTE ElementWorth[NUM_ELEMENT_CATEGORIES]; BYTE ElementWorth[NUM_ELEMENT_CATEGORIES];
@@ -958,7 +1012,9 @@ typedef struct
/* List of SIS escort ships; /* List of SIS escort ships;
* queue element is SHIP_FRAGMENT */ * queue element is SHIP_FRAGMENT */
#ifdef USE_OLD_STATE
BYTE GameState[(NUM_GAME_STATE_BITS + 7) >> 3]; BYTE GameState[(NUM_GAME_STATE_BITS + 7) >> 3];
#endif
} GAME_STATE; } GAME_STATE;
typedef struct typedef struct
@@ -1006,31 +1062,60 @@ 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 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 <map>
#include <string>
#include <cstdint>
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 #ifdef STATE_DEBUG
# define SET_GAME_STATE(SName, val) \ # define xSET_GAME_STATE(SName, val) \
setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName) setGameState (GLOBAL(GameState), (SName), (END_##SName), (val), #SName)
#else #else
# define SET_GAME_STATE(SName, val) \ # define xSET_GAME_STATE(SName, val) \
setGameState (GLOBAL(GameState), (SName), (END_##SName), (val)) setGameState (GLOBAL(GameState), (SName), (END_##SName), (val))
#endif #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 DWORD getGameState32 (BYTE *state, int startBit);
extern void setGameState32 (BYTE *state, int startBit, DWORD val extern void setGameState32 (BYTE *state, int startBit, DWORD val
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
, const char *name , const char *name
#endif #endif
); );
#define GET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName)) #define xGET_GAME_STATE_32(SName) getGameState32 (GLOBAL(GameState), (SName))
#ifdef STATE_DEBUG #ifdef STATE_DEBUG
# define SET_GAME_STATE_32(SName, val) \ # define xSET_GAME_STATE_32(SName, val) \
setGameState32 (GLOBAL(GameState), (SName), (val), #SName) setGameState32 (GLOBAL(GameState), (SName), (val), #SName)
#else #else
# define SET_GAME_STATE_32(SName, val) \ # define xSET_GAME_STATE_32(SName, val) \
setGameState32 (GLOBAL(GameState), (SName), (val)) setGameState32 (GLOBAL(GameState), (SName), (val))
#endif #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 CONTEXT RadarContext;
+3 -3
View File
@@ -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 cur_fuel_ticks;
COUNT hyper_dist; COUNT hyper_dist;
@@ -215,7 +215,7 @@ check_hyperspace_encounter (void)
percent *= GET_GAME_STATE (SLYLANDRO_MULTIPLIER); percent *= GET_GAME_STATE (SLYLANDRO_MULTIPLIER);
} }
else if (Type == MELNORME_SHIP else if (Type == MELNORME_SHIP
&& (GLOBAL_SIS (FuelOnBoard) == 0 && (GET_GAME_STATE (SIS.FuelOnBoard) == 0
|| GET_GAME_STATE (USED_BROADCASTER)) || GET_GAME_STATE (USED_BROADCASTER))
&& GET_GAME_STATE (MELNORME_ANGER) < 3) && GET_GAME_STATE (MELNORME_ANGER) < 3)
{ {
@@ -1626,7 +1626,7 @@ DoHyperspaceMenu (MENU_STATE *pMS)
BOOLEAN handled; BOOLEAN handled;
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0)
return FALSE; return FALSE;
handled = DoMenuChooser (pMS, PM_STARMAP); handled = DoMenuChooser (pMS, PM_STARMAP);
+119
View File
@@ -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 <fstream>
#include <iostream>
#include <sstream>
#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;
}
+2
View File
@@ -199,6 +199,7 @@ static DWORD old_defgrp_offsets[] = { 0, 52, 84, 116, 148, 180, 212, 244,
276, 308, 340, 372, 451, 879, 931 }; 276, 308, 340, 372, 451, 879, 931 };
static DWORD new_defgrp_offsets[] = { static DWORD new_defgrp_offsets[] = {
#if 0
0, 0,
SHOFIXTI_GRPOFFS0, SHOFIXTI_GRPOFFS0,
ZOQFOT_GRPOFFS0, ZOQFOT_GRPOFFS0,
@@ -214,6 +215,7 @@ static DWORD new_defgrp_offsets[] = {
URQUAN_PROBE_GRPOFFS0, URQUAN_PROBE_GRPOFFS0,
COLONY_GRPOFFS0, COLONY_GRPOFFS0,
SAMATRA_GRPOFFS0 SAMATRA_GRPOFFS0
#endif
}; };
static void static void
+4 -4
View File
@@ -513,11 +513,11 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState)
if (beg_index == PM_CREW) if (beg_index == PM_CREW)
snprintf (pm_crew_str, sizeof pm_crew_str, "%s(%d)", snprintf (pm_crew_str, sizeof pm_crew_str, "%s(%d)",
GAME_STRING (MAINMENU_STRING_BASE + PM_CREW), GAME_STRING (MAINMENU_STRING_BASE + PM_CREW),
GLOBAL (CrewCost)); GET_GAME_STATE (CrewCost));
if (beg_index == PM_FUEL) if (beg_index == PM_FUEL)
snprintf (pm_fuel_str, sizeof pm_fuel_str, "%s(%d)", snprintf (pm_fuel_str, sizeof pm_fuel_str, "%s(%d)",
GAME_STRING (MAINMENU_STRING_BASE + PM_FUEL), GAME_STRING (MAINMENU_STRING_BASE + PM_FUEL),
GLOBAL (FuelCost)); GET_GAME_STATE (FuelCost));
if (beg_index == PM_SOUND_ON) if (beg_index == PM_SOUND_ON)
{ {
end_index = beg_index + 5; end_index = beg_index + 5;
@@ -578,7 +578,7 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState)
t.align = ALIGN_RIGHT; t.align = ALIGN_RIGHT;
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
t.pStr = buf; t.pStr = buf;
snprintf (buf, sizeof buf, "%u", GLOBAL (CrewCost)); snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (CrewCost));
SetContextFont (TinyFont); SetContextFont (TinyFont);
SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR); SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR);
font_DrawText (&t); font_DrawText (&t);
@@ -589,7 +589,7 @@ DrawMenuStateStrings (BYTE beg_index, SWORD NewState)
t.align = ALIGN_RIGHT; t.align = ALIGN_RIGHT;
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
t.pStr = buf; t.pStr = buf;
snprintf (buf, sizeof buf, "%u", GLOBAL (FuelCost)); snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (FuelCost));
SetContextFont (TinyFont); SetContextFont (TinyFont);
SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR); SetContextForeGroundColor (THREEDOMENU_TEXT_COLOR);
font_DrawText (&t); font_DrawText (&t);
+21 -25
View File
@@ -99,19 +99,19 @@ DrawModuleStrings (MENU_STATE *pMS, BYTE NewModule)
static void static void
RedistributeFuel (void) RedistributeFuel (void)
{ {
const DWORD FuelVolume = GLOBAL_SIS (FuelOnBoard); const DWORD FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard);
const CONTEXT OldContext = SetContext (SpaceContext); const CONTEXT OldContext = SetContext (SpaceContext);
RECT r; RECT r;
r.extent.height = 1; r.extent.height = 1;
// Loop through all the rows to draw // Loop through all the rows to draw
BatchGraphics (); BatchGraphics ();
for (GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; for (SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE);
GLOBAL_SIS (FuelOnBoard) < GetFTankCapacity (&r.corner); GET_GAME_STATE (SIS.FuelOnBoard) < GetFTankCapacity (&r.corner);
GLOBAL_SIS (FuelOnBoard) += FUEL_VOLUME_PER_ROW) 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 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; r.extent.width = 3;
DrawPoint (&r.corner); DrawPoint (&r.corner);
@@ -132,7 +132,7 @@ RedistributeFuel (void)
UnbatchGraphics (); UnbatchGraphics ();
SetContext (OldContext); SetContext (OldContext);
GLOBAL_SIS (FuelOnBoard) = FuelVolume; SET_GAME_STATE (SIS.FuelOnBoard, FuelVolume);
} }
#define LANDER_X 24 #define LANDER_X 24
@@ -247,7 +247,7 @@ DoInstallModule (MENU_STATE *pMS)
{ {
if (new_slot_piece < EMPTY_SLOT) if (new_slot_piece < EMPTY_SLOT)
{ {
if (GLOBAL_SIS (ResUnits) < if (GET_GAME_STATE (SIS.ResUnits) <
(DWORD)(GLOBAL (ModuleCost[new_slot_piece]) (DWORD)(GLOBAL (ModuleCost[new_slot_piece])
* MODULE_COST_SCALE)) * MODULE_COST_SCALE))
{ // not enough RUs to build { // not enough RUs to build
@@ -259,7 +259,7 @@ DoInstallModule (MENU_STATE *pMS)
{ {
if (old_slot_piece == CREW_POD) 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)) * (CountSISPieces (CREW_POD) - 1))
{ // crew pod still needed for crew recruited { // crew pod still needed for crew recruited
PlayMenuSound (MENU_SOUND_FAILURE); PlayMenuSound (MENU_SOUND_FAILURE);
@@ -277,7 +277,7 @@ DoInstallModule (MENU_STATE *pMS)
* HEFUEL_TANK_CAPACITY; * HEFUEL_TANK_CAPACITY;
volume -= (old_slot_piece == FUEL_TANK volume -= (old_slot_piece == FUEL_TANK
? FUEL_TANK_CAPACITY : HEFUEL_TANK_CAPACITY); ? 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 { // fuel tank still needed for the fuel on board
PlayMenuSound (MENU_SOUND_FAILURE); PlayMenuSound (MENU_SOUND_FAILURE);
return (TRUE); return (TRUE);
@@ -557,9 +557,9 @@ ChangeFuelQuantity (void)
// Clamp incr to what we can afford/hold/have. // Clamp incr to what we can afford/hold/have.
{ {
const int maxFit = GetFuelTankCapacity () - GLOBAL_SIS (FuelOnBoard); const int maxFit = GetFuelTankCapacity () - GET_GAME_STATE (SIS.FuelOnBoard);
const int maxAfford = GLOBAL_SIS (ResUnits) / GLOBAL (FuelCost); const int maxAfford = GET_GAME_STATE (SIS.ResUnits) / GET_GAME_STATE (FuelCost);
const int minFit = - (int) GLOBAL_SIS (FuelOnBoard); const int minFit = - (int) GET_GAME_STATE (SIS.FuelOnBoard);
if (incr > maxFit) if (incr > maxFit)
incr = maxFit; // All we can hold. incr = maxFit; // All we can hold.
@@ -578,7 +578,7 @@ ChangeFuelQuantity (void)
} }
else else
{ {
const int cost = (incr / FUEL_TANK_SCALE) * GLOBAL (FuelCost); const int cost = (incr / FUEL_TANK_SCALE) * GET_GAME_STATE (FuelCost);
PreUpdateFlashRect (); PreUpdateFlashRect ();
DeltaSISGauges (0, incr, -cost); DeltaSISGauges (0, incr, -cost);
PostUpdateFlashRect (); PostUpdateFlashRect ();
@@ -670,22 +670,18 @@ DoOutfit (MENU_STATE *pMS)
DisplayLanders (pMS); DisplayLanders (pMS);
if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3) if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 3)
{ {
BYTE ShieldFlags;
ShieldFlags = GET_GAME_STATE (LANDER_SHIELDS);
s.frame = SetAbsFrameIndex (pMS->ModuleFrame, s.frame = SetAbsFrameIndex (pMS->ModuleFrame,
GetFrameCount (pMS->ModuleFrame) - 5); GetFrameCount (pMS->ModuleFrame) - 5);
if (ShieldFlags & (1 << EARTHQUAKE_DISASTER)) if (GET_GAME_STATE (LANDER_SHIELD_QUAKE))
DrawStamp (&s); DrawStamp (&s);
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
if (ShieldFlags & (1 << BIOLOGICAL_DISASTER)) if (GET_GAME_STATE (LANDER_SHIELD_BIO))
DrawStamp (&s); DrawStamp (&s);
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
if (ShieldFlags & (1 << LIGHTNING_DISASTER)) if (GET_GAME_STATE (LANDDER_SHIELD_LIGHTNING))
DrawStamp (&s); DrawStamp (&s);
s.frame = IncFrameIndex (s.frame); s.frame = IncFrameIndex (s.frame);
if (ShieldFlags & (1 << LAVASPOT_DISASTER)) if (GET_GAME_STATE (LANDER_SHIELD_HEAT))
DrawStamp (&s); DrawStamp (&s);
} }
@@ -700,10 +696,10 @@ DoOutfit (MENU_STATE *pMS)
SetFlashRect (SFR_MENU_3DO); SetFlashRect (SFR_MENU_3DO);
GLOBAL_SIS (FuelOnBoard) = SET_GAME_STATE (SIS.FuelOnBoard,
(GLOBAL_SIS (FuelOnBoard) (GET_GAME_STATE (SIS.FuelOnBoard)
+ (FUEL_TANK_SCALE >> 1)) / FUEL_TANK_SCALE; + (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);
} }
SetContext (StatusContext); SetContext (StatusContext);
+9 -7
View File
@@ -190,9 +190,9 @@ ChangeSelection:
StarShipPtr = LockStarShip (&race_q[0], hBattleShip); StarShipPtr = LockStarShip (&race_q[0], hBattleShip);
if (StarShipPtr->captains_name_index == 0) if (StarShipPtr->captains_name_index == 0)
{ {
t.pStr = GLOBAL_SIS (CommanderName); t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName);
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
crew_level = GLOBAL_SIS (CrewEnlisted); crew_level = GET_GAME_STATE (SIS.CrewEnlisted);
max_crew = GetCrewPodCapacity (); max_crew = GetCrewPodCapacity ();
} }
else else
@@ -344,14 +344,14 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
#define RUN_AWAY_FUEL_COST (5 * FUEL_TANK_SCALE) #define RUN_AWAY_FUEL_COST (5 * FUEL_TANK_SCALE)
if (LastStarShipPtr->crew_level == 0) if (LastStarShipPtr->crew_level == 0)
{ // Died in the line of duty { // Died in the line of duty
GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0);
} }
else else
{ // Player ran away { // Player ran away
if (GLOBAL_SIS (FuelOnBoard) > RUN_AWAY_FUEL_COST) if (GET_GAME_STATE (SIS.FuelOnBoard) > RUN_AWAY_FUEL_COST)
GLOBAL_SIS (FuelOnBoard) -= RUN_AWAY_FUEL_COST; SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) - RUN_AWAY_FUEL_COST);
else else
GLOBAL_SIS (FuelOnBoard) = 0; SET_GAME_STATE (SIS.FuelOnBoard, 0);
} }
} }
return 0; return 0;
@@ -397,6 +397,7 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect)
TEXT t; TEXT t;
CONTEXT OldContext; CONTEXT OldContext;
FRAME PickFrame; FRAME PickFrame;
UNICODE buf[ SIS_NAME_SIZE ];
OldContext = SetContext (SpaceContext); 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.x = pick_r.corner.x + (pick_r.extent.width >> 1);
t.baseline.y = pick_r.corner.y + pick_r.extent.height - 5; t.baseline.y = pick_r.corner.y + pick_r.extent.height - 5;
t.align = ALIGN_CENTER; 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; t.CharCount = (COUNT)~0;
SetContextForeGroundColor ( SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x12, 0x12, 0x12), 0x17)); BUILD_COLOR (MAKE_RGB15 (0x12, 0x12, 0x12), 0x17));
+5 -5
View File
@@ -356,7 +356,7 @@ InvokeDevice (BYTE which_device)
case UTWIG_BOMB_DEVICE: case UTWIG_BOMB_DEVICE:
SET_GAME_STATE (UTWIG_BOMB, 0); SET_GAME_STATE (UTWIG_BOMB, 0);
GLOBAL (CurrentActivity) &= ~IN_BATTLE; GLOBAL (CurrentActivity) &= ~IN_BATTLE;
GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; SET_GAME_STATE (SIS.CrewEnlisted, (COUNT)~0);
return DEVICE_SUCCESS; return DEVICE_SUCCESS;
case ULTRON_0_DEVICE: case ULTRON_0_DEVICE:
break; break;
@@ -444,12 +444,12 @@ InvokeDevice (BYTE which_device)
case PORTAL_SPAWNER_DEVICE: case PORTAL_SPAWNER_DEVICE:
#define PORTAL_FUEL_COST (10 * FUEL_TANK_SCALE) #define PORTAL_FUEL_COST (10 * FUEL_TANK_SCALE)
if (inHyperSpace () if (inHyperSpace ()
&& GLOBAL_SIS (FuelOnBoard) >= PORTAL_FUEL_COST) && GET_GAME_STATE (SIS.FuelOnBoard) >= PORTAL_FUEL_COST)
{ {
/* No DeltaSISGauges because the flagship picture /* No DeltaSISGauges because the flagship picture
* is currently obscured. * 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); SET_GAME_STATE (PORTAL_COUNTER, 1);
return DEVICE_SUCCESS; return DEVICE_SUCCESS;
} }
@@ -674,14 +674,14 @@ DevicesMenu (void)
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); 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)) && !(GLOBAL (CurrentActivity) & CHECK_ABORT))
{ {
ClearSISRect (DRAW_SIS_DISPLAY); ClearSISRect (DRAW_SIS_DISPLAY);
if (!GET_GAME_STATE (PORTAL_COUNTER) if (!GET_GAME_STATE (PORTAL_COUNTER)
&& !(GLOBAL (CurrentActivity) & START_ENCOUNTER) && !(GLOBAL (CurrentActivity) & START_ENCOUNTER)
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0)
return TRUE; return TRUE;
} }
+4 -1
View File
@@ -106,8 +106,11 @@ GenerateDefault_generateName (const SOLARSYS_STATE *solarSys,
const PLANET_DESC *world) const PLANET_DESC *world)
{ {
COUNT i = planetIndex (solarSys, 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)); GAME_STRING (PLANET_NUMBER_BASE + (9 + 7) + i));
SET_GAME_STATE_STRING (SIS.PlanetName, buf);
SET_GAME_STATE (BATTLE_PLANET, world->data_index); SET_GAME_STATE (BATTLE_PLANET, world->data_index);
return true; return true;
+27 -27
View File
@@ -51,7 +51,7 @@ namespace
{ {
void initNpcs( SolarSystem *solarSys ) override; void initNpcs( SolarSystem *solarSys ) override;
static int SelectMelnormeRefVar(); static std::string SelectMelnormeRefVar();
static DWORD GetMelnormeRef(); static DWORD GetMelnormeRef();
static void SetMelnormeRef( DWORD Ref ); static void SetMelnormeRef( DWORD Ref );
}; };
@@ -81,26 +81,26 @@ GenerateMelnorme::initNpcs( SolarSystem *const solarSys )
} }
int std::string
GenerateMelnorme::SelectMelnormeRefVar() GenerateMelnorme::SelectMelnormeRefVar()
{ {
const auto arg_p= CurStarDescPtr->supArg; const auto arg_p= CurStarDescPtr->supArg;
const std::string arg= arg_p ? arg_p : ""; 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 }, { "0"s, "MELNORME0_GRPOFFS0" },
{ "1"s, MELNORME1_GRPOFFS0 }, { "1"s, "MELNORME1_GRPOFFS0" },
{ "2"s, MELNORME2_GRPOFFS0 }, { "2"s, "MELNORME2_GRPOFFS0" },
{ "3"s, MELNORME3_GRPOFFS0 }, { "3"s, "MELNORME3_GRPOFFS0" },
{ "4"s, MELNORME4_GRPOFFS0 }, { "4"s, "MELNORME4_GRPOFFS0" },
{ "5"s, MELNORME5_GRPOFFS0 }, { "5"s, "MELNORME5_GRPOFFS0" },
{ "6"s, MELNORME6_GRPOFFS0 }, { "6"s, "MELNORME6_GRPOFFS0" },
{ "7"s, MELNORME7_GRPOFFS0 }, { "7"s, "MELNORME7_GRPOFFS0" },
{ "8"s, MELNORME8_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 ); return lookups.at( arg );
} }
@@ -108,26 +108,26 @@ GenerateMelnorme::SelectMelnormeRefVar()
DWORD DWORD
GenerateMelnorme::GetMelnormeRef() GenerateMelnorme::GetMelnormeRef()
{ {
int RefVar = SelectMelnormeRefVar (); const auto RefVar = SelectMelnormeRefVar ();
if (RefVar < 0) //if (RefVar < 0)
{ //{
log_add (log_Warning, "GetMelnormeRef(): reference unknown"); //log_add (log_Warning, "GetMelnormeRef(): reference unknown");
return 0; //return 0;
} //}
return GET_GAME_STATE_32 (RefVar); return getGameState_json( RefVar.c_str() );
} }
void void
GenerateMelnorme::SetMelnormeRef( DWORD Ref ) GenerateMelnorme::SetMelnormeRef( DWORD Ref )
{ {
int RefVar = SelectMelnormeRefVar (); const auto RefVar = SelectMelnormeRefVar ();
if (RefVar < 0) //if (RefVar < 0)
{ //{
log_add (log_Warning, "SetMelnormeRef(): reference unknown"); //log_add (log_Warning, "SetMelnormeRef(): reference unknown");
return; //return;
} //}
SET_GAME_STATE_32 (RefVar, Ref); setGameState_json (RefVar.c_str(), Ref);
} }
@@ -241,10 +241,10 @@ GenerateTalkingPet::ZapToUrquanEncounter()
+ (FUEL_TANK_SCALE >> 1); + (FUEL_TANK_SCALE >> 1);
DeltaSISGauges (0, -dx, 0); 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) dx = ((5 + ((COUNT)TFB_Random () % 5)) * FUEL_TANK_SCALE)
- (SIZE)GLOBAL_SIS (FuelOnBoard); - (SIZE)GET_GAME_STATE (SIS.FuelOnBoard);
DeltaSISGauges (0, dx, 0); DeltaSISGauges (0, dx, 0);
} }
DrawSISMessage (NULL); DrawSISMessage (NULL);
@@ -340,28 +340,26 @@ GenerateSol::generateName (const SolarSystem *const solarSys,
if( matchWorld( solarSys, world, 3, 0 ) ) if( matchWorld( solarSys, world, 3, 0 ) )
{ {
fprintf( stderr, "ADAM: Trying to set Phobos\n" ); fprintf( stderr, "ADAM: Trying to set Phobos\n" );
utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), setGameState_string_json( "SIS.PlanetName", "Phobos" );
"Phobos" );
} }
else if( matchWorld( solarSys, world, 3, 1 ) ) else if( matchWorld( solarSys, world, 3, 1 ) )
{ {
fprintf( stderr, "ADAM: Trying to set Deimos\n" ); fprintf( stderr, "ADAM: Trying to set Deimos\n" );
utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), setGameState_string_json( "SIS.PlanetName", "Deimos" );
"Deimos" );
} }
else if( matchWorld( solarSys, world, 4, MATCH_PLANET ) ) else if( matchWorld( solarSys, world, 4, MATCH_PLANET ) )
{ {
fprintf( stderr, "ADAM: Trying to set Ceres\n" ); fprintf( stderr, "ADAM: Trying to set Ceres\n" );
utf8StringCopy( GLOBAL_SIS( PlanetName ), sizeof( GLOBAL_SIS( PlanetName ) ), setGameState_string_json( "SIS.PlanetName", "Ceres" );
"Ceres" );
} }
else else
{ {
fprintf( stderr, "ADAM: Trying to set from default to: %s\n", GAME_STRING( PLANET_NUMBER_BASE + planetNr ) ); fprintf( stderr, "ADAM: Trying to set from default to: %s\n", GAME_STRING( PLANET_NUMBER_BASE + planetNr ) );
COUNT xPlanetNr= planetNr; COUNT xPlanetNr= planetNr;
if( xPlanetNr > 4 ) xPlanetNr-= 1; if( xPlanetNr > 4 ) xPlanetNr-= 1;
utf8StringCopy (GLOBAL_SIS (PlanetName), sizeof (GLOBAL_SIS (PlanetName)), std::string tmp= GAME_STRING (PLANET_NUMBER_BASE + xPlanetNr);
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); SET_GAME_STATE (BATTLE_PLANET, solarSys->PlanetDesc[planetNr].data_index);
+1 -1
View File
@@ -1328,7 +1328,7 @@ AnimateLanderWarmup (void)
animationInterframe (&TimeIn, 2); animationInterframe (&TimeIn, 2);
for (num_crew = 0; num_crew < (NUM_CREW_COLS * NUM_CREW_ROWS) 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); animationInterframe (&TimeIn, 1);
+2 -2
View File
@@ -198,7 +198,7 @@ DrawOrbitalDisplay (DRAW_ORBITAL_MODE Mode)
DrawSISFrame (); DrawSISFrame ();
DrawSISMessage (NULL); DrawSISMessage (NULL);
DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName));
DrawStarBackGround (); DrawStarBackGround ();
DrawPlanetSurfaceBorder (); DrawPlanetSurfaceBorder ();
} }
@@ -369,7 +369,7 @@ DoPlanetOrbit (MENU_STATE *pMS)
BOOLEAN handled; BOOLEAN handled;
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0)
return FALSE; return FALSE;
// XXX: pMS actually refers to pSolarSysState->MenuState // XXX: pMS actually refers to pSolarSysState->MenuState
+1 -1
View File
@@ -342,7 +342,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
// Draw the fuel range circle // Draw the fuel range circle
if (race_update == 0 if (race_update == 0
&& which_space < 2 && which_space < 2
&& (diameter = (long)GLOBAL_SIS (FuelOnBoard) << 1)) && (diameter = (long)GET_GAME_STATE (SIS.FuelOnBoard) << 1))
{ {
Color OldColor; Color OldColor;
+2 -2
View File
@@ -275,14 +275,14 @@ DoModifyRoster (MENU_STATE *pMS)
if (up) if (up)
{ {
if (GLOBAL_SIS (CrewEnlisted)) if (GET_GAME_STATE (SIS.CrewEnlisted))
delta = 1; delta = 1;
else else
failed = TRUE; failed = TRUE;
} }
else if (down) else if (down)
{ {
if (GLOBAL_SIS (CrewEnlisted) < GetCrewPodCapacity ()) if (GET_GAME_STATE (SIS.CrewEnlisted) < GetCrewPodCapacity ())
delta = -1; delta = -1;
else else
failed = TRUE; failed = TRUE;
+2 -2
View File
@@ -1059,9 +1059,9 @@ DoScan (MENU_STATE *pMS)
} }
fuel_required = getLandingFuelNeeded (); fuel_required = getLandingFuelNeeded ();
if (GLOBAL_SIS (FuelOnBoard) < fuel_required if (GET_GAME_STATE (SIS.FuelOnBoard) < fuel_required
|| GLOBAL_SIS (NumLanders) == 0 || GLOBAL_SIS (NumLanders) == 0
|| GLOBAL_SIS (CrewEnlisted) == 0) || GET_GAME_STATE (SIS.CrewEnlisted) == 0)
{ {
PlayMenuSound (MENU_SOUND_FAILURE); PlayMenuSound (MENU_SOUND_FAILURE);
return TRUE; return TRUE;
+6 -6
View File
@@ -1207,7 +1207,7 @@ DrawInnerSystem (void)
{ {
ValidateInnerOrbits (); ValidateInnerOrbits ();
DrawSystem (pSolarSysState->pOrbitalDesc->radius, TRUE); DrawSystem (pSolarSysState->pOrbitalDesc->radius, TRUE);
DrawSISTitle (GLOBAL_SIS (PlanetName)); DrawSISTitle (GET_GAME_STATE_STRING (SIS.PlanetName));
} }
static void static void
@@ -1279,7 +1279,7 @@ EnterPlanetOrbit (void)
pSolarSysState->pOrbitalDesc); pSolarSysState->pOrbitalDesc);
LastActivity &= ~(CHECK_LOAD | CHECK_RESTART); LastActivity &= ~(CHECK_LOAD | CHECK_RESTART);
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD | 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) || GET_GAME_STATE (CHMMR_BOMB_STATE) == 2)
return; return;
@@ -1298,7 +1298,7 @@ EnterPlanetOrbit (void)
// Could also have blown self up with Utwig Bomb // Could also have blown self up with Utwig Bomb
if (!(GLOBAL (CurrentActivity) & (START_ENCOUNTER | if (!(GLOBAL (CurrentActivity) & (START_ENCOUNTER |
CHECK_ABORT | CHECK_LOAD)) 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 { // Reload the system and return to the inner view
PLANET_DESC *orbital = LoadSolarSys (); PLANET_DESC *orbital = LoadSolarSys ();
assert (!orbital); assert (!orbital);
@@ -1857,7 +1857,7 @@ GetPlanetOrMoonName (UNICODE *buf, COUNT bufsize)
} }
// Either not named or we already have a name // 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 () || if (!playerInSolarSystem () || !playerInInnerSystem () ||
worldIsPlanet (pSolarSysState, pSolarSysState->pOrbitalDesc)) worldIsPlanet (pSolarSysState, pSolarSysState->pOrbitalDesc))
@@ -1923,7 +1923,7 @@ DoSolarSysMenu (MENU_STATE *pMS)
BOOLEAN handled; BOOLEAN handled;
if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if ((GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
|| GLOBAL_SIS (CrewEnlisted) == (COUNT)~0) || GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0)
return FALSE; return FALSE;
handled = DoMenuChooser (pMS, PM_STARMAP); handled = DoMenuChooser (pMS, PM_STARMAP);
@@ -2038,5 +2038,5 @@ DoIpFlight (SOLARSYS_STATE *pSS)
return (!(GLOBAL (CurrentActivity) return (!(GLOBAL (CurrentActivity)
& (START_ENCOUNTER | END_INTERPLANETARY & (START_ENCOUNTER | END_INTERPLANETARY
| CHECK_ABORT | CHECK_LOAD)) | CHECK_ABORT | CHECK_LOAD))
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0); && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0);
} }
+1 -1
View File
@@ -260,7 +260,7 @@ RestartMenu (MENU_STATE *pMS)
SetContext (ScreenContext); SetContext (ScreenContext);
GLOBAL (CurrentActivity) |= CHECK_ABORT; 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_ON_SHIP)
&& !GET_GAME_STATE (UTWIG_BOMB)) && !GET_GAME_STATE (UTWIG_BOMB))
{ // player blew himself up with Utwig bomb { // player blew himself up with Utwig bomb
+3 -3
View File
@@ -65,11 +65,11 @@ typedef struct
extern ACTIVITY NextActivity; extern ACTIVITY NextActivity;
extern BOOLEAN LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); extern bool LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc);
extern BOOLEAN LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc); extern bool LoadLegacyGame (COUNT which_game, SUMMARY_DESC *summary_desc);
extern void SaveProblem (void); 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) #if defined(__cplusplus)
} }
+5 -5
View File
@@ -243,7 +243,7 @@ LeaveAutoPilot:
(GLOBAL (autopilot)).x = (GLOBAL (autopilot)).x =
(GLOBAL (autopilot)).y = ~0; (GLOBAL (autopilot)).y = ~0;
if (!(StarShipPtr->cur_status_flags & THRUST) if (!(StarShipPtr->cur_status_flags & THRUST)
|| (GLOBAL_SIS (FuelOnBoard) == 0 || (GET_GAME_STATE (SIS.FuelOnBoard) == 0
&& GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1))
{ {
AccelerateDirection = -1; AccelerateDirection = -1;
@@ -314,7 +314,7 @@ LeaveAutoPilot:
} }
GetCurrentVelocityComponents (&ElementPtr->velocity, &dx, &dy); GetCurrentVelocityComponents (&ElementPtr->velocity, &dx, &dy);
if ((GLOBAL_SIS (FuelOnBoard) if ((GET_GAME_STATE (SIS.FuelOnBoard)
|| GET_GAME_STATE (ARILOU_SPACE_SIDE) > 1) || GET_GAME_STATE (ARILOU_SPACE_SIDE) > 1)
&& (int)facing == (int)StarShipPtr->ShipFacing) && (int)facing == (int)StarShipPtr->ShipFacing)
{ {
@@ -1029,7 +1029,7 @@ init_sis (void)
{ {
// Count the captain too. // Count the captain too.
new_sis_desc.ship_info.max_crew++; 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; new_sis_desc.ship_info.ship_flags |= PLAYER_CAPTAIN;
} }
@@ -1045,9 +1045,9 @@ uninit_sis (RACE_DESC *pRaceDesc)
{ {
if (!inHQSpace ()) 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) 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); SetCustomShipData (pRaceDesc, NULL);
+5 -3
View File
@@ -56,14 +56,16 @@ DrawCrewFuelString (COORD y, SIZE state)
} }
static void static void
DrawShipNameString (UNICODE *pStr, COUNT CharCount, COORD y) DrawShipNameString (const UNICODE *pStr, COUNT CharCount, COORD y)
{ {
TEXT Text; TEXT Text;
FONT OldFont; FONT OldFont;
UNICODE buf[ SIS_NAME_SIZE ];
strncpy( buf, pStr, SIS_NAME_SIZE );
OldFont = SetContextFont (StarConFont); OldFont = SetContextFont (StarConFont);
Text.pStr = pStr; Text.pStr = buf;
Text.CharCount = CharCount; Text.CharCount = CharCount;
Text.align = ALIGN_CENTER; Text.align = ALIGN_CENTER;
@@ -277,7 +279,7 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect)
else if (StarShipPtr->playerNr == RPG_PLAYER_NUM) else if (StarShipPtr->playerNr == RPG_PLAYER_NUM)
{ // This is SIS { // This is SIS
DrawCrewFuelString (y, 0); DrawCrewFuelString (y, 0);
DrawShipNameString (GLOBAL_SIS (ShipName), (COUNT)~0, y); DrawShipNameString (GET_GAME_STATE_STRING (SIS.ShipName), (COUNT)~0, y);
} }
{ {
+16 -16
View File
@@ -522,7 +522,7 @@ CrewTransaction (SIZE crew_delta)
if (crew_bought >= CREW_EXPENSE_THRESHOLD if (crew_bought >= CREW_EXPENSE_THRESHOLD
&& crew_bought - crew_delta < 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); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
} }
} }
@@ -531,7 +531,7 @@ CrewTransaction (SIZE crew_delta)
if (crew_bought < CREW_EXPENSE_THRESHOLD if (crew_bought < CREW_EXPENSE_THRESHOLD
&& crew_bought - crew_delta >= 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); DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);
} }
} }
@@ -724,7 +724,7 @@ DMS_HireFlagShipCrew (void)
return 0; return 0;
} }
if (GLOBAL_SIS (ResUnits) < (DWORD)GLOBAL (CrewCost)) if (GET_GAME_STATE (SIS.ResUnits) < (DWORD)GET_GAME_STATE (CrewCost))
{ {
// Not enough RUs. // Not enough RUs.
return 0; return 0;
@@ -736,7 +736,7 @@ DMS_HireFlagShipCrew (void)
// Update the crew counter and RU. Note that the crew counter is // Update the crew counter and RU. Note that the crew counter is
// flashing. // flashing.
PreUpdateFlashRect (); PreUpdateFlashRect ();
DeltaSISGauges (1, 0, -GLOBAL (CrewCost)); DeltaSISGauges (1, 0, -GET_GAME_STATE (CrewCost));
PostUpdateFlashRect (); PostUpdateFlashRect ();
return 1; return 1;
@@ -765,7 +765,7 @@ DMS_DismissFlagShipCrew (void)
// Update the crew counter and RU. Note that the crew counter is // Update the crew counter and RU. Note that the crew counter is
// flashing. // flashing.
PreUpdateFlashRect (); PreUpdateFlashRect ();
DeltaSISGauges (-1, 0, GLOBAL (CrewCost) - DeltaSISGauges (-1, 0, GET_GAME_STATE (CrewCost) -
(crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0));
PostUpdateFlashRect (); PostUpdateFlashRect ();
@@ -797,7 +797,7 @@ DMS_HireEscortShipCrew (SHIP_FRAGMENT *StarShipPtr)
UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); 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. // Not enough money to hire a crew member.
return 0; return 0;
@@ -817,7 +817,7 @@ DMS_HireEscortShipCrew (SHIP_FRAGMENT *StarShipPtr)
if (StarShipPtr->crew_level > 0) if (StarShipPtr->crew_level > 0)
{ {
DeltaSISGauges (0, 0, -GLOBAL (CrewCost)); DeltaSISGauges (0, 0, -GET_GAME_STATE (CrewCost));
} }
else else
{ {
@@ -855,7 +855,7 @@ DMS_DismissEscortShipCrew (SHIP_FRAGMENT *StarShipPtr)
GET_GAME_STATE (CREW_PURCHASED0), GET_GAME_STATE (CREW_PURCHASED0),
GET_GAME_STATE (CREW_PURCHASED1)); GET_GAME_STATE (CREW_PURCHASED1));
DeltaSISGauges (0, 0, GLOBAL (CrewCost) DeltaSISGauges (0, 0, GET_GAME_STATE (CrewCost)
- (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0));
} }
else else
@@ -956,7 +956,7 @@ DMS_TryAddEscortShip (MENU_STATE *pMS)
LOBYTE (pMS->delta_item)); LOBYTE (pMS->delta_item));
COUNT Index = GetIndexFromStarShip (&GLOBAL (avail_race_q), shipInfo); 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)) && CloneShipFragment (Index, &GLOBAL (built_ship_q), 1))
{ {
ShowCombatShip (pMS, pMS->CurState, NULL); ShowCombatShip (pMS, pMS->CurState, NULL);
@@ -1318,8 +1318,8 @@ DrawBluePrint (MENU_STATE *pMS)
} }
{ {
num_frames = GLOBAL_SIS (CrewEnlisted); num_frames = GET_GAME_STATE (SIS.CrewEnlisted);
GLOBAL_SIS (CrewEnlisted) = 0; SET_GAME_STATE (SIS.CrewEnlisted, 0);
while (num_frames--) while (num_frames--)
{ {
@@ -1328,7 +1328,7 @@ DrawBluePrint (MENU_STATE *pMS)
GetCPodCapacity (&pt); GetCPodCapacity (&pt);
DrawPoint (&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; num_frames -= m;
} }
} }
if (GLOBAL_SIS (FuelOnBoard) > FUEL_RESERVE) if (GET_GAME_STATE (SIS.FuelOnBoard) > FUEL_RESERVE)
{ {
DWORD FuelVolume; DWORD FuelVolume;
RECT r; RECT r;
FuelVolume = GLOBAL_SIS (FuelOnBoard) - FUEL_RESERVE; FuelVolume = GET_GAME_STATE (SIS.FuelOnBoard) - FUEL_RESERVE;
GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE);
r.extent.width = 3; r.extent.width = 3;
r.extent.height = 1; r.extent.height = 1;
@@ -1375,7 +1375,7 @@ DrawBluePrint (MENU_STATE *pMS)
DrawFilledRectangle (&r); DrawFilledRectangle (&r);
m = FuelVolume < FUEL_VOLUME_PER_ROW ? m = FuelVolume < FUEL_VOLUME_PER_ROW ?
(COUNT)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; FuelVolume -= m;
} }
} }
+29 -27
View File
@@ -123,16 +123,18 @@ ClearSISRect (BYTE ClearFlags)
// right hand side, containing the coordinates in HyperSpace, or the planet // right hand side, containing the coordinates in HyperSpace, or the planet
// name in IP. // name in IP.
void void
DrawSISTitle (UNICODE *pStr) DrawSISTitle (const UNICODE *pStr)
{ {
TEXT t; TEXT t;
CONTEXT OldContext; CONTEXT OldContext;
RECT r; RECT r;
UNICODE buf[ SIS_NAME_SIZE ];
strncpy( buf, pStr, SIS_NAME_SIZE );
t.baseline.x = SIS_TITLE_WIDTH >> 1; t.baseline.x = SIS_TITLE_WIDTH >> 1;
t.baseline.y = SIS_TITLE_HEIGHT - 2; t.baseline.y = SIS_TITLE_HEIGHT - 2;
t.align = ALIGN_CENTER; t.align = ALIGN_CENTER;
t.pStr = pStr; t.pStr = buf;
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
OldContext = SetContext (OffScreenContext); OldContext = SetContext (OffScreenContext);
@@ -398,7 +400,7 @@ DrawStatusMessage (const UNICODE *pStr)
{ {
if (GET_GAME_STATE (CHMMR_BOMB_STATE) < 2) 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" GAME_STRING (STATUS_STRING_BASE + 1)); // "RU"
} }
else else
@@ -466,7 +468,7 @@ DrawCaptainsName (void)
t.baseline.x = (STATUS_WIDTH >> 1) - 1; t.baseline.x = (STATUS_WIDTH >> 1) - 1;
t.baseline.y = r.corner.y + 6; t.baseline.y = r.corner.y + 6;
t.align = ALIGN_CENTER; t.align = ALIGN_CENTER;
t.pStr = GLOBAL_SIS (CommanderName); t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName);
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
SetContextForeGroundColor (CAPTAIN_NAME_TEXT_COLOR); SetContextForeGroundColor (CAPTAIN_NAME_TEXT_COLOR);
font_DrawText (&t); font_DrawText (&t);
@@ -497,7 +499,7 @@ DrawFlagshipName (BOOLEAN InStatusArea)
r.extent.width = SHIP_NAME_WIDTH; r.extent.width = SHIP_NAME_WIDTH;
r.extent.height = SHIP_NAME_HEIGHT; r.extent.height = SHIP_NAME_HEIGHT;
t.pStr = GLOBAL_SIS (ShipName); t.pStr = GET_GAME_STATE_STRING (SIS.ShipName);
} }
else else
{ {
@@ -511,7 +513,7 @@ DrawFlagshipName (BOOLEAN InStatusArea)
t.pStr = buf; t.pStr = buf;
snprintf (buf, sizeof buf, "%s %s", 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 // XXX: this will not work with UTF-8 strings
strupr (buf); strupr (buf);
} }
@@ -989,14 +991,14 @@ DeltaSISGauges_crewDelta (SIZE crew_delta)
COUNT CrewCapacity; COUNT CrewCapacity;
if (crew_delta < 0 if (crew_delta < 0
&& GLOBAL_SIS (CrewEnlisted) <= (COUNT)-crew_delta) && GET_GAME_STATE (SIS.CrewEnlisted) <= (COUNT)-crew_delta)
GLOBAL_SIS (CrewEnlisted) = 0; SET_GAME_STATE (SIS.CrewEnlisted, 0);
else else
{ {
GLOBAL_SIS (CrewEnlisted) += crew_delta; SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + crew_delta);
CrewCapacity = GetCrewPodCapacity (); CrewCapacity = GetCrewPodCapacity ();
if (GLOBAL_SIS (CrewEnlisted) > CrewCapacity) if (GET_GAME_STATE (SIS.CrewEnlisted) > CrewCapacity)
GLOBAL_SIS (CrewEnlisted) = CrewCapacity; SET_GAME_STATE(SIS.CrewEnlisted, CrewCapacity);
} }
} }
@@ -1005,7 +1007,7 @@ DeltaSISGauges_crewDelta (SIZE crew_delta)
UNICODE buf[60]; UNICODE buf[60];
RECT r; RECT r;
snprintf (buf, sizeof buf, "%u", GLOBAL_SIS (CrewEnlisted)); snprintf (buf, sizeof buf, "%u", GET_GAME_STATE (SIS.CrewEnlisted));
GetGaugeRect (&r, TRUE); GetGaugeRect (&r, TRUE);
@@ -1038,23 +1040,23 @@ DeltaSISGauges_fuelDelta (SIZE fuel_delta)
{ {
old_coarse_fuel = (COUNT)( old_coarse_fuel = (COUNT)(
GLOBAL_SIS (FuelOnBoard) / FUEL_TANK_SCALE); GET_GAME_STATE (SIS.FuelOnBoard) / FUEL_TANK_SCALE);
if (fuel_delta < 0 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 else
{ {
DWORD FuelCapacity = GetFuelTankCapacity (); DWORD FuelCapacity = GetFuelTankCapacity ();
GLOBAL_SIS (FuelOnBoard) += fuel_delta; SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + fuel_delta);
if (GLOBAL_SIS (FuelOnBoard) > FuelCapacity) if (GET_GAME_STATE (SIS.FuelOnBoard) > FuelCapacity)
GLOBAL_SIS (FuelOnBoard) = FuelCapacity; SET_GAME_STATE (SIS.FuelOnBoard, FuelCapacity);
} }
} }
new_coarse_fuel = (COUNT)( 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) if (new_coarse_fuel != old_coarse_fuel)
{ {
TEXT t; TEXT t;
@@ -1088,10 +1090,10 @@ DeltaSISGauges_resunitDelta (SIZE resunit_delta)
if (resunit_delta != UNDEFINED_DELTA) if (resunit_delta != UNDEFINED_DELTA)
{ {
if (resunit_delta < 0 if (resunit_delta < 0
&& GLOBAL_SIS (ResUnits) <= (DWORD)-resunit_delta) && GET_GAME_STATE (SIS.ResUnits) <= (DWORD)-resunit_delta)
GLOBAL_SIS (ResUnits) = 0; SET_GAME_STATE (SIS.ResUnits, 0);
else else
GLOBAL_SIS (ResUnits) += resunit_delta; SET_GAME_STATE (SIS.ResUnits, GET_GAME_STATE (SIS.ResUnits) + resunit_delta);
assert (curMsgMode == SMM_RES_UNITS); assert (curMsgMode == SMM_RES_UNITS);
} }
@@ -1169,7 +1171,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
COUNT COUNT
GetCrewCount (void) 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. // Get the number of crew which fit in a module of a specified type.
@@ -1376,7 +1378,7 @@ GetSBayCapacity (POINT *ppt)
static DWORD static DWORD
GetFuelTotal (void) 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. // 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) OnAutoPilot = (GLOBAL (autopilot.x) != ~0 && GLOBAL (autopilot.y) != ~0)
|| GLOBAL_SIS (FuelOnBoard) == 0; || GET_GAME_STATE (SIS.FuelOnBoard) == 0;
if (OnAutoPilot || LastPilot) if (OnAutoPilot || LastPilot)
{ {
@@ -1556,13 +1558,13 @@ DrawAutoPilotMessage (BOOLEAN Reset)
else if (GetTimeCounter () >= NextTime) else if (GetTimeCounter () >= NextTime)
{ {
if (!(GLOBAL (CurrentActivity) & CHECK_ABORT) if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)
&& GLOBAL_SIS (CrewEnlisted) != (COUNT)~0) && GET_GAME_STATE (SIS.CrewEnlisted) != (COUNT)~0)
{ {
CONTEXT OldContext; CONTEXT OldContext;
OldContext = SetContext (OffScreenContext); OldContext = SetContext (OffScreenContext);
SetContextForeGroundColor (cycle_tab[cycle_index]); SetContextForeGroundColor (cycle_tab[cycle_index]);
if (GLOBAL_SIS (FuelOnBoard) == 0) if (GET_GAME_STATE (SIS.FuelOnBoard) == 0)
{ {
DrawSISMessageEx (GAME_STRING (NAVIGATION_STRING_BASE + 2), DrawSISMessageEx (GAME_STRING (NAVIGATION_STRING_BASE + 2),
-1, -1, DSME_MYCOLOR); // "OUT OF FUEL" -1, -1, DSME_MYCOLOR); // "OUT OF FUEL"
+6 -4
View File
@@ -133,10 +133,10 @@ typedef struct
{ {
SDWORD log_x, log_y; SDWORD log_x, log_y;
DWORD ResUnits; //DWORD ResUnits;
DWORD FuelOnBoard; //DWORD FuelOnBoard;
COUNT CrewEnlisted; //COUNT CrewEnlisted;
// Number of crew on board, not counting the captain. // Number of crew on board, not counting the captain.
// Set to (COUNT) ~0 to indicate game over. // Set to (COUNT) ~0 to indicate game over.
COUNT TotalElementMass, TotalBioMass; COUNT TotalElementMass, TotalBioMass;
@@ -149,9 +149,11 @@ typedef struct
COUNT ElementAmounts[NUM_ELEMENT_CATEGORIES]; COUNT ElementAmounts[NUM_ELEMENT_CATEGORIES];
/*
UNICODE ShipName[SIS_NAME_SIZE]; UNICODE ShipName[SIS_NAME_SIZE];
UNICODE CommanderName[SIS_NAME_SIZE]; UNICODE CommanderName[SIS_NAME_SIZE];
UNICODE PlanetName[SIS_NAME_SIZE]; UNICODE PlanetName[SIS_NAME_SIZE];
*/
} SIS_STATE; } SIS_STATE;
#define OVERRIDE_LANDER_FLAGS (1 << 7) #define OVERRIDE_LANDER_FLAGS (1 << 7)
@@ -170,7 +172,7 @@ extern void ContinueFlash (void);
#define SFR_MENU_3DO ((RECT*)~0L) #define SFR_MENU_3DO ((RECT*)~0L)
#define SFR_MENU_ANY ((RECT*)~1L) #define SFR_MENU_ANY ((RECT*)~1L)
extern void DrawHyperCoords (POINT puniverse); extern void DrawHyperCoords (POINT puniverse);
extern void DrawSISTitle (UNICODE *pStr); extern void DrawSISTitle (const UNICODE *pStr);
// Flags for DrawSISMessageEx (may be OR'ed): // Flags for DrawSISMessageEx (may be OR'ed):
#define DSME_NONE 0 #define DSME_NONE 0
+2 -2
View File
@@ -474,7 +474,7 @@ VisitStarBase (void)
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip); UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
InitCommunication (ILWRATH_CONVERSATION); InitCommunication (ILWRATH_CONVERSATION);
if (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0 if (GET_GAME_STATE (SIS.CrewEnlisted) == (COUNT)~0
|| (GLOBAL (CurrentActivity) & CHECK_ABORT)) || (GLOBAL (CurrentActivity) & CHECK_ABORT))
return; // Killed by Ilwrath return; // Killed by Ilwrath
@@ -496,7 +496,7 @@ VisitStarBase (void)
// Starbase becomes available for the first time, or after Chmmr // Starbase becomes available for the first time, or after Chmmr
// install the bomb. // install the bomb.
DoTimePassage (); 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) return; // You are now dead! Thank you! (killed by Kohr-Ah)
SetCommIntroMode (CIM_FADE_IN_SCREEN, ONE_SECOND * 2); SetCommIntroMode (CIM_FADE_IN_SCREEN, ONE_SECOND * 2);
+1 -1
View File
@@ -292,7 +292,7 @@ while (--ac > 0)
if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)) if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))
&& (LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE && (LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE
// if died for some reason // 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)) if (GET_GAME_STATE (KOHR_AH_KILLED_ALL))
InitCommunication (BLACKURQ_CONVERSATION); InitCommunication (BLACKURQ_CONVERSATION);
+1 -1
View File
@@ -270,7 +270,7 @@ DrawCaptainsWindow (STARSHIP *StarShipPtr)
t.baseline.x = STATUS_WIDTH >> 1; t.baseline.x = STATUS_WIDTH >> 1;
t.baseline.y = y + 6; t.baseline.y = y + 6;
t.align = ALIGN_CENTER; t.align = ALIGN_CENTER;
t.pStr = GLOBAL_SIS (CommanderName); t.pStr = GET_GAME_STATE_STRING (SIS.CommanderName);
t.CharCount = (COUNT)~0; t.CharCount = (COUNT)~0;
SetContextForeGroundColor ( SetContextForeGroundColor (
BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02)); BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02));
+10 -11
View File
@@ -284,11 +284,10 @@ equipShip (void)
GLOBAL_SIS (JetSlots[i]) = TURNING_JETS; GLOBAL_SIS (JetSlots[i]) = TURNING_JETS;
// Shields: // Shields:
SET_GAME_STATE (LANDER_SHIELDS, SET_GAME_STATE (LANDER_SHIELD_BIO, 1);
(1 << EARTHQUAKE_DISASTER) | SET_GAME_STATE (LANDER_SHIELD_QUAKE, 1);
(1 << BIOLOGICAL_DISASTER) | SET_GAME_STATE (LANDER_SHIELD_LIGHTNING, 1);
(1 << LIGHTNING_DISASTER) | SET_GAME_STATE (LANDER_SHIELD_HEAT, 1);
(1 << LAVASPOT_DISASTER));
// Lander upgrades: // Lander upgrades:
SET_GAME_STATE (IMPROVED_LANDER_SPEED, 1); SET_GAME_STATE (IMPROVED_LANDER_SPEED, 1);
SET_GAME_STATE (IMPROVED_LANDER_CARGO, 1); SET_GAME_STATE (IMPROVED_LANDER_CARGO, 1);
@@ -335,19 +334,19 @@ equipShip (void)
assert (i <= NUM_MODULE_SLOTS); assert (i <= NUM_MODULE_SLOTS);
// Fill the fuel and crew compartments to the maximum. // Fill the fuel and crew compartments to the maximum.
GLOBAL_SIS (FuelOnBoard) = FUEL_RESERVE; SET_GAME_STATE (SIS.FuelOnBoard, FUEL_RESERVE);
GLOBAL_SIS (CrewEnlisted) = 0; SET_GAME_STATE (SIS.CrewEnlisted, 0);
for (i = 0; i < NUM_MODULE_SLOTS; i++) for (i = 0; i < NUM_MODULE_SLOTS; i++)
{ {
switch (GLOBAL_SIS (ModuleSlots[i])) { switch (GLOBAL_SIS (ModuleSlots[i])) {
case CREW_POD: case CREW_POD:
GLOBAL_SIS (CrewEnlisted) += CREW_POD_CAPACITY; SET_GAME_STATE (SIS.CrewEnlisted, GET_GAME_STATE (SIS.CrewEnlisted) + CREW_POD_CAPACITY);
break; break;
case FUEL_TANK: case FUEL_TANK:
GLOBAL_SIS (FuelOnBoard) += FUEL_TANK_CAPACITY; SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + FUEL_TANK_CAPACITY);
break; break;
case HIGHEFF_FUELSYS: case HIGHEFF_FUELSYS:
GLOBAL_SIS (FuelOnBoard) += HEFUEL_TANK_CAPACITY; SET_GAME_STATE (SIS.FuelOnBoard, GET_GAME_STATE (SIS.FuelOnBoard) + HEFUEL_TANK_CAPACITY);
break; break;
} }
} }
@@ -984,7 +983,7 @@ void
dumpPlanet (FILE *out, const PLANET_DESC *planet) dumpPlanet (FILE *out, const PLANET_DESC *planet)
{ {
(*pSolarSysState->genFuncs->generateName) (pSolarSysState, 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)); planetTypeString (planet->data_index & ~PLANET_SHIELDED));
dumpWorld (out, planet); dumpWorld (out, planet);
} }