Skip to content

Commit

Permalink
Merge pull request #123 from mdziekon/mdziekon/90/refactor-expedition…
Browse files Browse the repository at this point in the history
…s-part01
  • Loading branch information
mdziekon authored Aug 1, 2020
2 parents 51ac64a + a23e6e4 commit cbd64cf
Show file tree
Hide file tree
Showing 41 changed files with 831 additions and 509 deletions.
18 changes: 12 additions & 6 deletions admin/UserDevScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ function ResourceUpdate(&$CurrentPlanet, $CurrentUser, $StartTime, $EndTime) {
$PlanetsDumpData[$PlanetID]['id'] = $PlanetID;
foreach($_Vars_ElementCategories as $reskey => $resvals)
{
if(in_array($reskey, array('tech', 'buildOn', 'units')))
{
if (!in_array($reskey, [ 'build', 'fleet', 'defense', 'rockets', 'prod' ])) {
continue;
}

foreach($resvals as $resID)
{
if($reskey != 'prod')
Expand Down Expand Up @@ -1089,6 +1089,12 @@ function ResourceUpdate(&$CurrentPlanet, $CurrentUser, $StartTime, $EndTime) {

$PreventResourceUpdate = true;
}
else if($Place == 31)
{
// MissionCaseExpedition.php

$PreventResourceUpdate = true;
}
else
{
$ScanLog['Fatal'][] = array('ID' => '001', 'LogNo' => $ScaningNo, 'LogID' => $Log['ID'], 'Data' => array($Place));
Expand Down Expand Up @@ -1198,10 +1204,10 @@ function ResourceUpdate(&$CurrentPlanet, $CurrentUser, $StartTime, $EndTime) {

foreach($_Vars_ElementCategories as $Key => $Values)
{
if(in_array($Key, array('build', 'tech', 'prod', 'buildOn', 'units')))
{
if (!in_array($Key, [ 'fleet', 'defense', 'rockets' ])) {
continue;
}

foreach($Values as $ItemID)
{
$PlanetNew[$_Vars_GameElements[$ItemID]] += 0;
Expand Down Expand Up @@ -1404,10 +1410,10 @@ function ResourceUpdate(&$CurrentPlanet, $CurrentUser, $StartTime, $EndTime) {

foreach($_Vars_ElementCategories as $Key => $Values)
{
if(in_array($Key, array('tech', 'prod', 'buildOn', 'units')))
{
if (!in_array($Key, [ 'build', 'fleet', 'defense', 'rockets' ])) {
continue;
}

foreach($Values as $ItemID)
{
if($Key != 'build')
Expand Down
11 changes: 10 additions & 1 deletion admin/bashDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

include($_EnginePath.'common.php');

use UniEngine\Engine\Modules\Flights;

if(!CheckAuth('go'))
{
message($_Lang['sys_noalloaw'], $_Lang['sys_noaccess']);
Expand Down Expand Up @@ -140,10 +142,17 @@
$ThisArray = array($Usernames[$Set['SenderID']], $Set['SenderID'], $Set['SenderID'], $Usernames[$Set['OwnerID']], $Set['OwnerID'], $Set['OwnerID'], prettyDate('d m Y', $Set['Date'], 1));
$_Lang['Insert_BashOverallResult'][] = vsprintf($_Lang['Analysis_Info'], $ThisArray);

$excludedDestructionReasons = [
strval(Flights\Enums\FleetDestructionReason::INBATTLE_FIRSTROUND_NODAMAGE),
strval(Flights\Enums\FleetDestructionReason::DRAW_NOBASH),
strval(Flights\Enums\FleetDestructionReason::INBATTLE_OTHERROUND_NODAMAGE),
];
$excludedDestructionReasonsStr = implode(', ', $excludedDestructionReasons);

$Query_Where[] = "`Fleet_Mission` IN (1, 2, 9)";
$Query_Where[] = "`Fleet_End_Owner_IdleHours` < 168";
$Query_Where[] = "`Fleet_ReportID` > 0";
$Query_Where[] = "`Fleet_Destroyed_Reason` NOT IN (1, 4, 11)";
$Query_Where[] = "`Fleet_Destroyed_Reason` NOT IN ({$excludedDestructionReasonsStr})";

$Query_GetFleets = '';
$Query_GetFleets .= "SELECT `Fleet_ID`, `Fleet_Mission`, `Fleet_Time_Start`, `Fleet_End_ID`, `Fleet_ReportID` ";
Expand Down
60 changes: 30 additions & 30 deletions admin/scripts/script.createUserDevDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,42 @@
$Point['planets'][$PlanetData['id']]['lu'] = $PlanetData['last_update'];
$Point['planets'][$PlanetData['id']]['res'] = floor($PlanetData['metal']).','.floor($PlanetData['crystal']).','.floor($PlanetData['deuterium']);

$planetEntryRef = &$Point['planets'][$PlanetData['id']];

foreach($_Vars_ElementCategories as $Key => $Array)
{
if(in_array($Key, array('tech', 'buildOn', 'units')))
{
foreach ($_Vars_ElementCategories as $categoryKey => $categoryElementIDs) {
if (!in_array($categoryKey, [ 'build', 'prod', 'fleet', 'defense', 'rockets' ])) {
continue;
}
if($Key != 'build')
{
if($Key != 'prod')
{
foreach($Array as $ElementID)
{
if(isset($PlanetData[$_Vars_GameElements[$ElementID]]) && $PlanetData[$_Vars_GameElements[$ElementID]] > 0)
{
$Point['planets'][$PlanetData['id']]['f'][] = "{$ElementID},{$PlanetData[$_Vars_GameElements[$ElementID]]}";
}
}
}
else
{
foreach($Array as $ElementID)
{
$Point['planets'][$PlanetData['id']]['p'][] = $ElementID.','.$PlanetData[$_Vars_GameElements[$ElementID].'_workpercent'];
}

if ($categoryKey == 'prod') {
foreach ($categoryElementIDs as $elementID) {
$planetEntryRef['p'][] = $elementID.','.$PlanetData[$_Vars_GameElements[$elementID].'_workpercent'];
}

continue;
}
else
{
foreach($Array as $BuildID)
{
if(isset($PlanetData[$_Vars_GameElements[$BuildID]]) && $PlanetData[$_Vars_GameElements[$BuildID]] > 0)
{
$Point['planets'][$PlanetData['id']]['b'][] = "{$BuildID},{$PlanetData[$_Vars_GameElements[$BuildID]]}";
}

$inserter = function () {};

if ($categoryKey == 'build') {
$inserter = function ($value) use (&$planetEntryRef) {
$planetEntryRef['b'][] = $value;
};
} else {
$inserter = function ($value) use (&$planetEntryRef) {
$planetEntryRef['f'][] = $value;
};
}

foreach ($categoryElementIDs as $elementID) {
if (
!isset($PlanetData[$_Vars_GameElements[$elementID]]) ||
$PlanetData[$_Vars_GameElements[$elementID]] <= 0
) {
continue;
}

$inserter("{$elementID},{$PlanetData[$_Vars_GameElements[$elementID]]}");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ajax/galaxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function ajaxReturn($Array)
}

include($_EnginePath.'includes/functions/ShowGalaxyRows.php');
include($_EnginePath.'includes/functions/GalaxyRowExpedition.php');
include($_EnginePath.'includes/functions/GalaxyRowPos.php');
include($_EnginePath.'includes/functions/GalaxyRowPlanet.php');
include($_EnginePath.'includes/functions/GalaxyRowPlanetName.php');
Expand Down
21 changes: 20 additions & 1 deletion attackslist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
$_EnginePath = './';
include($_EnginePath.'common.php');

use UniEngine\Engine\Modules\Flights;

loggedCheck();

if(!isPro())
Expand All @@ -29,8 +31,25 @@

$SelectFields = '`Fleet_End_ID`, `Fleet_End_Owner`, `Fleet_End_ID_Changed`, `Fleet_End_Type_Changed`, `Fleet_End_Galaxy`, `Fleet_End_System`, `Fleet_End_Planet`, `Fleet_End_Type`, `Fleet_ACSID`';

$excludedDestructionReasons = [
strval(Flights\Enums\FleetDestructionReason::INBATTLE_FIRSTROUND_NODAMAGE),
strval(Flights\Enums\FleetDestructionReason::DRAW_NOBASH),
strval(Flights\Enums\FleetDestructionReason::INBATTLE_OTHERROUND_NODAMAGE),
];
$excludedDestructionReasonsStr = implode(', ', $excludedDestructionReasons);

$SQLResult_GetAttacks = doquery(
"SELECT {$SelectFields} FROM {{table}} WHERE (`Fleet_Time_Start` + `Fleet_Time_ACSAdd`) >= {$TodayTimestamp} AND `Fleet_Owner` = {$_User['id']} AND `Fleet_Mission` IN (1, 2, 9) AND `Fleet_End_Owner_IdleHours` < 168 AND `Fleet_ReportID` > 0 AND `Fleet_End_Owner` > 0 AND `Fleet_Destroyed_Reason` NOT IN (1, 4, 11);",
"SELECT {$SelectFields} " .
"FROM {{table}} " .
"WHERE " .
"(`Fleet_Time_Start` + `Fleet_Time_ACSAdd`) >= {$TodayTimestamp} AND " .
"`Fleet_Owner` = {$_User['id']} AND " .
"`Fleet_Mission` IN (1, 2, 9) AND " .
"`Fleet_End_Owner_IdleHours` < 168 AND " .
"`Fleet_ReportID` > 0 AND " .
"`Fleet_End_Owner` > 0 AND " .
"`Fleet_Destroyed_Reason` NOT IN ({$excludedDestructionReasonsStr}) " .
";",
'fleet_archive'
);

Expand Down
5 changes: 5 additions & 0 deletions fleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
$_Lang['P_MaxExpedSlots'] = 1 + floor($_User[$_Vars_GameElements[124]] / 3);
$_Lang['P_FlyingFleetsCount'] = (string)($FlyingFleetsCount + 0);
$_Lang['P_FlyingExpeditions'] = (string)($FlyingExpeditions + 0);
$_Lang['P_Expeditions_isHidden_style'] = (
isFeatureEnabled(FeatureType::Expeditions) ?
'' :
'display: none;'
);

// Get own fleets
$FL = 'fleet_';
Expand Down
2 changes: 1 addition & 1 deletion fleet1.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
{
$SetPos['s'] = $_Planet['system'];
}
if($SetPos['p'] < 1 OR $SetPos['p'] > MAX_PLANET_IN_SYSTEM)
if($SetPos['p'] < 1 OR $SetPos['p'] > (MAX_PLANET_IN_SYSTEM + 1))
{
$SetPos['p'] = $_Planet['planet'];
}
Expand Down
4 changes: 3 additions & 1 deletion fleet2.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@
{
if($Target['planet'] == (MAX_PLANET_IN_SYSTEM + 1))
{
$AvailableMissions[] = 15;
if (isFeatureEnabled(FeatureType::Expeditions)) {
$AvailableMissions[] = 15;
}
}
else
{
Expand Down
33 changes: 26 additions & 7 deletions fleet3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

include($_EnginePath.'common.php');

use UniEngine\Engine\Modules\Flights;

loggedCheck();

if($_POST['sending_fleet'] != '1')
Expand Down Expand Up @@ -81,6 +83,13 @@ function messageRed($Text, $Title)
messageRed($_Lang['fl3_NoMissionSelected'], $ErrorTitle);
}

if (
!isFeatureEnabled(FeatureType::Expeditions) &&
$Fleet['Mission'] == 15
) {
messageRed($_Lang['fl3_ExpeditionsAreOff'], $ErrorTitle);
}

// --- Get FlyingFleets Count
$FlyingFleetsCount = 0;
$FlyingExpeditions = 0;
Expand Down Expand Up @@ -126,12 +135,6 @@ function messageRed($Text, $Title)
messageRed($_Lang['fl3_NoMoreFreeExpedSlots'], $ErrorTitle);
}

// --- Switch Off Expeditions
if($Fleet['Mission'] == 15)
{
messageRed($_Lang['fl3_ExpeditionsAreOff'], $ErrorTitle);
}

// --- Check if all resources are correct (no negative numbers and enough on planet)
foreach($Fleet['resources'] as $Key => $Data)
{
Expand Down Expand Up @@ -971,8 +974,24 @@ function messageRed($Text, $Title)
sort($BashTimestamps, SORT_ASC);
$BashTimestampMinVal = $BashTimestamps[0]['stamp'];

$excludedDestructionReasons = [
strval(Flights\Enums\FleetDestructionReason::INBATTLE_FIRSTROUND_NODAMAGE),
strval(Flights\Enums\FleetDestructionReason::DRAW_NOBASH),
strval(Flights\Enums\FleetDestructionReason::INBATTLE_OTHERROUND_NODAMAGE),
];
$excludedDestructionReasonsStr = implode(', ', $excludedDestructionReasons);

$SQLResult_GetFleetArchiveRecords = doquery(
"SELECT * FROM {{table}} WHERE (`Fleet_Time_Start` + `Fleet_Time_ACSAdd`) >= {$BashTimestampMinVal} AND `Fleet_Owner` = {$_User['id']} AND `Fleet_End_Owner` = {$TargetData['owner']} AND `Fleet_Mission` IN (1, 2, 9) AND `Fleet_ReportID` > 0 AND `Fleet_Destroyed_Reason` NOT IN (1, 4, 11);",
"SELECT * " .
"FROM {{table}} " .
"WHERE " .
"(`Fleet_Time_Start` + `Fleet_Time_ACSAdd`) >= {$BashTimestampMinVal} AND " .
"`Fleet_Owner` = {$_User['id']} AND " .
"`Fleet_End_Owner` = {$TargetData['owner']} AND " .
"`Fleet_Mission` IN (1, 2, 9) AND " .
"`Fleet_ReportID` > 0 AND " .
"`Fleet_Destroyed_Reason` NOT IN ({$excludedDestructionReasonsStr}) " .
";",
'fleet_archive'
);

Expand Down
1 change: 1 addition & 0 deletions galaxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
include($_EnginePath.'includes/functions/ShowGalaxyMISelector.php');
include($_EnginePath.'includes/functions/ShowGalaxyTitles.php');
include($_EnginePath.'includes/functions/ShowGalaxyFooter.php');
include($_EnginePath.'includes/functions/GalaxyRowExpedition.php');
include($_EnginePath.'includes/functions/GalaxyRowPos.php');
include($_EnginePath.'includes/functions/GalaxyRowPlanet.php');
include($_EnginePath.'includes/functions/GalaxyRowPlanetName.php');
Expand Down
2 changes: 1 addition & 1 deletion includes/functions/FlyingFleetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function FlyingFleetHandler(&$planet, $IncludeFleetsFromEndIDs = array())
$Inc_MissionExpedition = true;
include('MissionCaseExpedition.php');
}
$MissionReturn = MissionCaseExpedition($CurrentFleet);
$MissionReturn = MissionCaseExpedition($CurrentFleet, $_FleetCache);
break;
}
default:
Expand Down
22 changes: 22 additions & 0 deletions includes/functions/GalaxyRowExpedition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

function GalaxyRowExpedition($Galaxy, $System) {
global $_Lang;
static $TPL = false;

if ($TPL === false) {
$TPL = gettemplate('galaxy_row_expedition');
}

$Parse = [
'data_galaxy' => $Galaxy,
'data_system' => $System,
'data_planetpos' => (MAX_PLANET_IN_SYSTEM + 1),
'data_missionid' => 15,
'lang_label' => $_Lang['Footer_Expedition'],
];

return parsetemplate($TPL, $Parse);
}

?>
12 changes: 6 additions & 6 deletions includes/functions/MissionCaseAttack.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,36 +500,36 @@ function MissionCaseAttack($FleetRow, &$_FleetCache)
{
if(count($RoundsData) == 2)
{
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = 1;
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::INBATTLE_FIRSTROUND_NODAMAGE;
}
else
{
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = 11;
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::INBATTLE_OTHERROUND_NODAMAGE;
}
}
else
{
if(count($RoundsData) == 2)
{
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = 12;
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::INBATTLE_FIRSTROUND_MADEDAMAGE;
}
else
{
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = 2;
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::INBATTLE_OTHERROUND_MADEDAMAGE;
}
}
}
else
{
unset($_FleetCache['defFleets'][$FleetRow['fleet_end_id']][$FleetID]);
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = 3;
$Return['FleetArchive'][$FleetID]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::FRIENDDEFENSE;
}
}
}

if($Result === COMBAT_DRAW AND (($RealDebrisMetalDef + $RealDebrisCrystalDef + $RealDebrisDeuteriumDef) <= 0))
{
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Destroyed_Reason'] = 4;
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::DRAW_NOBASH;
}

// Create debris field on the orbit
Expand Down
4 changes: 3 additions & 1 deletion includes/functions/MissionCaseColonisation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use UniEngine\Engine\Modules\Flights;

function MissionCaseColonisation($FleetRow, &$_FleetCache)
{
global $_Lang, $UserDev_Log, $_User, $GlobalParsedTasks, $UserTasksUpdate, $_Vars_TasksData;
Expand Down Expand Up @@ -89,7 +91,7 @@ function MissionCaseColonisation($FleetRow, &$_FleetCache)
$fleetHasBeenDeleted = true;
$Return['FleetsToDelete'][] = $FleetRow['fleet_id'];
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Destroyed'] = true;
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Destroyed_Reason'] = 8;
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Destroyed_Reason'] = Flights\Enums\FleetDestructionReason::COLONIZATION;
$Return['FleetArchive'][$FleetRow['fleet_id']]['Fleet_Info_HasLostShips'] = true;
$SetCode = '1';
}
Expand Down
Loading

0 comments on commit cbd64cf

Please sign in to comment.