@@ -591,6 +591,9 @@ discard block |
||
591 | 591 | return max(0, $this->shipsGetCapacity() - $this->resourcesGetTotal()); |
592 | 592 | } |
593 | 593 | |
594 | + /** |
|
595 | + * @param integer $ship_id |
|
596 | + */ |
|
594 | 597 | public function shipsGetTotalById($ship_id) { |
595 | 598 | return $this->unitList->unitsCountById($ship_id); |
596 | 599 | } |
@@ -705,7 +708,7 @@ discard block |
||
705 | 708 | /** |
706 | 709 | * Set current resource list from array of units |
707 | 710 | * |
708 | - * @param array $resource_list |
|
711 | + * @param integer[] $resource_list |
|
709 | 712 | */ |
710 | 713 | public function resourcesSet($resource_list) { |
711 | 714 | if(!empty($this->propertiesAdjusted['resource_list'])) { |
@@ -781,7 +784,6 @@ discard block |
||
781 | 784 | * Restores fleet or resources to planet |
782 | 785 | * |
783 | 786 | * @param bool $start |
784 | - * @param bool $only_resources |
|
785 | 787 | * @param int $result |
786 | 788 | * |
787 | 789 | * @return int |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | public function dbInsert() { |
284 | 284 | // WARNING! MISSION TIMES MUST BE SET WITH set_times() method! |
285 | 285 | // TODO - more checks! |
286 | - if(empty($this->_time_launch)) { |
|
286 | + if (empty($this->_time_launch)) { |
|
287 | 287 | die('Fleet time not set!'); |
288 | 288 | } |
289 | 289 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | // Записываем изменения в БД |
364 | 364 | $this->dbSave(); |
365 | 365 | |
366 | - if($this->_group_id) { |
|
366 | + if ($this->_group_id) { |
|
367 | 367 | // TODO: Make here to delete only one AKS - by adding aks_fleet_count to AKS table |
368 | 368 | db_fleet_aks_purge(); |
369 | 369 | } |
@@ -434,15 +434,15 @@ discard block |
||
434 | 434 | */ |
435 | 435 | // TODO - separate shipList and unitList |
436 | 436 | public function unitsSetFromArray($unit_array) { |
437 | - foreach($unit_array as $unit_id => $unit_count) { |
|
437 | + foreach ($unit_array as $unit_id => $unit_count) { |
|
438 | 438 | $unit_count = floatval($unit_count); |
439 | - if(!$unit_count) { |
|
439 | + if (!$unit_count) { |
|
440 | 440 | continue; |
441 | 441 | } |
442 | 442 | |
443 | - if($this->isShip($unit_id)) { |
|
443 | + if ($this->isShip($unit_id)) { |
|
444 | 444 | $this->unitList->unitSetCount($unit_id, $unit_count); |
445 | - } elseif($this->isResource($unit_id)) { |
|
445 | + } elseif ($this->isResource($unit_id)) { |
|
446 | 446 | $this->resource_list[$unit_id] = $unit_count; |
447 | 447 | } else { |
448 | 448 | throw new Exception('Trying to pass to fleet non-resource and non-ship ' . var_export($unit_array, true), ERR_ERROR); |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | public function parse_missile_db_row($missile_db_row) { |
472 | 472 | // $this->_reset(); |
473 | 473 | |
474 | - if(empty($missile_db_row) || !is_array($missile_db_row)) { |
|
474 | + if (empty($missile_db_row) || !is_array($missile_db_row)) { |
|
475 | 475 | return; |
476 | 476 | } |
477 | 477 | |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | public function shipsGetCapacityRecyclers(array $recycler_info) { |
608 | 608 | $recyclers_incoming_capacity = 0; |
609 | 609 | $fleet_data = $this->shipsGetArray(); |
610 | - foreach($recycler_info as $recycler_id => $recycler_data) { |
|
610 | + foreach ($recycler_info as $recycler_id => $recycler_data) { |
|
611 | 611 | $recyclers_incoming_capacity += $fleet_data[$recycler_id] * $recycler_data['capacity']; |
612 | 612 | } |
613 | 613 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | sn_db_transaction_check(true); |
628 | 628 | |
629 | 629 | // Если флот уже обработан - не существует или возращается - тогда ничего не делаем |
630 | - if($this->isEmpty()) { |
|
630 | + if ($this->isEmpty()) { |
|
631 | 631 | return $result; |
632 | 632 | } |
633 | 633 | |
@@ -649,18 +649,18 @@ discard block |
||
649 | 649 | // TODO - Проверка, что планета всё еще существует на указанных координатах, а не телепортировалась, не удалена хозяином, не уничтожена врагом |
650 | 650 | // Флот, который возвращается на захваченную планету, пропадает |
651 | 651 | // Ship landing is possible only to fleet owner's planet |
652 | - if($this->getPlayerOwnerId() == $planet_arrival['id_owner']) { |
|
652 | + if ($this->getPlayerOwnerId() == $planet_arrival['id_owner']) { |
|
653 | 653 | $db_changeset = array(); |
654 | 654 | |
655 | 655 | $fleet_array = $this->shipsGetArray(); |
656 | - foreach($fleet_array as $ship_id => $ship_count) { |
|
657 | - if($ship_count) { |
|
656 | + foreach ($fleet_array as $ship_id => $ship_count) { |
|
657 | + if ($ship_count) { |
|
658 | 658 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, $ship_count, $user, $planet_arrival['id']); |
659 | 659 | } |
660 | 660 | } |
661 | 661 | |
662 | 662 | // Adjusting ship amount on planet |
663 | - if(!empty($db_changeset)) { |
|
663 | + if (!empty($db_changeset)) { |
|
664 | 664 | db_changeset_apply($db_changeset); |
665 | 665 | } |
666 | 666 | |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | * @param array $resource_list |
709 | 709 | */ |
710 | 710 | public function resourcesSet($resource_list) { |
711 | - if(!empty($this->propertiesAdjusted['resource_list'])) { |
|
711 | + if (!empty($this->propertiesAdjusted['resource_list'])) { |
|
712 | 712 | throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::unitSetResourceList', ERR_ERROR); |
713 | 713 | } |
714 | 714 | $this->resourcesAdjust($resource_list, true); |
@@ -722,13 +722,13 @@ discard block |
||
722 | 722 | public function resourcesAdjust($resource_delta_list, $replace_value = false) { |
723 | 723 | !is_array($resource_delta_list) ? $resource_delta_list = array() : false; |
724 | 724 | |
725 | - foreach($resource_delta_list as $resource_id => $unit_delta) { |
|
726 | - if(!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) { |
|
725 | + foreach ($resource_delta_list as $resource_id => $unit_delta) { |
|
726 | + if (!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) { |
|
727 | 727 | // Not a resource or no resources - continuing |
728 | 728 | continue; |
729 | 729 | } |
730 | 730 | |
731 | - if($replace_value) { |
|
731 | + if ($replace_value) { |
|
732 | 732 | $this->resource_list[$resource_id] = $unit_delta; |
733 | 733 | } else { |
734 | 734 | $this->resource_list[$resource_id] += $unit_delta; |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | } |
739 | 739 | |
740 | 740 | // Check for negative unit value |
741 | - if($this->resource_list[$resource_id] < 0) { |
|
741 | + if ($this->resource_list[$resource_id] < 0) { |
|
742 | 742 | // TODO |
743 | 743 | throw new Exception('Resource ' . $resource_id . ' will become negative in ' . get_called_class() . '::unitAdjustResourceList', ERR_ERROR); |
744 | 744 | } |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | sn_db_transaction_check(true); |
791 | 791 | |
792 | 792 | // Если флот уже обработан - не существует или возращается - тогда ничего не делаем |
793 | - if(!$this->resourcesGetTotal()) { |
|
793 | + if (!$this->resourcesGetTotal()) { |
|
794 | 794 | return $result; |
795 | 795 | } |
796 | 796 | |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | // TODO - Проверка, что планета всё еще существует на указанных координатах, а не телепортировалась, не удалена хозяином, не уничтожена врагом |
811 | 811 | |
812 | 812 | // Restoring resources to planet |
813 | - if($this->resourcesGetTotal()) { |
|
813 | + if ($this->resourcesGetTotal()) { |
|
814 | 814 | $fleet_resources = $this->resourcesGetList(); |
815 | 815 | db_planet_set_by_id($planet_arrival['id'], |
816 | 816 | "`metal` = `metal` + '{$fleet_resources[RES_METAL]}', `crystal` = `crystal` + '{$fleet_resources[RES_CRYSTAL]}', `deuterium` = `deuterium` + '{$fleet_resources[RES_DEUTERIUM]}'"); |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * @param Fleet $objFleet |
12 | 12 | * @param bool $start |
13 | - * @param null $result |
|
13 | + * @param integer $result |
|
14 | 14 | * |
15 | 15 | * @return mixed |
16 | 16 | */ |
@@ -31,7 +31,7 @@ |
||
31 | 31 | /** |
32 | 32 | * Fleet mission "Relocate" |
33 | 33 | * |
34 | - * @param $mission_data Mission |
|
34 | + * @param Mission $mission_data Mission |
|
35 | 35 | * |
36 | 36 | * @return int |
37 | 37 | * |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param Unit $value |
89 | 89 | */ |
90 | 90 | public function offsetSet($offset, $value) { |
91 | - if(isset($this->mapUnitIdToDb[$value->unitId])) { |
|
91 | + if (isset($this->mapUnitIdToDb[$value->unitId])) { |
|
92 | 92 | classSupernova::$debug->error('UnitList::offsetSet: Unit with UnitId ' . $value->unitId . ' already exists'); |
93 | 93 | } |
94 | 94 | $this->mapUnitIdToDb[$value->unitId] = $value; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | public function offsetUnset($offset) { |
99 | - if(!empty($this[$offset]->unitId)) { |
|
99 | + if (!empty($this[$offset]->unitId)) { |
|
100 | 100 | // $unit_id = $this[$offset]->unitId; |
101 | 101 | // $this->mapUnitIdToDb[$unit_id] = null; |
102 | 102 | // unset($this->mapUnitIdToDb[$unit_id]); |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | public function dbLoad($dbId) { |
119 | 119 | // $this->_reset(); |
120 | 120 | |
121 | - if($dbId <= 0) { |
|
121 | + if ($dbId <= 0) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - if(!is_object($this->locatedAt)) { |
|
125 | + if (!is_object($this->locatedAt)) { |
|
126 | 126 | classSupernova::$debug->error('UnitList::dbLoad have no locatedAt field set'); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $unit_array = classSupernova::db_get_unit_list_by_location(0, $this->getLocationType(), $this->getLocationDbId()); |
130 | - if(!is_array($unit_array)) { |
|
130 | + if (!is_array($unit_array)) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - foreach($unit_array as $unit_db_row) { |
|
134 | + foreach ($unit_array as $unit_db_row) { |
|
135 | 135 | $unit = $this->_createElement(); |
136 | 136 | $unit->setLocatedAt($this); |
137 | 137 | $unit->dbRowParse($unit_db_row); |
@@ -147,25 +147,25 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | public function dbSave() { |
150 | - if(!is_object($this->locatedAt)) { |
|
150 | + if (!is_object($this->locatedAt)) { |
|
151 | 151 | classSupernova::$debug->error('UnitList::dbSave have no locatedAt field set'); |
152 | 152 | } |
153 | 153 | |
154 | - foreach($this->mapUnitIdToDb as $unit) { |
|
154 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
155 | 155 | $unit_db_id = $unit->dbId; |
156 | 156 | $unit->dbSave(); |
157 | 157 | |
158 | - if($unit->isEmpty()) { |
|
158 | + if ($unit->isEmpty()) { |
|
159 | 159 | // Removing unit object |
160 | 160 | // TODO - change when there will be common bus for all objects |
161 | 161 | // ...or should I? If COUNT is empty - it means that object does not exists in DB. So it should be deleted from PHP memory and cache too |
162 | 162 | unset($this[$unit_db_id]); |
163 | 163 | } else { |
164 | - if($unit->dbId <= 0) { |
|
164 | + if ($unit->dbId <= 0) { |
|
165 | 165 | classSupernova::$debug->error('Error writing unit to DB'); |
166 | 166 | } |
167 | 167 | // If unit is new then putting unit object to container |
168 | - if(empty($this->_container[$unit->dbId])) { |
|
168 | + if (empty($this->_container[$unit->dbId])) { |
|
169 | 169 | $this->_container[$unit->dbId] = $unit; |
170 | 170 | } |
171 | 171 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public function unitGetCount($unit_id) { |
203 | - if(empty($this->mapUnitIdToDb[$unit_id])) { |
|
203 | + if (empty($this->mapUnitIdToDb[$unit_id])) { |
|
204 | 204 | throw new Exception('Unit [' . $unit_id . '] is not exists in UnitList'); |
205 | 205 | } |
206 | 206 | return $this->mapUnitIdToDb[$unit_id]->count; |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | * @param bool $replace_value |
216 | 216 | */ |
217 | 217 | public function unitAdjustCount($unit_id, $unit_count = 0, $replace_value = false) { |
218 | - if(empty($this->mapUnitIdToDb[$unit_id])) { |
|
218 | + if (empty($this->mapUnitIdToDb[$unit_id])) { |
|
219 | 219 | // If unit not exists - creating one and setting all attributes |
220 | 220 | $this->mapUnitIdToDb[$unit_id] = $this->_createElement(); |
221 | 221 | $this->mapUnitIdToDb[$unit_id]->setUnitId($unit_id); |
222 | 222 | $this->mapUnitIdToDb[$unit_id]->setLocatedAt($this); |
223 | 223 | } |
224 | 224 | |
225 | - if($replace_value) { |
|
225 | + if ($replace_value) { |
|
226 | 226 | $this->mapUnitIdToDb[$unit_id]->count = $unit_count; |
227 | 227 | } else { |
228 | 228 | $this->mapUnitIdToDb[$unit_id]->adjustCount($unit_count); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function unitsGetArray() { |
238 | 238 | $result = array(); |
239 | - foreach($this->mapUnitIdToDb as $unit) { |
|
239 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
240 | 240 | $result[$unit->unitId] = $unit->count; |
241 | 241 | } |
242 | 242 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | public function unitsCountApplyLossMultiplier($ships_lost_multiplier) { |
247 | - foreach($this->mapUnitIdToDb as $unit_id => $unit) { |
|
247 | + foreach ($this->mapUnitIdToDb as $unit_id => $unit) { |
|
248 | 248 | $unit->count = floor($unit->count * $ships_lost_multiplier); |
249 | 249 | } |
250 | 250 | } |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | |
271 | 271 | public function unitsPropertySumById($unit_id = 0, $propertyName = 'count') { |
272 | 272 | $result = 0; |
273 | - foreach($this->mapUnitIdToDb as $unit) { |
|
274 | - if(!$unit_id || $unit->unitId == $unit_id) { |
|
273 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
274 | + if (!$unit_id || $unit->unitId == $unit_id) { |
|
275 | 275 | $result += $unit->$propertyName; |
276 | 276 | } |
277 | 277 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | print('</tr>'); |
354 | 354 | |
355 | - foreach($this->mapUnitIdToDb as $unit) { |
|
355 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
356 | 356 | print('<tr>'); |
357 | 357 | |
358 | 358 | print('<td>'); |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | |
404 | 404 | |
405 | 405 | public function unitZeroDbId() { |
406 | - foreach($this->mapUnitIdToDb as $unit) { |
|
406 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
407 | 407 | $unit->zeroDbId(); |
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
411 | 411 | |
412 | 412 | public function unitZeroCount() { |
413 | - foreach($this->mapUnitIdToDb as $unit) { |
|
413 | + foreach ($this->mapUnitIdToDb as $unit) { |
|
414 | 414 | $unit->count = 0; |
415 | 415 | } |
416 | 416 | } |