Location: PHPKode > projects > PhpBlock > A9.8/script/tick/abstractgrowthworld.class.php
<?php
/**This tick must be executed as last tick !*/
abstract class AbstractGrowthWorld extends Tick {
    public function __construct($parBlockRangeToCreate, $parServerTickNumber, 
    		$parTimeBaseBetweenRuns, $parResetTimeAfterRun=false) {
        parent::__construct($parServerTickNumber, $parTimeBaseBetweenRuns, $parResetTimeAfterRun=false);
        $this->blockRangeToCreate = $parBlockRangeToCreate;
        $this->minBlockY=Constante::getMinBlockY();
        $this->minBlockX=Constante::getMinBlockX();
        $this->maxBlockY=Constante::getMaxBlockY();
        $this->maxBlockX=Constante::getMaxBlockX();
        $this->worldLeftWidth=Constante::getWorldLeftWidth();
        $this->worldTopHeight=Constante::getWorldTopHeight();
    }

	private $worldLeftWidth;
	private $worldTopHeight;
	private $minBlockY;
	private $minBlockX;
	private $maxBlockY;
	private $maxBlockX;


    public function run() {
        Log::info("range to create: $this->blockRangeToCreate");
        set_time_limit(pow($this->worldLeftWidth+2, 2)*30);
        for($i = 0; $i < $this->blockRangeToCreate; $i++) {
            $this->worldLeftWidth++;
            $this->worldTopHeight++;
            $this->minBlockY-=Constante::$BLOCK_SIZE;
            $this->minBlockX-=Constante::$BLOCK_SIZE;
            $this->maxBlockY+=Constante::$BLOCK_SIZE;
            $this->maxBlockX+=Constante::$BLOCK_SIZE;
            GeneratedConstante::$WORLD_LEFT_WIDTH=$this->worldLeftWidth;
            GeneratedConstante::$WORLD_TOP_HEIGHT=$this->worldTopHeight;

            $this->modifyNewBlock(true);
            $this->modifyNewBlock(false);
        }
        Constante::generateConstante(Constante::getMinZ(), Constante::getMaxZ(), Constante::getWorldCenterX(), Constante::getWorldCenterY(), $this->worldLeftWidth, $this->worldTopHeight);
    }
    public abstract function getZoneGenerate($parZ);
    public abstract function generateBlock($parBlockId, $parZoneGenerator);
    private function generateOrInitialize($parToGenerated, $parBlockId, $locZoneGenerator) {
        if($parToGenerated) {
            $this->generateBlock($parBlockId, $locZoneGenerator);
        } else {
            $this->initializeZone($parBlockId, $locZoneGenerator);
        }
    }
    private function modifyNewBlock($parToGenerated) {
        for($z=Constante::getMinZ();
                $z <= Constante::getMaxZ();
                $z++) {
            $locZoneGenerator = $this->getZoneGenerate($z);

            $locCenterBlockId = Block::getBlockIdWithCenterCoord(Constante::getWorldCenterX(), Constante::getWorldCenterY(), $z);
            if(!mysql_fetch_array(executer("SELECT * FROM block WHERE blockId=$locCenterBlockId"))) {
                $this->generateOrInitialize(true, $locCenterBlockId, $locZoneGenerator);
                $this->generateOrInitialize(false, $locCenterBlockId, $locZoneGenerator);
            }
            $x=$this->maxBlockX;
            for($y=$this->minBlockY;
                    $y <= $this->maxBlockY;
                    $y += Constante::$BLOCK_SIZE) {
                $this->generateOrInitialize($parToGenerated, Block::getBlockIdWithCenterCoord($x, $y, $z), $locZoneGenerator);
            }
            $x=$this->minBlockX;
            for($y=$this->minBlockY;
                    $y <= $this->maxBlockY;
                    $y += Constante::$BLOCK_SIZE) {
                $this->generateOrInitialize($parToGenerated, Block::getBlockIdWithCenterCoord($x, $y, $z), $locZoneGenerator);
            }

            $y=$this->maxBlockY;
            for($x=$this->minBlockX + Constante::$BLOCK_SIZE;
                    $x <= $this->maxBlockX - Constante::$BLOCK_SIZE;
                    $x += Constante::$BLOCK_SIZE) {
                $this->generateOrInitialize($parToGenerated, Block::getBlockIdWithCenterCoord($x, $y, $z), $locZoneGenerator);
            }
            $y=$this->minBlockY;
            for($x=$this->minBlockX + Constante::$BLOCK_SIZE;
                    $x <= $this->maxBlockX - Constante::$BLOCK_SIZE;
                    $x += Constante::$BLOCK_SIZE) {
                $this->generateOrInitialize($parToGenerated, Block::getBlockIdWithCenterCoord($x, $y, $z), $locZoneGenerator);
            }
        }
    }
    private function initializeZone($parBlockId, $locZoneGenerator=false) {
        if($locZoneGenerator != false) {
            $res = executer("SELECT zoneId FROM zone WHERE blockId=$parBlockId");
            while($row = mysql_fetch_array($res)) {
                $locZoneGenerator->randomZone($row[0]);
            }
        }
    }
}
?>
Return current item: PhpBlock