Example #1
0
 /**
  * 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;
 }
 /**
  *
  * @param boolean $pReload
  * @return Ultimatum_Model_Ultgamegroups
  */
 function player_group($pReload = FALSE)
 {
     if ($pReload || is_null($this->_player_group)) {
         $value = Ultimatum_Model_Ultgamegroups::getInstance()->get($this->order()->player_group);
         // process
         $this->_player_group = $value;
     }
     return $this->_player_group;
 }
 function game_group($pReload = FALSE)
 {
     if ($pReload || is_null($this->_game_group)) {
         $value = Ultimatum_Model_Ultgamegroups::as_game_group($this->target_group_id);
         // process
         $this->_game_group = $value;
     }
     return $this->_game_group;
 }
 /**
  *
  * @return Ultimatum_Model_Ultgamegroups
  */
 public function player_group()
 {
     return Ultimatum_Model_Ultgamegroups::getInstance()->get($this->player_group);
 }
 /**
  * @return Ultimatum_Model_Ultplayergrouporders[]
  */
 public function pending_orders()
 {
     $orders = Ultimatum_Model_Ultplayergrouporders::getInstance();
     try {
         $sql = sprintf('SELECT po.id FROM %s po ', $orders->table()->tableName());
         $sql .= sprintf(' LEFT JOIN %s pg ON pg.id = po.player_group ', Ultimatum_Model_Ultgamegroups::getInstance()->table()->tableName());
         $sql .= sprintf(' WHERE po.target = %s ', $this->get_group()->identity());
         $sql .= sprintf(' AND pg.player = %s', $this->player);
         $sql .= ' AND po.active > 0;';
         error_log(__METHOD__ . ': finding orders; sql = ' . $sql);
         $out = $orders->find_from_sql($sql, FALSE);
     } catch (Exception $e) {
         error_log(__METHOD__ . ': error on sql ' . $sql);
         $out = array();
     }
     return $out;
 }
 /**
  *
  */
 public function gameviewstoreAction()
 {
     $game_id = $this->_getParam('game');
     $game = Ultimatum_Model_Ultgames::getInstance()->get($game_id);
     $player_ids = $game->player_ids();
     $player_group_ids = array_values(Ultimatum_Model_Ultgamegroups::getInstance()->player_group_ids($player_ids, TRUE));
     $scanned_group_ids = array_keys(Ultimatum_Model_Ultplayergroupknowledge::getInstance()->last_scans_for_player($player_ids, TRUE));
     $group_ids = array_merge($player_group_ids, $scanned_group_ids);
     array_unique($group_ids);
     $find_params = array('id' => array($group_ids, 'in'));
     $groups = Ultimatum_Model_Ultgroups::getInstance()->find($find_params);
     $out = array();
     foreach ($groups as $group) {
         $data = $group->toArray();
         $data['size'] = $group->size_in_game($game_id);
         $data['title'] = $group->get_title();
         $out[] = $data;
     }
     $this->_store('id', $out);
 }
Example #7
0
 /**
  *
  * @return <type>
  */
 public function next_turn()
 {
     $params = array('game' => $this->identity());
     $pgs = Ultimatum_Model_Ultgamegroups::getInstance()->find($params);
     $this->turn++;
     $this->save();
     foreach ($pgs as $player_group) {
         $po = $player_group->pending_order();
         if ($po->end_turn() <= $this->turn()) {
             $po->execute();
         }
     }
 }
Example #8
0
 /**
  *
  * @param Ultimatum_Model_Ultgroups $pGroup
  * @return Ultimatum_Model_Ultgamegroups
  */
 public function acquire($pGroup)
 {
     if (!($pGroup = $this->_as($pGroup, 'Ultimatum_Model_Ultgroups', TRUE))) {
         throw new Exception(__METHOD__ . ': bad gorup passed : ' . print_r($pGroup, 1));
     }
     $pgi = Ultimatum_Model_Ultgamegroups::getInstance();
     $pg = $pgi->group_for_game($pGroup, $this->get_game(), TRUE);
     $pg->set_player($this);
     return $pg;
 }
 /**
  *
  * @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;
 }
Example #10
0
    /**
     *
     * @param $pPlayer_group
     * @return string
     */
    public function playergroup(Ultimatum_Model_Ultgamegroups $pPlayer_group, $pContent = NULL)
    {
        $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/style/ultimatum/ult_style.css');
        $po = $pPlayer_group->pending_orders();
        $group = $pPlayer_group->get_group();
        ob_start();
        ?>

<fieldset class="ult_groupinfo">
    <legend>Group <?php 
        echo $group->get_title();
        ?>
</legend>
     <?php 
        echo $this->view->powerMatrix($group);
        ?>
    <p><b><?php 
        echo $group->get_lead();
        ?>
</b>:
        <?php 
        echo $group->get_content();
        ?>
</p>
    <?php 
        if ($pContent) {
            echo $pContent;
        } else {
            ?>
    <?php 
            if ($po && count($po)) {
                ?>
    <h3>Pending Orders</h3>
    <ol>
        <?php 
                foreach ($po as $o) {
                    ?>
        <li><?php 
                    echo $o;
                    ?>
 <?php 
                    echo $o->cancel_link();
                    ?>
</li>
        <?php 
                }
                ?>
    </ol>

    <?php 
            }
            ?>
        <h3>Command Group</h3>
    <ul>
    <?php 
            $params = array('active' => 1);
            foreach (Ultimatum_Model_Ultplayergroupordertypes::getInstance()->find($params) as $ot) {
                ?>
        <li><a class="linkbutton" href="/ultimatum/game/order/group/<?php 
                echo $group->identity();
                ?>
/order/<?php 
                echo $ot->identity();
                ?>
/"><?php 
                echo $ot;
                ?>
</a>
            <?php 
                echo $ot->get_lead();
                ?>
    <?php 
            }
            ?>
    </ul>
        <?php 
        }
        ?>
</fieldset>
<?php 
        return ob_get_clean();
    }
 /**
  * This methos presues any integer passed is an identity of a GAME GROUP
  * not a group.
  */
 public static function as_game_group($pGameGroup, $pAs_ID = FALSE)
 {
     if (!$pGameGroup instanceof Ultimatum_Model_Ultgamegroups) {
         if ($pGameGroup instanceof Ultimatum_Model_Ultgroups) {
             $pGameGroup = self::getInstance()->group_for_game($pGameGroup);
         } elseif (is_numeric($pGameGroup)) {
             $pGameGroup = new Ultimatum_Model_Ultgamegroups($pGameGroup);
             if (!$pGameGroup->isSaved()) {
                 return NULL;
             }
         }
     }
     if ($pAs_ID) {
         return $pGameGroup->identity();
     } else {
         return $pGameGroup;
     }
 }