diff --git a/sc2/src/uqm/battle.c b/sc2/src/uqm/battle.c index 7d6a254a5..84d55e958 100644 --- a/sc2/src/uqm/battle.c +++ b/sc2/src/uqm/battle.c @@ -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); diff --git a/sc2/src/uqm/cyborg.c b/sc2/src/uqm/cyborg.c index 45128a7a2..d86f14ae5 100644 --- a/sc2/src/uqm/cyborg.c +++ b/sc2/src/uqm/cyborg.c @@ -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 { diff --git a/sc2/src/uqm/encount.c b/sc2/src/uqm/encount.c index 627c8abe8..f30370d1d 100644 --- a/sc2/src/uqm/encount.c +++ b/sc2/src/uqm/encount.c @@ -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 diff --git a/sc2/src/uqm/init.c b/sc2/src/uqm/init.c index 2546d629a..c6c1cb3f3 100644 --- a/sc2/src/uqm/init.c +++ b/sc2/src/uqm/init.c @@ -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); diff --git a/sc2/src/uqm/intel.c b/sc2/src/uqm/intel.c index 627ae79a4..9cb7aeee1 100644 --- a/sc2/src/uqm/intel.c +++ b/sc2/src/uqm/intel.c @@ -27,8 +27,6 @@ #include -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); diff --git a/sc2/src/uqm/intel.h b/sc2/src/uqm/intel.h index 09a329f3e..b5381acaa 100644 --- a/sc2/src/uqm/intel.h +++ b/sc2/src/uqm/intel.h @@ -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 ( diff --git a/sc2/src/uqm/melee.c b/sc2/src/uqm/melee.c index 77723f738..c68df9bc2 100644 --- a/sc2/src/uqm/melee.c +++ b/sc2/src/uqm/melee.c @@ -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; diff --git a/sc2/src/uqm/pickmele.c b/sc2/src/uqm/pickmele.c index 300cf6e26..3716f5641 100644 --- a/sc2/src/uqm/pickmele.c +++ b/sc2/src/uqm/pickmele.c @@ -47,8 +47,6 @@ static void reportShipSelected (GETMELEE_STATE *gms, COUNT index); #endif // Returns the 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) { diff --git a/sc2/src/uqm/pickship.c b/sc2/src/uqm/pickship.c index a00afe39a..1e3e0cb4c 100644 --- a/sc2/src/uqm/pickship.c +++ b/sc2/src/uqm/pickship.c @@ -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]++; diff --git a/sc2/src/uqm/races.h b/sc2/src/uqm/races.h index a728daab7..5069c169b 100644 --- a/sc2/src/uqm/races.h +++ b/sc2/src/uqm/races.h @@ -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 * diff --git a/sc2/src/uqm/setup.h b/sc2/src/uqm/setup.h index fa5152d59..1d6bf3cb3 100644 --- a/sc2/src/uqm/setup.h +++ b/sc2/src/uqm/setup.h @@ -55,7 +55,6 @@ extern QUEUE race_q[]; extern ACTIVITY LastActivity; extern BYTE PlayerControl[]; -extern SIZE cur_player; BOOLEAN InitContexts (void); void UninitPlayerInput (void); diff --git a/sc2/src/uqm/ship.c b/sc2/src/uqm/ship.c index 7aa480c0b..759e9bfbc 100644 --- a/sc2/src/uqm/ship.c +++ b/sc2/src/uqm/ship.c @@ -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; diff --git a/sc2/src/uqm/ships/zoqfot/zoqfot.c b/sc2/src/uqm/ships/zoqfot/zoqfot.c index 14d2b04bb..71fbabb6c 100644 --- a/sc2/src/uqm/ships/zoqfot/zoqfot.c +++ b/sc2/src/uqm/ships/zoqfot/zoqfot.c @@ -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,