Untangling ship queues, stage 4: Full API separation for SHIP_INFO, MASTER_SHIP_INFO, STARSHIP, SHIP_FRAGMENT and FLEET_INFO structs; added QUEUE bug-checks
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2786 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
The various ship queues used in the game:
|
||||
|
||||
GlobData.Game_state.avail_race_q:
|
||||
Contains all the ships from the enum from races.h that defines
|
||||
NUM_AVAILABLE_RACES.
|
||||
Elements are of type EXTENDED_SHIP_FRAGMENT (to become FLEET_INFO).
|
||||
It contains information about the various races, not really about
|
||||
specific ships.
|
||||
Contains fleet information, ship template and other info about the
|
||||
alien races present in the game. All races are present that are
|
||||
defined by the enum in races.h that defines NUM_AVAILABLE_RACES,
|
||||
except for, technically, SAMATRA_SHIP. URQUAN_PROBE_SHIP is a
|
||||
very incomplete 'race'.
|
||||
Elements are of type FLEET_INFO.
|
||||
Filled in InitSIS().
|
||||
Partially included in savegames.
|
||||
|
||||
GlobData.Game_state.built_ship_q:
|
||||
The fleet accompanying the flagship.
|
||||
The fleet accompanying the flagship (escorts).
|
||||
Elements are of type SHIP_FRAGMENT.
|
||||
which_side is always GOOD_GUY here.
|
||||
Partially included in savegames.
|
||||
|
||||
master_q:
|
||||
Queue of all the ships that exist in the game.
|
||||
Elements are of type SHIP_FRAGMENT (to become MASTER_SHIP_INFO).
|
||||
List of templates for all the ships that are available in SuperMelee.
|
||||
Elements are of type MASTER_SHIP_INFO.
|
||||
Sorted on the (abbreviated) race name (see doc/racestrings).
|
||||
Filled in LoadMasterShipList().
|
||||
|
||||
|
||||
+89
-95
@@ -19,23 +19,24 @@
|
||||
#include "build.h"
|
||||
|
||||
#include "races.h"
|
||||
#include "master.h"
|
||||
#include "setup.h"
|
||||
#include "libs/compiler.h"
|
||||
#include "libs/mathlib.h"
|
||||
|
||||
|
||||
// Allocate a new STARSHIP and put it in the queue.
|
||||
HSTARSHIP
|
||||
HLINK
|
||||
Build (QUEUE *pQueue, DWORD RaceResIndex)
|
||||
{
|
||||
HSTARSHIP hNewShip;
|
||||
HLINK hNewShip;
|
||||
void *LinkPtr;
|
||||
|
||||
hNewShip = AllocStarShip (pQueue);
|
||||
hNewShip = AllocLink (pQueue);
|
||||
if (!hNewShip)
|
||||
return 0;
|
||||
|
||||
LinkPtr = LockStarShip (pQueue, hNewShip);
|
||||
LinkPtr = LockLink (pQueue, hNewShip);
|
||||
memset (LinkPtr, 0, GetLinkSize (pQueue));
|
||||
|
||||
if (GetLinkSize (pQueue) == sizeof (STARSHIP))
|
||||
@@ -48,15 +49,10 @@ Build (QUEUE *pQueue, DWORD RaceResIndex)
|
||||
SHIP_FRAGMENT *FragPtr = (SHIP_FRAGMENT *) LinkPtr;
|
||||
FragPtr->RaceResIndex = RaceResIndex;
|
||||
}
|
||||
else if (GetLinkSize (pQueue) == sizeof (EXTENDED_SHIP_FRAGMENT))
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *FragPtr = (EXTENDED_SHIP_FRAGMENT *) LinkPtr;
|
||||
FragPtr->RaceResIndex = RaceResIndex;
|
||||
}
|
||||
else
|
||||
assert (0 && "Build(): unknown queue type!");
|
||||
|
||||
UnlockStarShip (pQueue, hNewShip);
|
||||
UnlockLink (pQueue, hNewShip);
|
||||
PutQueue (pQueue, hNewShip);
|
||||
|
||||
return hNewShip;
|
||||
@@ -118,10 +114,10 @@ GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index)
|
||||
COUNT
|
||||
ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hFleet;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship);
|
||||
if (!hStarShip)
|
||||
hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship);
|
||||
if (!hFleet)
|
||||
return 0;
|
||||
|
||||
switch (state)
|
||||
@@ -129,24 +125,23 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
case SPHERE_TRACKING:
|
||||
case SPHERE_KNOWN:
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
if (state == SPHERE_KNOWN)
|
||||
which_ship = StarShipPtr->ShipInfo.known_strength;
|
||||
else if (StarShipPtr->ShipInfo.actual_strength == 0)
|
||||
which_ship = FleetPtr->known_strength;
|
||||
else if (FleetPtr->actual_strength == 0)
|
||||
{
|
||||
if (!(StarShipPtr->ShipInfo.ship_flags & (GOOD_GUY | BAD_GUY)))
|
||||
if (!(FleetPtr->ship_flags & (GOOD_GUY | BAD_GUY)))
|
||||
which_ship = 0;
|
||||
}
|
||||
else if (StarShipPtr->ShipInfo.known_strength == 0
|
||||
&& StarShipPtr->ShipInfo.actual_strength != (COUNT)~0)
|
||||
else if (FleetPtr->known_strength == 0
|
||||
&& FleetPtr->actual_strength != (COUNT)~0)
|
||||
{
|
||||
StarShipPtr->ShipInfo.known_strength = 1;
|
||||
StarShipPtr->ShipInfo.known_loc = StarShipPtr->ShipInfo.loc;
|
||||
FleetPtr->known_strength = 1;
|
||||
FleetPtr->known_loc = FleetPtr->loc;
|
||||
}
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
return (which_ship);
|
||||
}
|
||||
case ESCORT_WORTH:
|
||||
@@ -156,33 +151,34 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
RACE_SHIP_COST
|
||||
};
|
||||
COUNT total = 0;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
total += ShipCost[GET_RACE_ID (StarShipPtr)];
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
case ESCORTING_FLAGSHIP:
|
||||
{
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
BYTE ship_type;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
ship_type = GET_RACE_ID (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
if (ship_type == which_ship)
|
||||
return 1;
|
||||
@@ -196,35 +192,36 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
case CHECK_ALLIANCE:
|
||||
{
|
||||
COUNT flags;
|
||||
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);
|
||||
FLEET_INFO *FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q),
|
||||
hFleet);
|
||||
flags = FleetPtr->ship_flags & (GOOD_GUY | BAD_GUY);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
return flags;
|
||||
}
|
||||
case SET_ALLIED:
|
||||
case SET_NOT_ALLIED:
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr = (EXTENDED_SHIP_FRAGMENT*)
|
||||
LockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
FLEET_INFO *FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q),
|
||||
hFleet);
|
||||
|
||||
if (!(StarShipPtr->ShipInfo.ship_flags & (GOOD_GUY | BAD_GUY)))
|
||||
if (!(FleetPtr->ship_flags & (GOOD_GUY | BAD_GUY)))
|
||||
{ /* Strange request, silently ignore it */
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
break;
|
||||
}
|
||||
|
||||
StarShipPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
FleetPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
if (state == SET_ALLIED)
|
||||
StarShipPtr->ShipInfo.ship_flags |= GOOD_GUY;
|
||||
FleetPtr->ship_flags |= GOOD_GUY;
|
||||
else
|
||||
StarShipPtr->ShipInfo.ship_flags |= BAD_GUY;
|
||||
FleetPtr->ship_flags |= BAD_GUY;
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
break;
|
||||
}
|
||||
case REMOVE_BUILT:
|
||||
{
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
BOOLEAN ShipRemoved = FALSE;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||
@@ -233,18 +230,17 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
BOOLEAN RemoveShip;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
RemoveShip = (GET_RACE_ID (StarShipPtr) == which_ship);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
if (RemoveShip)
|
||||
{
|
||||
ShipRemoved = TRUE;
|
||||
|
||||
RemoveQueue (&GLOBAL (built_ship_q), hStarShip);
|
||||
FreeStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
FreeShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +263,8 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
which_window = 0;
|
||||
for (i = 0; i < (COUNT)state; i++)
|
||||
{
|
||||
HSTARSHIP hOldShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
HSHIPFRAG hOldShip;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
hStarShip = CloneShipFragment (which_ship,
|
||||
@@ -283,18 +280,17 @@ ActivateStarShip (COUNT which_ship, SIZE state)
|
||||
{
|
||||
BYTE win_loc;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hOldShip);
|
||||
win_loc = StarShipPtr->ShipInfo.var2;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hOldShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
hOldShip);
|
||||
win_loc = StarShipPtr->var2;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hOldShip);
|
||||
if (which_window <= win_loc)
|
||||
break;
|
||||
}
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr->ShipInfo.var2 = which_window - 1;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr->var2 = which_window - 1;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
InsertQueue (&GLOBAL (built_ship_q), hStarShip, hOldShip);
|
||||
}
|
||||
@@ -381,19 +377,21 @@ NameCaptain (QUEUE *pQueue, DWORD RaceResIndex)
|
||||
|
||||
// crew_level can be set to INFINITE_FLEET for a ship which is to
|
||||
// represent an infinite number of ships.
|
||||
HSTARSHIP
|
||||
HSHIPFRAG
|
||||
CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level)
|
||||
{
|
||||
HSTARSHIP hStarShip, hBuiltShip;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hFleet;
|
||||
HSHIPFRAG hBuiltShip;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
BYTE captains_name_index;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), shipIndex);
|
||||
if (hStarShip == 0)
|
||||
assert (GetLinkSize (pDstQueue) == sizeof (SHIP_FRAGMENT));
|
||||
|
||||
hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), shipIndex);
|
||||
if (!hFleet)
|
||||
return 0;
|
||||
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
if (shipIndex == SAMATRA_SHIP)
|
||||
captains_name_index = 0;
|
||||
else
|
||||
@@ -404,30 +402,30 @@ CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level)
|
||||
{
|
||||
SHIP_FRAGMENT *ShipFragPtr;
|
||||
|
||||
ShipFragPtr = (SHIP_FRAGMENT*) LockStarShip (pDstQueue, hBuiltShip);
|
||||
ShipFragPtr->which_side = TemplatePtr->ShipInfo.ship_flags &
|
||||
ShipFragPtr = LockShipFrag (pDstQueue, hBuiltShip);
|
||||
ShipFragPtr->which_side = TemplatePtr->ship_flags &
|
||||
(GOOD_GUY | BAD_GUY);
|
||||
ShipFragPtr->captains_name_index = captains_name_index;
|
||||
// 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;
|
||||
ShipFragPtr->race_strings = TemplatePtr->race_strings;
|
||||
ShipFragPtr->icons = TemplatePtr->icons;
|
||||
ShipFragPtr->melee_icon = TemplatePtr->melee_icon;
|
||||
if (crew_level)
|
||||
ShipFragPtr->ShipInfo.crew_level = crew_level;
|
||||
ShipFragPtr->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;
|
||||
ShipFragPtr->ShipInfo.loc.x = 0;
|
||||
ShipFragPtr->ShipInfo.loc.y = 0;
|
||||
ShipFragPtr->crew_level = TemplatePtr->crew_level;
|
||||
ShipFragPtr->max_crew = TemplatePtr->max_crew;
|
||||
ShipFragPtr->energy_level = 0;
|
||||
ShipFragPtr->max_energy = TemplatePtr->max_energy;
|
||||
ShipFragPtr->ship_flags = 0;
|
||||
ShipFragPtr->var1 = 0;
|
||||
ShipFragPtr->var2 = 0;
|
||||
ShipFragPtr->loc.x = 0;
|
||||
ShipFragPtr->loc.y = 0;
|
||||
SET_RACE_ID (ShipFragPtr, (BYTE)shipIndex);
|
||||
UnlockStarShip (pDstQueue, hBuiltShip);
|
||||
UnlockShipFrag (pDstQueue, hBuiltShip);
|
||||
}
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
|
||||
return hBuiltShip;
|
||||
}
|
||||
@@ -437,41 +435,37 @@ CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue, COUNT crew_level)
|
||||
int
|
||||
SetEscortCrewComplement (COUNT which_ship, COUNT crew_level, BYTE captain)
|
||||
{
|
||||
HSTARSHIP hTemplateShip;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HSTARSHIP hStarShip;
|
||||
HSTARSHIP hNextShip;
|
||||
HFLEETINFO hFleet;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
SHIP_FRAGMENT *StarShipPtr = 0;
|
||||
int Index;
|
||||
|
||||
hTemplateShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship);
|
||||
if (!hTemplateShip)
|
||||
hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_ship);
|
||||
if (!hFleet)
|
||||
return -1;
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hTemplateShip);
|
||||
TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
|
||||
/* Find first ship of which_ship race */
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)), Index = 0;
|
||||
hStarShip; hStarShip = hNextShip, ++Index)
|
||||
{
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
if (which_ship == GET_RACE_ID (StarShipPtr) &&
|
||||
StarShipPtr->ShipInfo.crew_level ==
|
||||
TemplatePtr->ShipInfo.crew_level)
|
||||
StarShipPtr->crew_level == TemplatePtr->crew_level)
|
||||
break; /* found one */
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
if (hStarShip)
|
||||
{
|
||||
StarShipPtr->ShipInfo.crew_level = crew_level;
|
||||
StarShipPtr->crew_level = crew_level;
|
||||
StarShipPtr->captains_name_index = captain;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
else
|
||||
Index = -1;
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hTemplateShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
return Index;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
& (NUM_CAPTAINS_NAMES - 1)) \
|
||||
+ NAME_OFFSET)
|
||||
|
||||
extern HSTARSHIP Build (QUEUE *pQueue, DWORD RaceResIndex);
|
||||
extern HSTARSHIP CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue,
|
||||
extern HLINK Build (QUEUE *pQueue, DWORD RaceResIndex);
|
||||
extern HSHIPFRAG CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue,
|
||||
COUNT crew_level);
|
||||
extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index);
|
||||
extern BYTE NameCaptain (QUEUE *pQueue, DWORD RaceResIndex);
|
||||
|
||||
@@ -46,6 +46,7 @@ typedef HLINK HEVENT;
|
||||
|
||||
typedef struct event
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HEVENT pred, succ;
|
||||
|
||||
BYTE day_index, month_index;
|
||||
|
||||
+12
-13
@@ -1593,7 +1593,7 @@ void
|
||||
RaceCommunication (void)
|
||||
{
|
||||
COUNT i, status;
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HENCOUNTER hEncounter = 0;
|
||||
RESOURCE RaceComm[] =
|
||||
@@ -1674,11 +1674,12 @@ RaceCommunication (void)
|
||||
}
|
||||
}
|
||||
|
||||
// First ship in the npc queue defines which alien race
|
||||
// the player will be talking to
|
||||
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
i = GET_RACE_ID (FragPtr);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
|
||||
status = InitCommunication (RaceComm[i]);
|
||||
|
||||
@@ -1711,21 +1712,19 @@ RaceCommunication (void)
|
||||
|
||||
for (i = 0; i < NumShips; ++i)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG 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);
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (npc_built_ship_q), i);
|
||||
TemplatePtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
// 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);
|
||||
BSIPtr->crew_level = TemplatePtr->crew_level;
|
||||
BSIPtr->max_crew = TemplatePtr->max_crew;
|
||||
BSIPtr->max_energy = TemplatePtr->max_energy;
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
UnlockEncounter (hEncounter);
|
||||
|
||||
+42
-18
@@ -19,7 +19,9 @@
|
||||
#ifndef _DISPLIST_H
|
||||
#define _DISPLIST_H
|
||||
|
||||
#include "memlib.h"
|
||||
#include <assert.h>
|
||||
#include "libs/memlib.h"
|
||||
#include "port.h"
|
||||
|
||||
#define QUEUE_TABLE
|
||||
|
||||
@@ -34,13 +36,50 @@ typedef QUEUE_HANDLE HLINK;
|
||||
|
||||
typedef struct link
|
||||
{
|
||||
// Every queue element of any queue must have these
|
||||
// two as the first members
|
||||
HLINK pred;
|
||||
HLINK succ;
|
||||
} LINK;
|
||||
|
||||
typedef struct queue
|
||||
{
|
||||
HLINK head;
|
||||
HLINK tail;
|
||||
#ifdef QUEUE_TABLE
|
||||
#define LockLink(pq, h) (LINK*)(h)
|
||||
#define UnlockLink(pq, h)
|
||||
BYTE *pq_tab;
|
||||
HLINK free_list;
|
||||
MEM_HANDLE hq_tab;
|
||||
#endif
|
||||
COUNT object_size;
|
||||
#ifdef QUEUE_TABLE
|
||||
BYTE num_objects;
|
||||
#endif /* QUEUE_TABLE */
|
||||
} QUEUE;
|
||||
|
||||
#ifdef QUEUE_TABLE
|
||||
|
||||
static inline LINK *
|
||||
LockLink (const QUEUE *pq, HLINK h)
|
||||
{
|
||||
if (h) // Apparently, h==0 is OK
|
||||
{ // Make sure the link is actually in our queue!
|
||||
assert (pq->pq_tab && (BYTE*)h >= pq->pq_tab &&
|
||||
(BYTE*)h < pq->pq_tab + pq->object_size * pq->num_objects);
|
||||
}
|
||||
return (LINK*)h;
|
||||
}
|
||||
|
||||
static inline void
|
||||
UnlockLink (const QUEUE *pq, HLINK h)
|
||||
{
|
||||
if (h) // Apparently, h==0 is OK
|
||||
{ // Make sure the link is actually in our queue!
|
||||
assert (pq->pq_tab && (BYTE*)h >= pq->pq_tab &&
|
||||
(BYTE*)h < pq->pq_tab + pq->object_size * pq->num_objects);
|
||||
}
|
||||
}
|
||||
|
||||
#define GetFreeList(pq) (pq)->free_list
|
||||
#define SetFreeList(pq, h) (pq)->free_list = (h)
|
||||
#define AllocQueueTab(pq,n) \
|
||||
@@ -59,21 +98,6 @@ typedef struct link
|
||||
#define FreeLink(pq,h) mem_release (h)
|
||||
#endif /* QUEUE_TABLE */
|
||||
|
||||
typedef struct queue
|
||||
{
|
||||
HLINK head;
|
||||
HLINK tail;
|
||||
#ifdef QUEUE_TABLE
|
||||
BYTE *pq_tab;
|
||||
HLINK free_list;
|
||||
MEM_HANDLE hq_tab;
|
||||
#endif
|
||||
COUNT object_size;
|
||||
#ifdef QUEUE_TABLE
|
||||
BYTE num_objects;
|
||||
#endif /* QUEUE_TABLE */
|
||||
} QUEUE;
|
||||
|
||||
#define SetLinkSize(pq,s) ((pq)->object_size = (COUNT)(s))
|
||||
#define GetLinkSize(pq) (COUNT)((pq)->object_size)
|
||||
#define GetHeadLink(pq) ((pq)->head)
|
||||
|
||||
@@ -108,6 +108,7 @@ typedef void (CollisionFunc) (ELEMENT *ElementPtr0, POINT *pPt0,
|
||||
// Any physical object in the simulation.
|
||||
struct element
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HELEMENT pred, succ;
|
||||
|
||||
void (*preprocess_func) (struct element *ElementPtr);
|
||||
|
||||
+29
-32
@@ -87,7 +87,7 @@ void
|
||||
BuildBattle (COUNT which_player)
|
||||
{
|
||||
QUEUE *pQueue;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
HSTARSHIP hBuiltShip;
|
||||
STARSHIP *BuiltShipPtr;
|
||||
|
||||
@@ -126,7 +126,7 @@ BuildBattle (COUNT which_player)
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
|
||||
FragPtr = LockShipFrag (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
|
||||
hBuiltShip = Build (&race_q[which_player],
|
||||
@@ -137,22 +137,22 @@ BuildBattle (COUNT which_player)
|
||||
BuiltShipPtr = LockStarShip (&race_q[which_player], hBuiltShip);
|
||||
BuiltShipPtr->captains_name_index = FragPtr->captains_name_index;
|
||||
BuiltShipPtr->which_side = 1 << which_player;
|
||||
if (FragPtr->ShipInfo.crew_level != INFINITE_FLEET)
|
||||
BuiltShipPtr->crew_level = FragPtr->ShipInfo.crew_level;
|
||||
if (FragPtr->crew_level != INFINITE_FLEET)
|
||||
BuiltShipPtr->crew_level = FragPtr->crew_level;
|
||||
else /* if infinite ships */
|
||||
BuiltShipPtr->crew_level = FragPtr->ShipInfo.max_crew;
|
||||
BuiltShipPtr->max_crew = FragPtr->ShipInfo.max_crew;
|
||||
BuiltShipPtr->race_strings = FragPtr->ShipInfo.race_strings;
|
||||
BuiltShipPtr->icons = FragPtr->ShipInfo.icons;
|
||||
BuiltShipPtr->index = FragPtr->ShipInfo.var2;
|
||||
BuiltShipPtr->crew_level = FragPtr->max_crew;
|
||||
BuiltShipPtr->max_crew = FragPtr->max_crew;
|
||||
BuiltShipPtr->race_strings = FragPtr->race_strings;
|
||||
BuiltShipPtr->icons = FragPtr->icons;
|
||||
BuiltShipPtr->index = FragPtr->var2;
|
||||
/* This is not technically necessary, but still */
|
||||
BuiltShipPtr->ship_cost = FragPtr->ShipInfo.ship_cost;
|
||||
//BuiltShipPtr->ship_cost = FragPtr->ship_cost;
|
||||
BuiltShipPtr->RaceDescPtr = 0;
|
||||
|
||||
UnlockStarShip (&race_q[which_player], hBuiltShip);
|
||||
}
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
}
|
||||
|
||||
if (which_player == 0
|
||||
@@ -262,7 +262,7 @@ InitEncounter (void)
|
||||
if (LOBYTE (GLOBAL (CurrentActivity)) != IN_LAST_BATTLE)
|
||||
{
|
||||
#define NUM_DISPLAY_PTS (sizeof (display_pt) / sizeof (display_pt[0]))
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
POINT display_pt[] =
|
||||
{
|
||||
{ 10, 51},
|
||||
@@ -283,9 +283,8 @@ InitEncounter (void)
|
||||
RECT r;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
if (FragPtr->ShipInfo.crew_level != INFINITE_FLEET)
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
if (FragPtr->crew_level != INFINITE_FLEET)
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
else /* if infinite ships */
|
||||
hNextShip = hStarShip;
|
||||
@@ -303,13 +302,13 @@ InitEncounter (void)
|
||||
s.origin.x = COSINE (angle, radius);
|
||||
s.origin.y = SINE (angle, radius);
|
||||
}
|
||||
s.frame = SetAbsFrameIndex (FragPtr->ShipInfo.icons, 0);
|
||||
s.frame = SetAbsFrameIndex (FragPtr->icons, 0);
|
||||
GetFrameRect (s.frame, &r);
|
||||
s.origin.x += (SIS_SCREEN_WIDTH >> 1) - (r.extent.width >> 1);
|
||||
s.origin.y += (SIS_SCREEN_HEIGHT >> 1) - (r.extent.height >> 1);
|
||||
DrawStamp (&s);
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +443,7 @@ UninitEncounter (void)
|
||||
const UNICODE *str1 = NULL;
|
||||
const UNICODE *str2 = NULL;
|
||||
UNICODE buf[80];
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
static const COLOR fade_ship_cycle[] =
|
||||
{
|
||||
@@ -476,21 +475,21 @@ UninitEncounter (void)
|
||||
) ? 0 : 1;
|
||||
|
||||
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
EncounterRace = GET_RACE_ID (FragPtr);
|
||||
if (GetStarShipFromIndex (&GLOBAL (avail_race_q), EncounterRace) == 0)
|
||||
{
|
||||
/* Suppress the final tally and salvage info */
|
||||
VictoryState = -1;
|
||||
InitSISContexts ();
|
||||
}
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
|
||||
Sleepy = TRUE;
|
||||
for (i = 0; i < NUM_SIDES; ++i)
|
||||
{
|
||||
QUEUE *pQueue;
|
||||
HSTARSHIP hNextShip;
|
||||
HSHIPFRAG hNextShip;
|
||||
|
||||
if (i == 0)
|
||||
pQueue = &GLOBAL (built_ship_q);
|
||||
@@ -521,10 +520,10 @@ UninitEncounter (void)
|
||||
for (hStarShip = GetHeadLink (pQueue); hStarShip;
|
||||
hStarShip = hNextShip)
|
||||
{
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
|
||||
FragPtr = LockShipFrag (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
|
||||
if (FragPtr->ShipInfo.crew_level == 0
|
||||
if (FragPtr->crew_level == 0
|
||||
|| (VictoryState && i == NUM_SIDES - 1))
|
||||
{
|
||||
if (i == NUM_SIDES - 1)
|
||||
@@ -543,15 +542,13 @@ UninitEncounter (void)
|
||||
|
||||
ship_s.origin.x = scavenge_r.corner.x + 32;
|
||||
ship_s.origin.y = scavenge_r.corner.y + 56;
|
||||
ship_s.frame = IncFrameIndex (
|
||||
FragPtr->ShipInfo.icons);
|
||||
ship_s.frame = IncFrameIndex (FragPtr->icons);
|
||||
DrawStamp (&ship_s);
|
||||
SetContextForeGroundColor (
|
||||
BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F));
|
||||
SetContextFont (TinyFont);
|
||||
|
||||
GetStringContents (
|
||||
FragPtr->ShipInfo.race_strings,
|
||||
GetStringContents (FragPtr->race_strings,
|
||||
(STRINGPTR)buf, FALSE);
|
||||
// XXX: this will not work with UTF-8 strings
|
||||
strupr (buf);
|
||||
@@ -568,7 +565,7 @@ UninitEncounter (void)
|
||||
t.CharCount = (COUNT)~0;
|
||||
font_DrawText (&t);
|
||||
|
||||
ship_s.frame = FragPtr->ShipInfo.icons;
|
||||
ship_s.frame = FragPtr->icons;
|
||||
|
||||
SetContextFont (MicroFont);
|
||||
str1 = GAME_STRING (
|
||||
@@ -639,14 +636,14 @@ UninitEncounter (void)
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
RemoveQueue (pQueue, hStarShip);
|
||||
FreeStarShip (pQueue, hStarShip);
|
||||
FreeShipFrag (pQueue, hStarShip);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HENCOUNTER pred, succ;
|
||||
|
||||
HELEMENT hElement;
|
||||
|
||||
+161
-190
@@ -105,16 +105,15 @@ EventHandler (BYTE selector)
|
||||
AddEvent (RELATIVE_EVENT, 0, 7, 0, ZOQFOT_DEATH_EVENT);
|
||||
else if (GET_GAME_STATE (ZOQFOT_DISTRESS))
|
||||
{
|
||||
HSTARSHIP hZoqFot;
|
||||
EXTENDED_SHIP_FRAGMENT *ZoqFotPtr;
|
||||
HFLEETINFO hZoqFot;
|
||||
FLEET_INFO *ZoqFotPtr;
|
||||
|
||||
hZoqFot = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
ZOQFOTPIK_SHIP);
|
||||
ZoqFotPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hZoqFot);
|
||||
ZoqFotPtr->ShipInfo.actual_strength = 0;
|
||||
ZoqFotPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
UnlockStarShip ( &GLOBAL (avail_race_q), hZoqFot);
|
||||
ZoqFotPtr = LockFleetInfo (&GLOBAL (avail_race_q), hZoqFot);
|
||||
ZoqFotPtr->actual_strength = 0;
|
||||
ZoqFotPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hZoqFot);
|
||||
|
||||
SET_GAME_STATE (ZOQFOT_DISTRESS, 2);
|
||||
}
|
||||
@@ -136,22 +135,21 @@ EventHandler (BYTE selector)
|
||||
AddEvent (RELATIVE_EVENT, 0, 7, 0, SPATHI_SHIELD_EVENT);
|
||||
else
|
||||
{
|
||||
HSTARSHIP hSpathi;
|
||||
EXTENDED_SHIP_FRAGMENT *SpathiPtr;
|
||||
HFLEETINFO hSpathi;
|
||||
FLEET_INFO *SpathiPtr;
|
||||
|
||||
hSpathi = GetStarShipFromIndex (
|
||||
&GLOBAL (avail_race_q), SPATHI_SHIP);
|
||||
SpathiPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hSpathi);
|
||||
hSpathi = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
SPATHI_SHIP);
|
||||
SpathiPtr = LockFleetInfo (&GLOBAL (avail_race_q), hSpathi);
|
||||
|
||||
if (SpathiPtr->ShipInfo.actual_strength)
|
||||
if (SpathiPtr->actual_strength)
|
||||
{
|
||||
ActivateStarShip (SPATHI_SHIP, SET_NOT_ALLIED);
|
||||
SET_GAME_STATE (SPATHI_SHIELDED_SELVES, 1);
|
||||
SpathiPtr->ShipInfo.actual_strength = 0;
|
||||
SpathiPtr->actual_strength = 0;
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hSpathi);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hSpathi);
|
||||
}
|
||||
break;
|
||||
case ADVANCE_ILWRATH_MISSION:
|
||||
@@ -165,25 +163,23 @@ EventHandler (BYTE selector)
|
||||
break;
|
||||
case YEHAT_REBEL_EVENT:
|
||||
{
|
||||
HSTARSHIP hRebel, hRoyalist;
|
||||
EXTENDED_SHIP_FRAGMENT *RebelPtr;
|
||||
EXTENDED_SHIP_FRAGMENT *RoyalistPtr;
|
||||
HFLEETINFO hRebel, hRoyalist;
|
||||
FLEET_INFO *RebelPtr;
|
||||
FLEET_INFO *RoyalistPtr;
|
||||
|
||||
hRebel = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
YEHAT_REBEL_SHIP);
|
||||
RebelPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hRebel);
|
||||
RebelPtr = LockFleetInfo (&GLOBAL (avail_race_q), hRebel);
|
||||
hRoyalist = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
YEHAT_SHIP);
|
||||
RoyalistPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hRoyalist);
|
||||
RebelPtr->ShipInfo.actual_strength =
|
||||
RoyalistPtr->ShipInfo.actual_strength =
|
||||
RoyalistPtr->ShipInfo.actual_strength * 2 / 3;
|
||||
RebelPtr->ShipInfo.loc.x = 5150;
|
||||
RebelPtr->ShipInfo.loc.y = 0;
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hRoyalist);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hRebel);
|
||||
RoyalistPtr = LockFleetInfo (&GLOBAL (avail_race_q), hRoyalist);
|
||||
RoyalistPtr->actual_strength = RoyalistPtr->actual_strength *
|
||||
2 / 3;
|
||||
RebelPtr->actual_strength = RoyalistPtr->actual_strength;
|
||||
RebelPtr->loc.x = 5150;
|
||||
RebelPtr->loc.y = 0;
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hRoyalist);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hRebel);
|
||||
ActivateStarShip (YEHAT_REBEL_SHIP, SPHERE_TRACKING);
|
||||
break;
|
||||
}
|
||||
@@ -217,19 +213,18 @@ void
|
||||
SetRaceDest (BYTE which_race, COORD x, COORD y, BYTE days_left, BYTE
|
||||
func_index)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hFleet;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_race);
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), which_race);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
|
||||
TemplatePtr->ShipInfo.dest_loc.x = x;
|
||||
TemplatePtr->ShipInfo.dest_loc.y = y;
|
||||
TemplatePtr->ShipInfo.days_left = days_left;
|
||||
TemplatePtr->ShipInfo.func_index = func_index;
|
||||
FleetPtr->dest_loc.x = x;
|
||||
FleetPtr->dest_loc.y = y;
|
||||
FleetPtr->days_left = days_left;
|
||||
FleetPtr->func_index = func_index;
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
}
|
||||
|
||||
|
||||
@@ -259,63 +254,55 @@ arilou_exit_event (void)
|
||||
static void
|
||||
check_race_growth (void)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (TemplatePtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if (TemplatePtr->ShipInfo.actual_strength
|
||||
&& TemplatePtr->ShipInfo.actual_strength != (COUNT)~0)
|
||||
if (FleetPtr->actual_strength
|
||||
&& FleetPtr->actual_strength != (COUNT)~0)
|
||||
{
|
||||
SIZE delta_strength;
|
||||
|
||||
delta_strength = (SBYTE)TemplatePtr->ShipInfo.energy_level;
|
||||
if (TemplatePtr->ShipInfo.growth_err_term <=
|
||||
TemplatePtr->ShipInfo.growth_fract)
|
||||
delta_strength = (SBYTE)FleetPtr->energy_level;
|
||||
if (FleetPtr->growth_err_term <= FleetPtr->growth_fract)
|
||||
{
|
||||
if (delta_strength <= 0)
|
||||
--delta_strength;
|
||||
else
|
||||
++delta_strength;
|
||||
}
|
||||
TemplatePtr->ShipInfo.growth_err_term -=
|
||||
TemplatePtr->ShipInfo.growth_fract;
|
||||
FleetPtr->growth_err_term -= FleetPtr->growth_fract;
|
||||
|
||||
delta_strength += TemplatePtr->ShipInfo.actual_strength;
|
||||
delta_strength += FleetPtr->actual_strength;
|
||||
if (delta_strength <= 0)
|
||||
{
|
||||
delta_strength = 0;
|
||||
TemplatePtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
FleetPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
}
|
||||
else if (delta_strength > MAX_FLEET_STRENGTH)
|
||||
delta_strength = MAX_FLEET_STRENGTH;
|
||||
|
||||
TemplatePtr->ShipInfo.actual_strength = (COUNT)delta_strength;
|
||||
if (TemplatePtr->ShipInfo.actual_strength &&
|
||||
TemplatePtr->ShipInfo.days_left)
|
||||
FleetPtr->actual_strength = (COUNT)delta_strength;
|
||||
if (FleetPtr->actual_strength && FleetPtr->days_left)
|
||||
{
|
||||
TemplatePtr->ShipInfo.loc.x +=
|
||||
(TemplatePtr->ShipInfo.dest_loc.x
|
||||
- TemplatePtr->ShipInfo.loc.x)
|
||||
/ TemplatePtr->ShipInfo.days_left;
|
||||
TemplatePtr->ShipInfo.loc.y +=
|
||||
(TemplatePtr->ShipInfo.dest_loc.y
|
||||
- TemplatePtr->ShipInfo.loc.y)
|
||||
/ TemplatePtr->ShipInfo.days_left;
|
||||
FleetPtr->loc.x += (FleetPtr->dest_loc.x - FleetPtr->loc.x)
|
||||
/ FleetPtr->days_left;
|
||||
FleetPtr->loc.y += (FleetPtr->dest_loc.y - FleetPtr->loc.y)
|
||||
/ FleetPtr->days_left;
|
||||
|
||||
if (--TemplatePtr->ShipInfo.days_left == 0
|
||||
&& TemplatePtr->ShipInfo.func_index != (BYTE) ~0)
|
||||
EventHandler (TemplatePtr->ShipInfo.func_index);
|
||||
if (--FleetPtr->days_left == 0
|
||||
&& FleetPtr->func_index != (BYTE) ~0)
|
||||
EventHandler (FleetPtr->func_index);
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,42 +312,40 @@ black_urquan_genocide (void)
|
||||
BYTE Index;
|
||||
long best_dist;
|
||||
SIZE best_dx, best_dy;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSTARSHIP hBlackUrquan;
|
||||
EXTENDED_SHIP_FRAGMENT *BlackUrquanPtr;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
HFLEETINFO hBlackUrquan;
|
||||
FLEET_INFO *BlackUrquanPtr;
|
||||
|
||||
hBlackUrquan = GetStarShipFromIndex (
|
||||
&GLOBAL (avail_race_q), BLACK_URQUAN_SHIP);
|
||||
BlackUrquanPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hBlackUrquan);
|
||||
hBlackUrquan = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
BLACK_URQUAN_SHIP);
|
||||
BlackUrquanPtr = LockFleetInfo (&GLOBAL (avail_race_q), hBlackUrquan);
|
||||
|
||||
best_dist = -1;
|
||||
best_dx = SOL_X - BlackUrquanPtr->ShipInfo.loc.x;
|
||||
best_dy = SOL_Y - BlackUrquanPtr->ShipInfo.loc.y;
|
||||
best_dx = SOL_X - BlackUrquanPtr->loc.x;
|
||||
best_dy = SOL_Y - BlackUrquanPtr->loc.y;
|
||||
for (Index = 0, hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip; ++Index, hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (TemplatePtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if (Index != BLACK_URQUAN_SHIP
|
||||
&& Index != URQUAN_SHIP
|
||||
&& TemplatePtr->ShipInfo.actual_strength != (COUNT)~0)
|
||||
&& FleetPtr->actual_strength != (COUNT)~0)
|
||||
{
|
||||
SIZE dx, dy;
|
||||
|
||||
dx = TemplatePtr->ShipInfo.loc.x - BlackUrquanPtr->ShipInfo.loc.x;
|
||||
dy = TemplatePtr->ShipInfo.loc.y - BlackUrquanPtr->ShipInfo.loc.y;
|
||||
dx = FleetPtr->loc.x - BlackUrquanPtr->loc.x;
|
||||
dy = FleetPtr->loc.y - BlackUrquanPtr->loc.y;
|
||||
if (dx == 0 && dy == 0)
|
||||
{
|
||||
// Arrived at the victim's home world. Cleanse it.
|
||||
TemplatePtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
TemplatePtr->ShipInfo.actual_strength = 0;
|
||||
FleetPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
FleetPtr->actual_strength = 0;
|
||||
}
|
||||
else if (TemplatePtr->ShipInfo.actual_strength)
|
||||
else if (FleetPtr->actual_strength)
|
||||
{
|
||||
long dist;
|
||||
|
||||
@@ -377,7 +362,7 @@ black_urquan_genocide (void)
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
if (best_dist < 0 && best_dx == 0 && best_dy == 0)
|
||||
@@ -409,51 +394,50 @@ black_urquan_genocide (void)
|
||||
SET_GAME_STATE (KOHR_AH_INFO, 0);
|
||||
SET_GAME_STATE (URQUAN_VISITS, 0);
|
||||
SetRaceDest (BLACK_URQUAN_SHIP,
|
||||
BlackUrquanPtr->ShipInfo.loc.x + best_dx,
|
||||
BlackUrquanPtr->ShipInfo.loc.y + best_dy,
|
||||
BlackUrquanPtr->loc.x + best_dx,
|
||||
BlackUrquanPtr->loc.y + best_dy,
|
||||
(BYTE)speed, KOHR_AH_GENOCIDE_EVENT);
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hBlackUrquan);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hBlackUrquan);
|
||||
}
|
||||
|
||||
static void
|
||||
pkunk_mission (void)
|
||||
{
|
||||
HSTARSHIP hPkunk;
|
||||
EXTENDED_SHIP_FRAGMENT *PkunkPtr;
|
||||
HFLEETINFO hPkunk;
|
||||
FLEET_INFO *PkunkPtr;
|
||||
|
||||
hPkunk = GetStarShipFromIndex (&GLOBAL (avail_race_q), PKUNK_SHIP);
|
||||
PkunkPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hPkunk);
|
||||
PkunkPtr = LockFleetInfo (&GLOBAL (avail_race_q), hPkunk);
|
||||
|
||||
if (PkunkPtr->ShipInfo.actual_strength)
|
||||
if (PkunkPtr->actual_strength)
|
||||
{
|
||||
BYTE MissionState;
|
||||
|
||||
MissionState = GET_GAME_STATE (PKUNK_MISSION);
|
||||
if (PkunkPtr->ShipInfo.days_left == 0 && MissionState)
|
||||
if (PkunkPtr->days_left == 0 && MissionState)
|
||||
{
|
||||
if ((MissionState & 1)
|
||||
/* made it to Yehat space */
|
||||
|| (PkunkPtr->ShipInfo.loc.x == 4970
|
||||
&& PkunkPtr->ShipInfo.loc.y == 400))
|
||||
PkunkPtr->ShipInfo.actual_strength = 0;
|
||||
else if (PkunkPtr->ShipInfo.loc.x == 502
|
||||
&& PkunkPtr->ShipInfo.loc.y == 401
|
||||
|| (PkunkPtr->loc.x == 4970
|
||||
&& PkunkPtr->loc.y == 400))
|
||||
PkunkPtr->actual_strength = 0;
|
||||
else if (PkunkPtr->loc.x == 502
|
||||
&& PkunkPtr->loc.y == 401
|
||||
&& GET_GAME_STATE (PKUNK_ON_THE_MOVE))
|
||||
{
|
||||
SET_GAME_STATE (PKUNK_ON_THE_MOVE, 0);
|
||||
AddEvent (RELATIVE_EVENT, 3, 0, 0, ADVANCE_PKUNK_MISSION);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hPkunk);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hPkunk);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PkunkPtr->ShipInfo.actual_strength == 0)
|
||||
if (PkunkPtr->actual_strength == 0)
|
||||
{
|
||||
SET_GAME_STATE (YEHAT_ABSORBED_PKUNK, 1);
|
||||
PkunkPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
PkunkPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
ActivateStarShip (YEHAT_SHIP, SPHERE_TRACKING);
|
||||
}
|
||||
else
|
||||
@@ -473,28 +457,27 @@ pkunk_mission (void)
|
||||
SET_GAME_STATE (PKUNK_ON_THE_MOVE, 1);
|
||||
SET_GAME_STATE (PKUNK_SWITCH, 0);
|
||||
SetRaceDest (PKUNK_SHIP, x, y,
|
||||
(BYTE)((365 >> 1) - PkunkPtr->ShipInfo.days_left),
|
||||
(BYTE)((365 >> 1) - PkunkPtr->days_left),
|
||||
ADVANCE_PKUNK_MISSION);
|
||||
}
|
||||
SET_GAME_STATE (PKUNK_MISSION, MissionState + 1);
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hPkunk);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hPkunk);
|
||||
}
|
||||
|
||||
static void
|
||||
thradd_mission (void)
|
||||
{
|
||||
BYTE MissionState;
|
||||
HSTARSHIP hThradd;
|
||||
EXTENDED_SHIP_FRAGMENT *ThraddPtr;
|
||||
HFLEETINFO hThradd;
|
||||
FLEET_INFO *ThraddPtr;
|
||||
|
||||
hThradd = GetStarShipFromIndex (&GLOBAL (avail_race_q), THRADDASH_SHIP);
|
||||
ThraddPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hThradd);
|
||||
ThraddPtr = LockFleetInfo (&GLOBAL (avail_race_q), hThradd);
|
||||
|
||||
MissionState = GET_GAME_STATE (THRADD_MISSION);
|
||||
if (ThraddPtr->ShipInfo.actual_strength && MissionState < 3)
|
||||
if (ThraddPtr->actual_strength && MissionState < 3)
|
||||
{
|
||||
COORD x, y;
|
||||
|
||||
@@ -513,19 +496,17 @@ thradd_mission (void)
|
||||
{ /* arrived at Kohr-Ah, engaging */
|
||||
SIZE strength_loss;
|
||||
|
||||
strength_loss = (SIZE)(ThraddPtr->ShipInfo.actual_strength >> 1);
|
||||
ThraddPtr->ShipInfo.energy_level =
|
||||
(BYTE)(-strength_loss / 14);
|
||||
ThraddPtr->ShipInfo.growth_fract =
|
||||
(BYTE)(((strength_loss % 14) << 8) / 14);
|
||||
ThraddPtr->ShipInfo.growth_err_term = 255 >> 1;
|
||||
strength_loss = (SIZE)(ThraddPtr->actual_strength >> 1);
|
||||
ThraddPtr->energy_level = (BYTE)(-strength_loss / 14);
|
||||
ThraddPtr->growth_fract = (BYTE)(((strength_loss % 14) << 8) / 14);
|
||||
ThraddPtr->growth_err_term = 255 >> 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MissionState != 0)
|
||||
{ /* stop losses */
|
||||
ThraddPtr->ShipInfo.energy_level = 0;
|
||||
ThraddPtr->ShipInfo.growth_fract = 0;
|
||||
ThraddPtr->energy_level = 0;
|
||||
ThraddPtr->growth_fract = 0;
|
||||
}
|
||||
}
|
||||
SetRaceDest (THRADDASH_SHIP, x, y, 14, ADVANCE_THRADD_MISSION);
|
||||
@@ -538,37 +519,35 @@ thradd_mission (void)
|
||||
AddEvent (RELATIVE_EVENT, 0, 0, 0, ADVANCE_ILWRATH_MISSION);
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hThradd);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hThradd);
|
||||
}
|
||||
|
||||
static void
|
||||
ilwrath_mission (void)
|
||||
{
|
||||
BYTE ThraddState;
|
||||
HSTARSHIP hIlwrath, hThradd;
|
||||
EXTENDED_SHIP_FRAGMENT *IlwrathPtr;
|
||||
EXTENDED_SHIP_FRAGMENT *ThraddPtr;
|
||||
HFLEETINFO hIlwrath, hThradd;
|
||||
FLEET_INFO *IlwrathPtr;
|
||||
FLEET_INFO *ThraddPtr;
|
||||
|
||||
hIlwrath = GetStarShipFromIndex (&GLOBAL (avail_race_q), ILWRATH_SHIP);
|
||||
IlwrathPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hIlwrath);
|
||||
IlwrathPtr = LockFleetInfo (&GLOBAL (avail_race_q), hIlwrath);
|
||||
hThradd = GetStarShipFromIndex (&GLOBAL (avail_race_q), THRADDASH_SHIP);
|
||||
ThraddPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hThradd);
|
||||
ThraddPtr = LockFleetInfo (&GLOBAL (avail_race_q), hThradd);
|
||||
|
||||
if (IlwrathPtr->ShipInfo.loc.x == ((2500 + 2535) >> 1)
|
||||
&& IlwrathPtr->ShipInfo.loc.y == ((8070 + 8358) >> 1))
|
||||
if (IlwrathPtr->loc.x == ((2500 + 2535) >> 1)
|
||||
&& IlwrathPtr->loc.y == ((8070 + 8358) >> 1))
|
||||
{
|
||||
IlwrathPtr->ShipInfo.actual_strength =
|
||||
ThraddPtr->ShipInfo.actual_strength = 0;
|
||||
IlwrathPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
ThraddPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
IlwrathPtr->actual_strength = 0;
|
||||
ThraddPtr->actual_strength = 0;
|
||||
IlwrathPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
ThraddPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
}
|
||||
else if (IlwrathPtr->ShipInfo.actual_strength)
|
||||
else if (IlwrathPtr->actual_strength)
|
||||
{
|
||||
if (!GET_GAME_STATE (ILWRATH_FIGHT_THRADDASH)
|
||||
&& (IlwrathPtr->ShipInfo.dest_loc.x != 2500
|
||||
|| IlwrathPtr->ShipInfo.dest_loc.y != 8070))
|
||||
&& (IlwrathPtr->dest_loc.x != 2500
|
||||
|| IlwrathPtr->dest_loc.y != 8070))
|
||||
{
|
||||
SetRaceDest (ILWRATH_SHIP, 2500, 8070, 90,
|
||||
ADVANCE_ILWRATH_MISSION);
|
||||
@@ -578,27 +557,27 @@ ilwrath_mission (void)
|
||||
#define MADD_LENGTH 128
|
||||
SIZE strength_loss;
|
||||
|
||||
if (IlwrathPtr->ShipInfo.days_left == 0)
|
||||
if (IlwrathPtr->days_left == 0)
|
||||
{ /* arrived for battle */
|
||||
SET_GAME_STATE (ILWRATH_FIGHT_THRADDASH, 1);
|
||||
SET_GAME_STATE (HELIX_UNPROTECTED, 1);
|
||||
strength_loss = (SIZE)IlwrathPtr->ShipInfo.actual_strength;
|
||||
IlwrathPtr->ShipInfo.energy_level =
|
||||
strength_loss = (SIZE)IlwrathPtr->actual_strength;
|
||||
IlwrathPtr->energy_level =
|
||||
(BYTE)(-strength_loss / MADD_LENGTH);
|
||||
IlwrathPtr->ShipInfo.growth_fract =
|
||||
IlwrathPtr->growth_fract =
|
||||
(BYTE)(((strength_loss % MADD_LENGTH) << 8) / MADD_LENGTH);
|
||||
SetRaceDest (ILWRATH_SHIP,
|
||||
(2500 + 2535) >> 1, (8070 + 8358) >> 1,
|
||||
MADD_LENGTH - 1, ADVANCE_ILWRATH_MISSION);
|
||||
|
||||
strength_loss = (SIZE)ThraddPtr->ShipInfo.actual_strength;
|
||||
ThraddPtr->ShipInfo.energy_level =
|
||||
strength_loss = (SIZE)ThraddPtr->actual_strength;
|
||||
ThraddPtr->energy_level =
|
||||
(BYTE)(-strength_loss / MADD_LENGTH);
|
||||
ThraddPtr->ShipInfo.growth_fract =
|
||||
ThraddPtr->growth_fract =
|
||||
(BYTE)(((strength_loss % MADD_LENGTH) << 8) / MADD_LENGTH);
|
||||
|
||||
SET_GAME_STATE (THRADD_VISITS, 0);
|
||||
if (ThraddPtr->ShipInfo.ship_flags & GOOD_GUY)
|
||||
if (ThraddPtr->ship_flags & GOOD_GUY)
|
||||
ActivateStarShip (THRADDASH_SHIP, SET_NOT_ALLIED);
|
||||
}
|
||||
|
||||
@@ -607,7 +586,7 @@ ilwrath_mission (void)
|
||||
{ /* never went to Kohr-Ah or returned */
|
||||
SetRaceDest (THRADDASH_SHIP,
|
||||
(2500 + 2535) >> 1, (8070 + 8358) >> 1,
|
||||
IlwrathPtr->ShipInfo.days_left + 1, (BYTE)~0);
|
||||
IlwrathPtr->days_left + 1, (BYTE)~0);
|
||||
}
|
||||
else if (ThraddState < 3)
|
||||
{ /* recall on the double */
|
||||
@@ -618,27 +597,25 @@ ilwrath_mission (void)
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hThradd);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hIlwrath);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hThradd);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hIlwrath);
|
||||
}
|
||||
|
||||
static void
|
||||
utwig_supox_mission (void)
|
||||
{
|
||||
BYTE MissionState;
|
||||
HSTARSHIP hUtwig, hSupox;
|
||||
EXTENDED_SHIP_FRAGMENT *UtwigPtr;
|
||||
EXTENDED_SHIP_FRAGMENT *SupoxPtr;
|
||||
HFLEETINFO hUtwig, hSupox;
|
||||
FLEET_INFO *UtwigPtr;
|
||||
FLEET_INFO *SupoxPtr;
|
||||
|
||||
hUtwig = GetStarShipFromIndex (&GLOBAL (avail_race_q), UTWIG_SHIP);
|
||||
UtwigPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hUtwig);
|
||||
UtwigPtr = LockFleetInfo (&GLOBAL (avail_race_q), hUtwig);
|
||||
hSupox = GetStarShipFromIndex (&GLOBAL (avail_race_q), SUPOX_SHIP);
|
||||
SupoxPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hSupox);
|
||||
SupoxPtr = LockFleetInfo (&GLOBAL (avail_race_q), hSupox);
|
||||
|
||||
MissionState = GET_GAME_STATE (UTWIG_SUPOX_MISSION);
|
||||
if (UtwigPtr->ShipInfo.actual_strength && MissionState < 5)
|
||||
if (UtwigPtr->actual_strength && MissionState < 5)
|
||||
{
|
||||
if (MissionState == 1)
|
||||
{
|
||||
@@ -647,21 +624,19 @@ utwig_supox_mission (void)
|
||||
AddEvent (RELATIVE_EVENT, 0, (160 >> 1), 0,
|
||||
ADVANCE_UTWIG_SUPOX_MISSION);
|
||||
|
||||
strength_loss = (SIZE)(UtwigPtr->ShipInfo.actual_strength >> 1);
|
||||
UtwigPtr->ShipInfo.energy_level =
|
||||
(BYTE)(-strength_loss / 160);
|
||||
UtwigPtr->ShipInfo.growth_fract =
|
||||
strength_loss = (SIZE)(UtwigPtr->actual_strength >> 1);
|
||||
UtwigPtr->energy_level = (BYTE)(-strength_loss / 160);
|
||||
UtwigPtr->growth_fract =
|
||||
(BYTE)(((strength_loss % 160) << 8) / 160);
|
||||
UtwigPtr->ShipInfo.growth_err_term = 255 >> 1;
|
||||
UtwigPtr->growth_err_term = 255 >> 1;
|
||||
|
||||
strength_loss = (SIZE)(SupoxPtr->ShipInfo.actual_strength >> 1);
|
||||
strength_loss = (SIZE)(SupoxPtr->actual_strength >> 1);
|
||||
if (strength_loss)
|
||||
{
|
||||
SupoxPtr->ShipInfo.energy_level =
|
||||
(BYTE)(-strength_loss / 160);
|
||||
SupoxPtr->ShipInfo.growth_fract =
|
||||
SupoxPtr->energy_level = (BYTE)(-strength_loss / 160);
|
||||
SupoxPtr->growth_fract =
|
||||
(BYTE)(((strength_loss % 160) << 8) / 160);
|
||||
SupoxPtr->ShipInfo.growth_err_term = 255 >> 1;
|
||||
SupoxPtr->growth_err_term = 255 >> 1;
|
||||
}
|
||||
|
||||
SET_GAME_STATE (UTWIG_WAR_NEWS, 0);
|
||||
@@ -693,10 +668,10 @@ utwig_supox_mission (void)
|
||||
sx = 7468;
|
||||
sy = 9246;
|
||||
|
||||
UtwigPtr->ShipInfo.energy_level = 0;
|
||||
UtwigPtr->ShipInfo.growth_fract = 0;
|
||||
SupoxPtr->ShipInfo.energy_level = 0;
|
||||
SupoxPtr->ShipInfo.growth_fract = 0;
|
||||
UtwigPtr->energy_level = 0;
|
||||
UtwigPtr->growth_fract = 0;
|
||||
SupoxPtr->energy_level = 0;
|
||||
SupoxPtr->growth_fract = 0;
|
||||
|
||||
SET_GAME_STATE (UTWIG_WAR_NEWS, 0);
|
||||
SET_GAME_STATE (SUPOX_WAR_NEWS, 0);
|
||||
@@ -711,33 +686,31 @@ utwig_supox_mission (void)
|
||||
}
|
||||
SET_GAME_STATE (UTWIG_SUPOX_MISSION, MissionState + 1);
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hSupox);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hUtwig);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hSupox);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hUtwig);
|
||||
}
|
||||
|
||||
static void
|
||||
mycon_mission (void)
|
||||
{
|
||||
HSTARSHIP hMycon;
|
||||
EXTENDED_SHIP_FRAGMENT *MyconPtr;
|
||||
HFLEETINFO hMycon;
|
||||
FLEET_INFO *MyconPtr;
|
||||
|
||||
hMycon = GetStarShipFromIndex (&GLOBAL (avail_race_q), MYCON_SHIP);
|
||||
MyconPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hMycon);
|
||||
MyconPtr = LockFleetInfo (&GLOBAL (avail_race_q), hMycon);
|
||||
|
||||
if (MyconPtr->ShipInfo.actual_strength)
|
||||
if (MyconPtr->actual_strength)
|
||||
{
|
||||
if (MyconPtr->ShipInfo.energy_level)
|
||||
if (MyconPtr->energy_level)
|
||||
{
|
||||
// Head back.
|
||||
SET_GAME_STATE (MYCON_KNOW_AMBUSH, 1);
|
||||
SetRaceDest (MYCON_SHIP, 6392, 2200, 30, (BYTE)~0);
|
||||
|
||||
MyconPtr->ShipInfo.energy_level = 0;
|
||||
MyconPtr->ShipInfo.growth_fract = 0;
|
||||
MyconPtr->energy_level = 0;
|
||||
MyconPtr->growth_fract = 0;
|
||||
}
|
||||
else if (MyconPtr->ShipInfo.loc.x != 6858
|
||||
|| MyconPtr->ShipInfo.loc.y != 577)
|
||||
else if (MyconPtr->loc.x != 6858 || MyconPtr->loc.y != 577)
|
||||
SetRaceDest (MYCON_SHIP, 6858, 577, 30, ADVANCE_MYCON_MISSION);
|
||||
// To Organon.
|
||||
else
|
||||
@@ -746,15 +719,13 @@ mycon_mission (void)
|
||||
SIZE strength_loss;
|
||||
|
||||
AddEvent (RELATIVE_EVENT, 0, 14, 0, ADVANCE_MYCON_MISSION);
|
||||
strength_loss = (SIZE)(MyconPtr->ShipInfo.actual_strength >> 1);
|
||||
MyconPtr->ShipInfo.energy_level =
|
||||
(BYTE)(-strength_loss / 14);
|
||||
MyconPtr->ShipInfo.growth_fract =
|
||||
(BYTE)(((strength_loss % 14) << 8) / 14);
|
||||
MyconPtr->ShipInfo.growth_err_term = 255 >> 1;
|
||||
strength_loss = (SIZE)(MyconPtr->actual_strength >> 1);
|
||||
MyconPtr->energy_level = (BYTE)(-strength_loss / 14);
|
||||
MyconPtr->growth_fract = (BYTE)(((strength_loss % 14) << 8) / 14);
|
||||
MyconPtr->growth_err_term = 255 >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hMycon);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hMycon);
|
||||
}
|
||||
|
||||
|
||||
+41
-48
@@ -173,11 +173,14 @@ LoadSC2Data (void)
|
||||
}
|
||||
|
||||
static void
|
||||
copyFleetInfo (EXTENDED_SHIP_INFO *dst, SHIP_INFO *src, BYTE *fleet_strength)
|
||||
copyFleetInfo (FLEET_INFO *dst, SHIP_INFO *src)
|
||||
{
|
||||
*fleet_strength = src->var2;
|
||||
// other leading fields are irrelevant
|
||||
if (src->var2 == (BYTE)~0)
|
||||
dst->actual_strength = (COUNT)~0;
|
||||
else
|
||||
dst->actual_strength = (COUNT)src->var2 << 1;
|
||||
|
||||
// other leading fields are irrelevant
|
||||
dst->crew_level = src->crew_level;
|
||||
dst->max_crew = src->max_crew;
|
||||
dst->energy_level = src->energy_level;
|
||||
@@ -211,12 +214,12 @@ InitSIS (void)
|
||||
num_ships = (GET_PACKAGE (BLACKURQ_SHIP_INDEX) - rp + 1)
|
||||
+ 2; /* Yehat Rebels and Ur-Quan probe */
|
||||
|
||||
InitQueue (&GLOBAL (avail_race_q),
|
||||
num_ships, sizeof (EXTENDED_SHIP_FRAGMENT));
|
||||
InitQueue (&GLOBAL (avail_race_q), num_ships, sizeof (FLEET_INFO));
|
||||
for (i = 0; i < num_ships; ++i)
|
||||
{
|
||||
DWORD ship_ref;
|
||||
HSTARSHIP hStarShip;
|
||||
HFLEETINFO hFleet;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
if (i < num_ships - 2)
|
||||
ship_ref = MAKE_RESOURCE (rp++, rt, ri++);
|
||||
@@ -224,27 +227,24 @@ InitSIS (void)
|
||||
ship_ref = YEHAT_SHIP_INDEX;
|
||||
else /* (i == num_ships - 1) */
|
||||
ship_ref = PROBE_RES_INDEX;
|
||||
hStarShip = Build (&GLOBAL (avail_race_q), ship_ref);
|
||||
if (hStarShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *FleetPtr;
|
||||
BYTE fleet_strength = 0;
|
||||
|
||||
FleetPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hFleet = AllocLink (&GLOBAL (avail_race_q));
|
||||
if (!hFleet)
|
||||
continue;
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
FleetPtr->RaceResIndex = ship_ref;
|
||||
|
||||
if (i < num_ships - 1)
|
||||
{
|
||||
HSTARSHIP hMasterShip;
|
||||
SHIP_FRAGMENT *MasterShipPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
MASTER_SHIP_INFO *MasterShipPtr;
|
||||
|
||||
hMasterShip = FindMasterShip (ship_ref);
|
||||
MasterShipPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q,
|
||||
hMasterShip);
|
||||
MasterShipPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
// Grab a copy of loaded icons and strings (not owned)
|
||||
// XXX: SHIP_INFO struct copy
|
||||
copyFleetInfo (&FleetPtr->ShipInfo, &MasterShipPtr->ShipInfo,
|
||||
&fleet_strength);
|
||||
UnlockStarShip (&master_q, hMasterShip);
|
||||
copyFleetInfo (FleetPtr, &MasterShipPtr->ShipInfo);
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -254,31 +254,26 @@ InitSIS (void)
|
||||
if (RDPtr)
|
||||
{ // Grab a copy of loaded icons and strings
|
||||
// XXX: SHIP_INFO struct copy
|
||||
copyFleetInfo (&FleetPtr->ShipInfo, &RDPtr->ship_info,
|
||||
&fleet_strength);
|
||||
copyFleetInfo (FleetPtr, &RDPtr->ship_info);
|
||||
// avail_race_q owns these resources now
|
||||
free_ship (RDPtr, FALSE, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
FleetPtr->ShipInfo.actual_strength = 0;
|
||||
else
|
||||
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;
|
||||
FleetPtr->ship_flags = BAD_GUY;
|
||||
FleetPtr->known_strength = 0;
|
||||
FleetPtr->known_loc = FleetPtr->loc;
|
||||
// XXX: Rebel special case
|
||||
if (i == YEHAT_REBEL_SHIP)
|
||||
FleetPtr->actual_strength = 0;
|
||||
FleetPtr->growth_fract = 0;
|
||||
FleetPtr->growth_err_term = 255 >> 1;
|
||||
FleetPtr->energy_level = 0;
|
||||
FleetPtr->days_left = 0;
|
||||
FleetPtr->func_index = ~0;
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
PutQueue (&GLOBAL (avail_race_q), hFleet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +385,7 @@ FreeSC2Data (void)
|
||||
void
|
||||
UninitSIS (void)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HFLEETINFO hStarShip;
|
||||
|
||||
if (!initedSIS)
|
||||
return;
|
||||
@@ -408,15 +403,13 @@ UninitSIS (void)
|
||||
hStarShip = GetTailLink (&GLOBAL (avail_race_q));
|
||||
if (hStarShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *FragPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
FragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.melee_icon));
|
||||
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.icons));
|
||||
DestroyStringTable (ReleaseStringTable (
|
||||
FragPtr->ShipInfo.race_strings));
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
DestroyDrawable (ReleaseDrawable (FleetPtr->melee_icon));
|
||||
DestroyDrawable (ReleaseDrawable (FleetPtr->icons));
|
||||
DestroyStringTable (ReleaseStringTable (FleetPtr->race_strings));
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
UninitQueue (&GLOBAL (avail_race_q));
|
||||
|
||||
@@ -945,7 +945,7 @@ typedef struct
|
||||
/* List of all the races in the game with information
|
||||
* about their ships, and what player knows about their
|
||||
* fleet, center of SoI, status, etc.
|
||||
* queue element is EXTENDED_SHIP_FRAGMENT */
|
||||
* queue element is FLEET_INFO */
|
||||
QUEUE npc_built_ship_q;
|
||||
/* Non-player-character list of ships (during encounter)
|
||||
* or list of groups present in solarsys (during IP);
|
||||
|
||||
+72
-82
@@ -94,18 +94,18 @@ ReadShipFragment (void *fp, SHIP_FRAGMENT *FragPtr)
|
||||
sread_16 (fp, &FragPtr->which_side);
|
||||
sread_8 (fp, &FragPtr->captains_name_index);
|
||||
sread_8 (fp, NULL); /* padding */
|
||||
// Read SHIP_INFO elements
|
||||
sread_16 (fp, &FragPtr->ShipInfo.ship_flags);
|
||||
sread_8 (fp, &FragPtr->ShipInfo.var1);
|
||||
sread_8 (fp, &FragPtr->ShipInfo.var2);
|
||||
sread_16 (fp, &FragPtr->ship_flags);
|
||||
sread_8 (fp, &FragPtr->var1);
|
||||
sread_8 (fp, &FragPtr->var2);
|
||||
// XXX: reading crew as BYTE to maintain savegame compatibility
|
||||
sread_8 (fp, &tmpb);
|
||||
FragPtr->ShipInfo.crew_level = tmpb;
|
||||
FragPtr->crew_level = tmpb;
|
||||
sread_8 (fp, &tmpb);
|
||||
FragPtr->ShipInfo.max_crew = tmpb;
|
||||
sread_8 (fp, &FragPtr->ShipInfo.energy_level);
|
||||
sread_8 (fp, &FragPtr->ShipInfo.max_energy);
|
||||
sread_16 (fp, &FragPtr->ShipInfo.loc.x);
|
||||
sread_16 (fp, &FragPtr->ShipInfo.loc.y);
|
||||
FragPtr->max_crew = tmpb;
|
||||
sread_8 (fp, &FragPtr->energy_level);
|
||||
sread_8 (fp, &FragPtr->max_energy);
|
||||
sread_16 (fp, &FragPtr->loc.x);
|
||||
sread_16 (fp, &FragPtr->loc.y);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -115,16 +115,16 @@ WriteShipFragment (void *fp, const SHIP_FRAGMENT *FragPtr)
|
||||
swrite_16 (fp, FragPtr->which_side);
|
||||
swrite_8 (fp, FragPtr->captains_name_index);
|
||||
swrite_8 (fp, 0); /* padding */
|
||||
// Write SHIP_INFO elements
|
||||
swrite_16 (fp, FragPtr->ShipInfo.ship_flags);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.var1);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.var2);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.crew_level);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.max_crew);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.energy_level);
|
||||
swrite_8 (fp, FragPtr->ShipInfo.max_energy);
|
||||
swrite_16 (fp, FragPtr->ShipInfo.loc.x);
|
||||
swrite_16 (fp, FragPtr->ShipInfo.loc.y);
|
||||
swrite_16 (fp, FragPtr->ship_flags);
|
||||
swrite_8 (fp, FragPtr->var1);
|
||||
swrite_8 (fp, FragPtr->var2);
|
||||
// XXX: writing crew as BYTE to maintain savegame compatibility
|
||||
swrite_8 (fp, FragPtr->crew_level);
|
||||
swrite_8 (fp, FragPtr->max_crew);
|
||||
swrite_8 (fp, FragPtr->energy_level);
|
||||
swrite_8 (fp, FragPtr->max_energy);
|
||||
swrite_16 (fp, FragPtr->loc.x);
|
||||
swrite_16 (fp, FragPtr->loc.y);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -168,7 +168,7 @@ BuildGroups (void)
|
||||
BYTE Index, BestIndex;
|
||||
COUNT BestPercent;
|
||||
POINT universe;
|
||||
HSTARSHIP hTemplate, hNextShip;
|
||||
HFLEETINFO hFleet, hNextFleet;
|
||||
BYTE HomeWorld[] =
|
||||
{
|
||||
0, /* ARILOU_SHIP */
|
||||
@@ -208,17 +208,16 @@ BuildGroups (void)
|
||||
|
||||
BestPercent = 0;
|
||||
universe = CurStarDescPtr->star_pt;
|
||||
for (hTemplate = GetHeadLink (&GLOBAL (avail_race_q)), Index = 0;
|
||||
hTemplate; hTemplate = hNextShip, ++Index)
|
||||
for (hFleet = GetHeadLink (&GLOBAL (avail_race_q)), Index = 0;
|
||||
hFleet; hFleet = hNextFleet, ++Index)
|
||||
{
|
||||
COUNT i, encounter_radius;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hTemplate);
|
||||
hNextShip = _GetSuccLink (TemplatePtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
hNextFleet = _GetSuccLink (FleetPtr);
|
||||
|
||||
if ((encounter_radius = TemplatePtr->ShipInfo.actual_strength)
|
||||
if ((encounter_radius = FleetPtr->actual_strength)
|
||||
&& (i = EncounterPercent[Index]))
|
||||
{
|
||||
SIZE dx, dy;
|
||||
@@ -229,19 +228,12 @@ BuildGroups (void)
|
||||
if (race_enc && CurStarDescPtr->Index == race_enc)
|
||||
{ // In general, there are always ships at the Homeworld for
|
||||
// the races specified in HomeWorld[] array.
|
||||
// XXX: This code is somewhat broken and the intent is not
|
||||
// 100% clear. Finding a Homeworld does not break you out
|
||||
// of the loop, so another race could override with its
|
||||
// ships when another race's SoI covers the Homeworld.
|
||||
// However, only a race later in the order can do that, so
|
||||
// for example, there will *always* be Yehat Rebel ships
|
||||
// at the Rebel Homeworld, but the same is not true for the
|
||||
// regular Yehat.
|
||||
BestIndex = Index;
|
||||
BestPercent = 70;
|
||||
if (race_enc == SPATHI_DEFINED || race_enc == SUPOX_DEFINED)
|
||||
BestPercent = 2;
|
||||
hNextShip = 0;
|
||||
// Terminate the loop!
|
||||
hNextFleet = 0;
|
||||
|
||||
goto FoundHome;
|
||||
}
|
||||
@@ -251,9 +243,11 @@ BuildGroups (void)
|
||||
else
|
||||
encounter_radius =
|
||||
(encounter_radius * SPHERE_RADIUS_INCREMENT) >> 1;
|
||||
if ((dx = universe.x - TemplatePtr->ShipInfo.loc.x) < 0)
|
||||
dx = universe.x - FleetPtr->loc.x;
|
||||
if (dx < 0)
|
||||
dx = -dx;
|
||||
if ((dy = universe.y - TemplatePtr->ShipInfo.loc.y) < 0)
|
||||
dy = universe.y - FleetPtr->loc.y;
|
||||
if (dy < 0)
|
||||
dy = -dy;
|
||||
if ((COUNT)dx < encounter_radius
|
||||
&& (COUNT)dy < encounter_radius
|
||||
@@ -265,7 +259,7 @@ BuildGroups (void)
|
||||
// EncounterPercent is only used in practice for the Slylandro
|
||||
// Probes, for the rest of races the chance of encounter is
|
||||
// calced directly below from the distance to the Homeworld
|
||||
if (TemplatePtr->ShipInfo.actual_strength != (COUNT)~0)
|
||||
if (FleetPtr->actual_strength != (COUNT)~0)
|
||||
{
|
||||
i = 70 - (COUNT)((DWORD)square_root (d_squared)
|
||||
* 60L / encounter_radius);
|
||||
@@ -276,7 +270,7 @@ BuildGroups (void)
|
||||
&& (BestPercent == 0
|
||||
|| (HIWORD (rand_val) % (i + BestPercent)) < i))
|
||||
{
|
||||
if (TemplatePtr->ShipInfo.actual_strength == (COUNT)~0)
|
||||
if (FleetPtr->actual_strength == (COUNT)~0)
|
||||
{ // The prevailing encounter chance is hereby limitted
|
||||
// to 4% for races with infinite SoI (currently, it
|
||||
// is only the Slylandro Probes)
|
||||
@@ -290,7 +284,7 @@ BuildGroups (void)
|
||||
}
|
||||
|
||||
FoundHome:
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hTemplate);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hFleet);
|
||||
}
|
||||
|
||||
if (BestPercent)
|
||||
@@ -332,17 +326,18 @@ static void
|
||||
FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
{
|
||||
BYTE RaceType, NumShips;
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
if (which_group == GROUP_LIST)
|
||||
{
|
||||
QUEUE temp_q;
|
||||
HSTARSHIP hNextShip;
|
||||
HSHIPFRAG hNextShip;
|
||||
|
||||
if (pGH->GroupOffset[0] == 0)
|
||||
pGH->GroupOffset[0] = LengthStateFile (fp);
|
||||
|
||||
/* Weed out the dead groups first */
|
||||
temp_q = GLOBAL (npc_built_ship_q);
|
||||
SetHeadLink (&GLOBAL (npc_built_ship_q), 0);
|
||||
SetTailLink (&GLOBAL (npc_built_ship_q), 0);
|
||||
@@ -351,22 +346,21 @@ FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
{
|
||||
COUNT crew_level;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&temp_q, hStarShip);
|
||||
FragPtr = LockShipFrag (&temp_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
crew_level = FragPtr->ShipInfo.crew_level;
|
||||
crew_level = FragPtr->crew_level;
|
||||
which_group = GET_GROUP_ID (FragPtr);
|
||||
UnlockStarShip (&temp_q, hStarShip);
|
||||
UnlockShipFrag (&temp_q, hStarShip);
|
||||
|
||||
if (crew_level == 0)
|
||||
{
|
||||
{ /* This group is dead -- remove it */
|
||||
if (GLOBAL (BattleGroupRef))
|
||||
PutGroupInfo (GLOBAL (BattleGroupRef), which_group);
|
||||
else
|
||||
FlushGroupInfo (pGH, GROUPS_RANDOM, which_group, fp);
|
||||
pGH->GroupOffset[which_group] = 0;
|
||||
RemoveQueue (&temp_q, hStarShip);
|
||||
FreeStarShip (&temp_q, hStarShip);
|
||||
FreeShipFrag (&temp_q, hStarShip);
|
||||
}
|
||||
}
|
||||
GLOBAL (npc_built_ship_q) = temp_q;
|
||||
@@ -374,17 +368,17 @@ FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
which_group = GROUP_LIST;
|
||||
}
|
||||
else if (which_group > pGH->NumGroups)
|
||||
{
|
||||
{ /* Group not present yet -- add it */
|
||||
pGH->NumGroups = which_group;
|
||||
pGH->GroupOffset[which_group] = LengthStateFile (fp);
|
||||
|
||||
/* The first ship in a group defines the alien race */
|
||||
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
RaceType = GET_RACE_ID (FragPtr);
|
||||
SeekStateFile (fp, pGH->GroupOffset[which_group], SEEK_SET);
|
||||
swrite_8 (fp, RaceType);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
SeekStateFile (fp, offset, SEEK_SET);
|
||||
WriteGroupHeader (fp, pGH);
|
||||
@@ -397,7 +391,7 @@ FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
NumShips = (BYTE)CountLinks (&GLOBAL (npc_built_ship_q));
|
||||
|
||||
if (which_group != GROUP_LIST)
|
||||
{ // skip RaceType
|
||||
{ /* Do not change RaceType (skip it) */
|
||||
SeekStateFile (fp, pGH->GroupOffset[which_group] + 1, SEEK_SET);
|
||||
}
|
||||
else
|
||||
@@ -410,10 +404,9 @@ FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
while (NumShips--)
|
||||
{
|
||||
HSTARSHIP hNextShip;
|
||||
HSHIPFRAG hNextShip;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
|
||||
RaceType = GET_RACE_ID (FragPtr);
|
||||
@@ -424,13 +417,13 @@ FlushGroupInfo (GROUP_HEADER* pGH, DWORD offset, BYTE which_group, void *fp)
|
||||
log_add (log_Debug, "F) type %u, loc %u<%d, %d>, task 0x%02x:%u",
|
||||
RaceType,
|
||||
GET_GROUP_LOC (FragPtr),
|
||||
FragPtr->ShipInfo.loc.x,
|
||||
FragPtr->ShipInfo.loc.y,
|
||||
FragPtr->loc.x,
|
||||
FragPtr->loc.y,
|
||||
GET_GROUP_MISSION (FragPtr),
|
||||
GET_GROUP_DEST (FragPtr));
|
||||
#endif /* DEBUG_GROUPS */
|
||||
WriteShipFragment (fp, FragPtr);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
}
|
||||
@@ -449,7 +442,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
{
|
||||
BYTE RaceType, NumShips;
|
||||
GROUP_HEADER GH;
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
SeekStateFile (fp, offset, SEEK_SET);
|
||||
@@ -510,8 +503,8 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
|
||||
hStarShip = CloneShipFragment (RaceType,
|
||||
&GLOBAL (npc_built_ship_q), 0);
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
// XXX: STARSHIP refactor; Cannot find what might be
|
||||
// using this info. Looks unused.
|
||||
FragPtr->which_side = BAD_GUY;
|
||||
@@ -538,17 +531,15 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
) + 1);
|
||||
SET_GROUP_DEST (FragPtr, group_loc);
|
||||
rand_val = TFB_Random ();
|
||||
FragPtr->ShipInfo.loc.x =
|
||||
(LOWORD (rand_val) % 10000) - 5000;
|
||||
FragPtr->ShipInfo.loc.y =
|
||||
(HIWORD (rand_val) % 10000) - 5000;
|
||||
FragPtr->loc.x = (LOWORD (rand_val) % 10000) - 5000;
|
||||
FragPtr->loc.y = (HIWORD (rand_val) % 10000) - 5000;
|
||||
if (task == EXPLORE)
|
||||
FragPtr->ShipInfo.group_counter =
|
||||
FragPtr->group_counter =
|
||||
((COUNT)TFB_Random () % MAX_REVOLUTIONS)
|
||||
<< FACING_SHIFT;
|
||||
else
|
||||
{
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
FragPtr->group_counter = 0;
|
||||
if (task == ON_STATION)
|
||||
{
|
||||
COUNT angle;
|
||||
@@ -559,9 +550,9 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
FALSE);
|
||||
angle = FACING_TO_ANGLE (GET_ORBIT_LOC (
|
||||
FragPtr) + 1);
|
||||
FragPtr->ShipInfo.loc.x = org.x
|
||||
FragPtr->loc.x = org.x
|
||||
+ COSINE (angle, STATION_RADIUS);
|
||||
FragPtr->ShipInfo.loc.y = org.y
|
||||
FragPtr->loc.y = org.y
|
||||
+ SINE (angle, STATION_RADIUS);
|
||||
group_loc = 0;
|
||||
}
|
||||
@@ -578,11 +569,11 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
NumShips,
|
||||
RaceType,
|
||||
group_loc,
|
||||
FragPtr->ShipInfo.loc.x,
|
||||
FragPtr->ShipInfo.loc.y,
|
||||
FragPtr->loc.x,
|
||||
FragPtr->loc.y,
|
||||
task);
|
||||
#endif /* DEBUG_GROUPS */
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q),
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
}
|
||||
}
|
||||
@@ -636,8 +627,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
hStarShip = CloneShipFragment (RaceType,
|
||||
&GLOBAL (npc_built_ship_q), 0);
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
ReadShipFragment (fp, FragPtr);
|
||||
|
||||
#ifdef DEBUG_GROUPS
|
||||
@@ -646,8 +636,8 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
"task 0x%02x:%u",
|
||||
RaceType,
|
||||
GET_GROUP_LOC (FragPtr),
|
||||
FragPtr->ShipInfo.loc.x,
|
||||
FragPtr->ShipInfo.loc.y,
|
||||
FragPtr->loc.x,
|
||||
FragPtr->loc.y,
|
||||
GET_GROUP_MISSION (FragPtr),
|
||||
GET_GROUP_DEST (FragPtr));
|
||||
#endif /* DEBUG_GROUPS */
|
||||
@@ -658,16 +648,16 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|
||||
#ifdef DEBUG_GROUPS
|
||||
log_add (log_Debug, "\n");
|
||||
#endif /* DEBUG_GROUPS */
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_GROUPS
|
||||
log_add (log_Debug, " -- REMOVING");
|
||||
#endif /* DEBUG_GROUPS */
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
RemoveQueue (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FreeStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FreeShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-18
@@ -143,7 +143,7 @@ check_hyperspace_encounter (void)
|
||||
{
|
||||
BYTE Type;
|
||||
POINT universe;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
COUNT EncounterPercent[] =
|
||||
{
|
||||
RACE_HYPERSPACE_PERCENT
|
||||
@@ -156,13 +156,12 @@ check_hyperspace_encounter (void)
|
||||
hStarShip = hNextShip, ++Type)
|
||||
{
|
||||
COUNT encounter_radius;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (TemplatePtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
encounter_radius = TemplatePtr->ShipInfo.actual_strength;
|
||||
encounter_radius = FleetPtr->actual_strength;
|
||||
if (encounter_radius)
|
||||
{
|
||||
BYTE encounter_flags;
|
||||
@@ -222,9 +221,11 @@ check_hyperspace_encounter (void)
|
||||
}
|
||||
}
|
||||
|
||||
if ((dx = universe.x - TemplatePtr->ShipInfo.loc.x) < 0)
|
||||
dx = universe.x - FleetPtr->loc.x;
|
||||
if (dx < 0)
|
||||
dx = -dx;
|
||||
if ((dy = universe.y - TemplatePtr->ShipInfo.loc.y) < 0)
|
||||
dy = universe.y - FleetPtr->loc.y;
|
||||
if (dy < 0)
|
||||
dy = -dy;
|
||||
if ((COUNT)dx < encounter_radius
|
||||
&& (COUNT)dy < encounter_radius
|
||||
@@ -238,7 +239,7 @@ check_hyperspace_encounter (void)
|
||||
{
|
||||
LockEncounter (hEncounter, &EncounterPtr);
|
||||
memset (EncounterPtr, 0, sizeof (*EncounterPtr));
|
||||
EncounterPtr->origin = TemplatePtr->ShipInfo.loc;
|
||||
EncounterPtr->origin = FleetPtr->loc;
|
||||
EncounterPtr->radius = encounter_radius;
|
||||
EncounterPtr->SD.Index = encounter_flags;
|
||||
EncounterPtr->SD.Type = Type;
|
||||
@@ -249,7 +250,7 @@ check_hyperspace_encounter (void)
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
SET_GAME_STATE (USED_BROADCASTER, 0);
|
||||
@@ -951,19 +952,18 @@ AddEncounterElement (ENCOUNTER *EncounterPtr, POINT *puniverse)
|
||||
NumShips, HINIBBLE (EncounterPtr->SD.Index));
|
||||
for (i = 0; i < NumShips; ++i)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hStarShip;
|
||||
FLEET_INFO *FleetPtr;
|
||||
BRIEF_SHIP_INFO *BSIPtr = &EncounterPtr->ShipList[i];
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), Type);
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
// 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);
|
||||
BSIPtr->crew_level = FleetPtr->crew_level;
|
||||
BSIPtr->max_crew = FleetPtr->max_crew;
|
||||
BSIPtr->max_energy = FleetPtr->max_energy;
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+50
-60
@@ -27,15 +27,14 @@
|
||||
void
|
||||
NotifyOthers (COUNT which_race, BYTE target_loc)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
|
||||
if (GET_RACE_ID (StarShipPtr) == which_race)
|
||||
@@ -62,9 +61,9 @@ NotifyOthers (COUNT which_race, BYTE target_loc)
|
||||
if (!(task & REFORM_GROUP))
|
||||
{
|
||||
if ((task & ~IGNORE_FLAGSHIP) != EXPLORE)
|
||||
StarShipPtr->ShipInfo.group_counter = 0;
|
||||
StarShipPtr->group_counter = 0;
|
||||
else
|
||||
StarShipPtr->ShipInfo.group_counter =
|
||||
StarShipPtr->group_counter =
|
||||
((COUNT) TFB_Random () % MAX_REVOLUTIONS)
|
||||
<< FACING_SHIFT;
|
||||
}
|
||||
@@ -74,7 +73,7 @@ NotifyOthers (COUNT which_race, BYTE target_loc)
|
||||
SET_GROUP_DEST (StarShipPtr, target_loc);
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
GetElementStarShip (EPtr, &StarShipPtr);
|
||||
group_loc = GET_GROUP_LOC (StarShipPtr);
|
||||
/* save old location */
|
||||
DisplayArray[EPtr->PrimIndex].Object.Point = StarShipPtr->ShipInfo.loc;
|
||||
DisplayArray[EPtr->PrimIndex].Object.Point = StarShipPtr->loc;
|
||||
|
||||
if (group_loc != 0)
|
||||
radius = MAX_ZOOM_RADIUS;
|
||||
@@ -107,10 +106,10 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
radius = pSolarSysState->SunDesc[0].radius;
|
||||
|
||||
dest_pt.x = (SIS_SCREEN_WIDTH >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.x
|
||||
+ (SIZE)((long)StarShipPtr->loc.x
|
||||
* (DISPLAY_FACTOR >> 1) / radius);
|
||||
dest_pt.y = (SIS_SCREEN_HEIGHT >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.y
|
||||
+ (SIZE)((long)StarShipPtr->loc.y
|
||||
* (DISPLAY_FACTOR >> 1) / radius);
|
||||
EPtr->current.location.x = DISPLAY_TO_WORLD (dest_pt.x)
|
||||
+ (COORD)(LOG_SPACE_WIDTH >> 1)
|
||||
@@ -131,18 +130,15 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
if (pSolarSysState->MenuState.CurState)
|
||||
goto ExitIPProcess;
|
||||
|
||||
if ((task & REFORM_GROUP)
|
||||
&& --StarShipPtr->ShipInfo.group_counter == 0)
|
||||
if ((task & REFORM_GROUP) && --StarShipPtr->group_counter == 0)
|
||||
{
|
||||
task &= ~REFORM_GROUP;
|
||||
SET_GROUP_MISSION (StarShipPtr, task);
|
||||
if ((task & ~IGNORE_FLAGSHIP) != EXPLORE)
|
||||
StarShipPtr->ShipInfo.group_counter = 0;
|
||||
StarShipPtr->group_counter = 0;
|
||||
else
|
||||
StarShipPtr->ShipInfo.group_counter =
|
||||
((COUNT)TFB_Random ()
|
||||
% MAX_REVOLUTIONS)
|
||||
<< FACING_SHIFT;
|
||||
StarShipPtr->group_counter = ((COUNT)TFB_Random ()
|
||||
% MAX_REVOLUTIONS) << FACING_SHIFT;
|
||||
}
|
||||
|
||||
if (!(task & REFORM_GROUP))
|
||||
@@ -185,10 +181,8 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
if (GET_RACE_ID (StarShipPtr) == URQUAN_PROBE_SHIP)
|
||||
detect_dist <<= 1;
|
||||
}
|
||||
vdx = GLOBAL (ip_location.x)
|
||||
- StarShipPtr->ShipInfo.loc.x;
|
||||
vdy = GLOBAL (ip_location.y)
|
||||
- StarShipPtr->ShipInfo.loc.y;
|
||||
vdx = GLOBAL (ip_location.x) - StarShipPtr->loc.x;
|
||||
vdy = GLOBAL (ip_location.y) - StarShipPtr->loc.y;
|
||||
if ((long)vdx * vdx
|
||||
+ (long)vdy * vdy < (long)detect_dist * detect_dist)
|
||||
{
|
||||
@@ -220,8 +214,8 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
Transition = FALSE;
|
||||
if (task == FLEE)
|
||||
{
|
||||
dest_pt.x = StarShipPtr->ShipInfo.loc.x << 1;
|
||||
dest_pt.y = StarShipPtr->ShipInfo.loc.y << 1;
|
||||
dest_pt.x = StarShipPtr->loc.x << 1;
|
||||
dest_pt.y = StarShipPtr->loc.y << 1;
|
||||
}
|
||||
else if (((task != ON_STATION || GET_GROUP_DEST (StarShipPtr) == 0)
|
||||
&& group_loc == target_loc)
|
||||
@@ -256,8 +250,8 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
angle = FACING_TO_ANGLE (GET_ORBIT_LOC (StarShipPtr) + 1);
|
||||
dest_pt.x = org.x + COSINE (angle, orbit_dist);
|
||||
dest_pt.y = org.y + SINE (angle, orbit_dist);
|
||||
if (StarShipPtr->ShipInfo.loc.x == dest_pt.x
|
||||
&& StarShipPtr->ShipInfo.loc.y == dest_pt.y)
|
||||
if (StarShipPtr->loc.x == dest_pt.x
|
||||
&& StarShipPtr->loc.y == dest_pt.y)
|
||||
{
|
||||
BYTE next_loc;
|
||||
|
||||
@@ -268,8 +262,8 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
dest_pt.y = org.y + SINE (angle, orbit_dist);
|
||||
|
||||
EPtr->thrust_wait = (BYTE)~0;
|
||||
if (StarShipPtr->ShipInfo.group_counter)
|
||||
--StarShipPtr->ShipInfo.group_counter;
|
||||
if (StarShipPtr->group_counter)
|
||||
--StarShipPtr->group_counter;
|
||||
else if (task == EXPLORE
|
||||
&& (next_loc = (BYTE)(((COUNT)TFB_Random ()
|
||||
% pSolarSysState->SunDesc[0].NumPlanets)
|
||||
@@ -294,12 +288,12 @@ ip_group_preprocess (ELEMENT *ElementPtr)
|
||||
if (task == ON_STATION)
|
||||
target_loc = 0;
|
||||
|
||||
dest_pt.x = StarShipPtr->ShipInfo.loc.x << 1;
|
||||
dest_pt.y = StarShipPtr->ShipInfo.loc.y << 1;
|
||||
dest_pt.x = StarShipPtr->loc.x << 1;
|
||||
dest_pt.y = StarShipPtr->loc.y << 1;
|
||||
}
|
||||
|
||||
delta_x = dest_pt.x - StarShipPtr->ShipInfo.loc.x;
|
||||
delta_y = dest_pt.y - StarShipPtr->ShipInfo.loc.y;
|
||||
delta_x = dest_pt.x - StarShipPtr->loc.x;
|
||||
delta_y = dest_pt.y - StarShipPtr->loc.y;
|
||||
angle = ARCTAN (delta_x, delta_y);
|
||||
|
||||
if (EPtr->thrust_wait && EPtr->thrust_wait != (BYTE)~0)
|
||||
@@ -346,7 +340,7 @@ PartialRevolution:
|
||||
if ((long)((COUNT)(dx * dx) + (COUNT)(dy * dy))
|
||||
>= (long)delta_x * delta_x + (long)delta_y * delta_y)
|
||||
{
|
||||
StarShipPtr->ShipInfo.loc = dest_pt;
|
||||
StarShipPtr->loc = dest_pt;
|
||||
vdx = vdy = 0;
|
||||
ZeroVelocityComponents (&EPtr->velocity);
|
||||
}
|
||||
@@ -378,10 +372,10 @@ PartialRevolution:
|
||||
{
|
||||
CheckGetAway:
|
||||
dest_pt.x = (SIS_SCREEN_WIDTH >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.x
|
||||
+ (SIZE)((long)StarShipPtr->loc.x
|
||||
* (DISPLAY_FACTOR >> 1) / MAX_ZOOM_RADIUS);
|
||||
dest_pt.y = (SIS_SCREEN_HEIGHT >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.y
|
||||
+ (SIZE)((long)StarShipPtr->loc.y
|
||||
* (DISPLAY_FACTOR >> 1) / MAX_ZOOM_RADIUS);
|
||||
if (dest_pt.x < 0
|
||||
|| dest_pt.x >= SIS_SCREEN_WIDTH
|
||||
@@ -402,18 +396,15 @@ CheckGetAway:
|
||||
PLANET_DESC *pCurDesc;
|
||||
|
||||
pCurDesc = &pSolarSysState->PlanetDesc[group_loc - 1];
|
||||
XFormIPLoc (
|
||||
&pCurDesc->image.origin,
|
||||
&StarShipPtr->ShipInfo.loc,
|
||||
FALSE
|
||||
);
|
||||
XFormIPLoc (&pCurDesc->image.origin, &StarShipPtr->loc,
|
||||
FALSE);
|
||||
SET_GROUP_LOC (StarShipPtr, group_loc = 0);
|
||||
}
|
||||
else if (target_loc == 0)
|
||||
{
|
||||
EPtr->life_span = 0;
|
||||
EPtr->state_flags |= DISAPPEARING | NONSOLID;
|
||||
StarShipPtr->ShipInfo.crew_level = 0;
|
||||
StarShipPtr->crew_level = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -424,15 +415,15 @@ CheckGetAway:
|
||||
NORMALIZE_FACING (
|
||||
ANGLE_TO_FACING (angle + HALF_CIRCLE)
|
||||
));
|
||||
StarShipPtr->ShipInfo.group_counter =
|
||||
StarShipPtr->group_counter =
|
||||
((COUNT)TFB_Random () % MAX_REVOLUTIONS)
|
||||
<< FACING_SHIFT;
|
||||
}
|
||||
|
||||
StarShipPtr->ShipInfo.loc.x = -(SIZE)((long)COSINE (
|
||||
StarShipPtr->loc.x = -(SIZE)((long)COSINE (
|
||||
angle, SIS_SCREEN_WIDTH * 9 / 16
|
||||
) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1));
|
||||
StarShipPtr->ShipInfo.loc.y = -(SIZE)((long)SINE (
|
||||
StarShipPtr->loc.y = -(SIZE)((long)SINE (
|
||||
angle, SIS_SCREEN_WIDTH * 9 / 16
|
||||
) * MAX_ZOOM_RADIUS / (DISPLAY_FACTOR >> 1));
|
||||
|
||||
@@ -458,14 +449,14 @@ CheckGetAway:
|
||||
}
|
||||
}
|
||||
}
|
||||
StarShipPtr->ShipInfo.loc.x += vdx;
|
||||
StarShipPtr->ShipInfo.loc.y += vdy;
|
||||
StarShipPtr->loc.x += vdx;
|
||||
StarShipPtr->loc.y += vdy;
|
||||
|
||||
dest_pt.x = (SIS_SCREEN_WIDTH >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.x
|
||||
+ (SIZE)((long)StarShipPtr->loc.x
|
||||
* (DISPLAY_FACTOR >> 1) / radius);
|
||||
dest_pt.y = (SIS_SCREEN_HEIGHT >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.y
|
||||
+ (SIZE)((long)StarShipPtr->loc.y
|
||||
* (DISPLAY_FACTOR >> 1) / radius);
|
||||
|
||||
ExitIPProcess:
|
||||
@@ -478,7 +469,7 @@ ExitIPProcess:
|
||||
|
||||
if (group_loc != flagship_loc
|
||||
|| ((task & REFORM_GROUP)
|
||||
&& (StarShipPtr->ShipInfo.group_counter & 1)))
|
||||
&& (StarShipPtr->group_counter & 1)))
|
||||
{
|
||||
SetPrimType (&DisplayArray[EPtr->PrimIndex], NO_PRIM);
|
||||
EPtr->state_flags |= NONSOLID;
|
||||
@@ -538,7 +529,7 @@ ip_group_collision (ELEMENT *ElementPtr0, POINT *pPt0,
|
||||
{
|
||||
ElementPtr1->state_flags |= COLLISION;
|
||||
|
||||
StarShipPtr->ShipInfo.loc =
|
||||
StarShipPtr->loc =
|
||||
DisplayArray[ElementPtr0->PrimIndex].Object.Point;
|
||||
ElementPtr0->next.location = ElementPtr0->current.location;
|
||||
InitIntersectEndPoint (ElementPtr0);
|
||||
@@ -557,7 +548,7 @@ ip_group_collision (ELEMENT *ElementPtr0, POINT *pPt0,
|
||||
{
|
||||
SET_GROUP_MISSION (StarShipPtr,
|
||||
GET_GROUP_MISSION (StarShipPtr) | REFORM_GROUP);
|
||||
StarShipPtr->ShipInfo.group_counter = 100;
|
||||
StarShipPtr->group_counter = 100;
|
||||
NotifyOthers (GET_RACE_ID (StarShipPtr), (BYTE)~0);
|
||||
}
|
||||
|
||||
@@ -606,10 +597,10 @@ spawn_ip_group (SHIP_FRAGMENT *StarShipPtr)
|
||||
}
|
||||
|
||||
SetPrimType (&DisplayArray[IPSHIPElementPtr->PrimIndex], STAMP_PRIM);
|
||||
IPSHIPElementPtr->current.image.farray =
|
||||
&StarShipPtr->ShipInfo.melee_icon;
|
||||
IPSHIPElementPtr->current.image.frame =
|
||||
SetAbsFrameIndex (StarShipPtr->ShipInfo.melee_icon, 1);
|
||||
// XXX: Hack: farray points to FRAME[3] and given FRAME
|
||||
IPSHIPElementPtr->current.image.farray = &StarShipPtr->melee_icon;
|
||||
IPSHIPElementPtr->current.image.frame = SetAbsFrameIndex (
|
||||
StarShipPtr->melee_icon, 1);
|
||||
/* preprocessing has a side effect
|
||||
* we wish to avoid. So death_func
|
||||
* is used instead, but will achieve
|
||||
@@ -629,10 +620,10 @@ spawn_ip_group (SHIP_FRAGMENT *StarShipPtr)
|
||||
radius = pSolarSysState->SunDesc[0].radius;
|
||||
|
||||
pt.x = (SIS_SCREEN_WIDTH >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.x
|
||||
+ (SIZE)((long)StarShipPtr->loc.x
|
||||
* DISPLAY_FACTOR / radius);
|
||||
pt.y = (SIS_SCREEN_HEIGHT >> 1)
|
||||
+ (SIZE)((long)StarShipPtr->ShipInfo.loc.y
|
||||
+ (SIZE)((long)StarShipPtr->loc.y
|
||||
* (DISPLAY_FACTOR >> 1) / radius);
|
||||
|
||||
IPSHIPElementPtr->current.location.x =
|
||||
@@ -821,7 +812,7 @@ spawn_flag_ship (void)
|
||||
void
|
||||
DoMissions (void)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
spawn_flag_ship ();
|
||||
|
||||
@@ -836,14 +827,13 @@ DoMissions (void)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
|
||||
if (StarShipPtr->ShipInfo.crew_level)
|
||||
if (StarShipPtr->crew_level)
|
||||
spawn_ip_group (StarShipPtr);
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+67
-36
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "libs/tasklib.h"
|
||||
#include "libs/log.h"
|
||||
#include "libs/misc.h"
|
||||
|
||||
//#define DEBUG_LOAD
|
||||
|
||||
@@ -133,6 +134,21 @@ read_a16 (void *fp, UWORD *ar, COUNT count)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
LoadEmptyQueue (DECODE_REF fh)
|
||||
{
|
||||
COUNT num_links;
|
||||
|
||||
cread_16 (fh, &num_links);
|
||||
if (num_links)
|
||||
{
|
||||
log_add (log_Error, "LoadEmptyQueue(): BUG: the queue is not empty!");
|
||||
#ifdef DEBUG
|
||||
explode ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
LoadShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
{
|
||||
@@ -142,7 +158,7 @@ LoadShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
|
||||
while (num_links--)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
COUNT Index;
|
||||
BYTE tmpb;
|
||||
@@ -150,26 +166,26 @@ LoadShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
cread_16 (fh, &Index);
|
||||
|
||||
hStarShip = CloneShipFragment (Index, pQueue, 0);
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
|
||||
FragPtr = LockShipFrag (pQueue, hStarShip);
|
||||
|
||||
// Read SHIP_FRAGMENT elements
|
||||
cread_16 (fh, &FragPtr->which_side);
|
||||
cread_8 (fh, &FragPtr->captains_name_index);
|
||||
cread_8 (fh, NULL); /* padding */
|
||||
// Read SHIP_INFO elements
|
||||
cread_16 (fh, &FragPtr->ShipInfo.ship_flags);
|
||||
cread_8 (fh, &FragPtr->ShipInfo.var1);
|
||||
cread_8 (fh, &FragPtr->ShipInfo.var2);
|
||||
cread_16 (fh, &FragPtr->ship_flags);
|
||||
cread_8 (fh, &FragPtr->var1);
|
||||
cread_8 (fh, &FragPtr->var2);
|
||||
// XXX: reading crew as BYTE to maintain savegame compatibility
|
||||
cread_8 (fh, &tmpb);
|
||||
FragPtr->ShipInfo.crew_level = tmpb;
|
||||
FragPtr->crew_level = tmpb;
|
||||
cread_8 (fh, &tmpb);
|
||||
FragPtr->ShipInfo.max_crew = tmpb;
|
||||
cread_8 (fh, &FragPtr->ShipInfo.energy_level);
|
||||
cread_8 (fh, &FragPtr->ShipInfo.max_energy);
|
||||
cread_16 (fh, &FragPtr->ShipInfo.loc.x);
|
||||
cread_16 (fh, &FragPtr->ShipInfo.loc.y);
|
||||
FragPtr->max_crew = tmpb;
|
||||
cread_8 (fh, &FragPtr->energy_level);
|
||||
cread_8 (fh, &FragPtr->max_energy);
|
||||
cread_16 (fh, &FragPtr->loc.x);
|
||||
cread_16 (fh, &FragPtr->loc.y);
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,40 +198,40 @@ LoadRaceQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
|
||||
while (num_links--)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
EXTENDED_SHIP_FRAGMENT *ExtFragPtr;
|
||||
HFLEETINFO hStarShip;
|
||||
FLEET_INFO *FleetPtr;
|
||||
COUNT Index;
|
||||
BYTE tmpb;
|
||||
|
||||
cread_16 (fh, &Index);
|
||||
|
||||
hStarShip = GetStarShipFromIndex (pQueue, Index);
|
||||
ExtFragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (pQueue, hStarShip);
|
||||
FleetPtr = LockFleetInfo (pQueue, hStarShip);
|
||||
|
||||
// Read EXTENDED_SHIP_INFO elements
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.ship_flags);
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.days_left);
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.growth_fract);
|
||||
// Read FLEET_INFO elements
|
||||
cread_16 (fh, &FleetPtr->ship_flags);
|
||||
cread_8 (fh, &FleetPtr->days_left);
|
||||
cread_8 (fh, &FleetPtr->growth_fract);
|
||||
cread_8 (fh, &tmpb);
|
||||
ExtFragPtr->ShipInfo.crew_level = tmpb;
|
||||
FleetPtr->crew_level = tmpb;
|
||||
cread_8 (fh, &tmpb);
|
||||
ExtFragPtr->ShipInfo.max_crew = tmpb;
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.energy_level);
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.max_energy);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.loc.x);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.loc.y);
|
||||
FleetPtr->max_crew = tmpb;
|
||||
cread_8 (fh, &FleetPtr->energy_level);
|
||||
cread_8 (fh, &FleetPtr->max_energy);
|
||||
cread_16 (fh, &FleetPtr->loc.x);
|
||||
cread_16 (fh, &FleetPtr->loc.y);
|
||||
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.actual_strength);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.known_strength);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.x);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.y);
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.growth_err_term);
|
||||
cread_8 (fh, &ExtFragPtr->ShipInfo.func_index);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.x);
|
||||
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.y);
|
||||
cread_16 (fh, &FleetPtr->actual_strength);
|
||||
cread_16 (fh, &FleetPtr->known_strength);
|
||||
cread_16 (fh, &FleetPtr->known_loc.x);
|
||||
cread_16 (fh, &FleetPtr->known_loc.y);
|
||||
cread_8 (fh, &FleetPtr->growth_err_term);
|
||||
cread_8 (fh, &FleetPtr->func_index);
|
||||
cread_16 (fh, &FleetPtr->dest_loc.x);
|
||||
cread_16 (fh, &FleetPtr->dest_loc.y);
|
||||
cread_16 (fh, NULL); /* alignment padding */
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockFleetInfo (pQueue, hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +266,7 @@ LoadEncounter (ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
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 */
|
||||
// XXX: reading crew as BYTE to maintain savegame compatibility
|
||||
cread_8 (fh, &tmpb);
|
||||
ShipInfo->crew_level = tmpb;
|
||||
cread_8 (fh, &tmpb);
|
||||
@@ -263,7 +280,7 @@ LoadEncounter (ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
cread_ptr (fh); /* useless ptr; FRAME melee_icon */
|
||||
}
|
||||
|
||||
// Load the stuff after the SHIP_INFO array:
|
||||
// Load the stuff after the BRIEF_SHIP_INFO array
|
||||
cread_32 (fh, &EncounterPtr->log_x);
|
||||
cread_32 (fh, &EncounterPtr->log_y);
|
||||
}
|
||||
@@ -515,8 +532,22 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
|
||||
GLOBAL (GameClock.TimeCounter) = 0;
|
||||
|
||||
LoadRaceQueue (fh, &GLOBAL (avail_race_q));
|
||||
// START_INTERPLANETARY is only set when saving from Homeworld
|
||||
// encounter screen. When the game is loaded, GENERATE_ORBITAL will
|
||||
// create the encounter anew and populate the npc queue.
|
||||
if (!(NextActivity & START_INTERPLANETARY))
|
||||
{
|
||||
if (NextActivity & START_ENCOUNTER)
|
||||
// load npc queue
|
||||
LoadShipQueue (fh, &GLOBAL (npc_built_ship_q));
|
||||
else if (LOBYTE (NextActivity) == IN_INTERPLANETARY)
|
||||
// load group queue
|
||||
LoadShipQueue (fh, &GLOBAL (npc_built_ship_q));
|
||||
else
|
||||
// XXX: The empty queue read is only needed to maintain
|
||||
// the savegame compatibility
|
||||
LoadEmptyQueue (fh);
|
||||
}
|
||||
LoadShipQueue (fh, &GLOBAL (built_ship_q));
|
||||
|
||||
// Load the game events (compressed)
|
||||
|
||||
+39
-42
@@ -38,16 +38,16 @@ LoadMasterShipList (void (* YieldProcessing)(void))
|
||||
ri = GET_INSTANCE (ARILOU_SHIP_INDEX);
|
||||
rp = GET_PACKAGE (ARILOU_SHIP_INDEX);
|
||||
num_entries = NUM_MELEE_SHIPS;
|
||||
InitQueue (&master_q, num_entries, sizeof (SHIP_FRAGMENT));
|
||||
InitQueue (&master_q, num_entries, sizeof (MASTER_SHIP_INFO));
|
||||
while (num_entries--)
|
||||
{
|
||||
HSTARSHIP hBuiltShip;
|
||||
HMASTERSHIP hBuiltShip;
|
||||
char built_buf[30];
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
SHIP_FRAGMENT *BuiltFragPtr;
|
||||
HMASTERSHIP hStarShip, hNextShip;
|
||||
MASTER_SHIP_INFO *BuiltPtr;
|
||||
RACE_DESC *RDPtr;
|
||||
|
||||
hBuiltShip = Build (&master_q, MAKE_RESOURCE (rp++, rt, ri++));
|
||||
hBuiltShip = AllocLink (&master_q);
|
||||
if (!hBuiltShip)
|
||||
continue;
|
||||
|
||||
@@ -56,25 +56,24 @@ LoadMasterShipList (void (* YieldProcessing)(void))
|
||||
if (YieldProcessing)
|
||||
YieldProcessing ();
|
||||
|
||||
BuiltFragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hBuiltShip);
|
||||
RDPtr = load_ship (BuiltFragPtr->RaceResIndex, FALSE);
|
||||
BuiltPtr = LockMasterShip (&master_q, hBuiltShip);
|
||||
BuiltPtr->RaceResIndex = MAKE_RESOURCE (rp++, rt, ri++);
|
||||
RDPtr = load_ship (BuiltPtr->RaceResIndex, FALSE);
|
||||
if (!RDPtr)
|
||||
{
|
||||
UnlockStarShip (&master_q, hBuiltShip);
|
||||
RemoveQueue (&master_q, hBuiltShip);
|
||||
UnlockMasterShip (&master_q, hBuiltShip);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab a copy of loaded icons, strings and info
|
||||
BuiltFragPtr->ShipInfo = RDPtr->ship_info;
|
||||
// XXX: SHIP_INFO implicitly referenced here
|
||||
BuiltPtr->ShipInfo = RDPtr->ship_info;
|
||||
free_ship (RDPtr, FALSE, FALSE);
|
||||
|
||||
GetStringContents (SetAbsStringTableIndex (
|
||||
BuiltFragPtr->ShipInfo.race_strings, 2
|
||||
BuiltPtr->ShipInfo.race_strings, 2
|
||||
), (STRINGPTR)built_buf, FALSE);
|
||||
UnlockStarShip (&master_q, hBuiltShip);
|
||||
|
||||
RemoveQueue (&master_q, hBuiltShip);
|
||||
UnlockMasterShip (&master_q, hBuiltShip);
|
||||
|
||||
// Insert the ship in the master queue in the right location
|
||||
// to keep the list sorted on the name of the race.
|
||||
@@ -82,14 +81,14 @@ LoadMasterShipList (void (* YieldProcessing)(void))
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
char ship_buf[30];
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
MasterPtr = LockMasterShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (MasterPtr);
|
||||
GetStringContents (SetAbsStringTableIndex (
|
||||
FragPtr->ShipInfo.race_strings, 2
|
||||
MasterPtr->ShipInfo.race_strings, 2
|
||||
), (STRINGPTR)ship_buf, FALSE);
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
UnlockMasterShip (&master_q, hStarShip);
|
||||
|
||||
if (strcmp (built_buf, ship_buf) < 0)
|
||||
break;
|
||||
@@ -101,42 +100,41 @@ LoadMasterShipList (void (* YieldProcessing)(void))
|
||||
void
|
||||
FreeMasterShipList (void)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HMASTERSHIP hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&master_q);
|
||||
hStarShip != 0; hStarShip = hNextShip)
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
MasterPtr = LockMasterShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (MasterPtr);
|
||||
|
||||
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.melee_icon));
|
||||
DestroyDrawable (ReleaseDrawable (FragPtr->ShipInfo.icons));
|
||||
DestroyDrawable (ReleaseDrawable (MasterPtr->ShipInfo.melee_icon));
|
||||
DestroyDrawable (ReleaseDrawable (MasterPtr->ShipInfo.icons));
|
||||
DestroyStringTable (ReleaseStringTable (
|
||||
FragPtr->ShipInfo.race_strings));
|
||||
MasterPtr->ShipInfo.race_strings));
|
||||
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
UnlockMasterShip (&master_q, hStarShip);
|
||||
}
|
||||
|
||||
UninitQueue (&master_q);
|
||||
}
|
||||
|
||||
HSTARSHIP
|
||||
HMASTERSHIP
|
||||
FindMasterShip (DWORD ship_ref)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSTARSHIP hNextShip;
|
||||
HMASTERSHIP hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&master_q); hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
DWORD ref;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
ref = FragPtr->RaceResIndex;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (MasterPtr);
|
||||
ref = MasterPtr->RaceResIndex;
|
||||
UnlockMasterShip (&master_q, hStarShip);
|
||||
|
||||
if (ref == ship_ref)
|
||||
break;
|
||||
@@ -148,20 +146,19 @@ FindMasterShip (DWORD ship_ref)
|
||||
int
|
||||
FindMasterShipIndex (DWORD ship_ref)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSTARSHIP hNextShip;
|
||||
HMASTERSHIP hStarShip, hNextShip;
|
||||
int index;
|
||||
|
||||
for (index = 0, hStarShip = GetHeadLink (&master_q); hStarShip;
|
||||
++index, hStarShip = hNextShip)
|
||||
{
|
||||
DWORD ref;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
ref = FragPtr->RaceResIndex;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hStarShip);
|
||||
hNextShip = _GetSuccLink (MasterPtr);
|
||||
ref = MasterPtr->RaceResIndex;
|
||||
UnlockMasterShip (&master_q, hStarShip);
|
||||
|
||||
if (ref == ship_ref)
|
||||
break;
|
||||
|
||||
@@ -20,13 +20,36 @@
|
||||
#include "races.h"
|
||||
#include "libs/compiler.h"
|
||||
|
||||
typedef HLINK HMASTERSHIP;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HMASTERSHIP pred;
|
||||
HMASTERSHIP succ;
|
||||
|
||||
DWORD RaceResIndex;
|
||||
|
||||
SHIP_INFO ShipInfo;
|
||||
} MASTER_SHIP_INFO;
|
||||
|
||||
extern QUEUE master_q;
|
||||
/* List of all ships present in the game;
|
||||
* queue element is SHIP_FRAGMENT */
|
||||
/* List of ships available in SuperMelee;
|
||||
* queue element is MASTER_SHIP_INFO */
|
||||
|
||||
static inline MASTER_SHIP_INFO *
|
||||
LockMasterShip (const QUEUE *pq, HMASTERSHIP h)
|
||||
{
|
||||
assert (GetLinkSize (pq) == sizeof (MASTER_SHIP_INFO));
|
||||
return (MASTER_SHIP_INFO *) LockLink (pq, h);
|
||||
}
|
||||
|
||||
#define UnlockMasterShip(pq, h) UnlockLink (pq, h)
|
||||
#define FreeMasterShip(pq, h) FreeLink (pq, h)
|
||||
|
||||
extern void LoadMasterShipList (void (* YieldProcessing)(void));
|
||||
extern void FreeMasterShipList (void);
|
||||
extern HSTARSHIP FindMasterShip (DWORD ship_ref);
|
||||
extern HMASTERSHIP FindMasterShip (DWORD ship_ref);
|
||||
extern int FindMasterShipIndex (DWORD ship_ref);
|
||||
|
||||
|
||||
|
||||
+41
-36
@@ -256,56 +256,59 @@ GetShipColumn (int index)
|
||||
return index % NUM_MELEE_COLUMNS;
|
||||
}
|
||||
|
||||
// XXX: Perhaps move this to master.c
|
||||
static COUNT
|
||||
GetShipCostFromIndex (unsigned Index)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
COUNT val;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hStarShip)
|
||||
hMasterShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hMasterShip)
|
||||
return 0;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
val = FragPtr->ShipInfo.ship_cost;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
val = MasterPtr->ShipInfo.ship_cost;
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
// XXX: Perhaps move this to master.c
|
||||
static FRAME
|
||||
GetShipIconsFromIndex (unsigned Index)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
FRAME val;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hStarShip)
|
||||
hMasterShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hMasterShip)
|
||||
return 0;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
val = FragPtr->ShipInfo.icons;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
val = MasterPtr->ShipInfo.icons;
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
// XXX: Perhaps move this to master.c
|
||||
static FRAME
|
||||
GetShipMeleeIconsFromIndex (unsigned Index)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
FRAME val;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hStarShip)
|
||||
hMasterShip = GetStarShipFromIndex (&master_q, Index);
|
||||
if (!hMasterShip)
|
||||
return 0;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
val = FragPtr->ShipInfo.melee_icon;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
val = MasterPtr->ShipInfo.melee_icon;
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
return val;
|
||||
}
|
||||
@@ -991,15 +994,15 @@ DrawMeleeShipStrings (MELEE_STATE *pMS, BYTE NewStarShip)
|
||||
}
|
||||
else
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&master_q, NewStarShip);
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hMasterShip = GetStarShipFromIndex (&master_q, NewStarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
InitShipStatus (&FragPtr->ShipInfo, ~0, NULL);
|
||||
InitShipStatus (&MasterPtr->ShipInfo, ~0, NULL);
|
||||
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
}
|
||||
|
||||
UnbatchGraphics ();
|
||||
@@ -2118,27 +2121,29 @@ BuildAndDrawShipList (MELEE_STATE *pMS)
|
||||
{
|
||||
BYTE row, col;
|
||||
BYTE ship_cost;
|
||||
HSTARSHIP hStarShip, hBuiltShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
HMASTERSHIP hMasterShip;
|
||||
HSTARSHIP hBuiltShip;
|
||||
MASTER_SHIP_INFO *MasterPtr;
|
||||
STARSHIP *BuiltShipPtr;
|
||||
BYTE captains_name_index;
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&master_q, StarShip);
|
||||
FragPtr = (SHIP_FRAGMENT *) LockStarShip (&master_q, hStarShip);
|
||||
hMasterShip = GetStarShipFromIndex (&master_q, StarShip);
|
||||
MasterPtr = LockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
captains_name_index = NameCaptain (&race_q[side],
|
||||
FragPtr->RaceResIndex);
|
||||
hBuiltShip = Build (&race_q[side], FragPtr->RaceResIndex);
|
||||
MasterPtr->RaceResIndex);
|
||||
hBuiltShip = Build (&race_q[side], MasterPtr->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 = FragPtr->ShipInfo.icons;
|
||||
s.frame = MasterPtr->ShipInfo.icons;
|
||||
DrawStamp (&s);
|
||||
|
||||
ship_cost = FragPtr->ShipInfo.ship_cost;
|
||||
UnlockStarShip (&master_q, hStarShip);
|
||||
ship_cost = MasterPtr->ShipInfo.ship_cost;
|
||||
UnlockMasterShip (&master_q, hMasterShip);
|
||||
|
||||
BuiltShipPtr = LockStarShip (&race_q[side], hBuiltShip);
|
||||
BuiltShipPtr->index = index;
|
||||
|
||||
+14
-13
@@ -330,8 +330,7 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
|
||||
else
|
||||
{
|
||||
// Full game.
|
||||
HSTARSHIP hStarShip;
|
||||
STARSHIP *SPtr;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
if (LastStarShipPtr == 0)
|
||||
@@ -349,21 +348,21 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
|
||||
{
|
||||
// Select the next ship for the computer.
|
||||
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
if (FragPtr->ShipInfo.crew_level == INFINITE_FLEET)
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
if (FragPtr->crew_level == INFINITE_FLEET)
|
||||
{
|
||||
// Infinite number of ships.
|
||||
battle_counter[1]++;
|
||||
}
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QUEUE *pQueue;
|
||||
HSTARSHIP hNextShip;
|
||||
HSHIPFRAG hNextShip;
|
||||
|
||||
if (which_player == 0)
|
||||
pQueue = &GLOBAL (built_ship_q);
|
||||
@@ -374,18 +373,20 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
|
||||
for (hStarShip = GetHeadLink (pQueue);
|
||||
hStarShip != 0; hStarShip = hNextShip)
|
||||
{
|
||||
STARSHIP *SPtr;
|
||||
|
||||
SPtr = LockStarShip (&race_q[which_player], hBattleShip);
|
||||
hNextShip = _GetSuccLink (SPtr);
|
||||
UnlockStarShip (&race_q[which_player], hBattleShip);
|
||||
hBattleShip = hNextShip;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
|
||||
FragPtr = LockShipFrag (pQueue, hStarShip);
|
||||
if (SPtr == LastStarShipPtr)
|
||||
{
|
||||
if (FragPtr->ShipInfo.crew_level != INFINITE_FLEET)
|
||||
if (FragPtr->crew_level != INFINITE_FLEET)
|
||||
{
|
||||
/* Record crew left after the battle */
|
||||
FragPtr->ShipInfo.crew_level = SPtr->crew_level;
|
||||
FragPtr->crew_level = SPtr->crew_level;
|
||||
if (GLOBAL (CurrentActivity) & IN_BATTLE)
|
||||
SPtr->RaceResIndex = 0;
|
||||
// deactivates the ship
|
||||
@@ -396,17 +397,17 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
|
||||
/* XXX: Note that if Syreen had a homeworld you could
|
||||
* fight, all Syreen ships there would be crewed to
|
||||
* the maximum, instead of the normal level */
|
||||
SPtr->crew_level = FragPtr->ShipInfo.max_crew;
|
||||
SPtr->crew_level = FragPtr->max_crew;
|
||||
SPtr->which_side = 1 << which_player;
|
||||
SPtr->captains_name_index = PickCaptainName ();
|
||||
|
||||
battle_counter[1]++;
|
||||
}
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
break;
|
||||
}
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
}
|
||||
|
||||
if (which_player == 0)
|
||||
|
||||
@@ -226,7 +226,7 @@ UseCaster (void)
|
||||
|
||||
{
|
||||
BOOLEAN FoundIlwrath;
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
FoundIlwrath = (BOOLEAN)(CurStarDescPtr->Index == ILWRATH_DEFINED);
|
||||
// In the Ilwrath home system?
|
||||
@@ -237,11 +237,9 @@ UseCaster (void)
|
||||
// Ilwrath ship is in the system.
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FoundIlwrath = (BOOLEAN)(
|
||||
GET_RACE_ID (FragPtr) == ILWRATH_SHIP);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FoundIlwrath = (GET_RACE_ID (FragPtr) == ILWRATH_SHIP);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
if (FoundIlwrath)
|
||||
|
||||
@@ -29,7 +29,7 @@ GenerateColony (BYTE control)
|
||||
{
|
||||
case INIT_NPCS:
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
GLOBAL (BattleGroupRef) = GET_GAME_STATE_32 (COLONY_GRPOFFS0);
|
||||
if (GLOBAL (BattleGroupRef) == 0)
|
||||
@@ -48,15 +48,14 @@ GenerateColony (BYTE control)
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
SET_GROUP_MISSION (FragPtr, IN_ORBIT);
|
||||
SET_GROUP_LOC (FragPtr, 0 + 1); /* orbitting colony */
|
||||
SET_GROUP_DEST (FragPtr, 0 + 1); /* orbitting colony */
|
||||
FragPtr->ShipInfo.loc.x = 0;
|
||||
FragPtr->ShipInfo.loc.y = 0;
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr->loc.x = 0;
|
||||
FragPtr->loc.y = 0;
|
||||
FragPtr->group_counter = 0;
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ ZapToUrquanEncounter (void)
|
||||
{
|
||||
SIZE dx, dy;
|
||||
ENCOUNTER *EncounterPtr;
|
||||
HSTARSHIP hStarShip;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hStarShip;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
BRIEF_SHIP_INFO *BSIPtr;
|
||||
|
||||
LockEncounter (hEncounter, &EncounterPtr);
|
||||
@@ -49,25 +49,24 @@ ZapToUrquanEncounter (void)
|
||||
InsertEncounter (hEncounter, GetHeadEncounter ());
|
||||
|
||||
hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), URQUAN_SHIP);
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
EncounterPtr->origin = TemplatePtr->ShipInfo.loc;
|
||||
EncounterPtr->radius = TemplatePtr->ShipInfo.actual_strength;
|
||||
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;
|
||||
// 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;
|
||||
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);
|
||||
GLOBAL_SIS (log_x) = EncounterPtr->log_x;
|
||||
GLOBAL_SIS (log_y) = EncounterPtr->log_y;
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
|
||||
{
|
||||
#define LOST_DAYS 15
|
||||
|
||||
@@ -32,7 +32,7 @@ BuildUrquanGuard (void)
|
||||
BYTE ship1, ship2;
|
||||
BYTE b0, b1;
|
||||
POINT org;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
GLOBAL (BattleGroupRef) = GET_GAME_STATE_32 (SAMATRA_GRPOFFS0);
|
||||
|
||||
@@ -80,20 +80,17 @@ BuildUrquanGuard (void)
|
||||
if (b1 % (FULL_CIRCLE / NUM_URQUAN_GUARDS1) == 0)
|
||||
b1 += FULL_CIRCLE / (NUM_URQUAN_GUARDS0 + NUM_URQUAN_GUARDS1);
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
SET_GROUP_MISSION (FragPtr, ON_STATION | IGNORE_FLAGSHIP);
|
||||
SET_GROUP_LOC (FragPtr, 0);
|
||||
SET_GROUP_DEST (FragPtr, 4 + 1);
|
||||
SET_ORBIT_LOC (FragPtr,
|
||||
NORMALIZE_FACING (ANGLE_TO_FACING (b1)));
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
FragPtr->ShipInfo.loc.x = org.x
|
||||
+ COSINE (b1, STATION_RADIUS);
|
||||
FragPtr->ShipInfo.loc.y = org.y
|
||||
+ SINE (b1, STATION_RADIUS);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr->group_counter = 0;
|
||||
FragPtr->loc.x = org.x + COSINE (b1, STATION_RADIUS);
|
||||
FragPtr->loc.y = org.y + SINE (b1, STATION_RADIUS);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
|
||||
@@ -103,20 +100,17 @@ BuildUrquanGuard (void)
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
SET_GROUP_MISSION (FragPtr, ON_STATION | IGNORE_FLAGSHIP);
|
||||
SET_GROUP_LOC (FragPtr, 0);
|
||||
SET_GROUP_DEST (FragPtr, 4 + 1);
|
||||
SET_ORBIT_LOC (FragPtr,
|
||||
NORMALIZE_FACING (ANGLE_TO_FACING (b1)));
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
FragPtr->ShipInfo.loc.x = org.x
|
||||
+ COSINE (b1, STATION_RADIUS);
|
||||
FragPtr->ShipInfo.loc.y = org.y
|
||||
+ SINE (b1, STATION_RADIUS);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr->group_counter = 0;
|
||||
FragPtr->loc.x = org.x + COSINE (b1, STATION_RADIUS);
|
||||
FragPtr->loc.y = org.y + SINE (b1, STATION_RADIUS);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
}
|
||||
@@ -140,7 +134,7 @@ GenerateSamatra (BYTE control)
|
||||
EncounterRace = -1; // Do not want guards to chase the player
|
||||
{
|
||||
BOOLEAN GuardEngaged;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
GuardEngaged = FALSE;
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
|
||||
@@ -149,8 +143,8 @@ GenerateSamatra (BYTE control)
|
||||
BYTE task;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
|
||||
task = GET_GROUP_MISSION (FragPtr);
|
||||
@@ -163,13 +157,13 @@ GenerateSamatra (BYTE control)
|
||||
else if (task & REFORM_GROUP)
|
||||
{
|
||||
task &= ~REFORM_GROUP;
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
FragPtr->group_counter = 0;
|
||||
SET_GROUP_MISSION (FragPtr, task);
|
||||
|
||||
GuardEngaged = TRUE;
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
if (GuardEngaged)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
static void
|
||||
check_old_shofixti (void)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
if (GLOBAL (BattleGroupRef)
|
||||
&& (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q)))
|
||||
@@ -34,15 +34,14 @@ check_old_shofixti (void)
|
||||
BYTE task;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
task = GET_GROUP_MISSION (FragPtr);
|
||||
|
||||
SET_GROUP_MISSION (FragPtr,
|
||||
FLEE | IGNORE_FLAGSHIP | (task & REFORM_GROUP));
|
||||
SET_GROUP_DEST (FragPtr, 0);
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ GenerateShofixti (BYTE control)
|
||||
if (GLOBAL (BattleGroupRef) == 0
|
||||
|| !GetGroupInfo (GLOBAL (BattleGroupRef), GROUP_INIT_IP))
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
if (GLOBAL (BattleGroupRef) == 0)
|
||||
GLOBAL (BattleGroupRef) = ~0L;
|
||||
@@ -70,13 +69,13 @@ GenerateShofixti (BYTE control)
|
||||
&GLOBAL (npc_built_ship_q), 1);
|
||||
if (hStarShip)
|
||||
{ /* Set old Shofixti name; his brother if Tanaka died */
|
||||
SHIP_FRAGMENT *FragPtr = (SHIP_FRAGMENT *) LockStarShip (
|
||||
SHIP_FRAGMENT *FragPtr = LockShipFrag (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
/* Name Tanaka or Katana (+1) */
|
||||
FragPtr->captains_name_index = NAME_OFFSET +
|
||||
NUM_CAPTAINS_NAMES +
|
||||
(GET_GAME_STATE (SHOFIXTI_KIA) & 1);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
GLOBAL (BattleGroupRef) = PutGroupInfo (
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
static int
|
||||
init_probe (void)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
if (!GET_GAME_STATE (PROBE_MESSAGE_DELIVERED)
|
||||
&& GetGroupInfo (GLOBAL (BattleGroupRef), GROUP_INIT_IP)
|
||||
@@ -41,14 +41,14 @@ init_probe (void)
|
||||
{
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
SET_GROUP_MISSION (FragPtr, IN_ORBIT);
|
||||
SET_GROUP_LOC (FragPtr, 2 + 1); /* orbitting earth */
|
||||
SET_GROUP_DEST (FragPtr, 2 + 1); /* orbitting earth */
|
||||
FragPtr->ShipInfo.loc.x = FragPtr->ShipInfo.loc.y = 0;
|
||||
FragPtr->ShipInfo.group_counter = 0;
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr->loc.x = 0;
|
||||
FragPtr->loc.y = 0;
|
||||
FragPtr->group_counter = 0;
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
static void
|
||||
check_scout (void)
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
if (GLOBAL (BattleGroupRef)
|
||||
&& (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q))))
|
||||
@@ -37,8 +37,7 @@ check_scout (void)
|
||||
BYTE task;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
task = GET_GROUP_MISSION (FragPtr);
|
||||
|
||||
if (task & REFORM_GROUP)
|
||||
@@ -48,7 +47,7 @@ check_scout (void)
|
||||
SET_GROUP_DEST (FragPtr, 0);
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -181,15 +181,11 @@ DrawAutoPilot (POINT *pDstPt)
|
||||
}
|
||||
|
||||
static void
|
||||
GetSphereRect (EXTENDED_SHIP_FRAGMENT *StarShipPtr, RECT *pRect,
|
||||
RECT *pRepairRect)
|
||||
GetSphereRect (FLEET_INFO *FleetPtr, RECT *pRect, RECT *pRepairRect)
|
||||
{
|
||||
long diameter;
|
||||
|
||||
diameter = (long)(
|
||||
StarShipPtr->ShipInfo.known_strength
|
||||
* SPHERE_RADIUS_INCREMENT
|
||||
);
|
||||
diameter = (long)(FleetPtr->known_strength * SPHERE_RADIUS_INCREMENT);
|
||||
pRect->extent.width = UNIVERSE_TO_DISPX (diameter)
|
||||
- UNIVERSE_TO_DISPX (0);
|
||||
if (pRect->extent.width < 0)
|
||||
@@ -203,12 +199,8 @@ GetSphereRect (EXTENDED_SHIP_FRAGMENT *StarShipPtr, RECT *pRect,
|
||||
else if (pRect->extent.height == 0)
|
||||
pRect->extent.height = 1;
|
||||
|
||||
pRect->corner.x = UNIVERSE_TO_DISPX (
|
||||
StarShipPtr->ShipInfo.known_loc.x
|
||||
);
|
||||
pRect->corner.y = UNIVERSE_TO_DISPY (
|
||||
StarShipPtr->ShipInfo.known_loc.y
|
||||
);
|
||||
pRect->corner.x = UNIVERSE_TO_DISPX (FleetPtr->known_loc.x);
|
||||
pRect->corner.y = UNIVERSE_TO_DISPY (FleetPtr->known_loc.y);
|
||||
pRect->corner.x -= pRect->extent.width >> 1;
|
||||
pRect->corner.y -= pRect->extent.height >> 1;
|
||||
|
||||
@@ -221,9 +213,7 @@ GetSphereRect (EXTENDED_SHIP_FRAGMENT *StarShipPtr, RECT *pRect,
|
||||
t.baseline.x = pRect->corner.x + (pRect->extent.width >> 1);
|
||||
t.baseline.y = pRect->corner.y + (pRect->extent.height >> 1) - 1;
|
||||
t.align = ALIGN_CENTER;
|
||||
locString = SetAbsStringTableIndex (
|
||||
StarShipPtr->ShipInfo.race_strings, 1
|
||||
);
|
||||
locString = SetAbsStringTableIndex (FleetPtr->race_strings, 1);
|
||||
t.CharCount = GetStringLength (locString);
|
||||
t.pStr = (UNICODE *)GetStringAddress (locString);
|
||||
TextRect (&t, pRepairRect, NULL);
|
||||
@@ -363,7 +353,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
|
||||
if (which_space <= 1)
|
||||
{
|
||||
COUNT index;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
static const COLOR race_colors[] =
|
||||
{
|
||||
RACE_COLORS
|
||||
@@ -373,17 +363,16 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
|
||||
hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip != 0; ++index, hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if (StarShipPtr->ShipInfo.known_strength)
|
||||
if (FleetPtr->known_strength)
|
||||
{
|
||||
RECT repair_r;
|
||||
|
||||
GetSphereRect (StarShipPtr, &r, &repair_r);
|
||||
GetSphereRect (FleetPtr, &r, &repair_r);
|
||||
if (r.corner.x < SIS_SCREEN_WIDTH
|
||||
&& r.corner.y < SIS_SCREEN_HEIGHT
|
||||
&& r.corner.x + r.extent.width > 0
|
||||
@@ -411,8 +400,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
|
||||
t.baseline.y = r.corner.y + (r.extent.height >> 1) - 1;
|
||||
t.align = ALIGN_CENTER;
|
||||
locString = SetAbsStringTableIndex (
|
||||
StarShipPtr->ShipInfo.race_strings, 1
|
||||
);
|
||||
FleetPtr->race_strings, 1);
|
||||
t.CharCount = GetStringLength (locString);
|
||||
t.pStr = (UNICODE *)GetStringAddress (locString);
|
||||
TextRect (&t, &r, NULL);
|
||||
@@ -448,7 +436,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1384,7 +1372,7 @@ UpdateMap (void)
|
||||
BYTE ButtonState, VisibleChange;
|
||||
BOOLEAN MapDrawn, Interrupted;
|
||||
COUNT index;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
FlushInput ();
|
||||
ButtonState = 1; /* assume a button down */
|
||||
@@ -1394,11 +1382,10 @@ UpdateMap (void)
|
||||
hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip; ++index, hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if (ButtonState)
|
||||
{
|
||||
@@ -1410,15 +1397,13 @@ UpdateMap (void)
|
||||
)))
|
||||
MapDrawn = TRUE;
|
||||
|
||||
if (StarShipPtr->ShipInfo.known_strength)
|
||||
if (FleetPtr->known_strength)
|
||||
{
|
||||
SIZE dx, dy, delta;
|
||||
RECT r, last_r, temp_r0, temp_r1;
|
||||
|
||||
dx = StarShipPtr->ShipInfo.loc.x
|
||||
- StarShipPtr->ShipInfo.known_loc.x;
|
||||
dy = StarShipPtr->ShipInfo.loc.y
|
||||
- StarShipPtr->ShipInfo.known_loc.y;
|
||||
dx = FleetPtr->loc.x - FleetPtr->known_loc.x;
|
||||
dy = FleetPtr->loc.y - FleetPtr->known_loc.y;
|
||||
if (dx || dy)
|
||||
{
|
||||
SIZE xincr, yincr,
|
||||
@@ -1455,7 +1440,7 @@ UpdateMap (void)
|
||||
MapDrawn = TRUE;
|
||||
}
|
||||
|
||||
GetSphereRect (StarShipPtr, &temp_r0, &last_r);
|
||||
GetSphereRect (FleetPtr, &temp_r0, &last_r);
|
||||
++last_r.extent.width;
|
||||
++last_r.extent.height;
|
||||
VisibleChange = FALSE;
|
||||
@@ -1465,15 +1450,15 @@ UpdateMap (void)
|
||||
{
|
||||
if ((xerror -= dx) <= 0)
|
||||
{
|
||||
StarShipPtr->ShipInfo.known_loc.x += xincr;
|
||||
FleetPtr->known_loc.x += xincr;
|
||||
xerror += cycle;
|
||||
}
|
||||
if ((yerror -= dy) <= 0)
|
||||
{
|
||||
StarShipPtr->ShipInfo.known_loc.y += yincr;
|
||||
FleetPtr->known_loc.y += yincr;
|
||||
yerror += cycle;
|
||||
}
|
||||
GetSphereRect (StarShipPtr, &temp_r1, &r);
|
||||
GetSphereRect (FleetPtr, &temp_r1, &r);
|
||||
} while (delta--
|
||||
&& ((delta & 0x1F)
|
||||
|| (temp_r0.corner.x == temp_r1.corner.x
|
||||
@@ -1505,11 +1490,10 @@ UpdateMap (void)
|
||||
RepairMap ((COUNT)~0, &last_r, &r);
|
||||
|
||||
DoneSphereMove:
|
||||
StarShipPtr->ShipInfo.known_loc = StarShipPtr->ShipInfo.loc;
|
||||
FleetPtr->known_loc = FleetPtr->loc;
|
||||
}
|
||||
|
||||
delta = StarShipPtr->ShipInfo.actual_strength
|
||||
- StarShipPtr->ShipInfo.known_strength;
|
||||
delta = FleetPtr->actual_strength - FleetPtr->known_strength;
|
||||
if (delta)
|
||||
{
|
||||
if (!MapDrawn)
|
||||
@@ -1527,7 +1511,7 @@ DoneSphereMove:
|
||||
}
|
||||
--delta;
|
||||
|
||||
GetSphereRect (StarShipPtr, &temp_r0, &last_r);
|
||||
GetSphereRect (FleetPtr, &temp_r0, &last_r);
|
||||
++last_r.extent.width;
|
||||
++last_r.extent.height;
|
||||
VisibleChange = FALSE;
|
||||
@@ -1535,8 +1519,8 @@ DoneSphereMove:
|
||||
{
|
||||
do
|
||||
{
|
||||
StarShipPtr->ShipInfo.known_strength += dx;
|
||||
GetSphereRect (StarShipPtr, &temp_r1, &r);
|
||||
FleetPtr->known_strength += dx;
|
||||
GetSphereRect (FleetPtr, &temp_r1, &r);
|
||||
} while (delta--
|
||||
&& ((delta & 0xF)
|
||||
|| temp_r0.extent.height == temp_r1.extent.height));
|
||||
@@ -1565,12 +1549,11 @@ DoneSphereMove:
|
||||
RepairMap ((COUNT)~0, &last_r, &r);
|
||||
|
||||
DoneSphereGrowth:
|
||||
StarShipPtr->ShipInfo.known_strength =
|
||||
StarShipPtr->ShipInfo.actual_strength;
|
||||
FleetPtr->known_strength = FleetPtr->actual_strength;
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@ flash_ship_task (void *data)
|
||||
|
||||
LockMutex (GraphicsLock);
|
||||
s.origin = pMenuState->first_item;
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame);
|
||||
s.frame = StarShipPtr->ShipInfo.icons;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q),
|
||||
(HSTARSHIP)pMenuState->CurFrame);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
(HSHIPFRAG)pMenuState->CurFrame);
|
||||
s.frame = StarShipPtr->icons;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q),
|
||||
(HSHIPFRAG)pMenuState->CurFrame);
|
||||
OldContext = SetContext (StatusContext);
|
||||
if (c >= BUILD_COLOR (MAKE_RGB15 (0x1F, 0x19, 0x19), 0x24))
|
||||
c = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x00, 0x00), 0x24);
|
||||
@@ -67,11 +67,11 @@ flash_ship_task (void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HSTARSHIP
|
||||
static HSHIPFRAG
|
||||
MatchSupportShip (MENU_STATE *pMS)
|
||||
{
|
||||
POINT *pship_pos;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)),
|
||||
pship_pos = (POINT*)pMS->flash_frame0;
|
||||
@@ -79,18 +79,17 @@ MatchSupportShip (MENU_STATE *pMS)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
if (pship_pos->x == pMS->first_item.x
|
||||
&& pship_pos->y == pMS->first_item.y)
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
return hStarShip;
|
||||
}
|
||||
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -101,34 +100,31 @@ DeltaSupportCrew (SIZE crew_delta)
|
||||
{
|
||||
BOOLEAN ret = FALSE;
|
||||
UNICODE buf[40];
|
||||
HSTARSHIP hTemplate;
|
||||
HFLEETINFO hTemplate;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
(HSHIPFRAG)pMenuState->CurFrame);
|
||||
hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
GET_RACE_ID (StarShipPtr));
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hTemplate);
|
||||
TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hTemplate);
|
||||
|
||||
StarShipPtr->ShipInfo.crew_level += crew_delta;
|
||||
StarShipPtr->crew_level += crew_delta;
|
||||
|
||||
if (StarShipPtr->ShipInfo.crew_level == 0)
|
||||
StarShipPtr->ShipInfo.crew_level = 1;
|
||||
else if (StarShipPtr->ShipInfo.crew_level >
|
||||
TemplatePtr->ShipInfo.crew_level &&
|
||||
if (StarShipPtr->crew_level == 0)
|
||||
StarShipPtr->crew_level = 1;
|
||||
else if (StarShipPtr->crew_level > TemplatePtr->crew_level &&
|
||||
crew_delta > 0)
|
||||
StarShipPtr->ShipInfo.crew_level -= crew_delta;
|
||||
StarShipPtr->crew_level -= crew_delta;
|
||||
else
|
||||
{
|
||||
if (StarShipPtr->ShipInfo.crew_level >=
|
||||
TemplatePtr->ShipInfo.crew_level)
|
||||
sprintf (buf, "%u", StarShipPtr->ShipInfo.crew_level);
|
||||
if (StarShipPtr->crew_level >= TemplatePtr->crew_level)
|
||||
sprintf (buf, "%u", StarShipPtr->crew_level);
|
||||
else
|
||||
sprintf (buf, "%u/%u",
|
||||
StarShipPtr->ShipInfo.crew_level,
|
||||
TemplatePtr->ShipInfo.crew_level);
|
||||
StarShipPtr->crew_level,
|
||||
TemplatePtr->crew_level);
|
||||
|
||||
DrawStatusMessage (buf);
|
||||
DeltaSISGauges (-crew_delta, 0, 0);
|
||||
@@ -146,8 +142,8 @@ DeltaSupportCrew (SIZE crew_delta)
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hTemplate);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMenuState->CurFrame);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -172,10 +168,10 @@ RosterCleanup (MENU_STATE *pMS)
|
||||
|
||||
SetContext (StatusContext);
|
||||
s.origin = pMS->first_item;
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), (HSTARSHIP)pMS->CurFrame);
|
||||
s.frame = StarShipPtr->ShipInfo.icons;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), (HSTARSHIP)pMS->CurFrame);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
(HSHIPFRAG)pMS->CurFrame);
|
||||
s.frame = StarShipPtr->icons;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame);
|
||||
if (!(pMS->CurState & SHIP_TOGGLE))
|
||||
DrawStamp (&s);
|
||||
else
|
||||
@@ -345,10 +341,10 @@ DoModifyRoster (MENU_STATE *pMS)
|
||||
LockMutex (GraphicsLock);
|
||||
SetContext (StatusContext);
|
||||
s.origin = pMS->first_item;
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), (HSTARSHIP)pMS->CurFrame);
|
||||
s.frame = StarShipPtr->ShipInfo.icons;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), (HSTARSHIP)pMS->CurFrame);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
(HSHIPFRAG)pMS->CurFrame);
|
||||
s.frame = StarShipPtr->icons;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame);
|
||||
DrawStamp (&s);
|
||||
SelectSupport:
|
||||
pship_pos = (POINT*)pMS->flash_frame1;
|
||||
|
||||
@@ -760,7 +760,7 @@ PickPlanetSide (MENU_STATE *pMS)
|
||||
if (GET_GAME_STATE (FOUND_PLUTO_SPATHI) == 1)
|
||||
{
|
||||
/* Create Fwiffo group and go into comm with it */
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
if (pMenuState->flash_task)
|
||||
{
|
||||
@@ -781,12 +781,12 @@ PickPlanetSide (MENU_STATE *pMS)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT *) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (npc_built_ship_q),
|
||||
hStarShip);
|
||||
// Name Fwiffo
|
||||
StarShipPtr->captains_name_index = NAME_OFFSET +
|
||||
NUM_CAPTAINS_NAMES;
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
SaveFlagshipState ();
|
||||
|
||||
+125
-74
@@ -133,17 +133,13 @@ typedef struct
|
||||
/* Also: group_id */
|
||||
POINT loc;
|
||||
|
||||
/* The fields above this line are included in queues in savegames,
|
||||
* All fields, including those below, are saved in ENCOUNTER structures
|
||||
* in savegames. The latter was probably not supposed to happen.
|
||||
*/
|
||||
|
||||
STRING race_strings;
|
||||
FRAME icons;
|
||||
FRAME melee_icon;
|
||||
#define INFINITE_FLEET ((COUNT) ~0)
|
||||
} SHIP_INFO;
|
||||
|
||||
// XXX: TODO: remove these
|
||||
#define ship_cost var1
|
||||
#define group_counter ship_flags
|
||||
|
||||
@@ -159,68 +155,26 @@ enum
|
||||
};
|
||||
#define MAX_REVOLUTIONS 5
|
||||
|
||||
#define GET_RACE_ID(s) ((s)->ShipInfo.var1)
|
||||
#define SET_RACE_ID(s,v) ((s)->ShipInfo.var1 = (v))
|
||||
#define GET_GROUP_LOC(s) LONIBBLE ((s)->ShipInfo.var2)
|
||||
#define SET_GROUP_LOC(s,v) ((s)->ShipInfo.var2 = \
|
||||
MAKE_BYTE ((v), HINIBBLE ((s)->ShipInfo.var2)))
|
||||
#define GET_GROUP_MISSION(s) HINIBBLE ((s)->ShipInfo.var2)
|
||||
#define SET_GROUP_MISSION(s,v) ((s)->ShipInfo.var2 = \
|
||||
MAKE_BYTE (LONIBBLE ((s)->ShipInfo.var2), (v)))
|
||||
#define GET_GROUP_DEST(s) LONIBBLE ((s)->ShipInfo.energy_level)
|
||||
#define SET_GROUP_DEST(s,v) ((s)->ShipInfo.energy_level = \
|
||||
MAKE_BYTE ((v), HINIBBLE ((s)->ShipInfo.energy_level)))
|
||||
#define GET_ORBIT_LOC(s) HINIBBLE ((s)->ShipInfo.energy_level)
|
||||
#define SET_ORBIT_LOC(s,v) ((s)->ShipInfo.energy_level = \
|
||||
MAKE_BYTE (LONIBBLE ((s)->ShipInfo.energy_level), (v)))
|
||||
#define GET_GROUP_ID(s) ((s)->ShipInfo.max_energy)
|
||||
#define SET_GROUP_ID(s,v) ((s)->ShipInfo.max_energy = (v))
|
||||
#define GET_RACE_ID(s) ((s)->var1)
|
||||
#define SET_RACE_ID(s,v) ((s)->var1 = (v))
|
||||
#define GET_GROUP_LOC(s) LONIBBLE ((s)->var2)
|
||||
#define SET_GROUP_LOC(s,v) ((s)->var2 = \
|
||||
MAKE_BYTE ((v), HINIBBLE ((s)->var2)))
|
||||
#define GET_GROUP_MISSION(s) HINIBBLE ((s)->var2)
|
||||
#define SET_GROUP_MISSION(s,v) ((s)->var2 = \
|
||||
MAKE_BYTE (LONIBBLE ((s)->var2), (v)))
|
||||
#define GET_GROUP_DEST(s) LONIBBLE ((s)->energy_level)
|
||||
#define SET_GROUP_DEST(s,v) ((s)->energy_level = \
|
||||
MAKE_BYTE ((v), HINIBBLE ((s)->energy_level)))
|
||||
#define GET_ORBIT_LOC(s) HINIBBLE ((s)->energy_level)
|
||||
#define SET_ORBIT_LOC(s,v) ((s)->energy_level = \
|
||||
MAKE_BYTE (LONIBBLE ((s)->energy_level), (v)))
|
||||
#define GET_GROUP_ID(s) ((s)->max_energy)
|
||||
#define SET_GROUP_ID(s,v) ((s)->max_energy = (v))
|
||||
|
||||
#define STATION_RADIUS 1600
|
||||
#define ORBIT_RADIUS 2400
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD ship_flags;
|
||||
BYTE days_left;
|
||||
/* Days left before the fleet reachers 'dest_loc'. */
|
||||
BYTE growth_fract;
|
||||
COUNT crew_level;
|
||||
COUNT max_crew;
|
||||
BYTE energy_level;
|
||||
BYTE max_energy;
|
||||
POINT loc;
|
||||
/* Location of the fleet (center) */
|
||||
|
||||
STRING race_strings;
|
||||
/* Race specific strings, see doc/devel/racestrings. */
|
||||
FRAME icons;
|
||||
FRAME melee_icon;
|
||||
|
||||
/* -== The fields below this line are included in savegames. ==- */
|
||||
|
||||
COUNT actual_strength;
|
||||
/* Measure for the size of the sphere of influence.
|
||||
* 0 if there is none and no ships will be generated.
|
||||
* '(COUNT) ~0' if there is none, and the ship generation
|
||||
* is handled separately. */
|
||||
COUNT known_strength;
|
||||
/* Measure for the size of the sphere of influence when last
|
||||
* checked the starmap.
|
||||
* 0 if the race's SoI is not known. */
|
||||
POINT known_loc;
|
||||
/* Location of the SoI (center) when last checked
|
||||
* the starmap. */
|
||||
|
||||
BYTE growth_err_term;
|
||||
BYTE func_index;
|
||||
/* Function index defined in clock.h (the same as in SetEvent())
|
||||
* for the function to call when the fleet reaches 'dest_loc'.
|
||||
* '(BYTE) ~0' means no function to call. */
|
||||
POINT dest_loc;
|
||||
/* Location to which the fleet (center) is moving. */
|
||||
} EXTENDED_SHIP_INFO;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FRAME ship[NUM_VIEWS];
|
||||
@@ -304,35 +258,132 @@ typedef struct
|
||||
COUNT ShipFacing _ALIGNED_ON(sizeof (COUNT));
|
||||
} STARSHIP;
|
||||
|
||||
static inline STARSHIP *
|
||||
LockStarShip (const QUEUE *pq, HSTARSHIP h)
|
||||
{
|
||||
assert (GetLinkSize (pq) == sizeof (STARSHIP));
|
||||
return (STARSHIP *) LockLink (pq, h);
|
||||
}
|
||||
|
||||
#define UnlockStarShip(pq, h) UnlockLink (pq, h)
|
||||
#define FreeStarShip(pq, h) FreeLink (pq, h)
|
||||
|
||||
|
||||
typedef HLINK HSHIPFRAG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HSTARSHIP pred;
|
||||
HSTARSHIP succ;
|
||||
HSHIPFRAG pred;
|
||||
HSHIPFRAG succ;
|
||||
|
||||
DWORD RaceResIndex;
|
||||
|
||||
COUNT which_side;
|
||||
BYTE captains_name_index;
|
||||
|
||||
SHIP_INFO ShipInfo;
|
||||
#if 0
|
||||
// XXX: new fields to replace var1 and var2
|
||||
// var1:
|
||||
BYTE race_id;
|
||||
BYTE ship_cost;
|
||||
// var2: datatypes?
|
||||
BYTE fleet_strength;
|
||||
BYTE index;
|
||||
#endif
|
||||
|
||||
UWORD ship_flags;
|
||||
/* Also: group_counter */
|
||||
BYTE var1;
|
||||
/* Also: ship_cost, race_id */
|
||||
BYTE var2;
|
||||
/* 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. */
|
||||
COUNT max_crew;
|
||||
BYTE energy_level;
|
||||
/* Also: group destination and orbit loc, */
|
||||
BYTE max_energy;
|
||||
/* Also: group_id */
|
||||
POINT loc;
|
||||
|
||||
STRING race_strings;
|
||||
FRAME icons;
|
||||
FRAME melee_icon;
|
||||
|
||||
} SHIP_FRAGMENT;
|
||||
|
||||
static inline SHIP_FRAGMENT *
|
||||
LockShipFrag (const QUEUE *pq, HSHIPFRAG h)
|
||||
{
|
||||
assert (GetLinkSize (pq) == sizeof (SHIP_FRAGMENT));
|
||||
return (SHIP_FRAGMENT *) LockLink (pq, h);
|
||||
}
|
||||
|
||||
#define UnlockShipFrag(pq, h) UnlockLink (pq, h)
|
||||
#define FreeShipFrag(pq, h) FreeLink (pq, h)
|
||||
|
||||
|
||||
typedef HLINK HFLEETINFO;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LINK elements; must be first
|
||||
HSTARSHIP pred;
|
||||
HSTARSHIP succ;
|
||||
HFLEETINFO pred;
|
||||
HFLEETINFO succ;
|
||||
|
||||
DWORD RaceResIndex;
|
||||
|
||||
EXTENDED_SHIP_INFO ShipInfo;
|
||||
} EXTENDED_SHIP_FRAGMENT;
|
||||
UWORD ship_flags;
|
||||
BYTE days_left;
|
||||
/* Days left before the fleet reachers 'dest_loc'. */
|
||||
BYTE growth_fract;
|
||||
COUNT crew_level;
|
||||
COUNT max_crew;
|
||||
BYTE energy_level;
|
||||
BYTE max_energy;
|
||||
POINT loc;
|
||||
/* Location of the fleet (center) */
|
||||
|
||||
#define AllocStarShip(pq) AllocLink (pq)
|
||||
#define LockStarShip(pq,h) (STARSHIP*)LockLink (pq, h)
|
||||
#define UnlockStarShip(pq,h) UnlockLink (pq, h)
|
||||
#define FreeStarShip(pq,h) FreeLink (pq, h)
|
||||
STRING race_strings;
|
||||
/* Race specific strings, see doc/devel/racestrings. */
|
||||
FRAME icons;
|
||||
FRAME melee_icon;
|
||||
|
||||
COUNT actual_strength;
|
||||
/* Measure for the size of the sphere of influence.
|
||||
* 0 if there is none and no ships will be generated.
|
||||
* '(COUNT) ~0' if there is none, and the ship generation
|
||||
* is handled separately. */
|
||||
COUNT known_strength;
|
||||
/* Measure for the size of the sphere of influence when last
|
||||
* checked the starmap.
|
||||
* 0 if the race's SoI is not known. */
|
||||
POINT known_loc;
|
||||
/* Location of the SoI (center) when last checked
|
||||
* the starmap. */
|
||||
|
||||
BYTE growth_err_term;
|
||||
BYTE func_index;
|
||||
/* Function index defined in clock.h (the same as in SetEvent())
|
||||
* for the function to call when the fleet reaches 'dest_loc'.
|
||||
* '(BYTE) ~0' means no function to call. */
|
||||
POINT dest_loc;
|
||||
/* Location to which the fleet (center) is moving. */
|
||||
|
||||
} FLEET_INFO;
|
||||
|
||||
static inline FLEET_INFO *
|
||||
LockFleetInfo (const QUEUE *pq, HFLEETINFO h)
|
||||
{
|
||||
assert (GetLinkSize (pq) == sizeof (FLEET_INFO));
|
||||
return (FLEET_INFO *) LockLink (pq, h);
|
||||
}
|
||||
|
||||
#define UnlockFleetInfo(pq, h) UnlockLink (pq, h)
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
+69
-46
@@ -109,11 +109,20 @@ write_a16 (void *fp, const UWORD *ar, COUNT count)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
SaveEmptyQueue (DECODE_REF fh)
|
||||
{
|
||||
COUNT num_links = 0;
|
||||
|
||||
// Write the number of entries in the queue.
|
||||
cwrite_16 (fh, num_links);
|
||||
}
|
||||
|
||||
static void
|
||||
SaveShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
{
|
||||
COUNT num_links;
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
|
||||
// Write the number of entries in the queue.
|
||||
num_links = CountLinks (pQueue);
|
||||
@@ -122,11 +131,11 @@ SaveShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
hStarShip = GetHeadLink (pQueue);
|
||||
while (num_links--)
|
||||
{
|
||||
HSTARSHIP hNextShip;
|
||||
HSHIPFRAG hNextShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
COUNT Index;
|
||||
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
|
||||
FragPtr = LockShipFrag (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (FragPtr);
|
||||
|
||||
Index = GET_RACE_ID (FragPtr);
|
||||
@@ -138,18 +147,18 @@ SaveShipQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
cwrite_16 (fh, FragPtr->which_side);
|
||||
cwrite_8 (fh, FragPtr->captains_name_index);
|
||||
cwrite_8 (fh, 0); /* padding */
|
||||
// Write SHIP_INFO elements
|
||||
cwrite_16 (fh, FragPtr->ShipInfo.ship_flags);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.var1);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.var2);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.crew_level);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.max_crew);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.energy_level);
|
||||
cwrite_8 (fh, FragPtr->ShipInfo.max_energy);
|
||||
cwrite_16 (fh, FragPtr->ShipInfo.loc.x);
|
||||
cwrite_16 (fh, FragPtr->ShipInfo.loc.y);
|
||||
cwrite_16 (fh, FragPtr->ship_flags);
|
||||
cwrite_8 (fh, FragPtr->var1);
|
||||
cwrite_8 (fh, FragPtr->var2);
|
||||
// XXX: writing crew as BYTE to maintain savegame compatibility
|
||||
cwrite_8 (fh, FragPtr->crew_level);
|
||||
cwrite_8 (fh, FragPtr->max_crew);
|
||||
cwrite_8 (fh, FragPtr->energy_level);
|
||||
cwrite_8 (fh, FragPtr->max_energy);
|
||||
cwrite_16 (fh, FragPtr->loc.x);
|
||||
cwrite_16 (fh, FragPtr->loc.y);
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
UnlockShipFrag (pQueue, hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
}
|
||||
@@ -158,49 +167,49 @@ static void
|
||||
SaveRaceQueue (DECODE_REF fh, QUEUE *pQueue)
|
||||
{
|
||||
COUNT num_links;
|
||||
HSTARSHIP hStarShip;
|
||||
HFLEETINFO hFleet;
|
||||
|
||||
// Write the number of entries in the queue.
|
||||
num_links = CountLinks (pQueue);
|
||||
cwrite_16 (fh, num_links);
|
||||
|
||||
hStarShip = GetHeadLink (pQueue);
|
||||
hFleet = GetHeadLink (pQueue);
|
||||
while (num_links--)
|
||||
{
|
||||
HSTARSHIP hNextShip;
|
||||
EXTENDED_SHIP_FRAGMENT *ExtFragPtr;
|
||||
HFLEETINFO hNextFleet;
|
||||
FLEET_INFO *FleetPtr;
|
||||
COUNT Index;
|
||||
|
||||
ExtFragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (pQueue, hStarShip);
|
||||
hNextShip = _GetSuccLink (ExtFragPtr);
|
||||
FleetPtr = LockFleetInfo (pQueue, hFleet);
|
||||
hNextFleet = _GetSuccLink (FleetPtr);
|
||||
|
||||
Index = GetIndexFromStarShip (pQueue, hStarShip);
|
||||
Index = GetIndexFromStarShip (pQueue, hFleet);
|
||||
// The index is the position in the queue.
|
||||
cwrite_16 (fh, Index);
|
||||
|
||||
// Write EXTENDED_SHIP_INFO elements
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.ship_flags);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.days_left);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.growth_fract);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.crew_level);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.max_crew);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.energy_level);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.max_energy);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.loc.x);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.loc.y);
|
||||
// Write FLEET_INFO elements
|
||||
cwrite_16 (fh, FleetPtr->ship_flags);
|
||||
cwrite_8 (fh, FleetPtr->days_left);
|
||||
cwrite_8 (fh, FleetPtr->growth_fract);
|
||||
cwrite_8 (fh, FleetPtr->crew_level);
|
||||
cwrite_8 (fh, FleetPtr->max_crew);
|
||||
cwrite_8 (fh, FleetPtr->energy_level);
|
||||
cwrite_8 (fh, FleetPtr->max_energy);
|
||||
cwrite_16 (fh, FleetPtr->loc.x);
|
||||
cwrite_16 (fh, FleetPtr->loc.y);
|
||||
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.actual_strength);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_strength);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.x);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.y);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.growth_err_term);
|
||||
cwrite_8 (fh, ExtFragPtr->ShipInfo.func_index);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.x);
|
||||
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.y);
|
||||
cwrite_16 (fh, FleetPtr->actual_strength);
|
||||
cwrite_16 (fh, FleetPtr->known_strength);
|
||||
cwrite_16 (fh, FleetPtr->known_loc.x);
|
||||
cwrite_16 (fh, FleetPtr->known_loc.y);
|
||||
cwrite_8 (fh, FleetPtr->growth_err_term);
|
||||
cwrite_8 (fh, FleetPtr->func_index);
|
||||
cwrite_16 (fh, FleetPtr->dest_loc.x);
|
||||
cwrite_16 (fh, FleetPtr->dest_loc.y);
|
||||
cwrite_16 (fh, 0); /* alignment padding */
|
||||
|
||||
UnlockStarShip (pQueue, hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
UnlockFleetInfo (pQueue, hFleet);
|
||||
hFleet = hNextFleet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,6 +240,7 @@ SaveEncounter (const ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
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 */
|
||||
// XXX: writing crew as BYTE to maintain savegame compatibility
|
||||
cwrite_8 (fh, ShipInfo->crew_level);
|
||||
cwrite_8 (fh, ShipInfo->max_crew);
|
||||
cwrite_8 (fh, 0); /* useless; was SHIP_INFO.energy_level */
|
||||
@@ -242,7 +252,7 @@ SaveEncounter (const ENCOUNTER *EncounterPtr, DECODE_REF fh)
|
||||
cwrite_ptr (fh); /* useless ptr; FRAME melee_icon */
|
||||
}
|
||||
|
||||
// Save the stuff after the SHIP_INFO array:
|
||||
// Save the stuff after the BRIEF_SHIP_INFO array
|
||||
cwrite_32 (fh, EncounterPtr->log_x);
|
||||
cwrite_32 (fh, EncounterPtr->log_y);
|
||||
}
|
||||
@@ -432,18 +442,17 @@ PrepareSummary (SUMMARY_DESC *SummPtr)
|
||||
SummPtr->MCreditHi = GET_GAME_STATE (MELNORME_CREDIT1);
|
||||
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)), SummPtr->NumShips = 0;
|
||||
hStarShip; hStarShip = hNextShip, ++SummPtr->NumShips)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
SummPtr->ShipList[SummPtr->NumShips] = GET_RACE_ID (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,8 +639,22 @@ RetrySave:
|
||||
GLOBAL (ShipStamp.frame) = frame;
|
||||
|
||||
SaveRaceQueue (fh, &GLOBAL (avail_race_q));
|
||||
// START_INTERPLANETARY is only set when saving from Homeworld
|
||||
// encounter screen. When the game is loaded, GENERATE_ORBITAL will
|
||||
// create the encounter anew and populate the npc queue.
|
||||
if (!(GLOBAL (CurrentActivity) & START_INTERPLANETARY))
|
||||
{
|
||||
if (GLOBAL (CurrentActivity) & START_ENCOUNTER)
|
||||
// save npc queue
|
||||
SaveShipQueue (fh, &GLOBAL (npc_built_ship_q));
|
||||
else if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY)
|
||||
// save group queue
|
||||
SaveShipQueue (fh, &GLOBAL (npc_built_ship_q));
|
||||
else
|
||||
// XXX: empty queue write-out is only needed to maintain
|
||||
// the savegame compatibility
|
||||
SaveEmptyQueue (fh);
|
||||
}
|
||||
SaveShipQueue (fh, &GLOBAL (built_ship_q));
|
||||
|
||||
// Save the number of game events (compressed).
|
||||
|
||||
+80
-87
@@ -124,15 +124,14 @@ hangar_anim_func (void *data)
|
||||
|
||||
#ifdef WANT_SHIP_SPINS
|
||||
static void
|
||||
SpinStarShip (HSTARSHIP hStarShip)
|
||||
SpinStarShip (HSHIPFRAG hStarShip)
|
||||
{
|
||||
int Index;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT *) LockStarShip (&GLOBAL (built_ship_q),
|
||||
hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
Index = FindMasterShipIndex (StarShipPtr->RaceResIndex);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
if (Index >= 0 && Index < NUM_MELEE_SHIPS)
|
||||
{
|
||||
@@ -148,46 +147,44 @@ static COUNT
|
||||
GetAvailableRaceCount (void)
|
||||
{
|
||||
COUNT Index;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
Index = 0;
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
if (StarShipPtr->ShipInfo.ship_flags & GOOD_GUY)
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
if (FleetPtr->ship_flags & GOOD_GUY)
|
||||
++Index;
|
||||
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
return Index;
|
||||
}
|
||||
|
||||
static HSTARSHIP
|
||||
static HFLEETINFO
|
||||
GetAvailableRaceFromIndex (BYTE Index)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
if ((StarShipPtr->ShipInfo.ship_flags & GOOD_GUY) && Index-- == 0)
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
if ((FleetPtr->ship_flags & GOOD_GUY) && Index-- == 0)
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
return hStarShip;
|
||||
}
|
||||
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -224,8 +221,8 @@ DrawRaceStrings (BYTE NewRaceItem)
|
||||
if (NewRaceItem != (BYTE)~0)
|
||||
{
|
||||
TEXT t;
|
||||
HSTARSHIP hStarShip;
|
||||
EXTENDED_SHIP_FRAGMENT *FragPtr;
|
||||
HFLEETINFO hStarShip;
|
||||
FLEET_INFO *FleetPtr;
|
||||
UNICODE buf[30];
|
||||
COUNT ShipCost[] =
|
||||
{
|
||||
@@ -238,10 +235,9 @@ DrawRaceStrings (BYTE NewRaceItem)
|
||||
s.frame = SetAbsFrameIndex (pMenuState->ModuleFrame,
|
||||
3 + NewRaceItem);
|
||||
DrawStamp (&s);
|
||||
FragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
s.frame = FragPtr->ShipInfo.melee_icon;
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
s.frame = FleetPtr->melee_icon;
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
|
||||
t.baseline.x = s.origin.x + RADAR_WIDTH - 2;
|
||||
t.baseline.y = s.origin.y + RADAR_HEIGHT - 2;
|
||||
@@ -275,23 +271,22 @@ ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, RECT *pRect)
|
||||
RECT r;
|
||||
TEXT t;
|
||||
UNICODE buf[80];
|
||||
HSTARSHIP hTemplate;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hTemplate;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
|
||||
hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q),
|
||||
GET_RACE_ID (StarShipPtr));
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hTemplate);
|
||||
if (StarShipPtr->ShipInfo.crew_level >=
|
||||
TemplatePtr->ShipInfo.crew_level)
|
||||
sprintf (buf, "%u", StarShipPtr->ShipInfo.crew_level);
|
||||
else if (StarShipPtr->ShipInfo.crew_level == 0)
|
||||
TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hTemplate);
|
||||
if (StarShipPtr->crew_level >= TemplatePtr->crew_level)
|
||||
sprintf (buf, "%u", StarShipPtr->crew_level);
|
||||
else if (StarShipPtr->crew_level == 0)
|
||||
// XXX: "SCRAP" needs to be moved to starcon.txt
|
||||
utf8StringCopy (buf, sizeof (buf), "SCRAP");
|
||||
else
|
||||
sprintf (buf, "%u/%u",
|
||||
StarShipPtr->ShipInfo.crew_level,
|
||||
TemplatePtr->ShipInfo.crew_level);
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hTemplate);
|
||||
StarShipPtr->crew_level,
|
||||
TemplatePtr->crew_level);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate);
|
||||
|
||||
r = *pRect;
|
||||
t.baseline.x = r.corner.x + (r.extent.width >> 1);
|
||||
@@ -307,7 +302,7 @@ ShowShipCrew (SHIP_FRAGMENT *StarShipPtr, RECT *pRect)
|
||||
SetContextForeGroundColor (BLACK_COLOR);
|
||||
DrawFilledRectangle (&r);
|
||||
}
|
||||
SetContextForeGroundColor ((StarShipPtr->ShipInfo.crew_level != 0) ?
|
||||
SetContextForeGroundColor ((StarShipPtr->crew_level != 0) ?
|
||||
(BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02)):
|
||||
(BUILD_COLOR (MAKE_RGB15 (0x12, 0x00, 0x00), 0x2B)));
|
||||
font_DrawText (&t);
|
||||
@@ -317,7 +312,7 @@ static void
|
||||
ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
{
|
||||
COUNT i, num_ships;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
struct
|
||||
{
|
||||
@@ -343,8 +338,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
|
||||
pship_win_info->ship_s.origin.x = (SHIP_WIN_WIDTH >> 1) + 1;
|
||||
pship_win_info->ship_s.origin.y = (SHIP_WIN_WIDTH >> 1);
|
||||
pship_win_info->ship_s.frame =
|
||||
YankedStarShipPtr->ShipInfo.melee_icon;
|
||||
pship_win_info->ship_s.frame = YankedStarShipPtr->melee_icon;
|
||||
|
||||
pship_win_info->finished_s.x = hangar_x_coords[
|
||||
which_window % HANGAR_SHIPS_ROW];
|
||||
@@ -360,7 +354,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
}
|
||||
else
|
||||
{
|
||||
HSTARSHIP hTailShip;
|
||||
HSHIPFRAG hTailShip;
|
||||
|
||||
hTailShip = GetTailLink (&GLOBAL (built_ship_q));
|
||||
RemoveQueue (&GLOBAL (built_ship_q), hTailShip);
|
||||
@@ -368,31 +362,28 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||
while (hStarShip)
|
||||
{
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
if (StarShipPtr->ShipInfo.var2 > which_window)
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
if (StarShipPtr->var2 > which_window)
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
break;
|
||||
}
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
InsertQueue (&GLOBAL (built_ship_q), hTailShip, hStarShip);
|
||||
|
||||
hStarShip = hTailShip;
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr->ShipInfo.var2 = which_window;
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr->var2 = which_window;
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_ships; ++i)
|
||||
{
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
|
||||
pship_win_info->StarShipPtr = StarShipPtr;
|
||||
@@ -408,8 +399,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
|
||||
pship_win_info->ship_s.origin.x = (SHIP_WIN_WIDTH >> 1) + 1;
|
||||
pship_win_info->ship_s.origin.y = (SHIP_WIN_WIDTH >> 1);
|
||||
pship_win_info->ship_s.frame =
|
||||
StarShipPtr->ShipInfo.melee_icon;
|
||||
pship_win_info->ship_s.frame = StarShipPtr->melee_icon;
|
||||
|
||||
which_window = GET_GROUP_LOC (StarShipPtr);
|
||||
pship_win_info->finished_s.x = hangar_x_coords[
|
||||
@@ -418,7 +408,7 @@ ShowCombatShip (COUNT which_window, SHIP_FRAGMENT *YankedStarShipPtr)
|
||||
(which_window / HANGAR_SHIPS_ROW));
|
||||
++pship_win_info;
|
||||
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hStarShip = hNextShip;
|
||||
}
|
||||
}
|
||||
@@ -564,7 +554,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
{
|
||||
#define MODIFY_CREW_FLAG (1 << 8)
|
||||
RECT r;
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
BOOLEAN select, cancel;
|
||||
#ifdef WANT_SHIP_SPINS
|
||||
@@ -651,17 +641,16 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||
hStarShip; hStarShip = hNextShip)
|
||||
{
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
if (StarShipPtr->ShipInfo.var2 == pMS->CurState)
|
||||
if (StarShipPtr->var2 == pMS->CurState)
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
break;
|
||||
}
|
||||
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
if ((pMS->delta_item & MODIFY_CREW_FLAG) && (hStarShip))
|
||||
{
|
||||
@@ -678,7 +667,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
#ifdef WANT_SHIP_SPINS
|
||||
if (special)
|
||||
{
|
||||
HSTARSHIP hSpinShip;
|
||||
HSHIPFRAG hSpinShip;
|
||||
|
||||
if ((special && (((hStarShip == 0
|
||||
&& HINIBBLE (pMS->CurState) == 0)
|
||||
@@ -695,11 +684,15 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
RECT OldClipRect;
|
||||
RECT flash_r;
|
||||
SetFlashRect (NULL, (FRAME)0);
|
||||
// Do not call EndHangarAnim() with GraphicsLock held!
|
||||
UnlockMutex (GraphicsLock);
|
||||
EndHangarAnim (pMS);
|
||||
LockMutex (GraphicsLock);
|
||||
|
||||
OldContext = SetContext (ScreenContext);
|
||||
GetContextClipRect (&OldClipRect);
|
||||
|
||||
// XXX: this is broken; we pass an HSHIPFRAG or HFLEETINFO
|
||||
SpinStarShip (hSpinShip);
|
||||
|
||||
SetContextClipRect (&OldClipRect);
|
||||
@@ -821,19 +814,19 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
if ((pMS->delta_item & MODIFY_CREW_FLAG)
|
||||
&& hStarShip != 0)
|
||||
{
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
if (StarShipPtr->ShipInfo.crew_level == 0)
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
hStarShip);
|
||||
if (StarShipPtr->crew_level == 0)
|
||||
{
|
||||
SetFlashRect (NULL, (FRAME)0);
|
||||
UnlockMutex (GraphicsLock);
|
||||
ShowCombatShip ((COUNT)pMS->CurState,
|
||||
StarShipPtr);
|
||||
LockMutex (GraphicsLock);
|
||||
UnlockStarShip (&GLOBAL (built_ship_q),
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q),
|
||||
hStarShip);
|
||||
RemoveQueue (&GLOBAL (built_ship_q), hStarShip);
|
||||
FreeStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
FreeShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
// refresh SIS display
|
||||
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA,
|
||||
UNDEFINED_DELTA);
|
||||
@@ -847,7 +840,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
}
|
||||
else
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (built_ship_q),
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q),
|
||||
hStarShip);
|
||||
}
|
||||
}
|
||||
@@ -883,8 +876,8 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
SIZE crew_delta, crew_bought;
|
||||
|
||||
if (hStarShip)
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||
hStarShip);
|
||||
else
|
||||
StarShipPtr = NULL; // Keeping compiler quiet.
|
||||
|
||||
@@ -915,28 +908,27 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
}
|
||||
else
|
||||
{
|
||||
HSTARSHIP hTemplate;
|
||||
EXTENDED_SHIP_FRAGMENT *TemplatePtr;
|
||||
HFLEETINFO hTemplate;
|
||||
FLEET_INFO *TemplatePtr;
|
||||
|
||||
hTemplate = GetStarShipFromIndex (
|
||||
&GLOBAL (avail_race_q),
|
||||
GET_RACE_ID (StarShipPtr));
|
||||
TemplatePtr = (EXTENDED_SHIP_FRAGMENT*)
|
||||
LockStarShip (&GLOBAL (avail_race_q),
|
||||
hTemplate);
|
||||
TemplatePtr = LockFleetInfo (
|
||||
&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->ShipInfo.crew_level)
|
||||
&& StarShipPtr->crew_level <
|
||||
StarShipPtr->max_crew &&
|
||||
StarShipPtr->crew_level <
|
||||
TemplatePtr->crew_level)
|
||||
{
|
||||
if (StarShipPtr->ShipInfo.crew_level > 0)
|
||||
if (StarShipPtr->crew_level > 0)
|
||||
DeltaSISGauges (0, 0, -GLOBAL (CrewCost));
|
||||
else
|
||||
DeltaSISGauges (0, 0, -(COUNT)ShipCost[
|
||||
GET_RACE_ID (StarShipPtr) ]);
|
||||
++StarShipPtr->ShipInfo.crew_level;
|
||||
++StarShipPtr->crew_level;
|
||||
crew_delta = 1;
|
||||
ShowShipCrew (StarShipPtr, &pMS->flash_rect0);
|
||||
r.corner.x = pMS->flash_rect0.corner.x;
|
||||
@@ -951,7 +943,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
{ // at capacity or not enough RUs
|
||||
PlayMenuSound (MENU_SOUND_FAILURE);
|
||||
}
|
||||
UnlockStarShip (&GLOBAL (avail_race_q),
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q),
|
||||
hTemplate);
|
||||
}
|
||||
}
|
||||
@@ -985,9 +977,9 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (StarShipPtr->ShipInfo.crew_level > 0)
|
||||
if (StarShipPtr->crew_level > 0)
|
||||
{
|
||||
if (StarShipPtr->ShipInfo.crew_level > 1)
|
||||
if (StarShipPtr->crew_level > 1)
|
||||
DeltaSISGauges (0, 0, GLOBAL (CrewCost)
|
||||
- (crew_bought ==
|
||||
CREW_EXPENSE_THRESHOLD ? 2 : 0));
|
||||
@@ -995,7 +987,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
DeltaSISGauges (0, 0, (COUNT)ShipCost[
|
||||
GET_RACE_ID (StarShipPtr)]);
|
||||
crew_delta = -1;
|
||||
--StarShipPtr->ShipInfo.crew_level;
|
||||
--StarShipPtr->crew_level;
|
||||
}
|
||||
else
|
||||
{ // no crew to dismiss
|
||||
@@ -1014,7 +1006,7 @@ DoModifyShips (MENU_STATE *pMS)
|
||||
|
||||
if (hStarShip)
|
||||
{
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
|
||||
// clear out the bought ship index
|
||||
// so that flash rects work correctly
|
||||
@@ -1210,6 +1202,7 @@ BeginHangarAnim (MENU_STATE *pMS)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Pre: GraphicsLock is NOT held (or risk a deadlock)
|
||||
static void
|
||||
EndHangarAnim (MENU_STATE *pMS)
|
||||
{
|
||||
|
||||
@@ -932,7 +932,7 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
||||
}
|
||||
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HSHIPFRAG hStarShip, hNextShip;
|
||||
POINT *pship_pos;
|
||||
POINT ship_pos[MAX_COMBAT_SHIPS] =
|
||||
{
|
||||
@@ -946,18 +946,17 @@ DeltaSISGauges (SIZE crew_delta, SIZE fuel_delta, int resunit_delta)
|
||||
{
|
||||
SHIP_FRAGMENT *StarShipPtr;
|
||||
|
||||
StarShipPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (built_ship_q), hStarShip);
|
||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
|
||||
s.origin.x = pship_pos->x;
|
||||
s.origin.y = pship_pos->y;
|
||||
s.frame = StarShipPtr->ShipInfo.icons;
|
||||
s.frame = StarShipPtr->icons;
|
||||
LockMutex (GraphicsLock);
|
||||
DrawStamp (&s);
|
||||
UnlockMutex (GraphicsLock);
|
||||
|
||||
UnlockStarShip (&GLOBAL (built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||
}
|
||||
LockMutex (GraphicsLock);
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ VisitStarBase (void)
|
||||
}
|
||||
else if (!GET_GAME_STATE (STARBASE_AVAILABLE))
|
||||
{
|
||||
HSTARSHIP hStarShip;
|
||||
HSHIPFRAG hStarShip;
|
||||
SHIP_FRAGMENT *FragPtr;
|
||||
|
||||
pMenuState = 0;
|
||||
@@ -483,10 +483,11 @@ VisitStarBase (void)
|
||||
|
||||
hStarShip = CloneShipFragment (ILWRATH_SHIP,
|
||||
&GLOBAL (npc_built_ship_q), 7);
|
||||
FragPtr = (SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
FragPtr = LockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
/* Hack (sort of): Suppress the tally and salvage info
|
||||
* after the battle */
|
||||
SET_RACE_ID (FragPtr, (BYTE)~0);
|
||||
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
UnlockShipFrag (&GLOBAL (npc_built_ship_q), hStarShip);
|
||||
|
||||
InitCommunication (ILWRATH_CONVERSATION);
|
||||
if (GLOBAL_SIS (CrewEnlisted) == (COUNT)~0
|
||||
|
||||
+17
-21
@@ -396,27 +396,24 @@ doInstantMove (void)
|
||||
void
|
||||
showSpheres (void)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip != NULL; hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if ((StarShipPtr->ShipInfo.actual_strength != (COUNT) ~0) &&
|
||||
(StarShipPtr->ShipInfo.known_strength !=
|
||||
StarShipPtr->ShipInfo.actual_strength))
|
||||
if ((FleetPtr->actual_strength != (COUNT) ~0) &&
|
||||
(FleetPtr->known_strength != FleetPtr->actual_strength))
|
||||
{
|
||||
StarShipPtr->ShipInfo.known_strength =
|
||||
StarShipPtr->ShipInfo.actual_strength;
|
||||
StarShipPtr->ShipInfo.known_loc = StarShipPtr->ShipInfo.loc;
|
||||
FleetPtr->known_strength = FleetPtr->actual_strength;
|
||||
FleetPtr->known_loc = FleetPtr->loc;
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,25 +422,24 @@ showSpheres (void)
|
||||
void
|
||||
activateAllShips (void)
|
||||
{
|
||||
HSTARSHIP hStarShip, hNextShip;
|
||||
HFLEETINFO hStarShip, hNextShip;
|
||||
|
||||
for (hStarShip = GetHeadLink (&GLOBAL (avail_race_q));
|
||||
hStarShip != NULL; hStarShip = hNextShip)
|
||||
{
|
||||
EXTENDED_SHIP_FRAGMENT *StarShipPtr;
|
||||
FLEET_INFO *FleetPtr;
|
||||
|
||||
StarShipPtr = (EXTENDED_SHIP_FRAGMENT*) LockStarShip (
|
||||
&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (StarShipPtr);
|
||||
FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
hNextShip = _GetSuccLink (FleetPtr);
|
||||
|
||||
if (StarShipPtr->ShipInfo.icons != NULL)
|
||||
if (FleetPtr->icons != NULL)
|
||||
// Skip the Ur-Quan probe.
|
||||
{
|
||||
StarShipPtr->ShipInfo.ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
StarShipPtr->ShipInfo.ship_flags |= GOOD_GUY;
|
||||
FleetPtr->ship_flags &= ~(GOOD_GUY | BAD_GUY);
|
||||
FleetPtr->ship_flags |= GOOD_GUY;
|
||||
}
|
||||
|
||||
UnlockStarShip (&GLOBAL (avail_race_q), hStarShip);
|
||||
UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user