Completed
Push — work-fleets ( 2c97e5...fff2b6 )
by SuperNova.WS
05:26
created

FleetValidator::unsetMission()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 7
Ratio 77.78 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 9
rs 9.6666
cc 3
eloc 6
nc 3
nop 3
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
      // TODO - Do the restrictMission checks
28
29
      // TODO - Кое-какие проверки дают FLIGHT_ALLOWED - ЧТО НЕПРАВДА В ДАННОМ СЛУЧАЕ!!!
30
      // На странице 1 некоторые проверки ДОЛЖНЫ БЫТЬ опущены - иначе будет некрасиво
31
      // А вот здесь надо проверять много дополнительной хуйни
32
      $this->checkMissionRestrictions($checklist);
33
34
      // 2nd level restrictions
35
      // Still cheap
36
      $this->restrict2ToAllowedMissions();
37
      $this->restrict2ToAllowedPlanetTypes();
38
    } catch (Exception $e) {
39
      if ($e->getCode() != FLIGHT_ALLOWED) {
40
        pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]);
41
      } else {
42
        pdump('FLIGHT_ALLOWED', FLIGHT_ALLOWED);
43
      }
44
    }
45
  }
46
47
  /**
48
   * @param array $checklist
49
   *
50
   * @throws Exception
51
   */
52
  public function checkMissionRestrictions($checklist) {
53
    foreach ($checklist as $condition => $action) {
54
      $checkResult = call_user_func(array($this, $condition));
55
56
      if (is_array($action) && !empty($action[$checkResult])) {
57
        $action = $action[$checkResult];
58
      }
59
60
      if (is_array($action)) {
61
        $this->checkMissionRestrictions($action);
62
      } elseif (!$checkResult) {
63
        throw new Exception($action, $action);
64
      }
65
    }
66
  }
67
68
69
  /**
70
   * @throws Exception
71
   */
72
  protected function restrict2ToAllowedMissions() {
73
    if (empty($this->fleet->allowed_missions[$this->fleet->mission_type])) {
74
      throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE);
75
    }
76
  }
77
78
  /**
79
   * @throws Exception
80
   */
81
  protected function restrict2ToAllowedPlanetTypes() {
82
    if (empty($this->fleet->allowed_planet_types[$this->fleet->targetVector->type])) {
83
      throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE);
84
    }
85
  }
86
87
88
  /**
89
   * @return bool
90
   */
