Fimbulwinter Project  Pre-Alpha
An Ragnarok Online Emulator
ZoneServer/MapManager.hpp
00001 #pragma once
00002 
00003 #include <ragnarok.hpp>
00004 #include <map_index.hpp>
00005 #include <vector>
00006 
00007 #define BLOCK_SIZE 8
00008 #define MAX_MAP_SIZE 512 * 512
00009 
00010 // Uncomment to activate custom cellflags like novending and nochat
00011 // Note that this will increase map cells memory usage by 100%
00012 //#define ENABLE_CUSTOM_CELLFLAGS
00013 
00014 typedef enum 
00015 {
00016         CELL_CHKWALL,           // wall (gat type 1)
00017         CELL_CHKWATER,          // water (gat type 3)
00018         CELL_CHKCLIFF,          // cliff/gap (gat type 5)
00019 
00020         CELL_CHKPASS,           // passable cell (gat type non-1/5)
00021         CELL_CHKREACH,          // Same as PASS, but ignores the cell-stacking mod.
00022         CELL_CHKNOPASS,         // non-passable cell (gat types 1 and 5)
00023         CELL_CHKNOREACH,        // Same as NOPASS, but ignores the cell-stacking mod.
00024         CELL_CHKSTACK,          // whether cell is full (reached cell stacking limit) 
00025 
00026         CELL_CHKNPC,
00027         CELL_CHKBASILICA,
00028         CELL_CHKLANDPROTECTOR,
00029         CELL_CHKNOVENDING,
00030         CELL_CHKNOCHAT,
00031         CELL_CHKMAELSTROM,
00032 } CellCheck;
00033 
00034 struct MapCell 
00035 {
00036         // terrain flags
00037         unsigned char
00038                 walkable : 1,
00039                 shootable : 1,
00040                 water : 1;
00041 
00042         // dynamic official flags
00043         unsigned char
00044                 npc : 1,
00045                 basilica : 1,
00046                 landprotector : 1,
00047                 maelstrom : 1;
00048         
00049         // custom flags
00050 #ifdef ENABLE_CUSTOM_CELLFLAGS
00051         unsigned char
00052                 novending : 1,
00053                 nochat : 1,
00054 #endif
00055 };
00056 
00057 enum BlockType 
00058 { 
00059         BL_NUL   = 0x000,
00060         BL_PC    = 0x001,
00061         BL_MOB   = 0x002,
00062         BL_PET   = 0x004,
00063         BL_HOM   = 0x008,
00064         BL_MER   = 0x010,
00065         BL_ITEM  = 0x020,
00066         BL_SKILL = 0x040,
00067         BL_NPC   = 0x080,
00068         BL_CHAT  = 0x100,
00069         BL_ELEM   = 0x200,
00070 
00071         BL_ALL   = 0xFFF,
00072 };
00073 
00074 struct BlockList
00075 {
00076         struct BlockList *next, *prev;
00077         int id;
00078         short m, x, y;
00079         enum BlockType type;
00080 };
00081 
00082 // MapData
00083 struct MapData 
00084 {
00085         // Map name
00086         char name[MAP_NAME_LENGTH];
00087 
00088         // MapCell array
00089         struct MapCell* cell;
00090 
00091         // MapIndex ID, Width, Height(in cells)
00092         short m, w, h, wb, hb;
00093 
00094         // Number of players on the map
00095         int users;
00096 
00097         // MapFlags
00098         struct map_flag 
00099         {
00100                 // PvP Flags
00101                 unsigned pvp : 1;
00102                 unsigned pvp_noparty : 1;
00103                 unsigned pvp_noguild : 1;
00104                 unsigned pvp_nightmaredrop :1;
00105                 unsigned pvp_nocalcrank : 1;
00106 
00107                 // GvG Flags
00108                 unsigned gvg_castle : 1;
00109                 unsigned gvg : 1;
00110                 unsigned gvg_dungeon : 1;
00111                 unsigned gvg_noparty : 1;
00112         } flags;
00113 
00114         // Blocks
00115         struct BlockList **blocks;
00116 };
00117 
00118 // eAthena MapCache file header
00119 struct MapCacheHeader 
00120 {
00121         unsigned int file_size;
00122         unsigned short map_count;
00123 };
00124 
00125 // eAthena MapCache Map Descriptor
00126 struct MapCacheMapInfo 
00127 {
00128         char name[MAP_NAME_LENGTH];
00129         unsigned short xs;
00130         unsigned short ys;
00131         unsigned int len;
00132 };
00133 
00134 class MapManager
00135 {
00136 public:
00137         static vector<MapData> maps;
00138         static map_index mapsidx;
00139 
00140         static void initialize();
00141         static bool decode_mapcache(struct MapData *m, char *buffer, char *decode_buffer);
00142 
00143         static int get_map_by_index(int m)
00144         {
00145                 for (unsigned int i = 0; i < maps.size(); i++)
00146                 {
00147                         if (maps[i].m == m)
00148                                 return i;
00149                 }
00150 
00151                 return -1;
00152         }
00153 
00154         static bool check_cell(unsigned int m, short x, short y, CellCheck cellchk);
00155 };
 All Classes Functions