ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/init.C
Revision: 1.68
Committed: Sun Jan 29 02:47:04 2017 UTC (7 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.67: +1 -1 lines
Log Message:
remove eol whitespace

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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 UNIQUE_DIR,
76 TMPDIR,
77 PK_LUCK_PENALTY,
78 STAT_LOSS_ON_DEATH,
79 PERMANENT_EXPERIENCE_RATIO,
80 DEATH_PENALTY_RATIO,
81 DEATH_PENALTY_LEVEL,
82 BALANCED_STAT_LOSS,
83 NOT_PERMADETH,
84 SIMPLE_EXP,
85 SET_TITLE,
86 RESURRECTION,
87 SEARCH_ITEMS,
88 SPELL_ENCUMBRANCE,
89 SPELL_FAILURE_EFFECTS,
90 SET_FRIENDLY_FIRE,
91 SPELLPOINT_LEVEL_DEPEND,
92 0,
93 1.25,
94
95 /* Armor enchantment stuff */
96 ARMOR_MAX_ENCHANT,
97 ARMOR_WEIGHT_REDUCTION,
98 ARMOR_WEIGHT_LINEAR,
99 ARMOR_SPEED_IMPROVEMENT,
100 ARMOR_SPEED_LINEAR,
101 };
102
103 /* perhaps not the best place for this, but needs to be
104 * in some file in the common area so that standalone
105 * programs, like the random map generator, can be built.
106 */
107 const char *const spellpathnames[NRSPELLPATHS] = {
108 "Protection",
109 "Fire",
110 "Frost",
111 "Electricity",
112 "Missiles",
113 "Self",
114 "Summoning",
115 "Abjuration",
116 "Restoration",
117 "Detonation",
118 "Mind",
119 "Creation",
120 "Teleportation",
121 "Information",
122 "Transmutation",
123 "Transferrence",
124 "Turning",
125 "Wounding",
126 "Death",
127 "Light"
128 };
129
130 /* init_environ initialises values from the environmental variables.
131 * it needs to be called very early, since command line options should
132 * overwrite these if specified.
133 */
134 void
135 init_environ ()
136 {
137 const char *cp;
138
139 if (cp = getenv ("DELIANTRA_CONFDIR" )) settings.confdir = cp;
140
141 if (cp = getenv ("DELIANTRA_LIBDIR" )) settings.datadir = cp; /* deprecated */
142 if (cp = getenv ("DELIANTRA_DATADIR" )) settings.datadir = cp;
143 if (cp = getenv ("DELIANTRA_MAPDIR" )) settings.mapdir = cp;
144
145 if (cp = getenv ("DELIANTRA_LOCALDIR" )) settings.localdir = cp;
146 if (cp = getenv ("DELIANTRA_PLAYERDIR" )) settings.playerdir = cp;
147 if (cp = getenv ("DELIANTRA_UNIQUEDIR" )) settings.uniquedir = cp;
148 if (cp = getenv ("DELIANTRA_TMPDIR" )) settings.tmpdir = cp;
149 if (cp = getenv ("DELIANTRA_LOGFILE" )) settings.logfilename = cp;
150 }
151
152 /*
153 * Initialises all global variables.
154 * Might use environment-variables as default for some of them.
155 */
156 void
157 init_globals ()
158 {
159 if (settings.logfilename[0] == 0)
160 log_setfd (-1);
161 else
162 {
163 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
164
165 if (logfd >= 0)
166 log_setfd (logfd);
167 else
168 {
169 log_setfd (-1);
170 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
171 }
172 }
173 }
174
175 void
176 init_dynamic ()
177 {
178 first_map_ext_path = "/start/HallsOfSelection";
179 first_map_path = "/HallOfSelection";
180 }
181
182 /*
183 * initialises the attack messages.
184 * Called by init_library().
185 */
186
187 //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
188
189 void
190 init_attackmess ()
191 {
192 object_thawer thawer (settings.datadir, "attackmess");
193
194 if (!thawer)
195 {
196 LOG (llevError, "Can't open %s.\n", thawer.name);
197 return;
198 }
199
200 int msgnum = -1;
201 int total = 0;
202
203 while (thawer.kw)
204 {
205 if (thawer.kw != KW_type)
206 if (!thawer.parse_error ("attackmess file"))
207 break;
208
209 thawer.get (msgnum);
210 thawer.next ();
211
212 int level = 0;
213
214 while (thawer.kw == KW_hp)
215 {
216 // our old friend, dog-slow sscanf
217 int hp;
218 char buf1[1024];
219 char buf2[1024];
220 char buf3[1024];
221
222 if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]",
223 &hp, buf1, buf2, buf3))
224 thawer.parse_error ("attackmess file");
225 else
226 {
227 if (*buf2 == '-')
228 *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
229
230 attack_mess[msgnum][level].level = hp;
231 attack_mess[msgnum][level].buf1 = strdup (buf1);
232 attack_mess[msgnum][level].buf2 = strdup (buf2);
233 attack_mess[msgnum][level].buf3 = strdup (buf3);
234
235 ++level;
236 ++total;
237 }
238
239 thawer.next ();
240 }
241
242 attack_mess[msgnum][level].level = -1;
243 attack_mess[msgnum][level].buf1 = 0;
244 attack_mess[msgnum][level].buf2 = 0;
245 attack_mess[msgnum][level].buf3 = 0;
246 }
247
248 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
249 }
250