Debian Codegraph @

include/global.h

raw symbols SCIP
1 /**
2 * @file
3 * Global type definitions and header inclusions.
4 */
5
6 #ifndef GLOBAL_H
7 #define GLOBAL_H
8
9 /**
10 * Define external variables. This is used in an ugly hack where EXTERN is
11 * re-defined to "" in 'init.c' in order to resolve missing symbols. Do not
12 * use this macro in new code.
13 */
14 #ifndef EXTERN
15 #define EXTERN extern
16 #endif
17
18 /* Include this first, because it lets us know what we are missing */
19 #ifdef WIN32 /* ---win32 exclude this, config comes from VC ide */
20 #include "win32.h"
21 #else
22 #include "autoconf.h"
23 /* socklen_t is defined in this file on some systems, and that type is
24 * used in newserver.h, which is used in all other files
25 */
26 #include <sys/socket.h>
27 #endif
28
29 #ifdef HAVE_LIBDMALLOC
30 #include <dmalloc.h>
31 #endif
32
33 #include <inttypes.h>
34 #include <stdbool.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include "compat.h"
38
39 /** Strings that should be manipulated through add_string() and free_string(). */
40 typedef const char *sstring;
41
42 #include "config.h"
43 #include "define.h"
44 #include "logger.h"
45 #include "shared/newclient.h"
46
47 /* This blob, in this order, is needed to actually define maps */
48 #include "face.h"
49 /* Include the basic defines from spells.h */
50 #include "attack.h" /* needs to be before material.h */
51 #include "material.h"
52 #include "living.h"
53 #include "object.h"
54 #include "map.h"
55 #include "tod.h"
56
57 #include "skills.h"
58
59 /* This defines the Account_Char structure which is used in the socket */
60 #include "account_char.h"
61
62 /* Pull in the socket structure - used in the player structure */
63 #include "newserver.h"
64
65 #include "party.h"
66
67 /* Pull in the player structure */
68 #include "player.h"
69
70 /* pull in treasure structure */
71 #include "treasure.h"
72
73 #include "commands.h"
74
75 /* pull in book structures */
76 #include "book.h"
77
78 /* ob_methods and ob_types subsystem */
79 #include "ob_methods.h"
80 #include "ob_types.h"
81
82 /*
83 * So far only used when dealing with artifacts.
84 * (now used by alchemy and other code too. Nov 95 b.t).
85 */
86 typedef struct linked_char {
87 const char *name;
88 struct linked_char *next;
89 } linked_char;
90
91
92 /* Pull in artifacts */
93 #include "artifact.h"
94
95 /* Now for gods */
96 #include "god.h"
97
98 /* Now for races */
99 #include "race.h"
100
101 /* Now for recipe/alchemy */
102 #include "recipe.h"
103
104 /* Now for spells */
105 #include "spells.h"
106
107 /*****************************************************************************
108 * GLOBAL VARIABLES: *
109 *****************************************************************************/
110
111 /**
112 * @defgroup first_xxx Beginnings of linked lists.
113 */
114 /*@{*/
115 EXTERN player *first_player; /**< First player. */
116 EXTERN mapstruct *first_map; /**< First map. */
117 EXTERN region *first_region; /**< First region. */
118 EXTERN treasurelist *first_treasurelist; /**< First treasure. */
119 EXTERN artifactlist *first_artifactlist; /**< First artifact. */
120 EXTERN archetype *first_archetype; /**< First archetype. */
121 EXTERN objectlink *first_friendly_object; /**< Objects monsters will go after. */
122 EXTERN godlink *first_god; /**< God list. */
123 EXTERN racelink *first_race; /**< Race list. */
124 /*@}*/
125
126 /*
127 * Variables set by different flags (see init.c):
128 */
129
130 EXTERN long init_done; /**< Ignores signals until init_done is true. */
131 EXTERN long trying_emergency_save; /**< True when emergency_save() is reached. */
132 EXTERN long nroferrors; /**< If it exceeds MAX_ERRORS, call fatal() */
133
134 extern uint32_t pticks; /**< Used by various function to determine
135 * how often to save the character */
136 /**
137 * @defgroup GLOBAL_VARIABLES Misc global variables.
138 */
139 /*@{*/
140 EXTERN FILE *logfile; /**< Used by server/daemon.c */
141 extern int reopen_logfile;
142 EXTERN int exiting; /**< True if the game is about to exit. */
143 EXTERN long nroftreasures; /**< Only used in malloc_info(). */
144 EXTERN long nrofartifacts; /**< Only used in malloc_info(). */
145 EXTERN long nrofallowedstr; /**< Only used in malloc_info(). */
146
147 EXTERN archetype *empty_archetype; /**< Nice to have fast access to it. */
148 EXTERN archetype *map_archeytpe;
149 EXTERN char first_map_path[MAX_BUF]; /**< The start-level. */
150 EXTERN char first_map_ext_path[MAX_BUF]; /**< Path used for per-race start maps. */
151
152 EXTERN long ob_count;
153 /*@}*/
154
155 /*
156 * Used in treasure.c
157 */
158 EXTERN archetype *ring_arch, *amulet_arch, *crown_arch;
159 EXTERN const char *undead_name; /* Used in hit_player() in main.c */
160
161 EXTERN Animations *animations;
162 EXTERN int num_animations, bmaps_checksum;
163
164 /* Rotate right from bsd sum. This is used in various places for checksumming */
165 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
166
167 #define SET_ANIMATION(ob, newanim) { ob->face = (ob->temp_animation ? ob->temp_animation : ob->animation)->faces[newanim]; }
168 #define GET_ANIMATION(ob, anim) ((ob->temp_animation ? ob->temp_animation : ob->animation)->faces[anim])
169 #define GET_ANIM(ob) (ob->temp_animation ? ob->temp_animation : ob->animation)
170 #define GET_ANIM_ID(ob) (ob->temp_animation ? ob->temp_animation->num : (ob->animation ? ob->animation->num : 0))
171 /* NUM_ANIMATIONS returns the number of animations allocated. The last
172 * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
173 * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
174 * range from 0 through 7.
175 */
176 #define NUM_ANIMATIONS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->num_animations)
177 #define NUM_FACINGS(ob) ((ob->temp_animation ? ob->temp_animation : ob->animation)->facings)
178
179 extern short freearr_x[SIZEOFFREE], freearr_y[SIZEOFFREE];
180 extern int maxfree[SIZEOFFREE], freedir[SIZEOFFREE];
181 extern int rightof_x[9], rightof_y[9];
182 extern int leftof_x[9], leftof_y[9];
183
184 extern const Face *blank_face, *empty_face;
185 extern const Face *smooth_face;
186
187 extern uint32_t max_time; /* loop time */
188 extern socket_struct *init_sockets;
189
190 #include "stringbuffer.h"
191 #include "libproto.h"
192 #include "sockproto.h"
193 #include "typesproto.h"
194
195 /**
196 * Free the pointer and then set it to NULL.
197 * This is generally done as a safety, and having this macro
198 * makes the code a bit cleaner when doing so.
199 */
200 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz = NULL; }
201 /**
202 * Release the shared string, and set it to NULL.
203 * Must not be NULL.
204 */
205 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
206
207 /**
208 * Release the shared string if not NULL, and make it a reference to nv.
209 */
210 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
211
212 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
213 #if HAVE_DIRENT_H
214 # include <dirent.h>
215 # define NAMLEN(dirent) strlen((dirent)->d_name)
216 #else
217 # define dirent direct
218 # define NAMLEN(dirent) (dirent)->d_namlen
219 # if HAVE_SYS_NDIR_H
220 # include <sys/ndir.h>
221 # endif
222 # if HAVE_SYS_DIR_H
223 # include <sys/dir.h>
224 # endif
225 # if HAVE_NDIR_H
226 # include <ndir.h>
227 # endif
228 #endif
229 #endif
230
231 /**
232 * Convert saved total experience into permanent experience
233 */
234 #define PERM_EXP(exptotal) (exptotal * settings.permanent_exp_ratio / 100 )
235 #define MAX_TOTAL_EXPERIENCE (settings.permanent_exp_ratio ? (MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio) : 0)
236
237 /**
238 * Server settings.
239 */
240 typedef struct Settings {
241 const char *logfilename; /**< Logfile to use */
242 uint16_t csport; /**< Port for new client/server */
243 LogLevel debug; /**< Default debugging level */
244 uint8_t dumpvalues; /**< Set to dump various values/tables */
245 const char *dumparg; /**< Additional argument for some dump functions */
246 const char *confdir; /**< Configuration files */
247 const char *datadir; /**< Read only data files */
248 const char *localdir; /**< Read/write data files */
249 const char *playerdir; /**< Where the player files are */
250 const char *mapdir; /**< Where the map files are */
251 const char *archetypes; /**< Name of the archetypes file - libdir is prepended */
252 const char *regions; /**< Name of the regions file - libdir is prepended */
253 const char *treasures; /**< Location of the treasures file. */
254 const char *uniquedir; /**< Directory for the unique items */
255 const char *templatedir; /**< Directory for the template map */
256 const char *tmpdir; /**< Directory to use for temporary files */
257 uint8_t stat_loss_on_death; /**< If true, chars lose a random stat when they die */
258 int16_t pk_luck_penalty; /**< Amount by which player luck is reduced if they PK */
259 uint8_t permanent_exp_ratio; /**< How much exp should be 'permenant' and unable to be lost*/
260 uint8_t death_penalty_ratio; /**< Hhow much exp should be lost at death */
261 uint8_t death_penalty_level; /**< How many levels worth of exp may be lost on one death */
262 uint8_t balanced_stat_loss; /**< If true, Death stat depletion based on level etc */
263 uint8_t not_permadeth; /**< If true, death is non-permament */
264 uint8_t simple_exp; /**< If true, use the simple experience system */
265 int reset_loc_time; /**< Number of seconds to put player back at home */
266 uint8_t set_title; /**< Players can set thier title */
267 uint8_t resurrection; /**< Ressurection possible w/ permadeth on */
268 uint8_t search_items; /**< Search_items command */
269 uint8_t spell_encumbrance; /**< Encumbrance effects spells */
270 uint8_t spell_failure_effects; /**< Nasty backlash to spell failures */
271 uint8_t casting_time; /**< It takes awhile to cast a spell */
272 uint8_t real_wiz; /**< Use mud-like wizards */
273 uint8_t recycle_tmp_maps; /**< Re-use tmp maps. */
274 uint8_t always_show_hp; /**< 'probe' spell HP bars for all living things (0, 1, or 2) */
275 uint8_t spellpoint_level_depend; /**< Spell costs go up with level */
276 uint16_t set_friendly_fire; /**< Percent of damage done by peaceful player vs player damage */
277 char who_format[MAX_BUF]; /**< The format that the who command should use */
278 char who_wiz_format[MAX_BUF]; /**< The format that the who command should use when called by a dm*/
279 char motd[MAX_BUF]; /**< Name of the motd file */
280 const char *rules; /**< Name of rules file*/
281 const char *news; /**< Name of news file*/
282 char dm_mail[MAX_BUF]; /**< DM's Email address */
283
284 /* The meta_ is information for the metaserver. These are set in
285 * the lib/settings file.
286 */
287 unsigned int meta_on:1; /**< True if we should send updates */
288 char meta_server[MAX_BUF]; /**< Hostname/ip addr of the metaserver */
289 char meta_host[MAX_BUF]; /**< Hostname of this host */
290 uint16_t meta_port; /**< Port number to use for updates */
291 char meta_comment[MAX_BUF]; /**< Comment we send to the metaserver */
292
293 uint32_t worldmapstartx; /**< Starting x tile for the worldmap */
294 uint32_t worldmapstarty; /**< Starting y tile for the worldmap */
295 uint32_t worldmaptilesx; /**< Number of tiles wide the worldmap is */
296 uint32_t worldmaptilesy; /**< Number of tiles high the worldmap is */
297 uint32_t worldmaptilesizex; /**< Number of squares wide in a wm tile */
298 uint32_t worldmaptilesizey; /**< Number of squares high in a wm tile */
299 uint8_t fastclock; /**< If true, clock goes warp 9 */
300
301 char *emergency_mapname; /**< Map to return players to in emergency */
302 uint16_t emergency_x, emergency_y; /**< Coordinates to use on that map */
303
304 int16_t max_level; /**< This is read out of exp_table */
305 float item_power_factor; /**< See note in setings file */
306
307 int armor_max_enchant; /**< Maximum number of times an armor can be enchanted */
308 int armor_weight_reduction; /**< Weight reduction per enchantment */
309 uint8_t armor_weight_linear; /**< If 1, weight reduction is linear, else exponantiel */
310 int armor_speed_improvement; /**< Speed improvement */
311 uint8_t armor_speed_linear; /**< If 1, speed improvement is linear, else exponantiel */
312 uint8_t no_player_stealing; /**< If 1, can not steal from other players */
313 uint8_t create_home_portals; /**< If 1, can create portals in unique maps (apartments) */
314 uint8_t personalized_blessings; /**< If 1, blessed weapons get an owner and a willpower value */
315 int64_t pk_max_experience; /**< Maximum experience one can get for PKing. Ignore if negative. */
316 int pk_max_experience_percent; /**< Percentage of experience of victim the killer gets. */
317 int allow_denied_spells_writing; /**< If set, players can write spells they can't cast. */
318 int allow_broken_converters; /**< If set, converters will work even if price of generated item is higher
319 * than the price of converted items. */
320 int log_timestamp; /**< If set, log will comport a timestamp. */
321 char *log_timestamp_format; /**< Format for timestap, if log_timestamp is set. */
322 uint8_t starting_stat_min; /**< Minimum value of a starting stat */
323 uint8_t starting_stat_max; /**< Maximum value of a starting stat */
324 uint8_t starting_stat_points; /**< How many stat points character starts with */
325 uint8_t roll_stat_points; /**< How many stat points legacy (rolled) chars start with */
326 uint8_t max_stat; /**< Maximum stat value - 255 should be sufficient */
327 uint8_t special_break_map; /**< If set, then submaps in random maps can break the walls. */
328 linked_char *disabled_plugins; /**< List of disabled plugins, 'All' means all. */
329 uint8_t ignore_plugin_compatibility; /**< If set, don't check plugin version. */
330 uint8_t account_block_create; /** Block account creation for untrusted hosts. */
331 char* account_trusted_host; /**< Trusted host for account creation, defaults to 127.0.0.1. */
332 uint8_t crypt_mode; /**< 0 for legacy behavior, 1 for always Traditional */
333 uint8_t min_name; /**< Minimum characters for an account or player name */
334 } Settings;
335
336 /**
337 * Server settings.
338 */
339 extern Settings settings;
340
341 /**
342 * This is used for various performance tracking statistics,
343 * or just how often certain events are done. It is much better
344 * to use a common structure then variables about.
345 * Note that since these are often counters, I'm using uint64s -
346 * this may be overkill, but it is just a couple extra bytes.
347 * This is initialized/declared in common/init.c. Note that if
348 * it only contains integer values, very easy to initialize/clear it -
349 * just a memset.
350 */
351 typedef struct Statistics {
352 uint64_t spell_merges; /**< Number of spell merges done */
353 uint64_t spell_hash_full; /**< Number of times spell hash was full*/
354 uint64_t spell_suppressions; /**< Number of times ok_to_put_more() returned FALSE*/
355 } Statistics;
356
357 /**
358 * Merged spell statistics.
359 */
360 extern Statistics statistics;
361
362 /**
363 * @defgroup SCRIPT_FIX_xxx For plugin events
364 * GROS: Those are used by plugin events (argument fixthem).
365 */
366 #define SCRIPT_FIX_ACTIVATOR 2
367 #define SCRIPT_FIX_ALL 1
368 #define SCRIPT_FIX_NOTHING 0
369
370 #include "plugin.h"
371
372 #endif /* GLOBAL_H */