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:
@@ -156,8 +156,7 @@ ProcessInput (void)
|
||||
for (sideI = 0; sideI < NUM_SIDES; sideI++)
|
||||
{
|
||||
HSTARSHIP hBattleShip, hNextShip;
|
||||
|
||||
cur_player = battleInputOrder[sideI];
|
||||
size_t cur_player = battleInputOrder[sideI];
|
||||
|
||||
for (hBattleShip = GetHeadLink (&race_q[cur_player]);
|
||||
hBattleShip != 0; hBattleShip = hNextShip)
|
||||
@@ -170,6 +169,10 @@ ProcessInput (void)
|
||||
|
||||
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 (
|
||||
PlayerInput[cur_player], StarShipPtr);
|
||||
|
||||
|
||||
@@ -435,11 +435,11 @@ ship_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
|
||||
ShipFired = FALSE;
|
||||
}
|
||||
|
||||
if (PlayerControl[cur_player] & AWESOME_RATING)
|
||||
if (StarShipPtr->control & AWESOME_RATING)
|
||||
margin_of_error = 0;
|
||||
else if (PlayerControl[cur_player] & GOOD_RATING)
|
||||
else if (StarShipPtr->control & GOOD_RATING)
|
||||
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);
|
||||
|
||||
ObjectsOfConcern += ConcernCounter;
|
||||
@@ -464,7 +464,7 @@ ship_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
|
||||
|| (ConcernCounter == ENEMY_WEAPON_INDEX
|
||||
&& ObjectsOfConcern->MoveState != AVOID
|
||||
#ifdef NEVER
|
||||
&& !(PlayerControl[cur_player] & STANDARD_RATING)
|
||||
&& !(StarShipPtr->control & STANDARD_RATING)
|
||||
#endif /* NEVER */
|
||||
)))
|
||||
{
|
||||
@@ -1035,7 +1035,7 @@ tactical_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
|
||||
|
||||
ShipMoved = TRUE;
|
||||
/* Disable ship's special completely for the Standard AI */
|
||||
if (PlayerControl[context->playerNr] & STANDARD_RATING)
|
||||
if (StarShipPtr->control & STANDARD_RATING)
|
||||
++StarShipPtr->special_counter;
|
||||
|
||||
#ifdef DEBUG_CYBORG
|
||||
@@ -1259,7 +1259,7 @@ if (!(ShipPtr->state_flags & FINITE_LIFE)
|
||||
ed.which_turn = 0;
|
||||
}
|
||||
}
|
||||
else if (!(PlayerControl[context->playerNr] & AWESOME_RATING))
|
||||
else if (!(StarShipPtr->control & AWESOME_RATING))
|
||||
ed.which_turn = 0;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -142,6 +142,7 @@ 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;
|
||||
BuiltShipPtr->playerNr = which_player;
|
||||
if (FragPtr->crew_level != INFINITE_FLEET)
|
||||
BuiltShipPtr->crew_level = FragPtr->crew_level;
|
||||
else /* if infinite ships */
|
||||
@@ -165,6 +166,7 @@ BuildBattle (COUNT which_player)
|
||||
BuiltShipPtr = LockStarShip (&race_q[0], hBuiltShip);
|
||||
BuiltShipPtr->captains_name_index = 0;
|
||||
BuiltShipPtr->which_side = GOOD_GUY;
|
||||
BuiltShipPtr->playerNr = 0;
|
||||
BuiltShipPtr->crew_level = 0;
|
||||
BuiltShipPtr->max_crew = 0;
|
||||
// Crew will be copied directly from
|
||||
|
||||
@@ -166,6 +166,7 @@ BuildSIS (void)
|
||||
return 0;
|
||||
StarShipPtr = LockStarShip (&race_q[0], hStarShip);
|
||||
StarShipPtr->which_side = GOOD_GUY;
|
||||
StarShipPtr->playerNr = 0;
|
||||
StarShipPtr->captains_name_index = 0;
|
||||
UnlockStarShip (&race_q[0], hStarShip);
|
||||
|
||||
|
||||
+1
-3
@@ -27,8 +27,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
SIZE cur_player;
|
||||
|
||||
BATTLE_INPUT_STATE
|
||||
computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
|
||||
{
|
||||
@@ -40,7 +38,7 @@ computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr)
|
||||
if (StarShipPtr)
|
||||
{
|
||||
// Selecting the next action for in battle.
|
||||
if (PlayerControl[context->playerNr] & CYBORG_CONTROL)
|
||||
if (StarShipPtr->control & CYBORG_CONTROL)
|
||||
{
|
||||
InputState = tactical_intelligence (context, StarShipPtr);
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ enum
|
||||
FIRST_EMPTY_INDEX
|
||||
};
|
||||
|
||||
extern SIZE cur_player;
|
||||
|
||||
extern BATTLE_INPUT_STATE computer_intelligence (
|
||||
ComputerInputContext *context, STARSHIP *StarShipPtr);
|
||||
extern BATTLE_INPUT_STATE tactical_intelligence (
|
||||
|
||||
@@ -1688,6 +1688,7 @@ BuildAndDrawShipList (MELEE_STATE *pMS)
|
||||
BuiltShipPtr->index = index;
|
||||
BuiltShipPtr->ship_cost = ship_cost;
|
||||
BuiltShipPtr->which_side = 1 << side;
|
||||
BuiltShipPtr->playerNr = side;
|
||||
BuiltShipPtr->captains_name_index = captains_name_index;
|
||||
// The next ones are not used in Melee
|
||||
BuiltShipPtr->crew_level = 0;
|
||||
|
||||
@@ -47,8 +47,6 @@ static void reportShipSelected (GETMELEE_STATE *gms, COUNT index);
|
||||
#endif
|
||||
|
||||
// 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
|
||||
MeleeShipByQueueIndex (const QUEUE *queue, COUNT index)
|
||||
{
|
||||
|
||||
@@ -404,6 +404,7 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
|
||||
* the maximum, instead of the normal level */
|
||||
SPtr->crew_level = FragPtr->max_crew;
|
||||
SPtr->which_side = 1 << which_player;
|
||||
SPtr->playerNr = which_player;
|
||||
SPtr->captains_name_index = PickCaptainName ();
|
||||
|
||||
battle_counter[1]++;
|
||||
|
||||
@@ -273,6 +273,11 @@ struct STARSHIP
|
||||
|
||||
HELEMENT hShip;
|
||||
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 *
|
||||
|
||||
@@ -55,7 +55,6 @@ extern QUEUE race_q[];
|
||||
extern ACTIVITY LastActivity;
|
||||
|
||||
extern BYTE PlayerControl[];
|
||||
extern SIZE cur_player;
|
||||
|
||||
BOOLEAN InitContexts (void);
|
||||
void UninitPlayerInput (void);
|
||||
|
||||
+4
-6
@@ -502,9 +502,6 @@ GetNextStarShip (STARSHIP *LastStarShipPtr, COUNT which_side)
|
||||
{
|
||||
HSTARSHIP hBattleShip;
|
||||
|
||||
cur_player = which_side;
|
||||
|
||||
|
||||
hBattleShip = GetEncounterStarShip (LastStarShipPtr, which_side);
|
||||
if (hBattleShip)
|
||||
{
|
||||
@@ -564,10 +561,11 @@ GetInitialStarShips (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
COUNT num_ships = NUM_PLAYERS;
|
||||
while (num_ships--)
|
||||
int i;
|
||||
|
||||
for (i = NUM_PLAYERS; i > 0; --i)
|
||||
{
|
||||
if (!GetNextStarShip (NULL, num_ships == 1))
|
||||
if (!GetNextStarShip (NULL, i - 1))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -316,7 +316,7 @@ zoqfotpik_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
|
||||
|| (ConcernCounter == ENEMY_WEAPON_INDEX
|
||||
&& ObjectsOfConcern->MoveState != AVOID
|
||||
#ifdef NEVER
|
||||
&& !(PlayerControl[cur_player] & STANDARD_RATING)
|
||||
&& !(StarShipPtr->control & STANDARD_RATING)
|
||||
#endif /* NEVER */
|
||||
))
|
||||
&& ship_weapons (ShipPtr,
|
||||
|
||||
Reference in New Issue
Block a user