Esempio n. 1
0
/**
 * This function shows the general information page
 */
function takeover_show($caveID, $meineHoehlen, $feedback = NULL)
{
    global $config, $params, $resourceTypeList, $TAKEOVERMAXPOPULARITYPOINTS, $TAKEOVERMINRESOURCEVALUE;
    // get params
    $playerID = $params->SESSION->player->playerID;
    $maxcaves = $params->SESSION->player->takeover_max_caves;
    // open template
    $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'takeover.ihtml');
    // show feedback
    if ($feedback !== NULL) {
        tmpl_set($template, '/MESSAGE/message', $feedback);
    }
    // don't show page, if maxcaves reached
    if (sizeof($meineHoehlen) >= $maxcaves) {
        tmpl_set($template, '/MESSAGE/message', sprintf(_('Sie haben bereits die maximale Anzahl von %d Höhlen erreicht.'), $maxcaves));
        // prepare page
    } else {
        // collect resource ratings
        $ratings = array();
        foreach ($resourceTypeList as $resource) {
            if ($resource->takeoverValue) {
                $ratings[] = array('dbFieldName' => $resource->dbFieldName, 'name' => $resource->name, 'value' => $resource->takeoverValue);
            }
        }
        // fill page
        tmpl_set($template, '/TAKEOVER', array('beliebtheit' => $TAKEOVERMAXPOPULARITYPOINTS, 'mindestgebot' => $TAKEOVERMINRESOURCEVALUE, 'maxcaves' => $maxcaves, 'targetXCoord' => $params->POST->targetXCoord, 'targetYCoord' => $params->POST->targetYCoord, 'RESOURCEVALUE' => $ratings));
        // get bidding
        $bidding = takeover_getBidding();
        if ($bidding) {
            tmpl_set($template, '/TAKEOVER/CHOSEN', $bidding);
            tmpl_set($template, '/TAKEOVER', array('currentXCoord' => $bidding['xCoord'], 'currentYCoord' => $bidding['yCoord']));
        }
    }
    return tmpl_parse($template);
}
Esempio n. 2
0
/**
 * This function delegates the task at issue to the respective function.
 */
function takeover_main($caveID, $ownCaves)
{
    global $template;
    // open template
    $template->setFile('takeover.tmpl');
    $feedback = '';
    $action = Request::getVar('action', '');
    switch ($action) {
        case 'withdrawal':
            if (!Request::isPost('postConfirm')) {
                break;
            }
            if (Request::isPost('postConfirm')) {
                $feedback = takeover_withdrawal();
                break;
            }
            break;
        case 'change':
            if (Request::isPost('abort_change')) {
                break;
            }
            $bidding = takeover_getBidding();
            $xCoord = Request::getVar('xCoord', 0);
            $yCoord = Request::getVar('yCoord', 0);
            $currentYCoord = isset($bidding['yCoord']) ? $bidding['yCoord'] : 0;
            $currentXCoord = isset($bidding['xCoord']) ? $bidding['xCoord'] : 0;
            // only one ordinate
            if ($xCoord == 0 || $yCoord == 0) {
                $feedback = array('type' => 'error', 'message' => _('Zum Wechseln mußt du sowohl die x- als auch die y-Koordinate angeben.'));
                break;
                // already bidding on this cave
            } else {
                if ($currentXCoord == $xCoord && $currentYCoord == $yCoord) {
                    $feedback = array('type' => 'error', 'message' => _('Du bietest bereits für diese Höhle.'));
                    break;
                }
            }
            if (Request::isPost('postConfirm')) {
                $feedback = takeover_change($xCoord, $yCoord);
                break;
            }
            // generate check value
            $_SESSION['change_check'] = uniqid('change_check');
            $template->addVar('change_check', $_SESSION['change_check']);
            $template->addVar('xCoord', $xCoord);
            $template->addVar('yCoord', $yCoord);
            break;
    }
    // get params
    $playerID = $_SESSION['player']->playerID;
    $maxcaves = $_SESSION['player']->takeover_max_caves;
    // show feedback
    if (!empty($feedback)) {
        $template->addVar('status_msg', $feedback);
    }
    // don't show page, if maxcaves reached
    if (sizeof($ownCaves) >= $maxcaves) {
        $template->addVars(array('status_msg' => array('type' => 'info', 'message' => sprintf(_('Sie haben bereits die maximale Anzahl von %d Höhlen erreicht.'), $maxcaves)), 'show_page' => false));
        // prepare page
    } else {
        $template->addVar('show_page', true);
        // collect resource ratings
        $ratings = array();
        foreach ($GLOBALS['resourceTypeList'] as $resource) {
            if ($resource->takeoverValue) {
                $ratings[] = array('dbFieldName' => $resource->dbFieldName, 'name' => $resource->name, 'value' => $resource->takeoverValue);
            }
        }
        /****************************************************************************************************
        *
        * Übergeben ans Template
        *
        ****************************************************************************************************/
        // generate check value
        $_SESSION['withdrawal_check'] = uniqid('withdrawal');
        $template->addVars(array('popularity' => GameConstants::TAKEOVER_MAX_POPULARITY_POINTS, 'maxcaves' => $maxcaves, 'target_x_coord' => Request::getVar('targetXCoord', 0) ? Request::getVar('targetXCoord', 0) : '', 'target_y_coord' => Request::getVar('targetYCoord', 0) ? Request::getVar('targetYCoord', 0) : '', 'resource_ratings' => $ratings, 'withdrawal_check' => $_SESSION['withdrawal_check']));
        // get bidding
        $bidding = takeover_getBidding(count($ownCaves));
        if ($bidding) {
            $template->addVars(array('chosen' => true, 'current_x_coord' => $bidding['xCoord'], 'current_y_Coord' => $bidding['yCoord'], 'current_name' => $bidding['caveName'], 'bidding' => $bidding));
        } else {
            $template->addVar('chosen', false);
        }
    }
}