1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class FleetValidator |
5
|
|
|
*/ |
6
|
|
|
class FleetValidator { |
7
|
|
|
/** |
8
|
|
|
* @var Fleet $fleet |
9
|
|
|
*/ |
10
|
|
|
protected $fleet; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* FleetValidator constructor. |
14
|
|
|
* |
15
|
|
|
* @param Fleet $fleet |
16
|
|
|
*/ |
17
|
|
|
public function __construct($fleet) { |
18
|
|
|
$this->fleet = $fleet; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
public function validate() { |
25
|
|
|
$checklist = sn_get_groups('mission_checks'); |
26
|
|
|
try { |
27
|
|
|
$this->checkMissionRestrictions($checklist); |
28
|
|
|
|
29
|
|
|
// Do the restrictMission checks |
30
|
|
|
|
31
|
|
|
// TODO - Кое-какие проверки дают FLIGHT_ALLOWED - ЧТО НЕПРАВДА В ДАННОМ СЛУЧАЕ!!! |
32
|
|
|
// На странице 1 некоторые проверки ДОЛЖНЫ БЫТЬ опущены - иначе будет некрасиво |
33
|
|
|
// А вот здесь надо проверять много дополнительной хуйни |
34
|
|
|
try { |
|
|
|
|
35
|
|
|
// TODO - ALL OF THE ABOVE! |
36
|
|
|
} catch (Exception $e) { |
|
|
|
|
37
|
|
|
// If mission is restricted - rethrow exception |
38
|
|
|
if ($e->getCode() != FLIGHT_ALLOWED) { |
|
|
|
|
39
|
|
|
throw new Exception($e->getMessage(), $e->getCode()); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// TODO - later then |
44
|
|
|
|
45
|
|
|
// 2nd level restrictions |
46
|
|
|
// Still cheap |
47
|
|
|
$this->restrict2ToAllowedMissions(); |
48
|
|
|
$this->restrict2ToAllowedPlanetTypes(); |
49
|
|
|
// $this->restrict2MissionTransportWithResources($fleetResources); |
|
|
|
|
50
|
|
|
} catch (Exception $e) { |
51
|
|
|
if ($e->getCode() != FLIGHT_ALLOWED) { |
52
|
|
|
pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]); |
53
|
|
|
} else { |
54
|
|
|
pdump('FLIGHT_ALLOWED', FLIGHT_ALLOWED); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $checklist |
61
|
|
|
* |
62
|
|
|
* @throws Exception |
63
|
|
|
*/ |
64
|
|
|
public function checkMissionRestrictions($checklist) { |
65
|
|
|
foreach ($checklist as $condition => $action) { |
66
|
|
|
$checkResult = call_user_func(array($this, $condition)); |
67
|
|
|
|
68
|
|
|
if (is_array($action) && !empty($action[$checkResult])) { |
69
|
|
|
$action = $action[$checkResult]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (is_array($action)) { |
73
|
|
|
$this->checkMissionRestrictions($action); |
74
|
|
|
} elseif (!$checkResult) { |
75
|
|
|
throw new Exception($action, $action); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @throws Exception |
91
|
|
|
*/ |
92
|
|
|
protected function restrict2ToAllowedMissions() { |
93
|
|
|
if (empty($this->fleet->allowed_missions[$this->fleet->mission_type])) { |
94
|
|
|
throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @throws Exception |
100
|
|
|
*/ |
101
|
|
|
protected function restrict2ToAllowedPlanetTypes() { |
102
|
|
|
if (empty($this->fleet->allowed_planet_types[$this->fleet->targetVector->type])) { |
103
|
|
|
throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
|
109
|
|
|
|
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
|
114
|
|
|
|
115
|
|
|
|
116
|
|
|
|
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
protected function checkSpeedPercentOld() { |
123
|
|
|
return in_array($this->fleet->oldSpeedInTens, array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
protected function checkSenderNoVacation() { |
130
|
|
|
return empty($this->fleet->dbOwnerRow['vacation']) || $this->fleet->dbOwnerRow['vacation'] >= SN_TIME_NOW; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
protected function checkTargetNoVacation() { |
137
|
|
|
return empty($this->fleet->dbTargetOwnerRow['vacation']) || $this->fleet->dbTargetOwnerRow['vacation'] >= SN_TIME_NOW; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
protected function checkMultiAccount() { |
144
|
|
|
return sys_is_multiaccount($this->fleet->dbOwnerRow, $this->fleet->dbTargetOwnerRow); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return bool |
149
|
|
|
*/ |
150
|
|
|
protected function checkTargetNotSource() { |
151
|
|
|
return !$this->fleet->targetVector->isEqualToPlanet($this->fleet->dbSourcePlanetRow); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return bool |
156
|
|
|
*/ |
157
|
|
|
protected function checkTargetInUniverse() { |
158
|
|
|
return $this->fleet->targetVector->isInUniverse(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return bool |
163
|
|
|
*/ |
164
|
|
|
protected function checkUnitsPositive() { |
165
|
|
|
return $this->fleet->shipsAllPositive(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
|
|
protected function checkOnlyFleetUnits() { |
172
|
|
|
return $this->fleet->shipsAllFlying(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return bool |
177
|
|
|
*/ |
178
|
|
|
protected function checkOnlyFlyingUnits() { |
179
|
|
|
return $this->fleet->shipsAllMovable(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return bool |
184
|
|
|
*/ |
185
|
|
|
protected function checkEnoughFleetSlots() { |
186
|
|
|
return FleetList::fleet_count_flying($this->fleet->getPlayerOwnerId()) < GetMaxFleets($this->fleet->dbOwnerRow); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
|
|
protected function checkEnoughCapacity($includeResources = true) { |
196
|
|
|
$checkVia = $this->fleet->travelData['consumption']; |
197
|
|
|
$checkVia = ceil(($includeResources ? array_sum($this->fleet->resource_list) : 0) + $checkVia); |
198
|
|
|
|
199
|
|
|
return |
200
|
|
|
!empty($this->fleet->travelData) && |
201
|
|
|
is_array($this->fleet->travelData) && |
202
|
|
|
floor($this->fleet->travelData['capacity']) >= $checkVia; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return bool |
207
|
|
|
*/ |
208
|
|
|
protected function checkNotTooFar() { |
209
|
|
|
return $this->checkEnoughCapacity(false); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return bool |
214
|
|
|
*/ |
215
|
|
|
protected function checkDebrisExists() { |
216
|
|
|
return is_array($this->fleet->dbTargetRow) && ($this->fleet->dbTargetRow['debris_metal'] + $this->fleet->dbTargetRow['debris_crystal'] > 0); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
|
221
|
|
|
|
222
|
|
|
|
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
|
227
|
|
|
|
228
|
|
|
|
229
|
|
|
|
230
|
|
|
// Resources checks |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return bool |
234
|
|
|
*/ |
235
|
|
|
protected function checkResourcesPositive() { |
236
|
|
|
foreach ($this->fleet->resource_list as $resourceId => $resourceAmount) { |
237
|
|
|
if ($resourceAmount < 0) { |
238
|
|
|
return false; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
return true; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return bool |
247
|
|
|
*/ |
248
|
|
|
protected function checkCargo() { |
249
|
|
|
return array_sum($this->fleet->resource_list) >= 1; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @return bool |
254
|
|
|
*/ |
255
|
|
|
protected function checkSourceEnoughFuel() { |
256
|
|
|
$deuteriumOnPlanet = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, RES_DEUTERIUM); |
257
|
|
|
|
258
|
|
|
return $deuteriumOnPlanet < ceil($this->fleet->travelData['consumption']); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return bool |
263
|
|
|
*/ |
264
|
|
|
protected function checkSourceEnoughResources() { |
265
|
|
|
$fleetResources = $this->fleet->resource_list; |
266
|
|
|
$fleetResources[RES_DEUTERIUM] = ceil($fleetResources[RES_DEUTERIUM] + $this->fleet->travelData['consumption']); |
267
|
|
|
foreach ($fleetResources as $resourceId => $resourceAmount) { |
268
|
|
|
if (mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, $resourceId) < ceil($fleetResources[$resourceId])) { |
269
|
|
|
return false; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return true; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
|
278
|
|
|
|
279
|
|
|
|
280
|
|
|
|
281
|
|
|
|
282
|
|
|
|
283
|
|
|
|
284
|
|
|
|
285
|
|
|
|
286
|
|
|
|
287
|
|
|
|
288
|
|
|
|
289
|
|
|
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
|
294
|
|
|
|
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
// Target vector checks (????????) |
|
|
|
|
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return bool |
304
|
|
|
*/ |
305
|
|
|
protected function checkKnownSpace() { |
306
|
|
|
return $this->fleet->targetVector->isInKnownSpace(); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @return bool |
311
|
|
|
*/ |
312
|
|
|
protected function checkTargetExists() { |
313
|
|
|
return !empty($this->fleet->dbTargetRow['id']); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @return bool |
318
|
|
|
*/ |
319
|
|
|
protected function checkTargetIsPlanet() { |
320
|
|
|
return $this->fleet->targetVector->type == PT_PLANET; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return bool |
325
|
|
|
*/ |
326
|
|
|
protected function checkTargetIsDebris() { |
327
|
|
|
return $this->fleet->targetVector->type == PT_DEBRIS; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
|
331
|
|
|
|
332
|
|
|
|
333
|
|
|
|
334
|
|
|
|
335
|
|
|
// Ships checks |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @return bool |
339
|
|
|
*/ |
340
|
|
|
protected function checkFleetNotEmpty() { |
341
|
|
|
return $this->fleet->shipsGetTotal() >= 1; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @return bool |
347
|
|
|
*/ |
348
|
|
|
protected function checkSourceEnoughShips() { |
349
|
|
|
return $this->fleet->shipsIsEnoughOnPlanet(); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @return bool |
355
|
|
|
*/ |
356
|
|
|
protected function checkHaveColonizer() { |
357
|
|
|
// Colonization fleet should have at least one colonizer |
358
|
|
|
return $this->fleet->shipsGetTotalById(SHIP_COLONIZER) >= 1; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @return bool |
363
|
|
|
*/ |
364
|
|
|
protected function checkHaveRecyclers() { |
365
|
|
|
$recyclers = 0; |
366
|
|
|
foreach (sn_get_groups('flt_recyclers') as $recycler_id) { |
367
|
|
|
$recyclers += $this->fleet->shipsGetTotalById($recycler_id); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
return $recyclers >= 1; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @return bool |
375
|
|
|
*/ |
376
|
|
|
protected function checkSpiesOnly() { |
377
|
|
|
return $this->fleet->shipsGetTotalById(SHIP_SPY) == $this->fleet->shipsGetTotal(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @return bool |
382
|
|
|
*/ |
383
|
|
|
protected function checkNotOnlySpies() { |
384
|
|
|
return !$this->checkSpiesOnly(); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @return bool |
389
|
|
|
*/ |
390
|
|
|
protected function checkNoMissiles() { |
391
|
|
|
return |
392
|
|
|
$this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET) == 0 |
393
|
|
|
&& |
394
|
|
|
$this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERCEPTOR) == 0; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
|
398
|
|
|
|
399
|
|
|
|
400
|
|
|
|
401
|
|
|
|
402
|
|
|
|
403
|
|
|
|
404
|
|
|
|
405
|
|
|
|
406
|
|
|
|
407
|
|
|
|
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @return bool |
411
|
|
|
*/ |
412
|
|
|
protected function checkTargetOwn() { |
413
|
|
|
return $this->fleet->dbTargetRow['id_owner'] == $this->fleet->dbSourcePlanetRow['id_owner']; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @return bool |
418
|
|
|
*/ |
419
|
|
|
protected function forceTargetOwn() { |
420
|
|
|
if ($result = $this->checkTargetOwn()) { |
421
|
|
|
// Spying can't be done on owner's planet/moon |
422
|
|
|
unset($this->fleet->allowed_missions[MT_SPY]); |
423
|
|
|
// Attack can't be done on owner's planet/moon |
424
|
|
|
unset($this->fleet->allowed_missions[MT_ATTACK]); |
425
|
|
|
// ACS can't be done on owner's planet/moon |
426
|
|
|
unset($this->fleet->allowed_missions[MT_ACS]); |
427
|
|
|
// Destroy can't be done on owner's moon |
428
|
|
|
unset($this->fleet->allowed_missions[MT_DESTROY]); |
429
|
|
|
unset($this->fleet->allowed_missions[MT_MISSILE]); |
430
|
|
|
} else { |
431
|
|
|
// Relocate can be done only on owner's planet/moon |
432
|
|
|
unset($this->fleet->allowed_missions[MT_RELOCATE]); |
433
|
|
|
|
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
return $result; // this->getPlayerOwnerId(); |
|
|
|
|
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @return bool |
441
|
|
|
*/ |
442
|
|
|
protected function checkTargetOther() { |
443
|
|
|
return !$this->checkTargetOwn(); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @return bool |
449
|
|
|
*/ |
450
|
|
|
protected function alwaysFalse() { |
451
|
|
|
return false; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* @return bool |
457
|
|
|
*/ |
458
|
|
|
protected function checkTargetAllyDeposit() { |
459
|
|
|
$result = mrc_get_level($this->fleet->dbTargetOwnerRow, $this->fleet->dbTargetRow, STRUC_ALLY_DEPOSIT) >= 1; |
460
|
|
|
if (!$result) { |
461
|
|
|
unset($this->fleet->allowed_missions[MT_HOLD]); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
return $result; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Forces missions that can flight to OWN planets |
470
|
|
|
* |
471
|
|
|
* @return bool |
472
|
|
|
*/ |
473
|
|
|
protected function forceMissionsOwn() { |
474
|
|
|
$result = |
475
|
|
|
!$this->fleet->mission_type |
476
|
|
|
|| |
477
|
|
|
in_array($this->fleet->mission_type, array( |
478
|
|
|
MT_HOLD, |
479
|
|
|
MT_RECYCLE, |
480
|
|
|
MT_RELOCATE, |
481
|
|
|
MT_TRANSPORT, |
482
|
|
|
)); |
483
|
|
|
|
484
|
|
|
unset($this->fleet->allowed_missions[MT_ATTACK]); |
485
|
|
|
unset($this->fleet->allowed_missions[MT_COLONIZE]); |
486
|
|
|
unset($this->fleet->allowed_missions[MT_EXPLORE]); |
487
|
|
|
unset($this->fleet->allowed_missions[MT_ACS]); |
488
|
|
|
unset($this->fleet->allowed_missions[MT_SPY]); |
489
|
|
|
unset($this->fleet->allowed_missions[MT_DESTROY]); |
490
|
|
|
unset($this->fleet->allowed_missions[MT_MISSILE]); |
491
|
|
|
|
492
|
|
|
return $result; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* Check mission type OR no mission - and limits available missions to this type if positive |
497
|
|
|
* |
498
|
|
|
* @param int $missionType |
499
|
|
|
* |
500
|
|
|
* @return bool |
501
|
|
|
*/ |
502
|
|
|
protected function forceMission($missionType) { |
503
|
|
|
$result = !$this->fleet->mission_type || $this->fleet->mission_type == $missionType; |
504
|
|
|
if ($result) { |
505
|
|
|
$this->fleet->allowed_missions = array( |
506
|
|
|
$missionType => $this->fleet->exists_missions[$missionType], |
507
|
|
|
); |
508
|
|
|
} else { |
509
|
|
|
unset($this->fleet->allowed_missions[$missionType]); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
return $result; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* @return bool |
517
|
|
|
*/ |
518
|
|
|
protected function forceMissionExplore() { |
519
|
|
|
return $this->forceMission(MT_EXPLORE); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* @return bool |
524
|
|
|
*/ |
525
|
|
|
protected function forceMissionColonize() { |
526
|
|
|
return $this->forceMission(MT_COLONIZE); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @return bool |
531
|
|
|
*/ |
532
|
|
|
protected function forceMissionRecycle() { |
533
|
|
|
return $this->forceMission(MT_RECYCLE); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @return bool |
538
|
|
|
*/ |
539
|
|
|
protected function forceMissionMissile() { |
540
|
|
|
return $this->forceMission(MT_MISSILE); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Just checks mission type |
545
|
|
|
* |
546
|
|
|
* @param int $missionType |
547
|
|
|
* |
548
|
|
|
* @return bool |
549
|
|
|
*/ |
550
|
|
|
protected function checkMissionNonRestrict($missionType) { |
551
|
|
|
return $this->fleet->mission_type == $missionType; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* @return bool |
557
|
|
|
*/ |
558
|
|
|
protected function checkNotEmptyMission() { |
559
|
|
|
return !empty($this->fleet->mission_type); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* @return bool |
564
|
|
|
*/ |
565
|
|
|
protected function checkMissionRelocate() { |
566
|
|
|
return $this->checkMissionNonRestrict(MT_RELOCATE); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* @return bool |
571
|
|
|
*/ |
572
|
|
|
protected function checkMissionHoldNonUnique() { |
573
|
|
|
$result = $this->checkMissionNonRestrict(MT_HOLD); |
574
|
|
|
|
575
|
|
|
return $result; |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* @return bool |
580
|
|
|
*/ |
581
|
|
|
protected function checkMissionTransport() { |
582
|
|
|
return $this->checkMissionNonRestrict(MT_TRANSPORT); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* @return bool |
587
|
|
|
*/ |
588
|
|
|
protected function checkMissionTransportReal() { |
589
|
|
|
return |
590
|
|
|
$this->checkRealFlight() |
591
|
|
|
&& |
592
|
|
|
$this->checkMissionTransport(); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* @return bool |
598
|
|
|
*/ |
599
|
|
|
protected function forceMissionSpy() { |
600
|
|
|
return $this->forceMission(MT_SPY); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @return bool |
605
|
|
|
*/ |
606
|
|
|
protected function checkRealFlight() { |
607
|
|
|
return $this->fleet->isRealFlight; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* @return bool |
613
|
|
|
*/ |
614
|
|
|
protected function unsetMissionSpyComplex() { |
615
|
|
|
unset($this->fleet->allowed_missions[MT_SPY]); |
616
|
|
|
if ($this->fleet->mission_type == MT_SPY) { |
617
|
|
|
if ($this->checkRealFlight()) { |
618
|
|
|
return false; |
619
|
|
|
} |
620
|
|
|
$this->fleet->mission_type = MT_NONE; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
return true; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @return bool |
629
|
|
|
*/ |
630
|
|
|
protected function checkMissionExists() { |
631
|
|
|
return !empty($this->fleet->exists_missions[$this->fleet->mission_type]); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* @return bool |
636
|
|
|
*/ |
637
|
|
|
protected function checkPlayerInactiveOrNotNoob() { |
638
|
|
|
return |
639
|
|
|
$this->checkTargetNotActive() |
640
|
|
|
|| |
641
|
|
|
$this->checkTargetNotNoob(); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* @return bool |
646
|
|
|
*/ |
647
|
|
|
protected function checkTargetActive() { |
648
|
|
|
return |
649
|
|
|
empty($this->fleet->dbTargetOwnerRow['onlinetime']) |
650
|
|
|
|| |
651
|
|
|
SN_TIME_NOW - $this->fleet->dbTargetOwnerRow['onlinetime'] >= PLAYER_TIME_ACTIVE_SECONDS; |
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
/** |
655
|
|
|
* @return bool |
656
|
|
|
*/ |
657
|
|
|
// TODO - REDO MAIN FUNCTION |
658
|
|
|
protected function checkTargetNotActive() { |
659
|
|
|
return !$this->checkTargetActive(); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* @return bool |
665
|
|
|
*/ |
666
|
|
|
protected function checkSameAlly() { |
667
|
|
|
return !empty($this->fleet->dbTargetOwnerRow['ally_id']) && $this->fleet->dbTargetOwnerRow['ally_id'] == $this->fleet->dbOwnerRow['ally_id']; |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @return bool |
672
|
|
|
*/ |
673
|
|
|
protected function checkTargetNoob() { |
674
|
|
|
$user_points = $this->fleet->dbTargetOwnerRow['total_points']; |
675
|
|
|
$enemy_points = $this->fleet->dbTargetOwnerRow['total_points']; |
676
|
|
|
|
677
|
|
|
return |
678
|
|
|
// Target is under Noob Protection but Fleet owner is not |
679
|
|
|
( |
680
|
|
|
classSupernova::$config->game_noob_points |
681
|
|
|
&& |
682
|
|
|
$enemy_points <= classSupernova::$config->game_noob_points |
683
|
|
|
&& |
684
|
|
|
$user_points > classSupernova::$config->game_noob_points |
685
|
|
|
) || ( |
686
|
|
|
classSupernova::$config->game_noob_factor |
687
|
|
|
&& |
688
|
|
|
$user_points > $enemy_points * classSupernova::$config->game_noob_factor |
689
|
|
|
); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* @return bool |
694
|
|
|
*/ |
695
|
|
|
// TODO - REDO MAIN FUNCTION |
696
|
|
|
protected function checkTargetNotNoob() { |
697
|
|
|
return !$this->checkTargetNoob(); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* @return bool |
703
|
|
|
*/ |
704
|
|
|
protected function checkMissionHoldReal() { |
705
|
|
|
return |
706
|
|
|
$this->checkRealFlight() |
707
|
|
|
&& |
708
|
|
|
$this->checkMissionHoldNonUnique(); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @return bool |
713
|
|
|
*/ |
714
|
|
|
protected function checkMissionHoldOnNotNoob() { |
715
|
|
|
return |
716
|
|
|
$this->checkTargetNotActive() |
717
|
|
|
|| |
718
|
|
|
($this->checkSameAlly() && classSupernova::$config->ally_help_weak) |
719
|
|
|
|| |
720
|
|
|
$this->checkTargetNotNoob(); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
|
724
|
|
|
// Missiles |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* @return bool |
728
|
|
|
*/ |
729
|
|
|
protected function checkOnlyAttackMissiles() { |
730
|
|
|
$missilesAttack = $this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET); |
731
|
|
|
|
732
|
|
|
return $missilesAttack != 0 && $missilesAttack == $this->fleet->shipsGetTotal(); |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
/** |
736
|
|
|
* @return bool |
737
|
|
|
*/ |
738
|
|
|
protected function checkSiloLevel() { |
739
|
|
|
$sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
740
|
|
|
|
741
|
|
|
return mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, STRUC_SILO) >= $sn_data_mip[P_REQUIRE][STRUC_SILO]; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
/** |
745
|
|
|
* @return bool |
746
|
|
|
*/ |
747
|
|
|
protected function checkSameGalaxy() { |
748
|
|
|
return $this->fleet->targetVector->galaxy == $this->fleet->dbSourcePlanetRow['galaxy']; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* @return bool |
753
|
|
|
*/ |
754
|
|
|
protected function checkMissileDistance() { |
755
|
|
|
return abs($this->fleet->dbSourcePlanetRow['system'] - $this->fleet->targetVector->system) <= flt_get_missile_range($this->fleet->dbOwnerRow); |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
/** |
759
|
|
|
* @return bool |
760
|
|
|
*/ |
761
|
|
|
protected function checkMissileTarget() { |
762
|
|
|
return empty($this->fleet->targetedUnitId) || in_array($this->fleet->targetedUnitId, sn_get_groups('defense_active')); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* @return int |
768
|
|
|
*/ |
769
|
|
|
protected function checkExpeditionsMax() { |
770
|
|
|
return get_player_max_expeditons($this->fleet->dbOwnerRow); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* @return bool |
775
|
|
|
*/ |
776
|
|
|
protected function checkExpeditionsFree() { |
777
|
|
|
return get_player_max_expeditons($this->fleet->dbOwnerRow) > FleetList::fleet_count_flying($this->fleet->dbOwnerRow['id'], MT_EXPLORE); |
778
|
|
|
} |
779
|
|
|
|
780
|
|
|
/** |
781
|
|
|
* @return bool |
782
|
|
|
*/ |
783
|
|
|
protected function checkCaptainSent() { |
784
|
|
|
return $this->fleet->captainId >= 1; |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* @return bool |
789
|
|
|
*/ |
790
|
|
|
protected function checkCaptainExists() { |
791
|
|
|
return !empty($this->fleet->captain) && is_array($this->fleet->captain); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
/** |
795
|
|
|
* @return bool |
796
|
|
|
*/ |
797
|
|
|
protected function checkCaptainOnPlanet() { |
798
|
|
|
return $this->fleet->captain['unit_location_type'] == LOC_PLANET; |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
/** |
802
|
|
|
* @return bool |
803
|
|
|
*/ |
804
|
|
|
protected function checkCaptainNotRelocating() { |
805
|
|
|
if($this->fleet->mission_type == MT_RELOCATE) { |
806
|
|
|
$arriving_captain = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbTargetRow, UNIT_CAPTAIN, true); |
807
|
|
|
} else { |
808
|
|
|
$arriving_captain = false; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
return empty($arriving_captain) || !is_array($arriving_captain); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
} |
815
|
|
|
|
This check looks for
try
blocks that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.If there is nothing in the
try
then thecatch
block can never be executed either. Thus, thesetry
statements can be removed completely.