From 8bde156ee241ea84e1fc9ad70e6a29996592a468 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Sun, 10 Mar 2019 12:22:39 -0700 Subject: [PATCH] Most functions now return by value Now that most variables are assigned by value instead of by reference, we can modify our function interfaces to only return results by value. See #317. --- lib/Default/AbstractSmrAccount.class.inc | 6 +-- lib/Default/AbstractSmrCombatWeapon.class.inc | 34 ++++++------- lib/Default/AbstractSmrLocation.class.inc | 14 ++--- lib/Default/AbstractSmrPlayer.class.inc | 30 +++++------ lib/Default/AbstractSmrPort.class.inc | 28 +++++----- lib/Default/AbstractSmrShip.class.inc | 40 +++++++-------- lib/Default/Council.class.inc | 2 +- lib/Default/Globals.class.inc | 14 ++--- lib/Default/SmrGalaxy.class.inc | 10 ++-- lib/Default/SmrPlayer.class.inc | 24 ++++----- lib/Default/SmrSector.class.inc | 51 +++++++++---------- 11 files changed, 124 insertions(+), 129 deletions(-) diff --git a/lib/Default/AbstractSmrAccount.class.inc b/lib/Default/AbstractSmrAccount.class.inc index ef993309a..c422ad25f 100644 --- a/lib/Default/AbstractSmrAccount.class.inc +++ b/lib/Default/AbstractSmrAccount.class.inc @@ -88,7 +88,7 @@ abstract class AbstractSmrAccount { return self::DEFAULT_HOTKEYS; } - public static function &getAccount($accountID,$forceUpdate = false) { + public static function getAccount($accountID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { self::$CACHE_ACCOUNTS[$accountID] = new SmrAccount($accountID); } @@ -416,7 +416,7 @@ abstract class AbstractSmrAccount { return $this->score; } - public function &getIndividualScores(SmrPlayer $player = null) { + public function getIndividualScores(SmrPlayer $player = null) { $gameID=0; if($player!=null) $gameID = $player->getGameID(); @@ -462,7 +462,7 @@ abstract class AbstractSmrAccount { return $this->referrerID>0; } - public function &getReferrer() { + public function getReferrer() { return SmrAccount::getAccount($this->getReferrerID()); } diff --git a/lib/Default/AbstractSmrCombatWeapon.class.inc b/lib/Default/AbstractSmrCombatWeapon.class.inc index 2aab1ffc1..d5fb6e0cb 100644 --- a/lib/Default/AbstractSmrCombatWeapon.class.inc +++ b/lib/Default/AbstractSmrCombatWeapon.class.inc @@ -77,14 +77,14 @@ abstract class AbstractSmrCombatWeapon { return array('MaxDamage' => $this->getMaxDamage(), 'Shield' => $this->getShieldDamage(), 'Armour' => $this->getArmourDamage(), 'Rollover' => $this->isDamageRollover()); } - abstract public function &getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces); - abstract public function &getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port); - abstract public function &getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet); - abstract public function &getModifiedPortDamageAgainstPlayer(SmrPort $port, AbstractSmrPlayer $targetPlayer); - abstract public function &getModifiedDamageAgainstPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer); - abstract public function &getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer); - - protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { + abstract public function getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces); + abstract public function getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port); + abstract public function getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet); + abstract public function getModifiedPortDamageAgainstPlayer(SmrPort $port, AbstractSmrPlayer $targetPlayer); + abstract public function getModifiedDamageAgainstPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer); + abstract public function getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer); + + protected function doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { $return['WeaponDamage'] = $this->getModifiedDamageAgainstForces($weaponPlayer,$forces); $return['ActualDamage'] = $forces->doWeaponDamage($return['WeaponDamage']); if($return['ActualDamage']['KillingShot']) @@ -92,7 +92,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { + protected function doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { $return['WeaponDamage'] = $this->getModifiedDamageAgainstPlayer($weaponPlayer,$targetPlayer); $return['ActualDamage'] = $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); @@ -101,7 +101,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) { + protected function doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) { $return['WeaponDamage'] = $this->getModifiedDamageAgainstPort($weaponPlayer,$port); $return['ActualDamage'] = $port->doWeaponDamage($return['WeaponDamage']); if($return['ActualDamage']['KillingShot']) @@ -109,7 +109,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { + protected function doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { $return['WeaponDamage'] = $this->getModifiedDamageAgainstPlanet($weaponPlayer,$planet); $return['ActualDamage'] = $planet->doWeaponDamage($return['WeaponDamage'],$delayed); if($return['ActualDamage']['KillingShot']) @@ -117,7 +117,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doPortDamageToPlayer(array &$return, SmrPort $port, AbstractSmrPlayer $targetPlayer) { + protected function doPortDamageToPlayer(array &$return, SmrPort $port, AbstractSmrPlayer $targetPlayer) { $return['WeaponDamage'] = $this->getModifiedPortDamageAgainstPlayer($port,$targetPlayer); $return['ActualDamage'] = $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); @@ -126,7 +126,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doPlanetDamageToPlayer(array &$return, SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { + protected function doPlanetDamageToPlayer(array &$return, SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { $return['WeaponDamage'] = $this->getModifiedPlanetDamageAgainstPlayer($planet,$targetPlayer); $return['ActualDamage'] = $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); @@ -135,7 +135,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - protected function &doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer) { + protected function doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer) { $return['WeaponDamage'] = $this->getModifiedForceDamageAgainstPlayer($forces,$targetPlayer); $return['ActualDamage'] = $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); @@ -144,7 +144,7 @@ abstract class AbstractSmrCombatWeapon { return $return; } - abstract public function &shootForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces); - abstract public function &shootPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer); - abstract public function &shootPlayerAsForce(SmrForce $forces, AbstractSmrPlayer $targetPlayer); + abstract public function shootForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces); + abstract public function shootPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer); + abstract public function shootPlayerAsForce(SmrForce $forces, AbstractSmrPlayer $targetPlayer); } diff --git a/lib/Default/AbstractSmrLocation.class.inc b/lib/Default/AbstractSmrLocation.class.inc index f9a8cdf78..7455feb9e 100644 --- a/lib/Default/AbstractSmrLocation.class.inc +++ b/lib/Default/AbstractSmrLocation.class.inc @@ -22,7 +22,7 @@ class AbstractSmrLocation { protected $shipsSold; protected $weaponsSold; - public static function &getAllLocations($forceUpdate = false) { + public static function getAllLocations($forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_ALL_LOCATIONS)) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM location_type ORDER BY location_type_id'); @@ -36,7 +36,7 @@ class AbstractSmrLocation { return self::$CACHE_ALL_LOCATIONS; } - public static function &getSectorLocations($gameID,$sectorID,$forceUpdate = false) { + public static function getSectorLocations($gameID,$sectorID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_SECTOR_LOCATIONS[$gameID][$sectorID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM location JOIN location_type USING (location_type_id) WHERE sector_id = ' . $db->escapeNumber($sectorID) . ' AND game_id=' . $db->escapeNumber($gameID)); @@ -50,7 +50,7 @@ class AbstractSmrLocation { return self::$CACHE_SECTOR_LOCATIONS[$gameID][$sectorID]; } - public static function &getLocation($locationTypeID, $forceUpdate=false, $db=null) { + public static function getLocation($locationTypeID, $forceUpdate=false, $db=null) { if($forceUpdate || !isset(self::$CACHE_LOCATIONS[$locationTypeID])) { self::$CACHE_LOCATIONS[$locationTypeID] = new SmrLocation($locationTypeID, $db); } @@ -225,7 +225,7 @@ class AbstractSmrLocation { } } - public function &getHardwareSold() { + public function getHardwareSold() { if(!isset($this->hardwareSold)) { $this->hardwareSold = array(); $this->db->query('SELECT hardware_type_id FROM location_sells_hardware WHERE ' . $this->SQL); @@ -261,7 +261,7 @@ class AbstractSmrLocation { unset($this->hardwareSold[$hardwareTypeID]); } - public function &getShipsSold() { + public function getShipsSold() { if(!isset($this->shipsSold)) { $this->shipsSold = array(); $this->db->query('SELECT * FROM location_sells_ships WHERE ' . $this->SQL); @@ -296,7 +296,7 @@ class AbstractSmrLocation { unset($this->shipsSold[$shipTypeID]); } - public function &getWeaponsSold() { + public function getWeaponsSold() { if(!isset($this->weaponsSold)) { $this->weaponsSold = array(); $this->db->query('SELECT * FROM location_sells_weapons JOIN weapon_type USING (weapon_type_id) WHERE ' . $this->SQL); @@ -330,7 +330,7 @@ class AbstractSmrLocation { unset($this->weaponsSold[$weaponTypeID]); } - public function &getLinkedLocations() { + public function getLinkedLocations() { $linkedLocations = array(); if($this->isHQ()) { if($this->getTypeID()==LOCATION_TYPE_FEDERAL_HQ) { diff --git a/lib/Default/AbstractSmrPlayer.class.inc b/lib/Default/AbstractSmrPlayer.class.inc index d49332b15..cd2bda420 100644 --- a/lib/Default/AbstractSmrPlayer.class.inc +++ b/lib/Default/AbstractSmrPlayer.class.inc @@ -66,7 +66,7 @@ abstract class AbstractSmrPlayer { return $this->gameID; } - public function &getGame() { + public function getGame() { return SmrGame::getGame($this->gameID); } @@ -108,11 +108,11 @@ abstract class AbstractSmrPlayer { } } - public function &getSectorPlanet() { + public function getSectorPlanet() { return SmrPlanet::getPlanet($this->getGameID(),$this->getSectorID()); } - public function &getSectorPort() { + public function getSectorPort() { return SmrPort::getPort($this->getGameID(),$this->getSectorID()); } @@ -120,7 +120,7 @@ abstract class AbstractSmrPlayer { return $this->sectorID; } - public function &getSector() { + public function getSector() { return SmrSector::getSector($this->getGameID(),$this->getSectorID()); } @@ -526,7 +526,7 @@ abstract class AbstractSmrPlayer { return $this->getAccountID() == $this->getAlliance($forceUpdate)->getLeaderID(); } - public function &getAlliance($forceUpdate = false) { + public function getAlliance($forceUpdate = false) { return SmrAlliance::getAlliance($this->getAllianceID(), $this->getGameID(), $forceUpdate); } @@ -653,25 +653,25 @@ abstract class AbstractSmrPlayer { return $rels[$raceID]; } - abstract public function &getShip(); + abstract public function getShip(); - public function &shootPlayer(AbstractSmrPlayer $targetPlayer) { + public function shootPlayer(AbstractSmrPlayer $targetPlayer) { return $this->getShip()->shootPlayer($targetPlayer); } - public function &shootForces(SmrForce $forces) { + public function shootForces(SmrForce $forces) { return $this->getShip()->shootForces($forces); } - public function &shootPort(SmrPort $port) { + public function shootPort(SmrPort $port) { return $this->getShip()->shootPort($port); } - public function &shootPlanet(SmrPlanet $planet, $delayed) { + public function shootPlanet(SmrPlanet $planet, $delayed) { return $this->getShip()->shootPlanet($planet, $delayed); } - public function &shootPlayers(array $targetPlayers) { + public function shootPlayers(array $targetPlayers) { return $this->getShip()->shootPlayers($targetPlayers); } @@ -925,10 +925,10 @@ abstract class AbstractSmrPlayer { } abstract public function killPlayer($sectorID); - abstract public function &killPlayerByPlayer(AbstractSmrPlayer $killer); - abstract public function &killPlayerByForces(SmrForce $forces); - abstract public function &killPlayerByPort(SmrPort $port); - abstract public function &killPlayerByPlanet(SmrPlanet $planet); + abstract public function killPlayerByPlayer(AbstractSmrPlayer $killer); + abstract public function killPlayerByForces(SmrForce $forces); + abstract public function killPlayerByPort(SmrPort $port); + abstract public function killPlayerByPlanet(SmrPlanet $planet); public function getTurns() { diff --git a/lib/Default/AbstractSmrPort.class.inc b/lib/Default/AbstractSmrPort.class.inc index 0988a5089..2d7a64848 100644 --- a/lib/Default/AbstractSmrPort.class.inc +++ b/lib/Default/AbstractSmrPort.class.inc @@ -68,7 +68,7 @@ class AbstractSmrPort { self::$CACHE_CACHED_PORTS = array(); } - public static function &getPort($gameID, $sectorID, $forceUpdate=false, $db=null) { + public static function getPort($gameID, $sectorID, $forceUpdate=false, $db=null) { if($forceUpdate || !isset(self::$CACHE_PORTS[$gameID][$sectorID])) { self::$CACHE_PORTS[$gameID][$sectorID] = new SmrPort($gameID, $sectorID, $db); } @@ -87,7 +87,7 @@ class AbstractSmrPort { unset(self::$CACHE_PORTS[$gameID][$sectorID]); } - public static function &createPort($gameID,$sectorID) { + public static function createPort($gameID,$sectorID) { if(!isset(self::$CACHE_PORTS[$gameID][$sectorID])) { $p = new SmrPort($gameID,$sectorID); self::$CACHE_PORTS[$gameID][$sectorID] = $p; @@ -247,25 +247,25 @@ class AbstractSmrPort { return $this->getVisibleGoods('Buy', $player); } - public function &getAllGoodIDs() { + public function getAllGoodIDs() { return $this->goodIDs['All']; } /** * Get IDs of goods that can be sold to the port */ - public function &getSoldGoodIDs() { + public function getSoldGoodIDs() { return $this->goodIDs['Sell']; } /** * Get IDs of goods that can be bought from the port */ - public function &getBoughtGoodIDs() { + public function getBoughtGoodIDs() { return $this->goodIDs['Buy']; } - public function &getGood($goodID) { + public function getGood($goodID) { if ($this->hasGood($goodID)) { return Globals::getGood($goodID); } else { @@ -743,7 +743,7 @@ class AbstractSmrPort { return $this->sectorID; } - public function &getSector() { + public function getSector() { return SmrSector::getSector($this->getGameID(),$this->getSectorID()); } @@ -814,7 +814,7 @@ class AbstractSmrPort { return $this->getLevel() + 3; } - public function &getWeapons() { + public function getWeapons() { $weapons = array(); for ($i=0; $i<$this->getNumWeapons(); ++$i) { $weapons[$i] = SmrWeapon::getWeapon(WEAPON_PORT_TURRET); @@ -1036,7 +1036,7 @@ class AbstractSmrPort { } return false; } - public static function &getCachedPort($gameID,$sectorID,$accountID,$forceUpdate=false) { + public static function getCachedPort($gameID,$sectorID,$accountID,$forceUpdate=false) { if($forceUpdate || !isset(self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT visited, port_info @@ -1128,11 +1128,11 @@ class AbstractSmrPort { } - public function &shootPlayer(AbstractSmrPlayer $targetPlayer) { + public function shootPlayer(AbstractSmrPlayer $targetPlayer) { return $this->shootPlayers(array($targetPlayer)); } - public function &shootPlayers(array $targetPlayers) { + public function shootPlayers(array $targetPlayers) { $results = array('Port' => $this, 'TotalDamage' => 0, 'TotalDamagePerTargetPlayer' => array()); foreach($targetPlayers as $targetPlayer) { $results['TotalDamagePerTargetPlayer'][$targetPlayer->getAccountID()] = 0; @@ -1164,7 +1164,7 @@ class AbstractSmrPort { return $results; } - public function &doWeaponDamage(array $damage) { + public function doWeaponDamage(array $damage) { $alreadyDead = $this->isDestroyed(); $shieldDamage = 0; $cdDamage = 0; @@ -1218,7 +1218,7 @@ class AbstractSmrPort { return $actualDamage; } - protected function &getAttackersToCredit() { + protected function getAttackersToCredit() { //get all players involved for HoF $attackers = array(); $this->db->query('SELECT account_id,level FROM player_attacks_port WHERE ' . $this->SQL . ' AND time > ' . $this->db->escapeNumber(TIME - self::TIME_TO_CREDIT_RAID)); @@ -1265,7 +1265,7 @@ class AbstractSmrPort { return $credits; } - public function &killPortByPlayer(AbstractSmrPlayer $killer) { + public function killPortByPlayer(AbstractSmrPlayer $killer) { $return = array(); // Port is destroyed, so empty the port of all trade goods diff --git a/lib/Default/AbstractSmrShip.class.inc b/lib/Default/AbstractSmrShip.class.inc index 03e18fef5..42c5aaf9b 100644 --- a/lib/Default/AbstractSmrShip.class.inc +++ b/lib/Default/AbstractSmrShip.class.inc @@ -23,7 +23,7 @@ abstract class AbstractSmrShip { protected $hasChangedCargo = false; protected $hasChangedHardware = array(); - public static function &getBaseShip($gameTypeID,$shipTypeID,$forceUpdate = false) { + public static function getBaseShip($gameTypeID,$shipTypeID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID])) { // determine ship $db = new SmrMySqlDatabase(); @@ -36,7 +36,7 @@ abstract class AbstractSmrShip { return self::$CACHE_BASE_SHIPS[$gameTypeID][$shipTypeID]; } - protected static function &buildBaseShip(MySqlDatabase $db) { + protected static function buildBaseShip(MySqlDatabase $db) { $ship = array(); $ship['Type'] = 'Ship'; $ship['Name'] = $db->getField('ship_name'); @@ -107,7 +107,7 @@ abstract class AbstractSmrShip { return $ship; } - public static function &getAllBaseShips($gameTypeID,$forceUpdate = false) { + public static function getAllBaseShips($gameTypeID,$forceUpdate = false) { // determine ship $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM ship_type ORDER BY ship_type_id ASC'); //TODO add game type id @@ -232,7 +232,7 @@ abstract class AbstractSmrShip { - public function &addWeapon($weaponTypeID) { + public function addWeapon($weaponTypeID) { if($this->hasOpenWeaponSlots() && $this->hasRemainingPower()) { $weapon = SmrWeapon::getWeapon($weaponTypeID); if($this->getRemainingPower()>=$weapon->getPowerLevel()) { @@ -241,8 +241,7 @@ abstract class AbstractSmrShip { return $weapon; } } - $return = false; - return $return; + return false; } public function moveWeaponUp($orderID) { @@ -414,7 +413,7 @@ abstract class AbstractSmrShip { return $this->illusionShip['Defense']; } - public function &getPlayer() { + public function getPlayer() { return $this->player; } @@ -708,12 +707,11 @@ abstract class AbstractSmrShip { $this->setHardware(HARDWARE_CARGO,$amount); } - public function &getCargo($goodID=false) { + public function getCargo($goodID=false) { if($goodID!==false) { if(isset($this->cargo[$goodID])) return $this->cargo[$goodID]; - $cargo = 0; - return $cargo; + return 0; } return $this->cargo; } @@ -786,7 +784,7 @@ abstract class AbstractSmrShip { return $this->getNumWeapons()>0; } - public function &getWeapons() { + public function getWeapons() { return $this->weapons; } @@ -836,11 +834,11 @@ abstract class AbstractSmrShip { return $this->getShipTypeID() == 23 || $this->getShipTypeID() == 24 || $this->getShipTypeID() == 25; } - public function &shootPlayer(AbstractSmrPlayer $targetPlayer) { + public function shootPlayer(AbstractSmrPlayer $targetPlayer) { return $this->shootPlayers(array($targetPlayer)); } - public function &shootPlayers(array $targetPlayers) { + public function shootPlayers(array $targetPlayers) { $thisPlayer = $this->getPlayer(); $results = array('Player' => $thisPlayer, 'TotalDamage' => 0); if($thisPlayer->isDead()) { @@ -864,7 +862,7 @@ abstract class AbstractSmrShip { return $results; } - public function &shootForces(SmrForce $forces) { + public function shootForces(SmrForce $forces) { $thisPlayer = $this->getPlayer(); $results = array('Player' => $thisPlayer, 'TotalDamage' => 0); if($thisPlayer->isDead()) { @@ -903,7 +901,7 @@ abstract class AbstractSmrShip { return $results; } - public function &shootPort(SmrPort $port) { + public function shootPort(SmrPort $port) { $thisPlayer = $this->getPlayer(); $results = array('Player' => $thisPlayer, 'TotalDamage' => 0); if($thisPlayer->isDead()) { @@ -940,7 +938,7 @@ abstract class AbstractSmrShip { return $results; } - public function &shootPlanet(SmrPlanet $planet, $delayed) { + public function shootPlanet(SmrPlanet $planet, $delayed) { $thisPlayer = $this->getPlayer(); $results = array('Player' => $thisPlayer, 'TotalDamage' => 0); if($thisPlayer->isDead()) { @@ -964,7 +962,7 @@ abstract class AbstractSmrShip { return $results; } - public function &doWeaponDamage(array $damage) { + public function doWeaponDamage(array $damage) { $alreadyDead = $this->getPlayer()->isDead(); $armourDamage = 0; $cdDamage = 0; @@ -980,7 +978,7 @@ abstract class AbstractSmrShip { $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'],$damage['Armour'])); } } - $return = array( + return array( 'KillingShot' => !$alreadyDead && $this->isDead(), 'TargetAlreadyDead' => $alreadyDead, 'Shield' => $shieldDamage, @@ -990,10 +988,9 @@ abstract class AbstractSmrShip { 'HasCDs' => $this->hasCDs(), 'TotalDamage' => $shieldDamage+$cdDamage+$armourDamage ); - return $return; } - public function &doMinesDamage(array $damage) { + public function doMinesDamage(array $damage) { $alreadyDead = $this->getPlayer()->isDead(); $armourDamage = 0; $cdDamage = 0; @@ -1005,7 +1002,7 @@ abstract class AbstractSmrShip { $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'],$damage['Armour'])); } } - $return = array( + return array( 'KillingShot' => !$alreadyDead && $this->isDead(), 'TargetAlreadyDead' => $alreadyDead, 'Shield' => $shieldDamage, @@ -1015,7 +1012,6 @@ abstract class AbstractSmrShip { 'HasCDs' => $this->hasCDs(), 'TotalDamage' => $shieldDamage+$cdDamage+$armourDamage ); - return $return; } protected function doShieldDamage($damage) { diff --git a/lib/Default/Council.class.inc b/lib/Default/Council.class.inc index 490392f97..14d512d77 100644 --- a/lib/Default/Council.class.inc +++ b/lib/Default/Council.class.inc @@ -16,7 +16,7 @@ class Council { /** * Returns an array of Account ID's of the Council for this race. */ - public static function &getRaceCouncil($gameID,$raceID) { + public static function getRaceCouncil($gameID,$raceID) { if (!isset(self::$COUNCILS[$gameID][$raceID])) { self::initialiseDatabase(); self::$COUNCILS[$gameID][$raceID] = array(); diff --git a/lib/Default/Globals.class.inc b/lib/Default/Globals.class.inc index 56da5f7a3..6cabe85ea 100644 --- a/lib/Default/Globals.class.inc +++ b/lib/Default/Globals.class.inc @@ -37,7 +37,7 @@ class Globals { } } - public static function &getHiddenPlayers() { + public static function getHiddenPlayers() { if(self::$HIDDEN_PLAYERS==null) { self::initialiseDatabase(); self::$db->query('SELECT account_id FROM hidden_players'); @@ -49,7 +49,7 @@ class Globals { return self::$HIDDEN_PLAYERS; } - public static function &getLevelRequirements() { + public static function getLevelRequirements() { if(self::$LEVEL_REQUIREMENTS==null) { self::initialiseDatabase(); self::$LEVEL_REQUIREMENTS = array(); @@ -66,7 +66,7 @@ class Globals { return self::$LEVEL_REQUIREMENTS; } - public static function &getRaces() { + public static function getRaces() { if(self::$RACES==null) { self::initialiseDatabase(); self::$RACES = array(); @@ -117,7 +117,7 @@ class Globals { return $raceName; } - public static function &getGoods() { + public static function getGoods() { if(self::$GOODS==null) { self::initialiseDatabase(); self::$GOODS = array(); @@ -139,7 +139,7 @@ class Globals { } return self::$GOODS; } - public static function &getGood($goodID) { + public static function getGood($goodID) { return Globals::getGoods()[$goodID]; } public static function getGoodName($goodID) { @@ -149,7 +149,7 @@ class Globals { return Globals::getGoods()[$goodID]['Name']; } - public static function &getHardwareTypes($hardwareTypeID=false) { + public static function getHardwareTypes($hardwareTypeID=false) { if(self::$HARDWARE_TYPES==null) { self::initialiseDatabase(); self::$HARDWARE_TYPES = array(); @@ -254,7 +254,7 @@ class Globals { return self::$FEATURE_REQUEST_OPEN; } - public static function &getRaceRelations($gameID,$raceID) { + public static function getRaceRelations($gameID,$raceID) { if(!isset(self::$RACE_RELATIONS[$gameID])) { self::$RACE_RELATIONS[$gameID] = array(); } diff --git a/lib/Default/SmrGalaxy.class.inc b/lib/Default/SmrGalaxy.class.inc index e17d8e848..407158a32 100644 --- a/lib/Default/SmrGalaxy.class.inc +++ b/lib/Default/SmrGalaxy.class.inc @@ -19,7 +19,7 @@ class SmrGalaxy { protected $hasChanged = false; protected $isNew = false; - public static function &getGameGalaxies($gameID,$forceUpdate = false) { + public static function getGameGalaxies($gameID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_GAME_GALAXIES[$gameID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM game_galaxy WHERE game_id = ' . $db->escapeNumber($gameID) .' ORDER BY galaxy_id ASC'); @@ -33,7 +33,7 @@ class SmrGalaxy { return self::$CACHE_GAME_GALAXIES[$gameID]; } - public static function &getGalaxy($gameID, $galaxyID, $forceUpdate=false, $db=null) { + public static function getGalaxy($gameID, $galaxyID, $forceUpdate=false, $db=null) { if($forceUpdate || !isset(self::$CACHE_GALAXIES[$gameID][$galaxyID])) { $g = new SmrGalaxy($gameID, $galaxyID, false, $db); self::$CACHE_GALAXIES[$gameID][$galaxyID] = $g; @@ -49,7 +49,7 @@ class SmrGalaxy { } } - public static function &createGalaxy($gameID,$galaxyID) { + public static function createGalaxy($gameID,$galaxyID) { if(!isset(self::$CACHE_GALAXIES[$gameID][$galaxyID])) { $g = new SmrGalaxy($gameID,$galaxyID,true); self::$CACHE_GALAXIES[$gameID][$galaxyID] = $g; @@ -178,7 +178,7 @@ class SmrGalaxy { return $this->getHeight() * $this->getWidth(); } - public function &getSectors() { + public function getSectors() { return SmrSector::getGalaxySectors($this->getGameID(), $this->getGalaxyID()); } @@ -311,7 +311,7 @@ class SmrGalaxy { return $sectorID >= $this->getStartSector() && $sectorID <= $this->getEndSector(); } - public static function &getGalaxyContaining($gameID, $sectorID) { + public static function getGalaxyContaining($gameID, $sectorID) { return SmrSector::getSector($gameID, $sectorID)->getGalaxy(); } diff --git a/lib/Default/SmrPlayer.class.inc b/lib/Default/SmrPlayer.class.inc index 00b61ffe5..296d08964 100644 --- a/lib/Default/SmrPlayer.class.inc +++ b/lib/Default/SmrPlayer.class.inc @@ -55,7 +55,7 @@ class SmrPlayer extends AbstractSmrPlayer { } } - public static function &getSectorPlayersByAlliances($gameID,$sectorID, array $allianceIDs, $forceUpdate = false) { + public static function getSectorPlayersByAlliances($gameID,$sectorID, array $allianceIDs, $forceUpdate = false) { $players = self::getSectorPlayers($gameID,$sectorID,$forceUpdate); // Don't use & as we do an unset foreach($players as $accountID => $player) { if(!in_array($player->getAllianceID(),$allianceIDs)) @@ -64,7 +64,7 @@ class SmrPlayer extends AbstractSmrPlayer { return $players; } - public static function &getSectorPlayers($gameID,$sectorID,$forceUpdate = false) { + public static function getSectorPlayers($gameID,$sectorID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_SECTOR_PLAYERS[$gameID][$sectorID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM player WHERE sector_id = ' . $db->escapeNumber($sectorID) . ' AND game_id=' . $db->escapeNumber($gameID) . ' AND land_on_planet = ' . $db->escapeBoolean(false) . ' AND (last_cpl_action > ' . $db->escapeNumber(TIME-TIME_BEFORE_INACTIVE) . ' OR newbie_turns = 0) AND account_id NOT IN (' . $db->escapeArray(Globals::getHiddenPlayers()) . ') ORDER BY last_cpl_action DESC'); @@ -78,7 +78,7 @@ class SmrPlayer extends AbstractSmrPlayer { return self::$CACHE_SECTOR_PLAYERS[$gameID][$sectorID]; } - public static function &getPlanetPlayers($gameID,$sectorID,$forceUpdate = false) { + public static function getPlanetPlayers($gameID,$sectorID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_PLANET_PLAYERS[$gameID][$sectorID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM player WHERE sector_id = ' . $db->escapeNumber($sectorID) . ' AND game_id=' . $db->escapeNumber($gameID) . ' AND land_on_planet = ' . $db->escapeBoolean(true) . ' AND account_id NOT IN (' . $db->escapeArray(Globals::getHiddenPlayers()) . ') ORDER BY last_cpl_action DESC'); @@ -92,7 +92,7 @@ class SmrPlayer extends AbstractSmrPlayer { return self::$CACHE_PLANET_PLAYERS[$gameID][$sectorID]; } - public static function &getAlliancePlayers($gameID,$allianceID,$forceUpdate = false) { + public static function getAlliancePlayers($gameID,$allianceID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_ALLIANCE_PLAYERS[$gameID][$allianceID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM player WHERE alliance_id = ' . $db->escapeNumber($allianceID) . ' AND game_id=' . $db->escapeNumber($gameID) .' ORDER BY experience DESC'); @@ -106,14 +106,14 @@ class SmrPlayer extends AbstractSmrPlayer { return self::$CACHE_ALLIANCE_PLAYERS[$gameID][$allianceID]; } - public static function &getPlayer($accountID, $gameID, $forceUpdate=false, $db=null) { + public static function getPlayer($accountID, $gameID, $forceUpdate=false, $db=null) { if ($forceUpdate || !isset(self::$CACHE_PLAYERS[$gameID][$accountID])) { self::$CACHE_PLAYERS[$gameID][$accountID] = new SmrPlayer($gameID, $accountID, $db); } return self::$CACHE_PLAYERS[$gameID][$accountID]; } - public static function &getPlayerByPlayerID($playerID,$gameID,$forceUpdate = false) { + public static function getPlayerByPlayerID($playerID,$gameID,$forceUpdate = false) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM player WHERE game_id = '.$db->escapeNumber($gameID).' AND player_id = '.$db->escapeNumber($playerID).' LIMIT 1'); if ($db->nextRecord()) { @@ -287,11 +287,11 @@ class SmrPlayer extends AbstractSmrPlayer { } } - public function &getShip($forceUpdate = false) { + public function getShip($forceUpdate = false) { return SmrShip::getShip($this, $forceUpdate); } - public function &getAccount() { + public function getAccount() { return SmrAccount::getAccount($this->getAccountID()); } @@ -885,7 +885,7 @@ class SmrPlayer extends AbstractSmrPlayer { $this->db->query('INSERT INTO alliance_vs_alliance (game_id, alliance_id_1, alliance_id_2, kills) VALUES (' . $this->db->escapeArray($values) . ') ON DUPLICATE KEY UPDATE kills = kills + 1'); } - public function &killPlayerByPlayer(AbstractSmrPlayer $killer) { + public function killPlayerByPlayer(AbstractSmrPlayer $killer) { $return = array(); $msg = $this->getBBLink(); @@ -1042,7 +1042,7 @@ class SmrPlayer extends AbstractSmrPlayer { return $return; } - public function &killPlayerByForces(SmrForce $forces) { + public function killPlayerByForces(SmrForce $forces) { $return = array(); $owner = $forces->getOwner(); // send a message to the person who died @@ -1080,7 +1080,7 @@ class SmrPlayer extends AbstractSmrPlayer { return $return; } - public function &killPlayerByPort(SmrPort $port) { + public function killPlayerByPort(SmrPort $port) { $return = array(); // send a message to the person who died self::sendMessageFromFedClerk($this->getGameID(), $this->getAccountID(), 'You were DESTROYED by the defenses of '.$port->getDisplayName()); @@ -1115,7 +1115,7 @@ class SmrPlayer extends AbstractSmrPlayer { return $return; } - public function &killPlayerByPlanet(SmrPlanet $planet) { + public function killPlayerByPlanet(SmrPlanet $planet) { $return = array(); // send a message to the person who died $planetOwner = $planet->getOwner(); diff --git a/lib/Default/SmrSector.class.inc b/lib/Default/SmrSector.class.inc index 5c01815ae..a2434d1c7 100644 --- a/lib/Default/SmrSector.class.inc +++ b/lib/Default/SmrSector.class.inc @@ -35,7 +35,7 @@ class SmrSector { } } - public static function &getGalaxySectors($gameID,$galaxyID,$forceUpdate = false) { + public static function getGalaxySectors($gameID,$galaxyID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_GALAXY_SECTORS[$gameID][$galaxyID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM sector WHERE game_id = ' . $db->escapeNumber($gameID) .' AND galaxy_id=' . $db->escapeNumber($galaxyID) . ' ORDER BY sector_id ASC'); @@ -49,7 +49,7 @@ class SmrSector { return self::$CACHE_GALAXY_SECTORS[$gameID][$galaxyID]; } - public static function &getLocationSectors($gameID,$locationTypeID,$forceUpdate = false) { + public static function getLocationSectors($gameID,$locationTypeID,$forceUpdate = false) { if($forceUpdate || !isset(self::$CACHE_LOCATION_SECTORS[$gameID][$locationTypeID])) { $db = new SmrMySqlDatabase(); $db->query('SELECT * FROM location JOIN sector USING (game_id, sector_id) WHERE location_type_id = ' . $db->escapeNumber($locationTypeID) . ' AND game_id=' . $db->escapeNumber($gameID) . ' ORDER BY sector_id ASC'); @@ -63,7 +63,7 @@ class SmrSector { return self::$CACHE_LOCATION_SECTORS[$gameID][$locationTypeID]; } - public static function &getSector($gameID, $sectorID, $forceUpdate=false, $db=null) { + public static function getSector($gameID, $sectorID, $forceUpdate=false, $db=null) { if(!isset(self::$CACHE_SECTORS[$gameID][$sectorID]) || $forceUpdate) { self::$CACHE_SECTORS[$gameID][$sectorID] = new SmrSector($gameID, $sectorID, false, $db); } @@ -84,7 +84,7 @@ class SmrSector { } } - public static function &createSector($gameID,$sectorID) { + public static function createSector($gameID,$sectorID) { if(!isset(self::$CACHE_SECTORS[$gameID][$sectorID])) { $s = new SmrSector($gameID,$sectorID,true); self::$CACHE_SECTORS[$gameID][$sectorID] = $s; @@ -358,7 +358,7 @@ class SmrSector { return $links; } - public function &getGalaxy() { + public function getGalaxy() { return SmrGalaxy::getGalaxy($this->getGameID(),$this->getGalaxyID()); } @@ -405,7 +405,7 @@ class SmrSector { return 'None'; } - public function &getNeighbourSector($dir) { + public function getNeighbourSector($dir) { return SmrSector::getSector($this->getGameID(),$this->getNeighbourID($dir)); } @@ -425,7 +425,7 @@ class SmrSector { return $this->getLink($name)!=0; } - public function &getLinkSector($name) { + public function getLinkSector($name) { if($this->hasLink($name)) return SmrSector::getSector($this->getGameID(),$this->getLink($name)); return false; @@ -544,7 +544,7 @@ class SmrSector { return $this->warp; } - public function &getWarpSector() { + public function getWarpSector() { return SmrSector::getSector($this->getGameID(),$this->getWarp()); } @@ -606,11 +606,11 @@ class SmrSector { return $this->getPort()->exists(); } - public function &getPort() { + public function getPort() { return SmrPort::getPort($this->getGameID(),$this->getSectorID()); } - public function &createPort() { + public function createPort() { return SmrPort::createPort($this->getGameID(),$this->getSectorID()); } @@ -622,10 +622,9 @@ class SmrSector { return $this->getCachedPort($player)!==false; } - public function &getCachedPort(AbstractSmrPlayer $player=null) { + public function getCachedPort(AbstractSmrPlayer $player=null) { if($player == null) { - $return = false; - return $return; + return false; } return SmrPort::getCachedPort($this->getGameID(),$this->getSectorID(),$player->getAccountID()); } @@ -653,7 +652,7 @@ class SmrSector { return false; } - public function &getLocations() { + public function getLocations() { return SmrLocation::getSectorLocations($this->getGameID(),$this->getSectorID()); } @@ -672,11 +671,11 @@ class SmrSector { return $this->getPlanet()->exists(); } - public function &getPlanet() { + public function getPlanet() { return SmrPlanet::getPlanet($this->getGameID(),$this->getSectorID()); } - public function &createPlanet($type=1) { + public function createPlanet($type=1) { return SmrPlanet::createPlanet($this->getGameID(),$this->getSectorID(), $type); } @@ -698,7 +697,7 @@ class SmrSector { return false; } - public function &getEnemyForces(AbstractSmrPlayer $player) { + public function getEnemyForces(AbstractSmrPlayer $player) { $enemyForces = array(); foreach ($this->getForces() as $force) { if(!$player->forceNAPAlliance($force->getOwner())) @@ -729,7 +728,7 @@ class SmrSector { return false; } - public function &getFriendlyForces(AbstractSmrPlayer $player) { + public function getFriendlyForces(AbstractSmrPlayer $player) { $friendlyForces = array(); foreach ($this->getForces() as $force) { if($player->forceNAPAlliance($force->getOwner())) @@ -738,11 +737,11 @@ class SmrSector { return $friendlyForces; } - public function &getForces() { + public function getForces() { return SmrForce::getSectorForces($this->getGameID(),$this->getSectorID()); } - public function &getPlayers() { + public function getPlayers() { return SmrPlayer::getSectorPlayers($this->getGameID(),$this->getSectorID()); } @@ -750,7 +749,7 @@ class SmrSector { return count($this->getPlayers()) > 0; } - public function &getOtherTraders(AbstractSmrPlayer $player) { + public function getOtherTraders(AbstractSmrPlayer $player) { $players = SmrPlayer::getSectorPlayers($this->getGameID(),$this->getSectorID()); //Do not use & because we unset something and only want that in what we return unset($players[$player->getAccountID()]); return $players; @@ -819,7 +818,7 @@ class SmrSector { return array($attackingPlayer); } - public function &getFightingTradersAgainstPort(AbstractSmrPlayer $attackingPlayer, SmrPort $defendingPort) { + public function getFightingTradersAgainstPort(AbstractSmrPlayer $attackingPlayer, SmrPort $defendingPort) { $fightingPlayers = array(); $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(),$this->getSectorID(), array($attackingPlayer->getAllianceID())); if(count($alliancePlayers) > 0) @@ -832,7 +831,7 @@ class SmrSector { return self::limitFightingTraders($fightingPlayers, $attackingPlayer, MAXIMUM_PORT_FLEET_SIZE); } - public function &getFightingTradersAgainstPlanet(AbstractSmrPlayer $attackingPlayer, SmrPlanet $defendingPlanet) { + public function getFightingTradersAgainstPlanet(AbstractSmrPlayer $attackingPlayer, SmrPlanet $defendingPlanet) { $fightingPlayers = array(); $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(),$this->getSectorID(), array($attackingPlayer->getAllianceID())); if(count($alliancePlayers) > 0) { @@ -847,7 +846,7 @@ class SmrSector { return self::limitFightingTraders($fightingPlayers, $attackingPlayer, min($defendingPlanet->getMaxAttackers(),MAXIMUM_PLANET_FLEET_SIZE)); } - public function &getFightingTraders(AbstractSmrPlayer $attackingPlayer, AbstractSmrPlayer $defendingPlayer, $checkForCloak=false) { + public function getFightingTraders(AbstractSmrPlayer $attackingPlayer, AbstractSmrPlayer $defendingPlayer, $checkForCloak=false) { if($attackingPlayer->traderNAPAlliance($defendingPlayer)) throw new Exception('These traders are NAPed.'); $fightingPlayers = array('Attackers' => array(), 'Defenders' => array()); @@ -876,7 +875,7 @@ class SmrSector { return $fightingPlayers; } - public static function &limitFightingTraders(array &$fightingPlayers, AbstractSmrPlayer $keepPlayer, $maximumFleetSize) { + public static function limitFightingTraders(array &$fightingPlayers, AbstractSmrPlayer $keepPlayer, $maximumFleetSize) { // Cap fleets to the required size $fleet_size = count($fightingPlayers); if($fleet_size > $maximumFleetSize) { @@ -891,7 +890,7 @@ class SmrSector { return $fightingPlayers; } - public function &getPotentialFightingTraders(AbstractSmrPlayer $attackingPlayer) { + public function getPotentialFightingTraders(AbstractSmrPlayer $attackingPlayer) { $fightingPlayers = array(); $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(),$this->getSectorID(), array($attackingPlayer->getAllianceID())); if(count($alliancePlayers) > 0)