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

# User Rev Content
1 elmex 1.1 /*
2 root 1.41 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.23 *
4 root 1.55 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.54 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 pippijn 1.23 *
8 root 1.49 * 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 pippijn 1.23 *
13 root 1.38 * 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 pippijn 1.23 *
18 root 1.49 * 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 root 1.36 *
22 root 1.41 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.23 */
24 elmex 1.1
25 root 1.10 #define EXTERN // horrible hack
26 root 1.7
27 elmex 1.1 #include <global.h>
28     #include <object.h>
29    
30 root 1.48 dynbuf_text msg_dynbuf (65536, 65536);
31    
32 root 1.61 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 root 1.10 extern const char *const attacktype_desc[NROFATTACKS] = {
39 root 1.61 # define def(uc, lc, desc, plus, change) # desc,
40 root 1.11 # include "attackinc.h"
41     # undef def
42 root 1.7 };
43    
44 root 1.10 extern const char *const resist_plus[NROFATTACKS] = {
45 root 1.61 # define def(uc, lc, desc, plus, change) # plus,
46 root 1.11 # include "attackinc.h"
47     # undef def
48 root 1.7 };
49    
50 root 1.10 extern const char *const change_resist_msg[NROFATTACKS] = {
51 root 1.61 # define def(uc, lc, desc, plus, change) # change,
52 root 1.11 # include "attackinc.h"
53     # undef def
54 root 1.7 };
55    
56     int resist_table[NROFATTACKS] = {
57 root 1.61 # define def(uc, lc, desc, plus, change) ATNR_ ## uc,
58 root 1.11 # include "attackinc.h"
59     # undef def
60 root 1.7 };
61    
62 elmex 1.1 /* You unforunately need to looking in include/global.h to see what these
63     * correspond to.
64     */
65     struct Settings settings = {
66 root 1.10 LOGFILE, /* Logfile */
67 root 1.59 llevTrace, /* Log level */
68 root 1.10 0, /* argc */
69     NULL, /* argv */
70     CONFDIR,
71     DATADIR,
72     LOCALDIR,
73 root 1.62 PLAYERDIR,
74     MAPDIR,
75     ARCHETYPES,
76     TREASURES,
77     UNIQUE_DIR,
78     "",
79 root 1.10 TMPDIR,
80 root 1.34 PK_LUCK_PENALTY,
81 root 1.10 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 root 1.34 SET_FRIENDLY_FIRE,
94 root 1.10 SPELLPOINT_LEVEL_DEPEND,
95     0,
96 root 1.60 1.25,
97 root 1.10
98 elmex 1.1 /* Armor enchantment stuff */
99 root 1.10 ARMOR_MAX_ENCHANT,
100     ARMOR_WEIGHT_REDUCTION,
101     ARMOR_WEIGHT_LINEAR,
102     ARMOR_SPEED_IMPROVEMENT,
103     ARMOR_SPEED_LINEAR,
104 elmex 1.1 };
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 root 1.10 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 elmex 1.1 };
132    
133 pippijn 1.21 /* init_environ initialises values from the environmental variables.
134 elmex 1.1 * it needs to be called very early, since command line options should
135     * overwrite these if specified.
136     */
137 root 1.10 void
138 root 1.52 init_environ ()
139 root 1.10 {
140 root 1.46 const char *cp;
141 elmex 1.1
142 root 1.47 if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp;
143 root 1.46 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 elmex 1.1 }
154 root 1.10
155 elmex 1.1 /*
156     * Initialises all global variables.
157     * Might use environment-variables as default for some of them.
158     */
159 root 1.10 void
160 root 1.52 init_globals ()
161 root 1.10 {
162     if (settings.logfilename[0] == 0)
163 root 1.56 log_setfd (-1);
164 root 1.44 else
165 root 1.10 {
166 root 1.44 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
167    
168     if (logfd >= 0)
169 root 1.56 log_setfd (logfd);
170 root 1.44 else
171     {
172 root 1.56 log_setfd (-1);
173 root 1.44 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
174     }
175 elmex 1.1 }
176     }
177    
178 root 1.10 void
179 root 1.52 init_dynamic ()
180 root 1.10 {
181 root 1.39 first_map_ext_path = "/start/HallsOfSelection";
182     first_map_path = "/HallOfSelection";
183 elmex 1.1 }
184    
185     /*
186 pippijn 1.21 * initialises the attack messages.
187 elmex 1.1 * Called by init_library().
188     */
189    
190     //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
191    
192 root 1.10 void
193 root 1.52 init_attackmess ()
194 root 1.10 {
195 root 1.58 object_thawer thawer (settings.datadir, "attackmess");
196 root 1.57
197     if (!thawer)
198 root 1.10 {
199 root 1.58 LOG (llevError, "Can't open %s.\n", thawer.name);
200 root 1.10 return;
201 elmex 1.1 }
202    
203 root 1.57 int msgnum = -1;
204     int total = 0;
205    
206     while (thawer.kw)
207 root 1.10 {
208 root 1.57 if (thawer.kw != KW_type)
209     if (!thawer.parse_error ("attackmess file"))
210     break;
211 root 1.45
212 root 1.57 thawer.get (msgnum);
213     thawer.next ();
214 root 1.45
215 root 1.57 int level = 0;
216 root 1.10
217 root 1.57 while (thawer.kw == KW_hp)
218 root 1.10 {
219 root 1.57 // 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 root 1.10 {
230 root 1.57 if (*buf2 == '-')
231     *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
232 root 1.45
233 root 1.57 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 root 1.51
238 root 1.57 ++level;
239     ++total;
240     }
241 root 1.51
242 root 1.57 thawer.next ();
243 root 1.10 }
244 root 1.51
245 root 1.57 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 elmex 1.1 }
250 root 1.45
251 root 1.51 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
252 elmex 1.1 }
253 root 1.45