91
  protected function checkSpeedPercentOld() {
92
    return in_array($this->fleet->oldSpeedInTens, array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
93
  }
94
95
  /**
96
   * @return bool
97
   */
98
  protected function checkSenderNoVacation() {
99
    return empty($this->fleet->dbOwnerRow['vacation']) || $this->fleet->dbOwnerRow['vacation'] >= SN_TIME_NOW;
100
  }
101
102
  /**
103
   * @return bool
104
   */
105
  protected function checkTargetNoVacation() {
106
    return empty($this->fleet->dbTargetOwnerRow['vacation']) || $this->fleet->dbTargetOwnerRow['vacation'] >= SN_TIME_NOW;
107
  }
108
109
  /**
110
   * @return bool
111
   */
112
  protected function checkMultiAccount() {
113
    return sys_is_multiaccount($this->fleet->dbOwnerRow, $this->fleet->dbTargetOwnerRow);
114
  }
115
116
  /**
117
   * @return bool
118
   */
119
  protected function checkTargetNotSource() {
120
    return !$this->fleet->targetVector->isEqualToPlanet($this->fleet->dbSourcePlanetRow);
121
  }
122
123
  /**
124
   * @return bool
125
   */
126
  protected function checkTargetInUniverse() {
127
    return $this->fleet->targetVector->isInUniverse();
128
  }
129
130
  /**
131
   * @return bool
132
   */
133
  protected function checkUnitsPositive() {
134
    return $this->fleet->shipsAllPositive();
135
  }
136
137
  /**
138
   * @return bool
139
   */
140
  protected function checkOnlyFleetUnits() {
141
    return $this->fleet->shipsAllFlying();
142
  }
143
144
  /**
145
   * @return bool
146
   */
147
  protected function checkOnlyFlyingUnits() {
148
    return $this->fleet->shipsAllMovable();
149
  }
150
151
  /**
152
   * @return bool
153
   */
154
  protected function checkEnoughFleetSlots() {
155
    return FleetList::fleet_count_flying($this->fleet->getPlayerOwnerId()) < GetMaxFleets($this->fleet->dbOwnerRow);
156
  }
157
158
159
  /**
160
   * @return bool
161
   */
162
  protected function checkEnoughCapacity($includeResources = true) {
163
    $checkVia = $this->fleet->travelData['consumption'];
164
    $checkVia = ceil(($includeResources ? array_sum($this->fleet->resource_list) : 0) + $checkVia);
165
166
    return
167
      !empty($this->fleet->travelData) &&
168
      is_array($this->fleet->travelData) &&
169
      floor($this->fleet->travelData['capacity']) >= $checkVia;
170
  }
171
172
  /**
173
   * @return bool
174
   */
175
  protected function checkNotTooFar() {
176
    return $this->checkEnoughCapacity(false);
177
  }
178
179
  /**
180
   * @return bool
181
   */
182
  protected function checkDebrisExists() {
183
    return is_array($this->fleet->dbTargetRow) && ($this->fleet->dbTargetRow['debris_metal'] + $this->fleet->dbTargetRow['debris_crystal'] > 0);
184
  }
185
186
187
188
189
190
191
192
193
194
195
196
197
  // Resources checks
198
199
  /**
200
   * @return bool
201
   */
202
  protected function checkResourcesPositive() {
203
    foreach ($this->fleet->resource_list as $resourceId => $resourceAmount) {
204
      if ($resourceAmount < 0) {
205
        return false;
206
      }
207
    }
208
209
    return true;
210
  }
211
212
  /**
213
   * @return bool
214
   */
215
  protected function checkCargo() {
216
    return array_sum($this->fleet->resource_list) >= 1;
217
  }
218
219
  /**
220
   * @return bool
221
   */
222
  protected function checkSourceEnoughFuel() {
223
    $deuteriumOnPlanet = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, RES_DEUTERIUM);
224
225
    return $deuteriumOnPlanet < ceil($this->fleet->travelData['consumption']);
226
  }
227
228
  /**
229
   * @return bool
230
   */
231
  protected function checkSourceEnoughResources() {
232
    $fleetResources = $this->fleet->resource_list;
233
    $fleetResources[RES_DEUTERIUM] = ceil($fleetResources[RES_DEUTERIUM] + $this->fleet->travelData['consumption']);
234
    foreach ($fleetResources as $resourceId => $resourceAmount) {
235
      if (mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, $resourceId) < ceil($fleetResources[$resourceId])) {
236
        return false;
237
      }
238
    }
239
240
    return true;
241
  }
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  // Target vector checks (????????)
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
268
269
  /**
270
   * @return bool
271
   */
272
  protected function checkKnownSpace() {
273
    return $this->fleet->targetVector->isInKnownSpace();
274
  }
275
276
  /**
277
   * @return bool
278
   */
279
  protected function checkTargetExists() {
280
    return !empty($this->fleet->dbTargetRow['id']);
281
  }
282
283
  /**
284
   * @return bool
285
   */
286
  protected function checkTargetIsPlanet() {
287
    return $this->fleet->targetVector->type == PT_PLANET;
288
  }
289
290
  /**
291
   * @return bool
292
   */
293
  protected function checkTargetIsDebris() {
294
    return $this->fleet->targetVector->type == PT_DEBRIS;
295
  }
296
297
  /**
298
   * @return bool
299
   */
300
  protected function checkTargetIsMoon() {
301
    return $this->fleet->targetVector->type == PT_MOON;
302
  }
303
304
305
306
307
308
309
  // Ships checks
310
311
  /**
312
   * @return bool
313
   */
314
  protected function checkFleetNotEmpty() {
315
    return $this->fleet->shipsGetTotal() >= 1;
316
  }
317
318
319
  /**
320
   * @return bool
321
   */
322
  protected function checkSourceEnoughShips() {
323
    return $this->fleet->shipsIsEnoughOnPlanet();
324
  }
325
326
327
  /**
328
   * @return bool
329
   */
330
  protected function checkHaveColonizer() {
331
    // Colonization fleet should have at least one colonizer
332
    return $this->fleet->shipsGetTotalById(SHIP_COLONIZER) >= 1;
333
  }
