public function getWeaponAlloacation($isAttack, $count = null) { $ret = array( 'trained' => array( 'weapons' => 0, 'noweapons' => 0, ), 'mercs' => array( 'weapons' => 0, 'noweapons' => 0, ), 'untrained' => array( 'weapons' => 0, 'noweapons' => 0, ), ); $weaponCount = $count; // If the count isn't provided, grab it if ($weaponCount == null) { $weaponCount = $isAttack ? Weapon::getUserAttackWeaponsCount($this->id) : Weapon::getUserDefenseWeaponsCount($this->id); } $trainedCount = $isAttack ? $this->sasoldiers : $this->dasoldiers; $mercCount = $isAttack ? $this->samercs : $this->damercs; $untrainedCount = $this->uu; // Can't have a merc-only army if ($trainedCount == 0) { // they'll be unarmed $ret['mercs']['noweapons'] = $mercCount; $mercCount = 0; } // Mercs can only be a max of 30% of the trained force if ($mercCount > $thirty = floor($trainedCount * 0.3)) { $ret['mercs']['noweapons'] = $mercCount - $thirty; $mercCount = $thirty; } // There are more weapons than trained soldiers, // so all soldiers will have weapons if ($weaponCount > $trainedCount) { $ret['trained']['weapons' ] = $trainedCount; $weaponCount -= $trainedCount; } // Not enough weapons for any mercs or untrained else { $ret['trained']['weapons' ] = $weaponCount; $ret['trained']['noweapons'] = $trainedCount - $weaponCount; $weaponCount = 0; } // There's enough weapons for the mercs if ($weaponCount > $mercCount) { $ret['mercs']['weapons' ] = $mercCount; $weaponCount -= $mercCount; } // only some or none of the mercs will have weapons else { $ret['mercs']['weapons' ] = $weaponCount; $ret['mercs']['noweapons'] = $mercCount - $weaponCount; $weaponCount = 0; } // There's enough for the untrained if ($weaponCount > $untrainedCount) { $ret['untrained']['weapons'] = $untrainedCount; } // some or none of the untrained will have weapons else { $ret['untrained']['weapons' ] = $weaponCount; $ret['untrained']['noweapons'] = $untrainedCount - $weaponCount; } return $ret; }