From 5e6fe6e4ac91f8f1088a5edf41cb2e199e241748 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 14:54:14 -0700 Subject: [PATCH 1/5] sector_move_processing.php: add comments Add comments to clarify what the two different mine processing sections are for (tl;dr: one is for hitting while leaving, and the other is for hitting while entering). --- engine/Default/sector_move_processing.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/Default/sector_move_processing.php b/engine/Default/sector_move_processing.php index a61268616..64732695b 100644 --- a/engine/Default/sector_move_processing.php +++ b/engine/Default/sector_move_processing.php @@ -51,6 +51,7 @@ if (!$sector->isLinked($var['target_sector'])) create_error('You cannot move to that sector!'); +// If you bump into mines in the sector you are trying to leave... if ($player->getLastSectorID() != $var['target_sector']) { $sectorForces =& $sector->getForces(); Sorter::sortByNumMethod($sectorForces,'getMines',true); @@ -138,6 +139,7 @@ } } unset($forces); +// If you bump into mines while entering the target sector... if ($mine_owner_id) { if ($player->hasNewbieTurns()) { $turns = $sectorForces[$mine_owner_id]->getBumpTurnCost($ship); From 6cb6ad462042aa944fb0e47df59507fb19015e2f Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 15:29:19 -0700 Subject: [PATCH 2/5] forces_attack.php: adjust element spacing Add an extra line break between the completion message and the continuation button. --- templates/Default/engine/Default/forces_attack.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/Default/engine/Default/forces_attack.php b/templates/Default/engine/Default/forces_attack.php index b50d4fe04..a766c7fb9 100644 --- a/templates/Default/engine/Default/forces_attack.php +++ b/templates/Default/engine/Default/forces_attack.php @@ -14,7 +14,8 @@ } else { ?>You have destroyed the forces.
+ } ?> +

- \ No newline at end of file + From 2809308a6fd8441e2aec301aa42583bcc1514924 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 14:20:18 -0700 Subject: [PATCH 3/5] SectorForces.inc: remove commented out code --- .../Default/engine/Default/includes/SectorForces.inc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/templates/Default/engine/Default/includes/SectorForces.inc b/templates/Default/engine/Default/includes/SectorForces.inc index 1c56dd1dc..22c427a92 100644 --- a/templates/Default/engine/Default/includes/SectorForces.inc +++ b/templates/Default/engine/Default/includes/SectorForces.inc @@ -59,14 +59,7 @@ ?>WAR - getLinkedDisplayName(); -// } -// else { -// UNKNOWN -// } ?> - + getLinkedDisplayName(); ?>
@@ -98,4 +91,4 @@ -
\ No newline at end of file + From a50cedfb430359ff027995ff3e5f7c56070cfc76 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 15:13:20 -0700 Subject: [PATCH 4/5] Remove the Examine page for enemy forces Since we now have only the attacking player engaged in force combat, there is little reason to have the "Examine" page for enemy forces. We know everything about the forces from the Current Sector page, so this intermediate page adds no new information. This extra page causes a lot of unnecessary headaches when multiple people are targetting forces, because you are often examining forces that have already been destroyed. --- engine/Default/forces_attack_processing.php | 16 +-- engine/Default/forces_examine.php | 101 ------------------ lib/Default/SmrForce.class.inc | 6 -- lib/Default/SmrSession.class.inc | 1 - .../engine/Default/includes/SectorForces.inc | 26 ++--- 5 files changed, 19 insertions(+), 131 deletions(-) delete mode 100644 engine/Default/forces_examine.php diff --git a/engine/Default/forces_attack_processing.php b/engine/Default/forces_attack_processing.php index 8348eb412..c550f2398 100644 --- a/engine/Default/forces_attack_processing.php +++ b/engine/Default/forces_attack_processing.php @@ -1,4 +1,8 @@ getGameID(), $player->getSectorID(), $var['owner_id']); +$forceOwner = $forces->getOwner(); + if ($player->hasNewbieTurns()) create_error('You are under newbie protection!'); if($player->hasFederalProtection()) @@ -7,9 +11,10 @@ create_error('You cannot attack forces whilst on a planet!'); if(!$player->canFight()) create_error('You are not allowed to fight!'); - -require_once(get_file_loc('SmrForce.class.inc')); -$forces =& SmrForce::getForce($player->getGameID(), $player->getSectorID(), $var['owner_id']); +if (!$ship->hasWeapons() && !$ship->hasCDs()) + create_error('You cannot attack without weapons!'); +if ($player->forceNAPAlliance($forceOwner)) + create_error('You cannot attack allied forces!'); // The attack is processed slightly differently if the attacker bumped into mines // when moving into sector @@ -31,11 +36,6 @@ create_error('You do not have enough turns to attack these forces!'); } -$forceOwner =& $forces->getOwner(); - -if($player->forceNAPAlliance($forceOwner)) - create_error('You have a force NAP, you cannot attack these forces!'); - // take the turns if ($bump) { $player->takeTurns($forces->getBumpTurnCost($ship)); diff --git a/engine/Default/forces_examine.php b/engine/Default/forces_examine.php deleted file mode 100644 index 61a66e991..000000000 --- a/engine/Default/forces_examine.php +++ /dev/null @@ -1,101 +0,0 @@ -getGameID(), $player->getSectorID(), $var['owner_id']); - -// first check if both ship and forces are in same sector -if ($player->getSectorID() != $forces->getSectorID()) { - create_error('Those forces are no longer here!'); -} - -$forces_owner =& $forces->getOwner(); - -$template->assign('PageTopic','Examine Forces'); - -// should we display an attack button -if (($ship->getAttackRating() > 0 || $ship->getCDs() > 0) && - !$player->hasFederalProtection() && - !$player->hasNewbieTurns() && - !$player->isLandedOnPlanet() && - !$player->forceNAPAlliance($forces_owner)) { - - $container = array(); - $container['url'] = 'forces_attack_processing.php'; - $container['action'] = 'attack'; - transfer('target'); - transfer('owner_id'); - $PHP_OUTPUT.=create_echo_form($container); - $PHP_OUTPUT.=create_submit('Attack Forces (' . $forces->getAttackTurnCost($ship) . ')'); - $PHP_OUTPUT.=('
'); - -} elseif ($player->hasFederalProtection()) - $PHP_OUTPUT.=('

