Some cleaning up of DoModifyShips(). More to come.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3724 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
Changes towards version 0.8:
|
Changes towards version 0.8:
|
||||||
|
- Cleaning up DoModifyShips() - SvdB
|
||||||
- Added Valgrind suppression file, from Louis Delacroix
|
- Added Valgrind suppression file, from Louis Delacroix
|
||||||
- Fix several memory leaks, from Loius Delacroix
|
- Fix several memory leaks, from Loius Delacroix
|
||||||
- Some cleanups / warnings fixes, from Louis Delacroix
|
- Some cleanups / warnings fixes, from Louis Delacroix
|
||||||
|
|||||||
@@ -68,6 +68,31 @@ GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index)
|
|||||||
return (hStarShip);
|
return (hStarShip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HSHIPFRAG
|
||||||
|
GetEscortByStarShipIndex (COUNT index)
|
||||||
|
{
|
||||||
|
HSHIPFRAG hStarShip;
|
||||||
|
HSHIPFRAG hNextShip;
|
||||||
|
SHIP_FRAGMENT *StarShipPtr;
|
||||||
|
|
||||||
|
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
||||||
|
hStarShip; hStarShip = hNextShip)
|
||||||
|
{
|
||||||
|
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
|
||||||
|
if (StarShipPtr->index == index)
|
||||||
|
{
|
||||||
|
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
hNextShip = _GetSuccLink (StarShipPtr);
|
||||||
|
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hStarShip;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Give the player 'count' ships of the specified race,
|
* Give the player 'count' ships of the specified race,
|
||||||
* limited by the number of free slots.
|
* limited by the number of free slots.
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ extern HLINK Build (QUEUE *pQueue, SPECIES_ID SpeciesID);
|
|||||||
extern HSHIPFRAG CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue,
|
extern HSHIPFRAG CloneShipFragment (COUNT shipIndex, QUEUE *pDstQueue,
|
||||||
COUNT crew_level);
|
COUNT crew_level);
|
||||||
extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index);
|
extern HLINK GetStarShipFromIndex (QUEUE *pShipQ, COUNT Index);
|
||||||
|
HSHIPFRAG GetEscortByStarShipIndex (COUNT index);
|
||||||
extern BYTE NameCaptain (QUEUE *pQueue, SPECIES_ID SpeciesID);
|
extern BYTE NameCaptain (QUEUE *pQueue, SPECIES_ID SpeciesID);
|
||||||
|
|
||||||
/* Possible values for the 'state' argument of
|
/* Possible values for the 'state' argument of
|
||||||
|
|||||||
+68
-60
@@ -533,6 +533,64 @@ CrewTransaction (SIZE crew_delta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MODIFY_CREW_FLAG (1 << 8)
|
||||||
|
#ifdef WANT_SHIP_SPINS
|
||||||
|
// Helper function for DoModifyShips(), called when the player presses the
|
||||||
|
// special button.
|
||||||
|
// It works both when the cursor is over an escort ship, while not editing
|
||||||
|
// the crew, and when a new ship is added.
|
||||||
|
// hStarShip is the ship in the slot under the cursor (or 0 if no such ship).
|
||||||
|
static BOOLEAN
|
||||||
|
DMS_SpinShip (MENU_STATE *pMS, HSHIPFRAG hStarShip)
|
||||||
|
{
|
||||||
|
HFLEETINFO hSpinShip = 0;
|
||||||
|
CONTEXT OldContext;
|
||||||
|
RECT OldClipRect;
|
||||||
|
|
||||||
|
// No spinning the flagship.
|
||||||
|
if (HINIBBLE (pMS->CurState) != 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
// We must either be hovering over a used ship slot, or adding a new
|
||||||
|
// ship to the fleet.
|
||||||
|
if ((hStarShip == 0) == !(pMS->delta_item & MODIFY_CREW_FLAG))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!hStarShip)
|
||||||
|
{
|
||||||
|
// Selecting a ship to build.
|
||||||
|
hSpinShip = GetAvailableRaceFromIndex (LOBYTE (pMS->delta_item));
|
||||||
|
if (!hSpinShip)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Hovering over an escort ship.
|
||||||
|
SHIP_FRAGMENT *FragPtr = LockShipFrag (
|
||||||
|
&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
hSpinShip = GetStarShipFromIndex (
|
||||||
|
&GLOBAL (avail_race_q), FragPtr->race_id);
|
||||||
|
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetFlashRect (NULL);
|
||||||
|
|
||||||
|
OldContext = SetContext (ScreenContext);
|
||||||
|
GetContextClipRect (&OldClipRect);
|
||||||
|
|
||||||
|
SpinStarShip (pMS, hSpinShip);
|
||||||
|
|
||||||
|
SetContextClipRect (&OldClipRect);
|
||||||
|
SetContext (OldContext);
|
||||||
|
|
||||||
|
if (hStarShip)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
SetFlashRect (SFR_MENU_3DO);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#endif /* WANT_SHIP_SPINS */
|
||||||
|
|
||||||
/* in this routine, the least significant byte of pMS->CurState is used
|
/* in this routine, the least significant byte of pMS->CurState is used
|
||||||
* to store the current selected ship index
|
* to store the current selected ship index
|
||||||
* a special case for the row is hi-nibble == -1 (0xf), which specifies
|
* a special case for the row is hi-nibble == -1 (0xf), which specifies
|
||||||
@@ -543,7 +601,6 @@ CrewTransaction (SIZE crew_delta)
|
|||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
DoModifyShips (MENU_STATE *pMS)
|
DoModifyShips (MENU_STATE *pMS)
|
||||||
{
|
{
|
||||||
#define MODIFY_CREW_FLAG (1 << 8)
|
|
||||||
BOOLEAN select, cancel;
|
BOOLEAN select, cancel;
|
||||||
#ifdef WANT_SHIP_SPINS
|
#ifdef WANT_SHIP_SPINS
|
||||||
BOOLEAN special;
|
BOOLEAN special;
|
||||||
@@ -611,7 +668,8 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
else if (dx && !HINIBBLE (NewState))
|
else if (dx && !HINIBBLE (NewState))
|
||||||
{
|
{
|
||||||
NewState = NewState % HANGAR_SHIPS_ROW;
|
NewState = NewState % HANGAR_SHIPS_ROW;
|
||||||
if ((dx += NewState) < 0)
|
dx += NewState;
|
||||||
|
if (dx < 0)
|
||||||
NewState = (BYTE)(pMS->CurState + (HANGAR_SHIPS_ROW - 1));
|
NewState = (BYTE)(pMS->CurState + (HANGAR_SHIPS_ROW - 1));
|
||||||
else if (dx > HANGAR_SHIPS_ROW - 1)
|
else if (dx > HANGAR_SHIPS_ROW - 1)
|
||||||
NewState = (BYTE)(pMS->CurState - (HANGAR_SHIPS_ROW - 1));
|
NewState = (BYTE)(pMS->CurState - (HANGAR_SHIPS_ROW - 1));
|
||||||
@@ -626,24 +684,11 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
|| NewState != pMS->CurState
|
|| NewState != pMS->CurState
|
||||||
|| ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy)))
|
|| ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy)))
|
||||||
{
|
{
|
||||||
HSHIPFRAG hStarShip, hNextShip;
|
HSHIPFRAG hStarShip;
|
||||||
SHIP_FRAGMENT *StarShipPtr;
|
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));
|
hStarShip = GetEscortByStarShipIndex (pMS->CurState);
|
||||||
hStarShip; hStarShip = hNextShip)
|
|
||||||
{
|
|
||||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
|
|
||||||
if (StarShipPtr->index == pMS->CurState)
|
|
||||||
{
|
|
||||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hNextShip = _GetSuccLink (StarShipPtr);
|
|
||||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
}
|
|
||||||
if ((pMS->delta_item & MODIFY_CREW_FLAG) && (hStarShip))
|
if ((pMS->delta_item & MODIFY_CREW_FLAG) && (hStarShip))
|
||||||
{
|
{
|
||||||
SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN,
|
SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN,
|
||||||
@@ -659,49 +704,11 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
#ifdef WANT_SHIP_SPINS
|
#ifdef WANT_SHIP_SPINS
|
||||||
if (special)
|
if (special)
|
||||||
{
|
{
|
||||||
HFLEETINFO hSpinShip = 0;
|
if (DMS_SpinShip (pMS, hStarShip))
|
||||||
|
goto ChangeFlashRect;
|
||||||
if ((special && (((hStarShip == 0
|
|
||||||
&& HINIBBLE (pMS->CurState) == 0)
|
|
||||||
&& (pMS->delta_item & MODIFY_CREW_FLAG))
|
|
||||||
|| ((hStarShip != 0 &&
|
|
||||||
HINIBBLE (pMS->CurState) == 0)
|
|
||||||
&& !(pMS->delta_item & MODIFY_CREW_FLAG))))
|
|
||||||
&& (hStarShip
|
|
||||||
|| (HINIBBLE (pMS->CurState) == 0
|
|
||||||
&& (hSpinShip = GetAvailableRaceFromIndex (
|
|
||||||
LOBYTE (pMS->delta_item))))))
|
|
||||||
{
|
|
||||||
CONTEXT OldContext;
|
|
||||||
RECT OldClipRect;
|
|
||||||
|
|
||||||
if (!hSpinShip)
|
|
||||||
{ /* Get fleet info from selected escort */
|
|
||||||
SHIP_FRAGMENT *FragPtr = LockShipFrag (
|
|
||||||
&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
hSpinShip = GetStarShipFromIndex (
|
|
||||||
&GLOBAL (avail_race_q), FragPtr->race_id);
|
|
||||||
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetFlashRect (NULL);
|
|
||||||
|
|
||||||
OldContext = SetContext (ScreenContext);
|
|
||||||
GetContextClipRect (&OldClipRect);
|
|
||||||
|
|
||||||
SpinStarShip (pMS, hSpinShip);
|
|
||||||
|
|
||||||
SetContextClipRect (&OldClipRect);
|
|
||||||
SetContext (OldContext);
|
|
||||||
|
|
||||||
if (hStarShip)
|
|
||||||
goto ChangeFlashRect;
|
|
||||||
|
|
||||||
SetFlashRect (SFR_MENU_3DO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif /* WANT_SHIP_SPINS */
|
||||||
if (select || ((pMS->delta_item & MODIFY_CREW_FLAG)
|
if (select || ((pMS->delta_item & MODIFY_CREW_FLAG)
|
||||||
&& (dx || dy || cancel)))
|
&& (dx || dy || cancel)))
|
||||||
{
|
{
|
||||||
@@ -800,8 +807,8 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
if ((pMS->delta_item & MODIFY_CREW_FLAG)
|
if ((pMS->delta_item & MODIFY_CREW_FLAG)
|
||||||
&& hStarShip != 0)
|
&& hStarShip != 0)
|
||||||
{
|
{
|
||||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
SHIP_FRAGMENT *StarShipPtr = LockShipFrag (
|
||||||
hStarShip);
|
&GLOBAL (built_ship_q), hStarShip);
|
||||||
if (StarShipPtr->crew_level == 0)
|
if (StarShipPtr->crew_level == 0)
|
||||||
{
|
{
|
||||||
SetFlashRect (NULL);
|
SetFlashRect (NULL);
|
||||||
@@ -858,6 +865,7 @@ DoModifyShips (MENU_STATE *pMS)
|
|||||||
else if (pMS->delta_item & MODIFY_CREW_FLAG)
|
else if (pMS->delta_item & MODIFY_CREW_FLAG)
|
||||||
{
|
{
|
||||||
SIZE crew_delta, crew_bought;
|
SIZE crew_delta, crew_bought;
|
||||||
|
SHIP_FRAGMENT *StarShipPtr;
|
||||||
|
|
||||||
if (hStarShip)
|
if (hStarShip)
|
||||||
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q),
|
||||||
|
|||||||
Reference in New Issue
Block a user