Battle & ship code cleanup: Removed the global var cur_player; control flags propagated forward

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3264 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-10-30 19:27:41 +00:00
parent 0919ab84fe
commit 6304f5e884
13 changed files with 27 additions and 23 deletions
+5 -2
View File
@@ -156,8 +156,7 @@ ProcessInput (void)
for (sideI = 0; sideI < NUM_SIDES; sideI++) for (sideI = 0; sideI < NUM_SIDES; sideI++)
{ {
HSTARSHIP hBattleShip, hNextShip; HSTARSHIP hBattleShip, hNextShip;
size_t cur_player = battleInputOrder[sideI];
cur_player = battleInputOrder[sideI];
for (hBattleShip = GetHeadLink (&race_q[cur_player]); for (hBattleShip = GetHeadLink (&race_q[cur_player]);
hBattleShip != 0; hBattleShip = hNextShip) hBattleShip != 0; hBattleShip = hNextShip)
@@ -170,6 +169,10 @@ ProcessInput (void)
if (StarShipPtr->hShip) if (StarShipPtr->hShip)
{ {
// TODO: review and see if we have to do this every frame, or
// if we can do this once somewhere
StarShipPtr->control = PlayerControl[cur_player];
InputState = PlayerInput[cur_player]->handlers->frameInput ( InputState = PlayerInput[cur_player]->handlers->frameInput (
PlayerInput[cur_player], StarShipPtr); PlayerInput[cur_player], StarShipPtr);
+6 -6
View File
@@ -435,11 +435,11 @@ ship_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
ShipFired = FALSE; ShipFired = FALSE;
} }
if (PlayerControl[cur_player] & AWESOME_RATING) if (StarShipPtr->control & AWESOME_RATING)
margin_of_error = 0; margin_of_error = 0;
else if (PlayerControl[cur_player] & GOOD_RATING) else if (StarShipPtr->control & GOOD_RATING)
margin_of_error = DISPLAY_TO_WORLD (20); margin_of_error = DISPLAY_TO_WORLD (20);
else /* if (PlayerControl[cur_player] & STANDARD_RATING) */ else /* if (StarShipPtr->control & STANDARD_RATING) */
margin_of_error = DISPLAY_TO_WORLD (40); margin_of_error = DISPLAY_TO_WORLD (40);
ObjectsOfConcern += ConcernCounter; ObjectsOfConcern += ConcernCounter;
@@ -464,7 +464,7 @@ ship_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
|| (ConcernCounter == ENEMY_WEAPON_INDEX || (ConcernCounter == ENEMY_WEAPON_INDEX
&& ObjectsOfConcern->MoveState != AVOID && ObjectsOfConcern->MoveState != AVOID
#ifdef NEVER #ifdef NEVER
&& !(PlayerControl[cur_player] & STANDARD_RATING) && !(StarShipPtr->control & STANDARD_RATING)
#endif /* NEVER */ #endif /* NEVER */
))) )))
{ {
@@ -1035,7 +1035,7 @@ tactical_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
ShipMoved = TRUE; ShipMoved = TRUE;
/* Disable ship's special completely for the Standard AI */ /* Disable ship's special completely for the Standard AI */
if (PlayerControl[context->playerNr] & STANDARD_RATING) if (StarShipPtr->control & STANDARD_RATING)
++StarShipPtr->special_counter; ++StarShipPtr->special_counter;
#ifdef DEBUG_CYBORG #ifdef DEBUG_CYBORG
@@ -1259,7 +1259,7 @@ if (!(ShipPtr->state_flags & FINITE_LIFE)
ed.which_turn = 0; ed.which_turn = 0;
} }
} }
else if (!(PlayerControl[context->playerNr] & AWESOME_RATING)) else if (!(StarShipPtr->control & AWESOME_RATING))
ed.which_turn = 0; ed.which_turn = 0;
else else
{ {
+2
View File
@@ -142,6 +142,7 @@ BuildBattle (COUNT which_player)
BuiltShipPtr = LockStarShip (&race_q[which_player], hBuiltShip); BuiltShipPtr = LockStarShip (&race_q[which_player], hBuiltShip);
BuiltShipPtr->captains_name_index = FragPtr->captains_name_index; BuiltShipPtr->captains_name_index = FragPtr->captains_name_index;
BuiltShipPtr->which_side = 1 << which_player; BuiltShipPtr->which_side = 1 << which_player;
BuiltShipPtr->playerNr = which_player;
if (FragPtr->crew_level != INFINITE_FLEET) if (FragPtr->crew_level != INFINITE_FLEET)
BuiltShipPtr->crew_level = FragPtr->crew_level; BuiltShipPtr->crew_level = FragPtr->crew_level;
else /* if infinite ships */ else /* if infinite ships */
@@ -165,6 +166,7 @@ BuildBattle (COUNT which_player)
BuiltShipPtr = LockStarShip (&race_q[0], hBuiltShip); BuiltShipPtr = LockStarShip (&race_q[0], hBuiltShip);
BuiltShipPtr->captains_name_index = 0; BuiltShipPtr->captains_name_index = 0;
BuiltShipPtr->which_side = GOOD_GUY; BuiltShipPtr->which_side = GOOD_GUY;
BuiltShipPtr->playerNr = 0;
BuiltShipPtr->crew_level = 0; BuiltShipPtr->crew_level = 0;
BuiltShipPtr->max_crew = 0; BuiltShipPtr->max_crew = 0;
// Crew will be copied directly from // Crew will be copied directly from
+1
View File
@@ -166,6 +166,7 @@ BuildSIS (void)
return 0; return 0;
StarShipPtr = LockStarShip (&race_q[0], hStarShip); StarShipPtr = LockStarShip (&race_q[0], hStarShip);
StarShipPtr->which_side = GOOD_GUY; StarShipPtr->which_side = GOOD_GUY;
StarShipPtr->playerNr = 0;
StarShipPtr->captains_name_index = 0; StarShipPtr->captains_name_index = 0;
UnlockStarShip (&race_q[0], hStarShip); UnlockStarShip (&race_q[0], hStarShip);
+1 -3
View File
@@ -27,8 +27,6 @@
#include <stdio.h> #include <stdio.h>
SIZE cur_player;
BATTLE_INPUT_STATE BATTLE_INPUT_STATE
computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr) computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
{ {
@@ -40,7 +38,7 @@ computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
if (StarShipPtr) if (StarShipPtr)
{ {
// Selecting the next action for in battle. // Selecting the next action for in battle.
if (PlayerControl[context->playerNr] & CYBORG_CONTROL) if (StarShipPtr->control & CYBORG_CONTROL)
{ {
InputState = tactical_intelligence (context, StarShipPtr); InputState = tactical_intelligence (context, StarShipPtr);
-2
View File
@@ -44,8 +44,6 @@ enum
FIRST_EMPTY_INDEX FIRST_EMPTY_INDEX
}; };
extern SIZE cur_player;
extern BATTLE_INPUT_STATE computer_intelligence ( extern BATTLE_INPUT_STATE computer_intelligence (
ComputerInputContext *context, STARSHIP *StarShipPtr); ComputerInputContext *context, STARSHIP *StarShipPtr);
extern BATTLE_INPUT_STATE tactical_intelligence ( extern BATTLE_INPUT_STATE tactical_intelligence (
+1
View File
@@ -1688,6 +1688,7 @@ BuildAndDrawShipList (MELEE_STATE *pMS)
BuiltShipPtr->index = index; BuiltShipPtr->index = index;
BuiltShipPtr->ship_cost = ship_cost; BuiltShipPtr->ship_cost = ship_cost;
BuiltShipPtr->which_side = 1 << side; BuiltShipPtr->which_side = 1 << side;
BuiltShipPtr->playerNr = side;
BuiltShipPtr->captains_name_index = captains_name_index; BuiltShipPtr->captains_name_index = captains_name_index;
// The next ones are not used in Melee // The next ones are not used in Melee
BuiltShipPtr->crew_level = 0; BuiltShipPtr->crew_level = 0;
-2
View File
@@ -47,8 +47,6 @@ static void reportShipSelected (GETMELEE_STATE *gms, COUNT index);
#endif #endif
// Returns the <index>th ship in the queue, or 0 if it is not available. // Returns the <index>th ship in the queue, or 0 if it is not available.
// For all the ships in the queue, the ShipFacing field contains the
// index in the queue.
static HSTARSHIP static HSTARSHIP
MeleeShipByQueueIndex (const QUEUE *queue, COUNT index) MeleeShipByQueueIndex (const QUEUE *queue, COUNT index)
{ {
+1
View File
@@ -404,6 +404,7 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
* the maximum, instead of the normal level */ * the maximum, instead of the normal level */
SPtr->crew_level = FragPtr->max_crew; SPtr->crew_level = FragPtr->max_crew;
SPtr->which_side = 1 << which_player; SPtr->which_side = 1 << which_player;
SPtr->playerNr = which_player;
SPtr->captains_name_index = PickCaptainName (); SPtr->captains_name_index = PickCaptainName ();
battle_counter[1]++; battle_counter[1]++;
+5
View File
@@ -273,6 +273,11 @@ struct STARSHIP
HELEMENT hShip; HELEMENT hShip;
COUNT ShipFacing; COUNT ShipFacing;
COUNT playerNr;
// 0: bottom player; In full-game: the human player
BYTE control;
// HUMAN, COMPUTER or NETWORK control flags, see intel.h
}; };
static inline STARSHIP * static inline STARSHIP *
-1
View File
@@ -55,7 +55,6 @@ extern QUEUE race_q[];
extern ACTIVITY LastActivity; extern ACTIVITY LastActivity;
extern BYTE PlayerControl[]; extern BYTE PlayerControl[];
extern SIZE cur_player;
BOOLEAN InitContexts (void); BOOLEAN InitContexts (void);
void UninitPlayerInput (void); void UninitPlayerInput (void);
+4 -6
View File
@@ -502,9 +502,6 @@ GetNextStarShip (STARSHIP *LastStarShipPtr, COUNT which_side)
{ {
HSTARSHIP hBattleShip; HSTARSHIP hBattleShip;
cur_player = which_side;
hBattleShip = GetEncounterStarShip (LastStarShipPtr, which_side); hBattleShip = GetEncounterStarShip (LastStarShipPtr, which_side);
if (hBattleShip) if (hBattleShip)
{ {
@@ -564,10 +561,11 @@ GetInitialStarShips (void)
} }
else else
{ {
COUNT num_ships = NUM_PLAYERS; int i;
while (num_ships--)
for (i = NUM_PLAYERS; i > 0; --i)
{ {
if (!GetNextStarShip (NULL, num_ships == 1)) if (!GetNextStarShip (NULL, i - 1))
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
+1 -1
View File
@@ -316,7 +316,7 @@ zoqfotpik_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
|| (ConcernCounter == ENEMY_WEAPON_INDEX || (ConcernCounter == ENEMY_WEAPON_INDEX
&& ObjectsOfConcern->MoveState != AVOID && ObjectsOfConcern->MoveState != AVOID
#ifdef NEVER #ifdef NEVER
&& !(PlayerControl[cur_player] & STANDARD_RATING) && !(StarShipPtr->control & STANDARD_RATING)
#endif /* NEVER */ #endif /* NEVER */
)) ))
&& ship_weapons (ShipPtr, && ship_weapons (ShipPtr,