-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastSurround.java
executable file
·294 lines (259 loc) · 8.8 KB
/
FastSurround.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import com.swath.*;
//Command to surround a sector with fighters and limpets.
//Author Mind Dagger
public class FastSurround extends UserDefinedCommand {
private int maxFigAttack;
private int layfigs;
private int layLimpets;
private int sector;
//private int displayCount;
private int[] surroundingSectors;
private final static int ONE_WAY = 1;
private final static int BOTH_WAY = 0;
private final static int AVOIDED = 2;
private final static int NOT_AVOIDED = 3;
private final static int ANOMALY = 4;
private final static int NO_ANOMALY = 5;
private int[] oneways;
private int[] avoided;
private int[] anomalies;
private String[] sectors;
boolean noScanner;
public String getName() {
return "Fast Surround";
}
public boolean initCommand() throws Exception {
// Initialisation of the command is done in this method.
// All parameters should be created and registered here.
// If something goes wrong, throw a CommandException or return false.
// Check that we are at the correct prompt
if (!atPrompt(Swath.COMMAND_PROMPT)) {
throw new CommandException(this, "Not at correct prompt");
}
//surroundingSectors = Swath.sector.warpSectors();
sector = Swath.sector.sector();
//displayCount = 0;
noScanner = false;
surroundingSectors = Swath.sector.warpSectors();
oneways = new int[surroundingSectors.length];
avoided = new int[surroundingSectors.length];
anomalies = new int[surroundingSectors.length];
sectors = new String[surroundingSectors.length];
return true;
}
public void startCommand() throws Exception {
String input = "d";
if(Swath.ship != null && Swath.ship.hasDensityScanner()){
input += "sd";
}
if(Swath.ship != null && Swath.ship.hasHoloScanner()){
input += "sh";
}
else{
input += "?";
noScanner = true;
}
input += "cx";
if(Swath.ship == null || !Swath.ship.hasHoloScanner()){
input += "q^";
for(int i = 0; i < surroundingSectors.length; i++){
input += "f"+surroundingSectors[i]+RETURN_KEY+Swath.sector.sector()+RETURN_KEY;
}
}
else{
for(int i = 0; i < surroundingSectors.length; i++){
input += "i"+surroundingSectors[i]+RETURN_KEY;
}
}
input += "q?";
//input += "'Starting MD Surround.."+RETURN_KEY+"?";
sendString(input);
//sendString(input);
}
public void endCommand(boolean result) throws Exception {
//sendString("'(MD Surround) Sector "+sector+" surrounded."+RETURN_KEY);
}
public void onText(String buffer, String text) throws Exception {
// Incoming text is sent to this method when it arrives.
// The text parameter only contains the new text that arrived
// and the buffer contains all text received so far.
// The buffer can be cleared or updated using the setTextBuffer method.
Tools.TextRange range;
if((range = Tools.findText(buffer,"Relative Density Scan","Computer command [")) != null){
String info = Tools.getText(buffer, range);
for(int i = 0; i < surroundingSectors.length; i++){
String[] data = info.split("\n");
for(int j = 0; j < data.length; j++){
if(data[j].indexOf(surroundingSectors[i]+" ==>") >= 0 && data[j].indexOf("Anom : Yes") >= 0){
anomalies[i] = ANOMALY;
}
else if(data[j].indexOf(surroundingSectors[i]+" ==>") >= 0 && data[j].indexOf("Anom : No") >= 0){
anomalies[i] = NO_ANOMALY;
}
else{
anomalies[i] = NO_ANOMALY;
}
}
}
}
if ((range = ((Tools.findText(buffer, "<Computer activated>","<Computer deactivated>")))) != null) {
String info = Tools.getText(buffer, range);
range = Tools.findText(info,"<List Avoided Sectors>","Computer command [");
String avoidText = Tools.getText(info,range);
for(int i = 0; i < surroundingSectors.length; i++){
if(avoidText.indexOf(" "+surroundingSectors[i]+" ") >= 0 || avoidText.indexOf(" "+surroundingSectors[i]+"\n") >= 0){
avoided[i] = AVOIDED;
}
else{
avoided[i] = NOT_AVOIDED;
}
}
if(avoidText.indexOf(" "+Swath.sector.sector()+" ") >= 0 || avoidText.indexOf(" "+Swath.sector.sector()+"\n") >= 0){
throw new CommandException(this,"Can't Run FastSurround From An Avoided Sector.. ("+Swath.sector.sector()+")");
}
if(noScanner || (Swath.ship != null && !Swath.ship.hasHoloScanner())){
}
else{
String[] data = info.split("\n");
if(data != null){
int count = 0;
for(int i = 0; i < data.length; i++){
if(data[i].indexOf(" has warps to sector(s) :") < 0){
data[i] = "";
}
else{
sectors[count] = data[i]+"#";
count++;
}
}
for(int i = 0; i < sectors.length; i++){
if(sectors[i] != null){
if(sectors[i].indexOf(" "+sector+" ") >= 0 || sectors[i].indexOf(sector+"#") >= 0 || sectors[i].indexOf("warps to sector(s) : "+sector) >= 0){
oneways[i] = BOTH_WAY;
}
else{
oneways[i] = ONE_WAY;
}
}
}
}
setBufferText("Starting MD Surround..");
Move();
}
}
if((range = Tools.findText(buffer,"FM >",": ENDINTERROG")) != null){
String info = Tools.getText(buffer, range);
for(int i = 0; i < surroundingSectors.length; i++){
if(info.indexOf(surroundingSectors[i]+" > "+sector) >= 0){
oneways[i] = BOTH_WAY;
}
else{
oneways[i] = ONE_WAY;
}
}
setBufferText("Starting MD Surround..");
Move();
}
if((range = Tools.findText(buffer,"Starting MD Surround..","(MD Surround)")) != null){
printTrace("Here..");
}
}
public static void exec() throws Exception {
FastSurround cmd = new FastSurround();
cmd.initInstance();
if(Swath.ship != null && Swath.ship.shipCategory() != null && (cmd.maxFigAttack = Swath.ship.shipCategory().maxFightersPerAttack()) > 0){
}
else{
cmd.maxFigAttack = 9999;
}
cmd.layfigs = 1;
cmd.layLimpets = 2;
cmd.execInstance();
}
public static void exec(int maxFigAttack,int layfigs, int layLimpets) throws Exception {
FastSurround cmd = new FastSurround();
cmd.initInstance();
cmd.maxFigAttack = maxFigAttack;
cmd.layfigs = layfigs;
cmd.layLimpets = layLimpets;
cmd.execInstance();
}
private String layFigs(int numOfFigs) throws Exception{
String result = new String();
if(Swath.you.corporation() != null){
result += "f "+numOfFigs+" "+RETURN_KEY+" c t ";
}
else{
result += "f "+numOfFigs+" "+RETURN_KEY+" t ";
}
return result;
}
private String layLimpets(int numOfLimpets) throws Exception{
String result = new String();
if(Swath.you.corporation() != null){
result += "h 2 z"+numOfLimpets+" "+RETURN_KEY+" c q"+RETURN_KEY;
}
else{
result += "h 2 z"+numOfLimpets+" "+RETURN_KEY+" ";
}
return result;
}
private void Move() throws Exception {
for(int i = 0; i < surroundingSectors.length; i++){
Sector next = Swath.getSector(surroundingSectors[i]);
if(noScanner){
if(oneways[i] == BOTH_WAY && avoided[i] == NOT_AVOIDED){
sendString("m"+surroundingSectors[i]+RETURN_KEY+" za");
if( maxFigAttack > Swath.ship.fighters()){
sendString(""+Swath.ship.fighters());
}
else{
sendString(maxFigAttack+"");
}
sendString(RETURN_KEY+" "+RETURN_KEY+" ");
if(!next.isFedSpace()){
if(layfigs >= 1){
sendString(layFigs(layfigs));
}
if(layLimpets > 0 && Swath.ship.limpetMines() > 0){
if(layLimpets <= Swath.ship.limpetMines() && next.limpetMines() <= 0){
sendString(layLimpets(layLimpets));
}
else{
sendString(layLimpets(1));
}
}
}
sendString("m"+sector+RETURN_KEY+" "+RETURN_KEY+" ");
}
}
else{
if(oneways[i] == BOTH_WAY && avoided[i] == NOT_AVOIDED && ((!next.isFedSpace() && (next.fighters() <= 0 || !(next.ftrOwner().isYou() || next.ftrOwner().isYourCorporation()) || (anomalies[i] == NO_ANOMALY && Swath.ship.limpetMines() > 0))))){
sendString("m"+surroundingSectors[i]+RETURN_KEY+" za");
if( maxFigAttack > Swath.ship.fighters()){
sendString(""+Swath.ship.fighters());
}
else{
sendString(maxFigAttack+"");
}
sendString(RETURN_KEY+" "+RETURN_KEY+" ");
if(!next.isFedSpace()){
if(layfigs >= 1){
sendString(layFigs(layfigs));
}
if(layLimpets > 0 && Swath.ship.limpetMines() > 0){
if(layLimpets <= Swath.ship.limpetMines() && next.limpetMines() <= 0){
sendString(layLimpets(layLimpets));
}
else{
sendString(layLimpets(1));
}
}
}
sendString("m"+sector+RETURN_KEY+" "+RETURN_KEY+" ");
}
}
}
//sendString("'(MD Surround) Sector "+sector+" surrounded."+RETURN_KEY);
}
}