project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Team.java
changeset 6432 ffb18b44415d
parent 6047 10011f051f9c
equal deleted inserted replaced
6431:f0a7c5415119 6432:ffb18b44415d
    17  */
    17  */
    18 
    18 
    19 package org.hedgewars.hedgeroid.EngineProtocol;
    19 package org.hedgewars.hedgeroid.EngineProtocol;
    20 
    20 
    21 import java.io.BufferedReader;
    21 import java.io.BufferedReader;
       
    22 import java.io.File;
    22 import java.io.FileNotFoundException;
    23 import java.io.FileNotFoundException;
    23 import java.io.FileReader;
    24 import java.io.FileReader;
    24 import java.io.IOException;
    25 import java.io.IOException;
    25 import java.io.OutputStream;
    26 import java.io.OutputStream;
    26 import java.util.ArrayList;
    27 import java.util.ArrayList;
    28 import org.xmlpull.v1.XmlPullParser;
    29 import org.xmlpull.v1.XmlPullParser;
    29 import org.xmlpull.v1.XmlPullParserException;
    30 import org.xmlpull.v1.XmlPullParserException;
    30 import org.xmlpull.v1.XmlPullParserFactory;
    31 import org.xmlpull.v1.XmlPullParserFactory;
    31 import org.xmlpull.v1.XmlSerializer;
    32 import org.xmlpull.v1.XmlSerializer;
    32 
    33 
       
    34 import android.content.Context;
    33 import android.os.Parcel;
    35 import android.os.Parcel;
    34 import android.os.Parcelable;
    36 import android.os.Parcelable;
    35 import android.util.Xml;
    37 import android.util.Xml;
    36 
    38 
    37 public class Team implements Parcelable{
    39 public class Team implements Parcelable{
    59 	private static final int STATE_START = 0;
    61 	private static final int STATE_START = 0;
    60 	private static final int STATE_ROOT = 1;
    62 	private static final int STATE_ROOT = 1;
    61 	private static final int STATE_HOG_ROOT = 2;
    63 	private static final int STATE_HOG_ROOT = 2;
    62 
    64 
    63 	public String name, grave, flag, voice, fort, hash;
    65 	public String name, grave, flag, voice, fort, hash;
       
    66 	public String file = null;
    64 
    67 
    65 	public static int maxNumberOfHogs = 0;
    68 	public static int maxNumberOfHogs = 0;
    66 	public static int maxNumberOfTeams = 0;
    69 	public static int maxNumberOfTeams = 0;
    67 
    70 
    68 	static{
    71 	static{
   128 			epn.sendToEngine(String.format("eaddhh %d %d %s", levels[i], health, hogNames[i]));
   131 			epn.sendToEngine(String.format("eaddhh %d %d %s", levels[i], health, hogNames[i]));
   129 			epn.sendToEngine(String.format("ehat %s", hats[i]));
   132 			epn.sendToEngine(String.format("ehat %s", hats[i]));
   130 		}
   133 		}
   131 	}
   134 	}
   132 
   135 
       
   136 	public void setFileName(Context c){
       
   137 		if(file == null){
       
   138 		  	file = validFileName(c, name);
       
   139 		}
       
   140 	}
       
   141 	private String validFileName(Context c, String fileName){
       
   142 		String absolutePath = String.format("%s/%s", c.getFilesDir(), fileName);
       
   143 		File f = new File(absolutePath);
       
   144 		if(f.exists()){
       
   145 			String newFileName = fileName + (int)(Math.random()*10);
       
   146 			return validFileName(c, newFileName);
       
   147 		}else{
       
   148 			return fileName;
       
   149 		}
       
   150 	}
       
   151 	
   133 	/*
   152 	/*
   134 	 * XML METHODS
   153 	 * XML METHODS
   135 	 */
   154 	 */
   136 
   155 
   137 	/**
   156 	/**
   309 		dest.writeStringArray(hats);
   328 		dest.writeStringArray(hats);
   310 		dest.writeStringArray(hogNames);
   329 		dest.writeStringArray(hogNames);
   311 		dest.writeIntArray(levels);
   330 		dest.writeIntArray(levels);
   312 		dest.writeInt(color);
   331 		dest.writeInt(color);
   313 		dest.writeInt(hogCount);
   332 		dest.writeInt(hogCount);
       
   333 		dest.writeString(file);
   314 	}
   334 	}
   315 
   335 
   316 
   336 
   317 	public void readFromParcel(Parcel src){
   337 	public void readFromParcel(Parcel src){
   318 		name = src.readString();
   338 		name = src.readString();
   324 		src.readStringArray(hats);
   344 		src.readStringArray(hats);
   325 		src.readStringArray(hogNames);
   345 		src.readStringArray(hogNames);
   326 		src.readIntArray(levels);
   346 		src.readIntArray(levels);
   327 		color = src.readInt();
   347 		color = src.readInt();
   328 		hogCount = src.readInt();
   348 		hogCount = src.readInt();
       
   349 		file = src.readString();
   329 	}
   350 	}
   330 
   351 
   331 	public static final Parcelable.Creator<Team> CREATOR = new Parcelable.Creator<Team>() {
   352 	public static final Parcelable.Creator<Team> CREATOR = new Parcelable.Creator<Team>() {
   332 		public Team createFromParcel(Parcel source) {
   353 		public Team createFromParcel(Parcel source) {
   333 			return new Team(source);
   354 			return new Team(source);