-
Notifications
You must be signed in to change notification settings - Fork 2
/
SMRFileWriter.java
104 lines (98 loc) · 2.36 KB
/
SMRFileWriter.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
package controller.fileaccess;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import model.Connection;
import model.Good;
import model.Sector;
public class SMRFileWriter
{
// public static String[] variableNames = {"Sector", "Right", "Left", "Up", "Down", "Warp", "Port Level", "Port Race", "Buys", "Sells","Planet", "Locations"};
public static void writeMap(FileWriter mapFile, Sector[] sectors)
{
try {
boolean b;
mapFile.write("SMR1.5 Sectors File v 1.01\r\n");
for(Sector sec : sectors)
{
if(sec != null)
{
mapFile.write("[Sector="+sec.getSectorID()+"]\r\n");
if(sec.hasConnections())
{
Iterator<Connection> iter = sec.getConnections().iterator();
String warps = "Warp=";
b = false;
while(iter.hasNext())
{
Connection c = iter.next();
if(c.getType().equals(Connection.WARP))
{
warps += c.getTargetSector()+",";
b=true;
}
else
mapFile.write(c.getType()+"="+c.getTargetSector()+"\r\n");
}
if(b)
{
mapFile.write(warps.substring(0, warps.length()-1)+"\r\n");
}
}
if(sec.hasPort())
{
mapFile.write("Port Level="+sec.getPort().getPortLevel()+"\r\nPort Race="+sec.getPort().getPortRace()+"\r\n");
Good[] goods = sec.getPort().getGoods();
b = false;
String temp="Buys=";
for(Good g : goods)
{
if(g.state==Good.BUYS)
{
temp += g.goodId+":"+g.getDistanceIndex()+",";
b=true;
}
}
if(b)
{
mapFile.write(temp.substring(0, temp.length()-1)+"\r\n");
}
b=false;
temp="Sells=";
for(Good g : goods)
{
if(g.state==Good.SELLS)
{
temp += g.goodId+":"+g.getDistanceIndex()+",";
b=true;
}
}
if(b)
{
mapFile.write(temp.substring(0, temp.length()-1) +"\r\n");
}
}
if(sec.hasPlanet())
{
mapFile.write("Planet=1\r\n");
}
if(sec.hasLocation())
{
Iterator<String> iter = sec.getLocations().iterator();
String temp = "Location=";
while(iter.hasNext())
{
temp += iter.next()+",";
}
mapFile.write(temp.substring(0, temp.length()-1) +"\r\n");
}
}
}
mapFile.flush();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}