Skip to content
Browse files

Fix for multiplayer not having a difficulty setting,

fixes multiplayer crashing too
  • Loading branch information...
1 parent c176f3b commit f47db6d20fbc865b85bccc24b83e17039c552911 @Borsty Borsty committed Feb 22, 2012
View
15 src/com/mojang/mojam/MojamComponent.java
@@ -44,6 +44,7 @@
import com.mojang.mojam.gui.LevelSelect;
import com.mojang.mojam.gui.PauseMenu;
import com.mojang.mojam.gui.TitleMenu;
+import com.mojang.mojam.level.DifficultyList;
import com.mojang.mojam.level.Level;
import com.mojang.mojam.level.LevelInformation;
import com.mojang.mojam.level.LevelList;
@@ -517,11 +518,10 @@ private void tick() {
synchronizer.setStarted(true);
if (TitleMenu.level.vanilla) {
packetLink.sendPacket(new StartGamePacket(
- TurnSynchronizer.synchedSeed, TitleMenu.level
- .getUniversalPath()));
+ TurnSynchronizer.synchedSeed, TitleMenu.level.getUniversalPath(),DifficultyList.getDifficultyID(TitleMenu.difficulty)));
} else {
packetLink.sendPacket(new StartGamePacketCustom(
- TurnSynchronizer.synchedSeed, level));
+ TurnSynchronizer.synchedSeed, level, DifficultyList.getDifficultyID(TitleMenu.difficulty)));
}
packetLink.setPacketListener(MojamComponent.this);
@@ -584,6 +584,7 @@ public void handle(Packet packet) {
if (!isServer) {
StartGamePacket sgPacker = (StartGamePacket) packet;
synchronizer.onStartGamePacket(sgPacker.getGameSeed());
+ TitleMenu.difficulty = DifficultyList.getDifficulties().get(sgPacker.getDifficulty());
createLevel(sgPacker.getLevelFile());
}
} else if (packet instanceof TurnPacket) {
@@ -592,6 +593,7 @@ public void handle(Packet packet) {
if (!isServer) {
StartGamePacketCustom sgPacker = (StartGamePacketCustom) packet;
synchronizer.onStartGamePacket(sgPacker.getGameSeed());
+ TitleMenu.difficulty = DifficultyList.getDifficulties().get(sgPacker.getDifficulty());
level = sgPacker.getLevel();
paused = false;
initLevel();
@@ -702,8 +704,7 @@ public void run() {
try {
localId = 1;
packetLink = new ClientSidePacketLink(TitleMenu.ip, 3000);
- synchronizer = new TurnSynchronizer(this, packetLink, localId,
- 2);
+ synchronizer = new TurnSynchronizer(this, packetLink, localId,2);
packetLink.setPacketListener(this);
} catch (Exception e) {
e.printStackTrace();
@@ -713,7 +714,9 @@ public void run() {
} else if (id == TitleMenu.HOW_TO_PLAY) {
addMenu(new HowToPlay());
} else if (id == TitleMenu.SELECT_DIFFICULTY_ID) {
- addMenu(new DifficultySelect());
+ addMenu(new DifficultySelect(false));
+ } else if (id == TitleMenu.SELECT_DIFFICULTY_HOSTING_ID) {
+ addMenu(new DifficultySelect(true));
} else if (id == TitleMenu.EXIT_GAME_ID) {
System.exit(0);
} else if (id == TitleMenu.RETURN_ID) {
View
4 src/com/mojang/mojam/gui/DifficultySelect.java
@@ -25,15 +25,15 @@
private Button startGameButton;
private Button cancelButton;
- public DifficultySelect() {
+ public DifficultySelect(boolean hosting) {
super();
DifficultyButtons = new DifficultyButton[difficulties.size()];
setupDifficultyButtons();
TitleMenu.difficulty = difficulties.get(0);
- startGameButton = new Button(TitleMenu.START_GAME_ID, "Start Game", (MojamComponent.GAME_WIDTH - 256 - 30), MojamComponent.GAME_HEIGHT - 24 - 25);
+ startGameButton = new Button(hosting ? TitleMenu.HOST_GAME_ID : TitleMenu.START_GAME_ID, "Start Game", (MojamComponent.GAME_WIDTH - 256 - 30), MojamComponent.GAME_HEIGHT - 24 - 25);
cancelButton = new Button(TitleMenu.CANCEL_JOIN_ID, "Cancel", MojamComponent.GAME_WIDTH - 128 - 20, MojamComponent.GAME_HEIGHT - 24 - 25);
addButton(startGameButton);
View
6 src/com/mojang/mojam/gui/LevelSelect.java
@@ -43,11 +43,7 @@ public LevelSelect(boolean bHosting) {
TitleMenu.level = levels.get(0);
// start + cancel button
- if (bHosting) {
- startGameButton = new Button(TitleMenu.HOST_GAME_ID, "Host", MojamComponent.GAME_WIDTH - 256 - 30, MojamComponent.GAME_HEIGHT - 24 - 25);
- } else {
- startGameButton = new Button(TitleMenu.SELECT_DIFFICULTY_ID, "Start", MojamComponent.GAME_WIDTH - 256 - 30, MojamComponent.GAME_HEIGHT - 24 - 25);
- }
+ startGameButton = new Button(bHosting ? TitleMenu.SELECT_DIFFICULTY_HOSTING_ID : TitleMenu.SELECT_DIFFICULTY_ID, "Host", MojamComponent.GAME_WIDTH - 256 - 30, MojamComponent.GAME_HEIGHT - 24 - 25);
cancelButton = new Button(TitleMenu.CANCEL_JOIN_ID, "Cancel", MojamComponent.GAME_WIDTH - 128 - 20, MojamComponent.GAME_HEIGHT - 24 - 25);
addButton(new Button(TitleMenu.UPDATE_LEVELS, "Update Levels", MojamComponent.GAME_WIDTH - 386 - 40, MojamComponent.GAME_HEIGHT - 24 - 25));
View
2 src/com/mojang/mojam/gui/TitleMenu.java
@@ -23,6 +23,8 @@
public static final int HOW_TO_PLAY = 1010;
public static final int UPDATE_LEVELS = 1011;
public static final int RETURN_ID = 1012;
+ public static final int SELECT_DIFFICULTY_HOSTING_ID = 1013;
+
public static LevelInformation level = null;
public static DifficultyInformation difficulty = null;
View
10 src/com/mojang/mojam/level/DifficultyList.java
@@ -20,4 +20,14 @@ private static void createDifficultyList() {
}
return Difficulties;
}
+
+ public static int getDifficultyID(DifficultyInformation di) {
+ if ( Difficulties == null )
+ createDifficultyList();
+ for (int i = 0; i < Difficulties.size();i++)
+ if (Difficulties.get(i) == di)
+ return i;
+ return 1; // default to normal
+ }
+
}
View
10 src/com/mojang/mojam/network/packet/StartGamePacket.java
@@ -8,25 +8,29 @@
private long gameSeed;
private String levelFile;
+ private int difficulty;
public StartGamePacket() {
}
- public StartGamePacket(long gameSeed, String levelFile) {
+ public StartGamePacket(long gameSeed, String levelFile, int difficulty) {
this.gameSeed = gameSeed;
this.levelFile = levelFile;
+ this.difficulty = difficulty;
}
@Override
public void read(DataInputStream dis) throws IOException {
gameSeed = dis.readLong();
levelFile = dis.readUTF();
+ difficulty = dis.readInt();
}
@Override
public void write(DataOutputStream dos) throws IOException {
dos.writeLong(gameSeed);
dos.writeUTF(levelFile);
+ dos.writeInt(difficulty);
}
public long getGameSeed() {
@@ -36,4 +40,8 @@ public long getGameSeed() {
public String getLevelFile() {
return levelFile;
}
+
+ public int getDifficulty() {
+ return difficulty;
+ }
}
View
10 src/com/mojang/mojam/network/packet/StartGamePacketCustom.java
@@ -14,13 +14,15 @@
public Level level;
public int levelWidth, levelHeight;
public Short[] shorts;
+ public int difficulty;
public StartGamePacketCustom() {
}
- public StartGamePacketCustom(long gameSeed, Level level) {
+ public StartGamePacketCustom(long gameSeed, Level level, int difficulty) {
this.gameSeed = gameSeed;
this.level = level;
+ this.difficulty = difficulty;
}
@Override
@@ -33,6 +35,7 @@ public void read(DataInputStream dis) throws IOException {
for(int i = 0; i < shorts.length; i++){
shorts[i] = dis.readShort();
}
+ this.difficulty = dis.readInt();
}
@Override
@@ -43,6 +46,7 @@ public void write(DataOutputStream dos) throws IOException {
for(int i = 0; i < level.tiles.length; i++){
dos.writeShort(TileID.tileToShort(level.tiles[i]));
}
+ dos.writeInt(difficulty);
}
public long getGameSeed() {
@@ -60,4 +64,8 @@ public Level getLevel() {
return level;
}
+ public int getDifficulty() {
+ return difficulty;
+ }
+
}

0 comments on commit f47db6d

Please sign in to comment.
Something went wrong with that request. Please try again.