author | Medo <smaxein@googlemail.com> |
Mon, 06 Aug 2012 22:31:02 +0200 | |
changeset 7464 | 859ab6859854 |
parent 7320 | e704706008d4 |
child 7470 | 0db1780ca938 |
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); |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
32 |
flib_team_destroy(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) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
37 |
if(log_badargs_if(filename==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
38 |
return NULL; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
39 |
} |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
40 |
|
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
41 |
flib_team *result = 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
|
42 |
flib_ini *ini = NULL; |
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 |
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
|
45 |
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
|
46 |
} |
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 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
53 |
|
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
} |
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 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
|
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 |
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
|
69 |
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
|
70 |
|
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 |
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
|
72 |
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
|
73 |
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
|
74 |
} |
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 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
} |
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 |
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
|
82 |
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
|
83 |
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
|
84 |
} |
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 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
result->hogs[i].difficulty = difficulty; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
93 |
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
|
94 |
|
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 |
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
|
96 |
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
|
97 |
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
|
98 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
99 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
100 |
|
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
} |
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 |
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
|
108 |
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
|
109 |
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
|
110 |
} |
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 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
} 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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
} |
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 |
free(keyname); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
121 |
} |
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 |
if(error) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
128 |
|
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
|
129 |
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
|
130 |
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
|
131 |
} |
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 |
|
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
133 |
void flib_team_destroy(flib_team *team) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
134 |
if(team) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
135 |
for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
136 |
free(team->hogs[i].name); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
137 |
free(team->hogs[i].hat); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
138 |
flib_weaponset_release(team->hogs[i].weaponset); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
139 |
} |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
140 |
free(team->name); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
141 |
free(team->grave); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
142 |
free(team->fort); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
143 |
free(team->voicepack); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
144 |
free(team->flag); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
145 |
if(team->bindings) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
146 |
for(int i=0; i<team->bindingCount; i++) { |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
147 |
free(team->bindings[i].action); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
148 |
free(team->bindings[i].binding); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
149 |
} |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
150 |
} |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
151 |
free(team->bindings); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
152 |
free(team->ownerName); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
153 |
free(team); |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
154 |
} |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
155 |
} |
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
156 |
|
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
|
157 |
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
|
158 |
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
|
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", 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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
} |
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 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
} |
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 |
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
|
182 |
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
|
183 |
} |
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 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
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
|
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 |
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
|
196 |
} |
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 |
|
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 |
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
|
199 |
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
|
200 |
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
|
201 |
} |
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 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
} 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
|
209 |
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
|
210 |
} |
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
|
211 |
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
|
212 |
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
|
213 |
} |
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
|
214 |
} |
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
|
215 |
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
|
216 |
} |
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
|
217 |
|
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
|
218 |
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
|
219 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
220 |
if(!log_badargs_if2(filename==NULL, team==NULL)) { |
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
} |
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
|
229 |
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
|
230 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
231 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
232 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
233 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
234 |
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
|
235 |
if(team) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
240 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7227
diff
changeset
|
241 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
242 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
243 |
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
|
244 |
if(team) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
245 |
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
|
246 |
team->hogs[i].initialHealth = health; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
247 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
248 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
249 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
250 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
251 |
static char *strdupWithError(const char *in, bool *error) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
*error = true; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
255 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
256 |
return out; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
257 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
258 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
if(team) { |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
262 |
flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team)); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
263 |
if(tmpTeam) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
264 |
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
|
265 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
277 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
293 |
} else { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
294 |
error = true; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
295 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
296 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
297 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
306 |
if(!error) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
307 |
result = tmpTeam; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
308 |
tmpTeam = 0; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
309 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
310 |
} |
7320
e704706008d4
frontlib: Renamed cfg to scheme, Un-refcounted some types, small API adjustments
Medo <smaxein@googlemail.com>
parents:
7316
diff
changeset
|
311 |
flib_team_destroy(tmpTeam); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
312 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
313 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
314 |
} |