public function __construct() { $time = time() - getLastLogin($_SESSION["user_id"]); $this->buildings = getBuildings($_SESSION["user_id"]); $this->buildingsworkers = getBuildingsWorkers($_SESSION["user_id"]); $this->userid = $_SESSION["user_id"]; $this->population = getPopulation($_SESSION["user_id"]); $this->food = getFood($_SESSION["user_id"]) * ($this->getFoodProduction() * $time); $this->water = getWater($_SESSION["user_id"]) * ($this->getWaterProduction() * $time); }
function get_tribe_table(&$objUser) { global $arrStats; include_once 'inc/functions/military.php'; include_once 'inc/functions/races.php'; include_once 'inc/functions/magic.php'; include_once 'inc/functions/population.php'; $arrBuild = $objUser->get_builds(); $iAcres = $arrBuild[LAND]; $iBarren = $objUser->get_barren(); $arrStats = $objUser->get_stats(); $arrGoods = $objUser->get_goods(); $arrPopulation = getPopulation($objUser); $arrArmys = $objUser->get_armys(); $iMageLevel = get_mage_level($objUser); $userid = $objUser->get_userid(); $iStrength = $objUser->get_strength(); $iRulerAge = getRulerAge($objUser); // $iSpells = getActiveSpells($objUser); $arrUnitVars = getUnitVariables($arrStats[RACE]); $arrUnitNames = $arrUnitVars['output']; $total_defence = getArmyDefence($objUser); $total_defence = $total_defence['raw']; $suicidal_offence = getArmyOffence($objUser); $suicidal_offence = $suicidal_offence['raw']; $offencePerAcre = ceil($suicidal_offence / $iAcres); $defencePerAcre = ceil($total_defence / $iAcres); $iMilitaryUnits = $arrArmys[UNIT1] + $arrArmys[UNIT2] + $arrArmys[UNIT3] + $arrArmys[UNIT4]; //========================================================================== // Stop people from avoiding the tribe page so they dont get updated //========================================================================== include_once 'inc/functions/update_ranking.php'; doUpdateRankings($objUser, 'yes'); $strServerTime = date("H:i:s"); $res = "<table class=\"medium\" cellpadding=\"0\" cellspacing=\"0\">" . "<tr class=\"header\">" . "<th colspan=\"5\">" . stripslashes($arrStats['tribe']) . " (#" . $arrStats['kingdom'] . ")" . "</th>" . "</tr>" . "<tr class=\"subheader\">" . "<th width=\"120px\">" . "Type" . "</th>" . "<td width=\"165px\">" . "Info" . "</td>" . "<td width=\"30px\">" . " " . "</td>" . "<th width=\"120px\">" . "Type" . "</th>" . "<td width=\"165px\">" . "Info" . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Ruler Age:" . "</th>" . "<td>" . $iRulerAge . " Years" . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Fame:" . "</th>" . "<td>" . number_format($arrStats['fame']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Race:" . "</th>" . "<td>" . $arrStats['race'] . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Strength:" . "</th>" . "<td>" . number_format($iStrength) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . $arrUnitNames[1] . "s:" . "</th>" . "<td>" . number_format($arrPopulation['citizens']) . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Military Units:" . "</th>" . "<td>" . number_format($iMilitaryUnits) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Mage Level:" . "</th>" . "<td>" . $iMageLevel . "</td>" . "<td>" . " " . "</td>"; if ($arrStats[RACE] == 'Templar') { $res .= "<th>" . "Mystics:" . "</th>"; } else { $res .= "<th>" . "Thieves:" . "</th>"; } $res .= "<td>" . number_format($arrArmys['unit5']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Raw Offence:" . "</th>" . "<td>" . $offencePerAcre . " OPA</td>" . "<td>" . " " . "</td>" . "<th>" . "Raw Defence:" . "</th>" . "<td>" . $defencePerAcre . " DPA</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Barren Land:" . "</th>" . "<td>" . number_format($iBarren) . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Land:" . "</th>" . "<td>" . number_format($iAcres) . "</td>" . "</tr>" . "</table>" . '<div class="center" style="font-size: 0.8em">' . 'Server Time: ' . $strServerTime . '</div>'; return $res; }
function max_market_buy(&$objSrcUser) { $arrSrcStats = $objSrcUser->get_stats(); $arrSrcGoods = $objSrcUser->get_goods(); $objSrcAlliance = $objSrcUser->get_alliance(); // M: Update just to ensure decays have affected the goods doUpdateMarket($objSrcAlliance); $arrSrcAlliance = $objSrcAlliance->get_alliance_infos(); // M: New functions connected to the object-oriented update routines include_once 'inc/functions/population.php'; $iArmy = getPopulation($objSrcUser); $iArmy = $iArmy['total_army']; $iRoom = getMaxPopulation($objSrcUser); $iRoom = $iRoom['total']; $iLeft = floor($iRoom - $iArmy) - 800; // 800 so we do not kill ourselves if ($iLeft < 0) { $iLeft = 0; } // M: Fetch the prices for each goods $arrMarketCost = getPriceArray($objSrcUser); // M: Besides looking up what we can afford, let's not allow someone to die $arrMaxMarketBuy[UNIT1] = min(floor($arrSrcGoods[CREDITS] / $arrMarketCost[UNIT1]), $iLeft); if ($arrMaxMarketBuy[UNIT1] >= $arrSrcAlliance[SOLDIERS]) { $arrMaxMarketBuy[UNIT1] = $arrSrcAlliance[SOLDIERS]; } $arrMaxMarketBuy[MONEY] = floor($arrSrcGoods[CREDITS] / $arrMarketCost[MONEY]); if ($arrMaxMarketBuy[MONEY] >= $arrSrcAlliance[MONEY]) { $arrMaxMarketBuy[MONEY] = $arrSrcAlliance[MONEY]; } $arrMaxMarketBuy[WOOD] = floor($arrSrcGoods[CREDITS] / $arrMarketCost[WOOD]); if ($arrMaxMarketBuy[WOOD] >= $arrSrcAlliance[WOOD]) { $arrMaxMarketBuy[WOOD] = $arrSrcAlliance[WOOD]; } $arrMaxMarketBuy[FOOD] = floor($arrSrcGoods[CREDITS] / $arrMarketCost[FOOD]); if ($arrMaxMarketBuy[FOOD] >= $arrSrcAlliance[FOOD]) { $arrMaxMarketBuy[FOOD] = $arrSrcAlliance[FOOD]; } return $arrMaxMarketBuy; }
function get_population_table(&$objUser) { include_once 'inc/functions/population.php'; $arrPopulation = getPopulation($objUser); $thieves = 'Thieves'; if ($objUser->get_stat(RACE) == 'Templar') { $thieves = 'Mystics'; } $population = "<table class=\"small\" cellpadding=\"0\" cellspacing=\"0\">" . "<tr class=\"header\">" . "<th colspan=\"2\">" . "Population" . "</th>" . "</tr>" . "<tr class=\"subheader\">" . "<th>" . "Type" . "</th>" . "<td>" . "Amount" . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Citizens:" . "</th>" . "<td>" . number_format($arrPopulation['citizens']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Military Units:" . "</th>" . "<td>" . number_format($arrPopulation['total_army']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "{$thieves}:" . "</th>" . "<td>" . number_format($arrPopulation['thieves']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th class=\"bsup\">" . "Total Current Population:" . "</th>" . "<td class=\"bsup\">" . number_format($arrPopulation['total_pop']) . "</td>" . "</tr>" . "</table>"; return $population; }
$flows = getFlowsFrom($_POST['c'], 10, "`qta` DESC"); $index = 1; $other_flow = getFlowFromTo($_POST['c'], $_POST['o']); } else { $flows = getFlowsTo($_POST['c'], 10, "`qta` DESC"); $index = 0; $other_flow = getFlowFromTo($_POST['o'], $_POST['c']); } if ($_POST['o']) { //var_export($other_flow); //var_export($flows); if (!in_array($other_flow, $flows)) { array_push($flows, array($other_flow[0], $other_flow[1], $other_flow[2], 1)); } } $population = getPopulation(2010, $_POST['c']); $str .= "<h2><a href=\"#" . ($_POST['src'] ? 'f' : 't') . "_" . $_POST['c'] . "\" id=\"" . ($_POST['src'] ? 'from' : 'to') . "_" . $_POST['c'] . "\" title=\"" . $country_names[$_POST['c']] . "\">" . $country_names[$_POST['c']] . "</a></h2><h3>Population: <b>" . number_format($population[$_POST['c']], 0, "", ",") . "</b></h3><a href=\"#\" class=\"close\" rel=\"" . ($_POST['src'] ? 'from' : 'to') . "_" . $_POST['c'] . "\">hide</a>"; $migrants = $index ? getMigrationTotalFrom(null, $_POST['c']) : getMigrationTotalTo(null, $_POST['c']); $perc = getSimplePercentageOnPopulation($migrants, $_POST['c']); $str .= "<h3>" . ($index ? 'E' : 'Im') . "migrants: <b>" . number_format($migrants, 0, "", ",") . "</b></h3>"; if (!$index) { $str .= "<h4>% of population: <b>" . round($perc, 2) . "%</b></h4>"; } $str .= "<h5>" . ($_POST['src'] ? "Migrant destinations" : "Migrant native countries") . "</h5>"; $str .= "<ul>"; $i = 0; foreach ($flows as $flow) { $add_class = ''; if (isset($flow[3])) { $add_class = 'o'; }
function obj_kill_user(&$objUser) { // Tag tribe to be restarted $objUser->set_stat(RESET_OPTION, 'yes'); // Remove invested research //require_once("inc/functions/research.php"); //delete_my_rps($objUser->get_userid()); // no more - AI 07/05/07 // Mail user to tell them they have been killed $strMail = "Unfortunately your tribe in ORKFiA has died. It is now ready " . "to be restarted." . "\n\n" . HOST . SIGNED_ORKFIA; $strEmail = stripslashes($objUser->get_preference(EMAIL)); mail($strEmail, "Your tribe is no more =(", $strMail, "From: ORKFiA <" . EMAIL_REPORTER . ">\r\nX-Mailer: PHP/" . phpversion() . "\r\nX-Priority: Normal"); // Calculate Re-starting Bonus // Species5618 (7-6-04): Setting a flag that marks the tribe as dead, so // that they do receive their age-death-bonus ("heritage") when they login if ($objUser->get_stat(KILLED) == 1 || $_SERVER['SERVER_NAME'] == DINAH_SERVER_NAME) { require_once 'inc/functions/population.php'; $arrPopulation = getPopulation($objUser); require_once 'inc/functions/races.php'; $strRace = $objUser->get_stat(RACE); $arrUnitVars = getUnitVariables($strRace); $arrUnitCost = $arrUnitVars['gold']; // Calculate the killed army's worth $total_value = $arrPopulation['basics'] * $arrUnitCost[2]; $total_value += $arrPopulation['off_specs'] * $arrUnitCost[3]; $total_value += $arrPopulation['def_specs'] * $arrUnitCost[4]; $total_value += $arrPopulation['elites'] * $arrUnitCost[5]; $total_value += $arrPopulation['thieves'] * $arrUnitCost[6]; $total_value = round($total_value * 0.02); // Calculate the killed army in basics $total_troops = round($arrPopulation['total_army'] / 40); // Base Housing Capacities require_once 'inc/functions/build.php'; $arrBuildVariables = getBuildingVariables($strRace); $homes_hold = $arrBuildVariables['housing'][1]; // Add kill-bonus $iLand = $objUser->get_build(LAND); $fame = $objUser->get_stat(FAME); //Removed - AI 08/05/07 //$research = $objUser->get_stat(INVESTED); $arrKills = array(LAND => $iLand, CASH => $total_value, BASICS => $total_troops, POP => $homes_hold, FAME => $fame); $objUser->set_kills($arrKills); } // Reset Tribe Rankings $arrRankingsPersonal = array(STRENGTH => 3000, LAND => STARTING_LAND, FAME => 5000, HOURS => 0); $objUser->set_rankings_personals($arrRankingsPersonal); // Update Alliance Rankings $objAlliance = $objUser->get_alliance(); $objAlliance->do_update_ranking(); // Set total land to what would be inherited (fix a science bug), // we're using a hardcoded value here which just happens to be the same // as the one used in inc/pages/reset_account.inc.php, // this is a BAD THING - AI 11/01/2006 // Age changes coding - new heritage formula // Martel, September 16, 2007 (Plus also using constant and not '400') $iLand = $objUser->get_build(LAND); $iNewFormulaHeritage = round(pow(max(0, $iLand - STARTING_LAND), 0.80459611995) + STARTING_LAND); if (($objUser->get_stat(KILLED) == 1 || $_SERVER['SERVER_NAME'] == DINAH_SERVER_NAME) && $iNewFormulaHeritage > STARTING_LAND) { $iLand = $iNewFormulaHeritage; } if ($iLand > 2000) { $iLand = 2000; } elseif ($iLand < STARTING_LAND) { $iLand = STARTING_LAND; } // Save new land (to fix a science bug) $objUser->set_build(LAND, $iLand); // Reset other stuff too, so the tribe can be defected - AI 02/12/06 $objUser->set_user_info(PAUSE_ACCOUNT, 0); }
function get_strength() { if (empty($this->_iStrength)) { $arrArmys = $this->get_armys(); $strRace = $this->get_stat(RACE); // Strength from Military Units ==================================== include_once 'inc/functions/races.php'; $arrUnitVars = getUnitVariables($strRace); $arrUnitOff = $arrUnitVars['offence']; $arrUnitDef = $arrUnitVars['defence']; $arrVars = $arrUnitVars['variables']; $military_str = 0; $temp_str = 0; // iterates through all units with offence value specified (also if it is 0) foreach ($arrUnitOff as $key => $iUnitOff) { $temp_str = $arrArmys[$arrVars[$key]] * calcUnitStr($this, $arrUnitOff[$key], $arrUnitDef[$key]); // possibly add some (unit_str *= 1.025 ?) if the unit is immortal here // ravens get double strength from their elites if ($strRace == 'Raven' && $arrVars[$key] == UNIT4) { $temp_str *= 2; } $military_str += $temp_str; } // Strength from "War Buildings" =================================== $arrBuilds = $this->get_builds(); $build_str = 75 * ($arrBuilds[CHURCHES] + $arrBuilds[GUARDHOUSES] + $arrBuilds[HIDEOUTS] + $arrBuilds[GUILDS] + $arrBuilds[ACADEMIES]); // Strength from Thieves =========================================== $tm_str = $arrArmys[UNIT5] * 1.25; // Strength from .. other stuff? :P ================================ include_once 'inc/functions/population.php'; $max_citz = getMaxPopulation($this); $max_citz = $max_citz['total']; $all_units_in_training = getPopulation($this); $all_units_in_training = $all_units_in_training['total_army']; $all_units_in_training -= $arrArmys[UNIT1] + $arrArmys[UNIT2] + $arrArmys[UNIT3] + $arrArmys[UNIT4] + $arrArmys[UNIT5]; $other_str = pow(($max_citz + $arrArmys[UNIT1] + $all_units_in_training) / (1 + $arrArmys[UNIT2] + $arrArmys[UNIT3] + $arrArmys[UNIT4] + $arrArmys[UNIT5]), 0.25); // Calculate Total Strength ======================================== $total_str = $other_str * ($military_str + $build_str + $tm_str); // ================================================================= // $strength['units'] = $military_str; // $strength['buildings'] = $build_str; // $strength['thieves'] = $tm_str; // $strength['other'] = $other_str; $strength['total'] = $total_str; $this->_iStrength = $strength['total']; } return $this->_iStrength; }
function getFoodProduction(&$objUser) { $production = array(); $strRace = $objUser->get_stat(RACE); $iOldFood = $objUser->get_good(FOOD); $iFarms = $objUser->get_build(FARMS); $food = 250; if ($strRace == "Dragon") { $food = 62.5; } $raw = $iFarms * $food; // Self Spell Bonus $update_spells = getSpellBonuses($objUser); $spell_bonus = round($raw * $update_spells['food']); // Research Bonus - New code January 09, 2008, Martel $arrResearch = getResearchBonuses($objUser->get_alliance()); $research_bonus = round($raw * $arrResearch['food']); // Food Eaten $population = getPopulation($objUser); $used = $population['total_pop'] * 0.15; // Race Exceptions if ($strRace == 'Brittonian') { $used *= 0.5; } elseif ($strRace == 'Mori Hai') { $used *= 0.75; } elseif ($strRace == 'Spirit') { $used = 0; } // 0% for spirit // Food Rotten $decayed = floor($iOldFood * 0.0002); // Food Produced $total = $raw + $research_bonus + $spell_bonus - $used - $decayed; $production['per_each'] = $food; $production['raw'] = $raw; $production['research_bonus'] = $research_bonus; $production['spell_bonus'] = $spell_bonus; $production['used'] = $used; $production['decayed'] = $decayed; $production['total'] = $total; return $production; }
function getPercentageOnPopulation($data2becompared, $year = 2010) { $percentages = array(); $population = getPopulation($year); foreach ($data2becompared as $country => $val) { if ($population[$country]) { $percentages[$country] = $val / $population[$country] * 100; } } return $percentages; }
function getCitizenIncome(&$objUser) { $taxes = array(); $strRace = $objUser->get_stat(RACE); $population = getPopulation($objUser); $citizens = $population['citizens']; $citizen_income = $citizens * 2; // Starvation = 50% Income $starvation = 0; $arrGoods = $objUser->get_goods(); $production = getFoodProduction($objUser); if ($arrGoods[FOOD] + $production['total'] < 0 && $strRace != "Spirit") { $starvation = round($citizen_income * 0.5); } // Spell Bonus $update_spells = getSpellBonuses($objUser); $quanta_bonus = $update_spells['income']; $spell_income_bonus = round(($citizen_income - $starvation) * $quanta_bonus); // Total $total_income = $citizen_income - $starvation + $spell_income_bonus; $taxes['raw'] = $citizen_income; $taxes['starvation'] = $starvation; $taxes['spell_bonus'] = $spell_income_bonus; $taxes['total'] = $total_income; return $taxes; }