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