From 103e46fdabc6f3fd241b7dc34d865bf99c9d1b4c Mon Sep 17 00:00:00 2001
From: ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>
Date: Sun, 21 Nov 2010 16:20:26 +0000
Subject: [PATCH] * Added enumeration RC2_* for mob data 'race2'
 (bugreport:4561). - Fixed race2-related bonus arrays using RC_MAX, rather
 than race2 maximum (since r6221, related r1277). - Fixed bSubRace2 lacking
 bounds check (since r1257). - Fixed bSubRace2 being documented as bSPSubRace2
 (since r1257).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14480 54d463be-8e91-2dee-dedb-b68131a5f0ec
---
 Changelog-Trunk.txt |  3 +++
 db/Changelog.txt    |  3 +++
 db/const.txt        |  8 ++++++++
 doc/item_bonus.txt  |  2 +-
 src/map/map.h       | 11 +++++++++++
 src/map/mob.c       |  2 +-
 src/map/mob.h       |  1 -
 src/map/pc.c        |  5 +++--
 src/map/pc.h        |  4 ++--
 9 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 693dea8b63..1fa18948f6 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,6 +3,9 @@ Date	Added
 2010/11/21
 	* Added msinttypes (rev. 26, http://msinttypes.googlecode.com/svn/trunk/) portability framework for Visual C++ compilers (related bugreport:4059). [Ai4rei]
 	* Added 64-bit variants of the socket and buffer I/O macros. [Ai4rei]
+	* Added enumeration RC2_* for mob data 'race2' (bugreport:4561). [Ai4rei]
+	- Fixed race2-related bonus arrays using RC_MAX, rather than race2 maximum (since r6221, related r1277).
+	- Fixed bSubRace2 lacking bounds check (since r1257).
 2010/11/20
 	* Fixed @doom and @doommap spamming packets for the visual effect on invoker unnecessarily over whole map and server respectively. The effect is now displayed on each killed character (bugreport:871, since r311). [Ai4rei]
 	* Fixed login-server account engine initialization not getting checked, whether it succeeds or not (bugreport:4361, since r12700, related r13000). [Ai4rei]
diff --git a/db/Changelog.txt b/db/Changelog.txt
index dc48cfb0c2..5d42354779 100644
--- a/db/Changelog.txt
+++ b/db/Changelog.txt
@@ -8,6 +8,9 @@
 	1475 Equestrian's Spear:	NEED INFO.
 	13005 Angelic Wing Dagger:	NEED INFO.
 =======================
+2010/11/21
+	* Rev. 14480 Added enumeration RC2_* to const.txt for mob data 'race2' (bugreport:4561). [Ai4rei]
+	- Fixed bSubRace2 being documented as bSPSubRace2 (since r1257).
 2010/11/19
 	* Rev. 14474 Item Database bugfixing. [L0ne_W0lf]
 	- Fixed equip locations and view IDs for some headgears. (bugreport:4336)
diff --git a/db/const.txt b/db/const.txt
index c6a8bcbffd..3fbec41fb3 100644
--- a/db/const.txt
+++ b/db/const.txt
@@ -487,6 +487,14 @@ RC_Boss	10
 RC_NonBoss	11
 RC_NonDemiHuman	12
 
+RC2_None	0
+RC2_Goblin	1
+RC2_Kobold	2
+RC2_Orc	3
+RC2_Golem	4
+RC2_Guardian	5
+RC2_Ninja	6
+
 BF_WEAPON	0x0001
 BF_MAGIC	0x0002
 BF_MISC	0x0004
diff --git a/doc/item_bonus.txt b/doc/item_bonus.txt
index d9224e1963..78e34f2fc8 100644
--- a/doc/item_bonus.txt
+++ b/doc/item_bonus.txt
@@ -285,7 +285,7 @@ bonus2 bSPRegenRate,n,x;		Gain n SP every x milliseconds
 bonus2 bSPLossRate,n,x;			Lose n SP every x milliseconds
 bonus2 bExpAddRace,n,x;			Increase exp gained by x% vs. enemies of race n
 bonus2 bSPGainRace,n,x;			When killing a monster of race n by physical attack gain x amount of sp
-bonus2 bSPSubRace2,n,x;			Damage x% reduction from enemies of race n
+bonus2 bSubRace2,n,x;			Damage x% reduction from enemies of race n
 							(Check db/mob_race2_db.txt)
 
 bonus2 bAddMonsterDropItemGroup,n,x;	x% chance to get an item of group type n when you kill a monster 
diff --git a/src/map/map.h b/src/map/map.h
index 199db618da..9f25249e29 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -210,6 +210,17 @@ enum {
 	RC_MAX
 };
 
+enum {
+	RC2_NONE = 0,
+	RC2_GOBLIN,
+	RC2_KOBOLD,
+	RC2_ORC,
+	RC2_GOLEM,
+	RC2_GUARDIAN,
+	RC2_NINJA,
+	RC2_MAX
+};
+
 enum {
 	ELE_NEUTRAL=0,
 	ELE_WATER,
diff --git a/src/map/mob.c b/src/map/mob.c
index 81fc9e68b2..413d88f269 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -4349,7 +4349,7 @@ static int mob_readdb_race(void)
 			continue;
 
 		race=atoi(str[0]);
-		if (race < 0 || race >= MAX_MOB_RACE_DB)
+		if (race < RC2_NONE || race >= RC2_MAX)
 			continue;
 
 		for (j=1; j<20; j++) {
diff --git a/src/map/mob.h b/src/map/mob.h
index b0efdbfb42..e8bd0a8378 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -12,7 +12,6 @@
 
 
 #define MAX_RANDOMMONSTER 4
-#define MAX_MOB_RACE_DB 6
 
 // 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.
diff --git a/src/map/pc.c b/src/map/pc.c
index e93ae8a938..c52a61003c 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -27,7 +27,6 @@
 #include "homunculus.h"
 #include "instance.h"
 #include "mercenary.h"
-#include "mob.h" // MAX_MOB_RACE_DB
 #include "npc.h" // fake_nd
 #include "pet.h" // pet_unlocktarget()
 #include "party.h" // party_search()
@@ -2741,7 +2740,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
 		}
 		break;
 	case SP_ADDRACE2:
-		if (!(type2 > 0 && type2 < MAX_MOB_RACE_DB))
+		if (!(type2 > RC2_NONE && type2 < RC2_MAX))
 			break;
 		if(sd->state.lr_flag != 2)
 			sd->right_weapon.addrace2[type2] += val;
@@ -2753,6 +2752,8 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
 			sd->subsize[type2]+=val;
 		break;
 	case SP_SUBRACE2:
+		if (!(type2 > RC2_NONE && type2 < RC2_MAX))
+			break;
 		if(sd->state.lr_flag != 2)
 			sd->subrace2[type2]+=val;
 		break;
diff --git a/src/map/pc.h b/src/map/pc.h
index 3744886090..7bf3a050f1 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -31,7 +31,7 @@ struct weapon_data {
 	int def_ratio_atk_race;
 	int addele[ELE_MAX];
 	int addrace[RC_MAX];
-	int addrace2[RC_MAX];
+	int addrace2[RC2_MAX];
 	int addsize[3];
 
 	struct drain_data {
@@ -219,7 +219,7 @@ struct map_session_data {
 	int param_bonus[6],param_equip[6]; //Stores card/equipment bonuses.
 	int subele[ELE_MAX];
 	int subrace[RC_MAX];
-	int subrace2[RC_MAX];
+	int subrace2[RC2_MAX];
 	int subsize[3];
 	int reseff[SC_COMMON_MAX-SC_COMMON_MIN+1];
 	int weapon_coma_ele[ELE_MAX];