Untangling ship queues, stage 2: Unaliasing STARSHIP, SHIP_FRAGMENT and EXTENDED_SHIP_FRAGMENT (incomplete; Build, OwnStarShip and Co still aliased)

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2780 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2007-06-22 21:29:44 +00:00
parent e08a6cb5a1
commit 6276e33e2f
30 changed files with 376 additions and 331 deletions
+39 -22
View File
@@ -36,6 +36,8 @@ Build (QUEUE *pQueue, DWORD RaceResIndex, COUNT which_player, BYTE
{
STARSHIP *StarShipPtr;
// XXX: STARSHIP refactor; The last remaining aliasing between
// STARSHIP and SHIP_FRAGMENT structs
StarShipPtr = LockStarShip (pQueue, hNewShip);
memset (StarShipPtr, 0, GetLinkSize (pQueue));
@@ -49,19 +51,19 @@ Build (QUEUE *pQueue, DWORD RaceResIndex, COUNT which_player, BYTE
return (hNewShip);
}
HSTARSHIP
HLINK
GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index)
{
HSTARSHIP hStarShip, hNextShip;
HLINK hStarShip, hNextShip;
for (hStarShip = GetHeadLink (pShipQ);
Index > 0 && hStarShip; hStarShip = hNextShip, --Index)
{
STARSHIP *StarShipPtr;
LINK *StarShipPtr;
StarShipPtr = LockStarShip (pShipQ, hStarShip);
StarShipPtr = LockLink (pShipQ, hStarShip);
hNextShip = _GetSuccLink (StarShipPtr);
UnlockStarShip (pShipQ, hStarShip);
UnlockLink (pShipQ, hStarShip);
}
return (hStarShip);
@@ -183,8 +185,8 @@ ActivateStarShip (COUNT which_ship, SIZE state)
case CHECK_ALLIANCE:
{
COUNT flags;
SHIP_FRAGMENT *StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
EXTENDED_SHIP_FRAGMENT *StarShipPtr = (EXTENDED_SHIP_FRAGMENT*)
LockStarShip (&GLOBAL (avail_race_q), hStarShip);
flags = StarShipPtr->ShipInfo.ship_flags & (GOOD_GUY | BAD_GUY);
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
return flags;
@@ -192,8 +194,8 @@ ActivateStarShip (COUNT which_ship, SIZE state)
case SET_ALLIED:
case SET_NOT_ALLIED:
{
SHIP_FRAGMENT *StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
EXTENDED_SHIP_FRAGMENT *StarShipPtr = (EXTENDED_SHIP_FRAGMENT*)
LockStarShip (&GLOBAL (avail_race_q), hStarShip);
if (!(StarShipPtr->ShipInfo.ship_flags & (GOOD_GUY | BAD_GUY)))
{ /* Strange request, silently ignore it */
@@ -272,6 +274,8 @@ ActivateStarShip (COUNT which_ship, SIZE state)
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (built_ship_q), hOldShip);
// XXX: hack; escort window is not group loc,
// should just use queue index (already var2)
win_loc = GET_GROUP_LOC (StarShipPtr);
UnlockStarShip (&GLOBAL (built_ship_q), hOldShip);
if (which_window <= win_loc)
@@ -280,6 +284,8 @@ ActivateStarShip (COUNT which_ship, SIZE state)
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (built_ship_q), hStarShip);
// XXX: hack; escort window is not group loc,
// should just use queue index (already var2)
SET_GROUP_LOC (StarShipPtr, which_window - 1);
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
@@ -298,19 +304,19 @@ ActivateStarShip (COUNT which_ship, SIZE state)
}
COUNT
GetIndexFromStarShip (QUEUE *pShipQ, HSTARSHIP hStarShip)
GetIndexFromStarShip (QUEUE *pShipQ, HLINK hStarShip)
{
COUNT Index;
Index = 0;
while (hStarShip != GetHeadLink (pShipQ))
{
HSTARSHIP hNextShip;
STARSHIP *StarShipPtr;
HLINK hNextShip;
LINK *StarShipPtr;
StarShipPtr = LockStarShip (pShipQ, hStarShip);
StarShipPtr = LockLink (pShipQ, hStarShip);
hNextShip = _GetPredLink (StarShipPtr);
UnlockStarShip (pShipQ, hStarShip);
UnlockLink (pShipQ, hStarShip);
hStarShip = hNextShip;
++Index;
@@ -320,7 +326,7 @@ GetIndexFromStarShip (QUEUE *pShipQ, HSTARSHIP hStarShip)
}
BYTE
NameCaptain (QUEUE *pQueue, STARSHIP *StarShipPtr)
NameCaptain (QUEUE *pQueue, DWORD RaceResIndex)
{
BYTE name_index;
HSTARSHIP hStarShip;
@@ -336,10 +342,14 @@ NameCaptain (QUEUE *pQueue, STARSHIP *StarShipPtr)
TestShipPtr = LockStarShip (pQueue, hStarShip);
hNextShip = _GetSuccLink (TestShipPtr);
if (TestShipPtr->RaceResIndex == StarShipPtr->RaceResIndex)
if (TestShipPtr->RaceResIndex == RaceResIndex)
{
BOOLEAN SameName;
// XXX: STARSHIP refactor; The last remaining aliasing between
// STARSHIP and SHIP_FRAGMENT structs
// This hack will not be needed once
// STARSHIP maintains captain/side permanently
if (LOBYTE (GLOBAL (CurrentActivity)) == SUPER_MELEE)
SameName = (name_index == TestShipPtr->captains_name_index);
else
@@ -364,27 +374,34 @@ HSTARSHIP
CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level)
{
HSTARSHIP hStarShip, hBuiltShip;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), shipIndex);
if (hStarShip == 0)
return 0;
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
TemplatePtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
hBuiltShip = Build (pDstQueue, TemplatePtr->RaceResIndex,
TemplatePtr->ShipInfo.ship_flags & (GOOD_GUY | BAD_GUY),
(BYTE)(shipIndex == SAMATRA_SHIP ?
0 : NameCaptain (pDstQueue, (STARSHIP*)TemplatePtr)));
0 : NameCaptain (pDstQueue, TemplatePtr->RaceResIndex)));
if (hBuiltShip)
{
SHIP_FRAGMENT *ShipFragPtr;
ShipFragPtr = (SHIP_FRAGMENT*) LockStarShip (pDstQueue, hBuiltShip);
ShipFragPtr->ShipInfo = TemplatePtr->ShipInfo;
// XXX: SHIP_INFO struct copy
ShipFragPtr->ShipInfo.race_strings = TemplatePtr->ShipInfo.race_strings;
ShipFragPtr->ShipInfo.icons = TemplatePtr->ShipInfo.icons;
ShipFragPtr->ShipInfo.melee_icon = TemplatePtr->ShipInfo.melee_icon;
if (crew_level)
ShipFragPtr->ShipInfo.crew_level = crew_level;
else
ShipFragPtr->ShipInfo.crew_level = TemplatePtr->ShipInfo.crew_level;
ShipFragPtr->ShipInfo.max_crew = TemplatePtr->ShipInfo.max_crew;
ShipFragPtr->ShipInfo.energy_level = 0;
ShipFragPtr->ShipInfo.max_energy = TemplatePtr->ShipInfo.max_energy;
ShipFragPtr->ShipInfo.ship_flags = 0;
ShipFragPtr->ShipInfo.var1 = 0;
ShipFragPtr->ShipInfo.var2 = 0;
@@ -404,7 +421,7 @@ int
SetEscortCrewComplement (COUNT which_ship, COUNT crew_level, BYTE captain)
{
HSTARSHIP hTemplateShip;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
HSTARSHIP hStarShip;
HSTARSHIP hNextShip;
SHIP_FRAGMENT *StarShipPtr = 0;
@@ -413,7 +430,7 @@ SetEscortCrewComplement (COUNT which_ship, COUNT crew_level, BYTE captain)
hTemplateShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship);
if (!hTemplateShip)
return -1;
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hTemplateShip);
/* Find first ship of which_ship race */
+8 -6
View File
@@ -33,6 +33,7 @@
#define NAME_OFFSET 5
#define NUM_CAPTAINS_NAMES 16
// XXX: STARSHIP refactor; These three alias STARSHIP and SHIP_FRAGMENT
#define OwnStarShip(S,p,n) \
(S)->s.Player = (p); \
(S)->s.Captain = (n);
@@ -48,8 +49,8 @@ extern HSTARSHIP Build (QUEUE *pQueue, DWORD RaceResIndex, COUNT
which_player, BYTE captains_name_index);
extern HSTARSHIP CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue,
COUNT crew_level);
extern HSTARSHIP GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index);
extern BYTE NameCaptain (QUEUE *pQueue, STARSHIP *StarShipPtr);
extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index);
extern BYTE NameCaptain (QUEUE *pQueue, DWORD RaceResIndex);
/* Possible values for the 'state' argument of
* COUNT ActivateStarShip (COUNT which_ship, SIZE state)
@@ -67,7 +68,7 @@ extern BYTE NameCaptain (QUEUE *pQueue, STARSHIP *StarShipPtr);
/* Check for how many escort ships there's still space */
extern COUNT ActivateStarShip (COUNT which_ship, SIZE state);
extern COUNT GetIndexFromStarShip (QUEUE *pShipQ, HSTARSHIP hStarShip);
extern COUNT GetIndexFromStarShip (QUEUE *pShipQ, HLINK hStarShip);
extern int SetEscortCrewComplement (COUNT which_ship, COUNT crew_level,
BYTE captain);
@@ -78,10 +79,11 @@ extern void free_ship (RACE_DESC *RaceDescPtr, BOOLEAN FreeIconData,
extern void DrawCrewFuelString (COORD y, SIZE state);
extern void ClearShipStatus (COORD y);
extern void OutlineShipStatus (COORD y);
extern void InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect);
extern void DeltaStatistics (STARSHIP *StarShipPtr, SIZE crew_delta,
extern void InitShipStatus (SHIP_INFO *ShipInfoPtr, BYTE captains_name_index,
RECT *pClipRect);
extern void DeltaStatistics (SHIP_INFO *ShipInfoPtr, SIZE crew_delta,
SIZE energy_delta);
extern void DrawBattleCrewAmount (STARSHIP *StarShipPtr);
extern void DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr);
#endif /* _BUILD_H */
+1 -1
View File
@@ -42,7 +42,7 @@ typedef struct
/* Queue element is EVENT */
} CLOCK_STATE;
typedef QUEUE_HANDLE HEVENT;
typedef HLINK HEVENT;
typedef struct event
{
+24 -15
View File
@@ -1595,6 +1595,7 @@ RaceCommunication (void)
COUNT i, status;
HSTARSHIP hStarShip;
SHIP_FRAGMENT *FragPtr;
HENCOUNTER hEncounter = 0;
RESOURCE RaceComm[] =
{
RACE_COMMUNICATION
@@ -1650,8 +1651,8 @@ RaceCommunication (void)
}
else
{
/* Encounter with a black globe in HS, prepare enemy ship list */
COUNT NumShips;
HENCOUNTER hEncounter;
ENCOUNTER *EncounterPtr;
hEncounter = GetHeadEncounter ();
@@ -1660,11 +1661,15 @@ RaceCommunication (void)
NumShips = LONIBBLE (EncounterPtr->SD.Index);
for (i = 0; i < NumShips; ++i)
{
// XXX: Bug 996 lives here: crew is set to default (0)
// None of ship info is actually used!
CloneShipFragment (EncounterPtr->SD.Type,
&GLOBAL (npc_built_ship_q), 0);
}
CurStarDescPtr = (STAR_DESC*)&EncounterPtr->SD;
// XXX: Bug: CurStarDescPtr was abused to point within
// an ENCOUNTER struct, which is immediately unlocked
//CurStarDescPtr = (STAR_DESC*)&EncounterPtr->SD;
UnlockEncounter (hEncounter);
}
}
@@ -1689,38 +1694,42 @@ RaceCommunication (void)
if (i == SLYLANDRO_SHIP && status == 0)
ReinitQueue (&GLOBAL (npc_built_ship_q));
}
else
{
EXTENDED_STAR_DESC *pESD;
pESD = (EXTENDED_STAR_DESC*)CurStarDescPtr;
if (pESD)
else if (hEncounter)
{
/* Update HSpace encounter info, ships lefts, etc. */
BYTE i, NumShips;
ENCOUNTER *EncounterPtr;
LockEncounter (hEncounter, &EncounterPtr);
NumShips = (BYTE)CountLinks (&GLOBAL (npc_built_ship_q));
pESD->Index = MAKE_BYTE (NumShips, HINIBBLE (pESD->Index));
pESD->Index |= ENCOUNTER_REFORMING;
EncounterPtr->SD.Index = MAKE_BYTE (NumShips,
HINIBBLE (EncounterPtr->SD.Index));
EncounterPtr->SD.Index |= ENCOUNTER_REFORMING;
if (status == 0)
pESD->Index |= ONE_SHOT_ENCOUNTER;
EncounterPtr->SD.Index |= ONE_SHOT_ENCOUNTER;
for (i = 0; i < NumShips; ++i)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *TemplatePtr;
BRIEF_SHIP_INFO *BSIPtr;
hStarShip = GetStarShipFromIndex (
&GLOBAL (npc_built_ship_q), i);
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
pESD->ShipList[i] = TemplatePtr->ShipInfo;
pESD->ShipList[i].var1 = GET_RACE_ID (TemplatePtr);
// XXX: SHIP_INFO struct copy
BSIPtr = &EncounterPtr->ShipList[i];
BSIPtr->race_id = GET_RACE_ID (TemplatePtr);
BSIPtr->crew_level = TemplatePtr->ShipInfo.crew_level;
BSIPtr->max_crew = TemplatePtr->ShipInfo.max_crew;
BSIPtr->max_energy = TemplatePtr->ShipInfo.max_energy;
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
}
UnlockEncounter (hEncounter);
ReinitQueue (&GLOBAL (npc_built_ship_q));
CurStarDescPtr = 0;
}
}
}
+1 -1
View File
@@ -41,7 +41,7 @@
#define NORMAL_LIFE 1
typedef QUEUE_HANDLE HELEMENT;
typedef HLINK HELEMENT;
// Bits for ELEMENT_FLAGS:
#define GOOD_GUY (1 << 0)
+9 -6
View File
@@ -25,7 +25,7 @@
#include "races.h"
typedef QUEUE_HANDLE HENCOUNTER;
typedef HLINK HENCOUNTER;
#define MAX_HYPER_SHIPS 7
#define ONE_SHOT_ENCOUNTER (1 << 7)
@@ -33,10 +33,12 @@ typedef QUEUE_HANDLE HENCOUNTER;
typedef struct
{
POINT star_pt;
BYTE Type, Index;
SHIP_INFO ShipList[MAX_HYPER_SHIPS];
} EXTENDED_STAR_DESC;
BYTE race_id;
COUNT crew_level;
COUNT max_crew;
BYTE max_energy;
} BRIEF_SHIP_INFO;
typedef struct
{
@@ -48,7 +50,8 @@ typedef struct
POINT origin;
COUNT radius;
EXTENDED_STAR_DESC SD;
STAR_DESC SD;
BRIEF_SHIP_INFO ShipList[MAX_HYPER_SHIPS];
SDWORD log_x, log_y;
} ENCOUNTER;
+46 -27
View File
@@ -172,6 +172,23 @@ LoadSC2Data (void)
return TRUE;
}
static void
copyFleetInfo (EXTENDED_SHIP_INFO *dst, SHIP_INFO *src, BYTE *fleet_strength)
{
*fleet_strength = src->var2;
// other leading fields are irrelevant
dst->crew_level = src->crew_level;
dst->max_crew = src->max_crew;
dst->energy_level = src->energy_level;
dst->max_energy = src->max_energy;
dst->loc = src->loc;
dst->race_strings = src->race_strings;
dst->icons = src->icons;
dst->melee_icon = src->melee_icon;
}
BOOLEAN
InitSIS (void)
{
@@ -210,10 +227,10 @@ InitSIS (void)
hStarShip = Build (&GLOBAL (avail_race_q), ship_ref, 0, 0);
if (hStarShip)
{
SHIP_FRAGMENT *FragPtr;
EXTENDED_SHIP_FRAGMENT *ExtFragPtr;
EXTENDED_SHIP_FRAGMENT *FleetPtr;
BYTE fleet_strength = 0;
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
FleetPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
if (i < num_ships - 1)
{
@@ -224,38 +241,41 @@ InitSIS (void)
MasterShipPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q,
hMasterShip);
// Grab a copy of loaded icons and strings (not owned)
FragPtr->ShipInfo = MasterShipPtr->ShipInfo;
// XXX: SHIP_INFO struct copy
copyFleetInfo (&FleetPtr->ShipInfo, &MasterShipPtr->ShipInfo,
&fleet_strength);
UnlockStarShip (&master_q, hMasterShip);
}
else
{
// Ur-Quan probe.
RACE_DESC *RDPtr = load_ship (FragPtr->RaceResIndex,
RACE_DESC *RDPtr = load_ship (FleetPtr->RaceResIndex,
FALSE);
if (RDPtr)
{ // Grab a copy of loaded icons and strings
// XXX: SHIP_INFO struct copy
copyFleetInfo (&FleetPtr->ShipInfo, &RDPtr->ship_info,
&fleet_strength);
// avail_race_q owns these resources now
FragPtr->ShipInfo = RDPtr->ship_info;
free_ship (RDPtr, FALSE, FALSE);
}
}
ExtFragPtr = (EXTENDED_SHIP_FRAGMENT*)FragPtr;
ExtFragPtr->ShipInfo.ship_flags = BAD_GUY;
ExtFragPtr->ShipInfo.known_strength = 0;
ExtFragPtr->ShipInfo.known_loc = ExtFragPtr->ShipInfo.loc;
if (FragPtr->ShipInfo.var2 == (BYTE)~0)
ExtFragPtr->ShipInfo.actual_strength = (COUNT)~0;
FleetPtr->ShipInfo.ship_flags = BAD_GUY;
FleetPtr->ShipInfo.known_strength = 0;
FleetPtr->ShipInfo.known_loc = FleetPtr->ShipInfo.loc;
if (fleet_strength == (BYTE)~0)
FleetPtr->ShipInfo.actual_strength = (COUNT)~0;
else if (i == YEHAT_REBEL_SHIP)
ExtFragPtr->ShipInfo.actual_strength = 0;
FleetPtr->ShipInfo.actual_strength = 0;
else
ExtFragPtr->ShipInfo.actual_strength =
(COUNT)FragPtr->ShipInfo.var2 << 1;
ExtFragPtr->ShipInfo.growth_fract = 0;
ExtFragPtr->ShipInfo.growth_err_term = 255 >> 1;
ExtFragPtr->ShipInfo.energy_level = 0;
ExtFragPtr->ShipInfo.days_left = 0;
ExtFragPtr->ExtShipInfoPtr = &ExtFragPtr->ShipInfo;
FleetPtr->ShipInfo.actual_strength =
(COUNT)fleet_strength << 1;
FleetPtr->ShipInfo.growth_fract = 0;
FleetPtr->ShipInfo.growth_err_term = 255 >> 1;
FleetPtr->ShipInfo.energy_level = 0;
FleetPtr->ShipInfo.days_left = 0;
FleetPtr->ShipInfo.func_index = ~0;
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
@@ -388,15 +408,14 @@ UninitSIS (void)
hStarShip = GetTailLink (&GLOBAL (avail_race_q));
if (hStarShip)
{
STARSHIP *StarShipPtr;
EXTENDED_SHIP_FRAGMENT *FragPtr;
StarShipPtr = LockStarShip (&GLOBAL (avail_race_q), hStarShip);
DestroyDrawable (ReleaseDrawable (
StarShipPtr->RaceDescPtr->ship_info.melee_icon));
DestroyDrawable (ReleaseDrawable (
StarShipPtr->RaceDescPtr->ship_info.icons));
FragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.melee_icon));
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.icons));
DestroyStringTable (ReleaseStringTable (
StarShipPtr->RaceDescPtr->ship_info.race_strings));
FragPtr->ShipInfo.race_strings));
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
+3
View File
@@ -511,6 +511,9 @@ GetGroupInfo (DWORD offset, BYTE which_group)
&GLOBAL (npc_built_ship_q), 0);
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
// XXX: STARSHIP refactor; this is probably needed
// because SHIP_INFO.ship_flags is used for
// group_counter
OwnStarShip (FragPtr, BAD_GUY, 0);
SET_GROUP_ID (FragPtr, which_group);
+8 -4
View File
@@ -952,13 +952,17 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
for (i = 0; i < NumShips; ++i)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
BRIEF_SHIP_INFO *BSIPtr = &EncounterPtr->ShipList[i];
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), Type);
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
EncounterPtr->SD.ShipList[i] = TemplatePtr->ShipInfo;
EncounterPtr->SD.ShipList[i].var1 = Type;
// XXX: SHIP_INFO struct copy
BSIPtr->race_id = Type;
BSIPtr->crew_level = TemplatePtr->ShipInfo.crew_level;
BSIPtr->max_crew = TemplatePtr->ShipInfo.max_crew;
BSIPtr->max_energy = TemplatePtr->ShipInfo.max_energy;
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
+9 -33
View File
@@ -234,36 +234,33 @@ LoadEncounter (ENCOUNTER *EncounterPtr, DECODE_REF fh)
cread_16 (fh, &EncounterPtr->origin.x);
cread_16 (fh, &EncounterPtr->origin.y);
cread_16 (fh, &EncounterPtr->radius);
// EXTENDED_STAR_DESC fields
// STAR_DESC fields
cread_16 (fh, &EncounterPtr->SD.star_pt.x);
cread_16 (fh, &EncounterPtr->SD.star_pt.y);
cread_8 (fh, &EncounterPtr->SD.Type);
cread_8 (fh, &EncounterPtr->SD.Index);
cread_16 (fh, NULL); /* alignment padding */
// Load each entry in the SHIP_INFO array:
// Load each entry in the BRIEF_SHIP_INFO array
for (i = 0; i < MAX_HYPER_SHIPS; i++)
{
SHIP_INFO *ShipInfo = &EncounterPtr->SD.ShipList[i];
BRIEF_SHIP_INFO *ShipInfo = &EncounterPtr->ShipList[i];
BYTE tmpb;
cread_16 (fh, &ShipInfo->ship_flags);
cread_8 (fh, &ShipInfo->var1);
cread_8 (fh, &ShipInfo->var2);
cread_16 (fh, NULL); /* useless; was SHIP_INFO.ship_flags */
cread_8 (fh, &ShipInfo->race_id);
cread_8 (fh, NULL); /* useless; was SHIP_INFO.var2 */
cread_8 (fh, &tmpb);
ShipInfo->crew_level = tmpb;
cread_8 (fh, &tmpb);
ShipInfo->max_crew = tmpb;
cread_8 (fh, &ShipInfo->energy_level);
cread_8 (fh, NULL); /* useless; was SHIP_INFO.energy_level */
cread_8 (fh, &ShipInfo->max_energy);
cread_16 (fh, &ShipInfo->loc.x);
cread_16 (fh, &ShipInfo->loc.y);
cread_16 (fh, NULL); /* useless; was SHIP_INFO.loc.x */
cread_16 (fh, NULL); /* useless; was SHIP_INFO.loc.y */
cread_32 (fh, NULL); /* useless val; STRING race_strings */
ShipInfo->race_strings = 0;
cread_ptr (fh); /* useless ptr; FRAME icons */
ShipInfo->icons = 0;
cread_ptr (fh); /* useless ptr; FRAME melee_icon */
ShipInfo->melee_icon = 0;
}
// Load the stuff after the SHIP_INFO array:
@@ -555,7 +552,6 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
{
while (num_links--)
{
BYTE i, NumShips;
HENCOUNTER hEncounter;
ENCOUNTER *EncounterPtr;
@@ -564,26 +560,6 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
LoadEncounter (EncounterPtr, fh);
NumShips = LONIBBLE (EncounterPtr->SD.Index);
for (i = 0; i < NumShips; ++i)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *TemplatePtr;
hStarShip = GetStarShipFromIndex (
&GLOBAL (avail_race_q),
EncounterPtr->SD.ShipList[i].var1);
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
EncounterPtr->SD.ShipList[i].race_strings =
TemplatePtr->ShipInfo.race_strings;
EncounterPtr->SD.ShipList[i].icons =
TemplatePtr->ShipInfo.icons;
EncounterPtr->SD.ShipList[i].melee_icon =
TemplatePtr->ShipInfo.melee_icon;
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
UnlockEncounter (hEncounter);
PutEncounter (hEncounter);
}
+26 -2
View File
@@ -65,10 +65,9 @@ LoadMasterShipList (void (* YieldProcessing)(void))
continue;
}
// Grab a copy of loaded icons and strings
// Grab a copy of loaded icons, strings and info
BuiltFragPtr->ShipInfo = RDPtr->ship_info;
free_ship (RDPtr, FALSE, FALSE);
BuiltFragPtr->ShipInfoPtr = &BuiltFragPtr->ShipInfo;
GetStringContents (SetAbsStringTableIndex (
BuiltFragPtr->ShipInfo.race_strings, 2
@@ -145,3 +144,28 @@ FindMasterShip (DWORD ship_ref)
return (hStarShip);
}
int
FindMasterShipIndex (DWORD ship_ref)
{
HSTARSHIP hStarShip;
HSTARSHIP hNextShip;
int index;
for (index = 0, hStarShip = GetHeadLink (&master_q); hStarShip;
++index, hStarShip = hNextShip)
{
DWORD ref;
SHIP_FRAGMENT *FragPtr;
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
hNextShip = _GetSuccLink (FragPtr);
ref = FragPtr->RaceResIndex;
UnlockStarShip (&master_q, hStarShip);
if (ref == ship_ref)
break;
}
return hStarShip ? index : -1;
}
+2
View File
@@ -27,6 +27,8 @@ extern QUEUE master_q;
extern void LoadMasterShipList (void (* YieldProcessing)(void));
extern void FreeMasterShipList (void);
extern HSTARSHIP FindMasterShip (DWORD ship_ref);
extern int FindMasterShipIndex (DWORD ship_ref);
#endif /* _MASTER_H */
+77 -65
View File
@@ -256,6 +256,60 @@ GetShipColumn (int index)
return index % NUM_MELEE_COLUMNS;
}
static COUNT
GetShipCostFromIndex (unsigned Index)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *FragPtr;
COUNT val;
hStarShip = GetStarShipFromIndex (&master_q, Index);
if (!hStarShip)
return 0;
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
val = FragPtr->ShipInfo.ship_cost;
UnlockStarShip (&master_q, hStarShip);
return val;
}
static FRAME
GetShipIconsFromIndex (unsigned Index)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *FragPtr;
FRAME val;
hStarShip = GetStarShipFromIndex (&master_q, Index);
if (!hStarShip)
return 0;
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
val = FragPtr->ShipInfo.icons;
UnlockStarShip (&master_q, hStarShip);
return val;
}
static FRAME
GetShipMeleeIconsFromIndex (unsigned Index)
{
HSTARSHIP hStarShip;
SHIP_FRAGMENT *FragPtr;
FRAME val;
hStarShip = GetStarShipFromIndex (&master_q, Index);
if (!hStarShip)
return 0;
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
val = FragPtr->ShipInfo.melee_icon;
UnlockStarShip (&master_q, hStarShip);
return val;
}
static void
DrawShipBox (COUNT side, COUNT row, COUNT col, BYTE ship, BOOLEAN HiLite)
{
@@ -280,17 +334,11 @@ DrawShipBox (COUNT side, COUNT row, COUNT col, BYTE ship, BOOLEAN HiLite)
if (ship != MELEE_NONE)
{
STAMP s;
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
hStarShip = GetStarShipFromIndex (&master_q, ship);
StarShipPtr = LockStarShip (&master_q, hStarShip);
s.origin.x = r.corner.x + (r.extent.width >> 1);
s.origin.y = r.corner.y + (r.extent.height >> 1);
s.frame = StarShipPtr->RaceDescPtr->ship_info.melee_icon;
s.frame = GetShipMeleeIconsFromIndex (ship);
DrawStamp (&s);
UnlockStarShip (&master_q, hStarShip);
}
UnbatchGraphics ();
}
@@ -556,17 +604,13 @@ static void
DrawPickIcon (COUNT iship, BYTE DrawErase)
{
STAMP s;
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
RECT r;
GetFrameRect (BuildPickFrame, &r);
hStarShip = GetStarShipFromIndex (&master_q, iship);
StarShipPtr = LockStarShip (&master_q, hStarShip);
s.origin.x = r.corner.x + 20 + (iship % NUM_PICK_COLS) * 18;
s.origin.y = r.corner.y + 5 + (iship / NUM_PICK_COLS) * 18;
s.frame = StarShipPtr->RaceDescPtr->ship_info.icons;
s.frame = GetShipIconsFromIndex (iship);
if (DrawErase)
{ // draw icon
DrawStamp (&s);
@@ -579,7 +623,6 @@ DrawPickIcon (COUNT iship, BYTE DrawErase)
DrawFilledStamp (&s);
SetContextForeGroundColor (OldColor);
}
UnlockStarShip (&master_q, hStarShip);
}
#ifdef NETPLAY
@@ -899,8 +942,6 @@ static void
DrawMeleeShipStrings (MELEE_STATE *pMS, BYTE NewStarShip)
{
RECT r, OldRect;
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
CONTEXT OldContext;
LockMutex (GraphicsLock);
@@ -950,10 +991,13 @@ DrawMeleeShipStrings (MELEE_STATE *pMS, BYTE NewStarShip)
}
else
{
hStarShip = GetStarShipFromIndex (&master_q, NewStarShip);
StarShipPtr = LockStarShip (&master_q, hStarShip);
HSTARSHIP hStarShip;
SHIP_FRAGMENT *FragPtr;
InitShipStatus (StarShipPtr, NULL);
hStarShip = GetStarShipFromIndex (&master_q, NewStarShip);
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
InitShipStatus (&FragPtr->ShipInfo, ~0, NULL);
UnlockStarShip (&master_q, hStarShip);
}
@@ -981,24 +1025,16 @@ UpdateCurrentShip (MELEE_STATE *pMS)
static COUNT
GetShipValue (BYTE StarShip)
{
HSTARSHIP hStarShip;
COUNT val;
if (StarShip == MELEE_NONE)
return 0;
hStarShip = GetStarShipFromIndex (&master_q, StarShip);
if (hStarShip == 0)
return (COUNT)~0;
val = GetShipCostFromIndex (StarShip);
if (val == 0)
val = (COUNT)~0;
{
STARSHIP *StarShipPtr;
COUNT val;
StarShipPtr = LockStarShip (&master_q, hStarShip);
val = StarShipPtr->RaceDescPtr->ship_info.ship_cost;
UnlockStarShip (&master_q, hStarShip);
return val;
}
}
static COUNT
@@ -1187,15 +1223,9 @@ DrawFileStrings (MELEE_STATE *pMS, int HiLiteState)
StarShip = pMS->FileList[bot - top].ShipList[index];
if (StarShip != MELEE_NONE)
{
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
hStarShip = GetStarShipFromIndex (&master_q, StarShip);
StarShipPtr = LockStarShip (&master_q, hStarShip);
s.frame = StarShipPtr->RaceDescPtr->ship_info.icons;
s.frame = GetShipIconsFromIndex (StarShip);
DrawStamp (&s);
s.origin.x += 17;
UnlockStarShip (&master_q, hStarShip);
}
}
@@ -1444,31 +1474,20 @@ static void
DeleteCurrentShip (MELEE_STATE *pMS)
{
RECT r;
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
FleetShipIndex fleetShipIndex;
int CurIndex;
fleetShipIndex = GetShipIndex (pMS->row, pMS->col);
CurIndex = pMS->SideState[pMS->side].TeamImage.ShipList[fleetShipIndex];
hStarShip = GetStarShipFromIndex (&master_q, CurIndex);
StarShipPtr = LockStarShip (&master_q, hStarShip);
if (StarShipPtr)
{
pMS->SideState[pMS->side].star_bucks -=
StarShipPtr->RaceDescPtr->ship_info.ship_cost;
UnlockStarShip (&master_q, hStarShip);
pMS->SideState[pMS->side].star_bucks -= GetShipCostFromIndex (CurIndex);
pMS->SideState[pMS->side].TeamImage.ShipList[fleetShipIndex] = MELEE_NONE;
pMS->SideState[pMS->side].TeamImage.ShipList[fleetShipIndex] =
MELEE_NONE;
}
LockMutex (GraphicsLock);
GetShipBox (&r, pMS->side, pMS->row, pMS->col);
RepairMeleeFrame (&r);
DrawTeamString (pMS, pMS->side, DTSHS_REPAIR);
UnlockMutex (GraphicsLock);
}
static void
@@ -1672,8 +1691,6 @@ DoEdit (MELEE_STATE *pMS)
static BOOLEAN
DoPickShip (MELEE_STATE *pMS)
{
STARSHIP *StarShipPtr;
if (GLOBAL (CurrentActivity) & CHECK_ABORT)
return (FALSE);
@@ -1718,14 +1735,8 @@ DoPickShip (MELEE_STATE *pMS)
if (!PulsedInputState.menu[KEY_MENU_CANCEL])
{
// Add the currently selected ship to the fleet.
HSTARSHIP hStarShip;
hStarShip = GetStarShipFromIndex (&master_q, pMS->CurIndex);
StarShipPtr = LockStarShip (&master_q, hStarShip);
pMS->SideState[pMS->side].star_bucks +=
StarShipPtr->RaceDescPtr->ship_info.ship_cost;
UnlockStarShip (&master_q, hStarShip);
GetShipCostFromIndex (pMS->CurIndex);
pMS->SideState[pMS->side].TeamImage.ShipList[index] =
pMS->CurIndex;
LockMutex (GraphicsLock);
@@ -2108,23 +2119,24 @@ BuildAndDrawShipList (MELEE_STATE *pMS)
BYTE row, col;
BYTE ship_cost;
HSTARSHIP hStarShip, hBuiltShip;
STARSHIP *StarShipPtr;
SHIP_FRAGMENT *FragPtr;
STARSHIP *BuiltShipPtr;
hStarShip = GetStarShipFromIndex (&master_q, StarShip);
StarShipPtr = LockStarShip (&master_q, hStarShip);
hBuiltShip = Build (&race_q[side], StarShipPtr->RaceResIndex,
1 << side, NameCaptain (&race_q[side], StarShipPtr));
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
hBuiltShip = Build (&race_q[side], FragPtr->RaceResIndex,
1 << side,
NameCaptain (&race_q[side], FragPtr->RaceResIndex));
// Draw the icon.
row = GetShipRow (index);
col = GetShipColumn (index);
s.origin.x = 4 + ((ICON_WIDTH + 2) * col);
s.origin.y = 10 + ((ICON_HEIGHT + 2) * row);
s.frame = StarShipPtr->RaceDescPtr->ship_info.icons;
s.frame = FragPtr->ShipInfo.icons;
DrawStamp (&s);
ship_cost = StarShipPtr->RaceDescPtr->ship_info.ship_cost;
ship_cost = FragPtr->ShipInfo.ship_cost;
UnlockStarShip (&master_q, hStarShip);
BuiltShipPtr = LockStarShip (&race_q[side], hBuiltShip);
+2
View File
@@ -664,6 +664,8 @@ GetMeleeStarShips (COUNT playerMask, HSTARSHIP *ships)
{
STARSHIP *StarShipPtr;
// XXX: STARSHIP refactor; This whole thing is probably not needed
// once captain/side are maintained permanently in STARSHIP
for (playerI = 0; playerI < NUM_PLAYERS; playerI++)
{
if (!gmstate.player[playerI].selecting)
+2 -1
View File
@@ -435,7 +435,8 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
}
}
// XXX: STARSHIP refactor; this whole thing is not really needed anymore
// XXX: STARSHIP refactor; this whole thing is not really needed
// once STARSHIP maintains captain/side permanently
if (hBattleShip)
{
SPtr = LockStarShip (&race_q[which_player], hBattleShip);
+8 -6
View File
@@ -38,6 +38,7 @@ ZapToUrquanEncounter (void)
ENCOUNTER *EncounterPtr;
HSTARSHIP hStarShip;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
BRIEF_SHIP_INFO *BSIPtr;
LockEncounter (hEncounter, &EncounterPtr);
@@ -54,18 +55,19 @@ ZapToUrquanEncounter (void)
EncounterPtr->radius = TemplatePtr->ShipInfo.actual_strength;
EncounterPtr->SD.Type = URQUAN_SHIP;
EncounterPtr->SD.Index = MAKE_BYTE (1, 0) | ONE_SHOT_ENCOUNTER;
EncounterPtr->SD.ShipList[0] = ((SHIP_FRAGMENT*)TemplatePtr)->ShipInfo;
EncounterPtr->SD.ShipList[0].var1 = URQUAN_SHIP;
// XXX: SHIP_INFO struct copy
BSIPtr = &EncounterPtr->ShipList[0];
BSIPtr->race_id = URQUAN_SHIP;
BSIPtr->crew_level = TemplatePtr->ShipInfo.crew_level;
BSIPtr->max_crew = TemplatePtr->ShipInfo.max_crew;
BSIPtr->max_energy = TemplatePtr->ShipInfo.max_energy;
EncounterPtr->SD.star_pt.x = 5288;
EncounterPtr->SD.star_pt.y = 4892;
EncounterPtr->log_x = UNIVERSE_TO_LOGX (EncounterPtr->SD.star_pt.x);
EncounterPtr->log_y = UNIVERSE_TO_LOGY (EncounterPtr->SD.star_pt.y);
GLOBAL_SIS (log_x) = EncounterPtr->log_x;
GLOBAL_SIS (log_y) = EncounterPtr->log_y;
UnlockStarShip (
&GLOBAL (avail_race_q),
hStarShip
);
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
{
#define LOST_DAYS 15
+3 -9
View File
@@ -93,9 +93,7 @@ BuildUrquanGuard (void)
+ COSINE (b1, STATION_RADIUS);
FragPtr->ShipInfo.loc.y = org.y
+ SINE (b1, STATION_RADIUS);
UnlockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip
);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
hStarShip = hNextShip;
}
@@ -118,9 +116,7 @@ BuildUrquanGuard (void)
+ COSINE (b1, STATION_RADIUS);
FragPtr->ShipInfo.loc.y = org.y
+ SINE (b1, STATION_RADIUS);
UnlockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip
);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
hStarShip = hNextShip;
}
}
@@ -173,9 +169,7 @@ GenerateSamatra (BYTE control)
GuardEngaged = TRUE;
}
UnlockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip
);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
}
if (GuardEngaged)
+2
View File
@@ -72,6 +72,8 @@ GenerateShofixti (BYTE control)
{ /* Set old Shofixti name; his brother if Tanaka died */
SHIP_FRAGMENT *FragPtr = (SHIP_FRAGMENT *) LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
// XXX: STARSHIP refactor; setting BAD_GUY here is redundant
// only the captain is needed
OwnStarShip (FragPtr, BAD_GUY, NAME_OFFSET +
NUM_CAPTAINS_NAMES +
(GET_GAME_STATE (SHOFIXTI_KIA) & 1));
+1 -3
View File
@@ -32,9 +32,7 @@ check_scout (void)
HSTARSHIP hStarShip;
if (GLOBAL (BattleGroupRef)
&& (hStarShip = GetHeadLink (
&GLOBAL (npc_built_ship_q)
)))
&& (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q))))
{
BYTE task;
SHIP_FRAGMENT *FragPtr;
+2 -6
View File
@@ -448,9 +448,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
}
}
UnlockStarShip (
&GLOBAL (avail_race_q), hStarShip
);
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
}
@@ -1572,9 +1570,7 @@ DoneSphereGrowth:
}
}
UnlockStarShip (
&GLOBAL (avail_race_q), hStarShip
);
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
}
}
+5 -5
View File
@@ -103,13 +103,13 @@ DeltaSupportCrew (SIZE crew_delta)
UNICODE buf[40];
HSTARSHIP hTemplate;
SHIP_FRAGMENT *StarShipPtr;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame);
hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q),
GET_RACE_ID (StarShipPtr));
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hTemplate);
StarShipPtr->ShipInfo.crew_level += crew_delta;
@@ -117,18 +117,18 @@ DeltaSupportCrew (SIZE crew_delta)
if (StarShipPtr->ShipInfo.crew_level == 0)
StarShipPtr->ShipInfo.crew_level = 1;
else if (StarShipPtr->ShipInfo.crew_level >
TemplatePtr->RaceDescPtr->ship_info.crew_level &&
TemplatePtr->ShipInfo.crew_level &&
crew_delta > 0)
StarShipPtr->ShipInfo.crew_level -= crew_delta;
else
{
if (StarShipPtr->ShipInfo.crew_level >=
TemplatePtr->RaceDescPtr->ship_info.crew_level)
TemplatePtr->ShipInfo.crew_level)
sprintf (buf, "%u", StarShipPtr->ShipInfo.crew_level);
else
sprintf (buf, "%u/%u",
StarShipPtr->ShipInfo.crew_level,
TemplatePtr->RaceDescPtr->ship_info.crew_level);
TemplatePtr->ShipInfo.crew_level);
DrawStatusMessage (buf);
DeltaSISGauges (-crew_delta, 0, 0);
+8 -7
View File
@@ -759,6 +759,7 @@ PickPlanetSide (MENU_STATE *pMS)
if (GET_GAME_STATE (FOUND_PLUTO_SPATHI) == 1)
{
/* Create Fwiffo group and go into comm with it */
HSTARSHIP hStarShip;
if (pMenuState->flash_task)
@@ -780,17 +781,17 @@ PickPlanetSide (MENU_STATE *pMS)
{
BYTE captains_name_index;
COUNT which_player;
STARSHIP *StarShipPtr;
SHIP_FRAGMENT *StarShipPtr;
StarShipPtr = LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip
);
StarShipPtr = (SHIP_FRAGMENT *) LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
// XXX: GOOD_GUY/BAD_GUY was set by CloneShipFragment()
// according to avail_race_q Spathi alliance state
which_player = StarShipPlayer (StarShipPtr);
captains_name_index = NAME_OFFSET + NUM_CAPTAINS_NAMES;
// XXX: STARSHIP refactor; only the captain is needed
OwnStarShip (StarShipPtr, which_player, captains_name_index);
UnlockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip
);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
}
SaveFlagshipState ();
+14 -26
View File
@@ -111,6 +111,8 @@ typedef struct
BYTE ship_mass;
} CHARACTERISTIC_STUFF;
// XXX: This struct is also used to store group info
// Groups should get an own struct
typedef struct
{
UWORD ship_flags;
@@ -118,7 +120,9 @@ typedef struct
BYTE var1;
/* Also: ship_cost, race_id */
BYTE var2;
/* Also: group loc and mission, ship's queue index */
/* Also: group loc and mission, ship's queue index,
* escort window number in built_ship_q,
* fleet strength in loaded ship descriptors */
COUNT crew_level;
/* For ships in npc_built_ship_q, the value INFINITE_FLEET for
* crew_level indicates an infinite number of ships. */
@@ -175,7 +179,6 @@ enum
#define STATION_RADIUS 1600
#define ORBIT_RADIUS 2400
/* XXX: overloads SHIP_INFO */
typedef struct
{
UWORD ship_flags;
@@ -183,8 +186,6 @@ typedef struct
/* Days left before the fleet reachers 'dest_loc'. */
BYTE growth_fract;
COUNT crew_level;
/* For ships in npc_built_ship_q, the value INFINITE_FLEET for
* crew_level indicates an infinite number of ships. */
COUNT max_crew;
BYTE energy_level;
BYTE max_energy;
@@ -260,10 +261,10 @@ struct race_desc
};
typedef QUEUE_HANDLE HSTARSHIP;
typedef HLINK HSTARSHIP;
/* XXX: STARSHIP, SHIP_FRAGMENT and EXTENDED_SHIP_FRAGMENT are inter-cast
* to each other in many places. Some of those are unsafe and potentially
/* XXX: STARSHIP and SHIP_FRAGMENT are inter-cast
* to each other in some places. Some of those are unsafe and potentially
* destructive if the code is changed later.
* Currently, the first 4 members of each struct MUST remain the same,
* the first 2 being the queue links. Functions Build() and CloneShipFragment()
@@ -332,17 +333,16 @@ typedef struct
DWORD RaceResIndex;
/* This field is abused to store other data when the ship
* is in GLOBAL(built_ship_q), GLOBDATA(npc_built_ship_q),
* or race_q[], namely the side this ship is on (accessed
/* This field is used to store other data when the ship
* is in GLOBAL(built_ship_q) or GLOBDATA(npc_built_ship_q),
* namely the side this ship is on (accessed
* through StarShipPlayer()), and the captains name for
* the ship (accessed through StarShipCaptain()).
* These values are set using OwnStarShip(). */
union {
// TODO: make RaceDescPtr inaccessible
RACE_DESC *RaceDescPtr;
SHIP_INFO *ShipInfoPtr;
EXTENDED_SHIP_INFO *ExtShipInfoPtr;
// XXX: only needed temporarily to maintain binary compat
// with STARSHIP for Build()
void *__tmp;
struct {
COUNT Player;
BYTE Captain;
@@ -352,7 +352,6 @@ typedef struct
SHIP_INFO ShipInfo;
} SHIP_FRAGMENT;
/* XXX: overloads SHIP_FRAGMENT */
typedef struct
{
HSTARSHIP pred;
@@ -360,17 +359,6 @@ typedef struct
DWORD RaceResIndex;
/* This field is set to actually point to struct's own EXTENDED_SHIP_INFO
* instead of a RACE_DESC when GLOBAL(avail_race_q) is initialized
* [see InitSIS]. For this reason, RACE_DESC must maintain a SHIP_INFO
* as the first member. */
union {
// TODO: make RaceDescPtr inaccessible
RACE_DESC *RaceDescPtr;
SHIP_INFO *ShipInfoPtr;
EXTENDED_SHIP_INFO *ExtShipInfoPtr;
};
EXTENDED_SHIP_INFO ShipInfo;
} EXTENDED_SHIP_FRAGMENT;
+9 -9
View File
@@ -216,27 +216,27 @@ SaveEncounter (const ENCOUNTER *EncounterPtr, DECODE_REF fh)
cwrite_16 (fh, EncounterPtr->origin.x);
cwrite_16 (fh, EncounterPtr->origin.y);
cwrite_16 (fh, EncounterPtr->radius);
// EXTENDED_STAR_DESC fields
// STAR_DESC fields
cwrite_16 (fh, EncounterPtr->SD.star_pt.x);
cwrite_16 (fh, EncounterPtr->SD.star_pt.y);
cwrite_8 (fh, EncounterPtr->SD.Type);
cwrite_8 (fh, EncounterPtr->SD.Index);
cwrite_16 (fh, 0); /* alignment padding */
// Save each entry in the SHIP_INFO array:
// Save each entry in the BRIEF_SHIP_INFO array
for (i = 0; i < MAX_HYPER_SHIPS; i++)
{
const SHIP_INFO *ShipInfo = &EncounterPtr->SD.ShipList[i];
const BRIEF_SHIP_INFO *ShipInfo = &EncounterPtr->ShipList[i];
cwrite_16 (fh, ShipInfo->ship_flags);
cwrite_8 (fh, ShipInfo->var1);
cwrite_8 (fh, ShipInfo->var2);
cwrite_16 (fh, 0); /* useless; was SHIP_INFO.ship_flags */
cwrite_8 (fh, ShipInfo->race_id);
cwrite_8 (fh, 0); /* useless; was SHIP_INFO.var2 */
cwrite_8 (fh, ShipInfo->crew_level);
cwrite_8 (fh, ShipInfo->max_crew);
cwrite_8 (fh, ShipInfo->energy_level);
cwrite_8 (fh, 0); /* useless; was SHIP_INFO.energy_level */
cwrite_8 (fh, ShipInfo->max_energy);
cwrite_16 (fh, ShipInfo->loc.x);
cwrite_16 (fh, ShipInfo->loc.y);
cwrite_16 (fh, 0); /* useless; was SHIP_INFO.loc.x */
cwrite_16 (fh, 0); /* useless; was SHIP_INFO.loc.y */
cwrite_32 (fh, 0); /* useless val; STRING race_strings */
cwrite_ptr (fh); /* useless ptr; FRAME icons */
cwrite_ptr (fh); /* useless ptr; FRAME melee_icon */
+2 -1
View File
@@ -176,7 +176,8 @@ ship_preprocess (ELEMENT *ElementPtr)
{
CONTEXT OldContext;
InitShipStatus (StarShipPtr, NULL);
InitShipStatus (&RDPtr->ship_info,
StarShipPtr->captains_name_index, NULL);
OldContext = SetContext (StatusContext);
DrawCaptainsWindow (StarShipPtr);
SetContext (OldContext);
+10 -16
View File
@@ -133,15 +133,13 @@ OutlineShipStatus (COORD y)
}
void
InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
InitShipStatus (SHIP_INFO *SIPtr, BYTE captains_name_index, RECT *pClipRect)
{
RECT r;
COORD y, y_stat;
STAMP Stamp;
CONTEXT OldContext;
SHIP_INFO *SIPtr;
SIPtr = &StarShipPtr->RaceDescPtr->ship_info;
y_stat = (SIPtr->ship_flags & GOOD_GUY) ?
GOOD_GUY_YOFFS : BAD_GUY_YOFFS;
@@ -227,8 +225,7 @@ InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
DrawFilledRectangle (&r);
}
if (StarShipPtr->captains_name_index
|| LOBYTE (GLOBAL (CurrentActivity)) == SUPER_MELEE)
if (captains_name_index)
{
STRING locString;
@@ -255,7 +252,7 @@ InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
else
{
locString = SetAbsStringTableIndex (SIPtr->race_strings,
StarShipPtr->captains_name_index);
captains_name_index);
Text.pStr = (UNICODE *)GetStringAddress (locString);
Text.CharCount = GetStringLength (locString);
}
@@ -270,8 +267,8 @@ InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
SetContextFont (OldFont);
}
}
else if (StarShipPtr->captains_name_index == 0)
{
else /* if (captains_name_index == 0) */
{ /* Only SIS or Sa-Matra */
if (SIPtr->ship_flags & GOOD_GUY)
{
DrawCrewFuelString (y, 0);
@@ -285,7 +282,7 @@ InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
crew_delta = SIPtr->crew_level;
energy_delta = SIPtr->energy_level;
SIPtr->crew_level = SIPtr->energy_level = 0;
DeltaStatistics (StarShipPtr, crew_delta, energy_delta);
DeltaStatistics (SIPtr, crew_delta, energy_delta);
}
UnbatchGraphics ();
@@ -303,20 +300,17 @@ InitShipStatus (STARSHIP *StarShipPtr, RECT *pClipRect)
SetContext (OldContext);
}
// Pre: -crew_delta <= StarShipPtr->crew_level
// crew_delta <= StarShipPtr->max_crew - StarShipPtr->crew_level
// Pre: -crew_delta <= ShipInfoPtr->crew_level
// crew_delta <= ShipInfoPtr->max_crew - ShipInfoPtr->crew_level
void
DeltaStatistics (STARSHIP *StarShipPtr, SIZE crew_delta, SIZE energy_delta)
DeltaStatistics (SHIP_INFO *ShipInfoPtr, SIZE crew_delta, SIZE energy_delta)
{
COORD x, y;
RECT r;
SHIP_INFO *ShipInfoPtr;
if (crew_delta == 0 && energy_delta == 0)
return;
ShipInfoPtr = &StarShipPtr->RaceDescPtr->ship_info;
x = 0;
y = GAUGE_YOFFS + ((ShipInfoPtr->ship_flags & GOOD_GUY) ?
GOOD_GUY_YOFFS : BAD_GUY_YOFFS);
@@ -394,7 +388,7 @@ DeltaStatistics (STARSHIP *StarShipPtr, SIZE crew_delta, SIZE energy_delta)
{
// All crew doesn't fit in the graphics; print a number.
// Always print a number for the SIS in the full game.
DrawBattleCrewAmount (StarShipPtr);
DrawBattleCrewAmount (ShipInfoPtr);
}
}
+28 -35
View File
@@ -126,27 +126,15 @@ hangar_anim_func (void *data)
static void
SpinStarShip (HSTARSHIP hStarShip)
{
COUNT Index;
HSTARSHIP hNextShip, hShip;
STARSHIP *StarShipPtr;
StarShipPtr = LockStarShip (&GLOBAL (built_ship_q), hStarShip);
for (Index = 0, hShip = GetHeadLink (&master_q);
hShip; hShip = hNextShip, ++Index)
{
STARSHIP *SSPtr;
SSPtr = LockStarShip (&master_q, hShip);
if (StarShipPtr->RaceResIndex == SSPtr->RaceResIndex)
break;
hNextShip = _GetSuccLink (SSPtr);
UnlockStarShip (&master_q, hShip);
}
int Index;
SHIP_FRAGMENT *StarShipPtr;
StarShipPtr = (SHIP_FRAGMENT *) LockStarShip (&GLOBAL (built_ship_q),
hStarShip);
Index = FindMasterShipIndex (StarShipPtr->RaceResIndex);
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
if (Index < NUM_MELEE_SHIPS)
if (Index >= 0 && Index < NUM_MELEE_SHIPS)
{
UnlockMutex (GraphicsLock);
DoShipSpin (Index, pMenuState->hMusic);
@@ -166,9 +154,9 @@ GetAvailableRaceCount (void)
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
hStarShip; hStarShip = hNextShip)
{
SHIP_FRAGMENT *StarShipPtr;
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
if (StarShipPtr->ShipInfo.ship_flags & GOOD_GUY)
++Index;
@@ -188,10 +176,10 @@ GetAvailableRaceFromIndex (BYTE Index)
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
hStarShip; hStarShip = hNextShip)
{
SHIP_FRAGMENT *StarShipPtr;
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (&GLOBAL (avail_race_q),
hStarShip);
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
if ((StarShipPtr->ShipInfo.ship_flags & GOOD_GUY) && Index-- == 0)
{
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
@@ -237,7 +225,7 @@ DrawRaceStrings (BYTE NewRaceItem)
{
TEXT t;
HSTARSHIP hStarShip;
STARSHIP *StarShipPtr;
EXTENDED_SHIP_FRAGMENT *FragPtr;
UNICODE buf[30];
COUNT ShipCost[] =
{
@@ -250,8 +238,9 @@ DrawRaceStrings (BYTE NewRaceItem)
s.frame = SetAbsFrameIndex (pMenuState->ModuleFrame,
3 + NewRaceItem);
DrawStamp (&s);
StarShipPtr = LockStarShip (&GLOBAL (avail_race_q), hStarShip);
s.frame = StarShipPtr->RaceDescPtr->ship_info.melee_icon;
FragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
&GLOBAL (avail_race_q), hStarShip);
s.frame = FragPtr->ShipInfo.melee_icon;
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
t.baseline.x = s.origin.x + RADAR_WIDTH - 2;
@@ -287,21 +276,21 @@ ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, RECT *pRect)
TEXT t;
UNICODE buf[80];
HSTARSHIP hTemplate;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q),
GET_RACE_ID (StarShipPtr));
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hTemplate);
if (StarShipPtr->ShipInfo.crew_level >=
TemplatePtr->RaceDescPtr->ship_info.crew_level)
TemplatePtr->ShipInfo.crew_level)
sprintf (buf, "%u", StarShipPtr->ShipInfo.crew_level);
else if (StarShipPtr->ShipInfo.crew_level == 0)
utf8StringCopy (buf, sizeof (buf), "SCRAP");
else
sprintf (buf, "%u/%u",
StarShipPtr->ShipInfo.crew_level,
TemplatePtr->RaceDescPtr->ship_info.crew_level);
TemplatePtr->ShipInfo.crew_level);
UnlockStarShip (&GLOBAL (avail_race_q), hTemplate);
r = *pRect;
@@ -396,6 +385,8 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
hStarShip = hTailShip;
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (built_ship_q), hStarShip);
// XXX: hack; escort window is not group loc,
// should just use queue index (already var2)
SET_GROUP_LOC (StarShipPtr, which_window);
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
}
@@ -665,6 +656,8 @@ DoModifyShips (MENU_STATE *pMS)
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (built_ship_q), hStarShip);
// XXX: hack; escort window is not group loc,
// should just use queue index (already var2)
if (GET_GROUP_LOC (StarShipPtr) == pMS->CurState)
{
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
@@ -927,20 +920,20 @@ DoModifyShips (MENU_STATE *pMS)
else
{
HSTARSHIP hTemplate;
SHIP_FRAGMENT *TemplatePtr;
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
hTemplate = GetStarShipFromIndex (
&GLOBAL (avail_race_q),
GET_RACE_ID (StarShipPtr));
TemplatePtr = (SHIP_FRAGMENT*) LockStarShip (
&GLOBAL (avail_race_q), hTemplate);
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*)
LockStarShip (&GLOBAL (avail_race_q),
hTemplate);
if (GLOBAL_SIS (ResUnits) >=
(DWORD)GLOBAL (CrewCost)
&& StarShipPtr->ShipInfo.crew_level <
StarShipPtr->ShipInfo.max_crew &&
StarShipPtr->ShipInfo.crew_level <
TemplatePtr->RaceDescPtr->ship_info.
crew_level)
TemplatePtr->ShipInfo.crew_level)
{
if (StarShipPtr->ShipInfo.crew_level > 0)
DeltaSISGauges (0, 0, -GLOBAL (CrewCost));
+1
View File
@@ -109,6 +109,7 @@ enum
#define FUEL_RESERVE FUEL_VOLUME_PER_ROW
#define MAX_COMBAT_SHIPS 12
// XXX: Only half of this number if actually used
#define MAX_BATTLE_GROUPS 64
#define IP_SHIP_THRUST_INCREMENT 8
+8 -8
View File
@@ -114,7 +114,7 @@ CaptainsWindow (CAPTAIN_STUFF *CSPtr, COORD y, ELEMENT_FLAGS
}
void
DrawBattleCrewAmount (STARSHIP *StarShipPtr)
DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr)
{
#define MAX_CREW_DIGITS 3
RECT r;
@@ -125,7 +125,7 @@ DrawBattleCrewAmount (STARSHIP *StarShipPtr)
if (optWhichMenu == OPT_PC)
t.baseline.x -= 8;
t.baseline.y = BATTLE_CREW_Y +
((StarShipPtr->RaceDescPtr->ship_info.ship_flags & GOOD_GUY) ?
((ShipInfoPtr->ship_flags & GOOD_GUY) ?
GOOD_GUY_YOFFS : BAD_GUY_YOFFS);
t.align = ALIGN_LEFT;
t.pStr = buf;
@@ -136,7 +136,7 @@ DrawBattleCrewAmount (STARSHIP *StarShipPtr)
r.extent.width = 6 * MAX_CREW_DIGITS + 6;
r.extent.height = 5;
sprintf (buf, "%u", StarShipPtr->RaceDescPtr->ship_info.crew_level);
sprintf (buf, "%u", ShipInfoPtr->crew_level);
SetContextFont (StarConFont);
SetContextForeGroundColor (
@@ -272,7 +272,7 @@ DrawCaptainsWindow (STARSHIP *StarShipPtr)
{
// All crew doesn't fit in the graphics; print a number.
// Always print a number for the SIS in the full game.
DrawBattleCrewAmount (StarShipPtr);
DrawBattleCrewAmount (&RDPtr->ship_info);
}
UnbatchGraphics ();
@@ -312,7 +312,7 @@ DeltaEnergy (ELEMENT *ElementPtr, SIZE energy_delta)
StarShipPtr->energy_counter =
StarShipPtr->RaceDescPtr->characteristics.energy_wait;
DeltaStatistics (StarShipPtr, 0, energy_delta);
DeltaStatistics (ShipInfoPtr, 0, energy_delta);
}
return (retval);
@@ -323,6 +323,7 @@ DeltaCrew (ELEMENT *ElementPtr, SIZE crew_delta)
{
BOOLEAN retval;
STARSHIP *StarShipPtr;
SHIP_INFO *ShipInfoPtr;
if (LOBYTE (GLOBAL (CurrentActivity)) == IN_LAST_BATTLE
&& (ElementPtr->state_flags & BAD_GUY))
@@ -330,10 +331,9 @@ DeltaCrew (ELEMENT *ElementPtr, SIZE crew_delta)
retval = TRUE;
GetElementStarShip (ElementPtr, &StarShipPtr);
ShipInfoPtr = &StarShipPtr->RaceDescPtr->ship_info;
if (crew_delta > 0)
{
SHIP_INFO *ShipInfoPtr = &StarShipPtr->RaceDescPtr->ship_info;
ElementPtr->crew_level += crew_delta;
if (ElementPtr->crew_level > ShipInfoPtr->max_crew)
{
@@ -353,7 +353,7 @@ DeltaCrew (ELEMENT *ElementPtr, SIZE crew_delta)
}
}
DeltaStatistics (StarShipPtr, crew_delta, 0);
DeltaStatistics (ShipInfoPtr, crew_delta, 0);
return (retval);
}
+2 -1
View File
@@ -285,7 +285,8 @@ ModifySilhouette (ELEMENT *ElementPtr, STAMP *modify_stamp,
{
or.corner.x += ObjectIntersect.IntersectStamp.origin.x;
or.corner.y += ObjectIntersect.IntersectStamp.origin.y;
InitShipStatus (StarShipPtr, &or);
InitShipStatus (&StarShipPtr->RaceDescPtr->ship_info,
StarShipPtr->captains_name_index, &or);
}
else
{