Skip to content

Commit ed11a9b

Browse files
authored
merge Refactoring&documentation for public opening of the repository (#21)
* first run at refactoring * fixed a bug where two planets could be at the same position * small bugfixes to registry * updated documentation
1 parent 01ea633 commit ed11a9b

File tree

4 files changed

+33
-79
lines changed

4 files changed

+33
-79
lines changed

LICENSE.md

Whitespace-only changes.

core/classes/data/units.php

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -490,77 +490,35 @@ function getRequirements(int $id) : array {
490490
/**
491491
* Calculates and returns the build-time for the next level (or one unit for fleet/defense) of the Unit
492492
* @param U_Building $building the unit-object of the given unit
493+
* @param int $robotLvl the level of the robotic factory
494+
* @param int $shipYardLvl the level of the shipyard factory
495+
* @param int $naniteLvl the level of the nanite factory
493496
* @return float the needed time to build in seconds
494497
*/
495-
function getBuildingBuildTime(U_Building $building) : float {
496-
global $data, $units;
497-
498-
499-
$roboID = $units->getUnitID('robotic_factory');
500-
$naniID = $units->getUnitID('nanite_factory');
501-
502-
$roboLvl = $data->getBuilding()[$roboID]->getLevel();
503-
$naniLvl = $data->getBuilding()[$naniID]->getLevel();
498+
function getBuildTime(U_Building $building, int $robotLvl, int $shipYardLvl, int $naniteLvl) : float {
504499

505500
$metal = $building->getCostMetal();
506501
$crystal = $building->getCostCrystal();
502+
$factor = $building->getFactor();
507503

508504
// building
509505
if ($building->getUnitId() < 100) {
510-
return ($metal + $crystal) / (2500 * (1 + $roboLvl) * (2 ** $naniLvl));
506+
//(39410 + 9852)/(2500 * (1+10) * 2^3)
507+
return ($metal + $crystal) / (2500 * (1 + $robotLvl) * (2 ** $naniteLvl));
511508
}
512509

513-
}
514-
515-
function getFleetBuildTime(U_Fleet $building) : float {
516-
global $data, $units;
517-
518-
$shipyardID = $units->getUnitID('shipyard');
519-
$naniID = $units->getUnitID('nanite_factory');
520-
521-
$shipyardLvl = $data->getBuilding()[$shipyardID]->getLevel();
522-
$naniLvl = $data->getBuilding()[$naniID]->getLevel();
523-
524-
$metal = $building->getCostMetal();
525-
$crystal = $building->getCostCrystal();
526-
527-
// fleet and defense
528-
if ($building->getUnitId() > 200 && $building->getUnitId() < 400) {
529-
return ($metal + $crystal) / (2500 * (1 + $shipyardLvl) * pow(2, $naniLvl));
530-
}
531-
}
532-
533-
function getResearchBuildTime(U_Research $building) : float {
534-
global $data, $units;
535-
536-
$researchLabID = $units->getUnitID('research_lab');
537-
$researchLabLvl = $data->getBuilding()[$researchLabID]->getLevel();
538-
539-
540-
$metal = $building->getCostMetal();
541-
$crystal = $building->getCostCrystal();
542-
543510
// tech
544511
if ($building->getUnitId() > 100 && $building->getUnitId() < 200) {
545-
return ($metal + $crystal) / (1000 * (1 + $researchLabLvl));
512+
return ($metal * $factor + $crystal * $factor) / (2500 * (1 + $robotLvl) * pow(2, $naniteLvl));
546513
}
547514

548-
// TODO: calculate research-network
549-
550-
}
551-
515+
// fleet and defense
516+
if ($building->getUnitId() > 200 && $building->getUnitId() < 400) {
517+
return ($metal + $crystal) / (2500 * (1 + $shipYardLvl) * pow(2, $naniteLvl));
518+
}
552519

553-
public function __call($method, $arg) {
554-
if($method == 'getBuildTime') {
520+
// TODO: research
555521

556-
if(get_class($arg[0]) === U_Building) {
557-
return call_user_func_array(array($this,'getBuildingBuildTime'), $arg);
558-
} else if(get_class($arg[0]) === U_Fleet) {
559-
return call_user_func_array(array($this,'getFleetBuildTime'), $arg);
560-
} else if(get_class($arg[0]) === U_Research) {
561-
return call_user_func_array(array($this,'getResearchBuildTime'), $arg);
562-
}
563-
}
564522
}
565523

566524
/**

core/classes/loader.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function __construct($userID) {
253253
intval($data->tech_shielding_tech),
254254
intval($data->tech_energy_tech),
255255
intval($data->tech_hyperspace_tech),
256-
intval($data->tech_combustion_tech),
256+
intval($data->tech_combustion_drive_tech),
257257
intval($data->tech_impulse_drive_tech),
258258
intval($data->tech_hyperspace_drive_tech),
259259
intval($data->tech_laser_tech),
@@ -286,13 +286,13 @@ function __construct($userID) {
286286
//$uID, $uLevel, $uCostMetal, $uCostCrystal, $uCostDeuterium, $uCostEnergy, $uCostFactor
287287

288288
$this->techList[$i + 100] = new U_Research(
289-
$i+100,
289+
$i,
290290
$dResearch[$i - 1],
291-
$units->getPriceList($i+100)['metal'],
292-
$units->getPriceList($i+100)['crystal'],
293-
$units->getPriceList($i+100)['deuterium'],
294-
$units->getPriceList($i+100)['energy'],
295-
$units->getPriceList($i+100)['factor']
291+
$units->getPriceList($i)['metal'],
292+
$units->getPriceList($i)['crystal'],
293+
$units->getPriceList($i)['deuterium'],
294+
$units->getPriceList($i)['energy'],
295+
$units->getPriceList($i)['factor']
296296
);
297297
}
298298

@@ -301,13 +301,13 @@ function __construct($userID) {
301301
//$uID, $uLevel, $uCostMetal, $uCostCrystal, $uCostDeuterium, $uCostEnergy, $uCostFactor
302302

303303
$this->fleetList[$i + 200] = new U_Fleet(
304-
$i+200,
304+
$i,
305305
$dFleet[$i - 1],
306-
$units->getPriceList($i+200)['metal'],
307-
$units->getPriceList($i+200)['crystal'],
308-
$units->getPriceList($i+200)['deuterium'],
309-
$units->getPriceList($i+200)['energy'],
310-
$units->getPriceList($i+200)['factor']
306+
$units->getPriceList($i)['metal'],
307+
$units->getPriceList($i)['crystal'],
308+
$units->getPriceList($i)['deuterium'],
309+
$units->getPriceList($i)['energy'],
310+
$units->getPriceList($i)['factor']
311311
);
312312
}
313313

@@ -316,13 +316,13 @@ function __construct($userID) {
316316
//$uID, $uLevel, $uCostMetal, $uCostCrystal, $uCostDeuterium, $uCostEnergy, $uCostFactor
317317

318318
$this->defenseList[$i + 300] = new U_Defense(
319-
$i+300,
319+
$i,
320320
$dDefense[$i - 1],
321-
$units->getPriceList($i+300)['metal'],
322-
$units->getPriceList($i+300)['crystal'],
323-
$units->getPriceList($i+300)['deuterium'],
324-
$units->getPriceList($i+300)['energy'],
325-
$units->getPriceList($i+300)['factor']
321+
$units->getPriceList($i)['metal'],
322+
$units->getPriceList($i)['crystal'],
323+
$units->getPriceList($i)['deuterium'],
324+
$units->getPriceList($i)['energy'],
325+
$units->getPriceList($i)['factor']
326326
);
327327
}
328328

core/classes/units/fleet.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public function getCostDeuterium() : float {
4848
}
4949

5050
public function getAmount() : int {
51-
return intval($this->amount);
52-
}
53-
54-
public function setAmount($cnt) : void {
55-
$this->amount = $cnt;
51+
return $this->amount;
5652
}
5753
}

0 commit comments

Comments
 (0)