This article mainly introduces how to process the fleet activity page of PHP web game Xnova (ogame) source code. if you need it, refer to the following October 18 and fleet activity (FlyingFleetHandler. php)
In the previous article, we have initially studied the source code of the fleet activity and mentioned the triggering of the fleet activity. Now I will further analyze the Xnova Fleet Activities, which are essentially triggered by players rather than timer computing. The triggering of fleet activities is carried out in common. php, so the entry is in this file, and the code is as follows:
// Check whether there is a fleet $ _ fleets = doquery ("SELECT * FROM {table} WHERE 'Fleet _ start_time '<= '". time (). "';", 'fleets'); // OR fleet_end_time <= ". time () // cyclically process each 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 handler function $ temp = FlyingFleetHandler ($ array );} // check whether the ship $ _ fleets = doquery ("SELECT * FROM {table} WHERE 'Fleet _ end_time '<='" is returned '". time (). "';", 'fleets'); // OR fleet_end_time <= ". time () // cyclically process each 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 handler function $ temp = FlyingFleetHandler ($ array );}
As you can see, the previous code is actually not well written, because it is called every time and the efficiency is too low. Therefore, we can optimize it here so that each loop only needs the ID of a fleet to be passed to the function. the corresponding function also needs to be modified and you can modify it as you like.
Next let's take a look at the function FlyingFleetHandler (), which is a function that calls the fleet activity in a centralized manner.
// LOCK the TABLE to prevent data synchronization and other problems. 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 segment here is to obtain the fleet array. the parameter can use the fleet ID, optimized $ 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'); // varies depending on the purpose of the fleet activity, go to different function processing while ($ CurrentFleet = mysql_fetch_array ($ fleetquery) {switch ($ CurrentFleet ["fleet_mission"]) {case 1: // MissionCaseAttack ($ CurrentFlee T); break; case 2: // This should be an ACS attack or another attack, however, doquery ("delete from {table} WHERE 'Fleet _ id' = '" is not used now '". $ CurrentFleet ['Fleet _ id']. "';", 'fleets'); break; case 3: // transport MissionCaseTransport ($ CurrentFleet); break; case 4: // dispatch MissionCaseStay ($ CurrentFleet); break; case 5: // joint dispatch, that is, ACS Defense MissionCaseStayAlly ($ CurrentFleet); break; case 6: // detects MissionCaseSpy ($ CurrentFleet); break; case 7: // colonial MissionCaseColonisation ($ CurrentFleet); break; case 8: // reclaim MissionCaseRecycling ($ CurrentFleet); break; case 9: // destroy the month, missionCaseDestruction ($ CurrentFleet); break; case 10: // retained !! Break; case 15: // expedition, adventure missioncaseincludition ($ CurrentFleet); break; // delete the fleet in other cases. this is a good habit of default: {doquery ("delete from {table} WHERE 'Fleet _ id' = '". $ CurrentFleet ['Fleet _ id']. "';", 'fleets') ;}}// UNLOCK table doquery ("unlock tables ","");
The above function structure is clear, the code is clear, and the comments are also very clear.