From: <av...@us...> - 2009-10-30 19:27:53
|
Revision: 3264 http://sc2.svn.sourceforge.net/sc2/?rev=3264&view=rev Author: avolkov Date: 2009-10-30 19:27:41 +0000 (Fri, 30 Oct 2009) Log Message: ----------- Battle & ship code cleanup: Removed the global var cur_player; control flags propagated forward Modified Paths: -------------- trunk/sc2/src/uqm/battle.c trunk/sc2/src/uqm/cyborg.c trunk/sc2/src/uqm/encount.c trunk/sc2/src/uqm/init.c trunk/sc2/src/uqm/intel.c trunk/sc2/src/uqm/intel.h trunk/sc2/src/uqm/melee.c trunk/sc2/src/uqm/pickmele.c trunk/sc2/src/uqm/pickship.c trunk/sc2/src/uqm/races.h trunk/sc2/src/uqm/setup.h trunk/sc2/src/uqm/ship.c trunk/sc2/src/uqm/ships/zoqfot/zoqfot.c Modified: trunk/sc2/src/uqm/battle.c =================================================================== --- trunk/sc2/src/uqm/battle.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/battle.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -156,9 +156,8 @@ for (sideI = 0; sideI < NUM_SIDES; sideI++) { HSTARSHIP hBattleShip, hNextShip; + size_t cur_player = battleInputOrder[sideI]; - cur_player = battleInputOrder[sideI]; - for (hBattleShip = GetHeadLink (&race_q[cur_player]); hBattleShip != 0; hBattleShip = hNextShip) { @@ -170,6 +169,10 @@ 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); Modified: trunk/sc2/src/uqm/cyborg.c =================================================================== --- trunk/sc2/src/uqm/cyborg.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/cyborg.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -435,11 +435,11 @@ 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 @@ || (ConcernCounter == ENEMY_WEAPON_INDEX && ObjectsOfConcern->MoveState != AVOID #ifdef NEVER - && !(PlayerControl[cur_player] & STANDARD_RATING) + && !(StarShipPtr->control & STANDARD_RATING) #endif /* NEVER */ ))) { @@ -1035,7 +1035,7 @@ 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 @@ ed.which_turn = 0; } } - else if (!(PlayerControl[context->playerNr] & AWESOME_RATING)) + else if (!(StarShipPtr->control & AWESOME_RATING)) ed.which_turn = 0; else { Modified: trunk/sc2/src/uqm/encount.c =================================================================== --- trunk/sc2/src/uqm/encount.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/encount.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -142,6 +142,7 @@ 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 @@ 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 Modified: trunk/sc2/src/uqm/init.c =================================================================== --- trunk/sc2/src/uqm/init.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/init.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -166,6 +166,7 @@ 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); Modified: trunk/sc2/src/uqm/intel.c =================================================================== --- trunk/sc2/src/uqm/intel.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/intel.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -27,8 +27,6 @@ #include <stdio.h> -SIZE cur_player; - BATTLE_INPUT_STATE computer_intelligence (ComputerInputContext *context, STARSHIP *StarShipPtr) { @@ -40,7 +38,7 @@ 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); Modified: trunk/sc2/src/uqm/intel.h =================================================================== --- trunk/sc2/src/uqm/intel.h 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/intel.h 2009-10-30 19:27:41 UTC (rev 3264) @@ -44,8 +44,6 @@ FIRST_EMPTY_INDEX }; -extern SIZE cur_player; - extern BATTLE_INPUT_STATE computer_intelligence ( ComputerInputContext *context, STARSHIP *StarShipPtr); extern BATTLE_INPUT_STATE tactical_intelligence ( Modified: trunk/sc2/src/uqm/melee.c =================================================================== --- trunk/sc2/src/uqm/melee.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/melee.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -1688,6 +1688,7 @@ 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; Modified: trunk/sc2/src/uqm/pickmele.c =================================================================== --- trunk/sc2/src/uqm/pickmele.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/pickmele.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -47,8 +47,6 @@ #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) { Modified: trunk/sc2/src/uqm/pickship.c =================================================================== --- trunk/sc2/src/uqm/pickship.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/pickship.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -404,6 +404,7 @@ * 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]++; Modified: trunk/sc2/src/uqm/races.h =================================================================== --- trunk/sc2/src/uqm/races.h 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/races.h 2009-10-30 19:27:41 UTC (rev 3264) @@ -273,6 +273,11 @@ 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 * Modified: trunk/sc2/src/uqm/setup.h =================================================================== --- trunk/sc2/src/uqm/setup.h 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/setup.h 2009-10-30 19:27:41 UTC (rev 3264) @@ -55,7 +55,6 @@ extern ACTIVITY LastActivity; extern BYTE PlayerControl[]; -extern SIZE cur_player; BOOLEAN InitContexts (void); void UninitPlayerInput (void); Modified: trunk/sc2/src/uqm/ship.c =================================================================== --- trunk/sc2/src/uqm/ship.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/ship.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -502,9 +502,6 @@ { HSTARSHIP hBattleShip; - cur_player = which_side; - - hBattleShip = GetEncounterStarShip (LastStarShipPtr, which_side); if (hBattleShip) { @@ -564,10 +561,11 @@ } 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; Modified: trunk/sc2/src/uqm/ships/zoqfot/zoqfot.c =================================================================== --- trunk/sc2/src/uqm/ships/zoqfot/zoqfot.c 2009-10-29 22:32:22 UTC (rev 3263) +++ trunk/sc2/src/uqm/ships/zoqfot/zoqfot.c 2009-10-30 19:27:41 UTC (rev 3264) @@ -316,7 +316,7 @@ || (ConcernCounter == ENEMY_WEAPON_INDEX && ObjectsOfConcern->MoveState != AVOID #ifdef NEVER - && !(PlayerControl[cur_player] & STANDARD_RATING) + && !(StarShipPtr->control & STANDARD_RATING) #endif /* NEVER */ )) && ship_weapons (ShipPtr, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |