project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapRecipe.java
changeset 7485 0481bd74267c
child 7508 763d3961400b
equal deleted inserted replaced
7482:d70a5b0d1190 7485:0481bd74267c
       
     1 /*
       
     2  * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 package org.hedgewars.hedgeroid.Datastructures;
       
    20 
       
    21 import org.hedgewars.hedgeroid.R;
       
    22 import org.hedgewars.hedgeroid.frontlib.Frontlib;
       
    23 
       
    24 import android.content.res.Resources;
       
    25 
       
    26 public final class MapRecipe {
       
    27 	public static final String MAPNAME_REGULAR = "+rnd+";
       
    28 	public static final String MAPNAME_MAZE = "+maze+";
       
    29 	public static final String MAPNAME_DRAWN = "+drawn+";
       
    30 
       
    31 	public final int mapgen;			// Frontlib.MAPGEN_xxx
       
    32 	public final int templateFilter;	// Frontlib.TEMPLATEFILTER_xxx, only used when mapgen==MAPGEN_REGULAR
       
    33 	public final int mazeSize;			// Frontlib.MAZE_SIZE_xxx, only used when mapgen==MAPGEN_MAZE
       
    34 	public final String name, seed, theme;
       
    35 	
       
    36 	private final byte[] drawData;		// For drawn maps, can be null.
       
    37 
       
    38 	public MapRecipe(int mapgen, int templateFilter, int mazeSize, String name, String seed, String theme, byte[] drawData) {
       
    39 		this.mapgen = mapgen;
       
    40 		this.templateFilter = templateFilter;
       
    41 		this.mazeSize = mazeSize;
       
    42 		this.name = name;
       
    43 		this.seed = seed;
       
    44 		this.theme = theme;
       
    45 		this.drawData = drawData==null ? null : drawData.clone();
       
    46 	}
       
    47 	
       
    48 	public static MapRecipe makeMap(String name, String seed, String theme) {
       
    49 		return new MapRecipe(Frontlib.MAPGEN_NAMED, 0, 0, name, seed, theme, null);
       
    50 	}
       
    51 	
       
    52 	public static MapRecipe makeRandomMap(int templateFilter, String seed, String theme) {
       
    53 		return new MapRecipe(Frontlib.MAPGEN_REGULAR, templateFilter, 0, MAPNAME_REGULAR, seed, theme, null);
       
    54 	}
       
    55 	
       
    56 	public static MapRecipe makeRandomMaze(int mazeSize, String seed, String theme) {
       
    57 		return new MapRecipe(Frontlib.MAPGEN_MAZE, 0, mazeSize, MAPNAME_MAZE, seed, theme, null);
       
    58 	}
       
    59 	
       
    60 	public static MapRecipe makeDrawnMap(String seed, String theme, byte[] drawData) {
       
    61 		return new MapRecipe(Frontlib.MAPGEN_DRAWN, 0, 0, MAPNAME_DRAWN, seed, theme, drawData);
       
    62 	}
       
    63 	
       
    64 	public byte[] getDrawData() {
       
    65 		return drawData==null ? null : drawData.clone();
       
    66 	}
       
    67 	
       
    68 	public static String formatMapName(Resources res, String map) {
       
    69 		if(map.charAt(0)=='+') {
       
    70 			if(map.equals(MAPNAME_REGULAR)) {
       
    71 				return res.getString(R.string.map_regular);
       
    72 			} else if(map.equals(MAPNAME_MAZE)) {
       
    73 				return res.getString(R.string.map_maze);
       
    74 			} else if(map.equals(MAPNAME_DRAWN)) {
       
    75 				return res.getString(R.string.map_drawn);
       
    76 			}
       
    77 		}
       
    78 		return map;
       
    79 	}
       
    80 }