Browse Source

Guardian hp handling code removal (see bugreport:342)
- removed guardian hp from the castle data structure, database, savefiles and various script functions (use upgrade_svn11914.sql)
- removed guardian hp calculation and manipulation from the castle manager npc, now the hp values are updated by the server itself (glitch: when castle defense changes, all guardians are healed to full)
- tweaked script function 'guardianinfo' to provide some data needed by the manager npc (currently available are hp, maxhp and visibility); also, it doesn't need a player attached to execute anymore
The whole thing is experimental, use at your own risk (seems to work though...)

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

ultramage 17 years ago
parent
commit
1e6922174e

+ 9 - 0
Changelog-Trunk.txt

@@ -4,6 +4,15 @@ 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/12/14
+	* Guardian hp handling code removal (see bugreport:342)
+	- removed guardian hp from the castle data structure, database,
+	  savefiles and various script functions (use upgrade_svn11914.sql)
+	- removed guardian hp calculation and manipulation from the castle
+	  manager npc, now the hp values are updated by the server itself
+	  (glitch: when castle defense changes, all guardians are healed to full)
+	- tweaked script function 'guardianinfo' to provide some data needed
+	  by the manager npc (currently available are hp, maxhp and visibility);
+	  also, it doesn't need a player attached to execute
 	* Added a precise and consistent tick() function for freebsd [ultramage]
 	* Wand of Hermode now dispells buffs only of allies.
 	* Fixed some null pointer checks in status_change_end.

+ 11 - 7
doc/script_commands.txt

@@ -94,6 +94,8 @@
 //=       Added setnpcdisplay. [FlavioJS]
 //= 3.10.20071211
 //=       Added query_logsql. [Skotlex]
+//= 3.11.20071215
+//=       Updated guardianinfo and get-/setcastledata [ultramage]
 //===== Description =======================================
 //= A reference manual for the eAthena scripting language,
 //= sorted out depending on their functionality.
@@ -5537,14 +5539,16 @@ set the things up that only castle guardians need.
 
 ---------------------------------------
 
-*guardianinfo(<guardian number>)
+*guardianinfo("<map name>", <guardian number>, <type>)
 
-This function will return the current hit point value for the specified guardian 
-number, if such guardian is currently installed. This function will only work if 
-the invoking character is on a castle map, and will refer only to the guardians 
-of that castle, regardless of anything else, i.e. whether the character is a 
-member of the guild owning the castle, etc, etc.
-If no guardian is installed in this slot, the function will return -1.
+This function will return various info about the specified guardian, or -1
+if it fails for some reason. It is primarily used in the castle manager npc.
+
+Map name and guardian number (value between 0 and 7) define the target.
+Type indicates what information to return:
+ 0 - visibility (whether the guardian is installed or not)
+ 1 - max. hp
+ 2 - current hp
 
 ---------------------------------------
 //

+ 13 - 36
npc/guild/gldfunc_manager.txt

@@ -143,7 +143,7 @@ function	script	F_GldManager	{
 				mes "I'm sorry but there is not enough zeny to invest in the reserves of guild. You have failed to invest, Master.";
 				return 0;
 			}
-			set zeny,zeny-.@eco_invest;;
+			set zeny,zeny-.@eco_invest;
 			SetCastleData getarg(1),4,GetCastleData(getarg(1),4)+1;
 			SetCastleData getarg(1),2,.@Economy + 1 + (.@Economy<99 && rand(2) && getgdskilllv(.@GID,10014));
 			mes "We have finished investing safely. I expect in our coming days, the growth level will increase.";
@@ -194,17 +194,6 @@ function	script	F_GldManager	{
 			set Zeny,Zeny-.@def_invest;
 			SetCastleData getarg(1),5,GetCastleData(getarg(1),5)+1;
 			SetCastleData getarg(1),3,.@Defence+1;
-			set .@Defence, .@Defence + 1;
-			set .@AGuardian, strmobinfo(4,1285) + (.@Defence*2000);
-			set .@KGuardian, strmobinfo(4,1286) + (.@Defence*2000);
-			set .@SGuardian, strmobinfo(4,1287) + (.@Defence*2000);
-
-			for (set .@i, 0; .@i <= 7 ; set .@i, .@i+1) {
-				if (.@guardiantype[.@i] == 1) set .@GHP,.@SGuardian;
-				else if (.@guardiantype[.@i] == 2) set .@GHP,.@AGuardian;
-				else set .@GHP,.@KGuardian;
-				if (GetCastleData(getarg(1),(.@i + 10)) == 1) SetCastleData getarg(1),(.@i + 18),.@GHP;
-			}
 			mes "We have finished investing safely. I expect in our coming days, the growth level will increase.";
 			return 0;
 		}
