/** * At this point the game has been created and registered - but the player has not chosen a group. * Note -- if they walk away they will be a player without a group -- not a good thing! */ public function run() { $c = $this->get_controller(); if (!$c->_prep()) { $params = array('error' => 'Cannot start game'); return $this->forward('index', NULL, NULL, $params); } //@TODO: make sure the groups are not already owned! hell is other players $t = Ultimatum_Model_Ultgroups::getInstance()->table(); $sql = sprintf('SELECT %s FROM %s', $t->idField(), $t->tableName()); $ids = $t->getAdapter()->fetchCol($sql); $group_ids = Zupal_Util_Array::random_set($ids, 4); $game_id = $this->view()->game->identity(); foreach ($group_ids as $id) { $groups[] = $group = Ultimatum_Model_Ultgroups::getInstance()->get($id); $gamegroup = new Ultimatum_Model_Ultgamegroups(); $gamegroup->game = $game_id; $gamegroup->group_id = $id; $gamegroup->save(); // note -- will be saved with no owner. $gamegroup->start_size(); $scans[] = $this->view()->player->scan_group($group); } $this->view()->groups = $groups; $this->view()->scans = $scans; }
function get_group($pReload = FALSE) { if ($pReload || is_null($this->_group)) { // process $this->_group = Ultimatum_Model_Ultgroups::getInstance()->get($this->target_group_id); } return $this->_group; }
public function repairatomsAction() { foreach (Pages_Model_Zupalpages::getInstance()->findAll() as $page) { $page->get_atom(); } foreach (Ultimatum_Model_Ultgroups::getInstance()->findAll() as $group) { /** * @var Model_Zupalatoms */ $atom = $group->get_atom(); if (!$atom->get_format_lead()) { $atom->strip_lead_markup(); } if (!$atom->get_format_content()) { $atom->strip_content_markup(); } } $this->_forward('atoms'); }
function get_target($pReload = FALSE) { if ($pReload || is_null($this->_target)) { if ($this->target) { $value = Ultimatum_Model_Ultgroups::getInstance()->get($this->target); } else { $value = FALSE; } // process $this->_target = $value; } return $this->_target; }
public function groupresizeAction() { $game_id = $this->_getParam("game_id", NULL); $group_id = $this->_getParam("group_id", NULL); $size = (int) $this->_getParam('size'); $mode = $this->_getParam('mode'); $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id); $group = Ultimatum_Model_Ultgroups::getInstance()->get($group_id); $sizer = new Ultimatum_Model_Ultplayergroupsize(); $sizer->group_id = $group_id; $sizer->game = $game_id; $sizer->turn = $game->turn(); switch ($mode) { case 'relative': if ($size) { $sizer->size = $size; $sizer->save(); $m_key = 'message'; $message = 'Sice changed by ' . $size; } else { $m_key = 'error'; $message = 'No Size Change Made'; } break; case 'absolute': $current = $group->size_in_game($game_id); if ($current != $size) { $size -= $current; $sizer->size = $size; $sizer->save(); $m_key = 'message'; $message = 'Size changed to ' . $size; } else { $m_key = 'error'; $message = 'No Size Change Made'; } break; } $params = array('id' => $group_id, 'game' => $game_id, $m_key => $message); $this->_forward('gamegroupview', NULL, NULL, $params); }
/** * * @param boolean $pString = FALSE * @return scalar */ public function growth_effect($pString = FALSE) { return Ultimatum_Model_Ultgroups::gp_effect($this, 'growth', $pString); }
/** * * @return <type> */ public function scan_group($pGroup) { $pGroup = Ultimatum_Model_Ultgroups::as_group($pGroup, TRUE); $params = array('target_group_id' => $pGroup, 'player' => $this->identity(), 'active' => 1); $old_scan = Ultimatum_Model_Ultgamegroupscans::getInstance()->findOne($params); if ($old_scan) { return $old_scan; } else { $scan = Ultimatum_Model_Ultgamegroupscans::getInstance()->get(NULL, $params); $scan->on_turn = Ultimatum_Model_Ultgames::get_active()->turn(); $scan->save(); return $scan; } }
/** * * @return void */ public function _prep() { $user = Model_Users::current_user(); if (!$user) { $params = array('error' => 'You must be logged in to run a game. '); $this->_forward('index', 'index', NULL, $params); return FALSE; } $game_id = $this->_getParam('game'); // either actively select game or reactivate last played game if ($game_id) { $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id); $player = Ultimatum_Model_Ultplayers::for_user_game($user, $game)->activate(); } else { $player = Ultimatum_Model_Ultplayers::user_active_player($user); if (!$player) { $params = array('error' => 'cannot find active game'); $this->_forward('index', 'index', NULL, $params); return FALSE; } $game = $player->get_game(); } // at this point the player and game objects should be set. if (!$player) { $params = array('errror' => 'You are not a player in game ' . $id); $this->_forward('index', 'index', NULL, $params); return FALSE; } $this->view->game = $game; $game->activate(); $this->view->player = $player; // there may or may not be a player group specified by paramerters. // player_group refers to the group indirectly by the game group id. // group refers to the group id directly. if ($player_group = $this->_getParam('player_group')) { $this->view->player_group = Ultimatum_Model_Ultgamegroups::getInstance()->get($player_group); } elseif ($group = $this->_getParam("group", NULL)) { $this->view->player_group = $player->player_group($group); } // there may or may not be a target. // the target id is the group id NOT the game group id. if ($target = $this->_getParam('target')) { $this->view->target = $target_obj = Ultimatum_Model_Ultgroups::getInstance()->get($target); $this->view->target_scan = $player->get_scan($target); } return TRUE; }
/** * */ public function as_group($pGroup, $pAs_ID = FALSE) { if (!$pGroup instanceof Ultimatum_Model_Ultgroups) { if ($pGroup instanceof Ultimatum_Model_Ultgamegroups) { $pGroup = $pGroup->get_group(); } elseif (is_numeric($pGroup)) { $pGroup = new Ultimatum_Model_Ultgroups($pGroup); if (!$pGroup->isSaved()) { return NULL; } } } if ($pAs_ID) { return $pGroup->identity(); } else { return $pGroup; } }