author | Medo <smaxein@googlemail.com> |
Wed, 27 Jun 2012 22:52:19 +0200 | |
changeset 7314 | 6171f0bad318 |
parent 7275 | 15f722e0b96f |
child 7316 | f7b49b2c5d84 |
permissions | -rw-r--r-- |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
1 |
/* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
4 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
9 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
13 |
* GNU General Public License for more details. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
14 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
18 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
19 |
|
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
#include "team.h" |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
21 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
22 |
#include "../util/inihelper.h" |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
23 |
#include "../util/util.h" |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
24 |
#include "../util/logging.h" |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
25 |
#include "../util/refcounter.h" |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
26 |
|
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
27 |
#include <string.h> |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
28 |
#include <stdlib.h> |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
29 |
|
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
30 |
static flib_team *from_ini_handleError(flib_team *result, flib_ini *settingfile) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
31 |
flib_ini_destroy(settingfile); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
32 |
flib_team_release(result); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
33 |
return NULL; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
34 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
35 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
36 |
flib_team *flib_team_from_ini(const char *filename) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
37 |
flib_team *result = flib_team_retain(flib_calloc(1, sizeof(flib_team))); |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
38 |
flib_ini *ini = NULL; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
39 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
40 |
if(!filename) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
41 |
flib_log_e("null parameter in flib_team_from_ini"); |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
42 |
return from_ini_handleError(result, ini); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
43 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
44 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
45 |
if(!result) { |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
46 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
47 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
48 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
49 |
ini = flib_ini_load(filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
50 |
if(!ini) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
51 |
flib_log_e("Error loading team file %s", filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
52 |
return from_ini_handleError(result, ini); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
53 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
54 |
|
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
55 |
if(flib_ini_enter_section(ini, "team")) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
56 |
flib_log_e("Missing section \"Team\" in team file %s", filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
57 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
58 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
59 |
bool error = false; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
60 |
error |= flib_ini_get_str(ini, &result->name, "name"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
61 |
error |= flib_ini_get_str(ini, &result->grave, "grave"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
62 |
error |= flib_ini_get_str(ini, &result->fort, "fort"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
63 |
error |= flib_ini_get_str(ini, &result->voicepack, "voicepack"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
64 |
error |= flib_ini_get_str(ini, &result->flag, "flag"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
65 |
error |= flib_ini_get_int(ini, &result->rounds, "rounds"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
66 |
error |= flib_ini_get_int(ini, &result->wins, "wins"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
67 |
error |= flib_ini_get_int(ini, &result->campaignProgress, "campaignprogress"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
68 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
69 |
int difficulty = 0; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
70 |
error |= flib_ini_get_int(ini, &difficulty, "difficulty"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
71 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
72 |
if(error) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
73 |
flib_log_e("Missing or malformed entry in section \"Team\" in file %s", filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
74 |
return from_ini_handleError(result, ini); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
75 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
76 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
77 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
78 |
char sectionName[32]; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
79 |
if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
80 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
81 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
82 |
if(flib_ini_enter_section(ini, sectionName)) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
83 |
flib_log_e("Missing section \"%s\" in team file %s", sectionName, filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
84 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
85 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
86 |
flib_hog *hog = &result->hogs[i]; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
87 |
error |= flib_ini_get_str(ini, &hog->name, "name"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
88 |
error |= flib_ini_get_str(ini, &hog->hat, "hat"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
89 |
error |= flib_ini_get_int(ini, &hog->rounds, "rounds"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
90 |
error |= flib_ini_get_int(ini, &hog->kills, "kills"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
91 |
error |= flib_ini_get_int(ini, &hog->deaths, "deaths"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
92 |
error |= flib_ini_get_int(ini, &hog->suicides, "suicides"); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
93 |
result->hogs[i].difficulty = difficulty; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
94 |
result->hogs[i].initialHealth = TEAM_DEFAULT_HEALTH; |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
95 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
96 |
if(error) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
97 |
flib_log_e("Missing or malformed entry in section \"%s\" in file %s", sectionName, filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
98 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
99 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
100 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
101 |
|
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
102 |
if(!flib_ini_enter_section(ini, "binds")) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
103 |
result->bindingCount = flib_ini_get_keycount(ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
104 |
if(result->bindingCount<0) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
105 |
flib_log_e("Error reading bindings from file %s", filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
106 |
result->bindingCount = 0; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
107 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
108 |
result->bindings = flib_calloc(result->bindingCount, sizeof(flib_binding)); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
109 |
if(!result->bindings) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
110 |
return from_ini_handleError(result, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
111 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
112 |
for(int i=0; i<result->bindingCount; i++) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
113 |
char *keyname = flib_ini_get_keyname(ini, i); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
114 |
if(!keyname) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
115 |
error = true; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
116 |
} else { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
117 |
result->bindings[i].action = flib_urldecode(keyname); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
118 |
error |= !result->bindings[i].action; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
119 |
error |= flib_ini_get_str(ini, &result->bindings[i].binding, keyname); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
120 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
121 |
free(keyname); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
122 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
123 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
124 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
125 |
if(error) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
126 |
flib_log_e("Error reading team file %s", filename); |
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
127 |
return from_ini_handleError(result, ini); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
128 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
129 |
|
7227
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
130 |
flib_ini_destroy(ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
131 |
return result; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
132 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
133 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
134 |
static int writeTeamSection(const flib_team *team, flib_ini *ini) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
135 |
if(flib_ini_create_section(ini, "team")) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
136 |
return -1; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
137 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
138 |
bool error = false; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
139 |
error |= flib_ini_set_str(ini, "name", team->name); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
140 |
error |= flib_ini_set_str(ini, "grave", team->grave); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
141 |
error |= flib_ini_set_str(ini, "fort", team->fort); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
142 |
error |= flib_ini_set_str(ini, "voicepack", team->voicepack); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
143 |
error |= flib_ini_set_str(ini, "flag", team->flag); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
144 |
error |= flib_ini_set_int(ini, "rounds", team->rounds); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
145 |
error |= flib_ini_set_int(ini, "wins", team->wins); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
146 |
error |= flib_ini_set_int(ini, "campaignprogress", team->campaignProgress); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
147 |
error |= flib_ini_set_int(ini, "difficulty", team->hogs[0].difficulty); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
148 |
return error; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
149 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
150 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
151 |
static int writeHogSections(const flib_team *team, flib_ini *ini) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
152 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
153 |
const flib_hog *hog = &team->hogs[i]; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
154 |
char sectionName[32]; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
155 |
if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
156 |
return -1; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
157 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
158 |
if(flib_ini_create_section(ini, sectionName)) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
159 |
return -1; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
160 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
161 |
bool error = false; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
162 |
error |= flib_ini_set_str(ini, "name", hog->name); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
163 |
error |= flib_ini_set_str(ini, "hat", hog->hat); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
164 |
error |= flib_ini_set_int(ini, "rounds", hog->rounds); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
165 |
error |= flib_ini_set_int(ini, "kills", hog->kills); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
166 |
error |= flib_ini_set_int(ini, "deaths", hog->deaths); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
167 |
error |= flib_ini_set_int(ini, "suicides", hog->suicides); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
168 |
if(error) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
169 |
return error; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
170 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
171 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
172 |
return 0; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
173 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
174 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
175 |
static int writeBindingSection(const flib_team *team, flib_ini *ini) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
176 |
if(flib_ini_create_section(ini, "binds")) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
177 |
return -1; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
178 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
179 |
for(int i=0; i<team->bindingCount; i++) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
180 |
bool error = false; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
181 |
char *action = flib_urlencode(team->bindings[i].action); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
182 |
if(action) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
183 |
error |= flib_ini_set_str(ini, action, team->bindings[i].binding); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
184 |
free(action); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
185 |
} else { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
186 |
error = true; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
187 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
188 |
if(error) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
189 |
return error; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
190 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
191 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
192 |
return 0; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
193 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
194 |
|
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
195 |
int flib_team_to_ini(const char *filename, const flib_team *team) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
196 |
int result = -1; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
197 |
if(!filename || !team) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
198 |
flib_log_e("null parameter in flib_team_to_ini"); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
199 |
} else { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
200 |
flib_ini *ini = flib_ini_create(filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
201 |
bool error = false; |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
202 |
error |= writeTeamSection(team, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
203 |
error |= writeHogSections(team, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
204 |
error |= writeBindingSection(team, ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
205 |
if(!error) { |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
206 |
result = flib_ini_save(ini, filename); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
207 |
} |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
208 |
flib_ini_destroy(ini); |
1c859f572d72
frontlib: Rewrote the ini helper code, finished ini reading/writing support for all relevant file types
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
209 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
210 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
211 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
212 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
213 |
flib_team *flib_team_retain(flib_team *team) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
214 |
if(team) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
215 |
flib_retain(&team->_referenceCount, "flib_team"); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
216 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
217 |
return team; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
218 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
219 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
220 |
void flib_team_release(flib_team *team) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
221 |
if(team && flib_release(&team->_referenceCount, "flib_team")) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
222 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
223 |
free(team->hogs[i].name); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
224 |
free(team->hogs[i].hat); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
225 |
flib_weaponset_release(team->hogs[i].weaponset); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
226 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
227 |
free(team->name); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
228 |
free(team->grave); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
229 |
free(team->fort); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
230 |
free(team->voicepack); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
231 |
free(team->flag); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
232 |
if(team->bindings) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
233 |
for(int i=0; i<team->bindingCount; i++) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
234 |
free(team->bindings[i].action); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
235 |
free(team->bindings[i].binding); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
236 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
237 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
238 |
free(team->bindings); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
239 |
free(team->ownerName); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
240 |
free(team); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
241 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
242 |
} |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
243 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
244 |
void flib_team_set_weaponset(flib_team *team, flib_weaponset *set) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
245 |
if(team) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
246 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
247 |
flib_weaponset_release(team->hogs[i].weaponset); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
248 |
team->hogs[i].weaponset = flib_weaponset_retain(set); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
249 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
250 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
251 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
252 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
253 |
void flib_team_set_health(flib_team *team, int health) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
254 |
if(team) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
255 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
256 |
team->hogs[i].initialHealth = health; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
257 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
258 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
259 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
260 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
261 |
char *strdupWithError(const char *in, bool *error) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
262 |
char *out = flib_strdupnull(in); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
263 |
if(in && !out) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
264 |
*error = true; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
265 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
266 |
return out; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
267 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
268 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
269 |
flib_team *flib_team_copy(const flib_team *team) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
270 |
flib_team *result = NULL; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
271 |
if(team) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
272 |
flib_team *tmpTeam = flib_team_retain(flib_calloc(1, sizeof(flib_team))); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
273 |
if(tmpTeam) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
274 |
bool error = false; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
275 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
276 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
277 |
tmpTeam->hogs[i].name = strdupWithError(team->hogs[i].name, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
278 |
tmpTeam->hogs[i].hat = strdupWithError(team->hogs[i].hat, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
279 |
tmpTeam->hogs[i].rounds = team->hogs[i].rounds; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
280 |
tmpTeam->hogs[i].kills = team->hogs[i].kills; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
281 |
tmpTeam->hogs[i].deaths = team->hogs[i].deaths; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
282 |
tmpTeam->hogs[i].suicides = team->hogs[i].suicides; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
283 |
tmpTeam->hogs[i].difficulty = team->hogs[i].difficulty; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
284 |
tmpTeam->hogs[i].initialHealth = team->hogs[i].initialHealth; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
285 |
tmpTeam->hogs[i].weaponset = flib_weaponset_retain(team->hogs[i].weaponset); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
286 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
287 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
288 |
tmpTeam->name = strdupWithError(team->name, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
289 |
tmpTeam->grave = strdupWithError(team->grave, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
290 |
tmpTeam->fort = strdupWithError(team->fort, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
291 |
tmpTeam->voicepack = strdupWithError(team->voicepack, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
292 |
tmpTeam->flag = strdupWithError(team->flag, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
293 |
tmpTeam->ownerName = strdupWithError(team->ownerName, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
294 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
295 |
tmpTeam->bindingCount = team->bindingCount; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
296 |
if(team->bindings) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
297 |
tmpTeam->bindings = flib_calloc(team->bindingCount, sizeof(flib_binding)); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
298 |
if(tmpTeam->bindings) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
299 |
for(int i=0; i<tmpTeam->bindingCount; i++) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
300 |
tmpTeam->bindings[i].action = strdupWithError(team->bindings[i].action, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
301 |
tmpTeam->bindings[i].binding = strdupWithError(team->bindings[i].binding, &error); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
302 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
303 |
} else { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
304 |
error = true; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
305 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
306 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
307 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
308 |
tmpTeam->rounds = team->rounds; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
309 |
tmpTeam->wins = team->wins; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
310 |
tmpTeam->campaignProgress = team->campaignProgress; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
311 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
312 |
tmpTeam->colorIndex = team->colorIndex; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
313 |
tmpTeam->hogsInGame = team->hogsInGame; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
314 |
tmpTeam->remoteDriven = team->remoteDriven; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
315 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
316 |
if(!error) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
317 |
result = tmpTeam; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
318 |
tmpTeam = 0; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
319 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
320 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
321 |
flib_team_release(tmpTeam); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
322 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
323 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
324 |
} |