Use a common SHIP_BASE for partially aliased ship structs
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2799 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+21
-43
@@ -25,32 +25,23 @@
|
||||
#include "libs/mathlib.h"
|
||||
|
||||
|
||||
// Allocate a new STARSHIP and put it in the queue.
|
||||
// Allocate a new STARSHIP or SHIP_FRAGMENT and put it in the queue
|
||||
HLINK
|
||||
Build (QUEUE *pQueue, DWORD RaceResIndex)
|
||||
{
|
||||
HLINK hNewShip;
|
||||
void *LinkPtr;
|
||||
SHIP_BASE *ShipPtr;
|
||||
|
||||
assert (GetLinkSize (pQueue) == sizeof (STARSHIP) ||
|
||||
GetLinkSize (pQueue) == sizeof (SHIP_FRAGMENT));
|
||||
|
||||
hNewShip = AllocLink (pQueue);
|
||||
if (!hNewShip)
|
||||
return 0;
|
||||
|
||||
LinkPtr = LockLink (pQueue, hNewShip);
|
||||
memset (LinkPtr, 0, GetLinkSize (pQueue));
|
||||
|
||||
if (GetLinkSize (pQueue) == sizeof (STARSHIP))
|
||||
{
|
||||
STARSHIP *StarShipPtr = (STARSHIP *) LinkPtr;
|
||||
StarShipPtr->RaceResIndex = RaceResIndex;
|
||||
}
|
||||
else if (GetLinkSize (pQueue) == sizeof (SHIP_FRAGMENT))
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr = (SHIP_FRAGMENT *) LinkPtr;
|
||||
FragPtr->RaceResIndex = RaceResIndex;
|
||||
}
|
||||
else
|
||||
assert (0 && "Build(): unknown queue type!");
|
||||
ShipPtr = (SHIP_BASE *) LockLink (pQueue, hNewShip);
|
||||
memset (ShipPtr, 0, GetLinkSize (pQueue));
|
||||
ShipPtr->RaceResIndex = RaceResIndex;
|
||||
|
||||
UnlockLink (pQueue, hNewShip);
|
||||
PutQueue (pQueue, hNewShip);
|
||||
@@ -334,43 +325,30 @@ NameCaptain (QUEUE *pQueue, DWORD RaceResIndex)
|
||||
BYTE name_index;
|
||||
HLINK hStarShip;
|
||||
|
||||
assert (GetLinkSize (pQueue) == sizeof (STARSHIP) ||
|
||||
GetLinkSize (pQueue) == sizeof (SHIP_FRAGMENT));
|
||||
|
||||
do
|
||||
{
|
||||
HLINK hNextShip;
|
||||
|
||||
name_index = PickCaptainName ();
|
||||
for (hStarShip = GetHeadLink (pQueue); hStarShip; hStarShip = hNextShip)
|
||||
for (hStarShip = GetHeadLink (pQueue); hStarShip;
|
||||
hStarShip = hNextShip)
|
||||
{
|
||||
LINK *LinkPtr;
|
||||
BYTE test_name_index;
|
||||
SHIP_BASE *ShipPtr;
|
||||
BYTE test_name_index = -1;
|
||||
|
||||
LinkPtr = LockLink (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (LinkPtr);
|
||||
if (GetLinkSize (pQueue) == sizeof (STARSHIP))
|
||||
{
|
||||
STARSHIP *TestShipPtr = (STARSHIP *) LinkPtr;
|
||||
if (TestShipPtr->RaceResIndex != RaceResIndex)
|
||||
continue;
|
||||
test_name_index = TestShipPtr->captains_name_index;
|
||||
}
|
||||
else if (GetLinkSize (pQueue) == sizeof (SHIP_FRAGMENT))
|
||||
{
|
||||
SHIP_FRAGMENT *TestShipPtr = (SHIP_FRAGMENT *) LinkPtr;
|
||||
if (TestShipPtr->RaceResIndex != RaceResIndex)
|
||||
continue;
|
||||
test_name_index = TestShipPtr->captains_name_index;
|
||||
}
|
||||
else
|
||||
assert (0 && "NameCaptain(): unknown queue type!");
|
||||
ShipPtr = (SHIP_BASE *) LockLink (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (ShipPtr);
|
||||
if (ShipPtr->RaceResIndex == RaceResIndex)
|
||||
test_name_index = ShipPtr->captains_name_index;
|
||||
UnlockLink (pQueue, hStarShip);
|
||||
|
||||
if (name_index == test_name_index)
|
||||
{
|
||||
UnlockLink (pQueue, hStarShip);
|
||||
break;
|
||||
}
|
||||
UnlockLink (pQueue, hStarShip);
|
||||
}
|
||||
} while (hStarShip);
|
||||
} while (hStarShip /* name matched another ship */);
|
||||
|
||||
return name_index;
|
||||
}
|
||||
|
||||
+17
-14
@@ -172,24 +172,32 @@ struct race_desc
|
||||
void *CodeRef _ALIGNED_ON(sizeof (void *));
|
||||
};
|
||||
|
||||
#define SHIP_BASE_COMMON \
|
||||
/* LINK elements; must be first */ \
|
||||
HLINK pred; \
|
||||
HLINK succ; \
|
||||
\
|
||||
DWORD RaceResIndex; \
|
||||
BYTE captains_name_index \
|
||||
/* Also used in full-game to detect if a STARSHIP is an escort
|
||||
* or the flagship (captains_name_index == 0) */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SHIP_BASE_COMMON;
|
||||
} SHIP_BASE;
|
||||
|
||||
typedef HLINK HSTARSHIP;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HSTARSHIP pred;
|
||||
HSTARSHIP succ;
|
||||
|
||||
DWORD RaceResIndex;
|
||||
SHIP_BASE_COMMON;
|
||||
|
||||
RACE_DESC *RaceDescPtr;
|
||||
|
||||
// Ship information
|
||||
UWORD which_side;
|
||||
// In race_q: side the ship is on
|
||||
BYTE captains_name_index;
|
||||
// Also used in full-game to detect if a STARSHIP is an escort
|
||||
// or the flagship (captains_name_index == 0)
|
||||
COUNT crew_level;
|
||||
// In full-game battles: crew left
|
||||
// In SuperMelee: irrelevant
|
||||
@@ -233,14 +241,9 @@ typedef HLINK HSHIPFRAG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HSHIPFRAG pred;
|
||||
HSHIPFRAG succ;
|
||||
|
||||
DWORD RaceResIndex;
|
||||
SHIP_BASE_COMMON;
|
||||
|
||||
COUNT which_side;
|
||||
BYTE captains_name_index;
|
||||
|
||||
BYTE race_id;
|
||||
BYTE index;
|
||||
|
||||
Reference in New Issue
Block a user