/** * 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; }
/** * Initialize the next turn. Create a new turn, point this match * to it, and copy over the CURRENT state */ public function initiateNextTurn() { global $config; $nextTurn = Turn::create($this->getMatch(), $this); $sql = "INSERT INTO match_state " . " (turn_id, territory_id, occupier_id, unit_type) " . " SELECT :next_turn_id, territory_id, occupier_id, unit_type " . " FROM match_state " . " WHERE turn_id = :current_turn_id "; $stmt = $config->system->db->prepare($sql); $stmt->execute(array(':next_turn_id' => $nextTurn->getPrimaryKey(), ':current_turn_id' => $this->getPrimaryKey())); $nextTurn->reload(); $this->getMatch()->setNextTurn($nextTurn); return $nextTurn; }