@@ -213,37 +202,26 @@ function	script	F_GldManager	{
 		return 0;
 
 	case 4:
-		set .@Defence,GetCastleData(getarg(1),3);
-		set .@AGuardian, strmobinfo(4,1285) + (.@Defence*2000);
-		set .@KGuardian, strmobinfo(4,1286) + (.@Defence*2000);
-		set .@SGuardian, strmobinfo(4,1287) + (.@Defence*2000);
-
 		mes "[ "+getarg(0)+" ]";
 		mes "Do you still want to summon a Guardian? It'll be a protector to defend us to the end.";
 		mes "Choose a Guardian to summon.";
 		next;
 
-		for (set .@i, 0; .@i <= 7 ; set .@i, .@i+1) {
-			if (.@guardiantype[.@i] == 1) {
-				set .@type$,"Soldier";
-				setarray .@GuardianHP[.@i],.@SGuardian;
-			}
-			else if (.@guardiantype[.@i] == 2) {
-				set .@type$,"Archer";
-				setarray .@GuardianHP[.@i],.@AGuardian;
-			}
-			else {
-				set .@type$,"Knight";
-				setarray .@GuardianHP[.@i],.@KGuardian;
-			}
+		for( set .@i, 0; .@i <= 7 ; set .@i, .@i+1 )
+		{
+			if      (.@guardiantype[.@i] == 1) set .@type$,"Guardian Soldier";
+			else if (.@guardiantype[.@i] == 2) set .@type$,"Guardian Archer";
+			else                               set .@type$,"Guardian Knight";
 
-			if (GetCastleData(getarg(1),(.@i+10)))
-				setarray .@name$[.@i],"Guardian "+.@type$+" - Implemented (" + guardianinfo(.@i) + "/" + .@GuardianHP[.@i] + ")";
+			if( guardianinfo(getarg(1),.@i,0) )
+				setarray .@name$[.@i], .@type$ + " - Implemented (" + guardianinfo(getarg(1),.@i,2) + "/" + guardianinfo(getarg(1),.@i,1) + ")";
 			else
-				setarray .@name$[.@i],"Guardian "+.@type$+" - Not Implemented";
+				setarray .@name$[.@i], .@type$ + " - Not Implemented";
 		}
 	
 		set .@menu$,.@name$[0]+":"+.@name$[1]+":"+.@name$[2]+":"+.@name$[3]+":"+.@name$[4]+":"+.@name$[5]+":"+.@name$[6]+":"+.@name$[7];
+
+		// this thing will propagate outside of this function
 		switch(select(.@menu$)) {
 		case 1: set @GDnum,10; break;
 		case 2: set @GDnum,11; break;
@@ -274,9 +252,8 @@ function	script	F_GldManager	{
 				return 0;
 			}
 			set zeny,zeny-10000;
-			set .@HP,@GDnum + 8;
-			SetCastleData getarg(1),@GDnum,1;
-			SetCastleData getarg(1),.@HP,.@GuardianHP[(@GDnum - 10)];
+			SetCastleData getarg(1),@GDnum,1; // mark as 'installed'
+			// guardian will be spawned outside of this function
 			mes "We have successfully summoned the Guardian. We now have our strong force to defend us!";
 			return 1;
 

+ 9 - 0
sql-files/upgrade_svn11914.sql

@@ -0,0 +1,9 @@
+ALTER TABLE `guild_castle`
+  DROP `gHP0`,
+  DROP `gHP1`,
+  DROP `gHP2`,
+  DROP `gHP3`,
+  DROP `gHP4`,
+  DROP `gHP5`,
+  DROP `gHP6`,
+  DROP `gHP7`;

+ 33 - 100
src/char/int_guild.c

@@ -309,13 +309,11 @@ int inter_guildcastle_tostr(char *str, struct guild_castle *gc)
 {
 	int len;
 
-	len = sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",	// added Guardian HP [Valaris]
+	len = sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
 	              gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE,
 	              gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC,
 	              gc->guardian[0].visible, gc->guardian[1].visible, gc->guardian[2].visible, gc->guardian[3].visible,
-					  gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible,
-					  gc->guardian[0].hp, gc->guardian[1].hp, gc->guardian[2].hp, gc->guardian[3].hp,
-					  gc->guardian[4].hp, gc->guardian[5].hp, gc->guardian[6].hp, gc->guardian[7].hp);
+	              gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible);
 
 	return 0;
 }
@@ -324,77 +322,40 @@ int inter_guildcastle_tostr(char *str, struct guild_castle *gc)
 // ギルド城データの文字列からの変換
 int inter_guildcastle_fromstr(char *str, struct guild_castle *gc)
 {
-	int tmp_int[26];
+	int castleid, guildid, economy, defense, triggerE, triggerD, nextTime, payTime, createTime, visibleC;
+	int guardian[8];
+	int dummy;
 
 	memset(gc, 0, sizeof(struct guild_castle));
-	// new structure of guild castle
-	if (sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
-	           &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6],
-	           &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13],
-	           &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20],
-	           &tmp_int[21], &tmp_int[22], &tmp_int[23], &tmp_int[24], &tmp_int[25]) == 26) {
-		gc->castle_id = tmp_int[0];
-		gc->guild_id = tmp_int[1];
-		gc->economy = tmp_int[2];
-		gc->defense = tmp_int[3];
-		gc->triggerE = tmp_int[4];
-		gc->triggerD = tmp_int[5];
-		gc->nextTime = tmp_int[6];
-		gc->payTime = tmp_int[7];
-		gc->createTime = tmp_int[8];
-		gc->visibleC = tmp_int[9];
-		gc->guardian[0].visible = tmp_int[10];
-		gc->guardian[1].visible = tmp_int[11];
-		gc->guardian[2].visible = tmp_int[12];
-		gc->guardian[3].visible = tmp_int[13];
-		gc->guardian[4].visible = tmp_int[14];
-		gc->guardian[5].visible = tmp_int[15];
-		gc->guardian[6].visible = tmp_int[16];
-		gc->guardian[7].visible = tmp_int[17];
-		gc->guardian[0].hp = tmp_int[18];
-		gc->guardian[1].hp = tmp_int[19];
-		gc->guardian[2].hp = tmp_int[20];
-		gc->guardian[3].hp = tmp_int[21];
-		gc->guardian[4].hp = tmp_int[22];
-		gc->guardian[5].hp = tmp_int[23];
-		gc->guardian[6].hp = tmp_int[24];
-		gc->guardian[7].hp = tmp_int[25];	// end additions [Valaris]
-	// old structure of guild castle
-	} else if (sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
-	                  &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6],
-	                  &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13],
-	                  &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17]) == 18) {
-		int i;
-		
-		gc->castle_id = tmp_int[0];
-		gc->guild_id = tmp_int[1];
-		gc->economy = tmp_int[2];
-		gc->defense = tmp_int[3];
-		gc->triggerE = tmp_int[4];
-		gc->triggerD = tmp_int[5];
-		gc->nextTime = tmp_int[6];
-		gc->payTime = tmp_int[7];
-		gc->createTime = tmp_int[8];
-		gc->visibleC = tmp_int[9];
-		gc->guardian[0].visible = tmp_int[10];
-		gc->guardian[1].visible = tmp_int[11];
-		gc->guardian[2].visible = tmp_int[12];
-		gc->guardian[3].visible = tmp_int[13];
-		gc->guardian[4].visible = tmp_int[14];
-		gc->guardian[5].visible = tmp_int[15];
-		gc->guardian[6].visible = tmp_int[16];
-		gc->guardian[7].visible = tmp_int[17];
-
-		for (i = 0; i < MAX_GUARDIANS; i++)
-		{
-			if (gc->guardian[i].visible)
-				gc->guardian[i].hp = 15000 + 2000 * gc->defense;
-			else
-				gc->guardian[i].hp = 0;
-		}
-	} else {
+	// structure of guild castle with the guardian hp included
+	if( sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
+		&castleid, &guildid, &economy, &defense, &triggerE, &triggerD, &nextTime, &payTime, &createTime, &visibleC,
+		&guardian[0], &guardian[1], &guardian[2], &guardian[3], &guardian[4], &guardian[5], &guardian[6], &guardian[7],
+		&dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) != 26 )
+	// structure of guild castle without the hps (current one)
+	if( sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
+		&castleid, &guildid, &economy, &defense, &triggerE, &triggerD, &nextTime, &payTime, &createTime, &visibleC,
+		&guardian[0], &guardian[1], &guardian[2], &guardian[3], &guardian[4], &guardian[5], &guardian[6], &guardian[7]) != 18 )
 		return 1;
