public static function CreateHomeBase(User $owner, $name) { // Import the configuration file. global $NN_config; // Get the location of the last added home colony in the universe $result = Database::Instance()->ExecuteQuery("SELECT last_galaxy_position, last_system_position, last_planet_position FROM game_information;", "SELECT"); $last_galaxy_position = $result["last_galaxy_position"]; $last_system_position = $result["last_system_position"]; $last_planet_position = $result["last_planet_position"]; // Search for a nice spot in the galaxy $suitablePositionFound = FALSE; while ($suitablePositionFound != TRUE) { for ($currentGalaxy = $last_galaxy_position; $currentGalaxy <= $NN_config["max_galaxies"]; $currentGalaxy++) { for ($currentSystem = $last_system_position; $currentSystem <= $NN_config["max_systems"]; $currentSystem++) { // Try to find a suitable planet in a system for ($currentPosition = $last_planet_position; $currentPosition <= 15; $currentPosition++) { // Check if the current position is not too crowded $query = "SELECT COUNT(ID) FROM colony WHERE galaxy_position = {$currentGalaxy} AND system_position = {$currentSystem};"; $result = Database::Instance()->ExecuteQuery($query, "SELECT"); if ($result["COUNT(ID)"] > 4) { if ($currentSystem == $NN_config["max_systems"]) { // We've filled up this galaxy, go to the next $currentGalaxy++; // Start from system 1 and position 1 again $currentSystem = 1; $currentPosition = 1; } else { // There's still space in this galaxy but the current system is full $currentSystem++; $currentPosition = 1; } continue; } // All right, we got up till here so this system is not too crowded // Randomly choose a slot that's not too hot and not too cold $selectedPlanet = round(mt_rand(4, 12)); // See if it's inhabited $query = "SELECT * FROM colony WHERE galaxy_position = {$currentGalaxy} AND system_position = {$currentSystem} AND planet_position = {$selectedPlanet};"; $result = Database::Instance()->ExecuteQuery($query, "SELECT"); if ($result === NULL) { $newColony =& Colony::NewColony($name, new Coordinates($currentGalaxy, $currentSystem, $selectedPlanet), $owner, TRUE); Colony::AddToDatabase($newColony); $suitablePositionFound = TRUE; } else { if ($currentPosition > 2) { if ($currentSystem == $NN_config["max_systems"]) { // We've filled up this galaxy, go to the next $currentGalaxy++; // Start from system 1 and position 1 again $currentSystem = 1; $currentPosition = 1; } else { // There's still space in this galaxy but the current system is full $currentSystem++; $currentPosition = 1; } } else { // There's still space in this system $currentPosition++; } } if ($suitablePositionFound) { $query = "UPDATE game_information SET last_galaxy_position = {$currentGalaxy}, last_system_position = {$currentSystem}, last_planet_position = {$selectedPlanet};"; Database::Instance()->ExecuteQuery($query, "UPDATE"); break 3; // Exit out of the galaxy search loop } } } } } if (isset($newColony)) { return $newColony; } return NULL; }
error_reporting(30719); require_once "common.php"; Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_defences", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_properties", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_resources", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_structures", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE fleet", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE user", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE production", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE user_officers", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE user_technology", NULL); Database::Instance()->ExecuteQuery("TRUNCATE TABLE scheduled_transports", NULL); Database::Instance()->SetDebugging(true); $user = User::NewUser("Beerdude26", "aSimplePassword", 100, "*****@*****.**", "alternate_email"); $colony = Colony::NewColony("Nigron", new Coordinates(100, 50, 7), $user, FALSE); Colony::AddToDatabase($colony); echo "<br/>"; echo "<br/>"; echo "Current colony:"; Helper::var_dump_pre($user->CurrentColony()->ID()); $units = array("light_fighter" => 10, "small_cargo_ship" => 20, "cruiser" => 10); $extrafleet = ShipFleet::FromList($units, $user->CurrentColony(), 0); //Helper::var_dump_pre( $user->CurrentColony()->Fleet() ); echo "Adding some extra units to original fleet: "; $user->CurrentColony()->Fleet()->AddToFleet($extrafleet); $user->CurrentColony()->Fleet()->UpdateDatabase(); $t_units = array("light_fighter" => 5, "small_cargo_ship" => 5, "cruiser" => 3); $t_fleet = ShipFleet::FromList($t_units, $user->CurrentColony(), 0); echo "Splitting up some units from the original fleet: "; $fleets = $user->CurrentColony()->Fleet()->SplitFleet($t_fleet);