@@ -4,11 +4,20 @@ discard block |
||
4 | 4 | { |
5 | 5 | return classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id, $for_update, $fields); |
6 | 6 | } |
7 | +/** |
|
8 | + * @param integer $galaxy |
|
9 | + * @param integer $system |
|
10 | + * @param integer $planet |
|
11 | + * @param integer $planet_type |
|
12 | + */ |
|
7 | 13 | function db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') |
8 | 14 | { |
9 | 15 | return classSupernova::db_get_record_list(LOC_PLANET, |
10 | 16 | "{{planets}}.`galaxy` = {$galaxy} AND {{planets}}.`system` = {$system} AND {{planets}}.`planet` = {$planet} AND {{planets}}.`planet_type` = {$planet_type}", true); |
11 | 17 | } |
18 | +/** |
|
19 | + * @param integer $planet_type |
|
20 | + */ |
|
12 | 21 | function db_planet_by_gspt($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') |
13 | 22 | { |
14 | 23 | $galaxy = intval($galaxy); |
@@ -79,6 +88,9 @@ discard block |
||
79 | 88 | return classSupernova::db_get_record_list(LOC_PLANET, |
80 | 89 | "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}"); |
81 | 90 | } |
91 | +/** |
|
92 | + * @param integer $planet_id |
|
93 | + */ |
|
82 | 94 | function db_planet_list_by_user_or_planet($user_id, $planet_id) { |
83 | 95 | if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false; |
84 | 96 | |
@@ -92,6 +104,9 @@ discard block |
||
92 | 104 | if(!($planet_id = idval($planet_id))) return false; |
93 | 105 | return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set); |
94 | 106 | } |
107 | +/** |
|
108 | + * @param integer $ui_planet_type |
|
109 | + */ |
|
95 | 110 | function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set) |
96 | 111 | { |
97 | 112 | if(!($set = trim($set))) return false; |
@@ -36,8 +36,7 @@ discard block |
||
36 | 36 | $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0; |
37 | 37 | $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0; |
38 | 38 | $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0; |
39 | - $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : |
|
40 | - (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0); |
|
39 | + $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0); |
|
41 | 40 | $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type; |
42 | 41 | |
43 | 42 | return db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields); |
@@ -45,7 +44,7 @@ discard block |
||
45 | 44 | |
46 | 45 | function db_planet_by_parent($parent_id, $for_update = false, $fields = '*') { |
47 | 46 | //if(!($parent_id = intval($parent_id))) return false; |
48 | - if(!($parent_id = idval($parent_id))) { |
|
47 | + if (!($parent_id = idval($parent_id))) { |
|
49 | 48 | return false; |
50 | 49 | } |
51 | 50 | |
@@ -55,7 +54,7 @@ discard block |
||
55 | 54 | |
56 | 55 | function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*') { |
57 | 56 | //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false; |
58 | - if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) { |
|
57 | + if (!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) { |
|
59 | 58 | return false; |
60 | 59 | } |
61 | 60 | |
@@ -66,7 +65,7 @@ discard block |
||
66 | 65 | |
67 | 66 | function db_planet_list_moon_other($user_id, $this_moon_id) { |
68 | 67 | // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false; |
69 | - if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) { |
|
68 | + if (!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) { |
|
70 | 69 | return false; |
71 | 70 | } |
72 | 71 | |
@@ -83,7 +82,7 @@ discard block |
||
83 | 82 | } |
84 | 83 | |
85 | 84 | function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') { |
86 | - if(!is_array($user_row)) { |
|
85 | + if (!is_array($user_row)) { |
|
87 | 86 | return false; |
88 | 87 | } |
89 | 88 | // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list; |
@@ -105,7 +104,7 @@ discard block |
||
105 | 104 | } |
106 | 105 | |
107 | 106 | function db_planet_list_by_user_or_planet($user_id, $planet_id) { |
108 | - if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) { |
|
107 | + if (!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) { |
|
109 | 108 | return false; |
110 | 109 | } |
111 | 110 | |
@@ -115,7 +114,7 @@ discard block |
||
115 | 114 | |
116 | 115 | function db_planet_set_by_id($planet_id, $set) { |
117 | 116 | // if(!($planet_id = intval($planet_id))) return false; |
118 | - if(!($planet_id = idval($planet_id))) { |
|
117 | + if (!($planet_id = idval($planet_id))) { |
|
119 | 118 | return false; |
120 | 119 | } |
121 | 120 | |
@@ -123,7 +122,7 @@ discard block |
||
123 | 122 | } |
124 | 123 | |
125 | 124 | function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set) { |
126 | - if(!($set = trim($set))) { |
|
125 | + if (!($set = trim($set))) { |
|
127 | 126 | return false; |
128 | 127 | } |
129 | 128 | |
@@ -137,7 +136,7 @@ discard block |
||
137 | 136 | |
138 | 137 | function db_planet_set_by_parent($ui_parent_id, $ss_set) { |
139 | 138 | //if(!($si_parent_id = intval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
140 | - if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) { |
|
139 | + if (!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) { |
|
141 | 140 | return false; |
142 | 141 | } |
143 | 142 | |
@@ -146,7 +145,7 @@ discard block |
||
146 | 145 | |
147 | 146 | function db_planet_set_by_owner($ui_owner_id, $ss_set) { |
148 | 147 | //if(!($si_owner_id = intval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
149 | - if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) { |
|
148 | + if (!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) { |
|
150 | 149 | return false; |
151 | 150 | } |
152 | 151 | |
@@ -156,7 +155,7 @@ discard block |
||
156 | 155 | |
157 | 156 | function db_planet_delete_by_id($planet_id) { |
158 | 157 | // if(!($planet_id = intval($planet_id))) return false; |
159 | - if(!($planet_id = idval($planet_id))) { |
|
158 | + if (!($planet_id = idval($planet_id))) { |
|
160 | 159 | return false; |
161 | 160 | } |
162 | 161 | classSupernova::db_del_record_by_id(LOC_PLANET, $planet_id); |
@@ -168,7 +167,7 @@ discard block |
||
168 | 167 | |
169 | 168 | function db_planet_list_delete_by_owner($ui_owner_id) { |
170 | 169 | // if(!($si_owner_id = intval($ui_owner_id))) return false; |
171 | - if(!($si_owner_id = idval($ui_owner_id))) { |
|
170 | + if (!($si_owner_id = idval($ui_owner_id))) { |
|
172 | 171 | return false; |
173 | 172 | } |
174 | 173 | classSupernova::db_del_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}"); |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | +/** |
|
4 | + * @param boolean $player |
|
5 | + */ |
|
3 | 6 | function db_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) { |
4 | 7 | return classSupernova::db_get_user_by_id($user_id_unsafe, $for_update, $fields, $player); |
5 | 8 | } |
@@ -161,7 +161,7 @@ |
||
161 | 161 | !is_array($user_id_list) ? $user_id_list = array($user_id_list) : false; |
162 | 162 | |
163 | 163 | $user_list = array(); |
164 | - foreach($user_id_list as $user_id_unsafe) { |
|
164 | + foreach ($user_id_list as $user_id_unsafe) { |
|
165 | 165 | $user = db_user_by_id($user_id_unsafe); |
166 | 166 | !empty($user) ? $user_list[$user_id_unsafe] = $user : false; |
167 | 167 | } |
@@ -10,6 +10,7 @@ discard block |
||
10 | 10 | * |
11 | 11 | * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
12 | 12 | * @version 1.0 |
13 | + * @param integer $lab_require |
|
13 | 14 | */ |
14 | 15 | function eco_get_lab_max_effective_level(&$user, $lab_require) |
15 | 16 | { |
@@ -193,6 +194,9 @@ discard block |
||
193 | 194 | return $result; |
194 | 195 | } |
195 | 196 | |
197 | +/** |
|
198 | + * @param integer[] $unit_list |
|
199 | + */ |
|
196 | 200 | function eco_is_builds_in_que($planet_que, $unit_list) |
197 | 201 | { |
198 | 202 | $eco_is_builds_in_que = false; |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | * @version 1.0 |
12 | 12 | */ |
13 | 13 | function eco_get_lab_max_effective_level(&$user, $lab_require) { |
14 | - if(!$user['user_as_ally'] && !isset($user['laboratories_active'])) { |
|
14 | + if (!$user['user_as_ally'] && !isset($user['laboratories_active'])) { |
|
15 | 15 | $user['laboratories_active'] = array(); |
16 | 16 | $query = db_unit_list_laboratories($user['id']); |
17 | - while($row = db_fetch($query)) { |
|
18 | - if(!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) { |
|
17 | + while ($row = db_fetch($query)) { |
|
18 | + if (!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) { |
|
19 | 19 | $row += array( |
20 | 20 | STRUC_LABORATORY => $level_lab = mrc_get_level($user, $row, STRUC_LABORATORY), |
21 | 21 | STRUC_LABORATORY_NANO => $level_lab_nano = mrc_get_level($user, $row, STRUC_LABORATORY_NANO), |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | uasort($user['laboratories_active'], 'eco_lab_sort_effectivness'); |
29 | 29 | } |
30 | 30 | |
31 | - if(!isset($user['research_effective_level'][$lab_require])) { |
|
32 | - if($user['user_as_ally']) { |
|
31 | + if (!isset($user['research_effective_level'][$lab_require])) { |
|
32 | + if ($user['user_as_ally']) { |
|
33 | 33 | $lab_level = db_ally_get_ally_count($user); |
34 | 34 | } else { |
35 | 35 | $tech_intergalactic = mrc_get_level($user, null, TECH_RESEARCH) + 1; |
36 | 36 | $lab_level['effective_level'] = 0; |
37 | 37 | |
38 | - foreach($user['laboratories_active'] as $data) { |
|
39 | - if($tech_intergalactic <= 0) { |
|
38 | + foreach ($user['laboratories_active'] as $data) { |
|
39 | + if ($tech_intergalactic <= 0) { |
|
40 | 40 | break; |
41 | 41 | } |
42 | - if($data[STRUC_LABORATORY] >= $lab_require) { |
|
42 | + if ($data[STRUC_LABORATORY] >= $lab_require) { |
|
43 | 43 | $lab_level['effective_level'] += $data['laboratory_effective_level']; |
44 | 44 | $tech_intergalactic--; |
45 | 45 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | $time = 0; |
66 | 66 | $only_dark_matter = 0; |
67 | 67 | $cost_in_metal = 0; |
68 | - foreach($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
69 | - if($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
68 | + foreach ($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
69 | + if ($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
70 | 70 | continue; |
71 | 71 | } |
72 | 72 | |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | |
76 | 76 | $resource_db_name = pname_resource_name($resource_id); |
77 | 77 | $cost_in_metal += $cost[BUILD_CREATE][$resource_id] * classSupernova::$config->__get("rpg_exchange_{$resource_db_name}"); |
78 | - if(in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
78 | + if (in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
79 | 79 | $time += $resource_cost * classSupernova::$config->__get("rpg_exchange_{$resource_db_name}") / $rpg_exchange_deuterium; |
80 | 80 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
81 | - } elseif($resource_id == RES_DARK_MATTER) { |
|
81 | + } elseif ($resource_id == RES_DARK_MATTER) { |
|
82 | 82 | $resource_got = mrc_get_level($user, null, $resource_id); |
83 | - } elseif($resource_id == RES_ENERGY) { |
|
83 | + } elseif ($resource_id == RES_ENERGY) { |
|
84 | 84 | $resource_got = max(0, $planet['energy_max'] - $planet['energy_used']); |
85 | 85 | } else { |
86 | 86 | $resource_got = 0; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | $resources_normalized = 0; |
95 | 95 | $resources_loot = sn_get_groups('resources_loot'); |
96 | - foreach($resources_loot as $resource_id) { |
|
96 | + foreach ($resources_loot as $resource_id) { |
|
97 | 97 | $resource_db_name = pname_resource_name($resource_id); |
98 | 98 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
99 | 99 | $resources_normalized += floor($resource_got) * classSupernova::$config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $cost[P_OPTIONS][P_TIME_RAW] = $time = $time * 60 * 60 / get_game_speed() / 2500; |
112 | 112 | |
113 | 113 | // TODO - Вынести в отдельную процедуру расчёт стоимости |
114 | - if($only_cost) { |
|
114 | + if ($only_cost) { |
|
115 | 115 | return $cost; |
116 | 116 | } |
117 | 117 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | $mercenary = 0; |
122 | 122 | $cost['RESULT'][BUILD_DESTROY] = BUILD_INDESTRUCTABLE; |
123 | - if(in_array($unit_id, sn_get_groups('structures'))) { |
|
123 | + if (in_array($unit_id, sn_get_groups('structures'))) { |
|
124 | 124 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1); |
125 | 125 | $mercenary = MRC_ENGINEER; |
126 | 126 | $cost['RESULT'][BUILD_DESTROY] = |
@@ -130,23 +130,23 @@ discard block |
||
130 | 130 | : BUILD_NO_RESOURCES |
131 | 131 | ) |
132 | 132 | : BUILD_NO_UNITS; |
133 | - } elseif(in_array($unit_id, sn_get_groups('tech'))) { |
|
133 | + } elseif (in_array($unit_id, sn_get_groups('tech'))) { |
|
134 | 134 | $lab_level = eco_get_lab_max_effective_level($user, intval($unit_data['require'][STRUC_LABORATORY])); |
135 | 135 | $time = $time / $lab_level; |
136 | 136 | $mercenary = MRC_ACADEMIC; |
137 | - } elseif(in_array($unit_id, sn_get_groups('defense'))) { |
|
137 | + } elseif (in_array($unit_id, sn_get_groups('defense'))) { |
|
138 | 138 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
139 | 139 | $mercenary = MRC_FORTIFIER; |
140 | - } elseif(in_array($unit_id, sn_get_groups('fleet'))) { |
|
140 | + } elseif (in_array($unit_id, sn_get_groups('fleet'))) { |
|
141 | 141 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
142 | 142 | $mercenary = MRC_ENGINEER; |
143 | 143 | } |
144 | 144 | |
145 | - if($mercenary) { |
|
145 | + if ($mercenary) { |
|
146 | 146 | $time = $time / mrc_modify_value($user, $planet, $mercenary, 1); |
147 | 147 | } |
148 | 148 | |
149 | - if(in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
149 | + if (in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
150 | 150 | $cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0; |
151 | 151 | } else { |
152 | 152 | $cost[RES_TIME][BUILD_CREATE] = round($time >= 1 ? $time : 1); |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | $result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result; |
164 | 164 | |
165 | 165 | $unit_param = get_unit_param($unit_id); |
166 | - if($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !classSupernova::$config->empire_mercenary_temporary) { |
|
166 | + if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !classSupernova::$config->empire_mercenary_temporary) { |
|
167 | 167 | $requirement = &$unit_param[P_REQUIRE]; |
168 | - if($result == BUILD_ALLOWED && $requirement) { |
|
169 | - foreach($requirement as $require_id => $require_level) { |
|
170 | - if(mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
168 | + if ($result == BUILD_ALLOWED && $requirement) { |
|
169 | + foreach ($requirement as $require_id => $require_level) { |
|
170 | + if (mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
171 | 171 | $result = BUILD_REQUIRE_NOT_MEET; |
172 | 172 | break; |
173 | 173 | } |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | |
184 | 184 | $unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list); |
185 | 185 | $planet_que = explode(';', $planet_que); |
186 | - foreach($planet_que as $planet_que_item) { |
|
187 | - if($planet_que_item) { |
|
186 | + foreach ($planet_que as $planet_que_item) { |
|
187 | + if ($planet_que_item) { |
|
188 | 188 | list($planet_que_item) = explode(',', $planet_que_item); |
189 | - if(in_array($planet_que_item, $unit_list)) { |
|
189 | + if (in_array($planet_que_item, $unit_list)) { |
|
190 | 190 | $eco_is_builds_in_que = true; |
191 | 191 | break; |
192 | 192 | } |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | |
201 | 201 | function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) { |
202 | 202 | $result = isset($result) ? $result : false; |
203 | - if(!$result) { |
|
204 | - if(($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !classSupernova::$config->BuildLabWhileRun) { |
|
203 | + if (!$result) { |
|
204 | + if (($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !classSupernova::$config->BuildLabWhileRun) { |
|
205 | 205 | $global_que = que_get($user['id'], $planet['id'], QUE_RESEARCH, false); |
206 | - if(is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) { |
|
206 | + if (is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) { |
|
207 | 207 | $first_element = reset($global_que['ques'][QUE_RESEARCH][$user['id']]); |
208 | - if(is_array($first_element)) { |
|
208 | + if (is_array($first_element)) { |
|
209 | 209 | $result = true; |
210 | 210 | } |
211 | 211 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | //{ |
214 | 214 | // $result = true; |
215 | 215 | //} |
216 | - } elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !classSupernova::$config->BuildLabWhileRun && $planet['que']) { |
|
216 | + } elseif (($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !classSupernova::$config->BuildLabWhileRun && $planet['que']) { |
|
217 | 217 | $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
218 | 218 | } |
219 | 219 | } |
@@ -55,6 +55,9 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | +/** |
|
59 | + * @param integer $build_mode |
|
60 | + */ |
|
58 | 61 | function que_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) { |
59 | 62 | global $lang, $config; |
60 | 63 | |
@@ -378,6 +381,9 @@ discard block |
||
378 | 381 | return classSupernova::db_que_list_by_type_location($user_id, $planet_id, $que_type, $for_update); |
379 | 382 | } |
380 | 383 | |
384 | +/** |
|
385 | + * @param integer $unit_id |
|
386 | + */ |
|
381 | 387 | function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) { |
382 | 388 | // TODO Унифицировать проверки |
383 | 389 |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | function que_get_unit_que($unit_id) { |
4 | 4 | $que_type = false; |
5 | - foreach(sn_get_groups('ques') as $que_id => $que_data) { |
|
6 | - if(in_array($unit_id, $que_data['unit_list'])) { |
|
5 | + foreach (sn_get_groups('ques') as $que_id => $que_data) { |
|
6 | + if (in_array($unit_id, $que_data['unit_list'])) { |
|
7 | 7 | $que_type = $que_id; |
8 | 8 | break; |
9 | 9 | } |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | |
16 | 16 | function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { |
17 | - if(empty($que_data)) { |
|
17 | + if (empty($que_data)) { |
|
18 | 18 | $que_data = sn_get_groups('ques'); |
19 | 19 | $que_data = $que_data[$que_id]; |
20 | 20 | } |
21 | 21 | |
22 | 22 | |
23 | 23 | $que_length = 1; |
24 | - switch($que_id) { |
|
24 | + switch ($que_id) { |
|
25 | 25 | case QUE_RESEARCH: |
26 | 26 | $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль |
27 | 27 | break; |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | |
36 | 36 | function eco_que_str2arr($que_str) { |
37 | 37 | $que_arr = explode(';', $que_str); |
38 | - foreach($que_arr as $que_index => &$que_item) { |
|
39 | - if($que_item) { |
|
38 | + foreach ($que_arr as $que_index => &$que_item) { |
|
39 | + if ($que_item) { |
|
40 | 40 | $que_item = explode(',', $que_item); |
41 | 41 | } else { |
42 | 42 | unset($que_arr[$que_index]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | function eco_que_arr2str($que_arr) { |
50 | - foreach($que_arr as &$que_item) { |
|
50 | + foreach ($que_arr as &$que_item) { |
|
51 | 51 | $que_item = implode(',', $que_item); |
52 | 52 | } |
53 | 53 | |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | $classLocale = classLocale::$lang; |
60 | 60 | |
61 | 61 | $is_autoconvert = false; |
62 | - if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
62 | + if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
63 | 63 | $build_mode = BUILD_CREATE; |
64 | 64 | $is_autoconvert = true; |
65 | 65 | } |
66 | 66 | |
67 | 67 | $unit_amount_qued = 0; |
68 | 68 | try { |
69 | - if(!$user['id']) { |
|
69 | + if (!$user['id']) { |
|
70 | 70 | throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
71 | 71 | } |
72 | 72 | |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break; |
78 | 78 | } |
79 | 79 | */ |
80 | - if(!$unit_id) { |
|
80 | + if (!$unit_id) { |
|
81 | 81 | throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
82 | 82 | } |
83 | 83 | |
84 | 84 | $que_id = que_get_unit_que($unit_id); |
85 | - if(!$que_id) { |
|
85 | + if (!$que_id) { |
|
86 | 86 | throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
87 | 87 | } |
88 | 88 | |
89 | - if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
89 | + if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
90 | 90 | throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION |
91 | 91 | } |
92 | 92 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | $que_data = $que_data[$que_id]; |
95 | 95 | |
96 | 96 | // TODO Переделать под подочереди |
97 | - if($que_id == QUE_STRUCTURES) { |
|
97 | + if ($que_id == QUE_STRUCTURES) { |
|
98 | 98 | $sn_groups_build_allow = sn_get_groups('build_allow'); |
99 | 99 | $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; |
100 | 100 | |
101 | - if(!isset($que_data['unit_list'][$unit_id])) { |
|
101 | + if (!isset($que_data['unit_list'][$unit_id])) { |
|
102 | 102 | throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION |
103 | 103 | } |
104 | 104 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | // Это нужно, что бы заблокировать пользователя и работу с очередями |
120 | 120 | $user = db_user_by_id($user['id']); |
121 | 121 | // Это нужно, что бы заблокировать планету от списания ресурсов |
122 | - if(isset($planet['id']) && $planet['id']) { |
|
122 | + if (isset($planet['id']) && $planet['id']) { |
|
123 | 123 | $planet = db_planet_by_id($planet['id'], true); |
124 | 124 | } else { |
125 | 125 | $planet['id'] = 0; |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id]; |
132 | 132 | $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data); |
133 | 133 | // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей |
134 | - if(count($in_que) >= $que_max_length) { |
|
134 | + if (count($in_que) >= $que_max_length) { |
|
135 | 135 | throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION |
136 | 136 | } |
137 | 137 | |
138 | 138 | // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов |
139 | - switch(eco_can_build_unit($user, $planet, $unit_id)) { |
|
139 | + switch (eco_can_build_unit($user, $planet, $unit_id)) { |
|
140 | 140 | case BUILD_ALLOWED: |
141 | 141 | break; |
142 | 142 | case BUILD_UNIT_BUSY: |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading |
145 | 145 | // case BUILD_REQUIRE_NOT_MEET: |
146 | 146 | default: |
147 | - if($build_mode == BUILD_CREATE) { |
|
147 | + if ($build_mode == BUILD_CREATE) { |
|
148 | 148 | throw new exception('{Требования не удовлетворены}', ERR_ERROR); |
149 | 149 | } |
150 | 150 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet |
@@ -154,14 +154,14 @@ discard block |
||
154 | 154 | $unit_amount_qued = $unit_amount; |
155 | 155 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; |
156 | 156 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; |
157 | - if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
158 | - if($unit_level >= $unit_max) { |
|
157 | + if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
158 | + if ($unit_level >= $unit_max) { |
|
159 | 159 | throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
160 | 160 | } |
161 | 161 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); |
162 | 162 | } |
163 | 163 | |
164 | - if($unit_amount < 1) { |
|
164 | + if ($unit_amount < 1) { |
|
165 | 165 | throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
166 | 166 | } |
167 | 167 | |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | // { |
171 | 171 | // die('Unit busy'); // TODO EXCEPTION |
172 | 172 | // } |
173 | - if(get_unit_param($unit_id, P_STACKABLE)) { |
|
173 | + if (get_unit_param($unit_id, P_STACKABLE)) { |
|
174 | 174 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь |
175 | - if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
175 | + if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
176 | 176 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита |
177 | 177 | $used_silo = 0; |
178 | - foreach($group_missile as $missile_id) { |
|
178 | + foreach ($group_missile as $missile_id) { |
|
179 | 179 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; |
180 | 180 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); |
181 | 181 | } |
182 | 182 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; |
183 | - if($free_silo <= 0) { |
|
183 | + if ($free_silo <= 0) { |
|
184 | 184 | throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
185 | 185 | } |
186 | 186 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); |
187 | - if($free_silo < $unit_size) { |
|
187 | + if ($free_silo < $unit_size) { |
|
188 | 188 | throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION |
189 | 189 | } |
190 | 190 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | $unit_level = $new_unit_level = 0; |
193 | 193 | } else { |
194 | 194 | $unit_amount = 1; |
195 | - if($que_id == QUE_STRUCTURES) { |
|
195 | + if ($que_id == QUE_STRUCTURES) { |
|
196 | 196 | // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) |
197 | 197 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; |
198 | - if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { |
|
198 | + if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { |
|
199 | 199 | throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION |
200 | 200 | } |
201 | 201 | // И что это я такое написал? Зачем? |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | |
213 | 213 | $exchange = array(); |
214 | 214 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); |
215 | - if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
215 | + if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
216 | 216 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
217 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
217 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
218 | 218 | throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION |
219 | 219 | } |
220 | 220 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $resource_exchange_rates = array(); |
225 | 225 | $resource_diff = array(); |
226 | 226 | $all_positive = true; |
227 | - foreach($resources_loot as $resource_id) { |
|
227 | + foreach ($resources_loot as $resource_id) { |
|
228 | 228 | $resource_db_name = pname_resource_name($resource_id); |
229 | 229 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); |
230 | 230 | $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); |
233 | 233 | } |
234 | 234 | // Нужна автоконвертация |
235 | - if($all_positive) { |
|
235 | + if ($all_positive) { |
|
236 | 236 | $is_autoconvert = false; |
237 | 237 | } else { |
238 | - foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
239 | - if($resource_diff_amount >= 0) { |
|
238 | + foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
239 | + if ($resource_diff_amount >= 0) { |
|
240 | 240 | continue; |
241 | 241 | } |
242 | - foreach($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
243 | - if($resource_got_amount <= 0) { |
|
242 | + foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
243 | + if ($resource_got_amount <= 0) { |
|
244 | 244 | continue; |
245 | 245 | } |
246 | 246 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; |
@@ -256,14 +256,14 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | $is_autoconvert_ok = true; |
259 | - foreach($resource_diff as $resource_diff_amount2) { |
|
260 | - if($resource_diff_amount2 < 0) { |
|
259 | + foreach ($resource_diff as $resource_diff_amount2) { |
|
260 | + if ($resource_diff_amount2 < 0) { |
|
261 | 261 | $is_autoconvert_ok = false; |
262 | 262 | break; |
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - if($is_autoconvert_ok) { |
|
266 | + if ($is_autoconvert_ok) { |
|
267 | 267 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; |
268 | 268 | $build_data['CAN'][$build_mode] = $unit_amount; |
269 | 269 | } else { |
@@ -272,19 +272,19 @@ discard block |
||
272 | 272 | } |
273 | 273 | } |
274 | 274 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); |
275 | - if($unit_amount <= 0) { |
|
275 | + if ($unit_amount <= 0) { |
|
276 | 276 | throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION |
277 | 277 | } |
278 | 278 | |
279 | - if($new_unit_level < 0) { |
|
279 | + if ($new_unit_level < 0) { |
|
280 | 280 | throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION |
281 | 281 | } |
282 | 282 | |
283 | - if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
283 | + if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
284 | 284 | throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION |
285 | 285 | } |
286 | 286 | |
287 | - if($is_autoconvert) { |
|
287 | + if ($is_autoconvert) { |
|
288 | 288 | ksort($exchange); |
289 | 289 | ksort($resource_got); |
290 | 290 | db_change_units($user, $planet, array( |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | |
301 | 301 | $unit_amount_qued = 0; |
302 | - while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
302 | + while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
303 | 303 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); |
304 | 304 | que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
305 | 305 | $unit_amount -= $place; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | |
310 | 310 | sn_db_transaction_commit(); |
311 | 311 | |
312 | - if($redirect) { |
|
312 | + if ($redirect) { |
|
313 | 313 | sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); |
314 | 314 | die(); |
315 | 315 | } |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | 'STATUS' => ERR_NONE, |
319 | 319 | 'MESSAGE' => '{Строительство начато}', |
320 | 320 | ); |
321 | - } catch(exception $e) { |
|
321 | + } catch (exception $e) { |
|
322 | 322 | sn_db_transaction_rollback(); |
323 | 323 | $operation_result = array( |
324 | 324 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ); |
327 | 327 | } |
328 | 328 | |
329 | - if(!empty($operation_result['MESSAGE'])) { |
|
329 | + if (!empty($operation_result['MESSAGE'])) { |
|
330 | 330 | $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']'; |
331 | 331 | } |
332 | 332 | |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | function que_recalculate($old_que) { |
338 | 338 | $new_que = array(); |
339 | 339 | |
340 | - if(!is_array($old_que['items'])) { |
|
340 | + if (!is_array($old_que['items'])) { |
|
341 | 341 | return $new_que; |
342 | 342 | } |
343 | - foreach($old_que['items'] as $row) { |
|
344 | - if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
343 | + foreach ($old_que['items'] as $row) { |
|
344 | + if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
345 | 345 | continue; |
346 | 346 | } |
347 | 347 | |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | |
353 | 353 | $last_id = count($new_que['items']) - 1; |
354 | 354 | |
355 | - if($row['que_planet_id']) { |
|
355 | + if ($row['que_planet_id']) { |
|
356 | 356 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
357 | - } elseif($row['que_type'] == QUE_RESEARCH) { |
|
357 | + } elseif ($row['que_type'] == QUE_RESEARCH) { |
|
358 | 358 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
359 | 359 | } |
360 | 360 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; |
@@ -389,9 +389,9 @@ discard block |
||
389 | 389 | $que_type = que_get_unit_que($unit_id); |
390 | 390 | $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL'; |
391 | 391 | $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin; |
392 | - if(is_numeric($planet_id)) { |
|
392 | + if (is_numeric($planet_id)) { |
|
393 | 393 | db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
394 | - } elseif(is_numeric($user['id'])) { |
|
394 | + } elseif (is_numeric($user['id'])) { |
|
395 | 395 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
396 | 396 | } |
397 | 397 | |
@@ -421,17 +421,17 @@ discard block |
||
421 | 421 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; |
422 | 422 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); |
423 | 423 | |
424 | - if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
424 | + if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
425 | 425 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); |
426 | 426 | |
427 | - foreach($que as $que_item) { |
|
427 | + foreach ($que as $que_item) { |
|
428 | 428 | db_que_delete_by_id($que_item['que_id']); |
429 | 429 | |
430 | - if($que_item['que_planet_id_origin']) { |
|
430 | + if ($que_item['que_planet_id_origin']) { |
|
431 | 431 | $planet['id'] = $que_item['que_planet_id_origin']; |
432 | 432 | } |
433 | 433 | |
434 | - if(!isset($planets_locked[$planet['id']])) { |
|
434 | + if (!isset($planets_locked[$planet['id']])) { |
|
435 | 435 | $planets_locked[$planet['id']] = $planet['id'] ? db_planet_by_id($planet['id'], true) : $planet; |
436 | 436 | } |
437 | 437 | |
@@ -443,14 +443,14 @@ discard block |
||
443 | 443 | RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'], |
444 | 444 | )); |
445 | 445 | |
446 | - if(!$clear) { |
|
446 | + if (!$clear) { |
|
447 | 447 | break; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if(is_numeric($planet['id'])) { |
|
451 | + if (is_numeric($planet['id'])) { |
|
452 | 452 | db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
453 | - } elseif(is_numeric($user['id'])) { |
|
453 | + } elseif (is_numeric($user['id'])) { |
|
454 | 454 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
455 | 455 | } |
456 | 456 | |
@@ -498,21 +498,21 @@ discard block |
||
498 | 498 | // TODO: Переделать для $que_type === false |
499 | 499 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; |
500 | 500 | |
501 | - if(!is_array($que)) { |
|
501 | + if (!is_array($que)) { |
|
502 | 502 | $que = que_get($user['id'], $planet['id'], $que_type); |
503 | 503 | } |
504 | 504 | |
505 | - if(is_array($que) && isset($que['items'])) { |
|
505 | + if (is_array($que) && isset($que['items'])) { |
|
506 | 506 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; |
507 | 507 | } |
508 | 508 | |
509 | - if($que) { |
|
510 | - foreach($que as $que_element) { |
|
509 | + if ($que) { |
|
510 | + foreach ($que as $que_element) { |
|
511 | 511 | $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); |
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
515 | - if($que_type == QUE_RESEARCH) { |
|
515 | + if ($que_type == QUE_RESEARCH) { |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | $user = db_user_by_id($user['id'], true); |
539 | 539 | |
540 | 540 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); |
541 | - if($planet === null && !$time_left[$user['id']][0]) { |
|
541 | + if ($planet === null && !$time_left[$user['id']][0]) { |
|
542 | 542 | // TODO |
543 | 543 | return $que; |
544 | 544 | } |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | $que_type_id = $planet === null ? QUE_RESEARCH : false; |
548 | 548 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false |
549 | 549 | $que = que_get($user['id'], $planet, $que_type_id, true); |
550 | - if(empty($que['items'])) { |
|
550 | + if (empty($que['items'])) { |
|
551 | 551 | return $que; |
552 | 552 | } |
553 | 553 | |
554 | 554 | $planet_list = array(); |
555 | - if($planet !== null) { |
|
555 | + if ($planet !== null) { |
|
556 | 556 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них |
557 | 557 | // TODO - от них не надо ничего, кроме ID и que_processed |
558 | 558 | $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet); |
@@ -561,21 +561,21 @@ discard block |
||
561 | 561 | } |
562 | 562 | |
563 | 563 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты |
564 | - if(array_sum($time_left[$user['id']]) == 0) { |
|
564 | + if (array_sum($time_left[$user['id']]) == 0) { |
|
565 | 565 | return $que; |
566 | 566 | } |
567 | 567 | |
568 | 568 | $db_changeset = array(); |
569 | 569 | $unit_changes = array(); |
570 | - foreach($que['items'] as &$que_item) { |
|
570 | + foreach ($que['items'] as &$que_item) { |
|
571 | 571 | $que_player_id = &$que_item['que_player_id']; |
572 | 572 | $que_planet_id = intval($que_item['que_planet_id']); |
573 | 573 | |
574 | 574 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; |
575 | - if(!isset($que_time_left)) { |
|
575 | + if (!isset($que_time_left)) { |
|
576 | 576 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; |
577 | 577 | } |
578 | - if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
578 | + if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
579 | 579 | continue; |
580 | 580 | } |
581 | 581 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля |
589 | 589 | |
590 | 590 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит |
591 | - if($que_time_left >= $que_item['que_time_left']) { |
|
591 | + if ($que_time_left >= $que_item['que_time_left']) { |
|
592 | 592 | // Увеличиваем количество отстроенных юнитов |
593 | 593 | $unit_processed++; |
594 | 594 | // Вычитаем из времени очереди потраченное на постройку время |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | $que_item['que_unit_amount'] -= $unit_processed; |
602 | 602 | |
603 | 603 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита |
604 | - if($que_item['que_unit_amount'] > 0) { |
|
604 | + if ($que_item['que_unit_amount'] > 0) { |
|
605 | 605 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; |
606 | 606 | $que_time_left = 0; |
607 | 607 | } |
608 | 608 | |
609 | - if($que_item['que_unit_amount'] <= 0) { |
|
609 | + if ($que_item['que_unit_amount'] <= 0) { |
|
610 | 610 | $db_changeset['que'][] = array( |
611 | 611 | 'action' => SQL_OP_DELETE, |
612 | 612 | P_VERSION => 1, |
@@ -632,14 +632,14 @@ discard block |
||
632 | 632 | ); |
633 | 633 | } |
634 | 634 | |
635 | - if($unit_processed) { |
|
635 | + if ($unit_processed) { |
|
636 | 636 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); |
637 | 637 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; |
638 | 638 | } |
639 | 639 | } |
640 | 640 | |
641 | - foreach($time_left as $player_id => $planet_data) { |
|
642 | - foreach($planet_data as $planet_id => $time_on_planet) { |
|
641 | + foreach ($time_left as $player_id => $planet_data) { |
|
642 | + foreach ($planet_data as $planet_id => $time_on_planet) { |
|
643 | 643 | $table = $planet_id ? 'planets' : 'users'; |
644 | 644 | $id = $planet_id ? $planet_id : $player_id; |
645 | 645 | $db_changeset[$table][] = array( |
@@ -655,8 +655,8 @@ discard block |
||
655 | 655 | ), |
656 | 656 | ); |
657 | 657 | |
658 | - if(is_array($unit_changes[$player_id][$planet_id])) { |
|
659 | - foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
658 | + if (is_array($unit_changes[$player_id][$planet_id])) { |
|
659 | + foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
660 | 660 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); |
661 | 661 | } |
662 | 662 | } |
@@ -666,38 +666,38 @@ discard block |
||
666 | 666 | $que = que_recalculate($que); |
667 | 667 | |
668 | 668 | // TODO: Re-enable quests for Alliances |
669 | - if(!empty($unit_changes) && !$user['user_as_ally']) { |
|
669 | + if (!empty($unit_changes) && !$user['user_as_ally']) { |
|
670 | 670 | $quest_list = qst_get_quests($user['id']); |
671 | 671 | $quest_triggers = qst_active_triggers($quest_list); |
672 | 672 | $quest_rewards = array(); |
673 | 673 | |
674 | 674 | |
675 | 675 | $xp_incoming = array(); |
676 | - foreach($unit_changes as $user_id => $planet_changes) { |
|
677 | - foreach($planet_changes as $planet_id => $changes) { |
|
676 | + foreach ($unit_changes as $user_id => $planet_changes) { |
|
677 | + foreach ($planet_changes as $planet_id => $changes) { |
|
678 | 678 | $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); |
679 | - foreach($changes as $unit_id => $unit_value) { |
|
679 | + foreach ($changes as $unit_id => $unit_value) { |
|
680 | 680 | $que_id = que_get_unit_que($unit_id); |
681 | 681 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; |
682 | - if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
682 | + if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
683 | 683 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); |
684 | 684 | $build_data = $build_data[BUILD_CREATE]; |
685 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
685 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
686 | 686 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена |
687 | 687 | } |
688 | 688 | } |
689 | 689 | |
690 | - if(is_array($quest_triggers)) { |
|
690 | + if (is_array($quest_triggers)) { |
|
691 | 691 | // TODO: Check mutiply condition quests |
692 | 692 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); |
693 | - if(is_array($quest_trigger_list)) { |
|
694 | - foreach($quest_trigger_list as $quest_id) { |
|
693 | + if (is_array($quest_trigger_list)) { |
|
694 | + foreach ($quest_trigger_list as $quest_id) { |
|
695 | 695 | $quest_unit_level = $unit_level_new; |
696 | - if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
696 | + if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
697 | 697 | $quest_unit_level = db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id); |
698 | 698 | $quest_unit_level = $quest_unit_level[$unit_id]['qty']; |
699 | 699 | } |
700 | - if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
700 | + if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
701 | 701 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; |
702 | 702 | $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; |
703 | 703 | } |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч |
711 | 711 | qst_reward($user, $quest_rewards, $quest_list); |
712 | 712 | |
713 | - foreach($xp_incoming as $que_id => $xp) { |
|
713 | + foreach ($xp_incoming as $que_id => $xp) { |
|
714 | 714 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); |
715 | 715 | } |
716 | 716 | } |
@@ -37,6 +37,9 @@ |
||
37 | 37 | return $list; |
38 | 38 | } |
39 | 39 | |
40 | +/** |
|
41 | + * @param integer $message_type |
|
42 | + */ |
|
40 | 43 | function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) |
41 | 44 | { |
42 | 45 | global $config, $user, $sn_message_class_list; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''), |
26 | 26 | false, 'id, username'); |
27 | 27 | // while ($u = db_fetch($query)) |
28 | - foreach($query as $u) { |
|
28 | + foreach ($query as $u) { |
|
29 | 29 | $sendList[] = $u['id']; |
30 | 30 | $list .= "<br>{$u['username']} "; |
31 | 31 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) { |
39 | 39 | global $user, $sn_message_class_list; |
40 | 40 | |
41 | - if(!$owners) { |
|
41 | + if (!$owners) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $timestamp = $timestamp ? $timestamp : SN_TIME_NOW; |
46 | 46 | $sender = intval($sender); |
47 | - if(!is_array($owners)) { |
|
47 | + if (!is_array($owners)) { |
|
48 | 48 | $owners = array($owners); |
49 | 49 | } |
50 | 50 | |
51 | - if(!$escaped) { |
|
51 | + if (!$escaped) { |
|
52 | 52 | $from = db_escape($from); |
53 | 53 | $subject = db_escape($subject); |
54 | 54 | $text = db_escape($text); |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | |
64 | 64 | $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name']; |
65 | 65 | |
66 | - if($owners[0] == '*') { |
|
67 | - if($user['authlevel'] < 3) { |
|
66 | + if ($owners[0] == '*') { |
|
67 | + if ($user['authlevel'] < 3) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | // TODO Добавить $timestamp - рассылка может быть и отсроченной |
@@ -75,24 +75,24 @@ discard block |
||
75 | 75 | $insert_values = array(); |
76 | 76 | $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')"); |
77 | 77 | |
78 | - foreach($owners as $owner) { |
|
79 | - if($user['id'] != $owner) { |
|
78 | + foreach ($owners as $owner) { |
|
79 | + if ($user['id'] != $owner) { |
|
80 | 80 | $owner_row = db_user_by_id($owner); |
81 | 81 | } else { |
82 | 82 | $owner_row = $user; |
83 | 83 | } |
84 | 84 | sys_user_options_unpack($owner_row); |
85 | 85 | |
86 | - if($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) { |
|
86 | + if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) { |
|
87 | 87 | $insert_values[] = sprintf($insert_template, $owner); |
88 | 88 | } |
89 | 89 | |
90 | - if($message_class_email && classSupernova::$config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) { |
|
90 | + if ($message_class_email && classSupernova::$config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) { |
|
91 | 91 | @$result = mymail($owner_row['email'], $subject, $text_unescaped, '', true); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - if(empty($insert_values)) { |
|
95 | + if (empty($insert_values)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | } |
101 | 101 | db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1"); |
102 | 102 | |
103 | - if(in_array($user['id'], $owners) || $owners[0] == '*') { |
|
103 | + if (in_array($user['id'], $owners) || $owners[0] == '*') { |
|
104 | 104 | $user[$message_class_name]++; |
105 | 105 | $user[$message_class_name_total]++; |
106 | 106 | } |
@@ -161,6 +161,9 @@ discard block |
||
161 | 161 | return $rows_affected; |
162 | 162 | } |
163 | 163 | |
164 | +/** |
|
165 | + * @param integer $type |
|
166 | + */ |
|
164 | 167 | function rpg_level_up(&$user, $type, $xp_to_add = 0) |
165 | 168 | { |
166 | 169 | $q = 1.03; |
@@ -223,6 +226,10 @@ discard block |
||
223 | 226 | } |
224 | 227 | } |
225 | 228 | |
229 | +/** |
|
230 | + * @param integer $b1 |
|
231 | + * @param double $q |
|
232 | + */ |
|
226 | 233 | function rpg_xp_for_level($level, $b1, $q) |
227 | 234 | { |
228 | 235 | return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
@@ -233,6 +240,9 @@ discard block |
||
233 | 240 | return rpg_xp_for_level($level, 50, 1.03); |
234 | 241 | } |
235 | 242 | |
243 | +/** |
|
244 | + * @param integer $level |
|
245 | + */ |
|
236 | 246 | function RPG_get_raider_xp($level) |
237 | 247 | { |
238 | 248 | return rpg_xp_for_level($level, 10, 1.03); |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * @package rpg |
|
5 | - * @version $Id$ |
|
6 | - * @copyright (c) 2009-2010 Gorlum for http://supernova.ws |
|
7 | - * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
8 | - * |
|
9 | - */ |
|
3 | + * |
|
4 | + * @package rpg |
|
5 | + * @version $Id$ |
|
6 | + * @copyright (c) 2009-2010 Gorlum for http://supernova.ws |
|
7 | + * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
8 | + * |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | |
12 | 12 | /** |
@@ -29,28 +29,28 @@ discard block |
||
29 | 29 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = '', $already_changed = false) { |
30 | 30 | global $debug, $dm_change_legit, $user; |
31 | 31 | |
32 | - if(!$user_id) { |
|
32 | + if (!$user_id) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | 36 | $dm_change_legit = true; |
37 | 37 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
38 | 38 | |
39 | - if($already_changed) { |
|
39 | + if ($already_changed) { |
|
40 | 40 | $rows_affected = 1; |
41 | 41 | } else { |
42 | 42 | $changeset = array(); |
43 | 43 | $a_user = db_user_by_id($user_id, true); |
44 | - if($dark_matter < 0) { |
|
44 | + if ($dark_matter < 0) { |
|
45 | 45 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
46 | 46 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
47 | 47 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
48 | - if($metamatter_to_reduce > 0) { |
|
48 | + if ($metamatter_to_reduce > 0) { |
|
49 | 49 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
50 | - if($metamatter_exists < $metamatter_to_reduce) { |
|
50 | + if ($metamatter_exists < $metamatter_to_reduce) { |
|
51 | 51 | $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
52 | 52 | } |
53 | - if(is_array($comment)) { |
|
53 | + if (is_array($comment)) { |
|
54 | 54 | $comment = call_user_func_array('sprintf', $comment); |
55 | 55 | } |
56 | 56 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | $rows_affected = classSupernova::$db->db_affected_rows(); |
66 | 66 | } |
67 | 67 | |
68 | - if($rows_affected || !$dark_matter) { |
|
68 | + if ($rows_affected || !$dark_matter) { |
|
69 | 69 | $page_url = db_escape($_SERVER['SCRIPT_NAME']); |
70 | - if(is_array($comment)) { |
|
70 | + if (is_array($comment)) { |
|
71 | 71 | $comment = call_user_func_array('sprintf', $comment); |
72 | 72 | } |
73 | 73 | $comment = db_escape($comment); |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | $row['username'] = db_escape($row['username']); |
76 | 76 | db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment, $row, $page_url); |
77 | 77 | |
78 | - if($user['id'] == $user_id) { |
|
78 | + if ($user['id'] == $user_id) { |
|
79 | 79 | $user['dark_matter'] += $dark_matter; |
80 | 80 | } |
81 | 81 | |
82 | - if($dark_matter > 0) { |
|
82 | + if ($dark_matter > 0) { |
|
83 | 83 | $old_referral = db_referral_get_by_id($user_id); |
84 | - if($old_referral['id']) { |
|
84 | + if ($old_referral['id']) { |
|
85 | 85 | db_referral_update_dm($user_id, $dark_matter); |
86 | 86 | $new_referral = db_referral_get_by_id($user_id); |
87 | 87 | |
88 | 88 | $partner_bonus = floor($new_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) : 0); |
89 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
89 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
90 | 90 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
91 | 91 | } |
92 | 92 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | function rpg_level_up(&$user, $type, $xp_to_add = 0) { |
104 | 104 | $q = 1.03; |
105 | 105 | |
106 | - switch($type) { |
|
106 | + switch ($type) { |
|
107 | 107 | case RPG_STRUCTURE: |
108 | 108 | $field_level = 'lvl_minier'; |
109 | 109 | $field_xp = 'xpminier'; |
@@ -140,17 +140,17 @@ discard block |
||
140 | 140 | |
141 | 141 | $xp = &$user[$field_xp]; |
142 | 142 | |
143 | - if($xp_to_add) { |
|
143 | + if ($xp_to_add) { |
|
144 | 144 | $xp += $xp_to_add; |
145 | 145 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
146 | 146 | } |
147 | 147 | |
148 | 148 | $level = $user[$field_level]; |
149 | - while($xp > rpg_xp_for_level($level + 1, $b1, $q)) { |
|
149 | + while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) { |
|
150 | 150 | $level++; |
151 | 151 | } |
152 | 152 | $level -= $user[$field_level]; |
153 | - if($level > 0) { |
|
153 | + if ($level > 0) { |
|
154 | 154 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
155 | 155 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
156 | 156 | $user[$field_level] += $level; |
@@ -141,6 +141,9 @@ |
||
141 | 141 | "); |
142 | 142 | } |
143 | 143 | |
144 | +/** |
|
145 | + * @param string $email_unsafe |
|
146 | + */ |
|
144 | 147 | function player_create($username_unsafe, $email_unsafe, $options) { |
145 | 148 | sn_db_transaction_check(true); |
146 | 149 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: Gorlum |
|
5 | - * Date: 17.04.2015 |
|
6 | - * Time: 6:37 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: Gorlum |
|
5 | + * Date: 17.04.2015 |
|
6 | + * Time: 6:37 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | function sys_user_vacation($user) { |
10 | 10 | global $config; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | function sys_user_vacation($user) { |
10 | - if(sys_get_param_str('vacation') == 'leave') { |
|
10 | + if (sys_get_param_str('vacation') == 'leave') { |
|
11 | 11 | if ($user['vacation'] < SN_TIME_NOW) { |
12 | 12 | $user['vacation'] = 0; |
13 | 13 | $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | } |
16 | 16 | } |
17 | 17 | |
18 | - if($user['vacation']) { |
|
18 | + if ($user['vacation']) { |
|
19 | 19 | // sn_sys_logout(false, true); |
20 | 20 | // core_auth::logout(false, true); |
21 | 21 | |
@@ -45,33 +45,33 @@ discard block |
||
45 | 45 | // TODO: Full rewrite |
46 | 46 | sn_db_transaction_start(); |
47 | 47 | $TheUser = db_user_by_id($UserID); |
48 | - if ( $TheUser['ally_id'] != 0 ) { |
|
49 | - $TheAlly = doquery ( "SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true ); |
|
48 | + if ($TheUser['ally_id'] != 0) { |
|
49 | + $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true); |
|
50 | 50 | $TheAlly['ally_members'] -= 1; |
51 | - if ( $TheAlly['ally_members'] > 0 ) { |
|
52 | - doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
51 | + if ($TheAlly['ally_members'] > 0) { |
|
52 | + doquery("UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
53 | 53 | } else { |
54 | - doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
55 | - doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';"); |
|
54 | + doquery("DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
55 | + doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';"); |
|
56 | 56 | } |
57 | 57 | } |
58 | - doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';"); |
|
58 | + doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';"); |
|
59 | 59 | |
60 | 60 | db_planet_list_delete_by_owner($UserID); |
61 | 61 | |
62 | - doquery ( "DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';"); |
|
63 | - doquery ( "DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';"); |
|
64 | - doquery ( "DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';"); |
|
62 | + doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';"); |
|
63 | + doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';"); |
|
64 | + doquery("DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';"); |
|
65 | 65 | FleetList::db_fleet_list_delete_by_owner($UserID); |
66 | 66 | // doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner1` = '" . $UserID . "';"); |
67 | 67 | // doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner2` = '" . $UserID . "';"); |
68 | - doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';"); |
|
69 | - doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';"); |
|
70 | - doquery ( "DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';"); |
|
68 | + doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';"); |
|
69 | + doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';"); |
|
70 | + doquery("DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';"); |
|
71 | 71 | |
72 | 72 | |
73 | 73 | classSupernova::db_del_record_by_id(LOC_USER, $UserID); |
74 | - doquery ( "DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');"); |
|
74 | + doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');"); |
|
75 | 75 | classSupernova::$config->db_saveItem('users_amount', classSupernova::$config->db_loadItem('users_amount') - 1); |
76 | 76 | sn_db_transaction_commit(); |
77 | 77 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; |
146 | 146 | |
147 | 147 | $user_new = classSupernova::db_ins_field_set(LOC_USER, $field_set); |
148 | - if(!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
148 | + if (!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
149 | 149 | $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos; |
150 | 150 | $options['system'] = classSupernova::$config->LastSettedSystemPos; |
151 | 151 | $segment_size = floor(classSupernova::$config->game_maxPlanet / 3); |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
155 | 155 | |
156 | 156 | // $new_planet_id = 0; |
157 | - while(true) { |
|
158 | - if($options['planet'] > classSupernova::$config->game_maxPlanet) { |
|
157 | + while (true) { |
|
158 | + if ($options['planet'] > classSupernova::$config->game_maxPlanet) { |
|
159 | 159 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
160 | 160 | $options['system']++; |
161 | 161 | } |
162 | - if($options['system'] > classSupernova::$config->game_maxSystem) { |
|
162 | + if ($options['system'] > classSupernova::$config->game_maxSystem) { |
|
163 | 163 | $options['system'] = 1; |
164 | 164 | $options['galaxy']++; |
165 | 165 | } |
166 | 166 | $options['galaxy'] > classSupernova::$config->game_maxGalaxy ? $options['galaxy'] = 1 : false; |
167 | 167 | |
168 | 168 | $galaxy_row = db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); |
169 | - if(!$galaxy_row['id']) { |
|
169 | + if (!$galaxy_row['id']) { |
|
170 | 170 | classSupernova::$config->db_saveItem(array( |
171 | 171 | 'LastSettedGalaxyPos' => $options['galaxy'], |
172 | 172 | 'LastSettedSystemPos' => $options['system'], |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $username_safe = db_escape($username_unsafe); |
190 | 190 | db_player_name_history_replace($user_new, $username_safe); |
191 | 191 | |
192 | - if(!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
192 | + if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
193 | 193 | db_referral_insert($options, $user_new); |
194 | 194 | } |
195 | 195 |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | +/** |
|
4 | + * @param double $planet_sectors |
|
5 | + */ |
|
3 | 6 | function uni_create_planet_get_density($position_data, $user_row, $planet_sectors) { |
4 | 7 | $density_list = sn_get_groups('planet_density'); |
5 | 8 | $density_min = reset($density_list); |
@@ -253,9 +253,11 @@ |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету |
256 | - if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
256 | + if(!isset($planet_row['id'])) { |
|
257 | + // || $planet_row['id'] != $user['current_planet'] |
|
257 | 258 | { |
258 | 259 | $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id'); |
260 | + } |
|
259 | 261 | // Если текущей планеты не существует - выставляем Столицу |
260 | 262 | if(!isset($planet_row['id'])) { |
261 | 263 | $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id'); |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | |
8 | 8 | $possible_cores = array(); |
9 | 9 | $probability = 0; |
10 | - foreach($density_list as $possible_core_id => $core_data) { |
|
11 | - if(!$core_data[UNIT_PLANET_DENSITY_RARITY]) { |
|
10 | + foreach ($density_list as $possible_core_id => $core_data) { |
|
11 | + if (!$core_data[UNIT_PLANET_DENSITY_RARITY]) { |
|
12 | 12 | continue; |
13 | 13 | } |
14 | 14 | |
15 | - if( |
|
15 | + if ( |
|
16 | 16 | // Core type exists |
17 | 17 | in_array($possible_core_id, $position_data['core_types']) |
18 | 18 | // Limit core type with planet sector count |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | |
34 | 34 | $random = mt_rand(1, $probability); |
35 | 35 | $selected_core = null; |
36 | - foreach($possible_cores as $core_type => $core_info) { |
|
37 | - if($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) { |
|
36 | + foreach ($possible_cores as $core_type => $core_info) { |
|
37 | + if ($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) { |
|
38 | 38 | $selected_core = $core_info; |
39 | 39 | break; |
40 | 40 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | function uni_create_planet($Galaxy, $System, $Position, $PlanetOwnerID, $planet_name_unsafe = '', $HomeWorld = false, $options = array()) { |
58 | 58 | $Position = intval($Position); |
59 | 59 | |
60 | - if(!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) { |
|
60 | + if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | |
67 | 67 | $planet_generator = sn_get_groups('planet_generator'); |
68 | 68 | |
69 | - if($HomeWorld) { |
|
69 | + if ($HomeWorld) { |
|
70 | 70 | $position_data = $planet_generator[0]; |
71 | 71 | } else { |
72 | 72 | $position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position]; |
73 | - if($Position >= UNIVERSE_RANDOM_PLANET_START) { |
|
73 | + if ($Position >= UNIVERSE_RANDOM_PLANET_START) { |
|
74 | 74 | // Корректируем температуру для планеты-странника |
75 | 75 | $position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START); |
76 | 76 | } |
@@ -170,15 +170,15 @@ discard block |
||
170 | 170 | $moon_name = ''; |
171 | 171 | $moon_row = array(); |
172 | 172 | $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id'); |
173 | - if(!$moon['id']) { |
|
173 | + if (!$moon['id']) { |
|
174 | 174 | $moon_planet = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET, true, '`id`, `temp_min`, `temp_max`, `name`, `debris_metal`, `debris_crystal`'); |
175 | 175 | |
176 | - if($moon_planet['id']) { |
|
176 | + if ($moon_planet['id']) { |
|
177 | 177 | $base_storage_size = BASE_STORAGE_SIZE; |
178 | 178 | |
179 | - if(!$moon_chance) { |
|
179 | + if (!$moon_chance) { |
|
180 | 180 | $size = mt_rand(1100, 8999); |
181 | - } elseif($moon_chance <= 100) { |
|
181 | + } elseif ($moon_chance <= 100) { |
|
182 | 182 | $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999); |
183 | 183 | } else { |
184 | 184 | $size = $moon_chance; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | $field_max = ceil($size / 1000); |
196 | 196 | |
197 | - if(isset($options['image']) && $options['image']) { |
|
197 | + if (isset($options['image']) && $options['image']) { |
|
198 | 198 | $moon_image = $options['image']; |
199 | 199 | } else { |
200 | 200 | $moon_image = 'mond'; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'" |
210 | 210 | ); |
211 | 211 | |
212 | - if($update_debris) { |
|
212 | + if ($update_debris) { |
|
213 | 213 | $debris_spent = $moon_chance * 1000000; |
214 | 214 | $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100)); |
215 | 215 | $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent); |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | $planet_row['id'] = $user['current_planet']; |
245 | 245 | |
246 | 246 | // Пытаемся переключить на новую планету |
247 | - if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) { |
|
247 | + if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) { |
|
248 | 248 | $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id'); |
249 | 249 | } else { |
250 | 250 | $planet_row = db_planet_by_id($planet_row['id']); |
251 | 251 | } |
252 | 252 | |
253 | 253 | // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету |
254 | - if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
254 | + if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
|
255 | 255 | { |
256 | 256 | $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id'); |
257 | 257 | // Если текущей планеты не существует - выставляем Столицу |
258 | - if(!isset($planet_row['id'])) { |
|
258 | + if (!isset($planet_row['id'])) { |
|
259 | 259 | $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id'); |
260 | 260 | // Если и столицы не существует - значит что-то очень не так с записью пользователя |
261 | - if(!isset($planet_row['id'])) { |
|
261 | + if (!isset($planet_row['id'])) { |
|
262 | 262 | global $debug; |
263 | 263 | $debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502); |
264 | 264 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | } |
267 | 267 | |
268 | 268 | // Если производилось переключение планеты - делаем запись в юзере |
269 | - if($user['current_planet'] != $planet_row['id']) { |
|
269 | + if ($user['current_planet'] != $planet_row['id']) { |
|
270 | 270 | db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'"); |
271 | 271 | $user['current_planet'] = $planet_row['id']; |
272 | 272 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | function uni_render_planet_full($from, $prefix = '', $html_safe = true, $include_id = false) { |
287 | - if(!$from['id']) { |
|
287 | + if (!$from['id']) { |
|
288 | 288 | $result = classLocale::$lang['sys_planet_expedition']; |
289 | 289 | } else { |
290 | 290 | $from_planet_id = $include_id ? ( |
@@ -335,23 +335,23 @@ discard block |
||
335 | 335 | |
336 | 336 | function uni_planet_teleport_check($user, $planetrow, $new_coordinates = null) { |
337 | 337 | try { |
338 | - if($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { |
|
338 | + if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { |
|
339 | 339 | throw new exception(classLocale::$lang['ov_teleport_err_cooldown'], ERR_ERROR); |
340 | 340 | } |
341 | 341 | |
342 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < classSupernova::$config->planet_teleport_cost) { |
|
342 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < classSupernova::$config->planet_teleport_cost) { |
|
343 | 343 | throw new exception(classLocale::$lang['ov_teleport_err_no_dark_matter'], ERR_ERROR); |
344 | 344 | } |
345 | 345 | |
346 | 346 | // TODO: Replace quick-check with using gathered flying fleet data |
347 | - if(FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) { |
|
347 | + if (FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) { |
|
348 | 348 | throw new exception(classLocale::$lang['ov_teleport_err_fleet'], ERR_ERROR); |
349 | 349 | } |
350 | 350 | |
351 | - if(is_array($new_coordinates)) { |
|
351 | + if (is_array($new_coordinates)) { |
|
352 | 352 | $new_coordinates['planet_type'] = PT_PLANET; |
353 | 353 | $incoming = db_planet_by_vector($new_coordinates, '', true, 'id'); |
354 | - if($incoming['id']) { |
|
354 | + if ($incoming['id']) { |
|
355 | 355 | throw new exception(classLocale::$lang['ov_teleport_err_destination_busy'], ERR_ERROR); |
356 | 356 | } |
357 | 357 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | 'result' => ERR_NONE, |
361 | 361 | 'message' => '', |
362 | 362 | ); |
363 | - } catch(exception $e) { |
|
363 | + } catch (exception $e) { |
|
364 | 364 | $response = array( |
365 | 365 | 'result' => $e->getCode(), |
366 | 366 | 'message' => $e->getMessage(), |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | require_once('general/math.php'); |
12 | 12 | require_once('general_pname.php'); |
13 | 13 | |
14 | +/** |
|
15 | + * @param string $func_name |
|
16 | + */ |
|
14 | 17 | function sn_function_call($func_name, $func_arg = array()) |
15 | 18 | { |
16 | 19 | global $functions; // All data in $functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
@@ -58,6 +61,9 @@ discard block |
||
58 | 61 | |
59 | 62 | // ---------------------------------------------------------------------------------------------------------------- |
60 | 63 | // Fonction de lecture / ecriture / exploitation de templates |
64 | +/** |
|
65 | + * @param string $filename |
|
66 | + */ |
|
61 | 67 | function sys_file_read($filename) |
62 | 68 | { |
63 | 69 | return @file_get_contents($filename); |
@@ -106,7 +112,7 @@ discard block |
||
106 | 112 | /** |
107 | 113 | * Получение курса обмены валюты в серверную валюту |
108 | 114 | * |
109 | - * @param $currency_symbol |
|
115 | + * @param string $currency_symbol |
|
110 | 116 | * |
111 | 117 | * @return float |
112 | 118 | */ |
@@ -143,6 +149,7 @@ discard block |
||
143 | 149 | null - standard result |
144 | 150 | true - return only style class for current params |
145 | 151 | false - return array('text' => $ret, 'class' => $class), where $ret - unstyled |
152 | + * @param boolean $style |
|
146 | 153 | */ |
147 | 154 | |
148 | 155 | function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) |
@@ -262,6 +269,9 @@ discard block |
||
262 | 269 | return preg_replace($ListCensure, '*', $String); |
263 | 270 | } |
264 | 271 | |
272 | +/** |
|
273 | + * @param string $email |
|
274 | + */ |
|
265 | 275 | function is_email($email) { |
266 | 276 | return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)); |
267 | 277 | } |
@@ -298,6 +308,9 @@ discard block |
||
298 | 308 | return floatval(sys_get_param($param_name, $default)); |
299 | 309 | } |
300 | 310 | |
311 | +/** |
|
312 | + * @param string $param_name |
|
313 | + */ |
|
301 | 314 | function sys_get_param_escaped($param_name, $default = '') |
302 | 315 | { |
303 | 316 | return db_escape(sys_get_param($param_name, $default)); |
@@ -542,6 +555,9 @@ discard block |
||
542 | 555 | } |
543 | 556 | |
544 | 557 | // Generates random string of $length symbols from $allowed_chars charset |
558 | +/** |
|
559 | + * @param string $allowed_chars |
|
560 | + */ |
|
545 | 561 | function sys_random_string($length = 16, $allowed_chars = SN_SYS_SEC_CHARS_ALLOWED) { |
546 | 562 | $allowed_length = strlen($allowed_chars); |
547 | 563 | |
@@ -667,6 +683,9 @@ discard block |
||
667 | 683 | return implode(';', $fleet_string); |
668 | 684 | } |
669 | 685 | |
686 | +/** |
|
687 | + * @param string $body |
|
688 | + */ |
|
670 | 689 | function mymail($email_unsafe, $title, $body, $from = '', $html = false) { |
671 | 690 | global $config, $lang; |
672 | 691 | |
@@ -954,6 +973,9 @@ discard block |
||
954 | 973 | return serialize($nick_array); |
955 | 974 | } |
956 | 975 | |
976 | +/** |
|
977 | + * @param string $nick_string |
|
978 | + */ |
|
957 | 979 | function player_nick_uncompact($nick_string) { |
958 | 980 | try { |
959 | 981 | $result = unserialize($nick_string); |
@@ -1237,6 +1259,9 @@ discard block |
||
1237 | 1259 | return $ranks; |
1238 | 1260 | } |
1239 | 1261 | |
1262 | +/** |
|
1263 | + * @param boolean $planet_id |
|
1264 | + */ |
|
1240 | 1265 | function sys_player_new_adjust($user_id, $planet_id){return sn_function_call('sys_player_new_adjust', array($user_id, $planet_id, &$result));} |
1241 | 1266 | function sn_sys_player_new_adjust($user_id, $planet_id, &$result) { |
1242 | 1267 | return $result; |
@@ -1589,6 +1614,9 @@ discard block |
||
1589 | 1614 | return version_compare(sn_version_compare_extra($ver1), sn_version_compare_extra($ver2)); |
1590 | 1615 | } |
1591 | 1616 | |
1617 | +/** |
|
1618 | + * @param string $name |
|
1619 | + */ |
|
1592 | 1620 | function sn_setcookie($name, $value = null, $expire = null, $path = SN_ROOT_RELATIVE, $domain = null, $secure = null, $httponly = null) { |
1593 | 1621 | $_COOKIE[$name] = $value; |
1594 | 1622 | return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); |
@@ -14,24 +14,24 @@ discard block |
||
14 | 14 | function sn_function_call($func_name, $func_arg = array()) { |
15 | 15 | // All data in classSupernova::$functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
16 | 16 | |
17 | - if(is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) { |
|
17 | + if (is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) { |
|
18 | 18 | // Chain-callable functions should be made as following: |
19 | 19 | // 1. Never use incomplete calls with parameters "by default" |
20 | 20 | // 2. Reserve last parameter for cumulative result |
21 | 21 | // 3. Use same format for original value and cumulative result (if there is original value) |
22 | 22 | // 4. Honor cumulative result |
23 | 23 | // 5. Return cumulative result |
24 | - foreach(classSupernova::$functions[$func_name] as $func_chain_name) { |
|
24 | + foreach (classSupernova::$functions[$func_name] as $func_chain_name) { |
|
25 | 25 | // По идее - это уже тут не нужно, потому что оно все должно быть callable к этому моменту |
26 | 26 | // Но для старых модулей... |
27 | - if(is_callable($func_chain_name)) { |
|
27 | + if (is_callable($func_chain_name)) { |
|
28 | 28 | $result = call_user_func_array($func_chain_name, $func_arg); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } else { |
32 | 32 | // TODO: This is left for backward compatibility. Appropriate code should be rewrote! |
33 | 33 | $func_name = isset(classSupernova::$functions[$func_name]) && is_callable(classSupernova::$functions[$func_name]) ? classSupernova::$functions[$func_name] : ('sn_' . $func_name); |
34 | - if(is_callable($func_name)) { |
|
34 | + if (is_callable($func_name)) { |
|
35 | 35 | $result = call_user_func_array($func_name, $func_arg); |
36 | 36 | } |
37 | 37 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param string $page_name - имя страницы, для которого должен был быть выполнен хук |
47 | 47 | */ |
48 | 48 | function execute_hooks(&$hook_list, &$template, $hook_type = null, $page_name = null) { |
49 | - if(!empty($hook_list)) { |
|
50 | - foreach($hook_list as $hook) { |
|
51 | - if(is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
49 | + if (!empty($hook_list)) { |
|
50 | + foreach ($hook_list as $hook) { |
|
51 | + if (is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
52 | 52 | $template = call_user_func($hook_call, $template, $hook_type, $page_name); |
53 | 53 | } |
54 | 54 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) { |
140 | 140 | $n = floatval($n); |
141 | - if(is_int($floor)) { |
|
141 | + if (is_int($floor)) { |
|
142 | 142 | $n = round($n, $floor); // , PHP_ROUND_HALF_DOWN |
143 | - } elseif($floor === true) { |
|
143 | + } elseif ($floor === true) { |
|
144 | 144 | $n = floor($n); |
145 | 145 | $floor = 0; |
146 | 146 | } else { |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | $ret = $n; |
151 | 151 | |
152 | 152 | $suffix = ''; |
153 | - if($limit) { |
|
154 | - if($ret > 0) { |
|
155 | - while($ret > $limit) { |
|
153 | + if ($limit) { |
|
154 | + if ($ret > 0) { |
|
155 | + while ($ret > $limit) { |
|
156 | 156 | $suffix .= 'k'; |
157 | 157 | $ret = round($ret / 1000); |
158 | 158 | } |
159 | 159 | } else { |
160 | - while($ret < -$limit) { |
|
160 | + while ($ret < -$limit) { |
|
161 | 161 | $suffix .= 'k'; |
162 | 162 | $ret = round($ret / 1000); |
163 | 163 | } |
@@ -167,16 +167,16 @@ discard block |
||
167 | 167 | $ret = number_format($ret, $floor, ',', '.'); |
168 | 168 | $ret .= $suffix; |
169 | 169 | |
170 | - if($color !== false) { |
|
171 | - if($color === true) { |
|
170 | + if ($color !== false) { |
|
171 | + if ($color === true) { |
|
172 | 172 | $class = $n == 0 ? 'zero' : ($n > 0 ? 'positive' : 'negative'); |
173 | - } elseif($color >= 0) { |
|
173 | + } elseif ($color >= 0) { |
|
174 | 174 | $class = $n == $color ? 'zero' : ($n < $color ? 'positive' : 'negative'); |
175 | 175 | } else { |
176 | 176 | $class = ($n == -$color) ? 'zero' : ($n < -$color ? 'negative' : 'positive'); |
177 | 177 | } |
178 | 178 | |
179 | - if(!isset($style)) { |
|
179 | + if (!isset($style)) { |
|
180 | 180 | $ret = "<span class='{$class}'>{$ret}</span>"; |
181 | 181 | } else { |
182 | 182 | $ret = $style ? $ret = $class : $ret = array('text' => $ret, 'class' => $class); |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | |
302 | 302 | function sys_get_param_phone($param_name, $default = '') { |
303 | 303 | $phone_raw = sys_get_param_str_unsafe($param_name, $default = ''); |
304 | - if($phone_raw) { |
|
304 | + if ($phone_raw) { |
|
305 | 305 | $phone = $phone_raw[0] == '+' ? '+' : ''; |
306 | - for($i = 0; $i < strlen($phone_raw); $i++) { |
|
306 | + for ($i = 0; $i < strlen($phone_raw); $i++) { |
|
307 | 307 | $ord = ord($phone_raw[$i]); |
308 | - if($ord >= 48 && $ord <= 57) { |
|
308 | + if ($ord >= 48 && $ord <= 57) { |
|
309 | 309 | $phone .= $phone_raw[$i]; |
310 | 310 | } |
311 | 311 | } |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | function CheckAbandonPlanetState(&$planet) { |
325 | - if($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
325 | + if ($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
326 | 326 | db_planet_delete_by_id($planet['id']); |
327 | 327 | } |
328 | 328 | } |
329 | 329 | |
330 | 330 | function eco_get_total_cost($unit_id, $unit_level) { |
331 | 331 | static $rate, $sn_group_resources_all, $sn_group_resources_loot; |
332 | - if(!$rate) { |
|
332 | + if (!$rate) { |
|
333 | 333 | $sn_group_resources_all = sn_get_groups('resources_all'); |
334 | 334 | $sn_group_resources_loot = sn_get_groups('resources_loot'); |
335 | 335 | |
@@ -339,19 +339,19 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | $unit_cost_data = get_unit_param($unit_id, 'cost'); |
342 | - if(!is_array($unit_cost_data)) { |
|
342 | + if (!is_array($unit_cost_data)) { |
|
343 | 343 | return array('total' => 0); |
344 | 344 | } |
345 | 345 | $factor = isset($unit_cost_data['factor']) ? $unit_cost_data['factor'] : 1; |
346 | 346 | $cost_array = array(BUILD_CREATE => array(), 'total' => 0); |
347 | 347 | $unit_level = $unit_level > 0 ? $unit_level : 0; |
348 | - foreach($unit_cost_data as $resource_id => $resource_amount) { |
|
349 | - if(!in_array($resource_id, $sn_group_resources_all)) { |
|
348 | + foreach ($unit_cost_data as $resource_id => $resource_amount) { |
|
349 | + if (!in_array($resource_id, $sn_group_resources_all)) { |
|
350 | 350 | continue; |
351 | 351 | } |
352 | 352 | // $cost_array[BUILD_CREATE][$resource_id] = $resource_amount * ($factor == 1 ? $unit_level : ((pow($factor, $unit_level) - $factor) / ($factor - 1))); |
353 | 353 | $cost_array[BUILD_CREATE][$resource_id] = round($resource_amount * ($factor == 1 ? $unit_level : ((1 - pow($factor, $unit_level)) / (1 - $factor)))); |
354 | - if(in_array($resource_id, $sn_group_resources_loot)) { |
|
354 | + if (in_array($resource_id, $sn_group_resources_loot)) { |
|
355 | 355 | $cost_array['total'] += $cost_array[BUILD_CREATE][$resource_id] * $rate[$resource_id]; |
356 | 356 | } |
357 | 357 | } |
@@ -435,19 +435,19 @@ discard block |
||
435 | 435 | $mercenary_level = 0; |
436 | 436 | $unit_db_name = pname_resource_name($unit_id); |
437 | 437 | |
438 | - if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
438 | + if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
439 | 439 | $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id); |
440 | 440 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
441 | - } elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
441 | + } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
442 | 442 | $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id); |
443 | 443 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
444 | - } elseif(in_array($unit_id, sn_get_groups('governors'))) { |
|
444 | + } elseif (in_array($unit_id, sn_get_groups('governors'))) { |
|
445 | 445 | $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0; |
446 | - } elseif($unit_id == RES_DARK_MATTER) { |
|
446 | + } elseif ($unit_id == RES_DARK_MATTER) { |
|
447 | 447 | $mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter); |
448 | - } elseif($unit_id == RES_METAMATTER) { |
|
448 | + } elseif ($unit_id == RES_METAMATTER) { |
|
449 | 449 | $mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name]; |
450 | - } elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
450 | + } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
451 | 451 | $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name]; |
452 | 452 | } |
453 | 453 | |
@@ -457,19 +457,19 @@ discard block |
||
457 | 457 | function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) { return sn_function_call(__FUNCTION__, array(&$user, $planet, $mercenaries, $value)); } |
458 | 458 | |
459 | 459 | function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) { |
460 | - if(!is_array($mercenaries)) { |
|
460 | + if (!is_array($mercenaries)) { |
|
461 | 461 | $mercenaries = array($mercenaries); |
462 | 462 | } |
463 | 463 | |
464 | 464 | $base_value = isset($base_value) ? $base_value : $value; |
465 | 465 | |
466 | - foreach($mercenaries as $mercenary_id) { |
|
466 | + foreach ($mercenaries as $mercenary_id) { |
|
467 | 467 | $mercenary_level = mrc_get_level($user, $planet, $mercenary_id); |
468 | 468 | |
469 | 469 | $mercenary = get_unit_param($mercenary_id); |
470 | 470 | $mercenary_bonus = $mercenary['bonus']; |
471 | 471 | |
472 | - switch($mercenary['bonus_type']) { |
|
472 | + switch ($mercenary['bonus_type']) { |
|
473 | 473 | case BONUS_PERCENT_CUMULATIVE: |
474 | 474 | $value *= 1 + $mercenary_level * $mercenary_bonus / 100; |
475 | 475 | break; |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $allowed_length = strlen($allowed_chars); |
501 | 501 | |
502 | 502 | $random_string = ''; |
503 | - for($i = 0; $i < $length; $i++) { |
|
503 | + for ($i = 0; $i < $length; $i++) { |
|
504 | 504 | $random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)]; |
505 | 505 | } |
506 | 506 | |
@@ -520,12 +520,12 @@ discard block |
||
520 | 520 | |
521 | 521 | $options = ''; |
522 | 522 | $option_list = array(); |
523 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
523 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
524 | 524 | $option_list[$option_group_id] = array(); |
525 | - foreach($option_group as $option_name => $option_value) { |
|
526 | - if(!isset($user[$option_name])) { |
|
525 | + foreach ($option_group as $option_name => $option_value) { |
|
526 | + if (!isset($user[$option_name])) { |
|
527 | 527 | $user[$option_name] = $option_value; |
528 | - } elseif($user[$option_name] == '') { |
|
528 | + } elseif ($user[$option_name] == '') { |
|
529 | 529 | $user[$option_name] = 0; |
530 | 530 | } |
531 | 531 | $options .= "{$option_name}^{$user[$option_name]}|"; |
@@ -545,16 +545,16 @@ discard block |
||
545 | 545 | $option_list = array(); |
546 | 546 | $option_string_list = explode('|', $user['options']); |
547 | 547 | |
548 | - foreach($option_string_list as $option_string) { |
|
548 | + foreach ($option_string_list as $option_string) { |
|
549 | 549 | list($option_name, $option_value) = explode('^', $option_string); |
550 | 550 | $option_list[$option_name] = $option_value; |
551 | 551 | } |
552 | 552 | |
553 | 553 | $final_list = array(); |
554 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
554 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
555 | 555 | $final_list[$option_group_id] = array(); |
556 | - foreach($option_group as $option_name => $option_value) { |
|
557 | - if(!isset($option_list[$option_name])) { |
|
556 | + foreach ($option_group as $option_name => $option_value) { |
|
557 | + if (!isset($option_list[$option_name])) { |
|
558 | 558 | $option_list[$option_name] = $option_value; |
559 | 559 | } |
560 | 560 | $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name]; |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | |
569 | 569 | function sys_unit_str2arr($fleet_string) { |
570 | 570 | $fleet_array = array(); |
571 | - if(!empty($fleet_string)) { |
|
571 | + if (!empty($fleet_string)) { |
|
572 | 572 | $arrTemp = explode(';', $fleet_string); |
573 | - foreach($arrTemp as $temp) { |
|
574 | - if($temp) { |
|
573 | + foreach ($arrTemp as $temp) { |
|
574 | + if ($temp) { |
|
575 | 575 | $temp = explode(',', $temp); |
576 | - if(!empty($temp[0]) && !empty($temp[1])) { |
|
576 | + if (!empty($temp[0]) && !empty($temp[1])) { |
|
577 | 577 | $fleet_array[$temp[0]] += $temp[1]; |
578 | 578 | } |
579 | 579 | } |
@@ -585,13 +585,13 @@ discard block |
||
585 | 585 | |
586 | 586 | function sys_unit_arr2str($unit_list) { |
587 | 587 | $fleet_string = array(); |
588 | - if(isset($unit_list)) { |
|
589 | - if(!is_array($unit_list)) { |
|
588 | + if (isset($unit_list)) { |
|
589 | + if (!is_array($unit_list)) { |
|
590 | 590 | $unit_list = array($unit_list => 1); |
591 | 591 | } |
592 | 592 | |
593 | - foreach($unit_list as $unit_id => $unit_count) { |
|
594 | - if($unit_id && $unit_count) { |
|
593 | + foreach ($unit_list as $unit_id => $unit_count) { |
|
594 | + if ($unit_id && $unit_count) { |
|
595 | 595 | $fleet_string[] = "{$unit_id},{$unit_count}"; |
596 | 596 | } |
597 | 597 | } |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | $body = str_replace("\r\n", "\n", $body); |
618 | 618 | $body = str_replace("\n", "\r\n", $body); |
619 | 619 | |
620 | - if($html) { |
|
620 | + if ($html) { |
|
621 | 621 | $body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>'; |
622 | 622 | } |
623 | 623 | |
@@ -661,21 +661,21 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | function sn_ali_fill_user_ally(&$user) { |
664 | - if(!$user['ally_id']) { |
|
664 | + if (!$user['ally_id']) { |
|
665 | 665 | return; |
666 | 666 | } |
667 | 667 | |
668 | - if(!isset($user['ally'])) { |
|
668 | + if (!isset($user['ally'])) { |
|
669 | 669 | $user['ally'] = db_ally_get_by_id($user['ally_id']); |
670 | 670 | } |
671 | 671 | |
672 | - if(!isset($user['ally']['player'])) { |
|
672 | + if (!isset($user['ally']['player'])) { |
|
673 | 673 | $user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false); |
674 | 674 | } |
675 | 675 | } |
676 | 676 | |
677 | 677 | function sn_get_url_contents($url) { |
678 | - if(function_exists('curl_init')) { |
|
678 | + if (function_exists('curl_init')) { |
|
679 | 679 | $crl = curl_init(); |
680 | 680 | $timeout = 5; |
681 | 681 | curl_setopt($crl, CURLOPT_URL, $url); |
@@ -710,10 +710,10 @@ discard block |
||
710 | 710 | |
711 | 711 | function get_ship_data($ship_id, $user) { |
712 | 712 | $ship_data = array(); |
713 | - if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
714 | - foreach(get_unit_param($ship_id, 'engine') as $engine_info) { |
|
713 | + if (in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
714 | + foreach (get_unit_param($ship_id, 'engine') as $engine_info) { |
|
715 | 715 | $tech_level = intval(mrc_get_level($user, null, $engine_info['tech'])); |
716 | - if(empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
716 | + if (empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
717 | 717 | $ship_data = $engine_info; |
718 | 718 | $ship_data['tech_level'] = $tech_level; |
719 | 719 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | return $ship_data; |
726 | 726 | } |
727 | 727 | |
728 | -if(!function_exists('strptime')) { |
|
728 | +if (!function_exists('strptime')) { |
|
729 | 729 | function strptime($date, $format) { |
730 | 730 | $masks = array( |
731 | 731 | '%d' => '(?P<d>[0-9]{2})', |
@@ -738,12 +738,12 @@ discard block |
||
738 | 738 | ); |
739 | 739 | |
740 | 740 | $rexep = "#" . strtr(preg_quote($format), $masks) . "#"; |
741 | - if(preg_match($rexep, $date, $out)) { |
|
741 | + if (preg_match($rexep, $date, $out)) { |
|
742 | 742 | $ret = array( |
743 | - "tm_sec" => (int)$out['S'], |
|
744 | - "tm_min" => (int)$out['M'], |
|
745 | - "tm_hour" => (int)$out['H'], |
|
746 | - "tm_mday" => (int)$out['d'], |
|
743 | + "tm_sec" => (int) $out['S'], |
|
744 | + "tm_min" => (int) $out['M'], |
|
745 | + "tm_hour" => (int) $out['H'], |
|
746 | + "tm_mday" => (int) $out['d'], |
|
747 | 747 | "tm_mon" => $out['m'] ? $out['m'] - 1 : 0, |
748 | 748 | "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0, |
749 | 749 | ); |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | function sn_sys_sector_buy($redirect = 'overview.php') { |
759 | 759 | global $user, $planetrow; |
760 | 760 | |
761 | - if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
761 | + if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
762 | 762 | return; |
763 | 763 | } |
764 | 764 | |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | // $planetrow = $planetrow['planet']; |
772 | 772 | $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); |
773 | 773 | $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; |
774 | - if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
774 | + if ($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
775 | 775 | $planet_name_text = uni_render_planet($planetrow); |
776 | - if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'], |
|
776 | + if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'], |
|
777 | 777 | $user['username'], $user['id'], $planet_name_text, classLocale::$lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost) |
778 | 778 | )) { |
779 | 779 | $sector_db_name = pname_resource_name(UNIT_SECTOR); |
@@ -788,30 +788,30 @@ discard block |
||
788 | 788 | } |
789 | 789 | |
790 | 790 | function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') { |
791 | - if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
792 | - foreach($handler_list as $function_name => $function_data) { |
|
793 | - if(is_string($function_data)) { |
|
791 | + if (isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
792 | + foreach ($handler_list as $function_name => $function_data) { |
|
793 | + if (is_string($function_data)) { |
|
794 | 794 | $override_with = &$function_data; |
795 | - } elseif(isset($function_data['callable'])) { |
|
795 | + } elseif (isset($function_data['callable'])) { |
|
796 | 796 | $override_with = &$function_data['callable']; |
797 | 797 | } |
798 | 798 | |
799 | 799 | $overwrite = $override_with[0] == '*'; |
800 | - if($overwrite) { |
|
800 | + if ($overwrite) { |
|
801 | 801 | $override_with = substr($override_with, 1); |
802 | 802 | } |
803 | 803 | |
804 | - if(($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
804 | + if (($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
805 | 805 | $override_with = array($class_module_name, $override_with); |
806 | - } elseif($point_position == 0) { |
|
806 | + } elseif ($point_position == 0) { |
|
807 | 807 | $override_with = substr($override_with, 1); |
808 | - } elseif($point_position > 0) { |
|
808 | + } elseif ($point_position > 0) { |
|
809 | 809 | $override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1)); |
810 | 810 | } |
811 | 811 | |
812 | - if($overwrite) { |
|
812 | + if ($overwrite) { |
|
813 | 813 | $functions[$function_name] = array(); |
814 | - } elseif(!isset($functions[$function_name])) { |
|
814 | + } elseif (!isset($functions[$function_name])) { |
|
815 | 815 | $functions[$function_name] = array(); |
816 | 816 | $sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : ''); |
817 | 817 | $functions[$function_name][] = $sn_function_name; |
@@ -827,15 +827,15 @@ discard block |
||
827 | 827 | function player_nick_render_to_html($result, $options = false) { |
828 | 828 | // TODO - обрабатывать разные случаи: $user, $render_nick_array, $string |
829 | 829 | |
830 | - if(is_string($result) && strpos($result, ':{i:')) { |
|
830 | + if (is_string($result) && strpos($result, ':{i:')) { |
|
831 | 831 | $result = player_nick_uncompact($result); |
832 | 832 | } |
833 | 833 | |
834 | - if(is_array($result)) { |
|
835 | - if(isset($result['id'])) { |
|
834 | + if (is_array($result)) { |
|
835 | + if (isset($result['id'])) { |
|
836 | 836 | $result = player_nick_render_current_to_array($result, $options); |
837 | 837 | } |
838 | - if(!isset($result[NICK_HTML])) { |
|
838 | + if (!isset($result[NICK_HTML])) { |
|
839 | 839 | $result = player_nick_render_array_to_html($result); |
840 | 840 | } |
841 | 841 | unset($result[NICK_HTML]); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | try { |
859 | 859 | $result = unserialize($nick_string); |
860 | 860 | // ksort($result); // Всегда ksort-ый в player_nick_compact() |
861 | - } catch(exception $e) { |
|
861 | + } catch (exception $e) { |
|
862 | 862 | $result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example |
863 | 863 | } |
864 | 864 | |
@@ -871,20 +871,20 @@ discard block |
||
871 | 871 | global $user; |
872 | 872 | |
873 | 873 | // ALL STRING ARE UNSAFE!!! |
874 | - if(isset($nick_array[NICK_BIRTHSDAY])) { |
|
874 | + if (isset($nick_array[NICK_BIRTHSDAY])) { |
|
875 | 875 | $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />'; |
876 | 876 | } |
877 | 877 | |
878 | - if(isset($nick_array[NICK_VACATION])) { |
|
878 | + if (isset($nick_array[NICK_VACATION])) { |
|
879 | 879 | $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />'; |
880 | 880 | } |
881 | 881 | |
882 | - if(isset($nick_array[NICK_GENDER])) { |
|
882 | + if (isset($nick_array[NICK_GENDER])) { |
|
883 | 883 | $result[NICK_GENDER] = '<img src="' . ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />'; |
884 | 884 | } |
885 | 885 | |
886 | - if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
887 | - switch($nick_array[NICK_AUTH_LEVEL]) { |
|
886 | + if (isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
887 | + switch ($nick_array[NICK_AUTH_LEVEL]) { |
|
888 | 888 | case 4: |
889 | 889 | $highlight = classSupernova::$config->chat_highlight_developer; |
890 | 890 | break; |
@@ -905,20 +905,20 @@ discard block |
||
905 | 905 | $highlight = isset($nick_array[NICK_PREMIUM]) ? classSupernova::$config->chat_highlight_premium : ''; |
906 | 906 | } |
907 | 907 | |
908 | - if($highlight) { |
|
908 | + if ($highlight) { |
|
909 | 909 | list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight); |
910 | 910 | } |
911 | 911 | // $result = preg_replace("#(.+)#", $highlight, $result); |
912 | 912 | } |
913 | 913 | |
914 | - if(isset($nick_array[NICK_CLASS])) { |
|
914 | + if (isset($nick_array[NICK_CLASS])) { |
|
915 | 915 | $result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>'; |
916 | 916 | $result[NICK_CLASS_END] = '</span>'; |
917 | 917 | } |
918 | 918 | |
919 | 919 | $result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]); |
920 | 920 | |
921 | - if(isset($nick_array[NICK_ALLY])) { |
|
921 | + if (isset($nick_array[NICK_ALLY])) { |
|
922 | 922 | $result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']'; |
923 | 923 | } |
924 | 924 | |
@@ -942,32 +942,32 @@ discard block |
||
942 | 942 | */ |
943 | 943 | |
944 | 944 | |
945 | - if($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
945 | + if ($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
946 | 946 | $result[NICK_BIRTHSDAY] = ''; |
947 | 947 | } |
948 | 948 | |
949 | - if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
949 | + if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
950 | 950 | $result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male'); |
951 | 951 | } |
952 | 952 | |
953 | - if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
953 | + if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
954 | 954 | $result[NICK_VACATION] = $render_user['vacation']; |
955 | 955 | } |
956 | 956 | |
957 | - if($options === true || (isset($options['color']) && $options['color'])) { |
|
958 | - if($user_auth_level = $render_user['authlevel']) { |
|
957 | + if ($options === true || (isset($options['color']) && $options['color'])) { |
|
958 | + if ($user_auth_level = $render_user['authlevel']) { |
|
959 | 959 | $result[NICK_AUTH_LEVEL] = $user_auth_level; |
960 | 960 | } |
961 | - if($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) { |
|
961 | + if ($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) { |
|
962 | 962 | $result[NICK_PREMIUM] = $user_premium; |
963 | 963 | } |
964 | 964 | } |
965 | 965 | |
966 | - if((isset($options['class']) && $options['class'])) { |
|
966 | + if ((isset($options['class']) && $options['class'])) { |
|
967 | 967 | $result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class']; |
968 | 968 | } |
969 | 969 | |
970 | - if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
970 | + if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
971 | 971 | $result[NICK_ALLY] = $render_user['ally_tag']; |
972 | 972 | } |
973 | 973 | |
@@ -983,25 +983,25 @@ discard block |
||
983 | 983 | |
984 | 984 | $user_skip_list = array(); |
985 | 985 | |
986 | - if(classSupernova::$config->stats_hide_admins) { |
|
986 | + if (classSupernova::$config->stats_hide_admins) { |
|
987 | 987 | $user_skip_list[] = '`authlevel` > 0'; |
988 | 988 | } |
989 | 989 | |
990 | - if(classSupernova::$config->stats_hide_player_list) { |
|
990 | + if (classSupernova::$config->stats_hide_player_list) { |
|
991 | 991 | $temp = explode(',', classSupernova::$config->stats_hide_player_list); |
992 | - foreach($temp as $user_id) { |
|
992 | + foreach ($temp as $user_id) { |
|
993 | 993 | $user_id = floatval($user_id); |
994 | - if($user_id) { |
|
994 | + if ($user_id) { |
|
995 | 995 | $user_skip_list[] = '`id` = ' . $user_id; |
996 | 996 | } |
997 | 997 | } |
998 | 998 | } |
999 | 999 | |
1000 | - if(!empty($user_skip_list)) { |
|
1000 | + if (!empty($user_skip_list)) { |
|
1001 | 1001 | $user_skip_list = implode(' OR ', $user_skip_list); |
1002 | 1002 | $user_skip_query = db_user_list($user_skip_list); |
1003 | - if(!empty($user_skip_query)) { |
|
1004 | - foreach($user_skip_query as $user_skip_row) { |
|
1003 | + if (!empty($user_skip_query)) { |
|
1004 | + foreach ($user_skip_query as $user_skip_row) { |
|
1005 | 1005 | $result[$user_skip_row['id']] = $user_skip_row['id']; |
1006 | 1006 | } |
1007 | 1007 | } |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | |
1033 | 1033 | function sn_sn_get_groups($groups, &$result) { |
1034 | 1034 | $result = is_array($result) ? $result : array(); |
1035 | - foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
1035 | + foreach ($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
1036 | 1036 | $result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array(); |
1037 | 1037 | } |
1038 | 1038 | |
@@ -1058,8 +1058,8 @@ discard block |
||
1058 | 1058 | $sn_data_unit = get_unit_param($unit_id); |
1059 | 1059 | |
1060 | 1060 | $result = is_array($result) ? $result : array(); |
1061 | - if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && classSupernova::$config->empire_mercenary_temporary)) { |
|
1062 | - foreach($sn_data_unit[$field] as $require_id => $require_level) { |
|
1061 | + if ($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && classSupernova::$config->empire_mercenary_temporary)) { |
|
1062 | + foreach ($sn_data_unit[$field] as $require_id => $require_level) { |
|
1063 | 1063 | $level_got = mrc_get_level($user, $planetrow, $require_id); |
1064 | 1064 | $level_basic = mrc_get_level($user, $planetrow, $require_id, false, true); |
1065 | 1065 | $result[] = array( |
@@ -1083,16 +1083,16 @@ discard block |
||
1083 | 1083 | |
1084 | 1084 | $ranks = array(); |
1085 | 1085 | |
1086 | - if($ally['ranklist']) { |
|
1086 | + if ($ally['ranklist']) { |
|
1087 | 1087 | $str_ranks = explode(';', $ally['ranklist']); |
1088 | - foreach($str_ranks as $str_rank) { |
|
1089 | - if(!$str_rank) { |
|
1088 | + foreach ($str_ranks as $str_rank) { |
|
1089 | + if (!$str_rank) { |
|
1090 | 1090 | continue; |
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | $tmp = explode(',', $str_rank); |
1094 | 1094 | $rank_id = count($ranks); |
1095 | - foreach($ally_rights as $key => $value) { |
|
1095 | + foreach ($ally_rights as $key => $value) { |
|
1096 | 1096 | $ranks[$rank_id][$value] = $tmp[$key]; |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | function array_merge_recursive_numeric($array1, $array2) { |
1111 | - if(!empty($array2) && is_array($array2)) { |
|
1112 | - foreach($array2 as $key => $value) { |
|
1111 | + if (!empty($array2) && is_array($array2)) { |
|
1112 | + foreach ($array2 as $key => $value) { |
|
1113 | 1113 | // if(!isset($array1[$key]) || !is_array($array1[$key])) { |
1114 | 1114 | // $array1[$key] = $value; |
1115 | 1115 | // } else { |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | function sn_sys_array_cumulative_sum(&$array) { |
1126 | 1126 | $accum = 0; |
1127 | - foreach($array as &$value) { |
|
1127 | + foreach ($array as &$value) { |
|
1128 | 1128 | $accum += $value; |
1129 | 1129 | $value = $accum; |
1130 | 1130 | } |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | $sn_data_density = sn_get_groups('planet_density'); |
1135 | 1135 | $density_price_chart = array(); |
1136 | 1136 | |
1137 | - foreach($sn_data_density as $density_id => $density_data) { |
|
1137 | + foreach ($sn_data_density as $density_id => $density_data) { |
|
1138 | 1138 | // Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра |
1139 | 1139 | $density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false; |
1140 | 1140 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | |
1143 | 1143 | $total_rarity = array_sum($density_price_chart); |
1144 | 1144 | |
1145 | - foreach($density_price_chart as &$density_data) { |
|
1145 | + foreach ($density_price_chart as &$density_data) { |
|
1146 | 1146 | $density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE); |
1147 | 1147 | } |
1148 | 1148 | |
@@ -1150,16 +1150,16 @@ discard block |
||
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | function sn_sys_planet_core_transmute(&$user, &$planetrow) { |
1153 | - if(!sys_get_param_str('transmute')) { |
|
1153 | + if (!sys_get_param_str('transmute')) { |
|
1154 | 1154 | return array(); |
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | try { |
1158 | - if($planetrow['planet_type'] != PT_PLANET) { |
|
1158 | + if ($planetrow['planet_type'] != PT_PLANET) { |
|
1159 | 1159 | throw new exception(classLocale::$lang['ov_core_err_not_a_planet'], ERR_ERROR); |
1160 | 1160 | } |
1161 | 1161 | |
1162 | - if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
1162 | + if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
1163 | 1163 | throw new exception(classLocale::$lang['ov_core_err_same_density'], ERR_WARNING); |
1164 | 1164 | } |
1165 | 1165 | |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | $planet_density_index = $planetrow['density_index']; |
1174 | 1174 | |
1175 | 1175 | $density_price_chart = planet_density_price_chart($planetrow); |
1176 | - if(!isset($density_price_chart[$new_density_index])) { |
|
1176 | + if (!isset($density_price_chart[$new_density_index])) { |
|
1177 | 1177 | // Hack attempt |
1178 | 1178 | throw new exception(classLocale::$lang['ov_core_err_denisty_type_wrong'], ERR_ERROR); |
1179 | 1179 | } |
@@ -1182,13 +1182,13 @@ discard block |
||
1182 | 1182 | // $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost'); |
1183 | 1183 | // $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index]; |
1184 | 1184 | $transmute_cost = $density_price_chart[$new_density_index]; |
1185 | - if($user_dark_matter < $transmute_cost) { |
|
1185 | + if ($user_dark_matter < $transmute_cost) { |
|
1186 | 1186 | throw new exception(classLocale::$lang['ov_core_err_no_dark_matter'], ERR_ERROR); |
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | $sn_data_planet_density = sn_get_groups('planet_density'); |
1190 | - foreach($sn_data_planet_density as $key => $value) { |
|
1191 | - if($key == $new_density_index) { |
|
1190 | + foreach ($sn_data_planet_density as $key => $value) { |
|
1191 | + if ($key == $new_density_index) { |
|
1192 | 1192 | break; |
1193 | 1193 | } |
1194 | 1194 | $prev_density_index = $key; |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | 'STATUS' => ERR_NONE, |
1220 | 1220 | 'MESSAGE' => sprintf(classLocale::$lang['ov_core_err_none'], classLocale::$lang['uni_planet_density_types'][$planet_density_index], classLocale::$lang['uni_planet_density_types'][$new_density_index], $new_density), |
1221 | 1221 | ); |
1222 | - } catch(exception $e) { |
|
1222 | + } catch (exception $e) { |
|
1223 | 1223 | sn_db_transaction_rollback(); |
1224 | 1224 | $result = array( |
1225 | 1225 | 'STATUS' => $e->getCode(), |
@@ -1232,8 +1232,8 @@ discard block |
||
1232 | 1232 | |
1233 | 1233 | function sn_module_get_active_count($group = '*') { |
1234 | 1234 | $active_modules = 0; |
1235 | - if(isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) { |
|
1236 | - foreach(sn_module::$sn_module_list[$group] as $payment_module) { |
|
1235 | + if (isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) { |
|
1236 | + foreach (sn_module::$sn_module_list[$group] as $payment_module) { |
|
1237 | 1237 | $active_modules += $payment_module->manifest['active']; |
1238 | 1238 | } |
1239 | 1239 | } |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | function get_resource_exchange() { |
1245 | 1245 | static $rates; |
1246 | 1246 | |
1247 | - if(!$rates) { |
|
1247 | + if (!$rates) { |
|
1248 | 1248 | $rates = array( |
1249 | 1249 | RES_METAL => 'rpg_exchange_metal', |
1250 | 1250 | RES_CRYSTAL => 'rpg_exchange_crystal', |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | RES_DARK_MATTER => 'rpg_exchange_darkMatter', |
1253 | 1253 | ); |
1254 | 1254 | |
1255 | - foreach($rates as &$rate) { |
|
1255 | + foreach ($rates as &$rate) { |
|
1256 | 1256 | $rate = classSupernova::$config->$rate; |
1257 | 1257 | } |
1258 | 1258 | } |
@@ -1263,12 +1263,12 @@ discard block |
||
1263 | 1263 | function get_unit_cost_in(&$cost, $in_resource = RES_METAL) { |
1264 | 1264 | static $rates; |
1265 | 1265 | |
1266 | - if(!$rates) { |
|
1266 | + if (!$rates) { |
|
1267 | 1267 | $rates = get_resource_exchange(); |
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | $metal_cost = 0; |
1271 | - foreach($cost as $resource_id => $resource_value) { |
|
1271 | + foreach ($cost as $resource_id => $resource_value) { |
|
1272 | 1272 | $metal_cost += $rates[$resource_id] * $resource_value; |
1273 | 1273 | } |
1274 | 1274 | |
@@ -1278,8 +1278,8 @@ discard block |
||
1278 | 1278 | function get_player_max_expeditons(&$user, $astrotech = -1) { return sn_function_call(__FUNCTION__, array(&$user, $astrotech, &$result)); } |
1279 | 1279 | |
1280 | 1280 | function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) { |
1281 | - if($astrotech == -1) { |
|
1282 | - if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
1281 | + if ($astrotech == -1) { |
|
1282 | + if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
1283 | 1283 | $astrotech = mrc_get_level($user, null, TECH_ASTROTECH); |
1284 | 1284 | $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0; |
1285 | 1285 | } |
@@ -1295,8 +1295,8 @@ discard block |
||
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | function get_player_max_colonies(&$user, $astrotech = -1) { |
1298 | - if($astrotech == -1) { |
|
1299 | - if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
1298 | + if ($astrotech == -1) { |
|
1299 | + if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
1300 | 1300 | |
1301 | 1301 | $expeditions = get_player_max_expeditons($user); |
1302 | 1302 | $astrotech = mrc_get_level($user, null, TECH_ASTROTECH); |
@@ -1341,10 +1341,10 @@ discard block |
||
1341 | 1341 | |
1342 | 1342 | // pdump($powerup_unit, '$powerup_unit'); |
1343 | 1343 | $level_current = $term_original = $time_left = 0; |
1344 | - if($is_upgrade) { |
|
1344 | + if ($is_upgrade) { |
|
1345 | 1345 | $time_finish = strtotime($powerup_unit['unit_time_finish']); |
1346 | 1346 | $time_left = max(0, $time_finish - SN_TIME_NOW); |
1347 | - if($time_left > 0) { |
|
1347 | + if ($time_left > 0) { |
|
1348 | 1348 | $term_original = $time_finish - strtotime($powerup_unit['unit_time_start']); |
1349 | 1349 | $level_current = $powerup_unit['unit_level']; |
1350 | 1350 | } |
@@ -1352,22 +1352,22 @@ discard block |
||
1352 | 1352 | |
1353 | 1353 | $level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK]; |
1354 | 1354 | $original_cost = 0; |
1355 | - for($i = 1; $i <= $level_max; $i++) { |
|
1355 | + for ($i = 1; $i <= $level_max; $i++) { |
|
1356 | 1356 | $base_cost = eco_get_total_cost($powerup_id, $i); |
1357 | 1357 | $base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER]; |
1358 | - foreach($sn_powerup_buy_discounts as $period => $discount) { |
|
1358 | + foreach ($sn_powerup_buy_discounts as $period => $discount) { |
|
1359 | 1359 | $upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH); |
1360 | 1360 | $result[$i][$period] = $upgrade_price; |
1361 | 1361 | $original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost; |
1362 | 1362 | } |
1363 | 1363 | } |
1364 | 1364 | |
1365 | - if($is_upgrade && $time_left) { |
|
1365 | + if ($is_upgrade && $time_left) { |
|
1366 | 1366 | $term_original = round($term_original / PERIOD_DAY); |
1367 | 1367 | $time_left = min(floor($time_left / PERIOD_DAY), $term_original); |
1368 | 1368 | $cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0; |
1369 | 1369 | |
1370 | - array_walk_recursive($result, function (&$value) use ($cost_left) { |
|
1370 | + array_walk_recursive($result, function(&$value) use ($cost_left) { |
|
1371 | 1371 | $value -= $cost_left; |
1372 | 1372 | }); |
1373 | 1373 | } |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | |
1424 | 1424 | function print_rr($var, $capture = false) { |
1425 | 1425 | $print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>'; |
1426 | - if($capture) { |
|
1426 | + if ($capture) { |
|
1427 | 1427 | return $print; |
1428 | 1428 | } else { |
1429 | 1429 | print($print); |