-	}
+
+	gc->castle_id = castleid;
+	gc->guild_id = guildid;
+	gc->economy = economy;
+	gc->defense = defense;
+	gc->triggerE = triggerE;
+	gc->triggerD = triggerD;
+	gc->nextTime = nextTime;
+	gc->payTime = payTime;
+	gc->createTime = createTime;
+	gc->visibleC = visibleC;
+	gc->guardian[0].visible = guardian[0];
+	gc->guardian[1].visible = guardian[1];
+	gc->guardian[2].visible = guardian[2];
+	gc->guardian[3].visible = guardian[3];
+	gc->guardian[4].visible = guardian[4];
+	gc->guardian[5].visible = guardian[5];
+	gc->guardian[6].visible = guardian[6];
+	gc->guardian[7].visible = guardian[7];
 
 	return 0;
 }
@@ -964,15 +925,6 @@ int mapif_guild_castle_datasave(int castle_id, int index, int value)
 	return 0;
 }
 
-int mapif_guild_castle_alldataload_sub(DBKey key, void *data, va_list ap)
-{
-	int fd = va_arg(ap, int);
-	int *p = va_arg(ap, int*);
-
-
-	return 0;
-}
-
 int mapif_guild_castle_alldataload(int fd)
 {
 	DBIterator* iter;
@@ -1498,16 +1450,6 @@ int mapif_parse_GuildCastleDataLoad(int fd, int castle_id, int index)
 	case 16:
 	case 17:
 		return mapif_guild_castle_dataload(gc->castle_id, index, gc->guardian[index-10].visible);
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		return mapif_guild_castle_dataload(gc->castle_id, index, gc->guardian[index-18].hp);	// end additions [Valaris]
-
 	default:
 		ShowError("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n", index);
 		return 0;
@@ -1555,15 +1497,6 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
 	case 16:
 	case 17:
 		gc->guardian[index-10].visible = value; break;
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		gc->guardian[index-18].hp = value; break;	// end additions [Valaris]
 	default:
 		ShowError("mapif_parse_GuildCastleDataSave ERROR!! (Not found index=%d)\n", index);
 		return 0;

+ 5 - 43
src/char_sql/int_guild.c

@@ -564,13 +564,10 @@ ShowDebug("Save guild_castle (%d)\n", gc->castle_id);
 //	sql_query("DELETE FROM `%s` WHERE `castle_id`='%d'",guild_castle_db, gc->castle_id);
 	if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` "
 		"(`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`,"
-		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`,"
-		"`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`)"
-		"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
-		guild_castle_db, gc->castle_id, gc->guild_id,  gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime,
-		gc->createTime, gc->visibleC,
-		gc->guardian[0].visible, gc->guardian[1].visible, gc->guardian[2].visible, gc->guardian[3].visible, gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible,
-		gc->guardian[0].hp, gc->guardian[1].hp, gc->guardian[2].hp, gc->guardian[3].hp, gc->guardian[4].hp, gc->guardian[5].hp, gc->guardian[6].hp, gc->guardian[7].hp) )
+		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`)"
+		"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
+		guild_castle_db, gc->castle_id, gc->guild_id,  gc->economy, gc->defense, gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC,
+		gc->guardian[0].visible, gc->guardian[1].visible, gc->guardian[2].visible, gc->guardian[3].visible, gc->guardian[4].visible, gc->guardian[5].visible, gc->guardian[6].visible, gc->guardian[7].visible) )
 		Sql_ShowDebug(sql_handle);
 
 #ifndef TXT_SQL_CONVERT
@@ -605,8 +602,7 @@ int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
 
 	memset(gc,0,sizeof(struct guild_castle));
 	if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, "
-		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`,"
-		"`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`"
+		"`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`"
 		" FROM `%s` WHERE `castle_id`='%d'", guild_castle_db, castle_id) )
 	{
 		Sql_ShowDebug(sql_handle);
@@ -637,14 +633,6 @@ int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc)
 	Sql_GetData(sql_handle, 15, &data, NULL); gc->guardian[5].visible = atoi(data);
 	Sql_GetData(sql_handle, 16, &data, NULL); gc->guardian[6].visible = atoi(data);
 	Sql_GetData(sql_handle, 17, &data, NULL); gc->guardian[7].visible = atoi(data);
