PHP Web Game Learning Xnova (Ogame) source Interpretation (15) _php instance

Source: Internet
Author: User
18. Fleet Activities (flyingfleethandler.php)

In the previous article, we had a preliminary study of the source of the fleet activity, mentioned the triggering of the fleet activity. Now I'm going to analyze the fleet activity in Xnova, which is triggered by the player in essence, not by the timer. The triggering of the fleet activity is carried out in common.php, so the entry is in this file, 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 each fleet while ($row = Mysql_fetch_array ($_fleets)) {$array = array (); $array [' G Alaxy '] = $row [' Fleet_start_galaxy ']; $array [' system '] = $row [' Fleet_start_system ']; $array [' planet '] = $row [' Fleet_st Art_planet ']; $array [' planet_type '] = $row [' Fleet_start_type '];//fleet processing function $temp = Flyingfleethandler ($array);} Check if there is a fleet returning to the origin $_fleets = Doquery ("select * from {{table}}} WHERE ' Fleet_end_time ' <= '". Time (). "';", ' fleets '); OR fleet_end_time <= ". Time ()//loop process each fleet while ($row = Mysql_fetch_array ($_fleets)) {$array = array (); $array [' G Alaxy '] = $row [' Fleet_end_galaxy ']; $array [' system '] = $row [' Fleet_end_system ']; $array [' planet '] = $row [' Fleet_end_pl Anet ']; $array [' planet_type '] = $row [' Fleet_end_type '];//fleet processing function $temp = Flyingfleethandler ($array);} 

As you can see, the code in front of this is actually not 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 should be modified, interested in modifying itself.

Next look at the function Flyingfleethandler (), which is the function that centrally calls the fleet activity.

Lock table to prevent problems such as data 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, "");//Here's a big part of getting the fleet array. , parameters can be fully used fleet ID, optimized $qryfleet = "Select * from {{table}}", $QryFleet. = "WHERE ("; $QryFleet. = "("; $QryFleet. = "' Fleet_sta Rt_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 ');//Depending on the target of the fleet activity, enter different functions to handle 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 another attack, but it is not currently used with 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://Scout Missioncasespy ($CurrentFleet); Break  Case 7://Colonial Missioncasecolonisation ($CurrentFleet); Break  Case 8://Recovery missioncaserecycling ($CurrentFleet); Break  Case 9://Ruin the month, missioncasedestruction ($CurrentFleet); Break   Case 10://Reserved!! Break  Case 15://Expedition, Expedition missioncaseexpedition ($CurrentFleet); Break Other conditions to remove the fleet, this is the good habit of default: {doquery ("delete from {{table}} WHERE ' fleet_id ' = ' ". $CurrentFleet [' fleet_id ']. "';", ' fleets '); }}}//Unlock Table Doquery ("UNLOCK TABLES", "");

The above function is clearly structured, the code is clear, and the annotations are clear.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.