16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
19 package org.hedgewars.hedgeroid.EngineProtocol; |
19 package org.hedgewars.hedgeroid.EngineProtocol; |
20 |
20 |
21 import java.io.IOException; |
|
22 import java.util.ArrayList; |
21 import java.util.ArrayList; |
23 import java.util.UUID; |
|
24 |
22 |
25 import org.hedgewars.hedgeroid.Datastructures.GameMode; |
23 import org.hedgewars.hedgeroid.Datastructures.GameMode; |
26 import org.hedgewars.hedgeroid.Datastructures.Map; |
24 import org.hedgewars.hedgeroid.Datastructures.Map; |
27 import org.hedgewars.hedgeroid.Datastructures.Scheme; |
25 import org.hedgewars.hedgeroid.Datastructures.Scheme; |
28 import org.hedgewars.hedgeroid.Datastructures.Team; |
26 import org.hedgewars.hedgeroid.Datastructures.Team; |
29 import org.hedgewars.hedgeroid.Datastructures.Weapon; |
27 import org.hedgewars.hedgeroid.Datastructures.Weapon; |
30 |
28 |
31 import android.os.Parcel; |
29 public class GameConfig { |
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; |
30 public GameMode mode = GameMode.MODE_LOCAL; |
38 public Map map = null; |
31 public Map map = null; |
39 public String theme = null; |
32 public String theme = null; |
40 public Scheme scheme = null; |
33 public Scheme scheme = null; |
41 public Weapon weapon = null; |
34 public Weapon weapon = null; |
47 public ArrayList<Team> teams = new ArrayList<Team>(); |
40 public ArrayList<Team> teams = new ArrayList<Team>(); |
48 |
41 |
49 public GameConfig(){ |
42 public GameConfig(){ |
50 |
43 |
51 } |
44 } |
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.getHealth()); |
|
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 } |
45 } |