-	Sql_GetData(sql_handle, 18, &data, NULL); gc->guardian[0].hp = atoi(data);
-	Sql_GetData(sql_handle, 19, &data, NULL); gc->guardian[1].hp = atoi(data);
-	Sql_GetData(sql_handle, 20, &data, NULL); gc->guardian[2].hp = atoi(data);
-	Sql_GetData(sql_handle, 21, &data, NULL); gc->guardian[3].hp = atoi(data);
-	Sql_GetData(sql_handle, 22, &data, NULL); gc->guardian[4].hp = atoi(data);
-	Sql_GetData(sql_handle, 23, &data, NULL); gc->guardian[5].hp = atoi(data);
-	Sql_GetData(sql_handle, 24, &data, NULL); gc->guardian[6].hp = atoi(data);
-	Sql_GetData(sql_handle, 25, &data, NULL); gc->guardian[7].hp = atoi(data);
 
 	Sql_FreeResult(sql_handle);
 	memcpy(&castles[castle_id],gc,sizeof(struct guild_castle));
@@ -1231,14 +1219,6 @@ int mapif_guild_castle_alldataload(int fd)
 		Sql_GetData(sql_handle, 15, &data, NULL); gc->guardian[5].visible = atoi(data);
 		Sql_GetData(sql_handle, 16, &data, NULL); gc->guardian[6].visible = atoi(data);
 		Sql_GetData(sql_handle, 17, &data, NULL); gc->guardian[7].visible = atoi(data);
