Просмотр исходного кода

- Fixed crash when looking for SC_MIRACLE in battle_calc_weapon_attack
- Some more standard C code cleanups.


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6038 54d463be-8e91-2dee-dedb-b68131a5f0ec

skotlex 19 лет назад
Родитель
Сommit
9aa86f86e4
4 измененных файлов с 25 добавлено и 19 удалено
  1. 3 0
      Changelog-Trunk.txt
  2. 19 17
      src/map/atcommand.c
  3. 1 1
      src/map/battle.c
  4. 2 1
      src/map/charcommand.c

+ 3 - 0
Changelog-Trunk.txt

@@ -5,6 +5,9 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2006/04/13
+	* Fixed crash when looking for SC_MIRACLE in battle_calc_weapon_attack
+	  [Skotlex]
+	* Some more standard C code cleanups. [Skotlex]
 	* atcommand_param and charcommand_stats to make them standard C (so it may
 	  compile with the Borland C). Also cleaned atcommand_param against
 	  overflows. [Skotlex]

+ 19 - 17
src/map/atcommand.c

@@ -4138,7 +4138,7 @@ int atcommand_param(
 	int index, value = 0, new_value, max;
 	const char* param[] = { "@str", "@agi", "@vit", "@int", "@dex", "@luk", NULL };
 	short* status[6];
- 	//We don't use direct initialization because it isn't part of the C standard.
+ 	//we don't use direct initialization because it isn't part of the c standard.
 	nullpo_retr(-1, sd);
 	
 	status[0] = &sd->status.str;
@@ -4167,18 +4167,15 @@ int atcommand_param(
 		clif_displaymessage(fd, atcmd_output);
 		return -1;
 	}
-	if (value >0) {
-		max = pc_maxparameter(sd);
-		if (*status[index] > max - value)
-			new_value = max;
-		else
-			new_value = *status[index] + value;
-	} else {
-		if (*status[index] <= -value)
-			new_value = 1;
-		else
-			new_value = *status[index] + value;
-	}
+
+	max = pc_maxparameter(sd);
+	if (value > 0 && *status[index] > max - value)
+		new_value = max;
+	else if (value < 0 && *status[index] <= -value)
+		new_value = 1;
+	else
+		new_value = *status[index] + value;
+	
 	if (new_value != (int)*status[index]) {
 		*status[index] = new_value;
 		clif_updatestatus(sd, SP_STR + index);
@@ -4206,11 +4203,16 @@ int atcommand_stat_all(
 	const char* command, const char* message)
 {
 	int index, count, value = 0, max, new_value;
-	short* status[] = {
-		&sd->status.str,  &sd->status.agi, &sd->status.vit,
-		&sd->status.int_, &sd->status.dex, &sd->status.luk
-	};
+	short* status[6];
+ 	//we don't use direct initialization because it isn't part of the c standard.
 	nullpo_retr(-1, sd);
+	
+	status[0] = &sd->status.str;
+	status[1] = &sd->status.agi;
+	status[2] = &sd->status.vit;
+	status[3] = &sd->status.int_;
+	status[4] = &sd->status.dex;
+	status[5] = &sd->status.luk;
 
 	if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0)
 		value = pc_maxparameter(sd);

+ 1 - 1
src/map/battle.c

@@ -1966,7 +1966,7 @@ static struct Damage battle_calc_weapon_attack(
 			{	//SG Anger bonus - ATK_ADDRATE [Komurka]
 				static int type[] = { SG_SUN_ANGER, SG_MOON_ANGER, SG_STAR_ANGER };
 				short t_class = status_get_class(target);
-				if (sc->data && sc->data[SC_MIRACLE].timer!=-1 && (skill = pc_checkskill(sd,type[2])))
+				if (sc && sc->data[SC_MIRACLE].timer!=-1 && (skill = pc_checkskill(sd,type[2])))
 				{
 					skillratio = (sd->status.base_level + status_get_str(src) + status_get_dex(src)+ status_get_luk(src))/(skill<4?12-3*skill:1);
 					ATK_ADDRATE(skillratio);

+ 2 - 1
src/map/charcommand.c

@@ -481,7 +481,7 @@ int charcommand_stats(
 			int value;
 		} output_table[] = {
 			{ "Base Level - %d", 0 },
-			{ job_jobname, 0 },
+			{ NULL, 0 },
 			{ "Hp - %d", 0 },
 			{ "MaxHp - %d", 0 },
 			{ "Sp - %d", 0 },
@@ -497,6 +497,7 @@ int charcommand_stats(
 		};
 		//direct array initialization with variables is not standard C compliant.
 		output_table[0].value = pl_sd->status.base_level;
+		output_table[1].format = job_jobname;
 		output_table[1].value = pl_sd->status.job_level;
 		output_table[2].value = pl_sd->status.hp;
 		output_table[3].value = pl_sd->status.max_hp;