We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -5,59 +5,73 @@ discard block |
||
5 | 5 | $amount = get_amount(); |
6 | 6 | $bargain_price = get_bargain_price(); |
7 | 7 | |
8 | -if (!is_numeric($amount) || !is_numeric($bargain_price)) |
|
8 | +if (!is_numeric($amount) || !is_numeric($bargain_price)) { |
|
9 | 9 | create_error('Numbers only please!'); |
10 | +} |
|
10 | 11 | // get good name, id, ... |
11 | 12 | $good_id = $var['good_id']; |
12 | 13 | $good_name = Globals::getGoodName($good_id); |
13 | 14 | |
14 | 15 | // do we have enough turns? |
15 | -if ($player->getTurns() == 0) |
|
16 | +if ($player->getTurns() == 0) { |
|
16 | 17 | create_error('You don\'t have enough turns to trade.'); |
18 | +} |
|
17 | 19 | |
18 | 20 | // get rid of those bugs when we die...there is no port at the home sector |
19 | -if (!$sector->hasPort()) |
|
21 | +if (!$sector->hasPort()) { |
|
20 | 22 | create_error('I can\'t see a port in this sector. Can you?'); |
23 | +} |
|
21 | 24 | $port = $sector->getPort(); |
22 | 25 | |
23 | 26 | // check if the player has the right relations to trade at the current port |
24 | -if ($player->getRelation($port->getRaceID()) < RELATIONS_WAR) |
|
27 | +if ($player->getRelation($port->getRaceID()) < RELATIONS_WAR) { |
|
25 | 28 | create_error('This port refuses to trade with you because you are at <span class="big bold red">WAR!</span>'); |
29 | +} |
|
26 | 30 | |
27 | 31 | // does the port actually buy or sell this good? |
28 | 32 | $transaction = $port->getGoodTransaction($good_id); |
29 | -if (empty($transaction)) |
|
33 | +if (empty($transaction)) { |
|
30 | 34 | create_error('I don\'t trade in that good.'); |
35 | +} |
|
31 | 36 | |
32 | 37 | $portGood = $port->getGood($good_id); |
33 | 38 | // check if there are enough left at port |
34 | -if ($port->getGoodAmount($good_id) < $amount) |
|
39 | +if ($port->getGoodAmount($good_id) < $amount) { |
|
35 | 40 | create_error('I\'m short of ' . $good_name . '. So I\'m not going to sell you ' . $amount . ' pcs.'); |
41 | +} |
|
36 | 42 | |
37 | 43 | // does we have what we are going to sell? |
38 | -if ($transaction == 'Sell' && $amount > $ship->getCargo($good_id)) |
|
44 | +if ($transaction == 'Sell' && $amount > $ship->getCargo($good_id)) { |
|
39 | 45 | create_error('Scanning your ships indicates you don\'t have ' . $amount . ' pcs. of ' . $good_name . '!'); |
46 | +} |
|
40 | 47 | |
41 | 48 | // check if we have enough room for the thing we are going to buy |
42 | -if ($transaction == 'Buy' && $amount > $ship->getEmptyHolds()) |
|
49 | +if ($transaction == 'Buy' && $amount > $ship->getEmptyHolds()) { |
|
43 | 50 | create_error('Scanning your ships indicates you don\'t have enough free cargo bays!'); |
51 | +} |
|
44 | 52 | |
45 | 53 | // check if the guy has enough money |
46 | -if ($transaction == 'Buy' && $player->getCredits() < $bargain_price) |
|
54 | +if ($transaction == 'Buy' && $player->getCredits() < $bargain_price) { |
|
47 | 55 | create_error('You don\'t have enough credits!'); |
56 | +} |
|
48 | 57 | |
49 | 58 | // get relations for us (global + personal) |
50 | 59 | $relations = $player->getRelation($port->getRaceID()); |
51 | 60 | |
52 | -if (!isset($var['ideal_price'])) SmrSession::updateVar('ideal_price', $port->getIdealPrice($good_id, $transaction, $amount, $relations)); |
|
61 | +if (!isset($var['ideal_price'])) { |
|
62 | + SmrSession::updateVar('ideal_price', $port->getIdealPrice($good_id, $transaction, $amount, $relations)); |
|
63 | +} |
|
53 | 64 | $ideal_price = $var['ideal_price']; |
54 | 65 | |
55 | -if (!isset($var['offered_price'])) SmrSession::updateVar('offered_price', $port->getOfferPrice($ideal_price, $relations, $transaction)); |
|
66 | +if (!isset($var['offered_price'])) { |
|
67 | + SmrSession::updateVar('offered_price', $port->getOfferPrice($ideal_price, $relations, $transaction)); |
|
68 | +} |
|
56 | 69 | $offered_price = $var['offered_price']; |
57 | 70 | |
58 | 71 | // nothing should happen here but just to avoid / by 0 |
59 | -if ($ideal_price == 0 || $offered_price == 0) |
|
72 | +if ($ideal_price == 0 || $offered_price == 0) { |
|
60 | 73 | create_error('Port calculation error...buy more goods.'); |
74 | +} |
|
61 | 75 | |
62 | 76 | if ($_REQUEST['action'] == 'Steal') { |
63 | 77 | if (!$ship->isUnderground()) { |
@@ -109,8 +123,7 @@ discard block |
||
109 | 123 | $player->increaseHOF($bargain_price, array('Trade', 'Money', 'Buying'), HOF_PUBLIC); |
110 | 124 | $port->buyGoods($portGood, $amount, $ideal_price, $bargain_price, $gained_exp); |
111 | 125 | $player->increaseRelationsByTrade($amount, $port->getRaceID()); |
112 | - } |
|
113 | - elseif ($transaction == 'Sell') { |
|
126 | + } elseif ($transaction == 'Sell') { |
|
114 | 127 | $msg_transaction = 'sold'; |
115 | 128 | $ship->decreaseCargo($good_id, $amount); |
116 | 129 | $player->increaseCredits($bargain_price); |
@@ -120,8 +133,7 @@ discard block |
||
120 | 133 | $player->increaseHOF($bargain_price, array('Trade', 'Money', 'Selling'), HOF_PUBLIC); |
121 | 134 | $port->sellGoods($portGood, $amount, $ideal_price, $bargain_price, $gained_exp); |
122 | 135 | $player->increaseRelationsByTrade($amount, $port->getRaceID()); |
123 | - } |
|
124 | - elseif ($transaction == 'Steal') { |
|
136 | + } elseif ($transaction == 'Steal') { |
|
125 | 137 | $msg_transaction = 'stolen'; |
126 | 138 | $ship->increaseCargo($good_id, $amount); |
127 | 139 | $player->increaseHOF($amount, array('Trade', 'Goods', 'Stolen'), HOF_ALLIANCE); |
@@ -151,13 +163,13 @@ discard block |
||
151 | 163 | |
152 | 164 | $container['trade_msg'] = $tradeMessage; |
153 | 165 | |
154 | - if ($ship->getEmptyHolds() == 0) |
|
155 | - $container['body'] = 'current_sector.php'; |
|
156 | - else |
|
157 | - $container['body'] = 'shop_goods.php'; |
|
166 | + if ($ship->getEmptyHolds() == 0) { |
|
167 | + $container['body'] = 'current_sector.php'; |
|
168 | + } else { |
|
169 | + $container['body'] = 'shop_goods.php'; |
|
170 | + } |
|
158 | 171 | |
159 | -} |
|
160 | -else { |
|
172 | +} else { |
|
161 | 173 | // does the trader try to outsmart us? |
162 | 174 | $container = create_container('skeleton.php', 'shop_goods_trade.php'); |
163 | 175 | transfer('ideal_price'); |
@@ -172,8 +184,9 @@ discard block |
||
172 | 184 | } |
173 | 185 | |
174 | 186 | // only take turns if they bargained |
175 | -if (!isset($container['number_of_bargains']) || $container['number_of_bargains'] != 1) |
|
187 | +if (!isset($container['number_of_bargains']) || $container['number_of_bargains'] != 1) { |
|
176 | 188 | $player->takeTurns(TURNS_PER_TRADE, TURNS_PER_TRADE); |
189 | +} |
|
177 | 190 | |
178 | 191 | // go to next page |
179 | 192 | forward($container); |
@@ -44,8 +44,8 @@ |
||
44 | 44 | */ |
45 | 45 | public function getValue() { |
46 | 46 | if ($this->rankID == self::RANK_JACK || |
47 | - $this->rankID == self::RANK_QUEEN || |
|
48 | - $this->rankID == self::RANK_KING) { |
|
47 | + $this->rankID == self::RANK_QUEEN || |
|
48 | + $this->rankID == self::RANK_KING) { |
|
49 | 49 | return 10; |
50 | 50 | } elseif ($this->isAce()) { |
51 | 51 | return 11; |
@@ -242,9 +242,9 @@ |
||
242 | 242 | */ |
243 | 243 | public function canFight() { |
244 | 244 | return !($this->hasNewbieTurns() || |
245 | - $this->isDead() || |
|
246 | - $this->isLandedOnPlanet() || |
|
247 | - $this->hasFederalProtection()); |
|
245 | + $this->isDead() || |
|
246 | + $this->isLandedOnPlanet() || |
|
247 | + $this->hasFederalProtection()); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | public function setDead($bool) { |
@@ -896,8 +896,8 @@ discard block |
||
896 | 896 | } |
897 | 897 | self::$HOFVis[$hofType] = $visibility; |
898 | 898 | |
899 | - $hof =& $this->HOF; |
|
900 | - $hofChanged =& $this->hasHOFChanged; |
|
899 | + $hof = & $this->HOF; |
|
900 | + $hofChanged = & $this->hasHOFChanged; |
|
901 | 901 | $new = false; |
902 | 902 | foreach ($typeList as $type) { |
903 | 903 | if (!isset($hofChanged[$type])) |
@@ -906,8 +906,8 @@ discard block |
||
906 | 906 | $hof[$type] = array(); |
907 | 907 | $new = true; |
908 | 908 | } |
909 | - $hof =& $hof[$type]; |
|
910 | - $hofChanged =& $hofChanged[$type]; |
|
909 | + $hof = & $hof[$type]; |
|
910 | + $hofChanged = & $hofChanged[$type]; |
|
911 | 911 | } |
912 | 912 | if ($hofChanged == null) { |
913 | 913 | $hofChanged = self::HOF_CHANGED; |
@@ -1059,7 +1059,7 @@ discard block |
||
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | private function setupMissionStep($missionID) { |
1062 | - $mission =& $this->missions[$missionID]; |
|
1062 | + $mission = & $this->missions[$missionID]; |
|
1063 | 1063 | if ($mission['On Step'] >= count(MISSIONS[$missionID]['Steps'])) { |
1064 | 1064 | // Nothing to do if this mission is already completed |
1065 | 1065 | return; |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | 'Starting Sector' => $this->getSectorID() |
1104 | 1104 | ); |
1105 | 1105 | |
1106 | - $this->missions[$missionID] =& $mission; |
|
1106 | + $this->missions[$missionID] = & $mission; |
|
1107 | 1107 | $this->setupMissionStep($missionID); |
1108 | 1108 | $this->rebuildMission($missionID); |
1109 | 1109 | |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | |
1163 | 1163 | public function claimMissionReward($missionID) { |
1164 | 1164 | $this->getMissions(); |
1165 | - $mission =& $this->missions[$missionID]; |
|
1165 | + $mission = & $this->missions[$missionID]; |
|
1166 | 1166 | if ($mission === false) { |
1167 | 1167 | throw new Exception('Unknown mission: ' . $missionID); |
1168 | 1168 | } |
@@ -76,8 +76,9 @@ discard block |
||
76 | 76 | return $this->getNewbieTurns() > 0; |
77 | 77 | } |
78 | 78 | public function setNewbieTurns($newbieTurns) { |
79 | - if ($this->newbieTurns == $newbieTurns) |
|
80 | - return; |
|
79 | + if ($this->newbieTurns == $newbieTurns) { |
|
80 | + return; |
|
81 | + } |
|
81 | 82 | $this->newbieTurns = $newbieTurns; |
82 | 83 | $this->hasChanged = true; |
83 | 84 | } |
@@ -87,8 +88,9 @@ discard block |
||
87 | 88 | } |
88 | 89 | |
89 | 90 | public function setShipTypeID($shipID) { |
90 | - if ($this->shipID == $shipID) |
|
91 | - return; |
|
91 | + if ($this->shipID == $shipID) { |
|
92 | + return; |
|
93 | + } |
|
92 | 94 | $this->shipID = $shipID; |
93 | 95 | $this->hasChanged = true; |
94 | 96 | } |
@@ -198,8 +200,9 @@ discard block |
||
198 | 200 | } |
199 | 201 | |
200 | 202 | $ship = $this->getShip(); |
201 | - if ($ship->hasIllegalGoods()) |
|
202 | - return false; |
|
203 | + if ($ship->hasIllegalGoods()) { |
|
204 | + return false; |
|
205 | + } |
|
203 | 206 | |
204 | 207 | if ($ship->getAttackRating() <= $this->getSafeAttackRating()) { |
205 | 208 | foreach ($sector->getFedRaceIDs() as $fedRaceID) { |
@@ -240,8 +243,9 @@ discard block |
||
240 | 243 | } |
241 | 244 | |
242 | 245 | public function setDead($bool) { |
243 | - if ($this->dead == $bool) |
|
244 | - return; |
|
246 | + if ($this->dead == $bool) { |
|
247 | + return; |
|
248 | + } |
|
245 | 249 | $this->dead = $bool; |
246 | 250 | $this->hasChanged = true; |
247 | 251 | } |
@@ -251,14 +255,16 @@ discard block |
||
251 | 255 | } |
252 | 256 | |
253 | 257 | public function increaseKills($kills) { |
254 | - if ($kills < 0) |
|
255 | - throw new Exception('Trying to increase negative kills.'); |
|
258 | + if ($kills < 0) { |
|
259 | + throw new Exception('Trying to increase negative kills.'); |
|
260 | + } |
|
256 | 261 | $this->setKills($this->kills + $kills); |
257 | 262 | } |
258 | 263 | |
259 | 264 | public function setKills($kills) { |
260 | - if ($this->kills == $kills) |
|
261 | - return; |
|
265 | + if ($this->kills == $kills) { |
|
266 | + return; |
|
267 | + } |
|
262 | 268 | $this->kills = $kills; |
263 | 269 | $this->hasChanged = true; |
264 | 270 | } |
@@ -268,14 +274,16 @@ discard block |
||
268 | 274 | } |
269 | 275 | |
270 | 276 | public function increaseDeaths($deaths) { |
271 | - if ($deaths < 0) |
|
272 | - throw new Exception('Trying to increase negative deaths.'); |
|
277 | + if ($deaths < 0) { |
|
278 | + throw new Exception('Trying to increase negative deaths.'); |
|
279 | + } |
|
273 | 280 | $this->setDeaths($this->getDeaths() + $deaths); |
274 | 281 | } |
275 | 282 | |
276 | 283 | public function setDeaths($deaths) { |
277 | - if ($this->deaths == $deaths) |
|
278 | - return; |
|
284 | + if ($this->deaths == $deaths) { |
|
285 | + return; |
|
286 | + } |
|
279 | 287 | $this->deaths = $deaths; |
280 | 288 | $this->hasChanged = true; |
281 | 289 | } |
@@ -297,24 +305,29 @@ discard block |
||
297 | 305 | } |
298 | 306 | |
299 | 307 | public function increaseAlignment($align) { |
300 | - if ($align < 0) |
|
301 | - throw new Exception('Trying to increase negative align.'); |
|
302 | - if ($align == 0) |
|
303 | - return; |
|
308 | + if ($align < 0) { |
|
309 | + throw new Exception('Trying to increase negative align.'); |
|
310 | + } |
|
311 | + if ($align == 0) { |
|
312 | + return; |
|
313 | + } |
|
304 | 314 | $align += $this->alignment; |
305 | 315 | $this->setAlignment($align); |
306 | 316 | } |
307 | 317 | public function decreaseAlignment($align) { |
308 | - if ($align < 0) |
|
309 | - throw new Exception('Trying to decrease negative align.'); |
|
310 | - if ($align == 0) |
|
311 | - return; |
|
318 | + if ($align < 0) { |
|
319 | + throw new Exception('Trying to decrease negative align.'); |
|
320 | + } |
|
321 | + if ($align == 0) { |
|
322 | + return; |
|
323 | + } |
|
312 | 324 | $align = $this->alignment - $align; |
313 | 325 | $this->setAlignment($align); |
314 | 326 | } |
315 | 327 | public function setAlignment($align) { |
316 | - if ($this->alignment == $align) |
|
317 | - return; |
|
328 | + if ($this->alignment == $align) { |
|
329 | + return; |
|
330 | + } |
|
318 | 331 | $this->alignment = $align; |
319 | 332 | $this->hasChanged = true; |
320 | 333 | } |
@@ -332,8 +345,9 @@ discard block |
||
332 | 345 | * This value is rounded because it is used primarily in HTML img widths. |
333 | 346 | */ |
334 | 347 | public function getNextLevelPercentAcquired() : int { |
335 | - if ($this->getNextLevelExperience() == $this->getThisLevelExperience()) |
|
336 | - return 100; |
|
348 | + if ($this->getNextLevelExperience() == $this->getThisLevelExperience()) { |
|
349 | + return 100; |
|
350 | + } |
|
337 | 351 | return max(0, min(100, IRound(($this->getExperience() - $this->getThisLevelExperience()) / ($this->getNextLevelExperience() - $this->getThisLevelExperience()) * 100))); |
338 | 352 | } |
339 | 353 | |
@@ -343,8 +357,10 @@ discard block |
||
343 | 357 | |
344 | 358 | public function getNextLevelExperience() { |
345 | 359 | $LEVELS_REQUIREMENTS = Globals::getLevelRequirements(); |
346 | - if (!isset($LEVELS_REQUIREMENTS[$this->getLevelID() + 1])) |
|
347 | - return $this->getThisLevelExperience(); //Return current level experience if on last level. |
|
360 | + if (!isset($LEVELS_REQUIREMENTS[$this->getLevelID() + 1])) { |
|
361 | + return $this->getThisLevelExperience(); |
|
362 | + } |
|
363 | + //Return current level experience if on last level. |
|
348 | 364 | return $LEVELS_REQUIREMENTS[$this->getLevelID() + 1]['Requirement']; |
349 | 365 | } |
350 | 366 | |
@@ -354,12 +370,15 @@ discard block |
||
354 | 370 | } |
355 | 371 | |
356 | 372 | public function setExperience($experience) { |
357 | - if ($this->experience == $experience) |
|
358 | - return; |
|
359 | - if ($experience < MIN_EXPERIENCE) |
|
360 | - $experience = MIN_EXPERIENCE; |
|
361 | - if ($experience > MAX_EXPERIENCE) |
|
362 | - $experience = MAX_EXPERIENCE; |
|
373 | + if ($this->experience == $experience) { |
|
374 | + return; |
|
375 | + } |
|
376 | + if ($experience < MIN_EXPERIENCE) { |
|
377 | + $experience = MIN_EXPERIENCE; |
|
378 | + } |
|
379 | + if ($experience > MAX_EXPERIENCE) { |
|
380 | + $experience = MAX_EXPERIENCE; |
|
381 | + } |
|
363 | 382 | $this->experience = $experience; |
364 | 383 | $this->hasChanged = true; |
365 | 384 | |
@@ -369,46 +388,57 @@ discard block |
||
369 | 388 | } |
370 | 389 | |
371 | 390 | public function increaseCredits($credits) { |
372 | - if ($credits < 0) |
|
373 | - throw new Exception('Trying to increase negative credits.'); |
|
374 | - if ($credits == 0) |
|
375 | - return; |
|
391 | + if ($credits < 0) { |
|
392 | + throw new Exception('Trying to increase negative credits.'); |
|
393 | + } |
|
394 | + if ($credits == 0) { |
|
395 | + return; |
|
396 | + } |
|
376 | 397 | $credits += $this->credits; |
377 | 398 | $this->setCredits($credits); |
378 | 399 | } |
379 | 400 | public function decreaseCredits($credits) { |
380 | - if ($credits < 0) |
|
381 | - throw new Exception('Trying to decrease negative credits.'); |
|
382 | - if ($credits == 0) |
|
383 | - return; |
|
401 | + if ($credits < 0) { |
|
402 | + throw new Exception('Trying to decrease negative credits.'); |
|
403 | + } |
|
404 | + if ($credits == 0) { |
|
405 | + return; |
|
406 | + } |
|
384 | 407 | $credits = $this->credits - $credits; |
385 | 408 | $this->setCredits($credits); |
386 | 409 | } |
387 | 410 | public function setCredits($credits) { |
388 | - if ($this->credits == $credits) |
|
389 | - return; |
|
390 | - if ($credits < 0) |
|
391 | - throw new Exception('Trying to set negative credits.'); |
|
392 | - if ($credits > MAX_MONEY) |
|
393 | - $credits = MAX_MONEY; |
|
411 | + if ($this->credits == $credits) { |
|
412 | + return; |
|
413 | + } |
|
414 | + if ($credits < 0) { |
|
415 | + throw new Exception('Trying to set negative credits.'); |
|
416 | + } |
|
417 | + if ($credits > MAX_MONEY) { |
|
418 | + $credits = MAX_MONEY; |
|
419 | + } |
|
394 | 420 | $this->credits = $credits; |
395 | 421 | $this->hasChanged = true; |
396 | 422 | } |
397 | 423 | |
398 | 424 | public function increaseExperience($experience) { |
399 | - if ($experience < 0) |
|
400 | - throw new Exception('Trying to increase negative experience.'); |
|
401 | - if ($experience == 0) |
|
402 | - return; |
|
425 | + if ($experience < 0) { |
|
426 | + throw new Exception('Trying to increase negative experience.'); |
|
427 | + } |
|
428 | + if ($experience == 0) { |
|
429 | + return; |
|
430 | + } |
|
403 | 431 | $newExperience = $this->experience + $experience; |
404 | 432 | $this->setExperience($newExperience); |
405 | 433 | $this->increaseHOF($experience, array('Experience', 'Total', 'Gain'), HOF_PUBLIC); |
406 | 434 | } |
407 | 435 | public function decreaseExperience($experience) { |
408 | - if ($experience < 0) |
|
409 | - throw new Exception('Trying to decrease negative experience.'); |
|
410 | - if ($experience == 0) |
|
411 | - return; |
|
436 | + if ($experience < 0) { |
|
437 | + throw new Exception('Trying to decrease negative experience.'); |
|
438 | + } |
|
439 | + if ($experience == 0) { |
|
440 | + return; |
|
441 | + } |
|
412 | 442 | $newExperience = $this->experience - $experience; |
413 | 443 | $this->setExperience($newExperience); |
414 | 444 | $this->decreaseHOF($experience, array('Experience', 'Total', 'Loss'), HOF_PUBLIC); |
@@ -419,8 +449,9 @@ discard block |
||
419 | 449 | } |
420 | 450 | |
421 | 451 | public function setLandedOnPlanet($bool) { |
422 | - if ($this->landedOnPlanet == $bool) |
|
423 | - return; |
|
452 | + if ($this->landedOnPlanet == $bool) { |
|
453 | + return; |
|
454 | + } |
|
424 | 455 | $this->landedOnPlanet = $bool; |
425 | 456 | $this->hasChanged = true; |
426 | 457 | } |
@@ -434,7 +465,9 @@ discard block |
||
434 | 465 | if ($this->level === null) { |
435 | 466 | $LEVELS_REQUIREMENTS = Globals::getLevelRequirements(); |
436 | 467 | foreach ($LEVELS_REQUIREMENTS as $level_id => $require) { |
437 | - if ($this->getExperience() >= $require['Requirement']) continue; |
|
468 | + if ($this->getExperience() >= $require['Requirement']) { |
|
469 | + continue; |
|
470 | + } |
|
438 | 471 | $this->level = $level_id - 1; |
439 | 472 | return $this->level; |
440 | 473 | } |
@@ -512,8 +545,9 @@ discard block |
||
512 | 545 | } |
513 | 546 | |
514 | 547 | public function setRaceID($raceID) { |
515 | - if ($this->raceID == $raceID) |
|
516 | - return; |
|
548 | + if ($this->raceID == $raceID) { |
|
549 | + return; |
|
550 | + } |
|
517 | 551 | $this->raceID = $raceID; |
518 | 552 | $this->hasChanged = true; |
519 | 553 | } |
@@ -535,8 +569,9 @@ discard block |
||
535 | 569 | } |
536 | 570 | |
537 | 571 | protected function setAllianceID($ID) { |
538 | - if ($this->allianceID == $ID) |
|
539 | - return; |
|
572 | + if ($this->allianceID == $ID) { |
|
573 | + return; |
|
574 | + } |
|
540 | 575 | $this->allianceID = $ID; |
541 | 576 | if ($this->allianceID != 0) { |
542 | 577 | $status = $this->hasNewbieStatus() ? 'NEWBIE' : 'VETERAN'; |
@@ -553,8 +588,7 @@ discard block |
||
553 | 588 | public function getAllianceDisplayName($linked = false, $includeAllianceID = false) { |
554 | 589 | if ($this->hasAlliance()) { |
555 | 590 | return $this->getAlliance()->getAllianceDisplayName($linked, $includeAllianceID); |
556 | - } |
|
557 | - else { |
|
591 | + } else { |
|
558 | 592 | return 'No Alliance'; |
559 | 593 | } |
560 | 594 | } |
@@ -582,8 +616,9 @@ discard block |
||
582 | 616 | } |
583 | 617 | |
584 | 618 | public function setCombatDronesKamikazeOnMines($bool) { |
585 | - if ($this->combatDronesKamikazeOnMines == $bool) |
|
586 | - return; |
|
619 | + if ($this->combatDronesKamikazeOnMines == $bool) { |
|
620 | + return; |
|
621 | + } |
|
587 | 622 | $this->combatDronesKamikazeOnMines = $bool; |
588 | 623 | $this->hasChanged = true; |
589 | 624 | } |
@@ -656,21 +691,24 @@ discard block |
||
656 | 691 | } |
657 | 692 | |
658 | 693 | public function setMilitaryPayment($amount) { |
659 | - if ($this->militaryPayment == $amount) |
|
660 | - return; |
|
694 | + if ($this->militaryPayment == $amount) { |
|
695 | + return; |
|
696 | + } |
|
661 | 697 | $this->militaryPayment = $amount; |
662 | 698 | $this->hasChanged = true; |
663 | 699 | } |
664 | 700 | |
665 | 701 | public function increaseMilitaryPayment($amount) { |
666 | - if ($amount < 0) |
|
667 | - throw new Exception('Trying to increase negative military payment.'); |
|
702 | + if ($amount < 0) { |
|
703 | + throw new Exception('Trying to increase negative military payment.'); |
|
704 | + } |
|
668 | 705 | $this->setMilitaryPayment($this->getMilitaryPayment() + $amount); |
669 | 706 | } |
670 | 707 | |
671 | 708 | public function decreaseMilitaryPayment($amount) { |
672 | - if ($amount < 0) |
|
673 | - throw new Exception('Trying to decrease negative military payment.'); |
|
709 | + if ($amount < 0) { |
|
710 | + throw new Exception('Trying to decrease negative military payment.'); |
|
711 | + } |
|
674 | 712 | $this->setMilitaryPayment($this->getMilitaryPayment() - $amount); |
675 | 713 | } |
676 | 714 | |
@@ -713,10 +751,11 @@ discard block |
||
713 | 751 | |
714 | 752 | protected function getNextBountyID() : int { |
715 | 753 | $keys = array_keys($this->getBounties()); |
716 | - if (count($keys) > 0) |
|
717 | - return max($keys) + 1; |
|
718 | - else |
|
719 | - return 0; |
|
754 | + if (count($keys) > 0) { |
|
755 | + return max($keys) + 1; |
|
756 | + } else { |
|
757 | + return 0; |
|
758 | + } |
|
720 | 759 | } |
721 | 760 | |
722 | 761 | protected function setBounty(array $bounty) : void { |
@@ -731,22 +770,25 @@ discard block |
||
731 | 770 | } |
732 | 771 | |
733 | 772 | public function increaseBountyAmount(int $bountyID, int $amount) : void { |
734 | - if ($amount < 0) |
|
735 | - throw new Exception('Trying to increase negative bounty.'); |
|
773 | + if ($amount < 0) { |
|
774 | + throw new Exception('Trying to increase negative bounty.'); |
|
775 | + } |
|
736 | 776 | $this->setBountyAmount($this->getBountyAmount($bountyID) + $amount); |
737 | 777 | } |
738 | 778 | |
739 | 779 | public function decreaseBountyAmount(int $bountyID, int $amount) : void { |
740 | - if ($amount < 0) |
|
741 | - throw new Exception('Trying to decrease negative bounty.'); |
|
780 | + if ($amount < 0) { |
|
781 | + throw new Exception('Trying to decrease negative bounty.'); |
|
782 | + } |
|
742 | 783 | $this->setBountyAmount($this->getBountyAmount($bountyID) + $amount); |
743 | 784 | } |
744 | 785 | |
745 | 786 | public function getCurrentBounty(string $type) : array { |
746 | 787 | $bounties = $this->getBounties(); |
747 | 788 | foreach ($bounties as $bounty) { |
748 | - if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) |
|
749 | - return $bounty; |
|
789 | + if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) { |
|
790 | + return $bounty; |
|
791 | + } |
|
750 | 792 | } |
751 | 793 | return $this->createBounty($type); |
752 | 794 | } |
@@ -754,8 +796,9 @@ discard block |
||
754 | 796 | public function hasCurrentBounty(string $type) : bool { |
755 | 797 | $bounties = $this->getBounties(); |
756 | 798 | foreach ($bounties as $bounty) { |
757 | - if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) |
|
758 | - return true; |
|
799 | + if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) { |
|
800 | + return true; |
|
801 | + } |
|
759 | 802 | } |
760 | 803 | return false; |
761 | 804 | } |
@@ -767,21 +810,24 @@ discard block |
||
767 | 810 | |
768 | 811 | protected function setCurrentBountyAmount(string $type, int $amount) : void { |
769 | 812 | $bounty = $this->getCurrentBounty($type); |
770 | - if ($bounty['Amount'] == $amount) |
|
771 | - return; |
|
813 | + if ($bounty['Amount'] == $amount) { |
|
814 | + return; |
|
815 | + } |
|
772 | 816 | $bounty['Amount'] = $amount; |
773 | 817 | $this->setBounty($bounty); |
774 | 818 | } |
775 | 819 | |
776 | 820 | public function increaseCurrentBountyAmount(string $type, int $amount) : void { |
777 | - if ($amount < 0) |
|
778 | - throw new Exception('Trying to increase negative current bounty.'); |
|
821 | + if ($amount < 0) { |
|
822 | + throw new Exception('Trying to increase negative current bounty.'); |
|
823 | + } |
|
779 | 824 | $this->setCurrentBountyAmount($type, $this->getCurrentBountyAmount($type) + $amount); |
780 | 825 | } |
781 | 826 | |
782 | 827 | public function decreaseCurrentBountyAmount(string $type, int $amount) : void { |
783 | - if ($amount < 0) |
|
784 | - throw new Exception('Trying to decrease negative current bounty.'); |
|
828 | + if ($amount < 0) { |
|
829 | + throw new Exception('Trying to decrease negative current bounty.'); |
|
830 | + } |
|
785 | 831 | $this->setCurrentBountyAmount($type, $this->getCurrentBountyAmount($type) - $amount); |
786 | 832 | } |
787 | 833 | |
@@ -792,21 +838,24 @@ discard block |
||
792 | 838 | |
793 | 839 | protected function setCurrentBountySmrCredits(string $type, int $credits) : void { |
794 | 840 | $bounty = $this->getCurrentBounty($type); |
795 | - if ($bounty['SmrCredits'] == $credits) |
|
796 | - return; |
|
841 | + if ($bounty['SmrCredits'] == $credits) { |
|
842 | + return; |
|
843 | + } |
|
797 | 844 | $bounty['SmrCredits'] = $credits; |
798 | 845 | $this->setBounty($bounty); |
799 | 846 | } |
800 | 847 | |
801 | 848 | public function increaseCurrentBountySmrCredits(string $type, int $credits) : void { |
802 | - if ($credits < 0) |
|
803 | - throw new Exception('Trying to increase negative current bounty.'); |
|
849 | + if ($credits < 0) { |
|
850 | + throw new Exception('Trying to increase negative current bounty.'); |
|
851 | + } |
|
804 | 852 | $this->setCurrentBountySmrCredits($type, $this->getCurrentBountySmrCredits($type) + $credits); |
805 | 853 | } |
806 | 854 | |
807 | 855 | public function decreaseCurrentBountySmrCredits(string $type, int $credits) : void { |
808 | - if ($credits < 0) |
|
809 | - throw new Exception('Trying to decrease negative current bounty.'); |
|
856 | + if ($credits < 0) { |
|
857 | + throw new Exception('Trying to decrease negative current bounty.'); |
|
858 | + } |
|
810 | 859 | $this->setCurrentBountySmrCredits($type, $this->getCurrentBountySmrCredits($type) - $credits); |
811 | 860 | } |
812 | 861 | |
@@ -824,51 +873,59 @@ discard block |
||
824 | 873 | |
825 | 874 | public function getHOF(array $typeList = null) { |
826 | 875 | $this->getHOFData(); |
827 | - if ($typeList == null) |
|
828 | - return $this->HOF; |
|
876 | + if ($typeList == null) { |
|
877 | + return $this->HOF; |
|
878 | + } |
|
829 | 879 | $hof = $this->HOF; |
830 | 880 | foreach ($typeList as $type) { |
831 | - if (!isset($hof[$type])) |
|
832 | - return 0; |
|
881 | + if (!isset($hof[$type])) { |
|
882 | + return 0; |
|
883 | + } |
|
833 | 884 | $hof = $hof[$type]; |
834 | 885 | } |
835 | 886 | return $hof; |
836 | 887 | } |
837 | 888 | |
838 | 889 | public function increaseHOF($amount, array $typeList, $visibility) { |
839 | - if ($amount < 0) |
|
840 | - throw new Exception('Trying to increase negative HOF: ' . implode(':', $typeList)); |
|
841 | - if ($amount == 0) |
|
842 | - return; |
|
890 | + if ($amount < 0) { |
|
891 | + throw new Exception('Trying to increase negative HOF: ' . implode(':', $typeList)); |
|
892 | + } |
|
893 | + if ($amount == 0) { |
|
894 | + return; |
|
895 | + } |
|
843 | 896 | $this->setHOF($this->getHOF($typeList) + $amount, $typeList, $visibility); |
844 | 897 | } |
845 | 898 | |
846 | 899 | public function decreaseHOF($amount, array $typeList, $visibility) { |
847 | - if ($amount < 0) |
|
848 | - throw new Exception('Trying to decrease negative HOF: ' . implode(':', $typeList)); |
|
849 | - if ($amount == 0) |
|
850 | - return; |
|
900 | + if ($amount < 0) { |
|
901 | + throw new Exception('Trying to decrease negative HOF: ' . implode(':', $typeList)); |
|
902 | + } |
|
903 | + if ($amount == 0) { |
|
904 | + return; |
|
905 | + } |
|
851 | 906 | $this->setHOF($this->getHOF($typeList) - $amount, $typeList, $visibility); |
852 | 907 | } |
853 | 908 | |
854 | 909 | public function setHOF($amount, array $typeList, $visibility) { |
855 | - if (is_array($this->getHOF($typeList))) |
|
856 | - throw new Exception('Trying to overwrite a HOF type: ' . implode(':', $typeList)); |
|
910 | + if (is_array($this->getHOF($typeList))) { |
|
911 | + throw new Exception('Trying to overwrite a HOF type: ' . implode(':', $typeList)); |
|
912 | + } |
|
857 | 913 | if ($this->isNPC()) { |
858 | 914 | // Don't store HOF for NPCs. |
859 | 915 | return; |
860 | 916 | } |
861 | - if ($this->getHOF($typeList) == $amount) |
|
862 | - return; |
|
863 | - if ($amount < 0) |
|
864 | - $amount = 0; |
|
917 | + if ($this->getHOF($typeList) == $amount) { |
|
918 | + return; |
|
919 | + } |
|
920 | + if ($amount < 0) { |
|
921 | + $amount = 0; |
|
922 | + } |
|
865 | 923 | $this->getHOF(); |
866 | 924 | |
867 | 925 | $hofType = implode(':', $typeList); |
868 | 926 | if (!isset(self::$HOFVis[$hofType])) { |
869 | 927 | self::$hasHOFVisChanged[$hofType] = self::HOF_NEW; |
870 | - } |
|
871 | - else if (self::$HOFVis[$hofType] != $visibility) { |
|
928 | + } else if (self::$HOFVis[$hofType] != $visibility) { |
|
872 | 929 | self::$hasHOFVisChanged[$hofType] = self::HOF_CHANGED; |
873 | 930 | } |
874 | 931 | self::$HOFVis[$hofType] = $visibility; |
@@ -877,8 +934,9 @@ discard block |
||
877 | 934 | $hofChanged =& $this->hasHOFChanged; |
878 | 935 | $new = false; |
879 | 936 | foreach ($typeList as $type) { |
880 | - if (!isset($hofChanged[$type])) |
|
881 | - $hofChanged[$type] = array(); |
|
937 | + if (!isset($hofChanged[$type])) { |
|
938 | + $hofChanged[$type] = array(); |
|
939 | + } |
|
882 | 940 | if (!isset($hof[$type])) { |
883 | 941 | $hof[$type] = array(); |
884 | 942 | $new = true; |
@@ -888,8 +946,9 @@ discard block |
||
888 | 946 | } |
889 | 947 | if ($hofChanged == null) { |
890 | 948 | $hofChanged = self::HOF_CHANGED; |
891 | - if ($new) |
|
892 | - $hofChanged = self::HOF_NEW; |
|
949 | + if ($new) { |
|
950 | + $hofChanged = self::HOF_NEW; |
|
951 | + } |
|
893 | 952 | } |
894 | 953 | $hof = $amount; |
895 | 954 | } |
@@ -954,8 +1013,9 @@ discard block |
||
954 | 1013 | } |
955 | 1014 | |
956 | 1015 | public function setLastActive($lastActive) { |
957 | - if ($this->lastActive == $lastActive) |
|
958 | - return; |
|
1016 | + if ($this->lastActive == $lastActive) { |
|
1017 | + return; |
|
1018 | + } |
|
959 | 1019 | $this->lastActive = $lastActive; |
960 | 1020 | $this->hasChanged = true; |
961 | 1021 | } |
@@ -965,8 +1025,9 @@ discard block |
||
965 | 1025 | } |
966 | 1026 | |
967 | 1027 | public function setLastCPLAction($time) { |
968 | - if ($this->lastCPLAction == $time) |
|
969 | - return; |
|
1028 | + if ($this->lastCPLAction == $time) { |
|
1029 | + return; |
|
1030 | + } |
|
970 | 1031 | $this->lastCPLAction = $time; |
971 | 1032 | $this->hasChanged = true; |
972 | 1033 | } |
@@ -1007,8 +1068,9 @@ discard block |
||
1007 | 1068 | |
1008 | 1069 | protected function getMission($missionID) { |
1009 | 1070 | $missions = $this->getMissions(); |
1010 | - if (isset($missions[$missionID])) |
|
1011 | - return $missions[$missionID]; |
|
1071 | + if (isset($missions[$missionID])) { |
|
1072 | + return $missions[$missionID]; |
|
1073 | + } |
|
1012 | 1074 | return false; |
1013 | 1075 | } |
1014 | 1076 | |
@@ -1067,8 +1129,9 @@ discard block |
||
1067 | 1129 | public function addMission($missionID, $step = 0) { |
1068 | 1130 | $this->getMissions(); |
1069 | 1131 | |
1070 | - if (isset($this->missions[$missionID])) |
|
1071 | - return; |
|
1132 | + if (isset($this->missions[$missionID])) { |
|
1133 | + return; |
|
1134 | + } |
|
1072 | 1135 | $sector = 0; |
1073 | 1136 | |
1074 | 1137 | $mission = array( |
@@ -1097,8 +1160,7 @@ discard block |
||
1097 | 1160 | if ($mission['On Step'] >= count(MISSIONS[$missionID]['Steps'])) { |
1098 | 1161 | // If we have completed this mission just use false to indicate no current task. |
1099 | 1162 | $currentStep = false; |
1100 | - } |
|
1101 | - else { |
|
1163 | + } else { |
|
1102 | 1164 | $currentStep = MISSIONS[$missionID]['Steps'][$mission['On Step']]; |
1103 | 1165 | $currentStep['Text'] = str_replace(array('<Race>', '<Sector>', '<Starting Sector>', '<trader>'), array($this->getRaceID(), $mission['Sector'], $mission['Starting Sector'], $this->playerName), $currentStep['Text']); |
1104 | 1166 | if (isset($currentStep['Task'])) { |
@@ -1106,8 +1168,7 @@ discard block |
||
1106 | 1168 | } |
1107 | 1169 | if (isset($currentStep['Level'])) { |
1108 | 1170 | $currentStep['Level'] = str_replace('<Player Level>', $this->getLevelID(), $currentStep['Level']); |
1109 | - } |
|
1110 | - else { |
|
1171 | + } else { |
|
1111 | 1172 | $currentStep['Level'] = 0; |
1112 | 1173 | } |
1113 | 1174 | } |
@@ -1235,12 +1296,15 @@ discard block |
||
1235 | 1296 | } |
1236 | 1297 | |
1237 | 1298 | public function canSee(AbstractSmrPlayer $otherPlayer) { |
1238 | - if (!$otherPlayer->getShip()->isCloaked()) |
|
1239 | - return true; |
|
1240 | - if ($this->sameAlliance($otherPlayer)) |
|
1241 | - return true; |
|
1242 | - if ($this->getExperience() >= $otherPlayer->getExperience()) |
|
1243 | - return true; |
|
1299 | + if (!$otherPlayer->getShip()->isCloaked()) { |
|
1300 | + return true; |
|
1301 | + } |
|
1302 | + if ($this->sameAlliance($otherPlayer)) { |
|
1303 | + return true; |
|
1304 | + } |
|
1305 | + if ($this->getExperience() >= $otherPlayer->getExperience()) { |
|
1306 | + return true; |
|
1307 | + } |
|
1244 | 1308 | return false; |
1245 | 1309 | } |
1246 | 1310 | |
@@ -1293,10 +1357,12 @@ discard block |
||
1293 | 1357 | } |
1294 | 1358 | |
1295 | 1359 | public function meetsAlignmentRestriction($restriction) { |
1296 | - if ($restriction < 0) |
|
1297 | - return $this->getAlignment() <= $restriction; |
|
1298 | - if ($restriction > 0) |
|
1299 | - return $this->getAlignment() >= $restriction; |
|
1360 | + if ($restriction < 0) { |
|
1361 | + return $this->getAlignment() <= $restriction; |
|
1362 | + } |
|
1363 | + if ($restriction > 0) { |
|
1364 | + return $this->getAlignment() >= $restriction; |
|
1365 | + } |
|
1300 | 1366 | return true; |
1301 | 1367 | } |
1302 | 1368 | |
@@ -1319,8 +1385,9 @@ discard block |
||
1319 | 1385 | if (!isset($this->visitedSectors)) { |
1320 | 1386 | $this->visitedSectors = array(); |
1321 | 1387 | $this->db->query('SELECT sector_id FROM player_visited_sector WHERE ' . $this->SQL); |
1322 | - while ($this->db->nextRecord()) |
|
1323 | - $this->visitedSectors[$this->db->getInt('sector_id')] = false; |
|
1388 | + while ($this->db->nextRecord()) { |
|
1389 | + $this->visitedSectors[$this->db->getInt('sector_id')] = false; |
|
1390 | + } |
|
1324 | 1391 | } |
1325 | 1392 | return !isset($this->visitedSectors[$sectorID]); |
1326 | 1393 | } |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | public function isAttacking(array &$board, array &$hasMoved, $king, $x = -1, $y = -1) { |
55 | - $moves =& $this->getPossibleMoves($board, $hasMoved, null, true); |
|
56 | - foreach($moves as &$move) { |
|
57 | - $p =& $board[$move[1]][$move[0]]; |
|
58 | - if(($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
55 | + $moves = & $this->getPossibleMoves($board, $hasMoved, null, true); |
|
56 | + foreach ($moves as &$move) { |
|
57 | + $p = & $board[$move[1]][$move[0]]; |
|
58 | + if (($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
59 | 59 | return true; |
60 | 60 | } |
61 | 61 | } |
@@ -64,130 +64,130 @@ discard block |
||
64 | 64 | |
65 | 65 | public function &getPossibleMoves(array &$board, array &$hasMoved, $forAccountID = null, $attackingCheck = false) { |
66 | 66 | $moves = array(); |
67 | - if($forAccountID == null || $this->accountID == $forAccountID) { |
|
68 | - if($this->pieceID==self::PAWN) { |
|
69 | - $dirY = $this->colour==ChessGame::PLAYER_BLACK ? 1 : -1; |
|
70 | - $moveY = $this->y+$dirY; |
|
67 | + if ($forAccountID == null || $this->accountID == $forAccountID) { |
|
68 | + if ($this->pieceID == self::PAWN) { |
|
69 | + $dirY = $this->colour == ChessGame::PLAYER_BLACK ? 1 : -1; |
|
70 | + $moveY = $this->y + $dirY; |
|
71 | 71 | //Pawn forward movement is not attacking - so don't check it if doing an attacking check. |
72 | - if(!$attackingCheck) { |
|
73 | - if(ChessGame::isValidCoord($this->x, $moveY, $board) && $board[$moveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $moveY)) { |
|
74 | - $moves[] = array($this->x,$moveY); |
|
72 | + if (!$attackingCheck) { |
|
73 | + if (ChessGame::isValidCoord($this->x, $moveY, $board) && $board[$moveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $moveY)) { |
|
74 | + $moves[] = array($this->x, $moveY); |
|
75 | 75 | } |
76 | 76 | $doubleMoveY = $moveY + $dirY; |
77 | - if($this->y-$dirY == 0 || $this->y-$dirY*2 == count($board)) { //Double move first move |
|
78 | - if($board[$moveY][$this->x] == null && $board[$doubleMoveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $doubleMoveY)) { |
|
79 | - $moves[] = array($this->x,$doubleMoveY); |
|
77 | + if ($this->y - $dirY == 0 || $this->y - $dirY * 2 == count($board)) { //Double move first move |
|
78 | + if ($board[$moveY][$this->x] == null && $board[$doubleMoveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $doubleMoveY)) { |
|
79 | + $moves[] = array($this->x, $doubleMoveY); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
83 | - for($i=-1;$i<2;$i+=2) { |
|
84 | - $moveX = $this->x+$i; |
|
85 | - if(ChessGame::isValidCoord($moveX, $moveY, $board)) { |
|
86 | - if($attackingCheck || |
|
83 | + for ($i = -1; $i < 2; $i += 2) { |
|
84 | + $moveX = $this->x + $i; |
|
85 | + if (ChessGame::isValidCoord($moveX, $moveY, $board)) { |
|
86 | + if ($attackingCheck || |
|
87 | 87 | ((($hasMoved[ChessPiece::PAWN][0] == $moveX && $hasMoved[ChessPiece::PAWN][1] == $this->y) || |
88 | - ($board[$moveY][$moveX] != null && $board[$moveY][$moveX]->colour!=$this->colour)) |
|
88 | + ($board[$moveY][$moveX] != null && $board[$moveY][$moveX]->colour != $this->colour)) |
|
89 | 89 | && $this->isSafeMove($board, $hasMoved, $moveX, $moveY))) { |
90 | - $moves[] = array($moveX,$moveY); |
|
90 | + $moves[] = array($moveX, $moveY); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | - else if($this->pieceID==self::KING) { |
|
96 | - for($i = -1; $i < 2; $i++) { |
|
97 | - for($j = -1; $j < 2; $j++) { |
|
98 | - if($i!=0 || $j!=0) { |
|
99 | - $this->addMove($this->x+$i, $this->y+$j, $board, $moves, $hasMoved, $attackingCheck); |
|
95 | + else if ($this->pieceID == self::KING) { |
|
96 | + for ($i = -1; $i < 2; $i++) { |
|
97 | + for ($j = -1; $j < 2; $j++) { |
|
98 | + if ($i != 0 || $j != 0) { |
|
99 | + $this->addMove($this->x + $i, $this->y + $j, $board, $moves, $hasMoved, $attackingCheck); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | //Castling is not attacking - so don't check it if doing an attacking check. |
104 | - if(!$attackingCheck && !$hasMoved[$this->colour][ChessPiece::KING] && !ChessGame::isPlayerChecked($board, $hasMoved, $this->colour)) { |
|
105 | - if(!$hasMoved[$this->colour][ChessPiece::ROOK]['Queen'] && |
|
106 | - ChessGame::isValidCoord($this->x-1, $this->y, $board) && $board[$this->y][$this->x-1] == null && |
|
107 | - ChessGame::isValidCoord($this->x-3, $this->y, $board) && $board[$this->y][$this->x-3] == null && |
|
108 | - $this->isSafeMove($board, $hasMoved, $this->x-1, $this->y)) { |
|
109 | - $this->addMove($this->x-2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
104 | + if (!$attackingCheck && !$hasMoved[$this->colour][ChessPiece::KING] && !ChessGame::isPlayerChecked($board, $hasMoved, $this->colour)) { |
|
105 | + if (!$hasMoved[$this->colour][ChessPiece::ROOK]['Queen'] && |
|
106 | + ChessGame::isValidCoord($this->x - 1, $this->y, $board) && $board[$this->y][$this->x - 1] == null && |
|
107 | + ChessGame::isValidCoord($this->x - 3, $this->y, $board) && $board[$this->y][$this->x - 3] == null && |
|
108 | + $this->isSafeMove($board, $hasMoved, $this->x - 1, $this->y)) { |
|
109 | + $this->addMove($this->x - 2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
110 | 110 | } |
111 | - if(!$hasMoved[$this->colour][ChessPiece::ROOK]['King'] && |
|
112 | - ChessGame::isValidCoord($this->x+1, $this->y, $board) && $board[$this->y][$this->x+1] == null && |
|
113 | - $this->isSafeMove($board, $hasMoved, $this->x+1, $this->y)) { |
|
114 | - $this->addMove($this->x+2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
111 | + if (!$hasMoved[$this->colour][ChessPiece::ROOK]['King'] && |
|
112 | + ChessGame::isValidCoord($this->x + 1, $this->y, $board) && $board[$this->y][$this->x + 1] == null && |
|
113 | + $this->isSafeMove($board, $hasMoved, $this->x + 1, $this->y)) { |
|
114 | + $this->addMove($this->x + 2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
118 | - else if($this->pieceID==self::QUEEN) { |
|
118 | + else if ($this->pieceID == self::QUEEN) { |
|
119 | 119 | $moveX = $this->x; |
120 | 120 | $moveY = $this->y; |
121 | - while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
121 | + while ($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
122 | 122 | $moveX = $this->x; |
123 | 123 | $moveY = $this->y; |
124 | - while($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
124 | + while ($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
125 | 125 | $moveX = $this->x; |
126 | 126 | $moveY = $this->y; |
127 | - while($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
127 | + while ($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
128 | 128 | $moveX = $this->x; |
129 | 129 | $moveY = $this->y; |
130 | - while($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
130 | + while ($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
131 | 131 | $moveX = $this->x; |
132 | 132 | $moveY = $this->y; |
133 | - while($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
133 | + while ($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
134 | 134 | $moveX = $this->x; |
135 | 135 | $moveY = $this->y; |
136 | - while($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
136 | + while ($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
137 | 137 | $moveX = $this->x; |
138 | 138 | $moveY = $this->y; |
139 | - while($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
139 | + while ($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
140 | 140 | $moveX = $this->x; |
141 | 141 | $moveY = $this->y; |
142 | - while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
142 | + while ($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
143 | 143 | } |
144 | - else if($this->pieceID==self::ROOK) { |
|
144 | + else if ($this->pieceID == self::ROOK) { |
|
145 | 145 | $moveX = $this->x; |
146 | 146 | $moveY = $this->y; |
147 | - while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
147 | + while ($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
148 | 148 | $moveX = $this->x; |
149 | 149 | $moveY = $this->y; |
150 | - while($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
150 | + while ($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
151 | 151 | $moveX = $this->x; |
152 | 152 | $moveY = $this->y; |
153 | - while($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
153 | + while ($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
154 | 154 | $moveX = $this->x; |
155 | 155 | $moveY = $this->y; |
156 | - while($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
156 | + while ($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
157 | 157 | } |
158 | - else if($this->pieceID==self::BISHOP) { |
|
158 | + else if ($this->pieceID == self::BISHOP) { |
|
159 | 159 | $moveX = $this->x; |
160 | 160 | $moveY = $this->y; |
161 | - while($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
161 | + while ($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
162 | 162 | $moveX = $this->x; |
163 | 163 | $moveY = $this->y; |
164 | - while($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
164 | + while ($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
165 | 165 | $moveX = $this->x; |
166 | 166 | $moveY = $this->y; |
167 | - while($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
167 | + while ($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
168 | 168 | $moveX = $this->x; |
169 | 169 | $moveY = $this->y; |
170 | - while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
170 | + while ($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
171 | 171 | } |
172 | - else if($this->pieceID==self::KNIGHT) { |
|
173 | - $moveX = $this->x-1; |
|
174 | - $moveY = $this->y-2; |
|
175 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2up-left |
|
172 | + else if ($this->pieceID == self::KNIGHT) { |
|
173 | + $moveX = $this->x - 1; |
|
174 | + $moveY = $this->y - 2; |
|
175 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2up-left |
|
176 | 176 | $moveX += 2; |
177 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2up-right |
|
178 | - $moveY = $this->y+2; |
|
179 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2down-right |
|
177 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2up-right |
|
178 | + $moveY = $this->y + 2; |
|
179 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2down-right |
|
180 | 180 | $moveX -= 2; |
181 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2down-left |
|
182 | - $moveX = $this->x-2; |
|
183 | - $moveY = $this->y-1; |
|
184 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2left-up |
|
181 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2down-left |
|
182 | + $moveX = $this->x - 2; |
|
183 | + $moveY = $this->y - 1; |
|
184 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2left-up |
|
185 | 185 | $moveY += 2; |
186 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2left-down |
|
187 | - $moveX = $this->x+2; |
|
188 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2right-down |
|
186 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2left-down |
|
187 | + $moveX = $this->x + 2; |
|
188 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2right-down |
|
189 | 189 | $moveY -= 2; |
190 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2right-up |
|
190 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2right-up |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | private function addMove($toX, $toY, array &$board, array &$moves, array &$hasMoved = null, $attackingCheck = true) { |
198 | - if(ChessGame::isValidCoord($toX, $toY, $board)) { |
|
199 | - if(($board[$toY][$toX] == null || $board[$toY][$toX]->colour!=$this->colour)) { |
|
198 | + if (ChessGame::isValidCoord($toX, $toY, $board)) { |
|
199 | + if (($board[$toY][$toX] == null || $board[$toY][$toX]->colour != $this->colour)) { |
|
200 | 200 | //We can only actually move to this position if it is safe to do so, however we can pass through it looking for a safe move so we still want to return true. |
201 | - if(($attackingCheck == true || $this->isSafeMove($board, $hasMoved, $toX, $toY))) { |
|
202 | - $moves[] = array($toX,$toY); |
|
201 | + if (($attackingCheck == true || $this->isSafeMove($board, $hasMoved, $toX, $toY))) { |
|
202 | + $moves[] = array($toX, $toY); |
|
203 | 203 | } |
204 | 204 | return true; |
205 | 205 | } |
@@ -208,30 +208,30 @@ discard block |
||
208 | 208 | } |
209 | 209 | |
210 | 210 | public function promote($pawnPromotionPieceID, array &$board) { |
211 | - if($pawnPromotionPieceID==null) { |
|
211 | + if ($pawnPromotionPieceID == null) { |
|
212 | 212 | throw new Exception('Promotion piece cannot be null on a promote.'); |
213 | 213 | } |
214 | 214 | $takenNos = array(); |
215 | - foreach($board as $row) { |
|
216 | - foreach($row as $piece) { |
|
217 | - if($piece != null && $piece->pieceID == $pawnPromotionPieceID && $piece->colour == $this->colour) { |
|
215 | + foreach ($board as $row) { |
|
216 | + foreach ($row as $piece) { |
|
217 | + if ($piece != null && $piece->pieceID == $pawnPromotionPieceID && $piece->colour == $this->colour) { |
|
218 | 218 | $takenNos[$piece->pieceNo] = true; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | } |
222 | - $i=0; |
|
223 | - while(isset($takenNos[$i])) { |
|
222 | + $i = 0; |
|
223 | + while (isset($takenNos[$i])) { |
|
224 | 224 | $i++; |
225 | 225 | } |
226 | 226 | return array('PieceID' => $pawnPromotionPieceID, 'PieceNo' => $i); |
227 | 227 | } |
228 | 228 | |
229 | 229 | public function getPieceLetter() { |
230 | - return self::getLetterForPiece($this->pieceID,$this->colour); |
|
230 | + return self::getLetterForPiece($this->pieceID, $this->colour); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | public function getPieceSymbol() { |
234 | - return self::getSymbolForPiece($this->pieceID,$this->colour); |
|
234 | + return self::getSymbolForPiece($this->pieceID, $this->colour); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | public static function getSymbolForPiece($pieceID, $colour) { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } |
240 | 240 | |
241 | 241 | public static function getLetterForPiece($pieceID, $colour) { |
242 | - switch($pieceID) { |
|
242 | + switch ($pieceID) { |
|
243 | 243 | case self::KING: |
244 | 244 | $letter = 'k'; |
245 | 245 | break; |
@@ -260,14 +260,14 @@ discard block |
||
260 | 260 | $letter = 'p'; |
261 | 261 | break; |
262 | 262 | } |
263 | - if($colour == ChessGame::PLAYER_WHITE) { |
|
263 | + if ($colour == ChessGame::PLAYER_WHITE) { |
|
264 | 264 | $letter = strtoupper($letter); |
265 | 265 | } |
266 | 266 | return $letter; |
267 | 267 | } |
268 | 268 | |
269 | 269 | public static function getPieceForLetter($letter) { |
270 | - switch($letter) { |
|
270 | + switch ($letter) { |
|
271 | 271 | case 'k': |
272 | 272 | case 'K': |
273 | 273 | return self::KING; |
@@ -91,8 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | - } |
|
95 | - else if($this->pieceID==self::KING) { |
|
94 | + } else if($this->pieceID==self::KING) { |
|
96 | 95 | for($i = -1; $i < 2; $i++) { |
97 | 96 | for($j = -1; $j < 2; $j++) { |
98 | 97 | if($i!=0 || $j!=0) { |
@@ -114,8 +113,7 @@ discard block |
||
114 | 113 | $this->addMove($this->x+2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
115 | 114 | } |
116 | 115 | } |
117 | - } |
|
118 | - else if($this->pieceID==self::QUEEN) { |
|
116 | + } else if($this->pieceID==self::QUEEN) { |
|
119 | 117 | $moveX = $this->x; |
120 | 118 | $moveY = $this->y; |
121 | 119 | while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
@@ -140,8 +138,7 @@ discard block |
||
140 | 138 | $moveX = $this->x; |
141 | 139 | $moveY = $this->y; |
142 | 140 | while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
143 | - } |
|
144 | - else if($this->pieceID==self::ROOK) { |
|
141 | + } else if($this->pieceID==self::ROOK) { |
|
145 | 142 | $moveX = $this->x; |
146 | 143 | $moveY = $this->y; |
147 | 144 | while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
@@ -154,8 +151,7 @@ discard block |
||
154 | 151 | $moveX = $this->x; |
155 | 152 | $moveY = $this->y; |
156 | 153 | while($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
157 | - } |
|
158 | - else if($this->pieceID==self::BISHOP) { |
|
154 | + } else if($this->pieceID==self::BISHOP) { |
|
159 | 155 | $moveX = $this->x; |
160 | 156 | $moveY = $this->y; |
161 | 157 | while($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
@@ -168,8 +164,7 @@ discard block |
||
168 | 164 | $moveX = $this->x; |
169 | 165 | $moveY = $this->y; |
170 | 166 | while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
171 | - } |
|
172 | - else if($this->pieceID==self::KNIGHT) { |
|
167 | + } else if($this->pieceID==self::KNIGHT) { |
|
173 | 168 | $moveX = $this->x-1; |
174 | 169 | $moveY = $this->y-2; |
175 | 170 | $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2up-left |
@@ -92,12 +92,14 @@ discard block |
||
92 | 92 | $sectorsTravelled = 0; |
93 | 93 | $visitedSectors = array(); |
94 | 94 | $visitedSectors[$checkSector->getSectorID()] = true; |
95 | - if ($x == 'Distance') |
|
96 | - $distances[0][$checkSector->getSectorID()] = new Distance($gameID, $checkSector->getSectorID()); |
|
95 | + if ($x == 'Distance') { |
|
96 | + $distances[0][$checkSector->getSectorID()] = new Distance($gameID, $checkSector->getSectorID()); |
|
97 | + } |
|
97 | 98 | |
98 | 99 | $distanceQ = array(); |
99 | - for ($i = 0; $i <= TURNS_WARP_SECTOR_EQUIVALENCE; $i++) |
|
100 | - $distanceQ[] = array(); |
|
100 | + for ($i = 0; $i <= TURNS_WARP_SECTOR_EQUIVALENCE; $i++) { |
|
101 | + $distanceQ[] = array(); |
|
102 | + } |
|
101 | 103 | //Warps first as a slight optimisation due to how visitedSectors is set. |
102 | 104 | if ($checkSector->hasWarp() === true) { |
103 | 105 | $d = new Distance($gameID, $checkSector->getSectorID()); |
@@ -115,8 +117,9 @@ discard block |
||
115 | 117 | $maybeWarps = 0; |
116 | 118 | while ($maybeWarps <= TURNS_WARP_SECTOR_EQUIVALENCE) { |
117 | 119 | $sectorsTravelled++; |
118 | - if ($sectorsTravelled > $distanceLimit) |
|
119 | - return $distances; |
|
120 | + if ($sectorsTravelled > $distanceLimit) { |
|
121 | + return $distances; |
|
122 | + } |
|
120 | 123 | if ($x == 'Distance') { |
121 | 124 | $distances[$sectorsTravelled] = array(); |
122 | 125 | } |
@@ -134,11 +137,11 @@ discard block |
||
134 | 137 | $checkSector = SmrSector::getSector($gameID, $checkSectorID); |
135 | 138 | if ($x == 'Distance') { |
136 | 139 | $distances[$sectorsTravelled][$checkSector->getSectorID()] = $distance; |
137 | - } |
|
138 | - else if (($needsToHaveBeenExploredBy === null || $needsToHaveBeenExploredBy->hasVisitedSector($checkSector->getSectorID())) === true |
|
140 | + } else if (($needsToHaveBeenExploredBy === null || $needsToHaveBeenExploredBy->hasVisitedSector($checkSector->getSectorID())) === true |
|
139 | 141 | && $checkSector->hasX($x, $player) === true) { |
140 | - if ($useFirst === true) |
|
141 | - return $distance; |
|
142 | + if ($useFirst === true) { |
|
143 | + return $distance; |
|
144 | + } |
|
142 | 145 | $distances[$checkSector->getSectorID()] = $distance; |
143 | 146 | } |
144 | 147 | //Warps first as a slight optimisation due to how visitedSectors is set. |
@@ -72,8 +72,7 @@ |
||
72 | 72 | $return = unserialize($db->getField('info')); |
73 | 73 | $return->regenerate($player); |
74 | 74 | self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] =& $return; |
75 | - } |
|
76 | - else { |
|
75 | + } else { |
|
77 | 76 | self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = new DummyShip($player); |
78 | 77 | } |
79 | 78 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $this->cargo_left = $this->getCargoHolds(); |
18 | 18 | } |
19 | 19 | protected function doFullUNO() { |
20 | - foreach($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
20 | + foreach ($this->getMaxHardware() as $hardwareTypeID => $max) { |
|
21 | 21 | $this->hardware[$hardwareTypeID] = $max; |
22 | 22 | $this->oldHardware[$hardwareTypeID] = $max; |
23 | 23 | } |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function getIllusionShip() { |
50 | - if(!isset($this->illusionShip)) { |
|
51 | - $this->illusionShip=false; |
|
50 | + if (!isset($this->illusionShip)) { |
|
51 | + $this->illusionShip = false; |
|
52 | 52 | } |
53 | 53 | return $this->illusionShip; |
54 | 54 | } |
@@ -58,20 +58,20 @@ discard block |
||
58 | 58 | $db = new SmrMySqlDatabase(); |
59 | 59 | $db->query('REPLACE INTO cached_dummys ' . |
60 | 60 | '(type, id, info) ' . |
61 | - 'VALUES (\'DummyShip\', '.$db->escapeString($this->getPlayer()->getPlayerName()).', '.$db->escapeString($cache).')'); |
|
61 | + 'VALUES (\'DummyShip\', ' . $db->escapeString($this->getPlayer()->getPlayerName()) . ', ' . $db->escapeString($cache) . ')'); |
|
62 | 62 | unserialize($cache); |
63 | 63 | } |
64 | 64 | |
65 | 65 | public static function getCachedDummyShip(AbstractSmrPlayer $player) { |
66 | - if(!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
66 | + if (!isset(self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()])) { |
|
67 | 67 | $db = new SmrMySqlDatabase(); |
68 | 68 | $db->query('SELECT info FROM cached_dummys |
69 | 69 | WHERE type = \'DummyShip\' |
70 | 70 | AND id = ' . $db->escapeString($player->getPlayerName()) . ' LIMIT 1'); |
71 | - if($db->nextRecord()) { |
|
71 | + if ($db->nextRecord()) { |
|
72 | 72 | $return = unserialize($db->getField('info')); |
73 | 73 | $return->regenerate($player); |
74 | - self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] =& $return; |
|
74 | + self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = & $return; |
|
75 | 75 | } |
76 | 76 | else { |
77 | 77 | self::$CACHED_DUMMY_SHIPS[$player->getPlayerName()] = new DummyShip($player); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $db->query('SELECT id FROM cached_dummys |
86 | 86 | WHERE type = \'DummyShip\''); |
87 | 87 | $dummyNames = array(); |
88 | - while($db->nextRecord()) { |
|
88 | + while ($db->nextRecord()) { |
|
89 | 89 | $dummyNames[] = $db->getField('id'); |
90 | 90 | } |
91 | 91 | return $dummyNames; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | |
96 | 96 | public function __sleep() { |
97 | - return array('gameID','weapons'); |
|
97 | + return array('gameID', 'weapons'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | public function __wakeup() { |
@@ -549,7 +549,7 @@ |
||
549 | 549 | */ |
550 | 550 | public function setWarp(SmrSector $warp) { |
551 | 551 | if ($this->getWarp() == $warp->getSectorID() && |
552 | - $warp->getWarp() == $this->getSectorID()) { |
|
552 | + $warp->getWarp() == $this->getSectorID()) { |
|
553 | 553 | // Warps are already set correctly! |
554 | 554 | return; |
555 | 555 | } |
@@ -126,15 +126,13 @@ discard block |
||
126 | 126 | $this->links['Right'] = $db->getInt('link_right'); |
127 | 127 | } |
128 | 128 | $this->warp = $db->getInt('warp'); |
129 | - } |
|
130 | - else if ($create) { |
|
129 | + } else if ($create) { |
|
131 | 130 | $this->battles = 0; |
132 | 131 | $this->links = array(); |
133 | 132 | $this->warp = 0; |
134 | 133 | $this->isNew = true; |
135 | 134 | return; |
136 | - } |
|
137 | - else { |
|
135 | + } else { |
|
138 | 136 | throw new SectorNotFoundException('No sector ' . $sectorID . ' in game ' . $gameID); |
139 | 137 | } |
140 | 138 | } |
@@ -167,52 +165,59 @@ discard block |
||
167 | 165 | } |
168 | 166 | |
169 | 167 | public function markVisited(AbstractSmrPlayer $player) { |
170 | - if ($this->hasPort()) |
|
171 | - $this->getPort()->addCachePort($player->getAccountID()); |
|
168 | + if ($this->hasPort()) { |
|
169 | + $this->getPort()->addCachePort($player->getAccountID()); |
|
170 | + } |
|
172 | 171 | |
173 | 172 | //now delete the entry from visited |
174 | - if (!$this->isVisited($player)) |
|
175 | - $this->db->query('DELETE FROM player_visited_sector WHERE ' . $this->SQL . ' |
|
173 | + if (!$this->isVisited($player)) { |
|
174 | + $this->db->query('DELETE FROM player_visited_sector WHERE ' . $this->SQL . ' |
|
176 | 175 | AND account_id = ' . $this->db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); |
176 | + } |
|
177 | 177 | $this->visited[$player->getAccountID()] = true; |
178 | 178 | } |
179 | 179 | |
180 | 180 | public function hasWeaponShop() { |
181 | 181 | foreach ($this->getLocations() as $location) { |
182 | - if ($location->isWeaponSold()) |
|
183 | - return true; |
|
182 | + if ($location->isWeaponSold()) { |
|
183 | + return true; |
|
184 | + } |
|
184 | 185 | } |
185 | 186 | return false; |
186 | 187 | } |
187 | 188 | |
188 | 189 | public function hasHQ() { |
189 | 190 | foreach ($this->getLocations() as $location) { |
190 | - if ($location->isHQ()) |
|
191 | - return true; |
|
191 | + if ($location->isHQ()) { |
|
192 | + return true; |
|
193 | + } |
|
192 | 194 | } |
193 | 195 | return false; |
194 | 196 | } |
195 | 197 | |
196 | 198 | public function hasUG() { |
197 | 199 | foreach ($this->getLocations() as $location) { |
198 | - if ($location->isUG()) |
|
199 | - return true; |
|
200 | + if ($location->isUG()) { |
|
201 | + return true; |
|
202 | + } |
|
200 | 203 | } |
201 | 204 | return false; |
202 | 205 | } |
203 | 206 | |
204 | 207 | public function hasShipShop() { |
205 | 208 | foreach ($this->getLocations() as $location) { |
206 | - if ($location->isShipSold()) |
|
207 | - return true; |
|
209 | + if ($location->isShipSold()) { |
|
210 | + return true; |
|
211 | + } |
|
208 | 212 | } |
209 | 213 | return false; |
210 | 214 | } |
211 | 215 | |
212 | 216 | public function offersFederalProtection() { |
213 | 217 | foreach ($this->getLocations() as $location) { |
214 | - if ($location->isFed()) |
|
215 | - return true; |
|
218 | + if ($location->isFed()) { |
|
219 | + return true; |
|
220 | + } |
|
216 | 221 | } |
217 | 222 | return false; |
218 | 223 | } |
@@ -220,32 +225,36 @@ discard block |
||
220 | 225 | public function getFedRaceIDs() { |
221 | 226 | $raceIDs = array(); |
222 | 227 | foreach ($this->getLocations() as $location) { |
223 | - if ($location->isFed()) |
|
224 | - $raceIDs[$location->getRaceID()] = $location->getRaceID(); |
|
228 | + if ($location->isFed()) { |
|
229 | + $raceIDs[$location->getRaceID()] = $location->getRaceID(); |
|
230 | + } |
|
225 | 231 | } |
226 | 232 | return $raceIDs; |
227 | 233 | } |
228 | 234 | |
229 | 235 | public function hasBar() { |
230 | 236 | foreach ($this->getLocations() as $location) { |
231 | - if ($location->isBar()) |
|
232 | - return true; |
|
237 | + if ($location->isBar()) { |
|
238 | + return true; |
|
239 | + } |
|
233 | 240 | } |
234 | 241 | return false; |
235 | 242 | } |
236 | 243 | |
237 | 244 | public function hasHardwareShop() { |
238 | 245 | foreach ($this->getLocations() as $location) { |
239 | - if ($location->isHardwareSold()) |
|
240 | - return true; |
|
246 | + if ($location->isHardwareSold()) { |
|
247 | + return true; |
|
248 | + } |
|
241 | 249 | } |
242 | 250 | return false; |
243 | 251 | } |
244 | 252 | |
245 | 253 | public function hasBank() { |
246 | 254 | foreach ($this->getLocations() as $location) { |
247 | - if ($location->isBank()) |
|
248 | - return true; |
|
255 | + if ($location->isBank()) { |
|
256 | + return true; |
|
257 | + } |
|
249 | 258 | } |
250 | 259 | return false; |
251 | 260 | } |
@@ -322,8 +331,9 @@ discard block |
||
322 | 331 | } |
323 | 332 | |
324 | 333 | public function setGalaxyID($galaxyID) { |
325 | - if ($this->galaxyID == $galaxyID) |
|
326 | - return; |
|
334 | + if ($this->galaxyID == $galaxyID) { |
|
335 | + return; |
|
336 | + } |
|
327 | 337 | $this->galaxyID = $galaxyID; |
328 | 338 | $this->hasChanged = true; |
329 | 339 | } |
@@ -334,18 +344,21 @@ discard block |
||
334 | 344 | |
335 | 345 | public function getNumberOfLinks() { |
336 | 346 | $num = 0; |
337 | - if (!is_array($this->getLinks())) |
|
338 | - return $num; |
|
339 | - foreach ($this->getLinks() as $link) |
|
340 | - if ($link !== 0) |
|
347 | + if (!is_array($this->getLinks())) { |
|
348 | + return $num; |
|
349 | + } |
|
350 | + foreach ($this->getLinks() as $link) { |
|
351 | + if ($link !== 0) |
|
341 | 352 | $num++; |
353 | + } |
|
342 | 354 | return $num; |
343 | 355 | } |
344 | 356 | |
345 | 357 | public function getNumberOfConnections() { |
346 | 358 | $links = $this->getNumberOfLinks(); |
347 | - if ($this->hasWarp()) |
|
348 | - $links++; |
|
359 | + if ($this->hasWarp()) { |
|
360 | + $links++; |
|
361 | + } |
|
349 | 362 | return $links; |
350 | 363 | } |
351 | 364 | |
@@ -354,30 +367,35 @@ discard block |
||
354 | 367 | } |
355 | 368 | |
356 | 369 | public function getNeighbourID($dir) { |
357 | - if ($this->hasLink($dir)) |
|
358 | - return $this->getLink($dir); |
|
370 | + if ($this->hasLink($dir)) { |
|
371 | + return $this->getLink($dir); |
|
372 | + } |
|
359 | 373 | $galaxy = $this->getGalaxy(); |
360 | 374 | $neighbour = $this->getSectorID(); |
361 | 375 | switch ($dir) { |
362 | 376 | case 'Up': |
363 | 377 | $neighbour -= $galaxy->getWidth(); |
364 | - if ($neighbour < $galaxy->getStartSector()) |
|
365 | - $neighbour += $galaxy->getSize(); |
|
378 | + if ($neighbour < $galaxy->getStartSector()) { |
|
379 | + $neighbour += $galaxy->getSize(); |
|
380 | + } |
|
366 | 381 | break; |
367 | 382 | case 'Down': |
368 | 383 | $neighbour += $galaxy->getWidth(); |
369 | - if ($neighbour > $galaxy->getEndSector()) |
|
370 | - $neighbour -= $galaxy->getSize(); |
|
384 | + if ($neighbour > $galaxy->getEndSector()) { |
|
385 | + $neighbour -= $galaxy->getSize(); |
|
386 | + } |
|
371 | 387 | break; |
372 | 388 | case 'Left': |
373 | 389 | $neighbour -= 1; |
374 | - if ((1 + $neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) |
|
375 | - $neighbour += $galaxy->getWidth(); |
|
390 | + if ((1 + $neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) { |
|
391 | + $neighbour += $galaxy->getWidth(); |
|
392 | + } |
|
376 | 393 | break; |
377 | 394 | case 'Right': |
378 | 395 | $neighbour += 1; |
379 | - if (($neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) |
|
380 | - $neighbour -= $galaxy->getWidth(); |
|
396 | + if (($neighbour - $galaxy->getStartSector()) % $galaxy->getWidth() == 0) { |
|
397 | + $neighbour -= $galaxy->getWidth(); |
|
398 | + } |
|
381 | 399 | break; |
382 | 400 | default: |
383 | 401 | throw new Exception($dir . ': is not a valid direction'); |
@@ -386,13 +404,16 @@ discard block |
||
386 | 404 | } |
387 | 405 | |
388 | 406 | public function getSectorDirection($sectorID) { |
389 | - if ($sectorID == $this->getSectorID()) |
|
390 | - return 'Current'; |
|
407 | + if ($sectorID == $this->getSectorID()) { |
|
408 | + return 'Current'; |
|
409 | + } |
|
391 | 410 | $dir = array_search($sectorID, $this->getLinks()); |
392 | - if ($dir !== false) |
|
393 | - return $dir; |
|
394 | - if ($sectorID == $this->getWarp()) |
|
395 | - return 'Warp'; |
|
411 | + if ($dir !== false) { |
|
412 | + return $dir; |
|
413 | + } |
|
414 | + if ($sectorID == $this->getWarp()) { |
|
415 | + return 'Warp'; |
|
416 | + } |
|
396 | 417 | return 'None'; |
397 | 418 | } |
398 | 419 | |
@@ -417,8 +438,9 @@ discard block |
||
417 | 438 | } |
418 | 439 | |
419 | 440 | public function getLinkSector($name) { |
420 | - if ($this->hasLink($name)) |
|
421 | - return SmrSector::getSector($this->getGameID(), $this->getLink($name)); |
|
441 | + if ($this->hasLink($name)) { |
|
442 | + return SmrSector::getSector($this->getGameID(), $this->getLink($name)); |
|
443 | + } |
|
422 | 444 | return false; |
423 | 445 | } |
424 | 446 | |
@@ -426,12 +448,14 @@ discard block |
||
426 | 448 | * Cannot be used for Warps |
427 | 449 | */ |
428 | 450 | public function setLink($name, $linkID) { |
429 | - if ($this->getLink($name) == $linkID) |
|
430 | - return; |
|
431 | - if ($linkID == 0) |
|
432 | - unset($this->links[$name]); |
|
433 | - else |
|
434 | - $this->links[$name] = $linkID; |
|
451 | + if ($this->getLink($name) == $linkID) { |
|
452 | + return; |
|
453 | + } |
|
454 | + if ($linkID == 0) { |
|
455 | + unset($this->links[$name]); |
|
456 | + } else { |
|
457 | + $this->links[$name] = $linkID; |
|
458 | + } |
|
435 | 459 | $this->hasChanged = true; |
436 | 460 | } |
437 | 461 | |
@@ -439,8 +463,9 @@ discard block |
||
439 | 463 | * Cannot be used for Warps |
440 | 464 | */ |
441 | 465 | public function setLinkSector($dir, SmrSector $linkSector) { |
442 | - if ($this->getLink($dir) == $linkSector->getSectorID() || $linkSector->equals($this)) |
|
443 | - return; |
|
466 | + if ($this->getLink($dir) == $linkSector->getSectorID() || $linkSector->equals($this)) { |
|
467 | + return; |
|
468 | + } |
|
444 | 469 | $this->setLink($dir, $linkSector->getSectorID()); |
445 | 470 | $linkSector->setLink(self::oppositeDir($dir), $this->getSectorID()); |
446 | 471 | $this->hasChanged = true; |
@@ -464,8 +489,7 @@ discard block |
||
464 | 489 | public function toggleLink($dir) { |
465 | 490 | if ($this->hasLink($dir)) { |
466 | 491 | $this->disableLink($dir); |
467 | - } |
|
468 | - else { |
|
492 | + } else { |
|
469 | 493 | $this->enableLink($dir); |
470 | 494 | } |
471 | 495 | } |
@@ -629,21 +653,25 @@ discard block |
||
629 | 653 | $locations = SmrLocation::getSectorLocations($this->getGameID(), $this->getSectorID()); |
630 | 654 | $hasAction = false; |
631 | 655 | foreach ($locations as $location) { |
632 | - if ($location->hasAction()) |
|
633 | - $hasAction = true; |
|
656 | + if ($location->hasAction()) { |
|
657 | + $hasAction = true; |
|
658 | + } |
|
634 | 659 | } |
635 | 660 | return $hasAction; |
636 | 661 | } |
637 | 662 | |
638 | 663 | public function hasLocation($locationTypeID = false) { |
639 | 664 | $locations = $this->getLocations(); |
640 | - if (count($locations) == 0) |
|
641 | - return false; |
|
642 | - if ($locationTypeID == false) |
|
643 | - return true; |
|
665 | + if (count($locations) == 0) { |
|
666 | + return false; |
|
667 | + } |
|
668 | + if ($locationTypeID == false) { |
|
669 | + return true; |
|
670 | + } |
|
644 | 671 | foreach ($locations as $location) { |
645 | - if ($location->getTypeID() == $locationTypeID) |
|
646 | - return true; |
|
672 | + if ($location->getTypeID() == $locationTypeID) { |
|
673 | + return true; |
|
674 | + } |
|
647 | 675 | } |
648 | 676 | return false; |
649 | 677 | } |
@@ -703,11 +731,13 @@ discard block |
||
703 | 731 | } |
704 | 732 | |
705 | 733 | public function hasEnemyForces(AbstractSmrPlayer $player = null) { |
706 | - if ($player == null || !$this->hasForces()) |
|
707 | - return false; |
|
734 | + if ($player == null || !$this->hasForces()) { |
|
735 | + return false; |
|
736 | + } |
|
708 | 737 | foreach ($this->getForces() as $force) { |
709 | - if (!$player->forceNAPAlliance($force->getOwner())) |
|
710 | - return true; |
|
738 | + if (!$player->forceNAPAlliance($force->getOwner())) { |
|
739 | + return true; |
|
740 | + } |
|
711 | 741 | } |
712 | 742 | return false; |
713 | 743 | } |
@@ -715,8 +745,9 @@ discard block |
||
715 | 745 | public function getEnemyForces(AbstractSmrPlayer $player) { |
716 | 746 | $enemyForces = array(); |
717 | 747 | foreach ($this->getForces() as $force) { |
718 | - if (!$player->forceNAPAlliance($force->getOwner())) |
|
719 | - $enemyForces[] = $force; |
|
748 | + if (!$player->forceNAPAlliance($force->getOwner())) { |
|
749 | + $enemyForces[] = $force; |
|
750 | + } |
|
720 | 751 | } |
721 | 752 | return $enemyForces; |
722 | 753 | } |
@@ -734,11 +765,13 @@ discard block |
||
734 | 765 | } |
735 | 766 | |
736 | 767 | public function hasFriendlyForces(AbstractSmrPlayer $player = null) { |
737 | - if ($player == null || !$this->hasForces()) |
|
738 | - return false; |
|
768 | + if ($player == null || !$this->hasForces()) { |
|
769 | + return false; |
|
770 | + } |
|
739 | 771 | foreach ($this->getForces() as $force) { |
740 | - if ($player->forceNAPAlliance($force->getOwner())) |
|
741 | - return true; |
|
772 | + if ($player->forceNAPAlliance($force->getOwner())) { |
|
773 | + return true; |
|
774 | + } |
|
742 | 775 | } |
743 | 776 | return false; |
744 | 777 | } |
@@ -746,8 +779,9 @@ discard block |
||
746 | 779 | public function getFriendlyForces(AbstractSmrPlayer $player) { |
747 | 780 | $friendlyForces = array(); |
748 | 781 | foreach ($this->getForces() as $force) { |
749 | - if ($player->forceNAPAlliance($force->getOwner())) |
|
750 | - $friendlyForces[] = $force; |
|
782 | + if ($player->forceNAPAlliance($force->getOwner())) { |
|
783 | + $friendlyForces[] = $force; |
|
784 | + } |
|
751 | 785 | } |
752 | 786 | return $friendlyForces; |
753 | 787 | } |
@@ -775,8 +809,9 @@ discard block |
||
775 | 809 | } |
776 | 810 | |
777 | 811 | public function hasEnemyTraders(AbstractSmrPlayer $player = null) { |
778 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
779 | - return false; |
|
812 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
813 | + return false; |
|
814 | + } |
|
780 | 815 | $otherPlayers = $this->getOtherTraders($player); |
781 | 816 | foreach ($otherPlayers as $otherPlayer) { |
782 | 817 | if (!$player->traderNAPAlliance($otherPlayer) |
@@ -789,12 +824,14 @@ discard block |
||
789 | 824 | } |
790 | 825 | |
791 | 826 | public function hasFriendlyTraders(AbstractSmrPlayer $player = null) { |
792 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
793 | - return false; |
|
827 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
828 | + return false; |
|
829 | + } |
|
794 | 830 | $otherPlayers = $this->getOtherTraders($player); |
795 | 831 | foreach ($otherPlayers as $otherPlayer) { |
796 | - if ($player->traderNAPAlliance($otherPlayer)) |
|
797 | - return true; |
|
832 | + if ($player->traderNAPAlliance($otherPlayer)) { |
|
833 | + return true; |
|
834 | + } |
|
798 | 835 | } |
799 | 836 | return false; |
800 | 837 | } |
@@ -816,8 +853,9 @@ discard block |
||
816 | 853 | } |
817 | 854 | |
818 | 855 | public function hasProtectedTraders(AbstractSmrPlayer $player = null) { |
819 | - if ($player == null || !$this->hasOtherTraders($player)) |
|
820 | - return false; |
|
856 | + if ($player == null || !$this->hasOtherTraders($player)) { |
|
857 | + return false; |
|
858 | + } |
|
821 | 859 | $otherPlayers = $this->getOtherTraders($player); |
822 | 860 | foreach ($otherPlayers as $otherPlayer) { |
823 | 861 | if (!$player->traderNAPAlliance($otherPlayer) |
@@ -853,8 +891,9 @@ discard block |
||
853 | 891 | $planetOwner = $defendingPlanet->getOwner(); |
854 | 892 | foreach ($alliancePlayers as $accountID => $player) { |
855 | 893 | if ($player->canFight()) { |
856 | - if ($attackingPlayer->traderAttackPlanetAlliance($player) && !$planetOwner->planetNAPAlliance($player)) |
|
857 | - $fightingPlayers[$accountID] = $alliancePlayers[$accountID]; |
|
894 | + if ($attackingPlayer->traderAttackPlanetAlliance($player) && !$planetOwner->planetNAPAlliance($player)) { |
|
895 | + $fightingPlayers[$accountID] = $alliancePlayers[$accountID]; |
|
896 | + } |
|
858 | 897 | } |
859 | 898 | } |
860 | 899 | } |
@@ -862,8 +901,9 @@ discard block |
||
862 | 901 | } |
863 | 902 | |
864 | 903 | public function getFightingTraders(AbstractSmrPlayer $attackingPlayer, AbstractSmrPlayer $defendingPlayer, $checkForCloak = false) { |
865 | - if ($attackingPlayer->traderNAPAlliance($defendingPlayer)) |
|
866 | - throw new Exception('These traders are NAPed.'); |
|
904 | + if ($attackingPlayer->traderNAPAlliance($defendingPlayer)) { |
|
905 | + throw new Exception('These traders are NAPed.'); |
|
906 | + } |
|
867 | 907 | $fightingPlayers = array('Attackers' => array(), 'Defenders' => array()); |
868 | 908 | $alliancePlayers = SmrPlayer::getSectorPlayersByAlliances($this->getGameID(), $this->getSectorID(), array($attackingPlayer->getAllianceID(), $defendingPlayer->getAllianceID())); |
869 | 909 | $attackers = array(); |
@@ -923,8 +963,9 @@ discard block |
||
923 | 963 | } |
924 | 964 | |
925 | 965 | public function setBattles($amount) { |
926 | - if ($this->battles == $amount) |
|
927 | - return; |
|
966 | + if ($this->battles == $amount) { |
|
967 | + return; |
|
968 | + } |
|
928 | 969 | $this->battles = $amount; |
929 | 970 | $this->hasChanged = true; |
930 | 971 | } |
@@ -946,8 +987,9 @@ discard block |
||
946 | 987 | } |
947 | 988 | |
948 | 989 | public function isVisited(AbstractSmrPlayer $player = null) { |
949 | - if ($player === null) |
|
950 | - return true; |
|
990 | + if ($player === null) { |
|
991 | + return true; |
|
992 | + } |
|
951 | 993 | if (!isset($this->visited[$player->getAccountID()])) { |
952 | 994 | $this->db->query('SELECT sector_id FROM player_visited_sector WHERE ' . $this->SQL . ' AND account_id=' . $this->db->escapeNumber($player->getAccountID()) . ' LIMIT 1'); |
953 | 995 | $this->visited[$player->getAccountID()] = !$this->db->nextRecord(); |
@@ -988,10 +1030,12 @@ discard block |
||
988 | 1030 | return $x->contains($this); |
989 | 1031 | } |
990 | 1032 | |
991 | - if (is_array($x) && $x['Type'] == 'Good') //Check if it's possible for port to have X, hacky but nice performance gains |
|
1033 | + if (is_array($x) && $x['Type'] == 'Good') { |
|
1034 | + //Check if it's possible for port to have X, hacky but nice performance gains |
|
992 | 1035 | if ($this->hasPort()) |
993 | 1036 | if ($this->getPort()->hasX($x)) |
994 | 1037 | return true; |
1038 | + } |
|
995 | 1039 | |
996 | 1040 | //Check if it's possible for location to have X, hacky but nice performance gains |
997 | 1041 | if ($x instanceof SmrWeapon || (is_array($x) && ($x['Type'] == 'Ship' || $x['Type'] == 'Hardware')) || (is_string($x) && ($x == 'Bank' || $x == 'Bar' || $x == 'Fed' || $x == 'SafeFed' || $x == 'HQ' || $x == 'UG' || $x == 'Hardware' || $x == 'Ship' || $x == 'Weapon'))) { |
@@ -446,20 +446,20 @@ |
||
446 | 446 | |
447 | 447 | if ($this->hasMines()) { |
448 | 448 | $thisMines = new SmrMines($this->getGameID(), $this->getMines()); |
449 | - $results['Results']['Mines'] =& $thisMines->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)], $minesAreAttacker); |
|
449 | + $results['Results']['Mines'] = & $thisMines->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)], $minesAreAttacker); |
|
450 | 450 | $results['TotalDamage'] += $results['Results']['Mines']['ActualDamage']['TotalDamage']; |
451 | 451 | } |
452 | 452 | |
453 | 453 | if ($this->hasCDs()) { |
454 | 454 | $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs()); |
455 | - $results['Results']['Drones'] =& $thisCDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
455 | + $results['Results']['Drones'] = & $thisCDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
456 | 456 | $results['TotalDamage'] += $results['Results']['Drones']['ActualDamage']['TotalDamage']; |
457 | 457 | } |
458 | 458 | |
459 | 459 | if (!$minesAreAttacker) { |
460 | 460 | if ($this->hasSDs()) { |
461 | 461 | $thisSDs = new SmrScoutDrones($this->getGameID(), $this->getSDs()); |
462 | - $results['Results']['Scouts'] =& $thisSDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
462 | + $results['Results']['Scouts'] = & $thisSDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
463 | 463 | $results['TotalDamage'] += $results['Results']['Scouts']['ActualDamage']['TotalDamage']; |
464 | 464 | } |
465 | 465 | } |
@@ -252,16 +252,16 @@ discard block |
||
252 | 252 | } |
253 | 253 | $this->hasChanged = true; |
254 | 254 | $this->expire = $time; |
255 | - if (!$this->isNew) |
|
256 | - $this->update(); |
|
255 | + if (!$this->isNew) { |
|
256 | + $this->update(); |
|
257 | + } |
|
257 | 258 | } |
258 | 259 | |
259 | 260 | public function updateExpire() { |
260 | 261 | // Changed (26/10/05) - scout drones count * 2 |
261 | 262 | if ($this->getCDs() == 0 && $this->getMines() == 0 && $this->getSDs() > 0) { |
262 | 263 | $time = self::TIME_PER_SCOUT_ONLY * $this->getSDs(); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | $time = ($this->getCDs() * self::TIME_PERCENT_PER_COMBAT + $this->getSDs() * self::TIME_PERCENT_PER_SCOUT + $this->getMines() * self::TIME_PERCENT_PER_MINE) * $this->getMaxGalaxyExpireTime(); |
266 | 266 | } |
267 | 267 | $this->setExpire(TIME + $time); |
@@ -288,11 +288,9 @@ discard block |
||
288 | 288 | } |
289 | 289 | if ($mines < 10) { |
290 | 290 | $turns = 1; |
291 | - } |
|
292 | - else if ($mines < 25) { |
|
291 | + } else if ($mines < 25) { |
|
293 | 292 | $turns = 2; |
294 | - } |
|
295 | - else { |
|
293 | + } else { |
|
296 | 294 | $turns = 3; |
297 | 295 | } |
298 | 296 | if ($ship->isFederal() || $ship->hasDCS()) { |
@@ -347,12 +345,10 @@ discard block |
||
347 | 345 | if (!$this->exists()) { |
348 | 346 | $this->db->query('DELETE FROM sector_has_forces WHERE ' . $this->SQL); |
349 | 347 | $this->isNew = true; |
350 | - } |
|
351 | - else if ($this->hasChanged) { |
|
348 | + } else if ($this->hasChanged) { |
|
352 | 349 | $this->db->query('UPDATE sector_has_forces SET combat_drones = ' . $this->db->escapeNumber($this->combatDrones) . ', scout_drones = ' . $this->db->escapeNumber($this->scoutDrones) . ', mines = ' . $this->db->escapeNumber($this->mines) . ', expire_time = ' . $this->db->escapeNumber($this->expire) . ' WHERE ' . $this->SQL); |
353 | 350 | } |
354 | - } |
|
355 | - else if ($this->exists()) { |
|
351 | + } else if ($this->exists()) { |
|
356 | 352 | $this->db->query('INSERT INTO sector_has_forces (game_id, sector_id, owner_id, combat_drones, scout_drones, mines, expire_time) |
357 | 353 | VALUES('.$this->db->escapeNumber($this->gameID) . ', ' . $this->db->escapeNumber($this->sectorID) . ', ' . $this->db->escapeNumber($this->ownerID) . ', ' . $this->db->escapeNumber($this->combatDrones) . ', ' . $this->db->escapeNumber($this->scoutDrones) . ', ' . $this->db->escapeNumber($this->mines) . ', ' . $this->db->escapeNumber($this->expire) . ')'); |
358 | 354 | $this->isNew = false; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | protected $maxDamage; |
13 | 13 | protected $shieldDamage; |
14 | 14 | protected $armourDamage; |
15 | - protected $empDamage=0; |
|
15 | + protected $empDamage = 0; |
|
16 | 16 | protected $accuracy; |
17 | 17 | protected $damageRollover; |
18 | 18 | protected $raidWeapon; |
@@ -85,62 +85,62 @@ discard block |
||
85 | 85 | abstract public function &getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer); |
86 | 86 | |
87 | 87 | protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
88 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstForces($weaponPlayer,$forces); |
|
89 | - $return['ActualDamage'] =& $forces->doWeaponDamage($return['WeaponDamage']); |
|
90 | - if($return['ActualDamage']['KillingShot']) |
|
91 | - $return['KillResults'] =& $forces->killForcesByPlayer($weaponPlayer); |
|
88 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstForces($weaponPlayer, $forces); |
|
89 | + $return['ActualDamage'] = & $forces->doWeaponDamage($return['WeaponDamage']); |
|
90 | + if ($return['ActualDamage']['KillingShot']) |
|
91 | + $return['KillResults'] = & $forces->killForcesByPlayer($weaponPlayer); |
|
92 | 92 | return $return; |
93 | 93 | } |
94 | 94 | |
95 | 95 | protected function &doPlayerDamageToPlayer(array &$return, AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { |
96 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlayer($weaponPlayer,$targetPlayer); |
|
97 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
96 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPlayer($weaponPlayer, $targetPlayer); |
|
97 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
98 | 98 | |
99 | - if($return['ActualDamage']['KillingShot']) |
|
100 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
99 | + if ($return['ActualDamage']['KillingShot']) |
|
100 | + $return['KillResults'] = & $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
101 | 101 | return $return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
105 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPort($weaponPlayer,$port); |
|
106 | - $return['ActualDamage'] =& $port->doWeaponDamage($return['WeaponDamage']); |
|
107 | - if($return['ActualDamage']['KillingShot']) |
|
108 | - $return['KillResults'] =& $port->killPortByPlayer($weaponPlayer); |
|
105 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPort($weaponPlayer, $port); |
|
106 | + $return['ActualDamage'] = & $port->doWeaponDamage($return['WeaponDamage']); |
|
107 | + if ($return['ActualDamage']['KillingShot']) |
|
108 | + $return['KillResults'] = & $port->killPortByPlayer($weaponPlayer); |
|
109 | 109 | return $return; |
110 | 110 | } |
111 | 111 | |
112 | 112 | protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { |
113 | - $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlanet($weaponPlayer,$planet); |
|
114 | - $return['ActualDamage'] =& $planet->doWeaponDamage($return['WeaponDamage'],$delayed); |
|
115 | - if($return['ActualDamage']['KillingShot']) |
|
116 | - $return['KillResults'] =& $planet->killPlanetByPlayer($weaponPlayer); |
|
113 | + $return['WeaponDamage'] = & $this->getModifiedDamageAgainstPlanet($weaponPlayer, $planet); |
|
114 | + $return['ActualDamage'] = & $planet->doWeaponDamage($return['WeaponDamage'], $delayed); |
|
115 | + if ($return['ActualDamage']['KillingShot']) |
|
116 | + $return['KillResults'] = & $planet->killPlanetByPlayer($weaponPlayer); |
|
117 | 117 | return $return; |
118 | 118 | } |
119 | 119 | |
120 | 120 | protected function &doPortDamageToPlayer(array &$return, SmrPort $port, AbstractSmrPlayer $targetPlayer) { |
121 | - $return['WeaponDamage'] =& $this->getModifiedPortDamageAgainstPlayer($port,$targetPlayer); |
|
122 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
121 | + $return['WeaponDamage'] = & $this->getModifiedPortDamageAgainstPlayer($port, $targetPlayer); |
|
122 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
123 | 123 | |
124 | - if($return['ActualDamage']['KillingShot']) |
|
125 | - $return['KillResults'] =& $targetPlayer->killPlayerByPort($port); |
|
124 | + if ($return['ActualDamage']['KillingShot']) |
|
125 | + $return['KillResults'] = & $targetPlayer->killPlayerByPort($port); |
|
126 | 126 | return $return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | protected function &doPlanetDamageToPlayer(array &$return, SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { |
130 | - $return['WeaponDamage'] =& $this->getModifiedPlanetDamageAgainstPlayer($planet,$targetPlayer); |
|
131 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
130 | + $return['WeaponDamage'] = & $this->getModifiedPlanetDamageAgainstPlayer($planet, $targetPlayer); |
|
131 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
132 | 132 | |
133 | - if($return['ActualDamage']['KillingShot']) |
|
134 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlanet($planet); |
|
133 | + if ($return['ActualDamage']['KillingShot']) |
|
134 | + $return['KillResults'] = & $targetPlayer->killPlayerByPlanet($planet); |
|
135 | 135 | return $return; |
136 | 136 | } |
137 | 137 | |
138 | 138 | protected function &doForceDamageToPlayer(array &$return, SmrForce $forces, AbstractSmrPlayer $targetPlayer) { |
139 | - $return['WeaponDamage'] =& $this->getModifiedForceDamageAgainstPlayer($forces,$targetPlayer); |
|
140 | - $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
139 | + $return['WeaponDamage'] = & $this->getModifiedForceDamageAgainstPlayer($forces, $targetPlayer); |
|
140 | + $return['ActualDamage'] = & $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
|
141 | 141 | |
142 | - if($return['ActualDamage']['KillingShot']) |
|
143 | - $return['KillResults'] =& $targetPlayer->killPlayerByForces($forces); |
|
142 | + if ($return['ActualDamage']['KillingShot']) |
|
143 | + $return['KillResults'] = & $targetPlayer->killPlayerByForces($forces); |
|
144 | 144 | return $return; |
145 | 145 | } |
146 | 146 |
@@ -87,8 +87,9 @@ discard block |
||
87 | 87 | protected function &doPlayerDamageToForce(array &$return, AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
88 | 88 | $return['WeaponDamage'] =& $this->getModifiedDamageAgainstForces($weaponPlayer,$forces); |
89 | 89 | $return['ActualDamage'] =& $forces->doWeaponDamage($return['WeaponDamage']); |
90 | - if($return['ActualDamage']['KillingShot']) |
|
91 | - $return['KillResults'] =& $forces->killForcesByPlayer($weaponPlayer); |
|
90 | + if($return['ActualDamage']['KillingShot']) { |
|
91 | + $return['KillResults'] =& $forces->killForcesByPlayer($weaponPlayer); |
|
92 | + } |
|
92 | 93 | return $return; |
93 | 94 | } |
94 | 95 | |
@@ -96,24 +97,27 @@ discard block |
||
96 | 97 | $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlayer($weaponPlayer,$targetPlayer); |
97 | 98 | $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
98 | 99 | |
99 | - if($return['ActualDamage']['KillingShot']) |
|
100 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
100 | + if($return['ActualDamage']['KillingShot']) { |
|
101 | + $return['KillResults'] =& $targetPlayer->killPlayerByPlayer($weaponPlayer); |
|
102 | + } |
|
101 | 103 | return $return; |
102 | 104 | } |
103 | 105 | |
104 | 106 | protected function &doPlayerDamageToPort(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
105 | 107 | $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPort($weaponPlayer,$port); |
106 | 108 | $return['ActualDamage'] =& $port->doWeaponDamage($return['WeaponDamage']); |
107 | - if($return['ActualDamage']['KillingShot']) |
|
108 | - $return['KillResults'] =& $port->killPortByPlayer($weaponPlayer); |
|
109 | + if($return['ActualDamage']['KillingShot']) { |
|
110 | + $return['KillResults'] =& $port->killPortByPlayer($weaponPlayer); |
|
111 | + } |
|
109 | 112 | return $return; |
110 | 113 | } |
111 | 114 | |
112 | 115 | protected function &doPlayerDamageToPlanet(array &$return, AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { |
113 | 116 | $return['WeaponDamage'] =& $this->getModifiedDamageAgainstPlanet($weaponPlayer,$planet); |
114 | 117 | $return['ActualDamage'] =& $planet->doWeaponDamage($return['WeaponDamage'],$delayed); |
115 | - if($return['ActualDamage']['KillingShot']) |
|
116 | - $return['KillResults'] =& $planet->killPlanetByPlayer($weaponPlayer); |
|
118 | + if($return['ActualDamage']['KillingShot']) { |
|
119 | + $return['KillResults'] =& $planet->killPlanetByPlayer($weaponPlayer); |
|
120 | + } |
|
117 | 121 | return $return; |
118 | 122 | } |
119 | 123 | |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | $return['WeaponDamage'] =& $this->getModifiedPortDamageAgainstPlayer($port,$targetPlayer); |
122 | 126 | $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
123 | 127 | |
124 | - if($return['ActualDamage']['KillingShot']) |
|
125 | - $return['KillResults'] =& $targetPlayer->killPlayerByPort($port); |
|
128 | + if($return['ActualDamage']['KillingShot']) { |
|
129 | + $return['KillResults'] =& $targetPlayer->killPlayerByPort($port); |
|
130 | + } |
|
126 | 131 | return $return; |
127 | 132 | } |
128 | 133 | |
@@ -130,8 +135,9 @@ discard block |
||
130 | 135 | $return['WeaponDamage'] =& $this->getModifiedPlanetDamageAgainstPlayer($planet,$targetPlayer); |
131 | 136 | $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
132 | 137 | |
133 | - if($return['ActualDamage']['KillingShot']) |
|
134 | - $return['KillResults'] =& $targetPlayer->killPlayerByPlanet($planet); |
|
138 | + if($return['ActualDamage']['KillingShot']) { |
|
139 | + $return['KillResults'] =& $targetPlayer->killPlayerByPlanet($planet); |
|
140 | + } |
|
135 | 141 | return $return; |
136 | 142 | } |
137 | 143 | |
@@ -139,8 +145,9 @@ discard block |
||
139 | 145 | $return['WeaponDamage'] =& $this->getModifiedForceDamageAgainstPlayer($forces,$targetPlayer); |
140 | 146 | $return['ActualDamage'] =& $targetPlayer->getShip()->doWeaponDamage($return['WeaponDamage']); |
141 | 147 | |
142 | - if($return['ActualDamage']['KillingShot']) |
|
143 | - $return['KillResults'] =& $targetPlayer->killPlayerByForces($forces); |
|
148 | + if($return['ActualDamage']['KillingShot']) { |
|
149 | + $return['KillResults'] =& $targetPlayer->killPlayerByForces($forces); |
|
150 | + } |
|
144 | 151 | return $return; |
145 | 152 | } |
146 | 153 |