-		Sql_GetData(sql_handle, 18, &data, NULL); gc->guardian[0].hp = atoi(data);
-		Sql_GetData(sql_handle, 19, &data, NULL); gc->guardian[1].hp = atoi(data);
-		Sql_GetData(sql_handle, 20, &data, NULL); gc->guardian[2].hp = atoi(data);
-		Sql_GetData(sql_handle, 21, &data, NULL); gc->guardian[3].hp = atoi(data);
-		Sql_GetData(sql_handle, 22, &data, NULL); gc->guardian[4].hp = atoi(data);
-		Sql_GetData(sql_handle, 23, &data, NULL); gc->guardian[5].hp = atoi(data);
-		Sql_GetData(sql_handle, 24, &data, NULL); gc->guardian[6].hp = atoi(data);
-		Sql_GetData(sql_handle, 25, &data, NULL); gc->guardian[7].hp = atoi(data);
 
 		memcpy(WFIFOP(fd, len), gc, sizeof(struct guild_castle));
 		len += sizeof(struct guild_castle);
@@ -1853,15 +1833,6 @@ int mapif_parse_GuildCastleDataLoad(int fd,int castle_id,int index)
 	case 16:
 	case 17:
 		return mapif_guild_castle_dataload(gc.castle_id,index,gc.guardian[index-10].visible); break;
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		return mapif_guild_castle_dataload(gc.castle_id,index,gc.guardian[index-18].hp); break;
 	default:
 		ShowError("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n", index);
 		return 0;
@@ -1906,15 +1877,6 @@ int mapif_parse_GuildCastleDataSave(int fd,int castle_id,int index,int value)
 	case 16:
 	case 17:
 		gc.guardian[index-10].visible = value; break;
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		gc.guardian[index-18].hp = value; break;	// end additions [Valaris]
 	default:
 		ShowError("mapif_parse_GuildCastleDataSave ERROR!! (Not found index=%d)\n", index);
 		return 0;

