function transfer_ships(&$source, &$target, &$doc, &$source_elem, &$target_elem, &$infantery, $data)
{
    $new_inf = array();
    $fid = $source->fid;
    foreach ($data as $prod_id => $count) {
        if ($source->ships[$prod_id] && $source->ships[$prod_id][0] >= $count && (int) $count > 0) {
            $source->ships[$prod_id][0] -= $count;
            $target->add_ships_arr(array($prod_id => array($count, $source->ships[$prod_id][1])));
            $shipname = get_name_by_prod_id($prod_id);
            $ship_elem = $doc->create_element("SR_SHIP");
            $ship_elem->set_attribute("prod_id", $prod_id);
            $ship_elem->set_attribute("count", $source->ships[$prod_id][0]);
            $ship_elem->set_attribute("reload", $source->ships[$prod_id][1]);
            $ship_elem->set_attribute("name", $shipname);
            $tship_elem = $doc->create_element("SR_SHIP");
            $tship_elem->set_attribute("prod_id", $prod_id);
            $tship_elem->set_attribute("count", $target->ships[$prod_id][0]);
            $tship_elem->set_attribute("reload", $target->ships[$prod_id][1]);
            $tship_elem->set_attribute("name", $shipname);
            $source_elem->append_child($ship_elem);
            $target_elem->append_child($tship_elem);
            if ($infantery > 0) {
                $sth = mysql_query("select i.storage*" . $count . " from fleet as f , inf_transporters as i where i.prod_id=f.prod_id and f.prod_id=" . $prod_id . " and f.prod_id=" . $prod_id . " and f.fid=" . $fid);
                $trans_storage = mysql_fetch_row($sth);
                $j = 0;
                if ($trans_storage[0] > 0) {
                    while ($infantery > 0 and $trans_storage[0] > 0) {
                        $sth = mysql_query("select if(i.tonnage*it.count>" . $trans_storage[0] . ",floor(" . $trans_storage[0] . "/i.tonnage),it.count),it.prod_id,it.count,i.tonnage AS storage from inf_transports as it, shipvalues as i, production as p where p.prod_id=i.prod_id and p.typ='I' and i.prod_id=it.prod_id and it.fid=" . $fid . " limit " . $j . "," . ($j + 1));
                        $j++;
                        if (!$sth) {
                            return 0;
                        }
                        // der schneider hätte mich getötet
                        if (mysql_num_rows($sth) == 0) {
                            break;
                        }
                        // mop: man hab ich früher hässlichen code gemacht...naja...ka was das macht..ich lass das ma so
                        $new = mysql_fetch_row($sth);
                        $new_inf[$new[1]] += $new[0];
                        $infantery -= $new[2] * $new[3];
                        $trans_storage[0] -= $new[0] * $new[3];
                        $sth = mysql_query("update inf_transports set count=count-" . $new[0] . " where fid=" . $fid . " and prod_id=" . $new[1]);
                        if (!$sth) {
                            return 0;
                        }
                    }
                }
            }
        }
    }
    return $new_inf;
}
Пример #2
0
function execute_tachyonscan()
{
    global $uid;
    global $oid;
    $actions_price = get_special_action_price(TACHYON_SCAN);
    $user_resources = get_users_resources($uid);
    $can_pay = true;
    if ($actions_price["metal"] != 0) {
        $user_resources["metal"] - $actions_price["metal"] < 0 ? $can_pay = false : ($price_string .= "- Metal: " . $actions_price["metal"]);
    }
    if ($actions_price["energy"] != 0) {
        $user_resources["energy"] - $actions_price["energy"] < 0 ? $can_pay = false : ($price_string .= "- Energy: " . $actions_price["energy"]);
    }
    if ($actions_price["mopgas"] != 0) {
        $user_resources["mopgas"] - $actions_price["mopgas"] < 0 ? $can_pay = false : ($price_string .= "- Mopgas: " . $actions_price["mopgas"]);
    }
    if ($actions_price["erkunum"] != 0) {
        $user_resources["erkunum"] - $actions_price["erkunum"] < 0 ? $can_pay = false : ($price_string .= "- Erkunum: " . $actions_price["erkunum"]);
    }
    if ($actions_price["gortium"] != 0) {
        $user_resources["gortium"] - $actions_price["gortium"] < 0 ? $can_pay = false : ($price_string .= "- Gortium: " . $actions_price["gortium"]);
    }
    if ($actions_price["susebloom"] != 0) {
        $user_resources["susebloom"] - $actions_price["susebloom"] < 0 ? $can_pay = false : ($price_string .= "- Susebloom: " . $actions_price["susebloom"]);
    }
    if ($can_pay) {
        $fleet = new fleet($oid);
        $sensor_jammers = get_number_sensor_jammers_at_fleet($fleet);
        $tonnage = $fleet->get_total_tonnage();
        $jam_probability = round($sensor_jammers * JAMMING_TONNAGE_PER_UNIT / $tonnage * 100);
        if ($jam_probability > 90) {
            $jam_probability = 90;
        }
        $request_content .= svg_text_paragraph("----------------------------------------------\n");
        $request_content .= svg_text_paragraph("SCAN REPORT\n");
        if ($price_string) {
            $request_content .= svg_text_paragraph("You have payed " . $price_string . ".\n");
        }
        $request_content .= svg_text_paragraph("----------------------------------------------\n");
        mt_srand((double) microtime() * 1000000);
        $random = mt_rand(1, 100);
        // erfolgreicher scan
        if ($random >= $jam_probability) {
            // fleets Admiral
            $itsAdmiral = $fleet->get_admiral();
            if ($itsAdmiral) {
                $request_content .= svg_text_paragraph("Admiral: " . get_admiral_name($itsAdmiral));
            } else {
                $request_content .= svg_text_paragraph("Admiral: none");
            }
            foreach ($fleet->ships as $prod_id => $count) {
                $its_name = get_name_by_prod_id($prod_id);
                $request_content .= svg_text_paragraph($count[0] . " " . strtoupper($its_name) . " must refuel " . $count[1] . " turns.\n");
            }
        } else {
            // misglückter scan
            $request_content .= svg_text_paragraph("We were not able to scan the fleet.");
        }
        // resourcen abziehen
        foreach ($actions_price as $res => $value) {
            if ($value != NULL) {
                subtract_users_resources($uid, $res, $value);
            }
        }
    } else {
        $request_content = svg_text_paragraph("Not enough resources to execute action");
    }
    $sr_request = "<SR_REQEST>";
    $sr_request .= $request_content;
    $sr_request .= "</SR_REQEST>";
    echo $sr_request;
}
Пример #3
0
function get_jumpgate($sid)
{
    global $uid;
    global $map_info;
    if (!in_array($sid, $map_info->get_possible_scan_systems()) && !in_array($sid, $map_info->get_all_fleet_scans())) {
        return false;
    }
    // BUTTON Definitionen
    $buttonShape = "button_circle_30x30_shadow";
    $system_info = $map_info->get_system($sid);
    $j_pid = get_pid_of_jumpgate($sid);
    // pid des jumpgates
    $j_uname = get_name_by_uid($j_uid);
    // name des jumpgatebesitzers
    $sth = mysql_query("select prod_id from jumpgates where pid='{$j_pid}'");
    if (!$sth || mysql_num_rows($sth) == 0) {
        return 0;
    }
    list($j_prodid) = mysql_fetch_row($sth);
    $j_prodname = get_name_by_prod_id($j_prodid);
    $j_pic = PIC_ROOT . get_pic($j_prodid);
    // Ok, Buttons kreieren und in $new_button[] speichern
    $new_button = array();
    $new_button[] = create_button($buttonShape, "button_face_info", "alert('not yet implemented')", 0, "show info");
    $new_header = create_header($j_pic, "Jumpgate in " . $system_info["name"], "", "", "");
    // Button in das Header Tag einfügen
    for ($i = 0; $i < sizeof($new_button); $i++) {
        $new_header .= $new_button[$i];
    }
    $new_header .= "</SR_HEAD>";
    echo "newItemBox\n";
    // nötig um zu ermitteln wie der inhalt behnadelt werden soll!
    echo $new_header;
}
Пример #4
0
function fleet_info()
{
    global $pid;
    global $uid;
    global $skin;
    $sth = mysql_query("select uid from planets where id={$pid} and uid={$uid}");
    if (!$sth) {
        show_error("Database failure!");
        return 0;
    }
    if (mysql_num_rows($sth) == 0) {
        show_error("Databaser failure!");
        return 0;
    }
    $fids = get_fids_by_pid($pid, $uid);
    if (!$fids) {
        show_message("You have no fleet on this planet");
    } else {
        table_start("center", "500");
        table_head_text(array("Ships in orbit"), "3");
        table_text_open("head");
        for ($i = 0; $i < sizeof($fids); $i++) {
            $fleet = new fleet($fids[$i]);
            table_text_open("head");
            table_text_design($fleet->name, "80", "", "", "head");
            table_text_design("Name", "300", "center", "", "smallhead");
            table_text_design("Count", "100", "center", "", "smallhead");
            table_text_close();
            while (list($prod_id, $ships_arr) = each($fleet->ships)) {
                $sth = mysql_query("select manual from production where prod_id={$prod_id}");
                if (!$sth) {
                    show_error("Database failure!");
                    return 0;
                }
                $manual = mysql_fetch_array($sth);
                table_text_open("text", "center");
                table_text_design("<a href='" . $manual["manual"] . "' target=\"_blank\"><img src='arts/" . get_pic($prod_id) . "' border='0' alt='" . get_description($prod_id) . "' align='center'></a><br><a href=\"" . $PHP_SELF . "?act=print_ship_info&prod_id=" . $prod_id . "\">Info</a>", "80", "", "", "text");
                table_text_design(get_name_by_prod_id($prod_id), "300", "", "", "text");
                table_text_design($ships_arr[0], "100", "", "", "text");
                table_text_close();
            }
        }
        table_end();
    }
    $sth3 = mysql_query("select * from s_production as sp,production as p where sp.planet_id='" . $pid . "' and p.prod_id=sp.prod_id order by sp.time,sp.prod_id");
    table_start("center", "500");
    fleet($sth3);
    table_end();
}
Пример #5
0
function print_ship_info($prod_id)
{
    if ($info = get_ship_info($prod_id)) {
        table_start("center", "500");
        table_head_text(array("Ships info for " . $info["name"]), "6");
        table_text_open("head");
        table_text_design("&nbsp;", "500", "", "2", "head");
        table_text_close();
        $info["p_depend"] = get_name_by_prod_id($info["p_depend"]);
        switch ($info["target1"]) {
            case "L":
                $info["target1"] = "Europe Class";
                break;
            case "M":
                $info["target1"] = "Zeus Class";
                break;
            case "H":
                $info["target1"] = "Olymp Class";
                break;
        }
        switch ($info["special"]) {
            case "E":
                $info["special"] = "Freezes enemy ships";
                break;
            case "R":
                $info["special"] = "Capable of stealing ships";
                break;
            case "S":
                $info["special"] = "Detects cloaked ships";
                break;
            case "C":
                $info["special"] = "Cloaked";
                break;
            default:
                $info["special"] = "Nothing";
        }
        foreach (array("name" => "Name", "metal" => "Metal", "energy" => "Energy", "mopgas" => "Mopgas", "erkunum" => "Erkunum", "gortium" => "Gortium", "susebloom" => "Susebloom", "rname" => "Needs tech", "p_depend" => "Needs building", "initiative" => "Initiative", "agility" => "Agility", "warpreload" => "Reload time", "hull" => "Hull", "tonnage" => "Tonnage", "weaponpower" => "Weaponpower", "shield" => "Shield", "ecm" => "ECM", "sensor" => "Sensor", "weaponskill" => "Weaponskill", "target1" => "Attacks", "special" => "Special abilities", "num_attacks" => "Number of attacks") as $key => $show) {
            table_text_open("text");
            table_text_design($show, "250", "", "", "text");
            table_text_design($info[$key], "250", "", "", "text");
            table_text_close();
        }
        table_end();
    } else {
        show_error("Can't get ship info!");
        return 0;
    }
}
Пример #6
0
function transfer()
{
    global $uid;
    global $fleet;
    global $PHP_SELF;
    global $HTTP_REFFERRER;
    if (!is_array($fleet)) {
        show_error("You have to select a fleet and some ships in order to transfer!");
        return 0;
    }
    $i = 0;
    while (list($key, $value) = each($fleet)) {
        if ($value == "Y") {
            $fleets[$i] = new fleet($key);
            if (!$fleets[$i]->uid == $uid) {
                show_error("Hello! I'm your friend...Why are you trying such nasty things?");
                return 0;
            }
            if (!$pid) {
                $pid = $fleets[$i]->pid;
                $sid = $fleets[$i]->sid;
            } else {
                if ($fleets[$i]->pid != $pid || $fleets[$i]->sid != $sid) {
                    show_error("You may only select fleets which are at the same planet and system!");
                    return 0;
                }
            }
        }
        $i++;
    }
    $new_fleet = new fleet();
    echo "<form action=\"" . $PHP_SELF . "\" method=post>";
    for ($i = 0; $i < sizeof($fleets); $i++) {
        $temp_var = "fleet_" . $fleets[$i]->fid;
        global ${$temp_var};
        foreach ((array) ${$temp_var} as $key => $value) {
            // Überprüfen ob die werte ok sind (key=>prod_id, value=>count)
            if ($fleets[$i]->ships[$key] && $fleets[$i]->ships[$key][0] >= $value && (int) $value > 0) {
                // Das wird nachher ausgelesen um die flotten auch um den wert zu reduzieren
                $fleets[$i]->ships[$key][0] -= $value;
                $aff_fleets[] = $fleets[$i]->fid;
                $new_fleet->add_ships_arr(array($key => array($value, $fleets[$i]->ships[$key][1])));
            } elseif ($value == 0) {
                continue;
            } else {
                show_error("You entered a wrong shipcount for fleet " . $fleets[$i]->name . "!");
                return 0;
            }
            form_hidden("fleet_" . $fleets[$i]->fid . "[" . $key . "]", $value);
        }
    }
    $fids = get_fids_by_pid($pid, $uid, $sid);
    for ($i = 0; $i < sizeof($fleets); $i++) {
        // mop: was für nen toller hack
        if (in_array($fleets[$i]->fid, $fids)) {
            // mop: umdrehen, damit wir das unsetten können ohne das array komplett durchsuchen zu müssen
            $fids_tmp = array_flip($fids);
            unset($fids_tmp[$fleets[$i]->fid]);
            // mop: und wieder zurück
            $fids = array_flip($fids_tmp);
        }
        form_hidden("fid[" . $i . "]", $fleets[$i]->fid);
    }
    // mop: wenn fertig fidsarray neubauen
    $fids = array_values($fids);
    // mop: jetzt die ausgewählten flotten abwählen
    for ($i = 0; $i < sizeof($fids); $i++) {
        $trans_fleets[$i] = new fleet($fids[$i]);
    }
    if (sizeof($trans_fleets) == 0) {
        center_headline("You have no fleets you could transfer these ships to:)");
        go_back($_SERVER["PHP_SELF"]);
    } else {
        for ($i = 0; $i < sizeof($trans_fleets); $i++) {
            $head_array = "";
            $text_arr = "";
            $prod_arr = "";
            table_start("center", "80%");
            table_head_text(array("Fleet " . $trans_fleets[$i]->name), "20");
            $head_array[0] = "&nbsp;";
            $prod_arr[0] = "";
            $text_arr[0] = "<input type=radio name=\"fleet\" value=\"" . $trans_fleets[$i]->fid . "\">";
            reset($trans_fleets[$i]);
            while (list($prod_id, $ship_arr) = each($trans_fleets[$i]->ships)) {
                $head_array[] = get_name_by_prod_id($prod_id);
                $text_arr[] = $ship_arr[0];
            }
            $mission = $trans_fleets[$i]->get_mission();
            list($type, $location) = $trans_fleets[$i]->get_location();
            if ($type == 0) {
                $mission_text = $mission[0] . " ";
            } else {
                $mission_text = "On its way to " . $mission[1] . " ";
            }
            list($location_id, $location_type) = $location;
            if ($location_type == 0) {
                $mission_text .= "planet " . get_planetname($trans_fleets[$i]->pid);
                $location_text = "Planet " . get_planetname($trans_fleets[$i]->pid) . "(" . get_systemname($trans_fleets[$i]->sid) . ")";
            } else {
                $mission_text .= "system " . get_system_coords($trans_fleets[$i]->sid);
                $location_text = "System " . get_systemname($trans_fleets[$i]->sid);
            }
            table_text(array("&nbsp;"), "", "", "20", "head");
            table_text_open();
            table_text_design("Mission:", "50", "", "", "smallhead");
            table_text_design($mission_text, "", "", "19", "text");
            table_text_close();
            table_text($head_array, "", "", "", "smallhead");
            table_text($text_arr, "", "", "", "text");
            table_end();
            echo "<br><br>\n";
        }
        form_hidden("act", "transferab");
        echo "<center>\n";
        echo "<input type=submit value=\"Transfer\">";
        echo "</center>\n";
        echo "</form>";
    }
}