1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #define EXTERN // horrible hack |
24 | #define EXTERN // horrible hack |
26 | |
25 | |
27 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
133 | "Wounding", |
132 | "Wounding", |
134 | "Death", |
133 | "Death", |
135 | "Light" |
134 | "Light" |
136 | }; |
135 | }; |
137 | |
136 | |
138 | /* |
|
|
139 | * It is vital that init_library() is called by any functions |
|
|
140 | * using this library. |
|
|
141 | * If you want to lessen the size of the program using the library, |
|
|
142 | * you can replace the call to init_library() with init_globals() and |
|
|
143 | * init_function_pointers(). Good idea to also call init_vars and |
|
|
144 | * init_hash_table if you are doing any object loading. |
|
|
145 | */ |
|
|
146 | void |
|
|
147 | init_library (void) |
|
|
148 | { |
|
|
149 | init_globals (); |
|
|
150 | init_block (); |
|
|
151 | init_dynamic (); |
|
|
152 | init_attackmess (); |
|
|
153 | init_experience (); |
|
|
154 | } |
|
|
155 | |
|
|
156 | /* init_environ initialises values from the environmental variables. |
137 | /* init_environ initialises values from the environmental variables. |
157 | * it needs to be called very early, since command line options should |
138 | * it needs to be called very early, since command line options should |
158 | * overwrite these if specified. |
139 | * overwrite these if specified. |
159 | */ |
140 | */ |
160 | void |
141 | void |
161 | init_environ (void) |
142 | init_environ (void) |
162 | { |
143 | { |
163 | char *cp; |
144 | const char *cp; |
164 | |
145 | |
165 | cp = getenv ("CROSSFIRE_LIBDIR"); |
146 | if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp; |
166 | if (cp) |
147 | if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp; |
167 | settings.datadir = cp; |
148 | if (cp = getenv ("DELIANTRA_LOCALDIR" )) settings.localdir = cp; |
|
|
149 | if (cp = getenv ("DELIANTRA_PLAYERDIR" )) settings.playerdir = cp; |
|
|
150 | if (cp = getenv ("DELIANTRA_MAPDIR" )) settings.mapdir = cp; |
|
|
151 | if (cp = getenv ("DELIANTRA_ARCHETYPES" )) settings.archetypes = cp; |
|
|
152 | if (cp = getenv ("DELIANTRA_TREASURES" )) settings.treasures = cp; |
|
|
153 | if (cp = getenv ("DELIANTRA_UNIQUEDIR" )) settings.uniquedir = cp; |
|
|
154 | if (cp = getenv ("DELIANTRA_TEMPLATEDIR")) settings.templatedir = cp; |
|
|
155 | if (cp = getenv ("DELIANTRA_TMPDIR" )) settings.tmpdir = cp; |
168 | |
156 | |
169 | cp = getenv ("CROSSFIRE_LOCALDIR"); |
157 | if (cp = getenv ("DELIANTRA_LOGFILE" )) settings.logfilename = cp; |
170 | if (cp) |
|
|
171 | settings.localdir = cp; |
|
|
172 | |
|
|
173 | cp = getenv ("CROSSFIRE_PLAYERDIR"); |
|
|
174 | if (cp) |
|
|
175 | settings.playerdir = cp; |
|
|
176 | |
|
|
177 | cp = getenv ("CROSSFIRE_MAPDIR"); |
|
|
178 | if (cp) |
|
|
179 | settings.mapdir = cp; |
|
|
180 | |
|
|
181 | cp = getenv ("CROSSFIRE_ARCHETYPES"); |
|
|
182 | if (cp) |
|
|
183 | settings.archetypes = cp; |
|
|
184 | |
|
|
185 | cp = getenv ("CROSSFIRE_TREASURES"); |
|
|
186 | if (cp) |
|
|
187 | settings.treasures = cp; |
|
|
188 | |
|
|
189 | cp = getenv ("CROSSFIRE_UNIQUEDIR"); |
|
|
190 | if (cp) |
|
|
191 | settings.uniquedir = cp; |
|
|
192 | |
|
|
193 | cp = getenv ("CROSSFIRE_TEMPLATEDIR"); |
|
|
194 | if (cp) |
|
|
195 | settings.templatedir = cp; |
|
|
196 | |
|
|
197 | cp = getenv ("CROSSFIRE_TMPDIR"); |
|
|
198 | if (cp) |
|
|
199 | settings.tmpdir = cp; |
|
|
200 | } |
158 | } |
201 | |
159 | |
202 | /* |
160 | /* |
203 | * Initialises all global variables. |
161 | * Initialises all global variables. |
204 | * Might use environment-variables as default for some of them. |
162 | * Might use environment-variables as default for some of them. |
205 | */ |
163 | */ |
206 | void |
164 | void |
207 | init_globals (void) |
165 | init_globals (void) |
208 | { |
166 | { |
209 | if (settings.logfilename[0] == 0) |
167 | if (settings.logfilename[0] == 0) |
210 | logfile = stderr; |
168 | set_logfd (-1); |
211 | else if ((logfile = fopen (settings.logfilename, "a")) == NULL) |
169 | else |
212 | { |
170 | { |
|
|
171 | int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666); |
|
|
172 | |
|
|
173 | if (logfd >= 0) |
|
|
174 | set_logfd (logfd); |
|
|
175 | else |
|
|
176 | { |
|
|
177 | set_logfd (-1); |
213 | fprintf (stderr, "Unable to open %s as the logfile - will use stderr instead\n", settings.logfilename); |
178 | LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename); |
214 | logfile = stderr; |
179 | } |
215 | } |
180 | } |
216 | else |
|
|
217 | setvbuf (logfile, NULL, _IOLBF, 0); |
|
|
218 | } |
181 | } |
219 | |
182 | |
220 | void |
183 | void |
221 | init_dynamic (void) |
184 | init_dynamic (void) |
222 | { |
185 | { |
223 | archetype *at = first_archetype; |
186 | first_map_ext_path = "/start/HallsOfSelection"; |
224 | |
187 | first_map_path = "/HallOfSelection"; |
225 | while (at) |
|
|
226 | { |
|
|
227 | if (at->clone.type == MAP) |
|
|
228 | { |
|
|
229 | if (at->clone.race) |
|
|
230 | first_map_ext_path = at->clone.race; |
|
|
231 | |
|
|
232 | if (EXIT_PATH (&at->clone)) |
|
|
233 | { |
|
|
234 | first_map_path = EXIT_PATH (&at->clone); |
|
|
235 | return; |
|
|
236 | } |
|
|
237 | } |
|
|
238 | |
|
|
239 | at = at->next; |
|
|
240 | } |
|
|
241 | |
|
|
242 | LOG (llevDebug, "You need an archetype of type 'map' and it has to contain the player start map\n"); |
|
|
243 | exit (-1); |
|
|
244 | } |
188 | } |
245 | |
189 | |
246 | /* |
190 | /* |
247 | * initialises the attack messages. |
191 | * initialises the attack messages. |
248 | * Called by init_library(). |
192 | * Called by init_library(). |
… | |
… | |
277 | level = 0; |
221 | level = 0; |
278 | while (fgets (buf, MAX_BUF, fp) != NULL) |
222 | while (fgets (buf, MAX_BUF, fp) != NULL) |
279 | { |
223 | { |
280 | if (*buf == '#') |
224 | if (*buf == '#') |
281 | continue; |
225 | continue; |
|
|
226 | |
282 | if ((cp = strchr (buf, '\n')) != NULL) |
227 | if ((cp = strchr (buf, '\n')) != NULL) |
283 | *cp = '\0'; |
228 | *cp = '\0'; |
|
|
229 | |
284 | cp = buf; |
230 | cp = buf; |
285 | while (*cp == ' ') /* Skip blanks */ |
231 | while (*cp == ' ') /* Skip blanks */ |
286 | cp++; |
232 | cp++; |
287 | |
233 | |
288 | if (strncmp (cp, "TYPE:", 5) == 0) |
234 | if (strncmp (cp, "TYPE:", 5) == 0) |
… | |
… | |
294 | attack_mess[mess][level].level = -1; |
240 | attack_mess[mess][level].level = -1; |
295 | attack_mess[mess][level].buf1 = NULL; |
241 | attack_mess[mess][level].buf1 = NULL; |
296 | attack_mess[mess][level].buf2 = NULL; |
242 | attack_mess[mess][level].buf2 = NULL; |
297 | attack_mess[mess][level].buf3 = NULL; |
243 | attack_mess[mess][level].buf3 = NULL; |
298 | } |
244 | } |
|
|
245 | |
299 | level = 0; |
246 | level = 0; |
300 | mess = atoi (p); |
247 | mess = atoi (p); |
301 | mode = 1; |
248 | mode = 1; |
302 | continue; |
249 | continue; |
303 | } |
250 | } |
|
|
251 | |
304 | if (mode == 1) |
252 | if (mode == 1) |
305 | { |
253 | { |
306 | p = strtok (buf, "="); |
254 | p = strtok (buf, "="); |
307 | attack_mess[mess][level].level = atoi (buf); |
255 | attack_mess[mess][level].level = atoi (buf); |
308 | p = strtok (NULL, "="); |
256 | p = strtok (NULL, "="); |
… | |
… | |
338 | level++; |
286 | level++; |
339 | total++; |
287 | total++; |
340 | continue; |
288 | continue; |
341 | } |
289 | } |
342 | } |
290 | } |
|
|
291 | |
343 | LOG (llevDebug, "got %d messages in %d categories.\n", total, mess + 1); |
292 | LOG (llevDebug, "got %d messages in %d categories.\n", total, mess + 1); |
344 | close_and_delete (fp, comp); |
293 | close_and_delete (fp, comp); |
345 | } |
294 | } |
|
|
295 | |