+ 2 - 3
src/common/mmo.h

@@ -391,9 +391,8 @@ struct guild_castle {
 	int visibleC;
 	struct {
 		unsigned visible : 1;
-		int hp;
-		int id;
-	} guardian[MAX_GUARDIANS]; //New simplified structure. [Skotlex]
+		int id; // object id
+	} guardian[MAX_GUARDIANS];
 };
 
 // for Brandish Spear calculations

+ 1 - 3
src/map/battle.c

@@ -548,9 +548,7 @@ int battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int dama
 		break;
 	default:
 		if (md && md->guardian_data) {
-			damage -= damage
-			  	* (md->guardian_data->castle->defense/100)
-				* battle_config.castle_defense_rate/100;
+			damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
 		}
 		if (flag & BF_SKILL) { //Skills get a different reduction than non-skills. [Skotlex]
 			if (flag&BF_WEAPON)

+ 17 - 26
src/map/guild.c

@@ -1723,15 +1723,6 @@ int guild_castledataloadack(int castle_id,int index,int value)
 	case 16:
 	case 17:
 		gc->guardian[index-10].visible = value; break;
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		gc->guardian[index-18].hp = value; break;
 	default:
 		ShowError("guild_castledataloadack ERROR!! (Not found index=%d)\n", index);
 		return 0;
@@ -1749,14 +1740,28 @@ int guild_castledataloadack(int castle_id,int index,int value)
 // ギルド城データ変更要求
 int guild_castledatasave(int castle_id,int index,int value)
 {
-	if (index == 1)
+	if( index == 1 )
 	{	//The castle's owner has changed? Update Guardian ownership, too. [Skotlex]
 		struct guild_castle *gc = guild_castle_search(castle_id);
 		int m = -1;
 		if (gc) m = map_mapname2mapid(gc->map_name);
 		if (m != -1)
-			map_foreachinmap(mob_guardian_guildchange, m, BL_MOB);
+			map_foreachinmap(mob_guardian_guildchange, m, BL_MOB); //FIXME: why not iterate over gc->guardian[i].id ?
 	}
+	else
+	if( index == 3 )
+	{	// defense invest change -> recalculate guardian hp
+		struct guild_castle* gc = guild_castle_search(castle_id);
+		if( gc )
+		{
+			int i;
+			struct mob_data* gd;
+			for( i = 0; i < MAX_GUARDIANS; i++ )
+				if( gc->guardian[i].visible && (gd = map_id2md(gc->guardian[i].id)) != NULL )
+						status_calc_mob(gd,0);
+		}
+	}
+
 	return intif_guild_castle_datasave(castle_id,index,value);
 }
 
@@ -1786,15 +1791,6 @@ int guild_castledatasaveack(int castle_id,int index,int value)
 	case 16:
 	case 17:
 		gc->guardian[index-10].visible = value; break;
-	case 18:
-	case 19:
-	case 20:
-	case 21:
-	case 22:
-	case 23:
-	case 24:
-	case 25:
-		gc->guardian[index-18].hp = value; break;
 	default:
 		ShowError("guild_castledatasaveack ERROR!! (Not found index=%d)\n", index);
 		return 0;
@@ -1864,7 +1860,7 @@ static int Gid[MAX_GUILDCASTLE];
 int guild_save_sub(int tid,unsigned int tick,int id,int data)
 {
 	struct guild_castle *gc;
-	int i,j;
+	int i;
 
 	for(i = 0; i < MAX_GUILDCASTLE; i++) {	// [Yor]
 		gc = guild_castle_search(i);
@@ -1874,11 +1870,6 @@ int guild_save_sub(int tid,unsigned int tick,int id,int data)
 			guild_castledatasave(gc->castle_id, 1, gc->guild_id);
 			Gid[i] = gc->guild_id;
 		}
-		for (j = 0; j < MAX_GUARDIANS; j++)
-		{
-			if (gc->guardian[j].visible && Ghp[i][j] != gc->guardian[j].hp)
-				guild_castledatasave(gc->castle_id, 18+j, gc->guardian[j].hp);
-		}
 	}
 
 	return 0;

+ 6 - 0
src/map/map.c

@@ -1763,6 +1763,12 @@ struct map_session_data * map_id2sd(int id)
 	return (struct map_session_data*)idb_get(pc_db,id);
 }
 
