/** * 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; }
/** * Creates a new match/turn state * * @return State */ public static function create(Game $game, Match $match, Turn $turn, TerritoryTemplate $territory, Empire $occupier = null, Unit $unit = null) { $o = new State(); $o->setTurn($turn); $o->setTerritory($territory); if (!is_null($occupier)) { // Not sure this is enough for the foreign keys if (is_null($unit)) { throw new InvalidUnitException('Must specify unit in occupation.'); } $o->setOccupation($occupier, $unit); } $o->save(); return $o; }