|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Colony\Component; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Lib\ColonyProduction\ColonyProduction; |
|
6
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
7
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
|
8
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
9
|
|
|
|
|
10
|
|
|
class ProceedMigration implements ColonyTickComponentInterface |
|
11
|
|
|
{ |
|
12
|
1 |
|
public function __construct( |
|
13
|
|
|
private readonly ColonyLibFactoryInterface $colonyLibFactory |
|
14
|
1 |
|
) {} |
|
15
|
|
|
|
|
16
|
|
|
public function work(ColonyInterface $colony, array &$production, InformationInterface $information): void |
|
17
|
|
|
{ |
|
18
|
|
|
$changeable = $colony->getChangeable(); |
|
19
|
|
|
|
|
20
|
|
|
if ($colony->getPopulation() > $changeable->getMaxBev()) { |
|
21
|
|
|
if ($changeable->getWorkless() !== 0) { |
|
22
|
|
|
$bev = random_int(1, $changeable->getWorkless()); |
|
23
|
|
|
$changeable->setWorkless($changeable->getWorkless() - $bev); |
|
24
|
|
|
$information->addInformationf("%d Einwohner sind ausgewandert", $bev); |
|
25
|
|
|
} |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if ($changeable->getPopulationLimit() > 0 && $colony->getPopulation() > $changeable->getPopulationLimit() && $changeable->getWorkless()) { |
|
30
|
|
|
if (($free = ($changeable->getPopulationLimit() - $colony->getWorkers())) > 0) { |
|
31
|
|
|
$information->addInformationf( |
|
32
|
|
|
_('Es sind %d Arbeitslose ausgewandert'), |
|
33
|
|
|
($changeable->getWorkless() - $free) |
|
34
|
|
|
); |
|
35
|
|
|
$changeable->setWorkless($free); |
|
36
|
|
|
} else { |
|
37
|
|
|
$information->addInformation('Es sind alle Arbeitslosen ausgewandert'); |
|
38
|
|
|
$changeable->setWorkless(0); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->proceedImmigration( |
|
43
|
|
|
$colony, |
|
44
|
|
|
$production |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param array<int, ColonyProduction> $production |
|
50
|
|
|
*/ |
|
51
|
|
|
private function proceedImmigration( |
|
52
|
|
|
ColonyInterface $colony, |
|
53
|
|
|
array $production |
|
54
|
|
|
): void { |
|
55
|
|
|
// @todo |
|
56
|
|
|
|
|
57
|
|
|
$changeable = $colony->getChangeable(); |
|
58
|
|
|
|
|
59
|
|
|
$changeable->setWorkless( |
|
60
|
|
|
$changeable->getWorkless() + |
|
61
|
|
|
$this->colonyLibFactory->createColonyPopulationCalculator($colony, $production)->getGrowth() |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|