+struct mob_data * map_id2md(int id)
+{// just a id2bl lookup because there's no mob_db
+	if (id <= 0) return NULL;
+	return (struct mob_data*)map_id2bl(id);
+}
+
 struct npc_data * map_id2nd(int id)
 {// just a id2bl lookup because there's no npc_db
 	if (id <= 0) return NULL;

+ 4 - 3
src/map/map.h

@@ -1319,9 +1319,10 @@ void map_reqnickdb(struct map_session_data* sd,int charid);
 const char* map_charid2nick(int charid);
 struct map_session_data* map_charid2sd(int charid);
 
-struct map_session_data * map_id2sd(int);
-struct npc_data * map_id2nd(int);
-struct block_list * map_id2bl(int);
+struct map_session_data * map_id2sd(int id);
+struct mob_data * map_id2md(int id);
+struct npc_data * map_id2nd(int id);
+struct block_list * map_id2bl(int id);
 
 #define map_id2index(id) map[(id)].index
 int map_mapindex2mapid(unsigned short mapindex);

+ 0 - 13
src/map/mob.c

@@ -439,7 +439,6 @@ static int mob_spawn_guardian_sub(int tid,unsigned int tick,int id,int data)
 			{	//Safe removal of guardian.
 				md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
 				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
-				guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
 			}
 			unit_free(&md->bl,0); //Remove guardian.
 		}
@@ -1734,9 +1733,6 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage)
 		if (src) mob_log_damage(md, src, damage);
 	}
 
-	if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS) // guardian hp update [Valaris] (updated by [Skotlex])
-		md->guardian_data->castle->guardian[md->guardian_data->number].hp = md->status.hp;
-
 	if (battle_config.show_mob_info&3)
 		clif_charnameack (0, &md->bl);
 	
@@ -1779,10 +1775,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 	status = &md->status;
 		
 	if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS)
-	{	// guardian hp update [Valaris] (updated by [Skotlex])
 		guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
-		guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
-	}
 
 	md->state.skillstate = MSS_DEAD;	
 	mobskill_use(md,tick,-1);	//On Dead skill.
@@ -2291,7 +2284,6 @@ int mob_guardian_guildchange(struct block_list *bl,va_list ap)
 			{	//Safe removal of guardian.
 				md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
 				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
-				guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
 			}
 			unit_free(&md->bl,0); //Remove guardian.
 		}
@@ -2304,7 +2296,6 @@ int mob_guardian_guildchange(struct block_list *bl,va_list ap)
 		ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
 		md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
 		guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
-		guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
 		unit_free(&md->bl,0);
 		return 0;
 	}
@@ -2412,10 +2403,6 @@ int mob_class_change (struct mob_data *md, int class_)
  *------------------------------------------*/
 void mob_heal(struct mob_data *md,unsigned int heal)
 {
-	if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS)
-	// guardian hp update [Valaris] (updated by [Skotlex])
-		md->guardian_data->castle->guardian[md->guardian_data->number].hp = md->status.hp;
-
 	if (battle_config.show_mob_info&3)
 		clif_charnameack (0, &md->bl);
 }

+ 32 - 45
src/map/script.c

@@ -9127,7 +9127,7 @@ BUILDIN_FUNC(getcastledata)
 		switch(index){
 			case 0: {
 				int i;
-				for(i=1;i<26;i++) // Initialize[AgitInit]
+				for(i=1;i<18;i++) // Initialize[AgitInit]
 					guild_castledataload(gc->castle_id,i);
 				} break;
 			case 1:
@@ -9157,15 +9157,6 @@ BUILDIN_FUNC(getcastledata)
 			case 16:
 			case 17:
 				script_pushint(st,gc->guardian[index-10].visible); break;
-			case 18:
-			case 19:
-			case 20:
-			case 21:
-			case 22:
-			case 23:
-			case 24:
-			case 25:
-				script_pushint(st,gc->guardian[index-18].hp); break;
 			default:
 				script_pushint(st,0); break;
 		}
@@ -9213,30 +9204,6 @@ BUILDIN_FUNC(setcastledata)
 			case 16:
 			case 17:
 				gc->guardian[index-10].visible = value; break;
