|
From: <Mee...@us...> - 2012-01-29 15:44:01
|
Revision: 3757
http://sc2.svn.sourceforge.net/sc2/?rev=3757&view=rev
Author: Meep-Eep
Date: 2012-01-29 15:43:55 +0000 (Sun, 29 Jan 2012)
Log Message:
-----------
Generalised some functions.
Modified Paths:
--------------
trunk/sc2/src/uqm/build.c
trunk/sc2/src/uqm/build.h
Modified: trunk/sc2/src/uqm/build.c
===================================================================
--- trunk/sc2/src/uqm/build.c 2012-01-28 21:10:41 UTC (rev 3756)
+++ trunk/sc2/src/uqm/build.c 2012-01-29 15:43:55 UTC (rev 3757)
@@ -271,18 +271,19 @@
}
/*
- * 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,12 +297,22 @@
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);
+}
+
+/*
* Test if the SIS can have an escort of the specified race.
* Returns 0 if 'race' is not available.
* Otherwise, returns the number of ships that can be added.
@@ -342,14 +353,18 @@
}
/*
- * 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,20 +378,34 @@
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
GetIndexFromStarShip (QUEUE *pShipQ, HLINK hStarShip)
{
Modified: trunk/sc2/src/uqm/build.h
===================================================================
--- trunk/sc2/src/uqm/build.h 2012-01-28 21:10:41 UTC (rev 3756)
+++ trunk/sc2/src/uqm/build.h 2012-01-29 15:43:55 UTC (rev 3757)
@@ -51,9 +51,11 @@
//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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|