Crossfire Server, Branches 1.12  R18729
global.h
Go to the documentation of this file.
1 /*
2  * static char *rcsid_global_h =
3  * "$Id: global.h 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 /*
7  CrossFire, A Multiplayer game for X-windows
8 
9  Copyright (C) 2006 Mark Wedel & Crossfire Development Team
10  Copyright (C) 1992 Frank Tore Johansen
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 
26  The author can be reached via e-mail to crossfire-devel@real-time.com
27 */
28 
34 #ifndef GLOBAL_H
35 #define GLOBAL_H
36 
37 #ifndef EXTERN
38 #define EXTERN extern
39 #endif
40 
41 #include "includes.h"
42 
43 /* Type defines for specific signed/unsigned variables of a certain number
44  * of bits. Not really used anyplace, but if a certain number of bits
45  * is required, these type defines should then be used. This will make
46  * porting to systems that have different sized data types easier.
47  *
48  * Note: The type defines should just mean that the data type has at
49  * least that many bits. if a uint16 is actually 32 bits, no big deal,
50  * it is just a waste of space.
51  *
52  * Note2: When using something that is normally stored in a character
53  * (ie strings), don't use the uint8/sint8 typdefs, use 'char' instead.
54  * The signedness for char is probably not universal, and using char
55  * will probably be more portable than sint8/unit8
56  */
57 
58 typedef unsigned int uint32;
59 
60 #ifndef UINT32_MAX
61 #define UINT32_MAX 4294967295U
62 #endif
63 
64 typedef signed int sint32;
65 #define SINT32_MAX 2147483647
66 
67 typedef unsigned short uint16;
68 #ifndef UINT16_MAX
69 #define UINT16_MAX 65535
70 #endif
71 
72 typedef signed short sint16;
73 #define SINT16_MAX 32767
74 
75 typedef unsigned char uint8;
76 #ifndef UINT8_MAX
77 #define UINT8_MAX 255
78 #endif
79 
80 typedef signed char sint8;
81 #define SINT8_MAX 127
82 
84 typedef const char *sstring;
85 
86 typedef unsigned short Fontindex;
87 
88 #ifdef WIN32
89 /* Python plugin stuff defines SIZEOF_LONG_LONG as 8, and besides __int64 is a 64b type on MSVC...
90  * So let's force the typedef */
91 typedef unsigned __int64 uint64;
92 typedef signed __int64 sint64;
93 /* Needed for experience */
94 #define atoll _atoi64
95 
96 #define FMT64 "I64d"
97 #define FMT64U "I64u"
98 
99 /* To reduce number of warnings */
100 #pragma warning(disable: 4244) /* conversion from 'xxx' to 'yyy', possible loss of data */
101 #pragma warning(disable: 4305) /* initializing float f = 0.05; instead of f = 0.05f; */
102 
103 #else /* WIN32 */
104 
105 #if SIZEOF_LONG == 8
106 
107 typedef unsigned long uint64;
108 typedef signed long sint64;
109 #define FMT64 "ld"
110 #define FMT64U "lu"
111 
112 #elif SIZEOF_LONG_LONG == 8
113 typedef unsigned long long uint64;
114 typedef signed long long sint64;
115 #define FMT64 "lld"
116 #define FMT64U "llu"
117 
118 #else
119 #error do not know how to get a 64 bit value on this system.
120 #error correct and send mail to crossfire-devel on how to do this
121 #endif
122 
123 #endif
124 
125 /* This blob, in this order, is needed to actually define maps */
126 #include "face.h"
127 /* Include the basic defines from spells.h */
128 #include "attack.h" /* needs to be before material.h */
129 #include "material.h"
130 #include "living.h"
131 #include "object.h"
132 #include "map.h"
133 #include "tod.h"
134 
135 #include "skills.h"
136 
137 /* Pull in the socket structure - used in the player structure */
138 #include "newserver.h"
139 
140 /* Pull in the player structure */
141 #include "player.h"
142 
143 /* pull in treasure structure */
144 #include "treasure.h"
145 
146 #include "commands.h"
147 
148 /* pull in book structures */
149 #include "book.h"
150 
151 /* ob_methods and ob_types subsystem */
152 #include "ob_methods.h"
153 #include "ob_types.h"
154 
155 /*
156  * So far only used when dealing with artifacts.
157  * (now used by alchemy and other code too. Nov 95 b.t).
158  */
159 typedef struct linked_char {
160  const char *name;
161  struct linked_char *next;
162 } linked_char;
163 
164 
165 /* Pull in artifacts */
166 #include "artifact.h"
167 
168 /* Now for gods */
169 #include "god.h"
170 
171 /* Now for races */
172 #include "race.h"
173 
174 /* Now for recipe/alchemy */
175 #include "recipe.h"
176 
177 /* Now for spells */
178 #include "spells.h"
179 
180 /*****************************************************************************
181  * GLOBAL VARIABLES: *
182  *****************************************************************************/
183 
184 extern New_Face *new_faces;
185 
200 
201 #define NROF_COMPRESS_METHODS 4
202 extern const char *uncomp[NROF_COMPRESS_METHODS][3];
203 
204 /*
205  * Variables set by different flags (see init.c):
206  */
207 
214 extern uint32 pticks;
221 extern int reopen_logfile;
235 /*
236  * Used in treasure.c
237  */
239 EXTERN const char *undead_name; /* Used in hit_player() in main.c */
240 
243 
244 /* Rotate right from bsd sum. This is used in various places for checksumming */
245 #define ROTATE_RIGHT(c) if ((c)&01) (c) = ((c)>>1)+0x80000000; else (c) >>= 1;
246 
247 #define SET_ANIMATION(ob, newanim) { if (ob->temp_animation_id) { ob->face = &new_faces[animations[ob->temp_animation_id].faces[newanim]]; } else { ob->face = &new_faces[animations[ob->animation_id].faces[newanim]]; } }
248 #define GET_ANIMATION(ob, anim) (ob->temp_animation_id ? animations[ob->temp_animation_id].faces[anim] : animations[ob->animation_id].faces[anim])
249 #define GET_ANIM_ID(ob) (ob->temp_animation_id ? ob->temp_animation_id : ob->animation_id)
250 /* NUM_ANIMATIONS returns the number of animations allocated. The last
251  * usuable animation will be NUM_ANIMATIONS-1 (for example, if an object
252  * has 8 animations, NUM_ANIMATIONS will return 8, but the values will
253  * range from 0 through 7.
254  */
255 #define NUM_ANIMATIONS(ob) (ob->temp_animation_id ? animations[ob->temp_animation_id].num_animations : animations[ob->animation_id].num_animations)
256 #define NUM_FACINGS(ob) (ob->temp_animation_id ? animations[ob->temp_animation_id].facings : animations[ob->animation_id].facings)
257 
258 extern short freearr_x[SIZEOFFREE], freearr_y[SIZEOFFREE];
259 extern int maxfree[SIZEOFFREE], freedir[SIZEOFFREE];
260 extern int rightof_x[9], rightof_y[9];
261 extern int leftof_x[9], leftof_y[9];
262 
263 extern New_Face *blank_face, *empty_face;
264 extern New_Face *smooth_face;
265 
266 extern uint32 max_time; /* loop time */
268 
269 #ifndef __CEXTRACT__
270 #include "stringbuffer.h"
271 #include "libproto.h"
272 #include "sockproto.h"
273 #include "typesproto.h"
274 #endif
275 
276 #define decrease_ob(xyz) decrease_ob_nr(xyz, 1)
277 
278 /* FREE_AND_CLEAR frees the pointer and then sets it to NULL.
279  * This is generally done as a safety, and having this macro
280  * makes the code a bit cleaner when doing so.
281  */
282 #define FREE_AND_CLEAR(xyz) { free((void *)xyz); xyz = NULL; }
283 #define FREE_AND_CLEAR_STR(xyz) { free_string(xyz); xyz = NULL; }
284 
285 /* FREE_AND_COPY is for the shared string - it is handy enough
286  * to use all over the place.
287  */
288 #define FREE_AND_COPY(sv, nv) { if (sv) free_string(sv); sv = add_string(nv); }
289 
290 #ifdef CALLOC
291 #undef CALLOC
292 #endif
293 
294 #ifdef USE_CALLOC
295 # define CALLOC(x, y) calloc(x, y)
296 # define CFREE(x) free(x)
297 #else
298 # define CALLOC(x, y) malloc(x*y)
299 # define CFREE(x) free(x)
300 #endif
301 
302 #ifndef WIN32 /* ---win32 we define this stuff in win32.h */
303 #if HAVE_DIRENT_H
304 # include <dirent.h>
305 # define NAMLEN(dirent) strlen((dirent)->d_name)
306 #else
307 # define dirent direct
308 # define NAMLEN(dirent) (dirnet)->d_namlen
309 # if HAVE_SYS_NDIR_H
310 # include <sys/ndir.h>
311 # endif
312 # if HAVE_SYS_DIR_H
313 # include <sys/dir.h>
314 # endif
315 # if HAVE_NDIR_H
316 # include <ndir.h>
317 # endif
318 #endif
319 #endif
320 
324 typedef struct Settings {
325  const char *logfilename;
329  const char *dumparg;
331  int argc;
332  char **argv;
333  const char *confdir;
334  const char *datadir;
335  const char *localdir;
336  const char *playerdir;
337  const char *mapdir;
338  const char *archetypes;
339  const char *regions;
340  const char *treasures;
341  const char *uniquedir;
342  const char *templatedir;
343  const char *tmpdir;
366  char motd[MAX_BUF];
367  const char *rules;
368  const char *news;
369  char dm_mail[MAX_BUF];
371  /* The meta_ is information for the metaserver. These are set in
372  * the lib/settings file.
373  */
374  unsigned int meta_on:1;
409 } Settings;
410 
411 extern Settings settings;
412 
423 typedef struct Statistics {
424  uint64 spell_merges;
427 } Statistics;
428 
429 extern Statistics statistics;
430 
431 /* 0.94.1 - change to GETTIMEOFDAY macro - SNI systems only one one option.
432  * rather than have complex #ifdefs throughout the file, lets just figure
433  * it out once, here at the top.
434  * Have no idea if that is the right symbol to check on for NetBSD,
435  * but NetBSD does use 2 params.
436  * Move this to global.h from time.c since its also used in arch.c
437  */
438 
439 #ifdef GETTIMEOFDAY_TWO_ARGS
440 #define GETTIMEOFDAY(last_time) gettimeofday(last_time, (struct timezone *)NULL);
441 #else
442 #define GETTIMEOFDAY(last_time) gettimeofday(last_time);
443 #endif
444 
449 #define SCRIPT_FIX_ACTIVATOR 2
450 #define SCRIPT_FIX_ALL 1
451 #define SCRIPT_FIX_NOTHING 0
452 
453 #include "plugin.h"
454 
455 #endif /* GLOBAL_H */
EXTERN FILE * logfile
Definition: global.h:220
uint8 spell_encumbrance
Definition: global.h:356
const char * rules
Definition: global.h:367
signed char sint8
Definition: global.h:80
Definition: player.h:146
uint16 emergency_y
Definition: global.h:389
uint32 worldmapstarty
Definition: global.h:381
uint32 worldmapstartx
Definition: global.h:380
char meta_host[MAX_BUF]
Definition: global.h:376
signed short sint16
Definition: global.h:72
EXTERN long ob_count
Definition: global.h:232
uint8 dumpvalues
Definition: global.h:328
Definition: object.h:298
uint32 pticks
Definition: time.c:56
uint16 emergency_x
Definition: global.h:389
int leftof_x[9]
uint32 worldmaptilesx
Definition: global.h:382
unsigned int meta_on
Definition: global.h:374
signed int sint32
Definition: global.h:64
uint8 death_penalty_ratio
Definition: global.h:347
uint64 spell_suppressions
Definition: global.h:426
uint8 recycle_tmp_maps
Definition: global.h:360
Definition: race.h:12
EXTERN int num_animations
Definition: global.h:242
char who_wiz_format[MAX_BUF]
Definition: global.h:365
Statistics statistics
Definition: init.c:119
uint8 fastclock
Definition: global.h:386
EXTERN objectlink * first_friendly_object
Definition: global.h:196
char motd[MAX_BUF]
Definition: global.h:366
uint8 casting_time
Definition: global.h:358
const char * playerdir
Definition: global.h:336
sint16 max_level
Definition: global.h:391
int reopen_logfile
Definition: logger.c:6
uint8 set_title
Definition: global.h:353
const char * regions
Definition: global.h:339
int allow_broken_converters
Definition: global.h:405
int armor_max_enchant
Definition: global.h:394
int rightof_y[9]
Definition: god.h:12
uint8 spellpoint_level_depend
Definition: global.h:362
uint32 worldmaptilesizey
Definition: global.h:385
char ** argv
Definition: global.h:332
uint32 worldmaptilesy
Definition: global.h:383
LogLevel debug
Definition: global.h:327
uint8 search_items
Definition: global.h:355
Settings settings
Definition: init.c:48
EXTERN char first_map_ext_path[MAX_BUF]
Definition: global.h:230
uint8 no_player_stealing
Definition: global.h:399
char meta_server[MAX_BUF]
Definition: global.h:375
uint8 balanced_stat_loss
Definition: global.h:349
int leftof_y[9]
uint8 explore_mode
Definition: global.h:361
const char * treasures
Definition: global.h:340
Definition: object.h:321
const char * logfilename
Definition: global.h:325
uint8 not_permadeth
Definition: global.h:350
char meta_comment[MAX_BUF]
Definition: global.h:378
socket_struct * init_sockets
Definition: init.c:68
uint8 daemonmode
Definition: global.h:330
uint8 resurrection
Definition: global.h:354
const char * news
Definition: global.h:368
EXTERN archetype * amulet_arch
Definition: global.h:238
int argc
Definition: global.h:331
EXTERN archetype * empty_archetype
Definition: global.h:227
char * log_timestamp_format
Definition: global.h:408
int armor_speed_improvement
Definition: global.h:397
const char * dumparg
Definition: global.h:329
uint8 spell_failure_effects
Definition: global.h:357
uint8 create_home_portals
Definition: global.h:400
EXTERN const char * undead_name
Definition: global.h:239
int rightof_x[9]
uint64 spell_merges
Definition: global.h:424
uint8 stat_loss_on_death
Definition: global.h:344
sint16 pk_luck_penalty
Definition: global.h:345
const char * tmpdir
Definition: global.h:343
Definition: map.h:297
struct linked_char * next
Definition: global.h:161
uint64 spell_hash_full
Definition: global.h:425
New_Face * new_faces
Definition: image.c:38
unsigned char uint8
Definition: global.h:75
int maxfree[SIZEOFFREE]
Definition: object.c:87
EXTERN racelink * first_race
Definition: global.h:198
#define SIZEOFFREE
Definition: define.h:441
EXTERN long nroferrors
Definition: global.h:212
EXTERN Animations * animations
Definition: global.h:241
short freearr_y[SIZEOFFREE]
Definition: object.c:81
const char * templatedir
Definition: global.h:342
#define NROF_COMPRESS_METHODS
Definition: global.h:201
EXTERN godlink * first_god
Definition: global.h:197
const char * archetypes
Definition: global.h:338
EXTERN treasurelist * first_treasurelist
Definition: global.h:193
EXTERN artifactlist * first_artifactlist
Definition: global.h:194
#define MAX_BUF
Definition: define.h:81
New_Face * empty_face
Definition: image.c:66
uint32 worldmaptilesizex
Definition: global.h:384
LogLevel
Definition: logger.h:37
char who_format[MAX_BUF]
Definition: global.h:364
unsigned short uint16
Definition: global.h:67
const char * confdir
Definition: global.h:333
EXTERN archetype * crown_arch
Definition: global.h:238
New_Face * smooth_face
Definition: image.c:66
const char * uniquedir
Definition: global.h:341
EXTERN long nrofartifacts
Definition: global.h:224
const char * sstring
Definition: global.h:84
const char * uncomp[NROF_COMPRESS_METHODS][3]
Definition: porting.c:593
uint16 meta_port
Definition: global.h:377
int log_timestamp
Definition: global.h:407
const char * datadir
Definition: global.h:334
EXTERN long nrofallowedstr
Definition: global.h:225
int freedir[SIZEOFFREE]
Definition: object.c:93
const char * name
Definition: global.h:160
int armor_weight_reduction
Definition: global.h:395
struct Settings Settings
#define EXTERN
Definition: global.h:38
uint8 armor_weight_linear
Definition: global.h:396
const char * localdir
Definition: global.h:335
uint8 death_penalty_level
Definition: global.h:348
EXTERN archetype * staff_arch
Definition: global.h:238
const char * mapdir
Definition: global.h:337
EXTERN int bmaps_checksum
Definition: global.h:242
EXTERN int exiting
Definition: global.h:222
EXTERN long trying_emergency_save
Definition: global.h:211
EXTERN int animations_allocated
Definition: global.h:242
char dm_mail[MAX_BUF]
Definition: global.h:369
EXTERN char first_map_path[MAX_BUF]
Definition: global.h:229
EXTERN player * first_player
Definition: global.h:190
uint16 csport
Definition: global.h:326
int reset_loc_time
Definition: global.h:352
struct linked_char linked_char
New_Face * blank_face
Definition: image.c:66
EXTERN long init_done
Definition: global.h:210
uint8 personalized_blessings
Definition: global.h:401
uint8 permanent_exp_ratio
Definition: global.h:346
uint16 set_friendly_fire
Definition: global.h:363
EXTERN long warn_archetypes
Definition: global.h:208
EXTERN archetype * ring_arch
Definition: global.h:238
unsigned int uint32
Definition: global.h:58
EXTERN region * first_region
Definition: global.h:192
short freearr_x[SIZEOFFREE]
Definition: object.c:75
uint32 max_time
Definition: time.c:46
int allow_denied_spells_writing
Definition: global.h:404
char * emergency_mapname
Definition: global.h:388
Definition: map.h:346
sint64 pk_max_experience
Definition: global.h:402
unsigned short Fontindex
Definition: global.h:86
int pk_max_experience_percent
Definition: global.h:403
EXTERN mapstruct * first_map
Definition: global.h:191
uint8 real_wiz
Definition: global.h:359
EXTERN archetype * first_archetype
Definition: global.h:195
EXTERN archetype * map_archeytpe
Definition: global.h:228
float item_power_factor
Definition: global.h:392
uint8 armor_speed_linear
Definition: global.h:398
struct Statistics Statistics
uint8 simple_exp
Definition: global.h:351
EXTERN long nroftreasures
Definition: global.h:223