/** * @param Army $oAttackedArmy * @return array */ public function act(Army $oAttackedArmy) { if ($oAttackedArmy->countAlive()) { return $this->shoot($oAttackedArmy->getRandomAliveUnit()); } return array(); }
/** * When a unit acts, he performs his default action. * A soldier will aim and fire, a tank might move and fire, a medic will heal, and so on. * @param Army $oAttackedArmy * @return array */ public function act(Army $oAttackedArmy) { $aResults = array(); $oResult = new BattleResult(); $oResult->attacker = $this; $oResult->amount = 0; // Insanity if (rand(1, 1000000) == 1) { $oResult->type = BattleLogger::TYPE_INSANE; switch (rand(0, 2)) { case 0: // Suicidal $this->iHealth = 0; $oResult->defender = $this; $oResult->message = $this->getRandomElement($this->aSuicideMessages); $oResult->amount = 1000; break; case 1: // Idle $oResult->defender = $this; $oResult->message = $this->getRandomElement($this->aIdleMessages); break; case 2: // Friendly fire $aResults[] = $this . ' ' . $this->getRandomElement($this->aFriendlyFireMessages) . '!'; $oAttackedUnit = $this->getArmy()->getRandomAliveUnit($this); $aResults = array_merge($aResults, $this->shoot($oAttackedUnit)); break; default: break; } } else { // No insanity, continue as planned $oAttackedUnit = $oAttackedArmy->getRandomAliveUnit(); if ($oAttackedUnit) { return $this->shoot($oAttackedUnit); } else { return array(); } } $aResults[] = $oResult; return $aResults; }