ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/init.C
Revision: 1.62
Committed: Sat Feb 26 11:34:31 2011 UTC (13 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.61: +6 -8 lines
Log Message:
settings cleanup

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
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
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */
24
25 #define EXTERN // horrible hack
26
27 #include <global.h>
28 #include <object.h>
29
30 dynbuf_text msg_dynbuf (65536, 65536);
31
32 extern const char *const attacktype_name[NROFATTACKS] = {
33 # define def(uc, lc, desc, plus, change) # lc,
34 # include "attackinc.h"
35 # undef def
36 };
37
38 extern const char *const attacktype_desc[NROFATTACKS] = {
39 # define def(uc, lc, desc, plus, change) # desc,
40 # include "attackinc.h"
41 # undef def
42 };
43
44 extern const char *const resist_plus[NROFATTACKS] = {
45 # define def(uc, lc, desc, plus, change) # plus,
46 # include "attackinc.h"
47 # undef def
48 };
49
50 extern const char *const change_resist_msg[NROFATTACKS] = {
51 # define def(uc, lc, desc, plus, change) # change,
52 # include "attackinc.h"
53 # undef def
54 };
55
56 int resist_table[NROFATTACKS] = {
57 # define def(uc, lc, desc, plus, change) ATNR_ ## uc,
58 # include "attackinc.h"
59 # undef def
60 };
61
62 /* You unforunately need to looking in include/global.h to see what these
63 * correspond to.
64 */
65 struct Settings settings = {
66 LOGFILE, /* Logfile */
67 llevTrace, /* Log level */
68 0, /* argc */
69 NULL, /* argv */
70 CONFDIR,
71 DATADIR,
72 LOCALDIR,
73 PLAYERDIR,
74 MAPDIR,
75 ARCHETYPES,
76 TREASURES,
77 UNIQUE_DIR,
78 "",
79 TMPDIR,
80 PK_LUCK_PENALTY,
81 STAT_LOSS_ON_DEATH,
82 PERMANENT_EXPERIENCE_RATIO,
83 DEATH_PENALTY_RATIO,
84 DEATH_PENALTY_LEVEL,
85 BALANCED_STAT_LOSS,
86 NOT_PERMADETH,
87 SIMPLE_EXP,
88 SET_TITLE,
89 RESURRECTION,
90 SEARCH_ITEMS,
91 SPELL_ENCUMBRANCE,
92 SPELL_FAILURE_EFFECTS,
93 SET_FRIENDLY_FIRE,
94 SPELLPOINT_LEVEL_DEPEND,
95 0,
96 1.25,
97
98 /* Armor enchantment stuff */
99 ARMOR_MAX_ENCHANT,
100 ARMOR_WEIGHT_REDUCTION,
101 ARMOR_WEIGHT_LINEAR,
102 ARMOR_SPEED_IMPROVEMENT,
103 ARMOR_SPEED_LINEAR,
104 };
105
106 /* perhaps not the best place for this, but needs to be
107 * in some file in the common area so that standalone
108 * programs, like the random map generator, can be built.
109 */
110 const char *const spellpathnames[NRSPELLPATHS] = {
111 "Protection",
112 "Fire",
113 "Frost",
114 "Electricity",
115 "Missiles",
116 "Self",
117 "Summoning",
118 "Abjuration",
119 "Restoration",
120 "Detonation",
121 "Mind",
122 "Creation",
123 "Teleportation",
124 "Information",
125 "Transmutation",
126 "Transferrence",
127 "Turning",
128 "Wounding",
129 "Death",
130 "Light"
131 };
132
133 /* init_environ initialises values from the environmental variables.
134 * it needs to be called very early, since command line options should
135 * overwrite these if specified.
136 */
137 void
138 init_environ ()
139 {
140 const char *cp;
141
142 if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp;
143 if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp;
144 if (cp = getenv ("DELIANTRA_LOCALDIR" )) settings.localdir = cp;
145 if (cp = getenv ("DELIANTRA_PLAYERDIR" )) settings.playerdir = cp;
146 if (cp = getenv ("DELIANTRA_MAPDIR" )) settings.mapdir = cp;
147 if (cp = getenv ("DELIANTRA_ARCHETYPES" )) settings.archetypes = cp;
148 if (cp = getenv ("DELIANTRA_TREASURES" )) settings.treasures = cp;
149 if (cp = getenv ("DELIANTRA_UNIQUEDIR" )) settings.uniquedir = cp;
150 if (cp = getenv ("DELIANTRA_TEMPLATEDIR")) settings.templatedir = cp;
151 if (cp = getenv ("DELIANTRA_TMPDIR" )) settings.tmpdir = cp;
152 if (cp = getenv ("DELIANTRA_LOGFILE" )) settings.logfilename = cp;
153 }
154
155 /*
156 * Initialises all global variables.
157 * Might use environment-variables as default for some of them.
158 */
159 void
160 init_globals ()
161 {
162 if (settings.logfilename[0] == 0)
163 log_setfd (-1);
164 else
165 {
166 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
167
168 if (logfd >= 0)
169 log_setfd (logfd);
170 else
171 {
172 log_setfd (-1);
173 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
174 }
175 }
176 }
177
178 void
179 init_dynamic ()
180 {
181 first_map_ext_path = "/start/HallsOfSelection";
182 first_map_path = "/HallOfSelection";
183 }
184
185 /*
186 * initialises the attack messages.
187 * Called by init_library().
188 */
189
190 //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
191
192 void
193 init_attackmess ()
194 {
195 object_thawer thawer (settings.datadir, "attackmess");
196
197 if (!thawer)
198 {
199 LOG (llevError, "Can't open %s.\n", thawer.name);
200 return;
201 }
202
203 int msgnum = -1;
204 int total = 0;
205
206 while (thawer.kw)
207 {
208 if (thawer.kw != KW_type)
209 if (!thawer.parse_error ("attackmess file"))
210 break;
211
212 thawer.get (msgnum);
213 thawer.next ();
214
215 int level = 0;
216
217 while (thawer.kw == KW_hp)
218 {
219 // our old friend, dog-slow sscanf
220 int hp;
221 char buf1[1024];
222 char buf2[1024];
223 char buf3[1024];
224
225 if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]",
226 &hp, buf1, buf2, buf3))
227 thawer.parse_error ("attackmess file");
228 else
229 {
230 if (*buf2 == '-')
231 *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
232
233 attack_mess[msgnum][level].level = hp;
234 attack_mess[msgnum][level].buf1 = strdup (buf1);
235 attack_mess[msgnum][level].buf2 = strdup (buf2);
236 attack_mess[msgnum][level].buf3 = strdup (buf3);
237
238 ++level;
239 ++total;
240 }
241
242 thawer.next ();
243 }
244
245 attack_mess[msgnum][level].level = -1;
246 attack_mess[msgnum][level].buf1 = 0;
247 attack_mess[msgnum][level].buf2 = 0;
248 attack_mess[msgnum][level].buf3 = 0;
249 }
250
251 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
252 }
253