13. Construction Overview (buildings.php)
Starting from this article, the research on xnova focuses on the process, which is actually a large number of functions; the structure of the page will not be explained in detail.
The buildings.php file not only deals with construction, metals and minerals, but also includes four functions: construction, research, shipyards, and defense. It determines which function to enter by passing different parameters, so this file is actually a navigation file. . Below we briefly explain this file.
//更新当前星球的建筑队列,比较复杂 UpdatePlanetBatimentQueueList ( $planetrow, $user ); //处理当前用户的科技研究 HandleTechnologieBuild ( $planetrow, $user ); //下面是根据参数进入不同的功能页面 //造船厂页面 case 'fleet': FleetBuildingPage ( $planetrow, $user ); //研究页面 case 'research': ResearchBuildingPage ( $planetrow, $user, $IsWorking['OnWork'], $IsWorking['WorkOn'] ); //防御页面 case 'defense': DefensesBuildingPage ( $planetrow, $user ); //剩下的自然是建筑页面 default: BatimentBuildingPage ( $planetrow, $user ); 下面我们看更新当前星球的建筑队列函数 function UpdatePlanetBatimentQueueList ( &$CurrentPlanet, &$CurrentUser ) { $RetValue = false; //判断是否有建筑队列,字段b_building_id保存建筑队列 if ( $CurrentPlanet['b_building_id'] != 0 ) { //进入循环,开始处理队列 while ( $CurrentPlanet['b_building_id'] != 0 ) { //如果当前建造的建筑时间小于time的话,就处理,字段b_building保存建筑到期的时间 if ( $CurrentPlanet['b_building'] <= time() ) { //先更新下星球的资源,以后再解析 PlanetResourceUpdate ( $CurrentUser, $CurrentPlanet, $CurrentPlanet['b_building'], false ); //处理掉当前的建筑,并把当前建筑字段清空;代码很多,其实比较简单 $IsDone = CheckPlanetBuildingQueue( $CurrentPlanet, $CurrentUser ); //如果前面处理成功,这里就要处理队列中的下一个建筑,包括扣除资源 if ( $IsDone == true ) { SetNextQueueElementOnTop ( $CurrentPlanet, $CurrentUser ); } } else { $RetValue = true; break; } } } return $RetValue; }
Let’s continue and trace into the CheckPlanetBuildingQueue function. This function has a lot of code, but it’s actually simple; I won’t write comments and will talk about the process. First parse the type of building, construction or demolition, end of construction time, etc. from the field b_building_id; then update the level of the building, upgrade or downgrade; update the maximum space and usable space of the planet; update the time of the current building to 0 and update the current of the remaining construction queue. It's not difficult, haha.
Next, it is not difficult to process the next building in the queue and track the SetNextQueueElementOnTop function. First parse the building data from the queue; then determine whether it can be built, and if so, calculate the construction resources, etc.; if not, send a message, etc.; finally update the time when the building is completed, the remaining building queue and resources, etc. The process is as simple as above, get it.