Esempio n. 1
0
function include_army2_text()
{
    // M: Secure / Validate Input
    if (!isset($_POST['trained'])) {
        include_once 'inc/pages/logout.inc.php';
    }
    $objUser =& $GLOBALS["objSrcUser"];
    $arrArmys = $objUser->get_armys();
    $iCitizens = $objUser->get_pop(CITIZENS);
    $arrArmysHome = $objUser->get_armys_home();
    $arrGoods = $objUser->get_goods();
    $arrUsers = $objUser->get_user_infos();
    $objRace = $objUser->get_race();
    $arrUnitVariables = $objRace->getUnitVariables();
    $arrUnitNames = $objRace->getUnitNames();
    $arrUnitCost = $objRace->getUnitCosts();
    $arrToTrain = $_POST['trained'];
    $arrToTrain[UNIT1] = max(0, floor(intval($arrToTrain[UNIT1])));
    $arrToTrain[UNIT2] = max(0, floor(intval($arrToTrain[UNIT2])));
    $arrToTrain[UNIT3] = max(0, floor(intval($arrToTrain[UNIT3])));
    $arrToTrain[UNIT4] = max(0, floor(intval($arrToTrain[UNIT4])));
    $arrToTrain[UNIT5] = max(0, floor(intval($arrToTrain[UNIT5])));
    // Maximum military trainable
    $arrMax = getMaxTrain($objUser);
    if ($arrToTrain[UNIT1] > $arrMax[UNIT1]) {
        $arrToTrain[UNIT1] = $arrMax[UNIT1];
    }
    if ($arrToTrain[UNIT2] > $arrMax[UNIT2]) {
        $arrToTrain[UNIT2] = $arrMax[UNIT2];
    }
    if ($arrToTrain[UNIT3] > $arrMax[UNIT3]) {
        $arrToTrain[UNIT3] = $arrMax[UNIT3];
    }
    if ($arrToTrain[UNIT4] > $arrMax[UNIT4]) {
        $arrToTrain[UNIT4] = $arrMax[UNIT4];
    }
    if ($arrToTrain[UNIT5] > $arrMax[UNIT5]) {
        $arrToTrain[UNIT5] = $arrMax[UNIT5];
    }
    if ($objRace->getRaceName() != "Oleg Hai") {
        $iToTrain = array_sum($arrToTrain);
        $iNonBasics = array_sum($arrToTrain) - $arrToTrain[UNIT1];
        $iBasicsNeeded = $iToTrain - $arrToTrain[UNIT1];
    } else {
        $iToTrain = $arrToTrain[UNIT1] + $arrToTrain[UNIT2] + $arrToTrain[UNIT3] + $arrToTrain[UNIT5];
        $iNonBasics = $arrToTrain[UNIT2] + $arrToTrain[UNIT3] + $arrToTrain[UNIT5];
        $iBasicsNeeded = max(0, $iToTrain - $arrToTrain[UNIT1]);
    }
    // M: Check if any numbers were provided
    if ($iToTrain <= 0 && $objRace->getRaceName() != "Oleg Hai") {
        header('location: main.php?cat=game&page=army&error=empty');
        exit;
    } elseif ($iBasicsNeeded > $arrArmysHome[UNIT1]) {
        header('location: main.php?cat=game&page=army&error=basics');
        exit;
    }
    // Training should not bring population below 800
    $iPossiblePop = $iCitizens - $arrToTrain[UNIT1];
    if ($objRace->getRaceName() == "Oleg Hai") {
        $iPossiblePop = $iCitizens - ($arrToTrain[UNIT1] + $arrToTrain[UNIT4]);
    }
    if ($iPossiblePop < 800) {
        header('location: main.php?cat=game&page=army&error=poplimit');
        exit;
    }
    // Total cost to train
    $iToPay = $arrUnitCost[2] * $arrToTrain[UNIT1] + $arrUnitCost[3] * $arrToTrain[UNIT2] + $arrUnitCost[4] * $arrToTrain[UNIT3] + $arrUnitCost[5] * $arrToTrain[UNIT4] + $arrUnitCost[6] * $arrToTrain[UNIT5];
    // Check that we have enough money
    if ($iToPay > $arrGoods[MONEY]) {
        header('location: main.php?cat=game&page=army&error=money');
        exit;
    }
    // At the end of a lifespan you can't train or release military
    if ($arrUsers[HOURS] > $objRace->getLifespan()) {
        echo $strReport = '<div class="center">' . "Your general is nowhere in sight and your captains seem to " . "be doubting your capability to judge properly what to train " . "or not." . '<br /><br />' . '<a href="main.php?cat=game&amp;page=army">Back To Training</a>' . '</div>';
        include_game_down();
        exit;
    }
    // Save to DB
    if ($objRace->getRaceName() == "Oleg Hai" && $arrToTrain[UNIT4] > 0) {
        // Save new army array
        $arrNewArmys = array(UNIT1_T4 => $arrArmys[UNIT1_T4] + $arrToTrain[UNIT1], UNIT2_T4 => $arrArmys[UNIT2_T4] + $arrToTrain[UNIT2], UNIT3_T4 => $arrArmys[UNIT3_T4] + $arrToTrain[UNIT3], UNIT4 => $arrArmys[UNIT4] + $arrToTrain[UNIT4], UNIT5_T4 => $arrArmys[UNIT5_T4] + $arrToTrain[UNIT5]);
        $objUser->set_armys($arrNewArmys);
        // Save new army mercs
        $iOldMercs = $objUser->get_army_merc(MERC_T3);
        $iNewMercs = $iOldMercs + $arrToTrain[UNIT4];
        $objUser->set_army_merc(MERC_T3, $iNewMercs);
    } else {
        // Save new army array
        $arrNewArmys = array(UNIT1_T4 => $arrArmys[UNIT1_T4] + $arrToTrain[UNIT1], UNIT2_T4 => $arrArmys[UNIT2_T4] + $arrToTrain[UNIT2], UNIT3_T4 => $arrArmys[UNIT3_T4] + $arrToTrain[UNIT3], UNIT4_T4 => $arrArmys[UNIT4_T4] + $arrToTrain[UNIT4], UNIT5_T4 => $arrArmys[UNIT5_T4] + $arrToTrain[UNIT5]);
        $objUser->set_armys($arrNewArmys);
    }
    // Update basic soldiers
    $iNewBasics = max(0, $arrArmys[UNIT1] - $iBasicsNeeded);
    $objUser->set_army(UNIT1, $iNewBasics);
    // Update citizens
    $iNewCitizens = $iCitizens - $arrToTrain[UNIT1];
    if ($objRace->getRaceName() == 'Oleg Hai') {
        $iNewCitizens -= $arrToTrain[UNIT4];
    }
    $iNewCitizens = max(0, $iNewCitizens);
    $objUser->set_pop(CITIZENS, $iNewCitizens);
    // Update money
    $iNewMoney = max(0, $arrGoods[MONEY] - $iToPay);
    $objUser->set_good(MONEY, $iNewMoney);
    // Check for brood
    $iBrood = $objUser->get_spell(BROOD);
    if ($iBrood > 0) {
        // Training basic soldiers take 2 updates instead of 4
        $arrArmys = $objUser->get_armys();
        $arrNewArmys = array(UNIT1_T2 => $arrArmys[UNIT1_T2] + $arrArmys[UNIT1_T4], UNIT1_T4 => 0);
        $objUser->set_armys($arrNewArmys);
    }
    // Create list with units trained
    $strUnitList = '<ul>';
    $j = 1;
    foreach ($arrUnitVariables as $strUnit) {
        if (isset($arrToTrain[$strUnit]) && ($iTrained = $arrToTrain[$strUnit]) > 0) {
            $strUnitName = $arrUnitNames[$j];
            $plural = 's';
            if ($strUnitName == 'Thief') {
                $strUnitName = 'Thieve';
            }
            if ($strUnitName == 'Priestess') {
                $plural = 'es';
            }
            if ($strUnitName == 'Mummy') {
                $strUnitName = 'Mummie';
            }
            if ($iTrained == 1) {
                $plural = '';
            }
            $strUnitList .= '<li>' . number_format($iTrained) . ' ' . $strUnitName . $plural . '</li>';
        }
        $j++;
    }
    $strUnitList .= '</ul>';
    $strHarpyText = '';
    if ($objRace->getRaceName() == "Oleg Hai" && $arrToTrain[UNIT4] > 0) {
        $strHarpyText = '<p>The harpy mercenaries will camp with ' . 'our army for <strong>4 months</strong>.</p>';
    }
    $strReport = '<div id="textMedium">' . '<h2>Training Report</h2>' . '<p>Excellent decision leader, the following military will soon join your army and are eager to prove themselves worth their upkeep.</p>' . $strUnitList . '<p>' . 'You have trained <strong>' . number_format($iToTrain) . ' ' . 'units</strong> costing you <strong class="indicator">' . number_format($iToPay) . ' crowns</strong>.' . '</p>' . $strHarpyText . '<p>' . '<a href="main.php?cat=game&amp;page=army">Back To Training</a>' . '</p>' . '</div>';
    echo $strReport;
}
Esempio n. 2
0
function max_train($race)
{
    global $objSrcUser, $max_train, $pop_allows;
    // retrofitted this function to use the object-based version.
    $pop_allows = $objSrcUser->get_pop(CITIZENS) * 0.3;
    $max_train = getMaxTrain($objSrcUser);
}
Esempio n. 3
0
function include_army_text()
{
    $objUser =& $GLOBALS["objSrcUser"];
    $arrStats = $objUser->get_stats();
    $arrUsers = $objUser->get_user_infos();
    $arrArmys = $objUser->get_armys();
    $arrArmysHome = $objUser->get_armys_home();
    $arrArmysDue = $objUser->get_armys_due();
    echo $topLinks = '<div class="center">' . '<a href="main.php?cat=game&amp;page=build">Construction</a> | ' . '<strong>Military Training</strong> | ' . '<a href="main.php?cat=game&amp;page=explore">Exploration</a>' . '</div>';
    $objRace = $objUser->get_race();
    $arrUnitVariables = $objRace->getUnitVariables();
    $arrUnitNames = $objRace->getUnitNames();
    $arrUnitCost = $objRace->getUnitCosts();
    $arrUnitOffence = $objRace->getUnitOffences();
    $arrUnitDefence = $objRace->getUnitDefences();
    $strOlegText = '';
    if ($arrStats['race'] == "Oleg Hai") {
        $strOlegText = '<p>' . '<strong>' . ucfirst($arrUnitNames[5]) . 's</strong> are ' . 'mercenary soldiers living amongst your ' . strtolower($arrUnitNames[1]) . 's. Up to 40% can be hired and ' . 'sent out in attacks, but only during their first month with ' . 'you. After that they will disagree to join any combat ' . 'measures other than defending your lands.' . '</p>';
    }
    // At the end of a lifespan you can't train or release military
    if ($arrUsers[HOURS] > $objRace->getLifespan()) {
        echo $strReport = '<div id="textMedium">' . '<p>' . "Your general is nowhere in sight! And your captains seem to " . "be doubting your capability to judge properly what to train " . "or not." . "</p>" . '</div>';
        include_game_down();
        exit;
    }
    $advisorText = '<div id="textMedium">' . '<p>' . "<strong>Your general</strong> greets you: <br />" . "To keep your tribe safe and strong you need an army. To upgrade " . "your army to units of higher " . "class you will first need to train " . "<strong>" . strtolower($arrUnitNames[2]) . "s</strong>." . "</p>" . $strOlegText . "</div>" . '<br />';
    echo $advisorText;
    // Non-forced update rankings (Non-forced limited to once each 15 minutes)
    include_once 'inc/functions/update_ranking.php';
    doUpdateRankings($objUser);
    // M: Error Messages =======================================================
    // Keep these short
    if (isset($_GET['error']) && $_GET['error'] == "empty") {
        echo '<div class="center">' . "I'm sorry leader, you did not train anything." . "</div><br />";
    } elseif (isset($_GET['error']) && $_GET['error'] == "basics") {
        echo '<div class="center">' . "I'm sorry leader, we don't have enough basic soldiers to " . "upgrade that many military units." . "</div><br />";
    } elseif (isset($_GET['error']) && $_GET['error'] == "poplimit") {
        echo '<div class="center">' . "I'm sorry leader, if we train that many soldiers we will " . "have too few citizens." . "</div><br />";
    } elseif (isset($_GET['error']) && $_GET['error'] == "money") {
        echo '<div class="center">' . "I'm sorry leader, we don't have enough crowns to " . "upgrade that many military units." . "</div><br />";
    }
    //==========================================================================
    $advisorLinks = '<div class="tableLinkMedium">' . '<a href="main.php?cat=game&amp;page=advisors&amp;show=military">The General</a>' . ' :: ' . '<a href="main.php?cat=game&amp;page=raze_army">Release Military</a>' . '</div>';
    echo $advisorLinks;
    $j = 2;
    // for unit array, we start at location #2 (basics == unit1)
    $strCurrent = $arrUnitVariables[$j];
    // UNIT1 = 'unit1'
    // Maximum military trainable
    $arrMax = getMaxTrain($objUser);
    // Show basic military already in training
    $strInTraining = '';
    if ($arrArmysDue[$strCurrent] > 0) {
        $strInTraining = '<span style="font-size: 0.8em;">' . '(' . number_format($arrArmysDue[$strCurrent]) . ')' . '</span>&nbsp;';
    }
    $strBasicsTable = '<form id="center" action="main.php?cat=game&amp;page=army2" method="post">' . '<table cellpadding="0" cellspacing="0" class="medium">' . '<tr class="header">' . '<th colspan="6">Basic</th>' . '</tr>' . '<tr class="subheader">' . '<th width="35%">Class</th>' . '<td class="right" width="25%">Owned</td>' . '<td class="right">Cost</td>' . '<td class="right">Max</td>' . '<td class="right">Train</td>' . '</tr>' . '<tr class="data">' . '<th>' . $arrUnitNames[$j] . 's <span class="militstats">(' . $arrUnitOffence[$j] . '/' . $arrUnitDefence[$j] . ')</span>' . '</th>' . '<td class="right">' . $strInTraining . '<strong>' . number_format($arrArmys[$strCurrent]) . '</strong>' . '</td>' . '<td class="right">' . number_format($arrUnitCost[$j]) . '</td>' . '<td align="right">' . number_format($arrMax[$strCurrent]) . '</td>' . '<td class="right">' . '<input name="trained[' . $strCurrent . ']" size="8" maxlength="8" />' . '</td>' . '</tr>' . '</table>';
    echo $strBasicsTable;
    echo '<br />';
    echo $strAdvancedTable = '<table cellpadding="0" cellspacing="0" class="medium">' . '<tr class="header">' . '<th colspan="6">Advanced</th>' . '</tr>' . '<tr class="subheader">' . '<th width="35%">Class</th>' . '<td class="right" width="25%">Owned</td>' . '<td class="right">Cost</td>' . '<td class="right">Max</td>' . '<td class="right">Upgrade</td>' . '</tr>';
    $j++;
    // for unit arrays, we start at location #3 (off spec)
    foreach ($arrUnitCost as $doesntmatter) {
        // We can only train units that cost money, so only show those
        if (isset($arrUnitCost[$j]) && $arrUnitCost[$j] > 0) {
            $strCurrent = $arrUnitVariables[$j];
            // unit2, unit3.. etc
            //             $sub_current1 = "$strCurrent"."_t1";
            //             $sub_current2 = "$strCurrent"."_t2";
            //             $sub_current3 = "$strCurrent"."_t3";
            //             $sub_current4 = "$strCurrent"."_t4";
            $plural = 's';
            if ($arrUnitNames[$j] == 'Swordmen') {
                $plural = '';
            }
            if ($arrUnitNames[$j] == 'Pikemen') {
                $plural = '';
            }
            if ($arrUnitNames[$j] == 'Crossbowmen') {
                $plural = '';
            }
            if ($arrUnitNames[$j] == 'Longbowmen') {
                $plural = '';
            }
            if ($arrUnitNames[$j] == 'Thief') {
                $arrUnitNames[$j] = 'Thieve';
            }
            if ($arrUnitNames[$j] == 'Priestess') {
                $plural = 'es';
            }
            if ($arrUnitNames[$j] == 'Mummy') {
                $arrUnitNames[$j] = 'Mummie';
            }
            // Show military units already being trained
            $strInTraining = '';
            if ($arrArmysDue[$strCurrent] > 0) {
                $strInTraining = '<span style="font-size: 0.8em;">' . '(' . number_format($arrArmysDue[$strCurrent]) . ')' . '</span>&nbsp;';
            }
            echo '<tr class="data">' . '<th>' . $arrUnitNames[$j] . $plural . ' <span class="militstats">(' . $arrUnitOffence[$j] . '/' . $arrUnitDefence[$j] . ')</span>' . '</th>' . '<td class="right">' . $strInTraining . '<strong>' . number_format($arrArmys[$strCurrent]) . '</strong>' . '</td>' . '<td class="right">' . number_format($arrUnitCost[$j]) . '</td>' . '<td align="right">' . '<span class="indicator">' . number_format($arrMax[$strCurrent]) . '</span>' . '</td>' . '<td class="right">' . '<input name="trained[' . $strCurrent . ']" size="8" maxlength="8" />' . '</td>' . '</tr>';
        }
        $j++;
    }
    echo '</table>' . '<br />' . '<input type="submit" value="Train Military" />' . '</form>';
    // $bleh = mysql_query("Select username from user where id = {$arrStats[ID]}");
    // $bleh = mysql_fetch_array($bleh);
    // $b = date("d");
    // $tiripoda = $bleh['username']."alpha".$b;
    // $b_checker = md5($tiripoda);
    // <input type=\"hidden\" name=\"piss_off_bots\" value=\"$b_checker\" />
}