1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Meta\Economic\BuildDataStatic; |
4
|
|
|
use Unit\DBStaticUnit; |
5
|
|
|
|
6
|
|
|
function eco_lab_sort_effectivness($a, $b) { |
7
|
|
|
return $a['laboratory_effective_level'] > $b['laboratory_effective_level'] ? -1 : ($a['laboratory_effective_level'] < $b['laboratory_effective_level'] ? 1 : 0); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* eco_get_build_data.php |
12
|
|
|
* |
13
|
|
|
* 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
14
|
|
|
* @version 1.0 |
15
|
|
|
*/ |
16
|
|
|
function eco_get_lab_max_effective_level(&$user, $lab_require) { |
17
|
|
|
if (!$user['user_as_ally'] && !isset($user['laboratories_active'])) { |
18
|
|
|
$user['laboratories_active'] = array(); |
19
|
|
|
$query = DBStaticUnit::db_unit_list_laboratories($user['id']); |
20
|
|
|
while ($row = db_fetch($query)) { |
21
|
|
|
if (!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) { |
22
|
|
|
$row += array( |
23
|
|
|
STRUC_LABORATORY => $level_lab = mrc_get_level($user, $row, STRUC_LABORATORY), |
24
|
|
|
STRUC_LABORATORY_NANO => $level_lab_nano = mrc_get_level($user, $row, STRUC_LABORATORY_NANO), |
25
|
|
|
'laboratory_effective_level' => $level_lab * pow(2, $level_lab_nano), |
|
|
|
|
26
|
|
|
); |
27
|
|
|
$user['laboratories_active'][$row['id']] = $row; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
uasort($user['laboratories_active'], 'eco_lab_sort_effectivness'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (!isset($user['research_effective_level'][$lab_require])) { |
35
|
|
|
if ($user['user_as_ally']) { |
36
|
|
|
$lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1", true); |
37
|
|
|
} else { |
38
|
|
|
$tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1; |
|
|
|
|
39
|
|
|
$lab_level['effective_level'] = 0; |
|
|
|
|
40
|
|
|
|
41
|
|
|
foreach ($user['laboratories_active'] as $data) { |
42
|
|
|
if ($tech_intergalactic <= 0) { |
43
|
|
|
break; |
44
|
|
|
} |
45
|
|
|
if ($data[STRUC_LABORATORY] >= $lab_require) { |
46
|
|
|
$lab_level['effective_level'] += $data['laboratory_effective_level']; |
47
|
|
|
$tech_intergalactic--; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
$user['research_effective_level'][$lab_require] = $lab_level['effective_level'] ? $lab_level['effective_level'] : 1; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $user['research_effective_level'][$lab_require]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $user |
59
|
|
|
* @param array $planet |
60
|
|
|
* @param int $unit_id |
61
|
|
|
* @param int|string $unit_level |
62
|
|
|
* @param bool $only_cost |
63
|
|
|
* @param array|null $info |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
function eco_get_build_data(&$user, $planet, $unit_id, $unit_level = 0, $only_cost = false, $info = null) { |
68
|
|
|
$unit_data = get_unit_param($unit_id); |
69
|
|
|
|
70
|
|
|
// Filling basic build data - unit cost |
71
|
|
|
$cost = BuildDataStatic::getBasicData($user, $planet, $unit_data, $unit_level); |
72
|
|
|
|
73
|
|
|
// Getting autoconvert unit amount |
74
|
|
|
$cost[BUILD_AUTOCONVERT] = $cost[P_OPTIONS][P_ONLY_DARK_MATTER] ? BuildDataStatic::getAutoconvertCount($user, $planet) : 0; |
75
|
|
|
// Limiting autoconvert amount to unit max stack - if is set |
76
|
|
|
!empty($unit_data[P_MAX_STACK]) ? $cost[BUILD_AUTOCONVERT] = min($unit_data[P_MAX_STACK], $cost[BUILD_AUTOCONVERT]) : false; |
77
|
|
|
|
78
|
|
|
$cost[P_OPTIONS][P_TIME_RAW] = $cost[P_OPTIONS][P_TIME_RAW] * 60 * 60 / get_game_speed() / 2500; |
79
|
|
|
|
80
|
|
|
// TODO - Вынести в отдельную процедуру расчёт стоимости |
81
|
|
|
if ($only_cost) { |
82
|
|
|
return $cost; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Check if unit can be built |
86
|
|
|
$cost['RESULT'][BUILD_CREATE] = BuildDataStatic::getBuildStatus($user, $planet, $unit_id, $cost['CAN'][BUILD_CREATE]); |
87
|
|
|
// Setting destroy status |
88
|
|
|
$cost['RESULT'][BUILD_DESTROY] = BuildDataStatic::getDestroyStatus($user, $planet, $unit_id, $cost); |
89
|
|
|
|
90
|
|
|
// Time calculations |
91
|
|
|
if (in_array($unit_id, sn_get_groups('governors')) || $cost[P_OPTIONS][P_ONLY_DARK_MATTER]) { |
92
|
|
|
// Zero build time for Governors and other units with DM in price |
93
|
|
|
$cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0; |
94
|
|
|
} else { |
95
|
|
|
$cost[RES_TIME][BUILD_CREATE] = $cost[P_OPTIONS][P_TIME_RAW]; |
96
|
|
|
|
97
|
|
|
// Applying time modifiers |
98
|
|
|
$cost[RES_TIME][BUILD_CREATE] /= BuildDataStatic::getCapitalTimeDivisor($user, $planet, $unit_id); |
99
|
|
|
$cost[RES_TIME][BUILD_CREATE] /= BuildDataStatic::getMercenaryTimeDivisor($user, $planet, $unit_id); |
100
|
|
|
$cost[RES_TIME][BUILD_CREATE] /= SN::$gc->pimp->getStructuresTimeDivisor($user, $planet, $unit_id, $unit_data); |
101
|
|
|
|
102
|
|
|
// Final calculations |
103
|
|
|
$cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_CREATE] > 1 ? ceil($cost[RES_TIME][BUILD_CREATE]) : 1; |
104
|
|
|
$cost[RES_TIME][BUILD_DESTROY] = $cost[RES_TIME][BUILD_CREATE] / 2 > 1 ? ceil($cost[RES_TIME][BUILD_CREATE] / 2) : 1; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $cost; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
function eco_can_build_unit($user, $planet, $unit_id) { |
112
|
|
|
$result = null; |
113
|
|
|
|
114
|
|
|
return sn_function_call('eco_can_build_unit', [$user, $planet, $unit_id, &$result]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
function sn_eco_can_build_unit($user, $planet, $unit_id, &$result) { |
118
|
|
|
$result = isset($result) ? $result : BUILD_ALLOWED; |
119
|
|
|
$result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result; |
120
|
|
|
|
121
|
|
|
$unit_param = get_unit_param($unit_id); |
122
|
|
|
if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !SN::$config->empire_mercenary_temporary) { |
123
|
|
|
$requirement = &$unit_param[P_REQUIRE]; |
124
|
|
|
if ($result == BUILD_ALLOWED && $requirement) { |
125
|
|
|
foreach ($requirement as $require_id => $require_level) { |
126
|
|
|
if (mrc_get_level($user, $planet, $require_id) < $require_level) { |
127
|
|
|
$result = BUILD_REQUIRE_NOT_MEET; |
128
|
|
|
break; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $result; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
function eco_is_builds_in_que($planet_que, $unit_list) { |
138
|
|
|
$eco_is_builds_in_que = false; |
139
|
|
|
|
140
|
|
|
$unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list); |
141
|
|
|
$planet_que = explode(';', $planet_que); |
142
|
|
|
foreach ($planet_que as $planet_que_item) { |
143
|
|
|
if ($planet_que_item) { |
144
|
|
|
list($planet_que_item) = explode(',', $planet_que_item); |
145
|
|
|
if (in_array($planet_que_item, $unit_list)) { |
146
|
|
|
$eco_is_builds_in_que = true; |
147
|
|
|
break; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $eco_is_builds_in_que; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
function eco_unit_busy(&$user, &$planet, $unit_id) { |
156
|
|
|
$result = null; |
157
|
|
|
|
158
|
|
|
return sn_function_call('eco_unit_busy', [&$user, &$planet, $unit_id, &$result]); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) { |
162
|
|
|
global $config; |
|
|
|
|
163
|
|
|
|
164
|
|
|
$result = isset($result) ? $result : false; |
165
|
|
|
if (!$result) { |
166
|
|
|
if (($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun) { |
167
|
|
|
$global_que = que_get($user['id'], $planet['id'], QUE_RESEARCH, false); |
168
|
|
|
if (is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) { |
169
|
|
|
$first_element = reset($global_que['ques'][QUE_RESEARCH][$user['id']]); |
170
|
|
|
if (is_array($first_element)) { |
171
|
|
|
$result = true; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
//if(!empty($global_que['ques'][QUE_RESEARCH][$user['id']][0])) |
|
|
|
|
175
|
|
|
//{ |
176
|
|
|
// $result = true; |
|
|
|
|
177
|
|
|
//} |
178
|
|
|
} elseif (($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) { |
179
|
|
|
$result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
// switch($unit_id) |
|
|
|
|
184
|
|
|
// { |
185
|
|
|
// case STRUC_FACTORY_HANGAR: |
186
|
|
|
// $hangar_busy = $planet['b_hangar'] && $planet['b_hangar_id']; |
187
|
|
|
// $return = $hangar_busy; |
188
|
|
|
// break; |
189
|
|
|
// } |
190
|
|
|
|
191
|
|
|
return $result; |
192
|
|
|
} |
193
|
|
|
|