There is much much more economy code in game.
Faction Managers logic making goals and sub goals for different factions, planning invasions, reacting, making reconnaissance!, planning staging areas, planning building stations and much more.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<mdscript name="FactionLogic_Economy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
<cues>
<!--TODO @Owen - if traffic levels for a station are at a sustained high level, build a dock area-->
<!--Helper libraries-->
<library name="UpdateSectorNeighbourTable">
<actions>
<assert value="$Faction? and $SectorNeighbourTable?" text="'Variable $Faction or $SectorNeighbourTable not set. [Owen]'" break="1"/>
<!--TODO @Owen take contested into account-->
<do_if value="$Faction? and $SectorNeighbourTable?">
<clear_table table="$SectorNeighbourTable"/>
<find_sector name="$Sectors" owner="$Faction" multiple="true"/>
<do_all exact="$Sectors.count" counter="$USNT_i">
<set_value name="$Neighbours" exact="[]"/>
<set_value name="$SectorNeighbourTable.{$Sectors.{$USNT_i}}" exact="$Neighbours"/>
<find_cluster_in_range name="$Clusters" object="$Sectors.{$USNT_i}" maxdistance="1" multiple="true"/>
<do_all exact="$Clusters.count" counter="$USNT_k">
<find_sector name="$Neighbours" owner="$Faction" space="$Clusters.{$USNT_k}" multiple="true" append="true"/>
</do_all>
</do_all>
</do_if>
</actions>
</library>
<!--Faction economy library-->
<library name="Econ_Manager" namespace="this">
<params>
<param name="FactionManagerCue"/>
<param name="Faction"/>
<param name="DebugChance" default="0"/>
</params>
<actions>
<set_value name="$DebugText" exact="'(' + $Faction.id + ') Econ_Manager - '"/>
<set_value name="$Reports" exact="table[]"/>
<!--Table of actions the faction has attemtped to fix economic problems.-->
<!--Key is by sector, value is the list of actions-->
<set_value name="$ActionReports" exact="table[]"/>
<!--Table of sectors within 1 jump of the sector (including itself)-->
<set_value name="$SectorNeighbourTable" exact="table[]"/>
<include_actions ref="md.FactionLogic_Economy.UpdateSectorNeighbourTable"/>
<set_value name="$InsufficientProductsTable" exact="table[]"/>
<set_value name="$ShortageProductsTable" exact="table[]"/>
<set_value name="$InsufficientWorkforceTable" exact="table[]"/>
<set_value name="$ShortageWorkforceTable" exact="table[]"/>
<set_value name="$InsufficientBuildTable" exact="table[]"/>
<set_value name="$ShortageBuildTable" exact="table[]"/>
<!--Aggregated tables have the Ware as key and the value is the aggregated time of all reports for that ware-->
<set_value name="$AggregatedInsufficientProductsTable" exact="table[]"/>
<set_value name="$AggregatedShortageProductsTable" exact="table[]"/>
<set_value name="$AggregatedInsufficientWorkforceTable" exact="table[]"/>
<set_value name="$AggregatedShortageWorkforceTable" exact="table[]"/>
<set_value name="$AggregatedInsufficientBuildTable" exact="table[]"/>
<set_value name="$AggregatedShortageBuildTable" exact="table[]"/>
<!--Table of sectors which contain ware tables of aggregated report values-->
<set_value name="$SectorInsufficientProductsTable" exact="table[]"/>
<set_value name="$SectorShortageProductsTable" exact="table[]"/>
<set_value name="$SectorInsufficientWorkforceTable" exact="table[]"/>
<set_value name="$SectorShortageWorkforceTable" exact="table[]"/>
<set_value name="$SectorInsufficientBuildTable" exact="table[]"/>
<set_value name="$SectorShortageBuildTable" exact="table[]"/>
</actions>
<cues>
<cue name="RespondToShortageData" instantiate="true">
<conditions>
<event_cue_signalled cue="md.FactionLogic_Economy.ShortageDataGenerated"/>
</conditions>
<delay min="1s" max="5s"/>
<actions>
<signal_cue cue="EvaluateShortages"/>
</actions>
</cue>
<cue name="EvaluateShortages" instantiate="true">
<conditions>
<event_cue_signalled/>
<check_value value="md.FactionLogic_Economy.GenerateShortageData.state == cuestate.waiting"/>
</conditions>
<actions>
<set_value name="$DebugChance" exact="0"/>
<include_actions ref="md.FactionLogic_Economy.UpdateSectorNeighbourTable"/>
<do_if value="@md.FactionLogic_Economy.GlobalStorageData.$Reports">
<set_value name="$OwnerReports" exact="@md.FactionLogic_Economy.GlobalStorageData.$Reports.{$Faction}"/>
<do_if value="$OwnerReports">
<clear_table table="$InsufficientProductsTable"/>
<clear_table table="$ShortageProductsTable"/>
<clear_table table="$InsufficientWorkforceTable"/>
<clear_table table="$ShortageWorkforceTable"/>
<clear_table table="$InsufficientBuildTable"/>
<clear_table table="$ShortageBuildTable"/>
<!--Aggregated tables have the Ware as key and the value is the aggregated time of all reports for that ware-->
<clear_table table="$AggregatedInsufficientProductsTable"/>
<clear_table table="$AggregatedShortageProductsTable"/>
<clear_table table="$AggregatedInsufficientWorkforceTable"/>
<clear_table table="$AggregatedShortageWorkforceTable"/>
<clear_table table="$AggregatedInsufficientBuildTable"/>
<clear_table table="$AggregatedShortageBuildTable"/>
<!--Table of sectors which contain ware tables of aggregated report values-->
<clear_table table="$SectorInsufficientProductsTable"/>
<clear_table table="$SectorShortageProductsTable"/>
<clear_table table="$SectorInsufficientWorkforceTable"/>
<clear_table table="$SectorShortageWorkforceTable"/>
<clear_table table="$SectorInsufficientBuildTable"/>
<clear_table table="$SectorShortageBuildTable"/>
<set_value name="$TableRef" exact="null"/>
<set_value name="$TableRefKeys" exact="null"/>
<set_value name="$ReportKeys" exact="$OwnerReports.keys.list"/>
<do_all exact="$ReportKeys.count" counter="$i">
<set_value name="$Station" exact="$ReportKeys.{$i}"/>
<set_value name="$Sector" exact="$Station.sector"/>
<!--Insufficient Production Wares-->
<do_if value="$OwnerReports.{$Station}.{'$InsufficientProductionWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$InsufficientProductionWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<set_value name="$ReportValue" exact="$TableRef.{$Ware}"/>
<set_value name="$AggregatedInsufficientProductsTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorInsufficientProductsTable.{$Sector}?">
<set_value name="$SectorInsufficientProductsTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorInsufficientProductsTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<!--Avoid clashes by adding a little to the report value-->
<do_while value="$InsufficientProductsTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$InsufficientProductsTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
<!--Production wares in short supply-->
<do_if value="$OwnerReports.{$Station}.{'$ShortageProductionWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$ShortageProductionWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<set_value name="$ReportValue" exact="$TableRef.{$Ware}"/>
<set_value name="$AggregatedShortageProductsTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorShortageProductsTable.{$Sector}?">
<set_value name="$SectorShortageProductsTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorShortageProductsTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<do_while value="$ShortageProductsTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$ShortageProductsTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
<!--Insufficient Workforce Wares-->
<do_if value="$OwnerReports.{$Station}.{'$InsufficientWorkforceWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$InsufficientWorkforceWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<set_value name="$ReportValue" exact="$TableRef.{$Ware}"/>
<set_value name="$AggregatedInsufficientWorkforceTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorInsufficientWorkforceTable.{$Sector}?">
<set_value name="$SectorInsufficientWorkforceTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorInsufficientWorkforceTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<do_while value="$InsufficientWorkforceTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$InsufficientWorkforceTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
<!--Workforce wares in short supply-->
<do_if value="$OwnerReports.{$Station}.{'$ShortageWorkforceWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$ShortageWorkforceWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<set_value name="$ReportValue" exact="$TableRef.{$Ware}"/>
<set_value name="$AggregatedShortageWorkforceTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorShortageWorkforceTable.{$Sector}?">
<set_value name="$SectorShortageWorkforceTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorShortageWorkforceTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<do_while value="$ShortageWorkforceTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$ShortageWorkforceTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
<!--Insufficient Build Wares-->
<do_if value="$OwnerReports.{$Station}.{'$InsufficientBuildWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$InsufficientBuildWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<!--treat insufficient build wares as higher priority?-->
<!--TODO @Owen move to params-->
<set_value name="$ReportValue" exact="$TableRef.{$Ware} * 2"/>
<set_value name="$AggregatedInsufficientBuildTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorInsufficientBuildTable.{$Sector}?">
<set_value name="$SectorInsufficientBuildTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorInsufficientBuildTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<do_while value="$InsufficientBuildTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$InsufficientBuildTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
<!--Build wares in short supply-->
<do_if value="$OwnerReports.{$Station}.{'$ShortageBuildWares'}?">
<set_value name="$TableRef" exact="$OwnerReports.{$Station}.{'$ShortageBuildWares'}"/>
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$k">
<set_value name="$Ware" exact="$TableRefKeys.{$k}"/>
<set_value name="$ReportValue" exact="$TableRef.{$Ware} * 1.5"/>
<set_value name="$AggregatedShortageBuildTable.{$Ware}" exact="$ReportValue" operation="add"/>
<do_if value="not $SectorShortageBuildTable.{$Sector}?">
<set_value name="$SectorShortageBuildTable.{$Sector}" exact="table[]"/>
</do_if>
<set_value name="$SectorShortageBuildTable.{$Sector}.{$Ware}" exact="$ReportValue" operation="add"/>
<do_while value="$ShortageBuildTable.{$ReportValue}?">
<set_value name="$ReportValue" exact="1" operation="add"/>
</do_while>
<set_value name="$ShortageBuildTable.{$ReportValue}" exact="table[{'$Station'} = $Station, {'$Ware'} = $Ware]"/>
</do_all>
</do_if>
</do_all>
<do_if value="$DebugChance == 100">
<debug_text text="'Insufficient production wares'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedInsufficientProductsTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<debug_text text="'Production ware shortages'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedShortageProductsTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<debug_text text="'Insufficient workforce res.'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedInsufficientWorkforceTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<debug_text text="'Workforce ware shortages'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedShortageWorkforceTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<debug_text text="'Insufficient build res.'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedInsufficientBuildTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<debug_text text="'Build ware shortages'" context="false"/>
<set_value name="$TableRef" exact="$AggregatedShortageBuildTable"/>
<include_actions ref="AggregatedReportTableHelper"/>
<set_value name="$TableRef" exact="$InsufficientProductsTable"/>
<debug_text text="'Worst insufficient production ware reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$ShortageProductsTable"/>
<debug_text text="'Worst production ware shortage reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'short'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$InsufficientWorkforceTable"/>
<debug_text text="'Worst insufficient workforce ware reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$ShortageWorkforceTable"/>
<debug_text text="'Worst workforce ware shortage reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'short'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$InsufficientBuildTable"/>
<debug_text text="'Worst insufficient build ware reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$ShortageBuildTable"/>
<debug_text text="'Worst build ware shortage reports (of ' + $TableRef.keys.count + ')'" context="false"/>
<set_value name="$DebugReportType" exact="'short'"/>
<include_actions ref="SortedReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorInsufficientProductsTable"/>
<debug_text text="'Aggregated insufficient production ware reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SectorReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorShortageProductsTable"/>
<debug_text text="'Aggregated production ware shortage reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'shortage'"/>
<include_actions ref="SectorReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorInsufficientWorkforceTable"/>
<debug_text text="'Aggregated insufficient workforce ware reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SectorReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorShortageWorkforceTable"/>
<debug_text text="'Aggregated workforce ware shortage reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'shortage'"/>
<include_actions ref="SectorReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorInsufficientBuildTable"/>
<debug_text text="'Aggregated insufficient build ware reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'insufficient'"/>
<include_actions ref="SectorReportTableHelper"/>
<set_value name="$TableRef" exact="$SectorShortageBuildTable"/>
<debug_text text="'Aggregated build ware shortage reports by sector'" context="false"/>
<set_value name="$DebugReportType" exact="'shortage'"/>
<include_actions ref="SectorReportTableHelper"/>
</do_if>
<!--Decide which reports to act on-->
<!--TODO @Owen - move to parameters.xml-->
<set_value name="$ActionThresholds" exact="table[]"/>
<set_value name="$ActionThresholds.{'$request_commandeerable_freighter'}" exact="3000"/>
<set_value name="$ActionThresholds.{'$request_freighter'}" exact="6000"/>
<set_value name="$ActionThresholds.{'$request_priority_freighter'}" exact="11000"/>
<set_value name="$ActionThresholds.{'$request_production'}" exact="35000"/>
<set_value name="$ActionThresholds.{'$request_factory'}" exact="65000"/>
<set_value name="$ActionThresholds.{'$not_viable'}" exact="90000"/>
<set_value name="$ActionThresholdsKeys" exact="$ActionThresholds.keys.sorted"/>
<set_value name="$InsufficientNeighbourMultiplier" exact="0.2" comment="Factor of which to take neighbouring insufficient resources into account"/>
<set_value name="$NeighbourActionMultiplier" exact="0.5" comment="Factor of which to take the action score of neighbouring sectors for this ware into account"/>
<set_value name="$Request_Commandeerable_Freighter_Release_Time" exact="5400s" comment="Time after which the ship will be released"/>
<set_value name="$Request_Freighter_Spawn_Wait_Time" exact="1000s" comment="Time to allow the freighter to start being placed in a shipyard"/>
<set_value name="$Request_Freighter_Build_Wait_Time" exact="1000s" comment="Time to allow the freighter to be built by the shipyard after spawning"/>
<set_value name="$Request_Pri_Freighter_Spawn_Wait_Time" exact="1500s" comment="Time to allow the freighter to start being placed in a shipyard"/>
<set_value name="$Request_Pri_Freighter_Build_Wait_Time" exact="1500s" comment="Time to allow the freighter to be built by the shipyard after spawning"/>
<set_value name="$Request_Production_Build_Wait_Time" exact="5h" comment="Time to allow the building to start"/>
<set_value name="$Request_Production_Build_Timeout" exact="5h" comment="Time to allow the build to progress before disregarding"/>
<set_value name="$Request_Production_Working_Timeout" exact="5h" comment="Time to allow the factory to work before disregarding"/>
<set_value name="$Request_Factory_Build_Wait_Time" exact="15h" comment="Time to allow the building to start, where any module is operational or buildmodule is building"/>
<set_value name="$Request_Factory_Build_Timeout" exact="10h" comment="Time to allow the build to progress before disregarding"/>
<set_value name="$Request_Factory_Working_Timeout" exact="5h" comment="Time to allow the factory to work before disregarding"/>
<!--Check the exising actions to see if any should be disregarded-->
<set_value name="$DisregardedActions" exact="[]"/>
<set_value name="$ActionReportKeys" exact="$ActionReports.keys.list"/>
<do_all exact="$ActionReportKeys.count" counter="$ARK_i">
<set_value name="$ActionReportList" exact="$ActionReports.{$ActionReportKeys.{$ARK_i}}"/>
<do_all exact="$ActionReportList.count" counter="$ARL_i" reverse="true">
<set_value name="$DisregardAction" exact="false"/>
<set_value name="$DisregardReason" exact="'UNKNOWN'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="null"/>
<set_value name="$ActionReport" exact="$ActionReportList.{$ARL_i}"/>
<set_value name="$ActionReportDef" exact="$ActionReport.$ActionDef"/>
<!--CHECK REQUEST_COMMANDEERABLE_FRIEGHTER ACTION-->
<do_if value="$ActionReportDef.$Type == '$request_commandeerable_freighter'">
<set_value name="$CommandeeredShip" exact="$ActionReportDef.$Ship"/>
<do_if value="$CommandeeredShip.isoperational and $CommandeeredShip.isjobship and not @$ActionReportDef.$Disregard" comment="$ActionReportDef.$Disregard can be set in the action handler itself">
<!--Ship is still an existing job ship-->
<do_if value="player.age ge $ActionReportDef.$CommandeerTime + $Request_Commandeerable_Freighter_Release_Time">
<!--Ship is no longer a requested ship. Disregard action report-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is to be released as a commandeered freighter'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$CommandeeredShip"/>
</do_if>
</do_if>
<do_else>
<!--Ship is no longer a requested ship. Disregard action report-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is no longer a suitable job ship'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$CommandeeredShip"/>
</do_else>
<remove_value name="$CommandeeredShip"/>
</do_if>
<!--CHECK REQUEST_FREIGHTER ACTION-->
<do_elseif value="$ActionReportDef.$Type == '$request_freighter'">
<set_value name="$RequestedShip" exact="$ActionReportDef.$Ship"/>
<do_if value="($RequestedShip.exists or $RequestedShip.isoperational) and $RequestedShip.isrequestedjobship">
<!--Ship is still an existing requested job ship or is an operational ship waiting to be built somewhere-->
<!--TODO @Owen - parameters for things such as how long to wait for requested ships-->
<do_if value="not $RequestedShip.exists">
<do_if value="$ActionReport.$StartTime lt player.age - $Request_Freighter_Spawn_Wait_Time">
<!--DISREGARD-->
<!--However, the ship still does not exist and it was requested some time ago. Kill and try something else-->
<destroy_object object="$RequestedShip"/>
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Time elapsed and it never existed'" chance="$DebugChance"/>
</do_if>
</do_if>
<do_elseif value="$RequestedShip.isoperational">
<!--TODO @Owen, check if actually doing something. Any trade runs?-->
<!--<do_elseif value="$ActionReportDef.$LaunchTime lt xxxxs and the situation is around the same or worse">
try another frieghter or a more drastic measure?
</do_elseif>-->
</do_elseif>
<do_elseif value="$RequestedShip.isconstruction">
<do_if value="@$ActionReportDef.$SpawnTime lt player.age - $Request_Freighter_Build_Wait_Time">
<!--DISREGARD-->
<!--Ship has not been built yet-->
<!--TODO @Owen. Check state of the build. Is it close to finishing? Allow a bit more time?-->
<!--TODO @Owen Recycle-->
<destroy_object object="$RequestedShip"/>
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship took too long to finish building'" chance="$DebugChance"/>
</do_if>
</do_elseif>
<do_elseif value="$RequestedShip.iswreck">
<!--DISREGARD-->
<!--Requested job ship is destroyed-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is destroyed.'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$RequestedShip"/>
</do_elseif>
</do_if>
<do_else>
<!--Ship is no longer a requested ship. Disregard action report-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is no longer a requested job ship'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$RequestedShip"/>
</do_else>
<remove_value name="$RequestedShip"/>
</do_elseif>
<!--CHECK REQUEST_PRIORITY_FRIEGHTER ACTION-->
<do_elseif value="$ActionReportDef.$Type == '$request_priority_freighter'">
<set_value name="$RequestedShip" exact="$ActionReportDef.$Ship"/>
<do_if value="($RequestedShip.exists or $RequestedShip.isoperational) and $RequestedShip.isrequestedjobship">
<!--Ship is still an existing requested job ship or is an operational ship waiting to be built somewhere-->
<!--TODO @Owen - parameters for things such as how long to wait for requested ships-->
<do_if value="not $RequestedShip.exists">
<do_if value="$ActionReport.$StartTime lt player.age - $Request_Pri_Freighter_Spawn_Wait_Time">
<!--DISREGARD-->
<!--However, the ship still does not exist and it was requested some time ago. Kill and try something else-->
<destroy_object object="$RequestedShip"/>
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Time elapsed and it never existed'" chance="$DebugChance"/>
</do_if>
</do_if>
<do_elseif value="$RequestedShip.isoperational">
<!--TODO @Owen, check if actually doing something. Any trade runs?-->
<!--<do_elseif value="$ActionReportDef.$LaunchTime lt xxxxs and the situation is around the same or worse">
try another frieghter or a more drastic measure?
</do_elseif>-->
</do_elseif>
<do_elseif value="$RequestedShip.isconstruction">
<do_if value="@$ActionReportDef.$SpawnTime lt player.age - $Request_Pri_Freighter_Build_Wait_Time">
<!--DISREGARD-->
<!--Ship has not been built yet-->
<!--TODO @Owen. Check state of the build. Is it close to finishing? Allow a bit more time?-->
<!--TODO @Owen Recycle-->
<destroy_object object="$RequestedShip"/>
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship took too long to finish building'" chance="$DebugChance"/>
</do_if>
</do_elseif>
<do_elseif value="$RequestedShip.iswreck">
<!--DISREGARD-->
<!--Requested job ship is destroyed-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is destroyed.'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$RequestedShip"/>
</do_elseif>
</do_if>
<do_else>
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Ship is no longer a requested job ship'" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$RequestedShip"/>
</do_else>
<remove_value name="$RequestedShip"/>
</do_elseif>
<!--CHECK REQUEST_PRODUCTION ACTION-->
<do_elseif value="$ActionReportDef.$Type == '$request_production'">
<set_value name="$Station" exact="$ActionReportDef.$Station"/>
<do_if value="not $Station.exists">
<!--DISREGARD-->
<!--The station no longer exists-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Station no longer exists'" chance="$DebugChance"/>
</do_if>
<do_elseif value="@$ActionReportDef.$BuiltTime">
<!--All productions were finished-->
<!--TODO @Owen check if the factory is actually producing?-->
<do_if value="$ActionReportDef.$BuiltTime lt player.age - $Request_Production_Working_Timeout">
<!--DISREGARD-->
<!--Productions have been complete for some time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Factory has had the new productions for ' + $Request_Production_Working_Timeout" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_elseif>
<do_elseif value="@$ActionReportDef.$StartBuildTime or @$ActionReportDef.$LastBuildTime">
<!--Some module has begun construction-->
<do_if value="[$ActionReportDef.$StartBuildTime, @$ActionReportDef.$LastBuildTime].max lt player.age - $Request_Production_Build_Timeout">
<!--DISREGARD-->
<!--Factory has been expanding for a long time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Factory has been expanding for ' + $Request_Production_Build_Timeout" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_elseif>
<do_else>
<!--Building has not started yet-->
<do_if value="$ActionReport.$StartTime lt player.age - $Request_Production_Build_Wait_Time">
<!--DISREGARD-->
<!--Construction has not started on the factory for a long time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Expansion has not started on factory for' + $Request_Production_Build_Wait_Time" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_else>
<remove_value name="$Station"/>
</do_elseif>
<!--CHECK REQUEST_FACTORY ACTION-->
<do_elseif value="$ActionReportDef.$Type == '$request_factory'">
<set_value name="$Station" exact="$ActionReportDef.$Station"/>
<do_if value="not $Station.exists">
<!--DISREGARD-->
<!--The module did exist, but no longer-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Station no longer exists'" chance="$DebugChance"/>
</do_if>
<do_elseif value="@$ActionReportDef.$BuiltTime">
<!--Build has finished-->
<!--TODO @Owen check if the factory is actually producing?-->
<do_if value="$ActionReportDef.$BuiltTime lt player.age - $Request_Factory_Working_Timeout">
<!--DISREGARD-->
<!--Factory has been complete for some time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Factory has been working for ' + $Request_Factory_Working_Timeout" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_elseif>
<do_elseif value="@$ActionReportDef.$StartBuildTime">
<!--Build has started-->
<do_if value="$ActionReportDef.$StartBuildTime lt player.age - $Request_Factory_Build_Timeout">
<!--DISREGARD-->
<!--Factory has been building for a long time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Factory has been building for ' + $Request_Factory_Build_Timeout" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_elseif>
<do_else>
<!--Building has not started yet-->
<do_if value="$ActionReport.$StartTime lt player.age - $Request_Factory_Build_Wait_Time">
<!--DISREGARD-->
<!--Construction has not started on the factory for a long time.-->
<set_value name="$DisregardAction" exact="true"/>
<set_value name="$DisregardReason" exact="'Construction has not started on factory for' + $Request_Factory_Build_Timeout" chance="$DebugChance"/>
<set_value name="$DisregardObject" exact="$Station"/>
</do_if>
</do_else>
<remove_value name="$Station"/>
</do_elseif>
<do_else>
<assert value="false" text="'Unknown action type ' + $ActionReportDef.$Type + ' [Owen]'" break="1"/>
</do_else>
<do_if value="$DisregardAction">
<debug_text text="'Disregarding action with reason: ' + $DisregardReason + ' Action: ' + $ActionReport" context="false" chance="$DebugChance"/>
<do_if value="$DisregardObject and $DisregardObject.isclass.component">
<!--.isclass.component check as $DisregardObject may be disconnected and .exists may not work-->
<signal_objects object="$DisregardObject" param="'factionlogic_econ_disregard'" param2="$ActionReportDef.$Type"/>
</do_if>
<append_to_list name="$DisregardedActions" exact="$ActionReportList.{$ARL_i}"/>
<remove_value name="$ActionReportList.{$ARL_i}"/>
</do_if>
</do_all>
</do_all>
<remove_value name="$ActionReportKeys"/>
<!--First, check the insufficient production resources-->
<!--TODO @Owen - deal with ware shortage tables-->
<set_value name="$ReportTablesToProcess" exact="[$SectorInsufficientProductsTable, $SectorInsufficientWorkforceTable, $SectorInsufficientBuildTable]"/>
<do_all exact="$ReportTablesToProcess.count" counter="$h">
<set_value name="$TableRef" exact="$ReportTablesToProcess.{$h}"/>
<!--TableRef keys are sectors-->
<do_if value="$TableRef.keys.count">
<set_value name="$TableRefKeys" exact="$TableRef.keys.list"/>
<do_all exact="$TableRefKeys.count" counter="$i">
<set_value name="$Sector" exact="$TableRefKeys.{$i}"/>
<debug_text text="'\n' + $DebugText + 'Checking sector ' + $Sector + ' ' + $Sector.knownname" context="false" chance="$DebugChance"/>
<set_value name="$SubTable" exact="$TableRef.{$Sector}"/>
<set_value name="$SubTableRefKeys" exact="$SubTable.keys.list"/>
<do_all exact="$SubTableRefKeys.count" counter="$k" reverse="true">
<set_value name="$Ware" exact="$SubTableRefKeys.{$k}"/>
<set_value name="$SectorValue" exact="$SubTable.{$SubTableRefKeys.{$k}}"/>
<debug_text text="'Sector ' + $Sector + ' ' + $Sector.knownname + ' has insufficient ware ' + $Ware + ' at value ' + $SectorValue" context="false" chance="$DebugChance"/>
<do_if value="$SectorNeighbourTable.{$Sector}?">
<set_value name="$NeighbouringSectors" exact="$SectorNeighbourTable.{$Sector}"/>
</do_if>
<do_else>
<!--TODO @Owen decypher the comment below-->
<!--TODO @Owen This sector does is not owned by this faction but has stations reporting about wares-->
<set_value name="$NeighbouringSectors" exact="[$Sector]"/>
</do_else>
<!--Check if the neighboring sectors have reports for the same ware. Take them into account but with the $InsufficientNeighbourMultiplier-->
<!--TODO @Owen - only if positive?-->
<do_all exact="$NeighbouringSectors.count" counter="$sector_i">
<set_value name="$NeighbourSector" exact="$NeighbouringSectors.{$sector_i}"/>
<do_if value="$NeighbourSector != $Sector and $TableRef.{$NeighbourSector}?">
<set_value name="$NeighbourSubTable" exact="$TableRef.{$NeighbourSector}"/>
<do_if value="$NeighbourSubTable.{$Ware}?">
<set_value name="$SectorValue" exact="$NeighbourSubTable.{$Ware} * $InsufficientNeighbourMultiplier" operation="add"/>
<debug_text text="'Neighbouring sector ' + $NeighbourSector + ' ' + $NeighbourSector.knownname + ' also has insufficient ware ' + $Ware + ' to add modified value ' + $NeighbourSubTable.{$Ware} * $InsufficientNeighbourMultiplier + ' for a new value of ' + $SectorValue" context="false" chance="$DebugChance"/>
</do_if>
</do_if>
</do_all>
<set_value name="$HighestActionCost" exact="0"/>
<set_value name="$HighestDisregardedActionCost" exact="0"/>
<do_all exact="$DisregardedActions.count" counter="$o">
<do_if value="$DisregardedActions.{$o}.$Sector and $DisregardedActions.{$o}.$Ware == $Ware">
<do_if value="$ActionThresholds.{$ActionReportDef.{'$Type'}} gt $HighestDisregardedActionCost">
<!--This was a disregarded action for this sector, remember how much worth it had so an action of higher worth can be queued-->
<set_value name="$HighestDisregardedActionCost" exact="$ActionThresholds.{$ActionReportDef.$Type}"/>
<debug_text text="'Disregarded action had the highest cost so far of ' + $HighestDisregardedActionCost" context="false" chance="$DebugChance"/>
</do_if>
</do_if>
</do_all>