Pārlūkot izejas kodu

Initial work for map server to C++ (#2565)

* Initial progression of moving the map-server to C++ format.
* Converted all core files to .cpp and header files to .hpp.
* Refactored the refine database parser to utilize native YAML C++.
Thanks to @Jeybla and @lighta for their help!
Aleos 7 gadi atpakaļ
vecāks
revīzija
c4a364be2c
100 mainītis faili ar 1649 papildinājumiem un 1769 dzēšanām
  1. 8 3
      3rdparty/libconfig/grammar.h
  2. 2 0
      3rdparty/libconfig/libconfig.h
  3. 2 0
      3rdparty/libconfig/parsectx.h
  4. 10 0
      3rdparty/libconfig/scanctx.h
  5. 2 0
      3rdparty/libconfig/scanner.h
  6. 10 0
      3rdparty/libconfig/strbuf.h
  7. 2 0
      3rdparty/libconfig/wincompat.h
  8. 10 0
      3rdparty/mt19937ar/mt19937ar.h
  9. 2 1
      src/common/cbasetypes.h
  10. 8 0
      src/common/conf.h
  11. 12 12
      src/common/db.h
  12. 38 1
      src/common/mmo.h
  13. 2 86
      src/map/CMakeLists.txt
  14. 3 2
      src/map/Makefile.in
  15. 19 16
      src/map/achievement.cpp
  16. 3 11
      src/map/achievement.hpp
  17. 41 33
      src/map/atcommand.cpp
  18. 6 14
      src/map/atcommand.hpp
  19. 31 32
      src/map/battle.cpp
  20. 22 23
      src/map/battle.hpp
  21. 11 8
      src/map/battleground.cpp
  22. 4 12
      src/map/battleground.hpp
  23. 15 11
      src/map/buyingstore.cpp
  24. 7 10
      src/map/buyingstore.hpp
  25. 18 11
      src/map/cashshop.cpp
  26. 8 12
      src/map/cashshop.hpp
  27. 16 10
      src/map/channel.cpp
  28. 11 11
      src/map/channel.hpp
  29. 12 8
      src/map/chat.cpp
  30. 4 12
      src/map/chat.hpp
  31. 29 24
      src/map/chrif.cpp
  32. 7 11
      src/map/chrif.hpp
  33. 11 7
      src/map/clan.cpp
  34. 0 32
      src/map/clan.h
  35. 26 0
      src/map/clan.hpp
  36. 45 48
      src/map/clif.cpp
  37. 35 46
      src/map/clif.hpp
  38. 3 3
      src/map/clif_obfuscation.hpp
  39. 3 3
      src/map/clif_packetdb.hpp
  40. 3 3
      src/map/clif_shuffle.hpp
  41. 2 1
      src/map/date.cpp
  42. 3 10
      src/map/date.hpp
  43. 10 6
      src/map/duel.cpp
  44. 4 9
      src/map/duel.hpp
  45. 19 14
      src/map/elemental.cpp
  46. 8 14
      src/map/elemental.hpp
  47. 23 21
      src/map/guild.cpp
  48. 7 12
      src/map/guild.hpp
  49. 18 16
      src/map/homunculus.cpp
  50. 13 19
      src/map/homunculus.hpp
  51. 15 12
      src/map/instance.cpp
  52. 10 14
      src/map/instance.hpp
  53. 34 29
      src/map/intif.cpp
  54. 7 13
      src/map/intif.hpp
  55. 41 34
      src/map/itemdb.cpp
  56. 6 14
      src/map/itemdb.hpp
  57. 19 17
      src/map/log.cpp
  58. 13 19
      src/map/log.hpp
  59. 12 8
      src/map/mail.cpp
  60. 3 11
      src/map/mail.hpp
  61. 84 80
      src/map/map-server.vcxproj
  62. 80 80
      src/map/map-server.vcxproj.filters
  63. 33 36
      src/map/map.cpp
  64. 25 30
      src/map/map.hpp
  65. 12 11
      src/map/mapreg.cpp
  66. 5 12
      src/map/mapreg.hpp
  67. 15 13
      src/map/mercenary.cpp
  68. 7 13
      src/map/mercenary.hpp
  69. 21 24
      src/map/mob.cpp
  70. 10 18
      src/map/mob.hpp
  71. 46 40
      src/map/npc.cpp
  72. 8 15
      src/map/npc.hpp
  73. 6 4
      src/map/npc_chat.cpp
  74. 16 11
      src/map/party.cpp
  75. 5 12
      src/map/party.hpp
  76. 17 12
      src/map/path.cpp
  77. 6 12
      src/map/path.hpp
  78. 70 56
      src/map/pc.cpp
  79. 26 31
      src/map/pc.hpp
  80. 8 7
      src/map/pc_groups.cpp
  81. 8 6
      src/map/pc_groups.hpp
  82. 17 12
      src/map/pet.cpp
  83. 13 11
      src/map/pet.hpp
  84. 15 10
      src/map/quest.cpp
  85. 8 9
      src/map/quest.hpp
  86. 41 39
      src/map/script.cpp
  87. 11 17
      src/map/script.hpp
  88. 3 3
      src/map/script_constants.hpp
  89. 6 4
      src/map/searchstore.cpp
  90. 7 10
      src/map/searchstore.hpp
  91. 32 38
      src/map/skill.cpp
  92. 11 13
      src/map/skill.hpp
  93. 118 131
      src/map/status.cpp
  94. 8 50
      src/map/status.hpp
  95. 17 13
      src/map/storage.cpp
  96. 4 12
      src/map/storage.hpp
  97. 16 10
      src/map/trade.cpp
  98. 3 12
      src/map/trade.hpp
  99. 29 22
      src/map/unit.cpp
  100. 14 21
      src/map/unit.hpp

+ 8 - 3
3rdparty/libconfig/grammar.h

@@ -1,4 +1,4 @@
-
+#pragma once
 /* A Bison parser, made by GNU Bison 2.4.1.  */
 
 /* Skeleton interface for Bison's Yacc-like parsers in C
@@ -32,7 +32,10 @@
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
-
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+    
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
@@ -109,5 +112,7 @@ typedef union YYSTYPE
 #endif
 
 
-
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
 

+ 2 - 0
3rdparty/libconfig/libconfig.h

@@ -20,6 +20,8 @@
    ----------------------------------------------------------------------------
 */
 
+#pragma once
+
 #ifndef __libconfig_h
 #define __libconfig_h
 

+ 2 - 0
3rdparty/libconfig/parsectx.h

@@ -1,3 +1,5 @@
+#pragma once
+
 /* ----------------------------------------------------------------------------
    libconfig - A library for processing structured configuration files
    Copyright (C) 2005-2010  Mark A Lindner

+ 10 - 0
3rdparty/libconfig/scanctx.h

@@ -1,3 +1,5 @@
+#pragma once
+
 /* ----------------------------------------------------------------------------
    libconfig - A library for processing structured configuration files
    Copyright (C) 2005-2010  Mark A Lindner
@@ -31,6 +33,10 @@
 
 #define MAX_INCLUDE_DEPTH 10
 
+#ifdef	__cplusplus
+extern "C" {
+#endif
+    
 struct scan_context
 {
   config_t *config;
@@ -59,4 +65,8 @@ extern char *scanctx_take_string(struct scan_context *ctx);
 
 extern const char *scanctx_current_filename(struct scan_context *ctx);
 
+#ifdef	__cplusplus
+}
+#endif
+    
 #endif /* __libconfig_scanctx_h */

+ 2 - 0
3rdparty/libconfig/scanner.h

@@ -1,3 +1,5 @@
+#pragma once
+
 #ifndef libconfig_yyHEADER_H
 #define libconfig_yyHEADER_H 1
 #define libconfig_yyIN_HEADER 1

+ 10 - 0
3rdparty/libconfig/strbuf.h

@@ -1,3 +1,5 @@
+#pragma once
+
 /* ----------------------------------------------------------------------------
    libconfig - A library for processing structured configuration files
    Copyright (C) 2005-2010  Mark A Lindner
@@ -26,6 +28,10 @@
 #include <string.h>
 #include <sys/types.h>
 
+#ifdef	__cplusplus
+extern "C" {
+#endif
+    
 typedef struct
 {
   char *string;
@@ -37,4 +43,8 @@ char *strbuf_release(strbuf_t *buf);
 
 void strbuf_append(strbuf_t *buf, const char *text);
 
+#ifdef	__cplusplus
+}
+#endif
+    
 #endif /* __libconfig_strbuf_h */

+ 2 - 0
3rdparty/libconfig/wincompat.h

@@ -1,3 +1,5 @@
+#pragma once
+
 /* ----------------------------------------------------------------------------
    libconfig - A library for processing structured configuration files
    Copyright (C) 2005-2010  Mark A Lindner

+ 10 - 0
3rdparty/mt19937ar/mt19937ar.h

@@ -1,3 +1,5 @@
+#pragma once
+
 /* 
    A C-program for MT19937, with initialization improved 2002/1/26.
    Coded by Takuji Nishimura and Makoto Matsumoto.
@@ -43,6 +45,10 @@
    email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
 */
 
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
 /* initializes mt[N] with a seed */
 void init_genrand(unsigned long s);
 
@@ -70,3 +76,7 @@ double genrand_real3(void);
 
 /* generates a random number on [0,1) with 53-bit resolution*/
 double genrand_res53(void);
+
+#ifdef	__cplusplus
+}
+#endif

+ 2 - 1
src/common/cbasetypes.h

@@ -288,7 +288,8 @@ typedef char bool;
 //#define SWAP(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b)))
 // Avoid "value computed is not used" warning and generates the same assembly code
 #define SWAP(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
-#define swap_ptr(a,b) if ((a) != (b)) ((a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)))
+#define swap_ptrcast(c,a,b) if ((a) != (b)) ((a) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))), (b) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))), (a) = static_cast<c>((void*)((intptr_t)(a) ^ (intptr_t)(b))) )
+#define swap_ptr(a,b) swap_ptrcast(void*,a,b)
 
 //////////////////////////////////////////////////////////////////////////
 // should not happen

+ 8 - 0
src/common/conf.h

@@ -4,10 +4,18 @@
 #ifndef _CONF_H_
 #define _CONF_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "cbasetypes.h"
 #include "../../3rdparty/libconfig/libconfig.h"
 
 int conf_read_file(config_t *config, const char *config_filename);
 int config_setting_copy(config_setting_t *parent, const config_setting_t *src);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif // _CONF_H_

+ 12 - 12
src/common/db.h

@@ -42,13 +42,13 @@
 #ifndef _DB_H_
 #define _DB_H_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <stdarg.h>
 
 #include "cbasetypes.h"
 
-#include <stdarg.h>
+#ifdef	__cplusplus
+extern "C" {
+#endif
 
 /*****************************************************************************\
  *  (1) Section with public typedefs, enums, unions, structures and defines. *
@@ -1133,12 +1133,12 @@ void  linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
 ///
 /// @param __vec Vector
 /// @param __n Size
-#define VECTOR_RESIZE(__vec,__n) \
+#define VECTOR_RESIZE(__vec,__n,__cast) \
 	do{ \
 		if( (__n) > VECTOR_CAPACITY(__vec) ) \
 		{ /* increase size */ \
-			if( VECTOR_CAPACITY(__vec) == 0 ) VECTOR_DATA(__vec) = aMalloc((__n)*sizeof(VECTOR_FIRST(__vec))); /* allocate new */ \
-			else VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \
+			if( VECTOR_CAPACITY(__vec) == 0 ) VECTOR_DATA(__vec) = (__cast)(aMalloc((__n)*sizeof(VECTOR_FIRST(__vec))) ); /* allocate new */ \
+			else VECTOR_DATA(__vec) = (__cast)(aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))) ); /* reallocate */ \
 			memset(VECTOR_DATA(__vec)+VECTOR_LENGTH(__vec), 0, (VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec))*sizeof(VECTOR_FIRST(__vec))); /* clear new data */ \
 			VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \
 		} \
@@ -1150,7 +1150,7 @@ void  linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
 		} \
 		else if( (__n) < VECTOR_CAPACITY(__vec) ) \
 		{ /* reduce size */ \
-			VECTOR_DATA(__vec) = aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))); /* reallocate */ \
+			VECTOR_DATA(__vec) = (__cast)(aRealloc(VECTOR_DATA(__vec),(__n)*sizeof(VECTOR_FIRST(__vec))) ); /* reallocate */ \
 			VECTOR_CAPACITY(__vec) = (__n); /* update capacity */ \
 			if( VECTOR_LENGTH(__vec) > (__n) ) VECTOR_LENGTH(__vec) = (__n); /* update length */ \
 		} \
@@ -1164,15 +1164,15 @@ void  linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
 /// @param __vec Vector
 /// @param __n Empty positions
 /// @param __step Increase
-#define VECTOR_ENSURE(__vec,__n,__step) \
+#define VECTOR_ENSURE2(__vec,__n,__step,__cast) \
 	do{ \
 		size_t _empty_ = VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec); \
 		if( (__n) > _empty_ ) { \
 			while( (__n) > _empty_ ) _empty_ += (__step); \
-			VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \
+			VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec),__cast); \
 		} \
 	}while(0)
-
+#define VECTOR_ENSURE(__vec,__n,__step) VECTOR_ENSURE2(__vec,__n,__step,int*)
 
 
 /// Inserts a zeroed value in the target index.
@@ -1428,7 +1428,7 @@ void  linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
 /// @param __n Empty positions
 /// @param __step Increase
 #define BHEAP_ENSURE(__heap,__n,__step) VECTOR_ENSURE(__heap,__n,__step)
-
+#define BHEAP_ENSURE2(__heap,__n,__step,__cast) VECTOR_ENSURE2(__heap,__n,__step,__cast)
 
 
 /// Returns the top value of the heap.

+ 38 - 1
src/common/mmo.h

@@ -165,6 +165,43 @@ enum item_types {
 	IT_MAX
 };
 
+/// Monster mode definitions to clear up code reading. [Skotlex]
+enum e_mode {
+	MD_NONE					= 0x0000000,
+	MD_CANMOVE				= 0x0000001,
+	MD_LOOTER				= 0x0000002,
+	MD_AGGRESSIVE			= 0x0000004,
+	MD_ASSIST				= 0x0000008,
+	MD_CASTSENSOR_IDLE		= 0x0000010,
+	MD_NORANDOM_WALK		= 0x0000020,
+	MD_NOCAST_SKILL			= 0x0000040,
+	MD_CANATTACK			= 0x0000080,
+	//FREE					= 0x0000100,
+	MD_CASTSENSOR_CHASE		= 0x0000200,
+	MD_CHANGECHASE			= 0x0000400,
+	MD_ANGRY				= 0x0000800,
+	MD_CHANGETARGET_MELEE	= 0x0001000,
+	MD_CHANGETARGET_CHASE	= 0x0002000,
+	MD_TARGETWEAK			= 0x0004000,
+	MD_RANDOMTARGET			= 0x0008000,
+	MD_IGNOREMELEE			= 0x0010000,
+	MD_IGNOREMAGIC			= 0x0020000,
+	MD_IGNORERANGED			= 0x0040000,
+	MD_MVP					= 0x0080000,
+	MD_IGNOREMISC			= 0x0100000,
+	MD_KNOCKBACK_IMMUNE		= 0x0200000,
+	MD_TELEPORT_BLOCK		= 0x0400000,
+	//FREE					= 0x0800000,
+	MD_FIXED_ITEMDROP		= 0x1000000,
+	MD_DETECTOR				= 0x2000000,
+	MD_STATUS_IMMUNE		= 0x4000000,
+	MD_SKILL_IMMUNE			= 0x8000000,
+};
+
+#define MD_MASK 0x000FFFF
+#define ATR_MASK 0x0FF0000
+#define CL_MASK 0xF000000
+
 // Questlog states
 enum quest_state {
 	Q_INACTIVE, ///< Inactive quest (the user can toggle between active and inactive quests)
@@ -405,7 +442,7 @@ struct s_elemental {
 	int elemental_id;
 	uint32 char_id;
 	short class_;
-	int mode;
+	enum e_mode mode;
 	int hp, sp, max_hp, max_sp, matk, atk, atk2;
 	short hit, flee, amotion, def, mdef;
 	int life_time;

+ 2 - 86
src/map/CMakeLists.txt

@@ -9,92 +9,8 @@ set( MAP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}  CACHE INTERNAL "" )
 #
 if( BUILD_SERVERS )
 message( STATUS "Creating target map-server" )
-set( MAP_HEADERS
-	"${MAP_SOURCE_DIR}/achievement.h"
-	"${MAP_SOURCE_DIR}/atcommand.h"
-	"${MAP_SOURCE_DIR}/battle.h"
-	"${MAP_SOURCE_DIR}/battleground.h"
-	"${MAP_SOURCE_DIR}/buyingstore.h"
-	"${MAP_SOURCE_DIR}/chat.h"
-	"${MAP_SOURCE_DIR}/chrif.h"
-	"${MAP_SOURCE_DIR}/clan.h"
-	"${MAP_SOURCE_DIR}/clif.h"
-	"${MAP_SOURCE_DIR}/date.h"
-	"${MAP_SOURCE_DIR}/duel.h"
-	"${MAP_SOURCE_DIR}/elemental.h"
-	"${MAP_SOURCE_DIR}/guild.h"
-	"${MAP_SOURCE_DIR}/homunculus.h"
-	"${MAP_SOURCE_DIR}/instance.h"
-	"${MAP_SOURCE_DIR}/intif.h"
-	"${MAP_SOURCE_DIR}/itemdb.h"
-	"${MAP_SOURCE_DIR}/log.h"
-	"${MAP_SOURCE_DIR}/mail.h"
-	"${MAP_SOURCE_DIR}/map.h"
-	"${MAP_SOURCE_DIR}/mapreg.h"
-	"${MAP_SOURCE_DIR}/mercenary.h"
-	"${MAP_SOURCE_DIR}/mob.h"
-	"${MAP_SOURCE_DIR}/npc.h"
-	"${MAP_SOURCE_DIR}/party.h"
-	"${MAP_SOURCE_DIR}/path.h"
-	"${MAP_SOURCE_DIR}/pc.h"
-	"${MAP_SOURCE_DIR}/pc_groups.h"
-	"${MAP_SOURCE_DIR}/pet.h"
-	"${MAP_SOURCE_DIR}/quest.h"
-	"${MAP_SOURCE_DIR}/script.h"
-	"${MAP_SOURCE_DIR}/script_constants.h"
-	"${MAP_SOURCE_DIR}/searchstore.h"
-	"${MAP_SOURCE_DIR}/skill.h"
-	"${MAP_SOURCE_DIR}/status.h"
-	"${MAP_SOURCE_DIR}/storage.h"
-	"${MAP_SOURCE_DIR}/trade.h"
-	"${MAP_SOURCE_DIR}/unit.h"
-	"${MAP_SOURCE_DIR}/vending.h"
-	"${MAP_SOURCE_DIR}/cashshop.h"
-	"${MAP_SOURCE_DIR}/channel.h"
-	)
-set( MAP_SOURCES
-	"${MAP_SOURCE_DIR}/achievement.c"
-	"${MAP_SOURCE_DIR}/atcommand.c"
-	"${MAP_SOURCE_DIR}/battle.c"
-	"${MAP_SOURCE_DIR}/battleground.c"
-	"${MAP_SOURCE_DIR}/buyingstore.c"
-	"${MAP_SOURCE_DIR}/chat.c"
-	"${MAP_SOURCE_DIR}/chrif.c"
-	"${MAP_SOURCE_DIR}/clan.c"
-	"${MAP_SOURCE_DIR}/clif.cpp"
-	"${MAP_SOURCE_DIR}/date.c"
-	"${MAP_SOURCE_DIR}/duel.c"
-	"${MAP_SOURCE_DIR}/elemental.c"
-	"${MAP_SOURCE_DIR}/guild.c"
-	"${MAP_SOURCE_DIR}/homunculus.c"
-	"${MAP_SOURCE_DIR}/instance.c"
-	"${MAP_SOURCE_DIR}/intif.c"
-	"${MAP_SOURCE_DIR}/itemdb.c"
-	"${MAP_SOURCE_DIR}/log.c"
-	"${MAP_SOURCE_DIR}/mail.c"
-	"${MAP_SOURCE_DIR}/map.cpp"
-	"${MAP_SOURCE_DIR}/mapreg.c"
-	"${MAP_SOURCE_DIR}/mercenary.c"
-	"${MAP_SOURCE_DIR}/mob.cpp"
-	"${MAP_SOURCE_DIR}/npc.c"
-	"${MAP_SOURCE_DIR}/npc_chat.c"
-	"${MAP_SOURCE_DIR}/party.c"
-	"${MAP_SOURCE_DIR}/path.c"
-	"${MAP_SOURCE_DIR}/pc.c"
-	"${MAP_SOURCE_DIR}/pc_groups.c"
-	"${MAP_SOURCE_DIR}/pet.c"
-	"${MAP_SOURCE_DIR}/quest.c"
-	"${MAP_SOURCE_DIR}/script.cpp"
-	"${MAP_SOURCE_DIR}/searchstore.c"
-	"${MAP_SOURCE_DIR}/skill.cpp"
-	"${MAP_SOURCE_DIR}/status.c"
-	"${MAP_SOURCE_DIR}/storage.c"
-	"${MAP_SOURCE_DIR}/trade.c"
-	"${MAP_SOURCE_DIR}/unit.c"
-	"${MAP_SOURCE_DIR}/vending.c"
-	"${MAP_SOURCE_DIR}/cashshop.c"
-	"${MAP_SOURCE_DIR}/channel.c"
-	)
+file(GLOB MAP_HEADERS ${MAP_SOURCE_DIR}/*.hpp)
+file(GLOB MAP_SOURCES ${MAP_SOURCE_DIR}/*.cpp)
 set( DEPENDENCIES common yaml-cpp)
 set( LIBRARIES ${GLOBAL_LIBRARIES} yaml-cpp)
 set( INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS} ${COMMON_BASE_INCLUDE_DIRS} )

+ 3 - 2
src/map/Makefile.in

@@ -17,9 +17,10 @@ YAML_CPP_AR = ../../3rdparty/yaml-cpp/obj/yaml-cpp.a
 YAML_CPP_H = $(shell find ../../3rdparty/yaml-cpp/ -type f -name "*.h")
 YAML_CPP_INCLUDE = -I../../3rdparty/yaml-cpp/include
 
-MAP_OBJ = $(shell ls *.c | sed -e "s/\.c/\.o/g") $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
+MAP_OBJ = $(shell ls *.cpp | sed -e "s/\.cpp/\.o/g")
+#MAP_OBJ += $(shell ls *.c | sed -e "s/\.c/\.o/g")
 MAP_DIR_OBJ = $(MAP_OBJ:%=obj/%)
-MAP_H = $(shell ls ../map/*.h) \
+MAP_H = $(shell ls ../map/*.hpp) \
 	$(shell ls ../config/*.h) 
 
 HAVE_MYSQL=@HAVE_MYSQL@

+ 19 - 16
src/map/achievement.c → src/map/achievement.cpp

@@ -1,6 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "achievement.hpp"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <setjmp.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/nullpo.h"
@@ -9,20 +16,16 @@
 #include "../common/utils.h"
 #include "../common/yamlwrapper.h"
 
-#include "achievement.h"
-#include "chrif.h"
-#include "clif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "map.h"
-#include "pc.h"
-#include "script.h"
-#include "status.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <setjmp.h>
+#include "battle.hpp"
+#include "chrif.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "itemdb.hpp"
+#include "map.hpp"
+#include "pc.hpp"
+#include "script.hpp"
+#include "status.hpp"
+#include "npc.hpp"
 
 static jmp_buf     av_error_jump;
 static char*       av_error_msg;
@@ -1120,7 +1123,7 @@ void achievement_read_db(void)
 	int i = 0;
 	const char *dbsubpath[] = {
 		"",
-		"/"DBIMPORT"/",
+		"/" DBIMPORT "/",
 		//add other path here
 	};
 
@@ -1169,7 +1172,7 @@ void achievement_read_db(void)
 		yaml_destroy_wrapper(adb_sub);
 		yaml_iterator_destroy(it);
 
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filepath);
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, filepath);
 	}
 
 	return;

+ 3 - 11
src/map/achievement.h → src/map/achievement.hpp

@@ -1,12 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef MAP_ACHIEVEMENTS_H
-#define MAP_ACHIEVEMENTS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef ACHIEVEMENT_HPP_
+#define ACHIEVEMENT_HPP_
 
 #include "../common/mmo.h"
 #include "../common/db.h"
@@ -126,8 +122,4 @@ const char *av_parse_simpleexpr(const char *p, struct av_condition *parent);
 long long achievement_check_condition(struct av_condition *condition, struct map_session_data *sd, int *count);
 void achievement_script_free(struct av_condition *condition);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* MAP_ACHIEVEMENTS_H */
+#endif /* ACHIEVEMENT_HPP_ */

+ 41 - 33
src/map/atcommand.c → src/map/atcommand.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "atcommand.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/mmo.h"
 #include "../common/timer.h"
@@ -13,32 +18,35 @@
 #include "../common/utils.h"
 #include "../common/conf.h"
 
-#include "map.h"
-#include "atcommand.h"
-#include "battle.h"
-#include "chat.h"
-#include "channel.h"
-#include "chrif.h"
-#include "duel.h"
-#include "instance.h"
-#include "intif.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "mail.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "party.h"
-#include "script.h"
-#include "storage.h"
-#include "trade.h"
-#include "mapreg.h"
-#include "quest.h"
-#include "pc.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-#include <math.h>
-
+#include "map.hpp"
+#include "battle.hpp"
+#include "chat.hpp"
+#include "channel.hpp"
+#include "chrif.hpp"
+#include "duel.hpp"
+#include "instance.hpp"
+#include "intif.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "mail.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "party.hpp"
+#include "script.hpp"
+#include "storage.hpp"
+#include "trade.hpp"
+#include "mapreg.hpp"
+#include "quest.hpp"
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "npc.hpp"
+#include "guild.hpp"
+#include "clif.hpp"
+#include "log.hpp"
+#include "itemdb.hpp" // MAX_ITEMGROUP
+#include "mob.hpp"
+#include "achievement.hpp"
+#include "clan.hpp"
 
 #define ATCOMMAND_LENGTH 50
 #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
@@ -1529,7 +1537,7 @@ ACMD_FUNC(help)
 	config_setting_t *help;
 	const char *text = NULL;
 	const char *command_name = NULL;
-	char *default_command = "help";
+	const char *default_command = "help";
 
 	nullpo_retr(-1, sd);
 
@@ -6240,7 +6248,7 @@ ACMD_FUNC(autolootitem)
 ACMD_FUNC(autoloottype)
 {
 	uint8 action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
-	enum item_types type = -1;
+	enum item_types type= IT_UNKNOWN;
 	int ITEM_MAX = 1533;
 
 	nullpo_retr(-1, sd);
@@ -6317,7 +6325,7 @@ ACMD_FUNC(autoloottype)
 				clif_displaymessage(fd, msg_txt(sd,1490)); // Item types on your autoloottype list:
 				while (i < IT_MAX) {
 					if (sd->state.autoloottype&(1<<i)) {
-						sprintf(atcmd_output, "  '%s' {%d}", itemdb_typename(i), i);
+						sprintf(atcmd_output, "  '%s' {%d}", itemdb_typename(static_cast<item_types>(i)), i);
 						clif_displaymessage(fd, atcmd_output);
 					}
 					i++;
@@ -8554,7 +8562,7 @@ ACMD_FUNC(clone)
 		y = sd->bl.y;
 	}
 
-	if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
+	if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, MD_NONE, flag?1:0, 0)) > 0) {
 		clif_displaymessage(fd, msg_txt(sd,128+flag*2));	// Evil Clone spawned. Clone spawned. Slave clone spawned.
 		return 0;
 	}
@@ -10649,7 +10657,7 @@ static void atcommand_config_read(const char* config_filename)
 		}
 	}
 
-	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename);
+	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' command aliases in '" CL_WHITE "%s" CL_RESET "'.\n", num_aliases, config_filename);
 	return;
 }
 void atcommand_db_load_groups(int* group_ids) {
@@ -10699,8 +10707,8 @@ void atcommand_db_clear(void) {
 
 void atcommand_doload(void) {
 	atcommand_db_clear();
-	atcommand_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
-	atcommand_alias_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
+	atcommand_db = stridb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), ATCOMMAND_LENGTH);
+	atcommand_alias_db = stridb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), ATCOMMAND_LENGTH);
 	atcommand_basecommands(); //fills initial atcommand_db with known commands
 	atcommand_config_read(ATCOMMAND_CONF_FILENAME);
 }

+ 6 - 14
src/map/atcommand.h → src/map/atcommand.hpp

@@ -1,13 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _ATCOMMAND_H_
-#define _ATCOMMAND_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _ATCOMMAND_HPP_
+#define _ATCOMMAND_HPP_
 
+#include "../common/cbasetypes.h"
 #include "../common/mmo.h"
 
 struct map_session_data;
@@ -23,10 +20,10 @@ extern char atcommand_symbol;
 extern char charcommand_symbol;
 extern int atcmd_binding_count;
 
-typedef enum {
+enum AtCommandType : uint8 {
 	COMMAND_ATCOMMAND = 1,
 	COMMAND_CHARCOMMAND = 2,
-} AtCommandType;
+} ;
 
 typedef int (*AtCommandFunc)(const int fd, struct map_session_data* sd, const char* command, const char* message);
 
