Cleanup of ENCOUNTER member fields abuse
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3670 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+6
-9
@@ -1536,7 +1536,6 @@ RaceCommunication (void)
|
||||
else
|
||||
{
|
||||
/* Encounter with a black globe in HS, prepare enemy ship list */
|
||||
COUNT NumShips;
|
||||
ENCOUNTER *EncounterPtr;
|
||||
|
||||
// The encounter globe that the flagship collided with is moved
|
||||
@@ -1544,10 +1543,9 @@ RaceCommunication (void)
|
||||
hEncounter = GetHeadEncounter ();
|
||||
LockEncounter (hEncounter, &EncounterPtr);
|
||||
|
||||
NumShips = LONIBBLE (EncounterPtr->SD.Index);
|
||||
for (i = 0; i < NumShips; ++i)
|
||||
for (i = 0; i < EncounterPtr->num_ships; ++i)
|
||||
{
|
||||
CloneShipFragment (EncounterPtr->SD.Type,
|
||||
CloneShipFragment (EncounterPtr->race_id,
|
||||
&GLOBAL (npc_built_ship_q),
|
||||
EncounterPtr->ShipList[i].crew_level);
|
||||
}
|
||||
@@ -1588,12 +1586,11 @@ RaceCommunication (void)
|
||||
|
||||
LockEncounter (hEncounter, &EncounterPtr);
|
||||
|
||||
NumShips = (BYTE)CountLinks (&GLOBAL (npc_built_ship_q));
|
||||
EncounterPtr->SD.Index = MAKE_BYTE (NumShips,
|
||||
HINIBBLE (EncounterPtr->SD.Index));
|
||||
EncounterPtr->SD.Index |= ENCOUNTER_REFORMING;
|
||||
NumShips = CountLinks (&GLOBAL (npc_built_ship_q));
|
||||
EncounterPtr->num_ships = NumShips;
|
||||
EncounterPtr->flags |= ENCOUNTER_REFORMING;
|
||||
if (status == 0)
|
||||
EncounterPtr->SD.Index |= ONE_SHOT_ENCOUNTER;
|
||||
EncounterPtr->flags |= ONE_SHOT_ENCOUNTER;
|
||||
|
||||
for (i = 0; i < NumShips; ++i)
|
||||
{
|
||||
|
||||
+14
-1
@@ -38,8 +38,16 @@ extern "C" {
|
||||
typedef HLINK HENCOUNTER;
|
||||
|
||||
#define MAX_HYPER_SHIPS 7
|
||||
|
||||
// ENCOUNTER.flags
|
||||
// XXX: Currently, the flags are combined with num_ships into a single BYTE
|
||||
// in the savegames: num_ships occupy the low nibble and flags the high one.
|
||||
// Bits 4 and 5 are available for more flags in the savegames,
|
||||
// and bits 0-3 available in the game but will not be saved.
|
||||
#define ONE_SHOT_ENCOUNTER (1 << 7)
|
||||
#define ENCOUNTER_REFORMING (1 << 6)
|
||||
#define ENCOUNTER_SHIPS_MASK 0x0f
|
||||
#define ENCOUNTER_FLAGS_MASK 0xf0
|
||||
|
||||
struct brief_ship_info
|
||||
{
|
||||
@@ -61,9 +69,14 @@ struct encounter
|
||||
SIZE transition_state;
|
||||
POINT origin;
|
||||
COUNT radius;
|
||||
BYTE race_id;
|
||||
BYTE num_ships;
|
||||
BYTE flags;
|
||||
// See ENCOUNTER.flags above
|
||||
POINT loc_pt;
|
||||
|
||||
STAR_DESC SD;
|
||||
BRIEF_SHIP_INFO ShipList[MAX_HYPER_SHIPS];
|
||||
// Only the crew_level member is currently used
|
||||
|
||||
SDWORD log_x, log_y;
|
||||
};
|
||||
|
||||
+23
-24
@@ -225,13 +225,13 @@ check_hyperspace_encounter (void)
|
||||
encounter_flags = ONE_SHOT_ENCOUNTER;
|
||||
}
|
||||
|
||||
|
||||
// There can be only one! (of either Slylandro or Melnorme)
|
||||
for (hEncounter = GetHeadEncounter ();
|
||||
hEncounter; hEncounter = hNextEncounter)
|
||||
{
|
||||
LockEncounter (hEncounter, &EncounterPtr);
|
||||
hNextEncounter = GetSuccEncounter (EncounterPtr);
|
||||
if (EncounterPtr->SD.Type == Type)
|
||||
if (EncounterPtr->race_id == Type)
|
||||
{
|
||||
percent = 0;
|
||||
hNextEncounter = 0;
|
||||
@@ -266,8 +266,8 @@ check_hyperspace_encounter (void)
|
||||
memset (EncounterPtr, 0, sizeof (*EncounterPtr));
|
||||
EncounterPtr->origin = FleetPtr->loc;
|
||||
EncounterPtr->radius = encounter_radius;
|
||||
EncounterPtr->SD.Index = encounter_flags;
|
||||
EncounterPtr->SD.Type = Type;
|
||||
EncounterPtr->flags = encounter_flags;
|
||||
EncounterPtr->race_id = Type;
|
||||
UnlockEncounter (hEncounter);
|
||||
|
||||
PutEncounter (hEncounter);
|
||||
@@ -956,20 +956,20 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
|
||||
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) >= 2)
|
||||
return 0;
|
||||
|
||||
if (EncounterPtr->SD.Index & ENCOUNTER_REFORMING)
|
||||
if (EncounterPtr->flags & ENCOUNTER_REFORMING)
|
||||
{
|
||||
EncounterPtr->SD.Index &= ~ENCOUNTER_REFORMING;
|
||||
EncounterPtr->flags &= ~ENCOUNTER_REFORMING;
|
||||
|
||||
EncounterPtr->transition_state = 100;
|
||||
if ((EncounterPtr->SD.Index & ONE_SHOT_ENCOUNTER)
|
||||
|| LONIBBLE (EncounterPtr->SD.Index) == 0)
|
||||
if ((EncounterPtr->flags & ONE_SHOT_ENCOUNTER)
|
||||
|| EncounterPtr->num_ships == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (LONIBBLE (EncounterPtr->SD.Index))
|
||||
if (EncounterPtr->num_ships)
|
||||
{
|
||||
NewEncounter = FALSE;
|
||||
enc_pt = EncounterPtr->SD.star_pt;
|
||||
enc_pt = EncounterPtr->loc_pt;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -987,7 +987,7 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
|
||||
|
||||
radius_squared = (DWORD)EncounterPtr->radius * EncounterPtr->radius;
|
||||
|
||||
Type = EncounterPtr->SD.Type;
|
||||
Type = EncounterPtr->race_id;
|
||||
NumShips = LONIBBLE (EncounterMakeup[Type]);
|
||||
for (i = HINIBBLE (EncounterMakeup[Type]) - NumShips; i; --i)
|
||||
{
|
||||
@@ -998,9 +998,7 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
|
||||
if (NumShips > MAX_HYPER_SHIPS)
|
||||
NumShips = MAX_HYPER_SHIPS;
|
||||
|
||||
|
||||
EncounterPtr->SD.Index =
|
||||
MAKE_BYTE (NumShips, HINIBBLE (EncounterPtr->SD.Index));
|
||||
EncounterPtr->num_ships = NumShips;
|
||||
for (i = 0; i < NumShips; ++i)
|
||||
{
|
||||
BRIEF_SHIP_INFO *BSIPtr = &EncounterPtr->ShipList[i];
|
||||
@@ -1038,7 +1036,7 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
|
||||
dy = enc_pt.y - EncounterPtr->origin.y;
|
||||
} while ((DWORD)((long)dx * dx + (long)dy * dy) > radius_squared);
|
||||
|
||||
EncounterPtr->SD.star_pt = enc_pt;
|
||||
EncounterPtr->loc_pt = enc_pt;
|
||||
EncounterPtr->log_x = UNIVERSE_TO_LOGX (enc_pt.x);
|
||||
EncounterPtr->log_y = UNIVERSE_TO_LOGY (enc_pt.y);
|
||||
}
|
||||
@@ -1197,8 +1195,8 @@ ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse,
|
||||
cur_facing = ANGLE_TO_FACING (
|
||||
GetVelocityTravelAngle (&ElementPtr->velocity));
|
||||
delta_facing = NORMALIZE_FACING (cur_facing - ANGLE_TO_FACING (
|
||||
ARCTAN (puniverse->x - EncounterPtr->SD.star_pt.x,
|
||||
puniverse->y - EncounterPtr->SD.star_pt.y)));
|
||||
ARCTAN (puniverse->x - EncounterPtr->loc_pt.x,
|
||||
puniverse->y - EncounterPtr->loc_pt.y)));
|
||||
if (delta_facing || (delta_x == 0 && delta_y == 0))
|
||||
{
|
||||
SIZE speed;
|
||||
@@ -1208,7 +1206,7 @@ ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse,
|
||||
};
|
||||
|
||||
#define ENCOUNTER_TRACK_WAIT 3
|
||||
speed = RaceHyperSpeed[EncounterPtr->SD.Type];
|
||||
speed = RaceHyperSpeed[EncounterPtr->race_id];
|
||||
if (delta_facing < ANGLE_TO_FACING (HALF_CIRCLE))
|
||||
--cur_facing;
|
||||
else
|
||||
@@ -1233,14 +1231,14 @@ ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse,
|
||||
}
|
||||
EncounterPtr->log_x += delta_x;
|
||||
EncounterPtr->log_y -= delta_y;
|
||||
EncounterPtr->SD.star_pt.x = LOGX_TO_UNIVERSE (EncounterPtr->log_x);
|
||||
EncounterPtr->SD.star_pt.y = LOGY_TO_UNIVERSE (EncounterPtr->log_y);
|
||||
EncounterPtr->loc_pt.x = LOGX_TO_UNIVERSE (EncounterPtr->log_x);
|
||||
EncounterPtr->loc_pt.y = LOGY_TO_UNIVERSE (EncounterPtr->log_y);
|
||||
|
||||
encounter_radius = EncounterPtr->radius + (GRID_OFFSET >> 1);
|
||||
delta_x = EncounterPtr->SD.star_pt.x - EncounterPtr->origin.x;
|
||||
delta_x = EncounterPtr->loc_pt.x - EncounterPtr->origin.x;
|
||||
if (delta_x < 0)
|
||||
delta_x = -delta_x;
|
||||
delta_y = EncounterPtr->SD.star_pt.y - EncounterPtr->origin.y;
|
||||
delta_y = EncounterPtr->loc_pt.y - EncounterPtr->origin.y;
|
||||
if (delta_y < 0)
|
||||
delta_y = -delta_y;
|
||||
if ((COUNT)delta_x >= encounter_radius
|
||||
@@ -1248,6 +1246,7 @@ ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse,
|
||||
|| (DWORD)delta_x * delta_x + (DWORD)delta_y * delta_y >=
|
||||
(DWORD)encounter_radius * encounter_radius)
|
||||
{
|
||||
// Encounter globe traveled outside the SoI and now disappears
|
||||
ElementPtr->state_flags |= NONSOLID;
|
||||
ElementPtr->life_span = 0;
|
||||
|
||||
@@ -1266,8 +1265,8 @@ ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse,
|
||||
}
|
||||
}
|
||||
|
||||
ex = EncounterPtr->SD.star_pt.x;
|
||||
ey = EncounterPtr->SD.star_pt.y;
|
||||
ex = EncounterPtr->loc_pt.x;
|
||||
ey = EncounterPtr->loc_pt.y;
|
||||
if (ex - puniverse->x >= -UNIT_SCREEN_WIDTH
|
||||
&& ex - puniverse->x <= UNIT_SCREEN_WIDTH
|
||||
&& ey - puniverse->y >= -UNIT_SCREEN_HEIGHT
|
||||
|
||||
+8
-6
@@ -325,6 +325,7 @@ static void
|
||||
LoadEncounter (ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
{
|
||||
COUNT i;
|
||||
BYTE tmpb;
|
||||
|
||||
cread_ptr (fh); /* useless ptr; HENCOUNTER pred */
|
||||
EncounterPtr->pred = 0;
|
||||
@@ -336,18 +337,19 @@ LoadEncounter (ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
cread_16s (fh, &EncounterPtr->origin.x);
|
||||
cread_16s (fh, &EncounterPtr->origin.y);
|
||||
cread_16 (fh, &EncounterPtr->radius);
|
||||
// STAR_DESC fields
|
||||
cread_16s (fh, &EncounterPtr->SD.star_pt.x);
|
||||
cread_16s (fh, &EncounterPtr->SD.star_pt.y);
|
||||
cread_8 (fh, &EncounterPtr->SD.Type);
|
||||
cread_8 (fh, &EncounterPtr->SD.Index);
|
||||
// former STAR_DESC fields
|
||||
cread_16s (fh, &EncounterPtr->loc_pt.x);
|
||||
cread_16s (fh, &EncounterPtr->loc_pt.y);
|
||||
cread_8 (fh, &EncounterPtr->race_id);
|
||||
cread_8 (fh, &tmpb);
|
||||
EncounterPtr->num_ships = tmpb & ENCOUNTER_SHIPS_MASK;
|
||||
EncounterPtr->flags = tmpb & ENCOUNTER_FLAGS_MASK;
|
||||
cread_16 (fh, NULL); /* alignment padding */
|
||||
|
||||
// Load each entry in the BRIEF_SHIP_INFO array
|
||||
for (i = 0; i < MAX_HYPER_SHIPS; i++)
|
||||
{
|
||||
BRIEF_SHIP_INFO *ShipInfo = &EncounterPtr->ShipList[i];
|
||||
BYTE tmpb;
|
||||
|
||||
cread_16 (fh, NULL); /* useless; was SHIP_INFO.ship_flags */
|
||||
cread_8 (fh, &ShipInfo->race_id);
|
||||
|
||||
@@ -211,17 +211,18 @@ ZapToUrquanEncounter (void)
|
||||
TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
EncounterPtr->origin = TemplatePtr->loc;
|
||||
EncounterPtr->radius = TemplatePtr->actual_strength;
|
||||
EncounterPtr->SD.Type = URQUAN_SHIP;
|
||||
EncounterPtr->SD.Index = MAKE_BYTE (1, 0) | ONE_SHOT_ENCOUNTER;
|
||||
EncounterPtr->race_id = URQUAN_SHIP;
|
||||
EncounterPtr->num_ships = 1;
|
||||
EncounterPtr->flags = ONE_SHOT_ENCOUNTER;
|
||||
BSIPtr = &EncounterPtr->ShipList[0];
|
||||
BSIPtr->race_id = URQUAN_SHIP;
|
||||
BSIPtr->crew_level = TemplatePtr->crew_level;
|
||||
BSIPtr->max_crew = TemplatePtr->max_crew;
|
||||
BSIPtr->max_energy = TemplatePtr->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);
|
||||
EncounterPtr->loc_pt.x = 5288;
|
||||
EncounterPtr->loc_pt.y = 4892;
|
||||
EncounterPtr->log_x = UNIVERSE_TO_LOGX (EncounterPtr->loc_pt.x);
|
||||
EncounterPtr->log_y = UNIVERSE_TO_LOGY (EncounterPtr->loc_pt.y);
|
||||
GLOBAL_SIS (log_x) = EncounterPtr->log_x;
|
||||
GLOBAL_SIS (log_y) = EncounterPtr->log_y;
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
@@ -236,8 +237,8 @@ ZapToUrquanEncounter (void)
|
||||
|
||||
GLOBAL (CurrentActivity) = MAKE_WORD (IN_HYPERSPACE, 0) | START_ENCOUNTER;
|
||||
|
||||
dx = CurStarDescPtr->star_pt.x - EncounterPtr->SD.star_pt.x;
|
||||
dy = CurStarDescPtr->star_pt.y - EncounterPtr->SD.star_pt.y;
|
||||
dx = CurStarDescPtr->star_pt.x - EncounterPtr->loc_pt.x;
|
||||
dy = CurStarDescPtr->star_pt.y - EncounterPtr->loc_pt.y;
|
||||
dx = (SIZE)square_root ((long)dx * dx + (long)dy * dy)
|
||||
+ (FUEL_TANK_SCALE >> 1);
|
||||
|
||||
@@ -250,7 +251,7 @@ ZapToUrquanEncounter (void)
|
||||
DeltaSISGauges (0, dx, 0);
|
||||
}
|
||||
DrawSISMessage (NULL);
|
||||
DrawHyperCoords (EncounterPtr->SD.star_pt);
|
||||
DrawHyperCoords (EncounterPtr->loc_pt);
|
||||
UnlockMutex (GraphicsLock);
|
||||
|
||||
UnlockEncounter (hEncounter);
|
||||
|
||||
+7
-5
@@ -276,11 +276,13 @@ SaveEncounter (const ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
cwrite_16 (fh, EncounterPtr->origin.x);
|
||||
cwrite_16 (fh, EncounterPtr->origin.y);
|
||||
cwrite_16 (fh, EncounterPtr->radius);
|
||||
// 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);
|
||||
// former STAR_DESC fields
|
||||
cwrite_16 (fh, EncounterPtr->loc_pt.x);
|
||||
cwrite_16 (fh, EncounterPtr->loc_pt.y);
|
||||
cwrite_8 (fh, EncounterPtr->race_id);
|
||||
// XXX: writing combined fields to maintain savegame compatibility
|
||||
cwrite_8 (fh, (EncounterPtr->num_ships & ENCOUNTER_SHIPS_MASK)
|
||||
| (EncounterPtr->flags & ENCOUNTER_FLAGS_MASK));
|
||||
cwrite_16 (fh, 0); /* alignment padding */
|
||||
|
||||
// Save each entry in the BRIEF_SHIP_INFO array
|
||||
|
||||
Reference in New Issue
Block a user