334
335
  /**
336
   * @return bool
337
   */
338
  protected function checkHaveRecyclers() {
339
    $recyclers = 0;
340
    foreach (sn_get_groups('flt_recyclers') as $recycler_id) {
341
      $recyclers += $this->fleet->shipsGetTotalById($recycler_id);
342
    }
343
344
    return $recyclers >= 1;
345
  }
346
347
  /**
348
   * @return bool
349
   */
350
  protected function checkSpiesOnly() {
351
    return $this->fleet->shipsGetTotalById(SHIP_SPY) == $this->fleet->shipsGetTotal();
352
  }
353
354
  /**
355
   * @return bool
356
   */
357
  protected function checkNotOnlySpies() {
358
    return !$this->checkSpiesOnly();
359
  }
360
361
  /**
362
   * @return bool
363
   */
364
  protected function checkNoMissiles() {
365
    return
366
      $this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET) == 0
367
      &&
368
      $this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERCEPTOR) == 0;
369
  }
370
371
372
  /**
373
   * @return bool
374
   */
375
  protected function checkTargetOwn() {
376
    return $this->fleet->dbTargetRow['id_owner'] == $this->fleet->dbSourcePlanetRow['id_owner'];
377
  }
378
379
  /**
380
   * @return bool
381
   */
382
  protected function forceTargetOwn() {
383
    if ($result = $this->checkTargetOwn()) {
384
      unset($this->fleet->allowed_missions[MT_MISSILE]);
385
      unset($this->fleet->allowed_missions[MT_SPY]);
386
387
      unset($this->fleet->allowed_missions[MT_ATTACK]);
388
      unset($this->fleet->allowed_missions[MT_ACS]);
389
      unset($this->fleet->allowed_missions[MT_DESTROY]);
390
    } else {
391
      unset($this->fleet->allowed_missions[MT_RELOCATE]);
392
    }
393
394
    return $result;
395
  }
396
397
  protected function checkMissionPeaceful() {
398
    return
399
      !$this->fleet->mission_type
400
      ||
401
      in_array($this->fleet->mission_type, array(
402
        MT_HOLD,
403
        MT_RELOCATE,
404
        MT_TRANSPORT,
405
      ));
406
  }
407
408
  /**
409
   * @return bool
410
   */
411
  protected function checkTargetOther() {
412
    return !$this->checkTargetOwn();
413
  }
414
415
416
  /**
417
   * @return bool
418
   */
419
  protected function alwaysFalse() {
420
    return false;
421
  }
422
423
424
  /**
425
   * @return bool
426
   */
427
  protected function checkTargetAllyDeposit() {
428
    $result = mrc_get_level($this->fleet->dbTargetOwnerRow, $this->fleet->dbTargetRow, STRUC_ALLY_DEPOSIT) >= 1;
429
    if (!$result) {
430
      unset($this->fleet->allowed_missions[MT_HOLD]);
431
    }
432
433
    return $result;
434
  }
435
436
437
  /**
438
   * Check mission type OR no mission - and limits available missions to this type if positive
439
   *
440
   * @param int $missionType
441
   *
442
   * @return bool
443
   */
444
  protected function forceMission($missionType) {
445
    $result = !$this->fleet->mission_type || $this->fleet->mission_type == $missionType;
446 View Code Duplication
    if ($result) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
447
      $this->fleet->allowed_missions = array(
448
        $missionType => $this->fleet->exists_missions[$missionType],
449
      );
450
    } else {
451
      unset($this->fleet->allowed_missions[$missionType]);
452
    }
453
454
    return $result;
455
  }
456
457
  /**
458
   * @return bool
459
   */
460
  protected function forceMissionExplore() {
461
    return $this->forceMission(MT_EXPLORE);
462
  }
463
464
  /**
465
   * @return bool
466
   */
467
  protected function forceMissionColonize() {
468
    return $this->forceMission(MT_COLONIZE);
469
  }
470
471
  /**
472
   * @return bool
473
   */
474
  protected function forceMissionRecycle() {
475
    return $this->forceMission(MT_RECYCLE);
476
  }
477
478
  /**
479
   * @return bool
480
   */
481
  protected function forceMissionMissile() {
482
    return $this->forceMission(MT_MISSILE);
483
  }
