|
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 #include "gamesetup.h" |
|
21 #include "../util/util.h" |
|
22 |
|
23 #include <stdlib.h> |
|
24 |
|
25 void flib_gamesetup_destroy(flib_gamesetup *gamesetup) { |
|
26 if(gamesetup) { |
|
27 free(gamesetup->style); |
|
28 flib_scheme_destroy(gamesetup->gamescheme); |
|
29 flib_map_destroy(gamesetup->map); |
|
30 flib_teamlist_destroy(gamesetup->teamlist); |
|
31 free(gamesetup); |
|
32 } |
|
33 } |
|
34 |
|
35 flib_gamesetup *flib_gamesetup_copy(const flib_gamesetup *setup) { |
|
36 if(!setup) { |
|
37 return NULL; |
|
38 } |
|
39 |
|
40 flib_gamesetup *result = flib_calloc(1, sizeof(flib_gamesetup)); |
|
41 if(result) { |
|
42 result->style = flib_strdupnull(setup->style); |
|
43 result->gamescheme = flib_scheme_copy(setup->gamescheme); |
|
44 result->map = flib_map_copy(setup->map); |
|
45 result->teamlist = flib_teamlist_copy(setup->teamlist); |
|
46 if((setup->style && !result->style) |
|
47 || (setup->gamescheme && !result->gamescheme) |
|
48 || (setup->map && !result->map) |
|
49 || (setup->teamlist && !result->teamlist)) { |
|
50 flib_gamesetup_destroy(result); |
|
51 result = NULL; |
|
52 } |
|
53 } |
|
54 return result; |
|
55 } |