-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlunder.php
96 lines (84 loc) · 3.35 KB
/
Plunder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @author jstar88
* @copyright 2013
*/
class Plunder
{
/**
* splitResources()
* This function return the stolen resources implementing the "plunder algorithm".
*
* from http://board.ogame.org/board703-miscellaneous/board156-archive-version-2-0/board705-help-questions-archive/board631-faq-s-guides/576831-formula-thread-v3/
* 1. Fill up to 1/3 of cargo capacity with metal
* 2. Fill up to half remaining capacity with crystal
* 3. The rest will be filled with deuterium
* 4. If there is still capacity available fill half of it with metal
* 5. Now fill the rest with crystal
*
*
* @param int $capacity: the amount of current fleet capacity
* @param int $metal: the amount of metal in the attacked planet
* @param int $crystal: the amount of crystal in the attacked planet
* @param int $deuterium: the amount of deuterium in the attacked planet
* @param int $percentage: the percentage of capturable resources.
* @return array(metal => amount, crystal => amount, deuterium => amount)
*/
public static function splitResources($capacity, $metal, $crystal, $deuterium, $percentage = 0.5)
{
//stolen resources
$steal = array(
'metal' => 0,
'crystal' => 0,
'deuterium' => 0);
//max resources that can be take
$metal *= $percentage;
$crystal *= $percentage;
$deuterium *= $percentage;
//Fill up to 1/3 of cargo capacity with metal
$stolen = min($capacity / 3, $metal);
$steal['metal'] += $stolen;
$metal -= $stolen;
$capacity -= $stolen;
//Fill up to half remaining capacity with crystal
$stolen = min($capacity / 2, $crystal);
$steal['crystal'] += $stolen;
$crystal -= $stolen;
$capacity -= $stolen;
//The rest will be filled with deuterium
$stolen = min($capacity, $deuterium);
$steal['deuterium'] += $stolen;
$deuterium -= $stolen;
$capacity -= $stolen;
//If there is still capacity available fill half of it with metal
$stolen = min($capacity / 2, $metal);
$steal['metal'] += $stolen;
$metal -= $stolen;
$capacity -= $stolen;
//Now fill the rest with crystal
$stolen = min($capacity, $crystal);
$steal['crystal'] += $stolen;
$crystal -= $stolen;
$capacity -= $stolen;
return $steal;
}
/**
* splitResourcesAcs()
* This function return the stolen resources
*
* @param int $totalCapacity: the amount of capacity of all attacking fleets
* @param int $capacity: the amount of current fleet capacity
* @param int $metal: the amount of metal in the attacked planet
* @param int $crystal: the amount of crystal in the attacked planet
* @param int $deuterium: the amount of deuterium in the attacked planet
* @return array(metal => amount, crystal => amount, deuterium => amount)
*/
public static function splitResourcesAcs($totalCapacity, $capacity, $metal, $crystal, $deuterium, $percentage = 0.5)
{
$metal *= $capacity / $totalCapacity;
$crystal *= $capacity / $totalCapacity;
$deuterium *= $capacity / $totalCapacity;
return Plunder::splitResources($capacity, $metal, $crystal, $deuterium, $percentage);
}
}
?>