484
485
  /**
486
   * Just checks mission type
487
   *
488
   * @param int $missionType
489
   *
490
   * @return bool
491
   */
492
  protected function checkMissionNonRestrict($missionType) {
493
    return $this->fleet->mission_type == $missionType;
494
  }
495
496
497
  /**
498
   * @return bool
499
   */
500
  protected function checkNotEmptyMission() {
501
    return !empty($this->fleet->mission_type);
502
  }
503
504
  /**
505
   * @return bool
506
   */
507
  protected function checkMissionRelocate() {
508
    return $this->checkMissionNonRestrict(MT_RELOCATE);
509
  }
510
511
  /**
512
   * @return bool
513
   */
514
  protected function checkMissionHoldNonUnique() {
515
    $result = $this->checkMissionNonRestrict(MT_HOLD);
516
517
    return $result;
518
  }
519
520
  /**
521
   * @return bool
522
   */
523
  protected function checkMissionTransport() {
524
    return $this->checkMissionNonRestrict(MT_TRANSPORT);
525
  }
526
527
  /**
528
   * @return bool
529
   */
530
  protected function forceMissionSpy() {
531
    return $this->forceMission(MT_SPY);
532
  }
533
534
  /**
535
   * @return bool
536
   */
537
  protected function checkRealFlight() {
538
    return $this->fleet->isRealFlight;
539
  }
540
541
542
  /**
543
   * @return bool
544
   */
545
  protected function unsetMissionSpyComplex() {
546
    unset($this->fleet->allowed_missions[MT_SPY]);
547
    if ($this->fleet->mission_type == MT_SPY) {
548
      if ($this->checkRealFlight()) {
549
        return false;
550
      }
551
      $this->fleet->mission_type = MT_NONE;
552
    }
553
554
    return true;
555
  }
556
557
558
  /**
559
   * @return bool
560
   */
561
  protected function checkMissionExists() {
562
    return !empty($this->fleet->exists_missions[$this->fleet->mission_type]);
563
  }
564
565
  /**
566
   * @return bool
567
   */
568
  protected function checkPlayerInactiveOrNotNoob() {
569
    return
570
      $this->checkTargetNotActive()
571
      ||
572
      $this->checkTargetNotNoob();
573
  }
574
575
  /**
576
   * @return bool
577
   */
578
  protected function checkTargetActive() {
579
    return
580
      empty($this->fleet->dbTargetOwnerRow['onlinetime'])
581
      ||
582
      SN_TIME_NOW - $this->fleet->dbTargetOwnerRow['onlinetime'] >= PLAYER_TIME_ACTIVE_SECONDS;
583
  }
584
585
  /**
586
   * @return bool
587
   */
588
  // TODO - REDO MAIN FUNCTION
589
  protected function checkTargetNotActive() {
590
    return !$this->checkTargetActive();
591
  }
592
593
594
  /**
595
   * @return bool
596
   */
597
  protected function checkSameAlly() {
598
    return !empty($this->fleet->dbTargetOwnerRow['ally_id']) && $this->fleet->dbTargetOwnerRow['ally_id'] == $this->fleet->dbOwnerRow['ally_id'];
599
  }
600
601
  /**
602
   * @return bool
603
   */
604
  protected function checkTargetNoob() {
605
    $user_points = $this->fleet->dbTargetOwnerRow['total_points'];
606
    $enemy_points = $this->fleet->dbTargetOwnerRow['total_points'];
607
608
    return
609
      // Target is under Noob Protection but Fleet owner is not
610
      (
611
        classSupernova::$config->game_noob_points
612
        &&
613
        $enemy_points <= classSupernova::$config->game_noob_points
614
        &&
615
        $user_points > classSupernova::$config->game_noob_points
616
      ) || (
617
        classSupernova::$config->game_noob_factor
618
        &&
619
        $user_points > $enemy_points * classSupernova::$config->game_noob_factor
620
      );
621
  }
622
623
  /**
624
   * @return bool
625
   */
626
  // TODO - REDO MAIN FUNCTION
627
  protected function checkTargetNotNoob() {
628
    return !$this->checkTargetNoob();
629
  }
630
631
632
  /**
633
   * @return bool
634
   */
635
  protected function checkMissionHoldReal() {
636
    return
637
      $this->checkRealFlight()
638
      &&
639
      $this->checkMissionHoldNonUnique();
640
  }
