Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1.     function runProduction($t) //$time/ticks
  2.     {
  3.         //run the cycles that are output only
  4.         $this->runOutputCycles($t);
  5.  
  6.         //go over all the province buildings
  7.         foreach ($this->buildings->getBuildings() as $building)
  8.         {
  9.             //if we have a cycle
  10.             if(isset($this->cycles->ageCycles[$building->name]))
  11.             {
  12.                 $building_cycles = $this->cycles->ageCycles[$building->name];
  13.                 foreach($building_cycles as $single_cycle)
  14.                 {
  15.                     $in  = (isset($single_cycle['in']) AND !empty($single_cycle['in'])) ? $single_cycle['in'] : array();
  16.                     $out = isset($single_cycle['out']) ? $single_cycle['out'] : array() ;
  17.                
  18.                     if(count($in) == 0)
  19.                         continue; //skip if there's no input, we've already done the pure output ones
  20.  
  21.                     $stop_cycle = false;
  22.                     foreach($in as $cycle_resource)
  23.                     {
  24.                        $resourceAmount = $this->run_cycle($building,$cycle_resource,$t);
  25.                        if($this->resources->hasEnough($cycle_resource->resourceID,$resourceAmount))
  26.                        {
  27.                               $this->resources->spend($cycle_resource->resourceID,$resourceAmount);
  28.                        }
  29.                        else
  30.                        {
  31.                         $stop_cycle = true;
  32.                         break;
  33.                        }
  34.                     }
  35.                    
  36.                    
  37.                     if(!$stop_cycle)
  38.                     foreach($out as $cycle_resource)
  39.                     {
  40.                         $resourceAmount = $this->run_cycle($building,$cycle_resource,$t);
  41.                         $this->resources->gather($cycle_resource->resourceID,$resourceAmount);
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement