function SpyArrive($queue, $fleet_obj, $fleet, $origin, $target) { global $UnitParam; $fleetmap = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215); $defmap = array(401, 402, 403, 404, 405, 406, 407, 408, 502, 503); $buildmap = array(1, 2, 3, 4, 12, 14, 15, 21, 22, 23, 24, 31, 33, 34, 41, 42, 43, 44); $resmap = array(106, 108, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 122, 123, 124, 199); $now = $queue['end']; $origin_user = LoadUser($origin['owner_id']); $target_user = LoadUser($target['owner_id']); $origin_ships = $target_ships = $origin_cost = 0; foreach ($fleetmap as $i => $gid) { $origin_ships += $fleet_obj["ship{$gid}"]; $origin_cost += $fleet_obj["ship{$gid}"] * $UnitParam[$gid][0]; $target_ships += $target["f{$gid}"]; } $origin_prem = PremiumStatus($origin_user); $target_prem = PremiumStatus($target_user); $origin_tech = $origin_user['r106']; if ($origin_prem['technocrat']) { $origin_tech += 2; } $target_tech = $target_user['r106']; if ($target_prem['technocrat']) { $target_tech += 2; } loca_add("technames", $origin_user['lang']); /* $diff = abs ( $target_tech - $origin_tech ); if ( $target_tech > $origin_tech ) { $level = $fleet_obj['ship210'] - pow ( $diff, 2 ); $counter_max = min (100, floor((($target_ships / 4) * $origin_ships) * pow ( 2, $diff ))); } else { $level = $fleet_obj['ship210'] + pow ( $diff, 2 ); $counter_max = min (100, floor((($target_ships / 4) * $origin_ships) / pow ( 2, $diff ))); } $counter = mt_rand ( 0, $counter_max ); */ $level = $origin_tech - $target_tech; $level = $level * abs($level) - 1 + $origin_ships; $cost = $origin_cost / 1000 / 400; $c = sqrt(pow(2, $origin_ships - ($level + 1))) * ($cost * sqrt($target_ships) * 5); if ($c > 2) { $c = 2; } $c = rand(0, $c * 100) / 100; if ($c < 0) { $c = 0; } if ($c > 1) { $c = 1; } $counter = $c * 100; $subj = "\n<span class=\"espionagereport\">\n" . "Разведданные с " . $target['name'] . "\n" . "<a onclick=\"showGalaxy(" . $target['g'] . "," . $target['s'] . "," . $target['p'] . ");\" href=\"#\">[" . $target['g'] . ":" . $target['s'] . ":" . $target['p'] . "]</a>\n"; $report = ""; // Шапка $report .= "<table width=400><tr><td class=c colspan=4>Сырьё на " . $target['name'] . " <a href=# onclick=showGalaxy(" . $target['g'] . "," . $target['s'] . "," . $target['p'] . "); >[" . $target['g'] . ":" . $target['s'] . ":" . $target['p'] . "]</a> (Игрок \\'" . $target_user['oname'] . "\\')<br /> на " . date("m-d H:i:s", $now) . "</td></tr>\n"; $report .= "</div></font></TD></TR><tr><td>металла:</td><td>" . nicenum($target['m']) . "</td>\n"; $report .= "<td>кристалла:</td><td>" . nicenum($target['k']) . "</td></tr>\n"; $report .= "<tr><td>дейтерия:</td><td>" . nicenum($target['d']) . "</td>\n"; $report .= "<td>энергии:</td><td>" . nicenum($target['emax']) . "</td></tr>\n"; $report .= "</table>\n"; // Активность $report .= "<table width=400><tr><td class=c colspan=4> </td></tr>\n"; $report .= "<TR><TD colspan=4><div onmouseover=\\'return overlib(\"<font color=white>Активность означает, что сканируемый игрок был активен на своей планете, либо на него был произведён вылет флота другого игрока.</font>\", STICKY, MOUSEOFF, DELAY, 750, CENTER, WIDTH, 100, OFFSETX, -130, OFFSETY, -10);\\' onmouseout=\\'return nd();\\'></TD></TR></table>\n"; // Флот на удержании $result = GetHoldingFleets($target['planet_id']); $holding_fleet = array(); while ($fobj = dbarray($result)) { foreach ($fleetmap as $i => $gid) { $holding_fleet[$gid] += $fobj["ship{$gid}"]; } } // Флот if ($level > 0) { $report .= "<table width=400><tr><td class=c colspan=4>Флоты </td></tr>\n"; $count = 0; foreach ($fleetmap as $i => $gid) { $amount = $target["f{$gid}"] + $holding_fleet[$gid]; if ($count % 2 == 0) { $report .= "</tr>\n"; } if ($amount > 0) { $report .= "<td>" . loca("NAME_{$gid}") . "</td><td>" . nicenum($amount) . "</td>\n"; $count++; } } $report .= "</table>\n"; } // Оборона if ($level > 1) { $report .= "<table width=400><tr><td class=c colspan=4>Оборона </td></tr>\n"; $count = 0; foreach ($defmap as $i => $gid) { $amount = $target["d{$gid}"]; if ($count % 2 == 0) { $report .= "</tr>\n"; } if ($amount > 0) { $report .= "<td>" . loca("NAME_{$gid}") . "</td><td>" . nicenum($amount) . "</td>\n"; $count++; } } $report .= "</table>\n"; } // Постройки if ($level > 3) { $report .= "<table width=400><tr><td class=c colspan=4>Постройки </td></tr>\n"; $count = 0; foreach ($buildmap as $i => $gid) { $amount = $target["b{$gid}"]; if ($count % 2 == 0) { $report .= "</tr>\n"; } if ($amount > 0) { $report .= "<td>" . loca("NAME_{$gid}") . "</td><td>" . nicenum($amount) . "</td>\n"; $count++; } } $report .= "</table>\n"; } // Исследования if ($level > 5) { $report .= "<table width=400><tr><td class=c colspan=4>Исследования </td></tr>\n"; $count = 0; foreach ($resmap as $i => $gid) { $amount = $target_user["r{$gid}"]; if ($count % 2 == 0) { $report .= "</tr>\n"; } if ($amount > 0) { $report .= "<td>" . loca("NAME_{$gid}") . "</td><td>" . nicenum($amount) . "</td>\n"; $count++; } } $report .= "</table>\n"; } $report .= "<center> Шанс на защиту от шпионажа:" . floor($counter) . "%</center>\n"; $report .= "<center><a href=\\'#\\' onclick=\\'showFleetMenu(" . $target['g'] . "," . $target['s'] . "," . $target['p'] . "," . GetPlanetType($target) . ",1);\\'>Атака</a></center>\n"; SendMessage($fleet_obj['owner_id'], "Командование флотом", $subj, $report, 1, $queue['end']); // Отправить сообщение чужому игроку о шпионаже. $text = "\nЧужой флот с планеты " . $origin['name'] . "\n" . "<a onclick=\"showGalaxy(" . $origin['g'] . "," . $origin['s'] . "," . $origin['p'] . ");\" href=\"#\">[" . $origin['g'] . ":" . $origin['s'] . ":" . $origin['p'] . "]</a>\n" . "был обнаружен вблизи от планеты " . $target['name'] . "\n" . "<a onclick=\"showGalaxy(" . $target['g'] . "," . $target['s'] . "," . $target['p'] . ");\" href=\"#\">[" . $target['g'] . ":" . $target['s'] . ":" . $target['p'] . "]</a>\n" . ". Шанс на защиту от шпионажа: {$counter} %\n" . "</td>\n"; SendMessage($target['owner_id'], "Наблюдение", "Шпионаж", $text, 5, $queue['end']); // Обновить активность на чужой планете. UpdatePlanetActivity($fleet_obj['target_planet'], $queue['end']); // Вернуть флот. if (mt_rand(0, 100) < $counter) { StartBattle($fleet_obj['fleet_id'], $fleet_obj['target_planet'], $queue['end']); } else { DispatchFleet($fleet, $origin, $target, 106, $fleet_obj['flight_time'], $fleet_obj['m'], $fleet_obj['k'], $fleet_obj['d'], $fleet_obj['fuel'] / 2, $queue['end']); } }
<form action="index.php?page=allianzdepot&session=<?php echo $session; ?> " method=post> <table width='519'> <td class='c' colspan='2'>Вместимость: <?php echo $deut_avail; ?> /<?php echo $depot_cap; ?> </td> <?php $fmap = array_reverse($fleetmap); $result = GetHoldingFleets($aktplanet['planet_id']); $rows = dbrows($result); $c = 1; while ($rows--) { $fleet_obj = dbarray($result); $queue = GetFleetQueue($fleet_obj['fleet_id']); $user = LoadUser($fleet_obj['owner_id']); $load = $queue['end'] - $now; echo " <tr>\n"; echo " <th>Флот " . $user['oname'] . ":<br>"; $cons = 0; foreach ($fmap as $i => $id) { $amount = $fleet_obj["ship" . $id]; if ($amount > 0) { echo loca("NAME_" . $id) . ":" . $amount . "<br>"; $cons += $amount * FleetCons($id, $user['r115'], $user['r117'], $user['r118']) / 10;
function StartBattle($fleet_id, $planet_id, $when) { global $db_prefix; global $GlobalUni; $fleetmap = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215); $defmap = array(401, 402, 403, 404, 405, 406, 407, 408); $a_result = array(0 => "combatreport_ididattack_iwon", 1 => "combatreport_ididattack_ilost", 2 => "combatreport_ididattack_draw"); $d_result = array(1 => "combatreport_igotattacked_iwon", 0 => "combatreport_igotattacked_ilost", 2 => "combatreport_igotattacked_draw"); global $db_host, $db_user, $db_pass, $db_name, $db_prefix; $a = array(); $d = array(); $unitab = LoadUniverse(); $fid = $unitab['fid']; $did = $unitab['did']; $rf = $unitab['rapid']; $f = LoadFleet($fleet_id); // *** Сгенерировать исходные данные // Список атакующих $anum = 0; if ($f['union_id'] == 0) { $a[0] = LoadUser($f['owner_id']); $a[0]['fleet'] = array(); foreach ($fleetmap as $i => $gid) { $a[0]['fleet'][$gid] = abs($f["ship{$gid}"]); } $start_planet = GetPlanet($f['start_planet']); $a[0]['g'] = $start_planet['g']; $a[0]['s'] = $start_planet['s']; $a[0]['p'] = $start_planet['p']; $a[0]['id'] = $fleet_id; $a[0]['points'] = $a[0]['fpoints'] = 0; $anum++; } else { $result = EnumUnionFleets($f['union_id']); $rows = dbrows($result); while ($rows--) { $fleet_obj = dbarray($result); $a[$anum] = LoadUser($fleet_obj['owner_id']); $a[$anum]['fleet'] = array(); foreach ($fleetmap as $i => $gid) { $a[$anum]['fleet'][$gid] = abs($fleet_obj["ship{$gid}"]); } $start_planet = GetPlanet($fleet_obj['start_planet']); $a[$anum]['g'] = $start_planet['g']; $a[$anum]['s'] = $start_planet['s']; $a[$anum]['p'] = $start_planet['p']; $a[$anum]['id'] = $fleet_obj['fleet_id']; $a[$anum]['points'] = $a[$anum]['fpoints'] = 0; $anum++; } } // Список обороняющихся $dnum = 0; $p = GetPlanet($planet_id); $d[0] = LoadUser($p['owner_id']); $d[0]['fleet'] = array(); $d[0]['defense'] = array(); foreach ($fleetmap as $i => $gid) { $d[0]['fleet'][$gid] = abs($p["f{$gid}"]); } foreach ($defmap as $i => $gid) { $d[0]['defense'][$gid] = abs($p["d{$gid}"]); } $d[0]['g'] = $p['g']; $d[0]['s'] = $p['s']; $d[0]['p'] = $p['p']; $d[0]['id'] = $planet_id; $d[0]['points'] = $d[0]['fpoints'] = 0; $dnum++; // Флоты на удержании $result = GetHoldingFleets($planet_id); $rows = dbrows($result); while ($rows--) { $fleet_obj = dbarray($result); $d[$dnum] = LoadUser($fleet_obj['owner_id']); $d[$dnum]['fleet'] = array(); $d[$dnum]['defense'] = array(); foreach ($fleetmap as $i => $gid) { $d[$dnum]['fleet'][$gid] = abs($fleet_obj["ship{$gid}"]); } foreach ($defmap as $i => $gid) { $d[$dnum]['defense'][$gid] = 0; } $start_planet = GetPlanet($fleet_obj['start_planet']); $d[$dnum]['g'] = $start_planet['g']; $d[$dnum]['s'] = $start_planet['s']; $d[$dnum]['p'] = $start_planet['p']; $d[$dnum]['id'] = $fleet_obj['fleet_id']; $d[$dnum]['points'] = $d[$dnum]['fpoints'] = 0; $dnum++; } $source .= "Rapidfire = {$rf}\n"; $source .= "FID = {$fid}\n"; $source .= "DID = {$did}\n"; $source .= "Attackers = " . $anum . "\n"; $source .= "Defenders = " . $dnum . "\n"; foreach ($a as $num => $attacker) { $source .= "Attacker" . $num . " = (<" . $attacker['oname'] . "> "; $source .= $attacker['id'] . " "; $source .= $attacker['g'] . " " . $attacker['s'] . " " . $attacker['p'] . " "; $source .= $attacker['r109'] . " " . $attacker['r110'] . " " . $attacker['r111'] . " "; foreach ($fleetmap as $i => $gid) { $source .= $attacker['fleet'][$gid] . " "; } $source .= ")\n"; } foreach ($d as $num => $defender) { $source .= "Defender" . $num . " = (<" . $defender['oname'] . "> "; $source .= $defender['id'] . " "; $source .= $defender['g'] . " " . $defender['s'] . " " . $defender['p'] . " "; $source .= $defender['r109'] . " " . $defender['r110'] . " " . $defender['r111'] . " "; foreach ($fleetmap as $i => $gid) { $source .= $defender['fleet'][$gid] . " "; } foreach ($defmap as $i => $gid) { $source .= $defender['defense'][$gid] . " "; } $source .= ")\n"; } $battle = array(null, $source, "", "", $when); $battle_id = AddDBRow($battle, "battledata"); $bf = fopen("battledata/battle_" . $battle_id . ".txt", "w"); fwrite($bf, $source); fclose($bf); // *** Передать данные боевому движку $arg = "\"battle_id={$battle_id}\""; system($unitab['battle_engine'] . " {$arg}"); // *** Обработать выходные данные $battleres = file_get_contents("battleresult/battle_" . $battle_id . ".txt"); $res = unserialize($battleres); // Определить исход битвы. if ($res['result'] === "awon") { $battle_result = 0; } else { if ($res['result'] === "dwon") { $battle_result = 1; } else { $battle_result = 2; } } // Восстановить оборону $repaired = RepairDefense($d, $res, $unitab['defrepair'], $unitab['defrepair_delta']); // Рассчитать общие потери (учитывать дейтерий и восстановленную оборону) $aloss = $dloss = 0; $loss = CalcLosses($a, $d, $res, $repaired); $a = $loss['a']; $d = $loss['d']; $aloss = $loss['aloss']; $dloss = $loss['dloss']; // Захватить ресурсы $cm = $ck = $cd = 0; if ($battle_result == 0) { $sum_cargo = CargoSummaryLastRound($a, $res); $captured = Plunder($sum_cargo, $p['m'], $p['k'], $p['d']); $cm = $captured['cm']; $ck = $captured['ck']; $cd = $captured['cd']; } // Создать поле обломков. $debris_id = CreateDebris($p['g'], $p['s'], $p['p'], $p['owner_id']); AddDebris($debris_id, $res['dm'], $res['dk']); // Создать луну $mooncreated = false; $moonchance = min(floor(($res['dm'] + $res['dk']) / 100000), 20); if (PlanetHasMoon($planet_id) || $p['type'] == 0 || $p['type'] == 10003) { $moonchance = 0; } if (mt_rand(1, 100) <= $moonchance) { CreatePlanet($p['g'], $p['s'], $p['p'], $p['owner_id'], 0, 1, $moonchance); $mooncreated = true; } // Обновить активность на планете. $queue = GetFleetQueue($fleet_id); UpdatePlanetActivity($planet_id, $queue['end']); // Сгенерировать боевой доклад. loca_add("battlereport", $GlobalUni['lang']); loca_add("technames", $GlobalUni['lang']); $text = BattleReport($res, $when, $aloss, $dloss, $cm, $ck, $cd, $moonchance, $mooncreated, $repaired); // Разослать сообщения $mailbox = array(); foreach ($d as $i => $user) { if ($mailbox[$user['player_id']] == true) { continue; } $bericht = SendMessage($user['player_id'], "Командование флотом", "Боевой доклад", $text, 6, $when); MarkMessage($user['player_id'], $bericht); $subj = "<a href=\"#\" onclick=\"fenster(\\'index.php?page=bericht&session={PUBLIC_SESSION}&bericht={$bericht}\\', \\'Bericht_Kampf\\');\" ><span class=\"" . $d_result[$battle_result] . "\">Боевой доклад [" . $p['g'] . ":" . $p['s'] . ":" . $p['p'] . "] (V:" . nicenum($dloss) . ",A:" . nicenum($aloss) . ")</span></a>"; SendMessage($user['player_id'], "Командование флотом", $subj, "", 2, $when); $mailbox[$user['player_id']] = true; } // Обновить лог боевого доклада $subj = "<a href=\"#\" onclick=\"fenster(\\'index.php?page=admin&session={PUBLIC_SESSION}&mode=BattleReport&bericht={$battle_id}\\', \\'Bericht_Kampf\\');\" ><span class=\"" . $a_result[$battle_result] . "\">Боевой доклад [" . $p['g'] . ":" . $p['s'] . ":" . $p['p'] . "] (V:" . nicenum($dloss) . ",A:" . nicenum($aloss) . ")</span></a>"; $query = "UPDATE " . $db_prefix . "battledata SET title = '" . $subj . "', report = '" . $text . "' WHERE battle_id = {$battle_id};"; dbquery($query); // Если флот уничтожен за 1 или 2 раунда - не показывать лог боя для атакующих. if (count($res['rounds']) <= 2 && $battle_result == 1) { $text = "Контакт с флотом потерян. <br> Это означает, что его уничтожили первым же залпом <!--A:{$aloss},W:{$dloss}-->"; } foreach ($a as $i => $user) { if ($mailbox[$user['player_id']] == true) { continue; } $bericht = SendMessage($user['player_id'], "Командование флотом", "Боевой доклад", $text, 6, $when); MarkMessage($user['player_id'], $bericht); $subj = "<a href=\"#\" onclick=\"fenster(\\'index.php?page=bericht&session={PUBLIC_SESSION}&bericht={$bericht}\\', \\'Bericht_Kampf\\');\" ><span class=\"" . $a_result[$battle_result] . "\">Боевой доклад [" . $p['g'] . ":" . $p['s'] . ":" . $p['p'] . "] (V:" . nicenum($dloss) . ",A:" . nicenum($aloss) . ")</span></a>"; SendMessage($user['player_id'], "Командование флотом", $subj, "", 2, $when); $mailbox[$user['player_id']] = true; } // Почистить старые боевые доклады $ago = $when - 2 * 7 * 24 * 60 * 60; $query = "DELETE FROM " . $db_prefix . "battledata WHERE date < {$ago};"; dbquery($query); // Модифицировать флоты и планету в соответствии с потерями и захваченными ресурсами WritebackBattleResults($a, $d, $res, $repaired, $cm, $ck, $cd, $sum_cargo); // Изменить статистику игроков foreach ($a as $i => $user) { AdjustStats($user['player_id'], $user['points'], $user['fpoints'], 0, '-'); } foreach ($d as $i => $user) { AdjustStats($user['player_id'], $user['points'], $user['fpoints'], 0, '-'); } RecalcRanks(); // Чистим промежуточные данные боевого движка unlink("battledata/battle_" . $battle_id . ".txt"); unlink("battleresult/battle_" . $battle_id . ".txt"); return $battle_result; }