/** * BE_calculateTech.php * Battle Engine Effective Tech levels calculations * "rf" stands for "Rapid Fire" * "rp" stands for "ResourcePoints" */ function BE_calculateTechs(&$user) { global $sn_data; $armor_tech = mrc_modify_value($user, false, MRC_ADMIRAL, 1 + 0.1 * $user['defence_tech']); $shield_tech = mrc_modify_value($user, false, MRC_ADMIRAL, 1 + 0.1 * $user['shield_tech']); $weapon_tech = mrc_modify_value($user, false, MRC_ADMIRAL, 1 + 0.1 * $user['military_tech']); return array('def' => $armor_tech, 'shield' => $shield_tech, 'att' => $weapon_tech); }
function eco_get_build_data(&$user, $planet, $unit_id, $unit_level = 0, $only_cost = false) { global $config; $rpg_exchange_deuterium = $config->rpg_exchange_deuterium; $unit_data = get_unit_param($unit_id); // $unit_db_name = &$unit_data[P_NAME]; $unit_factor = $unit_data[P_COST][P_FACTOR] ? $unit_data[P_COST][P_FACTOR] : 1; $price_increase = pow($unit_factor, $unit_level); $can_build = isset($unit_data[P_MAX_STACK]) && $unit_data[P_MAX_STACK] ? $unit_data[P_MAX_STACK] : 1000000000000.0; $can_destroy = 1000000000000.0; $time = 0; $only_dark_matter = 0; foreach ($unit_data[P_COST] as $resource_id => $resource_amount) { if ($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { continue; } $cost[BUILD_CREATE][$resource_id] = round($resource_cost); $cost[BUILD_DESTROY][$resource_id] = round($resource_cost / 2); $resource_db_name = pname_resource_name($resource_id); if (in_array($resource_id, sn_get_groups('resources_loot'))) { $time += $resource_cost * $config->__get("rpg_exchange_{$resource_db_name}") / $rpg_exchange_deuterium; $resource_got = mrc_get_level($user, $planet, $resource_id); } elseif ($resource_id == RES_DARK_MATTER) { $resource_got = mrc_get_level($user, null, $resource_id); } elseif ($resource_id == RES_ENERGY) { $resource_got = max(0, $planet['energy_max'] - $planet['energy_used']); } else { $resource_got = 0; } $only_dark_matter = $only_dark_matter ? $only_dark_matter : $resource_id; $can_build = min($can_build, $resource_got / $cost[BUILD_CREATE][$resource_id]); $can_destroy = min($can_destroy, $resource_got / $cost[BUILD_DESTROY][$resource_id]); } $can_build = $can_build > 0 ? floor($can_build) : 0; $cost['CAN'][BUILD_CREATE] = $can_build; $can_destroy = $can_destroy > 0 ? floor($can_destroy) : 0; $cost['CAN'][BUILD_DESTROY] = $can_destroy; $cost[P_OPTIONS][P_ONLY_DARK_MATTER] = $only_dark_matter = $only_dark_matter == RES_DARK_MATTER; $cost[P_OPTIONS][P_TIME_RAW] = $time = $time * 60 * 60 / get_game_speed() / 2500; // TODO - Вынести в отдельную процедуру расчёт стоимости if ($only_cost) { return $cost; } $cost['RESULT'][BUILD_CREATE] = eco_can_build_unit($user, $planet, $unit_id); $cost['RESULT'][BUILD_CREATE] = $cost['RESULT'][BUILD_CREATE] == BUILD_ALLOWED ? $cost['CAN'][BUILD_CREATE] ? BUILD_ALLOWED : BUILD_NO_RESOURCES : $cost['RESULT'][BUILD_CREATE]; $mercenary = 0; $cost['RESULT'][BUILD_DESTROY] = BUILD_INDESTRUCTABLE; if (in_array($unit_id, sn_get_groups('structures'))) { $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1); $mercenary = MRC_ENGINEER; $cost['RESULT'][BUILD_DESTROY] = mrc_get_level($user, $planet, $unit_id, false, true) ? $cost['CAN'][BUILD_DESTROY] ? $cost['RESULT'][BUILD_CREATE] == BUILD_UNIT_BUSY ? BUILD_UNIT_BUSY : BUILD_ALLOWED : BUILD_NO_RESOURCES : BUILD_NO_UNITS; } elseif (in_array($unit_id, sn_get_groups('tech'))) { $lab_level = eco_get_lab_max_effective_level($user, intval($unit_data['require'][STRUC_LABORATORY])); $time = $time / $lab_level; $mercenary = MRC_ACADEMIC; } elseif (in_array($unit_id, sn_get_groups('defense'))) { $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); $mercenary = MRC_FORTIFIER; } elseif (in_array($unit_id, sn_get_groups('fleet'))) { $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); $mercenary = MRC_ENGINEER; } if ($mercenary) { $time = $time / mrc_modify_value($user, $planet, $mercenary, 1); } if (in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { $cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0; } else { $cost[RES_TIME][BUILD_CREATE] = round($time >= 1 ? $time : 1); $cost[RES_TIME][BUILD_DESTROY] = round($time / 2 <= 1 ? 1 : $time / 2); } return $cost; }
function eco_get_planet_caps(&$user, &$planet_row, $production_time = 0) { // TODO Считать $production_time для термоядерной электростанции global $config; static $sn_group_modifiers, $config_resource_multiplier, $config_eco_scale_storage; if (!$sn_group_modifiers) { $sn_group_modifiers = sn_get_groups('modifiers'); // $config_resource_multiplier = $config->resource_multiplier; $config_resource_multiplier = game_resource_multiplier(); $config_eco_scale_storage = $config->eco_scale_storage ? $config_resource_multiplier : 1; } $caps = array(); foreach (sn_get_groups('storages') as $unit_id) { foreach (get_unit_param($unit_id, P_STORAGE) as $resource_id => $function) { $caps['storage'][$resource_id][$unit_id] = floor($config_eco_scale_storage * mrc_modify_value($user, $planet_row, $sn_group_modifiers[MODIFIER_RESOURCE_CAPACITY], $function(mrc_get_level($user, $planet_row, $unit_id)))); } } if ($planet_row['planet_type'] == PT_MOON) { return $caps; } $sn_group_planet_density = sn_get_groups('planet_density'); $planet_density = $sn_group_planet_density[$planet_row['density_index']][UNIT_RESOURCES]; $caps['production_full'][RES_METAL][0] = floor($config->metal_basic_income * $config_resource_multiplier * (isset($planet_density[RES_METAL]) ? $planet_density[RES_METAL] : 1)); $caps['production_full'][RES_CRYSTAL][0] = floor($config->crystal_basic_income * $config_resource_multiplier * (isset($planet_density[RES_CRYSTAL]) ? $planet_density[RES_CRYSTAL] : 1)); $caps['production_full'][RES_DEUTERIUM][0] = floor($config->deuterium_basic_income * $config_resource_multiplier * (isset($planet_density[RES_DEUTERIUM]) ? $planet_density[RES_DEUTERIUM] : 1)); $caps['production_full'][RES_ENERGY][0] = floor($config->energy_basic_income * $config_resource_multiplier * (isset($planet_density[RES_ENERGY]) ? $planet_density[RES_ENERGY] : 1)); foreach (sn_get_groups('factories') as $unit_id) { $unit_data = get_unit_param($unit_id); $unit_level = mrc_get_level($user, $planet_row, $unit_id); $unit_load = $planet_row[pname_factory_production_field_name($unit_id)]; foreach ($unit_data['production'] as $resource_id => $function) { $caps['production_full'][$resource_id][$unit_id] = $function($unit_level, $unit_load, $user, $planet_row) * $config_resource_multiplier * (isset($planet_density[$resource_id]) ? $planet_density[$resource_id] : 1); } } array_walk_recursive($caps['production_full'], 'eco_get_planet_caps_modify_production', array('user' => $user, 'planet' => $planet_row)); foreach ($caps['production_full'] as $resource_id => $resource_data) { $caps['total_production_full'][$resource_id] = array_sum($resource_data); } $caps['production'] = $caps['production_full']; if ($caps['production'][RES_ENERGY][STRUC_MINE_FUSION]) { $deuterium_balance = array_sum($caps['production'][RES_DEUTERIUM]); $energy_balance = array_sum($caps['production'][RES_ENERGY]); if ($deuterium_balance < 0 || $energy_balance < 0) { $caps['production'][RES_DEUTERIUM][STRUC_MINE_FUSION] = $caps['production'][RES_ENERGY][STRUC_MINE_FUSION] = 0; } } foreach ($caps['production'][RES_ENERGY] as $energy) { $caps[RES_ENERGY][$energy >= 0 ? BUILD_CREATE : BUILD_DESTROY] += $energy; } $caps[RES_ENERGY][BUILD_DESTROY] = -$caps[RES_ENERGY][BUILD_DESTROY]; $caps['efficiency'] = $caps[RES_ENERGY][BUILD_DESTROY] > $caps[RES_ENERGY][BUILD_CREATE] ? $caps[RES_ENERGY][BUILD_CREATE] / $caps[RES_ENERGY][BUILD_DESTROY] : 1; foreach ($caps['production'] as $resource_id => &$resource_data) { if ($caps['efficiency'] != 1) { foreach ($resource_data as $unit_id => &$resource_production) { if (!($unit_id == STRUC_MINE_FUSION && $resource_id == RES_DEUTERIUM) && $unit_id != 0 && !($resource_id == RES_ENERGY && $resource_production >= 0)) { $resource_production = $resource_production * $caps['efficiency']; } } } $caps['total'][$resource_id] = array_sum($resource_data); $caps['total'][$resource_id] = $caps['total'][$resource_id] >= 0 ? floor($caps['total'][$resource_id]) : ceil($caps['total'][$resource_id]); } foreach ($caps['storage'] as $resource_id => &$resource_data) { $caps['total_storage'][$resource_id] = array_sum($resource_data); } $planet_row['caps'] = $caps; $planet_row['metal_max'] = $caps['total_storage'][RES_METAL]; $planet_row['crystal_max'] = $caps['total_storage'][RES_CRYSTAL]; $planet_row['deuterium_max'] = $caps['total_storage'][RES_DEUTERIUM]; $planet_row['energy_max'] = $caps[RES_ENERGY][BUILD_CREATE]; $planet_row['energy_used'] = $caps[RES_ENERGY][BUILD_DESTROY]; return $caps; }
/** * eco_build.php * * @version 1.5 - Using PTE (not everywhere) by Gorlum for http://supernova.ws * @version 1.4 - Complying with PCG by Gorlum for http://supernova.ws * @version 1.3 - Security checked for SQL-injection by Gorlum for http://supernova.ws // 1.0 Mise en module initiale (creation) // 1.1 FIX interception cheat +1 // 1.2 FIX interception cheat destruction a -1 * @version 1.1 * @copyright 2008 by Chlorel for XNova */ function eco_build($que_type, $user, &$planet, $que) { global $sn_data, $lang, $config, $time_now; // start transaction here $template = gettemplate('buildings_builds', true); // Caching values that used more then one time into local variables $config_resource_multiplier = $config->resource_multiplier; $planet_type_structs = $sn_data['groups']['build_allow'][$planet['planet_type']]; // Getting parameters $action = sys_get_param_escaped('action'); $unit_id = sys_get_param_int('unit_id'); $unit_level = sys_get_param_int('unit_level'); $GET_listid = $_GET['listid']; $que_type = $que_type == SUBQUE_FLEET || $que_type == SUBQUE_DEFENSE ? QUE_HANGAR : $que_type; CheckPlanetUsedFields($planet); if ($action) { switch ($action) { case 'create': // Add unit to que for build $que = eco_que_add($user, $planet, $que, QUE_STRUCTURES, $unit_id); break; case 'destroy': // Add unit to que for remove $que = eco_que_add($user, $planet, $que, QUE_STRUCTURES, $unit_id, 1, BUILD_DESTROY); break; case 'trim': // Cancel unit from que $que = eco_que_clear($user, $planet, $que, QUE_STRUCTURES, true); break; case 'clear': // Clear que $que = eco_que_clear($user, $planet, $que, QUE_STRUCTURES); break; } header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"); } /* // Code for fully working new que system $hangar_busy = count($que['que'][QUE_HANGAR]); $lab_busy = count($que['que'][QUE_RESEARCH]) && !$config->BuildLabWhileRun; */ $que_length = count($que['que'][$que_type]); $can_que_element = $que_length < MAX_BUILDING_QUEUE_SIZE; $fleet_list = flt_get_fleets_to_planet($planet); $caps = ECO_getPlanetCaps($user, &$planet); $planet_fields_max = eco_planet_fields_max($planet); $planet_fields_current = $planet['field_current']; $planet_fields_que = -$que['amounts'][$que_type]; $planet_fields_free = max(0, $planet_fields_max - $planet_fields_current + $planet_fields_que); $planet_fields_queable = $planet_fields_free > 0; $planet_temp_max = $planet['temp_max']; $GLOBALS['user_tech_energy'] = $user['energy_tech']; foreach ($planet_type_structs as $Element) { if (eco_can_build_unit($user, $planet, $Element)) { $element_name = $lang['tech'][$Element]; $element_sn_data =& $sn_data[$Element]; $element_level = $planet[$sn_data[$Element]['name']] + $que['in_que'][$Element]; // show energy on BuildingPage //================================ if ($element_sn_data['production']) { $element_production_energy = $element_sn_data['production'][RES_ENERGY]; $energy_current = floor($element_production_energy($element_level, 10, $planet_temp_max)); $energy_next = floor($element_production_energy($element_level + 1, 10, $planet_temp_max)); if ($Element == STRUC_MINE_SOLAR || $Element == STRUC_MINE_FUSION) { $energy_current = floor(mrc_modify_value($user, $planet, array(MRC_POWERMAN), $energy_current)); $energy_next = floor(mrc_modify_value($user, $planet, array(MRC_POWERMAN), $energy_next)); } $energy_balance = floor($energy_next - $energy_current); } else { $energy_balance = 0; } //================================ $build_data = eco_get_build_data($user, $planet, $Element, $element_level); $temp[RES_METAL] = floor($planet['metal'] + $fleet_list['own']['total'][RES_METAL] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] + $fleet_list['own']['total'][RES_CRYSTAL] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] + $fleet_list['own']['total'][RES_DEUTERIUM] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $template->assign_block_vars('production', array('ID' => $Element, 'NAME' => $element_name, 'DESCRIPTION' => $lang['info'][$Element]['description_short'], 'LEVEL' => $element_level, 'LEVEL_OLD' => $planet[$sn_data[$Element]['name']], 'LEVEL_CHANGE' => $que['in_que'][$Element], 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[BUILD_CREATE][RES_TIME]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[BUILD_DESTROY][RES_TIME]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_BALANCE' => $caps['metal_perhour'][$Element], 'CRYSTAL_BALANCE' => $caps['crystal_perhour'][$Element], 'DEUTERIUM_BALANCE' => $caps['deuterium_perhour'][$Element], 'ENERGY_BALANCE' => $energy_balance, 'UNIT_BUSY' => eco_unit_busy($user, $planet, $que, $Element))); } } if (is_array($que['que'][$que_type])) { foreach ($que['que'][$que_type] as $que_element) { $template->assign_block_vars('que', $que_element); } } $template->assign_vars(array('TIME_NOW' => $time_now, 'QUE_ID' => $que_type, 'METAL' => $planet['metal'], 'CRYSTAL' => $planet['crystal'], 'DEUTERIUM' => $planet['deuterium'], 'METAL_INCOMING' => $fleet_list['own']['total'][RES_METAL], 'CRYSTAL_INCOMING' => $fleet_list['own']['total'][RES_CRYSTAL], 'DEUTERIUM_INCOMING' => $fleet_list['own']['total'][RES_DEUTERIUM], 'FIELDS_CURRENT' => $planet_fields_current, 'FIELDS_MAX' => $planet_fields_max, 'FIELDS_FREE' => $planet_fields_free, 'FIELDS_QUE' => $planet_fields_que == 0 ? '' : $planet_fields_que > 0 ? "+{$planet_fields_que}" : $planet_fields_que, 'QUE_HAS_PLACE' => $can_que_element, 'QUE_HAS_FIELDS' => $planet_fields_queable, 'FLEET_OWN' => $fleet_list['own']['count'], 'PAGE_HINT' => $lang['eco_bld_page_hint'])); display(parsetemplate($template), $lang['Builds']); }
function COE_missileAttack($defenceTech, $attackerTech, $MIPs, $structures, $targetedStructure = '0') { // Here we select which part of defense should take damage: structure or shield // $damageTo = P_SHIELD; // $damageTo = P_STRUCTURE; $damageTo = P_DEFENSE; $mip_data = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); $MIPDamage = floor(mrc_modify_value($attackerTech, false, TECH_WEAPON, $MIPs * $mip_data[P_ATTACK] * mt_rand(80, 120) / 100)); foreach ($structures as $key => $structure) { $unit_info = get_unit_param($key); $amplify = isset($mip_data[P_AMPLIFY][$key]) ? $mip_data[P_AMPLIFY][$key] : 1; $structures[$key][P_SHIELD] = floor(mrc_modify_value($defenceTech, false, TECH_SHIELD, $unit_info[P_SHIELD]) / $amplify); $structures[$key][P_STRUCTURE] = floor(mrc_modify_value($defenceTech, false, TECH_ARMOR, $unit_info[P_ARMOR]) / $amplify); $structures[$key][P_DEFENSE] = floor((mrc_modify_value($defenceTech, false, TECH_ARMOR, $unit_info[P_ARMOR]) + mrc_modify_value($defenceTech, false, TECH_SHIELD, $unit_info[P_SHIELD])) / $amplify * mt_rand(80, 120) / 100); } $startStructs = $structures; if ($targetedStructure) { //attacking only selected structure $damageDone = $structures[$targetedStructure][$damageTo]; $structsDestroyed = min(floor($MIPDamage / $damageDone), $structures[$targetedStructure][0]); $structures[$targetedStructure][0] -= $structsDestroyed; $MIPDamage -= $structsDestroyed * $damageDone; } else { // REALLY random attack $can_be_damaged = sn_get_groups('defense_active'); //debug($structures); //debug($can_be_damaged); do { // finding is there any structure that can be damaged with leftovers of $MIPDamage foreach ($can_be_damaged as $key => $unit_id) { //debug($structures[$unit_id][0]); //debug($structures[$unit_id][$damageTo], $MIPDamage); if ($structures[$unit_id][0] <= 0 || $structures[$unit_id][$damageTo] > $MIPDamage) { unset($can_be_damaged[$key]); } } if (empty($can_be_damaged)) { break; } sort($can_be_damaged); //debug($can_be_damaged, 'can be damaged'); $random_defense = mt_rand(0, count($can_be_damaged) - 1); //debug($can_be_damaged[$random_defense], 'Target'); $current_target =& $structures[$can_be_damaged[$random_defense]]; //debug($current_target[0], 'Amount was'); $can_be_destroyed = min($current_target[0], floor($MIPDamage / $current_target[$damageTo])); //debug($MIPDamage, 'MIPDamage'); //debug($can_be_destroyed, 'Can be destroyed'); $destroyed = mt_rand(1, $can_be_destroyed); $MIPDamage -= $current_target[$damageTo] * $destroyed; $current_target[0] -= $destroyed; //debug($destroyed, 'Actually destroyed'); //print('<hr>'); } while ($MIPDamage > 0 && !empty($can_be_damaged)); //debug($MIPDamage, 'MIPDamage left'); } //debug($structures);//die(); // 1/2 of metal and 1/4 of crystal of destroyed structures returns to planet $metal = 0; $crystal = 0; foreach ($structures as $key => $structure) { $unit_info = get_unit_param($key); $destroyed = $startStructs[$key][0] - $structure[0]; $metal += $destroyed * $unit_info[P_COST][RES_METAL] / 2; $crystal += $destroyed * $unit_info[P_COST][RES_CRYSTAL] / 4; } $return['structures'] = $structures; // Structures left after attack $return['metal'] = floor($metal); // Metal scraps $return['crystal'] = floor($crystal); // Crystal scraps return $return; }
function ShowProductionTable($CurrentUser, $CurrentPlanet, $BuildID, $Template) { $config_resource_multiplier = game_resource_multiplier(); $config_resource_multiplier_plain = game_resource_multiplier(true); $CurrentBuildtLvl = mrc_get_level($CurrentUser, $CurrentPlanet, $BuildID); $BuildLevel = $CurrentBuildtLvl > 0 ? $CurrentBuildtLvl : 1; $modifiers = sn_get_groups('modifiers'); $Prod[STRUC_MINE_METAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_METAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_CRYSTAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_CRYSTAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_DEUTERIUM] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_DEUTERIUM]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_SOLAR] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier_plain * $unit_data[P_UNIT_PRODUCTION][RES_ENERGY]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $ActualProd = floor($Prod[$BuildID]); if ($BuildID != STRUC_MINE_FUSION) { $ActualNeed = floor($Prod[STRUC_MINE_SOLAR]); } else { $ActualNeed = floor($Prod[STRUC_MINE_DEUTERIUM]); } $BuildStartLvl = $CurrentBuildtLvl - 2; if ($BuildStartLvl < 1) { $BuildStartLvl = 1; } $Table = ''; $ProdFirst = 0; for ($BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 10; $BuildLevel++) { if ($BuildID != STRUC_MOON_PHALANX) { $Prod[STRUC_MINE_METAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_METAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_CRYSTAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_CRYSTAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_DEUTERIUM] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_DEUTERIUM]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_SOLAR] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier_plain * $unit_data[P_UNIT_PRODUCTION][RES_ENERGY]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; if ($ProdFirst > 0) { if ($BuildID != STRUC_MINE_FUSION) { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[$BuildID] - $ProdFirst)) . ")</font>"; } else { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ProdFirst)) . ")</font>"; } } else { $bloc['build_gain'] = ''; } if ($BuildID != STRUC_MINE_FUSION) { $bloc['build_prod'] = pretty_number(floor($Prod[$BuildID])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[$BuildID] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ActualNeed), true, true); } else { $bloc['build_prod'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[STRUC_MINE_DEUTERIUM]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[STRUC_MINE_DEUTERIUM] - $ActualNeed), true, true); } if ($ProdFirst == 0) { if ($BuildID != STRUC_MINE_FUSION) { $ProdFirst = floor($Prod[$BuildID]); } else { $ProdFirst = floor($Prod[STRUC_MINE_SOLAR]); } } } else { // Cas particulier de la phalange $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; $bloc['build_range'] = $BuildLevel * $BuildLevel - 1; } $Table .= parsetemplate($Template, $bloc); } return $Table; }
function ECO_getPlanetCaps($user, &$planet_row) { global $sn_data, $config; $sn_groups = $sn_data['groups']; $sn_group_structures = $sn_groups['structures']; $storage_overflowed_size = BASE_STORAGE_SIZE * MAX_OVERFLOW; $Caps = array('planet' => array('metal' => $planet_row['metal'], 'crystal' => $planet_row['crystal'], 'deuterium' => $planet_row['deuterium'], 'metal_max' => floor(mrc_modify_value($user, $planet_row, MRC_STOCKMAN, $storage_overflowed_size * pow(1.5, $planet_row[$sn_data[22]['name']]))), 'crystal_max' => floor(mrc_modify_value($user, $planet_row, MRC_STOCKMAN, $storage_overflowed_size * pow(1.5, $planet_row[$sn_data[23]['name']]))), 'deuterium_max' => floor(mrc_modify_value($user, $planet_row, MRC_STOCKMAN, $storage_overflowed_size * pow(1.5, $planet_row[$sn_data[24]['name']]))))); if ($planet_row['planet_type'] == 3) { return $Caps; } $config_resource_multiplier = $config->resource_multiplier; // Calcul de production linéaire des divers types $BuildTemp = $planet_row['temp_max']; $BuildEnergyTech = $user['energy_tech']; $Caps['metal_perhour'][0] = $config->metal_basic_income * $config_resource_multiplier; $Caps['crystal_perhour'][0] = $config->crystal_basic_income * $config_resource_multiplier; $Caps['deuterium_perhour'][0] = $config->deuterium_basic_income * $config_resource_multiplier; $Caps['energy'][0] = $config->energy_basic_income; $Caps['planet']['energy_max'] = $Caps['energy'][0]; foreach ($sn_groups['prod'] as $ProdID) { $unit_data = $sn_data[$ProdID]; $BuildLevel = $planet_row[$sn_data[$ProdID]['name']]; $BuildLevelFactor = $planet_row["{$sn_data[$ProdID]['name']}_porcent"]; $Caps['energy'][$ProdID] = floor(eval($unit_data['energy_perhour'])); if ($ProdID == 12) { if ($planet_row['deuterium'] > 0) { $Caps['deuterium_perhour'][$ProdID] = floor(eval($unit_data['deuterium_perhour'])); } else { $Caps['energy'][$ProdID] = 0; } } else { if (in_array($ProdID, $sn_group_structures)) { $Caps['metal_perhour'][$ProdID] += floor(mrc_modify_value($user, $planet_row, MRC_GEOLOGIST, eval($unit_data['metal_perhour']) * $config_resource_multiplier)); $Caps['crystal_perhour'][$ProdID] += floor(mrc_modify_value($user, $planet_row, MRC_GEOLOGIST, eval($unit_data['crystal_perhour']) * $config_resource_multiplier)); $Caps['deuterium_perhour'][$ProdID] += floor(mrc_modify_value($user, $planet_row, MRC_GEOLOGIST, eval($unit_data['deuterium_perhour']) * $config_resource_multiplier)); } } if ($Caps['energy'][$ProdID] > 0) { $Caps['energy'][$ProdID] = floor(mrc_modify_value($user, $planet_row, array(MRC_POWERMAN), $Caps['energy'][$ProdID])); $Caps['planet']['energy_max'] += floor($Caps['energy'][$ProdID]); } else { $Caps['planet']['energy_used'] -= floor($Caps['energy'][$ProdID]); } $Caps['planet']['metal_perhour'] += $Caps['metal_perhour'][$ProdID]; $Caps['planet']['crystal_perhour'] += $Caps['crystal_perhour'][$ProdID]; $Caps['planet']['deuterium_perhour'] += $Caps['deuterium_perhour'][$ProdID]; } if ($Caps['planet']['energy_used']) { $Caps['production'] = max(0, min(1, $Caps['planet']['energy_max'] / $Caps['planet']['energy_used'])); } else { $Caps['production'] = 1; } $Caps['real']['metal_perhour'] = floor($Caps['planet']['metal_perhour'] * $Caps['production'] + $Caps['metal_perhour'][0]); $Caps['real']['crystal_perhour'] = floor($Caps['planet']['crystal_perhour'] * $Caps['production'] + $Caps['crystal_perhour'][0]); $Caps['real']['deuterium_perhour'] = floor($Caps['planet']['deuterium_perhour'] * $Caps['production'] + $Caps['deuterium_perhour'][0]); foreach ($Caps['energy'] as $element => $production) { $Caps['real']['units']['metal_perhour'][$element] = floor($Caps['metal_perhour'][$element] * $Caps['production']); $Caps['real']['units']['crystal_perhour'][$element] = floor($Caps['crystal_perhour'][$element] * $Caps['production']); $Caps['real']['units']['deuterium_perhour'][$element] = floor($Caps['deuterium_perhour'][$element] * $Caps['production']); } return $Caps; }
function ShowProductionTable($CurrentUser, $CurrentPlanet, $BuildID, $Template) { global $sn_data, $config; $unit_data = $sn_data[$BuildID]; $config_resource_multiplier = $config->resource_multiplier; $BuildLevelFactor = $CurrentPlanet[$unit_data['name'] . "_porcent"]; $BuildTemp = $CurrentPlanet['temp_max']; $BuildEnergyTech = $CurrentUser['energy_tech']; $CurrentBuildtLvl = $CurrentPlanet[$unit_data['name']]; $BuildLevel = $CurrentBuildtLvl > 0 ? $CurrentBuildtLvl : 1; $Prod[1] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['metal_perhour']))); $Prod[2] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['crystal_perhour']))); $Prod[3] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['deuterium_perhour']))); $Prod[4] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_POWERMAN, eval($unit_data['energy_perhour']))); $ActualProd = floor($Prod[$BuildID]); if ($BuildID != 12) { $ActualNeed = floor($Prod[4]); } else { $ActualNeed = floor($Prod[3]); } $BuildStartLvl = $CurrentBuildtLvl - 2; if ($BuildStartLvl < 1) { $BuildStartLvl = 1; } $Table = ""; $ProdFirst = 0; for ($BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 10; $BuildLevel++) { if ($BuildID != 42) { $Prod[1] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['metal_perhour']))); $Prod[2] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['crystal_perhour']))); $Prod[3] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_GEOLOGIST, $config_resource_multiplier * eval($unit_data['deuterium_perhour']))); $Prod[4] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, MRC_POWERMAN, eval($unit_data['energy_perhour']))); $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; if ($ProdFirst > 0) { if ($BuildID != 12) { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[$BuildID] - $ProdFirst)) . ")</font>"; } else { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[4] - $ProdFirst)) . ")</font>"; } } else { $bloc['build_gain'] = ""; } if ($BuildID != 12) { $bloc['build_prod'] = pretty_number(floor($Prod[$BuildID])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[$BuildID] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[4]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[4] - $ActualNeed), true, true); } else { $bloc['build_prod'] = pretty_number(floor($Prod[4])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[4] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[3]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[3] - $ActualNeed), true, true); } if ($ProdFirst == 0) { if ($BuildID != 12) { $ProdFirst = floor($Prod[$BuildID]); } else { $ProdFirst = floor($Prod[4]); } } } else { // Cas particulier de la phalange $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; $bloc['build_range'] = $BuildLevel * $BuildLevel - 1; } $Table .= parsetemplate($Template, $bloc); } return $Table; }
function GetMaxFleets(&$user) { return mrc_modify_value($user, false, MRC_COORDINATOR, 1 + $user[$GLOBALS['sn_data'][TECH_COMPUTER]['name']]); }
function get_engine_data($user, $engine_info) { $sn_data_tech_bonus = get_unit_param($engine_info['tech'], 'bonus'); $user_tech_level = intval(mrc_get_level($user, false, $engine_info['tech'])); $engine_info['speed_base'] = $engine_info['speed']; $tech_bonus = ($user_tech_level - $engine_info['min_level']) * $sn_data_tech_bonus / 100; $tech_bonus = $tech_bonus < -0.9 ? -0.95 : $tech_bonus; $engine_info['speed'] = floor(mrc_modify_value($user, false, array(MRC_NAVIGATOR), $engine_info['speed']) * (1 + $tech_bonus)); $engine_info['consumption_base'] = $engine_info['consumption']; $tech_bonus = ($user_tech_level - $engine_info['min_level']) * $sn_data_tech_bonus / 1000; $tech_bonus = $tech_bonus > 0.5 ? 0.5 : ($tech_bonus < 0 ? $tech_bonus * 2 : $tech_bonus); $engine_info['consumption'] = ceil($engine_info['consumption'] * (1 - $tech_bonus)); return $engine_info; }
function sn_eco_build($que_type, &$auser, &$planet) { global $lang, $config; if ($ally_id = sys_get_param_id('ally_id')) { define('SN_IN_ALLY', true); $ranks = ally_get_ranks($auser['ally']); if ($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { $user =& $auser['ally']['player']; $planet = array('metal' => $user['metal'], 'crystal' => $user['crystal'], 'deuterium' => $user['deuterium']); } } if (!$user) { $user =& $auser; } switch ($action = sys_get_param_escaped('action')) { case 'create': // Add unit to que for build // Add unit to que for build case 'destroy': // Add unit to que for remove $operation_result = que_build($user, $planet, $action == 'destroy' ? BUILD_DESTROY : BUILD_CREATE); break; case 'trim': que_delete($que_type, $user, $planet, false); break; case 'clear': que_delete($que_type, $user, $planet, true); break; } $group_missile = sn_get_groups('missile'); $silo_capacity_free = 0; if ($que_type == QUE_STRUCTURES) { $build_unit_list = sn_get_groups('build_allow'); $build_unit_list = $build_unit_list[$planet['planet_type']]; $artifact_id = ART_NANO_BUILDER; $page_header = $lang['tech'][UNIT_STRUCTURES]; } elseif ($que_type == QUE_RESEARCH) { if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); } if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); } $build_unit_list = sn_get_groups('tech'); $artifact_id = ART_HEURISTIC_CHIP; $page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); } elseif ($que_type == QUE_MERCENARY) { // if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { // message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); // } // if(eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { // message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); // } $build_unit_list = sn_get_groups('mercenaries'); $artifact_id = 0; $page_header = $lang['tech'][UNIT_MERCENARIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); } else { if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { message($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]); } $build_unit_list = sn_get_groups($page_mode = $que_type == SUBQUE_FLEET ? 'fleet' : 'defense'); $page_header = $lang[$page_mode]; $artifact_id = 0; $silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY); foreach ($group_missile as $unit_id) { $silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE); } $silo_capacity_free = max(0, $silo_capacity_free); } // Caching values that used more then one time into local variables // $config_resource_multiplier = $config->resource_multiplier; $config_resource_multiplier = game_resource_multiplier(); /* // Code for fully working new que system $hangar_busy = count($que['que'][QUE_HANGAR]); $lab_busy = count($que['que'][QUE_RESEARCH]) && !$config->BuildLabWhileRun; */ $template = gettemplate('buildings_builds', true); if (!empty($operation_result)) { $template->assign_block_vars('result', $operation_result); } $planet_id = $que_type == QUE_RESEARCH || $que_type == QUE_MERCENARY ? 0 : $planet['id']; $ques = que_get($user['id'], $planet_id, $que_type); $in_que =& $ques['in_que'][$que_type][$user['id']][$planet_id]; $que =& $ques['ques'][$que_type][$user['id']][$planet_id]; que_tpl_parse($template, $que_type, $user, $planet, $que); $que_length = count($que); $can_que_element = $que_length < que_get_max_que_length($user, $planet, $que_type); $fleet_list = flt_get_fleets_to_planet($planet); $planet_fields_max = eco_planet_fields_max($planet); $planet_fields_current = $planet['field_current']; $planet_fields_que = is_array($in_que) ? -array_sum($in_que) : 0; $planet_fields_free = max(0, $planet_fields_max - $planet_fields_current + $planet_fields_que); $planet_fields_queable = $que_type != QUE_STRUCTURES || $planet_fields_free > 0; //$planet_temp_max = $planet['temp_max']; $sn_modifiers_resource = sn_get_groups('modifiers'); $sn_modifiers_resource = $sn_modifiers_resource[MODIFIER_RESOURCE_PRODUCTION]; $sn_groups_density = sn_get_groups('planet_density'); $density_info = $sn_groups_density[$planet['density_index']][UNIT_RESOURCES]; $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); foreach ($build_unit_list as $unit_id) { $level_base = mrc_get_level($user, $planet, $unit_id, false, true); $level_effective = mrc_get_level($user, $planet, $unit_id); $level_in_que = $in_que[$unit_id]; $level_bonus = max(0, $level_effective - $level_base); $level_base_and_que = $level_base + $level_in_que; $unit_info = get_unit_param($unit_id); // pdump($unit_info, '$unit_info'); $unit_stackable = isset($unit_info[P_STACKABLE]) && $unit_info[P_STACKABLE]; $build_data = eco_get_build_data($user, $planet, $unit_id, $level_base_and_que); // pdump($build_data, '$build_data'); $temp[RES_METAL] = floor($planet['metal'] + $fleet_list['own']['total'][RES_METAL] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] + $fleet_list['own']['total'][RES_CRYSTAL] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] + $fleet_list['own']['total'][RES_DEUTERIUM] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $temp[RES_DARK_MATTER] = floor($user_dark_matter - $build_data[BUILD_CREATE][RES_DARK_MATTER]); $build_data['RESULT'][BUILD_CREATE] = $build_data['RESULT'][BUILD_CREATE] == BUILD_ALLOWED && !$can_que_element ? BUILD_QUE_FULL : $build_data['RESULT'][BUILD_CREATE]; // Restricting $can_build by resources on planet and (where applicable) with max count per unit $can_build = $unit_info[P_MAX_STACK] ? max(0, $unit_info[P_MAX_STACK] - $level_in_que - $level_effective) : $build_data['CAN'][BUILD_CREATE]; // Restricting $can_build by free silo capacity $can_build = ($unit_is_missile = in_array($unit_id, $group_missile)) ? min($can_build, floor($silo_capacity_free / $unit_info[P_UNIT_SIZE])) : $can_build; if (!$can_build) { if (!$build_data['CAN'][BUILD_CREATE]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_NO_RESOURCES; } elseif ($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_SILO_FULL; } elseif ($unit_info[P_MAX_STACK]) { $build_data['RESULT'][BUILD_CREATE] = BUILD_MAX_REACHED; } } $build_result_text = $lang['sys_build_result'][$build_data['RESULT'][BUILD_CREATE]]; $build_result_text = !is_array($build_result_text) ? $build_result_text : (isset($build_result_text[$unit_id]) ? $build_result_text[$unit_id] : $build_result_text[0]); $template->assign_block_vars('production', array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'DESCRIPTION' => $lang['info'][$unit_id]['description_short'], 'LEVEL_OLD' => $level_base, 'LEVEL_BONUS' => $level_bonus, 'LEVEL_NEXT' => $level_base + $level_in_que + 1, 'LEVEL_QUED' => $level_in_que, 'LEVEL' => $level_base_and_que, 'CAN_BUILD' => $can_build, 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[RES_TIME][BUILD_CREATE]), 'TIME_SECONDS' => $build_data[RES_TIME][BUILD_CREATE], 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'METAL_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'CRYSTAL_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'DEUTERIUM_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'ENERGY' => $build_data[BUILD_CREATE][RES_ENERGY], 'DARK_MATTER' => $build_data[BUILD_CREATE][RES_DARK_MATTER], 'DARK_MATTER_ONLY' => $build_data[P_OPTIONS][P_ONLY_DARK_MATTER], 'BUILD_RESULT' => $build_data['RESULT'][BUILD_CREATE], 'BUILD_RESULT_TEXT' => $build_result_text, 'DESTROY_RESULT' => $build_data['RESULT'][BUILD_DESTROY], 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[RES_TIME][BUILD_DESTROY]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'DARK_MATTER_REST' => pretty_number($temp[RES_DARK_MATTER], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'DARK_MATTER_REST_NUM' => $temp[RES_DARK_MATTER], 'UNIT_BUSY' => eco_unit_busy($user, $planet, $que, $unit_id), 'MAP_IS_RESOURCE' => !empty($unit_info['production']))); if ($unit_stackable) { $level_production_base = array('ACTUAL_SHIELD' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_SHIELD), $unit_info['shield'])), 'ACTUAL_ARMOR' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_ARMOR), $unit_info['armor'])), 'ACTUAL_WEAPON' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_WEAPON), $unit_info['attack']))); if ($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { $ship_data = get_ship_data($unit_id, $user); $level_production_base += array('ACTUAL_SPEED' => pretty_number($ship_data['speed']), 'ACTUAL_CONSUMPTION' => pretty_number($ship_data['consumption']), 'ACTUAL_CAPACITY' => pretty_number($ship_data['capacity'])); } if ($unit_info['production']) { foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc(1, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base['R' . $resource_id] = $resource_income; } } } $template->assign_block_vars('production.resource', $level_production_base); } elseif ($unit_info['production']) { $level_production_base = array(); $element_level_start = $level_effective + $in_que[$unit_id]; foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base[$resource_id] = $resource_income; } } $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; for ($i = 0; $i < 6; $i++) { $level_production = array('LEVEL' => $level_start + $i); foreach ($unit_info['production'] as $resource_id => $resource_calc) { if ($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production['R' . $resource_id] = $resource_income; $level_production['D' . $resource_id] = $resource_income - $level_production_base[$resource_id]; } } $template->assign_block_vars('production.resource', $level_production); } } elseif ($unit_id == TECH_ASTROTECH) { $element_level_start = $level_effective + $in_que[$unit_id]; /* foreach($unit_info['production'] as $resource_id => $resource_calc) { if($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production_base[$resource_id] = $resource_income; } } */ $level_production_base = array(UNIT_PLAYER_EXPEDITIONS_MAX => get_player_max_expeditons($user, $element_level_start), UNIT_PLAYER_COLONIES_MAX => get_player_max_colonies($user, $element_level_start)); $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; for ($i = 0; $i < 6; $i++) { $level_production = array('LEVEL' => $level_start + $i); $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] = get_player_max_expeditons($user, $level_start + $i); $level_production['D' . UNIT_PLAYER_EXPEDITIONS_MAX] = $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] - $level_production_base[UNIT_PLAYER_EXPEDITIONS_MAX]; $level_production['R' . UNIT_PLAYER_COLONIES_MAX] = get_player_max_colonies($user, $level_start + $i); $level_production['D' . UNIT_PLAYER_COLONIES_MAX] = $level_production['R' . UNIT_PLAYER_COLONIES_MAX] - $level_production_base[UNIT_PLAYER_COLONIES_MAX]; /* foreach($unit_info['production'] as $resource_id => $resource_calc) { if($resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) * $config_resource_multiplier * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1)))) { $level_production['R'.$resource_id] = $resource_income; $level_production['D'.$resource_id] = $resource_income - $level_production_base[$resource_id]; } } $template->assign_block_vars('production.resource', $level_production); */ $template->assign_block_vars('production.resource', $level_production); $level_production_base = array(UNIT_PLAYER_EXPEDITIONS_MAX => $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX], UNIT_PLAYER_COLONIES_MAX => $level_production['R' . UNIT_PLAYER_COLONIES_MAX]); } } //pdump(unit_requirements_render($user, $planet, $unit_id)); foreach (unit_requirements_render($user, $planet, $unit_id) as $requirement) { $template->assign_block_vars('production.require', $requirement); } } $sector_cost = eco_get_build_data($user, $planet, UNIT_SECTOR, mrc_get_level($user, $planet, UNIT_SECTOR), true); $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; $template->assign_vars(array('ALLY_ID' => $user['user_as_ally'], 'QUE_ID' => $que_type, 'SHOW_SECTORS' => $que_type == QUE_STRUCTURES, 'FLEET_OWN_COUNT' => $fleet_list['own']['count'], 'ARTIFACT_ID' => $artifact_id, 'ARTIFACT_LEVEL' => mrc_get_level($user, array(), $artifact_id), 'ARTIFACT_NAME' => $lang['tech'][$artifact_id], 'REQUEST_URI' => urlencode($_SERVER['REQUEST_URI']), 'PAGE_HEADER' => $page_header, 'TIME_NOW' => SN_TIME_NOW, 'PLN_ID' => $planet['id'], 'METAL' => $planet['metal'], 'CRYSTAL' => $planet['crystal'], 'DEUTERIUM' => $planet['deuterium'], 'DARK_MATTER' => $user_dark_matter, 'METAL_INCOMING' => $fleet_list['own']['total'][RES_METAL], 'CRYSTAL_INCOMING' => $fleet_list['own']['total'][RES_CRYSTAL], 'DEUTERIUM_INCOMING' => $fleet_list['own']['total'][RES_DEUTERIUM], 'FIELDS_CURRENT' => $planet_fields_current, 'FIELDS_MAX' => $planet_fields_max, 'FIELDS_FREE' => $planet_fields_free, 'FIELDS_QUE' => $planet_fields_que == 0 ? '' : $planet_fields_que > 0 ? "+{$planet_fields_que}" : $planet_fields_que, 'QUE_HAS_PLACE' => $can_que_element, 'QUE_HAS_FIELDS' => $planet_fields_queable, 'PAGE_HINT' => $lang['eco_bld_page_hint'], 'PLANET_TYPE' => $planet['planet_type'], 'SECTOR_CAN_BUY' => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER), 'SECTOR_COST' => $sector_cost, 'SECTOR_COST_TEXT' => pretty_number($sector_cost), 'STACKABLE' => $unit_stackable, 'TEMPORARY' => intval($config->empire_mercenary_temporary && $que_type == QUE_MERCENARY), 'STRING_CREATE' => $que_type == QUE_MERCENARY ? $lang['bld_hire'] : ($que_type == QUE_RESEARCH ? $lang['bld_research'] : $lang['bld_create']), 'STRING_BUILD_TIME' => $que_type == QUE_RESEARCH ? $lang['ResearchTime'] : $lang['ConstructionTime'], 'U_opt_int_struc_vertical' => $user['option_list'][OPT_INTERFACE]['opt_int_struc_vertical'])); display(parsetemplate($template)); // , $lang['Builds'] }
function GetBuildingTime($user, $planet, $Element, $for_building = BUILD_CREATE, $level = false) { global $config, $sn_data; $isDefense = in_array($Element, $sn_data['groups']['defense']); $isFleet = in_array($Element, $sn_data['groups']['fleet']); if ($level === false) { $unit_db_name = $sn_data[$Element]['name']; $level = $planet[$unit_db_name] ? $planet[$unit_db_name] : $user[$unit_db_name]; $level = ($level and !($isDefense or $isFleet)) ? $level : 1; } $time = ($sn_data[$Element]['metal'] + $sn_data[$Element]['crystal'] + $sn_data[$Element]['deuterium']) * pow($sn_data[$Element]['factor'], $level) / get_game_speed() / 2500; if (in_array($Element, $sn_data['groups']['structures'])) { // Pour un batiment ... $time = $time * (1 / ($planet[$sn_data['14']['name']] + 1)) * pow(0.5, $planet[$sn_data['15']['name']]); $time = floor(mrc_modify_value($user, $planet, MRC_ARCHITECT, $time * 60 * 60)); } elseif (in_array($Element, $sn_data['groups']['tech'])) { // Pour une recherche $intergal_lab = $user[$sn_data[TECH_RESEARCH]['name']]; if ($intergal_lab < 1) { $time = $time / (($planet[$sn_data['31']['name']] + 1) * 2) * pow(0.5, $planet[$sn_data['35']['name']]); } else { $lab_require = intval($sn_data[$Element]['require'][31]); $limite = $intergal_lab + 1; $inves = doquery("SELECT SUM(laboratory) AS laboratorio\r\n FROM\r\n (\r\n SELECT laboratory\r\n FROM {{planets}}\r\n WHERE id_owner='{$user['id']}' AND laboratory>={$lab_require}\r\n ORDER BY laboratory DESC\r\n LIMIT {$limite}\r\n ) AS subquery;", '', true); // $time = $time / (($inves['laboratorio'] + 1) * 2) * pow(0.5, $planet[$sn_data[35]['name']]); $inves = doquery("SELECT SUM(lab) AS laboratorio\r\n FROM\r\n (\r\n SELECT ({$sn_data[31]['name']} + 1) * 2 / pow(0.5, {$sn_data[35]['name']}) AS lab\r\n FROM {{planets}}\r\n WHERE id_owner='{$user['id']}' AND {$sn_data[31]['name']} >= {$lab_require}\r\n ORDER BY lab DESC\r\n LIMIT {$limite}\r\n ) AS subquery;", '', true); $time = $time / $inves['laboratorio']; } $time = floor(mrc_modify_value($user, $planet, MRC_ACADEMIC, $time * 60 * 60)); } elseif ($isDefense) { // Pour les defenses ou la flotte 'tarif fixe' durée adaptée a u niveau nanite et usine robot $time = $time * (1 / ($planet[$sn_data[21]['name']] + 1)) * pow(1 / 2, $planet[$sn_data[15]['name']]); $time = floor(mrc_modify_value($user, $planet, MRC_FORTIFIER, $time * 60 * 60)); } elseif ($isFleet) { $time = $time * (1 / ($planet[$sn_data[21]['name']] + 1)) * pow(1 / 2, $planet[$sn_data[15]['name']]); $time = floor(mrc_modify_value($user, $planet, MRC_CONSTRUCTOR, $time * 60 * 60)); } if ($for_building == BUILD_DESTROY) { $time = floor($time / 2); } return $time ? $time : 1; }
/** * eco_get_build_data.php * * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws * @version 1.0 */ function eco_get_build_data($user, $planet, $unit_id, $unit_level = 0) { global $sn_data; $sn_groups = $sn_data['groups']; $unit_data = $sn_data[$unit_id]; $unit_db_name = $unit_data['name']; $unit_factor = $unit_data['factor'] ? $unit_data['factor'] : 1; $price_increase = pow($unit_factor, $unit_level); $can_build = 1000000000000; foreach ($unit_data['cost'] as $resource_id => $resource_amount) { $resource_cost = $resource_amount * $price_increase; $cost[BUILD_CREATE][$resource_id] = floor($resource_cost); $cost[BUILD_DESTROY][$resource_id] = floor($resource_cost / 2); if ($resource_id != RES_ENERGY && $resource_id != RES_DARK_MATTER) { if ($resource_cost != 0) { $can_build = min($can_build, $planet[$sn_data[$resource_id]['name']] / $resource_cost); } $time += $resource_cost; } } $cost['CAN'][BUILD_DESTROY] = floor($can_build * 2); $cost['CAN'][BUILD_CREATE] = floor($can_build); $time = $time * 60 * 60 / get_game_speed() / 2500; $mercenary = 0; if (in_array($unit_id, $sn_groups['structures'])) { $time = $time * pow(0.5, $planet[$sn_data[15]['name']]) / ($planet[$sn_data[14]['name']] + 1); $mercenary = MRC_ARCHITECT; } elseif (in_array($unit_id, $sn_groups['tech'])) { $tech_intergalactic = $user[$sn_data[TECH_RESEARCH]['name']]; if ($tech_intergalactic < 1) { $time = $time * pow(0.5, $planet[$sn_data[35]['name']]) / (($planet[$sn_data[31]['name']] + 1) * 2); } else { $lab_db_name = $sn_data[31]['name']; $lab_require = intval($unit_data['require'][31]); $tech_intergalactic = $tech_intergalactic + 1; /* $inves = doquery("SELECT SUM(`{$lab_db_name}`) AS `laboratorio` FROM ( SELECT `{$lab_db_name}` FROM `{{planets}}` WHERE `id_owner` = '{$user['id']}' AND `{$lab_db_name}` >= {$lab_require} ORDER BY `{$lab_db_name}` DESC LIMIT {$tech_intergalactic} ) AS subquery;", '', true); // $time = $time / (($inves['laboratorio'] + 1) * 2) * pow(0.5, $planet[$sn_data[35]['name']]); */ // TODO: Fix bug with counting building labs/nanolabs $inves = doquery("SELECT SUM(lab) AS effective_level\r\n FROM\r\n (\r\n SELECT ({$lab_db_name} + 1) * 2 / pow(0.5, {$sn_data[35]['name']}) AS lab\r\n FROM {{planets}}\r\n WHERE id_owner='{$user['id']}' AND {$lab_db_name} >= {$lab_require}\r\n ORDER BY lab DESC\r\n LIMIT {$tech_intergalactic}\r\n ) AS subquery;", '', true); $time = $time / $inves['effective_level']; } $mercenary = MRC_ACADEMIC; } elseif (in_array($unit_id, $sn_groups['defense'])) { $time = $time * pow(0.5, $planet[$sn_data[15]['name']]) / ($planet[$sn_data[21]['name']] + 1); $mercenary = MRC_FORTIFIER; } elseif (in_array($unit_id, $sn_groups['fleet'])) { $time = $time * pow(0.5, $planet[$sn_data[15]['name']]) / ($planet[$sn_data[21]['name']] + 1); $mercenary = MRC_CONSTRUCTOR; } if ($mercenary) { $time = mrc_modify_value($user, $planet, $mercenary, $time); } $time = $time >= 2 ? $time : 2; $cost[BUILD_CREATE][RES_TIME] = floor($time); $cost[BUILD_DESTROY][RES_TIME] = floor($time / 2); return $cost; }