1 /* |
1 /* |
2 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
2 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
3 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
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 |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
20 |
20 |
21 import java.io.IOException; |
21 import java.io.IOException; |
22 import java.util.ArrayList; |
22 import java.util.ArrayList; |
23 import java.util.UUID; |
23 import java.util.UUID; |
24 |
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 |
25 import android.os.Parcel; |
31 import android.os.Parcel; |
26 import android.os.Parcelable; |
32 import android.os.Parcelable; |
27 import android.util.Log; |
33 import android.util.Log; |
28 |
34 |
29 public class GameConfig implements Parcelable{ |
35 public class GameConfig implements Parcelable{ |
32 public Map map = null; |
38 public Map map = null; |
33 public String theme = null; |
39 public String theme = null; |
34 public Scheme scheme = null; |
40 public Scheme scheme = null; |
35 public Weapon weapon = null; |
41 public Weapon weapon = null; |
36 |
42 |
37 public String mission = null; |
43 public String style = null; |
|
44 public String training = null; |
38 public String seed = null; |
45 public String seed = null; |
39 |
46 |
40 public ArrayList<Team> teams = new ArrayList<Team>(); |
47 public ArrayList<Team> teams = new ArrayList<Team>(); |
41 |
48 |
42 public GameConfig(){ |
49 public GameConfig(){ |
51 |
58 |
52 public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
59 public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
53 Log.d("HW_Frontend", "Sending Gameconfig..."); |
60 Log.d("HW_Frontend", "Sending Gameconfig..."); |
54 int teamCount = 4; |
61 int teamCount = 4; |
55 epn.sendToEngine("TL"); //Write game mode |
62 epn.sendToEngine("TL"); //Write game mode |
56 if(mission != null) epn.sendToEngine(mission); |
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)); |
57 |
65 |
58 //seed info |
66 //seed info |
59 epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString())); |
67 epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString())); |
60 |
68 |
61 map.sendToEngine(epn); |
69 map.sendToEngine(epn); |
69 scheme.sendToEngine(epn); |
77 scheme.sendToEngine(epn); |
70 |
78 |
71 weapon.sendToEngine(epn, teamCount); |
79 weapon.sendToEngine(epn, teamCount); |
72 |
80 |
73 for(Team t : teams){ |
81 for(Team t : teams){ |
74 if(t != null)t.sendToEngine(epn, teamCount, 50); |
82 if(t != null)t.sendToEngine(epn, teamCount, scheme.health); |
75 } |
83 } |
76 } |
84 } |
77 |
85 |
78 public int describeContents() { |
86 public int describeContents() { |
79 return 0; |
87 return 0; |
83 dest.writeString(mode.name()); |
91 dest.writeString(mode.name()); |
84 dest.writeParcelable(map, flags); |
92 dest.writeParcelable(map, flags); |
85 dest.writeString(theme); |
93 dest.writeString(theme); |
86 dest.writeParcelable(scheme, flags); |
94 dest.writeParcelable(scheme, flags); |
87 dest.writeParcelable(weapon, flags); |
95 dest.writeParcelable(weapon, flags); |
88 dest.writeString(mission); |
96 dest.writeString(style); |
|
97 dest.writeString(training); |
89 dest.writeString(seed); |
98 dest.writeString(seed); |
90 dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0); |
99 dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0); |
91 } |
100 } |
92 |
101 |
93 private void readFromParcel(Parcel src){ |
102 private void readFromParcel(Parcel src){ |
94 mode = GameMode.valueOf(src.readString()); |
103 mode = GameMode.valueOf(src.readString()); |
95 map = src.readParcelable(Map.class.getClassLoader()); |
104 map = src.readParcelable(Map.class.getClassLoader()); |
96 theme = src.readString(); |
105 theme = src.readString(); |
97 scheme = src.readParcelable(Scheme.class.getClassLoader()); |
106 scheme = src.readParcelable(Scheme.class.getClassLoader()); |
98 weapon = src.readParcelable(Weapon.class.getClassLoader()); |
107 weapon = src.readParcelable(Weapon.class.getClassLoader()); |
99 mission = src.readString(); |
108 style = src.readString(); |
|
109 training = src.readString(); |
100 seed = src.readString(); |
110 seed = src.readString(); |
101 Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader()); |
111 Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader()); |
102 for(Parcelable team : parcelables){ |
112 for(Parcelable team : parcelables){ |
103 teams.add((Team)team); |
113 teams.add((Team)team); |
104 } |
114 } |