-
Notifications
You must be signed in to change notification settings - Fork 1
/
ut.cac.com.manager.gatherressources.xml
158 lines (147 loc) · 9.4 KB
/
ut.cac.com.manager.gatherressources.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?xml version="1.0" encoding="UTF-8"?>
<aiscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="ut.cac.com.manager.gatherressources" xsi:noNamespaceSchemaLocation="http://utnas/~unitrader/XRebirthxsds/aiscripts.xsd" version="1">
<!--
Manager-Based Gas Mining Script by UniTrader
IMPORTANT NOTE:
This Script is intended to be called regulary with >the same< Table as $params because it stores some needed Values there to actually Work. Please keep this in mind when using this Script.
-->
<params>
<param name="params" default="false" comment="pass a single Table filled with the wanted param Values here to make calls via list possible (always has priority)"/>
</params>
<interrupts>
<handler comment="Print Script Vars">
<conditions>
<event_object_signalled object="this" param="'print script vars to logfile'"/>
</conditions>
<actions>
<debug_text filter="general" text="'\n
Manager Name ' + this.knownname + ' at Time ' + player.age + ' Script Values:\n'"/>
</actions>
</handler>
</interrupts>
<init>
</init>
<attention min="unknown">
<actions>
<do_if value="$params">
<do_if value="$params.$wareslist?">
<set_value name="$wareslist" exact="$params.$wareslist"/>
</do_if>
<do_if value="$params.$next_call?">
<set_value name="$next_call" exact="$params.$next_call"/>
</do_if>
</do_if>
<debug_text filter="general" chance="@this.$debug * 100" text="'%1 %2 %3 manager Gather Script called with: \n%4'.[player.age,this.name,this.container.name,$params]"/>
<!-- first check if we already started gathering Ressources and add them to the Station -->
<do_if value="$params.$gatherware?">
<remove_ware_reservation object="this.container" entity="this" ware="$params.$gatherware" type="sell"/>
<get_resource_gatherrate name="$gatherrate" refobject="this.container" zone="this.zone" ware="$params.$gatherware" />
<set_value name="$gatherrate" exact="$gatherrate / 3" comment="Station Gas Mining is only 30% as effective as it could be"/>
<set_value name="$gatherrate" exact="[$gatherrate,$params.$gatherrate].min"/>
<set_value name="$gathertime" exact="player.age - $params.$gatherstart" />
<set_value name="$gathered" exact="$gathertime * $gatherrate" />
<get_ware_reservation ware="$params.$gatherware" object="this.container" result="$incomingamount" type="sell"/>
<set_value name="$gathered" exact=" [ this.container.cargo.{$params.$gatherware}.target - this.container.cargo.{$params.$gatherware}.count - $incomingamount , $gathered ].min"/>
<do_if value="$gathered gt 0">
<deplete_yield zone="this.zone" container="this.container" ware="$params.$gatherware" amount="$gathered" />
</do_if>
<debug_text filter="general" chance="@this.$debug * 100" text="'%1 %2 %3 Gathered from previous run:\n%4 units of %5 in %6 seconds (%7 units/s)'.[player.age,this.name,this.container.name,$gathered, $params.$gatherware, $gathertime, $gatherrate]"/>
<remove_value name="$params.$gatherstart"/>
<remove_value name="$params.$gatherware"/>
<remove_value name="$params.$gatherrate"/>
</do_if>
<do_if value="$wareslist.count == 0">
<return/>
</do_if>
<!-- first sort $wareslist by its priority and filter out Minerals for now (to be implemented later) -->
<create_list name="$wareslist_prio" exact="$wareslist.count"/>
<do_all exact="$wareslist.count" counter="$i" reverse="true">
<do_if value="$wareslist.{$i}.tags.indexof.{tag.liquid}">
<get_ware_reservation ware="$wareslist.{$i}" object="this.container" result="$incomingamount" type="sell"/>
<set_value name="$wareslist_prio.{$i}" exact="1 - ( ( this.container.cargo.{$wareslist.{$i}}.count + $incomingamount )f / ( this.container.cargo.{$wareslist.{$i}}.target )f )"/>
<!-- filter out Wares we dont need (very low demand) and Wares which can not be mined here -->
<do_if value="$wareslist_prio.{$i} lt 0.003 or not this.zone.yield.indexof.{$wareslist.{$i}}">
<remove_value name="$wareslist.{$i}"/>
<remove_value name="$wareslist_prio.{$i}"/>
</do_if>
</do_if>
<do_else>
<remove_value name="$wareslist.{$i}"/>
<remove_value name="$wareslist_prio.{$i}"/>
</do_else>
</do_all>
<do_all exact="$wareslist.count" counter="$imax">
<do_all exact="$imax - 1" counter="$i">
<do_if value="$wareslist_prio.{$i} lt $wareslist_prio.{$i+1}">
<set_value name="$tmp_ware" exact="$wareslist.{$i}"/>
<set_value name="$tmp_prio" exact="$wareslist_prio.{$i}"/>
<set_value name="$wareslist.{$i}" exact="$wareslist.{$i+1}"/>
<set_value name="$wareslist_prio.{$i}" exact="$wareslist_prio.{$i+1}"/>
<set_value name="$wareslist.{$i+1}" exact="$tmp_ware"/>
<set_value name="$wareslist_prio.{$i+1}" exact="$tmp_prio"/>
</do_if>
</do_all>
</do_all>
<debug_text filter="general" chance="@this.$debug * 100" text="'%1 %2 %3 Mineable List sorted:\n%4\n%5'.[player.age,this.name,this.container.name,$wareslist,$wareslist_prio]"/>
<!-- nothing to mine - aborting -->
<do_if value="$wareslist.count == 0">
<!--do_if value="$params.$gascollectormk1quota?">
<stop_mass_traffic_quota quota="$params.$gascollectormk1quota"/>
<remove_value name="$params.$gascollectormk1quota"/>
</do_if>
<do_if value="$params.$gascollectormk2quota?">
<stop_mass_traffic_quota quota="$params.$gascollectormk2quota"/>
<remove_value name="$params.$gascollectormk2quota"/>
</do_if-->
<return/>
</do_if>
<label name="start mining"/>
<!-- Starting Mining with the most important Ressource we can actively Mine -->
<set_command command="command.freemining"/>
<do_if value="this.$ut_cac?">
<set_value name="this.$ut_cac.$isactive"/>
</do_if>
<get_resource_gatherrate name="$gatherrate" refobject="this.container" zone="this.zone" ware="$wareslist.{1}" />
<do_if value="$gatherrate" max="0">
<debug_text filter="error" text="'%1 %2 %3 Gatherrate is 0 (should not happen) - aborting'.[player.age,this.name,this.container.name]"/>
<return/>
</do_if>
<set_value name="$gatherrate" exact="$gatherrate / 3" comment="Station Gas Mining is only 30% as effective as it could be"/>
<add_ware_reservation object="this.container" entity="this" ware="$wareslist.{1}" amount="$gatherrate * $next_call" type="sell"/>
<!-- save values to $params to add Ressources on the next call -->
<set_value name="$params.$gatherstart" exact="player.age" />
<set_value name="$params.$gatherrate" exact="$gatherrate" />
<set_value name="$params.$gatherware" exact="$wareslist.{1}" />
<debug_text filter="general" chance="@this.$debug * 100" text="'%1 %2 %3 Gathering started'.[player.age,this.name,this.container.name]"/>
<!-- launch drones to collect gas - only for show -->
<!-- Better method, but owner faction not set-able, so using old method.. -->
<!--do_if value="not $params.$gascollectormk1quota?">
<add_mass_traffic_quota quota="$params.$gascollectormk1quota" zone="this.zone" start="this.container" end="this.container" macro="macro.units_size_drone_liquid_collector_mk1_macro" amount="this.container.units.{unitcategory.gascollector}.mk.{1}.count" />
</do_if>
<do_if value="not $params.$gascollectormk2quota?">
<add_mass_traffic_quota quota="$params.$gascollectormk2quota" zone="this.zone" start="this.container" end="this.container" macro="macro.units_size_drone_liquid_collector_mk2_macro" amount="this.container.units.{unitcategory.gascollector}.mk.{2}.count" />
</do_if-->
<do_if value="this.container.attention ge attention.visible">
<debug_text filter="general" chance="@this.$debug * 100" text="'launching Drones'"/>
<find_object_component groupname="$dronelaunchbays" object="this.container" multiple="true" class="class.dronelaunchpad" checkoperational="true"/>
<create_group groupname="$drones"/>
<!-- launching about half the Drones available so we can also laumch some on the next cycle in case they didnt return yet -->
<do_while value="($drones.count lt this.container.units.{unitcategory.gascollector}.count / 3 or $drones.count lt 15 ) and this.container.availableunits.{unitcategory.gascollector}.count">
<do_all exact="$dronelaunchbays.count" counter="$i">
<launch_drone groupname="$drones" object="$dronelaunchbays.{$i}" group="unitcategory.gascollector" exact="1"/>
</do_all>
</do_while>
<debug_text filter="general" chance="@this.$debug * 100" text="'Launched %1 Drones from %2 launch bays'.[$drones.count,$dronelaunchbays.count]"/>
<do_all exact="$drones.count" counter="$i">
<do_if value="$drones.{$i}.isoperational">
<!-- ToDo: needs a better Script -->
<start_script name="'ut.cac.com.drone.gatherressources'" object="$drones.{$i}.pilot">
<param name="homebase" value="this.container"/>
<param name="ware" value="$params.$gatherware"/>
</start_script>
</do_if>
</do_all>
</do_if>
</actions>
</attention>
</aiscript>