|
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
|
|
|
|
|
27
|
|
|
$this->checkMissionRestrictions($checklist); |
|
28
|
|
|
|
|
29
|
|
|
// try { |
|
|
|
|
|
|
30
|
|
|
// // TODO - Do the restrictMission checks |
|
31
|
|
|
// |
|
32
|
|
|
// // TODO - Кое-какие проверки дают FLIGHT_ALLOWED - ЧТО НЕПРАВДА В ДАННОМ СЛУЧАЕ!!! |
|
33
|
|
|
// // На странице 1 некоторые проверки ДОЛЖНЫ БЫТЬ опущены - иначе будет некрасиво |
|
34
|
|
|
// // А вот здесь надо проверять много дополнительной хуйни |
|
35
|
|
|
// $this->checkMissionRestrictions($checklist); |
|
36
|
|
|
////pdump('passed'); |
|
37
|
|
|
// |
|
38
|
|
|
// // 2nd level restrictions |
|
39
|
|
|
// // Still cheap |
|
40
|
|
|
//// $this->restrict2ToAllowedMissions(); |
|
41
|
|
|
//// $this->restrict2ToAllowedPlanetTypes(); |
|
42
|
|
|
// } catch (ExceptionFleetInvalid $e) { |
|
43
|
|
|
////pdump($e->getCode(), '$e->getCode()'); |
|
44
|
|
|
////pdump($e->getMessage(), '$e->getMessage()'); |
|
45
|
|
|
// if ($e->getCode() != FLIGHT_ALLOWED) { |
|
46
|
|
|
// pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]); |
|
47
|
|
|
// } else { |
|
48
|
|
|
// pdump('FLIGHT_ALLOWED', FLIGHT_ALLOWED); |
|
49
|
|
|
// } |
|
50
|
|
|
// } |
|
51
|
|
|
pdump('// TODO - Сделать flletvalidator DI - внутре контейнер для методов, а методы - анонимные функции, вызывающие другие методы же', FLIGHT_ALLOWED); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param array $checklist |
|
56
|
|
|
* |
|
57
|
|
|
* @throws Exception |
|
58
|
|
|
*/ |
|
59
|
|
|
public function checkMissionRestrictions($checklist) { |
|
60
|
|
|
foreach ($checklist as $condition => $action) { |
|
61
|
|
|
|
|
62
|
|
|
$checkResult = call_user_func(array($this, $condition)); |
|
63
|
|
|
pdump($action, $condition . ' ' . ($checkResult ? 'TRUE' : 'FALSE')); |
|
64
|
|
|
|
|
65
|
|
|
// // Simple action on failed check |
|
|
|
|
|
|
66
|
|
|
// if(!is_array($action)) { |
|
67
|
|
|
// if(!$checkResult) { |
|
68
|
|
|
// throw new ExceptionFleetInvalid($action, $action); |
|
69
|
|
|
// } else { |
|
70
|
|
|
// continue; |
|
71
|
|
|
// } |
|
72
|
|
|
// } |
|
73
|
|
|
// If check failed and there no alternative actions - throw exception |
|
74
|
|
|
// Shortcut ACTION => FAIL_STATUS instead of ACTION => array(false => FAIL_STATUS) |
|
75
|
|
|
if (!$checkResult && !is_array($action)) { |
|
76
|
|
|
throw new ExceptionFleetInvalid($action, $action); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// If no actions on current result - just skipping to next condition |
|
80
|
|
|
if (!isset($action[$checkResult])) { |
|
81
|
|
|
// If not - just continuing |
|
82
|
|
|
continue; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// Otherwise - we got some action for current result |
|
86
|
|
|
$action = $action[$checkResult]; |
|
87
|
|
|
|
|
88
|
|
|
// Is it a list of conditions? |
|
89
|
|
|
if (is_array($action)) { |
|
90
|
|
|
// Yes - performing condition check |
|
91
|
|
|
$this->checkMissionRestrictions($action); |
|
92
|
|
|
} else { |
|
93
|
|
|
// No - then just performing action |
|
94
|
|
|
throw new ExceptionFleetInvalid($action, $action); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
// // Is there some alternatives? |
|
|
|
|
|
|
99
|
|
|
// if (is_array($action)) { |
|
100
|
|
|
// if (!empty($action[$checkResult])) { |
|
101
|
|
|
// // Now action is selected alternative |
|
102
|
|
|
// $action = $action[$checkResult]; |
|
103
|
|
|
// } else { |
|
104
|
|
|
// continue; |
|
105
|
|
|
// } |
|
106
|
|
|
// // No alternatives - just action |
|
107
|
|
|
// } elseif (!$checkResult) { |
|
108
|
|
|
// // Action launched if check failed |
|
109
|
|
|
// |
|
110
|
|
|
// throw new ExceptionFleetInvalid($action, $action); |
|
111
|
|
|
// } |
|
112
|
|
|
// |
|
113
|
|
|
// // Here we got action that should be processed |
|
114
|
|
|
// |
|
115
|
|
|
////pdump($action, $condition); |
|
116
|
|
|
// |
|
117
|
|
|
////var_dump($checkResult); |
|
118
|
|
|
// // Is new action an array - i.e. list of other checks? |
|
119
|
|
|
// if (is_array($action)) { |
|
120
|
|
|
// // Yes - performing check |
|
121
|
|
|
// $this->checkMissionRestrictions($action); |
|
122
|
|
|
// } else { |
|
123
|
|
|
//// if (!$checkResult) |
|
124
|
|
|
// { |
|
125
|
|
|
// throw new ExceptionFleetInvalid($action, $action); |
|
126
|
|
|
// } |
|
127
|
|
|
// } |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @throws Exception |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function restrict2ToAllowedMissions() { |
|
136
|
|
|
if (empty($this->fleet->allowed_missions[$this->fleet->mission_type])) { |
|
137
|
|
|
throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @throws Exception |
|
143
|
|
|
*/ |
|
144
|
|
|
protected function restrict2ToAllowedPlanetTypes() { |
|
145
|
|
|
if (empty($this->fleet->allowed_planet_types[$this->fleet->targetVector->type])) { |
|
146
|
|
|
throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return bool |
|
153
|
|
|
*/ |
|
154
|
|
|
protected function checkSpeedPercentOld() { |
|
155
|
|
|
return in_array($this->fleet->oldSpeedInTens, array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return bool |
|
160
|
|
|
*/ |
|
161
|
|
|
protected function checkSenderNoVacation() { |
|
162
|
|
|
return empty($this->fleet->dbOwnerRow['vacation']) || $this->fleet->dbOwnerRow['vacation'] <= SN_TIME_NOW; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return bool |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function checkTargetNoVacation() { |
|
169
|
|
|
return empty($this->fleet->dbTargetOwnerRow['vacation']) || $this->fleet->dbTargetOwnerRow['vacation'] >= SN_TIME_NOW; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return bool |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function checkMultiAccountNot() { |
|
176
|
|
|
return !sys_is_multiaccount($this->fleet->dbOwnerRow, $this->fleet->dbTargetOwnerRow); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return bool |
|
181
|
|
|
*/ |
|
182
|
|
|
protected function checkTargetNotSource() { |
|
183
|
|
|
return !$this->fleet->targetVector->isSameLocation($this->fleet->dbSourcePlanetRow); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return bool |
|
188
|
|
|
*/ |
|
189
|
|
|
protected function checkTargetInUniverse() { |
|
190
|
|
|
return $this->fleet->targetVector->isInUniverse(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return bool |
|
195
|
|
|
*/ |
|
196
|
|
|
protected function checkUnitsPositive() { |
|
197
|
|
|
return $this->fleet->shipsAllPositive(); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return bool |
|
202
|
|
|
*/ |
|
203
|
|
|
protected function checkOnlyFleetUnits() { |
|
204
|
|
|
return $this->fleet->shipsAllFlying(); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return bool |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function checkOnlyFlyingUnits() { |
|
211
|
|
|
return $this->fleet->shipsAllMovable(); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return bool |
|
216
|
|
|
*/ |
|
217
|
|
|
protected function checkEnoughFleetSlots() { |
|
218
|
|
|
return FleetList::fleet_count_flying($this->fleet->getPlayerOwnerId()) < GetMaxFleets($this->fleet->dbOwnerRow); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @return bool |
|
224
|
|
|
*/ |
|
225
|
|
|
protected function checkEnoughCapacity($includeResources = true) { |
|
226
|
|
|
$checkVia = $this->fleet->travelData['consumption']; |
|
227
|
|
|
$checkVia = ceil(($includeResources ? array_sum($this->fleet->resource_list) : 0) + $checkVia); |
|
228
|
|
|
|
|
229
|
|
|
return |
|
230
|
|
|
!empty($this->fleet->travelData) && |
|
231
|
|
|
is_array($this->fleet->travelData) && |
|
232
|
|
|
floor($this->fleet->travelData['capacity']) >= $checkVia; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @return bool |
|
237
|
|
|
*/ |
|
238
|
|
|
protected function checkNotTooFar() { |
|
239
|
|
|
return $this->checkEnoughCapacity(false); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @return bool |
|
244
|
|
|
*/ |
|
245
|
|
|
protected function checkDebrisExists() { |
|
246
|
|
|
return is_array($this->fleet->dbTargetRow) && ($this->fleet->dbTargetRow['debris_metal'] + $this->fleet->dbTargetRow['debris_crystal'] > 0); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
// Resources checks |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @return bool |
|
264
|
|
|
*/ |
|
265
|
|
|
protected function checkResourcesPositive() { |
|
266
|
|
|
foreach ($this->fleet->resource_list as $resourceId => $resourceAmount) { |
|
267
|
|
|
if ($resourceAmount < 0) { |
|
268
|
|
|
return false; |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
return true; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @return bool |
|
277
|
|
|
*/ |
|
278
|
|
|
protected function checkCargo() { |
|
279
|
|
|
return array_sum($this->fleet->resource_list) >= 1; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @return bool |
|
284
|
|
|
*/ |
|
285
|
|
|
protected function checkSourceEnoughFuel() { |
|
286
|
|
|
$deuteriumOnPlanet = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, RES_DEUTERIUM); |
|
287
|
|
|
|
|
288
|
|
|
return $deuteriumOnPlanet > ceil($this->fleet->travelData['consumption']); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @return bool |
|
293
|
|
|
*/ |
|
294
|
|
|
protected function checkSourceEnoughResources() { |
|
295
|
|
|
$fleetResources = $this->fleet->resource_list; |
|
296
|
|
|
$fleetResources[RES_DEUTERIUM] = ceil($fleetResources[RES_DEUTERIUM] + $this->fleet->travelData['consumption']); |
|
297
|
|
|
foreach ($fleetResources as $resourceId => $resourceAmount) { |
|
298
|
|
|
if (mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, $resourceId) < ceil($fleetResources[$resourceId])) { |
|
299
|
|
|
return false; |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
return true; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
|
|
312
|
|
|
|
|
313
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
|
|
318
|
|
|
|
|
319
|
|
|
|
|
320
|
|
|
|
|
321
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
|
|
329
|
|
|
|
|
330
|
|
|
// Target vector checks (????????) |
|
|
|
|
|
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* @return bool |
|
334
|
|
|
*/ |
|
335
|
|
|
protected function checkKnownSpace() { |
|
336
|
|
|
return $this->fleet->targetVector->isInKnownSpace(); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* @return bool |
|
341
|
|
|
*/ |
|
342
|
|
|
protected function checkTargetExists() { |
|
343
|
|
|
return !empty($this->fleet->dbTargetRow['id']); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* @return bool |
|
348
|
|
|
*/ |
|
349
|
|
|
protected function checkTargetIsPlanet() { |
|
350
|
|
|
return $this->fleet->targetVector->type == PT_PLANET; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* @return bool |
|
355
|
|
|
*/ |
|
356
|
|
|
protected function checkTargetIsDebris() { |
|
357
|
|
|
return $this->fleet->targetVector->type == PT_DEBRIS; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* @return bool |
|
362
|
|
|
*/ |
|
363
|
|
|
protected function checkTargetIsMoon() { |
|
364
|
|
|
return $this->fleet->targetVector->type == PT_MOON; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
// Ships checks |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* @return bool |
|
376
|
|
|
*/ |
|
377
|
|
|
protected function checkFleetNotEmpty() { |
|
378
|
|
|
return $this->fleet->shipsGetTotal() >= 1; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @return bool |
|
384
|
|
|
*/ |
|
385
|
|
|
protected function checkSourceEnoughShips() { |
|
386
|
|
|
return $this->fleet->shipsIsEnoughOnPlanet(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* @return bool |
|
392
|
|
|
*/ |
|
393
|
|
|
protected function checkHaveColonizer() { |
|
394
|
|
|
// Colonization fleet should have at least one colonizer |
|
395
|
|
|
return $this->fleet->shipsGetTotalById(SHIP_COLONIZER) >= 1; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* @return bool |
|
400
|
|
|
*/ |
|
401
|
|
|
protected function checkHaveRecyclers() { |
|
402
|
|
|
$recyclers = 0; |
|
403
|
|
|
foreach (Fleet::$snGroupRecyclers as $recycler_id) { |
|
404
|
|
|
$recyclers += $this->fleet->shipsGetTotalById($recycler_id); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
return $recyclers >= 1; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* @return bool |
|
412
|
|
|
*/ |
|
413
|
|
|
// TODO - used only as callable. Redo inversion |
|
414
|
|
|
protected function checkSpiesOnly() { |
|
415
|
|
|
return $this->fleet->shipsGetTotalById(SHIP_SPY) == $this->fleet->shipsGetTotal(); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* @return bool |
|
420
|
|
|
*/ |
|
421
|
|
|
protected function checkNotOnlySpies() { |
|
422
|
|
|
return !$this->checkSpiesOnly(); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* @return bool |
|
427
|
|
|
*/ |
|
428
|
|
|
protected function checkNoMissiles() { |
|
429
|
|
|
return |
|
430
|
|
|
$this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET) == 0 |
|
431
|
|
|
&& |
|
432
|
|
|
$this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERCEPTOR) == 0; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* @return bool |
|
438
|
|
|
*/ |
|
439
|
|
|
protected function checkTargetOwn() { |
|
440
|
|
|
return $this->fleet->dbTargetRow['id_owner'] == $this->fleet->dbSourcePlanetRow['id_owner']; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* @return bool |
|
445
|
|
|
*/ |
|
446
|
|
|
protected function forceTargetOwn() { |
|
447
|
|
|
if ($result = $this->checkTargetOwn()) { |
|
448
|
|
|
unset($this->fleet->allowed_missions[MT_EXPLORE]); |
|
449
|
|
|
unset($this->fleet->allowed_missions[MT_COLONIZE]); |
|
450
|
|
|
unset($this->fleet->allowed_missions[MT_RECYCLE]); |
|
451
|
|
|
unset($this->fleet->allowed_missions[MT_MISSILE]); |
|
452
|
|
|
|
|
453
|
|
|
unset($this->fleet->allowed_missions[MT_SPY]); |
|
454
|
|
|
|
|
455
|
|
|
unset($this->fleet->allowed_missions[MT_ATTACK]); |
|
456
|
|
|
unset($this->fleet->allowed_missions[MT_ACS]); |
|
457
|
|
|
unset($this->fleet->allowed_missions[MT_DESTROY]); |
|
458
|
|
|
} else { |
|
459
|
|
|
unset($this->fleet->allowed_missions[MT_RELOCATE]); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
return $result; |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
protected function checkMissionPeaceful() { |
|
466
|
|
|
return |
|
467
|
|
|
!$this->fleet->mission_type |
|
468
|
|
|
|| |
|
469
|
|
|
in_array($this->fleet->mission_type, array( |
|
470
|
|
|
MT_HOLD, |
|
471
|
|
|
MT_RELOCATE, |
|
472
|
|
|
MT_TRANSPORT, |
|
473
|
|
|
)); |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
/** |
|
477
|
|
|
* @return bool |
|
478
|
|
|
*/ |
|
479
|
|
|
protected function checkTargetOther() { |
|
480
|
|
|
return !$this->checkTargetOwn(); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
|
|
484
|
|
|
/** |
|
485
|
|
|
* @return bool |
|
486
|
|
|
*/ |
|
487
|
|
|
protected function alwaysFalse() { |
|
488
|
|
|
return false; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* @return bool |
|
494
|
|
|
*/ |
|
495
|
|
|
protected function checkTargetAllyDeposit() { |
|
496
|
|
|
$result = mrc_get_level($this->fleet->dbTargetOwnerRow, $this->fleet->dbTargetRow, STRUC_ALLY_DEPOSIT) >= 1; |
|
497
|
|
|
if (!$result) { |
|
498
|
|
|
unset($this->fleet->allowed_missions[MT_HOLD]); |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
return $result; |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* @param int $missionType |
|
506
|
|
|
* @param bool $exact |
|
507
|
|
|
* |
|
508
|
|
|
* @return bool |
|
509
|
|
|
*/ |
|
510
|
|
|
protected function checkMission($missionType, $exact = false) { |
|
511
|
|
|
return $this->fleet->mission_type == $missionType || (!$exact && $this->fleet->mission_type == MT_NONE); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* Check mission type OR no mission - and limits available missions to this type if positive |
|
517
|
|
|
* |
|
518
|
|
|
* @param int $missionType |
|
519
|
|
|
* |
|
520
|
|
|
* @return bool |
|
521
|
|
|
*/ |
|
522
|
|
|
protected function forceMission($missionType, $exact = false) { |
|
523
|
|
|
return $this->unsetMission($missionType, $this->checkMission($missionType, $exact), true); |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
protected function unsetMission($missionType, $result, $forceMission = false) { |
|
527
|
|
|
if (!$result) { |
|
528
|
|
|
unset($this->fleet->allowed_missions[$missionType]); |
|
529
|
|
|
} elseif ($forceMission) { |
|
530
|
|
|
$this->fleet->allowed_missions = array( |
|
531
|
|
|
$missionType => $this->fleet->exists_missions[$missionType], |
|
532
|
|
|
); |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
return $result; |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
/** |
|
539
|
|
|
* @param string $name |
|
540
|
|
|
* @param string $prefix |
|
541
|
|
|
* |
|
542
|
|
|
* @return int|false |
|
543
|
|
|
* @throws Exception |
|
544
|
|
|
*/ |
|
545
|
|
|
protected function checkMissionPrefix($name, $prefix) { |
|
546
|
|
|
$result = false; |
|
547
|
|
|
if (strpos($name, $prefix) === 0) { |
|
548
|
|
|
$mission = 'MT_' . strtoupper(substr($name, strlen($prefix))); |
|
549
|
|
|
if (!defined($mission)) { |
|
550
|
|
|
// TODO - Ну, как-то получше это обделать |
|
551
|
|
|
throw new Exception('Mission type "' . $mission . '" is not defined'); |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
$result = constant($mission); |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
return $result; |
|
558
|
|
|
} |
|
559
|
|
|
|
|
560
|
|
|
public function __call($name, $arguments) { |
|
561
|
|
|
$result = null; |
|
562
|
|
|
if (($missionType = $this->checkMissionPrefix($name, 'unsetMission')) !== false) { |
|
563
|
|
|
$result = $this->unsetMission($missionType, false); |
|
564
|
|
|
} elseif (($missionType = $this->checkMissionPrefix($name, 'forceMissionExact')) !== false) { |
|
565
|
|
|
$result = $this->forceMission($missionType, true); |
|
566
|
|
|
} elseif (($missionType = $this->checkMissionPrefix($name, 'forceMission')) !== false) { |
|
567
|
|
|
$result = $this->forceMission($missionType, false); |
|
568
|
|
|
} elseif (($missionType = $this->checkMissionPrefix($name, 'checkMissionExact')) !== false) { |
|
569
|
|
|
$result = $this->checkMission($missionType, true); |
|
570
|
|
|
} elseif (($missionType = $this->checkMissionPrefix($name, 'checkMission')) !== false) { |
|
571
|
|
|
$result = $this->checkMission($missionType, false); |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
return $result; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
/** |
|
578
|
|
|
* Just checks mission type |
|
579
|
|
|
* |
|
580
|
|
|
* @param int $missionType |
|
581
|
|
|
* |
|
582
|
|
|
* @return bool |
|
583
|
|
|
*/ |
|
584
|
|
|
// TODO - obsolete ?? |
|
585
|
|
|
protected function checkMissionExact($missionType) { |
|
586
|
|
|
return $this->checkMission($missionType, true); |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
|
|
590
|
|
|
/** |
|
591
|
|
|
* @return bool |
|
592
|
|
|
*/ |
|
593
|
|
|
protected function checkNotEmptyMission() { |
|
594
|
|
|
return !empty($this->fleet->mission_type); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
/** |
|
598
|
|
|
* @return bool |
|
599
|
|
|
*/ |
|
600
|
|
|
protected function checkRealFlight() { |
|
601
|
|
|
return $this->fleet->isRealFlight; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
|
|
605
|
|
|
/** |
|
606
|
|
|
* @return bool |
|
607
|
|
|
*/ |
|
608
|
|
|
protected function unsetMissionSpyComplex() { |
|
609
|
|
|
unset($this->fleet->allowed_missions[MT_SPY]); |
|
610
|
|
|
if ($this->fleet->mission_type == MT_SPY) { |
|
611
|
|
|
if ($this->checkRealFlight()) { |
|
612
|
|
|
return false; |
|
613
|
|
|
} |
|
614
|
|
|
$this->fleet->mission_type = MT_NONE; |
|
615
|
|
|
} |
|
616
|
|
|
|
|
617
|
|
|
return true; |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
|
|
621
|
|
|
/** |
|
622
|
|
|
* @return bool |
|
623
|
|
|
*/ |
|
624
|
|
|
protected function checkMissionExists() { |
|
625
|
|
|
return !empty($this->fleet->exists_missions[$this->fleet->mission_type]); |
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
/** |
|
629
|
|
|
* @return bool |
|
630
|
|
|
*/ |
|
631
|
|
|
protected function checkMissionAllowed() { |
|
632
|
|
|
return !empty($this->fleet->allowed_missions[$this->fleet->mission_type]); |
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
/** |
|
636
|
|
|
* @return bool |
|
637
|
|
|
*/ |
|
638
|
|
|
protected function checkPlayerInactiveOrNotNoob() { |
|
639
|
|
|
return |
|
640
|
|
|
$this->checkTargetNotActive() |
|
641
|
|
|
|| |
|
642
|
|
|
$this->checkTargetNotNoob(); |
|
643
|
|
|
} |
|
644
|
|
|
|
|
645
|
|
|
/** |
|
646
|
|
|
* @return bool |
|
647
|
|
|
*/ |
|
648
|
|
|
protected function checkTargetActive() { |
|
649
|
|
|
return |
|
650
|
|
|
empty($this->fleet->dbTargetOwnerRow['onlinetime']) |
|
651
|
|
|
|| |
|
652
|
|
|
SN_TIME_NOW - $this->fleet->dbTargetOwnerRow['onlinetime'] >= PLAYER_TIME_ACTIVE_SECONDS; |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
/** |
|
656
|
|
|
* @return bool |
|
657
|
|
|
*/ |
|
658
|
|
|
// TODO - REDO MAIN FUNCTION |
|
659
|
|
|
protected function checkTargetNotActive() { |
|
660
|
|
|
return !$this->checkTargetActive(); |
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
|
|
|
664
|
|
|
/** |
|
665
|
|
|
* @return bool |
|
666
|
|
|
*/ |
|
667
|
|
|
protected function checkSameAlly() { |
|
668
|
|
|
return !empty($this->fleet->dbTargetOwnerRow['ally_id']) && $this->fleet->dbTargetOwnerRow['ally_id'] == $this->fleet->dbOwnerRow['ally_id']; |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* @return bool |
|
673
|
|
|
*/ |
|
674
|
|
|
protected function checkTargetNoob() { |
|
675
|
|
|
$user_points = $this->fleet->dbTargetOwnerRow['total_points']; |
|
676
|
|
|
$enemy_points = $this->fleet->dbTargetOwnerRow['total_points']; |
|
677
|
|
|
|
|
678
|
|
|
return |
|
679
|
|
|
// Target is under Noob Protection but Fleet owner is not |
|
680
|
|
|
( |
|
681
|
|
|
classSupernova::$config->game_noob_points |
|
682
|
|
|
&& |
|
683
|
|
|
$enemy_points <= classSupernova::$config->game_noob_points |
|
684
|
|
|
&& |
|
685
|
|
|
$user_points > classSupernova::$config->game_noob_points |
|
686
|
|
|
) || ( |
|
687
|
|
|
classSupernova::$config->game_noob_factor |
|
688
|
|
|
&& |
|
689
|
|
|
$user_points > $enemy_points * classSupernova::$config->game_noob_factor |
|
690
|
|
|
); |
|
691
|
|
|
} |
|
692
|
|
|
|
|
693
|
|
|
/** |
|
694
|
|
|
* @return bool |
|
695
|
|
|
*/ |
|
696
|
|
|
// TODO - REDO MAIN FUNCTION |
|
697
|
|
|
protected function checkTargetNotNoob() { |
|
698
|
|
|
return !$this->checkTargetNoob(); |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
|
|
702
|
|
|
/** |
|
703
|
|
|
* @return bool |
|
704
|
|
|
*/ |
|
705
|
|
|
protected function checkMissionHoldReal() { |
|
706
|
|
|
return |
|
707
|
|
|
$this->checkRealFlight() |
|
708
|
|
|
&& |
|
709
|
|
|
$this->checkMissionExact(MT_HOLD); |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
/** |
|
713
|
|
|
* @return bool |
|
714
|
|
|
*/ |
|
715
|
|
|
protected function checkMissionHoldOnNotNoob() { |
|
716
|
|
|
return |
|
717
|
|
|
$this->checkTargetNotActive() |
|
718
|
|
|
|| |
|
719
|
|
|
($this->checkSameAlly() && classSupernova::$config->ally_help_weak) |
|
720
|
|
|
|| |
|
721
|
|
|
$this->checkTargetNotNoob(); |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
|
|
725
|
|
|
// Missiles |
|
726
|
|
|
|
|
727
|
|
|
/** |
|
728
|
|
|
* @return bool |
|
729
|
|
|
*/ |
|
730
|
|
|
protected function checkOnlyAttackMissiles() { |
|
731
|
|
|
$missilesAttack = $this->fleet->shipsGetTotalById(UNIT_DEF_MISSILE_INTERPLANET); |
|
732
|
|
|
|
|
733
|
|
|
return $missilesAttack != 0 && $missilesAttack == $this->fleet->shipsGetTotal(); |
|
734
|
|
|
} |
|
735
|
|
|
|
|
736
|
|
|
/** |
|
737
|
|
|
* @return bool |
|
738
|
|
|
*/ |
|
739
|
|
|
protected function checkSiloLevel() { |
|
740
|
|
|
$sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
|
741
|
|
|
|
|
742
|
|
|
return mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbSourcePlanetRow, STRUC_SILO) >= $sn_data_mip[P_REQUIRE][STRUC_SILO]; |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
/** |
|
746
|
|
|
* @return bool |
|
747
|
|
|
*/ |
|
748
|
|
|
protected function checkSameGalaxy() { |
|
749
|
|
|
return $this->fleet->targetVector->galaxy == $this->fleet->dbSourcePlanetRow['galaxy']; |
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
/** |
|
753
|
|
|
* @return bool |
|
754
|
|
|
*/ |
|
755
|
|
|
protected function checkMissileDistance() { |
|
756
|
|
|
return abs($this->fleet->dbSourcePlanetRow['system'] - $this->fleet->targetVector->system) <= flt_get_missile_range($this->fleet->dbOwnerRow); |
|
757
|
|
|
} |
|
758
|
|
|
|
|
759
|
|
|
/** |
|
760
|
|
|
* @return bool |
|
761
|
|
|
*/ |
|
762
|
|
|
protected function checkMissileTarget() { |
|
763
|
|
|
return empty($this->fleet->targetedUnitId) || in_array($this->fleet->targetedUnitId, sn_get_groups('defense_active')); |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
|
|
767
|
|
|
/** |
|
768
|
|
|
* @return int |
|
769
|
|
|
*/ |
|
770
|
|
|
protected function checkExpeditionsMax() { |
|
771
|
|
|
return get_player_max_expeditons($this->fleet->dbOwnerRow) > 0; |
|
772
|
|
|
} |
|
773
|
|
|
|
|
774
|
|
|
/** |
|
775
|
|
|
* @return bool |
|
776
|
|
|
*/ |
|
777
|
|
|
protected function checkExpeditionsFree() { |
|
778
|
|
|
return get_player_max_expeditons($this->fleet->dbOwnerRow) > FleetList::fleet_count_flying($this->fleet->dbOwnerRow['id'], MT_EXPLORE); |
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
/** |
|
782
|
|
|
* @return bool |
|
783
|
|
|
*/ |
|
784
|
|
|
protected function checkCaptainSent() { |
|
785
|
|
|
return $this->fleet->captainId >= 1; |
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
/** |
|
789
|
|
|
* @return bool |
|
790
|
|
|
*/ |
|
791
|
|
|
protected function checkCaptainExists() { |
|
792
|
|
|
return !empty($this->fleet->captain) && is_array($this->fleet->captain); |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
/** |
|
796
|
|
|
* @return bool |
|
797
|
|
|
*/ |
|
798
|
|
|
protected function checkCaptainOnPlanetType() { |
|
799
|
|
|
return $this->fleet->captain['unit_location_type'] == $this->fleet->dbSourcePlanetRow['planet_type']; |
|
800
|
|
|
} |
|
801
|
|
|
|
|
802
|
|
|
/** |
|
803
|
|
|
* @return bool |
|
804
|
|
|
*/ |
|
805
|
|
|
protected function checkCaptainOnPlanetSource() { |
|
806
|
|
|
return $this->checkCaptainOnPlanetType() && $this->fleet->captain['unit_location_id'] == $this->fleet->dbSourcePlanetRow['id']; |
|
807
|
|
|
} |
|
808
|
|
|
|
|
809
|
|
|
/** |
|
810
|
|
|
* @return bool |
|
811
|
|
|
*/ |
|
812
|
|
|
protected function checkCaptainNotRelocating() { |
|
813
|
|
|
if ($this->fleet->mission_type == MT_RELOCATE) { |
|
814
|
|
|
$arriving_captain = mrc_get_level($this->fleet->dbOwnerRow, $this->fleet->dbTargetRow, UNIT_CAPTAIN, true); |
|
815
|
|
|
} else { |
|
816
|
|
|
$arriving_captain = false; |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
return empty($arriving_captain) || !is_array($arriving_captain); |
|
820
|
|
|
} |
|
821
|
|
|
|
|
822
|
|
|
|
|
823
|
|
|
/** |
|
824
|
|
|
* @return bool |
|
825
|
|
|
*/ |
|
826
|
|
|
protected function checkMissionDestroyReal() { |
|
827
|
|
|
return |
|
828
|
|
|
$this->checkRealFlight() |
|
829
|
|
|
&& |
|
830
|
|
|
$this->checkMissionExact(MT_DESTROY); |
|
831
|
|
|
} |
|
832
|
|
|
|
|
833
|
|
|
/** |
|
834
|
|
|
* @return bool |
|
835
|
|
|
*/ |
|
836
|
|
|
protected function checkHaveReapers() { |
|
837
|
|
|
$unitsTyped = 0; |
|
838
|
|
|
foreach (sn_get_groups('flt_reapers') as $unit_id) { |
|
839
|
|
|
$unitsTyped += $this->fleet->shipsGetTotalById($unit_id); |
|
840
|
|
|
} |
|
841
|
|
|
|
|
842
|
|
|
return $unitsTyped >= 1; |
|
843
|
|
|
} |
|
844
|
|
|
|
|
845
|
|
|
|
|
846
|
|
|
/** |
|
847
|
|
|
* @return bool |
|
848
|
|
|
*/ |
|
849
|
|
|
protected function checkMissionACSReal() { |
|
850
|
|
|
return |
|
851
|
|
|
$this->checkRealFlight() |
|
852
|
|
|
&& |
|
853
|
|
|
$this->checkMissionExact(MT_ACS); |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
|
|
protected function checkACSInTime() { |
|
857
|
|
|
return $this->fleet->acs['ankunft'] - $this->fleet->time_launch >= $this->fleet->travelData['duration']; |
|
858
|
|
|
} |
|
859
|
|
|
|
|
860
|
|
|
|
|
861
|
|
|
protected function checkMissionRealAndSelected($missionType) { |
|
862
|
|
|
return |
|
863
|
|
|
$this->checkRealFlight() |
|
864
|
|
|
&& |
|
865
|
|
|
$this->checkMissionExact($missionType); |
|
866
|
|
|
} |
|
867
|
|
|
|
|
868
|
|
|
protected function checkMissionResultAndUnset($missionType, $result, $forceMission = false) { |
|
869
|
|
|
$this->unsetMission($missionType, $result, $forceMission); |
|
870
|
|
|
|
|
871
|
|
|
return $result && $this->checkMissionRealAndSelected($missionType); |
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
|
|
875
|
|
|
/** |
|
876
|
|
|
* @return bool |
|
877
|
|
|
*/ |
|
878
|
|
|
protected function checkMissionSpyPossibleAndReal() { |
|
879
|
|
|
return $this->checkMissionResultAndUnset( |
|
880
|
|
|
MT_SPY, |
|
881
|
|
|
$this->checkSpiesOnly() && $this->checkTargetOther(), |
|
882
|
|
|
true |
|
883
|
|
|
); |
|
884
|
|
|
} |
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* @return bool |
|
888
|
|
|
*/ |
|
889
|
|
|
protected function checkMissionDestroyAndReal() { |
|
890
|
|
|
return $this->checkMissionResultAndUnset( |
|
891
|
|
|
MT_DESTROY, |
|
892
|
|
|
$this->checkTargetIsMoon() && $this->checkHaveReapers() |
|
893
|
|
|
); |
|
894
|
|
|
} |
|
895
|
|
|
|
|
896
|
|
|
/** |
|
897
|
|
|
* @return bool |
|
898
|
|
|
*/ |
|
899
|
|
|
protected function checkMissionHoldPossibleAndReal() { |
|
900
|
|
|
return $this->checkMissionResultAndUnset( |
|
901
|
|
|
MT_HOLD, |
|
902
|
|
|
$this->checkTargetAllyDeposit() && $this->checkMissionHoldOnNotNoob() && $this->checkNotOnlySpies() |
|
903
|
|
|
); |
|
904
|
|
|
} |
|
905
|
|
|
|
|
906
|
|
|
/** |
|
907
|
|
|
* @return bool |
|
908
|
|
|
*/ |
|
909
|
|
|
protected function checkSpiesOnlyFriendlyRestrictsToRelocate() { |
|
910
|
|
|
if ($result = $this->checkSpiesOnly()) { |
|
911
|
|
|
$this->fleet->allowed_missions = array( |
|
912
|
|
|
MT_RELOCATE => $this->fleet->exists_missions[MT_RELOCATE], |
|
913
|
|
|
); |
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
return $result; |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
|
|
920
|
|
|
protected function checkFleetGroupACS() { |
|
921
|
|
|
$result = !empty($this->fleet->group_id) && !empty($this->fleet->acs); |
|
922
|
|
|
$this->unsetMission(MT_ACS, $result, true); |
|
923
|
|
|
if ($result) { |
|
924
|
|
|
$this->fleet->mission_type = MT_ACS; |
|
925
|
|
|
} else { |
|
926
|
|
|
$this->fleet->group_id = 0; |
|
927
|
|
|
} |
|
928
|
|
|
|
|
929
|
|
|
return $result; |
|
930
|
|
|
} |
|
931
|
|
|
|
|
932
|
|
|
protected function checkACSNotEmpty() { |
|
933
|
|
|
return !empty($this->fleet->acs); |
|
934
|
|
|
} |
|
935
|
|
|
|
|
936
|
|
|
/** |
|
937
|
|
|
* @return bool |
|
938
|
|
|
*/ |
|
939
|
|
|
protected function checkACSInvited() { |
|
940
|
|
|
$playersInvited = !empty($this->fleet->acs['eingeladen']) ? explode(',', $this->fleet->acs['eingeladen']) : array(); |
|
941
|
|
|
foreach ($playersInvited as $playerId) { |
|
942
|
|
|
if (intval($playerId) == $this->fleet->dbOwnerRow['id']) { |
|
943
|
|
|
return true; |
|
944
|
|
|
} |
|
945
|
|
|
} |
|
946
|
|
|
|
|
947
|
|
|
return false; |
|
948
|
|
|
} |
|
949
|
|
|
|
|
950
|
|
|
/** |
|
951
|
|
|
* @return bool |
|
952
|
|
|
*/ |
|
953
|
|
|
protected function checkMissionACSPossibleAndReal() { |
|
954
|
|
|
return $this->checkMissionResultAndUnset( |
|
955
|
|
|
MT_ACS, |
|
956
|
|
|
$this->checkACSNotEmpty() && $this->checkACSInvited() && $this->checkACSInTime(), |
|
957
|
|
|
true |
|
958
|
|
|
); |
|
959
|
|
|
} |
|
960
|
|
|
|
|
961
|
|
|
/** |
|
962
|
|
|
* @return bool |
|
963
|
|
|
*/ |
|
964
|
|
|
protected function checkMissionTransportPossibleAndReal() { |
|
965
|
|
|
return $this->checkMissionResultAndUnset( |
|
966
|
|
|
MT_TRANSPORT, |
|
967
|
|
|
$this->checkCargo() && $this->checkPlayerInactiveOrNotNoob() && $this->checkNotOnlySpies() |
|
968
|
|
|
); |
|
969
|
|
|
} |
|
970
|
|
|
|
|
971
|
|
|
/** |
|
972
|
|
|
* @return bool |
|
973
|
|
|
*/ |
|
974
|
|
|
protected function checkMissionTransportReal() { |
|
975
|
|
|
return |
|
976
|
|
|
$this->checkMissionExact(MT_TRANSPORT) |
|
977
|
|
|
&& |
|
978
|
|
|
$this->checkRealFlight(); |
|
979
|
|
|
} |
|
980
|
|
|
|
|
981
|
|
|
|
|
982
|
|
|
protected function checkBashingNotRestricted() { |
|
983
|
|
|
return classSupernova::$config->fleet_bashing_attacks <= 0; |
|
984
|
|
|
} |
|
985
|
|
|
|
|
986
|
|
|
protected function checkBashingBothAllies() { |
|
987
|
|
|
return $this->fleet->dbOwnerRow['ally_id'] && $this->fleet->dbTargetOwnerRow['ally_id']; |
|
988
|
|
|
} |
|
989
|
|
|
|
|
990
|
|
|
protected function checkBashingAlliesHaveRelationWar() { |
|
991
|
|
|
return ali_relation($this->fleet->dbOwnerRow['ally_id'], $this->fleet->dbTargetOwnerRow['ally_id']) == ALLY_DIPLOMACY_WAR; |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
protected function checkBashingBothAlliesAndRelationWar() { |
|
995
|
|
|
return $this->checkBashingBothAllies() && $this->checkBashingAlliesHaveRelationWar(); |
|
996
|
|
|
} |
|
997
|
|
|
|
|
998
|
|
|
protected function checkBashingAlliesWarNoDelay() { |
|
999
|
|
|
$user = $this->fleet->dbOwnerRow; |
|
1000
|
|
|
$enemy = $this->fleet->dbTargetOwnerRow; |
|
1001
|
|
|
|
|
1002
|
|
|
$relations = ali_relations($user['ally_id'], $enemy['ally_id']); |
|
1003
|
|
|
|
|
1004
|
|
|
return SN_TIME_NOW - $relations[$enemy['ally_id']]['alliance_diplomacy_time'] > classSupernova::$config->fleet_bashing_war_delay; |
|
1005
|
|
|
} |
|
1006
|
|
|
|
|
1007
|
|
|
|
|
1008
|
|
|
protected function checkBashingNone() { |
|
1009
|
|
|
$user = $this->fleet->dbOwnerRow; |
|
1010
|
|
|
|
|
1011
|
|
|
$time_limit = SN_TIME_NOW + $this->fleet->travelData['duration'] - classSupernova::$config->fleet_bashing_scope; |
|
1012
|
|
|
$bashing_list = array(SN_TIME_NOW); |
|
1013
|
|
|
|
|
1014
|
|
|
// Retrieving flying fleets |
|
1015
|
|
|
$objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $this->fleet->dbTargetRow); |
|
1016
|
|
View Code Duplication |
foreach ($objFleetsBashing->_container as $fleetBashing) { |
|
|
|
|
|
|
1017
|
|
|
// Checking for ACS - each ACS count only once |
|
1018
|
|
|
if ($fleetBashing->group_id) { |
|
1019
|
|
|
$bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target; |
|
1020
|
|
|
} else { |
|
1021
|
|
|
$bashing_list[] = $fleetBashing->time_arrive_to_target; |
|
1022
|
|
|
} |
|
1023
|
|
|
} |
|
1024
|
|
|
|
|
1025
|
|
|
// Check for joining to ACS - if there are already fleets in ACS no checks should be done |
|
1026
|
|
|
if ($this->fleet->mission_type == MT_ACS && $bashing_list["{$user['id']}_{$this->fleet->group_id}"]) { |
|
1027
|
|
|
return true; |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
$query = DBStaticFleetBashing::db_bashing_list_get($user, $this->fleet->dbTargetRow, $time_limit); |
|
1031
|
|
|
while ($bashing_row = db_fetch($query)) { |
|
1032
|
|
|
$bashing_list[] = $bashing_row['bashing_time']; |
|
1033
|
|
|
} |
|
1034
|
|
|
|
|
1035
|
|
|
sort($bashing_list); |
|
1036
|
|
|
|
|
1037
|
|
|
$last_attack = 0; |
|
1038
|
|
|
$wave = 0; |
|
1039
|
|
|
$attack = 1; |
|
1040
|
|
|
foreach ($bashing_list as &$bash_time) { |
|
1041
|
|
|
$attack++; |
|
1042
|
|
|
if ( |
|
1043
|
|
|
$bash_time - $last_attack > classSupernova::$config->fleet_bashing_interval |
|
1044
|
|
|
|| |
|
1045
|
|
|
$attack > classSupernova::$config->fleet_bashing_attacks |
|
1046
|
|
|
) { |
|
1047
|
|
|
$wave++; |
|
1048
|
|
|
$attack = 1; |
|
1049
|
|
|
} |
|
1050
|
|
|
|
|
1051
|
|
|
$last_attack = $bash_time; |
|
1052
|
|
|
} |
|
1053
|
|
|
|
|
1054
|
|
|
return $wave <= classSupernova::$config->fleet_bashing_waves; |
|
1055
|
|
|
} |
|
1056
|
|
|
|
|
1057
|
|
|
} |
|
1058
|
|
|
|
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.