From fe0a9a11267a9ba0c959d2a16daeeca54dabf840 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Fri, 18 Oct 2013 22:38:39 -0700 Subject: [PATCH] Expose some of the statefile structure to load and save. --- sc2/src/uqm/grpinfo.c | 49 ++++++------------------------------ sc2/src/uqm/grpintrn.h | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 sc2/src/uqm/grpintrn.h diff --git a/sc2/src/uqm/grpinfo.c b/sc2/src/uqm/grpinfo.c index dc7be0f4c..43f1b22b6 100644 --- a/sc2/src/uqm/grpinfo.c +++ b/sc2/src/uqm/grpinfo.c @@ -23,7 +23,7 @@ #include "globdata.h" #include "intel.h" #include "state.h" -#include "grpinfo.h" +#include "grpintrn.h" #include "libs/mathlib.h" #include "libs/log.h" @@ -35,42 +35,7 @@ static BYTE LastEncGroup; // Last encountered group, saved into state files -//#define DEBUG_GROUPS - -// A group header describes battle groups present in a star system. There is -// at most 1 group header per system. -// 'Random' group info file (RANDGRPINFO_FILE) always contains only one -// group header record, which describes the last-visited star system, -// (which may be the current system). Thus the randomly generated groups -// are valid for 7 days (set in PutGroupInfo) after the player leaves -// the system, or until the player enters another star system. -typedef struct -{ - BYTE NumGroups; - BYTE day_index, month_index; - COUNT star_index, year_index; - // day_index, month_index, year_index specify when - // random groups expire (if you were to leave the system - // by going to HSpace and stay there till such time) - // star_index is the index of a star this group header - // applies to; ~0 means uninited - DWORD GroupOffset[NUM_SAVED_BATTLE_GROUPS + 1]; - // Absolute offsets of group definitions in a state file - // Group 0 is a list of groups present in solarsys - // (RANDGRPINFO_FILE only) - // Groups 1..max are definitions of actual battle groups - // containing ship makeup and status - - // Each group has the following format: - // 1 byte, RaceType (LastEncGroup in Group 0) - // 1 byte, NumShips (NumGroups in Group 0) - // Ships follow: - // 1 byte, RaceType - // 16 bytes, part of SHIP_FRAGMENT struct - -} GROUP_HEADER; - -static void +void ReadGroupHeader (GAME_STATE_FILE *fp, GROUP_HEADER *pGH) { sread_8 (fp, &pGH->NumGroups); @@ -82,7 +47,7 @@ ReadGroupHeader (GAME_STATE_FILE *fp, GROUP_HEADER *pGH) sread_a32 (fp, pGH->GroupOffset, NUM_SAVED_BATTLE_GROUPS + 1); } -static void +void WriteGroupHeader (GAME_STATE_FILE *fp, const GROUP_HEADER *pGH) { swrite_8 (fp, pGH->NumGroups); @@ -94,7 +59,7 @@ WriteGroupHeader (GAME_STATE_FILE *fp, const GROUP_HEADER *pGH) swrite_a32 (fp, pGH->GroupOffset, NUM_SAVED_BATTLE_GROUPS + 1); } -static void +void ReadShipFragment (GAME_STATE_FILE *fp, SHIP_FRAGMENT *FragPtr) { BYTE tmpb; @@ -116,7 +81,7 @@ ReadShipFragment (GAME_STATE_FILE *fp, SHIP_FRAGMENT *FragPtr) sread_16 (fp, NULL); /* unused; was loc.y */ } -static void +void WriteShipFragment (GAME_STATE_FILE *fp, const SHIP_FRAGMENT *FragPtr) { swrite_16 (fp, 0); /* unused: was which_side */ @@ -134,7 +99,7 @@ WriteShipFragment (GAME_STATE_FILE *fp, const SHIP_FRAGMENT *FragPtr) swrite_16 (fp, 0); /* unused; was loc.y */ } -static void +void ReadIpGroup (GAME_STATE_FILE *fp, IP_GROUP *GroupPtr) { BYTE tmpb; @@ -157,7 +122,7 @@ ReadIpGroup (GAME_STATE_FILE *fp, IP_GROUP *GroupPtr) sread_16s(fp, &GroupPtr->loc.y); } -static void +void WriteIpGroup (GAME_STATE_FILE *fp, const IP_GROUP *GroupPtr) { swrite_16 (fp, 0); /* unused; was which_side */ diff --git a/sc2/src/uqm/grpintrn.h b/sc2/src/uqm/grpintrn.h new file mode 100644 index 000000000..d2136a507 --- /dev/null +++ b/sc2/src/uqm/grpintrn.h @@ -0,0 +1,56 @@ +#ifndef _GRPINTRN_H +#define _GRPINTRN_H + +// For IPGROUP +#include "grpinfo.h" + +// For SHIP_FRAGMENT +#include "races.h" + +// For GAME_STATE_FILE +#include "state.h" + +//#define DEBUG_GROUPS + +// A group header describes battle groups present in a star system. There is +// at most 1 group header per system. +// 'Random' group info file (RANDGRPINFO_FILE) always contains only one +// group header record, which describes the last-visited star system, +// (which may be the current system). Thus the randomly generated groups +// are valid for 7 days (set in PutGroupInfo) after the player leaves +// the system, or until the player enters another star system. +typedef struct +{ + BYTE NumGroups; + BYTE day_index, month_index; + COUNT star_index, year_index; + // day_index, month_index, year_index specify when + // random groups expire (if you were to leave the system + // by going to HSpace and stay there till such time) + // star_index is the index of a star this group header + // applies to; ~0 means uninited + DWORD GroupOffset[NUM_SAVED_BATTLE_GROUPS + 1]; + // Absolute offsets of group definitions in a state file + // Group 0 is a list of groups present in solarsys + // (RANDGRPINFO_FILE only) + // Groups 1..max are definitions of actual battle groups + // containing ship makeup and status + + // Each group has the following format: + // 1 byte, RaceType (LastEncGroup in Group 0) + // 1 byte, NumShips (NumGroups in Group 0) + // Ships follow: + // 1 byte, RaceType + // 16 bytes, part of SHIP_FRAGMENT struct + // (part of IP_GROUP struct in Group 0) + +} GROUP_HEADER; + +void ReadGroupHeader (GAME_STATE_FILE *fp, GROUP_HEADER *pGH); +void WriteGroupHeader (GAME_STATE_FILE *fp, const GROUP_HEADER *pGH); +void ReadShipFragment (GAME_STATE_FILE *fp, SHIP_FRAGMENT *FragPtr); +void WriteShipFragment (GAME_STATE_FILE *fp, const SHIP_FRAGMENT *FragPtr); +void ReadIpGroup (GAME_STATE_FILE *fp, IP_GROUP *GroupPtr); +void WriteIpGroup (GAME_STATE_FILE *fp, const IP_GROUP *GroupPtr); + +#endif