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