author | Medo <smaxein@googlemail.com> |
Sun, 12 Aug 2012 22:37:57 +0200 | |
changeset 7482 | d70a5b0d1190 |
parent 7476 | 2fb781bbdd51 |
child 7485 | 0481bd74267c |
permissions | -rw-r--r-- |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
1 |
/* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com> |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
4 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
8 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
13 |
* |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
17 |
*/ |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
18 |
|
6488
c356ddebab84
android: moved the different objects representing the different game parameters to a different package
Xeli
parents:
6432
diff
changeset
|
19 |
package org.hedgewars.hedgeroid.Datastructures; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
20 |
|
6432
ffb18b44415d
Use proper names when storing custom teams, also fixes the bug which created new teams when you editted one of the default ones
Xeli
parents:
6047
diff
changeset
|
21 |
import java.io.File; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
22 |
import java.io.IOException; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
23 |
import java.util.ArrayList; |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
24 |
import java.util.Collections; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
25 |
import java.util.List; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
26 |
|
6488
c356ddebab84
android: moved the different objects representing the different game parameters to a different package
Xeli
parents:
6432
diff
changeset
|
27 |
import org.hedgewars.hedgeroid.EngineProtocol.PascalExports; |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.frontlib.Flib; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.frontlib.Frontlib.TeamPtr; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
30 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
31 |
import android.util.Log; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
32 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
33 |
public final class Team { |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
34 |
public static final String DIRECTORY_TEAMS = "teams"; |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
35 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
36 |
public static final int maxNumberOfHogs = PascalExports.HWgetMaxNumberOfHogs(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
37 |
public static final int maxNumberOfTeams = PascalExports.HWgetMaxNumberOfTeams(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
38 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
39 |
public final String name, grave, flag, voice, fort; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
40 |
public final List<Hog> hogs; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
41 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
42 |
public Team(String name, String grave, String flag, String voice, String fort, List<Hog> hogs) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
43 |
if(hogs.size() != maxNumberOfHogs) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
44 |
throw new IllegalArgumentException("A team must consist of "+maxNumberOfHogs+" hogs."); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
45 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
46 |
this.name = name; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
47 |
this.grave = grave; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
48 |
this.flag = flag; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
49 |
this.voice = voice; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
50 |
this.fort = fort; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
51 |
this.hogs = Collections.unmodifiableList(new ArrayList<Hog>(hogs)); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
52 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
53 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
54 |
public void save(File f) throws IOException { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
55 |
Log.d("Team", "saving to "+f.getAbsolutePath()); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
56 |
TeamPtr teamPtr = TeamPtr.createJavaOwned(this); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
57 |
if(Flib.INSTANCE.flib_team_to_ini(f.getAbsolutePath(), teamPtr) != 0) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
58 |
throw new IOException("Error saving team "+name); |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
59 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
60 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
61 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
62 |
public static Team load(File f) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
63 |
TeamPtr teamPtr = Flib.INSTANCE.flib_team_from_ini(f.getAbsolutePath()); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
64 |
if(teamPtr != null) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
65 |
Team team = teamPtr.deref().team; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
66 |
Flib.INSTANCE.flib_team_destroy(teamPtr); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
67 |
return team; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
68 |
} else { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
69 |
return null; |
6432
ffb18b44415d
Use proper names when storing custom teams, also fixes the bug which created new teams when you editted one of the default ones
Xeli
parents:
6047
diff
changeset
|
70 |
} |
ffb18b44415d
Use proper names when storing custom teams, also fixes the bug which created new teams when you editted one of the default ones
Xeli
parents:
6047
diff
changeset
|
71 |
} |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
72 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
73 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
74 |
public String toString() { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
75 |
return "Team [name=" + name + ", grave=" + grave + ", flag=" + flag |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
76 |
+ ", voice=" + voice + ", fort=" + fort + ", hogs=" + hogs |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
6840
diff
changeset
|
77 |
+ "]"; |
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
78 |
} |
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff
changeset
|
79 |
} |