project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomStateManager.java
changeset 7582 714310efad8f
child 7584 7831c84cc644
equal deleted inserted replaced
7580:c92596feac0d 7582:714310efad8f
       
     1 package org.hedgewars.hedgeroid;
       
     2 
       
     3 import org.hedgewars.hedgeroid.Datastructures.GameConfig;
       
     4 import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
       
     5 import org.hedgewars.hedgeroid.Datastructures.Scheme;
       
     6 import org.hedgewars.hedgeroid.Datastructures.Team;
       
     7 import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
       
     8 import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
       
     9 import org.hedgewars.hedgeroid.Datastructures.Weaponset;
       
    10 
       
    11 import android.util.Log;
       
    12 
       
    13 /**
       
    14  * This RoomStateManager is responsible for keeping/changing the roomstate in local play.
       
    15  * That is very straightforward, just react to every request by immediately changing the
       
    16  * state.
       
    17  */
       
    18 public class LocalRoomStateManager extends BasicRoomState {
       
    19 	private static final String TAG = LocalRoomStateManager.class.getSimpleName(); 
       
    20 
       
    21 	public LocalRoomStateManager(Scheme defaultScheme, Weaponset defaultWeaponset) {
       
    22 		setChief(true);
       
    23 		setGameStyle(GameConfig.DEFAULT_STYLE);
       
    24 		setMapRecipe(MapRecipe.makeRandomMap(0, MapRecipe.makeRandomSeed(), GameConfig.DEFAULT_THEME));
       
    25 		setScheme(defaultScheme);
       
    26 		setWeaponset(defaultWeaponset);
       
    27 	}
       
    28 	
       
    29 	public void changeMapRecipe(MapRecipe map) {
       
    30 		setMapRecipe(map);
       
    31 	}
       
    32 
       
    33 	public void changeMapTheme(String theme) {
       
    34 		setMapRecipe(getMapRecipe().withTheme(theme));
       
    35 	}
       
    36 
       
    37 	public void changeMapNameAndGenerator(String mapName) {
       
    38 		int newGenerator = MapRecipe.generatorForMapname(mapName);
       
    39 		setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
       
    40 	}
       
    41 
       
    42 	public void changeMapTemplate(int template) {
       
    43 		setMapRecipe(getMapRecipe().withTemplateFilter(template));
       
    44 	}
       
    45 
       
    46 	public void changeMazeSize(int mazeSize) {
       
    47 		setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
       
    48 	}
       
    49 
       
    50 	public void changeMapSeed(String seed) {
       
    51 		setMapRecipe(getMapRecipe().withSeed(seed));
       
    52 	}
       
    53 
       
    54 	public void changeMapDrawdata(byte[] drawdata) {
       
    55 		setMapRecipe(getMapRecipe().withDrawData(drawdata));
       
    56 	}
       
    57 
       
    58 	public void changeScheme(Scheme scheme) {
       
    59 		setScheme(scheme);
       
    60 	}
       
    61 
       
    62 	public void changeGameStyle(String style) {
       
    63 		setGameStyle(style);
       
    64 	}
       
    65 
       
    66 	public void changeWeaponset(Weaponset weaponset) {
       
    67 		setWeaponset(weaponset);
       
    68 	}
       
    69 
       
    70 	public void requestAddTeam(Team team, int colorIndex) {
       
    71 		putTeam(new TeamInGame(team, new TeamIngameAttributes("Player", colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false)));
       
    72 	}
       
    73 
       
    74 	public void requestRemoveTeam(String teamname) {
       
    75 		removeTeam(teamname);
       
    76 	}
       
    77 
       
    78 	public void changeTeamColorIndex(String teamname, int colorIndex) {
       
    79 		TeamInGame oldTeam = getTeams().get(teamname);
       
    80 		if(oldTeam != null) {
       
    81 			putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withColorIndex(colorIndex)));
       
    82 		} else {
       
    83 			Log.e(TAG, "Requested color change for unknown team "+ teamname);
       
    84 		}
       
    85 	}
       
    86 
       
    87 	public void changeTeamHogCount(String teamname, int hogcount) {
       
    88 		TeamInGame oldTeam = getTeams().get(teamname);
       
    89 		if(oldTeam != null) {
       
    90 			putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withHogCount(hogcount)));
       
    91 		} else {
       
    92 			Log.e(TAG, "Requested hog count change for unknown team "+ teamname);
       
    93 		}
       
    94 	}
       
    95 }