--- /dev/null
+
+This lists some changes to files to support multiple maps.
+
+Map files
+---------
+
+Maps are encoded in a binary format and stored in multiple files under
+defMaps/
+
+The filename of the map is the name as referenced elsewhere.
+
+LivingThing
+-----------
+
+New parameter 'map' supplies the name of the map the thing is on.
+
+mobs
+----
+
+Added the map name to the mob entries. Changed the header name from
+'mob2.3' to 'mob'.
+
+mob
+Ent
+mainmap
+100
+100
+
+merchants
+---------
+
+Each entry in the merchants file now starts with
+
+mapname
+xlocation
+ylocation
+
+rather than xlocation.
+
+TODO: it needs more structure/consistency
+
+mainmap
+100
+100
+Wooden boots
+end
+
+
+signs
+-----
+
+Added map to location
+
+TODO: it needs more structure/consistency
+
+some sign text
+mapname
+100
+100
+
+props
+-----
+
+Added map to location
+
+prop type
+mapname
+100
+100
}
}
- TileMap map = new TileMap(tmap.getWidth(), tmap.getHeight());
+ TileMap map = new TileMap("main", tmap.getWidth(), tmap.getHeight());
int lid = 0;
// TODO: write out tileset info somewhere
- TileMap map = new TileMap(tmap.getWidth(), tmap.getHeight());
+ TileMap map = new TileMap(dst.getName(), tmap.getWidth(), tmap.getHeight());
int lid = 0;
}
}
+ if (twidth == 0 || theight == 0)
+ throw new IOException("Couldn't find a layer called 'ground'");
+
System.out.printf("Found %d layers\n", nlayers);
System.out.printf("Ground on layer %d\n", groundid);
// Create map
public static void main(String[] args) throws IOException {
//testimport(new File("/home/notzed/house.tmx"),
// new File("/home/notzed/house.jar"));
- tiledToDusk(new File("/home/notzed/test-map.tmx"),
- new File("/home/notzed/test-map.bin"));
+ //tiledToDusk(new File("/home/notzed/test-map.tmx"),
+ // new File("/home/notzed/test-map.bin"));
+ tiledToDusk(new File("/home/notzed/dusk/maps/do-drop-inn.tmx"),
+ new File("/home/notzed/src/DuskRPG/DuskFiles/DuskX/defMaps/do-drop-inn"));
//testexport();
}
}
thnFront1 = thnFront1.getMaster();
}
thnFront1 = inpla1;
- engGame.chatMessage("-" + inpla1.name + " has attacked " + inpla2.name, inpla1.x, inpla1.y, "default");
+ engGame.chatMessage(inpla1.map, "-" + inpla1.name + " has attacked " + inpla2.name, inpla1.x, inpla1.y, "default");
inpla1.startBattle(inpla2);
inpla2.startBattle(inpla1);
} catch (Exception e) {
hitMessage(attackee.getID(), 0, attackee.hp, attackee.maxhp, attackor.getID(), "Dodged!");
} else {
if (engGame.battlesound != -1) {
- engGame.playSound(engGame.battlesound, attackee.x, attackee.y);
+ engGame.playSound(attackor.map, engGame.battlesound, attackee.x, attackee.y);
}
int i = damRoll(attackor, attackee, range);
if (i < 0) {
updateFlags(vctSide2, thnFront2.getFollowing().ID, 0);
thnFront2.getFollowing().leaveBattle();
thnFront2.getFollowing().damageDone = 0;
- thnFront2.getFollowing().changeLocBypass(thnFront2.x, thnFront2.y);
+ thnFront2.getFollowing().changeLocBypass(thnFront2.map, thnFront2.x, thnFront2.y);
}
} else if (thnFront2.isMob()) {
Mob mob = (Mob) thnFront2;
import duskz.server.entity.Equipment;
import duskz.server.entity.PlayerMerchant;
import duskz.server.entity.LivingThing;
+import duskz.server.entity.TileMap;
import java.io.*;
import java.util.LinkedList;
import java.util.StringTokenizer;
String strMapLog = "shortmap_redraw";
try (PrintStream psMap = new PrintStream(new FileOutputStream(strMapLog, true), true)) {
- game.changeMap(lt.x, lt.y, Short.parseShort(cmdline));
+ game.changeMap(lt, lt.x, lt.y, Short.parseShort(cmdline));
psMap.println("changetile " + lt.x + " " + lt.y + " " + Short.parseShort(cmdline));
return null;
} catch (Exception e) {
game.saveMap();
return "Game settings saved";
} else if (cmdline.equalsIgnoreCase("merchant")) {
- if (game.overMerchant(lt.x, lt.y) != null) {
+ if (lt.overMerchant() != null) {
return "There's already a merchant there.";
}
- if (game.overPlayerMerchant(lt.x, lt.y) != null) {
+ if (lt.overPlayerMerchant() != null) {
return "There's already a merchant there.";
}
Merchant mrcStore = new Merchant(game);
mrcStore.y = lt.y;
//game.vctMerchants.add(mrcStore);
//game.blnMerchantListChanged = true;
- game.addDuskObject(mrcStore);
+ game.addDuskObject(lt.map, mrcStore);
return null;
} else if (cmdline.toLowerCase().startsWith("prop ")) {
if (cmdline.length() == 5) {
prpStore.y = lt.y;
//game.vctProps.addElement(prpStore);
//game.blnPropListChanged = true;
- game.addDuskObject(prpStore);
+ game.addDuskObject(lt.map, prpStore);
}
return null;
} else if (cmdline.startsWith("sign ")) {
Sign sgnStore = new Sign(game, "sign", cmdline.substring(5), lt.x, lt.y, game.getID());
//game.vctSigns.add(sgnStore);
//game.blnSignListChanged = true;
- game.addDuskObject(sgnStore);
+ game.addDuskObject(lt.map, sgnStore);
return null;
}
Item itmStore = game.getItem(cmdline);
itmStore.x = lt.x;
itmStore.y = lt.y;
//game.vctItems.add(itmStore);
- game.addDuskObject(itmStore);
+ game.addDuskObject(lt.map, itmStore);
return null;
}
try {
// TODO: this previously didn't call addDuskObject - bug or intentional?
//game.vctMobs.addElement(mob);
//game.blnMobListChanged = true;
- game.addDuskObject(mob);
+ game.addDuskObject(lt.map, mob);
- mob.changeLocBypass(lt.x, lt.y);
+ mob.changeLocBypass(lt.map, lt.x, lt.y);
} catch (Exception e) {
game.log.printError("parseCommand():While creating mob \"" + cmdline + "\"", e);
}
thnStore.chatMessage("You have been kicked out of " + lt.clan + ".");
thnStore.clan = "none";
game.removeDuskObject(thnStore);
- game.addDuskObject(thnStore);
+ game.addDuskObject(thnStore.map, thnStore);
return thnStore.name + " has been kicked out of your clan.";
}
// if (lt.privs > 2) {
if (lt.privs <= 4)
return "Huh?";
game.log.printMessage(Log.INFO, "godcommand:" + lt.name + ":" + cmdline + ":" + lt.x + "," + lt.y);
- game.resizeMap(lt.x + 1, lt.y + 1);
+ game.resizeMap(lt.map, lt.x + 1, lt.y + 1);
return "Map resized";
case "shutdown":
if (lt.privs <= 4)
thnStore.chatMessage("You are now a member of the " + args + " clan.");
}
game.removeDuskObject(thnStore);
- game.addDuskObject(thnStore);
+ game.addDuskObject(thnStore.map, thnStore);
return thnStore.name + " is now a leader of the " + args + " clan.";
}
case "boot": {
charSep = '_';
}
try {
- int destX = Integer.parseInt(args.substring(0, args.lastIndexOf(charSep)));
- int destY = Integer.parseInt(args.substring(args.lastIndexOf(charSep) + 1));
- if (lt.privs < 5 && destX >= game.map.getCols()) {
- destX = game.map.getCols() - 1;
+ String[] params = args.split(" ");
+ TileMap map;
+ int destX, destY;
+ if (params.length == 3) {
+ map = game.maps.get(params[0]);
+ destX = Integer.parseInt(params[1]);
+ destY = Integer.parseInt(params[2]);
+ } else {
+ map = lt.map;
+ destX = Integer.parseInt(params[0]);
+ destY = Integer.parseInt(params[1]);
+ }
+ if (lt.privs < 5 && destX >= map.getCols()) {
+ destX = map.getCols() - 1;
}
- if (lt.privs < 5 && destY >= game.map.getRows()) {
- destY = game.map.getRows() - 1;
+ if (lt.privs < 5 && destY >= map.getRows()) {
+ destY = map.getRows() - 1;
}
if (destX < 0) {
destX = 0;
if (destY < 0) {
destY = 0;
}
- lt.changeLocBypass(destX, destY);
+ lt.changeLocBypass(map, destX, destY);
} catch (Exception e) {
LivingThing thnStore = game.getPlayer(args);
if (thnStore == null) {
return "Teleport to where?";
} else {
+ // Hmm, i'm not sure what this does, teleport to another player?
+ // Whats with the weird range checking?
int destX = thnStore.x;
int destY = thnStore.y;
if (lt.privs < 5 && destX > 349) {
if (destY < 0) {
destY = 0;
}
- lt.changeLocBypass(destX, destY);
+ lt.changeLocBypass(thnStore.map, destX, destY);
}
}
return null;
if (args == null) {
return "Madd what?";
}
- Merchant mrcStore = game.overMerchant(lt.x, lt.y);
+ Merchant mrcStore = lt.overMerchant();
if (mrcStore != null) {
game.log.printMessage(Log.INFO, "godcommand:" + lt.name + ":" + cmdline + ":" + lt.x + "," + lt.y);
mrcStore.items.add(args);
game.refreshEntities(lt);
} else {
- if (game.overPlayerMerchant(lt.x, lt.y) != null) {
+ if (lt.overPlayerMerchant() != null) {
return "You cannot add items to a player's merchant this way.";
}
return "You are not on a merchant.";
if (args == null) {
return "Mremove what?";
}
- Merchant mrcStore = game.overMerchant(lt.x, lt.y);
+ Merchant mrcStore = lt.overMerchant();
if (mrcStore != null) {
game.log.printMessage(Log.INFO, "godcommand:" + lt.name + ":" + cmdline + ":" + lt.x + "," + lt.y);
mrcStore.items.remove(args);
game.refreshEntities(lt);
} else {
- if (game.overPlayerMerchant(lt.x, lt.y) != null) {
+ if (lt.overPlayerMerchant() != null) {
return "You cannot remove items from a player's merchant this way.";
}
return "You are not on a merchant.";
lt.isSleeping = true;
lt.updateActions();
game.removeDuskObject(lt);
- game.addDuskObject(lt);
+ game.addDuskObject(lt.map, lt);
return "You go to sleep";
}
case "wake": {
lt.isSleeping = false;
lt.updateActions();
game.removeDuskObject(lt);
- game.addDuskObject(lt);
+ game.addDuskObject(lt.map, lt);
return "You wake up";
} else {
return "You are already awake";
}
*/
game.removeDuskObject(lt);
- game.addDuskObject(lt);
+ game.addDuskObject(lt.map, lt);
lt.updateStats();
return "Your race has been changed.";
}
}
if (!args.equals("")) {
if (lt.isPet()) {
- game.chatMessage("Pet " + lt.name + " says: " + args, lt.x, lt.y, lt.name);
+ game.chatMessage(lt.map, "Pet " + lt.name + " says: " + args, lt.x, lt.y, lt.name);
} else if (lt.isMob()) {
- game.chatMessage("Mob " + lt.name + " says: " + args, lt.x, lt.y, "default");
+ game.chatMessage(lt.map, "Mob " + lt.name + " says: " + args, lt.x, lt.y, "default");
} else {
long lTemp = lt.lastMessageStamp;
lt.lastMessageStamp = System.currentTimeMillis();
&& lt.hasCondition("invis2")) {
strPerson = "A god";
}
- game.chatMessage(strPerson + " says: " + args, lt.x, lt.y, lt.name);
+ game.chatMessage(lt.map, strPerson + " says: " + args, lt.x, lt.y, lt.name);
}
}
return null;
&& lt.hasCondition("invis2")) {
strPerson = "A god";
}
- game.chatMessage(strPerson + " " + args, lt.x, lt.y, lt.name);
+ game.chatMessage(lt.map, strPerson + " " + args, lt.x, lt.y, lt.name);
}
return null;
}
itmStore.y = lt.y;
if (itmStore.intCost != 0) {
//game.vctItems.add(itmStore);
- game.addDuskObject(itmStore);
+ game.addDuskObject(lt.map, itmStore);
lt.updateItems();
}
itmStore.onDropItem(game, lt);
} else if (quantity < 1) {
return "You can't buy less than one of something.";
}
- PlayerMerchant pmrStore = game.overPlayerMerchant(lt.x, lt.y);
+ PlayerMerchant pmrStore = lt.overPlayerMerchant();
if (pmrStore != null) {
long numItem = pmrStore.contains(args);
if (numItem > 0) {
}
}
- Merchant mrcStore = game.overMerchant(lt.x, lt.y);
+ Merchant mrcStore = lt.overMerchant();
if (mrcStore == null) {
return "Buy from whom?";
}
return "Sell what?";
}
- PlayerMerchant pmrStore = game.overPlayerMerchant(lt.x, lt.y);
+ PlayerMerchant pmrStore = lt.overPlayerMerchant();
if (pmrStore != null) {
if (lt.name.equalsIgnoreCase(pmrStore.strOwner)) {
int quantity = 1;
return "You cannot sell items to this merchant.";
}
- Merchant mrcStore = game.overMerchant(lt.x, lt.y);
+ Merchant mrcStore = lt.overMerchant();
if (mrcStore == null) {
return "Sell that to whom?";
}
return "unclan not implemented yet";
try {
/*
- lt.halt();
- lt.chatMessage("Are you sure you want to drop out of your clan? If so type yes.");
- if (lt.instream.readLine().equalsIgnoreCase("yes")) {
- lt.clan = "none";
- if (lt.privs == 1) {
- lt.privs = 0;
- }
- lt.proceed();
- game.removeDuskObject(lt);
- game.addDuskObject(lt);
- return "You have been removed from your clan.";
- }*/
+ lt.halt();
+ lt.chatMessage("Are you sure you want to drop out of your clan? If so type yes.");
+ if (lt.instream.readLine().equalsIgnoreCase("yes")) {
+ lt.clan = "none";
+ if (lt.privs == 1) {
+ lt.privs = 0;
+ }
+ lt.proceed();
+ game.removeDuskObject(lt);
+ game.addDuskObject(lt);
+ return "You have been removed from your clan.";
+ }*/
} catch (Exception e) {
game.log.printError("parseCommand():While " + lt.name + " was trying to dropout of their clan", e);
}
}
return "password changing not re-implemented yet";
/*
- try {
- lt.halt();
- lt.chatMessage("Enter your current password.");
- String strOldPass = lt.instream.readLine();
- if (!strOldPass.equals(lt.password)) {
- lt.proceed();
- return "Sorry, that is not your password.";
- }
- lt.chatMessage("Enter a new password.");
- String strNewPass = lt.instream.readLine();
- lt.chatMessage("Repeat that password.");
- String strNewPassRepeat = lt.instream.readLine();
- if (strNewPass == null) {
- lt.proceed();
- return "Not a valid password.";
- }
- if (!strNewPass.equals(strNewPassRepeat)) {
- lt.proceed();
- return "Sorry, those passwords do not match.";
- }
- lt.password = strNewPass;
- lt.proceed();
- return "Your password has now been changed.";
- } catch (Exception e) {
- game.log.printError("parseCommand():While " + lt.name + " was changing their password", e);
- }
- lt.proceed();
- */
+ try {
+ lt.halt();
+ lt.chatMessage("Enter your current password.");
+ String strOldPass = lt.instream.readLine();
+ if (!strOldPass.equals(lt.password)) {
+ lt.proceed();
+ return "Sorry, that is not your password.";
+ }
+ lt.chatMessage("Enter a new password.");
+ String strNewPass = lt.instream.readLine();
+ lt.chatMessage("Repeat that password.");
+ String strNewPassRepeat = lt.instream.readLine();
+ if (strNewPass == null) {
+ lt.proceed();
+ return "Not a valid password.";
+ }
+ if (!strNewPass.equals(strNewPassRepeat)) {
+ lt.proceed();
+ return "Sorry, those passwords do not match.";
+ }
+ lt.password = strNewPass;
+ lt.proceed();
+ return "Your password has now been changed.";
+ } catch (Exception e) {
+ game.log.printError("parseCommand():While " + lt.name + " was changing their password", e);
+ }
+ lt.proceed();
+ */
}
case "wear": {
//protected short shrMapOwnerPrivs[][];
//protected int intMapOwnerID[][];
//protected Config IDtoName;
- public TileMap map;
+ //public TileMap map;
+ public final HashMap<String, TileMap> maps = new HashMap<>();
final public List<Battle> battleList = new ArrayList<>();
// Indices of various Entities
final public HashSet<Merchant> merchantList = new HashSet<>();
try {
int x = 0,
y = 0;
- String strStore;
+ String line;
loadPrefs();
// Load Map
- File newmap = new File("defMaps/main");
+ File newmap = new File("defMaps");
if (newmap.exists()) {
- // FIXME: load multiple maps here
- log.printMessage(Log.INFO, "Loading Layered Map...");
- map = TileMap.loadLayered(newmap);
- log.printMessage(Log.VERBOSE, map.getCols() + "x" + map.getRows() + "x" + map.getLayerCount());
+ for (File mapfile : newmap.listFiles()) {
+ TileMap map;
+ log.printMessage(Log.INFO, "Loading Layered Maps...");
+ map = TileMap.loadLayered(mapfile);
+ maps.put(map.name, map);
+ log.printMessage(Log.VERBOSE, map.name + ": " + map.getCols() + "x" + map.getRows() + "x" + map.getLayerCount());
+ }
} else if ((newmap = new File("shortmapx")).exists()) {
+ TileMap map;
log.printMessage(Log.INFO, "Loading Map...");
map = TileMap.loadMapX(newmap);
+ maps.put("main", map);
log.printMessage(Log.VERBOSE, map.getCols() + "/" + map.getRows());
} else {
+ TileMap map;
newmap = new File("shortmap");
if (newmap.exists()) {
log.printMessage(Log.INFO, "Loading Map...");
map = TileMap.loadMap(newmap, TileMap.FORMAT_BYTE);
log.printMessage(Log.VERBOSE, map.getCols() + "/" + map.getRows());
}
+ maps.put("main", map);
}
log.printMessage(Log.INFO, "Map Loaded...");
rafFile.close();
}*/
+ // FIXME: use some sort of common file format or at least conventions
+ // between all these state files.
+
// Load Merchants
try {
rafFile = new RandomAccessFile("merchants", "r");
Merchant mrcStore;
log.printMessage(Log.INFO, "Loading Merchants...");
- strStore = rafFile.readLine();
- while (!(strStore == null || strStore.equals(""))) {
+ line = rafFile.readLine();
+ while (!(line == null || line.equals(""))) {
mrcStore = new Merchant(this);
- mrcStore.x = Integer.parseInt(strStore);
+ TileMap map = maps.get(line);
+ mrcStore.x = Integer.parseInt(rafFile.readLine());
mrcStore.y = Integer.parseInt(rafFile.readLine());
log.printMessage(Log.VERBOSE, "Merchant(" + mrcStore.x + "," + mrcStore.y + ")");
- strStore = rafFile.readLine();
- while (strStore != null && !strStore.equals("") && !strStore.equalsIgnoreCase("end")) {
- log.printMessage(Log.DEBUG, "\t" + strStore);
- mrcStore.items.add(strStore);
- strStore = rafFile.readLine();
+ line = rafFile.readLine();
+ while (line != null && !line.equals("") && !line.equalsIgnoreCase("end")) {
+ log.printMessage(Log.DEBUG, "\t" + line);
+ mrcStore.items.add(line);
+ line = rafFile.readLine();
}
if (!map.inside(mrcStore.x, mrcStore.y)) {
log.printMessage(Log.VERBOSE, "Previous merchant is off of the map, ignoring");
blnMerchantListChanged = true;
} else {
- //vctMerchants.add(mrcStore);
- addDuskObject(mrcStore);
+ addDuskObject(mrcStore.map, mrcStore);
}
- strStore = rafFile.readLine();
+ line = rafFile.readLine();
}
} catch (Exception e) {
log.printError("DuskEngine():While loading merchants", e);
LivingThing thnStore;
rafFile = new RandomAccessFile("mobs", "r");
log.printMessage(Log.INFO, "Loading Mobs...");
- strStore = rafFile.readLine();
- while (strStore != null) {
- if (strStore.equals("")) {
+ line = rafFile.readLine();
+ while (line != null) {
+ if (line.equals("")) {
break;
}
- if (strStore.equals("mob2.3")) {
- strStore = rafFile.readLine();
- log.printMessage(Log.VERBOSE, strStore);
- try {
- thnStore = new Mob(strStore,
- Integer.parseInt(rafFile.readLine()),
- Integer.parseInt(rafFile.readLine()),
- this);
- if (!map.inside(thnStore.x, thnStore.y)) {
- log.printMessage(Log.VERBOSE, "Previous mob is off of the map, ignoring");
- blnMobListChanged = true;
- } else {
- //vctMobs.addElement(thnStore);
- addDuskObject(thnStore);
- }
- } catch (Exception e) {
- log.printError("DuskEngine():While loading mobs", e);
- }
- } else {
- log.printMessage(Log.VERBOSE, strStore);
+ // Only bother to support new file format:
+ // mob
+ // type
+ // map
+ // x
+ // y
+ if (line.equals("mob")) {
try {
- thnStore = new Mob(strStore,
- Integer.parseInt(rafFile.readLine()),
- Integer.parseInt(rafFile.readLine()),
- Integer.parseInt(rafFile.readLine()),
+ String mobtype = rafFile.readLine();
+ String mapname = rafFile.readLine();
+ int locx = Integer.parseInt(rafFile.readLine());
+ int locy = Integer.parseInt(rafFile.readLine());
+ TileMap map = maps.get(mapname);
+
+ thnStore = new Mob(mobtype,
+ locx,
+ locy,
this);
+
if (!map.inside(thnStore.x, thnStore.y)) {
log.printMessage(Log.VERBOSE, "Previous mob is off of the map, ignoring");
blnMobListChanged = true;
} else {
//vctMobs.addElement(thnStore);
- addDuskObject(thnStore);
+ addDuskObject(map, thnStore);
}
+
} catch (Exception e) {
- log.printError("DuskEngine():While loading mobs", e);
+ log.printError("Error loading mobs", e);
}
}
- strStore = rafFile.readLine();
+ line = rafFile.readLine();
}
rafFile.close();
Sign sgnStore;
rafFile = new RandomAccessFile("signs", "r");
log.printMessage(Log.INFO, "Loading Signs...");
- strStore = rafFile.readLine();
- while (!(strStore == null || strStore.equals(""))) {
- log.printMessage(Log.VERBOSE, strStore);
- sgnStore = new Sign(this, "sign", strStore, Integer.parseInt(rafFile.readLine()), Integer.parseInt(rafFile.readLine()), getID());
+ line = rafFile.readLine();
+ while (!(line == null || line.equals(""))) {
+ String mapname = rafFile.readLine();
+ int locx = Integer.parseInt(rafFile.readLine());
+ int locy = Integer.parseInt(rafFile.readLine());
+ TileMap map = maps.get(mapname);
+ log.printMessage(Log.VERBOSE, line);
+ sgnStore = new Sign(this, "sign", line, locx, locy, getID());
if (!map.inside(sgnStore.x, sgnStore.y)) {
log.printMessage(Log.VERBOSE, "Previous sign is off of the map, ignoring");
blnSignListChanged = true;
} else {
- //vctSigns.add(sgnStore);
- addDuskObject(sgnStore);
+ addDuskObject(map, sgnStore);
}
- strStore = rafFile.readLine();
+ line = rafFile.readLine();
}
rafFile.close();
Prop prpStore;
rafFile = new RandomAccessFile("props", "r");
log.printMessage(Log.INFO, "Loading Props...");
- strStore = rafFile.readLine();
- while (!(strStore == null || strStore.equals(""))) {
- log.printMessage(Log.VERBOSE, strStore);
- prpStore = getProp(strStore);
+ line = rafFile.readLine();
+ while (!(line == null || line.equals(""))) {
+ String mapname = rafFile.readLine();
+ int locx = Integer.parseInt(rafFile.readLine());
+ int locy = Integer.parseInt(rafFile.readLine());
+ TileMap map = maps.get(mapname);
+
+ log.printMessage(Log.VERBOSE, line);
+ prpStore = getProp(line);
if (prpStore != null) {
- prpStore.x = Integer.parseInt(rafFile.readLine());
- prpStore.y = Integer.parseInt(rafFile.readLine());
+ prpStore.x = locx;
+ prpStore.y = locy;
if (!map.inside(prpStore.x, prpStore.y)) {
log.printMessage(Log.VERBOSE, "Previous prop is off of the map, ignoring");
blnPropListChanged = true;
} else {
- //vctProps.addElement(prpStore);
- addDuskObject(prpStore);
+ addDuskObject(map, prpStore);
}
}
- strStore = rafFile.readLine();
+ line = rafFile.readLine();
}
rafFile.close();
try {
scripts.put(i, new Script(path + i, this, true));
} catch (Exception e) {
+ System.out.println("Loaded tile scripts " + path + " until: " + i);
break;
}
}
}
}
- public void chatMessage(String inMessage, int locx, int locy, String strFrom) {
+ /**
+ * Sends a chat message to other players within visible range.
+ *
+ * @param map
+ * @param inMessage
+ * @param locx
+ * @param locy
+ * @param strFrom
+ */
+ // FIXME: move somewhere better
+ public void chatMessage(TileMap map, String inMessage, int locx, int locy, String strFrom) {
strFrom = strFrom.toLowerCase();
LivingThing thnStore;
log.printMessage(Log.ALWAYS, inMessage);
}
}
+ // FIXME: move to livinghting?
public void refreshEntities(LivingThing refresh) {
LinkedList<DuskObject> newEntities = new LinkedList<>();
- for (TileMap.MapData md : map.range(refresh.x, refresh.y, viewrange)) {
+ for (TileMap.MapData md : refresh.map.range(refresh.x, refresh.y, viewrange)) {
if (!md.entities.isEmpty()
&& canSeeTo(refresh, md.x, md.y)) {
for (DuskObject o : md.entities) {
refresh.setEntities(newEntities);
}
- public void addEntity(DuskObject add) {
+ // FIXME: move to map or livingthing?
+ public void addEntity(TileMap map, DuskObject add) {
for (TileMap.MapData md : map.range(add.x, add.y, viewrange)) {
for (DuskObject o : md.entities) {
if (o.isLivingThing()) {
public void cleanup() {
log.printMessage(Log.INFO, "Starting cleanup.");
- for (TileMap.MapData md : map) {
- for (DuskObject o : md.entities) {
- if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
- if (lt.isPlayer()) {
- if (!playersByName.containsKey(lt.name)) {
- log.printMessage(Log.INFO, "**found defunct player at " + md.x + "," + md.y + " during cleanup.");
- removeDuskObject(lt);
- lt.battle = null;
- lt.isStopped = true;
+ for (TileMap map : maps.values()) {
+ for (TileMap.MapData md : map) {
+ for (DuskObject o : md.entities) {
+ if (o.isLivingThing()) {
+ LivingThing lt = (LivingThing) o;
+ if (lt.isPlayer()) {
+ if (!playersByName.containsKey(lt.name)) {
+ log.printMessage(Log.INFO, "**found defunct player at " + md.x + "," + md.y + " during cleanup.");
+ removeDuskObject(lt);
+ lt.battle = null;
+ lt.isStopped = true;
+ }
}
- }
- if (lt.isPet()) {
- if (!petList.contains(lt)) {
- log.printMessage(Log.INFO, "**found defunct pet at " + md.x + "," + md.y + " during cleanup.");
- removeDuskObject(lt);
+ if (lt.isPet()) {
+ if (!petList.contains(lt)) {
+ log.printMessage(Log.INFO, "**found defunct pet at " + md.x + "," + md.y + " during cleanup.");
+ removeDuskObject(lt);
+ }
}
}
}
log.printMessage(Log.INFO, "Finished cleanup.");
}
+ // FIXME: Move to map?
void notifyRemoved(DuskObject remove) {
- for (TileMap.MapData md : map.range(remove.x, remove.y, viewrange)) {
+ for (TileMap.MapData md : remove.map.range(remove.x, remove.y, viewrange)) {
for (DuskObject o : md.entities) {
if (o.isLivingThing()) {
LivingThing lt = (LivingThing) o;
pla1.chatMessage("Players who are not in clans cannot fight other players.");
return;
}
- if (pla2.isPlayer() && overMerchant(pla2.x, pla2.y) != null) {
+ if (pla2.isPlayer() && pla2.overMerchant() != null) {
pla1.chatMessage("You cannot attack players who are shopping.");
return;
}
- if (pla2.isPlayer() && overPlayerMerchant(pla2.x, pla2.y) != null) {
+ if (pla2.isPlayer() && pla2.overPlayerMerchant() != null) {
pla1.chatMessage("You cannot attack players who are shopping.");
return;
}
return null;
}
- void playSound(int sfxid, int locx, int locy) {
+ // FIXME: move to map or livinghting?
+ void playSound(TileMap map, int sfxid, int locx, int locy) {
for (TileMap.MapData md : map.range(locx, locy, viewrange)) {
for (DuskObject o : md.entities) {
if (o.isLivingThing()) {
}
}
- public boolean canMoveTo(int inLocX, int inLocY, LivingThing thnStore) {
+ // FIXME: move to map or livingthing
+ public boolean canMoveTo(int inLocX, int inLocY, LivingThing lt) {
int i;
LivingThing thnStore2;
Script scrStore;
boolean blnStore;
- if (!map.inside(inLocX, inLocY))
+ if (!lt.map.inside(inLocX, inLocY))
return false;
- for (DuskObject o : map.getEntities(inLocX, inLocY, null)) {
+ System.out.printf("can move to: %d,%d tid=%3d on map %s\n", inLocX, inLocY, lt.map.getTile(inLocX, inLocY), lt.map.name);
+
+ for (DuskObject o : lt.map.getEntities(inLocX, inLocY, null)) {
if (o.isLivingThing()) {
thnStore2 = (LivingThing) o;
- if (!canMoveThrougLivingThing(thnStore, thnStore2))
+ if (!canMoveThrougLivingThing(lt, thnStore2))
return false;
}
}
try {
scrStore = new Script("defCanMoveScripts/" + inLocX + "_" + inLocY, this, false);
- scrStore.varVariables.addVariable("trigger", thnStore);
+ scrStore.varVariables.addVariable("trigger", lt);
blnStore = scrStore.rewindAndParseScript();
scrStore.close();
return blnStore;
} catch (Exception e) {
}
try {
- scrStore = (Script) tileCanMove.get((int) map.getTile(inLocX, inLocY));
+ int tid = lt.map.getTile(inLocX, inLocY);
+ scrStore = (Script) tileCanMove.get(tid);
synchronized (scrStore) {
scrStore.varVariables.clearVariables();
- scrStore.varVariables.addVariable("trigger", thnStore);
+ scrStore.varVariables.addVariable("trigger", lt);
blnStore = scrStore.rewindAndParseScript();
}
return blnStore;
return false;
}
- boolean canSee(int inLocX, int inLocY, LivingThing thnStore) {
+ // FIXME: move to lt
+ boolean canSee(LivingThing lt, int inLocX, int inLocY) {
int i;
- LivingThing thnStore2;
- DuskObject objStore = null;
- Script scrStore;
+ Script script;
boolean blnStore;
try {
- scrStore = new Script("defCanSeeScripts/" + inLocX + "_" + inLocY, this, false);
- scrStore.varVariables.addVariable("trigger", thnStore);
- blnStore = scrStore.rewindAndParseScript();
- scrStore.close();
+ script = new Script("defCanSeeScripts/" + inLocX + "_" + inLocY, this, false);
+ script.varVariables.addVariable("trigger", lt);
+ blnStore = script.rewindAndParseScript();
+ script.close();
return blnStore;
} catch (Exception e) {
}
try {
- scrStore = (Script) tileCanSee.get((int) map.getTile(inLocX, inLocY));
- synchronized (scrStore) {
- scrStore.varVariables.clearVariables();
- scrStore.varVariables.addVariable("trigger", thnStore);
- blnStore = scrStore.rewindAndParseScript();
+ script = (Script) tileCanSee.get((int) lt.map.getTile(inLocX, inLocY));
+ synchronized (script) {
+ script.varVariables.clearVariables();
+ script.varVariables.addVariable("trigger", lt);
+ blnStore = script.rewindAndParseScript();
}
return blnStore;
} catch (Exception e) {
}
// TODO: Move this to map, then everything that uses it can be elsewhere
+ // Or to living thing
// Following by Randall Leeds and Tom Weingarten
// map/iterator version by notzed
- public boolean canSeeTo(LivingThing thing, int destX, int destY) {
- if (Math.abs(thing.x - destX) > viewrange || Math.abs(thing.y - destY) > viewrange) {
+ public boolean canSeeTo(LivingThing lt, int destX, int destY) {
+ if (Math.abs(lt.x - destX) > viewrange || Math.abs(lt.y - destY) > viewrange) {
return false;
}
return true;
}
- for (TileMap.MapData md : map.look(thing.x, thing.y, destX, destY)) {
- if (!canSee(md.x, md.y, thing))
+ for (TileMap.MapData md : lt.map.look(lt.x, lt.y, destX, destY)) {
+ if (!canSee(lt, md.x, md.y))
return false;
}
return true;
}
//End contributed portion
- public Merchant overMerchant(int x, int y) {
- for (DuskObject o : map.getEntities(x, y, null)) {
- if (o.isMerchant()) {
- return (Merchant) o;
- }
- }
- return null;
- }
-
- public PlayerMerchant overPlayerMerchant(int x, int y) {
- for (DuskObject o : map.getEntities(x, y, null)) {
- if (o.isPlayerMerchant()) {
- return (PlayerMerchant) o;
- }
- }
- return null;
- }
-
- synchronized void changeMap(int locx, int locy, short value) {
+ // FIXME: Move to livingthing? Enforce privs?
+ synchronized void changeMap(LivingThing god, int locx, int locy, short value) {
if (value < 0 || value > tileCanMove.size()) {
log.printMessage(Log.INFO, "Invalid value passed to changeMap(" + locx + "," + locy + "," + value + ")");
return;
}
- if (!map.inside(locx, locy)) {
+ if (!god.map.inside(locx, locy)) {
log.printMessage(Log.INFO, "Invalid location to changeMap(" + locx + "," + locy + "," + value + ")");
return;
}
- map.setTile(locx, locy, value);
+ god.map.setTile(locx, locy, value);
blnMapHasChanged = true;
- updateMap(locx, locy);
+ updateMap(god, locx, locy);
+ }
+
+ void updateMap(LivingThing thing, int locx, int locy) {
+ for (TileMap.MapData md : thing.map.range(locx, locy, viewrange)) {
+ for (DuskObject o : md.entities) {
+ if (o.isLivingThing()) {
+ LivingThing lt = (LivingThing) o;
+ if (lt.isPlayer()) {
+ lt.updateMap();
+ }
+ }
+ }
+ }
}
- synchronized void resizeMap(int x, int y) {
+ // FIXME: move to livingthing enforce privs?
+ synchronized void resizeMap(TileMap map, int x, int y) {
map.resize(x, y);
- for (LivingThing lt : playersByName.values()) {
- lt.initMap();
+ // FIXME: only the map that changed
+ for (LivingThing thing : playersByName.values()) {
+ thing.initMap();
}
blnMapHasChanged = true;
}
int i,
i2;
if (blnMapHasChanged) {
+ System.err.println("save map not implemented");
log.printMessage(Log.ALWAYS, "Saving map...");
- map.saveMap(new File("shortmap"));
+ //map.saveMap(new File("shortmap"));
String strMapLog = "shortmap_redraw";
PrintStream psMap = new PrintStream(new FileOutputStream(strMapLog, true), true);
psMap.println("# Map Saved");
}
void backupMap() {
+ if (true)
+ throw new UnsupportedOperationException("backupmap not implemented");
try {
StringTokenizer tknStore;
Mob mobStore;
Sign sgnStore;
Merchant mrcStore;
Prop prpStore;
- synchronized (map) {
+// synchronized (map) {
+ {
File deleteme;
RandomAccessFile rafFile;
int i, i2;
- map.saveMap(new File("backup/shortmap.backup"));
+ // map.saveMap(new File("backup/shortmap.backup"));
deleteme = new File("backup/mobs.backup");
deleteme.delete();
}
@Deprecated
- DuskObject getDuskObject(int x, int y, String name) {
- //synchronized (entities) {
- // return DuskObject.find(entities[x][y], name);
- //}
- for (DuskObject o : map.getEntities(x, y, null)) {
- if (o.name.equalsIgnoreCase(name))
- return o;
-
- }
- return null;
- }
-
- // must have objEntities locked
- @Deprecated
- private void pushDuskObject(DuskObject o) {
+ private void pushDuskObject(TileMap map, DuskObject o) {
+ o.map = map;
map.addEntity(o);
}
@Deprecated
- private void popDuskObject(DuskObject o) {
+ private void popDuskObject(TileMap map, DuskObject o) {
map.removeEntity(o);
}
- public void addDuskObject(DuskObject obj) {
+ public void addDuskObject(TileMap map, DuskObject obj) {
if (obj.isLivingThing()) {
LivingThing lt = (LivingThing) obj;
if (!lt.isLoaded) {
blnPropListChanged = true;
}
-
- pushDuskObject(obj);
- addEntity(obj);
+ pushDuskObject(map, obj);
+ addEntity(map, obj);
}
/**
*/
public void mobKilled(Mob obj) {
notifyRemoved(obj);
- popDuskObject(obj);
+ popDuskObject(obj.map, obj);
}
public void removeDuskObject(DuskObject obj) {
}
notifyRemoved(obj);
- popDuskObject(obj);
- }
-
- public Iterable<TileMap.MapData> visibleMap(int x, int y) {
- return map.range(x, y, viewrange);
+ popDuskObject(obj.map, obj);
}
/**
- * Move a living thing, updating any other living things within range
+ * Move a living thing, updating any other living things within range.
+ *
+ * Only moves wihin the same map
*
* @param thing
* @param inlocx
* @param inlocy
* @param dir
*/
- // FIXME: now i think this probably needs to be moved back to livingthing ...
+ // FIXME: after moving here now i think this probably needs to be moved back to livingthing ...
public void moveDuskObject(LivingThing thing, int inlocx, int inlocy, byte dir) {
- for (TileMap.MapData md : map.range(thing.x, thing.y, viewrange)) {
+ for (TileMap.MapData md : thing.map.range(thing.x, thing.y, viewrange)) {
for (DuskObject o : md.entities) {
if (o.isLivingThing()) {
LivingThing lt = (LivingThing) o;
}
}
// Move it from cell to cell
- popDuskObject(thing);
+ popDuskObject(thing.map, thing);
thing.x = inlocx;
thing.y = inlocy;
- pushDuskObject(thing);
+ pushDuskObject(thing.map, thing);
//addDuskObject(objIn);
}
* @param name
* @return
*/
+ // FIXME: move to livingthing?
public DuskObject findVisibleObject(LivingThing thing, String name) {
int number = 0;
int byid = -1;
}
//Search surrounding area
- for (TileMap.MapData md : map.range(thing.x, thing.y, viewrange)) {
+ for (TileMap.MapData md : thing.map.range(thing.x, thing.y, viewrange)) {
for (DuskObject o : md.entities) {
if (byid == o.ID
|| (byid == -1 && o.name.equalsIgnoreCase(name))) {
return null;
}
- void updateMap(int locx, int locy) {
- for (TileMap.MapData md : map.range(locx, locy, viewrange)) {
- for (DuskObject o : md.entities) {
- if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
- if (lt.isPlayer()) {
- lt.updateMap();
- }
- }
- }
- }
- }
-
public void run() {
log.printMessage(Log.ALWAYS, "Mob ticks = " + lngMobTicks);
log.printMessage(Log.ALWAYS, "Player ticks = " + lngPlayerTicks);
if (mob.hp > 0) {
mob.hp = mob.maxhp;
mob.mp = mob.maxmp;
- mob.changeLocBypass(mob.originalX, mob.originalY);
+ // mobx always stay on same map?
+ mob.changeLocBypass(mob.map, mob.originalX, mob.originalY);
}
}
}
Mob mobStore;
double enemyrelation = 0;
boolean visiblePlayer = false;
- for (MapData md : game.map.range(mob.x, mob.y, game.viewrange - 1)) {
+ for (MapData md : mob.map.range(mob.x, mob.y, game.viewrange - 1)) {
for (DuskObject o : md.entities) {
if (o.isLivingThing()) {
LivingThing lt = (LivingThing) o;
for (int i = 0; i < vctVisibleUpdate.size(); i++) {
thnStore = (LivingThing) vctVisibleUpdate.elementAt(i);
engGame.removeDuskObject(thnStore);
- engGame.addDuskObject(thnStore);
+ engGame.addDuskObject(thnStore.map, thnStore);
}
}
rafCompile.writeByte(24);
rafCompile.writeBytes(getStringForCompile());
}
+ if (strStore.equalsIgnoreCase("mapxy")) {
+ rafCompile.writeByte(25);
+ rafCompile.writeBytes(getStringForCompile());
+ rafCompile.writeBytes(parseValueForCompile());
+ }
rafCompile.writeBytes(parseValueForCompile());
return true;
} else if (strStore.equalsIgnoreCase("changeTile")) {
return false;
}
case 5: {
- engGame.playSound((int) parseValue(), (int) parseValue(), (int) parseValue());
+ // FIXME: playsound script, who played it?
+ //engGame.playSound((int) parseValue(), (int) parseValue(), (int) parseValue());
return true;
}
case 6: {
return false;
}
case 29: {
+ // These all need a map-name as well
+ System.err.println("create mob not implemented");
Mob mobStore = new Mob(getString(), (int) parseValue(), (int) parseValue(), engGame);
- //engGame.vctMobs.add(mobStore);
- engGame.addDuskObject(mobStore);
+ //engGame.addDuskObject(mobStore);
return true;
}
case 30: {
+ System.err.println("create mob one use not implemented");
Mob mobStore = new Mob(getString(), (int) parseValue(), (int) parseValue(), engGame);
mobStore.blnOneUse = true;
- //engGame.vctMobs.add(mobStore);
- engGame.addDuskObject(mobStore);
+ //engGame.addDuskObject(mobStore);
return true;
}
case 31: {
+ System.err.println("create item not implemented");
Item itmStore = engGame.getItem(getString());
itmStore.x = (int) parseValue();
itmStore.y = (int) parseValue();
- engGame.addDuskObject(itmStore);
+ //engGame.addDuskObject(itmStore);
return true;
}
case 59: {
return true;
}
case 19: {
- thnStore.changeLocBypass((int) parseValue() + thnStore.x, thnStore.y);
+ thnStore.changeLocBypass(thnStore.map, (int) parseValue() + thnStore.x, thnStore.y);
return true;
}
case 20: {
- thnStore.changeLocBypass(thnStore.x, (int) parseValue() + thnStore.y);
+ thnStore.changeLocBypass(thnStore.map, thnStore.x, (int) parseValue() + thnStore.y);
return true;
}
case 21: {
- thnStore.changeLocBypass((int) parseValue() + thnStore.x, (int) parseValue() + thnStore.y);
+ thnStore.changeLocBypass(thnStore.map, (int) parseValue() + thnStore.x, (int) parseValue() + thnStore.y);
return true;
}
case 22: {
return true;
}
case 19: {
- thnStore.changeLocBypass((int) parseValue(), thnStore.y);
+ thnStore.changeLocBypass(thnStore.map, (int) parseValue(), thnStore.y);
return true;
}
case 20: {
- thnStore.changeLocBypass(thnStore.x, (int) parseValue());
+ thnStore.changeLocBypass(thnStore.map, thnStore.x, (int) parseValue());
return true;
}
case 21: {
- thnStore.changeLocBypass((int) parseValue(), (int) parseValue());
+ thnStore.changeLocBypass(thnStore.map, (int) parseValue(), (int) parseValue());
return true;
}
case 22: {
}
return true;
}
+ case 25: {
+ thnStore.changeLocBypass(engGame.maps.get(getString()), (int) parseValue(), (int) parseValue());
+ return true;
+ }
}
}
case 46: {
engGame.log.printMessage(Log.DEBUG, "Script " + strName + " called changeMap with 0 at " + dbgX + "," + dbgY);
}
// engGame.changeMap((int)parseValue(),(int)parseValue(),(short)parseValue());
- engGame.changeMap(dbgX, dbgY, dbgValue);
- return true;
+ // FIXME:
+ throw new UnsupportedOperationException("script changemap not implemented");
+ //engGame.changeMap(dbgX, dbgY, dbgValue);
}
case 47: {
String strOne = getString();
return true;
}
case 49: {
- LivingThing thnStore = getLivingThing(getString());
- engGame.notifyRemoved(thnStore);
- engGame.addEntity(thnStore);
+ // FIXME: do i need ensurevisible?
+ //LivingThing thnStore = getLivingThing(getString());
+ //engGame.notifyRemoved(thnStore);
+ //engGame.addEntity(thnStore);
return true;
}
case 50: {
if (mob.x == -6) {
mob.hp++;
if (mob.hp > -1) {
- mob.changeLocBypass(mob.originalX, mob.originalY);
+ mob.changeLocBypass(mob.map, mob.originalX, mob.originalY);
mob.hp = mob.maxhp;
}
} else {
public String name; // Name of this object
public String description = null; // Description of this object
boolean isHideName; // if true: Do not display object's name on the client map.
+ // Current map for object
+ public TileMap map;
+ // current location on map
public int x, y;
DuskObject next = null; //Linked List
case "description":
description = in.readLine();
break;
+ case "map":
+ map = game.maps.get(in.readLine());
+ break;
case "x":
x = Integer.parseInt(in.readLine());
break;
} else {
rafPlayerFile.writeBytes("clan\nnone\n");
}
+ rafPlayerFile.writeBytes("map\n" + map.name + "\n");
rafPlayerFile.writeBytes("x\n" + String.valueOf(x) + "\n");
rafPlayerFile.writeBytes("y\n" + String.valueOf(y) + "\n");
if (popup == false) {
};
int mflags = goon ? 0 : TileMap.SKIP_END;
- for (MoveData md : game.map.move(x, y, destX, destY, mflags, ml)) {
+ for (MoveData md : map.move(x, y, destX, destY, mflags, ml)) {
moveQueue.add(md.direction);
}
}
return null;
}
- // FIXME: should probably be in DuskEngine
+ // This implemented path seeking, and moving within the same map
protected synchronized void moveTo(int newLocX, int newLocY, byte dir, int intNewStep) {
- if (privs < 5 && (newLocX >= (game.map.getCols() - 1)
- || newLocY >= (game.map.getRows() - 1)
+ if (privs < 5 && (newLocX >= (map.getCols())
+ || newLocY >= (map.getRows())
|| newLocX < 0
|| newLocY < 0)) {
return;
} else {
return;
}
+ boolean wasMerchant = overMerchant() != null || overPlayerMerchant() != null;
int oldLocX = x;
int oldLocY = y;
+ TileMap oldMap = map;
// Move it from cell to cell
game.moveDuskObject(this, newLocX, newLocY, dir);
try {
imagestep = intNewStep;
if (isPlayer()) {
- if (game.overMerchant(oldLocX, oldLocY) != null) {
- offMerchant();
- }
- if (game.overPlayerMerchant(oldLocX, oldLocY) != null) {
+ if (wasMerchant) {
offMerchant();
}
updateMap();
}
Script scrStore;
try {
- scrStore = (Script) game.tileAction.get((int) game.map.getTile(x, y));
+ scrStore = (Script) game.tileAction.get((int) map.getTile(x, y));
synchronized (scrStore) {
scrStore.varVariables.clearVariables();
scrStore.varVariables.addVariable("trigger", this);
following.following.master = null;
following.following = null;
}
- following.changeLocBypass(oldLocX, oldLocY);
+ // FIXME: verify this is correct: moveTo can't change the map anyway
+ following.changeLocBypass(oldMap, oldLocX, oldLocY);
} else {
chatMessage(following.name + " is no longer following you.");
following.chatMessage("You are no longer following " + name + ".");
} else {
// This is a new one
//nearEntities.put(o.ID, o);
- game.addEntity(o);
+ game.addEntity(map, o);
}
}
// anything left over must be removed
}
}
- public void changeLoc(int newLocX, int newLocY) {
- if (privs > 1 || (battle == null && !isSleeping && game.canMoveTo(newLocX, newLocY, this))) {
- if (isMob()) {
- if (!(Math.abs(originalX - newLocX) < game.viewrange && Math.abs(originalY - newLocY) < game.viewrange)) {
- return;
- }
- }
- changeLocBypass(newLocX, newLocY);
- }
- }
-
- synchronized public void changeLocBypass(int newLocX, int newLocY) {
+ /*
+ * unused
+ public void changeLoc(int newLocX, int newLocY) {
+ if (privs > 1 || (battle == null && !isSleeping && game.canMoveTo(newLocX, newLocY, this))) {
+ if (isMob()) {
+ if (!(Math.abs(originalX - newLocX) < game.viewrange && Math.abs(originalY - newLocY) < game.viewrange)) {
+ return;
+ }
+ }
+ changeLocBypass(newLocX, newLocY);
+ }
+ }*/
+ // FIXME: supply map too
+ synchronized public void changeLocBypass(TileMap map, int newLocX, int newLocY) {
int oldLocX = x;
int oldLocY = y;
+ boolean wasMerchant = overMerchant() != null || overPlayerMerchant() != null;
game.removeDuskObject(this);
x = newLocX;
y = newLocY;
try {
+ // Really move + map should be atomic to client.
+
+ //update entity:
+ if (isWorking) {
+ game.addDuskObject(map, this);
+ }
+ // Moved after addDuskObject so the map is set on 'this'
if (isPlayer()) {
updateMap();
- if (game.overMerchant(oldLocX, oldLocY) != null) {
- offMerchant();
- }
- if (game.overPlayerMerchant(oldLocX, oldLocY) != null) {
+ if (wasMerchant) {
offMerchant();
}
}
- //update entity:
- if (isWorking) {
- game.addDuskObject(this);
- }
Script scrStore;
try {
- scrStore = (Script) game.tileAction.get((int) game.map.getTile(newLocX, newLocY));
+ scrStore = (Script) game.tileAction.get((int) map.getTile(newLocX, newLocY));
synchronized (scrStore) {
scrStore.varVariables.clearVariables();
scrStore.varVariables.addVariable("trigger", this);
}
Script.exec("defMoveActions/" + newLocX + "_" + newLocY, game, this);
if (following != null) {
- following.changeLocBypass(oldLocX, oldLocY);
+ following.changeLocBypass(map, oldLocX, oldLocY);
}
if (isPlayer()) {
game.refreshEntities(this);
int r = game.viewrange;
+ System.out.printf("update map %d,%d map %s\n", x, y, map.name);
+
int width = r * 2 + 1;
int height = r * 2 + 1;
short[] tiles = null;
int i = 0;
- int nlayers = game.map.getLayerCount();
+ int nlayers = map.getLayerCount();
int nused = 0;
short[][] layers = new short[nlayers][];
int groundLayer = 0;
- for (int l=0;l<nlayers;l++) {
+ for (int l = 0; l < nlayers; l++) {
if (tiles == null)
- tiles = new short[width*height];
-
- short[] visible = game.map.getRegion(l, x-r, y-r, width, height, tiles);
-
+ tiles = new short[width * height];
+
+ short[] visible = map.getRegion(l, x - r, y - r, width, height, tiles);
+
if (visible != null) {
tiles = null;
-
- if (l == game.map.getGroundLayer())
+
+ if (l == map.getGroundLayer())
groundLayer = nused;
-
+
layers[nused++] = visible;
}
}
-
+
send(new MapMessage(MSG_UPDATE_MAP, width, height, x, y, groundLayer, nused, layers));
}
}
}
+ public Merchant overMerchant() {
+ // or move to map?
+ for (DuskObject o : map.getEntities(x, y, null)) {
+ if (o.isMerchant()) {
+ return (Merchant) o;
+ }
+ }
+ return null;
+ }
+
+ public PlayerMerchant overPlayerMerchant() {
+ for (DuskObject o : map.getEntities(x, y, null)) {
+ if (o.isPlayerMerchant()) {
+ return (PlayerMerchant) o;
+ }
+ }
+ return null;
+ }
+
public boolean isWearing(String name) {
return wornItems.isWearing(name);
}
connectionThread.setName("LivingThing(" + name + ")");
sendThread.setName("LivingThing(" + name + ").send");
initMap();
- changeLocBypass(x, y);
+ changeLocBypass(map, x, y);
updateInfo();
updateStats();
updateItems();
isLoaded = true;
if (following != null) {
following.isLoaded = true;
- following.changeLocBypass(x, y);
+ following.changeLocBypass(map, x, y);
}
if (create) {
case "description":
description = in.readLine();
break;
+ // Mobs are assigned locations separately
+ /*
+ case "map":
+ map = game.maps.get(in.readLine());
+ break;
case "x":
x = Integer.parseInt(in.readLine());
break;
case "y":
y = Integer.parseInt(in.readLine());
- break;
+ break;*/
case "maxhp":
maxhp = Integer.parseInt(in.readLine());
break;
*/
public class TileMap implements Iterable<TileMap.MapData> {
+ /**
+ * Name of map for referencing
+ */
+ public final String name;
+ /**
+ * Size
+ */
private int rows, cols;
/**
* Tile map
* @param cols
* @param rows
*/
- public TileMap(int cols, int rows) {
+ public TileMap(String name, int cols, int rows) {
+ this.name = name;
this.rows = rows;
this.cols = cols;
throw new IOException("Invalid format/magic/unknown version");
}
- map = new TileMap(cols, rows);
+ System.out.println("Load map: " + path);
+ System.out.printf(" size: %dx%d\n", cols, rows);
+ System.out.printf(" groundLayer: %d\n", groundLayer);
+ System.out.printf(" layerCount: %d\n", layerCount);
+
+ map = new TileMap(path.getName(), cols, rows);
map.groundLayer = groundLayer;
map.layers = new TileLayer[layerCount];
int theight = mapFile.readInt();
TileLayer tl;
+ System.out.printf(" layer %2d: at %3d,%3d size %3dx%3d\n", l, tx, ty, twidth, theight);
if (l == groundLayer)
tl = new TileLayer(tx, ty, twidth, theight, map.tiles);
else
try (DataInputStream mapFile = new DataInputStream(new FileInputStream(path))) {
int cols = mapFile.readInt();
int rows = mapFile.readInt();
- map = new TileMap(cols, rows);
+ map = new TileMap(path.getName(), cols, rows);
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
map.setTile(x, y, mapFile.readShort());
try (RandomAccessFile mapFile = new RandomAccessFile(path, "r")) {
int cols = mapFile.readInt();
int rows = mapFile.readInt();
- map = new TileMap(cols, rows);
+ map = new TileMap(path.getName(), cols, rows);
for (int x = 0; x < cols; x++) {
for (int y = 0; y < rows; y++) {
if (format == FORMAT_BYTE)
}
public static void main(String[] args) {
- TileMap map = new TileMap(16, 16);
+ TileMap map = new TileMap("test", 16, 16);
/*
for (MapData md : map.look(5, 5, 10, 3)) {