Пример #1
0
 /**
  * New match.
  * @param $name Name of the match/map
  * @param $year Stating year, i.e. 1846
  * @param $season Starting season (0=spring, 1=fall)
  **/
 public static function create(Game $game, $name)
 {
     $m = new Match();
     $m->setGame($game);
     $m->setName($name);
     // Create the first turn
     $turn = Turn::create($m);
     $m->setCurrentTurn($turn);
     // Copy over the territories to our first state
     $tts = $game->getGameTerritories();
     foreach ($tts as $tt) {
         $state = State::create($game, $m, $turn, $tt, $tt->getInitialOccupier(), new Unit($tt->getInitialUnit()));
     }
     $m->save();
     return $m;
 }
Пример #2
0
 /**
  * Try to look up a game territory given a string.  This is intended
  * to be as loose as possible to match what people type.  Only return
  * if one result is found.
  *
  * @param $str Territory name, or abbreviation, or anything we put in
  *             the system that a user may use
  * @param Match Requires a match such that it can use the current turn,
  *              without this several results (one per turn) will be returned
  *              everytime
  * @param Empire Sometimes we can limit what territories might be
  *               being searched for by the empire.  In this case,
  *               use the game state to filter the results.
  * @return State
  * @throws TerritoryMatchException
  */
 public function lookupTerritory($str, Match $match, Empire $empire = null)
 {
     //global $config; $config->system->db->useDebug(true);
     $query = StateQuery::create()->filterByTurn($match->getCurrentTurn())->_if($empire instanceof Empire)->filterByOccupier($empire)->_endif()->join('State.Territory')->useTerritoryQuery()->filterByGame($this)->filterByName($str . '%', Criteria::LIKE)->_or()->filterByPrimaryKey($str)->endUse();
     $ts = $query->find();
     //$config->system->db->useDebug(false);
     if (count($ts) == 1) {
         return $ts[0];
     } elseif (count($ts) > 1) {
         $match_names = [];
         foreach ($ts as $t) {
             $match_names[] = $t->getTerritory()->getName();
         }
         throw new MultiTerritoryMatchException("Multiple matches for {$str}: '" . join("', '", $match_names) . "'");
     } else {
         $msg = "No match for {$str}";
         if (!is_null($empire)) {
             $msg .= ". Purhaps {$empire} does not own {$str}?";
         }
         throw new NoTerritoryMatchException($msg);
     }
 }