641
642
  /**
643
   * @return bool
644
   */
645
  protected function checkMissionHoldOnNotNoob() {
646
    return
647
      $this->checkTargetNotActive()
648
      ||
649
      ($this->checkSameAlly() && classSupernova::$config->ally_help_weak)
650
      ||
651
      $this->checkTargetNotNoob();
652
  }
653
654
655
  // Missiles
656
657
  /**
658
   * @return bool
659
   */
660
  protected function checkOnlyAttackMissiles() {
661
    $missilesAttack = $this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET);
662
663
    return $missilesAttack != 0 && $missilesAttack == $this->fleet->shipsGetTotal();
664
  }
665
666
  /**
667
   * @return bool
668
   */
669
  protected function checkSiloLevel() {
670
    $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET);
671
672
    return mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, STRUC_SILO) >= $sn_data_mip[P_REQUIRE][STRUC_SILO];
673
  }
674
675
  /**
676
   * @return bool
677
   */
678
  protected function checkSameGalaxy() {
679
    return $this->fleet->targetVector->galaxy == $this->fleet->dbSourcePlanetRow['galaxy'];
680
  }
681
682
  /**
683
   * @return bool
684
   */
685
  protected function checkMissileDistance() {
686
    return abs($this->fleet->dbSourcePlanetRow['system'] - $this->fleet->targetVector->system) <= flt_get_missile_range($this->fleet->dbOwnerRow);
687
  }
688
689
  /**
690
   * @return bool
691
   */
692
  protected function checkMissileTarget() {
693
    return empty($this->fleet->targetedUnitId) || in_array($this->fleet->targetedUnitId, sn_get_groups('defense_active'));
694
  }
695
696
697
  /**
698
   * @return int
699
   */
700
  protected function checkExpeditionsMax() {
701
    return get_player_max_expeditons($this->fleet->dbOwnerRow);
702
  }
703
704
  /**
705
   * @return bool
706
   */
707
  protected function checkExpeditionsFree() {
708
    return get_player_max_expeditons($this->fleet->dbOwnerRow) > FleetList::fleet_count_flying($this->fleet->dbOwnerRow['id'], MT_EXPLORE);
709
  }
710
711
  /**
712
   * @return bool
713
   */
714
  protected function checkCaptainSent() {
715
    return $this->fleet->captainId >= 1;
716
  }
717
718
  /**
719
   * @return bool
720
   */
721
  protected function checkCaptainExists() {
722
    return !empty($this->fleet->captain) && is_array($this->fleet->captain);
723
  }
724
725
  /**
726
   * @return bool
727
   */
728
  protected function checkCaptainOnPlanet() {
729
    return $this->fleet->captain['unit_location_type'] == LOC_PLANET;
730
  }
731
732
  /**
733
   * @return bool
734
   */
735
  protected function checkCaptainNotRelocating() {
736
    if ($this->fleet->mission_type == MT_RELOCATE) {
737
      $arriving_captain = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbTargetRow, UNIT_CAPTAIN, true);
738
    } else {
739
      $arriving_captain = false;
740
    }
741
742
    return empty($arriving_captain) || !is_array($arriving_captain);
743
  }
744
745
746
  /**
747
   * @return bool
748
   */
749
  protected function checkMissionDestroyReal() {
750
    return
751
      $this->checkRealFlight()
752
      &&
753
      $this->checkMissionNonRestrict(MT_DESTROY);
754
  }
755
756
  /**
757
   * @return bool
758
   */
759
  protected function checkHaveReapers() {
760
    $unitsTyped = 0;
761
    foreach (sn_get_groups('flt_reapers') as $unit_id) {
762
      $unitsTyped += $this->fleet->shipsGetTotalById($unit_id);
763
    }
764
765
    return $unitsTyped >= 1;
766
  }
767
768
769
  /**
770
   * @return bool
771
   */
772
  protected function checkMissionACSReal() {
773
    return
774
      $this->checkRealFlight()
775
      &&
776
      $this->checkMissionNonRestrict(MT_ACS);
777
  }
778
779
  protected function checkACSInTime() {
780
    return $this->fleet->acs['ankunft'] - $this->fleet->time_launch >= $this->fleet->travelData['duration'];
781
  }