-			case 18:
-			case 19:
-			case 20:
-			case 21:
-			case 22:
-			case 23:
-			case 24:
-			case 25:
-				gc->guardian[index-18].hp = value;
-				if (gc->guardian[index-18].id)
-				{	//Update this mob's HP.
-					struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
-					if (!bl)
-					{	//Wrong target?
-						gc->guardian[index-18].id = 0;
-						break;
-					}
-					if (value < 1) {
-						status_kill(bl);
-						break;
-					}
-					status_set_hp(bl, value, 0);
-				}
-				break;
 			default:
 				return 0;
 		}
@@ -9742,27 +9709,47 @@ BUILDIN_FUNC(guardian)
 	return 0;
 }
 
-/*================================================
- * Script for Displaying Guardian Info [Valaris]
- *------------------------------------------------*/
+/// Retrieves various information about the specified guardian.
+///
+/// guardianinfo("<map_name>", <index>, <type>) -> <value>
+/// type: 0 - whether it is deployed or not
+///       1 - maximum hp
+///       2 - current hp
+///
 BUILDIN_FUNC(guardianinfo)
 {
-	int guardian=script_getnum(st,2);
-	TBL_PC *sd=script_rid2sd(st);
-	struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
+	const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
+	int id = script_getnum(st,3);
+	int type = script_getnum(st,4);
 
-	if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
+	struct guild_castle* gc = guild_mapname2gc(mapname);
+	struct mob_data* gd;
+
+	if( gc == NULL || id < 0 || id >= MAX_GUARDIANS )
 	{
 		script_pushint(st,-1);
 		return 0;
 	}
 
-	if(gc->guardian[guardian].visible)
-		script_pushint(st,gc->guardian[guardian].hp);
-	else script_pushint(st,-1);
+	if( type == 0 )
+		script_pushint(st, gc->guardian[id].visible);
+	else
+	if( !gc->guardian[id].visible )
+		script_pushint(st,-1);
+	else
+	if( (gd = map_id2md(gc->guardian[id].id)) == NULL )
+		script_pushint(st,-1);
+	else
+	{
+		if     ( type == 1 ) script_pushint(st,gd->status.max_hp);
+		else if( type == 2 ) script_pushint(st,gd->status.hp);
+		else
+			script_pushint(st,-1);
+	}
 
 	return 0;
 }
+
 /*==========================================
  * ID‚©‚çItem–¼
  *------------------------------------------*/
@@ -13158,7 +13145,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(soundeffectall,"si*"),	// SoundEffectAll [Codemaster]
 	BUILDIN_DEF(strmobinfo,"ii"),	// display mob data [Valaris]
 	BUILDIN_DEF(guardian,"siisi??"),	// summon guardians
-	BUILDIN_DEF(guardianinfo,"i"),	// display guardian data [Valaris]
+	BUILDIN_DEF(guardianinfo,"sii"),	// display guardian data [Valaris]
 	BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris]
 	BUILDIN_DEF(petrecovery,"ii"), // [Valaris]
 	BUILDIN_DEF(petloot,"i"), // [Valaris]

+ 3 - 4
src/map/status.c

@@ -834,11 +834,13 @@ int status_heal(struct block_list *bl,int hp,int sp, int flag)
 	)	//End auto berserk.
 		status_change_end(bl,SC_PROVOKE,-1);
 
+	// send hp update to client
 	switch(bl->type) {
 	case BL_PC:  pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
 	case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
 	case BL_HOM: merc_hom_heal((TBL_HOM*)bl,hp,sp); break;
 	}
+
 	return hp+sp;
 }
 
@@ -1446,10 +1448,7 @@ int status_calc_mob(struct mob_data* md, int first)
 		else {
 			status->max_hp += 2000 * gc->defense;
 			status->max_sp += 200 * gc->defense;
-			if (md->guardian_data->number < MAX_GUARDIANS) //Spawn with saved HP
-				status->hp = gc->guardian[md->guardian_data->number].hp;
-			else //Emperium
-				status->hp = status->max_hp;
+			status->hp = status->max_hp;
 			status->sp = status->max_sp;
 		}
 		status->batk += status->batk * 10*md->guardian_data->guardup_lv/100;