@@ -47,9 +44,4 @@ struct atcmd_binding_data {
 };
 extern struct atcmd_binding_data** atcmd_binding;
 struct atcmd_binding_data* get_atcommandbind_byname(const char* name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ATCOMMAND_H_ */
+#endif /* _ATCOMMAND_HPP_ */

+ 31 - 32
src/map/battle.c → src/map/battle.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "battle.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -12,19 +17,21 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 
-#include "map.h"
-#include "path.h"
-#include "pc.h"
-#include "homunculus.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "pet.h"
-#include "party.h"
-#include "battleground.h"
-#include "chrif.h"
-
-#include <stdlib.h>
-#include <math.h>
+#include "map.hpp"
+#include "path.hpp"
+#include "pc.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "pet.hpp"
+#include "party.hpp"
+#include "battleground.hpp"
+#include "chrif.hpp"
+#include "guild.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "log.hpp"
+#include "pc_groups.hpp"
 
 int attr_fix_table[4][ELE_MAX][ELE_MAX];
 
@@ -1319,7 +1326,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
 		if (sc->data[SC_SU_STOOP])
 			damage -= damage * 90 / 100;
 
-		// Compressed code, fixed by map.h [Epoque]
+		// Compressed code, fixed by map.hpp [Epoque]
 		if (src->type == BL_MOB) {
 			if( sc->data[SC_MANU_DEF] && status_get_race2(src) == RC2_MANUK ){
 				damage -= damage * sc->data[SC_MANU_DEF]->val1 / 100;
@@ -2446,7 +2453,7 @@ static bool battle_skill_get_damage_properties(uint16 skill_id, int is_splash)
 	int nk = skill_get_nk(skill_id);
 	if( !skill_id && is_splash ) //If flag, this is splash damage from Baphomet Card and it always hits.
 		nk |= NK_NO_CARDFIX_ATK|NK_IGNORE_FLEE;
-	return nk;
+	return nk > 0;
 }
 
 /*=============================
@@ -2660,7 +2667,7 @@ static bool attack_ignores_def(struct Damage wd, struct block_list *src, struct
 		}
 	}
 
-	return (nk&NK_IGNORE_DEF);
+	return (nk&NK_IGNORE_DEF) > 0;
 }
 
 /*================================================
@@ -6673,11 +6680,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
 		}
 	}
 
-	switch(skill_id) {
-		default:
-			md.damage += battle_calc_cardfix(BF_MISC, src, target, nk, s_ele, 0, md.damage, 0, md.flag);
-			break;
-	}
+	md.damage += battle_calc_cardfix(BF_MISC, src, target, nk, s_ele, 0, md.damage, 0, md.flag);
 
 	if (sd && (i = pc_skillatk_bonus(sd, skill_id)))
 		md.damage += (int64)md.damage*i/100;
@@ -6719,15 +6722,11 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
 			break;
 	}
 
-	switch(skill_id) {
-		default:
-			md.damage = battle_calc_damage(src,target,&md,md.damage,skill_id,skill_lv);
-			if(map_flag_gvg2(target->m))
-				md.damage = battle_calc_gvg_damage(src,target,md.damage,skill_id,md.flag);
-			else if(map[target->m].flag.battleground)
-				md.damage = battle_calc_bg_damage(src,target,md.damage,skill_id,md.flag);
-			break;
-	}
+	md.damage = battle_calc_damage(src,target,&md,md.damage,skill_id,skill_lv);
+	if(map_flag_gvg2(target->m))
+		md.damage = battle_calc_gvg_damage(src,target,md.damage,skill_id,md.flag);
+	else if(map[target->m].flag.battleground)
+		md.damage = battle_calc_bg_damage(src,target,md.damage,skill_id,md.flag);
 
 	// Skill damage adjustment
 #ifdef ADJUST_SKILL_DAMAGE
@@ -7556,7 +7555,7 @@ struct block_list* battle_get_master(struct block_list *src)
  * (enemy, friend, party, guild, etc)
  *------------------------------------------
  * Usage:
- * See battle.h for possible values/combinations
+ * See battle.hpp for possible values/combinations
  * to be used here (BCT_* constants)
  * Return value is:
  * 1: flag holds true (is enemy, party, etc)
@@ -8626,7 +8625,7 @@ int battle_config_read(const char* cfgName)
  *--------------------------*/
 void do_init_battle(void)
 {
-	delay_damage_ers = ers_new(sizeof(struct delay_damage),"battle.c::delay_damage_ers",ERS_OPT_CLEAR);
+	delay_damage_ers = ers_new(sizeof(struct delay_damage),"battle.cpp::delay_damage_ers",ERS_OPT_CLEAR);
 	add_timer_func_list(battle_delay_damage_sub, "battle_delay_damage_sub");
 }
 

+ 22 - 23
src/map/battle.h → src/map/battle.hpp

@@ -1,30 +1,35 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _BATTLE_H_
-#define _BATTLE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _BATTLE_HPP_
+#define _BATTLE_HPP_
 
+#include "../common/cbasetypes.h"
 #include "../common/mmo.h"
+
 #include "../config/core.h"
-#include "clif.h" // e_damage_type
-#include "map.h" //ELE_MAX
+
+#include "map.hpp" //ELE_MAX
+
+//fwd declaration
+struct map_session_data;
+struct mob_data;
+struct block_list;
+enum e_damage_type : uint8;
+
 
 /// State of a single attack attempt; used in flee/def penalty calculations when mobbed
-typedef enum damage_lv {
+enum damage_lv : uint8 {
 	ATK_NONE,    /// Not an attack
 	ATK_LUCKY,   /// Attack was lucky-dodged
 	ATK_FLEE,    /// Attack was dodged
 	ATK_MISS,    /// Attack missed because of element/race modifier.
 	ATK_BLOCK,   /// Attack was blocked by some skills.
 	ATK_DEF      /// Attack connected
-} damage_lv;
+};
 
 /// Flag of the final calculation
-enum e_battle_flag {
+enum e_battle_flag : uint16 {
 	BF_WEAPON	= 0x0001, /// Weapon attack
 	BF_MAGIC	= 0x0002, /// Magic attack
 	BF_MISC		= 0x0004, /// Misc attack
@@ -41,7 +46,7 @@ enum e_battle_flag {
 };
 
 /// Battle check target [Skotlex]
-enum e_battle_check_target {
+enum e_battle_check_target : uint32 {
 	BCT_NOONE		= 0x000000, ///< No one
 	BCT_SELF		= 0x010000, ///< Self
 	BCT_ENEMY		= 0x020000, ///< Enemy
@@ -80,10 +85,6 @@ struct Damage {
 //(Used in read pc.c,) attribute table (battle_attr_fix)
 extern int attr_fix_table[4][ELE_MAX][ELE_MAX];
 
-struct map_session_data;
-struct mob_data;
-struct block_list;
-
 // Damage Calculation
 
 struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct block_list *target,uint16 skill_id,uint16 skill_lv,int flag);
@@ -137,7 +138,7 @@ bool is_infinite_defense(struct block_list *target, int flag);
 #define MIN_BODY_STYLE battle_config.min_body_style
 #define MAX_BODY_STYLE battle_config.max_body_style
 
-extern struct Battle_Config
+struct Battle_Config
 {
 	int warp_point_debug;
 	int enable_critical;
@@ -636,7 +637,9 @@ extern struct Battle_Config
 	int event_refine_chance;
 
 #include "../custom/battle_config_struct.inc"
-} battle_config;
+};
+
+extern struct Battle_Config battle_config;
 
 void do_init_battle(void);
 void do_final_battle(void);
@@ -652,8 +655,4 @@ struct block_list* battle_getenemyarea(struct block_list *src, int x, int y, int
  **/
 int battle_damage_area( struct block_list *bl, va_list ap);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _BATTLE_H_ */
+#endif /* _BATTLE_HPP_ */

+ 11 - 8
src/map/battleground.c → src/map/battleground.cpp

@@ -1,6 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "battleground.hpp"
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/malloc.h"
@@ -8,14 +10,15 @@
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
 
-#include "battleground.h"
-#include "battle.h"
-#include "clif.h"
-#include "npc.h"
-#include "pc.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "mercenary.h"
+#include "battle.hpp"
+#include "clif.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "guild.hpp"
+#include "mob.hpp"
 
 static DBMap* bg_team_db; // int bg_id -> struct battleground_data*
 static unsigned int bg_team_counter = 0; // Next bg_id

+ 4 - 12
src/map/battleground.h → src/map/battleground.hpp

@@ -1,15 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _BATTLEGROUND_H_
-#define _BATTLEGROUND_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _BATTLEGROUND_HPP_
+#define _BATTLEGROUND_HPP_
 
+#include "../common/cbasetypes.h"
 #include "../common/mmo.h" // struct party
-#include "guild.h"
 
 #define MAX_BG_MEMBERS 30
 
@@ -46,8 +42,4 @@ int bg_team_warp(int bg_id, unsigned short mapindex, short x, short y);
 int bg_member_respawn(struct map_session_data *sd);
 int bg_send_message(struct map_session_data *sd, const char *mes, int len);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _BATTLEGROUND_H_ */
+#endif /* _BATTLEGROUND_HPP_ */

+ 15 - 11
src/map/buyingstore.c → src/map/buyingstore.cpp

@@ -1,21 +1,25 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "buyingstore.hpp"  // struct s_buyingstore
+
+#include <stdlib.h> // atoi
+
 #include "../common/nullpo.h"
 #include "../common/db.h"  // ARR_FIND
 #include "../common/malloc.h" // aMalloc, aFree
 #include "../common/showmsg.h"  // ShowWarning
 #include "../common/socket.h"  // RBUF*
 #include "../common/strlib.h"  // safestrncpy
-#include "atcommand.h"  // msg_txt
-#include "battle.h"  // battle_config.*
-#include "buyingstore.h"  // struct s_buyingstore
-#include "clif.h"  // clif_buyingstore_*
-#include "log.h"  // log_pick_pc, log_zeny
-#include "pc.h"  // struct map_session_data
-#include "chrif.h"
+#include "../common/timer.h"  // gettick
 
-#include <stdlib.h> // atoi
+#include "atcommand.hpp"  // msg_txt
+#include "battle.hpp"  // battle_config.*
+#include "clif.hpp"  // clif_buyingstore_*
+#include "log.hpp"  // log_pick_pc, log_zeny
+#include "pc.hpp"  // struct map_session_data
+#include "chrif.hpp"
+#include "npc.hpp"
 
 //Autotrader
 static DBMap *buyingstore_autotrader_db; /// Holds autotrader info: char_id -> struct s_autotrader
@@ -628,7 +632,7 @@ void buyingstore_reopen( struct map_session_data* sd ){
 			// Immediate save
 			chrif_save(sd, CSAVE_AUTOTRADE);
 
-			ShowInfo("Buyingstore loaded for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n",
+			ShowInfo("Buyingstore loaded for '" CL_WHITE "%s" CL_RESET "' with '" CL_WHITE "%d" CL_RESET "' items at " CL_WHITE "%s (%d,%d)" CL_RESET "\n",
 				sd->status.name, count, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y);
 		}
 		aFree(data);
@@ -641,7 +645,7 @@ void buyingstore_reopen( struct map_session_data* sd ){
 	}
 
 	if (fail != 0) {
-		ShowError("buyingstore_reopen: (Error:%d) Load failed for autotrader '"CL_WHITE"%s"CL_RESET"' (CID=%/AID=%d)\n", fail, sd->status.name, sd->status.char_id, sd->status.account_id);
+		ShowError("buyingstore_reopen: (Error:%d) Load failed for autotrader '" CL_WHITE "%s" CL_RESET "' (CID=%/AID=%d)\n", fail, sd->status.name, sd->status.char_id, sd->status.account_id);
 		map_quit(sd);
 	}
 }
@@ -742,7 +746,7 @@ void do_init_buyingstore_autotrade( void ) {
 			}
 			dbi_destroy(iter);
 
-			ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' buyingstore autotraders with '"CL_WHITE"%d"CL_RESET"' items.\n", db_size(buyingstore_autotrader_db), items);
+			ShowStatus("Done loading '" CL_WHITE "%d" CL_RESET "' buyingstore autotraders with '" CL_WHITE "%d" CL_RESET "' items.\n", db_size(buyingstore_autotrader_db), items);
 		}
 	}
 

+ 7 - 10
src/map/buyingstore.h → src/map/buyingstore.hpp

@@ -1,14 +1,15 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _BUYINGSTORE_H_
-#define _BUYINGSTORE_H_
+#ifndef _BUYINGSTORE_HPP_
+#define _BUYINGSTORE_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+
+#include "map.hpp" //MESSAGE_SIZE
 
 struct s_search_store_search;
+struct map_session_data;
 
 #define MAX_BUYINGSTORE_SLOTS 5
 
@@ -68,8 +69,4 @@ void do_init_buyingstore(void);
 void do_init_buyingstore_autotrade( void );
 void buyingstore_reopen( struct map_session_data* sd );
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif  // _BUYINGSTORE_H_
+#endif  // _BUYINGSTORE_HPP_

+ 18 - 11
src/map/cashshop.c → src/map/cashshop.cpp

@@ -1,15 +1,19 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "cashshop.hpp"
+
+#include <string.h> // memset
+#include <stdlib.h> // atoi
+
 #include "../common/cbasetypes.h" // uint16, uint32
 #include "../common/malloc.h" // CREATE, RECREATE, aFree
 #include "../common/showmsg.h" // ShowWarning, ShowStatus
 
-#include "cashshop.h"
-#include "pet.h" // pet_create_egg
-
-#include <string.h> // memset
-#include <stdlib.h> // atoi
+#include "pc.hpp" // s_map_session_data
+#include "pet.hpp" // pet_create_egg
+#include "clif.hpp"
+#include "log.hpp"
 
 struct cash_item_db cash_shop_items[CASHSHOP_TAB_MAX];
 #if PACKETVER_SUPPORTS_SALES
@@ -71,7 +75,7 @@ static bool cashshop_parse_dbrow(char* fields[], int columns, int current) {
 static void cashshop_read_db_txt( void ){
 	const char* dbsubpath[] = {
 		"",
-		"/"DBIMPORT,
+		"/" DBIMPORT,
 	};
 	int fi;
 
@@ -90,7 +94,7 @@ static void cashshop_read_db_txt( void ){
 			safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[fi]);
 		}
 
-		sv_readdb(dbsubpath2, "item_cash_db.txt",          ',', 3, 3, -1, &cashshop_parse_dbrow, fi);
+		sv_readdb(dbsubpath2, "item_cash_db.txt", ',', 3, 3, -1, &cashshop_parse_dbrow, fi > 0);
 
 		aFree(dbsubpath1);
 		aFree(dbsubpath2);
@@ -113,8 +117,10 @@ static int cashshop_read_db_sql( void ){
 			continue;
 		}
 
+
 		while( SQL_SUCCESS == Sql_NextRow( mmysql_handle ) ){
 			char* str[3];
+			char dummy[256] = "";
 			int i;
 
 			++lines;
@@ -123,7 +129,7 @@ static int cashshop_read_db_sql( void ){
 				Sql_GetData( mmysql_handle, i, &str[i], NULL );
 
 				if( str[i] == NULL ){
-					str[i] = "";
+					str[i] = dummy;
 				}
 			}
 
@@ -137,7 +143,7 @@ static int cashshop_read_db_sql( void ){
 
 		Sql_FreeResult( mmysql_handle );
 
-		ShowStatus( "Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, cash_db_name[fi] );
+		ShowStatus( "Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, cash_db_name[fi] );
 	}
 
 	return 0;
@@ -203,6 +209,7 @@ static void sale_read_db_sql( void ){
 
 	while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ){
 		char* str[4];
+		char dummy[256] = "";
 		int i;
 
 		lines++;
@@ -211,7 +218,7 @@ static void sale_read_db_sql( void ){
 			Sql_GetData( mmysql_handle, i, &str[i], NULL );
 
 			if( str[i] == NULL ){
-				str[i] = "";
+				str[i] = dummy;
 			}
 		}
 
@@ -225,7 +232,7 @@ static void sale_read_db_sql( void ){
 
 	Sql_FreeResult(mmysql_handle);
 
-	ShowStatus( "Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, sales_table );
+	ShowStatus( "Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, sales_table );
 }
 
 static int sale_end_timer( int tid, unsigned int tick, int id, intptr_t data ){

+ 8 - 12
src/map/cashshop.h → src/map/cashshop.hpp

@@ -1,15 +1,15 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CASHSHOP_H_
-#define _CASHSHOP_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _CASHSHOP_HPP_
+#define _CASHSHOP_HPP_
 
 #include "../common/cbasetypes.h" // uint16, uint32
-#include "pc.h" // struct map_session_data
+#include "../common/timer.h" // ShowWarning, ShowStatus
+
+#include "../config/packets.h"
+
+struct map_session_data;
 
 void do_init_cashshop( void );
 void do_final_cashshop( void );
@@ -96,8 +96,4 @@ bool sale_remove_item(uint16 nameid);
 void sale_notify_login( struct map_session_data* sd );
 #endif
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CASHSHOP_H_ */
+#endif /* _CASHSHOP_HPP_ */

+ 16 - 10
src/map/channel.c → src/map/channel.cpp

@@ -1,19 +1,25 @@
 // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "channel.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/conf.h" //libconfig
 #include "../common/showmsg.h"
-#include "../common/nullpo.h"
 #include "../common/strlib.h" //safestrncpy
 #include "../common/socket.h" //set_eof
+#include "../common/timer.h"  // DIFF_TICK
+#include "../common/nullpo.h"
 
-#include "map.h" //msg_conf
-#include "clif.h" //clif_chsys_msg
-#include "channel.h"
-
-#include <stdlib.h>
+#include "map.hpp" //msg_conf
+#include "clif.hpp" //clif_chsys_msg
+#include "pc.hpp"
+#include "guild.hpp"
+#include "pc_groups.hpp"
+#include "battle.hpp"
 
 static DBMap* channel_db; // channels
 
@@ -39,7 +45,7 @@ struct Channel* channel_create(struct Channel *tmp_chan) {
 	CREATE(channel, struct Channel, 1); //will exit on fail allocation
 	//channel->id = tmp_chan->id;
 	channel->users = idb_alloc(DB_OPT_BASE);
-	channel->banned = idb_alloc(DB_OPT_BASE|DB_OPT_RELEASE_DATA);
+	channel->banned = idb_alloc(static_cast<DBOptions>(DB_OPT_BASE|DB_OPT_RELEASE_DATA) );
 	channel->opt = tmp_chan->opt;
 	channel->type = tmp_chan->type;
 	channel->color = tmp_chan->color;
@@ -563,7 +569,7 @@ int channel_pc_haschan(struct map_session_data *sd, struct Channel *channel){
  *   void: List of public channel and map and guild and number of users
  * @return 0 on success or -1 on failure
  */
-int channel_display_list(struct map_session_data *sd, char *options){
+int channel_display_list(struct map_session_data *sd, const char *options){
 
 	if(!sd || !options)
 		return -1;
@@ -1461,7 +1467,7 @@ void channel_read_config(void) {
 			}
 		}
 
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' channels in '"CL_WHITE"%s"CL_RESET"'.\n", db_size(channel_db), channel_conf);
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' channels in '" CL_WHITE "%s" CL_RESET "'.\n", db_size(channel_db), channel_conf);
 		config_destroy(&channels_conf);
 	}
 }
@@ -1470,7 +1476,7 @@ void channel_read_config(void) {
  * Initialise db and read configuration
  */
 void do_init_channel(void) {
-	channel_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, CHAN_NAME_LENGTH);
+	channel_db = stridb_alloc(static_cast<DBOptions>(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), CHAN_NAME_LENGTH);
 	memset(&channel_config.private_channel, 0, sizeof(struct Channel));
 	memset(&channel_config.ally_tmpl, 0, sizeof(struct Channel));
 	memset(&channel_config.map_tmpl, 0, sizeof(struct Channel));

+ 11 - 11
src/map/channel.h → src/map/channel.hpp

@@ -4,11 +4,14 @@
 #ifndef CHANNEL_H
 #define	CHANNEL_H
 
-#include "pc.h"
+#include "../common/cbasetypes.h"
+#include "../common/mmo.h"
 
-#ifdef	__cplusplus
-extern "C" {
-#endif
+//namespace rA {
+
+struct map_session_data;
+struct guild;
+struct DBMap;
 
 #define CHAN_NAME_LENGTH 20
 #define CHAN_MSG_LENGTH 150
@@ -52,10 +55,11 @@ struct Channel {
 	unsigned short *groups;		  ///< List of group id, only these groups can join the channel
 };
 
-extern struct chan_banentry {
+struct chan_banentry {
 	uint32 char_id;
 	char char_name[NAME_LENGTH];
-} chan_banentry;
+};
+extern chan_banentry chan_banentry;
 
 struct Channel_Config {
 	unsigned long *colors;		///< List of available colors
@@ -105,7 +109,7 @@ struct Channel* channel_name2channel(char *chname, struct map_session_data *sd,
 int channel_haspc(struct Channel *channel,struct map_session_data *sd);
 int channel_haspcbanned(struct Channel *channel,struct map_session_data *sd);
 int channel_pc_haschan(struct map_session_data *sd, struct Channel *channel);
-int channel_display_list(struct map_session_data *sd, char *option);
+int channel_display_list(struct map_session_data *sd, const char *option);
 
 void channel_autojoin(struct map_session_data *sd);
 bool channel_pccheckgroup(struct Channel *channel, int group_id);
@@ -124,8 +128,4 @@ int channel_pcsetopt(struct map_session_data *sd, char *chname, const char *opti
 void do_init_channel(void);
 void do_final_channel(void);
 
-#ifdef	__cplusplus
-}
-#endif
-
 #endif	/* CHANNEL_H */

+ 12 - 8
src/map/chat.c → src/map/chat.cpp

@@ -1,21 +1,25 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "chat.hpp"
+
+#include <cstring>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/nullpo.h"
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
 #include "../common/mmo.h"
-#include "map.h"
-#include "atcommand.h" // msg_txt()
-#include "battle.h" // struct battle_config
-#include "clif.h"
-#include "npc.h" // npc_event_do()
-#include "pc.h"
-#include "chat.h"
-#include "achievement.h"
 
+#include "map.hpp"
+#include "atcommand.hpp" // msg_txt()
+#include "battle.hpp" // struct battle_config
+#include "clif.hpp"
+#include "npc.hpp" // npc_event_do()
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "achievement.hpp"
 
 int chat_triggerevent(struct chat_data *cd); // forward declaration
 

+ 4 - 12
src/map/chat.h → src/map/chat.hpp

@@ -1,14 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CHAT_H_
-#define _CHAT_H_
+#ifndef _CHAT_HPP_
+#define _CHAT_HPP_
 
-#include "map.h" // struct block_list, CHATROOM_TITLE_SIZE
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
+#include "map.hpp" // struct block_list, CHATROOM_TITLE_SIZE
 
 struct map_session_data;
 struct chat_data;
@@ -47,8 +43,4 @@ int chat_npckickall(struct chat_data* cd);
 
 int chat_npckickchat(struct chat_data* cd, const char* kickusername);
 
-#ifdef	__cplusplus
-}
-#endif
-
-#endif /* _CHAT_H_ */
+#endif /* _CHAT_HPP_ */

+ 29 - 24
src/map/chrif.c → src/map/chrif.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "chrif.hpp"
+
+#include <cstdlib>
+#include <cstring>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/socket.h"
@@ -10,23 +15,23 @@
 #include "../common/strlib.h"
 #include "../common/ers.h"
 
-#include "map.h"
-#include "battle.h"
-#include "clan.h"
-#include "clif.h"
-#include "intif.h"
-#include "npc.h"
-#include "pc.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "chrif.h"
-#include "script.h" // script_config
-#include "storage.h"
-
-#include <stdlib.h>
+#include "map.hpp"
+#include "battle.hpp"
+#include "clan.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "instance.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "script.hpp" // script_config
+#include "storage.hpp"
+#include "guild.hpp"
+#include "log.hpp"
 
 static int check_connect_char_server(int tid, unsigned int tick, int id, intptr_t data);
 
@@ -261,7 +266,7 @@ int chrif_setip(const char* ip) {
 
 	safestrncpy(char_ip_str, ip, sizeof(char_ip_str));
 
-	ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
+	ShowInfo("Char Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(char_ip, ip_str));
 
 	return 1;
 }
@@ -510,7 +515,7 @@ int chrif_connectack(int fd) {
 		exit(EXIT_FAILURE);
 	}
 
-	ShowStatus("Successfully logged on to Char Server (Connection: '"CL_WHITE"%d"CL_RESET"').\n",fd);
+	ShowStatus("Successfully logged on to Char Server (Connection: '" CL_WHITE "%d" CL_RESET "').\n",fd);
 	chrif_state = 1;
 	chrif_connected = 1;
 
@@ -608,14 +613,14 @@ int chrif_sendmapack(int fd) {
 
 	// Server name
 	memcpy(wisp_server_name, RFIFOP(fd,5), NAME_LENGTH);
-	ShowStatus("Map-server connected to char-server '"CL_WHITE"%s"CL_RESET"'.\n", wisp_server_name);
+	ShowStatus("Map-server connected to char-server '" CL_WHITE "%s" CL_RESET "'.\n", wisp_server_name);
 
 	// Default map
 	memcpy(map_default.mapname, RFIFOP(fd, (offs+=NAME_LENGTH)), MAP_NAME_LENGTH);
 	map_default.x = RFIFOW(fd, (offs+=MAP_NAME_LENGTH));
 	map_default.y = RFIFOW(fd, (offs+=2));
 	if (battle_config.etc_log)
-		ShowInfo("Received default map from char-server '"CL_WHITE"%s %d,%d"CL_RESET"'.\n", map_default.mapname, map_default.x, map_default.y);
+		ShowInfo("Received default map from char-server '" CL_WHITE "%s %d,%d" CL_RESET "'.\n", map_default.mapname, map_default.x, map_default.y);
 
 	chrif_on_ready();
 
@@ -698,7 +703,7 @@ void chrif_authok(int fd) {
 	login_id2 = RFIFOL(fd,12);
 	expiration_time = (time_t)(int32)RFIFOL(fd,16);
 	group_id = RFIFOL(fd,20);
-	changing_mapservers = (RFIFOB(fd,24));
+	changing_mapservers = (RFIFOB(fd,24)) > 0;
 	status = (struct mmo_charstatus*)RFIFOP(fd,25);
 	char_id = status->char_id;
 
@@ -1271,7 +1276,7 @@ int chrif_recvfamelist(int fd) {
 
 	total += num;
 
-	ShowInfo("Received Fame List of '"CL_WHITE"%d"CL_RESET"' characters.\n", total);
+	ShowInfo("Received Fame List of '" CL_WHITE "%d" CL_RESET "' characters.\n", total);
 
 	return 0;
 }
@@ -2000,7 +2005,7 @@ void do_init_chrif(void) {
 	}
 
 	auth_db = idb_alloc(DB_OPT_BASE);
-	auth_db_ers = ers_new(sizeof(struct auth_node),"chrif.c::auth_db_ers",ERS_OPT_NONE);
+	auth_db_ers = ers_new(sizeof(struct auth_node),"chrif.cpp::auth_db_ers",ERS_OPT_NONE);
 
 	add_timer_func_list(check_connect_char_server, "check_connect_char_server");
 	add_timer_func_list(auth_db_cleanup, "auth_db_cleanup");

+ 7 - 11
src/map/chrif.h → src/map/chrif.hpp

@@ -1,16 +1,16 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CHRIF_H_
-#define _CHRIF_H_
+#ifndef _CHRIF_HPP_
+#define _CHRIF_HPP_
+
+#include <time.h>
 
 #include "../common/cbasetypes.h"
 #include "../common/socket.h" // enum chrif_req_op
-#include <time.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+//fwd declaration
+struct map_session_data;
 
 enum sd_state { ST_LOGIN, ST_LOGOUT, ST_MAPCHANGE };
 
@@ -92,8 +92,4 @@ void do_init_chrif(void);
 
 int chrif_flush_fifo(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CHRIF_H_ */
+#endif /* _CHRIF_HPP_ */

+ 11 - 7
src/map/clan.c → src/map/clan.cpp

@@ -1,18 +1,22 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "clan.hpp"
+
+#include <string.h> //memset
+
 #include "../common/cbasetypes.h"
 #include "../common/mmo.h"
 #include "../common/malloc.h"
 #include "../common/nullpo.h"
 #include "../common/showmsg.h"
 
-#include "clan.h"
-#include "clif.h"
-#include "intif.h"
-#include "pc.h"
-#include "script.h"
-#include "status.h"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "pc.hpp"
+#include "script.hpp"
+#include "status.hpp"
+#include "log.hpp"
 
 static DBMap* clan_db; // int clan_id -> struct clan*
 
@@ -47,7 +51,7 @@ void clan_load_clandata( int count, struct clan* clans ){
 		j++;
 	}
 
-	ShowStatus( "Received '"CL_WHITE"%d"CL_RESET"' clans from char-server.\n", j );
+	ShowStatus( "Received '" CL_WHITE "%d" CL_RESET "' clans from char-server.\n", j );
 }
 
 struct clan* clan_search( int id ){

+ 0 - 32
src/map/clan.h

@@ -1,32 +0,0 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-
-#ifndef _CLAN_H_
-	#define _CLAN_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-	#include "../common/mmo.h"
-	#include "status.h"
-
-	void do_init_clan();
-	void do_final_clan();
-	struct clan* clan_search( int id );
-	struct clan* clan_searchname( const char* name );
-	void clan_load_clandata( int count, struct clan* clans );
-	void clan_member_joined( struct map_session_data* sd );
-	void clan_member_left( struct map_session_data* sd );
-	bool clan_member_join( struct map_session_data *sd, int clan_id, uint32 account_id, uint32 char_id );
-	bool clan_member_leave( struct map_session_data* sd, int clan_id, uint32 account_id, uint32 char_id );
-	void clan_send_message( struct map_session_data *sd, const char *mes, int len );
-	void clan_recv_message(int clan_id,uint32 account_id,const char *mes,int len);
-	struct map_session_data* clan_getavailablesd( struct clan* clan );
-	int clan_get_alliance_count( struct clan *clan, int flag );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

+ 26 - 0
src/map/clan.hpp

@@ -0,0 +1,26 @@
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#ifndef _CLAN_HPP_
+#define _CLAN_HPP_
+
+#include "../common/mmo.h"
+
+struct clan;
+struct map_session_data;
+
+void do_init_clan();
+void do_final_clan();
+struct clan* clan_search( int id );
+struct clan* clan_searchname( const char* name );
+void clan_load_clandata( int count, struct clan* clans );
+void clan_member_joined( struct map_session_data* sd );
+void clan_member_left( struct map_session_data* sd );
+bool clan_member_join( struct map_session_data *sd, int clan_id, uint32 account_id, uint32 char_id );
+bool clan_member_leave( struct map_session_data* sd, int clan_id, uint32 account_id, uint32 char_id );
+void clan_send_message( struct map_session_data *sd, const char *mes, int len );
+void clan_recv_message(int clan_id,uint32 account_id,const char *mes,int len);
+struct map_session_data* clan_getavailablesd( struct clan* clan );
+int clan_get_alliance_count( struct clan *clan, int flag );
+
+#endif /* CLAN_H */

+ 45 - 48
src/map/clif.cpp

@@ -1,6 +1,14 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "clif.hpp"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cstdarg>
+#include <ctime>
+
 #include "../common/cbasetypes.h"
 #include "../common/socket.h"
 #include "../common/timer.h"
@@ -14,48 +22,40 @@
 #include "../common/ers.h"
 #include "../common/conf.h"
 
-#include "map.h"
-#include "chrif.h"
-#include "pc.h"
-#include "status.h"
-#include "npc.h"
-#include "itemdb.h"
-#include "chat.h"
-#include "trade.h"
-#include "storage.h"
-#include "script.h"
-#include "skill.h"
-#include "atcommand.h"
-#include "intif.h"
-#include "battle.h"
-#include "battleground.h"
-#include "mob.h"
-#include "party.h"
-#include "unit.h"
-#include "guild.h"
-#include "vending.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "log.h"
-#include "clif.h"
-#include "mail.h"
-#include "quest.h"
-#include "cashshop.h"
-#include "channel.h"
-#include "achievement.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <time.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "map.hpp"
+#include "chrif.hpp"
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "status.hpp"
+#include "npc.hpp"
+#include "itemdb.hpp"
+#include "chat.hpp"
+#include "trade.hpp"
+#include "storage.hpp"
+#include "script.hpp"
+#include "skill.hpp"
+#include "atcommand.hpp"
+#include "intif.hpp"
+#include "battle.hpp"
+#include "battleground.hpp"
+#include "mob.hpp"
+#include "party.hpp"
+#include "unit.hpp"
+#include "guild.hpp"
+#include "vending.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "instance.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "log.hpp"
+#include "clif.hpp"
+#include "mail.hpp"
+#include "quest.hpp"
+#include "cashshop.hpp"
+#include "channel.hpp"
+#include "achievement.hpp"
+#include "clan.hpp"
 
 /* for clif_clearunit_delayed */
 static struct eri *delay_clearunit_ers;
@@ -64,7 +64,7 @@ struct s_packet_db packet_db[MAX_PACKET_DB + 1];
 int packet_db_ack[MAX_ACK_FUNC + 1];
 unsigned long color_table[COLOR_MAX];
 
-#include "clif_obfuscation.h"
+#include "clif_obfuscation.hpp"
 static bool clif_session_isValid(struct map_session_data *sd);
 
 #if PACKETVER >= 20150513
@@ -20252,8 +20252,8 @@ void packetdb_readdb(){
 	memset(packet_db,0,sizeof(packet_db));
 	memset(packet_db_ack,0,sizeof(packet_db_ack));
 
-#include "clif_packetdb.h"
-#include "clif_shuffle.h"
+#include "clif_packetdb.hpp"
+#include "clif_shuffle.hpp"
 
 	ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
 
@@ -20303,6 +20303,3 @@ void do_final_clif(void) {
 	ers_destroy(delay_clearunit_ers);
 }
 
-#ifdef __cplusplus
-}
-#endif

+ 35 - 46
src/map/clif.h → src/map/clif.hpp

@@ -1,22 +1,18 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CLIF_H_
-#define _CLIF_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _CLIF_HPP_
+#define _CLIF_HPP_
 
 #include "../common/cbasetypes.h"
 #include "../common/db.h" //dbmap
-//#include "../common/mmo.h"
+#include "../common/mmo.h"
 
 struct Channel;
 struct clan;
 struct item;
 struct s_storage;
-//#include "map.h"
+//#include "map.hpp"
 struct block_list;
 struct unit_data;
 struct map_session_data;
@@ -34,21 +30,18 @@ struct guild;
 struct battleground_data;
 struct quest;
 struct party_booking_ad_info;
-enum e_party_member_withdraw;
 struct sale_item_data;
-enum mail_inbox_type;
 struct mail_message;
-enum mail_attachment_type;
 struct achievement;
 #include <stdarg.h>
 
-enum { // packet DB
+enum e_PacketDBVersion { // packet DB
 	MIN_PACKET_DB  = 0x064,
 	MAX_PACKET_DB  = 0xAFF,
 	MAX_PACKET_POS = 20,
 };
 
-enum e_packet_ack {
+enum e_packet_ack : uint8_t{
 	ZC_ACK_OPEN_BANKING = 0,
 	ZC_ACK_CLOSE_BANKING,
 	ZC_ACK_BANKING_DEPOSIT,
@@ -80,7 +73,7 @@ struct s_packet_keys {
 };
 #endif
 
-enum e_CASHSHOP_ACK {
+enum e_CASHSHOP_ACK : uint8_t{
 	ERROR_TYPE_NONE             = 0, ///< The deal has successfully completed.
 	ERROR_TYPE_NPC              = 1, ///< The Purchase has failed because the NPC does not exist.
 	ERROR_TYPE_SYSTEM           = 2, ///< The Purchase has failed because the Kafra Shop System is not working correctly.
@@ -92,67 +85,67 @@ enum e_CASHSHOP_ACK {
 	ERROR_TYPE_PURCHASE_FAIL    = 8, ///< Some items could not be purchased.
 };
 
-enum e_BANKING_DEPOSIT_ACK {
+enum e_BANKING_DEPOSIT_ACK : uint8_t {
 	BDA_SUCCESS  = 0x0,
 	BDA_ERROR    = 0x1,
 	BDA_NO_MONEY = 0x2,
 	BDA_OVERFLOW = 0x3,
 };
 
-enum e_BANKING_WITHDRAW_ACK {
+enum e_BANKING_WITHDRAW_ACK : uint8_t {
 	BWA_SUCCESS       = 0x0,
 	BWA_NO_MONEY      = 0x1,
 	BWA_UNKNOWN_ERROR = 0x2,
 };
 
-enum RECV_ROULETTE_ITEM_REQ {
+enum RECV_ROULETTE_ITEM_REQ : uint8_t {
 	RECV_ITEM_SUCCESS    = 0x0,
 	RECV_ITEM_FAILED     = 0x1,
 	RECV_ITEM_OVERCOUNT  = 0x2,
 	RECV_ITEM_OVERWEIGHT = 0x3,
 };
 
-enum RECV_ROULETTE_ITEM_ACK {
+enum RECV_ROULETTE_ITEM_ACK : uint8_t {
 	RECV_ITEM_NORMAL =  0x0,
 	RECV_ITEM_LOSING =  0x1,
 };
 
-enum GENERATE_ROULETTE_ACK {
+enum GENERATE_ROULETTE_ACK : uint8_t {
 	GENERATE_ROULETTE_SUCCESS         = 0x0,
 	GENERATE_ROULETTE_FAILED          = 0x1,
 	GENERATE_ROULETTE_NO_ENOUGH_POINT = 0x2,
 	GENERATE_ROULETTE_LOSING          = 0x3,
 };
 
-enum OPEN_ROULETTE_ACK {
+enum OPEN_ROULETTE_ACK : uint8_t {
 	OPEN_ROULETTE_SUCCESS = 0x0,
 	OPEN_ROULETTE_FAILED  = 0x1,
 };
 
-enum CLOSE_ROULETTE_ACK {
+enum CLOSE_ROULETTE_ACK : uint8_t {
 	CLOSE_ROULETTE_SUCCESS = 0x0,
 	CLOSE_ROULETTE_FAILED  = 0x1,
 };
 
-enum MERGE_ITEM_ACK {
+enum MERGE_ITEM_ACK : uint8_t {
 	MERGE_ITEM_SUCCESS = 0x0,
 	MERGE_ITEM_FAILED_NOT_MERGE = 0x1,
 	MERGE_ITEM_FAILED_MAX_COUNT = 0x2,
 };
 
-enum BROADCASTING_SPECIAL_ITEM_OBTAIN {
+enum BROADCASTING_SPECIAL_ITEM_OBTAIN : uint8_t {
 	ITEMOBTAIN_TYPE_BOXITEM =  0x0,
 	ITEMOBTAIN_TYPE_MONSTER_ITEM =  0x1,
 	ITEMOBTAIN_TYPE_NPC =  0x2,
 };
 
-enum e_adopt_reply {
+enum e_adopt_reply : uint8_t {
 	ADOPT_REPLY_MORE_CHILDREN = 0,
 	ADOPT_REPLY_LEVEL_70,
 	ADOPT_REPLY_MARRIED,
 };
 
-enum e_wip_block {
+enum e_wip_block : uint8_t {
 	WIP_DISABLE_NONE = 0x0,
 	WIP_DISABLE_SKILLITEM = 0x1,
 	WIP_DISABLE_NPC = 0x2,
@@ -185,8 +178,8 @@ extern struct s_packet_db packet_db[MAX_PACKET_DB+1];
 extern int packet_db_ack[MAX_ACK_FUNC + 1];
 
 // local define
-typedef enum send_target {
-	ALL_CLIENT,
+enum send_target : uint8_t {
+	ALL_CLIENT = 0,
 	ALL_SAMEMAP,
 	AREA,				// area
 	AREA_WOS,			// area, without self
@@ -220,9 +213,9 @@ typedef enum send_target {
 	BG_AREA_WOS,
 
 	CLAN,				// Clan System
-} send_target;
+};
 
-typedef enum broadcast_flags {
+enum broadcast_flags : uint8_t {
 	BC_ALL			= 0,
 	BC_MAP			= 1,
 	BC_AREA			= 2,
@@ -239,9 +232,9 @@ typedef enum broadcast_flags {
 	BC_COLOR_MASK	= 0x30, // BC_YELLOW|BC_BLUE|BC_WOE
 
 	BC_DEFAULT		= BC_ALL|BC_PC|BC_YELLOW
-} broadcast_flags;
+};
 
-typedef enum emotion_type {
+enum emotion_type {
 	E_GASP = 0,     // /!
 	E_WHAT,         // /?
 	E_HO,
@@ -332,18 +325,18 @@ typedef enum emotion_type {
 	E_YUT7,
 	//
 	E_MAX
-} emotion_type;
+};
 
-typedef enum clr_type
+enum clr_type : uint8_t 
 {
 	CLR_OUTSIGHT = 0,
 	CLR_DEAD,
 	CLR_RESPAWN,
 	CLR_TELEPORT,
 	CLR_TRICKDEAD,
-} clr_type;
+};
 
-enum map_property
+enum map_property : uint8_t 
 {// clif_map_property
 	MAPPROPERTY_NOTHING       = 0,
 	MAPPROPERTY_FREEPVPZONE   = 1,
@@ -354,7 +347,7 @@ enum map_property
 	MAPPROPERTY_DENYSKILLZONE = 6,
 };
 
-enum map_type
+enum map_type : uint8_t 
 {// clif_map_type
 	MAPTYPE_VILLAGE              = 0,
 	MAPTYPE_VILLAGE_IN           = 1,
@@ -383,7 +376,7 @@ enum map_type
 	MAPTYPE_UNUSED               = 29,
 };
 
-enum useskill_fail_cause
+enum useskill_fail_cause : uint8_t 
 {// clif_skill_fail
 	USESKILL_FAIL_LEVEL = 0,
 	USESKILL_FAIL_SP_INSUFFICIENT = 1,
@@ -476,7 +469,7 @@ enum useskill_fail_cause
 	USESKILL_FAIL_MAX
 };
 
-enum clif_messages {
+enum clif_messages : uint16_t {
 	/* Constant values */
 	// clif_cart_additem_ack flags
 	ADDITEM_TO_CART_FAIL_WEIGHT = 0x0,
@@ -518,7 +511,7 @@ enum clif_messages {
 	SKILL_NEED_GRENADE = 0xa01,
 };
 
-enum e_personalinfo {
+enum e_personalinfo : uint8_t {
 	PINFO_BASIC = 0,
 	PINFO_PREMIUM,
 	PINFO_SERVER,
@@ -526,7 +519,7 @@ enum e_personalinfo {
 	PINFO_MAX,
 };
 
-enum e_damage_type {
+enum e_damage_type : uint8_t {
 	DMG_NORMAL = 0,			/// damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
 	DMG_PICKUP_ITEM,		/// pick up item
 	DMG_SIT_DOWN,			/// sit down
@@ -892,7 +885,7 @@ void do_init_clif(void);
 void do_final_clif(void);
 
 // MAIL SYSTEM
-enum mail_send_result{
+enum mail_send_result : uint8_t {
 	WRITE_MAIL_SUCCESS = 0x0,
 	WRITE_MAIL_FAILED = 0x1,
 	WRITE_MAIL_FAILED_CNT = 0x2,
@@ -1074,8 +1067,4 @@ void clif_achievement_update(struct map_session_data *sd, struct achievement *ac
 void clif_pAchievementCheckReward(int fd, struct map_session_data *sd);
 void clif_achievement_reward_ack(int fd, unsigned char result, int ach_id);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CLIF_H_ */
+#endif /* _CLIF_HPP_ */

+ 3 - 3
src/map/clif_obfuscation.h → src/map/clif_obfuscation.hpp

@@ -1,8 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CLIF_OBFUSCATION_H_
-#define _CLIF_OBFUSCATION_H_
+#ifndef _CLIF_OBFUSCATION_HPP_
+#define _CLIF_OBFUSCATION_HPP_
 
 #if defined(PACKET_OBFUSCATION) || defined(PACKET_OBFUSCATION_WARN)
 	#define packet_keys(a,b,c) static unsigned int clif_cryptKey[] = { a, b, c };
@@ -391,4 +391,4 @@
 	#undef packet_keys
 #endif
 
-#endif /* _CLIF_OBFUSCATION_H_ */
+#endif /* _CLIF_OBFUSCATION_HPP_ */

+ 3 - 3
src/map/clif_packetdb.h → src/map/clif_packetdb.hpp

@@ -1,8 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CLIF_PACKETDB_H_
-#define _CLIF_PACKETDB_H_
+#ifndef _CLIF_PACKETDB_HPP_
+#define _CLIF_PACKETDB_HPP_
 
 	#define packet(cmd,length) packetdb_addpacket(cmd,length,NULL,0)
 	#define parseable_packet(cmd,length,func,...) packetdb_addpacket(cmd,length,func,__VA_ARGS__,0)
@@ -2352,4 +2352,4 @@
 	packet(0x0ACC,18);
 #endif
 
-#endif /* _CLIF_PACKETDB_H_ */
+#endif /* _CLIF_PACKETDB_HPP_ */

+ 3 - 3
src/map/clif_shuffle.h → src/map/clif_shuffle.hpp

@@ -1,8 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _CLIF_SHUFFLE_H_
-#define _CLIF_SHUFFLE_H_
+#ifndef _CLIF_SHUFFLE_HPP_
+#define _CLIF_SHUFFLE_HPP_
 
 // 2013-05-15aRagexe
 #if PACKETVER == 20130515
@@ -4193,4 +4193,4 @@
 	parseable_packet(0x096A,6,clif_parse_GetCharNameRequest,2);
 #endif
 
-#endif /* _CLIF_SHUFFLE_H_ */
+#endif /* _CLIF_SHUFFLE_HPP_ */

+ 2 - 1
src/map/date.c → src/map/date.cpp

@@ -1,7 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include "date.h"
+#include "date.hpp"
+
 #include <time.h>
 
 /*

+ 3 - 10
src/map/date.h → src/map/date.hpp

@@ -1,15 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _DATE_H_
-#define _DATE_H_
+#ifndef _DATE_HPP_
+#define _DATE_HPP_
 
 #include "../common/cbasetypes.h"
 
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
 enum e_month{
 	JANUARY = 1,
 	FEBRUARY,
@@ -64,7 +60,4 @@ bool is_day_of_sun(void);
 bool is_day_of_moon(void);
 bool is_day_of_star(void);
 
-#ifdef	__cplusplus
-}
-#endif
-#endif /* _DATE_H_ */
+#endif /* _DATE_HPP_ */

+ 10 - 6
src/map/duel.c → src/map/duel.cpp

@@ -2,16 +2,19 @@
 // For more information, see LICENCE in the main folder
 // Duel organizing functions [LuzZza]
 
-#include "../common/cbasetypes.h"
-
-#include "atcommand.h"  // msg_txt
-#include "clif.h"
-#include "duel.h"
-#include "pc.h"
+#include "duel.hpp"
 
 #include <stdio.h>
 #include <string.h>
 
+#include "../common/cbasetypes.h"
+#include "../common/timer.h"
+
+#include "atcommand.hpp"  // msg_txt
+#include "clif.hpp"
+#include "pc.hpp"
+#include "battle.hpp"
+
 //global var (extern)
 struct duel duel_list[MAX_DUEL]; //list of current duel
 int duel_count = 0; //number of duel active
@@ -112,6 +115,7 @@ static void duel_set(const unsigned int did, struct map_session_data* sd) {
 
 /*
  * Create a new duel for sd
+ * return duel_id or 0 when fail
  */
 int duel_create(struct map_session_data* sd, const unsigned int maxpl)
 {

+ 4 - 9
src/map/duel.h → src/map/duel.hpp

@@ -1,12 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _DUEL_H_
-#define _DUEL_H_
+#ifndef _DUEL_HPP_
+#define _DUEL_HPP_
 
-#ifdef	__cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
 struct duel {
 	int members_count;
@@ -30,8 +28,5 @@ int duel_checktime(struct map_session_data* sd);
 void do_init_duel(void);
 void do_final_duel(void);
 
-#ifdef	__cplusplus
-}
-#endif
 
-#endif /* _DUEL_H_ */
+#endif /* _DUEL_HPP_ */

+ 19 - 14
src/map/elemental.c → src/map/elemental.cpp

@@ -1,6 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "elemental.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+#include <ctgmath> //floor
+#include <cstring>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/timer.h"
@@ -11,17 +18,15 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 
-#include "log.h"
-#include "clif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "pc.h"
-#include "party.h"
-#include "trade.h"
-#include "elemental.h"
-
-#include <stdlib.h>
-#include <math.h>
+#include "log.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "itemdb.hpp"
+#include "pc.hpp"
+#include "party.hpp"
+#include "trade.hpp"
+#include "npc.hpp"
+#include "battle.hpp"
 
 struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database
 static uint16 elemental_count;
@@ -306,7 +311,7 @@ int elemental_clean_single_effect(struct elemental_data *ed, uint16 skill_id) {
 			case SC_CIRCLE_OF_FIRE_OPTION:
 			case SC_TIDAL_WEAPON_OPTION:
 				if( bl ) status_change_end(bl,type,INVALID_TIMER);	// Master
-				status_change_end(&ed->bl,type-1,INVALID_TIMER);	// Elemental Spirit
+				status_change_end(&ed->bl,static_cast<sc_type>(type-1),INVALID_TIMER);	// Elemental Spirit
 				break;
 			case SC_ZEPHYR:
 				if( bl ) status_change_end(bl,type,INVALID_TIMER);
@@ -823,7 +828,7 @@ void read_elementaldb(void) {
 	elemental_count = 0;
 	memset(elemental_db, 0, sizeof(elemental_db));
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 26, 26, -1, &read_elementaldb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 26, 26, -1, &read_elementaldb_sub, i > 0);
 	}
 }
 
@@ -871,7 +876,7 @@ void read_elemental_skilldb(void) {
 	const char *filename[] = { "elemental_skill_db.txt", DBIMPORT"/elemental_skill_db.txt" };
 	uint8 i;
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 4, 4, -1, &read_elemental_skilldb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 4, 4, -1, &read_elemental_skilldb_sub, i > 0);
 	}
 }
 

+ 8 - 14
src/map/elemental.h → src/map/elemental.hpp

@@ -1,15 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _ELEMENTAL_H_
-#define _ELEMENTAL_H_
+#ifndef _ELEMENTAL_HPP_
+#define _ELEMENTAL_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/mmo.h"
 
-#include "status.h" // struct status_data, struct status_change
-#include "unit.h" // struct unit_data
+#include "status.hpp" // struct status_data, struct status_change
+#include "unit.hpp" // struct unit_data
 
 #define MIN_ELETHINKTIME 100
 #define MIN_ELEDISTANCE 2
@@ -20,14 +18,14 @@ extern "C" {
 #define EL_MODE_PASSIVE MD_CANMOVE
 
 ///Enum of Elemental Skill Mode
-enum elemental_skillmode {
+enum elemental_skillmode : uint8 {
 	EL_SKILLMODE_PASSIVE    = 0x1,
 	EL_SKILLMODE_ASSIST     = 0x2,
 	EL_SKILLMODE_AGGRESSIVE = 0x4,
 };
 
 ///Enum of Elemental ID
-enum elemental_elementalid {
+enum elemental_elementalid  : uint16 {
 	ELEMENTALID_AGNI_S = 2114,
 	ELEMENTALID_AGNI_M,
 	ELEMENTALID_AGNI_L,
@@ -115,8 +113,4 @@ void reload_elemental_skilldb(void);
 void do_init_elemental(void);
 void do_final_elemental(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ELEMENTAL_H_ */
+#endif /* _ELEMENTAL_HPP_ */

+ 23 - 21
src/map/guild.c → src/map/guild.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "guild.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -11,20 +15,18 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 
-#include "map.h"
-#include "guild.h"
-#include "storage.h"
-#include "battle.h"
-#include "npc.h"
-#include "pc.h"
-#include "instance.h"
-#include "intif.h"
-#include "channel.h"
-#include "log.h"
-#include "trade.h"
-
-#include <stdlib.h>
-
+#include "map.hpp"
+#include "storage.hpp"
+#include "battle.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "instance.hpp"
+#include "intif.hpp"
+#include "channel.hpp"
+#include "log.hpp"
+#include "trade.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
 
 static DBMap* guild_db; // int guild_id -> struct guild*
 static DBMap* castle_db; // int castle_id -> struct guild_castle*
@@ -49,7 +51,7 @@ struct guild_expcache {
 static struct eri *expcache_ers; //For handling of guild exp payment.
 
 #define MAX_GUILD_SKILL_REQUIRE 5
-struct{
+struct s_guild_skill_tree {
 	int id;
 	int max;
 	struct{
@@ -1940,7 +1942,7 @@ void guild_castle_map_init(void) {
 		}
 		dbi_destroy(iter);
 		if (intif_guild_castle_dataload(num, castle_ids))
-			ShowStatus("Requested '"CL_WHITE"%d"CL_RESET"' guild castles from char-server...\n", num);
+			ShowStatus("Requested '" CL_WHITE "%d" CL_RESET "' guild castles from char-server...\n", num);
 		aFree(castle_ids);
 	}
 }
@@ -2087,7 +2089,7 @@ int guild_castledataloadack(int len, struct guild_castle *gc) {
 			}
 		}
 	}
-	ShowStatus("Received '"CL_WHITE"%d"CL_RESET"' guild castles from char-server.\n", n);
+	ShowStatus("Received '" CL_WHITE "%d" CL_RESET "' guild castles from char-server.\n", n);
 	return 0;
 }
 
@@ -2295,7 +2297,7 @@ void guild_flags_clear(void) {
 void do_init_guild(void) {
 	const char* dbsubpath[] = {
 		"",
-		"/"DBIMPORT,
+		"/" DBIMPORT,
 	};
 	int i;
 	
@@ -2303,7 +2305,7 @@ void do_init_guild(void) {
 	castle_db          = idb_alloc(DB_OPT_BASE);
 	guild_expcache_db  = idb_alloc(DB_OPT_BASE);
 	guild_infoevent_db = idb_alloc(DB_OPT_BASE);
-	expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.c::expcache_ers",ERS_OPT_NONE);
+	expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.cpp::expcache_ers",ERS_OPT_NONE);
 
 	guild_flags_count = 0;
 
@@ -2314,8 +2316,8 @@ void do_init_guild(void) {
 		char* dbsubpath1 = (char*)aMalloc(n1+1);
 		safesnprintf(dbsubpath1,n1+1,"%s%s",db_path,dbsubpath[i]);
 		
-		sv_readdb(dbsubpath1, "castle_db.txt", ',', 4, 4, -1, &guild_read_castledb, i);
-		sv_readdb(dbsubpath1, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db, i); //guild skill tree [Komurka]
+		sv_readdb(dbsubpath1, "castle_db.txt", ',', 4, 4, -1, &guild_read_castledb, i > 0);
+		sv_readdb(dbsubpath1, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, &guild_read_guildskill_tree_db, i > 0); //guild skill tree [Komurka]
 		
 		aFree(dbsubpath1);
 	}

+ 7 - 12
src/map/guild.h → src/map/guild.hpp

@@ -1,19 +1,18 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _GUILD_H_
-#define _GUILD_H_
+#ifndef _GUILD_HPP_
+#define _GUILD_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+#include "../common/mmo.h"
+
+#include "map.hpp" // NAME_LENGTH
 
-//#include "../common/mmo.h"
 struct guild;
 struct guild_member;
 struct guild_position;
 struct guild_castle;
-#include "map.h" // NAME_LENGTH
 struct map_session_data;
 struct mob_data;
 
@@ -119,8 +118,4 @@ void guild_retrieveitembound(uint32 char_id,uint32 account_id,int guild_id);
 
 void do_final_guild(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _GUILD_H_ */
+#endif /* _GUILD_HPP_ */

+ 18 - 16
src/map/homunculus.c → src/map/homunculus.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "homunculus.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/timer.h"
@@ -11,17 +15,15 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 
-#include "log.h"
-#include "clif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "pc.h"
-#include "party.h"
-#include "trade.h"
-
-#include "homunculus.h"
-
-#include <stdlib.h>
+#include "log.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "itemdb.hpp"
+#include "pc.hpp"
+#include "party.hpp"
+#include "trade.hpp"
+#include "npc.hpp"
+#include "battle.hpp"
 
 struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS];	//[orn]
 struct homun_skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_HOM_SKILL_TREE];
@@ -1071,7 +1073,7 @@ bool hom_call(struct map_session_data *sd)
 
 	// If homunc not yet loaded, load it
 	if (!sd->hd)
-		return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id);
+		return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id) > 0;
 
 	hd = sd->hd;
 
@@ -1514,7 +1516,7 @@ void read_homunculusdb(void) {
 	homunculus_count = 0;
 	memset(homunculus_db,0,sizeof(homunculus_db));
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, &read_homunculusdb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, &read_homunculusdb_sub, i > 0);
 	}
 }
 
@@ -1567,7 +1569,7 @@ static void read_homunculus_skilldb(void) {
 	int i;
 	memset(hskill_tree,0,sizeof(hskill_tree));
 	for (i = 0; i<ARRAYLENGTH(filename); i++) {
-		sv_readdb(db_path, filename[i], ',', 15, 15, -1, &read_homunculus_skilldb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 15, 15, -1, &read_homunculus_skilldb_sub, i > 0);
 	}
 }
 
@@ -1577,7 +1579,7 @@ static void read_homunculus_skilldb(void) {
 void read_homunculus_expdb(void)
 {
 	int i;
-	char *filename[]={
+	const char *filename[]={
 		DBPATH"exp_homun.txt",
 		DBIMPORT"/exp_homun.txt"
 	};
@@ -1609,7 +1611,7 @@ void read_homunculus_expdb(void)
 			hexptbl[MAX_LEVEL - 1] = 0;
 		}
 		fclose(fp);
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s/%s"CL_RESET"'.\n", j, db_path, filename[i]);
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' levels in '" CL_WHITE "%s/%s" CL_RESET "'.\n", j, db_path, filename[i]);
 	}
 }
 

+ 13 - 19
src/map/homunculus.h → src/map/homunculus.hpp

@@ -1,15 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _HOMUNCULUS_H_
-#define _HOMUNCULUS_H_
+#ifndef _HOMUNCULUS_HPP_
+#define _HOMUNCULUS_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
-#include "status.h" // struct status_data, struct status_change
-#include "unit.h" // struct unit_data
+#include "status.hpp" // struct status_data, struct status_change
+#include "unit.hpp" // struct unit_data
 
 #ifdef RENEWAL
 	#define	HOMUN_LEVEL_STATWEIGHT_VALUE 0
@@ -38,17 +36,17 @@ struct s_homunculus_db {
 };
 extern struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS];
 
-enum e_hom_search_type { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD };
+enum e_hom_search_type : uint8  { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD };
 
-enum e_hom_mode { MH_MD_FIGHTING = 1, MH_MD_GRAPPLING };
+enum e_hom_mode : uint8  { MH_MD_FIGHTING = 1, MH_MD_GRAPPLING };
 
-enum e_hom_state {
+enum e_hom_state : uint8 {
 	HOM_ST_ACTIVE	= 0,
 	HOM_ST_REST		= 1,
 	HOM_ST_MORPH	= 2,
 };
 
-enum {
+enum e_hom_state2 : uint8 {
 	SP_ACK      = 0x0,
 	SP_INTIMATE = 0x1,
 	SP_HUNGRY   = 0x2,
@@ -111,7 +109,7 @@ enum homun_mapid {
 };
 
 /// Homunculus type
-enum homun_type {
+enum homun_type : int8 {
 	HT_REG		= 0x1,
 	HT_EVO		= 0x2,
 	HT_S		= 0x4,
@@ -119,7 +117,7 @@ enum homun_type {
 };
 
 /// Homunculus battle_config setting
-enum homun_setting {
+enum homun_setting : uint8 {
 	HOMSET_NO_SUPPORT_SKILL				= 0x01, /// Cannot be targetted by support skills, except for their master
 	HOMSET_NO_INSTANT_LAND_SKILL		= 0x02, /// Unit/land skill doesn't applied immediately
 	HOMSET_FIRST_TARGET					= 0x04, /// Mobs will always go after them instead of players until attacked
@@ -130,7 +128,7 @@ enum homun_setting {
 	HOMSET_RESET_REUSESKILL_TELEPORTED	= 0x80, /// Skill re-use delay is reset when they are warped (by skill or item) with player.
 };
 
-enum e_homun_grade {
+enum e_homun_grade : uint8 {
 	HOMGRADE_HATE_WITH_PASSION = 0,
 	HOMGRADE_HATE,
 	HOMGRADE_AWKWARD,
@@ -195,8 +193,4 @@ short hom_skill_get_index(uint16 skill_id);
 void do_final_homunculus(void);
 void do_init_homunculus(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _HOMUNCULUS_H_ */
+#endif /* _HOMUNCULUS_HPP_ */

+ 15 - 12
src/map/instance.c → src/map/instance.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "instance.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/socket.h"
 #include "../common/timer.h"
@@ -9,16 +13,15 @@
 #include "../common/strlib.h"
 #include "../common/db.h"
 #include "../common/malloc.h"
+#include "../common/ers.h"  // ers_destroy
 
-#include "clif.h"
-#include "guild.h"
-#include "instance.h"
-#include "map.h"
-#include "npc.h"
-#include "party.h"
-#include "pc.h"
-
-#include <stdlib.h>
+#include "clan.hpp"
+#include "clif.hpp"
+#include "guild.hpp"
+#include "map.hpp"
+#include "npc.hpp"
+#include "party.hpp"
+#include "pc.hpp"
 
 #define INSTANCE_INTERVAL	60000	// Interval used to check when an instance is to be destroyed (ms)
 
@@ -1038,7 +1041,7 @@ void instance_readdb(void) {
 	int f;
 
 	for (f = 0; f<ARRAYLENGTH(filename); f++) {
-		sv_readdb(db_path, filename[f], ',', 7, 7+MAX_MAP_PER_INSTANCE, -1, &instance_readdb_sub, f);
+		sv_readdb(db_path, filename[f], ',', 7, 7+MAX_MAP_PER_INSTANCE, -1, &instance_readdb_sub, f > 0);
 	}
 }
 
@@ -1124,14 +1127,14 @@ void do_reload_instance(void)
 
 void do_init_instance(void) {
 	InstanceDB = uidb_alloc(DB_OPT_BASE);
-	InstanceNameDB = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,0);
+	InstanceNameDB = strdb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA),0);
 
 	instance_readdb();
 	memset(instance_data, 0, sizeof(instance_data));
 	memset(&instance_wait, 0, sizeof(instance_wait));
 	instance_wait.timer = -1;
 
-	instance_maps_ers = ers_new(sizeof(struct s_instance_map),"instance.c::instance_maps_ers", ERS_OPT_NONE);
+	instance_maps_ers = ers_new(sizeof(struct s_instance_map),"instance.cpp::instance_maps_ers", ERS_OPT_NONE);
 
 	add_timer_func_list(instance_delete_timer,"instance_delete_timer");
 	add_timer_func_list(instance_subscription_timer,"instance_subscription_timer");

+ 10 - 14
src/map/instance.h → src/map/instance.hpp

@@ -1,16 +1,16 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _INSTANCE_H_
-#define _INSTANCE_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _INSTANCE_HPP_
+#define _INSTANCE_HPP_
 
+#include "../common/cbasetypes.h"
 #include "../common/mmo.h" // struct point
-#include "script.h" // struct reg_db
+#include "../common/strlib.h"
+
+#include "script.hpp" // struct reg_db
 
+enum send_target : uint8;
 struct block_list;
 
 #define MAX_INSTANCE_DATA		300	// Essentially how many instances we can create, but instance creation is primarily decided by MAX_MAP_PER_SERVER
@@ -18,11 +18,11 @@ struct block_list;
 
 #define INSTANCE_NAME_LENGTH (60+1)
 
-typedef enum instance_state {
+enum instance_state {
 	INSTANCE_FREE,
 	INSTANCE_IDLE,
 	INSTANCE_BUSY
-} instance_state;
+};
 
 enum instance_mode {
 	IM_NONE,
@@ -64,7 +64,7 @@ struct instance_db {
 	StringBuf *name; ///< Instance name
 	unsigned int limit, ///< Duration limit
 		timeout; ///< Timeout limit
-	struct {
+	struct s_MapInfo {
 		StringBuf *mapname; ///< Mapname, the limit should be MAP_NAME_LENGTH_EXT
 		short x, y; ///< Map coordinates
 	} enter;
@@ -99,8 +99,4 @@ void do_final_instance(void);
 	#error Too many maps per instance defined! Please adjust MAX_MAP_PER_INSTANCE to a lower value.
 #endif
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

+ 34 - 29
src/map/intif.c → src/map/intif.cpp

@@ -1,31 +1,36 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "intif.hpp"
+
+#include <stdlib.h>
+
 #include "../common/showmsg.h"
 #include "../common/socket.h"
 #include "../common/nullpo.h"
 #include "../common/malloc.h"
 #include "../common/strlib.h"
 #include "../common/mmo.h"
-#include "map.h"
-#include "battle.h"
-#include "chrif.h"
-#include "clan.h"
-#include "clif.h"
-#include "pc.h"
-#include "intif.h"
-#include "storage.h"
-#include "party.h"
-#include "pet.h"
-#include "mercenary.h"
-#include "homunculus.h"
-#include "elemental.h"
-#include "mail.h"
-#include "quest.h"
-#include "status.h"
-#include "achievement.h"
-
-#include <stdlib.h>
+#include "../common/timer.h"
+
+#include "map.hpp"
+#include "battle.hpp"
+#include "chrif.hpp"
+#include "clan.hpp"
+#include "guild.hpp"
+#include "clif.hpp"
+#include "pc.hpp"
+#include "storage.hpp"
+#include "party.hpp"
+#include "pet.hpp"
+#include "mercenary.hpp"
+#include "homunculus.hpp"
+#include "elemental.hpp"
+#include "mail.hpp"
+#include "quest.hpp"
+#include "status.hpp"
+#include "achievement.hpp"
+#include "log.hpp"
 
 /// Received packet Lengths from inter-server
 static const int packet_len_table[] = {
@@ -641,7 +646,7 @@ int intif_party_changeoption(int party_id,uint32 account_id,int exp,int item)
  * @param char_id : cid of player to leave
  * @return 0:char-serv disconected, 1=msg sent
  */
-int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, char *name, enum e_party_member_withdraw type)
+int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, const char *name, enum e_party_member_withdraw type)
 {
 	if (CheckForCharServer())
 		return 0;
@@ -2293,7 +2298,7 @@ int intif_parse_Mail_inboxreceived(int fd)
 		// Refresh top right icon
 		clif_Mail_new(sd, 0, NULL, NULL);
 #endif
-		clif_Mail_refreshinbox(sd,RFIFOB(fd,9),0);
+		clif_Mail_refreshinbox(sd,static_cast<mail_inbox_type>(RFIFOB(fd,9)),0);
 	}else if( battle_config.mail_show_status && ( battle_config.mail_show_status == 1 || sd->mail.inbox.unread ) )
 	{
 		char output[128];
@@ -2410,7 +2415,7 @@ int intif_parse_Mail_delete(int fd)
 {
 	uint32 char_id = RFIFOL(fd,2);
 	int mail_id = RFIFOL(fd,6);
-	bool failed = RFIFOB(fd,10);
+	bool failed = RFIFOB(fd,10) > 0;
 
 	struct map_session_data *sd = map_charid2sd(char_id);
 	if (sd == NULL)
@@ -2577,7 +2582,7 @@ static void intif_parse_Mail_new(int fd)
 	clif_Mail_new(sd, mail_id, sender_name, title);
 #if PACKETVER >= 20150513
 	// Make sure the window gets refreshed when its open
-	intif_Mail_requestinbox(sd->status.char_id, 1, RFIFOB(fd,74));
+	intif_Mail_requestinbox(sd->status.char_id, 1, static_cast<mail_inbox_type>(RFIFOB(fd,74)));
 #endif
 }
 
@@ -2912,7 +2917,7 @@ int intif_parse_mercenary_received(int fd)
 		return 0;
 	}
 
-	mercenary_recv_data((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4));
+	mercenary_recv_data((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
 	return 1;
 }
 
@@ -3037,7 +3042,7 @@ int intif_parse_elemental_received(int fd)
 		return 0;
 	}
 
-	elemental_data_received((struct s_elemental*)RFIFOP(fd,5), RFIFOB(fd,4));
+	elemental_data_received((struct s_elemental*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
 	return 1;
 }
 
@@ -3302,7 +3307,7 @@ void intif_itembound_guild_retrieve(uint32 char_id,uint32 account_id,int guild_i
 	WFIFOSET(inter_fd,12);
 	if (gstor)
 		gstor->lock = true; //Lock for retrieval process
-	ShowInfo("Request guild bound item(s) retrieval for CID = "CL_WHITE"%d"CL_RESET", AID = %d, Guild ID = "CL_WHITE"%d"CL_RESET".\n", char_id, account_id, guild_id);
+	ShowInfo("Request guild bound item(s) retrieval for CID = " CL_WHITE "%d" CL_RESET ", AID = %d, Guild ID = " CL_WHITE "%d" CL_RESET ".\n", char_id, account_id, guild_id);
 }
 
 /**
@@ -3342,7 +3347,7 @@ void intif_parse_itembound_store2gstorage(int fd) {
 		if (!storage_guild_additem2(gstor, item, item->amount))
 			failed++;
 	}
-	ShowInfo("Retrieved '"CL_WHITE"%d"CL_RESET"' (failed: %d) guild bound item(s) for Guild ID = "CL_WHITE"%d"CL_RESET".\n", count, failed, guild_id);
+	ShowInfo("Retrieved '" CL_WHITE "%d" CL_RESET "' (failed: %d) guild bound item(s) for Guild ID = " CL_WHITE "%d" CL_RESET ".\n", count, failed, guild_id);
 	gstor->lock = false;
 	gstor->status = false;
 }
@@ -3430,7 +3435,7 @@ static bool intif_parse_StorageReceived(int fd)
 			status_set_viewdata(&sd->bl, sd->status.class_);
 			pc_load_combo(sd);
 			status_calc_pc(sd, (enum e_status_calc_opt)(SCO_FIRST|SCO_FORCE));
-			status_calc_weight(sd, CALCWT_ITEM|CALCWT_MAXBONUS); // Refresh weight data
+			status_calc_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS)); // Refresh weight data
 			chrif_scdata_request(sd->status.account_id, sd->status.char_id);
 			break;
 		}
@@ -3515,7 +3520,7 @@ void intif_parse_StorageInfo_recv(int fd) {
 	}
 
 	if (battle_config.etc_log)
-		ShowInfo("Received '"CL_WHITE"%d"CL_RESET"' storage info from inter-server.\n", storage_count);
+		ShowInfo("Received '" CL_WHITE "%d" CL_RESET "' storage info from inter-server.\n", storage_count);
 }
 
 /**

+ 7 - 13
src/map/intif.h → src/map/intif.hpp

@@ -1,14 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _INTIF_H_
-#define _INTIF_H_
+#ifndef _INTIF_HPP_
+#define _INTIF_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+#include "../common/mmo.h"
 
-//#include "../common/mmo.h"
 struct party_member;
 struct guild_member;
 struct guild_position;
@@ -18,8 +16,8 @@ struct s_mercenary;
 struct s_elemental;
 struct mail_message;
 struct auction_data;
-enum storage_type;
 struct achievement_db;
+struct map_session_data;
 
 int intif_parse(int fd);
 
@@ -43,7 +41,7 @@ int intif_request_partyinfo(int party_id, uint32 char_id);
 
 int intif_party_addmember(int party_id,struct party_member *member);
 int intif_party_changeoption(int party_id, uint32 account_id, int exp, int item);
-int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, char *name, enum e_party_member_withdraw type);
+int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, const char *name, enum e_party_member_withdraw type);
 int intif_party_changemap(struct map_session_data *sd, int online);
 int intif_break_party(int party_id);
 int intif_party_message(int party_id, uint32 account_id, const char *mes,int len);
@@ -131,8 +129,4 @@ bool intif_storage_save(struct map_session_data *sd, struct s_storage *stor);
 
 int CheckForCharServer(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _INTIF_H_ */
+#endif /* _INTIF_HPP_ */

+ 41 - 34
src/map/itemdb.c → src/map/itemdb.cpp

@@ -1,18 +1,25 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "itemdb.hpp"
+
+#include <stdlib.h>
+
 #include "../common/nullpo.h"
 #include "../common/malloc.h"
 #include "../common/random.h"
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
 #include "../common/utils.h"
-#include "itemdb.h"
-#include "battle.h" // struct battle_config
-#include "cashshop.h"
-#include "intif.h"
 
-#include <stdlib.h>
+#include "battle.hpp" // struct battle_config
+#include "cashshop.hpp"
+#include "intif.hpp"
+#include "pc.hpp"
+#include "status.hpp"
+#include "clif.hpp"
+#include "log.hpp"
+#include "mob.hpp"
 
 static DBMap *itemdb; /// Item DB
 static DBMap *itemdb_combo; /// Item Combo DB
@@ -663,11 +670,11 @@ static bool itemdb_read_group(char* str[], int columns, int current) {
 	}
 
 	if( columns > 3 ) entry.amount = cap_value(atoi(str[3]),1,MAX_AMOUNT);
-	if( columns > 5 ) entry.isAnnounced= atoi(str[5]);
+	if( columns > 5 ) entry.isAnnounced= atoi(str[5]) > 0;
 	if( columns > 6 ) entry.duration = cap_value(atoi(str[6]),0,UINT16_MAX);
-	if( columns > 7 ) entry.GUID = atoi(str[7]);
+	if( columns > 7 ) entry.GUID = atoi(str[7]) > 0;
 	if( columns > 8 ) entry.bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1);
-	if( columns > 9 ) entry.isNamed = atoi(str[9]);
+	if( columns > 9 ) entry.isNamed = atoi(str[9]) > 0;
 	
 	if (!(group = (struct s_item_group_db *) uidb_get(itemdb_group, group_id))) {
 		CREATE(group, struct s_item_group_db, 1);
@@ -1069,7 +1076,7 @@ static void itemdb_read_combos(const char* basedir, bool silent) {
 	}
 	fclose(fp);
 
-	ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",count,path);
+	ShowStatus("Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n",count,path);
 
 	return;
 }
@@ -1163,7 +1170,7 @@ bool itemdb_parse_roulette_db(void)
 		}
 	}
 
-	ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, roulette_table);
+	ShowStatus("Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, roulette_table);
 
 	return true;
 }
@@ -1498,7 +1505,7 @@ static int itemdb_readdb(void){
 
 		fclose(fp);
 
-		ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, path);
+		ShowStatus("Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, path);
 	}
 
 	return 0;
@@ -1527,7 +1534,7 @@ static int itemdb_read_sqldb(void) {
 		// process rows one by one
 		while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {// wrap the result into a TXT-compatible format
 			char* str[22];
-			char* dummy = "";
+			char dummy[256] = "";
 			int i;
 			++lines;
 			for( i = 0; i < 22; ++i ) {
@@ -1544,7 +1551,7 @@ static int itemdb_read_sqldb(void) {
 		// free the query result
 		Sql_FreeResult(mmysql_handle);
 
-		ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, item_db_name[fi]);
+		ShowStatus("Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, item_db_name[fi]);
 	}
 
 	return 0;
@@ -1682,7 +1689,7 @@ static bool itemdb_read_randomopt(const char* basedir, bool silent) {
 	}
 	fclose(fp);
 
-	ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, path);
+	ShowStatus("Done reading '" CL_WHITE "%lu" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, path);
 
 	return true;
 }
@@ -1767,7 +1774,7 @@ static void itemdb_read(void) {
 	int i;
 	const char* dbsubpath[] = {
 		"",
-		"/"DBIMPORT,
+		"/" DBIMPORT,
 	};
 	
 	if (db_use_sqldbs)
@@ -1791,27 +1798,27 @@ static void itemdb_read(void) {
 			safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
 		}
 		
-		sv_readdb(dbsubpath1, "item_avail.txt",         ',', 2, 2, -1, &itemdb_read_itemavail, i);
-		sv_readdb(dbsubpath2, "item_stack.txt",         ',', 3, 3, -1, &itemdb_read_stack, i);
-		sv_readdb(dbsubpath1, "item_nouse.txt",         ',', 3, 3, -1, &itemdb_read_nouse, i);
-		sv_readdb(dbsubpath2, "item_group_db.txt",		',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath2, "item_bluebox.txt",		',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath2, "item_violetbox.txt",		',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath2, "item_cardalbum.txt",		',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath1, "item_findingore.txt",	',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath2, "item_giftbox.txt",		',', 2, 10, -1, &itemdb_read_group, i);
-		sv_readdb(dbsubpath2, "item_misc.txt",			',', 2, 10, -1, &itemdb_read_group, i);
+		sv_readdb(dbsubpath1, "item_avail.txt",         ',', 2, 2, -1, &itemdb_read_itemavail, i > 0);
+		sv_readdb(dbsubpath2, "item_stack.txt",         ',', 3, 3, -1, &itemdb_read_stack, i > 0);
+		sv_readdb(dbsubpath1, "item_nouse.txt",         ',', 3, 3, -1, &itemdb_read_nouse, i > 0);
+		sv_readdb(dbsubpath2, "item_group_db.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath2, "item_bluebox.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath2, "item_violetbox.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath2, "item_cardalbum.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath1, "item_findingore.txt",	',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath2, "item_giftbox.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
+		sv_readdb(dbsubpath2, "item_misc.txt",			',', 2, 10, -1, &itemdb_read_group, i > 0);
 #ifdef RENEWAL
-		sv_readdb(dbsubpath2, "item_package.txt",		',', 2, 10, -1, &itemdb_read_group, i);
+		sv_readdb(dbsubpath2, "item_package.txt",		',', 2, 10, -1, &itemdb_read_group, i > 0);
 #endif
-		itemdb_read_combos(dbsubpath2,i); //TODO change this to sv_read ? id#script ?
-		itemdb_read_randomopt(dbsubpath2, i);
-		sv_readdb(dbsubpath2, "item_noequip.txt",       ',', 2, 2, -1, &itemdb_read_noequip, i);
-		sv_readdb(dbsubpath2, "item_trade.txt",         ',', 3, 3, -1, &itemdb_read_itemtrade, i);
-		sv_readdb(dbsubpath2, "item_delay.txt",         ',', 2, 3, -1, &itemdb_read_itemdelay, i);
-		sv_readdb(dbsubpath2, "item_buyingstore.txt",   ',', 1, 1, -1, &itemdb_read_buyingstore, i);
-		sv_readdb(dbsubpath2, "item_flag.txt",          ',', 2, 2, -1, &itemdb_read_flag, i);
-		sv_readdb(dbsubpath2, "item_randomopt_group.txt", ',', 5, 2+5*MAX_ITEM_RDM_OPT, -1, &itemdb_read_randomopt_group, i);
+		itemdb_read_combos(dbsubpath2,i > 0); //TODO change this to sv_read ? id#script ?
+		itemdb_read_randomopt(dbsubpath2, i > 0);
+		sv_readdb(dbsubpath2, "item_noequip.txt",       ',', 2, 2, -1, &itemdb_read_noequip, i > 0);
+		sv_readdb(dbsubpath2, "item_trade.txt",         ',', 3, 3, -1, &itemdb_read_itemtrade, i > 0);
+		sv_readdb(dbsubpath2, "item_delay.txt",         ',', 2, 3, -1, &itemdb_read_itemdelay, i > 0);
+		sv_readdb(dbsubpath2, "item_buyingstore.txt",   ',', 1, 1, -1, &itemdb_read_buyingstore, i > 0);
+		sv_readdb(dbsubpath2, "item_flag.txt",          ',', 2, 2, -1, &itemdb_read_flag, i > 0);
+		sv_readdb(dbsubpath2, "item_randomopt_group.txt", ',', 5, 2+5*MAX_ITEM_RDM_OPT, -1, &itemdb_read_randomopt_group, i > 0);
 		aFree(dbsubpath1);
 		aFree(dbsubpath2);
 	}

+ 6 - 14
src/map/itemdb.h → src/map/itemdb.hpp

@@ -1,16 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _ITEMDB_H_
-#define _ITEMDB_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _ITEMDB_HPP_
+#define _ITEMDB_HPP_
 
 #include "../common/db.h"
 #include "../common/mmo.h" // ITEM_NAME_LENGTH
-#include "map.h"
 
 ///Maximum allowed Item ID (range: 1 ~ 65,534)
 #define MAX_ITEMID USHRT_MAX
@@ -785,12 +780,13 @@ struct s_item_group_db
 };
 
 /// Struct of Roulette db
-extern struct s_roulette_db {
+struct s_roulette_db {
 	unsigned short *nameid[MAX_ROULETTE_LEVEL], /// Item ID
 		           *qty[MAX_ROULETTE_LEVEL]; /// Amount of Item ID
 	int *flag[MAX_ROULETTE_LEVEL]; /// Whether the item is for loss or win
 	int items[MAX_ROULETTE_LEVEL]; /// Number of items in the list for each
-} rd;
+};
+extern struct s_roulette_db rd;
 
 ///Main item data struct
 struct item_data
@@ -964,8 +960,4 @@ void itemdb_reload(void);
 void do_final_itemdb(void);
 void do_init_itemdb(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ITEMDB_H_ */
+#endif /* _ITEMDB_HPP_ */

+ 19 - 17
src/map/log.c → src/map/log.cpp

@@ -1,21 +1,23 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "log.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/sql.h" // SQL_INNODB
 #include "../common/strlib.h"
 #include "../common/nullpo.h"
 #include "../common/showmsg.h"
-#include "map.h"
-#include "battle.h"
-#include "itemdb.h"
-#include "homunculus.h"
-#include "log.h"
-#include "mob.h"
-#include "pet.h"
-#include "pc.h"
 
-#include <stdlib.h>
+#include "map.hpp"
+#include "battle.hpp"
+#include "itemdb.hpp"
+#include "homunculus.hpp"
+#include "mob.hpp"
+#include "pet.hpp"
+#include "pc.hpp"
 
 static char log_timestamp_format[20];
 
@@ -219,11 +221,11 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
 #ifdef BETA_THREAD_TEST
 		char entry[512];
 		int e_length = 0;
-		e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
+		e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%" PRIu64 "', '%d')",
 				log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound);
 		queryThread_log(entry,e_length);
 #else
-		if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
+		if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%" PRIu64 "', '%d')",
 			log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound) )
 		{
 			Sql_ShowDebug(logmysql_handle);
@@ -241,7 +243,7 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
 			return;
 		time(&curtime);
 		strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
-		fprintf(logfp,"%s - %d\t%c\t%hu,%d,%d,%hu,%hu,%hu,%hu,%s,'%"PRIu64"',%d\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound);
+		fprintf(logfp,"%s - %d\t%c\t%hu,%d,%d,%hu,%hu,%hu,%hu,%s,'%" PRIu64 "',%d\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound);
 		fclose(logfp);
 	}
 }
@@ -559,11 +561,11 @@ void log_feeding(struct map_session_data *sd, e_log_feeding_type type, unsigned
 #ifdef BETA_THREAD_TEST
 		char entry[512];
 		int e_length = 0;
-		e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%"PRIu32"', '%"PRIu32"', '%hu', '%c', '%"PRIu32"', '%hu', '%s', '%hu', '%hu' )",
+		e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%" PRIu32 "', '%" PRIu32 "', '%hu', '%c', '%" PRIu32 "', '%hu', '%s', '%hu', '%hu' )",
 			log_config.log_feeding, sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y);
 		queryThread_log(entry, e_length);
 #else
-		if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%"PRIu32"', '%"PRIu32"', '%hu', '%c', '%"PRIu32"', '%hu', '%s', '%hu', '%hu' )",
+		if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%" PRIu32 "', '%" PRIu32 "', '%hu', '%c', '%" PRIu32 "', '%hu', '%s', '%hu', '%hu' )",
 			log_config.log_feeding, sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y))
 		{
 			Sql_ShowDebug(logmysql_handle);
@@ -623,7 +625,7 @@ int log_config_read(const char* cfgName)
 			if( strcmpi(w1, "enable_logs") == 0 )
 				log_config.enable_logs = (e_log_pick_type)config_switch(w2);
 			else if( strcmpi(w1, "sql_logs") == 0 )
-				log_config.sql_logs = (bool)config_switch(w2);
+				log_config.sql_logs = config_switch(w2) > 0;
 //start of common filter settings
 			else if( strcmpi(w1, "rare_items_log") == 0 )
 				log_config.rare_items_log = atoi(w2);
@@ -641,7 +643,7 @@ int log_config_read(const char* cfgName)
 			else if( strcmpi(w1, "log_zeny") == 0 )
 				log_config.zeny = config_switch(w2);
 			else if( strcmpi( w1, "log_cash" ) == 0 )
-				log_config.cash = config_switch( w2 );
+				log_config.cash = config_switch( w2 ) > 0;
 			else if( strcmpi(w1, "log_commands") == 0 )
 				log_config.commands = config_switch(w2);
 			else if( strcmpi(w1, "log_npc") == 0 )
@@ -653,7 +655,7 @@ int log_config_read(const char* cfgName)
 			else if( strcmpi(w1, "log_feeding") == 0 )
 				log_config.feeding = config_switch(w2);
 			else if( strcmpi(w1, "log_chat_woe_disable") == 0 )
-				log_config.log_chat_woe_disable = (bool)config_switch(w2);
+				log_config.log_chat_woe_disable = config_switch(w2) > 0;
 			else if( strcmpi(w1, "log_branch_db") == 0 )
 				safestrncpy(log_config.log_branch, w2, sizeof(log_config.log_branch));
 			else if( strcmpi(w1, "log_pick_db") == 0 )

+ 13 - 19
src/map/log.h → src/map/log.hpp

@@ -1,20 +1,17 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef _LOG_HPP_
+#define _LOG_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
-//#include "map.h"
 struct block_list;
 struct map_session_data;
 struct mob_data;
 struct item;
 
-typedef enum e_log_chat_type
+enum e_log_chat_type : uint8
 {
 	LOG_CHAT_GLOBAL      = 0x01,
 	LOG_CHAT_WHISPER     = 0x02,
@@ -24,9 +21,9 @@ typedef enum e_log_chat_type
 	LOG_CHAT_CLAN        = 0x20,
 	// all
 	LOG_CHAT_ALL         = 0xFF,
-} e_log_chat_type;
+};
 
-typedef enum e_log_pick_type
+enum e_log_pick_type : uint32
 {
 	LOG_TYPE_NONE             = 0,
 	LOG_TYPE_TRADE            = 0x000001,
@@ -56,18 +53,19 @@ typedef enum e_log_pick_type
 	LOG_TYPE_LOOT             = LOG_TYPE_PICKDROP_MONSTER|LOG_TYPE_CONSUME,
 	// all
 	LOG_TYPE_ALL              = 0xFFFFFF,
-} e_log_pick_type;
+};
 
-typedef enum e_log_cash_type
+enum e_log_cash_type : uint8
 {
 	LOG_CASH_TYPE_CASH = 0x1,
 	LOG_CASH_TYPE_KAFRA = 0x2
-} e_log_cash_type;
+};
 
-typedef enum e_log_feeding_type {
+enum e_log_feeding_type : uint8 
+{
 	LOG_FEED_HOMUNCULUS = 0x1,
 	LOG_FEED_PET        = 0x2,
-} e_log_feeding_type;
+};
 
 /// new logs
 void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount, struct item* itm);
@@ -106,8 +104,4 @@ extern struct Log_Config
 	} logThreadData;
 #endif
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LOG_H_ */
+#endif /* _LOG_HPP_ */

+ 12 - 8
src/map/mail.c → src/map/mail.cpp

@@ -1,17 +1,21 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "mail.hpp"
+
 #include "../common/nullpo.h"
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
+#include "../common/timer.h"
 
-#include "mail.h"
-#include "atcommand.h"
-#include "itemdb.h"
-#include "clif.h"
-#include "pc.h"
-#include "intif.h"
-#include "date.h" // date_get_dayofyear
+#include "atcommand.hpp"
+#include "itemdb.hpp"
+#include "clif.hpp"
+#include "pc.hpp"
+#include "intif.hpp"
+#include "date.hpp" // date_get_dayofyear
+#include "log.hpp"
+#include "battle.hpp"
 
 void mail_clear(struct map_session_data *sd)
 {
@@ -110,7 +114,7 @@ bool mail_removezeny( struct map_session_data *sd, bool flag ){
 * @param sd : player attaching the content
 * @param idx 0 - Zeny; >= 2 - Inventory item
 * @param amount : amout of zeny or number of item
-* @return see enum mail_attach_result in mail.h
+* @return see enum mail_attach_result in mail.hpp
 */
 enum mail_attach_result mail_setitem(struct map_session_data *sd, short idx, uint32 amount) {
 	if( pc_istrading(sd) )

+ 3 - 11
src/map/mail.h → src/map/mail.hpp

@@ -1,12 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _MAIL_H_
-#define _MAIL_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _MAIL_HPP_
+#define _MAIL_HPP_
 
 #include "../common/mmo.h"
 
@@ -37,8 +33,4 @@ bool mail_invalid_operation(struct map_session_data *sd);
 void mail_send(struct map_session_data *sd, const char *dest_name, const char *title, const char *body_msg, int body_len);
 void mail_refresh_remaining_amount( struct map_session_data* sd );
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MAIL_H_ */
+#endif /* _MAIL_HPP_ */

+ 84 - 80
src/map/map-server.vcxproj

@@ -94,6 +94,7 @@
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>$(DefineConstants);WIN32;FD_SETSIZE=4096;PCRE_SUPPORT;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;LIBCONFIG_STATIC;YY_USE_CONST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <AdditionalIncludeDirectories>$(SolutionDir)3rdparty\yaml-cpp\include\</AdditionalIncludeDirectories>
       <DisableSpecificWarnings>4018</DisableSpecificWarnings>
     </ClCompile>
     <Link>
@@ -110,6 +111,7 @@
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>$(DefineConstants);WIN32;FD_SETSIZE=4096;PCRE_SUPPORT;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;LIBCONFIG_STATIC;YY_USE_CONST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <AdditionalIncludeDirectories>$(SolutionDir)3rdparty\yaml-cpp\include\</AdditionalIncludeDirectories>
       <DisableSpecificWarnings>4018</DisableSpecificWarnings>
     </ClCompile>
     <Link>
@@ -128,6 +130,7 @@
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>$(DefineConstants);WIN32;FD_SETSIZE=4096;PCRE_SUPPORT;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;LIBCONFIG_STATIC;YY_USE_CONST;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <AdditionalIncludeDirectories>$(SolutionDir)3rdparty\yaml-cpp\include\</AdditionalIncludeDirectories>
       <DisableSpecificWarnings>4018</DisableSpecificWarnings>
     </ClCompile>
     <Link>
@@ -148,6 +151,7 @@
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>$(DefineConstants);WIN32;FD_SETSIZE=4096;PCRE_SUPPORT;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;LIBCONFIG_STATIC;YY_USE_CONST;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <AdditionalIncludeDirectories>$(SolutionDir)3rdparty\yaml-cpp\include\</AdditionalIncludeDirectories>
       <DisableSpecificWarnings>4018</DisableSpecificWarnings>
     </ClCompile>
     <Link>
@@ -159,93 +163,93 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="achievement.h" />
-    <ClInclude Include="atcommand.h" />
-    <ClInclude Include="battle.h" />
-    <ClInclude Include="battleground.h" />
-    <ClInclude Include="buyingstore.h" />
-    <ClInclude Include="cashshop.h" />
-    <ClInclude Include="channel.h" />
-    <ClInclude Include="chat.h" />
-    <ClInclude Include="chrif.h" />
-    <ClInclude Include="clan.h" />
-    <ClInclude Include="clif.h" />
-    <ClInclude Include="clif_obfuscation.h" />
-    <ClInclude Include="clif_packetdb.h" />
-    <ClInclude Include="clif_shuffle.h" />
-    <ClInclude Include="date.h" />
-    <ClInclude Include="duel.h" />
-    <ClInclude Include="elemental.h" />
-    <ClInclude Include="guild.h" />
-    <ClInclude Include="homunculus.h" />
-    <ClInclude Include="instance.h" />
-    <ClInclude Include="intif.h" />
-    <ClInclude Include="itemdb.h" />
-    <ClInclude Include="log.h" />
-    <ClInclude Include="mail.h" />
-    <ClInclude Include="map.h" />
-    <ClInclude Include="mapreg.h" />
-    <ClInclude Include="mercenary.h" />
-    <ClInclude Include="mob.h" />
-    <ClInclude Include="npc.h" />
-    <ClInclude Include="party.h" />
-    <ClInclude Include="path.h" />
-    <ClInclude Include="pc.h" />
-    <ClInclude Include="pc_groups.h" />
-    <ClInclude Include="pet.h" />
-    <ClInclude Include="quest.h" />
-    <ClInclude Include="script.h" />
-    <ClInclude Include="script_constants.h" />
-    <ClInclude Include="searchstore.h" />
-    <ClInclude Include="skill.h" />
-    <ClInclude Include="status.h" />
-    <ClInclude Include="storage.h" />
-    <ClInclude Include="trade.h" />
-    <ClInclude Include="unit.h" />
-    <ClInclude Include="vending.h" />
+    <ClInclude Include="achievement.hpp" />
+    <ClInclude Include="atcommand.hpp" />
+    <ClInclude Include="battle.hpp" />
+    <ClInclude Include="battleground.hpp" />
+    <ClInclude Include="buyingstore.hpp" />
+    <ClInclude Include="cashshop.hpp" />
+    <ClInclude Include="channel.hpp" />
+    <ClInclude Include="chat.hpp" />
+    <ClInclude Include="chrif.hpp" />
+    <ClInclude Include="clan.hpp" />
+    <ClInclude Include="clif.hpp" />
+    <ClInclude Include="clif_obfuscation.hpp" />
+    <ClInclude Include="clif_packetdb.hpp" />
+    <ClInclude Include="clif_shuffle.hpp" />
+    <ClInclude Include="date.hpp" />
+    <ClInclude Include="duel.hpp" />
+    <ClInclude Include="elemental.hpp" />
+    <ClInclude Include="guild.hpp" />
+    <ClInclude Include="homunculus.hpp" />
+    <ClInclude Include="instance.hpp" />
+    <ClInclude Include="intif.hpp" />
+    <ClInclude Include="itemdb.hpp" />
+    <ClInclude Include="log.hpp" />
+    <ClInclude Include="mail.hpp" />
+    <ClInclude Include="map.hpp" />
+    <ClInclude Include="mapreg.hpp" />
+    <ClInclude Include="mercenary.hpp" />
+    <ClInclude Include="mob.hpp" />
+    <ClInclude Include="npc.hpp" />
+    <ClInclude Include="party.hpp" />
+    <ClInclude Include="path.hpp" />
+    <ClInclude Include="pc.hpp" />
+    <ClInclude Include="pc_groups.hpp" />
+    <ClInclude Include="pet.hpp" />
+    <ClInclude Include="quest.hpp" />
+    <ClInclude Include="script.hpp" />
+    <ClInclude Include="script_constants.hpp" />
+    <ClInclude Include="searchstore.hpp" />
+    <ClInclude Include="skill.hpp" />
+    <ClInclude Include="status.hpp" />
+    <ClInclude Include="storage.hpp" />
+    <ClInclude Include="trade.hpp" />
+    <ClInclude Include="unit.hpp" />
+    <ClInclude Include="vending.hpp" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="achievement.c" />
-    <ClCompile Include="atcommand.c" />
-    <ClCompile Include="battle.c" />
-    <ClCompile Include="battleground.c" />
-    <ClCompile Include="buyingstore.c" />
-    <ClCompile Include="cashshop.c" />
-    <ClCompile Include="channel.c" />
-    <ClCompile Include="chat.c" />
-    <ClCompile Include="chrif.c" />
-    <ClCompile Include="clan.c" />
+    <ClCompile Include="achievement.cpp" />
+    <ClCompile Include="atcommand.cpp" />
+    <ClCompile Include="battle.cpp" />
+    <ClCompile Include="battleground.cpp" />
+    <ClCompile Include="buyingstore.cpp" />
+    <ClCompile Include="cashshop.cpp" />
+    <ClCompile Include="channel.cpp" />
+    <ClCompile Include="chat.cpp" />
+    <ClCompile Include="chrif.cpp" />
+    <ClCompile Include="clan.cpp" />
     <ClCompile Include="clif.cpp" />
-    <ClCompile Include="date.c" />
-    <ClCompile Include="duel.c" />
-    <ClCompile Include="elemental.c" />
-    <ClCompile Include="guild.c" />
-    <ClCompile Include="homunculus.c" />
-    <ClCompile Include="instance.c" />
-    <ClCompile Include="intif.c" />
-    <ClCompile Include="itemdb.c" />
-    <ClCompile Include="log.c" />
-    <ClCompile Include="mail.c" />
+    <ClCompile Include="date.cpp" />
+    <ClCompile Include="duel.cpp" />
+    <ClCompile Include="elemental.cpp" />
+    <ClCompile Include="guild.cpp" />
+    <ClCompile Include="homunculus.cpp" />
+    <ClCompile Include="instance.cpp" />
+    <ClCompile Include="intif.cpp" />
+    <ClCompile Include="itemdb.cpp" />
+    <ClCompile Include="log.cpp" />
+    <ClCompile Include="mail.cpp" />
     <ClCompile Include="map.cpp" />
-    <ClCompile Include="mapreg.c" />
-    <ClCompile Include="mercenary.c" />
+    <ClCompile Include="mapreg.cpp" />
+    <ClCompile Include="mercenary.cpp" />
     <ClCompile Include="mob.cpp" />
-    <ClCompile Include="npc.c" />
-    <ClCompile Include="npc_chat.c" />
-    <ClCompile Include="party.c" />
-    <ClCompile Include="path.c" />
-    <ClCompile Include="pc.c" />
-    <ClCompile Include="pc_groups.c" />
-    <ClCompile Include="pet.c" />
-    <ClCompile Include="quest.c" />
+    <ClCompile Include="npc.cpp" />
+    <ClCompile Include="npc_chat.cpp" />
+    <ClCompile Include="party.cpp" />
+    <ClCompile Include="path.cpp" />
+    <ClCompile Include="pc.cpp" />
+    <ClCompile Include="pc_groups.cpp" />
+    <ClCompile Include="pet.cpp" />
+    <ClCompile Include="quest.cpp" />
     <ClCompile Include="script.cpp" />
-    <ClCompile Include="searchstore.c" />
+    <ClCompile Include="searchstore.cpp" />
     <ClCompile Include="skill.cpp" />
-    <ClCompile Include="status.c" />
-    <ClCompile Include="storage.c" />
-    <ClCompile Include="trade.c" />
-    <ClCompile Include="unit.c" />
-    <ClCompile Include="vending.c" />
+    <ClCompile Include="status.cpp" />
+    <ClCompile Include="storage.cpp" />
+    <ClCompile Include="trade.cpp" />
+    <ClCompile Include="unit.cpp" />
+    <ClCompile Include="vending.cpp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 80 - 80
src/map/map-server.vcxproj.filters

@@ -11,261 +11,261 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="achievement.h">
+    <ClInclude Include="achievement.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="atcommand.h">
+    <ClInclude Include="atcommand.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="battle.h">
+    <ClInclude Include="battle.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="battleground.h">
+    <ClInclude Include="battleground.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="buyingstore.h">
+    <ClInclude Include="buyingstore.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="cashshop.h">
+    <ClInclude Include="cashshop.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="channel.h">
+    <ClInclude Include="channel.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="chat.h">
+    <ClInclude Include="chat.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="chrif.h">
+    <ClInclude Include="chrif.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="clan.h">
+    <ClInclude Include="clan.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="clif.h">
+    <ClInclude Include="clif.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="clif_obfuscation.h">
+    <ClInclude Include="clif_obfuscation.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="clif_packetdb.h">
+    <ClInclude Include="clif_packetdb.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="clif_shuffle.h">
+    <ClInclude Include="clif_shuffle.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="date.h">
+    <ClInclude Include="date.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="duel.h">
+    <ClInclude Include="duel.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="elemental.h">
+    <ClInclude Include="elemental.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="guild.h">
+    <ClInclude Include="guild.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="homunculus.h">
+    <ClInclude Include="homunculus.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="instance.h">
+    <ClInclude Include="instance.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="intif.h">
+    <ClInclude Include="intif.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="itemdb.h">
+    <ClInclude Include="itemdb.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="log.h">
+    <ClInclude Include="log.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="mail.h">
+    <ClInclude Include="mail.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="map.h">
+    <ClInclude Include="map.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="mapreg.h">
+    <ClInclude Include="mapreg.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="mercenary.h">
+    <ClInclude Include="mercenary.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="mob.h">
+    <ClInclude Include="mob.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="npc.h">
+    <ClInclude Include="npc.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="party.h">
+    <ClInclude Include="party.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="path.h">
+    <ClInclude Include="path.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="pc.h">
+    <ClInclude Include="pc.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="pc_groups.h">
+    <ClInclude Include="pc_groups.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="pet.h">
+    <ClInclude Include="pet.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="quest.h">
+    <ClInclude Include="quest.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="script.h">
+    <ClInclude Include="script.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="script_constants.h">
+    <ClInclude Include="script_constants.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="searchstore.h">
+    <ClInclude Include="searchstore.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="skill.h">
+    <ClInclude Include="skill.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="status.h">
+    <ClInclude Include="status.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="storage.h">
+    <ClInclude Include="storage.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="trade.h">
+    <ClInclude Include="trade.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="unit.h">
+    <ClInclude Include="unit.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="vending.h">
+    <ClInclude Include="vending.hpp">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="achievement.c">
+    <ClCompile Include="achievement.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="atcommand.c">
+    <ClCompile Include="atcommand.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="battle.c">
+    <ClCompile Include="battle.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="battleground.c">
+    <ClCompile Include="battleground.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="buyingstore.c">
+    <ClCompile Include="buyingstore.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="cashshop.c">
+    <ClCompile Include="cashshop.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="channel.c">
+    <ClCompile Include="channel.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="chat.c">
+    <ClCompile Include="chat.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="chrif.c">
+    <ClCompile Include="chrif.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="clan.c">
+    <ClCompile Include="clan.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="clif.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="date.c">
+    <ClCompile Include="date.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="duel.c">
+    <ClCompile Include="duel.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="elemental.c">
+    <ClCompile Include="elemental.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="guild.c">
+    <ClCompile Include="guild.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="homunculus.c">
+    <ClCompile Include="homunculus.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="instance.c">
+    <ClCompile Include="instance.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="intif.c">
+    <ClCompile Include="intif.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="itemdb.c">
+    <ClCompile Include="itemdb.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="log.c">
+    <ClCompile Include="log.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="mail.c">
+    <ClCompile Include="mail.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="map.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="mapreg.c">
+    <ClCompile Include="mapreg.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="mercenary.c">
+    <ClCompile Include="mercenary.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="mob.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="npc.c">
+    <ClCompile Include="npc.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="npc_chat.c">
+    <ClCompile Include="npc_chat.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="party.c">
+    <ClCompile Include="party.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="path.c">
+    <ClCompile Include="path.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="pc.c">
+    <ClCompile Include="pc.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="pc_groups.c">
+    <ClCompile Include="pc_groups.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="pet.c">
+    <ClCompile Include="pet.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="quest.c">
+    <ClCompile Include="quest.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="script.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="searchstore.c">
+    <ClCompile Include="searchstore.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="skill.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="status.c">
+    <ClCompile Include="status.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="storage.c">
+    <ClCompile Include="storage.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="trade.c">
+    <ClCompile Include="trade.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="unit.c">
+    <ClCompile Include="unit.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="vending.c">
+    <ClCompile Include="vending.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>

+ 33 - 36
src/map/map.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "map.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/core.h"
 #include "../common/timer.h"
@@ -15,39 +20,34 @@
 #include "../common/cli.h"
 #include "../common/ers.h"
 
-#include "map.h"
-#include "path.h"
-#include "chrif.h"
-#include "clan.h"
-#include "clif.h"
-#include "duel.h"
-#include "intif.h"
-#include "npc.h"
-#include "pc.h"
-#include "chat.h"
-#include "storage.h"
-#include "trade.h"
-#include "party.h"
-#include "battleground.h"
-#include "quest.h"
-#include "mapreg.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "cashshop.h"
-#include "channel.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-#include <math.h>
-#ifndef _WIN32
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "path.hpp"
+#include "chrif.hpp"
+#include "clan.hpp"
+#include "clif.hpp"
+#include "duel.hpp"
+#include "intif.hpp"
+#include "npc.hpp"
+#include "pc.hpp"
+#include "chat.hpp"
+#include "storage.hpp"
+#include "trade.hpp"
+#include "party.hpp"
+#include "battleground.hpp"
+#include "quest.hpp"
+#include "mapreg.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "instance.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "cashshop.hpp"
+#include "channel.hpp"
+#include "achievement.hpp"
+#include "guild.hpp"
+#include "atcommand.hpp"
+#include "battle.hpp"
+#include "log.hpp"
+#include "mob.hpp"
 
 char default_codepage[32] = "";
 
@@ -4781,6 +4781,3 @@ int do_init(int argc, char *argv[])
 	return 0;
 }
 
-#ifdef __cplusplus
-}
-#endif

+ 25 - 30
src/map/map.h → src/map/map.hpp

@@ -1,12 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _MAP_H_
-#define _MAP_H_
+#ifndef _MAP_HPP_
+#define _MAP_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <stdarg.h>
 
 #include "../common/cbasetypes.h"
 #include "../common/core.h" // CORE_ST_LAST
@@ -17,7 +15,17 @@ extern "C" {
 
 #include "../config/core.h"
 
-#include <stdarg.h>
+extern "C" {
+	//Options read in cli (c-linkage for now)
+	extern const char*INTER_CONF_NAME;
+	extern const char*LOG_CONF_NAME;
+	extern const char*MAP_CONF_NAME;
+	extern const char*BATTLE_CONF_FILENAME;
+	extern const char*ATCOMMAND_CONF_FILENAME;
+	extern const char*SCRIPT_CONF_NAME;
+	extern const char*MSG_CONF_NAME_EN;
+	extern const char*GRF_PATH_FILENAME;
+}
 
 struct npc_data;
 struct item_data;
@@ -244,7 +252,7 @@ enum e_mapid {
 
 //This stackable implementation does not means a BL can be more than one type at a time, but it's
 //meant to make it easier to check for multiple types at a time on invocations such as map_foreach* calls [Skotlex]
-enum bl_type {
+enum bl_type : uint16{
 	BL_NUL   = 0x000,
 	BL_PC    = 0x001,
 	BL_MOB   = 0x002,
@@ -264,7 +272,7 @@ enum bl_type {
 #define BL_CHAR (BL_PC|BL_MOB|BL_HOM|BL_MER|BL_ELEM)
 
 /// NPC Subtype
-enum npc_subtype {
+enum npc_subtype : uint8{
 	NPCTYPE_WARP, /// Warp
 	NPCTYPE_SHOP, /// Shop
 	NPCTYPE_SCRIPT, /// Script
@@ -275,7 +283,7 @@ enum npc_subtype {
 	NPCTYPE_MARKETSHOP, /// Marketshop
 };
 
-enum e_race {
+enum e_race : int8{
 	RC_NONE_ = -1, //don't give us bonus
 	RC_FORMLESS = 0,
 	RC_UNDEAD,
@@ -292,7 +300,7 @@ enum e_race {
 	RC_MAX //auto upd enum for array size
 };
 
-enum e_classAE {
+enum e_classAE : int8{
 	CLASS_NONE = -1, //don't give us bonus
 	CLASS_NORMAL = 0,
 	CLASS_BOSS,
@@ -302,7 +310,7 @@ enum e_classAE {
 	CLASS_MAX //auto upd enum for array len
 };
 
-enum e_race2 {
+enum e_race2 : uint8{
 	RC2_NONE = 0,
 	RC2_GOBLIN,
 	RC2_KOBOLD,
@@ -321,7 +329,7 @@ enum e_race2 {
 };
 
 /// Element list
-enum e_element {
+enum e_element : int8{
 	ELE_NONE=-1,
 	ELE_NEUTRAL=0,
 	ELE_WATER,
@@ -509,7 +517,7 @@ enum _look {
 };
 
 // used by map_setcell()
-typedef enum {
+enum cell_t{
 	CELL_WALKABLE,
 	CELL_SHOOTABLE,
 	CELL_WATER,
@@ -522,10 +530,10 @@ typedef enum {
 	CELL_MAELSTROM,
 	CELL_ICEWALL,
 
-} cell_t;
+};
 
 // used by map_getcell()
-typedef enum {
+enum cell_chk : uint8 {
 	CELL_GETTYPE,			// Retrieves a cell's 'gat' type
 
 	CELL_CHKWALL,			// Whether the cell is a wall (gat type 1)
@@ -546,7 +554,7 @@ typedef enum {
 	CELL_CHKMAELSTROM,		// Whether the cell has Maelstrom
 	CELL_CHKICEWALL,		// Whether the cell has Ice Wall
 
-} cell_chk;
+};
 
 struct mapcell
 {
@@ -930,15 +938,6 @@ void map_skill_damage_add(struct map_data *m, uint16 skill_id, int pc, int mob,
 #define CHK_RACE2(race2) ((race2) >= RC2_NONE && (race2) < RC2_MAX) /// Check valid Race2
 #define CHK_CLASS(class_) ((class_) > CLASS_NONE && (class_) < CLASS_MAX) /// Check valid Class
 
-//Options read in cli
-extern const char*INTER_CONF_NAME;
-extern const char*LOG_CONF_NAME;
-extern const char*MAP_CONF_NAME;
-extern const char*BATTLE_CONF_FILENAME;
-extern const char*ATCOMMAND_CONF_FILENAME;
-extern const char*SCRIPT_CONF_NAME;
-extern const char*MSG_CONF_NAME_EN;
-extern const char*GRF_PATH_FILENAME;
 //Other languages supported
 extern const char*MSG_CONF_NAME_RUS;
 extern const char*MSG_CONF_NAME_SPN;
@@ -1006,8 +1005,4 @@ extern char roulette_table[32];
 
 void do_shutdown(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MAP_H_ */
+#endif /* _MAP_HPP_ */

+ 12 - 11
src/map/mapreg.c → src/map/mapreg.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "mapreg.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/db.h"
 #include "../common/ers.h"
@@ -10,11 +14,8 @@
 #include "../common/strlib.h"
 #include "../common/timer.h"
 
-#include "map.h" // mmysql_handle
-#include "mapreg.h"
-#include "script.h"
-
-#include <stdlib.h>
+#include "map.hpp" // mmysql_handle
+#include "script.hpp"
 
 static struct eri *mapreg_ers;
 
@@ -66,7 +67,7 @@ bool mapreg_setreg(int64 uid, int val)
 	const char* name = get_str(num);
 
 	if (val != 0) {
-		if ((m = i64db_get(regs.vars, uid))) {
+		if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) {
 			m->u.i = val;
 			if (name[1] != '@') {
 				m->save = true;
@@ -94,7 +95,7 @@ bool mapreg_setreg(int64 uid, int val)
 	} else { // val == 0
 		if (i)
 			script_array_update(&regs, uid, true);
-		if ((m = i64db_get(regs.vars, uid))) {
+		if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) {
 			ers_free(mapreg_ers, m);
 		}
 		i64db_remove(regs.vars, uid);
@@ -133,14 +134,14 @@ bool mapreg_setregstr(int64 uid, const char* str)
 			if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, esc_name, i))
 				Sql_ShowDebug(mmysql_handle);
 		}
-		if ((m = i64db_get(regs.vars, uid))) {
+		if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) {
 			if (m->u.str != NULL)
 				aFree(m->u.str);
 			ers_free(mapreg_ers, m);
 		}
 		i64db_remove(regs.vars, uid);
 	} else {
-		if ((m = i64db_get(regs.vars, uid))) {
+		if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) {
 			if (m->u.str != NULL)
 				aFree(m->u.str);
 			m->u.str = aStrdup(str);
@@ -234,7 +235,7 @@ static void script_save_mapreg(void)
 	if (mapreg_dirty) {
 		DBIterator *iter = db_iterator(regs.vars);
 		struct mapreg_save *m;
-		for (m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter)) {
+		for (m = static_cast<mapreg_save *>(dbi_first(iter)); dbi_exists(iter); m = static_cast<mapreg_save *>(dbi_next(iter))) {
 			if (m->save) {
 				int num = script_getvarid(m->uid);
 				int i = script_getvaridx(m->uid);
@@ -281,7 +282,7 @@ int mapreg_destroyreg(DBKey key, DBData *data, va_list ap)
 	if (data->type != DB_DATA_PTR) // Sanity check
 		return 0;
 
-	m = db_data2ptr(data);
+	m = static_cast<mapreg_save *>(db_data2ptr(data));
 
 	if (m->is_string) {
 		if (m->u.str)

+ 5 - 12
src/map/mapreg.h → src/map/mapreg.hpp

@@ -1,14 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _MAPREG_H_
-#define _MAPREG_H_
+#ifndef _MAPREG_HPP_
+#define _MAPREG_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "script.h"
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
 
 struct mapreg_save {
 	int64 uid;         ///< Unique ID
@@ -34,8 +31,4 @@ bool mapreg_setreg(int64 uid, int val);
 bool mapreg_setregstr(int64 uid, const char* str);
 int mapreg_destroyreg(DBKey key, DBData *data, va_list ap);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MAPREG_H_ */
+#endif /* _MAPREG_HPP_ */

+ 15 - 13
src/map/mercenary.c → src/map/mercenary.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "mercenary.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/timer.h"
@@ -11,17 +16,14 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 
-#include "log.h"
-#include "clif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "pc.h"
-#include "party.h"
-#include "trade.h"
-#include "mercenary.h"
-
-#include <stdlib.h>
-#include <math.h>
+#include "log.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "itemdb.hpp"
+#include "pc.hpp"
+#include "party.hpp"
+#include "trade.hpp"
+#include "npc.hpp"
 
 struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; // Mercenary Database
 static uint16 mercenary_count;
@@ -547,7 +549,7 @@ void mercenary_readdb(void) {
 	mercenary_count = 0; //Reset the counter
 	memset(mercenary_db,0,sizeof(mercenary_db));
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 26, 26, MAX_MERCENARY_CLASS, &mercenary_readdb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 26, 26, MAX_MERCENARY_CLASS, &mercenary_readdb_sub, i > 0);
 	}
 }
 
@@ -592,7 +594,7 @@ void mercenary_read_skilldb(void){
 	uint8 i;
 
 	for(i = 0; i<ARRAYLENGTH(filename); i++){
-		sv_readdb(db_path, filename[i], ',', 3, 3, -1, &mercenary_read_skilldb_sub, i);
+		sv_readdb(db_path, filename[i], ',', 3, 3, -1, &mercenary_read_skilldb_sub, i > 0);
 	}
 }
 

+ 7 - 13
src/map/mercenary.h → src/map/mercenary.hpp

@@ -1,20 +1,18 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _MERCENARY_H_
-#define _MERCENARY_H_
+#ifndef _MERCENARY_HPP_
+#define _MERCENARY_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
-#include "status.h" // struct status_data, struct status_change
-#include "unit.h" // struct unit_data
+#include "status.hpp" // struct status_data, struct status_change
+#include "unit.hpp" // struct unit_data
 
 // number of cells that a mercenary can walk to from it's master before being warped
 #define MAX_MER_DISTANCE 15
 
-enum {
+enum e_MercGuildType {
 	ARCH_MERC_GUILD,
 	SPEAR_MERC_GUILD,
 	SWORD_MERC_GUILD,
@@ -86,8 +84,4 @@ void mercenary_read_skilldb(void);
 void do_init_mercenary(void);
 void do_final_mercenary(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MERCENARY_H_ */
+#endif /* _MERCENARY_HPP_ */

+ 21 - 24
src/map/mob.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "mob.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/db.h"
@@ -13,25 +18,22 @@
 #include "../common/utils.h"
 #include "../common/socket.h"
 
-#include "map.h"
-#include "path.h"
-#include "clif.h"
-#include "intif.h"
-#include "pc.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "party.h"
-#include "quest.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-#include <math.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "map.hpp"
+#include "path.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "pc.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "party.hpp"
+#include "quest.hpp"
+#include "npc.hpp"
+#include "guild.hpp"
+#include "battle.hpp"
+#include "log.hpp"
+#include "achievement.hpp"
 
 #define ACTIVE_AI_RANGE 2	//Distance added on top of 'AREA_SIZE' at which mobs enter active AI mode.
 
@@ -5380,8 +5382,3 @@ void do_final_mob(bool is_reload){
 		ers_destroy(item_drop_list_ers);
 	}
 }
-
-#ifdef __cplusplus
-}
-#endif
-

+ 10 - 18
src/map/mob.h → src/map/mob.hpp

@@ -1,19 +1,15 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _MOB_H_
-#define _MOB_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _MOB_HPP_
+#define _MOB_HPP_
 
 #include "../common/mmo.h" // struct item
-#include "guild.h" // struct guardian_data
-#include "map.h" // struct status_data, struct view_data, struct mob_skill
-#include "status.h" // struct status data, struct status_change
-#include "unit.h" // unit_stop_walking(), unit_stop_attack()
-#include "npc.h"
+
+#include "status.hpp" // struct status data, struct status_change
+#include "unit.hpp" // unit_stop_walking(), unit_stop_attack()
+
+struct guardian_data;
 
 // Change this to increase the table size in your mob_db to accomodate a larger mob database.
 // Be sure to note that IDs 4001 to 4048 are reserved for advanced/baby/expanded classes.
@@ -178,12 +174,12 @@ struct mob_data {
 	struct status_change sc;
 	struct mob_db *db;	//For quick data access (saves doing mob_db(md->mob_id) all the time) [Skotlex]
 	char name[NAME_LENGTH];
-	struct {
+	struct s_specialState {
 		unsigned int size : 2; //Small/Big monsters.
 		enum mob_ai ai; //Special ai for summoned monsters.
 		unsigned int clone : 1;/* is clone? 1:0 */
 	} special_state; //Special mob information that does not needs to be zero'ed on mob respawn.
-	struct {
+	struct s_MobState {
 		unsigned int aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex]
 		unsigned int steal_coin_flag : 1;
 		unsigned int soul_change_flag : 1; // Celest
@@ -371,8 +367,4 @@ void mob_setdropitem_option(struct item *itm, struct s_mob_drop *mobdrop);
 
 #define CHK_MOBSIZE(size) ((size) >= SZ_SMALL && (size) < SZ_MAX) /// Check valid Monster Size
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MOB_H_ */
+#endif /* _MOB_HPP_ */

+ 46 - 40
src/map/npc.c → src/map/npc.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "npc.hpp"
+
+#include <stdlib.h>
+#include <errno.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -10,20 +15,21 @@
 #include "../common/utils.h"
 #include "../common/ers.h"
 #include "../common/db.h"
-#include "map.h"
-#include "log.h"
-#include "clif.h"
-#include "date.h" // days of week enum
-#include "intif.h"
-#include "pc.h"
-#include "pet.h"
-#include "instance.h"
-#include "chat.h"
-#include "script.h" // script_config
-
-#include <stdlib.h>
-#include <errno.h>
 
+#include "map.hpp"
+#include "log.hpp"
+#include "clif.hpp"
+#include "date.hpp" // days of week enum
+#include "intif.hpp"
+#include "pc.hpp"
+#include "pet.hpp"
+#include "instance.hpp"
+#include "chat.hpp"
+#include "script.hpp" // script_config
+#include "guild.hpp"
+#include "battle.hpp"
+#include "mob.hpp"
+#include "log.hpp"
 
 struct npc_data* fake_nd;
 
@@ -355,7 +361,7 @@ static int npc_event_export(struct npc_data *nd, int i)
 		// NPC:<name> the prefix uses 4 characters
 		if( !strncasecmp( lname, script_config.onwhisper_event_name, NAME_LENGTH ) && strlen(nd->exname) > ( NAME_LENGTH - 4 ) ){
 			// The client only allows that many character so that NPC could not be whispered by unmodified clients
-			ShowWarning( "Whisper event in npc '"CL_WHITE"%s"CL_RESET"' was ignored, because it's name is too long.\n", nd->exname );
+			ShowWarning( "Whisper event in npc '" CL_WHITE "%s" CL_RESET "' was ignored, because it's name is too long.\n", nd->exname );
 			return 0;
 		}
 
@@ -451,7 +457,7 @@ int npc_event_doall(const char* name)
 
 // runs the specified event(global only) and reports call count
 void npc_event_runall( const char* eventname ){
-	ShowStatus( "Event '"CL_WHITE"%s"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", eventname, npc_event_doall( eventname ) );
+	ShowStatus( "Event '" CL_WHITE "%s" CL_RESET "' executed with '" CL_WHITE "%d" CL_RESET "' NPCs.\n", eventname, npc_event_doall( eventname ) );
 }
 
 // runs the specified event, with a RID attached (global only)
@@ -2795,7 +2801,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
 	if (type != NPCTYPE_SHOP) {
 		if (type == NPCTYPE_ITEMSHOP) nd->u.shop.itemshop_nameid = nameid; // Item shop currency
 		else if (type == NPCTYPE_POINTSHOP) safestrncpy(nd->u.shop.pointshop_str,point_str,strlen(point_str)+1); // Point shop currency
-		nd->u.shop.discount = is_discount;
+		nd->u.shop.discount = is_discount > 0;
 	}
 
 	npc_parsename(nd, w3, start, buffer, filepath);
@@ -3353,7 +3359,7 @@ int npc_instancedestroy(struct npc_data* nd)
  **/
 void npc_market_tosql(const char *exname, struct npc_item_list *list) {
 	SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
-	if (SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`name`,`nameid`,`price`,`amount`,`flag`) VALUES ('%s','%hu','%d','%hu','%"PRIu8"')",
+	if (SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`name`,`nameid`,`price`,`amount`,`flag`) VALUES ('%s','%hu','%d','%hu','%" PRIu8 "')",
 		market_table, exname, list->nameid, list->value, list->qty, list->flag) ||
 		SQL_ERROR == SqlStmt_Execute(stmt))
 		SqlStmt_ShowDebug(stmt);
@@ -3467,9 +3473,9 @@ static void npc_market_checkall(void) {
 	if (!db_size(NPCMarketDB))
 		return;
 	else {
-		ShowInfo("Checking '"CL_WHITE"%d"CL_RESET"' NPC Markets...\n", db_size(NPCMarketDB));
+		ShowInfo("Checking '" CL_WHITE "%d" CL_RESET "' NPC Markets...\n", db_size(NPCMarketDB));
 		NPCMarketDB->foreach(NPCMarketDB, npc_market_checkall_sub);
-		ShowStatus("Done checking '"CL_WHITE"%d"CL_RESET"' NPC Markets.\n", db_size(NPCMarketDB));
+		ShowStatus("Done checking '" CL_WHITE "%d" CL_RESET "' NPC Markets.\n", db_size(NPCMarketDB));
 		NPCMarketDB->clear(NPCMarketDB, npc_market_free);
 	}
 }
@@ -3510,7 +3516,7 @@ static void npc_market_fromsql(void) {
 	}
 	Sql_FreeResult(mmysql_handle);
 
-	ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' entries for '"CL_WHITE"%d"CL_RESET"' NPC Markets from '"CL_WHITE"%s"CL_RESET"' table.\n", count, db_size(NPCMarketDB), market_table);
+	ShowStatus("Done loading '" CL_WHITE "%d" CL_RESET "' entries for '" CL_WHITE "%d" CL_RESET "' NPC Markets from '" CL_WHITE "%s" CL_RESET "' table.\n", count, db_size(NPCMarketDB), market_table);
 }
 #endif
 
@@ -3756,11 +3762,12 @@ void npc_parse_mob2(struct spawn_data* mob)
 
 static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
 {
-	int num, class_, i, j, mob_lv = -1, ai = -1, size = -1, w1count;
+	int num, class_, i, j, mob_lv = -1, size = -1, w1count;
 	short m,x,y,xs = -1, ys = -1;
 	char mapname[MAP_NAME_LENGTH_EXT], mobname[NAME_LENGTH];
 	struct spawn_data mob, *data;
 	struct mob_db* db;
+	int ai; // mob_ai
 
 	memset(&mob, 0, sizeof(struct spawn_data));
 
@@ -3835,7 +3842,7 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
 	if (size > SZ_SMALL && size <= SZ_BIG)
 		mob.state.size = size;
 	if (ai > AI_NONE && ai <= AI_MAX)
-		mob.state.ai = ai;
+		mob.state.ai = static_cast<enum mob_ai>(ai);
 
 	if (mob.xs < 0) {
 		if (w1count > 3) {
@@ -4630,16 +4637,16 @@ int npc_reload(void) {
 	//TODO: the following code is copy-pasted from do_init_npc(); clean it up
 	// Reloading npcs now
 	for (nsl = npc_src_files; nsl; nsl = nsl->next) {
-		ShowStatus("Loading NPC file: %s"CL_CLL"\r", nsl->name);
+		ShowStatus("Loading NPC file: %s" CL_CLL "\r", nsl->name);
 		npc_parsesrcfile(nsl->name,false);
 	}
-	ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Warps\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Shops\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Scripts\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Spawn sets\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Mobs Cached\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Mobs Not Cached\n",
+	ShowInfo ("Done loading '" CL_WHITE "%d" CL_RESET "' NPCs:" CL_CLL "\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Warps\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Shops\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Scripts\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Spawn sets\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Mobs Cached\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Mobs Not Cached\n",
 		npc_id - npc_new_min, npc_warp, npc_shop, npc_script, npc_mob, npc_cache_mob, npc_delay_mob);
 
 	//Re-read the NPC Script Events cache.
@@ -4762,7 +4769,7 @@ void do_init_npc(void){
 
 	ev_db = strdb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), EVENT_NAME_LENGTH);
 	npcname_db = strdb_alloc(DB_OPT_BASE, NPC_NAME_LENGTH+1);
-	npc_path_db = strdb_alloc(DB_OPT_BASE|DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,80);
+	npc_path_db = strdb_alloc((DBOptions)(DB_OPT_BASE|DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA),80);
 #if PACKETVER >= 20131223
 	NPCMarketDB = strdb_alloc(DB_OPT_BASE, NPC_NAME_LENGTH+1);
 	npc_market_fromsql();
@@ -4774,16 +4781,16 @@ void do_init_npc(void){
 	// process all npc files
 	ShowStatus("Loading NPCs...\r");
 	for( file = npc_src_files; file != NULL; file = file->next ) {
-		ShowStatus("Loading NPC file: %s"CL_CLL"\r", file->name);
+		ShowStatus("Loading NPC file: %s" CL_CLL "\r", file->name);
 		npc_parsesrcfile(file->name,false);
 	}
-	ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Warps\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Shops\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Scripts\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Spawn sets\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Mobs Cached\n"
-		"\t-'"CL_WHITE"%d"CL_RESET"' Mobs Not Cached\n",
+	ShowInfo ("Done loading '" CL_WHITE "%d" CL_RESET "' NPCs:" CL_CLL "\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Warps\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Shops\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Scripts\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Spawn sets\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Mobs Cached\n"
+		"\t-'" CL_WHITE "%d" CL_RESET "' Mobs Not Cached\n",
 		npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, npc_cache_mob, npc_delay_mob);
 
 	// set up the events cache
@@ -4819,4 +4826,3 @@ void do_init_npc(void){
 	map_addiddb(&fake_nd->bl);
 	// End of initialization
 }
-

+ 8 - 15
src/map/npc.h → src/map/npc.hpp

@@ -1,16 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _NPC_H_
-#define _NPC_H_
+#ifndef _NPC_HPP_
+#define _NPC_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "map.h" // struct block_list
-#include "status.h" // struct status_change
-#include "unit.h" // struct unit_data
+#include "map.hpp" // struct block_list
+#include "status.hpp" // struct status_change
+#include "unit.hpp" // struct unit_data
 
 struct block_list;
 struct npc_data;
@@ -106,6 +102,7 @@ struct npc_data {
 	} progressbar;
 };
 
+struct eri;
 extern struct eri *npc_sc_display_ers;
 
 #define START_NPC_NUM 110000000
@@ -1107,7 +1104,7 @@ void npc_chat_finalize(struct npc_data* nd);
 #endif
 
 //Script NPC events.
-enum npce_event {
+enum npce_event : uint8 {
 	NPCE_LOGIN,
 	NPCE_LOGOUT,
 	NPCE_LOADMAP,
@@ -1203,8 +1200,4 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
 
 bool npc_unloadfile( const char* path );
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _NPC_H_ */
+#endif /* _NPC_HPP_ */

+ 6 - 4
src/map/npc_chat.c → src/map/npc_chat.cpp

@@ -3,15 +3,17 @@
 
 #ifdef PCRE_SUPPORT
 
+#include "npc.hpp"
+
+#include "../../3rdparty/pcre/include/pcre.h"
+
 #include "../common/timer.h"
 #include "../common/malloc.h"
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
 
-#include "mob.h" // struct mob_data
-#include "pc.h" // struct map_session_data
-
-#include "../../3rdparty/pcre/include/pcre.h"
+#include "mob.hpp" // struct mob_data
+#include "pc.hpp" // struct map_session_data
 
 
 /**

+ 16 - 11
src/map/party.c → src/map/party.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "party.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/socket.h" // last_tick
@@ -11,17 +15,18 @@
 #include "../common/utils.h"
 #include "../common/strlib.h"
 
-#include "party.h"
-#include "atcommand.h"	//msg_txt()
-#include "pc.h"
-#include "instance.h"
-#include "intif.h"
-#include "mapreg.h"
-#include "trade.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-
+#include "atcommand.hpp"	//msg_txt()
+#include "pc.hpp"
+#include "instance.hpp"
+#include "intif.hpp"
+#include "mapreg.hpp"
+#include "trade.hpp"
+#include "clif.hpp"
+#include "battle.hpp"
+#include "mob.hpp"
+#include "log.hpp"
+#include "pc_groups.hpp"
+#include "achievement.hpp"
 
 static DBMap* party_db; // int party_id -> struct party_data* (releases data)
 static DBMap* party_booking_db; // uint32 char_id -> struct party_booking_ad_info* (releases data) // Party Booking [Spiria]

+ 5 - 12
src/map/party.h → src/map/party.hpp

@@ -1,21 +1,18 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _PARTY_H_
-#define _PARTY_H_
+#ifndef _PARTY_HPP_
+#define _PARTY_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <stdarg.h>
 
 #include "../common/mmo.h" // struct party
+
 struct block_list;
 struct map_session_data;
 struct party;
 struct item;
 
-#include <stdarg.h>
-
 #define MAX_PARTY_BOOKING_JOBS 6
 #define MAX_PARTY_BOOKING_RESULTS 10
 
@@ -102,8 +99,4 @@ void party_booking_update(struct map_session_data *sd, short* job);
 void party_booking_search(struct map_session_data *sd, short level, short mapid, short job, unsigned long lastindex, short resultcount);
 bool party_booking_delete(struct map_session_data *sd);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _PARTY_H_ */
+#endif /* _PARTY_HPP_ */

+ 17 - 12
src/map/path.c → src/map/path.cpp

@@ -1,20 +1,22 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "path.hpp"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/db.h"
 #include "../common/malloc.h"
 #include "../common/nullpo.h"
 #include "../common/random.h"
 #include "../common/showmsg.h"
-#include "map.h"
-#include "battle.h"
-#include "path.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include "map.hpp"
+#include "battle.hpp"
 
 #define SET_OPEN 0
 #define SET_CLOSED 1
@@ -54,7 +56,7 @@ static BHEAP_STRUCT_VAR(node_heap, g_open_set);	// use static heap for all path
 /// @}
 
 // Translates dx,dy into walking direction
-static const unsigned char walk_choices [3][3] =
+static const char walk_choices [3][3] =
 {
 	{DIR_NORTHWEST,DIR_NORTH,DIR_NORTHEAST},
 	{DIR_WEST,DIR_CENTER,DIR_EAST},
@@ -197,11 +199,14 @@ bool path_search_long(struct shootpath_data *spd,int16 m,int16 x0,int16 y0,int16
 
 /// Pushes path_node to the binary node_heap.
 /// Ensures there is enough space in array to store new element.
+
+#define swap_ptrcast_pathnode(a, b) swap_ptrcast(struct path_node *, a, b)
+
 static void heap_push_node(struct node_heap *heap, struct path_node *node)
 {
 #ifndef __clang_analyzer__ // TODO: Figure out why clang's static analyzer doesn't like this
-	BHEAP_ENSURE(*heap, 1, 256);
-	BHEAP_PUSH2(*heap, node, NODE_MINTOPCMP, swap_ptr);
+	BHEAP_ENSURE2(*heap, 1, 256, struct path_node **);
+	BHEAP_PUSH2(*heap, node, NODE_MINTOPCMP, swap_ptrcast_pathnode);
 #endif // __clang_analyzer__
 }
 
@@ -214,7 +219,7 @@ static int heap_update_node(struct node_heap *heap, struct path_node *node)
 		ShowError("heap_update_node: node not found\n");
 		return 1;
 	}
-	BHEAP_UPDATE(*heap, i, NODE_MINTOPCMP, swap_ptr);
+	BHEAP_UPDATE(*heap, i, NODE_MINTOPCMP, swap_ptrcast_pathnode);
 	return 0;
 }
 
@@ -371,7 +376,7 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x
 			}
 
 			current = BHEAP_PEEK(g_open_set); // Look for the lowest f_cost node in the 'open' set
-			BHEAP_POP2(g_open_set, NODE_MINTOPCMP, swap_ptr); // Remove it from 'open' set
+			BHEAP_POP2(g_open_set, NODE_MINTOPCMP, swap_ptrcast_pathnode); // Remove it from 'open' set
 
 			x      = current->x;
 			y      = current->y;

+ 6 - 12
src/map/path.h → src/map/path.hpp

@@ -1,14 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _PATH_H_
-#define _PATH_H_
+#ifndef _PATH_HPP_
+#define _PATH_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
-#include "map.h" // enum cell_chk
+enum cell_chk : uint8;
 
 #define MOVE_COST 10
 #define MOVE_DIAGONAL_COST 14
@@ -26,7 +24,7 @@ struct shootpath_data {
 	int y[MAX_WALKPATH];
 };
 
-enum directions{
+enum directions : int8 {
 	DIR_CENTER = -1,
 	DIR_NORTH = 0,
 	DIR_NORTHWEST = 1,
@@ -74,9 +72,5 @@ int distance_client(int dx, int dy);
 void do_init_path();
 void do_final_path();
 
-#ifdef __cplusplus
-}
-#endif
 
-
-#endif /* _PATH_H_ */
+#endif /* _PATH_HPP_ */

+ 70 - 56
src/map/pc.c → src/map/pc.cpp

@@ -1,7 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include "pc.h"
+#include "pc.hpp"
+
+#include <stdlib.h>
+#include <math.h>
 
 #include "../common/cbasetypes.h"
 #include "../common/core.h" // get_svn_revision()
@@ -14,30 +17,41 @@
 #include "../common/timer.h"
 #include "../common/utils.h"
 #include "../common/mmo.h" //NAME_LENGTH
-
-#include "atcommand.h" // get_atcommand_level()
-#include "map.h"
-#include "battle.h" // battle_config
-#include "battleground.h"
-#include "channel.h"
-#include "chat.h"
-#include "chrif.h"
-#include "clan.h"
-#include "date.h" // is_day_of_*()
-#include "duel.h"
-#include "intif.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "pet.h" // pet_unlocktarget()
-#include "party.h" // party_search()
-#include "storage.h"
-#include "quest.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-#include <math.h>
+#include "../common/ers.h"  // ers_destroy
+
+#include "atcommand.hpp" // get_atcommand_level()
+#include "map.hpp"
+#include "battle.hpp" // battle_config
+#include "battleground.hpp"
+#include "channel.hpp"
+#include "chat.hpp"
+#include "chrif.hpp"
+#include "date.hpp" // is_day_of_*()
+#include "duel.hpp"
+#include "intif.hpp"
+#include "homunculus.hpp"
+#include "instance.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "pet.hpp" // pet_unlocktarget()
+#include "party.hpp" // party_search()
+#include "storage.hpp"
+#include "quest.hpp"
+#include "npc.hpp"
+#include "guild.hpp"
+#include "clif.hpp"
+#include "buyingstore.hpp"  // struct s_buyingstore
+#include "itemdb.hpp" // MAX_ITEMGROUP
+#include "script.hpp" // struct script_reg, struct script_regstr
+#include "searchstore.hpp"  // struct s_search_store_info
+#include "status.hpp" // OPTION_*, struct weapon_atk
+#include "unit.hpp" // unit_stop_attack(), unit_stop_walking()
+#include "vending.hpp" // struct s_vending
+#include "mob.hpp"
+#include "log.hpp"
+#include "pc_groups.hpp"
+#include "achievement.hpp"
+#include "clan.hpp"
 
 int pc_split_atoui(char* str, unsigned int* val, char sep, int max);
 
@@ -141,7 +155,7 @@ int pc_class2idx(int class_) {
 * @param sd
 * @return Group ID
 */
-inline int pc_get_group_id(struct map_session_data *sd) {
+int pc_get_group_id(struct map_session_data *sd) {
 	return sd->group_id;
 }
 
@@ -149,7 +163,7 @@ inline int pc_get_group_id(struct map_session_data *sd) {
 * @param sd
 * @return Group Level
 */
-inline int pc_get_group_level(struct map_session_data *sd) {
+int pc_get_group_level(struct map_session_data *sd) {
 	return sd->group_level;
 }
 
@@ -1283,10 +1297,10 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_
 	sd->die_counter=-1;
 
 	//display login notice
-	ShowInfo("'"CL_WHITE"%s"CL_RESET"' logged in."
-	         " (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"',"
-	         " IP: '"CL_WHITE"%d.%d.%d.%d"CL_RESET"',"
-	         " Group '"CL_WHITE"%d"CL_RESET"').\n",
+	ShowInfo("'" CL_WHITE "%s" CL_RESET "' logged in."
+	         " (AID/CID: '" CL_WHITE "%d/%d" CL_RESET "',"
+	         " IP: '" CL_WHITE "%d.%d.%d.%d" CL_RESET "',"
+	         " Group '" CL_WHITE "%d" CL_RESET "').\n",
 	         sd->status.name, sd->status.account_id, sd->status.char_id,
 	         CONVIP(ip), sd->group_id);
 	// Send friends list
@@ -5826,8 +5840,8 @@ short pc_checkequip(struct map_session_data *sd,int pos)
  * Check if sd has nameid equipped somewhere
  * @sd : the player session
  * @nameid : id of the item to check
- * @min : : see pc.h enum equip_index from ? to @max
- * @max : see pc.h enum equip_index for @min to ?
+ * @min : : see pc.hpp enum equip_index from ? to @max
+ * @max : see pc.hpp enum equip_index for @min to ?
  * -return true,false
  *------------------------------------------*/
 bool pc_checkequip2(struct map_session_data *sd, unsigned short nameid, int min, int max)
@@ -8911,7 +8925,7 @@ bool pc_setcart(struct map_session_data *sd,int type) {
 		default:/* everything else is an allowed ID so we can move on */
 			if( !sd->sc.data[SC_PUSH_CART] ) { /* first time, so fill cart data */
 				clif_cartlist(sd);
-				status_calc_cart_weight(sd, CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE);
+				status_calc_cart_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE));
 			}
 			clif_updatestatus(sd, SP_CARTINFO);
 			sc_start(&sd->bl, &sd->bl, SC_PUSH_CART, 100, type, 0);
@@ -9309,9 +9323,9 @@ bool pc_setreg2(struct map_session_data *sd, const char *reg, int val) {
 		case '@':
 			return pc_setreg(sd, add_str(reg), val);
 		case '#':
-			return (reg[1] == '#') ? pc_setaccountreg2(sd, add_str(reg), val) : pc_setaccountreg(sd, add_str(reg), val);
+			return (reg[1] == '#') ? pc_setaccountreg2(sd, add_str(reg), val) > 0 : pc_setaccountreg(sd, add_str(reg), val) > 0;
 		default:
-			return pc_setglobalreg(sd, add_str(reg), val);
+			return pc_setglobalreg(sd, add_str(reg), val) > 0;
 	}
 
 	return false;
@@ -11246,7 +11260,7 @@ static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
 	sprintf(line, "%s/statpoint.txt", basedir);
 	fp=fopen(line,"r");
 	if(fp == NULL){
-		if(silent==0) ShowWarning("Can't read '"CL_WHITE"%s"CL_RESET"'... Generating DB.\n",line);
+		if(silent==0) ShowWarning("Can't read '" CL_WHITE "%s" CL_RESET "'... Generating DB.\n",line);
 		return max(last_s,i);
 	} else {
 		int entries=0;
@@ -11265,7 +11279,7 @@ static int pc_read_statsdb(const char *basedir, int last_s, bool silent){
 			entries++;
 		}
 		fclose(fp);
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, basedir,"statpoint.txt");
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s/%s" CL_RESET "'.\n", entries, basedir,"statpoint.txt");
 	}
 	return max(last_s,i);
 }
@@ -11283,7 +11297,7 @@ void pc_readdb(void) {
 	int i, k, s = 1;
 	const char* dbsubpath[] = {
 		"",
-		"/"DBIMPORT,
+		"/" DBIMPORT,
 		//add other path here
 	};
 		
@@ -11326,22 +11340,22 @@ void pc_readdb(void) {
 			safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
 		}
 
-		s = pc_read_statsdb(dbsubpath2,s,i);
+		s = pc_read_statsdb(dbsubpath2,s,i > 0);
 		if (i == 0)
 #ifdef RENEWAL_ASPD
-			sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
+			sv_readdb(dbsubpath1, "re/job_db1.txt",',',6+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i > 0);
 #else
-			sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
+			sv_readdb(dbsubpath1, "pre-re/job_db1.txt",',',5+MAX_WEAPON_TYPE,5+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i > 0);
 #endif
 		else
-			sv_readdb(dbsubpath1, "job_db1.txt",',',5+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i);
-		sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i);
-		sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i); //support till 1000lvl
+			sv_readdb(dbsubpath1, "job_db1.txt",',',5+MAX_WEAPON_TYPE,6+MAX_WEAPON_TYPE,CLASS_COUNT,&pc_readdb_job1, i > 0);
+		sv_readdb(dbsubpath1, "job_db2.txt",',',1,1+MAX_LEVEL,CLASS_COUNT,&pc_readdb_job2, i > 0);
+		sv_readdb(dbsubpath2, "job_exp.txt",',',4,1000+3,CLASS_COUNT*2,&pc_readdb_job_exp, i > 0); //support till 1000lvl
 #ifdef HP_SP_TABLES
-		sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i); //Make it support until lvl 500!
+		sv_readdb(dbsubpath2, "job_basehpsp_db.txt", ',', 4, 4+500, CLASS_COUNT*2, &pc_readdb_job_basehpsp, i > 0); //Make it support until lvl 500!
 #endif
-		sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i);
-		sv_readdb(dbsubpath2, "job_noenter_map.txt", ',', 3, 3, CLASS_COUNT, &pc_readdb_job_noenter_map, i);
+		sv_readdb(dbsubpath2, "job_param_db.txt", ',', 2, PARAM_MAX+1, CLASS_COUNT, &pc_readdb_job_param, i > 0);
+		sv_readdb(dbsubpath2, "job_noenter_map.txt", ',', 3, 3, CLASS_COUNT, &pc_readdb_job_noenter_map, i > 0);
 		aFree(dbsubpath1);
 		aFree(dbsubpath2);
 	}
@@ -11410,7 +11424,7 @@ int pc_read_motd(void)
 				char * ptr;
 				buf[len] = 0;
 				if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
-					ShowWarning("Found sequence '"CL_WHITE" :"CL_RESET"' on line '"CL_WHITE"%u"CL_RESET"' in '"CL_WHITE"%s"CL_RESET"'. This can cause newer clients to crash.\n", lines, motd_txt);
+					ShowWarning("Found sequence '" CL_WHITE " :" CL_RESET "' on line '" CL_WHITE "%u" CL_RESET "' in '" CL_WHITE "%s" CL_RESET "'. This can cause newer clients to crash.\n", lines, motd_txt);
 			}
 			else {// empty line
 				buf[0] = ' ';
@@ -11420,10 +11434,10 @@ int pc_read_motd(void)
 			entries++;
 		}
 		fclose(fp);
-		ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt);
+		ShowStatus("Done reading '" CL_WHITE "%u" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", entries, motd_txt);
 	}
 	else
-		ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
+		ShowWarning("File '" CL_WHITE "%s" CL_RESET "' not found.\n", motd_txt);
 
 	return 0;
 }
@@ -11628,7 +11642,7 @@ void pc_scdata_received(struct map_session_data *sd) {
 
 	if (pc_iscarton(sd)) {
 		sd->cart_weight_max = 0; // Force a client refesh
-		status_calc_cart_weight(sd, CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE);
+		status_calc_cart_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE));
 	}
 }
 
@@ -12475,10 +12489,10 @@ void do_init_pc(void) {
 
 	do_init_pc_groups();
 
-	pc_sc_display_ers = ers_new(sizeof(struct sc_display_entry), "pc.c:pc_sc_display_ers", ERS_OPT_FLEX_CHUNK);
-	pc_itemgrouphealrate_ers = ers_new(sizeof(struct s_pc_itemgrouphealrate), "pc.c:pc_itemgrouphealrate_ers", ERS_OPT_NONE);
-	num_reg_ers = ers_new(sizeof(struct script_reg_num), "pc.c:num_reg_ers", ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
-	str_reg_ers = ers_new(sizeof(struct script_reg_str), "pc.c:str_reg_ers", ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
+	pc_sc_display_ers = ers_new(sizeof(struct sc_display_entry), "pc.cpp:pc_sc_display_ers", ERS_OPT_FLEX_CHUNK);
+	pc_itemgrouphealrate_ers = ers_new(sizeof(struct s_pc_itemgrouphealrate), "pc.cpp:pc_itemgrouphealrate_ers", ERS_OPT_NONE);
+	num_reg_ers = ers_new(sizeof(struct script_reg_num), "pc.cpp:num_reg_ers", (ERSOptions)(ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK));
+	str_reg_ers = ers_new(sizeof(struct script_reg_str), "pc.cpp:str_reg_ers", (ERSOptions)(ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK));
 
 	ers_chunk_size(pc_sc_display_ers, 150);
 	ers_chunk_size(num_reg_ers, 300);

+ 26 - 31
src/map/pc.h → src/map/pc.hpp

@@ -1,31 +1,28 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _PC_H_
-#define _PC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _PC_HPP_
+#define _PC_HPP_
 
 #include "../common/mmo.h" // JOB_*, MAX_FAME_LIST, struct fame_list, struct mmo_charstatus
-#include "../common/ers.h"
-#include "../common/timer.h" // INVALID_TIMER
 #include "../common/strlib.h"// StringBuf
-#include "map.h" // RC_ALL
-#include "atcommand.h" // AtCommandType
-#include "battle.h" // battle_config
-#include "buyingstore.h"  // struct s_buyingstore
-#include "clan.h"
-#include "itemdb.h" // MAX_ITEMGROUP
-#include "script.h" // struct script_reg, struct script_regstr
-#include "searchstore.h"  // struct s_search_store_info
-#include "status.h" // OPTION_*, struct weapon_atk
-#include "unit.h" // unit_stop_attack(), unit_stop_walking()
-#include "vending.h" // struct s_vending
-#include "mob.h"
-#include "log.h"
-#include "pc_groups.h"
+
+#include "map.hpp" // RC_ALL
+#include "itemdb.hpp" // MAX_ITEMGROUP
+#include "searchstore.hpp"  // struct s_search_store_info
+#include "vending.hpp" // struct s_vending
+#include "buyingstore.hpp" // struct s_buyingstore
+#include "unit.hpp" // unit_data
+#include "status.hpp" // unit_data
+#include "script.hpp" // struct script_reg, struct script_regstr
+#include "mob.hpp" //e_size
+#include "clif.hpp" //e_wip_block
+
+enum AtCommandType : uint8;
+//enum e_log_chat_type : uint8;
+enum e_log_pick_type : uint32;
+enum sc_type : int16;
+enum si_type : short;
 
 #define MAX_PC_BONUS 10 /// Max bonus, usually used by item bonus
 #define MAX_PC_SKILL_REQUIRE 5 /// Max skill tree requirement
@@ -263,7 +260,7 @@ struct map_session_data {
 		unsigned disable_atcommand_on_npc : 1; //Prevent to use atcommand while talking with NPC [Kichi]
 		uint8 isBoundTrading; // Player is currently add bound item to trade list [Cydh]
 		bool ignoretimeout; // Prevent the SECURE_NPCTIMEOUT function from closing current script.
-		unsigned int workinprogress : 2; // See clif.h::e_workinprogress
+		unsigned int workinprogress : 2; // See clif.hpp::e_workinprogress
 		bool pc_loaded; // Ensure inventory data and status data is loaded before we calculate player stats
 		bool keepshop; // Whether shop data should be removed when the player disconnects
 		bool mail_writing; // Whether the player is currently writing a mail in RODEX or not
@@ -832,7 +829,7 @@ enum item_check {
 	ITMCHK_ALL       = ITMCHK_INVENTORY|ITMCHK_CART|ITMCHK_STORAGE,
 };
 
-extern struct s_job_info {
+struct s_job_info {
 	unsigned int base_hp[MAX_LEVEL], base_sp[MAX_LEVEL]; //Storage for the first calculation with hp/sp factor and multiplicator
 	int hp_factor, hp_multiplicator, sp_factor;
 	int max_weight_base;
@@ -851,7 +848,8 @@ extern struct s_job_info {
 		uint32 zone;
 		uint8 group_lv;
 	} noenter_map;
-} job_info[CLASS_COUNT];
+};
+extern struct s_job_info job_info[CLASS_COUNT];
 
 #define EQP_WEAPON EQP_HAND_R
 #define EQP_SHIELD EQP_HAND_L
@@ -1295,6 +1293,8 @@ void pc_baselevelchanged(struct map_session_data *sd);
 void pc_damage_log_add(struct map_session_data *sd, int id);
 void pc_damage_log_clear(struct map_session_data *sd, int id);
 
+enum e_BANKING_DEPOSIT_ACK : uint8;
+enum e_BANKING_WITHDRAW_ACK : uint8;
 enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int money);
 enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int money);
 
@@ -1329,9 +1329,4 @@ bool pc_job_can_entermap(enum e_job jobid, int m, int group_lv);
 #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP)
 int pc_level_penalty_mod(int level_diff, uint32 mob_class, enum e_mode mode, int type);
 #endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _PC_H_ */
+#endif /* _PC_HPP_ */

+ 8 - 7
src/map/pc_groups.c → src/map/pc_groups.cpp

@@ -1,6 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "pc_groups.hpp"
+
 #include "../common/conf.h"
 #include "../common/db.h"
 #include "../common/malloc.h"
@@ -8,9 +10,8 @@
 #include "../common/strlib.h" // strcmp
 #include "../common/socket.h"
 
-#include "atcommand.h" // AtCommandType
-#include "pc_groups.h"
-#include "pc.h" // e_pc_permission
+#include "atcommand.hpp" // AtCommandType
+#include "pc.hpp" // e_pc_permission
 
 typedef struct GroupSettings GroupSettings;
 
@@ -125,7 +126,7 @@ static void read_config(void)
 			group_settings->id = id;
 			group_settings->level = level;
 			group_settings->name = groupname;
-			group_settings->log_commands = (bool)log_commands;
+			group_settings->log_commands = log_commands != 0;
 			group_settings->inherit = config_setting_get_member(group, "inherit");
 			group_settings->commands = config_setting_get_member(group, "commands");
 			group_settings->permissions = config_setting_get_member(group, "permissions");
@@ -270,7 +271,7 @@ static void read_config(void)
 		dbi_destroy(iter);
 	}
 
-	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename);
+	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' groups in '" CL_WHITE "%s" CL_RESET "'.\n", group_count, config_filename);
 
 	
 	if( ( pc_group_max = group_count ) ) {
@@ -333,12 +334,12 @@ bool pc_group_can_use_command(int group_id, const char *command, AtCommandType t
 		
 		// <commandname> : <bool> (only atcommand)
 		if (type == COMMAND_ATCOMMAND && config_setting_lookup_bool(commands, command, &result))
-			return (bool)result;
+			return result != 0;
 
 		// <commandname> : [ <bool>, <bool> ] ([ atcommand, charcommand ])
 		if ((cmd = config_setting_get_member(commands, command)) != NULL &&
 		    config_setting_is_aggregate(cmd) && config_setting_length(cmd) == 2)
-			return (bool)config_setting_get_bool_elem(cmd, AtCommandType2idx(type));
+			return config_setting_get_bool_elem(cmd, AtCommandType2idx(type)) != 0;
 	}
 	return false;
 }

+ 8 - 6
src/map/pc_groups.h → src/map/pc_groups.hpp

@@ -1,10 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _PC_GROUPS_H_
-#define _PC_GROUPS_H_
+#ifndef _PC_GROUPS_HPP_
+#define _PC_GROUPS_HPP_
 
-#include "atcommand.h" // AtCommandType
+#include "../common/cbasetypes.h"
+
+enum AtCommandType : uint8;
 
 extern int pc_group_max;
 
@@ -20,7 +22,7 @@ void do_init_pc_groups(void);
 void do_final_pc_groups(void);
 void pc_groups_reload(void);
 
-enum e_pc_permission {
+enum e_pc_permission : uint32 {
 	PC_PERM_NONE                = 0,
 	PC_PERM_TRADE               = 0x00000001,
 	PC_PERM_PARTY               = 0x00000002,
@@ -54,7 +56,7 @@ enum e_pc_permission {
 	PC_PERM_ALLPERMISSION       = 0xFFFFFFFF,
 };
 
-static const struct {
+static const struct s_pcg_permission_name {
 	const char *name;
 	enum e_pc_permission permission;
 } pc_g_permission_name[] = {
@@ -89,4 +91,4 @@ static const struct {
 	{ "all_permission", PC_PERM_ALLPERMISSION },
 };
 
-#endif // _PC_GROUPS_H_
+#endif // _PC_GROUPS_HPP_

+ 17 - 12
src/map/pet.c → src/map/pet.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "pet.hpp"
+
+#include <stdlib.h>
+
 #include "../common/db.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -11,14 +15,15 @@
 #include "../common/utils.h"
 #include "../common/ers.h"
 
-#include "pc.h"
-#include "intif.h"
-#include "chrif.h"
-#include "pet.h"
-#include "achievement.h"
-
-#include <stdlib.h>
-
+#include "pc.hpp"
+#include "intif.hpp"
+#include "chrif.hpp"
+#include "npc.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "battle.hpp"
+#include "log.hpp"
+#include "achievement.hpp"
 
 #define MIN_PETTHINKTIME 100
 
@@ -1535,7 +1540,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
  */
 void read_petdb()
 {
-	char* filename[] = {
+	const char* filename[] = {
 		DBPATH"pet_db.txt",
 		DBIMPORT"/pet_db.txt"
 	};
@@ -1680,7 +1685,7 @@ void read_petdb()
 			ShowWarning("read_petdb: Reached max number of pets [%d]. Remaining pets were not read.\n ", MAX_PET_DB);
 
 		fclose(fp);
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' pets in '"CL_WHITE"%s/%s"CL_RESET"'.\n", entries, db_path, filename[i]);
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' pets in '" CL_WHITE "%s/%s" CL_RESET "'.\n", entries, db_path, filename[i]);
 	}
 }
 
@@ -1691,8 +1696,8 @@ void do_init_pet(void)
 {
 	read_petdb();
 
-	item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
-	item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE);
+	item_drop_ers = ers_new(sizeof(struct item_drop),"pet.cpp::item_drop_ers",ERS_OPT_NONE);
+	item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.cpp::item_drop_list_ers",ERS_OPT_NONE);
 
 	add_timer_func_list(pet_hungry,"pet_hungry");
 	add_timer_func_list(pet_ai_hard,"pet_ai_hard");

+ 13 - 11
src/map/pet.h → src/map/pet.hpp

@@ -1,12 +1,18 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _PET_H_
-#define _PET_H_
+#ifndef _PET_HPP_
+#define _PET_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+#include "../common/mmo.h"
+
+#include "unit.hpp"
+#include "status.hpp"
+
+//fwd declaration
+struct s_map_session_data;
+enum e_sc_type : int16;
 
 #define MAX_PET_DB	300
 #define MAX_PETLOOT_SIZE	30
@@ -39,7 +45,7 @@ struct s_pet_db {
 };
 extern struct s_pet_db pet_db[MAX_PET_DB];
 
-enum { PET_CLASS,PET_CATCH,PET_EGG,PET_EQUIP,PET_FOOD };
+enum e_pet_itemtype : uint8 { PET_CLASS,PET_CATCH,PET_EGG,PET_EQUIP,PET_FOOD };
 
 struct pet_recovery { //Stat recovery
 	enum sc_type type;	//Status Change id
@@ -142,8 +148,4 @@ void read_petdb(void);
 void do_init_pet(void);
 void do_final_pet(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _PET_H_ */
+#endif /* _PET_HPP_ */

+ 15 - 10
src/map/quest.c → src/map/quest.cpp

@@ -1,6 +1,10 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "quest.hpp"
+
+#include <stdlib.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/socket.h"
 #include "../common/malloc.h"
@@ -9,15 +13,16 @@
 #include "../common/showmsg.h"
 #include "../common/strlib.h"
 
-#include "itemdb.h"
-#include "map.h"
-#include "pc.h"
-#include "party.h"
-#include "quest.h"
-#include "chrif.h"
-#include "intif.h"
-
-#include <stdlib.h>
+#include "itemdb.hpp"
+#include "map.hpp"
+#include "pc.hpp"
+#include "party.hpp"
+#include "chrif.hpp"
+#include "intif.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "battle.hpp"
+#include "log.hpp"
 
 static DBMap *questdb;
 static void questdb_free_sub(struct quest_db *quest, bool free);
@@ -547,7 +552,7 @@ void quest_read_txtdb(void)
 		}
 
 		fclose(fp);
-		ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename);
+		ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, filename);
 	}
 }
 

+ 8 - 9
src/map/quest.h → src/map/quest.hpp

@@ -1,12 +1,15 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _QUEST_H_
-#define _QUEST_H_
+#ifndef _QUEST_HPP_
+#define _QUEST_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+#include "../common/strlib.h"
+
+#include "map.hpp"
+
+struct map_session_data;
 
 struct quest_dropitem {
 	uint16 nameid;
@@ -60,8 +63,4 @@ void do_init_quest(void);
 void do_final_quest(void);
 void do_reload_quest(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

+ 41 - 39
src/map/script.cpp

@@ -7,6 +7,13 @@
 //#define DEBUG_HASH
 //#define DEBUG_DUMP_STACK
 
+#include "script.hpp"
+
+#include <math.h>
+#include <stdlib.h> // atoi, strtol, strtoll, exit
+#include <setjmp.h>
+#include <errno.h>
+
 #ifdef PCRE_SUPPORT
 #include "../../3rdparty/pcre/include/pcre.h" // preg_match
 #endif
@@ -21,6 +28,7 @@
 #include "../common/strlib.h"
 #include "../common/timer.h"
 #include "../common/utils.h"
+#include "../common/ers.h"  // ers_destroy
 #ifdef BETA_THREAD_TEST
 	#include "../common/atomic.h"
 	#include "../common/spinlock.h"
@@ -28,38 +36,36 @@
 	#include "../common/mutex.h"
 #endif
 
-#include "map.h"
-#include "path.h"
-#include "clan.h"
-#include "clif.h"
-#include "chrif.h"
-#include "date.h" // date type enum, date_get()
-#include "itemdb.h"
-#include "pc.h"
-#include "storage.h"
-#include "pet.h"
-#include "mapreg.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "intif.h"
-#include "chat.h"
-#include "battleground.h"
-#include "party.h"
-#include "mail.h"
-#include "quest.h"
-#include "elemental.h"
-#include "channel.h"
-#include "achievement.h"
-
-#include <math.h>
-#include <stdlib.h> // atoi, strtol, strtoll, exit
-#include <setjmp.h>
-#include <errno.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "map.hpp"
+#include "path.hpp"
+#include "clan.hpp"
+#include "clif.hpp"
+#include "chrif.hpp"
+#include "date.hpp" // date type enum, date_get()
+#include "itemdb.hpp"
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "storage.hpp"
+#include "pet.hpp"
+#include "mapreg.hpp"
+#include "homunculus.hpp"
+#include "instance.hpp"
+#include "mercenary.hpp"
+#include "intif.hpp"
+#include "chat.hpp"
+#include "battleground.hpp"
+#include "party.hpp"
+#include "mail.hpp"
+#include "quest.hpp"
+#include "elemental.hpp"
+#include "npc.hpp"
+#include "guild.hpp"
+#include "atcommand.hpp"
+#include "battle.hpp"
+#include "log.hpp"
+#include "mob.hpp"
+#include "channel.hpp"
+#include "achievement.hpp"
 
 struct eri *array_ers;
 DBMap *st_db;
@@ -2403,7 +2409,7 @@ static void read_constdb(void)
  * Sets source-end constants for NPC scripts to access.
  **/
 void script_hardcoded_constants(void) {
-	#include "script_constants.h"
+	#include "script_constants.hpp"
 }
 
 /*==========================================
@@ -3112,7 +3118,7 @@ void script_array_update(struct reg_db *src, int64 num, bool empty)
  *
  * TODO: return values are screwed up, have been for some time (reaad: years), e.g. some functions return 1 failure and success.
  *------------------------------------------*/
-int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref)
+int set_reg(struct script_state* st, struct map_session_data* sd, int64 num, const char* name, const void* value, struct reg_db *ref)
 {
 	char prefix = name[0];
 
@@ -3238,7 +3244,7 @@ int set_var(struct map_session_data* sd, char* name, void* val)
 	return set_reg(NULL, sd, reference_uid(add_str(name),0), name, val, NULL);
 }
 
-void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct reg_db *ref)
+void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct reg_db *ref)
 {
 	set_reg(st, sd, reference_uid(add_str(varname),elem), varname, value, ref);
 }
@@ -24321,7 +24327,3 @@ struct script_function buildin_func[] = {
 
 	{NULL,NULL,NULL},
 };
-
-#ifdef __cplusplus
-}
-#endif

+ 11 - 17
src/map/script.h → src/map/script.hpp

@@ -1,15 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _SCRIPT_H_
-#define _SCRIPT_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _SCRIPT_HPP_
+#define _SCRIPT_HPP_
 
 #include "../common/cbasetypes.h"
-#include "map.h"
+#include "../common/db.h"
+#include "../common/mmo.h"
 
 #define NUM_WHISPER_VAR 10
 
@@ -133,7 +130,7 @@ enum script_cmd_result {
 };
 
 #define SCRIPT_BLOCK_SIZE 512
-enum { LABEL_NEXTLINE = 1, LABEL_START };
+enum e_labelType { LABEL_NEXTLINE = 1, LABEL_START };
 
 struct map_session_data;
 struct eri;
@@ -144,7 +141,7 @@ extern int potion_target;
 extern unsigned int *generic_ui_array;
 extern unsigned int generic_ui_array_size;
 
-extern struct Script_Config {
+struct Script_Config {
 	unsigned warn_func_mismatch_argtypes : 1;
 	unsigned warn_func_mismatch_paramnum : 1;
 	int check_cmdcount;
@@ -207,7 +204,8 @@ extern struct Script_Config {
 	// Instance related
 	const char* instance_init_event_name;
 	const char* instance_destroy_event_name;
-} script_config;
+};
+extern struct Script_Config script_config;
 
 typedef enum c_op {
 	C_NOP, // end of script/no value (nil)
@@ -1886,7 +1884,7 @@ bool is_number(const char *p);
 struct script_code* parse_script(const char* src,const char* file,int line,int options);
 void run_script(struct script_code *rootscript,int pos,int rid,int oid);
 
-int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref);
+int set_reg(struct script_state* st, struct map_session_data* sd, int64 num, const char* name, const void* value, struct reg_db *ref);
 int set_var(struct map_session_data *sd, char *name, void *val);
 int conv_num(struct script_state *st,struct script_data *data);
 const char* conv_str(struct script_state *st,struct script_data *data);
@@ -1922,7 +1920,7 @@ const char* get_str(int id);
 void script_reload(void);
 
 // @commands (script based)
-void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct reg_db *ref);
+void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct reg_db *ref);
 
 /**
  * Array Handling
@@ -1947,8 +1945,4 @@ unsigned int *script_array_cpy_list(struct script_array *sa);
 void queryThread_log(char * entry, int length);
 #endif
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SCRIPT_H_ */
+#endif /* _SCRIPT_HPP_ */

+ 3 - 3
src/map/script_constants.h → src/map/script_constants.hpp

@@ -1,8 +1,8 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _SCRIPT_CONSTANTS_H_
-	#define _SCRIPT_CONSTANTS_H_
+#ifndef _SCRIPT_CONSTANTS_HPP_
+	#define _SCRIPT_CONSTANTS_HPP_
 
 	#define export_constant(a) script_set_constant(#a,a,false,false)
 	#define export_constant2(a,b) script_set_constant(a,b,false,false)
@@ -6012,4 +6012,4 @@
 	#undef export_parameter
 	#undef export_constant_offset
 
-#endif /* _SCRIPT_CONSTANTS_H_ */
+#endif /* _SCRIPT_CONSTANTS_HPP_ */

+ 6 - 4
src/map/searchstore.c → src/map/searchstore.cpp

@@ -1,14 +1,16 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "searchstore.hpp"  // struct s_search_store_info
+
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"  // aMalloc, aRealloc, aFree
 #include "../common/showmsg.h"  // ShowError, ShowWarning
 #include "../common/strlib.h"  // safestrncpy
-#include "battle.h"  // battle_config.*
-#include "clif.h"  // clif_open_search_store_info, clif_search_store_info_*
-#include "pc.h"  // struct map_session_data
-#include "searchstore.h"  // struct s_search_store_info
+
+#include "battle.hpp"  // battle_config.*
+#include "clif.hpp"  // clif_open_search_store_info, clif_search_store_info_*
+#include "pc.hpp"  // struct map_session_data
 
 /// Failure constants for clif functions
 enum e_searchstore_failure

+ 7 - 10
src/map/searchstore.h → src/map/searchstore.hpp

@@ -1,12 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _SEARCHSTORE_H_
-#define _SEARCHSTORE_H_
+#ifndef _SEARCHSTORE_HPP_
+#define _SEARCHSTORE_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+#include "../common/mmo.h"
+
+#include "map.hpp"
 
 #define SEARCHSTORE_RESULTS_PER_PAGE 10
 
@@ -55,8 +56,4 @@ bool searchstore_queryremote(struct map_session_data* sd, uint32 account_id);
 void searchstore_clearremote(struct map_session_data* sd);
 bool searchstore_result(struct map_session_data* sd, int store_id, uint32 account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const unsigned short* card, unsigned char refine);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif  // _SEARCHSTORE_H_
+#endif  // _SEARCHSTORE_HPP_

+ 32 - 38
src/map/skill.cpp

@@ -1,6 +1,14 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "skill.hpp"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <math.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -11,40 +19,30 @@
 #include "../common/utils.h"
 #include "../common/ers.h"
 
-#include "map.h"
-#include "path.h"
-#include "clif.h"
-#include "pc.h"
-#include "status.h"
-#include "skill.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "mob.h"
-#include "npc.h"
-#include "battle.h"
-#include "battleground.h"
-#include "party.h"
-#include "itemdb.h"
-#include "script.h"
-#include "intif.h"
-#include "log.h"
-#include "chrif.h"
-#include "guild.h"
-#include "date.h"
-#include "unit.h"
-#include "achievement.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <math.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "map.hpp"
+#include "path.hpp"
+#include "clif.hpp"
+#include "pc.hpp"
+#include "status.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "mob.hpp"
+#include "npc.hpp"
+#include "battle.hpp"
+#include "battleground.hpp"
+#include "party.hpp"
+#include "itemdb.hpp"
+#include "script.hpp"
+#include "intif.hpp"
+#include "log.hpp"
+#include "chrif.hpp"
+#include "guild.hpp"
+#include "date.hpp"
+#include "unit.hpp"
+#include "achievement.hpp"
+#include "pc_groups.hpp"
 
 #define SKILLUNITTIMER_INTERVAL	100
 #define TIMERSKILL_INTERVAL	150
@@ -21607,7 +21605,3 @@ void do_final_skill(void)
 	ers_destroy(skill_unit_ers);
 	ers_destroy(skill_timer_ers);
 }
-
-#ifdef __cplusplus
-}
-#endif

+ 11 - 13
src/map/skill.h → src/map/skill.hpp

@@ -1,17 +1,19 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _SKILL_H_
-#define _SKILL_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef _SKILL_HPP_
+#define _SKILL_HPP_
 
+#include "../common/cbasetypes.h"
 #include "../common/mmo.h" // MAX_SKILL, struct square
 #include "../common/db.h"
-#include "map.h" // struct block_list
-#include "battle.h" // enum damage_lv
+
+#include "map.hpp" // struct block_list
+
+enum damage_lv : uint8;
+enum sc_type : int16;
+enum send_target : uint8;
+enum e_damage_type : uint8;
 struct map_session_data;
 struct homun_data;
 struct skill_unit;
@@ -2190,8 +2192,4 @@ enum e_skill_damage_caster {
 #define SKILL_CHK_ELEM(skill_id)  ( (skill_id) >= EL_SKILLBASE && (skill_id) < EL_SKILLBASE+MAX_ELEMENTALSKILL )
 #define SKILL_CHK_GUILD(skill_id) ( (skill_id) >= GD_SKILLBASE && (skill_id) < GD_SKILLBASE+MAX_GUILDSKILL )
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SKILL_H_ */
+#endif /* _SKILL_HPP_ */

+ 118 - 131
src/map/status.c → src/map/status.cpp

@@ -1,6 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "status.hpp"
+
+#include <stdlib.h>
+#include <math.h>
+#include <string>
+#include <yaml-cpp/yaml.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -10,22 +17,23 @@
 #include "../common/utils.h"
 #include "../common/ers.h"
 #include "../common/strlib.h"
-#include "../common/yamlwrapper.h"
-
-#include "battle.h"
-#include "itemdb.h"
-#include "map.h"
-#include "path.h"
-#include "pc.h"
-#include "pet.h"
-#include "battleground.h"
-#include "homunculus.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "script.h"
 
-#include <stdlib.h>
-#include <math.h>
+#include "battle.hpp"
+#include "itemdb.hpp"
+#include "map.hpp"
+#include "path.hpp"
+#include "pc.hpp"
+#include "pet.hpp"
+#include "battleground.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "script.hpp"
+#include "npc.hpp"
+#include "guild.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "pc_groups.hpp"
 
 // Regen related flags.
 enum e_regen {
@@ -104,7 +112,7 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned
 static int status_get_sc_interval(enum sc_type type);
 
 static bool status_change_isDisabledOnMap_(sc_type type, bool mapIsVS, bool mapIsPVP, bool mapIsGVG, bool mapIsBG, unsigned int mapZone, bool mapIsTE);
-#define status_change_isDisabledOnMap(type, m) ( status_change_isDisabledOnMap_((type), map_flag_vs2((m)), map[(m)].flag.pvp, map_flag_gvg2_no_te((m)), map[(m)].flag.battleground, map[(m)].zone << 3, map_flag_gvg2_te((m))) )
+#define status_change_isDisabledOnMap(type, m) ( status_change_isDisabledOnMap_((type), map_flag_vs2((m)), map[(m)].flag.pvp != 0, map_flag_gvg2_no_te((m)), map[(m)].flag.battleground != 0, (map[(m)].zone << 3) != 0, map_flag_gvg2_te((m))) )
 
 /**
  * Returns the status change associated with a skill.
@@ -2801,7 +2809,7 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt)
 					break;
 				case AM_CANNIBALIZE:
 					status->max_hp = 1500 + 200*ud->skill_lv + 10*status_get_lv(mbl);
-					status->mode|= MD_CANATTACK|MD_AGGRESSIVE;
+					status->mode = static_cast<e_mode>(status->mode|MD_CANATTACK|MD_AGGRESSIVE);
 					break;
 				case MH_SUMMON_LEGION:
 				{
@@ -2863,7 +2871,7 @@ void status_calc_pet_(struct pet_data *pd, enum e_status_calc_opt opt)
 
 		if(battle_config.pet_attack_support || battle_config.pet_damage_support) {
 			// Attack support requires the pet to be able to attack
-			pd->status.mode |= MD_CANATTACK;
+			pd->status.mode = static_cast<e_mode>(pd->status.mode|MD_CANATTACK);
 		}
 	}
 
@@ -3322,8 +3330,8 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt)
 	sd->regen.state.block = 0;
 	sd->add_max_weight = 0;
 
-	// Zeroed arrays, order follows the order in pc.h.
-	// Add new arrays to the end of zeroed area in pc.h (see comments) and size here. [zzo]
+	// Zeroed arrays, order follows the order in pc.hpp.
+	// Add new arrays to the end of zeroed area in pc.hpp (see comments) and size here. [zzo]
 	memset (sd->param_bonus, 0, sizeof(sd->param_bonus)
 		+ sizeof(sd->param_equip)
 		+ sizeof(sd->subele)
@@ -3388,7 +3396,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt)
 
 	// !FIXME: Most of these stuff should be calculated once, but how do I fix the memset above to do that? [Skotlex]
 	// Give them all modes except these (useful for clones)
-	base_status->mode = MD_MASK&~(MD_STATUS_IMMUNE|MD_IGNOREMELEE|MD_IGNOREMAGIC|MD_IGNORERANGED|MD_IGNOREMISC|MD_DETECTOR|MD_ANGRY|MD_TARGETWEAK);
+	base_status->mode = static_cast<e_mode>(MD_MASK&~(MD_STATUS_IMMUNE|MD_IGNOREMELEE|MD_IGNOREMAGIC|MD_IGNORERANGED|MD_IGNOREMISC|MD_DETECTOR|MD_ANGRY|MD_TARGETWEAK));
 
 	base_status->size = (sd->class_&JOBL_BABY || (sd->class_&MAPID_BASEMASK) == MAPID_SUMMONER) ? SZ_SMALL : SZ_MEDIUM;
 	if (battle_config.character_size && pc_isriding(sd)) { // [Lupus]
@@ -4200,7 +4208,7 @@ int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt
 	if (opt&SCO_FIRST) {
 		memcpy(status, &md->db->status, sizeof(struct status_data));
 		status->class_ = CLASS_NORMAL;
-		status->mode = MD_CANMOVE|MD_CANATTACK;
+		status->mode = static_cast<e_mode>(MD_CANMOVE|MD_CANATTACK);
 		status->hp = status->max_hp;
 		status->sp = status->max_sp;
 		md->battle_status.hp = merc->hp;
@@ -4245,7 +4253,7 @@ int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt)
 		status->class_ = CLASS_NORMAL;
 		status->size = (hom->class_ == db->evo_class) ? db->evo_size : db->base_size;
 		status->rhw.range = 1 + status->size;
-		status->mode = MD_CANMOVE|MD_CANATTACK;
+		status->mode = static_cast<e_mode>(MD_CANMOVE|MD_CANATTACK);
 		status->speed = DEFAULT_WALK_SPEED;
 		if (battle_config.hom_setting&HOMSET_COPY_SPEED && hd->master)
 			status->speed = status_get_speed(&hd->master->bl);
@@ -4385,7 +4393,7 @@ int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt)
 		status->class_ = CLASS_NORMAL;
 		status->size = nd->size;
 		status->rhw.range = 1 + status->size;
-		status->mode = (MD_CANMOVE|MD_CANATTACK);
+		status->mode = static_cast<e_mode>(MD_CANMOVE|MD_CANATTACK);
 		status->speed = nd->speed;
 	}
 
@@ -7215,16 +7223,16 @@ unsigned char status_calc_attack_element(struct block_list *bl, struct status_ch
 static enum e_mode status_calc_mode(struct block_list *bl, struct status_change *sc, enum e_mode mode)
 {
 	if(!sc || !sc->count)
-		return cap_value(mode, 0, INT_MAX);
+		return cap_value(mode, MD_NONE, static_cast<e_mode>(INT_MAX));
 	if(sc->data[SC_MODECHANGE]) {
 		if (sc->data[SC_MODECHANGE]->val2)
-			mode = (mode&~MD_MASK)|sc->data[SC_MODECHANGE]->val2; // Set mode
+			mode = static_cast<e_mode>((mode&~MD_MASK)|sc->data[SC_MODECHANGE]->val2); // Set mode
 		if (sc->data[SC_MODECHANGE]->val3)
-			mode|= sc->data[SC_MODECHANGE]->val3; // Add mode
+			mode = static_cast<e_mode>(mode|sc->data[SC_MODECHANGE]->val3); // Add mode
 		if (sc->data[SC_MODECHANGE]->val4)
-			mode&=~sc->data[SC_MODECHANGE]->val4; // Del mode
+			mode = static_cast<e_mode>(mode&~sc->data[SC_MODECHANGE]->val4); // Del mode
 	}
-	return cap_value(mode, 0, INT_MAX);
+	return cap_value(mode, MD_NONE, static_cast<e_mode>(INT_MAX));
 }
 
 /**
@@ -8572,9 +8580,9 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 			val3 |= sc->data[type]->val3;
 			val4 |= sc->data[type]->val4;
 		}
-		mode = val2 ? ((val2&~MD_MASK)|val2) : bstatus->mode; // Base mode
-		if (val4) mode&=~val4; // Del mode
-		if (val3) mode|= val3; // Add mode
+		mode = val2 ? static_cast<e_mode>((val2&~MD_MASK)|val2) : bstatus->mode; // Base mode
+		if (val4) mode = static_cast<e_mode>(mode&~val4); // Del mode
+		if (val3) mode = static_cast<e_mode>(mode|val3); // Add mode
 		if (mode == bstatus->mode) { // No change.
 			if (sc->data[type]) // Abort previous status
 				return status_change_end(bl, type, INVALID_TIMER);
@@ -11810,7 +11818,8 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
 	struct status_change_entry *sce;
 	struct status_data *status;
 	struct view_data *vd;
-	int opt_flag = 0, calc_flag;
+	int opt_flag = 0;
+	enum scb_flag calc_flag = SCB_NONE;
 
 	nullpo_ret(bl);
 
@@ -11898,7 +11907,7 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
 		status_display_remove(bl,type);
 
 	vd = status_get_viewdata(bl);
-	calc_flag = StatusChangeFlagTable[type];
+	calc_flag = static_cast<scb_flag>(StatusChangeFlagTable[type]);
 	switch(type) {
 		case SC_GRANITIC_ARMOR:
 			{
@@ -12530,14 +12539,14 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
 	if (calc_flag&SCB_DYE) { // Restore DYE color
 		if (vd && !vd->cloth_color && sce->val4)
 			clif_changelook(bl,LOOK_CLOTHES_COLOR,sce->val4);
-		calc_flag&=~SCB_DYE;
+		calc_flag = static_cast<scb_flag>(calc_flag&~SCB_DYE);
 	}
 
 	/*if (calc_flag&SCB_BODY)// Might be needed in the future. [Rytech]
 	{	//Restore body style
 		if (vd && !vd->body_style && sce->val4)
 			clif_changelook(bl,LOOK_BODY2,sce->val4);
-		calc_flag&=~SCB_BODY;
+		calc_flag = static_cast<scb_flag>(calc_flag&~SCB_BODY);
 	}*/
 
 	// On Aegis, when turning off a status change, first goes the sc packet, then the option packet.
@@ -12708,12 +12717,12 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
 	case SC_POISON:
 	case SC_DPOISON:
 		if (sce->val4 >= 0 && !sc->data[SC_SLOWPOISON]) {
-			int64 damage = 0;
+			unsigned int damage = 0;
 			if (sd)
 				damage = (type == SC_DPOISON) ? 2 + status->max_hp / 50 : 2 + status->max_hp * 3 / 200;
 			else
 				damage = (type == SC_DPOISON) ? 2 + status->max_hp / 100 : 2 + status->max_hp / 200;
-			if (status->hp > max(status->max_hp / 4, damage)) // Stop damaging after 25% HP left.
+			if (status->hp > umax(status->max_hp / 4, damage)) // Stop damaging after 25% HP left.
 				status_zap(bl, damage, 0);
 		}
 		break;
@@ -13306,9 +13315,9 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
 		if( !status_charge(bl,0,sce->val2) ) {
 			struct block_list *s_bl = battle_get_master(bl);
 			if (bl->type == BL_ELEM)
-				elemental_change_mode(BL_CAST(BL_ELEM, bl), MAX_ELESKILLTREE);
+				elemental_change_mode(BL_CAST(BL_ELEM, bl), static_cast<e_mode>(MAX_ELESKILLTREE));
 			if( s_bl )
-				status_change_end(s_bl,type+1,INVALID_TIMER);
+				status_change_end(s_bl,static_cast<sc_type>(type+1),INVALID_TIMER);
 			status_change_end(bl,type,INVALID_TIMER);
 			break;
 		}
@@ -13564,7 +13573,7 @@ int status_change_timer_sub(struct block_list* bl, va_list ap)
 		break;
 	case SC_TINDER_BREAKER:
 	case SC_CLOSECONFINE:{
-		int type2 = ((type==SC_CLOSECONFINE)?SC_CLOSECONFINE2:SC_TINDER_BREAKER2);
+		enum sc_type type2 = ((type==SC_CLOSECONFINE)?SC_CLOSECONFINE2:SC_TINDER_BREAKER2);
 		// Lock char has released the hold on everyone...
 		if (tsc && tsc->data[type2] && tsc->data[type2]->val2 == src->id) {
 			tsc->data[type2]->val2 = 0;
@@ -14172,9 +14181,9 @@ void status_change_clear_onChangeMap(struct block_list *bl, struct status_change
 	if (sc && sc->count) {
 		unsigned short i;
 		bool mapIsVS = map_flag_vs2(bl->m);
-		bool mapIsPVP = map[bl->m].flag.pvp;
+		bool mapIsPVP = map[bl->m].flag.pvp != 0;
 		bool mapIsGVG = map_flag_gvg2_no_te(bl->m);
-		bool mapIsBG = map[bl->m].flag.battleground;
+		bool mapIsBG = map[bl->m].flag.battleground != 0;
 		bool mapIsTE = map_flag_gvg2_te(bl->m);
 		unsigned int mapZone = map[bl->m].zone << 3;
 
@@ -14234,85 +14243,68 @@ static bool status_readdb_sizefix(char* fields[], int columns, int current)
 
 /**
  * Reads and parses an entry from the refine_db
- * @param wrapper: The YAML wrapper containing the entry
+ * @param node: The YAML node containing the entry
  * @param refine_info_index: The sequential index of the current entry
  * @param file_name: File name for displaying only
  * @return True on success or false on failure
  */
-static bool status_yaml_readdb_refine_sub(yamlwrapper* wrapper, int refine_info_index, char* file_name) {
+static bool status_yaml_readdb_refine_sub(const YAML::Node &node, int refine_info_index, const std::string &file_name) {
 	if (refine_info_index < 0 || refine_info_index >= REFINE_TYPE_MAX)
 		return false;
 
-	int bonus_per_level = yaml_get_int(wrapper, "StatsPerLevel");
-	int random_bonus_start_level = yaml_get_int(wrapper, "RandomBonusStartLevel");
-	int random_bonus = yaml_get_int(wrapper, "RandomBonusValue");
-
-	yamlwrapper* costs = yaml_get_subnode(wrapper, "Costs");
-	yamliterator* it = yaml_get_iterator(costs);
-	if (yaml_iterator_is_valid(it)) {
-		for (yamlwrapper* type = yaml_iterator_first(it); yaml_iterator_has_next(it); type = yaml_iterator_next(it)) {
-			int idx = 0, price;
-			unsigned short material;
-			static char* keys[] = {"Type", "Price", "Material" };
-			char* result;
-
-			if ((result = yaml_verify_nodes(type, ARRAYLENGTH(keys), keys)) != NULL) {
-				ShowWarning("status_yaml_readdb_refine_sub: Invalid refine cost with undefined " CL_WHITE "%s" CL_RESET "in file" CL_WHITE "%s" CL_RESET ".\n", result, file_name);
-				yaml_destroy_wrapper(type);
-				continue;
-			}
-
-			char* refine_cost_const = yaml_get_c_string(type, "Type");
-			if (ISDIGIT(refine_cost_const[0]))
-				idx = atoi(refine_cost_const);
-			else
-				script_get_constant(refine_cost_const, &idx);
-			price = yaml_get_int(type, "Price");
-			material = yaml_get_uint16(type, "Material");
+	int bonus_per_level = node["StatsPerLevel"].as<int>();
+	int random_bonus_start_level = node["RandomBonusStartLevel"].as<int>();
+	int random_bonus = node["RandomBonusValue"].as<int>();
+	const YAML::Node &costs = node["Costs"];
 
-			refine_info[refine_info_index].cost[idx].nameid = material;
-			refine_info[refine_info_index].cost[idx].zeny = price;
+	for (const auto costit : costs) {
+		const YAML::Node &type = costit;
+		int idx = 0, price;
+		unsigned short material;
+		const std::string keys[] = { "Type", "Price", "Material" };
 
-			aFree(refine_cost_const);
-			yaml_destroy_wrapper(type);
+		for (int i = 0; i < ARRAYLENGTH(keys); i++) {
+			if (!type[keys[i]].IsDefined())
+				ShowWarning("status_yaml_readdb_refine_sub: Invalid refine cost with undefined " CL_WHITE "%s" CL_RESET "in file" CL_WHITE "%s" CL_RESET ".\n", keys[i].c_str(), file_name.c_str());
 		}
+
+		std::string refine_cost_const = type["Type"].as<std::string>();
+		if (ISDIGIT(refine_cost_const[0]))
+			idx = atoi(refine_cost_const.c_str());
+		else
+			script_get_constant(refine_cost_const.c_str(), &idx);
+		price = type["Price"].as<int>();
+		material = type["Material"].as<uint16>();
+
+		refine_info[refine_info_index].cost[idx].nameid = material;
+		refine_info[refine_info_index].cost[idx].zeny = price;
 	}
-	yaml_destroy_wrapper(costs);
-	yaml_iterator_destroy(it);
 
-	yamlwrapper* rates = yaml_get_subnode(wrapper, "Rates");
-	it = yaml_get_iterator(rates);
+	const YAML::Node &rates = node["Rates"];
 
-	if (yaml_iterator_is_valid(it)) {
-		for (yamlwrapper* level = yaml_iterator_first(it); yaml_iterator_has_next(it); level = yaml_iterator_next(it)) {
-			int refine_level = yaml_get_int(level, "Level") - 1;
+	for (const auto rateit : rates) {
+		const YAML::Node &level = rateit;
+		int refine_level = level["Level"].as<int>() - 1;
 
-			if (refine_level >= MAX_REFINE) {
-				yaml_destroy_wrapper(level);
-				continue;
-			}
+		if (refine_level >= MAX_REFINE)
+			continue;
 
-			if (yaml_node_is_defined(level, "NormalChance"))
-				refine_info[refine_info_index].chance[REFINE_CHANCE_NORMAL][refine_level] = yaml_get_int(level, "NormalChance");
-			if (yaml_node_is_defined(level, "EnrichedChance"))
-				refine_info[refine_info_index].chance[REFINE_CHANCE_ENRICHED][refine_level] = yaml_get_int(level, "EnrichedChance");
-			if (yaml_node_is_defined(level, "EventNormalChance"))
-				refine_info[refine_info_index].chance[REFINE_CHANCE_EVENT_NORMAL][refine_level] = yaml_get_int(level, "EventNormalChance");
-			if (yaml_node_is_defined(level, "EventEnrichedChance"))
-				refine_info[refine_info_index].chance[REFINE_CHANCE_EVENT_ENRICHED][refine_level] = yaml_get_int(level, "EventEnrichedChance");
-			if (yaml_node_is_defined(level, "Bonus"))
-				refine_info[refine_info_index].bonus[refine_level] = yaml_get_int(level, "Bonus");
+		if (level["NormalChance"].IsDefined())
+			refine_info[refine_info_index].chance[REFINE_CHANCE_NORMAL][refine_level] = level["NormalChance"].as<int>();
+		if (level["EnrichedChance"].IsDefined())
+			refine_info[refine_info_index].chance[REFINE_CHANCE_ENRICHED][refine_level] = level["EnrichedChance"].as<int>();
+		if (level["EventNormalChance"].IsDefined())
+			refine_info[refine_info_index].chance[REFINE_CHANCE_EVENT_NORMAL][refine_level] = level["EventNormalChance"].as<int>();
+		if (level["EventEnrichedChance"].IsDefined())
+			refine_info[refine_info_index].chance[REFINE_CHANCE_EVENT_ENRICHED][refine_level] = level["EventEnrichedChance"].as<int>();
+		if (level["Bonus"].IsDefined())
+			refine_info[refine_info_index].bonus[refine_level] = level["Bonus"].as<int>();
 
-			if (refine_level >= random_bonus_start_level - 1)
-				refine_info[refine_info_index].randombonus_max[refine_level] = random_bonus * (refine_level - random_bonus_start_level + 2);
-			yaml_destroy_wrapper(level);
-		}
-		for (int refine_level = 0; refine_level < MAX_REFINE; ++refine_level) {
-			refine_info[refine_info_index].bonus[refine_level] += bonus_per_level + (refine_level > 0 ? refine_info[refine_info_index].bonus[refine_level - 1] : 0);
-		}
+		if (refine_level >= random_bonus_start_level - 1)
+			refine_info[refine_info_index].randombonus_max[refine_level] = random_bonus * (refine_level - random_bonus_start_level + 2);
 	}
-	yaml_destroy_wrapper(rates);
-	yaml_iterator_destroy(it);
+	for (int refine_level = 0; refine_level < MAX_REFINE; ++refine_level)
+		refine_info[refine_info_index].bonus[refine_level] += bonus_per_level + (refine_level > 0 ? refine_info[refine_info_index].bonus[refine_level - 1] : 0);
 
 	return true;
 }
@@ -14322,32 +14314,27 @@ static bool status_yaml_readdb_refine_sub(yamlwrapper* wrapper, int refine_info_
  * @param directory: Location of refine_db file
  * @param file: File name
  */
-static void status_yaml_readdb_refine(const char* directory, const char* file) {
+static void status_yaml_readdb_refine(const std::string &directory, const std::string &file) {
 	int count = 0;
-	const char* labels[6] = { "Armor", "WeaponLv1", "WeaponLv2", "WeaponLv3", "WeaponLv4", "Shadow" };
-	size_t str_size = strlen(directory) + strlen(file) + 2;
-	char* buf = (char*)aCalloc(1, str_size);
-	sprintf(buf, "%s/%s", directory, file);
-	yamlwrapper* root_node, *sub_node;
-
-	if ((root_node = yaml_load_file(buf)) == NULL) {
-		ShowError("Failed to read '%s'.\n", buf);
-		aFree(buf);
+	const std::string labels[] = { "Armor", "WeaponLv1", "WeaponLv2", "WeaponLv3", "WeaponLv4", "Shadow" };
+	const std::string current_file = directory + "/" + file;
+	YAML::Node config;
+
+	try {
+		config = YAML::LoadFile(current_file);
+	}
+	catch (...) {
+		ShowError("Failed to read '" CL_WHITE "%s" CL_RESET "'.\n", current_file.c_str());
 		return;
 	}
 
 	for (int i = 0; i < ARRAYLENGTH(labels); i++) {
-		if (yaml_node_is_defined(root_node, labels[i])) {
-			sub_node = yaml_get_subnode(root_node, labels[i]);
-			if (status_yaml_readdb_refine_sub(sub_node, i, buf))
-				count++;
-			yaml_destroy_wrapper(sub_node);
-		}
-	}
-	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, buf);
+		const YAML::Node &node = config[labels[i]];
 
-	yaml_destroy_wrapper(root_node);
-	aFree(buf);
+		if (node.IsDefined() && status_yaml_readdb_refine_sub(node, i, file))
+			count++;
+	}
+	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, current_file.c_str());
 }
 
 /**
@@ -14411,7 +14398,7 @@ static bool status_readdb_attrfix(const char *basedir,bool silent)
 		entries++;
 	}
 	fclose(fp);
-	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, path);
+	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", entries, path);
 	return true;
 }
 
@@ -14430,7 +14417,7 @@ int status_readdb(void)
 	int i, j, k;
 	const char* dbsubpath[] = {
 		"",
-		"/"DBIMPORT,
+		"/" DBIMPORT,
 		//add other path here
 	};
 	// Initialize databases to default
@@ -14475,9 +14462,9 @@ int status_readdb(void)
 			safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
 		}
 		
-		status_readdb_attrfix(dbsubpath2,i); // !TODO use sv_readdb ?
-		sv_readdb(dbsubpath1, "status_disabled.txt", ',', 2, 2, -1, &status_readdb_status_disabled, i);
-		sv_readdb(dbsubpath1, "size_fix.txt",',',MAX_WEAPON_TYPE,MAX_WEAPON_TYPE,ARRAYLENGTH(atkmods),&status_readdb_sizefix, i);
+		status_readdb_attrfix(dbsubpath2,i > 0); // !TODO use sv_readdb ?
+		sv_readdb(dbsubpath1, "status_disabled.txt", ',', 2, 2, -1, &status_readdb_status_disabled, i > 0);
+		sv_readdb(dbsubpath1, "size_fix.txt",',',MAX_WEAPON_TYPE,MAX_WEAPON_TYPE,ARRAYLENGTH(atkmods),&status_readdb_sizefix, i > 0);
 		status_yaml_readdb_refine(dbsubpath2, "refine_db.yml");
 		aFree(dbsubpath1);
 		aFree(dbsubpath2);
@@ -14496,7 +14483,7 @@ int do_init_status(void)
 	initDummyData();
 	status_readdb();
 	natural_heal_prev_tick = gettick();
-	sc_data_ers = ers_new(sizeof(struct status_change_entry),"status.c::sc_data_ers",ERS_OPT_NONE);
+	sc_data_ers = ers_new(sizeof(struct status_change_entry),"status.cpp::sc_data_ers",ERS_OPT_NONE);
 	add_timer_interval(natural_heal_prev_tick + NATURAL_HEAL_INTERVAL, status_natural_heal_timer, 0, 0, NATURAL_HEAL_INTERVAL);
 	return 0;
 }

+ 8 - 50
src/map/status.h → src/map/status.hpp

@@ -1,13 +1,12 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _STATUS_H_
-#define _STATUS_H_
+#ifndef _STATUS_HPP_
+#define _STATUS_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/mmo.h"
 
+enum e_race2 : uint8;
 struct block_list;
 struct mob_data;
 struct pet_data;
@@ -58,7 +57,7 @@ int status_get_refine_chance(enum refine_type wlv, int refine, bool enriched);
 int status_get_refine_cost(int weapon_lv, int type, bool what);
 
 /// Status changes listing. These code are for use by the server.
-typedef enum sc_type {
+enum sc_type : int16 {
 	SC_NONE = -1,
 
 	//First we enumerate common status ailments which are often used around.
@@ -845,10 +844,10 @@ typedef enum sc_type {
 	SC_EXTREMITYFIST2, //! NOTE: This SC should be right before SC_MAX, so it doesn't disturb if RENEWAL is disabled
 #endif
 	SC_MAX, //Automatically updated max, used in for's to check we are within bounds.
-} sc_type;
+};
 
 /// Official status change ids, used to display status icons on the client.
-enum si_type {
+enum si_type : short {
 	SI_BLANK		= -1,
 	SI_PROVOKE		= 0,
 	SI_ENDURE		= 1,
@@ -1831,43 +1830,6 @@ extern int current_equip_card_id;
 extern bool running_npc_stat_calc_event;
 extern short current_equip_opt_index;
 
-/// Mode definitions to clear up code reading. [Skotlex]
-enum e_mode {
-	MD_NONE					= 0x0000000,
-	MD_CANMOVE				= 0x0000001,
-	MD_LOOTER				= 0x0000002,
-	MD_AGGRESSIVE			= 0x0000004,
-	MD_ASSIST				= 0x0000008,
-	MD_CASTSENSOR_IDLE		= 0x0000010,
-	MD_NORANDOM_WALK		= 0x0000020,
-	MD_NOCAST_SKILL			= 0x0000040,
-	MD_CANATTACK			= 0x0000080,
-	//FREE					= 0x0000100,
-	MD_CASTSENSOR_CHASE		= 0x0000200,
-	MD_CHANGECHASE			= 0x0000400,
-	MD_ANGRY				= 0x0000800,
-	MD_CHANGETARGET_MELEE	= 0x0001000,
-	MD_CHANGETARGET_CHASE	= 0x0002000,
-	MD_TARGETWEAK			= 0x0004000,
-	MD_RANDOMTARGET			= 0x0008000,
-	MD_IGNOREMELEE			= 0x0010000,
-	MD_IGNOREMAGIC			= 0x0020000,
-	MD_IGNORERANGED			= 0x0040000,
-	MD_MVP					= 0x0080000,
-	MD_IGNOREMISC			= 0x0100000,
-	MD_KNOCKBACK_IMMUNE		= 0x0200000,
-	MD_TELEPORT_BLOCK		= 0x0400000,
-	//FREE					= 0x0800000,
-	MD_FIXED_ITEMDROP		= 0x1000000,
-	MD_DETECTOR				= 0x2000000,
-	MD_STATUS_IMMUNE		= 0x4000000,
-	MD_SKILL_IMMUNE			= 0x8000000,
-};
-
-#define MD_MASK 0x000FFFF
-#define ATR_MASK 0x0FF0000
-#define CL_MASK 0xF000000
-
 //Status change option definitions (options are what makes status changes visible to chars
 //who were not on your field of sight when it happened)
 
@@ -2404,8 +2366,4 @@ int status_readdb(void);
 int do_init_status(void);
 void do_final_status(void);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _STATUS_H_ */
+#endif /* _STATUS_HPP_ */

+ 17 - 13
src/map/storage.c → src/map/storage.cpp

@@ -1,23 +1,27 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "storage.hpp"
+
+#include <stdlib.h>
+#include <string.h>
+
 #include "../common/cbasetypes.h"
 #include "../common/db.h"
 #include "../common/nullpo.h"
 #include "../common/malloc.h"
 #include "../common/showmsg.h"
 
-#include "map.h" // struct map_session_data
-#include "storage.h"
-#include "chrif.h"
-#include "itemdb.h"
-#include "clif.h"
-#include "intif.h"
-#include "pc.h"
-
-#include <stdlib.h>
-#include <string.h>
-
+#include "map.hpp" // struct map_session_data
+#include "chrif.hpp"
+#include "itemdb.hpp"
+#include "clif.hpp"
+#include "intif.hpp"
+#include "pc.hpp"
+#include "pc_groups.hpp"
+#include "guild.hpp"
+#include "log.hpp"
+#include "battle.hpp"
 
 static DBMap* guild_storage_db; ///Databases of guild_storage : int guild_id -> struct guild_storage*
 struct s_storage_table *storage_db;
@@ -125,7 +129,7 @@ void do_final_storage(void)
  */
 static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap)
 {
-	struct s_storage *stor = db_data2ptr(data);
+	struct s_storage *stor = static_cast<s_storage *>(db_data2ptr(data));
 
 	if (stor->dirty && stor->status == 0) //Save closed storages.
 		storage_guild_storagesave(0, stor->id, 0);
@@ -714,7 +718,7 @@ bool storage_guild_additem2(struct s_storage* stor, struct item* item, int amoun
 				// Set the amount, make it fit with max amount
 				amount = min(amount, ((id->stack.guildstorage) ? id->stack.amount : MAX_AMOUNT) - stor->u.items_guild[i].amount);
 				if (amount != item->amount)
-					ShowWarning("storage_guild_additem2: Stack limit reached! Altered amount of item \""CL_WHITE"%s"CL_RESET"\" (%d). '"CL_WHITE"%d"CL_RESET"' -> '"CL_WHITE"%d"CL_RESET"'.\n", id->name, id->nameid, item->amount, amount);
+					ShowWarning("storage_guild_additem2: Stack limit reached! Altered amount of item \"" CL_WHITE "%s" CL_RESET "\" (%d). '" CL_WHITE "%d" CL_RESET "' -> '" CL_WHITE"%d" CL_RESET "'.\n", id->name, id->nameid, item->amount, amount);
 				stor->u.items_guild[i].amount += amount;
 				stor->dirty = true;
 				return true;

+ 4 - 12
src/map/storage.h → src/map/storage.hpp

@@ -1,17 +1,13 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _STORAGE_H_
-#define _STORAGE_H_
+#ifndef _STORAGE_HPP_
+#define _STORAGE_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
 
-//#include "../common/mmo.h"
 struct s_storage;
 struct item;
-//#include "map.h"
 struct map_session_data;
 
 extern struct s_storage_table *storage_db;
@@ -67,8 +63,4 @@ void storage_premiumStorage_quit(struct map_session_data *sd);
 
 int compare_item(struct item *a, struct item *b);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _STORAGE_H_ */
+#endif /* _STORAGE_HPP_ */

+ 16 - 10
src/map/trade.c → src/map/trade.cpp

@@ -1,20 +1,26 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include "../common/nullpo.h"
-#include "../common/socket.h"
-#include "clif.h"
-#include "itemdb.h"
-#include "path.h"
-#include "trade.h"
-#include "pc.h"
-#include "chrif.h"
-#include "storage.h"
-#include "intif.h"
+#include "trade.hpp"
 
 #include <stdio.h>
 #include <string.h>
 
+#include "../common/nullpo.h"
+#include "../common/socket.h"
+
+#include "clif.hpp"
+#include "itemdb.hpp"
+#include "path.hpp"
+#include "pc.hpp"
+#include "chrif.hpp"
+#include "storage.hpp"
+#include "intif.hpp"
+#include "atcommand.hpp"
+#include "log.hpp"
+#include "pc_groups.hpp"
+#include "battle.hpp"
+
 #define TRADE_DISTANCE 2 ///Max distance from traders to enable a trade to take place.
 
 /**

+ 3 - 12
src/map/trade.h → src/map/trade.hpp

@@ -1,14 +1,9 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef	_TRADE_H_
-#define	_TRADE_H_
+#ifndef	_TRADE_HPP_
+#define	_TRADE_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-
-#endif
-//#include "map.h"
 struct map_session_data;
 
 void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd);
@@ -19,8 +14,4 @@ void trade_tradeok(struct map_session_data *sd);
 void trade_tradecancel(struct map_session_data *sd);
 void trade_tradecommit(struct map_session_data *sd);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TRADE_H_ */
+#endif /* _TRADE_HPP_ */

+ 29 - 22
src/map/unit.c → src/map/unit.cpp

@@ -1,6 +1,11 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "unit.hpp"
+
+#include <stdlib.h>
+#include <string.h>
+
 #include "../common/showmsg.h"
 #include "../common/timer.h"
 #include "../common/nullpo.h"
@@ -8,27 +13,29 @@
 #include "../common/malloc.h"
 #include "../common/random.h"
 #include "../common/socket.h"
-
-#include "achievement.h"
-#include "map.h"
-#include "path.h"
-#include "pc.h"
-#include "pet.h"
-#include "homunculus.h"
-#include "mercenary.h"
-#include "elemental.h"
-#include "channel.h"
-#include "duel.h"
-#include "battleground.h"
-#include "chat.h"
-#include "trade.h"
-#include "party.h"
-#include "intif.h"
-#include "storage.h"
-
-#include <stdlib.h>
-#include <string.h>
-
+#include "../common/ers.h"  // ers_destroy
+
+#include "achievement.hpp"
+#include "map.hpp"
+#include "path.hpp"
+#include "pc.hpp"
+#include "pet.hpp"
+#include "homunculus.hpp"
+#include "mercenary.hpp"
+#include "elemental.hpp"
+#include "channel.hpp"
+#include "duel.hpp"
+#include "battleground.hpp"
+#include "chat.hpp"
+#include "trade.hpp"
+#include "party.hpp"
+#include "intif.hpp"
+#include "storage.hpp"
+#include "guild.hpp"
+#include "npc.hpp"
+#include "clif.hpp"
+#include "mob.hpp"
+#include "battle.hpp"
 
 // Directions values
 // 1 0 7
@@ -1033,7 +1040,7 @@ uint8 unit_getdir(struct block_list *bl)
  * @param dx: Destination cell X
  * @param dy: Destination cell Y
  * @param count: How many cells to push bl
- * @param flag: See skill.h::e_skill_blown
+ * @param flag: See skill.hpp::e_skill_blown
  * @return count (can be modified due to map cell restrictions)
  */
 int unit_blown(struct block_list* bl, int dx, int dy, int count, enum e_skill_blown flag)

+ 14 - 21
src/map/unit.h → src/map/unit.hpp

@@ -1,22 +1,19 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#ifndef _UNIT_H_
-#define _UNIT_H_
+#ifndef _UNIT_HPP_
+#define _UNIT_HPP_
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "../common/cbasetypes.h"
+
+#include "path.hpp" // struct walkpath_data
+#include "skill.hpp" // struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset
 
-//#include "map.h"
+enum sc_type : int16;
 struct block_list;
 struct unit_data;
 struct map_session_data;
-
-#include "clif.h"  // clr_type
-#include "map.h" // struct block_list
-#include "path.h" // struct walkpath_data
-#include "skill.h" // struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset
+enum clr_type : uint8;
 
 extern const short dirx[DIR_MAX]; ///lookup to know where will move to x according dir
 extern const short diry[DIR_MAX]; ///lookup to know where will move to y according dir
@@ -48,7 +45,7 @@ struct unit_data {
 	uint8 dir;
 	unsigned char walk_count;
 	unsigned char target_count;
-	struct {
+	struct s_udState {
 		unsigned change_walk_target : 1 ;
 		unsigned skillcastcancel : 1 ;
 		unsigned attack_continue : 1 ;
@@ -65,12 +62,11 @@ struct unit_data {
 
 struct view_data {
 #ifdef __64BIT__
-	unsigned int class_;
-#endif
-	unsigned short
-#ifndef __64BIT__
-		class_,
+	unsigned int class_; //why arch dependant ??? make no sense imo [lighta]
+#else
+	unsigned short class_;
 #endif
+unsigned short
 		weapon,
 		shield, //Or left-hand weapon.
 		robe,
@@ -173,8 +169,5 @@ int unit_changetarget(struct block_list *bl,va_list ap);
 void do_init_unit(void);
 void do_final_unit(void);
 
-#ifdef __cplusplus
-}
-#endif
 
-#endif /* _UNIT_H_ */
+#endif /* _UNIT_HPP_ */

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels