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, 6 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

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