diff -r 4feced261c68 -r de822cd3df3a project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetRoomState.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetRoomState.java Tue Jan 21 22:38:13 2014 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetRoomState.java Tue Jan 21 22:43:06 2014 +0100 @@ -41,145 +41,145 @@ * This class manages the room state in a network game. */ class NetRoomState extends BasicRoomState { - final Map requestedTeams = new TreeMap(); - private Netplay netplay; - - public NetRoomState(Netplay netplay) { - this.netplay = netplay; - initRoomState(false); - } + final Map requestedTeams = new TreeMap(); + private Netplay netplay; + + public NetRoomState(Netplay netplay) { + this.netplay = netplay; + initRoomState(false); + } + + public void changeWeaponset(Weaponset weaponset) { + if(getChiefStatus() && !equal(weaponset, getWeaponset())) { + sendToNet(MSG_SEND_WEAPONSET, weaponset); + setWeaponset(weaponset); + } + } + + public void changeMapRecipe(MapRecipe mapRecipe) { + if(getChiefStatus() && !equal(mapRecipe, getMapRecipe())) { + sendToNet(MSG_SEND_MAP, mapRecipe); + setMapRecipe(mapRecipe); + } + } + + public void changeMapNameAndGenerator(String mapName) { + if(getChiefStatus() && !equal(mapName, getMapRecipe().name)) { + int newGenerator = MapRecipe.generatorForMapname(mapName); + if(newGenerator != getMapRecipe().mapgen) { + sendToNet(MSG_SEND_MAP_GENERATOR, newGenerator, null); + } + sendToNet(MSG_SEND_MAP_NAME, mapName); + setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator)); + } + } + + public void changeMapTemplate(int template) { + if(getChiefStatus() && template != getMapRecipe().templateFilter) { + sendToNet(MSG_SEND_MAP_TEMPLATE, template, null); + setMapRecipe(getMapRecipe().withTemplateFilter(template)); + } + } + + public void changeMazeSize(int mazeSize) { + if(getChiefStatus() && mazeSize != getMapRecipe().mazeSize) { + sendToNet(MSG_SEND_MAZE_SIZE, mazeSize, 0); + setMapRecipe(getMapRecipe().withMazeSize(mazeSize)); + } + } + + public void changeMapSeed(String seed) { + if(getChiefStatus() && !equal(seed, getMapRecipe().seed)) { + sendToNet(MSG_SEND_MAP_SEED, seed); + setMapRecipe(getMapRecipe().withSeed(seed)); + } + } + + public void changeMapTheme(String theme) { + if(getChiefStatus() && !equal(theme, getMapRecipe().theme)) { + sendToNet(MSG_SEND_MAP_THEME, theme); + setMapRecipe(getMapRecipe().withTheme(theme)); + } + } + + public void changeMapDrawdata(byte[] drawdata) { + if(getChiefStatus() && !Arrays.equals(drawdata, getMapRecipe().getDrawData())) { + sendToNet(MSG_SEND_MAP_DRAWDATA, drawdata); + setMapRecipe(getMapRecipe().withDrawData(drawdata)); + } + } - public void changeWeaponset(Weaponset weaponset) { - if(getChiefStatus() && !equal(weaponset, getWeaponset())) { - sendToNet(MSG_SEND_WEAPONSET, weaponset); - setWeaponset(weaponset); - } - } - - public void changeMapRecipe(MapRecipe mapRecipe) { - if(getChiefStatus() && !equal(mapRecipe, getMapRecipe())) { - sendToNet(MSG_SEND_MAP, mapRecipe); - setMapRecipe(mapRecipe); - } - } - - public void changeMapNameAndGenerator(String mapName) { - if(getChiefStatus() && !equal(mapName, getMapRecipe().name)) { - int newGenerator = MapRecipe.generatorForMapname(mapName); - if(newGenerator != getMapRecipe().mapgen) { - sendToNet(MSG_SEND_MAP_GENERATOR, newGenerator, null); - } - sendToNet(MSG_SEND_MAP_NAME, mapName); - setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator)); - } - } - - public void changeMapTemplate(int template) { - if(getChiefStatus() && template != getMapRecipe().templateFilter) { - sendToNet(MSG_SEND_MAP_TEMPLATE, template, null); - setMapRecipe(getMapRecipe().withTemplateFilter(template)); - } - } - - public void changeMazeSize(int mazeSize) { - if(getChiefStatus() && mazeSize != getMapRecipe().mazeSize) { - sendToNet(MSG_SEND_MAZE_SIZE, mazeSize, 0); - setMapRecipe(getMapRecipe().withMazeSize(mazeSize)); - } - } - - public void changeMapSeed(String seed) { - if(getChiefStatus() && !equal(seed, getMapRecipe().seed)) { - sendToNet(MSG_SEND_MAP_SEED, seed); - setMapRecipe(getMapRecipe().withSeed(seed)); - } - } - - public void changeMapTheme(String theme) { - if(getChiefStatus() && !equal(theme, getMapRecipe().theme)) { - sendToNet(MSG_SEND_MAP_THEME, theme); - setMapRecipe(getMapRecipe().withTheme(theme)); - } - } - - public void changeMapDrawdata(byte[] drawdata) { - if(getChiefStatus() && !Arrays.equals(drawdata, getMapRecipe().getDrawData())) { - sendToNet(MSG_SEND_MAP_DRAWDATA, drawdata); - setMapRecipe(getMapRecipe().withDrawData(drawdata)); - } - } - - public void changeGameStyle(String gameStyle) { - if(getChiefStatus() && !equal(gameStyle, getGameStyle())) { - sendToNet(MSG_SEND_GAMESTYLE, gameStyle); - setGameStyle(gameStyle); - } - } - - public void changeScheme(Scheme scheme) { - if(getChiefStatus() && !equal(scheme, getScheme())) { - sendToNet(MSG_SEND_SCHEME, scheme); - setScheme(scheme); - } - } - - void initRoomState(boolean chief) { - setTeams(Collections.emptyMap()); - requestedTeams.clear(); - - setChief(chief); - setGameStyle(GameConfig.DEFAULT_STYLE); - setMapRecipe(MapRecipe.makeRandomMap(0, "seed", GameConfig.DEFAULT_THEME)); - setScheme(netplay.defaultScheme); - setWeaponset(netplay.defaultWeaponset); - sendFullConfig(); - } - - void sendFullConfig() { - if(getChiefStatus()) { - sendToNet(MSG_SEND_GAMESTYLE, getGameStyle()); - sendToNet(MSG_SEND_SCHEME, getScheme()); - sendToNet(MSG_SEND_WEAPONSET, getWeaponset()); - sendToNet(MSG_SEND_MAP, getMapRecipe()); - } - } - - private boolean sendToNet(ToNetMsgType what, Object obj) { - return netplay.sendToNet(what, 0, obj); - } - - private boolean sendToNet(ToNetMsgType what, int arg1, Object obj) { - return netplay.sendToNet(what, arg1, obj); - } + public void changeGameStyle(String gameStyle) { + if(getChiefStatus() && !equal(gameStyle, getGameStyle())) { + sendToNet(MSG_SEND_GAMESTYLE, gameStyle); + setGameStyle(gameStyle); + } + } + + public void changeScheme(Scheme scheme) { + if(getChiefStatus() && !equal(scheme, getScheme())) { + sendToNet(MSG_SEND_SCHEME, scheme); + setScheme(scheme); + } + } + + void initRoomState(boolean chief) { + setTeams(Collections.emptyMap()); + requestedTeams.clear(); + + setChief(chief); + setGameStyle(GameConfig.DEFAULT_STYLE); + setMapRecipe(MapRecipe.makeRandomMap(0, "seed", GameConfig.DEFAULT_THEME)); + setScheme(netplay.defaultScheme); + setWeaponset(netplay.defaultWeaponset); + sendFullConfig(); + } + + void sendFullConfig() { + if(getChiefStatus()) { + sendToNet(MSG_SEND_GAMESTYLE, getGameStyle()); + sendToNet(MSG_SEND_SCHEME, getScheme()); + sendToNet(MSG_SEND_WEAPONSET, getWeaponset()); + sendToNet(MSG_SEND_MAP, getMapRecipe()); + } + } - public void requestAddTeam(Team team, int colorIndex) { - TeamIngameAttributes tia = new TeamIngameAttributes(netplay.getPlayerName(), colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false); - TeamInGame newTeamInGame = new TeamInGame(team, tia); - requestedTeams.put(team.name, newTeamInGame); - sendToNet(MSG_SEND_ADD_TEAM, newTeamInGame); - } + private boolean sendToNet(ToNetMsgType what, Object obj) { + return netplay.sendToNet(what, 0, obj); + } + + private boolean sendToNet(ToNetMsgType what, int arg1, Object obj) { + return netplay.sendToNet(what, arg1, obj); + } - public void requestRemoveTeam(String teamname) { - sendToNet(MSG_SEND_REMOVE_TEAM, teamname); - } + public void requestAddTeam(Team team, int colorIndex) { + TeamIngameAttributes tia = new TeamIngameAttributes(netplay.getPlayerName(), colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false); + TeamInGame newTeamInGame = new TeamInGame(team, tia); + requestedTeams.put(team.name, newTeamInGame); + sendToNet(MSG_SEND_ADD_TEAM, newTeamInGame); + } + + public void requestRemoveTeam(String teamname) { + sendToNet(MSG_SEND_REMOVE_TEAM, teamname); + } - public void changeTeamColorIndex(String teamname, int colorIndex) { - if(getChiefStatus()) { - TeamInGame team = getTeams().get(teamname); - if(team.ingameAttribs.colorIndex != colorIndex) { - sendToNet(MSG_SEND_TEAM_COLOR_INDEX, colorIndex, teamname); - putTeam(team.withAttribs(team.ingameAttribs.withColorIndex(colorIndex))); - } - } - } + public void changeTeamColorIndex(String teamname, int colorIndex) { + if(getChiefStatus()) { + TeamInGame team = getTeams().get(teamname); + if(team.ingameAttribs.colorIndex != colorIndex) { + sendToNet(MSG_SEND_TEAM_COLOR_INDEX, colorIndex, teamname); + putTeam(team.withAttribs(team.ingameAttribs.withColorIndex(colorIndex))); + } + } + } - public void changeTeamHogCount(String teamname, int hogcount) { - if(getChiefStatus()) { - TeamInGame team = getTeams().get(teamname); - if(team.ingameAttribs.hogCount != hogcount) { - sendToNet(MSG_SEND_TEAM_HOG_COUNT, hogcount, teamname); - putTeam(team.withAttribs(team.ingameAttribs.withHogCount(hogcount))); - } - } - } + public void changeTeamHogCount(String teamname, int hogcount) { + if(getChiefStatus()) { + TeamInGame team = getTeams().get(teamname); + if(team.ingameAttribs.hogCount != hogcount) { + sendToNet(MSG_SEND_TEAM_HOG_COUNT, hogcount, teamname); + putTeam(team.withAttribs(team.ingameAttribs.withHogCount(hogcount))); + } + } + } }