18. Fleet Activities (flyingfleethandler.php)
In the previous article we have initially studied the source code of the fleet activity, mentioned the trigger of the fleet activity. Now I am further analyzing the fleet activities in Xnova, which are essentially triggered by the player and not timed by the timer. The trigger for the fleet activity is in the common.php, so the entry is in the file, and the code is as follows:
/Check if there is a fleet to reach the destination $_fleets = Doquery (" select * FROM {table}}} WHERE ' Fleet_start_time ' < = ' ". Time ()." '; ", ' fleets ');
or Fleet_end_time <= ". Time ()//loop process per fleet while ($row = Mysql_fetch_array ($_fleets)) {$array = array ();
$array [' galaxy '] = $row [' Fleet_start_galaxy '];
$array [' system '] = $row [' Fleet_start_system '];
$array [' planet '] = $row [' fleet_start_planet '];
$array [' planet_type '] = $row [' Fleet_start_type '];
Fleet processing Function $temp = Flyingfleethandler ($array); Check to see if there is a fleet to return to the starting $_fleets = Doquery ("select * from {{table}}} WHERE ' Fleet_end_time ' <= '". Time (). "';", ' fleets ');
or Fleet_end_time <= ". Time ()//loop process per fleet while ($row = Mysql_fetch_array ($_fleets)) {$array = array ();
$array [' galaxy '] = $row [' Fleet_end_galaxy '];
$array [' system '] = $row [' Fleet_end_system '];
$array [' planet '] = $row [' fleet_end_planet '];
$array [' planet_type '] = $row [' Fleet_end_type '];
Fleet processing Function $temp = Flyingfleethandler ($array); }
As you can see, the previous code is not very good, because it is called every time, the efficiency is too low. So we can optimize here so that each cycle requires only one fleet ID to be passed to the function, and the corresponding function must be modified and interested in the modification.
Let's look at the function Flyingfleethandler (), which is a function that calls the fleet activity centrally.
Lock table, prevent data from being out of sync doquery ("lock table {Table}}lunas Write, {{Table}}rw write, {{Table}}errors write, {{table}}messages
Write, {{Table}}fleets write, {{Table}}planets write, {{Table}}galaxy write, {{table}}users write ', ' "");
A large section here is to obtain the fleet array, parameters can use the Fleet ID, optimization $QryFleet = "Select * from {{table}}";
$QryFleet. = "WHERE (";
$QryFleet. = "("; $QryFleet. = "' fleet_start_galaxy ' =". $planet [' Galaxy ']. "
and "; $QryFleet. = "' Fleet_start_system ' =". $planet [' System '].
and "; $QryFleet. = "' fleet_start_planet ' =". $planet [' Planet ']. "
and "; $QryFleet. = "' Fleet_start_type ' =". $planet [' Planet_type ']. "
";
$QryFleet. = ") OR ("; $QryFleet. = "' fleet_end_galaxy ' =". $planet [' Galaxy ']. "
and "; $QryFleet. = "' Fleet_end_system ' =". $planet [' System '].
and "; $QryFleet. = "' fleet_end_planet ' =". $planet [' Planet ']. ")
and "; $QryFleet. = "' Fleet_end_type ' =". $planet [' Planet_type ']. ")
and "; $QryFleet. = "(' Fleet_start_time ' < '). Time (). "' OR ' Fleet_end_timE ' < '.
Time (). "');";
$fleetquery = Doquery ($QryFleet, ' fleets '); According to the objectives of the fleet activities, enter different function processing while ($CurrentFleet = Mysql_fetch_array ($fleetquery)) {switch ($CurrentFleet ["fleet_
Mission "]) {Case 1://Common attack missioncaseattack ($CurrentFleet);
Break Case 2://This should be an ACS attack or other attack, but there is no doquery ("DELETE from {{table}}} where ' fleet_id '").
$CurrentFleet [' fleet_id ']. "';", ' fleets ');
Break
Case 3://Transport Missioncasetransport ($CurrentFleet);
Break
Case 4://dispatch of Missioncasestay ($CurrentFleet);
Break
Case 5://joint dispatch, i.e. ACS Defense missioncasestayally ($CurrentFleet);
Break
Case 6://Investigative Missioncasespy ($CurrentFleet);
Break
Case 7://Colonial Missioncasecolonisation ($CurrentFleet);
Break
Case 8://Recovery missioncaserecycling ($CurrentFleet);
Break
Case 9://Destroy the Moon, Missioncasedestruction ($CurrentFleet);
Break
Case 10://Reserved!!
Break
Case 15://Expedition, Adventure Missioncaseexpedition ($CurrentFleet); BreaK Other circumstances remove the fleet, this is a good habit. Default: {doquery ("DELETE from {Table}}} WHERE ' fleet_id ' = '".
$CurrentFleet [' fleet_id ']. "';", ' fleets '); }}//Unlock table Doquery ("UNLOCK Tables", "");
The functions above are clearly structured, the code is clear, and the annotations are clear.