Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planet size calculation #391 fixes #507

Merged
merged 7 commits into from
Dec 24, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 238 additions & 11 deletions app/Factories/PlanetServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ private function createPlanet(PlayerService $player, Coordinate $new_position, s
if ($planet_type === PlanetType::Moon) {
$this->setupMoonProperties($planet);
} else {
$this->setupPlanetProperties($planet);
$is_first_planet = $player->planets->planetCount() == 0;

$this->setupPlanetProperties($planet, $is_first_planet);
}

$planet->save();
Expand Down Expand Up @@ -428,13 +430,17 @@ private function setupMoonProperties(Planet $planet): void
* Sets up planet-specific properties.
* @param Planet $planet
*/
private function setupPlanetProperties(Planet $planet): void
private function setupPlanetProperties(Planet $planet, bool $is_first_planet = false): void
{
$planet->diameter = 300;
$planet->field_max = rand(140, 250);

$planet_data = $this->planetData($planet->planet, $is_first_planet);

// Random field count between the min and max values and add the Server planet fields bonus setting.
$planet->field_max = rand($planet_data['fields'][0], $planet_data['fields'][1]) + $this->settings->planetFieldsBonus();
$planet->diameter = (int) (36.14 * $planet->field_max + 5697.23);

// TODO: temperature range should be dependent on the planet position.
yazilimmz marked this conversation as resolved.
Show resolved Hide resolved
$planet->temp_min = rand(0, 100);
$planet->temp_min = rand($planet_data['temperature'][0], $planet_data['temperature'][1]);
$planet->temp_max = $planet->temp_min + 40;

// Starting resources for planets.
Expand All @@ -443,11 +449,232 @@ private function setupPlanetProperties(Planet $planet): void
$planet->deuterium = 0;

// Set default mine production percentages to 10 (100%).
$planet->metal_mine_percent = 10;
$planet->crystal_mine_percent = 10;
$planet->deuterium_synthesizer_percent = 10;
$planet->solar_plant_percent = 10;
$planet->fusion_plant_percent = 10;
$planet->solar_satellite_percent = 10;
$planet->metal_mine_percent = $planet_data['metal_mine_percent'];
$planet->crystal_mine_percent = $planet_data['crystal_mine_percent'];
$planet->deuterium_synthesizer_percent = $planet_data['deuterium_synthesizer_percent'];
$planet->solar_plant_percent = $planet_data['solar_plant_percent'];
$planet->fusion_plant_percent = $planet_data['fusion_plant_percent'];
$planet->solar_satellite_percent = $planet_data['solar_satellite_percent'];
yazilimmz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns an array of planet data:
* - fields => int[]
* - temperature => int[]
* - X_mine_percent => int
*
* @return array{
* fields: int[],
* temperature: int[],
* metal_mine_percent: int,
* crystal_mine_percent: int,
* deuterium_synthesizer_percent: int,
* solar_plant_percent: int,
* fusion_plant_percent: int,
* solar_satellite_percent: int
* }
*/
public function planetData(int $planetPosition, bool $is_first_planet): array
{
// Each planet position (1-15) has its own data: field range, temperature range,
// and production bonuses for metal, crystal, and deuterium.
// The base production percent is 10 (which is effectively 100%).
// "Max Deterium production" on position 15 is interpreted as a higher deuterium bonus.
// You can tweak these values according to your game's balance.

$data = [
// Position 1
1 => [
'fields' => [96, 172], // min:96, max:172
'temperature' => [220, 260], // min:220°C, max:260°C
'metal_mine_percent' => 10, // base 100%
'crystal_mine_percent' => 14, // +40% => 10 + (10 * 0.40) = 14
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 2
2 => [
'fields' => [104, 176],
'temperature' => [170, 210],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 13, // +30% => 10 + (10 * 0.30) = 13
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 3
3 => [
'fields' => [112, 182],
'temperature' => [120, 160],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 12, // +20% => 10 + (10 * 0.20) = 12
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 4
4 => [
'fields' => [118, 208],
'temperature' => [70, 110],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 5
5 => [
'fields' => [133, 232],
'temperature' => [60, 100],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 6
6 => [
'fields' => [146, 242],
'temperature' => [50, 90],
'metal_mine_percent' => 12, // +17% => 10 + (10 * 0.17) ≈ 12
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 7
7 => [
'fields' => [152, 248],
'temperature' => [40, 80],
'metal_mine_percent' => 12, // +23% => 10 + (10 * 0.23) ≈ 12
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 8
8 => [
'fields' => [156, 252],
'temperature' => [30, 70],
'metal_mine_percent' => 14, // +35% => 10 + (10 * 0.35) = 14
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 9
9 => [
'fields' => [150, 246],
'temperature' => [20, 60],
'metal_mine_percent' => 12, // +23% => 10 + (10 * 0.23) ≈ 12
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 10
10 => [
'fields' => [142, 232],
'temperature' => [10, 50],
'metal_mine_percent' => 12, // +17% => 10 + (10 * 0.17) ≈ 12
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 11
11 => [
'fields' => [136, 210],
'temperature' => [0, 40],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 12
12 => [
'fields' => [125, 186],
'temperature' => [-10, 30],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 13
13 => [
'fields' => [114, 172],
'temperature' => [-50, -10],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 14
14 => [
'fields' => [100, 168],
'temperature' => [-90, -50],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
// Position 15
15 => [
'fields' => [90, 164],
'temperature' => [-130, -90],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10, // 10 + (10 * 0.50) = 15
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
],
];

//first_planet static data
if ($is_first_planet) {
return $data[$planetPosition] ?? [
'fields' => [163, 163],
'temperature' => [20, 60],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
];
}

// If the position doesn't exist, return some default values
// Deuterium can be adjusted according to planet temperature as needed
return $data[$planetPosition] ?? [
'fields' => [100, 150],
'temperature' => [0, 40],
'metal_mine_percent' => 10,
'crystal_mine_percent' => 10,
'deuterium_synthesizer_percent' => 10,
'solar_plant_percent' => 10,
'fusion_plant_percent' => 10,
'solar_satellite_percent' => 10,
];
}
}
Loading