Location: PHPKode > projects > PhpBlock > A9.8/script/tick/actionallobject.php
<?php
include_once $PATH_TO_CODE."/script/tick/allincludefortick.php";

class ActionAllObjectTick extends Tick {
	public function getName() {
		return "ActionAllObjectTick-$this->actionAllObjectTickIndex ($this->actionAllObjectMaxTime)";
	}

	public function __construct($parServerTickNumber, $parActionAllObjectTickIndex, $parActionAllObjectMaxTime,
	$parTimeBaseBetweenRuns, $parResetTimeAfterRun=false) {
		parent::__construct($parServerTickNumber, $parTimeBaseBetweenRuns, $parResetTimeAfterRun);
		$this->actionAllObjectTickIndex = $parActionAllObjectTickIndex;
		$this->actionAllObjectMaxTime = $parActionAllObjectMaxTime;
	}

	public function run() {
		$locBegin = microtime(true);
		global $gloObjectManager;
//		executer("UPDATE object
//		SET timeInMsSinceNoDecision=timeInMsSinceNoDecision+$this->timeElapsedInMs
//		WHERE objectTickIndex=$this->actionAllObjectTickIndex
//		AND isLobotomize=".RealObject::$UNIT_IS_NOT_LOBOTOMIZE);
//		Log::info("a ".((microtime(true)-$locBegin)*1000)."ms ".mysql_affected_rows());

//		executer("UPDATE object
//		SET objectTickIndex=IF(timeInMsSinceNoDecision >= timeInMsBeforeADecision, 0, ".($this->actionAllObjectTickIndex+1).")
//		WHERE objectTickIndex=$this->actionAllObjectTickIndex
//		AND isLobotomize=".RealObject::$UNIT_IS_NOT_LOBOTOMIZE."
//		AND timeInMsSinceNoDecision > $this->actionAllObjectMaxTime");
		executer("UPDATE object
		SET timeInMsSinceNoDecision=timeInMsSinceNoDecision+$this->timeElapsedInMs,
		objectTickIndex=
		IF(timeInMsSinceNoDecision > $this->actionAllObjectMaxTime, 
			IF(timeInMsSinceNoDecision >= timeInMsBeforeADecision, 0, ".($this->actionAllObjectTickIndex+1)."),
			objectTickIndex)
		WHERE objectTickIndex=$this->actionAllObjectTickIndex
		AND isLobotomize=".RealObject::$UNIT_IS_NOT_LOBOTOMIZE);
		Log::info("b ".((microtime(true)-$locBegin)*1000)."ms ".mysql_affected_rows());

		if(0 == $this->actionAllObjectTickIndex) {
			$res = executer("SELECT objectId
			FROM object
			WHERE objectTickIndex=0
			AND isLobotomize=".RealObject::$UNIT_IS_NOT_LOBOTOMIZE."
			AND timeInMsSinceNoDecision >= timeInMsBeforeADecision
			ORDER BY RAND()
			LIMIT 100");
			Log::info("c ".((microtime(true)-$locBegin)*1000)."ms");
			$locObjectIdList = array();
			while($row = mysql_fetch_array($res)) {
				array_push($locObjectIdList, $row[0]);
			}
			$locObjectList = $gloObjectManager->getRealObjects($locObjectIdList);
			Log::info("d ".((microtime(true)-$locBegin)*1000)."ms");			
			foreach($locObjectList as $locObject) {
				if($locObject->isAlive()) {
					Log::info("manage action on ".$locObject->realObjectId);
					$locObject->manageAction($this->timeElapsedInMs);
				} else {
					Log::info("unit ".$locObject->realObjectId." is dead, so it can't act");
				}
			}
			Log::info("e ".((microtime(true)-$locBegin)*1000)."ms");
		}
	}
}
?>
Return current item: PhpBlock