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

# 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.67 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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 root 1.66 *
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 root 1.66 *
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 root 1.66 *
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.66 *
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     UNIQUE_DIR,
76 root 1.10 TMPDIR,
77 root 1.34 PK_LUCK_PENALTY,
78 root 1.10 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 root 1.34 SET_FRIENDLY_FIRE,
91 root 1.10 SPELLPOINT_LEVEL_DEPEND,
92     0,
93 root 1.60 1.25,
94 root 1.10
95 elmex 1.1 /* Armor enchantment stuff */
96 root 1.10 ARMOR_MAX_ENCHANT,
97     ARMOR_WEIGHT_REDUCTION,
98     ARMOR_WEIGHT_LINEAR,
99     ARMOR_SPEED_IMPROVEMENT,
100     ARMOR_SPEED_LINEAR,
101 elmex 1.1 };
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 root 1.10 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 elmex 1.1 };
129    
130 pippijn 1.21 /* init_environ initialises values from the environmental variables.
131 elmex 1.1 * it needs to be called very early, since command line options should
132     * overwrite these if specified.
133     */
134 root 1.10 void
135 root 1.52 init_environ ()
136 root 1.10 {
137 root 1.46 const char *cp;
138 elmex 1.1
139 root 1.63 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 root 1.46 if (cp = getenv ("DELIANTRA_LOCALDIR" )) settings.localdir = cp;
146     if (cp = getenv ("DELIANTRA_PLAYERDIR" )) settings.playerdir = cp;
147 root 1.63 if (cp = getenv ("DELIANTRA_UNIQUEDIR" )) settings.uniquedir = cp;
148 root 1.46 if (cp = getenv ("DELIANTRA_TMPDIR" )) settings.tmpdir = cp;
149     if (cp = getenv ("DELIANTRA_LOGFILE" )) settings.logfilename = cp;
150 elmex 1.1 }
151 root 1.10
152 elmex 1.1 /*
153     * Initialises all global variables.
154     * Might use environment-variables as default for some of them.
155     */
156 root 1.10 void
157 root 1.52 init_globals ()
158 root 1.10 {
159     if (settings.logfilename[0] == 0)
160 root 1.56 log_setfd (-1);
161 root 1.68 else
162 root 1.10 {
163 root 1.44 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
164    
165     if (logfd >= 0)
166 root 1.56 log_setfd (logfd);
167 root 1.44 else
168     {
169 root 1.56 log_setfd (-1);
170 root 1.44 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
171     }
172 elmex 1.1 }
173     }
174    
175 root 1.10 void
176 root 1.52 init_dynamic ()
177 root 1.10 {
178 root 1.39 first_map_ext_path = "/start/HallsOfSelection";
179     first_map_path = "/HallOfSelection";
180 elmex 1.1 }
181    
182     /*
183 pippijn 1.21 * initialises the attack messages.
184 elmex 1.1 * Called by init_library().
185     */
186    
187     //attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
188    
189 root 1.10 void
190 root 1.52 init_attackmess ()
191 root 1.10 {
192 root 1.58 object_thawer thawer (settings.datadir, "attackmess");
193 root 1.57
194     if (!thawer)
195 root 1.10 {
196 root 1.58 LOG (llevError, "Can't open %s.\n", thawer.name);
197 root 1.10 return;
198 elmex 1.1 }
199    
200 root 1.57 int msgnum = -1;
201     int total = 0;
202    
203     while (thawer.kw)
204 root 1.10 {
205 root 1.57 if (thawer.kw != KW_type)
206     if (!thawer.parse_error ("attackmess file"))
207     break;
208 root 1.45
209 root 1.57 thawer.get (msgnum);
210     thawer.next ();
211 root 1.45
212 root 1.57 int level = 0;
213 root 1.10
214 root 1.57 while (thawer.kw == KW_hp)
215 root 1.10 {
216 root 1.57 // 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 root 1.10 {
227 root 1.57 if (*buf2 == '-')
228     *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
229 root 1.45
230 root 1.57 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 root 1.51
235 root 1.57 ++level;
236     ++total;
237     }
238 root 1.51
239 root 1.57 thawer.next ();
240 root 1.10 }
241 root 1.51
242 root 1.57 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 elmex 1.1 }
247 root 1.45
248 root 1.51 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
249 elmex 1.1 }
250 root 1.45