Generalised some functions.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3757 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2012-01-29 15:43:55 +00:00
parent bf0d86fcf3
commit e4902fa2c3
2 changed files with 44 additions and 13 deletions
+42 -13
View File
@@ -271,18 +271,19 @@ StartSphereTracking (COUNT race)
}
/*
* Returns true if and only if a ship of the specified race is among the
* Returns the number of ships of the specified race among the
* escort ships.
*/
BOOLEAN
HaveEscortShip (COUNT race)
COUNT
CountEscortShips (COUNT race)
{
HFLEETINFO hFleet;
HSHIPFRAG hStarShip, hNextShip;
COUNT result = 0;
hFleet = GetStarShipFromIndex (&GLOBAL (avail_race_q), race);
if (!hFleet)
return FALSE;
return 0;
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); hStarShip;
hStarShip = hNextShip)
@@ -296,9 +297,19 @@ HaveEscortShip (COUNT race)
UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip);
if (ship_type == race)
return TRUE;
result++;
}
return FALSE;
return result;
}
/*
* Returns true if and only if a ship of the specified race is among the
* escort ships.
*/
BOOLEAN
HaveEscortShip (COUNT race)
{
return (CountEscortShips (race) > 0);
}
/*
@@ -342,13 +353,17 @@ CheckAlliance (COUNT race)
}
/*
* Remove all escort ships of the specified race.
* Remove a number of escort ships of the specified race (if present).
* Returns the number of escort ships removed.
*/
void
RemoveEscortShips (COUNT race)
COUNT
RemoveSomeEscortShips (COUNT race, COUNT count)
{
HSHIPFRAG hStarShip, hNextShip;
BOOLEAN ShipRemoved = FALSE;
HSHIPFRAG hStarShip;
HSHIPFRAG hNextShip;
if (count == 0)
return 0;
for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)); hStarShip;
hStarShip = hNextShip)
@@ -363,18 +378,32 @@ RemoveEscortShips (COUNT race)
if (RemoveShip)
{
ShipRemoved = TRUE;
RemoveQueue (&GLOBAL (built_ship_q), hStarShip);
FreeShipFrag (&GLOBAL (built_ship_q), hStarShip);
count--;
if (count == 0)
break;
}
}
if (ShipRemoved)
if (count > 0)
{
// Update the display.
LockMutex (GraphicsLock);
DeltaSISGauges (UNDEFINED_DELTA, UNDEFINED_DELTA, UNDEFINED_DELTA);
UnlockMutex (GraphicsLock);
}
return count;
}
/*
* Remove all escort ships of the specified race.
*/
void
RemoveEscortShips (COUNT race)
{
RemoveSomeEscortShips (race, (COUNT) -1);
}
COUNT
+2
View File
@@ -51,9 +51,11 @@ extern COUNT CalculateEscortsWorth (void);
//extern COUNT GetRaceKnownSize (COUNT race);
extern COUNT SetRaceAllied (COUNT race, BOOLEAN flag);
extern COUNT StartSphereTracking (COUNT race);
extern COUNT CountEscortShips (COUNT race);
extern BOOLEAN HaveEscortShip (COUNT race);
extern COUNT EscortFeasibilityStudy (COUNT race);
extern COUNT CheckAlliance (COUNT race);
extern COUNT RemoveSomeEscortShips (COUNT race, COUNT count);
extern void RemoveEscortShips (COUNT race);
extern RACE_DESC *load_ship (SPECIES_ID SpeciesID, BOOLEAN LoadBattleData);