|
|
@ -3,8 +3,10 @@ package sig.map; |
|
|
|
import java.io.DataInputStream; |
|
|
|
import java.io.DataInputStream; |
|
|
|
import java.io.DataOutputStream; |
|
|
|
import java.io.DataOutputStream; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
|
|
import sig.RabiClone; |
|
|
|
import sig.RabiClone; |
|
|
|
import sig.engine.Sprite; |
|
|
|
import sig.engine.Sprite; |
|
|
@ -13,6 +15,7 @@ public class Map { |
|
|
|
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
|
|
|
|
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
|
|
|
|
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
|
|
|
|
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
//Starts with 294912 bytes for visual tiles.
|
|
|
|
//After the map data, the next 1024 bytes will indicate the map view information.
|
|
|
|
//After the map data, the next 1024 bytes will indicate the map view information.
|
|
|
|
//After that, the next 1024 bytes will indicate the background information.
|
|
|
|
//After that, the next 1024 bytes will indicate the background information.
|
|
|
|
//After that, the next 1024 bytes will indicate the map color information.
|
|
|
|
//After that, the next 1024 bytes will indicate the map color information.
|
|
|
@ -45,7 +48,14 @@ public class Map { |
|
|
|
|
|
|
|
|
|
|
|
public static Map LoadMap(Maps map) { |
|
|
|
public static Map LoadMap(Maps map) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Map newMap = new Map(); |
|
|
|
if (RabiClone.CURRENT_MAP!=map) { |
|
|
|
|
|
|
|
resetMapData(RabiClone.CURRENT_MAP.getMap()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resetAndReloadEventData(RabiClone.CURRENT_MAP); |
|
|
|
|
|
|
|
return RabiClone.CURRENT_MAP.getMap(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
RabiClone.CURRENT_MAP=map; |
|
|
|
|
|
|
|
Map newMap = RabiClone.CURRENT_MAP.getMap()!=null?RabiClone.CURRENT_MAP.getMap():new Map(); |
|
|
|
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile())); |
|
|
|
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile())); |
|
|
|
int marker=0; |
|
|
|
int marker=0; |
|
|
|
int iterationCount=MAP_WIDTH*MAP_HEIGHT; |
|
|
|
int iterationCount=MAP_WIDTH*MAP_HEIGHT; |
|
|
@ -107,6 +117,41 @@ public class Map { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void resetAndReloadEventData(Maps map) { |
|
|
|
|
|
|
|
Arrays.fill(map.getMap().data,(char)0); |
|
|
|
|
|
|
|
map.getMap().eventTileCount=0; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile())); |
|
|
|
|
|
|
|
final long requestBytes = 294912+1024+1024+1024+1024; |
|
|
|
|
|
|
|
long actualBytes = stream.skip(requestBytes); |
|
|
|
|
|
|
|
if (actualBytes!=requestBytes) { |
|
|
|
|
|
|
|
stream.close(); |
|
|
|
|
|
|
|
throw new IOException("Could not read "+requestBytes+" bytes! Read "+actualBytes+" instead."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map.getMap().eventTileCount=stream.readInt(); |
|
|
|
|
|
|
|
int remainingCount = map.getMap().eventTileCount; |
|
|
|
|
|
|
|
while (remainingCount-->0) { |
|
|
|
|
|
|
|
int dataPacket = stream.readInt(); |
|
|
|
|
|
|
|
//First 14 bits are event info. Last 18 bits are index info.
|
|
|
|
|
|
|
|
char event = (char)(dataPacket>>>18); |
|
|
|
|
|
|
|
int index = dataPacket&0b00000000000000111111111111111111; |
|
|
|
|
|
|
|
map.getMap().data[index]=event; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
stream.close(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void resetMapData(Map newMap) { |
|
|
|
|
|
|
|
Arrays.fill(newMap.tiles,(char)0); |
|
|
|
|
|
|
|
Arrays.fill(newMap.views,(byte)0); |
|
|
|
|
|
|
|
Arrays.fill(newMap.backgrounds,(byte)0); |
|
|
|
|
|
|
|
Arrays.fill(newMap.colors,(byte)0); |
|
|
|
|
|
|
|
Arrays.fill(newMap.types,(byte)0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void SaveMap(Maps map) throws IOException { |
|
|
|
public static void SaveMap(Maps map) throws IOException { |
|
|
|
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile())); |
|
|
|
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile())); |
|
|
|
saveCharData(stream,map.map.tiles); |
|
|
|
saveCharData(stream,map.map.tiles); |
|
|
@ -158,4 +203,16 @@ public class Map { |
|
|
|
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal()); |
|
|
|
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal()); |
|
|
|
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
|
|
|
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ModifyDataTile(int x,int y,DataTile t) { |
|
|
|
|
|
|
|
DataTile prevTile = DataTile.values()[data[y*Map.MAP_WIDTH+x]]; |
|
|
|
|
|
|
|
if (prevTile.ordinal()==0) { |
|
|
|
|
|
|
|
eventTileCount++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (t.ordinal()==0) { |
|
|
|
|
|
|
|
eventTileCount--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data[y*Map.MAP_WIDTH+x]=(char)(t.ordinal()); |
|
|
|
|
|
|
|
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|