Atrinik Server 2.5
include/global.h
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #ifndef GLOBAL_H
00031 #define GLOBAL_H
00032 
00033 #ifndef EXTERN
00034 #define EXTERN extern
00035 #endif
00036 
00037 /* If we're not using GNU C, ignore __attribute__ */
00038 #ifndef __GNUC__
00039 #   define  __attribute__(x)
00040 #endif
00041 
00042 #include "includes.h"
00043 
00044 /* Type defines for specific signed/unsigned variables of a certain number
00045  * of bits.  Not really used anyplace, but if a certain number of bits
00046  * is required, these type defines should then be used.  This will make
00047  * porting to systems that have different sized data types easier.
00048  *
00049  * Note: The type defines should just mean that the data type has at
00050  * least that many bits.  if a uint16 is actually 32 bits, no big deal,
00051  * it is just a waste of space.
00052  *
00053  * Note2:  When using something that is normally stored in a character
00054  * (ie strings), don't use the uint8/sint8 typedefs, use 'char' instead.
00055  * The signedness for char is probably not universal, and using char
00056  * will probably be more portable than sint8/unit8 */
00057 
00059 typedef unsigned int uint32;
00060 #ifndef UINT32_MAX
00061 #   define UINT32_MAX (4294967295U)
00062 #endif
00063 
00065 typedef signed int sint32;
00066 #define SINT32_MIN (-2147483647 - 1)
00067 #define SINT32_MAX 2147483647
00068 
00070 typedef unsigned short uint16;
00071 #ifndef UINT16_MAX
00072 #   define UINT16_MAX (65535U)
00073 #endif
00074 
00076 typedef signed short sint16;
00077 #define SINT16_MIN (-32767 - 1)
00078 #define SINT16_MAX (32767)
00079 
00081 typedef unsigned char uint8;
00082 #ifndef UINT8_MAX
00083 #   define UINT8_MAX (255U)
00084 #endif
00085 
00087 typedef signed char sint8;
00088 #define SINT8_MIN (-128)
00089 #define SINT8_MAX (127)
00090 
00092 typedef unsigned short Fontindex;
00093 
00095 typedef unsigned int tag_t;
00096 
00098 typedef const char shstr;
00099 
00100 #ifdef WIN32
00101     /* Python plugin stuff defines SIZEOF_LONG_LONG as 8, and besides __int64
00102      * is a 64b type on MSVC... So let's force the typedef. */
00103     typedef unsigned __int64            uint64;
00104     typedef signed __int64              sint64;
00105 #   define atoll                        _atoi64
00106 
00107 #   define FMT64                        "I64d"
00108 #   define FMT64U                       "I64u"
00109 #   define FMT64HEX                     "I64x"
00110 #else
00111 #   if SIZEOF_LONG == 8
00112         typedef unsigned long           uint64;
00113         typedef signed long             sint64;
00114 #       define FMT64                    "ld"
00115 #       define FMT64U                   "lu"
00116 #       define FMT64HEX                 "lx"
00117 
00118 #   elif SIZEOF_LONG_LONG == 8
00119         typedef unsigned long long      uint64;
00120         typedef signed long long        sint64;
00121 #       define FMT64                    "lld"
00122 #       define FMT64U                   "llu"
00123 #       define FMT64HEX                 "llx"
00124 
00125 #   else
00126 #       error Do not know how to get a 64 bit value on this system.
00127 #       error Correct and send email to the Atrinik Team on how to do this.
00128 #   endif
00129 #endif
00130 
00131 #ifndef UINT64_MAX
00132 #   define UINT64_MAX (18446744073709551615LLU)
00133 #endif
00134 
00135 #define SINT64_MIN (-9223372036854775807LL - 1)
00136 #define SINT64_MAX (9223372036854775807LL)
00137 
00144 #define MONEYSTRING_NOTHING 0
00145 
00146 #define MONEYSTRING_AMOUNT 1
00147 
00148 #define MONEYSTRING_ALL -1
00149 
00154 typedef struct _money_block
00155 {
00157     int mode;
00158 
00160     sint64 mithril;
00161 
00163     sint64 gold;
00164 
00166     sint64 silver;
00167 
00169     sint64 copper;
00170 } _money_block;
00171 
00182 #define BANK_SYNTAX_ERROR -1
00183 
00184 #define BANK_SUCCESS 0
00185 
00187 #define BANK_WITHDRAW_HIGH 1
00188 
00189 #define BANK_WITHDRAW_MISSING 2
00190 
00191 #define BANK_WITHDRAW_OVERWEIGHT 3
00192 
00194 #define BANK_DEPOSIT_COPPER 1
00195 
00196 #define BANK_DEPOSIT_SILVER 2
00197 
00198 #define BANK_DEPOSIT_GOLD 3
00199 
00200 #define BANK_DEPOSIT_MITHRIL 4
00201 
00203 #define POW2(x) ((x) * (x))
00204 
00211 #define MAP_INFO_NORMAL 12
00212 
00213 #define MAP_INFO_ALL 9999
00214 
00225 #define FREE_AND_COPY_HASH(_sv_, _nv_) \
00226 {                                      \
00227     if (_sv_)                          \
00228     {                                  \
00229         free_string_shared(_sv_);      \
00230     }                                  \
00231                                        \
00232     _sv_ = add_string(_nv_);           \
00233 }
00234 
00238 #define FREE_AND_ADD_REF_HASH(_sv_, _nv_) \
00239 {                                         \
00240     if (_sv_)                             \
00241     {                                     \
00242         free_string_shared(_sv_);         \
00243     }                                     \
00244                                           \
00245     _sv_ = add_refcount(_nv_);            \
00246 }
00247 
00250 #define FREE_AND_CLEAR_HASH(_nv_) \
00251 {                                 \
00252     if (_nv_)                     \
00253     {                             \
00254         free_string_shared(_nv_); \
00255         _nv_ = NULL;              \
00256     }                             \
00257 }
00258 
00261 #define FREE_ONLY_HASH(_nv_)  \
00262 if (_nv_)                     \
00263 {                             \
00264     free_string_shared(_nv_); \
00265 }
00266 
00269 #define ADD_REF_NOT_NULL_HASH(_nv_) \
00270 if (_nv_)                           \
00271 {                                   \
00272     add_refcount(_nv_);             \
00273 }
00274 
00277 #define FREE_AND_CLEAR_HASH2(_nv_) \
00278 if (_nv_)                          \
00279 {                                  \
00280     free_string_shared(_nv_);      \
00281     _nv_ = NULL;                   \
00282 }
00283 
00285 #define SPAWN_RANDOM_RANGE 10000
00286 
00287 #define T_STYLE_UNSET (-2)
00288 #define ART_CHANCE_UNSET (-1)
00289 
00291 #define MIN_MON_RADIUS 2
00292 
00293 #define MAX_AGGRO_RANGE 9
00294 
00295 #define MAX_AGGRO_TIME 12
00296 
00303 #define SEND_FACE_OK             0
00304 
00305 #define SEND_FACE_OUT_OF_BOUNDS  1
00306 
00307 #define SEND_FACE_NO_DATA        2
00308 
00311 #define TILED_MAPS 8
00312 
00313 #define EXP_AGILITY 1
00314 #define EXP_MENTAL 2
00315 #define EXP_MAGICAL 3
00316 #define EXP_PERSONAL 4
00317 #define EXP_PHYSICAL 5
00318 #define EXP_WISDOM 6
00319 
00320 #define MAX_EXP_CAT 7
00321 
00323 #define EXP_NONE 0
00324 
00326 #define MAXLEVEL 115
00327 extern uint64 new_levels[MAXLEVEL + 2];
00328 
00331 typedef struct linked_char
00332 {
00334     shstr *name;
00335 
00337     struct linked_char *next;
00338 } linked_char;
00339 
00340 #include "face.h"
00341 #include "attack.h"
00342 #include "material.h"
00343 #include "living.h"
00344 #include "object.h"
00345 #include "arch.h"
00346 #include "map.h"
00347 #include "mempool.h"
00348 #include "tod.h"
00349 #include "pathfinder.h"
00350 #include "newserver.h"
00351 #include "skills.h"
00352 #include "party.h"
00353 #include "player.h"
00354 #include "treasure.h"
00355 #include "commands.h"
00356 #include "artifact.h"
00357 #include "god.h"
00358 #include "race.h"
00359 #include "sounds.h"
00360 #include "recipe.h"
00361 #include "spells.h"
00362 #include "stringbuffer.h"
00363 
00368 #define special_potion(__op_sp) (__op_sp)->last_eat
00369 
00370 extern int arch_cmp;
00371 extern int arch_search;
00372 
00374 #define move_object(__op, __dir) move_ob(__op, __dir, __op)
00375 
00376 #define is_magical(__op_) QUERY_FLAG(__op_, FLAG_IS_MAGICAL)
00377 
00378 extern New_Face *new_faces;
00379 
00384 player *first_player;
00386 mapstruct *first_map;
00388 treasurelist *first_treasurelist;
00390 artifactlist *first_artifactlist;
00392 godlink *first_god;
00396 player *last_player;
00397 
00398 #define NROF_COMPRESS_METHODS 4
00399 EXTERN char *uncomp[NROF_COMPRESS_METHODS][3];
00400 
00402 EXTERN long init_done;
00404 EXTERN long nroferrors;
00405 
00407 extern long pticks;
00408 
00410 EXTERN FILE *logfile;
00412 EXTERN long nroftreasures;
00414 EXTERN long nrofartifacts;
00416 EXTERN long nrofallowedstr;
00417 
00418 extern object void_container;
00419 
00421 EXTERN char first_map_path[MAX_BUF];
00425 EXTERN long ob_count;
00426 
00428 EXTERN uint32 global_round_tag;
00429 #define ROUND_TAG global_round_tag /* put this here because the DIFF */
00430 
00432 EXTERN int global_race_counter;
00433 
00435 EXTERN struct timeval last_time;
00436 EXTERN Animations *animations;
00437 EXTERN int num_animations, animations_allocated;
00438 
00440 #define STRING_SAFE(__string__) (__string__ ? __string__ : ">NULL<")
00441 
00442 #define STRING_ARCH_NAME(__arch__) ((__arch__)->name ? (__arch__)->name : ">NULL<")
00443 
00444 #define STRING_OBJ_NAME(__ob__) ((__ob__) && (__ob__)->name ? (__ob__)->name : ">NULL<")
00445 
00446 #define STRING_OBJ_ARCH_NAME(__ob__) ((__ob__)->arch ? ((__ob__)->arch->name ? (__ob__)->arch->name : ">NULL<") : ">NULL<")
00447 
00448 #define STRING_OBJ_SLAYING(__ob__) ((__ob__)->slaying ? (__ob__)->slaying : ">NULL<")
00449 
00454 #define SET_ANIMATION(ob, newanim) ob->face = &new_faces[animations[ob->animation_id].faces[newanim]]
00455 
00456 #define GET_ANIM_ID(ob) (ob->animation_id)
00457 
00458 #define GET_INV_ANIM_ID(ob) (ob->inv_animation_id)
00459 
00460 #define NUM_ANIMATIONS(ob) (animations[ob->animation_id].num_animations)
00461 
00462 #define NUM_FACINGS(ob) (animations[ob->animation_id].facings)
00463 
00464 extern int freearr_x[SIZEOFFREE], freearr_y[SIZEOFFREE];
00465 extern int maxfree[SIZEOFFREE], freedir[SIZEOFFREE];
00466 
00467 extern New_Face *blank_face, *next_item_face, *prev_item_face;
00468 
00469 extern long max_time;
00470 extern socket_struct *init_sockets;
00471 extern unsigned long todtick;
00472 extern int world_darkness;
00473 
00475 EXTERN archetype *wp_archetype;
00477 EXTERN archetype *empty_archetype;
00479 EXTERN archetype *base_info_archetype;
00480 EXTERN archetype *level_up_arch;
00481 
00483 #define FREE_AND_NULL_PTR(_xyz_) \
00484 {                                \
00485     if (_xyz_)                   \
00486     {                            \
00487         free(_xyz_);             \
00488     }                            \
00489                                  \
00490     _xyz_ = NULL;                \
00491 }
00492 
00493 #ifdef CALLOC
00494 #undef CALLOC
00495 #endif
00496 
00497 #ifdef USE_CALLOC
00498 #   define CALLOC(x, y) calloc(x, y)
00499 #   define CFREE(x) free(x)
00500 #else
00501 #   define CALLOC(x, y) malloc(x * y)
00502 #   define CFREE(x) free(x)
00503 #endif
00504 
00506 typedef struct Settings
00507 {
00509     char *logfilename;
00510 
00512     uint16 csport;
00513 
00515     LogLevel debug;
00516 
00518     uint8 dumpvalues;
00519 
00521     char *dumparg;
00522 
00524     uint8 daemonmode;
00525 
00527     char *datadir;
00528 
00530     char *localdir;
00531 
00533     char *mapdir;
00534 
00536     char *playerdir;
00537 
00539     char *archetypes;
00540 
00542     char *treasures;
00543 
00545     char *uniquedir;
00546 
00548     char *tmpdir;
00549 
00551     uint8 stat_loss_on_death;
00552 
00554     uint8 balanced_stat_loss;
00555 
00557     unsigned int meta_on:1;
00558 
00560     char meta_server[MAX_BUF];
00561 
00563     char meta_host[MAX_BUF];
00564 
00566     char meta_name[MAX_BUF];
00567 
00569     char meta_comment[MAX_BUF];
00570 
00572     char world_maker_dir[MAX_BUF];
00573 
00575     char client_maps_url[MAX_BUF];
00576 
00578     uint8 watchdog;
00579 
00581     uint8 interactive;
00582 
00584     uint8 unit_tests;
00585 
00587     uint8 world_maker;
00588 
00590     sint8 magic_devices_level;
00591 
00593     float item_power_factor;
00594 
00595     uint8 timestamp;
00596 } Settings;
00597 
00598 extern Settings settings;
00599 
00601 EXTERN struct shstr_constants
00602 {
00603     const char *none;
00604     const char *NONE;
00605     const char *home;
00606     const char *force;
00607     const char *portal_destination_name;
00608     const char *portal_active_name;
00609     const char *spell_quickslot;
00610 
00611     const char *GUILD_FORCE;
00612     const char *guild_force;
00613     const char *RANK_FORCE;
00614     const char *rank_force;
00615     const char *ALIGNMENT_FORCE;
00616     const char *alignment_force;
00617 
00618     const char *grace_limit;
00619     const char *restore_grace;
00620     const char *restore_hitpoints;
00621     const char *restore_spellpoints;
00622     const char *heal_spell;
00623     const char *remove_curse;
00624     const char *remove_damnation;
00625     const char *heal_depletion;
00626     const char *message;
00627     const char *enchant_weapon;
00628 
00629     const char *player_info;
00630     const char *BANK_GENERAL;
00631 
00632     const char *of_poison;
00633     const char *of_hideous_poison;
00634 } shstr_cons;
00635 
00636 EXTERN void (*object_initializers[256])(object *);
00637 
00639 typedef struct ban_struct
00640 {
00642     const char *name;
00643 
00645     char *ip;
00646 } _ban_struct;
00647 
00653 #define CACHE_FLAG_PYOBJ 1
00654 
00655 #define CACHE_FLAG_AUTOFREE 2
00656 
00657 #define CACHE_FLAG_GEVENT 4
00658 
00661 typedef struct cache_struct
00662 {
00664     shstr *key;
00665 
00667     void *ptr;
00668 
00670     uint32 flags;
00671 
00673     size_t id;
00674 } cache_struct;
00675 
00676 #ifndef tolower
00677 #   define tolower(C) (((C) >= 'A' && (C) <= 'Z') ? (C) - 'A' + 'a': (C))
00678 #endif
00679 
00680 #define GETTIMEOFDAY(last_time) gettimeofday(last_time, (struct timezone *) NULL);
00681 
00687 #define SCRIPT_FIX_ACTIVATOR 2
00688 
00689 #define SCRIPT_FIX_ALL 1
00690 
00691 #define SCRIPT_FIX_NOTHING 0
00692 
00694 #include "random_map.h"
00695 #include "proto.h"
00696 #include "plugin.h"
00697 
00698 #endif