782
783
784
  protected function checkMissionRealAndSelected($missionType) {
785
    return
786
      $this->checkRealFlight()
787
      &&
788
      $this->checkMissionNonRestrict($missionType);
789
  }
790
791
  protected function unsetMission($missionType, $result, $restrictToMission = false) {
792 View Code Duplication
    if (!$result) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
793
      unset($this->fleet->allowed_missions[$missionType]);
794
    } elseif ($restrictToMission) {
795
      $this->fleet->allowed_missions = array(
796
        $missionType => $this->fleet->exists_missions[$missionType],
797
      );
798
    }
799
  }
800
801
  protected function checkMissionResultAndUnset($missionType, $result, $forceMission = false) {
802
    $this->unsetMission($missionType, $result, $forceMission);
803
804
    return $result && $this->checkMissionRealAndSelected($missionType);
805
  }
806
807
808
  /**
809
   * @return bool
810
   */
811
  protected function checkMissionSpyPossibleAndReal() {
812
    return $this->checkMissionResultAndUnset(
813
      MT_SPY,
814
      $this->checkSpiesOnly() && $this->checkTargetOther(),
815
      true
816
    );
817
  }
818
819
  /**
820
   * @return bool
821
   */
822
  protected function checkMissionDestroyAndReal() {
823
    return $this->checkMissionResultAndUnset(
824
      MT_DESTROY,
825
      $this->checkTargetIsMoon() && $this->checkHaveReapers()
826
    );
827
  }
828
829
  /**
830
   * @return bool
831
   */
832
  protected function checkMissionHoldPossibleAndReal() {
833
    return $this->checkMissionResultAndUnset(
834
      MT_HOLD,
835
      $this->checkTargetAllyDeposit() && $this->checkMissionHoldOnNotNoob()
836
    );
837
  }
838
839
  /**
840
   * @return bool
841
   */
842
  protected function checkSpiesOnlyFriendlyRestrictsToRelocate() {
843
    if ($result = $this->checkSpiesOnly()) {
844
      $this->fleet->allowed_missions = array(
845
        MT_RELOCATE => $this->fleet->exists_missions[MT_RELOCATE],
846
      );
847
    }
848
849
    return $result;
850
  }
851
852
853
  protected function checkFleetGroupACS() {
854
    $result = !empty($this->fleet->group_id) && !empty($this->fleet->acs);
855
    $this->unsetMission(MT_ACS, $result, true);
856
    if ($result) {
857
      $this->fleet->mission_type = MT_ACS;
858
    } else {
859
      $this->fleet->group_id = 0;
860
    }
861
862
    return $result;
863
  }
864
865
  protected function checkACSNotEmpty() {
866
    return !empty($this->fleet->acs);
867
  }
868
869
  /**
870
   * @return bool
871
   */
872
  protected function checkACSInvited() {
873
    $playersInvited = !empty($this->fleet->acs['eingeladen']) ? explode(',', $this->fleet->acs['eingeladen']) : array();
874
    foreach($playersInvited as $playerId) {
875
      if(intval($playerId) == $this->fleet->dbOwnerRow['id']) {
876
        return true;
877
      }
878
    }
879
880
    return false;
881
  }
882
883
  /**
884
   * @return bool
885
   */
886
  protected function checkMissionACSPossibleAndReal() {
887
    return $this->checkMissionResultAndUnset(
888
      MT_ACS,
889
      $this->checkACSNotEmpty() && $this->checkACSInvited() && $this->checkACSInTime(),
890
      true
891
    );
892
  }
893
894
  /**
895
   * @return bool
896
   */
897
  protected function checkMissionAttack() {
898
    return $this->checkMissionNonRestrict(MT_ATTACK);
899
  }
900
901
  /**
902
   * @return bool
903
   */
904
  protected function checkMissionTransportPossibleAndReal() {
905
    return $this->checkMissionResultAndUnset(
906
      MT_TRANSPORT,
907
      $this->checkCargo() && $this->checkPlayerInactiveOrNotNoob() && $this->checkNotOnlySpies()
908
    );
909
  }
910
911
  /**
912
   * @return bool
913
   */
914
  protected function checkMissionTransportReal() {
915
    return
916
      $this->checkMissionTransport()
917
      &&
918
      $this->checkRealFlight();
919
  }
920
921
}
922