ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/init.C
Revision: 1.69
Committed: Sat Nov 17 23:40:00 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.68: +1 -0 lines
Log Message:
copyright update 2018

File Contents

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