|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU General Public License |
|
7 * as published by the Free Software Foundation; either version 2 |
|
8 * of the License, or (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program; if not, write to the Free Software |
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 */ |
|
19 |
|
20 #ifndef MODEL_WEAPON_H_ |
|
21 #define MODEL_WEAPON_H_ |
|
22 |
|
23 #include "../hwconsts.h" |
|
24 |
|
25 /** |
|
26 * These values are all ASCII characters in the range '0'..'9' |
|
27 * The fields are zero-terminated so they can easily be used as strings. |
|
28 * |
|
29 * For loadout, 9 means inifinite ammo. |
|
30 * For the other setting, 9 is invalid. |
|
31 */ |
|
32 typedef struct { |
|
33 char loadout[WEAPONS_COUNT+1]; |
|
34 char crateprob[WEAPONS_COUNT+1]; |
|
35 char crateammo[WEAPONS_COUNT+1]; |
|
36 char delay[WEAPONS_COUNT+1]; |
|
37 char *name; |
|
38 } flib_weaponset; |
|
39 |
|
40 typedef struct { |
|
41 int weaponsetCount; |
|
42 flib_weaponset **weaponsets; |
|
43 } flib_weaponsetlist; |
|
44 |
|
45 /** |
|
46 * Returns a new weapon set, or NULL on error. |
|
47 * name must not be NULL. |
|
48 * |
|
49 * The new weapon set is pre-filled with default |
|
50 * settings (see hwconsts.h) |
|
51 */ |
|
52 flib_weaponset *flib_weaponset_create(const char *name); |
|
53 |
|
54 /** |
|
55 * Free the memory used by this weaponset |
|
56 */ |
|
57 void flib_weaponset_destroy(flib_weaponset *weaponset); |
|
58 |
|
59 flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset); |
|
60 |
|
61 /** |
|
62 * Create a weaponset from an ammostring. This format is used both in the ini files |
|
63 * and in the net protocol. |
|
64 */ |
|
65 flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring); |
|
66 |
|
67 /** |
|
68 * Load a list of weaponsets from the ini file. |
|
69 * Returns NULL on error. |
|
70 */ |
|
71 flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename); |
|
72 |
|
73 /** |
|
74 * Store the list of weaponsets to an ini file. |
|
75 * Returns NULL on error. |
|
76 */ |
|
77 int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *weaponsets); |
|
78 |
|
79 /** |
|
80 * Create an empty weaponset list. Returns NULL on error. |
|
81 */ |
|
82 flib_weaponsetlist *flib_weaponsetlist_create(); |
|
83 |
|
84 /** |
|
85 * Release all memory associated with the weaponsetlist and release all contained weaponsets |
|
86 */ |
|
87 void flib_weaponsetlist_destroy(flib_weaponsetlist *list); |
|
88 |
|
89 /** |
|
90 * Insert a new weaponset into the list at position pos, moving all higher weaponsets to make place. |
|
91 * pos must be at least 0 (insert at the start) and at most list->weaponsetCount (insert at the end). |
|
92 * Ownership of the weaponset is transferred to the list. |
|
93 * Returns 0 on success. |
|
94 */ |
|
95 int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *weaponset, int pos); |
|
96 |
|
97 /** |
|
98 * Delete a weaponset from the list at position pos, moving down all higher weaponsets. |
|
99 * The weaponset is destroyed. |
|
100 * Returns 0 on success. |
|
101 */ |
|
102 int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos); |
|
103 |
|
104 #endif |