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; } }
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; }
function suggest($prod_id, $side) { global $uid; $sth = mysql_query("select if(s.special=b.special,0,b.special) as special,b.initiative-s.initiative as initiative,b.agility-s.agility as agility,b.hull-s.hull as hull,b.weaponpower-s.weaponpower as weaponpower,b.shield-s.shield as shield,b.ecm-s.ecm as ecm,b.sensor-s.sensor as sensor,b.weaponskill-s.weaponskill as weaponskill,b.armor-s.armor as armor,b.num_attacks-s.num_attacks as num_attacks from battle_" . $uid . " b, production p, shipvalues s where b.prod_id=" . $prod_id . " and b.side=" . $side . " and b.prod_id=p.prod_id and b.prod_id=s.prod_id"); if (!$sth) { show_error("ERR::GET VALUES"); return false; } $new_values = mysql_fetch_assoc($sth); $changes = ""; foreach ($new_values as $ident => $change) { if ($change != 0) { $changes .= $ident . " => " . $change . "\n"; } } if ($changes != "") { $sth = mysql_query("select name from production where prod_id=" . $prod_id); if (!$sth || mysql_num_rows($sth) == 0) { return false; } list($name) = mysql_fetch_row($sth); mail("*****@*****.**", "Request for Change von " . get_name_by_uid($uid), "Changes für " . $name . " (" . $prod_id . ")\n\n" . $changes); mail("*****@*****.**", "Request for Change von " . get_name_by_uid($uid), "Changes für " . $name . " (" . $prod_id . ")\n\n" . $changes); mail("*****@*****.**", "Request for Change von " . get_name_by_uid($uid), "Changes für " . $name . " (" . $prod_id . ")\n\n" . $changes); } }
function join_alliance() { global $id; global $uid; if (has_alliance_lock($uid)) { show_message("You can't use any alliance options due to an alliance lock!"); return false; } $sth = mysql_query("select * from invitations where aid={$id} and uid={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } if (mysql_num_rows($sth) == 0) { show_message("HUND!"); return 0; } if (!alliance_not_full($id)) { show_message("Alliance can not hold any more members."); return false; } $sth = mysql_query("select alliance from users where id=" . $uid); if (!$sth) { show_message("ERR::get alliance"); return false; } list($its_alliance) = mysql_fetch_row($sth); if ($its_alliance != 0) { show_message("First you must leave the alliance and recieve an alliance lock."); return false; } $sth = mysql_query("select * from alliance where leader={$uid}"); if (!$sth) { show_error("Database error!"); return 0; } if (mysql_num_rows($sth) > 0) { show_message("You're leader of an alliance! Please resign first!"); return 0; } $sth = mysql_query("select * from alliance where milminister={$uid} or forminister={$uid} or devminister={$uid}"); if (!$sth) { show_error("Database error!"); return 0; } if (mysql_num_rows($sth) > 0) { show_message("You're a minister of an alliance! Please resign first!"); return 0; } $sth = mysql_query("update users set alliance={$id} where id={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } $sth = mysql_query("delete from invitations where uid={$uid} and aid={$id}"); if (!$sth) { show_error("Database failure!"); return 0; } // Nachticht an alle Allianzenmitglieder schicken $allies = get_allied_ids($uid); $username = get_name_by_uid($uid); if (is_array($allies)) { for ($i = 0; $i < sizeof($allies); $i++) { send_ticker_from_to(0, $allies[$i], "w", $username . " has joined your alliance"); } } show_message("You have joined!"); }
/** * 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()]++; } } }
function infantery_info() { global $pid; global $uid; global $skin; $sth = mysql_query("select id from planets where id={$pid} and uid={$uid}"); if (!$sth) { show_error("Database failure!"); return 0; } if (mysql_num_rows($sth) == 0) { show_error("Yeah! You just hit one of my security barriers:)!"); return 0; } table_start("center", "500"); table_head_text(array("Infantry"), "4"); table_text_open("head"); table_text_design(" ", "80", "", "", "head"); table_text_design(" ", "420", "", "3", "head"); table_text_close(); /* $sth=mysql_query("select i.prod_id,i.count,i.uid from infantery as i, production as p where i.pid='".$pid."' and i.prod_id=p.prod_id"); while ($infantery=mysql_fetch_array($sth)) { $total_infantery[$infantery["prod_id"]][$infantery["uid"]] += $infantery["count"]; } */ $sth = mysql_query("select i.prod_id, i.count, i.uid, p.name, p.pic from infantery as i, production as p where i.pid='{$pid}' and i.prod_id=p.prod_id order by i.uid"); while ($inf = mysql_fetch_array($sth)) { $inf_on_planet[$inf["uid"]][$inf["prod_id"]] = $inf["count"]; $inf_info[$inf["prod_id"]]["name"] = $inf["name"]; $inf_info[$inf["prod_id"]]["pic"] = $inf["pic"]; if (!$user_info[$inf["uid"]]) { $user_info[$inf["uid"]]["relation"] = get_uids_relation($uid, $inf["uid"], 1); $user_info[$inf["uid"]]["name"] = get_name_by_uid($inf["uid"]); } $dummy3 = ""; } if (is_array($inf_on_planet)) { foreach ($inf_on_planet as $i_uid => $inf) { foreach ($inf as $prod_id => $count) { table_text_open("text", "center"); table_text_design("<img src='arts/" . $inf_info[$prod_id]["pic"] . "' border='1' alt='" . $infantery["description"] . "' align='center'></a>", "80", "", "", "text"); table_text_design($inf_info[$prod_id]["name"] . " (" . $user_info[$i_uid]["name"] . ")", "320", "", "", "text"); table_text_design($count, "100", "", "", "text"); table_text_close(); } } } if (!isset($dummy3)) { show_message("You have no infantry on this planet"); } table_end(); $sth4 = mysql_query("select * from i_production as ip,production as p where ip.planet_id='" . $pid . "' and p.prod_id=ip.prod_id"); infantery($sth4); }
function send_ticker_from_to($uid, $fuid, $type, $message) { if ($uid) { $name = get_name_by_uid($uid); $sth = mysql_query("insert into ticker (uid,type,text,time) values ('" . $fuid . "','" . $type . "','" . $name . ": " . $message . "','" . date("YmdHis") . "')"); } else { $sth = mysql_query("insert into ticker (uid,type,text,time) values ('" . $fuid . "','" . $type . "','" . $message . "','" . date("YmdHis") . "')"); } if (!$sth) { return 0; } }
function show_invitations() { global $uid; global $PHP_SELF; $invitations = get_user_invitations($uid); if (!$invitations) { echo "<table width=\"280\" class=\"list\">\n"; echo "<center>No invitation requests!</center><br>"; echo "</table>\n"; } else { echo "<table width=\"280\" class=\"list\">\n"; table_text_open(); table_text_design("Invitation requests", "240", "center", "2", "top"); table_text_close(); while (list($user) = mysql_fetch_row($invitations)) { table_text_open(); table_text_design(get_name_by_uid($user), "200", "right", "", "list"); table_text_design("<a href=\"" . $PHP_SELF . "?act=add&fuid={$user}\"><img src=\"arts/bok.jpg\" alt=\"accept\" width=\"15\" height=\"15\" onmouseover=\"this.src='arts/bok2.jpg'\" onmouseout=\"this.src='arts/bok.jpg'\" border=\"0\"></a><a href=\"" . $PHP_SELF . "?act=del_foreign_invite&fuid={$user}\"><img src=\"arts/bdrop.jpg\" alt=\"decline\" width=\"15\" height=\"15\" onmouseover=\"this.src='arts/bdrop2.jpg'\" onmouseout=\"this.src='arts/bdrop.jpg'\" border=\"0\"></a>", "40", "right", "", "list"); table_text_close(); } echo "</table>\n"; } $invitations = get_buddy_invitations($uid); if ($invitations) { echo "<table width=\"280\" class=\"list\">\n"; table_text_open(); table_text_design("pending invitations!", "240", "center", "2", "top"); table_text_close(); while (list($user) = mysql_fetch_row($invitations)) { table_text_open(); table_text_design(get_name_by_uid($user), "200", "right", "", "list"); table_text_design("<a href=\"" . $PHP_SELF . "?act=del_invitation&fuid={$user}\"><img src=\"arts/bdrop.jpg\" alt=\"drop\" width=\"15\" height=\"15\" onmouseover=\"this.src='arts/bdrop2.jpg'\" onmouseout=\"this.src='arts/bdrop.jpg'\" border=\"0\"></a>", "40", "right", "", "list"); table_text_close(); } echo "</table>\n"; echo "<br>"; } }