project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapRecipe.java
author Medo <smaxein@googlemail.com>
Mon, 20 Aug 2012 20:19:35 +0200
changeset 7582 714310efad8f
parent 7508 763d3961400b
child 7584 7831c84cc644
permissions -rw-r--r--
Hedgeroid: Final sprint to the deadline - Changed local game setup to use the new fragments from the netroom - Pulled team editing into the main activity menu / action bar - Cleanups, renames, anything to make the code look better ;)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
/*
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
 *
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
 *
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
 *
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
 */
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
package org.hedgewars.hedgeroid.Datastructures;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    21
import java.util.Arrays;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    22
import java.util.UUID;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    23
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.R;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import org.hedgewars.hedgeroid.frontlib.Frontlib;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
import android.content.res.Resources;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
public final class MapRecipe {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
	public static final String MAPNAME_REGULAR = "+rnd+";
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
	public static final String MAPNAME_MAZE = "+maze+";
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
	public static final String MAPNAME_DRAWN = "+drawn+";
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
	public final int mapgen;			// Frontlib.MAPGEN_xxx
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	public final int templateFilter;	// Frontlib.TEMPLATEFILTER_xxx, only used when mapgen==MAPGEN_REGULAR
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
	public final int mazeSize;			// Frontlib.MAZE_SIZE_xxx, only used when mapgen==MAPGEN_MAZE
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
	public final String name, seed, theme;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	private final byte[] drawData;		// For drawn maps, can be null.
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
	public MapRecipe(int mapgen, int templateFilter, int mazeSize, String name, String seed, String theme, byte[] drawData) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
		this.mapgen = mapgen;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
		this.templateFilter = templateFilter;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
		this.mazeSize = mazeSize;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
		this.name = name;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
		this.seed = seed;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
		this.theme = theme;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		this.drawData = drawData==null ? null : drawData.clone();
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	public static MapRecipe makeMap(String name, String seed, String theme) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
		return new MapRecipe(Frontlib.MAPGEN_NAMED, 0, 0, name, seed, theme, null);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
	public static MapRecipe makeRandomMap(int templateFilter, String seed, String theme) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
		return new MapRecipe(Frontlib.MAPGEN_REGULAR, templateFilter, 0, MAPNAME_REGULAR, seed, theme, null);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
	public static MapRecipe makeRandomMaze(int mazeSize, String seed, String theme) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
		return new MapRecipe(Frontlib.MAPGEN_MAZE, 0, mazeSize, MAPNAME_MAZE, seed, theme, null);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
	public static MapRecipe makeDrawnMap(String seed, String theme, byte[] drawData) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
		return new MapRecipe(Frontlib.MAPGEN_DRAWN, 0, 0, MAPNAME_DRAWN, seed, theme, drawData);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
	public byte[] getDrawData() {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
		return drawData==null ? null : drawData.clone();
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
	}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    71
	public MapRecipe withMapgen(int mapgen) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    72
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    73
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    74
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    75
	public MapRecipe withTemplateFilter(int templateFilter) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    76
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    77
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    78
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    79
	public MapRecipe withMazeSize(int mazeSize) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    80
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    81
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    82
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    83
	public MapRecipe withName(String name) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    84
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    85
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    86
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    87
	public MapRecipe withSeed(String seed) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    88
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    89
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    90
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    91
	public MapRecipe withTheme(String theme) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    92
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    93
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    94
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    95
	public MapRecipe withDrawData(byte[] drawData) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    96
		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    97
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    98
	
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
	public static String formatMapName(Resources res, String map) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
		if(map.charAt(0)=='+') {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
			if(map.equals(MAPNAME_REGULAR)) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
				return res.getString(R.string.map_regular);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
			} else if(map.equals(MAPNAME_MAZE)) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
				return res.getString(R.string.map_maze);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
			} else if(map.equals(MAPNAME_DRAWN)) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
				return res.getString(R.string.map_drawn);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
			}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
		}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
		return map;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
	}
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   111
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   112
	/**
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   113
	 * Returns the mapname corresponding to the map generator (e.g. "+rnd+" for regular maps)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   114
	 * If the mapgen does not have a unique name (MAPGEN_NAMED) or is not known, the def
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   115
	 * value is returned.
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   116
	 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   117
	public static String mapnameForGenerator(int mapgen, String def) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   118
		switch(mapgen) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   119
		case Frontlib.MAPGEN_REGULAR: return MAPNAME_REGULAR;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   120
		case Frontlib.MAPGEN_MAZE: return MAPNAME_MAZE;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   121
		case Frontlib.MAPGEN_DRAWN: return MAPNAME_DRAWN;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   122
		default: return def;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   123
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   124
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   125
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   126
	/**
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   127
	 * In a sense this is the inverse of mapnameForGenerator. Returns the mapgen that uses
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   128
	 * mapName as special identifier, or MAPGEN_NAMED if there is none.
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   129
	 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   130
	public static int generatorForMapname(String mapName) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   131
		if(MapRecipe.MAPNAME_REGULAR.equals(mapName)) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   132
			return Frontlib.MAPGEN_REGULAR;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   133
		} else if(MapRecipe.MAPNAME_MAZE.equals(mapName)) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   134
			return Frontlib.MAPGEN_MAZE;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   135
		} else if(MapRecipe.MAPNAME_DRAWN.equals(mapName)) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   136
			return Frontlib.MAPGEN_DRAWN;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   137
		} else {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   138
			return Frontlib.MAPGEN_NAMED;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   139
		}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   140
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   141
	
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   142
	@Override
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   143
	public String toString() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   144
		return "MapRecipe [mapgen=" + mapgen + ", templateFilter="
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   145
				+ templateFilter + ", mazeSize=" + mazeSize + ", name=" + name
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   146
				+ ", seed=" + seed + ", theme=" + theme + ", drawData="
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   147
				+ Arrays.toString(drawData) + "]";
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   148
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   149
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   150
	@Override
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   151
	public int hashCode() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   152
		final int prime = 31;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   153
		int result = 1;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   154
		result = prime * result + Arrays.hashCode(drawData);
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   155
		result = prime * result + mapgen;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   156
		result = prime * result + mazeSize;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   157
		result = prime * result + ((name == null) ? 0 : name.hashCode());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   158
		result = prime * result + ((seed == null) ? 0 : seed.hashCode());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   159
		result = prime * result + templateFilter;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   160
		result = prime * result + ((theme == null) ? 0 : theme.hashCode());
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   161
		return result;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   162
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   163
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   164
	@Override
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   165
	public boolean equals(Object obj) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   166
		if (this == obj)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   167
			return true;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   168
		if (obj == null)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   169
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   170
		if (getClass() != obj.getClass())
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   171
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   172
		MapRecipe other = (MapRecipe) obj;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   173
		if (!Arrays.equals(drawData, other.drawData))
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   174
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   175
		if (mapgen != other.mapgen)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   176
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   177
		if (mazeSize != other.mazeSize)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   178
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   179
		if (name == null) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   180
			if (other.name != null)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   181
				return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   182
		} else if (!name.equals(other.name))
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   183
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   184
		if (seed == null) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   185
			if (other.seed != null)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   186
				return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   187
		} else if (!seed.equals(other.seed))
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   188
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   189
		if (templateFilter != other.templateFilter)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   190
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   191
		if (theme == null) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   192
			if (other.theme != null)
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   193
				return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   194
		} else if (!theme.equals(other.theme))
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   195
			return false;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   196
		return true;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   197
	}
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   198
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   199
	public static String makeRandomSeed() {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   200
		return "{"+UUID.randomUUID().toString()+"}";
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
   201
	}
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   202
}