Пример #1
0
function get_auto_build_resource_field_id($result)
{
    $level_all = get_resource_fields_level($result);
    $res = get_res_info($result);
    unset($res[4], $res[5], $res[6], $res[7]);
    asort($res);
    // print_r($res);
    foreach ($res as $type => $num) {
        $level_type = $level_all[$type];
        asort($level_type);
        //print_r($level_type);
        list($id, $level) = each($level_type);
        if ($level >= 10) {
            continue;
        }
        return $id;
    }
    echo "all resource fields level 10.\n";
    return false;
}
Пример #2
0
function get_auto_build_resource_field_id($result)
{
    global $race;
    global $account;
    global $village;
    $level_all = get_resource_fields_level($result);
    $res = get_res_info($result);
    $warehouse_capacity = $res[4];
    $granary_capacity = $res[7];
    // roman don't auto build farm
    //		if($race == "roman"){
    //			unset($res[3], $res[4], $res[5], $res[6], $res[7]);
    //		}else{
    unset($res[4], $res[5], $res[6], $res[7]);
    //		}
    asort($res);
    // print_r($res);
    foreach ($res as $type => $num) {
        $level_type = $level_all[$type];
        asort($level_type);
        //print_r($level_type);
        list($id, $level) = each($level_type);
        if ($level >= 10) {
            continue;
        }
        $min_capacity = array(800, 800, 1200, 1200, 1700, 5000, 6300, 7800, 9600, 14000);
        if ($min_capacity[$level] > $granary_capacity) {
            if ($granary_capacity > 800) {
                build_granary();
            } else {
                create_granary();
            }
            return false;
        }
        if ($min_capacity[$level] > $warehouse_capacity) {
            if ($warehouse_capacity == 800) {
                create_warehouse();
                return false;
            }
            if ($dorf2_html = build_warehouse()) {
                if (!strstr($dorf2_html, 'id="map2"')) {
                    echo "get_auto_build_resource_field_id failed: can not find map2.\n";
                    return false;
                }
                $dorf2_buildings = get_dorf2_building_level($dorf2_html);
                // no main building, try to build one
                if (!isset($dorf2_buildings['main_building'])) {
                    $id = get_free_space($dorf2_html);
                    if (!$id) {
                        return false;
                    }
                    $id = $id + 18;
                    $sql = "insert into `build`(account, village, id, gid) values({$account}, {$village}, {$id}, 15)";
                    if (!mysql_query($sql)) {
                        die(mysql_error());
                    }
                } else {
                    if ($dorf2_buildings['main_building'] < $level + 3) {
                        $sql = "insert into `build`(account, village, id) values({$account}, {$village}, 26)";
                        if (!mysql_query($sql)) {
                            die(mysql_error());
                        }
                    }
                }
                return false;
            }
        }
        return $id;
    }
    echo "all resource fields level 10.\n";
    build_when_all_resource_done();
    return false;
}