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