예제 #1
0
function combat_report($pid, $sid)
{
    global $combat;
    if (COMBAT_VERBOSE) {
        start_timer(1);
        echo "Erstelle Kampfbericht...";
    }
    $combat_smarty = new Smarty();
    global $__base_inc_dir;
    $combat_smarty->template_dir = $__base_inc_dir . "battle/templates/";
    $combat_smarty->compile_dir = $__base_inc_dir . "battle/templates_c";
    $combat_smarty->config_dir = $__base_inc_dir . "battle/configs/";
    $combat_smarty->cache_dir = $__base_inc_dir . "battle/cache/";
    $puid = get_uid_by_pid($pid);
    if ($pid) {
        if ($puid) {
            $puname = get_name_by_uid($puid);
        } else {
            $puname = "no owner";
        }
        if ($pid == -1) {
            $combat_smarty->assign("location", "SimOrbit");
        } else {
            $combat_smarty->assign("location", get_planetname($pid) . " ({$puname})");
        }
    } else {
        $combat_smarty->assign("location", get_systemname($sid));
    }
    $invader_id = combat_get_conqueror($pid);
    if (!$invader_id) {
        $combat_smarty->assign("invasion", "");
    } else {
        $combat["shots_fired"]++;
        if ($invader_id < 0 && $invader_id > -100) {
            $combat_smarty->assign("invasion", "Planet1 has been invaded by Side2");
        } elseif ($invader_id == -100) {
            $combat_smarty->assign("invasion", "Planetary combat, production was delayed.");
        } else {
            $combat_smarty->assign("invasion", get_planetname($pid) . " has been invaded by " . get_name_by_uid($invader_id));
        }
    }
    // Admiraele berichten
    $query = $GLOBALS["db"]->query("SELECT SUM(c1.challenge) AS xp_earned, c2.admiral_id AS admiral_id, c2.uid \nAS uid FROM combat c1 INNER JOIN combat c2 ON (c1.killed_by=c2.id) WHERE c2.admiral_id <> 0 \nGROUP BY c2.admiral_id") or die("Admiral-XP: " . $GLOBALS["db"]->error);
    while ($result = $query->fetch_assoc()) {
        if (!is_array($results[$result["uid"]]["admirals"])) {
            $aidx = 0;
        } else {
            $aidx = sizeof($results[$result["uid"]]["admirals"]);
        }
        $results[$result["uid"]]["admirals"][$aidx]["name"] = dlookup("name", "admirals", "id=" . $result["admiral_id"]);
        if (is_null(dlookup("killed_by", "combat", "admiral_carried=" . $result["admiral_id"]))) {
            $results[$result["uid"]]["admirals"][$aidx]["xp"] = dlookup("value", "admirals", "id=" . $result["admiral_id"]);
            $results[$result["uid"]]["admirals"][$aidx]["newxp"] = dlookup("value", "admirals", "id=" . $result["admiral_id"]) + $result["xp_earned"];
            $results[$result["uid"]]["admirals"][$aidx]["lvlup"] = calculate_admiral_level(dlookup("value", "admirals", "id=" . $result["admiral_id"]) + $result["xp_earned"]) != calculate_admiral_level(dlookup("value", "admirals", "id=" . $result["admiral_id"]));
        }
    }
    $users_query = $GLOBALS["db"]->query("SELECT DISTINCT uid, aid FROM combat") or die($GLOBALS["db"]->error);
    if (!$users_query) {
        return false;
    }
    while ($users_result = $users_query->fetch_assoc()) {
        // Feinde
        $results_query = $GLOBALS["db"]->query("SELECT alliance2 FROM diplomacy dp WHERE status=0 AND \nalliance1=" . $users_result["aid"]) or die($GLOBALS["db"]->error);
        if (!$results_query) {
            return false;
        }
        while (list($results[$users_result["uid"]]["enemies"][]) = $results_query->fetch_row()) {
        }
        // Schiffe gesamt
        $namefield = "CONCAT(p.name, ' ', IF(c.position='L','[unloaded]',\nIF(c.position='T','[on transport]',IF(c.position='U','[landed]',IF(IFNULL(c.killed_special,'')='E',\n'[disabled]',IF(IFNULL(c.killed_special,'')='R', '[captured]', ''))))))";
        $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, \nSUM(c.count_max) AS count FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, c.killed_special") or die($GLOBALS["db"]->error);
        if (!$results_query) {
            return false;
        }
        while ($unit = $results_query->fetch_assoc()) {
            $results[$users_result["uid"]]["ships"][$unit["name"]] = $unit["count"];
        }
        // Schiffe zerstört
        $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, SUM(c.count_max-c.count) AS count,\nIFNULL(c.killed_special,'') AS killed_special FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, c.killed_special") or die($GLOBALS["db"]->error);
        if (!$results_query) {
            return false;
        }
        while ($unit = $results_query->fetch_assoc()) {
            if ($unit["killed_special"] != "E" && $unit["killed_special"] != "R") {
                $results[$users_result["uid"]]["destroyed_ships"][$unit["name"]] = $unit["count"];
            }
        }
        // Schiffe lebendig
        $results_query = $GLOBALS["db"]->query("SELECT {$namefield} AS name, SUM(c.count) AS count,\nIFNULL(c.killed_special,'') AS killed_special FROM combat c INNER JOIN production p \nUSING (prod_id) WHERE c.killed_by IS NULL AND uid=" . $users_result["uid"] . " GROUP BY p.name, c.position, \nc.killed_special") or die($GLOBALS["db"]->error);
        if (!$results_query) {
            return false;
        }
        while ($unit = $results_query->fetch_assoc()) {
            if ($unit["killed_special"] != "E" && $unit["killed_special"] != "R") {
                $results[$users_result["uid"]]["remaining_ships"][$unit["name"]] = $unit["count"];
            }
        }
    }
    // Planetare Schilde berichten
    $query = $GLOBALS["db"]->query("SELECT 'Planetary shields' AS name, SUM(c.shield) AS shieldsum, \nSUM(c.shield_max) AS maxsum FROM combat c INNER JOIN production p USING (prod_id) WHERE c.special \nLIKE 'H%'") or die($GLOBALS["db"]->error);
    while ($result = $query->fetch_assoc()) {
        if ($result["maxsum"] > 0) {
            $results[$puid]["ships"][$result["name"]] = $result["maxsum"];
            $results[$puid]["destroyed_ships"][$result["name"]] = $result["maxsum"] - $result["shieldsum"];
            $results[$puid]["remaining_ships"][$result["name"]] = $result["shieldsum"];
        }
    }
    $combat_smarty->assign("results", $results);
    $users_query = $GLOBALS["db"]->query("SELECT DISTINCT uid FROM combat") or die($GLOBALS["db"]->error);
    if (!$users_query) {
        return false;
    }
    while ($users_result = $users_query->fetch_assoc()) {
        if ($users_result["uid"] < 0) {
            $users[$users_result["uid"]] = "BattleSim Side " . $users_result["uid"] * -1;
        } else {
            $users[$users_result["uid"]] = get_name_by_uid($users_result["uid"]);
        }
    }
    $combat_smarty->assign("users", $users);
    ob_start();
    $combat_smarty->display("battlereport.tpl");
    $report = ob_get_contents();
    ob_end_clean();
    $combat_smarty->clear_all_assign();
    // Report abspeichern
    if (BATTLE_DESTROY && $combat["shots_fired"] > 0) {
        $week = dlookup("week", "timeinfo");
        $sth = $GLOBALS["db"]->query("INSERT INTO battlereports SET pid={$pid}, sid={$sid}, \nreport='" . addslashes($report) . "', week={$week}") or die($GLOBALS["db"]->error);
        $report_id = $GLOBALS["db"]->insert_id;
        $query = $GLOBALS["db"]->query("SELECT DISTINCT uid FROM combat") or die($GLOBALS["db"]->error);
        while (list($id) = $query->fetch_row()) {
            $sth = $GLOBALS["db"]->query("INSERT INTO battlereports_user (uid, rid) VALUES ({$id}, {$report_id})") or die($GLOBALS["db"]->error);
        }
        $query = $GLOBALS["db"]->query("SELECT DISTINCT aid FROM combat") or die($GLOBALS["db"]->error);
        while (list($id) = $query->fetch_row()) {
            $sth = $GLOBALS["db"]->query("INSERT INTO battlereports_alliance (aid, rid) VALUES ({$id}, {$report_id})") or die($GLOBALS["db"]->error);
        }
    }
    if (COMBAT_VERBOSE) {
        echo "OK! (" . round(read_timer(1), 4) . "s)" . COMBAT_NEWLINE . COMBAT_NEWLINE;
    }
    if (!BATTLE_DESTROY) {
        echo "{$report}" . COMBAT_NEWLINE . COMBAT_NEWLINE;
    }
}
예제 #2
0
function upgrade_admiral_value($id, $value)
{
    // vorher immer checken ob value auch in ordnung is
    $sth = mysql_query("update admirals set {$value}={$value}+1 where id={$id} and used_upgrades<3");
    if (!$sth) {
        return 0;
    }
    $sth = mysql_query("select used_upgrades,used_xp from admirals where id={$id}");
    if (!$sth || mysql_num_rows($sth) == 0) {
        return false;
    }
    list($upgrades, $used_xp) = mysql_fetch_row($sth);
    if ($upgrades >= 2) {
        $sth = mysql_query("update admirals set used_xp=pow(2," . calculate_admiral_level($used_xp) . ")*1000,used_upgrades=0 where id={$id}");
    } else {
        $sth = mysql_query("update admirals set used_upgrades=used_upgrades+1 where id={$id}");
    }
    if (!$sth) {
        return false;
    }
    return true;
}
 /**
  * sammelt die ergebnisse
  */
 function gather_results()
 {
     $participants = $this->battlefield->get_participants();
     foreach ($participants as $participant) {
         if (!$this->users[$participant->get_uid()]) {
             $this->users[$participant->get_uid()] = get_name_by_uid($participant->get_uid()) . " (" . get_empire_by_uid($participant->get_uid()) . ")";
         }
         $this->results[$participant->get_uid()]["enemies"] = $participant->get_enemies();
         $units = $participant->get_units();
         foreach ($units as $unit) {
             if ($unit->has_subunits()) {
                 $sub_units = $unit->get_subunits();
                 for ($i = 0; $i < sizeof($sub_units); $i++) {
                     $this->results[$participant->get_uid()]["remaining_ships"][$sub_units[$i]->get_name()]++;
                     $this->results[$participant->get_uid()]["ships"][$sub_units[$i]->get_name()]++;
                 }
             }
             $this->results[$participant->get_uid()]["remaining_ships"][$unit->get_name()]++;
             $this->results[$participant->get_uid()]["ships"][$unit->get_name()]++;
         }
         $units = $participant->get_unloaded_units();
         foreach ($units as $unit) {
             $name = $unit->get_name() . " (unloaded)";
             $this->results[$participant->get_uid()]["remaining_ships"][$name]++;
             $this->results[$participant->get_uid()]["ships"][$name]++;
         }
         if ($participant->admiral) {
             if (!is_array($this->results[$participant->get_uid()]["admirals"])) {
                 $aidx = 0;
             } else {
                 $aidx = sizeof($this->results[$participant->get_uid()]["admirals"]);
             }
             echo "=> " . $aidx . "\n";
             $this->results[$participant->get_uid()]["admirals"][$aidx]["name"] = $participant->admiral->name;
             $this->results[$participant->get_uid()]["admirals"][$aidx]["xp"] = $participant->admiral->value;
             $this->results[$participant->get_uid()]["admirals"][$aidx]["newxp"] = $participant->admiral->newvalue;
             $this->results[$participant->get_uid()]["admirals"][$aidx]["lvlup"] = calculate_admiral_level($participant->admiral->newvalue) != calculate_admiral_level($participant->admiral->value);
         }
         $units = $participant->get_destroyed_units();
         if (!is_array($units)) {
             $units = array();
         }
         foreach ($units as $unit) {
             $this->results[$participant->get_uid()]["destroyed_ships"][$unit->get_name()]++;
             $this->results[$participant->get_uid()]["ships"][$unit->get_name()]++;
         }
         $units = $participant->get_fled_units();
         if (!is_array($units)) {
             $units = array();
         }
         foreach ($units as $unit) {
             $this->results[$participant->get_uid()]["remaining_ships"][$unit->get_name()]++;
             $this->results[$participant->get_uid()]["ships"][$unit->get_name()]++;
         }
     }
 }
