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;
}
Esempio n. 2
0
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 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'] ? "&nbsp;{$lang['sys_of_ally']}&nbsp;{$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'] ? "&nbsp;{$lang['sys_of_ally']}&nbsp;{$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']
}
Esempio n. 4
0
<?php

$allow_anonymous = true;
include 'common.' . substr(strrchr(__FILE__, '.'), 1);
lng_include('admin');
$template = gettemplate('server_info', true);
$template->assign_vars(array('game_build_and_research' => $config->BuildLabWhileRun, 'USER_VACATION_DISABLE' => $config->user_vacation_disable, 'ALLOW_BUFFING' => $config->allow_buffing, 'ALLY_HELP_WEAK' => $config->ally_help_weak, 'FLEET_BASHING_ATTACKS' => $config->fleet_bashing_attacks, 'fleet_bashing_interval' => sys_time_human($config->fleet_bashing_interval), 'fleet_bashing_scope' => sys_time_human($config->fleet_bashing_scope), 'fleet_bashing_war_delay' => sys_time_human($config->fleet_bashing_war_delay), 'EMPIRE_MERCENARY_TEMPORARY' => $config->empire_mercenary_temporary, 'ALI_BONUS_MEMBERS' => isset($sn_module['ali_ally_player']) ? $config->ali_bonus_members : 0, 'PLAYER_MAX_COLONIES' => $config->player_max_colonies, 'GAME_MULTIACCOUNT_ENABLED' => $config->game_multiaccount_enabled, 'GAME_SPEED' => get_game_speed(), 'GAME_SPEED_PLAIN' => get_game_speed(true), 'FLEET_SPEED' => flt_server_flight_speed_multiplier(), 'FLEET_SPEED_PLAIN' => flt_server_flight_speed_multiplier(true), 'RESOURCE_MULTIPLIER' => game_resource_multiplier(), 'RESOURCE_MULTIPLIER_PLAIN' => game_resource_multiplier(true)));
display(parsetemplate($template));
Esempio n. 5
0
function flt_mission_explore(&$mission_data)
{
    if (!isset($mission_data['fleet_event']) || $mission_data['fleet_event'] != EVENT_FLT_ACOMPLISH) {
        return CACHE_NONE;
    }
    global $lang, $config;
    static $ship_data, $rates;
    $result = array('$mission_data' => $mission_data, '$outcome_list' => array(), '$mission_outcome' => FLT_EXPEDITION_OUTCOME_NONE, '$outcome_value' => 0, '$outcome_percent' => 0, '$outcome_mission_sub' => -1, '$fleet' => array(), '$fleet_lost' => array(), '$found_dark_matter' => 0, '$fleet_metal_points' => 0);
    $fleet =& $result['$fleet'];
    //  $fleet_left = &$result['$fleet_left'];
    $fleet_lost =& $result['$fleet_lost'];
    $outcome_mission_sub =& $result['$outcome_mission_sub'];
    $outcome_percent =& $result['$outcome_percent'];
    $found_dark_matter =& $result['$found_dark_matter'];
    $mission_outcome =& $result['$mission_outcome'];
    $outcome_value =& $result['$outcome_value'];
    $outcome_list =& $result['$outcome_list'];
    $fleet_metal_points =& $result['$fleet_metal_points'];
    if (!$ship_data) {
        foreach (sn_get_groups('fleet') as $unit_id) {
            $unit_info = get_unit_param($unit_id);
            if ($unit_info[P_UNIT_TYPE] != UNIT_SHIPS || !isset($unit_info['engine'][0]['speed']) || !$unit_info['engine'][0]['speed']) {
                continue;
            }
            $ship_data[$unit_id][P_COST_METAL] = get_unit_cost_in($unit_info[P_COST]);
        }
        $rates = get_resource_exchange();
    }
    $fleet_row = $mission_data['fleet'];
    $fleet = sys_unit_str2arr($fleet_row['fleet_array']);
    $fleet_capacity = 0;
    $fleet_metal_points = 0;
    foreach ($fleet as $ship_id => $ship_amount) {
        $unit_info = get_unit_param($ship_id);
        $fleet_capacity += $ship_amount * $unit_info[P_CAPACITY];
        $fleet_metal_points += $ship_amount * $ship_data[$ship_id][P_COST_METAL];
    }
    $fleet_capacity = max(0, $fleet_capacity - $fleet_row['fleet_resource_metal'] + $fleet_row['fleet_resource_crystal'] + $fleet_row['fleet_resource_deuterium']);
    $flt_stay_hours = ($fleet_row['fleet_end_stay'] - $fleet_row['fleet_start_time']) / 3600 * ($config->game_speed_expedition ? $config->game_speed_expedition : 1);
    $outcome_list = sn_get_groups('mission_explore_outcome_list');
    $outcome_list[FLT_EXPEDITION_OUTCOME_NONE]['chance'] = ceil(200 / pow($flt_stay_hours, 1 / 1.7));
    $chance_max = 0;
    foreach ($outcome_list as $key => &$value) {
        if (!$value['chance']) {
            unset($outcome_list[$key]);
            continue;
        }
        $value['value'] = $chance_max = $value['chance'] + $chance_max;
    }
    $outcome_value = mt_rand(0, $chance_max);
    // $outcome_value = 409;
    $outcome_description =& $outcome_list[$mission_outcome = FLT_EXPEDITION_OUTCOME_NONE];
    foreach ($outcome_list as $key => &$value) {
        if (!$value['chance']) {
            continue;
        }
        $mission_outcome = $key;
        $outcome_description = $value;
        if ($outcome_value <= $outcome_description['value']) {
            break;
        }
    }
    // Вычисляем вероятность выпадения данного числа в общем пуле
    $msg_sender = $lang['flt_mission_expedition']['msg_sender'];
    $msg_title = $lang['flt_mission_expedition']['msg_title'];
    $outcome_percent = ($outcome_description['value'] - $outcome_value) / $outcome_description['chance'];
    $msg_text = '';
    $msg_text_addon = '';
    $found_dark_matter = 0;
    //  $outcome_mission_sub = -1;
    switch ($mission_outcome) {
        //  switch(FLT_EXPEDITION_OUTCOME_LOST_FLEET) { // TODO DEBUG!
        case FLT_EXPEDITION_OUTCOME_LOST_FLEET:
            flt_mission_explore_outcome_lost_fleet($result);
            //      // $fleet_left = 1 - mt_rand(1, 3) * 0.25;// * 0.25;
            //      $fleet_left = 1 - mt_rand(1, 3) * mt_rand(200000, 300000) / 1000000;
            //      $fleet_lost = array();
            //      foreach($fleet as $unit_id => &$unit_amount) {
            //        $ships_left = floor($unit_amount * $fleet_left);
            //        $fleet_lost[$unit_id] = $unit_amount - $ships_left;
            //        $unit_amount = $ships_left;
            //        if(!$unit_amount) {
            //          unset($fleet[$unit_id]);
            //        }
            //      }
            break;
        case FLT_EXPEDITION_OUTCOME_LOST_FLEET_ALL:
            flt_mission_explore_outcome_lost_fleet_all($result);
            //      $fleet_lost = $fleet;
            //      $fleet = array();
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_FLEET:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем эквивалент найденного флота в метале
            // $found_in_metal = min($outcome_percent * $fleet_metal_points, $config->resource_multiplier * 10000000); // game_speed
            $found_in_metal = min($outcome_percent * $fleet_metal_points, game_resource_multiplier(true) * 10000000);
            // game_speed
            //  13 243 754 000 g x1
            //  60 762 247 000 a x10
            // 308 389 499 488 000 b x500
            // Рассчитываем стоимость самого дорого корабля в металле
            $max_metal_cost = 0;
            foreach ($fleet as $ship_id => $ship_amount) {
                $max_metal_cost = max($max_metal_cost, $ship_data[$ship_id]['metal_cost']);
            }
            // Ограничиваем корабли только теми, чья стоимость в металле меньше или равно стоимости самого дорогого корабля
            $can_be_found = array();
            foreach ($ship_data as $ship_id => $ship_info) {
                if ($ship_info['metal_cost'] < $max_metal_cost) {
                    $can_be_found[$ship_id] = $ship_info['metal_cost'];
                }
            }
            // Убираем колонизаторы и шпионов - миллиарды шпионов и колонизаторов нам не нужны
            unset($can_be_found[SHIP_COLONIZER]);
            unset($can_be_found[SHIP_SPY]);
            $fleet_found = array();
            while (count($can_be_found) && $found_in_metal >= max($can_be_found)) {
                $found_index = mt_rand(1, count($can_be_found)) - 1;
                $found_ship = array_slice($can_be_found, $found_index, 1, true);
                $found_ship_cost = reset($found_ship);
                $found_ship_id = key($found_ship);
                if ($found_ship_cost > $found_in_metal) {
                    unset($can_be_found[$found_ship_id]);
                } else {
                    $found_ship_count = mt_rand(1, floor($found_in_metal / $found_ship_cost));
                    $fleet_found[$found_ship_id] += $found_ship_count;
                    $found_in_metal -= $found_ship_count * $found_ship_cost;
                }
            }
            if (empty($fleet_found)) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            } else {
                foreach ($fleet_found as $unit_id => $unit_amount) {
                    $fleet[$unit_id] += $unit_amount;
                }
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_RESOURCES:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем количество найденных ресурсов
            $found_in_metal = ceil(min($outcome_percent * $fleet_metal_points, game_resource_multiplier(true) * 10000000, $fleet_capacity) * mt_rand(950000, 1050000) / 1000000);
            // game_speed
            $resources_found[RES_METAL] = floor(mt_rand(300000, 700000) / 1000000 * $found_in_metal);
            $found_in_metal -= $resources_found[RES_METAL];
            $found_in_metal = floor($found_in_metal * $rates[RES_METAL] / $rates[RES_CRYSTAL]);
            $resources_found[RES_CRYSTAL] = floor(mt_rand(500000, 1000000) / 1000000 * $found_in_metal);
            $found_in_metal -= $resources_found[RES_CRYSTAL];
            $found_in_metal = floor($found_in_metal * $rates[RES_CRYSTAL] / $rates[RES_DEUTERIUM]);
            $resources_found[RES_DEUTERIUM] = $found_in_metal;
            $fleet_row['fleet_resource_metal'] += $resources_found[RES_METAL];
            $fleet_row['fleet_resource_crystal'] += $resources_found[RES_CRYSTAL];
            $fleet_row['fleet_resource_deuterium'] += $resources_found[RES_DEUTERIUM];
            if (array_sum($resources_found) == 0) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_DM:
            $outcome_mission_sub = $outcome_percent >= 0.99 ? 0 : ($outcome_percent >= 0.9 ? 1 : 2);
            $outcome_percent = $outcome_description['percent'][$outcome_mission_sub];
            // Рассчитываем количество найденной ТМ
            $found_dark_matter = floor(min($outcome_percent * $fleet_metal_points / $rates[RES_DARK_MATTER], 10000) * mt_rand(750000, 1000000) / 1000000);
            if (!$found_dark_matter) {
                $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
            }
            break;
        case FLT_EXPEDITION_OUTCOME_FOUND_ARTIFACT:
            break;
        default:
            break;
    }
    flt_mission_explore_addon($result);
    $query_data = array();
    if ($found_dark_matter) {
        rpg_points_change($fleet_row['fleet_owner'], RPG_EXPEDITION, $found_dark_matter, 'Expedition Bonus');
        $msg_text_addon = sprintf($lang['flt_mission_expedition']['found_dark_matter'], $found_dark_matter);
    }
    if (!empty($fleet_lost)) {
        $msg_text_addon = $lang['flt_mission_expedition']['lost_fleet'];
        foreach ($fleet_lost as $ship_id => $ship_amount) {
            $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
        }
    }
    $fleet_row['fleet_amount'] = array_sum($fleet);
    if (!empty($fleet) && $fleet_row['fleet_amount']) {
        if (!empty($fleet_found)) {
            $msg_text_addon = $lang['flt_mission_expedition']['found_fleet'];
            foreach ($fleet_found as $ship_id => $ship_amount) {
                $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
            }
        }
        if (!empty($resources_found) && array_sum($resources_found) > 0) {
            $msg_text_addon = $lang['flt_mission_expedition']['found_resources'];
            foreach ($resources_found as $ship_id => $ship_amount) {
                $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
            }
            $query_data[] = "`fleet_resource_metal` = `fleet_resource_metal` + {$resources_found[RES_METAL]}";
            $query_data[] = "`fleet_resource_crystal` = `fleet_resource_crystal` + {$resources_found[RES_CRYSTAL]}";
            $query_data[] = "`fleet_resource_deuterium` = `fleet_resource_deuterium` + {$resources_found[RES_DEUTERIUM]}";
        }
        if (!empty($fleet_lost) || !empty($fleet_found)) {
            $fleet_row['fleet_array'] = sys_unit_arr2str($fleet);
            $query_data[] = "`fleet_amount` = {$fleet_row['fleet_amount']}";
            $query_data[] = "`fleet_array` = '{$fleet_row['fleet_array']}'";
        }
        $query_data[] = '`fleet_mess` = 1';
        $query_data = "UPDATE {{fleets}} SET " . implode(',', $query_data);
    } else {
        // Удалить флот
        $query_data = "DELETE FROM {{fleets}}";
    }
    $query_data .= " WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1";
    doquery($query_data);
    db_user_set_by_id($fleet_row['fleet_owner'], "`player_rpg_explore_xp` = `player_rpg_explore_xp` + 1");
    if (!$msg_text) {
        $messages =& $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['messages'];
        if ($outcome_mission_sub >= 0 && is_array($messages)) {
            $messages =& $messages[$outcome_mission_sub];
        }
        $msg_text = is_string($messages) ? $messages : (is_array($messages) ? $messages[mt_rand(0, count($messages) - 1)] : '');
    }
    $msg_text = sprintf($msg_text, $fleet_row['fleet_id'], uni_render_coordinates($fleet_row, 'fleet_end_')) . ($msg_text_addon ? "\r\n" . $msg_text_addon : '');
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_end_stay'], MSG_TYPE_EXPLORE, $msg_sender, $msg_title, $msg_text);
    return CACHE_FLEET | CACHE_USER_SRC;
}