From 6607aef66bbb7e1d4bb079be2ba19c788ce22586 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 17:58:54 -0700 Subject: [PATCH] forces_attack_processing.php: optimize for single attacker We have committed to only the attacker firing against forces, so it is no longer necessary to process every player in sector (which can be very expensive if there are a lot of people there). Instead, we simply use the current player as the attacker. --- engine/Default/forces_attack_processing.php | 8 +------- htdocs/config.php | 1 - lib/Default/SmrSector.class.inc | 19 +++---------------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/engine/Default/forces_attack_processing.php b/engine/Default/forces_attack_processing.php index c550f2398..c7611cbf4 100644 --- a/engine/Default/forces_attack_processing.php +++ b/engine/Default/forces_attack_processing.php @@ -60,13 +60,7 @@ 'Forces' => array(), 'Forced' => $bump); -$sector =& $player->getSector(); -if ($bump) { - //When hitting mines by bumping only the current player attacks/gets hit. - $attackers = array(&$player); -} else { - $attackers =& $sector->getFightingTradersAgainstForces($player, $forces); -} +$attackers = $player->getSector()->getFightingTradersAgainstForces($player, $bump); //decloak all attackers foreach($attackers as &$attacker) { diff --git a/htdocs/config.php b/htdocs/config.php index d398a514b..781f557f9 100644 --- a/htdocs/config.php +++ b/htdocs/config.php @@ -165,7 +165,6 @@ const MAXIMUM_PVP_FLEET_SIZE = 10; const MAXIMUM_PORT_FLEET_SIZE = 10; const MAXIMUM_PLANET_FLEET_SIZE = 10; -const MAXIMUM_FORCES_FLEET_SIZE = 1; const MINE_ARMOUR = 20; const CD_ARMOUR = 3; const SD_ARMOUR = 20; diff --git a/lib/Default/SmrSector.class.inc b/lib/Default/SmrSector.class.inc index d8ec261c7..f233c7c9f 100644 --- a/lib/Default/SmrSector.class.inc +++ b/lib/Default/SmrSector.class.inc @@ -825,22 +825,9 @@ class SmrSector { return false; } - public function &getFightingTradersAgainstForces(AbstractSmrPlayer $attackingPlayer, SmrForce $defendingForces) { - $forceOwner = $defendingForces->getOwner(); - if($attackingPlayer->forceNAPAlliance($forceOwner)) { - throw new Exception('The trader has a force NAP.'); - } - $fightingPlayers = array(); - $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(),$this->getSectorID(), array($attackingPlayer->getAllianceID())); - if(count($alliancePlayers) > 0) { - foreach($alliancePlayers as $accountID => $player) { - if($player->canFight()) { - if($attackingPlayer->traderAttackForceAlliance($player) && !$player->forceNAPAlliance($forceOwner)) - $fightingPlayers[$accountID] = $alliancePlayers[$accountID]; - } - } - } - return self::limitFightingTraders($fightingPlayers, $attackingPlayer, MAXIMUM_FORCES_FLEET_SIZE); + public function getFightingTradersAgainstForces(AbstractSmrPlayer $attackingPlayer, $bump) { + // Whether bumping or attacking, only the current player fires at forces + return array($attackingPlayer); } public function &getFightingTradersAgainstPort(AbstractSmrPlayer $attackingPlayer, SmrPort $defendingPort) {