Преглед изворни кода

- Reverted the position of the max_hp/max_sp basic setting, modified the max_hp/max_sp bonuses to use casting in order to work correctly with negative bonuses.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11832 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex пре 17 година
родитељ
комит
8463446738
3 измењених фајлова са 26 додато и 16 уклоњено
  1. 3 0
      Changelog-Trunk.txt
  2. 10 12
      src/map/pc.c
  3. 13 4
      src/map/status.c

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2007/11/28
+	* Reverted the position of the max_hp/max_sp basic setting, modified the
+	  max_hp/max_sp bonuses to use casting in order to work correctly with
+	  negative bonuses. [Skotlex]
 	* Reconstructed a list of all PACKETVER types, by reverse-engineering
 	  it from places in the code where the define is used [ultramage]
 	- recovered PACKETVER 6 which was added in r51, but overwritten by r141,

+ 10 - 12
src/map/pc.c

@@ -1543,20 +1543,18 @@ int pc_bonus(struct map_session_data *sd,int type,int val)
 			status->def_ele=val;
 		break;
 	case SP_MAXHP:
-		if(sd->state.lr_flag != 2) {
-			if (val < 0 && status->max_hp <= (unsigned int)(-val))
-				status->max_hp = 1;
-			else
-				status->max_hp+=val;
-		}
+		if(sd->state.lr_flag == 2)
+			break;
+		val += (int)status->max_hp;
+		//Negative bonuses will underflow, this will be handled in status_calc_pc through casting 
+		//If this is called outside of status_calc_pc, you'd better pray they do not underflow and end with UINT_MAX max_hp.
+		status->max_hp = (unsigned int)val;
 		break;
 	case SP_MAXSP:
-		if(sd->state.lr_flag != 2) {
-			if (val < 0 && status->max_sp <= (unsigned int)(-val))
-				status->max_sp = 1;
-			else
-				status->max_sp+=val;
-		}
+		if(sd->state.lr_flag == 2) 
+			break;
+		val += (int)status->max_sp;
+		status->max_sp = (unsigned int)val;
 		break;
 	case SP_CASTRATE:
 		if(sd->state.lr_flag != 2)

+ 13 - 4
src/map/status.c

@@ -1715,10 +1715,6 @@ int status_calc_pc(struct map_session_data* sd,int first)
 	status->aspd_rate = 1000;
 	status->ele_lv = 1;
 	status->race = RC_DEMIHUMAN;
-	//Set base Max-Hp/Sp (required here for negative Hp/Sp bonuses to work properly)
-	//We hold the standard Max HP here to make it faster to recalculate on vit changes.
-	sd->status.max_hp = status->max_hp = status_base_pc_maxhp(sd,status);
-	sd->status.max_sp = status->max_sp = status_base_pc_maxsp(sd,status);
 
 	//zero up structures...
 	memset(&sd->autospell,0,sizeof(sd->autospell)
@@ -2036,6 +2032,13 @@ int status_calc_pc(struct map_session_data* sd,int first)
 
 // ----- HP MAX CALCULATION -----
 
+	// Basic MaxHP value
+	//We hold the standard Max HP here to make it faster to recalculate on vit changes.
+	sd->status.max_hp = status_base_pc_maxhp(sd,status);
+	//This is done to handle underflows from negative Max HP bonuses
+	i = sd->status.max_hp + (int)status->max_hp;
+	status->max_hp = cap_value(i, 0, INT_MAX);
+
 	// Absolute modifiers from passive skills
 	if((skill=pc_checkskill(sd,CR_TRUST))>0)
 		status->max_hp += skill*200;
@@ -2055,6 +2058,12 @@ int status_calc_pc(struct map_session_data* sd,int first)
 
 // ----- SP MAX CALCULATION -----
 
+	// Basic MaxSP value
+	sd->status.max_sp = status_base_pc_maxsp(sd,status);
+	//This is done to handle underflows from negative Max SP bonuses
+	i = sd->status.max_sp + (int)status->max_sp;
+	status->max_sp = cap_value(i, 0, INT_MAX);
+
 	// Absolute modifiers from passive skills
 	if((skill=pc_checkskill(sd,SL_KAINA))>0)
 		status->max_sp += 30*skill;