project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/GameConfig.java
author Xeli
Sun, 21 Aug 2011 16:25:18 +0200
branchhedgeroid
changeset 5621 ea796c83ea47
parent 5508 dcf1b3645af6
permissions -rw-r--r--
added licenses
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     1
/*
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    17
 */
ea796c83ea47 added licenses
Xeli
parents: 5508
diff changeset
    18
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    19
package org.hedgewars.mobile.EngineProtocol;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    20
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    21
import java.io.IOException;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    22
import java.util.ArrayList;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    23
import java.util.UUID;
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
import android.os.Parcel;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    26
import android.os.Parcelable;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    27
import android.util.Log;
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 class GameConfig implements Parcelable{
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
	public GameMode mode = GameMode.MODE_LOCAL;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    32
	public Map map = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    33
	public String theme = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    34
	public Scheme scheme = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    35
	public Weapon weapon = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    36
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    37
	public String mission = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    38
	public String seed = null;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    39
	
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    40
	public ArrayList<Team> teams = new ArrayList<Team>();
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    41
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    42
	public GameConfig(){
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
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    45
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    46
	public GameConfig(Parcel in){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    47
		readFromParcel(in);	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    48
	}
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
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
	public void sendToEngine(EngineProtocolNetwork epn) throws IOException{
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    53
		Log.d("HW_Frontend", "Sending Gameconfig...");
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    54
		int teamCount = 4;
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    55
		epn.sendToEngine("TL"); //Write game mode
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    56
		if(mission != null) epn.sendToEngine(mission);
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
		//seed info
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    59
		epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString()));
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
		map.sendToEngine(epn);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    62
		//dimensions of the map
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    63
		//templatefilter_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    64
		//mapgen_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    65
		//mazesize_command
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    66
		
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    67
		epn.sendToEngine(String.format("etheme %s", theme));
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    68
		
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    69
		scheme.sendToEngine(epn);
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    70
		
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    71
		weapon.sendToEngine(epn, teamCount);
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    72
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    73
		for(Team t : teams){
5508
dcf1b3645af6 Fixed IPC provide gameconfig
Xeli
parents: 5475
diff changeset
    74
			if(t != null)t.sendToEngine(epn, teamCount, 50);
5475
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    75
		}
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
	public int describeContents() {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    79
		return 0;
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    80
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    81
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    82
	public void writeToParcel(Parcel dest, int flags) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    83
		dest.writeString(mode.name());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    84
		dest.writeParcelable(map, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    85
		dest.writeString(theme);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    86
		dest.writeParcelable(scheme, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    87
		dest.writeParcelable(weapon, flags);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    88
		dest.writeString(mission);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    89
		dest.writeString(seed);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    90
		dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0);
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
	private void readFromParcel(Parcel src){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    94
		mode = GameMode.valueOf(src.readString());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    95
		map = src.readParcelable(Map.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    96
		theme = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    97
		scheme = src.readParcelable(Scheme.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    98
		weapon = src.readParcelable(Weapon.class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
    99
		mission = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   100
		seed = src.readString();
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   101
		Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader());
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   102
		for(Parcelable team : parcelables){
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   103
			teams.add((Team)team);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   104
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   105
		
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   106
	}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   107
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   108
	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
   109
		public GameConfig createFromParcel(Parcel source) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   110
			return new GameConfig(source);
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   111
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   112
		public GameConfig[] newArray(int size) {
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   113
			return new GameConfig[size];
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   114
		}
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   115
	};
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   116
	
06a87ff38ffb The start of the IPC transers to the engine
Xeli
parents:
diff changeset
   117
}