Exemplo n.º 1
0
 /**
  *
  * @return Ultimatum_Model_Ultgames
  */
 public static function getInstance()
 {
     if ($pReload || is_null(self::$_Instance)) {
         // process
         self::$_Instance = new self();
     }
     return self::$_Instance;
 }
Exemplo n.º 2
0
 public function __construct($pGroup, $pGame = NULL)
 {
     $pGroup = Zupal_Domain_Abstract::_as($pGroup, 'Ultimatum_Model_Ultgroups');
     if ($pGame) {
         $pGame = Zupal_Domain_Abstract::_as($pGame, 'Ultimatum_Model_Ultgames');
     } else {
         $pGame = Ultimatum_Model_Ultgames::get_active();
     }
     parent::_load();
     $this->game_id->set_value($pGame->identity());
     $this->group_id->set_value($pGroup->identity());
     $this->set_label('Change size of ' . $pGroup);
 }
 public function group_sizes($pGroup, $pGame = NULL)
 {
     $pGroup = Zupal_Domain_Abstract::_as($pGroup, 'Ultimatum_Model_Ultgroups');
     if (!$pGroup) {
         throw new Exception(__METHOD__ . ': no group found');
     }
     if (is_null($pGame)) {
         $pGame = Ultimatum_Model_Ultgames::get_active();
     } else {
         $pGame = Zupal_Domain_Abstract::_as($pGame, 'Ultimatum_Model_Ultgames');
     }
     if (!$pGame) {
         throw new Exception(__METHOD__ . ': no game found');
     }
     $params = array('game' => $pGame->identity(), 'group_id' => $pGroup->identity());
     return $this->find($params, array('turn', 'changed_on'));
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 /**
  *
  * @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;
     }
 }
Exemplo n.º 6
0
 /**
  *
  * @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;
 }
Exemplo n.º 7
0
 /**
  * This method is a bit more "expansive" than as_game_group
  * as it allows a game group object to autospawn if $pGreat = TRUE.
  * @param  $pGroup
  * @return Ultimatum_Model_Ultgamegroups
  */
 public function group_for_game($pGroup, $pGame = NULL, $pCreate = FALSE)
 {
     $pGroup = Zupal_Domain_Abstract::_as($pGroup, 'Ultimatum_Model_Ultgroups', TRUE);
     $pGame = $pGame ? Zupal_Domain_Abstract::_as($pGame, 'Ultimatum_Model_Ultgames', TRUE) : Ultimatum_Model_Ultgames::getInstance()->get_active_id();
     $params = array('group' => $pGroup, 'game' => $pGame);
     $gfg = $this->findOne($params);
     if (!$gfg && $pCreate) {
         $gfg = new self();
         $gfg->group = $pGroup;
         $gfg->game = $pGame;
         $gfg->save();
     }
     return $gfg;
 }
Exemplo n.º 8
0
    /**
     *
     * @param Ultimatum_Model_GroupProfileIF $pParam
     * @return <type>
     */
    public function powerMatrix(Ultimatum_Model_GroupProfileIF $profile)
    {
        ob_start();
        ?>
<table class="ult_power_matrix">
    <tr>
        <th>Off</th>
        <th>Def</th>
        <th>Grow</th>
        <th>Net</th>
    </tr>
    <?php 
        if (Ultimatum_Model_Ultgames::get_active()) {
            ?>
    <tr>
        <td><small><?php 
            echo $profile->offense_size(TRUE);
            ?>
 &times; <?php 
            echo $profile->offense_efficiency(TRUE);
            ?>
</small></td>
        <td><small><?php 
            echo $profile->defense_size(TRUE);
            ?>
 &times; <?php 
            echo $profile->defense_efficiency(TRUE);
            ?>
</small></td>
        <td><small><?php 
            echo $profile->growth_size(TRUE);
            ?>
 &times; <?php 
            echo $profile->growth_efficiency(TRUE);
            ?>
</small></td>
        <td><small><?php 
            echo $profile->network_size(TRUE);
            ?>
 &times; <?php 
            echo $profile->network_efficiency(TRUE);
            ?>
</small></td>
        </tr>
    <tr>
        <td><?php 
            echo $profile->offense_effect(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->defense_effect(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->growth_effect(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->network_effect(TRUE);
            ?>
</td>
    </tr>
    <?php 
        } else {
            ?>
    <tr>
        <td><?php 
            echo $profile->offense_efficiency(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->defense_efficiency(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->growth_efficiency(TRUE);
            ?>
</td>
        <td><?php 
            echo $profile->network_efficiency(TRUE);
            ?>
</td>
    </tr>

    <?php 
        }
        ?>
</table>

<?php 
        return ob_get_clean();
    }
Exemplo n.º 9
0
 /**
  *
  * @param int $pGame_id
  * @return <type>
  */
 public function sizes($pGame_id = NULL)
 {
     if (!$pGame) {
         $pGame = Ultimatum_Model_Ultgames::get_active();
     }
     if ($pGame) {
         $sizes = $this->sizes_in_game($pGame);
     } else {
         $sizes = array();
     }
     return $sizes;
 }