示例#1
0
/**
* This file manages the output from the battle, it formats the cr, it makes the debris field, and then sends the fleets home.
* Here is the expected imput
	$results = array(
		[debrcry] => num
		[debrmet] => num
		[attlost] => num
		[deflost] => num
		[won]	 => char //(d)raw, (a)ttacker ,(v)defender
		[data] => array(
			[$roundno] => array(
				[attfires] => num
				[attpower] => num
				[attblock] => num
				[deffires] => num
				[defpower] => num
				[defblock] => num
				[attack_fleets] => array(
					[$fleetid] => array(
	either:				[$shiptype] => array('count' => num)
	or:					[$shiptype] => num
					)
				)
				[defend_fleets] => array(
					[$fleetid] => array(
	either:				[$shiptype] => array('count' => num)
	or:					[$shiptype] => num
					)
				)
			)
		)
	)
*/
function ManageCR($results, $CurrentPlanet)
{
    global $resource, $lang, $CombatCaps, $pricelist, $reslist;
    //The usual...
    $parse = $lang;
    //This will be poulated with planet and user data later.
    $fleets = array();
    $permafleets = array();
    //Loop through the rounds:
    $parse['rounds'] = '';
    foreach ($results['data'] as $roundno => $round) {
        $rparse = array();
        //List attackers and defenders fleets.
        $rparse['attackers'] = '';
        foreach ($round['attack_fleets'] as $id => $attacker) {
            //Lets get some info about this guy
            if ($roundno == 0) {
                $fleets[$id] = array();
                $fleets[$id]['side'] = 'a';
                if ($id > 0) {
                    $fleets[$id]['user'] = doquery("SELECT * FROM {{table}} WHERE `id` = (SELECT `owner_userid` FROM {{prefix}}fleets WHERE `fleet_id` = '" . idstring($id) . "') LIMIT 1 ;", 'users', true);
                } else {
                    $fleets[$id]['user'] = doquery("SELECT * FROM {{table}} WHERE `{{table}}`.`id` = '" . idstring($CurrentPlanet['id_owner']) . "' LIMIT 1 ;", 'users', true);
                }
            }
            $aparse = $lang;
            $aparse['td_types'] = '';
            $aparse['td_count'] = '';
            $aparse['td_weapons'] = '';
            $aparse['td_shields'] = '';
            $aparse['td_armour'] = '';
            $aparse['weap_pc'] = $fleets[$id]['user'][$resource[109]] * 10;
            $aparse['shield_pc'] = $fleets[$id]['user'][$resource[111]] * 10;
            $aparse['hull_pc'] = $fleets[$id]['user'][$resource[110]] * 10;
            $aparse['mode'] = 'attacker';
            $aparse['name'] = $lang['Attacker'] . " " . $fleets[$id]['user']['username'] . " <a>[" . $fleets[$id]['user']['galaxy'] . ":" . $fleets[$id]['user']['system'] . ":" . $fleets[$id]['user']['planet'] . "]</a>";
            foreach ($attacker as $id => $count) {
                if (is_array($count)) {
                    $count = $count['count'];
                }
                $aparse['td_types'] .= "\t\t\t\t\t\t\t\t\t\t<th class=\"textGrow\">" . $lang['cr_names'][$id] . "</th>\n";
                $aparse['td_count'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($count) . "</td>\n";
                $aparse['td_weapons'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($CombatCaps[$id]['attack']) . "</td>\n";
                $aparse['td_shields'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($CombatCaps[$id]['shield']) . "</td>\n";
                $aparse['td_armour'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($pricelist[$id]['metal'] + $pricelist[$id]['crystal']) . "</td>\n";
            }
            $rparse['attackers'] .= parsetemplate(gettemplate('fleet/combatattacker'), $aparse);
        }
        $rparse['defenders'] = '';
        foreach ($round['defend_fleets'] as $id => $defender) {
            //Lets get some info about this guy
            if ($roundno == 0) {
                $fleets[$id] = array();
                $fleets[$id]['side'] = 'd';
                if ($id > 0) {
                    $fleets[$id]['user'] = doquery("SELECT * FROM {{table}} WHERE `id` = (SELECT `owner_userid` FROM {{prefix}}fleets WHERE `fleet_id` = '" . idstring($id) . "') LIMIT 1 ;", 'users', true);
                } else {
                    $fleets[$id]['user'] = doquery("SELECT * FROM {{table}} WHERE `{{table}}`.`id` = '" . idstring($CurrentPlanet['id_owner']) . "' LIMIT 1 ;", 'users', true);
                }
            }
            $aparse = $lang;
            $aparse['td_types'] = '';
            $aparse['td_count'] = '';
            $aparse['td_weapons'] = '';
            $aparse['td_shields'] = '';
            $aparse['td_armour'] = '';
            $aparse['weap_pc'] = $fleets[$id]['user'][$resource[109]] * 10;
            $aparse['shield_pc'] = $fleets[$id]['user'][$resource[111]] * 10;
            $aparse['hull_pc'] = $fleets[$id]['user'][$resource[110]] * 10;
            $aparse['mode'] = 'defender';
            $aparse['name'] = $lang['Defender'] . " " . $fleets[$id]['user']['username'] . " <a>[" . $fleets[$id]['user']['galaxy'] . ":" . $fleets[$id]['user']['system'] . ":" . $fleets[$id]['user']['planet'] . "]</a>";
            foreach ($defender as $id => $count) {
                if (is_array($count)) {
                    $count = $count['count'];
                }
                $aparse['td_types'] .= "\t\t\t\t\t\t\t\t\t\t<th class=\"textGrow\">" . $lang['cr_names'][$id] . "</th>\n";
                $aparse['td_count'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($count) . "</td>\n";
                $aparse['td_weapons'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($CombatCaps[$id]['attack']) . "</td>\n";
                $aparse['td_shields'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($CombatCaps[$id]['shield']) . "</td>\n";
                $aparse['td_armour'] .= "\t\t\t\t\t\t\t\t\t\t<td>" . pretty_number($pricelist[$id]['metal'] + $pricelist[$id]['crystal']) . "</td>\n";
            }
            $rparse['defenders'] .= parsetemplate(gettemplate('fleet/combatattacker'), $aparse);
        }
        //We need to keep a note on who is in the battle, as well as showing any destroyed fleets.
        $peeps = array(array(), array());
        foreach ($fleets as $id => $array) {
            //We need a list of members for the title
            if ($roundno == 0) {
                if ($array['side'] == 'a') {
                    $peeps[0][] = $array['user']['username'];
                } else {
                    $peeps[1][] = $array['user']['username'];
                }
                $permafleets = $fleets;
            }
            //Look for fleets which are no more and list them as destroyed.
            if (!(in_array($id, array_keys($round['defend_fleets'])) || in_array($id, array_keys($round['attack_fleets'])))) {
                if ($array['side'] == 'a') {
                    $rparse['attackers'] .= '
		<td class="round_attacker textCenter"> 
			<table cellpadding="0" cellspacing="0"> 
				<tr>
					<td class="newBack"> 
						<center> 
							<span class="destroyed textBeefy">' . $lang['Attacker'] . ' ' . $array['user']['username'] . ' ' . $lang['destroyed'] . '.</span> 
						</center> 
					</td> 
				</tr> 
			</table> 
		</td>';
                } else {
                    $rparse['defenders'] .= '
		<td class="round_defender textCenter"> 
			<table cellpadding="0" cellspacing="0"> 
				<tr>
					<td class="newBack"> 
						<center> 
							<span class="destroyed textBeefy">' . $lang['Defender'] . ' ' . $array['user']['username'] . ' ' . $lang['destroyed'] . '.</span> 
						</center> 
					</td> 
				</tr> 
			</table> 
		</td>';
                }
                //If its been destroyed, we only want to show the destroyed message once, so remove the destroyed fleets.
                unset($fleets[$id]);
            }
        }
        //The round info, if its rounf one then we introduce the battle, otherwise its shots fired.
        if ($roundno == 0) {
            $rparse['roundinfo'] = "\t\t<p class=\"start\">" . sprintf($lang['report_start'], date("j.n.Y H:i:s")) . "</p>\n\t\t<p class=\"start opponents\">" . implode(', ', $peeps[0]) . ' ' . $lang['report_vs'] . ' ' . implode(', ', $peeps[1]) . "</p>\n";
        } else {
            $rparse['roundinfo'] = sprintf($lang['report_rinfo'], pretty_number($round['attfires']), pretty_number($round['attpower']), pretty_number($round['defblock']), pretty_number($round['deffires']), pretty_number($round['defpower']), pretty_number($round['attblock']));
        }
        $parse['rounds'] .= parsetemplate(gettemplate('fleet/combatround'), $rparse);
    }
    //Phew, lets deal with all the fleets:
    $end = $results['data'][sizeof($results['data']) - 1];
    $owners = array();
    foreach ($permafleets as $id => $array) {
        if ($id == 0) {
            //This is the planet...
            $set = array();
            foreach (array_merge($reslist['dbattle'], $reslist['fleet']) as $e) {
                $count = $end['defend_fleets'][0][$e];
                if (is_array($count)) {
                    $count = $count['count'];
                }
                if ($count > 0) {
                    $set[] = '`' . $resource[$e] . '` = \'' . idstring($count) . '\'';
                } else {
                    $set[] = '`' . $resource[$e] . '` = 0';
                }
            }
            doquery("UPDATE {{table}} SET " . implode(', ', $set) . " WHERE `id` = '" . $CurrentPlanet['id'] . "' LIMIT 1 ;", 'planets', true);
            //Note the user
            $owners[] = idstring($CurrentPlanet['id_owner']);
        } else {
            if ($array['side'] == 'a') {
                $mode = 'attack';
            } else {
                $mode = 'defend';
            }
            $fleetarray = array();
            $fleetcount = 0;
            foreach ($end[$mode . '_fleets'][$id] as $ship => $count) {
                if (is_array($count)) {
                    $count = $count['count'];
                }
                $fleetarray[] = idstring($ship) . ',' . idstring($count);
                $fleetcount += idstring($count);
            }
            $fleetarray = implode(';', $fleetarray);
            $fleetrow = doquery("SELECT * FROM {{table}} WHERE `fleet_id` = '" . idstring($id) . "' ;", 'fleets', true);
            $permafleets[$id]['row'] = $fleetrow;
            doquery("UPDATE {{table}} SET `array` = '" . $fleetarray . "', `shipcount` = '" . $fleetcount . "' WHERE `partner_fleet` = '" . idstring($id) . "' LIMIT 1 ;", 'fleets', false);
            DeleteFleet($id);
            $owners[] = idstring($fleetrow['owner_userid']);
        }
    }
    //Who won?
    if ($results['won'] == 'a') {
        //Need to deal with raiding.
        $stealmax = array($CurrentPlanet['metal'] * MAX_ATTACK_RAID, $CurrentPlanet['crystal'] * MAX_ATTACK_RAID, $CurrentPlanet['deuterium'] * MAX_ATTACK_RAID);
        //How much cargo space do we have?
        $cargo = array('total' => 0);
        foreach ($end['attack_fleets'] as $id => $attacker) {
            $cargo[$id] = 0;
            foreach ($attacker as $ship => $count) {
                if (is_array($count)) {
                    $count = $count['count'];
                }
                $space = $pricelist[$ship]['capacity'] * $count;
                $space -= $permafleets[$id]['row']['metal'];
                $space -= $permafleets[$id]['row']['crystal'];
                $space -= $permafleets[$id]['row']['deuterium'];
                if ($space > 0) {
                    $cargo[$id] += $space;
                    $cargo['total'] += $pricelist[$ship]['capacity'] * $count;
                }
            }
        }
        //So how much can we take?
        $totaltake = $stealmax[0] + $stealmax[1] + $stealmax[2];
        //Is there enough res to go around?
        if ($totaltake > $cargo['total']) {
            //We can fill all the cargo holds in the ratios:
            $ratio_m = $stealmax[0] / $totaltake;
            $ratio_c = $stealmax[1] / $totaltake;
            $ratio_d = $stealmax[2] / $totaltake;
        } else {
            //We can take the following ratios of resources: (nb its a bit late, so I haven't worked out why the below works but basically the $totaltake cancels so I just removed it)
            $ratio_m = $stealmax[0] / $cargo;
            $ratio_c = $stealmax[1] / $cargo;
            $ratio_d = $stealmax[2] / $cargo;
        }
        //Right lets start filling up the fleets:
        $stolen = array(0, 0, 0);
        foreach ($cargo as $id => $space) {
            if ($id != 'total') {
                $take_m = floor($ratio_m * $space);
                $take_c = floor($ratio_c * $space);
                $take_d = floor($ratio_d * $space);
                $stolen[0] += $take_m;
                $stolen[1] += $take_c;
                $stolen[2] += $take_d;
                doquery("UPDATE {{table}} SET `metal` = `metal` + '" . $take_m . "', `crystal` = `crystal` + '" . $take_c . "', `deuterium` = `deuterium` + '" . $take_d . "' WHERE `partner_fleet` = '" . idstring($id) . "' LIMIT 1 ;", 'fleets', false);
            }
        }
        $parse['result'] = sprintf($lang['A_won'], pretty_number($stolen[0]), $lang['Metal'], pretty_number($stolen[1]), $lang['Crystal'], pretty_number($stolen[2]), $lang['Deuterium']);
    } elseif ($results['won'] == 'v') {
        $parse['result'] = $lang['D_won'];
    } else {
        $results['won'] = 'd';
        $parse['result'] = $lang['Draw'];
    }
    //Results, attlost, defost debris ect.
    $parse['alost'] = sprintf($lang['AttLost'], pretty_number($results['attlost']));
    $parse['dlost'] = sprintf($lang['DefLost'], pretty_number($results['deflost']));
    $parse['debris'] = sprintf($lang['DebrisF'], pretty_number($results['debrmet']), $lang['Metal'], pretty_number($results['debrcry']), $lang['Crystal']);
    //Now the exiting bit!!! Moons stuff
    $debris_pc = floor(($results['debrmet'] + $results['debrcry']) / DEBRIS_PER_PERCENT);
    if ($debris_pc > MIN_MOON_PERCENT) {
        if ($debris_pc > MAX_MOON_PERCENT) {
            $debris_pc = MAX_MOON_PERCENT;
        }
        $parse['moon'] = sprintf($lang['MoonChance'], $debris_pc . '%');
        //So does he get a moon?
        $need = rand(0, 100);
        if ($debris_pc > $nees) {
            //Got a moon
            $pl_name = $CurrentPlanet['name'] . ' [' . $CurrentPlanet['galaxy'] . ':' . $CurrentPlanet['system'] . ':' . $CurrentPlanet['planet'] . ']';
            $parse['moon_got'] = sprintf($lang['GotMoon'], $pl_name);
            AddMoon($CurrentPlanet['galaxy'], $CurrentPlanet['system'], $CurrentPlanet['planet']);
        }
    }
    //Now we need to generate the report:
    $report = parsetemplate(gettemplate('fleet/combatreport'), $parse);
    //Add the report to the database
    doquery("INSERT INTO {{table}} (`report`, `owners`, `wonby`, `damage`, `time`) VALUES ('" . mysql_real_escape_string($report) . "', '" . implode(",", $owners) . "', '" . $results['won'] . "', '" . ($results['attlost'] + $results['deflost']) . "', '" . time() . "');", 'cr', false);
    //Now we need to message the user...
    $message = "<a href=\"./?page=report&raport=" . $rid . "\" target=\"_new\"><center>";
    $message2 = "<a href=\"./?page=report&raport=" . $rid . "\" target=\"_new\"><center>";
    if ($results['won'] == 'a') {
        $message .= "<font color=\"green\">";
        $message2 .= "<font color=\"red\">";
    } elseif ($results['won'] == 'v') {
        $message .= "<font color=\"red\">";
        $message2 .= "<font color=\"green\">";
    } else {
        $message .= "<font color=\"orange\">";
        $message2 .= "<font color=\"orange\">";
    }
    $message .= $lang['fleet_1_tit'] . " [" . $CurrentPlanet['galaxy'] . ":" . $CurrentPlanet['system'] . ":" . $CurrentPlanet['planet'] . "] </font></a>";
    $message2 .= $lang['fleet_1_tit'] . " [" . $CurrentPlanet['galaxy'] . ":" . $CurrentPlanet['system'] . ":" . $CurrentPlanet['planet'] . "] </font></a>";
    PM($FleetRow['owner_userid'], 0, $message, $lang['fleet_1_tit'], $lang['fleet_control'], 2);
    PM($FleetRow['target_userid'], 0, $message2, $lang['fleet_1_tit'], $lang['fleet_control'], 2);
}
示例#2
0
function Queue_Fleet_End($queue)
{
    global $GlobalUser;
    $fleetmap = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215);
    $fleet_obj = LoadFleet($queue['sub_id']);
    if ($fleet_obj['m'] < 0) {
        $fleet_obj['m'] = 0;
    }
    if ($fleet_obj['k'] < 0) {
        $fleet_obj['k'] = 0;
    }
    if ($fleet_obj['d'] < 0) {
        $fleet_obj['d'] = 0;
    }
    if ($fleet_obj == null) {
        return;
    }
    $fleet = array();
    foreach ($fleetmap as $i => $gid) {
        $fleet[$gid] = $fleet_obj["ship{$gid}"];
    }
    // Обновить выработку ресурсов на планетах
    $origin = GetPlanet($fleet_obj['start_planet']);
    $target = GetPlanet($fleet_obj['target_planet']);
    $target = ProdResources($target, $target['lastpeek'], $queue['end']);
    $origin = ProdResources($origin, $origin['lastpeek'], $queue['end']);
    switch ($fleet_obj['mission']) {
        case 1:
            AttackArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 101:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 2:
            AttackArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 102:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 3:
            TransportArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 103:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 4:
            DeployArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 104:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 5:
            HoldingArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 205:
            HoldingHold($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 105:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 6:
            SpyArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 106:
            SpyReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 7:
            ColonizationArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 107:
            ColonizationReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 8:
            RecycleArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 108:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 9:
            DestroyArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 109:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 15:
            ExpeditionArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 215:
            ExpeditionHold($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 115:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 20:
            RocketAttackArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 21:
            AttackArrive($queue, $fleet_obj, $fleet, $origin, $target);
            break;
        case 121:
            CommonReturn($queue, $fleet_obj, $fleet, $origin, $target);
            break;
            //default: Error ( "Неизвестное задание для флота: " . $fleet_obj['mission'] ); break;
    }
    if ($fleet_obj['union_id'] && $fleet_obj['mission'] < 100) {
        $union_id = $fleet_obj['union_id'];
        $result = EnumUnionFleets($union_id);
        $rows = dbrows($result);
        while ($rows--) {
            $fleet_obj = dbarray($result);
            $queue = GetFleetQueue($fleet_obj['fleet_id']);
            DeleteFleet($fleet_obj['fleet_id']);
            // удалить флот
            RemoveQueue($queue['task_id']);
            // удалить задание
        }
        RemoveUnion($union_id);
        // удалить союз
    } else {
        DeleteFleet($fleet_obj['fleet_id']);
        // удалить флот
        RemoveQueue($queue['task_id']);
        // удалить задание
    }
    $player_id = $fleet_obj['owner_id'];
    if ($GlobalUser['player_id'] == $player_id) {
        InvalidateUserCache();
        $GlobalUser = LoadUser($player_id);
        // обновить данные текущего пользователя
    }
}
示例#3
0
function ManageFleets($limit = 5)
{
    global $lang;
    getLang('fleet_management');
    //Lock the tables
    $tables = array('aks', 'cr', 'errors', 'messages', 'fleets', 'planets', 'users');
    foreach ($tables as $k => $v) {
        $tables[$k] = "``{{prefix}}" . $v . "`` WRITE";
    }
    doquery("LOCK TABLE " . implode(", ", $tables), "");
    //Get the fleets - ordered by their returning time
    $fleets = doquery("SELECT * FROM {{table}} WHERE (`arrival` + `hold_time`) < " . time() . " ORDER BY (`arrival` + `hold_time`) ASC LIMIT " . idstring($limit) . " ;", 'fleets');
    //If there are any fleets.
    if (mysql_num_rows($fleets) > 0) {
        include_once ROOT_PATH . 'includes/functions/MissionCaseStay.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseStayAlly.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseSpy.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseRecycling.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseDestroy.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseExpedition.php';
        include_once ROOT_PATH . 'includes/functions/MissionCaseColonisation.php';
        //Now loop through the fleets.
        while ($row = mysql_fetch_array($fleets)) {
            //Update the users menus if he is online:
            doquery("UPDATE {{table}} SET `menus_update` = '" . time() . "' WHERE `id` = '" . $row['owner_userid'] . "' LIMIT 1 ;", 'users', false);
            doquery("UPDATE {{table}} SET `menus_update` = '" . time() . "' WHERE `id` = '" . $row['target_userid'] . "' LIMIT 1 ;", 'users', false);
            //Now deal with the fleet
            if ($row["mission"] == 0 || $row["mission"] == 4) {
                //Fleet is returning home, just restore the fleet to the planet and delete it.
                DeleteFleet($row['fleet_id']);
                RestoreFleet($row);
                $StartPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['owner_id'] . "' LIMIT 1 ;", 'planets', true);
                $TargetPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                //Send the user a message
                $Message = sprintf($lang['fleet_return_m'], $StartPlanet['name'], "[" . $StartPlanet['galaxy'] . ":" . $StartPlanet['system'] . ":" . $StartPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                PM($row['target_userid'], 0, $Message, $lang['fleet_return'], $lang['fleet_control'], 2);
            } else {
                switch ($row["mission"]) {
                    case 1:
                        if ($row["fleet_mess"] == 0) {
                            // Attack
                            doquery("UPDATE {{table}} SET `fleet_mess` = '3' WHERE `fleet_id` = '" . $row["fleet_id"] . "' LIMIT 1 ;", 'fleets', false);
                            require_once ROOT_PATH . 'includes/battle_engines/MissionCaseAttack_' . BATTLE_ENGINE . '.php';
                            include_once ROOT_PATH . 'includes/battle_engines/ManageCR.php';
                            $results = MissionCaseAttack($row);
                            $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                            ManageCR($results, $CurrentPlanet);
                        }
                        break;
                    case 2:
                        // ACS Attack
                        // Wait, this fleet will be dealt with when the attack fleet arrives.
                        // Note that the return fleet won't exist until after the attack.
                        break;
                    case 3:
                        // Transport
                        DeleteFleet($row['fleet_id']);
                        //Send the res
                        RestoreRes($row);
                        //Now send messages to the players
                        $StartPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['owner_id'] . "' LIMIT 1 ;", 'planets', true);
                        $TargetPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                        $Message = sprintf($lang['fleet_3_yours'], $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                        PM($StartPlanet['id_owner'], 0, $Message, $lang['sys_mess_transport'], $lang['fleet_control'], 2);
                        if ($TargetPlanet['id_owner'] != $StartPlanet['id_owner']) {
                            $Message = sprintf($lang['fleet_3_allied'], $StartPlanet['name'], "[" . $StartPlanet['galaxy'] . ":" . $StartPlanet['system'] . ":" . $StartPlanet['planet'] . "]", $TargetPlanet['name'], "[" . $TargetPlanet['galaxy'] . ":" . $TargetPlanet['system'] . ":" . $TargetPlanet['planet'] . "]", pretty_number($row['metal']), $lang['Metal'], pretty_number($row['crystal']), $lang['Crystal'], pretty_number($row['deuterium']), $lang['Deuterium']);
                            PM($TargetPlanet['id_owner'], 0, $Message, $lang['sys_mess_transport'], $lang['fleet_control'], 2);
                        }
                        break;
                    case 4:
                        // Deploy (note that this is imposible so is really only here to avoid confusion)
                        DeleteFleet($row['fleet_id']);
                        break;
                    case 5:
                        // ACS Defend
                        // Wait, this fleet will be dealt with when the attack fleet arrives.
                        // Note that the return fleet won't exist until after the attack.
                        //DeleteFleet($row['fleet_id']);
                        break;
                    case 6:
                        // Espionage
                        DeleteFleet($row['fleet_id']);
                        MissionCaseSpy($row);
                        break;
                    case 7:
                        // Colonise
                        DeleteFleet($row['fleet_id']);
                        MissionCaseColonisation($row);
                        break;
                    case 8:
                        // Recycle
                        DeleteFleet($row['fleet_id']);
                        MissionCaseRecycling($row);
                        break;
                    case 9:
                        // Moon Destroy
                        $CurrentPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
                        if ($row["fleet_mess"] == 0 && $CurrentPlanet['planet_type'] == 3) {
                            // Attack
                            doquery("UPDATE {{table}} SET `fleet_mess` = '3' WHERE `fleet_id` = '" . $row["fleet_id"] . "' LIMIT 1 ;", 'fleets', false);
                            require_once ROOT_PATH . 'includes/battle_engines/MissionCaseAttack_' . BATTLE_ENGINE . '.php';
                            include_once ROOT_PATH . 'includes/battle_engines/ManageCR.php';
                            $results = MissionCaseAttack($row);
                            ManageCR($results, $CurrentPlanet);
                            //And then destroy, if the fleet survived
                            if ($results['won'] == 'a') {
                                $nowfleet = doquery("SELECT * FROM {{table}} WHERE `partner_fleet` = '" . $row['fleet_id'] . "' LIMIT 1 ;", 'fleets', true);
                                MissionCaseDestruction($nowfleet, $CurrentPlanet);
                            }
                        }
                        DeleteFleet($row['fleet_id']);
                        break;
                    case 10:
                        // Missiles !!
                        DeleteFleet($row['fleet_id']);
                        MissileAttack($row);
                        break;
                    case 15:
                        // Expedition
                        DeleteFleet($row['fleet_id']);
                        MissionCaseExpedition($row);
                        break;
                    default:
                        DeleteFleet($row['fleet_id']);
                }
            }
        }
    }
    //Unlock tables
    doquery("UNLOCK TABLES", "");
}
示例#4
0
/**
 * MissionCaseDestroy.php
 *
 * @version 1.0
 * @copyright 2009 By MadnessRed for XNova Redesigned
 */
function MissionCaseDestroy($FleetRow, $CurrentPlanet)
{
    global $resource, $lang, $CombatCaps, $pricelist;
    //Get the fleet
    $fleet = array();
    foreach (explode(';', $FleetRow['array']) as $r) {
        $r = explode(',', $r);
        $fleet[$r[0]] = $r[1];
    }
    //Check we still have Deathstarts
    if ($fleet[214] > 0) {
        $destroyed = array(false, false);
        //Firstly is the moon destroyed:
        $chance_m = (100 - pow($moonsize, 0.5)) * pow($fleet[214], 0.5);
        if ($chance_m > mt_rand(0, 100)) {
            //Any fleet going to the moon should be recalled
            $tomoon = doquery("SELECT `fleet_id` FROM {{table}} WHERE `target_id` = '" . $CurrentPlanet['id'] . "' AND `fleet_mess` = '0' ;", 'fleets', false);
            while ($row = FetchArray($tomoon)) {
                $fleetrow = doquery("SELECT *, COUNT('fleet_id') AS `count` FROM {{table}} WHERE `fleet_id` = '" . idstring($row['fleet_id']) . "' AND `fleet_mess` = '0' AND `mission` <> '0' ;", 'fleets', true);
                //Check we found the fleet:
                if ($fleetrow['count'] == 1) {
                    //Incase script takes over a second, lets keep now constant.
                    $now = time();
                    //Duration in flight
                    $duration = $now - $fleetrow['departure'];
                    //ok, lets update the fleet
                    doquery("UPDATE {{table}} SET `departure` = '" . $now . "', `arrival` = '" . ($now + $duration) . "', `target_id` = '" . $fleetrow['owner_id'] . "', `target_userid` = '" . $fleetrow['owner_userid'] . "', `owner_id` = '" . $fleetrow['target_id'] . "', `owner_userid` = '" . $fleetrow['target_userid'] . "', `fleet_mess` = '1', `mission` = '0' WHERE `fleet_id` = '" . $fleetrow['fleet_id'] . "' ;", 'fleets', false);
                    //Remove any partner fleets
                    doquery("DELETE FROM {{table}} WHERE `partner_fleet` = '" . $fleetrow['fleet_id'] . "' ;", 'fleets', false);
                    //Update menus
                    doquery("UPDATE {{table}} SET `menus_update` = '" . time() . "' WHERE `id` = '" . $fleetrow['owner_userid'] . "' LIMIT 1 ;", 'users', false);
                }
            }
            //And fleets returning to the moon should go the planet
            $planet = doquery("SELECT `id` FROM {{table}} WHERE `galaxy` = '" . $CurrentPlanet['galaxy'] . "' AND `system` = '" . $CurrentPlanet['system'] . "' AND `planet` = '" . $CurrentPlanet['planet'] . "' AND `planet_type` = '1' LIMIT 1 ;", 'planets', true);
            doquery("UPDATE {{table}} SET `target_id` = '" . $planet['id'] . "' WHERE `target_id` = '" . $CurrentPlanet['id'] . "' ;", 'fleets', false);
            doquery("UPDATE {{table}} SET `owner_id` = '" . $planet['id'] . "' WHERE `owner_id` = '" . $CurrentPlanet['id'] . "' ;", 'fleets', false);
            //Delete the moon
            doquery("DELETE FROM {{table}} WHERE `id` = '" . $CurrentPlanet['id'] . "' LIMIT 1 ;", 'planets', false);
            //Mark it as destroyed for the message
            $destroyed[0] = true;
        }
        //Secondly are the Deathstars destroyed.
        $chance_k = 0.5 * pow($moonsize, 0.5);
        if ($chance_k > mt_rand(0, 100)) {
            //Are there any other ships in the fleet?
            if (array_sum($fleet) > $fleet[214]) {
                //Remove rips from the fleet
                unset($fleet[214]);
                //Compile fleet array
                $array = array();
                foreach ($fleet as $id => $c) {
                    $array[] = $id . "," . $c;
                }
                $array = implode(";", $array);
                //Update row
                doquery("UPDATE {{table}} SET `array` = '" . $array . "', `count` = `count` - '" . array_sum($fleet) . "' WHERE `fleet_id` = '" . $FleetRow['fleet_id'] . "' LIMIT 1 ;", 'fleets', false);
            } else {
                //Just remove the fleet
                DeleteFleet($FleetRow['fleet_id']);
            }
            //Mark it as destroyed for the message
            $destroyed[1] = true;
        }
        //Start the message
        $HomePlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '" . $row['target_id'] . "' LIMIT 1 ;", 'planets', true);
        $message = '';
        $message .= sprintf($lang['fleet_9_mess1'], $HomePlanet['name'] . " [" . $HomePlanet['galaxy'] . ":" . $HomePlanet['system'] . ":" . $HomePlanet['planet'] . "]", "[" . $CurrentPlanet['galaxy'] . ":" . $CurrentPlanet['system'] . ":" . $CurrentPlanet['planet'] . "]");
        $message .= sprintf($lang['fleet_9_moon'], $chance_m . '%') . "<br />";
        $message .= sprintf($lang['fleet_9_rips'], $chance_k . '%') . "<br />";
        $message .= $lang['fleet_9_mess2'];
        //So what happen (for the message?)
        if ($destroyed[0] && $destroyed[1]) {
            //Both moon and RIPs destroyed
            $message .= $lang['fleet_9_messD'];
            $message .= $lang['fleet_9_messK'];
        } elseif ($destroyed[0]) {
            //Moon Destroyed
            $message .= $lang['fleet_9_messD'];
        } elseif ($destroyed[1]) {
            //RIPs destroyed
            $message .= $lang['fleet_9_messK'];
        } else {
            //Nothing destroyed
            $message .= $lang['fleet_9_messN'];
        }
        PM($FleetRow['owner_userid'], 0, $message, sprintf($lang['fleet_9_tit'], $CurrentPlanet['name']), $lang['fleet_control'], 2);
        PM($FleetRow['target_userid'], 0, $message, sprintf($lang['fleet_9_tit'], $CurrentPlanet['name']), $lang['fleet_control'], 2);
    }
}
示例#5
0
function WritebackBattleResults($a, $d, $res, $repaired, $cm, $ck, $cd, $sum_cargo)
{
    $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);
    global $db_prefix;
    // Бой с раундами.
    $rounds = count($res['rounds']);
    if ($rounds > 0) {
        $last = $res['rounds'][$rounds - 1];
        foreach ($last['attackers'] as $i => $attacker) {
            $fleet_obj = LoadFleet($attacker['id']);
            $queue = GetFleetQueue($fleet_obj['fleet_id']);
            $origin = GetPlanet($fleet_obj['start_planet']);
            $target = GetPlanet($fleet_obj['target_planet']);
            $ships = 0;
            foreach ($fleetmap as $ii => $gid) {
                $ships += $attacker[$gid];
            }
            if ($sum_cargo == 0) {
                $cargo = 0;
            } else {
                $cargo = (FleetCargoSummary($attacker) - ($fleet_obj['m'] + $fleet_obj['k'] + $fleet_obj['d']) - $fleet_obj['fuel']) / $sum_cargo;
            }
            if ($ships > 0) {
                if ($fleet_obj['mission'] == 9 && $res['result'] === "awon") {
                    $result = GravitonAttack($fleet_obj, $attacker, $queue['end']);
                } else {
                    $result = 0;
                }
                if ($result < 2) {
                    DispatchFleet($attacker, $origin, $target, $fleet_obj['mission'] + 100, $fleet_obj['flight_time'], $fleet_obj['m'] + $cm * $cargo, $fleet_obj['k'] + $ck * $cargo, $fleet_obj['d'] + $cd * $cargo, $fleet_obj['fuel'] / 2, $queue['end']);
                }
            }
        }
        foreach ($last['defenders'] as $i => $defender) {
            if ($i == 0) {
                AdjustResources($cm, $ck, $cd, $defender['id'], '-');
                $objects = array();
                foreach ($fleetmap as $ii => $gid) {
                    $objects["f{$gid}"] = $defender[$gid] ? $defender[$gid] : 0;
                }
                foreach ($defmap as $ii => $gid) {
                    $objects["d{$gid}"] = $repaired[$gid] ? $repaired[$gid] : 0;
                    $objects["d{$gid}"] += $defender[$gid];
                }
                SetPlanetFleetDefense($defender['id'], $objects);
            } else {
                $ships = 0;
                foreach ($fleetmap as $ii => $gid) {
                    $ships += $defender[$gid];
                }
                if ($ships > 0) {
                    SetFleet($defender['id'], $defender);
                } else {
                    $queue = GetFleetQueue($defender['id']);
                    DeleteFleet($defender['id']);
                    // удалить флот
                    RemoveQueue($queue['task_id']);
                    // удалить задание
                }
            }
        }
    } else {
        foreach ($a as $i => $attacker) {
            $fleet_obj = LoadFleet($attacker['id']);
            $queue = GetFleetQueue($fleet_obj['fleet_id']);
            $origin = GetPlanet($fleet_obj['start_planet']);
            $target = GetPlanet($fleet_obj['target_planet']);
            $ships = 0;
            foreach ($fleetmap as $ii => $gid) {
                $ships += $attacker['fleet'][$gid];
            }
            if ($sum_cargo == 0) {
                $cargo = 0;
            } else {
                $cargo = (FleetCargoSummary($attacker['fleet']) - ($fleet_obj['m'] + $fleet_obj['k'] + $fleet_obj['d']) - $fleet_obj['fuel']) / $sum_cargo;
            }
            if ($ships > 0) {
                if ($fleet_obj['mission'] == 9 && $res['result'] === "awon") {
                    $result = GravitonAttack($fleet_obj, $attacker['fleet'], $queue['end']);
                } else {
                    $result = 0;
                }
                if ($result < 2) {
                    DispatchFleet($attacker['fleet'], $origin, $target, $fleet_obj['mission'] + 100, $fleet_obj['flight_time'], $fleet_obj['m'] + $cm * $cargo, $fleet_obj['k'] + $ck * $cargo, $fleet_obj['d'] + $cd * $cargo, $fleet_obj['fuel'] / 2, $queue['end']);
                }
            }
        }
        foreach ($d as $i => $defender) {
            if ($i == 0) {
                AdjustResources($cm, $ck, $cd, $defender['id'], '-');
                $objects = array();
                foreach ($fleetmap as $ii => $gid) {
                    $objects["f{$gid}"] = $defender[$gid] ? $defender[$gid] : 0;
                }
                foreach ($defmap as $ii => $gid) {
                    $objects["d{$gid}"] = $repaired[$gid] ? $repaired[$gid] : 0;
                    $objects["d{$gid}"] += $defender[$gid];
                }
                SetPlanetFleetDefense($defender['id'], $objects);
            } else {
                $ships = 0;
                foreach ($fleetmap as $ii => $gid) {
                    $ships += $defender[$gid];
                }
                if ($ships > 0) {
                    SetFleet($defender['id'], $defender);
                } else {
                    $queue = GetFleetQueue($defender['id']);
                    DeleteFleet($defender['id']);
                    // удалить флот
                    RemoveQueue($queue['task_id']);
                    // удалить задание
                }
            }
        }
    }
}