Completed
Push — work-fleets ( 3b3d1f...1e06e1 )
by SuperNova.WS
04:45
created
includes/db.php 3 patches
Doc Comments   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@  discard block
 block discarded – undo
11 11
 
12 12
 require_once('db/db_queries.php');
13 13
 
14
+/**
15
+ * @param string $tablename
16
+ */
14 17
 function db_change_units_perform($query, $tablename, $object_id) {
15 18
   $query = implode(',', $query);
16 19
   if($query && $object_id) {
@@ -63,6 +66,9 @@  discard block
 block discarded – undo
63 66
   db_change_units_perform($query[LOC_USER], 'users', $user['id']);
64 67
   db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']);
65 68
 }
69
+/**
70
+ * @param string $table
71
+ */
66 72
 function sn_db_perform($table, $values, $type = 'insert', $options = false) {
67 73
   $mass_perform = false;
68 74
 
@@ -171,11 +177,8 @@  discard block
 block discarded – undo
171 177
 /**
172 178
  * Функция проверяет статус транзакции
173 179
  *
174
- * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки
175
- *   <p>null - транзакция НЕ должна быть запущена</p>
176
- *   <p>true - транзакция должна быть запущена - для совместимости с $for_update</p>
177
- *   <p>false - всё равно - для совместимости с $for_update</p>
178
- * @return bool Текущий статус транзакции
180
+ * @param boolean $transaction_should_be_started
181
+ * @return null|boolean Текущий статус транзакции
179 182
  */
180 183
 function sn_db_transaction_check($transaction_should_be_started = null) {
181 184
   return classSupernova::db_transaction_check($transaction_should_be_started);
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -169,14 +169,14 @@
 block discarded – undo
169 169
   return classSupernova::db_changeset_apply($db_changeset);
170 170
 }
171 171
 /**
172
- * Функция проверяет статус транзакции
173
- *
174
- * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки
175
- *   <p>null - транзакция НЕ должна быть запущена</p>
176
- *   <p>true - транзакция должна быть запущена - для совместимости с $for_update</p>
177
- *   <p>false - всё равно - для совместимости с $for_update</p>
178
- * @return bool Текущий статус транзакции
179
- */
172
+   * Функция проверяет статус транзакции
173
+   *
174
+   * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки
175
+   *   <p>null - транзакция НЕ должна быть запущена</p>
176
+   *   <p>true - транзакция должна быть запущена - для совместимости с $for_update</p>
177
+   *   <p>false - всё равно - для совместимости с $for_update</p>
178
+   * @return bool Текущий статус транзакции
179
+   */
180 180
 function sn_db_transaction_check($transaction_should_be_started = null) {
181 181
   return classSupernova::db_transaction_check($transaction_should_be_started);
182 182
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 function db_change_units_perform($query, $tablename, $object_id) {
13 13
   $query = implode(',', $query);
14
-  if($query && $object_id) {
14
+  if ($query && $object_id) {
15 15
     return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query);
16 16
     // return doquery("UPDATE {{{$tablename}}} SET {$query} WHERE `id` = '{$object_id}' LIMIT 1;");
17 17
   }
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
 
29 29
   $group = sn_get_groups('resources_loot');
30 30
 
31
-  foreach($unit_list as $unit_id => $unit_amount) {
32
-    if(!in_array($unit_id, $group)) {
31
+  foreach ($unit_list as $unit_id => $unit_amount) {
32
+    if (!in_array($unit_id, $group)) {
33 33
       // TODO - remove later
34 34
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>');
35 35
       pdump(debug_backtrace());
36 36
       die('db_change_units() вызван для не-ресурсов!');
37 37
     }
38 38
 
39
-    if(!$unit_amount) {
39
+    if (!$unit_amount) {
40 40
       continue;
41 41
     }
42 42
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     $unit_location = sys_get_unit_location($user, $planet, $unit_id);
46 46
 
47 47
     // Changing value in object
48
-    switch($unit_location) {
48
+    switch ($unit_location) {
49 49
       case LOC_USER:
50 50
         $user[$unit_db_name] += $unit_amount;
51 51
         break;
@@ -67,23 +67,23 @@  discard block
 block discarded – undo
67 67
   $field_set = '';
68 68
   $value_set = '';
69 69
 
70
-  switch($type) {
70
+  switch ($type) {
71 71
     case 'delete':
72 72
       $query = 'DELETE FROM';
73 73
       break;
74 74
 
75 75
     case 'insert':
76 76
       $query = 'INSERT INTO';
77
-      if(isset($options['__multi'])) {
77
+      if (isset($options['__multi'])) {
78 78
         // Here we generate mass-insert set
79 79
         break;
80 80
       }
81 81
     case 'update':
82
-      if(!$query) {
82
+      if (!$query) {
83 83
         $query = 'UPDATE';
84 84
       }
85 85
 
86
-      foreach($values as $field => &$value) {
86
+      foreach ($values as $field => &$value) {
87 87
         $value_type = gettype($value);
88 88
         if ($value_type == 'string') {
89 89
           $value = "'" . db_escape($value) . "'";
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
   $field_set['__IS_SAFE'] = true;
112 112
 }
113 113
 function sn_db_field_set_make_safe($field_set, $serialize = false) {
114
-  if(!is_array($field_set)) {
114
+  if (!is_array($field_set)) {
115 115
     die('$field_set is not an array!');
116 116
   }
117 117
 
118 118
   $result = array();
119
-  foreach($field_set as $field => $value) {
119
+  foreach ($field_set as $field => $value) {
120 120
     $field = db_escape(trim($field));
121 121
     switch (true) {
122 122
       case is_int($value):
Please login to merge, or discard this patch.
includes/db/db_queries_planets.php 3 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -4,11 +4,20 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +12 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
   $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0;
24 24
   $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0;
25 25
   $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0;
26
-  $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) :
27
-    (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0);
26
+  $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0);
28 27
   $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type;
29 28
 
30 29
   return db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields);
@@ -32,14 +31,14 @@  discard block
 block discarded – undo
32 31
 function db_planet_by_parent($parent_id, $for_update = false, $fields = '*')
33 32
 {
34 33
   //if(!($parent_id = intval($parent_id))) return false;
35
-  if(!($parent_id = idval($parent_id))) return false;
34
+  if (!($parent_id = idval($parent_id))) return false;
36 35
   return classSupernova::db_get_record_list(LOC_PLANET,
37 36
     "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true);
38 37
 }
39 38
 function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*')
40 39
 {
41 40
   //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false;
42
-  if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false;
41
+  if (!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false;
43 42
   return classSupernova::db_get_record_list(LOC_PLANET,
44 43
     "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true);
45 44
 }
@@ -48,7 +47,7 @@  discard block
 block discarded – undo
48 47
 function db_planet_list_moon_other($user_id, $this_moon_id)
49 48
 {
50 49
   // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false;
51
-  if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false;
50
+  if (!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false;
52 51
   return classSupernova::db_get_record_list(LOC_PLANET,
53 52
     "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}");
54 53
 }
@@ -61,7 +60,7 @@  discard block
 block discarded – undo
61 60
 }
62 61
 
63 62
 function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') {
64
-  if(!is_array($user_row)) return false;
63
+  if (!is_array($user_row)) return false;
65 64
   // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list;
66 65
   $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : '';
67 66
 
@@ -80,7 +79,7 @@  discard block
 block discarded – undo
80 79
     "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}");
81 80
 }
82 81
 function db_planet_list_by_user_or_planet($user_id, $planet_id) {
83
-  if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false;
82
+  if (!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false;
84 83
 
85 84
   return classSupernova::db_get_record_list(LOC_PLANET,
86 85
     $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id);
@@ -89,12 +88,12 @@  discard block
 block discarded – undo
89 88
 function db_planet_set_by_id($planet_id, $set)
90 89
 {
91 90
   // if(!($planet_id = intval($planet_id))) return false;
92
-  if(!($planet_id = idval($planet_id))) return false;
91
+  if (!($planet_id = idval($planet_id))) return false;
93 92
   return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set);
94 93
 }
95 94
 function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set)
96 95
 {
97
-  if(!($set = trim($set))) return false;
96
+  if (!($set = trim($set))) return false;
98 97
 
99 98
   $si_galaxy = intval($ui_galaxy);
100 99
   $si_system = intval($ui_system);
@@ -106,13 +105,13 @@  discard block
 block discarded – undo
106 105
 function db_planet_set_by_parent($ui_parent_id, $ss_set)
107 106
 {
108 107
   //if(!($si_parent_id = intval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false;
109
-  if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false;
108
+  if (!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false;
110 109
   return classSupernova::db_upd_record_list(LOC_PLANET, "`parent_planet` = {$si_parent_id}", $ss_set);
111 110
 }
112 111
 function db_planet_set_by_owner($ui_owner_id, $ss_set)
113 112
 {
114 113
   //if(!($si_owner_id = intval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false;
115
-  if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false;
114
+  if (!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false;
116 115
   return classSupernova::db_upd_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}", $ss_set);
117 116
 }
118 117
 
@@ -120,7 +119,7 @@  discard block
 block discarded – undo
120 119
 function db_planet_delete_by_id($planet_id)
121 120
 {
122 121
   // if(!($planet_id = intval($planet_id))) return false;
123
-  if(!($planet_id = idval($planet_id))) return false;
122
+  if (!($planet_id = idval($planet_id))) return false;
124 123
   classSupernova::db_del_record_by_id(LOC_PLANET, $planet_id);
125 124
   classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_location_id` = " . $planet_id);
126 125
   // Очереди очистятся автоматически по FOREIGN KEY
@@ -129,7 +128,7 @@  discard block
 block discarded – undo
129 128
 function db_planet_list_delete_by_owner($ui_owner_id)
130 129
 {
131 130
   // if(!($si_owner_id = intval($ui_owner_id))) return false;
132
-  if(!($si_owner_id = idval($ui_owner_id))) return false;
131
+  if (!($si_owner_id = idval($ui_owner_id))) return false;
133 132
   classSupernova::db_del_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}");
134 133
   classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_player_id` = " . $si_owner_id);
135 134
   // Очереди очистятся автоматически по FOREIGN KEY
Please login to merge, or discard this patch.
Braces   +33 added lines, -11 removed lines patch added patch discarded remove patch
@@ -32,14 +32,18 @@  discard block
 block discarded – undo
32 32
 function db_planet_by_parent($parent_id, $for_update = false, $fields = '*')
33 33
 {
34 34
   //if(!($parent_id = intval($parent_id))) return false;
35
-  if(!($parent_id = idval($parent_id))) return false;
35
+  if(!($parent_id = idval($parent_id))) {
36
+    return false;
37
+  }
36 38
   return classSupernova::db_get_record_list(LOC_PLANET,
37 39
     "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true);
38 40
 }
39 41
 function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*')
40 42
 {
41 43
   //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false;
42
-  if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false;
44
+  if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) {
45
+    return false;
46
+  }
43 47
   return classSupernova::db_get_record_list(LOC_PLANET,
44 48
     "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true);
45 49
 }
@@ -48,7 +52,9 @@  discard block
 block discarded – undo
48 52
 function db_planet_list_moon_other($user_id, $this_moon_id)
49 53
 {
50 54
   // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false;
51
-  if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false;
55
+  if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) {
56
+    return false;
57
+  }
52 58
   return classSupernova::db_get_record_list(LOC_PLANET,
53 59
     "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}");
54 60
 }
@@ -61,7 +67,9 @@  discard block
 block discarded – undo
61 67
 }
62 68
 
63 69
 function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') {
64
-  if(!is_array($user_row)) return false;
70
+  if(!is_array($user_row)) {
71
+    return false;
72
+  }
65 73
   // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list;
66 74
   $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : '';
67 75
 
@@ -80,7 +88,9 @@  discard block
 block discarded – undo
80 88
     "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}");
81 89
 }
82 90
 function db_planet_list_by_user_or_planet($user_id, $planet_id) {
83
-  if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false;
91
+  if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) {
92
+    return false;
93
+  }
84 94
 
85 95
   return classSupernova::db_get_record_list(LOC_PLANET,
86 96
     $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id);
@@ -89,12 +99,16 @@  discard block
 block discarded – undo
89 99
 function db_planet_set_by_id($planet_id, $set)
90 100
 {
91 101
   // if(!($planet_id = intval($planet_id))) return false;
92
-  if(!($planet_id = idval($planet_id))) return false;
102
+  if(!($planet_id = idval($planet_id))) {
103
+    return false;
104
+  }
93 105
   return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set);
94 106
 }
95 107
 function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set)
96 108
 {
97
-  if(!($set = trim($set))) return false;
109
+  if(!($set = trim($set))) {
110
+    return false;
111
+  }
98 112
 
99 113
   $si_galaxy = intval($ui_galaxy);
100 114
   $si_system = intval($ui_system);
@@ -106,13 +120,17 @@  discard block
 block discarded – undo
106 120
 function db_planet_set_by_parent($ui_parent_id, $ss_set)
107 121
 {
108 122
   //if(!($si_parent_id = intval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false;
109
-  if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false;
123
+  if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) {
124
+    return false;
125
+  }
110 126
   return classSupernova::db_upd_record_list(LOC_PLANET, "`parent_planet` = {$si_parent_id}", $ss_set);
111 127
 }
112 128
 function db_planet_set_by_owner($ui_owner_id, $ss_set)
113 129
 {
114 130
   //if(!($si_owner_id = intval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false;
115
-  if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false;
131
+  if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) {
132
+    return false;
133
+  }
116 134
   return classSupernova::db_upd_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}", $ss_set);
117 135
 }
118 136
 
@@ -120,7 +138,9 @@  discard block
 block discarded – undo
120 138
 function db_planet_delete_by_id($planet_id)
121 139
 {
122 140
   // if(!($planet_id = intval($planet_id))) return false;
123
-  if(!($planet_id = idval($planet_id))) return false;
141
+  if(!($planet_id = idval($planet_id))) {
142
+    return false;
143
+  }
124 144
   classSupernova::db_del_record_by_id(LOC_PLANET, $planet_id);
125 145
   classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_location_id` = " . $planet_id);
126 146
   // Очереди очистятся автоматически по FOREIGN KEY
@@ -129,7 +149,9 @@  discard block
 block discarded – undo
129 149
 function db_planet_list_delete_by_owner($ui_owner_id)
130 150
 {
131 151
   // if(!($si_owner_id = intval($ui_owner_id))) return false;
132
-  if(!($si_owner_id = idval($ui_owner_id))) return false;
152
+  if(!($si_owner_id = idval($ui_owner_id))) {
153
+    return false;
154
+  }
133 155
   classSupernova::db_del_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}");
134 156
   classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_player_id` = " . $si_owner_id);
135 157
   // Очереди очистятся автоматически по FOREIGN KEY
Please login to merge, or discard this patch.
includes/db/db_queries_users.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@
 block discarded – undo
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
   }
Please login to merge, or discard this patch.
includes/functions/eco_get_build_data.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -10,6 +10,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,8 +38,7 @@  discard block
 block discarded – undo
38 38
     if($user['user_as_ally'])
39 39
     {
40 40
       $lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1", true);
41
-    }
42
-    else
41
+    } else
43 42
     {
44 43
       $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1;
45 44
       $lab_level['effective_level'] = 0;
@@ -238,8 +237,7 @@  discard block
 block discarded – undo
238 237
       //{
239 238
       //  $result = true;
240 239
       //}
241
-    }
242
-    elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que'])
240
+    } elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que'])
243 241
     {
244 242
       $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO));
245 243
     }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
  */
14 14
 function eco_get_lab_max_effective_level(&$user, $lab_require)
15 15
 {
16
-  if(!$user['user_as_ally'] && !isset($user['laboratories_active']))
16
+  if (!$user['user_as_ally'] && !isset($user['laboratories_active']))
17 17
   {
18 18
     $user['laboratories_active'] = array();
19 19
     $query = db_unit_list_laboratories($user['id']);
20
-    while($row = db_fetch($query))
20
+    while ($row = db_fetch($query))
21 21
     {
22
-      if(!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES))
22
+      if (!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES))
23 23
       {
24 24
         $row += array(
25 25
           STRUC_LABORATORY => $level_lab = mrc_get_level($user, $row, STRUC_LABORATORY),
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
     uasort($user['laboratories_active'], 'eco_lab_sort_effectivness');
34 34
   }
35 35
 
36
-  if(!isset($user['research_effective_level'][$lab_require]))
36
+  if (!isset($user['research_effective_level'][$lab_require]))
37 37
   {
38
-    if($user['user_as_ally'])
38
+    if ($user['user_as_ally'])
39 39
     {
40 40
       $lab_level = db_ally_get_ally_count($user);
41 41
     }
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
       $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1;
45 45
       $lab_level['effective_level'] = 0;
46 46
 
47
-      foreach($user['laboratories_active'] as $data)
47
+      foreach ($user['laboratories_active'] as $data)
48 48
       {
49
-        if($tech_intergalactic <= 0)
49
+        if ($tech_intergalactic <= 0)
50 50
         {
51 51
           break;
52 52
         }
53
-        if($data[STRUC_LABORATORY] >= $lab_require)
53
+        if ($data[STRUC_LABORATORY] >= $lab_require)
54 54
         {
55 55
           $lab_level['effective_level'] += $data['laboratory_effective_level'];
56 56
           $tech_intergalactic--;
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
   $time = 0;
80 80
   $only_dark_matter = 0;
81 81
   $cost_in_metal = 0;
82
-  foreach($unit_data[P_COST] as $resource_id => $resource_amount) {
83
-    if($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) {
82
+  foreach ($unit_data[P_COST] as $resource_id => $resource_amount) {
83
+    if ($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) {
84 84
       continue;
85 85
     }
86 86
 
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 
90 90
     $resource_db_name = pname_resource_name($resource_id);
91 91
     $cost_in_metal += $cost[BUILD_CREATE][$resource_id] * $config->__get("rpg_exchange_{$resource_db_name}");
92
-    if(in_array($resource_id, sn_get_groups('resources_loot'))) {
92
+    if (in_array($resource_id, sn_get_groups('resources_loot'))) {
93 93
       $time += $resource_cost * $config->__get("rpg_exchange_{$resource_db_name}") / $rpg_exchange_deuterium;
94 94
       $resource_got = mrc_get_level($user, $planet, $resource_id);
95
-    } elseif($resource_id == RES_DARK_MATTER) {
95
+    } elseif ($resource_id == RES_DARK_MATTER) {
96 96
       $resource_got = mrc_get_level($user, null, $resource_id);
97
-    } elseif($resource_id == RES_ENERGY) {
97
+    } elseif ($resource_id == RES_ENERGY) {
98 98
       $resource_got = max(0, $planet['energy_max'] - $planet['energy_used']);
99 99
     } else {
100 100
       $resource_got = 0;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 
108 108
   $resources_normalized = 0;
109 109
   $resources_loot = sn_get_groups('resources_loot');
110
-  foreach($resources_loot as $resource_id) {
110
+  foreach ($resources_loot as $resource_id) {
111 111
     $resource_db_name = pname_resource_name($resource_id);
112 112
     $resource_got = mrc_get_level($user, $planet, $resource_id);
113 113
     $resources_normalized += floor($resource_got) * $config->__get("rpg_exchange_{$resource_db_name}");
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
   $cost[P_OPTIONS][P_TIME_RAW] = $time = $time * 60 * 60 / get_game_speed() / 2500;
126 126
 
127 127
   // TODO - Вынести в отдельную процедуру расчёт стоимости
128
-  if($only_cost) {
128
+  if ($only_cost) {
129 129
     return $cost;
130 130
   }
131 131
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
   $mercenary = 0;
136 136
   $cost['RESULT'][BUILD_DESTROY] = BUILD_INDESTRUCTABLE;
137
-  if(in_array($unit_id, sn_get_groups('structures'))) {
137
+  if (in_array($unit_id, sn_get_groups('structures'))) {
138 138
     $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1);
139 139
     $mercenary = MRC_ENGINEER;
140 140
     $cost['RESULT'][BUILD_DESTROY] =
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
             : BUILD_NO_RESOURCES
145 145
           )
146 146
         : BUILD_NO_UNITS;
147
-  } elseif(in_array($unit_id, sn_get_groups('tech'))) {
147
+  } elseif (in_array($unit_id, sn_get_groups('tech'))) {
148 148
     $lab_level = eco_get_lab_max_effective_level($user, intval($unit_data['require'][STRUC_LABORATORY]));
149 149
     $time = $time / $lab_level;
150 150
     $mercenary = MRC_ACADEMIC;
151
-  } elseif(in_array($unit_id, sn_get_groups('defense'))) {
152
-    $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1) ;
151
+  } elseif (in_array($unit_id, sn_get_groups('defense'))) {
152
+    $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1);
153 153
     $mercenary = MRC_FORTIFIER;
154
-  } elseif(in_array($unit_id, sn_get_groups('fleet'))) {
154
+  } elseif (in_array($unit_id, sn_get_groups('fleet'))) {
155 155
     $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1);
156 156
     $mercenary = MRC_ENGINEER;
157 157
   }
158 158
 
159
-  if($mercenary) {
159
+  if ($mercenary) {
160 160
     $time = $time / mrc_modify_value($user, $planet, $mercenary, 1);
161 161
   }
162 162
 
163
-  if(in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) {
163
+  if (in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) {
164 164
     $cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0;
165 165
   } else {
166 166
     $cost[RES_TIME][BUILD_CREATE]  = round($time >= 1 ? $time : 1);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
   return $cost;
171 171
 }
172 172
 
173
-function eco_can_build_unit($user, $planet, $unit_id){return sn_function_call(__FUNCTION__, array($user, $planet, $unit_id, &$result));}
173
+function eco_can_build_unit($user, $planet, $unit_id) {return sn_function_call(__FUNCTION__, array($user, $planet, $unit_id, &$result)); }
174 174
 function sn_eco_can_build_unit($user, $planet, $unit_id, &$result) {
175 175
   global $config;
176 176
 
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
   $result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result;
179 179
 
180 180
   $unit_param = get_unit_param($unit_id);
181
-  if($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) {
181
+  if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) {
182 182
     $requirement = &$unit_param[P_REQUIRE];
183
-    if($result == BUILD_ALLOWED && $requirement) {
184
-      foreach($requirement as $require_id => $require_level) {
185
-        if(mrc_get_level($user, $planet, $require_id) < $require_level) {
183
+    if ($result == BUILD_ALLOWED && $requirement) {
184
+      foreach ($requirement as $require_id => $require_level) {
185
+        if (mrc_get_level($user, $planet, $require_id) < $require_level) {
186 186
           $result = BUILD_REQUIRE_NOT_MEET;
187 187
           break;
188 188
         }
@@ -199,12 +199,12 @@  discard block
 block discarded – undo
199 199
 
200 200
   $unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list);
201 201
   $planet_que = explode(';', $planet_que);
202
-  foreach($planet_que as $planet_que_item)
202
+  foreach ($planet_que as $planet_que_item)
203 203
   {
204
-    if($planet_que_item)
204
+    if ($planet_que_item)
205 205
     {
206 206
       list($planet_que_item) = explode(',', $planet_que_item);
207
-      if(in_array($planet_que_item, $unit_list))
207
+      if (in_array($planet_que_item, $unit_list))
208 208
       {
209 209
         $eco_is_builds_in_que = true;
210 210
         break;
@@ -215,21 +215,21 @@  discard block
 block discarded – undo
215 215
   return $eco_is_builds_in_que;
216 216
 }
217 217
 
218
-function eco_unit_busy(&$user, &$planet, $unit_id){return sn_function_call(__FUNCTION__, array(&$user, &$planet, $unit_id, &$result));}
218
+function eco_unit_busy(&$user, &$planet, $unit_id) {return sn_function_call(__FUNCTION__, array(&$user, &$planet, $unit_id, &$result)); }
219 219
 function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result)
220 220
 {
221 221
   global $config;
222 222
 
223 223
   $result = isset($result) ? $result : false;
224
-  if(!$result)
224
+  if (!$result)
225 225
   {
226
-    if(($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun)
226
+    if (($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun)
227 227
     {
228 228
       $global_que = que_get($user['id'], $planet['id'], QUE_RESEARCH, false);
229
-      if(is_array($global_que['ques'][QUE_RESEARCH][$user['id']]))
229
+      if (is_array($global_que['ques'][QUE_RESEARCH][$user['id']]))
230 230
       {
231 231
         $first_element = reset($global_que['ques'][QUE_RESEARCH][$user['id']]);
232
-        if(is_array($first_element))
232
+        if (is_array($first_element))
233 233
         {
234 234
           $result = true;
235 235
         }
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
       //  $result = true;
240 240
       //}
241 241
     }
242
-    elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que'])
242
+    elseif (($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que'])
243 243
     {
244 244
       $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO));
245 245
     }
Please login to merge, or discard this patch.
includes/functions/eco_queue.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -55,6 +55,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -458,8 +458,7 @@
 block discarded – undo
458 458
 
459 459
     if(is_numeric($planet['id'])) {
460 460
       db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
461
-    }
462
-    elseif(is_numeric($user['id'])) {
461
+    } elseif(is_numeric($user['id'])) {
463 462
       db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
464 463
     }
465 464
 
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
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
     }
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 function que_get_max_que_length($user, $planet, $que_id, $que_data = null) {
17 17
   global $config;
18 18
 
19
-  if(empty($que_data)) {
19
+  if (empty($que_data)) {
20 20
     $que_data = sn_get_groups('ques');
21 21
     $que_data = $que_data[$que_id];
22 22
   }
23 23
 
24 24
 
25 25
   $que_length = 1;
26
-  switch($que_id) {
26
+  switch ($que_id) {
27 27
     case QUE_RESEARCH:
28 28
       $que_length = $config->server_que_length_research + mrc_get_level($user, '', UNIT_PREMIUM); // TODO - вынести в модуль
29 29
     break;
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
 function eco_que_str2arr($que_str) {
39 39
   $que_arr = explode(';', $que_str);
40
-  foreach($que_arr as $que_index => &$que_item) {
41
-    if($que_item) {
40
+  foreach ($que_arr as $que_index => &$que_item) {
41
+    if ($que_item) {
42 42
       $que_item = explode(',', $que_item);
43 43
     } else {
44 44
       unset($que_arr[$que_index]);
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 }
49 49
 
50 50
 function eco_que_arr2str($que_arr) {
51
-  foreach($que_arr as &$que_item) {
51
+  foreach ($que_arr as &$que_item) {
52 52
     $que_item = implode(',', $que_item);
53 53
   }
54 54
   return implode(';', $que_arr);
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
   global $lang, $config;
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,17 +131,17 @@  discard block
 block discarded – undo
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: break;
141 141
       case BUILD_UNIT_BUSY: throw new exception('{Строение занято}', ERR_ERROR); break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading
142 142
       // case BUILD_REQUIRE_NOT_MEET:
143 143
       default:
144
-        if($build_mode == BUILD_CREATE) {
144
+        if ($build_mode == BUILD_CREATE) {
145 145
           throw new exception('{Требования не удовлетворены}', ERR_ERROR);
146 146
         }
147 147
         break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     $unit_amount_qued = $unit_amount;
152 152
     $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0;
153 153
     $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued;
154
-    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
155
-      if($unit_level >= $unit_max) {
154
+    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
155
+      if ($unit_level >= $unit_max) {
156 156
         throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
157 157
       }
158 158
       $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level));
159 159
     }
160 160
 
161
-    if($unit_amount < 1) {
161
+    if ($unit_amount < 1) {
162 162
       throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
163 163
     }
164 164
 
@@ -174,21 +174,21 @@  discard block
 block discarded – undo
174 174
     //  {
175 175
     //    die('Unit busy'); // TODO EXCEPTION
176 176
     //  }
177
-    if(get_unit_param($unit_id, P_STACKABLE)) {
177
+    if (get_unit_param($unit_id, P_STACKABLE)) {
178 178
       // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь
179
-      if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) {
179
+      if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) {
180 180
         // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита
181 181
         $used_silo = 0;
182
-        foreach($group_missile as $missile_id) {
182
+        foreach ($group_missile as $missile_id) {
183 183
           $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0;
184 184
           $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE);
185 185
         }
186 186
         $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo;
187
-        if($free_silo <= 0) {
187
+        if ($free_silo <= 0) {
188 188
           throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
189 189
         }
190 190
         $unit_size = get_unit_param($unit_id, P_UNIT_SIZE);
191
-        if($free_silo < $unit_size) {
191
+        if ($free_silo < $unit_size) {
192 192
           throw new exception("{В ракетной шахте нет места для {$lang['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION
193 193
         }
194 194
         $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size)));
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
       $unit_level = $new_unit_level = 0;
197 197
     } else {
198 198
       $unit_amount = 1;
199
-      if($que_id == QUE_STRUCTURES) {
199
+      if ($que_id == QUE_STRUCTURES) {
200 200
         // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0)
201 201
         $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0;
202
-        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0)
202
+        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0)
203 203
         {
204 204
           throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION
205 205
         }
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 
218 218
     $exchange = array();
219 219
     $market_get_autoconvert_cost = market_get_autoconvert_cost();
220
-    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
220
+    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
221 221
       $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
222
-      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
222
+      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
223 223
         throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
224 224
       }
225 225
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
       $resource_exchange_rates = array();
230 230
       $resource_diff = array();
231 231
       $all_positive = true;
232
-      foreach($resources_loot as $resource_id) {
232
+      foreach ($resources_loot as $resource_id) {
233 233
         $resource_db_name = pname_resource_name($resource_id);
234 234
         $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id));
235 235
         $resource_exchange_rates[$resource_id] = $config->__get("rpg_exchange_{$resource_db_name}");
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
         $all_positive = $all_positive && ($resource_diff[$resource_id] > 0);
238 238
       }
239 239
       // Нужна автоконвертация
240
-      if($all_positive) {
240
+      if ($all_positive) {
241 241
         $is_autoconvert = false;
242 242
       } else {
243
-        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) {
244
-          if($resource_diff_amount >= 0) {
243
+        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) {
244
+          if ($resource_diff_amount >= 0) {
245 245
             continue;
246 246
           }
247
-          foreach($resource_diff as $resource_got_id => &$resource_got_amount) {
248
-            if($resource_got_amount <= 0) {
247
+          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) {
248
+            if ($resource_got_amount <= 0) {
249 249
               continue;
250 250
             }
251 251
             $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id];
@@ -261,14 +261,14 @@  discard block
 block discarded – undo
261 261
         }
262 262
 
263 263
         $is_autoconvert_ok = true;
264
-        foreach($resource_diff as $resource_diff_amount2) {
265
-          if($resource_diff_amount2 < 0) {
264
+        foreach ($resource_diff as $resource_diff_amount2) {
265
+          if ($resource_diff_amount2 < 0) {
266 266
             $is_autoconvert_ok = false;
267 267
             break;
268 268
           }
269 269
         }
270 270
 
271
-        if($is_autoconvert_ok) {
271
+        if ($is_autoconvert_ok) {
272 272
           $build_data['RESULT'][$build_mode] = BUILD_ALLOWED;
273 273
           $build_data['CAN'][$build_mode] = $unit_amount;
274 274
         } else {
@@ -277,19 +277,19 @@  discard block
 block discarded – undo
277 277
       }
278 278
     }
279 279
     $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount);
280
-    if($unit_amount <= 0) {
280
+    if ($unit_amount <= 0) {
281 281
       throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION
282 282
     }
283 283
 
284
-    if($new_unit_level < 0) {
284
+    if ($new_unit_level < 0) {
285 285
       throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION
286 286
     }
287 287
 
288
-    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
288
+    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
289 289
       throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION
290 290
     }
291 291
 
292
-    if($is_autoconvert) {
292
+    if ($is_autoconvert) {
293 293
       ksort($exchange);
294 294
       ksort($resource_got);
295 295
       db_change_units($user, $planet, array(
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
     }
305 305
 
306 306
     $unit_amount_qued = 0;
307
-    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
307
+    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
308 308
       $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW);
309 309
       que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode);
310 310
       $unit_amount -= $place;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
     sn_db_transaction_commit();
316 316
 
317
-    if($redirect) {
317
+    if ($redirect) {
318 318
       sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id'));
319 319
       die();
320 320
     }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
       'STATUS'  => ERR_NONE,
324 324
       'MESSAGE' => '{Строительство начато}',
325 325
     );
326
-  } catch(exception $e) {
326
+  } catch (exception $e) {
327 327
     sn_db_transaction_rollback();
328 328
     $operation_result = array(
329 329
       'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
     );
332 332
   }
333 333
 
334
-  if(!empty($operation_result['MESSAGE'])) {
334
+  if (!empty($operation_result['MESSAGE'])) {
335 335
     $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . $lang['tech'][$unit_id] . ']';
336 336
   }
337 337
 
@@ -345,11 +345,11 @@  discard block
 block discarded – undo
345 345
 function que_recalculate($old_que) {
346 346
   $new_que = array();
347 347
 
348
-  if(!is_array($old_que['items'])) {
348
+  if (!is_array($old_que['items'])) {
349 349
     return $new_que;
350 350
   }
351
-  foreach($old_que['items'] as $row) {
352
-    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
351
+  foreach ($old_que['items'] as $row) {
352
+    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
353 353
       continue;
354 354
     }
355 355
 
@@ -360,9 +360,9 @@  discard block
 block discarded – undo
360 360
 
361 361
     $last_id = count($new_que['items']) - 1;
362 362
 
363
-    if($row['que_planet_id']) {
363
+    if ($row['que_planet_id']) {
364 364
       $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id];
365
-    } elseif($row['que_type'] == QUE_RESEARCH) {
365
+    } elseif ($row['que_type'] == QUE_RESEARCH) {
366 366
       $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id];
367 367
     }
368 368
     $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id];
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
   $que_type = que_get_unit_que($unit_id);
398 398
   $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
399 399
   $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
400
-  if(is_numeric($planet_id)) {
400
+  if (is_numeric($planet_id)) {
401 401
     db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
402
-  } elseif(is_numeric($user['id'])) {
402
+  } elseif (is_numeric($user['id'])) {
403 403
     db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
404 404
   }
405 405
 
@@ -429,17 +429,17 @@  discard block
 block discarded – undo
429 429
   $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
430 430
   $global_que = que_get($user['id'], $planet['id'], $que_type, true);
431 431
 
432
-  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
432
+  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
433 433
     $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
434 434
 
435
-    foreach($que as $que_item) {
435
+    foreach ($que as $que_item) {
436 436
       db_que_delete_by_id($que_item['que_id']);
437 437
 
438
-      if($que_item['que_planet_id_origin']) {
438
+      if ($que_item['que_planet_id_origin']) {
439 439
         $planet['id'] = $que_item['que_planet_id_origin'];
440 440
       }
441 441
 
442
-      if(!isset($planets_locked[$planet['id']])) {
442
+      if (!isset($planets_locked[$planet['id']])) {
443 443
         $planets_locked[$planet['id']] = $planet['id'] ? db_planet_by_id($planet['id'], true) : $planet;
444 444
       }
445 445
 
@@ -451,15 +451,15 @@  discard block
 block discarded – undo
451 451
         RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'],
452 452
       ));
453 453
 
454
-      if(!$clear) {
454
+      if (!$clear) {
455 455
         break;
456 456
       }
457 457
     }
458 458
 
459
-    if(is_numeric($planet['id'])) {
459
+    if (is_numeric($planet['id'])) {
460 460
       db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
461 461
     }
462
-    elseif(is_numeric($user['id'])) {
462
+    elseif (is_numeric($user['id'])) {
463 463
       db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
464 464
     }
465 465
 
@@ -504,21 +504,21 @@  discard block
 block discarded – undo
504 504
   // TODO: Переделать для $que_type === false
505 505
   $planet['id'] = $planet['id'] ? $planet['id'] : 0;
506 506
 
507
-  if(!is_array($que)) {
507
+  if (!is_array($que)) {
508 508
     $que = que_get($user['id'], $planet['id'], $que_type);
509 509
   }
510 510
 
511
-  if(is_array($que) && isset($que['items'])) {
511
+  if (is_array($que) && isset($que['items'])) {
512 512
     $que = $que['ques'][$que_type][$user['id']][$planet['id']];
513 513
   }
514 514
 
515
-  if($que) {
516
-    foreach($que as $que_element) {
515
+  if ($que) {
516
+    foreach ($que as $que_element) {
517 517
       $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names));
518 518
     }
519 519
   }
520 520
 
521
-  if($que_type == QUE_RESEARCH) {
521
+  if ($que_type == QUE_RESEARCH) {
522 522
     // TODO Исправить
523 523
 //    $template->assign_var('RESEARCH_ONGOING', count($global_que[QUE_RESEARCH][0]) >= $config->server_que_length_research);
524 524
   }
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
   $user = db_user_by_id($user['id'], true);
547 547
 
548 548
   $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']);
549
-  if($planet === null && !$time_left[$user['id']][0]) {
549
+  if ($planet === null && !$time_left[$user['id']][0]) {
550 550
     // TODO
551 551
     return $que;
552 552
   }
@@ -555,12 +555,12 @@  discard block
 block discarded – undo
555 555
   $que_type_id = $planet === null ? QUE_RESEARCH : false;
556 556
   $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false
557 557
   $que = que_get($user['id'], $planet, $que_type_id, true);
558
-  if(empty($que['items'])) {
558
+  if (empty($que['items'])) {
559 559
     return $que;
560 560
   }
561 561
 
562 562
   $planet_list = array();
563
-  if($planet !== null) {
563
+  if ($planet !== null) {
564 564
     // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них
565 565
     // TODO - от них не надо ничего, кроме ID и que_processed
566 566
     $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet);
@@ -569,21 +569,21 @@  discard block
 block discarded – undo
569 569
   }
570 570
 
571 571
   // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты
572
-  if(array_sum($time_left[$user['id']]) == 0) {
572
+  if (array_sum($time_left[$user['id']]) == 0) {
573 573
     return $que;
574 574
   }
575 575
 
576 576
   $db_changeset = array();
577 577
   $unit_changes = array();
578
-  foreach($que['items'] as &$que_item) {
578
+  foreach ($que['items'] as &$que_item) {
579 579
     $que_player_id = &$que_item['que_player_id'];
580 580
     $que_planet_id = intval($que_item['que_planet_id']);
581 581
 
582 582
     $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']];
583
-    if(!isset($que_time_left)) {
583
+    if (!isset($que_time_left)) {
584 584
       $que_time_left = $time_left[$que_player_id][$que_planet_id];
585 585
     }
586
-    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
586
+    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
587 587
       continue;
588 588
     }
589 589
     // Дальше мы идем, если только осталось время в очереди И юниты к постройке
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
     // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля
597 597
 
598 598
     // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит
599
-    if($que_time_left >= $que_item['que_time_left']) {
599
+    if ($que_time_left >= $que_item['que_time_left']) {
600 600
       // Увеличиваем количество отстроенных юнитов
601 601
       $unit_processed++;
602 602
       // Вычитаем из времени очереди потраченное на постройку время
@@ -609,12 +609,12 @@  discard block
 block discarded – undo
609 609
     $que_item['que_unit_amount'] -= $unit_processed;
610 610
 
611 611
     // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита
612
-    if($que_item['que_unit_amount'] > 0) {
612
+    if ($que_item['que_unit_amount'] > 0) {
613 613
       $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left;
614 614
       $que_time_left = 0;
615 615
     }
616 616
 
617
-    if($que_item['que_unit_amount'] <= 0) {
617
+    if ($que_item['que_unit_amount'] <= 0) {
618 618
       $db_changeset['que'][] = array(
619 619
         'action' => SQL_OP_DELETE,
620 620
         P_VERSION => 1,
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
       );
641 641
     }
642 642
 
643
-    if($unit_processed) {
643
+    if ($unit_processed) {
644 644
       $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1);
645 645
       $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta;
646 646
     }
647 647
   }
648 648
 
649
-  foreach($time_left as $player_id => $planet_data) {
650
-    foreach($planet_data as $planet_id => $time_on_planet) {
649
+  foreach ($time_left as $player_id => $planet_data) {
650
+    foreach ($planet_data as $planet_id => $time_on_planet) {
651 651
       $table = $planet_id ? 'planets' : 'users';
652 652
       $id = $planet_id ? $planet_id : $player_id;
653 653
       $db_changeset[$table][] = array(
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
         ),
664 664
       );
665 665
 
666
-      if(is_array($unit_changes[$player_id][$planet_id])) {
667
-        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
666
+      if (is_array($unit_changes[$player_id][$planet_id])) {
667
+        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
668 668
           $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null);
669 669
         }
670 670
       }
@@ -674,38 +674,38 @@  discard block
 block discarded – undo
674 674
   $que = que_recalculate($que);
675 675
 
676 676
   // TODO: Re-enable quests for Alliances
677
-  if(!empty($unit_changes) && !$user['user_as_ally']) {
677
+  if (!empty($unit_changes) && !$user['user_as_ally']) {
678 678
     $quest_list = qst_get_quests($user['id']);
679 679
     $quest_triggers = qst_active_triggers($quest_list);
680 680
     $quest_rewards = array();
681 681
 
682 682
 
683 683
     $xp_incoming = array();
684
-    foreach($unit_changes as $user_id => $planet_changes) {
685
-      foreach($planet_changes as $planet_id => $changes) {
684
+    foreach ($unit_changes as $user_id => $planet_changes) {
685
+      foreach ($planet_changes as $planet_id => $changes) {
686 686
         $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array();
687
-        foreach($changes as $unit_id => $unit_value) {
687
+        foreach ($changes as $unit_id => $unit_value) {
688 688
           $que_id = que_get_unit_que($unit_id);
689 689
           $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value;
690
-          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
690
+          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
691 691
             $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1);
692 692
             $build_data = $build_data[BUILD_CREATE];
693
-            foreach(sn_get_groups('resources_loot') as $resource_id) {
693
+            foreach (sn_get_groups('resources_loot') as $resource_id) {
694 694
               $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена
695 695
             }
696 696
           }
697 697
 
698
-          if(is_array($quest_triggers)) {
698
+          if (is_array($quest_triggers)) {
699 699
             // TODO: Check mutiply condition quests
700 700
             $quest_trigger_list = array_keys($quest_triggers, $unit_id);
701
-            if(is_array($quest_trigger_list)) {
702
-              foreach($quest_trigger_list as $quest_id) {
701
+            if (is_array($quest_trigger_list)) {
702
+              foreach ($quest_trigger_list as $quest_id) {
703 703
                 $quest_unit_level = $unit_level_new;
704
-                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
704
+                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
705 705
                   $quest_unit_level = db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id);
706 706
                   $quest_unit_level = $quest_unit_level[$unit_id]['qty'];
707 707
                 }
708
-                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
708
+                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
709 709
                   $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list'];
710 710
                   $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE;
711 711
                 }
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
     // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч
719 719
     qst_reward($user, $quest_rewards, $quest_list);
720 720
 
721
-    foreach($xp_incoming as $que_id => $xp) {
721
+    foreach ($xp_incoming as $que_id => $xp) {
722 722
       rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000);
723 723
     }
724 724
   }
Please login to merge, or discard this patch.
includes/functions/msg_send_simple_message.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -37,6 +37,9 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''),
27 27
     false, 'id, username');
28 28
   // while ($u = db_fetch($query))
29
-  foreach($query as $u)
29
+  foreach ($query as $u)
30 30
   {
31 31
     $sendList[] = $u['id'];
32 32
     $list .= "<br>{$u['username']} ";
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
 {
42 42
   global $config, $user, $sn_message_class_list;
43 43
 
44
-  if(!$owners)
44
+  if (!$owners)
45 45
   {
46 46
     return;
47 47
   }
48 48
 
49 49
   $timestamp = $timestamp ? $timestamp : SN_TIME_NOW;
50 50
   $sender = intval($sender);
51
-  if(!is_array($owners))
51
+  if (!is_array($owners))
52 52
   {
53 53
     $owners = array($owners);
54 54
   }
55 55
 
56
-  if(!$escaped)
56
+  if (!$escaped)
57 57
   {
58 58
     $from = db_escape($from);
59 59
     $subject = db_escape($subject);
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 
70 70
   $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name'];
71 71
 
72
-  if($owners[0] == '*')
72
+  if ($owners[0] == '*')
73 73
   {
74
-    if($user['authlevel'] < 3)
74
+    if ($user['authlevel'] < 3)
75 75
     {
76 76
       return false;
77 77
     }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
     foreach ($owners as $owner)
89 89
     {
90
-      if($user['id'] != $owner)
90
+      if ($user['id'] != $owner)
91 91
       {
92 92
         $owner_row = db_user_by_id($owner);
93 93
       }
@@ -97,18 +97,18 @@  discard block
 block discarded – undo
97 97
       }
98 98
       sys_user_options_unpack($owner_row);
99 99
 
100
-      if($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"])
100
+      if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"])
101 101
       {
102 102
         $insert_values[] = sprintf($insert_template, $owner);
103 103
       }
104 104
 
105
-      if($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"])
105
+      if ($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"])
106 106
       {
107 107
         @$result = mymail($owner_row['email'], $subject, $text_unescaped, '', true);
108 108
       }
109 109
     }
110 110
 
111
-    if(empty($insert_values))
111
+    if (empty($insert_values))
112 112
     {
113 113
       return;
114 114
     }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
   }
119 119
   db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1");
120 120
 
121
-  if(in_array($user['id'], $owners) || $owners[0] == '*')
121
+  if (in_array($user['id'], $owners) || $owners[0] == '*')
122 122
   {
123 123
     $user[$message_class_name]++;
124 124
     $user[$message_class_name_total]++;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@  discard block
 block discarded – undo
79 79
     // TODO Добавить $sender - рассылка может быть и от кого-то
80 80
     db_message_insert_all($message_type, $from, $subject, $text);
81 81
     $owners = array();
82
-  }
83
-  else
82
+  } else
84 83
   {
85 84
     $insert_values = array();
86 85
     $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')");
@@ -90,8 +89,7 @@  discard block
 block discarded – undo
90 89
       if($user['id'] != $owner)
91 90
       {
92 91
         $owner_row = db_user_by_id($owner);
93
-      }
94
-      else
92
+      } else
95 93
       {
96 94
         $owner_row = $user;
97 95
       }
Please login to merge, or discard this patch.
includes/functions/rpg_points.php 3 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -161,6 +161,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
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
 /**
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@  discard block
 block discarded – undo
29 29
 function rpg_points_change($user_id, $change_type, $dark_matter, $comment = '', $already_changed = false) {
30 30
   global $debug, $config, $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
 block discarded – undo
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
 block discarded – undo
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'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0);
89
-        if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) {
89
+        if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
includes/functions/sys_user.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -141,6 +141,9 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 function sys_user_vacation($user) {
10 10
   global $config;
11 11
 
12
-  if(sys_get_param_str('vacation') == 'leave') {
12
+  if (sys_get_param_str('vacation') == 'leave') {
13 13
     if ($user['vacation'] < SN_TIME_NOW) {
14 14
       $user['vacation'] = 0;
15 15
       $user['vacation_next'] = SN_TIME_NOW + $config->player_vacation_timeout;
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     }
18 18
   }
19 19
 
20
-  if($user['vacation']) {
20
+  if ($user['vacation']) {
21 21
     // sn_sys_logout(false, true);
22 22
     // core_auth::logout(false, true);
23 23
 
@@ -49,33 +49,33 @@  discard block
 block discarded – undo
49 49
   // TODO: Full rewrite
50 50
   sn_db_transaction_start();
51 51
   $TheUser = db_user_by_id($UserID);
52
-  if ( $TheUser['ally_id'] != 0 ) {
53
-    $TheAlly = doquery ( "SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true );
52
+  if ($TheUser['ally_id'] != 0) {
53
+    $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true);
54 54
     $TheAlly['ally_members'] -= 1;
55
-    if ( $TheAlly['ally_members'] > 0 ) {
56
-      doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
55
+    if ($TheAlly['ally_members'] > 0) {
56
+      doquery("UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
57 57
     } else {
58
-      doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';");
59
-      doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';");
58
+      doquery("DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';");
59
+      doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';");
60 60
     }
61 61
   }
62
-  doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';");
62
+  doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';");
63 63
 
64 64
   db_planet_list_delete_by_owner($UserID);
65 65
 
66
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';");
67
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';");
68
-  doquery ( "DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';");
66
+  doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';");
67
+  doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';");
68
+  doquery("DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';");
69 69
   FleetList::db_fleet_list_delete_by_owner($UserID);
70 70
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner1` = '" . $UserID . "';");
71 71
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner2` = '" . $UserID . "';");
72
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';");
73
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';");
74
-  doquery ( "DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';");
72
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';");
73
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';");
74
+  doquery("DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';");
75 75
 
76 76
 
77 77
   classSupernova::db_del_record_by_id(LOC_USER, $UserID);
78
-  doquery ( "DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
78
+  doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
79 79
   global $config;
80 80
   $config->db_saveItem('users_amount', $config->db_loadItem('users_amount') - 1);
81 81
   sn_db_transaction_commit();
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
   !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false;
153 153
 
154 154
   $user_new = classSupernova::db_ins_field_set(LOC_USER, $field_set);
155
-  if(!($options['galaxy'] && $options['system'] && $options['planet'])) {
155
+  if (!($options['galaxy'] && $options['system'] && $options['planet'])) {
156 156
     $options['galaxy'] = $config->LastSettedGalaxyPos;
157 157
     $options['system'] = $config->LastSettedSystemPos;
158 158
     $segment_size = floor($config->game_maxPlanet / 3);
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
     $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size);
162 162
 
163 163
     // $new_planet_id = 0;
164
-    while(true) {
165
-      if($options['planet'] > $config->game_maxPlanet) {
164
+    while (true) {
165
+      if ($options['planet'] > $config->game_maxPlanet) {
166 166
         $options['planet'] = mt_rand(0, $segment_size - 1) + 1;
167 167
         $options['system']++;
168 168
       }
169
-      if($options['system'] > $config->game_maxSystem) {
169
+      if ($options['system'] > $config->game_maxSystem) {
170 170
         $options['system'] = 1;
171 171
         $options['galaxy']++;
172 172
       }
173 173
       $options['galaxy'] > $config->game_maxGalaxy ? $options['galaxy'] = 1 : false;
174 174
 
175 175
       $galaxy_row = db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id');
176
-      if(!$galaxy_row['id']) {
176
+      if (!$galaxy_row['id']) {
177 177
         $config->db_saveItem(array(
178 178
           'LastSettedGalaxyPos' => $options['galaxy'],
179 179
           'LastSettedSystemPos' => $options['system'],
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
   $username_safe = db_escape($username_unsafe);
203 203
   db_player_name_history_replace($user_new, $username_safe);
204 204
 
205
-  if(!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) {
205
+  if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) {
206 206
     db_referral_insert($options, $user_new);
207 207
   }
208 208
 
Please login to merge, or discard this patch.
includes/functions/uni_functions.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -253,9 +253,11 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
   $Position = intval($Position);
61 61
 
62
-  if(!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
62
+  if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
63 63
     return false;
64 64
   }
65 65
 
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 
69 69
   $planet_generator = sn_get_groups('planet_generator');
70 70
 
71
-  if($HomeWorld) {
71
+  if ($HomeWorld) {
72 72
     $position_data = $planet_generator[0];
73 73
   } else {
74 74
     $position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position];
75
-    if($Position >= UNIVERSE_RANDOM_PLANET_START) {
75
+    if ($Position >= UNIVERSE_RANDOM_PLANET_START) {
76 76
       // Корректируем температуру для планеты-странника
77 77
       $position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START);
78 78
     }
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
   $moon_name = '';
173 173
   $moon_row = array();
174 174
   $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id');
175
-  if(!$moon['id']) {
175
+  if (!$moon['id']) {
176 176
     $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`');
177 177
 
178
-    if($moon_planet['id']) {
178
+    if ($moon_planet['id']) {
179 179
       $base_storage_size = BASE_STORAGE_SIZE;
180 180
 
181
-      if(!$moon_chance) {
181
+      if (!$moon_chance) {
182 182
         $size = mt_rand(1100, 8999);
183
-      } elseif($moon_chance <= 100) {
183
+      } elseif ($moon_chance <= 100) {
184 184
         $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999);
185 185
       } else {
186 186
         $size = $moon_chance;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
       $field_max = ceil($size / 1000);
198 198
 
199
-      if(isset($options['image']) && $options['image']) {
199
+      if (isset($options['image']) && $options['image']) {
200 200
         $moon_image = $options['image'];
201 201
       } else {
202 202
         $moon_image = 'mond';
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
           `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'"
212 212
       );
213 213
 
214
-      if($update_debris) {
214
+      if ($update_debris) {
215 215
         $debris_spent = $moon_chance * 1000000;
216 216
         $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100));
217 217
         $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent);
@@ -246,21 +246,21 @@  discard block
 block discarded – undo
246 246
   $planet_row['id'] = $user['current_planet'];
247 247
 
248 248
   // Пытаемся переключить на новую планету
249
-  if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
249
+  if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
250 250
     $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id');
251 251
   } else {
252 252
     $planet_row = db_planet_by_id($planet_row['id']);
253 253
   }
254 254
 
255 255
   // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету
256
-  if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
256
+  if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
257 257
   {
258 258
     $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id');
259 259
     // Если текущей планеты не существует - выставляем Столицу
260
-    if(!isset($planet_row['id'])) {
260
+    if (!isset($planet_row['id'])) {
261 261
       $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id');
262 262
       // Если и столицы не существует - значит что-то очень не так с записью пользователя
263
-      if(!isset($planet_row['id'])) {
263
+      if (!isset($planet_row['id'])) {
264 264
         global $debug;
265 265
         $debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502);
266 266
       }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
   }
269 269
 
270 270
   // Если производилось переключение планеты - делаем запись в юзере
271
-  if($user['current_planet'] != $planet_row['id']) {
271
+  if ($user['current_planet'] != $planet_row['id']) {
272 272
     db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'");
273 273
     $user['current_planet'] = $planet_row['id'];
274 274
   }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 }
287 287
 
288 288
 function uni_render_planet_full($from, $prefix = '', $html_safe = true, $include_id = false) {
289
-  if(!$from['id']) {
289
+  if (!$from['id']) {
290 290
     $result = classLocale::$lang['sys_planet_expedition'];
291 291
   } else {
292 292
     $from_planet_id = $include_id ? (
@@ -341,23 +341,23 @@  discard block
 block discarded – undo
341 341
   global $config;
342 342
 
343 343
   try {
344
-    if($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
344
+    if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
345 345
       throw new exception(classLocale::$lang['ov_teleport_err_cooldown'], ERR_ERROR);
346 346
     }
347 347
 
348
-    if(mrc_get_level($user, null, RES_DARK_MATTER) < $config->planet_teleport_cost) {
348
+    if (mrc_get_level($user, null, RES_DARK_MATTER) < $config->planet_teleport_cost) {
349 349
       throw new exception(classLocale::$lang['ov_teleport_err_no_dark_matter'], ERR_ERROR);
350 350
     }
351 351
 
352 352
     // TODO: Replace quick-check with using gathered flying fleet data
353
-    if(FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
353
+    if (FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
354 354
       throw new exception(classLocale::$lang['ov_teleport_err_fleet'], ERR_ERROR);
355 355
     }
356 356
 
357
-    if(is_array($new_coordinates)) {
357
+    if (is_array($new_coordinates)) {
358 358
       $new_coordinates['planet_type'] = PT_PLANET;
359 359
       $incoming = db_planet_by_vector($new_coordinates, '', true, 'id');
360
-      if($incoming['id']) {
360
+      if ($incoming['id']) {
361 361
         throw new exception(classLocale::$lang['ov_teleport_err_destination_busy'], ERR_ERROR);
362 362
       }
363 363
     }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
       'result'  => ERR_NONE,
367 367
       'message' => '',
368 368
     );
369
-  } catch(exception $e) {
369
+  } catch (exception $e) {
370 370
     $response = array(
371 371
       'result'  => $e->getCode(),
372 372
       'message' => $e->getMessage(),
Please login to merge, or discard this patch.