1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
72 | NULL, /* argv */ |
72 | NULL, /* argv */ |
73 | CONFDIR, |
73 | CONFDIR, |
74 | DATADIR, |
74 | DATADIR, |
75 | LOCALDIR, |
75 | LOCALDIR, |
76 | PLAYERDIR, MAPDIR, ARCHETYPES, REGIONS, TREASURES, |
76 | PLAYERDIR, MAPDIR, ARCHETYPES, REGIONS, TREASURES, |
77 | UNIQUE_DIR, TEMPLATE_DIR, |
77 | UNIQUE_DIR, "", |
78 | TMPDIR, |
78 | TMPDIR, |
79 | PK_LUCK_PENALTY, |
79 | PK_LUCK_PENALTY, |
80 | STAT_LOSS_ON_DEATH, |
80 | STAT_LOSS_ON_DEATH, |
81 | PERMANENT_EXPERIENCE_RATIO, |
81 | PERMANENT_EXPERIENCE_RATIO, |
82 | DEATH_PENALTY_RATIO, |
82 | DEATH_PENALTY_RATIO, |
… | |
… | |
135 | /* init_environ initialises values from the environmental variables. |
135 | /* init_environ initialises values from the environmental variables. |
136 | * it needs to be called very early, since command line options should |
136 | * it needs to be called very early, since command line options should |
137 | * overwrite these if specified. |
137 | * overwrite these if specified. |
138 | */ |
138 | */ |
139 | void |
139 | void |
140 | init_environ (void) |
140 | init_environ () |
141 | { |
141 | { |
142 | const char *cp; |
142 | const char *cp; |
143 | |
143 | |
144 | if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp; |
144 | if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp; |
145 | if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp; |
145 | if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp; |
… | |
… | |
158 | /* |
158 | /* |
159 | * Initialises all global variables. |
159 | * Initialises all global variables. |
160 | * Might use environment-variables as default for some of them. |
160 | * Might use environment-variables as default for some of them. |
161 | */ |
161 | */ |
162 | void |
162 | void |
163 | init_globals (void) |
163 | init_globals () |
164 | { |
164 | { |
165 | if (settings.logfilename[0] == 0) |
165 | if (settings.logfilename[0] == 0) |
166 | set_logfd (-1); |
166 | log_setfd (-1); |
167 | else |
167 | else |
168 | { |
168 | { |
169 | int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666); |
169 | int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666); |
170 | |
170 | |
171 | if (logfd >= 0) |
171 | if (logfd >= 0) |
172 | set_logfd (logfd); |
172 | log_setfd (logfd); |
173 | else |
173 | else |
174 | { |
174 | { |
175 | set_logfd (-1); |
175 | log_setfd (-1); |
176 | LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename); |
176 | LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename); |
177 | } |
177 | } |
178 | } |
178 | } |
179 | } |
179 | } |
180 | |
180 | |
181 | void |
181 | void |
182 | init_dynamic (void) |
182 | init_dynamic () |
183 | { |
183 | { |
184 | first_map_ext_path = "/start/HallsOfSelection"; |
184 | first_map_ext_path = "/start/HallsOfSelection"; |
185 | first_map_path = "/HallOfSelection"; |
185 | first_map_path = "/HallOfSelection"; |
186 | } |
186 | } |
187 | |
187 | |
… | |
… | |
191 | */ |
191 | */ |
192 | |
192 | |
193 | //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; |
193 | //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; |
194 | |
194 | |
195 | void |
195 | void |
196 | init_attackmess (void) |
196 | init_attackmess () |
197 | { |
197 | { |
198 | char buf[MAX_BUF]; |
198 | object_thawer thawer (settings.datadir, "attackmess"); |
199 | char filename[MAX_BUF]; |
|
|
200 | char *cp, *p; |
|
|
201 | FILE *fp; |
|
|
202 | static int has_been_done = 0; |
|
|
203 | int mess, level, comp; |
|
|
204 | int mode = 0, total = 0; |
|
|
205 | |
199 | |
206 | if (has_been_done) |
200 | if (!thawer) |
207 | return; |
|
|
208 | else |
|
|
209 | has_been_done = 1; |
|
|
210 | |
|
|
211 | sprintf (filename, "%s/attackmess", settings.datadir); |
|
|
212 | LOG (llevDebug, "Reading attack messages from %s...\n", filename); |
|
|
213 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
|
|
214 | { |
201 | { |
215 | LOG (llevError, "Can't open %s.\n", filename); |
202 | LOG (llevError, "Can't open %s.\n", thawer.name); |
216 | return; |
203 | return; |
217 | } |
204 | } |
218 | |
205 | |
219 | level = 0; |
206 | int msgnum = -1; |
220 | while (fgets (buf, MAX_BUF, fp) != NULL) |
207 | int total = 0; |
|
|
208 | |
|
|
209 | while (thawer.kw) |
221 | { |
210 | { |
222 | if (*buf == '#') |
211 | if (thawer.kw != KW_type) |
223 | continue; |
212 | if (!thawer.parse_error ("attackmess file")) |
|
|
213 | break; |
224 | |
214 | |
225 | if ((cp = strchr (buf, '\n')) != NULL) |
215 | thawer.get (msgnum); |
226 | *cp = '\0'; |
216 | thawer.next (); |
227 | |
217 | |
228 | cp = buf; |
218 | int level = 0; |
229 | while (*cp == ' ') /* Skip blanks */ |
|
|
230 | cp++; |
|
|
231 | |
219 | |
232 | if (strncmp (cp, "TYPE:", 5) == 0) |
220 | while (thawer.kw == KW_hp) |
233 | { |
221 | { |
234 | p = strtok (buf, ":"); |
222 | // our old friend, dog-slow sscanf |
235 | p = strtok (NULL, ":"); |
223 | int hp; |
236 | if (mode == 1) |
224 | char buf1[1024]; |
|
|
225 | char buf2[1024]; |
|
|
226 | char buf3[1024]; |
|
|
227 | |
|
|
228 | if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]", |
|
|
229 | &hp, buf1, buf2, buf3)) |
|
|
230 | thawer.parse_error ("attackmess file"); |
|
|
231 | else |
237 | { |
232 | { |
|
|
233 | if (*buf2 == '-') |
|
|
234 | *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker |
|
|
235 | |
238 | attack_mess[mess][level].level = -1; |
236 | attack_mess[msgnum][level].level = hp; |
239 | attack_mess[mess][level].buf1 = NULL; |
237 | attack_mess[msgnum][level].buf1 = strdup (buf1); |
240 | attack_mess[mess][level].buf2 = NULL; |
238 | attack_mess[msgnum][level].buf2 = strdup (buf2); |
241 | attack_mess[mess][level].buf3 = NULL; |
239 | attack_mess[msgnum][level].buf3 = strdup (buf3); |
|
|
240 | |
|
|
241 | ++level; |
|
|
242 | ++total; |
242 | } |
243 | } |
243 | |
244 | |
244 | level = 0; |
245 | thawer.next (); |
245 | mess = atoi (p); |
|
|
246 | mode = 1; |
|
|
247 | continue; |
|
|
248 | } |
246 | } |
249 | |
247 | |
250 | if (mode == 1) |
|
|
251 | { |
|
|
252 | p = strtok (buf, "="); |
|
|
253 | attack_mess[mess][level].level = atoi (buf); |
248 | attack_mess[msgnum][level].level = -1; |
254 | p = strtok (NULL, "="); |
|
|
255 | if (p != NULL) |
|
|
256 | attack_mess[mess][level].buf1 = strdup (p); |
249 | attack_mess[msgnum][level].buf1 = 0; |
257 | else |
|
|
258 | attack_mess[mess][level].buf1 = strdup (""); |
|
|
259 | mode = 2; |
|
|
260 | continue; |
|
|
261 | } |
|
|
262 | else if (mode == 2) |
|
|
263 | { |
|
|
264 | p = strtok (buf, "="); |
|
|
265 | attack_mess[mess][level].level = atoi (buf); |
|
|
266 | p = strtok (NULL, "="); |
|
|
267 | if (p != NULL) |
|
|
268 | attack_mess[mess][level].buf2 = strdup (p); |
250 | attack_mess[msgnum][level].buf2 = 0; |
269 | else |
|
|
270 | attack_mess[mess][level].buf2 = strdup (""); |
|
|
271 | mode = 3; |
|
|
272 | continue; |
|
|
273 | } |
|
|
274 | else if (mode == 3) |
|
|
275 | { |
|
|
276 | p = strtok (buf, "="); |
|
|
277 | attack_mess[mess][level].level = atoi (buf); |
|
|
278 | p = strtok (NULL, "="); |
|
|
279 | if (p != NULL) |
|
|
280 | attack_mess[mess][level].buf3 = strdup (p); |
251 | attack_mess[msgnum][level].buf3 = 0; |
281 | else |
|
|
282 | attack_mess[mess][level].buf3 = strdup (""); |
|
|
283 | mode = 1; |
|
|
284 | level++; |
|
|
285 | total++; |
|
|
286 | continue; |
|
|
287 | } |
|
|
288 | } |
252 | } |
289 | |
253 | |
290 | LOG (llevDebug, "got %d messages in %d categories.\n", total, mess + 1); |
254 | LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1); |
291 | close_and_delete (fp, comp); |
|
|
292 | } |
255 | } |
293 | |
256 | |