예제 #4
0
/** 
 * callback um xp => level zu machen
 * 
 * @param $spaltenname,$values,$unmod_values 
 * @return 
 */
function browser_calc_level($spaltenname, $values, $unmod_values)
{
    return calculate_admiral_level($values[$spaltenname]);
}
예제 #5
0
function admiral_pool()
{
    global $uid;
    $sth = mysql_query("select * from admirals where uid={$uid} and fid=0");
    if (!$sth) {
        show_error("Database error!");
        return 0;
    }
    if (mysql_num_rows($sth) == 0) {
        return 0;
    }
    center_headline("Admiral Pool");
    table_start("center", "500");
    table_head_text(array("Admirals"), "7");
    table_text(array("&nbsp;"), "", "", "7", "text");
    table_text_open();
    table_text_design("&nbsp;", "50", "", "", "head");
    table_text_design("Name", "200", "", "", "head");
    table_text_design("Rank", "75", "", "", "head");
    table_text_design("Initiative", "75", "", "", "head");
    table_text_design("Agility", "75", "", "", "head");
    table_text_design("Sensor", "75", "", "", "head");
    table_text_design("Weaponskill", "75", "", "", "head");
    table_text_close();
    while ($admiral = mysql_fetch_array($sth)) {
        if ($admiral["value"] < 1000) {
            $level = 0;
        } else {
            $level = floor(log10($admiral["value"] / 1000) / log10(2) + 1);
        }
        table_text_open();
        table_text_design("<img src=\"portraits/" . $admiral["pic"] . "\" border=\"0\" alt=\"" . $admiral["name"] . "\">", $admiral["name"], "200", "center", "", "text");
        table_text_design($admiral["name"], "75", "center", "", "text");
        table_text_design($level, "75", "center", "", "text");
        foreach (array("initiative", "agility", "sensor", "weaponskill") as $dummy => $value) {
            if (calculate_admiral_level($admiral["used_xp"]) < $level) {
                $upgrade = "<a href=\"" . $PHP_SELF . "?act=upgrade_admiral_pool&id=" . $admiral["id"] . "&value=" . $value . "\"><img src=\"arts/plus.jpg\" border=\"0\" width=\"10\"></a>";
            } else {
                $upgrade = "";
            }
            table_text_design($upgrade . $admiral[$value], "75", "center", "", "text");
        }
        table_text_close();
    }
    table_end();
}