Skip to content

Commit

Permalink
forces_attack_processing.php: optimize for single attacker
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hemberger committed Apr 28, 2018
1 parent a50cedf commit 6607aef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
8 changes: 1 addition & 7 deletions engine/Default/forces_attack_processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion htdocs/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 3 additions & 16 deletions lib/Default/SmrSector.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6607aef

Please sign in to comment.