project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/GameConfig.java
author Xeli
Thu, 04 Aug 2011 17:37:40 +0200
branchhedgeroid
changeset 5475 06a87ff38ffb
child 5508 dcf1b3645af6
permissions -rw-r--r--
The start of the IPC transers to the engine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     1
package org.hedgewars.mobile.EngineProtocol;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     2
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     3
import java.io.IOException;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     4
import java.io.OutputStream;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     5
import java.util.ArrayList;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     6
import java.util.UUID;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     7
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     8
import android.os.Parcel;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
     9
import android.os.Parcelable;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    10
import android.util.Log;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    11
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    12
public class GameConfig implements Parcelable{
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    13
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    14
	public GameMode mode = GameMode.MODE_LOCAL;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    15
	public Map map = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    16
	public String theme = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    17
	public Scheme scheme = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    18
	public Weapon weapon = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    19
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    20
	public String mission = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    21
	public String seed = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    22
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    23
	public ArrayList<Team> teams = new ArrayList<Team>(8);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    24
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    25
	public GameConfig(){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    26
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    27
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    28
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    29
	public GameConfig(Parcel in){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    30
		readFromParcel(in);	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    31
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    32
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    33
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    34
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    35
	public void sendToEngine(EngineProtocolNetwork epn) throws IOException{
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    36
		Log.d("HW_Frontend", "Sending Gameconfig...");
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    37
		int teamCount = 8;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    38
		epn.sendToEngine("TL"); //Write game mode
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    39
		if(mission != null) epn.sendToEngine(mission);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    40
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    41
		//seed info
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    42
		epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString()));
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    43
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    44
		map.sendToEngine(epn);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    45
		//dimensions of the map
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    46
		//templatefilter_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    47
		//mapgen_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    48
		//mazesize_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    49
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    50
		//epn.sendToEngine(String.format("etheme %s", theme));
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    51
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    52
		//scheme.sendToEngine(epn);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    53
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    54
		//weapon.sendToEngine(os, teamCount);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    55
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    56
		for(Team t : teams){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    57
			//t.sendToEngine(os, teamCount, 50, 0);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    58
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    59
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    60
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    61
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    62
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    63
	public int describeContents() {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    64
		return 0;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    65
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    66
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    67
	public void writeToParcel(Parcel dest, int flags) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    68
		dest.writeString(mode.name());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    69
		dest.writeParcelable(map, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    70
		dest.writeString(theme);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    71
		dest.writeParcelable(scheme, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    72
		dest.writeParcelable(weapon, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    73
		dest.writeString(mission);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    74
		dest.writeString(seed);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    75
		dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    76
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    77
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    78
	private void readFromParcel(Parcel src){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    79
		mode = GameMode.valueOf(src.readString());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    80
		map = src.readParcelable(Map.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    81
		theme = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    82
		scheme = src.readParcelable(Scheme.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    83
		weapon = src.readParcelable(Weapon.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    84
		mission = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    85
		seed = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    86
		Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    87
		for(Parcelable team : parcelables){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    88
			teams.add((Team)team);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    89
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    90
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    91
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    92
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    93
	public static final Parcelable.Creator<GameConfig> CREATOR = new Parcelable.Creator<GameConfig>() {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    94
		public GameConfig createFromParcel(Parcel source) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    95
			return new GameConfig(source);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    96
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    97
		public GameConfig[] newArray(int size) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    98
			return new GameConfig[size];
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    99
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   100
	};
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   101
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   102
}