-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanetTrader2_5.java
executable file
·260 lines (224 loc) · 8.23 KB
/
PlanetTrader2_5.java
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import com.swath.*;
import com.swath.cmd.*;
import java.util.*;
/**
* Dana's Automatic Planet Trader 2.5
*
* @author Mind Dagger
*/
public class PlanetTrader2_5 extends UserDefinedScript {
private Parameter output;
private List allSectors;
public final static int PORT_MAX = 65530;
private Parameter planet;
private Parameter noCIM;
private Parameter xBB;
private Parameter xxB;
private Parameter xBx;
private Parameter minProduct;
private Planet[] planets;
private Planet currentPlanet;
private int firstSector;
private int creditsStart;
private int sectorCount = 0;
private int organicsStart;
private int equipmentStart;
public String getName() {
return "Dana's Planet Trader 2.5";
}
public boolean initScript() throws Exception {
if (!atPrompt(Swath.COMMAND_PROMPT)) return false;
planets = Swath.sector.planets();
planet = new Parameter("Planet With Product To Sell");
for(int i=0;i < planets.length; i++)
{
planet.addChoice(i, planets[i].toString());
}
planet.setCurrentChoice(0);
minProduct = new Parameter("BUY Port Minimum Product");
minProduct.setType(Parameter.INTEGER);
minProduct.setInteger(1000);
noCIM = new Parameter("Skip Info Download? (less accurate)");
noCIM.setType(Parameter.BOOLEAN);
noCIM.setBoolean(false);
xBB = new Parameter("Visit xBB Ports");
xBB.setType(Parameter.BOOLEAN);
xBB.setBoolean(true);
xxB = new Parameter("Visit xBx Ports");
xxB.setType(Parameter.BOOLEAN);
xxB.setBoolean(true);
xBx = new Parameter("Visit xxB Ports");
xBx.setType(Parameter.BOOLEAN);
xBx.setBoolean(true);
output = new Parameter("Output Should Go To");
output.setType(Parameter.CHOICE);
output.addChoice(0,"Swath Console");
output.addChoice(1,"SubSpace Radio");
output.addChoice(2,"None");
output.setCurrentChoice(0);
registerParam(output);
registerParam(planet);
registerParam(minProduct);
registerParam(xBB);
registerParam(xBx);
registerParam(xxB);
registerParam(noCIM);
return true;
}
public boolean runScript() throws Exception {
currentPlanet = (Planet)(planets[planet.getCurrentChoice()]);
firstSector = Swath.sector.sector();
allSectors = new ArrayList();
DisplayCurrentInfo.exec();
creditsStart = Swath.you.credits();
findAllBuyingPorts();
Iterator itr = allSectors.iterator();
Sector tempSector;
Land.exec(currentPlanet);
LiftOff.exec();
organicsStart = currentPlanet.productAmounts()[Swath.ORGANICS];
equipmentStart = currentPlanet.productAmounts()[Swath.EQUIPMENT];
int[] products = currentPlanet.productAmounts();
while((itr.hasNext()) && (products[Swath.ORGANICS] > 1000 || products[Swath.EQUIPMENT] > 1000))
{
tempSector = (Sector)itr.next();
if((tempSector.portAmounts()[Swath.ORGANICS] >= minProduct.getInteger() && tempSector.portInfo()[Swath.ORGANICS] == Sector.BUYING) || (tempSector.portAmounts()[Swath.EQUIPMENT] >= minProduct.getInteger() && tempSector.portInfo()[Swath.EQUIPMENT] == Sector.BUYING)){
Land.exec(currentPlanet);
EnterCitadel.exec();
try{
PlanetWarp.exec(tempSector);
sectorCount++;
}
catch(Exception e){
//output("Sector "+tempSector+" does not have friendly fighters in it. Skipping this sector.");
}
LeaveCitadel.exec();
LiftOff.exec();
DisplaySector.exec();
EnterComputer.exec();
PortReport.exec(Swath.sector);
LeaveComputer.exec();
if(Swath.sector.portStatus() == Sector.PORT_AVAILABLE){
PlanetaryTrade.exec(currentPlanet,0,Swath.sector.portAmounts()[Swath.ORGANICS],Swath.sector.portAmounts()[Swath.EQUIPMENT]);
currentPlanet = Swath.getPlanet(currentPlanet.id());
products = currentPlanet.productAmounts();
if(products[Swath.FUEL_ORE] < 20000){
DisplaySector.exec();
EnterComputer.exec();
PortReport.exec(Swath.sector.sector());
LeaveComputer.exec();
while(Swath.sector.portAmounts()[Swath.FUEL_ORE] > 500 && Swath.sector.portInfo()[Swath.FUEL_ORE] == Sector.SELLING && products[Swath.FUEL_ORE] < 50000){
Trade.exec(Swath.ship.holds(),0,0);
Land.exec(currentPlanet);
TakeLeaveProducts.exec(-1*Swath.ship.fuel(),0,0);
LiftOff.exec();
currentPlanet = Swath.getPlanet(currentPlanet.id());
products = currentPlanet.productAmounts();
}
}
}
}
}
Land.exec(currentPlanet);
EnterCitadel.exec();
PlanetWarp.exec(firstSector);
LeaveCitadel.exec();
LiftOff.exec();
output("\nSectors visited: "+sectorCount+"\nCredits Made: "+(Swath.you.credits()-creditsStart)+"\nOrganics Sold: "+(organicsStart-currentPlanet.productAmounts()[Swath.ORGANICS])+"\nEquipment Sold: "+(equipmentStart-currentPlanet.productAmounts()[Swath.EQUIPMENT]));
output("Sectors visited: "+sectorCount+",Credits Made: "+(Swath.you.credits()-creditsStart));
return true;
}
private void findAllBuyingPorts() throws Exception{
if(!noCIM.getBoolean()){
output("Downloading all recent port data..");
CIMDownload.exec(false,true);
output("Downloading current fighter deployment..");
ShowDeployedFighters.exec();
}
Tools.PortSearchParameters xBBpass = new Tools.PortSearchParameters();
xBBpass.setMaxAmount(Swath.EQUIPMENT,PORT_MAX);
xBBpass.setMinAmount(Swath.EQUIPMENT,minProduct.getInteger());
xBBpass.setMaxAmount(Swath.ORGANICS,PORT_MAX);
xBBpass.setMinAmount(Swath.ORGANICS,minProduct.getInteger());
xBBpass.setPortOption(Swath.EQUIPMENT,true);
xBBpass.setPortOption(Swath.ORGANICS,true);
Tools.PortSearchParameters xxBpass = new Tools.PortSearchParameters();
xxBpass.setMaxAmount(Swath.EQUIPMENT,PORT_MAX);
xxBpass.setMinAmount(Swath.EQUIPMENT,minProduct.getInteger());
xxBpass.setPortOption(Swath.EQUIPMENT,true);
Tools.PortSearchParameters xBxpass = new Tools.PortSearchParameters();
xxBpass.setMaxAmount(Swath.ORGANICS,PORT_MAX);
xxBpass.setMinAmount(Swath.ORGANICS,minProduct.getInteger());
xxBpass.setPortOption(Swath.ORGANICS,true);
output("Searching known ports..");
int[] xBBResults,xBxResults,xxBResults;
xBBResults = null;
xBxResults = null;
xxBResults = null;
List throwAway = new ArrayList();
allSectors = null;
if(xBB.getBoolean()){
output("Starting xBB pass...");
xBBResults = Tools.findPorts(xBBpass,true,-1);
output("Pass completed.. "+xBBResults.length+" Buying sectors found.");
}
if(xxB.getBoolean()){
output("Starting xxB pass...");
xxBResults = Tools.findPorts(xxBpass,true,-1);
output("Pass completed.. "+xxBResults.length+" Buying sectors found.");
}
if(xBx.getBoolean()){
output("Starting xBx pass...");
xBxResults = Tools.findPorts(xBxpass,true,-1);
output("Pass completed.. "+xBxResults.length+" Buying sectors found.");
}
allSectors = new ArrayList();
if(xBB.getBoolean()){
for(int i = 0; i < xBBResults.length; i++){
allSectors.add(Swath.getSector(xBBResults[i]));
}
}
if(xxB.getBoolean()){
for(int i = 0; i < xxBResults.length; i++){
allSectors.add(Swath.getSector(xxBResults[i]));
}
}
if(xBx.getBoolean()){
for(int i = 0; i < xBxResults.length; i++){
allSectors.add(Swath.getSector(xBxResults[i]));
}
}
Iterator itr2 = allSectors.iterator();
while(itr2.hasNext()){
Sector temp = (Sector)itr2.next();
if(temp.isFedSpace()){
throwAway.add(temp);
}
else if(!(temp.ftrOwner().isYou() || temp.ftrOwner().isYourCorporation())){
throwAway.add(temp);
}
else if(temp.busted() != null){
throwAway.add(temp);
}
}
output(allSectors.size()+" total Buying Ports found before removing bad sectors.");
output("Removing invalid sectors..");
Iterator throwAwayItr = throwAway.iterator();
while(throwAwayItr.hasNext()){
allSectors.remove((Sector)throwAwayItr.next());
}
output(allSectors.size()+" total good Buying Ports found.");
}
private void output(String message) throws Exception{
String m = message;
if(output.getCurrentChoice() == 0){
UserAlert.exec(m,UserAlert.TYPE_INFORMATION);
}
else if(output.getCurrentChoice() == 1){
SendSSRadioMessage.exec(m);
}
else{
//No Output
}
}
}