Example #1
0
 public function addOrder(Order $l)
 {
     if ($this->getStatus() !== 'open') {
         // One exception, retreats
         if ($this->getStatus() === 'require_retreats' && $l instanceof Retreat) {
             // Good
         } else {
             throw new TurnClosedToOrdersException($this . ' status is "' . $this->getStatus() . '", can only accept orders on "open" state');
         }
     }
     if (is_null($l->getUnitType())) {
         // Guess at the unit based on game state
         $states = StateQuery::create()->filterByTurn($this)->filterByOccupier($l->getEmpire())->filterByTerritory($l->getSource()->getTerritory())->find();
         if (count($states) == 1) {
             if ($states[0]->getUnitType() == 'none') {
                 throw new \DiplomacyOrm\InvalidUnitException("It seems that there is no unit on " . $l->getSource()->getTerritory() . ", cannot issue order.");
             }
             $l->setUnitType($states[0]->getUnitType());
         } else {
             throw new \DiplomacyOrm\InvalidUnitException("Could not determine unit, " . $l->getEmpire() . " likely doesn't own " . $l->getSource()->getTerritory());
         }
     }
     return parent::addOrder($l);
 }