|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Vector\Vector; |
|
4
|
|
|
|
|
5
|
|
|
define('SN_IN_FLEET', true); |
|
6
|
|
|
define('SN_RENDER_NAVBAR_PLANET', true); |
|
7
|
|
|
|
|
8
|
|
|
include('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
|
9
|
|
|
|
|
10
|
|
|
// TODO - Переместить это куда-нибудь |
|
11
|
|
|
$fleet_page = sys_get_param_int('fleet_page', sys_get_param_int('mode')); |
|
12
|
|
|
|
|
13
|
|
|
global $template_result, $user, $planetrow; |
|
14
|
|
|
$template_result = !empty($template_result) && is_array($template_result) ? $template_result : array(); |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
require_once('../includes/includes/flt_functions.php'); |
|
18
|
|
|
|
|
19
|
|
|
lng_include('fleet'); |
|
20
|
|
|
|
|
21
|
|
|
$targetVector = new Vector(Vector::READ_PARAMS_FLEET, $planetrow); |
|
22
|
|
|
$target_mission = sys_get_param_int('target_mission', MT_NONE); |
|
23
|
|
|
$ships = sys_get_param_array('ships'); |
|
24
|
|
|
$fleet_group_mr = sys_get_param_id('fleet_group'); |
|
25
|
|
|
$speed_percent = sys_get_param_int('speed', 10); |
|
26
|
|
|
|
|
27
|
|
|
$captainId = sys_get_param_id('captain_id'); |
|
28
|
|
|
// TODO - Missile - targeted unit ID |
|
29
|
|
|
|
|
30
|
|
|
$resources = array( |
|
31
|
|
|
RES_METAL => max(0, floor(sys_get_param_float('resource0'))), |
|
32
|
|
|
RES_CRYSTAL => max(0, floor(sys_get_param_float('resource1'))), |
|
33
|
|
|
RES_DEUTERIUM => max(0, floor(sys_get_param_float('resource2'))), |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
require_once '_tests.php'; |
|
38
|
|
|
|
|
39
|
|
|
$testUser = $user; |
|
40
|
|
|
$testPlanetRow = $planetrow; |
|
41
|
|
|
|
|
42
|
|
|
$testData = array( |
|
43
|
|
|
//array($fleet_page, $user, $planetrow, $targetVector, $target_mission, $ships, $fleet_group_mr, $speed_percent, $missileTarget, $captainId, $resources, $exceptionCode, $resourcesOnPlanet) |
|
|
|
|
|
|
44
|
|
|
// checkSpeedPercentOld - Wrong speed_percent (1..10) |
|
45
|
|
|
array(FLIGHT_FLEET_SPEED_WRONG, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, 1, 1, PT_NONE), MT_NONE, array(), 0, 11, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
46
|
|
|
// checkTargetInUniverse |
|
47
|
|
|
array(FLIGHT_VECTOR_BEYOND_UNIVERSE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(-PHP_INT_MAX, 1, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
48
|
|
|
array(FLIGHT_VECTOR_BEYOND_UNIVERSE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(PHP_INT_MAX, 1, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
49
|
|
|
array(FLIGHT_VECTOR_BEYOND_UNIVERSE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, -PHP_INT_MAX, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
50
|
|
|
array(FLIGHT_VECTOR_BEYOND_UNIVERSE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, PHP_INT_MAX, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
51
|
|
|
// checkTargetNotSource |
|
52
|
|
|
array(FLIGHT_VECTOR_SAME_SOURCE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector($testPlanetRow['galaxy'], $testPlanetRow['system'], $testPlanetRow['planet'], $testPlanetRow['planet_type']), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
53
|
|
|
// TODO 'checkSenderNoVacation' => FLIGHT_PLAYER_VACATION_OWN, |
|
54
|
|
|
// checkTargetNoVacation |
|
55
|
|
|
array(FLIGHT_PLAYER_VACATION, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, 1, 12, PT_PLANET), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
56
|
|
|
// checkFleetNotEmpty |
|
57
|
|
|
array(FLIGHT_SHIPS_NO_SHIPS, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, 1, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
58
|
|
|
|
|
59
|
|
|
// // 'checkUnitsPositive' |
|
60
|
|
|
array(FLIGHT_SHIPS_NEGATIVE, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, 1, 11, PT_PLANET), MT_NONE, array(SHIP_CARGO_SMALL => -1), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
61
|
|
|
// // 'checkOnlyFleetUnits' => FLIGHT_SHIPS_UNIT_WRONG, |
|
|
|
|
|
|
62
|
|
|
// // 'checkOnlyFlyingUnits' => FLIGHT_SHIPS_UNMOVABLE, |
|
63
|
|
|
// // 'checkResourcesPositive' => FLIGHT_RESOURCES_NEGATIVE, |
|
64
|
|
|
// // 'checkNotTooFar' => FLIGHT_FLEET_TOO_FAR, |
|
65
|
|
|
// // 'checkEnoughCapacity' => FLIGHT_FLEET_OVERLOAD, |
|
66
|
|
|
// array(FLIGHT_FLEET_SPEED_WRONG, FLEET_PAGE_MISSION, $testUser, $testPlanetRow, new Vector(1, 1, 1, PT_NONE), MT_NONE, array(), 0, 10, 0, 0, array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0), array(RES_METAL => 0, RES_CRYSTAL => 0, RES_DEUTERIUM => 0)), |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
function testFleet($exceptionCode, $fleet_page, $user, $planetrow, $targetVector, $target_mission, $ships, $fleet_group_mr, $speed_percent, $missileTarget, $captainId, $resources, $resourcesOnPlanet) { |
|
|
|
|
|
|
70
|
|
|
// Инициализируем объекты значениями по умолчанию |
|
71
|
|
|
$objFleet5 = new Fleet(); |
|
72
|
|
|
try { |
|
73
|
|
|
$objFleet5->initDefaults($user, $planetrow, $targetVector, $target_mission, $ships, $fleet_group_mr, $speed_percent, 0, $captainId, $resources); |
|
74
|
|
|
|
|
75
|
|
|
switch ($fleet_page) { |
|
76
|
|
|
// case FLEET_PAGE_DESTINATION: |
|
|
|
|
|
|
77
|
|
|
// $objFleet5->fleetPage1(); |
|
78
|
|
|
// break; |
|
79
|
|
|
// |
|
80
|
|
|
case FLEET_PAGE_MISSION: |
|
81
|
|
|
$objFleet5->fleetPage2Prepare($resourcesOnPlanet); |
|
82
|
|
|
break; |
|
83
|
|
|
// |
|
|
|
|
|
|
84
|
|
|
// case FLEET_PAGE_SEND: |
|
85
|
|
|
// $objFleet5->fleetPage3(); |
|
86
|
|
|
// break; |
|
87
|
|
|
// |
|
88
|
|
|
// case 4: |
|
89
|
|
|
// require('../includes/includes/flt_page4.inc'); |
|
90
|
|
|
// break; |
|
91
|
|
|
// |
|
92
|
|
|
// case 5: |
|
93
|
|
|
// require('../includes/includes/flt_page5.inc'); |
|
94
|
|
|
// break; |
|
95
|
|
|
// |
|
96
|
|
|
// default: |
|
97
|
|
|
// $objFleet5->fleetPage0(); |
|
98
|
|
|
// break; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
print('Passed'); |
|
102
|
|
|
} catch (Exception $e) { |
|
103
|
|
|
if ($exceptionCode !== null && $e->getCode() === $exceptionCode) { |
|
104
|
|
|
print('<font color="green">Exception [' . $exceptionCode . ']: "' . classLocale::$lang['fl_attack_error'][$e->getCode()] . '" - passed</font><br />'); |
|
105
|
|
|
} else { |
|
106
|
|
|
print('<font color="red">'); |
|
107
|
|
|
throw $e; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
unset($objFleet5); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
_testProcess('testFleet', $testData); |
|
115
|
|
|
|
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.