You are under federal protection! That wouldn\'t be fair.

'); -elseif ($player->hasNewbieTurns()) - $PHP_OUTPUT.=('

You are under newbie protection!

'); -elseif ($forces_owner->getAccountID() == $player->getAccountID()) - $PHP_OUTPUT.=('

These are your forces!

'); -elseif ($player->forceNAPAlliance($forces_owner)) - $PHP_OUTPUT.=('

These are allied forces!

'); - -$PHP_OUTPUT.=('
'); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); - -// ******************************** -// * -// * A t t a c k e r -// * -// ******************************** - -$sector =& $player->getSector(); -$attackers =& $sector->getFightingTradersAgainstForces($player, $forces); -$attackers[$player->getAccountID()] =& $player; - -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=(''); -$PHP_OUTPUT.=('
AttackerForces
'); - -foreach($attackers as &$attacker) { - $attackerShip =& $attacker->getShip(); - - $PHP_OUTPUT.=($attacker->getLevelName().'
'); - $PHP_OUTPUT.=($attacker->getLinkedDisplayName(false).'
'); - $PHP_OUTPUT.=('Race: '.$attacker->getRaceName().'
'); - $PHP_OUTPUT.=('Level: '.$attacker->getLevelID().'
'); - $PHP_OUTPUT.=('Alliance: '.$attacker->getAllianceName(true).'

'); - $PHP_OUTPUT.=(''); - $PHP_OUTPUT.=($attackerShip->getName().'
'); - $PHP_OUTPUT.=('Rating : ' . $attackerShip->getAttackRating() . '/' . $attackerShip->getDefenseRating() . '
'); - $PHP_OUTPUT.=('Shields : ' . $attackerShip->getShields() . '
'); - $PHP_OUTPUT.=('Armour : ' . $attackerShip->getArmour() . '
'); - $PHP_OUTPUT.=('Hard Points: '.$attackerShip->getNumWeapons().'
'); - $PHP_OUTPUT.=('Combat Drones: ' . $attackerShip->getCDs()); - $PHP_OUTPUT.=('



'); -} - -$PHP_OUTPUT.=('
'); - -// ******************************** -// * -// * F o r c e s -// * -// ******************************** - -if ($player->forceNAPAlliance($forces_owner)) { - // you can't attack ur own alliance forces. - $PHP_OUTPUT.=' '; -} -else { - $PHP_OUTPUT.=('Mines: '.$forces->getMines().'
'); - $PHP_OUTPUT.=('Combat Drones: '.$forces->getCDs().'
'); - $PHP_OUTPUT.=('Scouts: '.$forces->getSDs().'

'); -} - -$PHP_OUTPUT.=('
'); -$PHP_OUTPUT.=('
'); diff --git a/lib/Default/SmrForce.class.inc b/lib/Default/SmrForce.class.inc index ae9f440c8..5b1f1a280 100644 --- a/lib/Default/SmrForce.class.inc +++ b/lib/Default/SmrForce.class.inc @@ -406,12 +406,6 @@ class SmrForce { return SmrSession::getNewHREF($container); } - public function getExamineAttackForcesHREF() { - $container = create_container('skeleton.php', 'forces_examine.php'); - $container['owner_id'] = $this->getOwnerID(); - return SmrSession::getNewHREF($container); - } - public function getAttackForcesHREF() { $container = create_container('forces_attack_processing.php'); $container['action'] = 'attack'; diff --git a/lib/Default/SmrSession.class.inc b/lib/Default/SmrSession.class.inc index 1ffe17d2b..47315edf7 100644 --- a/lib/Default/SmrSession.class.inc +++ b/lib/Default/SmrSession.class.inc @@ -38,7 +38,6 @@ class SmrSession { 'donation.php' => self::ALWAYS_AVAILABLE, 'feature_request_comments.php' => self::ALWAYS_AVAILABLE, 'feature_request.php' => self::ALWAYS_AVAILABLE, - 'forces_examine.php' => self::ALWAYS_AVAILABLE, 'forces_list.php' => self::ALWAYS_AVAILABLE, 'forces_mass_refresh.php' => self::ALWAYS_AVAILABLE, 'government.php' => 1, diff --git a/templates/Default/engine/Default/includes/SectorForces.inc b/templates/Default/engine/Default/includes/SectorForces.inc index 22c427a92..606d196ba 100644 --- a/templates/Default/engine/Default/includes/SectorForces.inc +++ b/templates/Default/engine/Default/includes/SectorForces.inc @@ -60,22 +60,18 @@ } ?> getLinkedDisplayName(); ?> - - - -
-
+ +

+ + From 6607aef66bbb7e1d4bb079be2ba19c788ce22586 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Fri, 27 Apr 2018 17:58:54 -0700 Subject: [PATCH 5/5] 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) {