Home >Backend Development >PHP Tutorial >Xnova (ogame) source code interpretation for PHP web game learning (14)_PHP tutorial

Xnova (ogame) source code interpretation for PHP web game learning (14)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:16935browse

17. Resource update (PlanetResourceUpdate.php page)

We have basically explained the important functions before. In this chapter we analyze the important function PlanetResourceUpdate. Its main function is to update resources, manufacture ships and defense units. The code is very organized. Here is a detailed description:

1. Calculate the maximum storage space of the planet, including the floating value set by the system
2. Calculate the total production and energy consumption of the planet’s three resources, including the expert’s bonus
3. If the planet is the moon, the output and energy calculated above are directly 0
4. Calculate the time since the last resource update
5. Calculate the change in output due to the energy ratio. When the energy is 0, there is only the basic output
6. Next, you need to determine whether it is a holiday. If it is not a holiday, calculate the output during this period based on the data prepared previously and add it to the existing resources
7. Get the number of ships and defenses that should be completed during this period, function HandleElementBuildingQueue
8. Construct the SQL statement, submit it to the server, and the resource update is completed

This function is executed every time the player clicks on each function , giving the player the feeling as if the resources have been calculated in advance, haha. However, in some versions, when a player does not log in for a long time, the player's resources cannot be updated. At this time, the player's resource updates need to be processed. The specific update method can be arbitrary. I use spy detection every time. updated from time to time.

The function HandleElementBuildingQueue will be explained below. The logic is not complicated and it is easy to understand.
Remember here: b_hangar_id is the string to be built, b_hangar is the last maintained construction time .

Explanation:

1. First determine whether there is a construction queue
2. Get the elapsed time and add the hold time
3. Parse the construction queue and save it in the array for later use
4. The following foreach is constructed one by one
5. Finally, if there is anything unfinished, keep it for next time and return to

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824765.htmlTechArticle17. Resource Update (PlanetResourceUpdate.php page) The important functions have been basically explained before. Let’s analyze it in this chapter An important function is PlanetResourceUpdate. Its main function is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn