1 /* |
|
2 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2011-2012 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.hedgeroid.EngineProtocol; |
|
20 |
|
21 import java.io.IOException; |
|
22 import java.util.ArrayList; |
|
23 import java.util.UUID; |
|
24 |
|
25 import org.hedgewars.hedgeroid.Datastructures.GameMode; |
|
26 import org.hedgewars.hedgeroid.Datastructures.Map; |
|
27 import org.hedgewars.hedgeroid.Datastructures.Scheme; |
|
28 import org.hedgewars.hedgeroid.Datastructures.Team; |
|
29 import org.hedgewars.hedgeroid.Datastructures.Weapon; |
|
30 |
|
31 import android.os.Parcel; |
|
32 import android.os.Parcelable; |
|
33 import android.util.Log; |
|
34 |
|
35 public class GameConfig implements Parcelable{ |
|
36 |
|
37 public GameMode mode = GameMode.MODE_LOCAL; |
|
38 public Map map = null; |
|
39 public String theme = null; |
|
40 public Scheme scheme = null; |
|
41 public Weapon weapon = null; |
|
42 |
|
43 public String style = null; |
|
44 public String training = null; |
|
45 public String seed = null; |
|
46 |
|
47 public ArrayList<Team> teams = new ArrayList<Team>(); |
|
48 |
|
49 public GameConfig(){ |
|
50 |
|
51 } |
|
52 |
|
53 public GameConfig(Parcel in){ |
|
54 readFromParcel(in); |
|
55 } |
|
56 |
|
57 |
|
58 |
|
59 public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
|
60 Log.d("HW_Frontend", "Sending Gameconfig..."); |
|
61 int teamCount = 4; |
|
62 epn.sendToEngine("TL"); //Write game mode |
|
63 if(training != null) epn.sendToEngine(String.format("escript Scripts/Training/%s.lua", training)); |
|
64 else if(style != null) epn.sendToEngine(String.format("escript Scripts/Multiplayer/%s.lua", style)); |
|
65 |
|
66 //seed info |
|
67 epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString())); |
|
68 |
|
69 map.sendToEngine(epn); |
|
70 //dimensions of the map |
|
71 //templatefilter_command |
|
72 //mapgen_command |
|
73 //mazesize_command |
|
74 |
|
75 epn.sendToEngine(String.format("etheme %s", theme)); |
|
76 |
|
77 scheme.sendToEngine(epn); |
|
78 |
|
79 weapon.sendToEngine(epn, teamCount); |
|
80 |
|
81 for(Team t : teams){ |
|
82 if(t != null)t.sendToEngine(epn, teamCount, scheme.health); |
|
83 } |
|
84 } |
|
85 |
|
86 public int describeContents() { |
|
87 return 0; |
|
88 } |
|
89 |
|
90 public void writeToParcel(Parcel dest, int flags) { |
|
91 dest.writeString(mode.name()); |
|
92 dest.writeParcelable(map, flags); |
|
93 dest.writeString(theme); |
|
94 dest.writeParcelable(scheme, flags); |
|
95 dest.writeParcelable(weapon, flags); |
|
96 dest.writeString(style); |
|
97 dest.writeString(training); |
|
98 dest.writeString(seed); |
|
99 dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0); |
|
100 } |
|
101 |
|
102 private void readFromParcel(Parcel src){ |
|
103 mode = GameMode.valueOf(src.readString()); |
|
104 map = src.readParcelable(Map.class.getClassLoader()); |
|
105 theme = src.readString(); |
|
106 scheme = src.readParcelable(Scheme.class.getClassLoader()); |
|
107 weapon = src.readParcelable(Weapon.class.getClassLoader()); |
|
108 style = src.readString(); |
|
109 training = src.readString(); |
|
110 seed = src.readString(); |
|
111 Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader()); |
|
112 for(Parcelable team : parcelables){ |
|
113 teams.add((Team)team); |
|
114 } |
|
115 |
|
116 } |
|
117 |
|
118 public static final Parcelable.Creator<GameConfig> CREATOR = new Parcelable.Creator<GameConfig>() { |
|
119 public GameConfig createFromParcel(Parcel source) { |
|
120 return new GameConfig(source); |
|
121 } |
|
122 public GameConfig[] newArray(int size) { |
|
123 return new GameConfig[size]; |
|
124 } |
|
125 }; |
|
126 |
|
127 } |
|