Browse Source

Added constants for Castle Data manipulation (#3531)

* Fixes #3530.
* Added constants for script commands getcastledata and setcastledata.
* Adjusted the guardian constants to adjust based on MAX_GUARDIANS define value.
* Updated scripts to reflect changes.
Thanks to @keitenai, @Atemo, and @Lemongrass3110!
Aleos 6 years ago
parent
commit
7045d585e4

+ 20 - 20
doc/script_commands.txt

@@ -3375,29 +3375,29 @@ to by its map name. Castle information is stored in `guild_castle` SQL table.
 
 
 Types of data correspond to `guild_castle` table columns:
 Types of data correspond to `guild_castle` table columns:
 
 
- 1 - `guild_id`   - Guild ID.
- 2 - `economy`    - Castle Economy score.
- 3 - `defense`    - Castle Defense score.
- 4 - `triggerE`   - Number of times the economy was invested in today.
- 5 - `triggerD`   - Number of times the defense was invested in today.
- 6 - `nextTime`   - unused
- 7 - `payTime`    - unused
- 8 - `createTime` - unused
- 9 - `visibleC`   - Is 1 if a Kafra was hired for this castle, 0 otherwise.
-10 - `visibleG0`  - Is 1 if the 1st guardian is present (Soldier Guardian)
-11 - `visibleG1`  - Is 1 if the 2nd guardian is present (Soldier Guardian)
-12 - `visibleG2`  - Is 1 if the 3rd guardian is present (Soldier Guardian)
-13 - `visibleG3`  - Is 1 if the 4th guardian is present (Archer Guardian)
-14 - `visibleG4`  - Is 1 if the 5th guardian is present (Archer Guardian)
-15 - `visibleG5`  - Is 1 if the 6th guardian is present (Knight Guardian)
-16 - `visibleG6`  - Is 1 if the 7th guardian is present (Knight Guardian)
-17 - `visibleG7`  - Is 1 if the 8th guardian is present (Knight Guardian)
+CD_GUILD_ID          - Guild ID.
+CD_CURRENT_ECONOMY   - Castle Economy score.
+CD_CURRENT_DEFENSE   - Castle Defense score.
+CD_INVESTED_ECONOMY  - Number of times the economy was invested in today.
+CD_INVESTED_DEFENSE  - Number of times the defense was invested in today.
+CD_NEXT_TIME         - unused
+CD_PAY_TIME          - unused
+CD_CREATE_TIME       - unused
+CD_ENABLED_KAFRA     - Is 1 if a Kafra was hired for this castle, 0 otherwise.
+CD_ENABLED_GUARDIAN0 - Is 1 if the 1st guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN1 - Is 1 if the 2nd guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN2 - Is 1 if the 3rd guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN3 - Is 1 if the 4th guardian is present (Archer Guardian)
+CD_ENABLED_GUARDIAN4 - Is 1 if the 5th guardian is present (Archer Guardian)
+CD_ENABLED_GUARDIAN5 - Is 1 if the 6th guardian is present (Knight Guardian)
+CD_ENABLED_GUARDIAN6 - Is 1 if the 7th guardian is present (Knight Guardian)
+CD_ENABLED_GUARDIAN7 - Is 1 if the 8th guardian is present (Knight Guardian)
 
 
 All types of data have their meaning determined by War of Emperium scripts,
 All types of data have their meaning determined by War of Emperium scripts,
 with exception of:
 with exception of:
- - `guild_id` that is always considered ID of the guild that owns the castle,
- - `defense` that is used in Guardians & Emperium HP calculations,
- - `visibleG` that is always considered to hold guardian presence bits.
+ - CD_GUILD_ID that is always considered ID of the guild that owns the castle,
+ - CD_CURRENT_DEFENSE that is used in Guardians & Emperium HP calculations,
+ - CD_ENABLED_GUARDIANX that is always considered to hold guardian presence bits.
 
 
 The 'setcastledata' command will behave identically, but instead of returning
 The 'setcastledata' command will behave identically, but instead of returning
 values for the specified types of accessible data, it will alter them and cause
 values for the specified types of accessible data, it will alter them and cause

+ 46 - 46
npc/guild/agit_main.txt

@@ -63,7 +63,7 @@
 // War of Emperium has started.
 // War of Emperium has started.
 OnAgitStart:
 OnAgitStart:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
-	MapRespawnGuildID strnpcinfo(2),GetCastleData(strnpcinfo(2),1),6;
+	MapRespawnGuildID strnpcinfo(2),GetCastleData(strnpcinfo(2),CD_GUILD_ID),6;
 	GvgOn strnpcinfo(2);
 	GvgOn strnpcinfo(2);
 
 
 // Spawn (fall through), or respawn the Emperium once it has been broken.
 // Spawn (fall through), or respawn the Emperium once it has been broken.
@@ -109,16 +109,16 @@ OnAgitBreak:
 		end;
 		end;
 	}
 	}
 	// Adjust Economy Invest Level for Castle
 	// Adjust Economy Invest Level for Castle
-	set .@Economy,GetCastleData(strnpcinfo(2),2) - 5;
+	set .@Economy,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY) - 5;
 	if (.@Economy < 0) set .@Economy, 0;
 	if (.@Economy < 0) set .@Economy, 0;
-	SetCastleData strnpcinfo(2), 2, .@Economy;
+	SetCastleData strnpcinfo(2), CD_CURRENT_ECONOMY, .@Economy;
 	// Adjust Defense Invest Level for Castle
 	// Adjust Defense Invest Level for Castle
-	set .@Defence,GetCastleData(strnpcinfo(2),3) - 5;
+	set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE) - 5;
 	if (.@Defence < 0) set .@Defence, 0;
 	if (.@Defence < 0) set .@Defence, 0;
-	SetCastleData strnpcinfo(2), 3, .@Defence;
+	SetCastleData strnpcinfo(2), CD_CURRENT_DEFENSE, .@Defence;
 
 
 	// Set new Castle Occupant
 	// Set new Castle Occupant
-	SetCastleData strnpcinfo(2),1, .@GID;
+	SetCastleData strnpcinfo(2),CD_GUILD_ID, .@GID;
 
 
 	// Announce that the Emperium is destroyed, and respawn all but new castle-occupants.
 	// Announce that the Emperium is destroyed, and respawn all but new castle-occupants.
 	mapannounce strnpcinfo(2),"The emperium has been destroyed.",bc_map|bc_woe,"0x00CCFF",FW_NORMAL,12;
 	mapannounce strnpcinfo(2),"The emperium has been destroyed.",bc_map|bc_woe,"0x00CCFF",FW_NORMAL,12;
@@ -127,12 +127,12 @@ OnAgitBreak:
 	// Refresh castle data, disable Kafra and reset Invest information.
 	// Refresh castle data, disable Kafra and reset Invest information.
 	donpcevent strnpcinfo(0)+"::OnRecvCastle";
 	donpcevent strnpcinfo(0)+"::OnRecvCastle";
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
-	for( set .@i, 4; .@i <= 9; set .@i, .@i+1 ) {
+	for( set .@i, CD_INVESTED_ECONOMY; .@i <= CD_ENABLED_KAFRA; set .@i, .@i+1 ) {
 		SetCastleData strnpcinfo(2), .@i, 0;
 		SetCastleData strnpcinfo(2), .@i, 0;
 	}
 	}
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	if( getgdskilllv(.@GID,10002) == 0 ) {
 	if( getgdskilllv(.@GID,10002) == 0 ) {
-		for( set .@i, 10; .@i <= 17; set .@i, .@i+1 ) {
+		for( set .@i, CD_ENABLED_GUARDIAN00; .@i < CD_MAX; set .@i, .@i+1 ) {
 			SetCastleData strnpcinfo(2), .@i, 0;
 			SetCastleData strnpcinfo(2), .@i, 0;
 		}
 		}
 	}
 	}
@@ -149,7 +149,7 @@ OnAgitEnd:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	GvgOff strnpcinfo(2);
 	GvgOff strnpcinfo(2);
 	// If the castle has no owner at the end of WoE, do not kill Emperium.
 	// If the castle has no owner at the end of WoE, do not kill Emperium.
-	if (GetCastleData(strnpcinfo(2),1)) {
+	if (GetCastleData(strnpcinfo(2),CD_GUILD_ID)) {
 		KillMonster strnpcinfo(2),"Agit#"+strnpcinfo(2)+"::OnAgitBreak";
 		KillMonster strnpcinfo(2),"Agit#"+strnpcinfo(2)+"::OnAgitBreak";
 	}
 	}
 	end;
 	end;
@@ -160,7 +160,7 @@ OnGuildBreak:
 	// Kill guardians, disable the Kafra, and set owner to 0.
 	// Kill guardians, disable the Kafra, and set owner to 0.
 	killmonster strnpcinfo(2),"Guardian#"+strnpcinfo(2)+"::OnGuardianDied";
 	killmonster strnpcinfo(2),"Guardian#"+strnpcinfo(2)+"::OnGuardianDied";
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
-	SetCastleData strnpcinfo(2),1,0;
+	SetCastleData strnpcinfo(2),CD_GUILD_ID,0;
 	// Wait before refreshing guild information.
 	// Wait before refreshing guild information.
 	sleep 7000;
 	sleep 7000;
 	Announce "Guild Base [" + GetCastleName(strnpcinfo(2)) + "] has been abandoned.",0;
 	Announce "Guild Base [" + GetCastleName(strnpcinfo(2)) + "] has been abandoned.",0;
@@ -171,7 +171,7 @@ OnAgitInit:
 OnRecvCastle:
 OnRecvCastle:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	// Spawn Monsters if the castle is empty.
 	// Spawn Monsters if the castle is empty.
-	set .@GID, GetCastleData(strnpcinfo(2),1);
+	set .@GID, GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 	if (.@GID == 0) {
 	if (.@GID == 0) {
 		killmonsterall strnpcinfo(2);
 		killmonsterall strnpcinfo(2);
 		if (compare(strnpcinfo(2),"aldeg")) {
 		if (compare(strnpcinfo(2),"aldeg")) {
@@ -309,7 +309,7 @@ OnRecvCastle:
 		// And load purchased Guardian in castles.
 		// And load purchased Guardian in castles.
 		donpcevent "Guardian#"+strnpcinfo(2)+"::OnSpawnGuardians";
 		donpcevent "Guardian#"+strnpcinfo(2)+"::OnSpawnGuardians";
 		// And display Kafra if purchased.
 		// And display Kafra if purchased.
-		if (GetCastleData(strnpcinfo(2),9) < 1) disablenpc "Kafra Staff#"+strnpcinfo(2);
+		if (GetCastleData(strnpcinfo(2),CD_ENABLED_KAFRA) < 1) disablenpc "Kafra Staff#"+strnpcinfo(2);
 	}
 	}
 	end;
 	end;
 }
 }
@@ -318,7 +318,7 @@ OnRecvCastle:
 //============================================================
 //============================================================
 -	script	Kafra Staff#woe::guildkafra	-1,{
 -	script	Kafra Staff#woe::guildkafra	-1,{
 
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 
 	if (compare(strnpcinfo(2),"aldeg")) {
 	if (compare(strnpcinfo(2),"aldeg")) {
 		setarray .@destination$[0],"Al De Baran","aldebaran";
 		setarray .@destination$[0],"Al De Baran","aldebaran";
@@ -467,7 +467,7 @@ OnRecvCastle:
 //============================================================
 //============================================================
 -	script	Castle Manager#cm::cm	-1,{
 -	script	Castle Manager#cm::cm	-1,{
 
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 
 	// .@guardiantype = Defines the types of guardians per castle basis.
 	// .@guardiantype = Defines the types of guardians per castle basis.
 	// 1 - Soldier Guardian, 2 - Archer Guardian, 3 - Knight Guardian
 	// 1 - Soldier Guardian, 2 - Archer Guardian, 3 - Knight Guardian
@@ -624,19 +624,19 @@ OnRecvCastle:
 		mes "["+strnpcinfo(1)+"]";
 		mes "["+strnpcinfo(1)+"]";
 		mes "I will report the Castle briefing, Master.";
 		mes "I will report the Castle briefing, Master.";
 		mes " ";
 		mes " ";
-		mes "^0000ffNow, the commercial growth level is "+GetCastleData(strnpcinfo(2),2)+".";
-		if (GetCastleData(strnpcinfo(2),4)) {
-			mes " You invested "+GetCastleData(strnpcinfo(2),4)+" times in past 1 day.";
+		mes "^0000ffNow, the commercial growth level is "+GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY)+".";
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+			mes " You invested "+GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)+" times in past 1 day.";
 		}
 		}
-		mes " Now, the Castle Defense level is "+GetCastleData(strnpcinfo(2),3)+".^000000";
-		if (GetCastleData(strnpcinfo(2),5)) {
-			mes " ^0000ff- You invested "+GetCastleData(strnpcinfo(2),5)+" times in past 1 day.^000000";
+		mes " Now, the Castle Defense level is "+GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE)+".^000000";
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+			mes " ^0000ff- You invested "+GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)+" times in past 1 day.^000000";
 		}
 		}
 		mes " ";
 		mes " ";
 		mes "That's all I have to report, Master.";
 		mes "That's all I have to report, Master.";
 		close;
 		close;
 	case 2:
 	case 2:
-		set .@Economy,GetCastleData(strnpcinfo(2),2);
+		set .@Economy,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY);
 		if (.@Economy < 6) { set .@eco_invest,5000; }
 		if (.@Economy < 6) { set .@eco_invest,5000; }
 		else if ((.@Economy >= 6) && (.@Economy <= 10)) { set .@eco_invest,10000; }
 		else if ((.@Economy >= 6) && (.@Economy <= 10)) { set .@eco_invest,10000; }
 		else if ((.@Economy >= 11) && (.@Economy <= 15)) { set .@eco_invest,20000; }
 		else if ((.@Economy >= 11) && (.@Economy <= 15)) { set .@eco_invest,20000; }
@@ -658,7 +658,7 @@ OnRecvCastle:
 		else if ((.@Economy >= 91) && (.@Economy <= 95)) { set .@eco_invest,860000; }
 		else if ((.@Economy >= 91) && (.@Economy <= 95)) { set .@eco_invest,860000; }
 		else if ((.@Economy >= 96) && (.@Economy <= 100)) { set .@eco_invest,955000; }
 		else if ((.@Economy >= 96) && (.@Economy <= 100)) { set .@eco_invest,955000; }
 		//Quadruple the cost of investing if you've already invested once.
 		//Quadruple the cost of investing if you've already invested once.
-		if (GetCastleData(strnpcinfo(2),4)) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
 			set .@eco_invest,.@eco_invest*4;
 			set .@eco_invest,.@eco_invest*4;
 		}
 		}
 		mes "["+strnpcinfo(1)+"]";
 		mes "["+strnpcinfo(1)+"]";
@@ -670,12 +670,12 @@ OnRecvCastle:
 			mes "^ff0000The commercial growth level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great economist like you, Master.^000000";
 			mes "^ff0000The commercial growth level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great economist like you, Master.^000000";
 			close;
 			close;
 		}
 		}
-		if (GetCastleData(strnpcinfo(2),4) >= 2) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) >= 2) {
 			mes " ";
 			mes " ";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect riches of the guild to grow at a high rate.";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect riches of the guild to grow at a high rate.";
 			close;
 			close;
 		}
 		}
-		if (GetCastleData(strnpcinfo(2),4) == 0) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) == 0) {
 			mes " ";
 			mes " ";
 			mes "The current investment amount required is ^ff0000"+.@eco_invest+"^000000 zeny. Will you invest?";
 			mes "The current investment amount required is ^ff0000"+.@eco_invest+"^000000 zeny. Will you invest?";
 		}
 		}
@@ -692,7 +692,7 @@ OnRecvCastle:
 				close;
 				close;
 			}
 			}
 			set Zeny, Zeny - .@eco_invest;
 			set Zeny, Zeny - .@eco_invest;
-			SetCastleData strnpcinfo(2),4,GetCastleData(strnpcinfo(2),4)+1;
+			SetCastleData strnpcinfo(2),CD_INVESTED_ECONOMY,GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)+1;
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "We finished the investment safely. I expect that our growth level will be increased by tomorrow.";
 			mes "We finished the investment safely. I expect that our growth level will be increased by tomorrow.";
 			close;
 			close;
@@ -702,7 +702,7 @@ OnRecvCastle:
 			close;
 			close;
 		}
 		}
 	case 3:
 	case 3:
-		set .@Defence,GetCastleData(strnpcinfo(2),3);
+		set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE);
 		if (.@Defence < 6) { set .@def_invest,10000; }
 		if (.@Defence < 6) { set .@def_invest,10000; }
 		else if ((.@Defence >= 6) && (.@Defence <= 10)) { set .@def_invest,20000; }
 		else if ((.@Defence >= 6) && (.@Defence <= 10)) { set .@def_invest,20000; }
 		else if ((.@Defence >= 11) && (.@Defence <= 15)) { set .@def_invest,40000; }
 		else if ((.@Defence >= 11) && (.@Defence <= 15)) { set .@def_invest,40000; }
@@ -724,7 +724,7 @@ OnRecvCastle:
 		else if ((.@Defence >= 91) && (.@Defence <= 95)) { set .@def_invest,1720000; }
 		else if ((.@Defence >= 91) && (.@Defence <= 95)) { set .@def_invest,1720000; }
 		else if ((.@Defence >= 96) && (.@Defence <= 100)) { set .@def_invest,1910000; }
 		else if ((.@Defence >= 96) && (.@Defence <= 100)) { set .@def_invest,1910000; }
 		//Quadruple the cost of investing if you've already invested once.
 		//Quadruple the cost of investing if you've already invested once.
-		if (GetCastleData(strnpcinfo(2),5)) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
 			set .@def_invest,.@def_invest*4;
 			set .@def_invest,.@def_invest*4;
 		}
 		}
 		mes "["+strnpcinfo(1)+"]";
 		mes "["+strnpcinfo(1)+"]";
@@ -736,12 +736,12 @@ OnRecvCastle:
 			mes "^ff0000But the Castle Defense level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great strategist like you, Master.^000000";
 			mes "^ff0000But the Castle Defense level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great strategist like you, Master.^000000";
 			close;
 			close;
 		}
 		}
-		if (GetCastleData(strnpcinfo(2),5) >= 2) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE) >= 2) {
 			mes " ";
 			mes " ";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect the Defenses of the guild to grow at a high rate.";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect the Defenses of the guild to grow at a high rate.";
 			close;
 			close;
 		}
 		}
-		if (GetCastleData(strnpcinfo(2),5) == 0) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE) == 0) {
 			mes " ";
 			mes " ";
 			mes "The current investment amount required is ^ff0000"+.@def_invest+"^000000 zeny. Will you invest?";
 			mes "The current investment amount required is ^ff0000"+.@def_invest+"^000000 zeny. Will you invest?";
 		}
 		}
@@ -758,7 +758,7 @@ OnRecvCastle:
 				close;
 				close;
 			}
 			}
 			set Zeny, Zeny - .@def_invest;
 			set Zeny, Zeny - .@def_invest;
-			SetCastleData strnpcinfo(2),5,GetCastleData(strnpcinfo(2),5)+1;
+			SetCastleData strnpcinfo(2),CD_INVESTED_DEFENSE,GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)+1;
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "We finished the investment safely. I expect that our Castle Defense level will be increased by tomorrow.";
 			mes "We finished the investment safely. I expect that our Castle Defense level will be increased by tomorrow.";
 			close;
 			close;
@@ -821,7 +821,7 @@ OnRecvCastle:
 			close;
 			close;
 		}
 		}
 	case 5:
 	case 5:
-		if (GetCastleData(strnpcinfo(2),9) == 1) {
+		if (GetCastleData(strnpcinfo(2),CD_ENABLED_KAFRA) == 1) {
 			mes "["+strnpcinfo(1)+"]";
 			mes "["+strnpcinfo(1)+"]";
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			next;
 			next;
@@ -850,7 +850,7 @@ OnRecvCastle:
 				close;
 				close;
 			}
 			}
 			disablenpc "Kafra Staff#"+strnpcinfo(2);
 			disablenpc "Kafra Staff#"+strnpcinfo(2);
-			SetCastleData strnpcinfo(2),9,0;
+			SetCastleData strnpcinfo(2),CD_ENABLED_KAFRA,0;
 			mes "["+strnpcinfo(1)+"]";
 			mes "["+strnpcinfo(1)+"]";
 			mes "....";
 			mes "....";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
@@ -874,7 +874,7 @@ OnRecvCastle:
 			}
 			}
 			set Zeny, Zeny - 10000;
 			set Zeny, Zeny - 10000;
 			enablenpc "Kafra Staff#"+strnpcinfo(2);
 			enablenpc "Kafra Staff#"+strnpcinfo(2);
-			SetCastleData strnpcinfo(2),9,1;
+			SetCastleData strnpcinfo(2),CD_ENABLED_KAFRA,1;
 			mes "["+strnpcinfo(1)+"]";
 			mes "["+strnpcinfo(1)+"]";
 			mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 			mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 			next;
 			next;
@@ -919,7 +919,7 @@ OnRecvCastle:
 //============================================================
 //============================================================
 -	script	Lever#gd::gdlever	-1,{
 -	script	Lever#gd::gdlever	-1,{
 
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 
 	if (.@GID == 0) {
 	if (.@GID == 0) {
 		mes "[Ringing Voice]";
 		mes "[Ringing Voice]";
@@ -1133,13 +1133,13 @@ OnClock0001:
 	// Do nothing if this script is the template.
 	// Do nothing if this script is the template.
 	if (strnpcinfo(1) == "Gld_Trea_Spawn") end;
 	if (strnpcinfo(1) == "Gld_Trea_Spawn") end;
 	
 	
-	set .@GID, GetCastleData(strnpcinfo(2),1);
+	set .@GID, GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 	
 	
 	// If there is no owner, do nothing.
 	// If there is no owner, do nothing.
 	if (!.@GID) end;
 	if (!.@GID) end;
 
 
 	// Is there Economy in this castle?
 	// Is there Economy in this castle?
-	set .@Treasure,GetCastleData(strnpcinfo(2),2)/5+4;
+	set .@Treasure,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY)/5+4;
 
 
 	// Set information
 	// Set information
 	if (strnpcinfo(2) == "aldeg_cas01") { 
 	if (strnpcinfo(2) == "aldeg_cas01") { 
@@ -1249,19 +1249,19 @@ OnClock0001:
 
 
 	// Apply investment to Eco. and Def. Only happens if there were investments made.
 	// Apply investment to Eco. and Def. Only happens if there were investments made.
 	// Permanent Development can only happen once per day.
 	// Permanent Development can only happen once per day.
-	if (GetCastleData(strnpcinfo(2),4)) {
-		set .@Economy,GetCastleData(strnpcinfo(2),2);
-		SetCastleData strnpcinfo(2),2,.@Economy + GetCastleData(strnpcinfo(2),4) + (rand(2) && getgdskilllv(.@GID,10014));
-		if (GetCastleData(strnpcinfo(2),2) > 100) SetCastleData strnpcinfo(2),2,100;
+	if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+		set .@Economy,GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY);
+		SetCastleData strnpcinfo(2),CD_INVESTED_ECONOMY,.@Economy + GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) + (rand(2) && getgdskilllv(.@GID,10014));
+		if (GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY) > 100) SetCastleData strnpcinfo(2),CD_CURRENT_ECONOMY,100;
 	}
 	}
-	if (GetCastleData(strnpcinfo(2),5)) {
-		set .@Defence,GetCastleData(strnpcinfo(2),3);
-		SetCastleData strnpcinfo(2),3,.@Defence + GetCastleData(strnpcinfo(2),5);
-		if (GetCastleData(strnpcinfo(2),3) > 100) SetCastleData strnpcinfo(2),3,100;
+	if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+		set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE);
+		SetCastleData strnpcinfo(2),CD_CURRENT_DEFENSE,.@Defence + GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE);
+		if (GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE) > 100) SetCastleData strnpcinfo(2),CD_CURRENT_DEFENSE,100;
 	}
 	}
 	// Reset daily investment limits.
 	// Reset daily investment limits.
-	setcastledata strnpcinfo(2),4,0;
-	setcastledata strnpcinfo(2),5,0;
+	setcastledata strnpcinfo(2),CD_INVESTED_ECONOMY,0;
+	setcastledata strnpcinfo(2),CD_INVESTED_DEFENSE,0;
 
 
 	// Spawn boxes in proper order.
 	// Spawn boxes in proper order.
 	for (set .@i,0; .@i < .@Treasure ; set .@i,.@i+1) {
 	for (set .@i,0; .@i < .@Treasure ; set .@i,.@i+1) {

+ 57 - 57
npc/guild2/agit_main_se.txt

@@ -25,7 +25,7 @@
 OnAgitInit2:
 OnAgitInit2:
 OnRecvCastle2:
 OnRecvCastle2:
 	if (strnpcinfo(2) == "template") end;
 	if (strnpcinfo(2) == "template") end;
-	if (!getcastledata(strnpcinfo(2),1)) {
+	if (!getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		donpcevent strnpcinfo(0)+"::OnStart";
 		donpcevent strnpcinfo(0)+"::OnStart";
 		// Monster spawns are identical for all castles.
 		// Monster spawns are identical for all castles.
 		monster strnpcinfo(2),0,0,"Evil Druid",1117,10;
 		monster strnpcinfo(2),0,0,"Evil Druid",1117,10;
@@ -42,14 +42,14 @@ OnRecvCastle2:
 		monster strnpcinfo(2),0,0,"Dark Lord",1272,2;
 		monster strnpcinfo(2),0,0,"Dark Lord",1272,2;
 		monster strnpcinfo(2),0,0,"Tower Keeper",1270,4;
 		monster strnpcinfo(2),0,0,"Tower Keeper",1270,4;
 	}
 	}
-	if (getcastledata(strnpcinfo(2),9) < 1)
+	if (getcastledata(strnpcinfo(2),CD_ENABLED_KAFRA) < 1)
 		disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 		disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 	end;
 	end;
 
 
 OnAgitStart2:
 OnAgitStart2:
 	if (strnpcinfo(2) == "template") end;
 	if (strnpcinfo(2) == "template") end;
 	if (agitcheck2()) {
 	if (agitcheck2()) {
-		maprespawnguildid strnpcinfo(2),getcastledata(strnpcinfo(2),1),2;
+		maprespawnguildid strnpcinfo(2),getcastledata(strnpcinfo(2),CD_GUILD_ID),2;
 		gvgon strnpcinfo(2);
 		gvgon strnpcinfo(2);
 		donpcevent strnpcinfo(0)+"::OnStart";
 		donpcevent strnpcinfo(0)+"::OnStart";
 	}
 	}
@@ -60,7 +60,7 @@ OnAgitStart2:
 OnAgitEnd2:
 OnAgitEnd2:
 	if (strnpcinfo(2) == "template") end;
 	if (strnpcinfo(2) == "template") end;
 	gvgoff strnpcinfo(2);
 	gvgoff strnpcinfo(2);
-	if (getcastledata(strnpcinfo(2),1)) {
+	if (getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		set .@str$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 		set .@str$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 		killmonster strnpcinfo(2),"Steward#"+.@str$+"::OnStartArena";
 		killmonster strnpcinfo(2),"Steward#"+.@str$+"::OnStartArena";
 		donpcevent strnpcinfo(0)+"::OnReset";
 		donpcevent strnpcinfo(0)+"::OnReset";
@@ -73,7 +73,7 @@ OnGuildBreak:
 	killmonster strnpcinfo(2),"gard1#"+strnpcinfo(2)+"::OnGuardianDied";
 	killmonster strnpcinfo(2),"gard1#"+strnpcinfo(2)+"::OnGuardianDied";
 	killmonster strnpcinfo(2),"gard2#"+strnpcinfo(2)+"::OnGuardianDied";
 	killmonster strnpcinfo(2),"gard2#"+strnpcinfo(2)+"::OnGuardianDied";
 	disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 	disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
-	setcastledata strnpcinfo(2),1,0;
+	setcastledata strnpcinfo(2),CD_GUILD_ID,0;
 	sleep 7000;
 	sleep 7000;
 	announce "Guild Base ["+getcastlename(strnpcinfo(2))+"] has been abandoned.",0;
 	announce "Guild Base ["+getcastlename(strnpcinfo(2))+"] has been abandoned.",0;
 	donpcevent strnpcinfo(0)+"::OnRecvCastle2";
 	donpcevent strnpcinfo(0)+"::OnRecvCastle2";
@@ -84,7 +84,7 @@ OnStart:
 	// 1st Guardian stone, 2nd Guardian stone, Barrier 1, Barrier 2, Barrier 3, Summon Guardians
 	// 1st Guardian stone, 2nd Guardian stone, Barrier 1, Barrier 2, Barrier 3, Summon Guardians
 	// Settings for all but Summon Guardians: 0 = Okay | 1 = Destroyed | 2 = Repairing
 	// Settings for all but Summon Guardians: 0 = Okay | 1 = Destroyed | 2 = Repairing
 	// Summon Guardians: 0 = Do not Summon | 1 = Summon
 	// Summon Guardians: 0 = Do not Summon | 1 = Summon
-	if (getcastledata(strnpcinfo(2),1)) {
+	if (getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		setarray getd("$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"[0]"),0,0,0,0,0,0;
 		setarray getd("$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"[0]"),0,0,0,0,0,0;
 		donpcevent "df1#"+strnpcinfo(2)+"::OnEnable";
 		donpcevent "df1#"+strnpcinfo(2)+"::OnEnable";
 		donpcevent "df2#"+strnpcinfo(2)+"::OnEnable";
 		donpcevent "df2#"+strnpcinfo(2)+"::OnEnable";
@@ -136,21 +136,21 @@ OnChange:
 OnClock0001:
 OnClock0001:
 	// Spawn Treasure Chests based on castle economy.
 	// Spawn Treasure Chests based on castle economy.
 	if (strnpcinfo(2) == "template") end;
 	if (strnpcinfo(2) == "template") end;
-	if (!getcastledata(strnpcinfo(2),1)) end;
+	if (!getcastledata(strnpcinfo(2),CD_GUILD_ID)) end;
 	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";
 	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";
-	if (getcastledata(strnpcinfo(2),4)) {
-		set .@Economy,getcastledata(strnpcinfo(2),2);
-		setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));
-		if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;
-		setcastledata strnpcinfo(2),4,0;
+	if (getcastledata(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+		set .@Economy,getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY);
+		setcastledata strnpcinfo(2),CD_CURRENT_ECONOMY,.@Economy+getcastledata(strnpcinfo(2),CD_INVESTED_ECONOMY)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),CD_GUILD_ID),10014));
+		if (getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY) > 100) setcastledata strnpcinfo(2),CD_CURRENT_ECONOMY,100;
+		setcastledata strnpcinfo(2),CD_INVESTED_ECONOMY,0;
 	}
 	}
-	if (getcastledata(strnpcinfo(2),5)) {
-		set .@Defence,getcastledata(strnpcinfo(2),3);
-		setcastledata strnpcinfo(2),3,.@Defence+getcastledata(strnpcinfo(2),5);
-		if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;
-		setcastledata strnpcinfo(2),5,0;
+	if (getcastledata(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+		set .@Defence,getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE);
+		setcastledata strnpcinfo(2),CD_CURRENT_DEFENSE,.@Defence+getcastledata(strnpcinfo(2),CD_INVESTED_DEFENSE);
+		if (getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE) > 100) setcastledata strnpcinfo(2),CD_CURRENT_DEFENSE,100;
+		setcastledata strnpcinfo(2),CD_INVESTED_DEFENSE,0;
 	}
 	}
-	set .@Treasure,getcastledata(strnpcinfo(2),2)/5+4;
+	set .@Treasure,getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY)/5+4;
 	if (!.@Treasure) end;
 	if (!.@Treasure) end;
 	freeloop(1);
 	freeloop(1);
 	if (compare(strnpcinfo(2),"arug")) {
 	if (compare(strnpcinfo(2),"arug")) {
@@ -205,7 +205,7 @@ OnTreasureDied:
 // Guild Manager
 // Guild Manager
 //============================================================
 //============================================================
 -	script	Steward#template	-1,{
 -	script	Steward#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (!.@GID) {
 	if (!.@GID) {
 		mes "[ Steward ]";
 		mes "[ Steward ]";
 		mes "I await for the master";
 		mes "I await for the master";
@@ -236,24 +236,24 @@ OnTreasureDied:
 	case 1:
 	case 1:
 		mes "[ Steward ]";
 		mes "[ Steward ]";
 		mes "The Commercial Growth";
 		mes "The Commercial Growth";
-		mes "Level of the stronghold is ^0000ff"+getcastledata(strnpcinfo(4),2)+".";
-		if (getcastledata(strnpcinfo(4),4) > 0) {
+		mes "Level of the stronghold is ^0000ff"+getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY)+".";
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) > 0) {
 			mes "Last time, you invested in";
 			mes "Last time, you invested in";
-			mes "Commercial Growth "+getcastledata(strnpcinfo(4),4)+".";
+			mes "Commercial Growth "+getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)+".";
 		}
 		}
 		next;
 		next;
 		mes "[ Steward ]";
 		mes "[ Steward ]";
 		mes "Our stronghold's";
 		mes "Our stronghold's";
-		mes "safeguard level is "+getcastledata(strnpcinfo(4),3)+".";
-		if (getcastledata(strnpcinfo(4),5) > 0) {
+		mes "safeguard level is "+getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE)+".";
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) > 0) {
 			mes "Last time, you invested";
 			mes "Last time, you invested";
-			mes "in defense "+getcastledata(strnpcinfo(4),5)+" times.";
+			mes "in defense "+getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)+" times.";
 		}
 		}
 		mes " ";
 		mes " ";
 		mes "That is all, master.";
 		mes "That is all, master.";
 		close;
 		close;
 	case 2:
 	case 2:
-		set .@Economy,getcastledata(strnpcinfo(4),2);
+		set .@Economy,getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY);
 		setarray .@cost[0],5000,10000,20000,35000,55000,80000,110000,145000,185000,230000,280000,335000,395000,460000,530000,605000,685000,770000,860000,955000;
 		setarray .@cost[0],5000,10000,20000,35000,55000,80000,110000,145000,185000,230000,280000,335000,395000,460000,530000,605000,685000,770000,860000,955000;
 		set .@j,0;
 		set .@j,0;
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
@@ -264,7 +264,7 @@ OnTreasureDied:
 			set .@j, .@j+1;
 			set .@j, .@j+1;
 		}
 		}
 		// Quadruple the cost of investing if you've already invested once.
 		// Quadruple the cost of investing if you've already invested once.
-		if (getcastledata(strnpcinfo(4),4)) set .@eco_invest,.@eco_invest*4;
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)) set .@eco_invest,.@eco_invest*4;
 		mes "[ Steward ]";
 		mes "[ Steward ]";
 		mes "Raising the stronghold's";
 		mes "Raising the stronghold's";
 		mes "commercial growth will";
 		mes "commercial growth will";
@@ -290,7 +290,7 @@ OnTreasureDied:
 			mes "any further than that.";
 			mes "any further than that.";
 			close;
 			close;
 		}
 		}
-		if (getcastledata(strnpcinfo(4),4) >= 2) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) >= 2) {
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "You've already made two";
 			mes "You've already made two";
 			mes "investments today, so you'll";
 			mes "investments today, so you'll";
@@ -298,7 +298,7 @@ OnTreasureDied:
 			mes "to make another investment.";
 			mes "to make another investment.";
 			close;
 			close;
 		}
 		}
-		if (getcastledata(strnpcinfo(4),4) == 0) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) == 0) {
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "You must pay ^FF0000"+.@eco_invest+"^000000 Zeny";
 			mes "You must pay ^FF0000"+.@eco_invest+"^000000 Zeny";
 			mes "to make an investment";
 			mes "to make an investment";
@@ -316,7 +316,7 @@ OnTreasureDied:
 		next;
 		next;
 		switch(select("Invest in Commercial Growth:Cancel")) {
 		switch(select("Invest in Commercial Growth:Cancel")) {
 		case 1:
 		case 1:
-			if (getcastledata(strnpcinfo(4),4) >= 2) {
+			if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) >= 2) {
 				mes "[ Steward ]";
 				mes "[ Steward ]";
 				mes "You've already made two";
 				mes "You've already made two";
 				mes "investments today, so you'll";
 				mes "investments today, so you'll";
@@ -333,7 +333,7 @@ OnTreasureDied:
 				close;
 				close;
 			}
 			}
 			set Zeny, Zeny-.@eco_invest;
 			set Zeny, Zeny-.@eco_invest;
-			setcastledata strnpcinfo(4),4,getcastledata(strnpcinfo(4),4)+1;
+			setcastledata strnpcinfo(4),CD_INVESTED_ECONOMY,getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)+1;
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "A wise use of the guild's";
 			mes "A wise use of the guild's";
 			mes "funds, Master. We can expect";
 			mes "funds, Master. We can expect";
@@ -346,7 +346,7 @@ OnTreasureDied:
 			close;
 			close;
 		}
 		}
 	case 3:
 	case 3:
-		set .@Defence,getcastledata(strnpcinfo(4),3);
+		set .@Defence,getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE);
 		setarray .@cost[0],10000,20000,40000,70000,110000,160000,220000,290000,370000,460000,560000,670000,790000,920000,1060000,1210000,1370000,1540000,1720000,1910000;
 		setarray .@cost[0],10000,20000,40000,70000,110000,160000,220000,290000,370000,460000,560000,670000,790000,920000,1060000,1210000,1370000,1540000,1720000,1910000;
 		set .@j,0;
 		set .@j,0;
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
@@ -357,7 +357,7 @@ OnTreasureDied:
 			set .@j, .@j+1;
 			set .@j, .@j+1;
 		}
 		}
 		// Quadruple the cost of investing if you've already invested once.
 		// Quadruple the cost of investing if you've already invested once.
-		if (getcastledata(strnpcinfo(4),5)) set .@def_invest,.@def_invest*4;
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)) set .@def_invest,.@def_invest*4;
 		mes "[ Steward ]";
 		mes "[ Steward ]";
 		mes "Investing in our stronghold's";
 		mes "Investing in our stronghold's";
 		mes "defense will enhance the";
 		mes "defense will enhance the";
@@ -373,13 +373,13 @@ OnTreasureDied:
 		mes "a maximum of two times daily.";
 		mes "a maximum of two times daily.";
 		next;
 		next;
 		mes "[ Steward ]";
 		mes "[ Steward ]";
-		if (getcastledata(strnpcinfo(4),3) == 100) {
+		if (getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE) == 100) {
 			mes "The Defense Level of this";
 			mes "The Defense Level of this";
 			mes "stronghold is 100%, and";
 			mes "stronghold is 100%, and";
 			mes "cannot be increased further.";
 			mes "cannot be increased further.";
 			close;
 			close;
 		}
 		}
-		if (getcastledata(strnpcinfo(4),5) >= 2) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) >= 2) {
 			mes "Master, you've already";
 			mes "Master, you've already";
 			mes "invested in Defense twice";
 			mes "invested in Defense twice";
 			mes "today. You'll need to wait";
 			mes "today. You'll need to wait";
@@ -387,7 +387,7 @@ OnTreasureDied:
 			mes "want to increase our defenses.";
 			mes "want to increase our defenses.";
 			close;
 			close;
 		}
 		}
-		if (getcastledata(strnpcinfo(4),5) == 0) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) == 0) {
 			mes "We need ^FF0000"+.@def_invest+"^000000";
 			mes "We need ^FF0000"+.@def_invest+"^000000";
 			mes "Zeny to invest in our";
 			mes "Zeny to invest in our";
 			mes "stronghold's defenses.";
 			mes "stronghold's defenses.";
@@ -403,7 +403,7 @@ OnTreasureDied:
 		next;
 		next;
 		switch(select("Invest in Defense:Cancel")) {
 		switch(select("Invest in Defense:Cancel")) {
 		case 1:
 		case 1:
-			if (getcastledata(strnpcinfo(4),5) >= 2) {
+			if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) >= 2) {
 				mes "[ Steward ]";
 				mes "[ Steward ]";
 				mes "Master, you've already";
 				mes "Master, you've already";
 				mes "invested in Defense twice";
 				mes "invested in Defense twice";
@@ -421,7 +421,7 @@ OnTreasureDied:
 				close;
 				close;
 			}
 			}
 			set Zeny, Zeny-.@def_invest;
 			set Zeny, Zeny-.@def_invest;
-			setcastledata strnpcinfo(4),5,getcastledata(strnpcinfo(4),5)+1;
+			setcastledata strnpcinfo(4),CD_INVESTED_DEFENSE,getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)+1;
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "A wise use of the guild's";
 			mes "A wise use of the guild's";
 			mes "funds, Master. Increasing";
 			mes "funds, Master. Increasing";
@@ -435,7 +435,7 @@ OnTreasureDied:
 			close;
 			close;
 		}
 		}
 	case 4:
 	case 4:
-		if (getcastledata(strnpcinfo(4),9) == 1) {
+		if (getcastledata(strnpcinfo(4),CD_ENABLED_KAFRA) == 1) {
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "Do you wish to dismiss";
 			mes "Do you wish to dismiss";
 			mes "the Kafra Employee that";
 			mes "the Kafra Employee that";
@@ -478,7 +478,7 @@ OnTreasureDied:
 				close;
 				close;
 			}
 			}
 			disablenpc "Kafra Employee#"+strnpcinfo(2);
 			disablenpc "Kafra Employee#"+strnpcinfo(2);
-			setcastledata strnpcinfo(4),9,0;
+			setcastledata strnpcinfo(4),CD_ENABLED_KAFRA,0;
 			mes "[ Steward ]";
 			mes "[ Steward ]";
 			mes "That Kafra Employee";
 			mes "That Kafra Employee";
 			mes "has been dismissed.";
 			mes "has been dismissed.";
@@ -514,7 +514,7 @@ OnTreasureDied:
 				}
 				}
 				set Zeny, Zeny-10000;
 				set Zeny, Zeny-10000;
 				enablenpc "Kafra Employee#"+strnpcinfo(2);
 				enablenpc "Kafra Employee#"+strnpcinfo(2);
-				setcastledata strnpcinfo(4),9,1;
+				setcastledata strnpcinfo(4),CD_ENABLED_KAFRA,1;
 				mes "[ Steward ]";
 				mes "[ Steward ]";
 				mes "Very well. We have formed";
 				mes "Very well. We have formed";
 				mes "a contract with the Kafra";
 				mes "a contract with the Kafra";
@@ -605,17 +605,17 @@ OnStartArena:
 	set .@GID,getcharid(2);
 	set .@GID,getcharid(2);
 	set .@region$, (compare(strnpcinfo(4),"arug"))?"Valfreyja":"Nithafjoll";
 	set .@region$, (compare(strnpcinfo(4),"arug"))?"Valfreyja":"Nithafjoll";
 	// Lower castle Economy
 	// Lower castle Economy
-	set .@Economy,getcastledata(strnpcinfo(4),2)-5;
+	set .@Economy,getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY)-5;
 	if (.@Economy < 0) set .@Economy, 0;
 	if (.@Economy < 0) set .@Economy, 0;
-	setcastledata strnpcinfo(4),2,.@Economy;
+	setcastledata strnpcinfo(4),CD_CURRENT_ECONOMY,.@Economy;
 	// Lower Castle Defence
 	// Lower Castle Defence
-	set .@Defence,getcastledata(strnpcinfo(4),3)-5;
+	set .@Defence,getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE)-5;
 	if (.@Defence < 0) set .@Defence, 0;
 	if (.@Defence < 0) set .@Defence, 0;
-	setcastledata strnpcinfo(4),3,.@Defence;
+	setcastledata strnpcinfo(4),CD_CURRENT_DEFENSE,.@Defence;
 	// Set new owner
 	// Set new owner
-	setcastledata strnpcinfo(4),1,.@GID;
+	setcastledata strnpcinfo(4),CD_GUILD_ID,.@GID;
 	// Clear castle's data.
 	// Clear castle's data.
-	for(set .@i,4; .@i<10; set .@i,.@i+1)
+	for(set .@i,CD_INVESTED_ECONOMY; .@i<CD_ENABLED_GUARDIAN00; set .@i,.@i+1)
 		setcastledata strnpcinfo(4),.@i,0;
 		setcastledata strnpcinfo(4),.@i,0;
 	// Disable Kafra
 	// Disable Kafra
 	disablenpc "Kafra Employee#"+strnpcinfo(2);
 	disablenpc "Kafra Employee#"+strnpcinfo(2);
@@ -623,7 +623,7 @@ OnStartArena:
 	announce "The ["+getguildname(.@GID)+"] guild conquered the ["+.@region$+" "+charat(strnpcinfo(2),3)+"] stronghold of "+getcastlename(strnpcinfo(4))+"!",bc_all|bc_woe;
 	announce "The ["+getguildname(.@GID)+"] guild conquered the ["+.@region$+" "+charat(strnpcinfo(2),3)+"] stronghold of "+getcastlename(strnpcinfo(4))+"!",bc_all|bc_woe;
 	mapannounce strnpcinfo(4),"The emperium has been shattered!",bc_map,"0x00FF00",FW_NORMAL,20,0,40;
 	mapannounce strnpcinfo(4),"The emperium has been shattered!",bc_map,"0x00FF00",FW_NORMAL,20,0,40;
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnReset";
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnReset";
-	maprespawnguildid strnpcinfo(4),getcastledata(strnpcinfo(4),1),2;
+	maprespawnguildid strnpcinfo(4),getcastledata(strnpcinfo(4),CD_GUILD_ID),2;
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnRecvCastle2";
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnRecvCastle2";
 	donpcevent "::OnRecvCastle"+strnpcinfo(2);
 	donpcevent "::OnRecvCastle"+strnpcinfo(2);
 	sleep 10000;
 	sleep 10000;
@@ -637,7 +637,7 @@ OnStartArena:
 // Castle Guardians
 // Castle Guardians
 //============================================================
 //============================================================
 -	script	Guardian#template	-1,{
 -	script	Guardian#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@n$, "["+strnpcinfo(1)+"]";
 	set .@n$, "["+strnpcinfo(1)+"]";
 	if (!.@GID) {
 	if (!.@GID) {
 		mes .@n$;
 		mes .@n$;
@@ -838,7 +838,7 @@ OnInit:
 //============================================================
 //============================================================
 -	script	Kafra#template	-1,{
 -	script	Kafra#template	-1,{
 	cutin "kafra_01",2;
 	cutin "kafra_01",2;
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (getcharid(2) == .@GID && getgdskilllv(.@GID,10001)) {
 	if (getcharid(2) == .@GID && getgdskilllv(.@GID,10001)) {
 		mes "[Kafra Employee]";
 		mes "[Kafra Employee]";
 		mes "Welcome, proud member";
 		mes "Welcome, proud member";
@@ -950,7 +950,7 @@ OnInit:
 // Guardian Stones (2)
 // Guardian Stones (2)
 //============================================================
 //============================================================
 -	script	Guardian Stone#template	-1,{
 -	script	Guardian Stone#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@num, atoi(charat(strnpcinfo(1),0));
 	set .@num, atoi(charat(strnpcinfo(1),0));
 	set .@var$,"$agit_"+strnpcinfo(2);
 	set .@var$,"$agit_"+strnpcinfo(2);
 	if (getcharid(2) == .@GID) {
 	if (getcharid(2) == .@GID) {
@@ -1104,7 +1104,7 @@ OnEnable:
 // Control Devices (3)
 // Control Devices (3)
 //============================================================
 //============================================================
 -	script	Control#template	-1,{
 -	script	Control#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@num, atoi(charat(strnpcinfo(1),15));
 	set .@num, atoi(charat(strnpcinfo(1),15));
 	set .@var$,"$agit_"+strnpcinfo(2);
 	set .@var$,"$agit_"+strnpcinfo(2);
 	if (getcharid(2) == .@GID) {
 	if (getcharid(2) == .@GID) {
@@ -1386,7 +1386,7 @@ OnEnable:
 	}
 	}
 	if (charat(strnpcinfo(1),4) == "2") set .@z,11;
 	if (charat(strnpcinfo(1),4) == "2") set .@z,11;
 	freeloop(1);
 	freeloop(1);
-	set .@defence,getcastledata(strnpcinfo(2),3);
+	set .@defence,getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE);
 	callsub OnSummon,.@z;
 	callsub OnSummon,.@z;
 	if (.@defence > 70) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),5;
 	if (.@defence > 70) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),5;
 	else if (.@defence > 50) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),4;
 	else if (.@defence > 50) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),4;
@@ -1710,7 +1710,7 @@ OnDisable:
 // Link Flags (function)
 // Link Flags (function)
 //============================================================
 //============================================================
 function	script	LinkFlag	{
 function	script	LinkFlag	{
-	if (!getcharid(2) || getcharid(2) != getcastledata(strnpcinfo(4),1)) end;
+	if (!getcharid(2) || getcharid(2) != getcastledata(strnpcinfo(4),CD_GUILD_ID)) end;
 	if (getarg(0) == "Convenience Facility") {
 	if (getarg(0) == "Convenience Facility") {
 		mes "^3355FFThis is the Stronghold";
 		mes "^3355FFThis is the Stronghold";
 		mes "Teleport Service. Would";
 		mes "Teleport Service. Would";
@@ -1748,7 +1748,7 @@ function	script	LinkFlag	{
 function	script	ReturnFlag	{
 function	script	ReturnFlag	{
 	.@map$ = getarg(0);
 	.@map$ = getarg(0);
 	set .@str$, (compare(strnpcinfo(4),"aru"))?"Arunafeltz":"Schwaltzvalt";
 	set .@str$, (compare(strnpcinfo(4),"aru"))?"Arunafeltz":"Schwaltzvalt";
-	.@GID =  getcastledata(.@map$,1);
+	.@GID =  getcastledata(.@map$,CD_GUILD_ID);
 	if (!.@GID) {
 	if (!.@GID) {
 		mes "[ "+.@str$+" Royal Edict ]";
 		mes "[ "+.@str$+" Royal Edict ]";
 		mes "The Holy Kingdom of";
 		mes "The Holy Kingdom of";
@@ -1765,7 +1765,7 @@ function	script	ReturnFlag	{
 		mes "do you wish to return";
 		mes "do you wish to return";
 		mes "to your stronghold?";
 		mes "to your stronghold?";
 		next;
 		next;
-		if(select("Return to the Stronghold:Cancel") == 1 && getcharid(2) == getcastledata(.@map$,1)) {
+		if(select("Return to the Stronghold:Cancel") == 1 && getcharid(2) == getcastledata(.@map$,CD_GUILD_ID)) {
 			if (compare(.@map$,"arug")) {
 			if (compare(.@map$,"arug")) {
 				if (.@map$ == "arug_cas01") setarray .@i[0],67,193;
 				if (.@map$ == "arug_cas01") setarray .@i[0],67,193;
 				else if (.@map$ == "arug_cas02") setarray .@i[0],43,256;
 				else if (.@map$ == "arug_cas02") setarray .@i[0],43,256;
@@ -1821,7 +1821,7 @@ function	script	ReturnFlag	{
 // Guild Dungeon Warps
 // Guild Dungeon Warps
 //============================================================
 //============================================================
 -	script	Sunflower#template	-1,{
 -	script	Sunflower#template	-1,{
-	if (getcharid(2) == getcastledata(strnpcinfo(4),1)) {
+	if (getcharid(2) == getcastledata(strnpcinfo(4),CD_GUILD_ID)) {
 		mes "- It's an amazingly huge sunflower; as big as a human! ... You feel something mysterious emanating from the flower. -";
 		mes "- It's an amazingly huge sunflower; as big as a human! ... You feel something mysterious emanating from the flower. -";
 		next;
 		next;
 		switch(select("Hold the stem.:Do nothing.")) {
 		switch(select("Hold the stem.:Do nothing.")) {

+ 3 - 3
npc/re/guild/invest_main.txt

@@ -896,7 +896,7 @@ OnAgitInvest:
 		set .@guild, getcharid(2);
 		set .@guild, getcharid(2);
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 			set .@castle_name$[.@i], getcastlename(.@npc$+"g_cas0"+.@i);
 			set .@castle_name$[.@i], getcastlename(.@npc$+"g_cas0"+.@i);
-			set .@owner_id[.@i], getcastledata(.@npc$+"g_cas0"+.@i,1);
+			set .@owner_id[.@i], getcastledata(.@npc$+"g_cas0"+.@i,CD_GUILD_ID);
 			set .@owner_name$[.@i], getguildname(.@owner_id[.@i]);
 			set .@owner_name$[.@i], getguildname(.@owner_id[.@i]);
 			if (.@guild == .@owner_id[.@i]) {
 			if (.@guild == .@owner_id[.@i]) {
 				set .@menu$, .@menu$+.@castle_name$[.@i]+" ["+.@owner_name$[.@i]+"] Guild:";
 				set .@menu$, .@menu$+.@castle_name$[.@i]+" ["+.@owner_name$[.@i]+"] Guild:";
@@ -1044,7 +1044,7 @@ OnAgitInvest:
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 			set .@map$, .@npc$+"g_cas0"+.@i;
 			set .@map$, .@npc$+"g_cas0"+.@i;
 			set .@fund[.@i], getd("$@vfund_"+.@npc$+"0"+.@i);
 			set .@fund[.@i], getd("$@vfund_"+.@npc$+"0"+.@i);
-			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,1))+" Guild: "+.@fund[.@i];
+			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,CD_GUILD_ID))+" Guild: "+.@fund[.@i];
 		}
 		}
 		set .@fund[0], getd("$@vfund_"+.@npc$+"_extra");
 		set .@fund[0], getd("$@vfund_"+.@npc$+"_extra");
 		mes .@realm$+" normal: "+.@fund[0];
 		mes .@realm$+" normal: "+.@fund[0];
@@ -1098,7 +1098,7 @@ OnAgitInvest:
 		set .@realm$,"Valkyrie Realm";
 		set .@realm$,"Valkyrie Realm";
 	}
 	}
 
 
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (getcharid(2) != .@GID) {
 	if (getcharid(2) != .@GID) {
 		mes "[Gate Manager]";
 		mes "[Gate Manager]";
 		mes "You don't seem to be the member of guild owning this castle.";
 		mes "You don't seem to be the member of guild owning this castle.";

+ 2 - 2
npc/re/guild/mission_main.txt

@@ -93,7 +93,7 @@ function calcjobexp;
 						} else {
 						} else {
 							.@total = 0;
 							.@total = 0;
 							for(.@i = 0; .@i < 5; ++.@i){
 							for(.@i = 0; .@i < 5; ++.@i){
-								.@total += (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],1));
+								.@total += (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],CD_GUILD_ID));
 							}
 							}
 
 
 							if(!.@total){
 							if(!.@total){
@@ -108,7 +108,7 @@ function calcjobexp;
 								else
 								else
 									mes "Currently, the total number of fortresses that your guild has conquered";
 									mes "Currently, the total number of fortresses that your guild has conquered";
 								for(.@i = 0; .@i < 5; ++.@i){
 								for(.@i = 0; .@i < 5; ++.@i){
-									mes getcastlename(.castle$[.@i+.@zoneid*5]) + (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],1) ? ": ^4d4dffOccupied^000000" : "");
+									mes getcastlename(.castle$[.@i+.@zoneid*5]) + (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],CD_GUILD_ID) ? ": ^4d4dffOccupied^000000" : "");
 								}
 								}
 								if(.@total == 5)
 								if(.@total == 5)
 									mes "Your guild has conquered " + .region$[.@zoneid] + "!";
 									mes "Your guild has conquered " + .region$[.@zoneid] + "!";

+ 46 - 46
npc/re/guild3/agit_main_te.txt

@@ -19,7 +19,7 @@ OnAgitInit3:
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	if (.@map$ == "") end;
 	.@npc_name$ = strnpcinfo(0);
 	.@npc_name$ = strnpcinfo(0);
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	if (.@guild_id == 0) {
 	if (.@guild_id == 0) {
 		killmonster .@map$, .@npc_name$ +"::OnMyMobDead";
 		killmonster .@map$, .@npc_name$ +"::OnMyMobDead";
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
@@ -75,7 +75,7 @@ OnAgitInit3:
 	else {
 	else {
 		requestguildinfo .@guild_id;
 		requestguildinfo .@guild_id;
 		donpcevent "::OnFlagTE" + strnpcinfo(2);// Guild emblem on flags.
 		donpcevent "::OnFlagTE" + strnpcinfo(2);// Guild emblem on flags.
-		if (getcastledata(.@map$,9)  == 0)
+		if (getcastledata(.@map$,CD_ENABLED_KAFRA)  == 0)
 			disablenpc "Kafra Employee#"+ replacestr(.@map$, "cas", "");
 			disablenpc "Kafra Employee#"+ replacestr(.@map$, "cas", "");
 
 
 		// Load purchased Guardian in castles.
 		// Load purchased Guardian in castles.
@@ -113,7 +113,7 @@ OnAgitStart3:
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	if (.@map$ == "") end;
 	if (agitcheck3()) {
 	if (agitcheck3()) {
-		maprespawnguildid .@map$, getcastledata(.@map$,1),2;// warp all non-guild members
+		maprespawnguildid .@map$, getcastledata(.@map$,CD_GUILD_ID),2;// warp all non-guild members
 		gvgon3 .@map$;
 		gvgon3 .@map$;
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
 		callsub S_Message,"OnCommandOn";
 		callsub S_Message,"OnCommandOn";
@@ -124,7 +124,7 @@ OnAgitEnd3:
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	if (.@map$ == "") end;
 	gvgoff3 .@map$;
 	gvgoff3 .@map$;
-	if (getcastledata(.@map$,1))
+	if (getcastledata(.@map$,CD_GUILD_ID))
 		killmonster .@map$, strnpcinfo(0) +"::OnAgitBreak";
 		killmonster .@map$, strnpcinfo(0) +"::OnAgitBreak";
 	callsub S_Message,"OnReset";
 	callsub S_Message,"OnReset";
 	end;
 	end;
@@ -133,26 +133,26 @@ OnAgitBreak:
 	.@guild_id = getcharid(2);
 	.@guild_id = getcharid(2);
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 
 
-	.@economy = getcastledata(.@map$,2) - 5;// Adjust economy Invest Level for Castle
+	.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY) - 5;// Adjust economy Invest Level for Castle
 	if (.@economy < 1)
 	if (.@economy < 1)
-		setcastledata .@map$, 2,1;
+		setcastledata .@map$, CD_CURRENT_ECONOMY,1;
 	else
 	else
-		setcastledata .@map$, 2,.@economy;
-	.@defense = getcastledata(.@map$,3) - 5;// Adjust Defense Invest Level for Castle
+		setcastledata .@map$, CD_CURRENT_ECONOMY,.@economy;
+	.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE) - 5;// Adjust Defense Invest Level for Castle
 	if (.@defense < 1)
 	if (.@defense < 1)
-		setcastledata .@map$, 3,1;
+		setcastledata .@map$, CD_CURRENT_DEFENSE,1;
 	else
 	else
-		setcastledata .@map$, 3,.@defense;
-	setcastledata .@map$,1,.@guild_id;
+		setcastledata .@map$, CD_CURRENT_DEFENSE,.@defense;
+	setcastledata .@map$,CD_GUILD_ID,.@guild_id;
 
 
 	// Reset Invest information and refresh castle data
 	// Reset Invest information and refresh castle data
-	for ( .@i = 4; .@i <= 9; .@i++ )
+	for ( .@i = CD_INVESTED_ECONOMY; .@i < CD_ENABLED_GUARDIAN00; .@i++ )
 		setcastledata .@map$,.@i,0;
 		setcastledata .@map$,.@i,0;
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";// spawn guardians / monsters
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";// spawn guardians / monsters
 
 
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	if (getgdskilllv(.@guild_id,10002) == 0) {
 	if (getgdskilllv(.@guild_id,10002) == 0) {
-		for ( .@i = 10; .@i <= 17; .@i++ )
+		for ( .@i = CD_ENABLED_GUARDIAN00; .@i < CD_MAX; .@i++ )
 			setcastledata .@map$,.@i,0;
 			setcastledata .@map$,.@i,0;
 	}
 	}
 
 
@@ -172,7 +172,7 @@ OnGuildBreak:
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	disablenpc "Kafra Employee#"+ .@tmp$;
 	disablenpc "Kafra Employee#"+ .@tmp$;
-	setcastledata .@map$,1,0;
+	setcastledata .@map$,CD_GUILD_ID,0;
 	sleep 7000;
 	sleep 7000;
 	announce "Guild Base [" + getcastlename(.@map$) + "] has been abandoned.",bc_all;
 	announce "Guild Base [" + getcastlename(.@map$) + "] has been abandoned.",bc_all;
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";
@@ -180,7 +180,7 @@ OnGuildBreak:
 
 
 S_Message:
 S_Message:
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	
 	
 	if (.@guild_id)
 	if (.@guild_id)
 		announce "The [" + getcastlename(.@map$) + "] castle is occupied by the [" + getguildname(.@guild_id) + "] guild.",bc_all,"0xFF0000",FW_NORMAL,10;
 		announce "The [" + getcastlename(.@map$) + "] castle is occupied by the [" + getguildname(.@guild_id) + "] guild.",bc_all,"0xFF0000",FW_NORMAL,10;
@@ -211,7 +211,7 @@ OnMyMobDead:
 // Guild Kafras
 // Guild Kafras
 //============================================================
 //============================================================
 -	script	Kafra_Staff_TE	-1,{
 -	script	Kafra_Staff_TE	-1,{
-	.@guild_id = getcastledata( strnpcinfo(4),1 );
+	.@guild_id = getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	.@guildname$ = getguildname(.@guild_id);
 	.@guildname$ = getguildname(.@guild_id);
 
 
 	cutin "kafra_01",2;
 	cutin "kafra_01",2;
@@ -335,7 +335,7 @@ function GuardianData;
 
 
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 	.@npc_name$ = "[ Butler "+ strnpcinfo(1) +"]";
 	.@npc_name$ = "[ Butler "+ strnpcinfo(1) +"]";
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	.@guildmaster$ = getguildmaster(.@guild_id);
 	.@guildmaster$ = getguildmaster(.@guild_id);
 
 
 	mes .@npc_name$;
 	mes .@npc_name$;
@@ -353,15 +353,15 @@ function GuardianData;
 	next;
 	next;
 	switch( select( "Castle briefing", "Invest in commercial growth", "Invest in Castle Defenses", "Summon Guardian", "Hire / Fire a Kafra Employee", "Go into Master's room" ) ) {
 	switch( select( "Castle briefing", "Invest in commercial growth", "Invest in Castle Defenses", "Summon Guardian", "Hire / Fire a Kafra Employee", "Go into Master's room" ) ) {
 	case 1:
 	case 1:
-		.@economy_today = getcastledata(.@map$,4);
-		.@defense_today = getcastledata(.@map$,5);
+		.@economy_today = getcastledata(.@map$,CD_INVESTED_ECONOMY);
+		.@defense_today = getcastledata(.@map$,CD_INVESTED_DEFENSE);
 		mes .@npc_name$;
 		mes .@npc_name$;
 		mes "I will report the Castle briefing, Master.";
 		mes "I will report the Castle briefing, Master.";
 		mes " ";
 		mes " ";
-		mes "^0000ffNow, the commercial growth level is "+GetCastleData(.@map$,2)+".";
+		mes "^0000ffNow, the commercial growth level is "+GetCastleData(.@map$,CD_CURRENT_ECONOMY)+".";
 		if (.@economy_today > 0)
 		if (.@economy_today > 0)
 			mes " You invested "+.@economy_today+" times in past 1 day.";
 			mes " You invested "+.@economy_today+" times in past 1 day.";
-		mes " Now, the Castle Defense level is "+GetCastleData(.@map$,3)+".^000000";
+		mes " Now, the Castle Defense level is "+GetCastleData(.@map$,CD_CURRENT_DEFENSE)+".^000000";
 		if (.@defense_today > 0)
 		if (.@defense_today > 0)
 			mes " ^0000ff- You invested "+.@defense_today+" times in past 1 day.^000000";
 			mes " ^0000ff- You invested "+.@defense_today+" times in past 1 day.^000000";
 		mes " ";
 		mes " ";
@@ -369,20 +369,20 @@ function GuardianData;
 		close;
 		close;
 
 
 	case 2:
 	case 2:
-		.@economy = getcastledata(.@map$,2);
+		.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY);
 		setarray .@eco_invest[0], 5,5000, 10,10000, 15,20000, 20,35000, 25,55000, 30,80000, 35,110000, 40,145000, 45,185000, 50,230000,
 		setarray .@eco_invest[0], 5,5000, 10,10000, 15,20000, 20,35000, 25,55000, 30,80000, 35,110000, 40,145000, 45,185000, 50,230000,
 			55,280000, 60,335000, 65,395000, 70,460000, 75,530000, 80,605000, 85,685000, 90,770000, 95,860000, 100,955000;
 			55,280000, 60,335000, 65,395000, 70,460000, 75,530000, 80,605000, 85,685000, 90,770000, 95,860000, 100,955000;
 		for ( .@i = 0; .@i < getarraysize(.@eco_invest); .@i += 2 )
 		for ( .@i = 0; .@i < getarraysize(.@eco_invest); .@i += 2 )
 			if (.@economy <= .@eco_invest[.@i]) break;
 			if (.@economy <= .@eco_invest[.@i]) break;
-		callsub( S_Invest, 4, .@eco_invest[.@i+1], getcastledata(.@map$,4), "commercial growth", "quantity of goods made by the guild will increase", "future", "economist", "riches" );
+		callsub( S_Invest, 4, .@eco_invest[.@i+1], getcastledata(.@map$,CD_INVESTED_ECONOMY), "commercial growth", "quantity of goods made by the guild will increase", "future", "economist", "riches" );
 
 
 	case 3:
 	case 3:
-		.@defense = getcastledata(.@map$,3);
+		.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE);
 		setarray .@def_invest[0], 5,10000, 10,20000, 15,40000, 20,70000, 25,110000, 30,160000, 35,220000, 40,290000, 45,370000, 50,460000,
 		setarray .@def_invest[0], 5,10000, 10,20000, 15,40000, 20,70000, 25,110000, 30,160000, 35,220000, 40,290000, 45,370000, 50,460000,
 			55,560000, 60,670000, 65,790000, 70,920000, 75,1060000, 80,1210000, 85,1370000, 90,1540000, 95,1720000, 100,1910000;
 			55,560000, 60,670000, 65,790000, 70,920000, 75,1060000, 80,1210000, 85,1370000, 90,1540000, 95,1720000, 100,1910000;
 		for ( .@i = 0; .@i < getarraysize(.@def_invest); .@i += 2 )
 		for ( .@i = 0; .@i < getarraysize(.@def_invest); .@i += 2 )
 			if (.@defense <= .@def_invest[.@i]) break;
 			if (.@defense <= .@def_invest[.@i]) break;
-		callsub( S_Invest, 5, .@def_invest[.@i+1], getcastledata(.@map$,5), "Castle Defenses", "durability of Guardians and the Emperium will increase", "coming battles", "strategist", "Defenses" );
+		callsub( S_Invest, 5, .@def_invest[.@i+1], getcastledata(.@map$,CD_INVESTED_DEFENSE), "Castle Defenses", "durability of Guardians and the Emperium will increase", "coming battles", "strategist", "Defenses" );
 
 
 	case 4:
 	case 4:
 		mes .@npc_name$;
 		mes .@npc_name$;
@@ -409,13 +409,13 @@ function GuardianData;
 		if (getgdskilllv(.@guild_id,10002) == 0) {
 		if (getgdskilllv(.@guild_id,10002) == 0) {
 			mes "Master, we have not the resources to Summon the Guardian. If you want to accumulate them, you have to learn the Guild skill. We failed to summon the Guardian.";
 			mes "Master, we have not the resources to Summon the Guardian. If you want to accumulate them, you have to learn the Guild skill. We failed to summon the Guardian.";
 		}
 		}
-		else if (getcastledata( .@map$,(.@s+10) ) == 1)
+		else if (getcastledata( .@map$,(.@s + CD_ENABLED_GUARDIAN00) ) == 1)
 			mes "Master, you already have summoned that Guardian. We cannot summon another.";
 			mes "Master, you already have summoned that Guardian. We cannot summon another.";
 		else if (Zeny <  10000)
 		else if (Zeny <  10000)
 			mes "Well... I'm sorry but we don't have funds to summon the Guardian. We failed to summon the Guardian.";
 			mes "Well... I'm sorry but we don't have funds to summon the Guardian. We failed to summon the Guardian.";
 		else {
 		else {
 			Zeny = Zeny - 10000;
 			Zeny = Zeny - 10000;
-			setcastledata .@map$,(.@s+10),1;
+			setcastledata .@map$,(.@s + CD_ENABLED_GUARDIAN00),1;
 			guardian .@map$, .@x[.@s], .@y[.@s], .@name$[.@s], .@mob_id[.@s], "Kafra Employee#"+ replacestr(.@map$, "cas", "") +"::OnGuardianDied", .@s;
 			guardian .@map$, .@x[.@s], .@y[.@s], .@name$[.@s], .@mob_id[.@s], "Kafra Employee#"+ replacestr(.@map$, "cas", "") +"::OnGuardianDied", .@s;
 			mes "We completed the summoning of the Guardian. Our defenses are now increased with it in place.";
 			mes "We completed the summoning of the Guardian. Our defenses are now increased with it in place.";
 		}
 		}
@@ -423,7 +423,7 @@ function GuardianData;
 
 
 	case 5:
 	case 5:
 		mes .@npc_name$;
 		mes .@npc_name$;
-		if (getcastledata(.@map$,9) == 1) {
+		if (getcastledata(.@map$,CD_ENABLED_KAFRA) == 1) {
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			next;
 			next;
 			if (select( "Fire","Cancel" ) == 2) {
 			if (select( "Fire","Cancel" ) == 2) {
@@ -445,7 +445,7 @@ function GuardianData;
 			next;
 			next;
 			cutin "",255;
 			cutin "",255;
 			disablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
 			disablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
-			setcastledata .@map$,9,0;
+			setcastledata .@map$,CD_ENABLED_KAFRA,0;
 			mes .@npc_name$;
 			mes .@npc_name$;
 			mes "....";
 			mes "....";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
@@ -470,7 +470,7 @@ function GuardianData;
 		}
 		}
 		Zeny = Zeny - 10000;
 		Zeny = Zeny - 10000;
 		enablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
 		enablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
-		setcastledata .@map$,9,1;
+		setcastledata .@map$,CD_ENABLED_KAFRA,1;
 
 
 		mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 		mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 		next;
 		next;
@@ -532,7 +532,7 @@ S_Invest:
 	mes " ";
 	mes " ";
 	mes "Initially, you are able to invest just once but if you pay more money, you will be able to invest twice.";
 	mes "Initially, you are able to invest just once but if you pay more money, you will be able to invest twice.";
 	mes " ";
 	mes " ";
-	if (getcastledata(strnpcinfo(4),2) >= 100) {
+	if (getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY) >= 100) {
 		mes "^ff0000The "+ getarg(3) +" level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great "+ getarg(6) +" like you, Master.^000000";
 		mes "^ff0000The "+ getarg(3) +" level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great "+ getarg(6) +" like you, Master.^000000";
 		close;
 		close;
 	}
 	}
@@ -689,7 +689,7 @@ OnSpawnGuardians:
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	for ( .@i = 0; .@i < MAX_GUARDIANS; .@i++ ) {
 	for ( .@i = 0; .@i < MAX_GUARDIANS; .@i++ ) {
-		if (getcastledata( .@map$,(.@i+10) ))
+		if (getcastledata( .@map$,(.@i + CD_ENABLED_GUARDIAN00) ))
 			guardian .@map$, .@x[.@i], .@y[.@i], .@name$[.@i], .@mob_id[.@i], "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied",.@i;
 			guardian .@map$, .@x[.@i], .@y[.@i], .@name$[.@i], .@mob_id[.@i], "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied",.@i;
 	}
 	}
 }
 }
@@ -697,7 +697,7 @@ OnSpawnGuardians:
 // Guild Dungeon Entrances
 // Guild Dungeon Entrances
 //============================================================
 //============================================================
 -	script	lever2_TE	-1,{
 -	script	lever2_TE	-1,{
-	.@guild_id = getcastledata( strnpcinfo(4),1 );
+	.@guild_id = getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	if (.@guild_id == 0) {
 	if (.@guild_id == 0) {
 		mes "[Ringing Voice]";
 		mes "[Ringing Voice]";
 		mes "'Those who overcome an ordeal shows a great deal of bravery... and will find their way to another ordeal.'";
 		mes "'Those who overcome an ordeal shows a great deal of bravery... and will find their way to another ordeal.'";
@@ -768,26 +768,26 @@ OnSpawnGuardians:
 OnClock0001:// Spawn Treasure Chests based on castle economy.
 OnClock0001:// Spawn Treasure Chests based on castle economy.
 	.@map$ = strnpcinfo(4);
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	if (.@map$ == "") end;
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	if (.@guild_id == 0) end;
 	if (.@guild_id == 0) end;
 
 
-	.@economy = getcastledata(.@map$,2);
-	.@defense = getcastledata(.@map$,3);
-	.@economy_today = getcastledata(.@map$,4);
-	.@defense_today = getcastledata(.@map$,5);
+	.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY);
+	.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE);
+	.@economy_today = getcastledata(.@map$,CD_INVESTED_ECONOMY);
+	.@defense_today = getcastledata(.@map$,CD_INVESTED_DEFENSE);
 
 
 	killmonster .@map$, strnpcinfo(0)+"::OnTreasureDied";
 	killmonster .@map$, strnpcinfo(0)+"::OnTreasureDied";
 	if (.@economy_today) {
 	if (.@economy_today) {
 		.@economy = .@economy + .@economy_today + (rand(2) && getgdskilllv(.@guild_id,10014));
 		.@economy = .@economy + .@economy_today + (rand(2) && getgdskilllv(.@guild_id,10014));
 		.@economy = ( .@economy > 100 ) ? 100 : .@economy;
 		.@economy = ( .@economy > 100 ) ? 100 : .@economy;
-		setcastledata .@map$,2,.@economy;
-		setcastledata .@map$,4,0;
+		setcastledata .@map$,CD_CURRENT_ECONOMY,.@economy;
+		setcastledata .@map$,CD_INVESTED_ECONOMY,0;
 	}
 	}
 	if (.@defense_today) {
 	if (.@defense_today) {
 		.@defense = .@defense + .@defense_today;
 		.@defense = .@defense + .@defense_today;
 		.@defense = ( .@defense > 100 ) ? 100 : .@defense;
 		.@defense = ( .@defense > 100 ) ? 100 : .@defense;
-		setcastledata .@map$,3,.@defense;
-		setcastledata .@map$,5,0;
+		setcastledata .@map$,CD_CURRENT_DEFENSE,.@defense;
+		setcastledata .@map$,CD_INVESTED_DEFENSE,0;
 	}
 	}
 
 
 	if (.@map$ == "te_aldecas1") {
 	if (.@map$ == "te_aldecas1") {
@@ -1071,7 +1071,7 @@ OnTreasureDied:
 //============================================================
 //============================================================
 function	script	F_flag_woe_TE	{
 function	script	F_flag_woe_TE	{
 	.@castle$ = getarg(1);
 	.@castle$ = getarg(1);
-	.@guild_id = getcastledata( .@castle$,1 );
+	.@guild_id = getcastledata( .@castle$,CD_GUILD_ID );
 	if (.@guild_id == 0) {
 	if (.@guild_id == 0) {
 		mes "[ Edict of the Divine Rune-Midgarts Kingdom ]";
 		mes "[ Edict of the Divine Rune-Midgarts Kingdom ]";
 		mes " ";
 		mes " ";
@@ -1096,7 +1096,7 @@ function	script	F_flag_woe_TE	{
 				mes "Tertiary job class and users with expanded levels are not allowed to participate in Training Siege Battles.";
 				mes "Tertiary job class and users with expanded levels are not allowed to participate in Training Siege Battles.";
 				close;
 				close;
 			}
 			}
-			if (getcastledata( getarg(1),1 ) == getcharid(2))
+			if (getcastledata( getarg(1),CD_GUILD_ID ) == getcharid(2))
 				warp getarg(1),getarg(2),getarg(3);
 				warp getarg(1),getarg(2),getarg(3);
 			end;
 			end;
 		}
 		}
@@ -1120,7 +1120,7 @@ function	script	F_flag_woe_TE	{
 	callfunc( "F_flag_woe_TE",0,strnpcinfo(4) );
 	callfunc( "F_flag_woe_TE",0,strnpcinfo(4) );
 OnInit:
 OnInit:
 	if (strnpcinfo(4) != "")
 	if (strnpcinfo(4) != "")
-		flagemblem getcastledata( strnpcinfo(4),1 );
+		flagemblem getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	end;
 	end;
 }
 }
 
 
@@ -1128,7 +1128,7 @@ OnInit:
 	end;
 	end;
 OnInit:
 OnInit:
 	if (strnpcinfo(2) != "")
 	if (strnpcinfo(2) != "")
-		flagemblem getcastledata( strnpcinfo(2),1 );
+		flagemblem getcastledata( strnpcinfo(2),CD_GUILD_ID );
 	end;
 	end;
 }
 }
 
 

+ 22 - 22
src/char/int_guild.cpp

@@ -603,17 +603,17 @@ struct guild_castle* inter_guildcastle_fromsql(int castle_id)
 	gc->castle_id = castle_id;
 	gc->castle_id = castle_id;
 
 
 	if (SQL_SUCCESS == Sql_NextRow(sql_handle)) {
 	if (SQL_SUCCESS == Sql_NextRow(sql_handle)) {
-		Sql_GetData(sql_handle, 1, &data, NULL); gc->guild_id =  atoi(data);
-		Sql_GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data);
-		Sql_GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data);
-		Sql_GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data);
-		Sql_GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data);
-		Sql_GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data);
-		Sql_GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data);
-		Sql_GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data);
-		Sql_GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data);
-		for (i = 10; i < 10+MAX_GUARDIANS; i++) {
-			Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data);
+		Sql_GetData(sql_handle, CD_GUILD_ID, &data, NULL); gc->guild_id =  atoi(data);
+		Sql_GetData(sql_handle, CD_CURRENT_ECONOMY, &data, NULL); gc->economy = atoi(data);
+		Sql_GetData(sql_handle, CD_CURRENT_DEFENSE, &data, NULL); gc->defense = atoi(data);
+		Sql_GetData(sql_handle, CD_INVESTED_ECONOMY, &data, NULL); gc->triggerE = atoi(data);
+		Sql_GetData(sql_handle, CD_INVESTED_DEFENSE, &data, NULL); gc->triggerD = atoi(data);
+		Sql_GetData(sql_handle, CD_NEXT_TIME, &data, NULL); gc->nextTime = atoi(data);
+		Sql_GetData(sql_handle, CD_PAY_TIME, &data, NULL); gc->payTime = atoi(data);
+		Sql_GetData(sql_handle, CD_CREATE_TIME, &data, NULL); gc->createTime = atoi(data);
+		Sql_GetData(sql_handle, CD_ENABLED_KAFRA, &data, NULL); gc->visibleC = atoi(data);
+		for (i = CD_ENABLED_GUARDIAN00; i < CD_MAX; i++) {
+			Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i - CD_ENABLED_GUARDIAN00].visible = atoi(data);
 		}
 		}
 	}
 	}
 	Sql_FreeResult(sql_handle);
 	Sql_FreeResult(sql_handle);
@@ -1805,7 +1805,7 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
 	}
 	}
 
 
 	switch (index) {
 	switch (index) {
-		case 1:
+		case CD_GUILD_ID:
 			if (charserv_config.log_inter && gc->guild_id != value) {
 			if (charserv_config.log_inter && gc->guild_id != value) {
 				int gid = (value) ? value : gc->guild_id;
 				int gid = (value) ? value : gc->guild_id;
 				struct guild *g = (struct guild*)idb_get(guild_db_, gid);
 				struct guild *g = (struct guild*)idb_get(guild_db_, gid);
@@ -1814,17 +1814,17 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
 			}
 			}
 			gc->guild_id = value;
 			gc->guild_id = value;
 			break;
 			break;
-		case 2: gc->economy = value; break;
-		case 3: gc->defense = value; break;
-		case 4: gc->triggerE = value; break;
-		case 5: gc->triggerD = value; break;
-		case 6: gc->nextTime = value; break;
-		case 7: gc->payTime = value; break;
-		case 8: gc->createTime = value; break;
-		case 9: gc->visibleC = value; break;
+		case CD_CURRENT_ECONOMY: gc->economy = value; break;
+		case CD_CURRENT_DEFENSE: gc->defense = value; break;
+		case CD_INVESTED_ECONOMY: gc->triggerE = value; break;
+		case CD_INVESTED_DEFENSE: gc->triggerD = value; break;
+		case CD_NEXT_TIME: gc->nextTime = value; break;
+		case CD_PAY_TIME: gc->payTime = value; break;
+		case CD_CREATE_TIME: gc->createTime = value; break;
+		case CD_ENABLED_KAFRA: gc->visibleC = value; break;
 		default:
 		default:
-			if (index > 9 && index <= 9+MAX_GUARDIANS) {
-				gc->guardian[index-10].visible = value;
+			if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+				gc->guardian[index - CD_ENABLED_GUARDIAN00].visible = value;
 				break;
 				break;
 			}
 			}
 			ShowError("mapif_parse_GuildCastleDataSave: not found index=%d\n", index);
 			ShowError("mapif_parse_GuildCastleDataSave: not found index=%d\n", index);

+ 17 - 0
src/common/mmo.hpp

@@ -701,6 +701,23 @@ struct guild_castle {
 	int temp_guardians_max;
 	int temp_guardians_max;
 };
 };
 
 
+/// Enum for guild castle data script commands
+enum e_castle_data : uint8 {
+	CD_NONE = 0,
+	CD_GUILD_ID, ///< Guild ID
+	CD_CURRENT_ECONOMY, ///< Castle Economy score
+	CD_CURRENT_DEFENSE, ///< Castle Defense score
+	CD_INVESTED_ECONOMY, ///< Number of times the economy was invested in today
+	CD_INVESTED_DEFENSE, ///< Number of times the defense was invested in today
+	CD_NEXT_TIME, ///< unused
+	CD_PAY_TIME, ///< unused
+	CD_CREATE_TIME, ///< unused
+	CD_ENABLED_KAFRA, ///< Is 1 if a Kafra was hired for this castle, 0 otherwise
+	CD_ENABLED_GUARDIAN00, ///< Is 1 if the 1st guardian is present (Soldier Guardian)
+	// The others in between are not needed in src, but are exported for the script engine
+	CD_MAX = CD_ENABLED_GUARDIAN00 + MAX_GUARDIANS
+};
+
 /// Guild Permissions
 /// Guild Permissions
 enum e_guild_permission {
 enum e_guild_permission {
 	GUILD_PERM_INVITE	= 0x001,
 	GUILD_PERM_INVITE	= 0x001,

+ 1 - 1
src/map/chrif.cpp

@@ -583,7 +583,7 @@ void chrif_on_ready(void) {
 	do_reconnect_storage();
 	do_reconnect_storage();
 
 
 	//Re-save any guild castles that were modified in the disconnection time.
 	//Re-save any guild castles that were modified in the disconnection time.
-	guild_castle_reconnect(-1, 0, 0);
+	guild_castle_reconnect(-1, CD_NONE, 0);
 	
 	
 	// Charserver is ready for loading autotrader
 	// Charserver is ready for loading autotrader
 	if (!char_init_done)
 	if (!char_init_done)

+ 12 - 12
src/map/guild.cpp

@@ -1730,7 +1730,7 @@ int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap)
 		npc_event_do(name);
 		npc_event_do(name);
 
 
 		//Save the new 'owner', this should invoke guardian clean up and other such things.
 		//Save the new 'owner', this should invoke guardian clean up and other such things.
-		guild_castledatasave(gc->castle_id, 1, 0);
+		guild_castledatasave(gc->castle_id, CD_GUILD_ID, 0);
 	}
 	}
 	return 0;
 	return 0;
 }
 }
@@ -1970,7 +1970,7 @@ int guild_castledatasave(int castle_id, int index, int value) {
 	}
 	}
 
 
 	switch (index) {
 	switch (index) {
-	case 1: // The castle's owner has changed? Update or remove Guardians too. [Skotlex]
+	case CD_GUILD_ID: // The castle's owner has changed? Update or remove Guardians too. [Skotlex]
 	{
 	{
 		int i;
 		int i;
 		gc->guild_id = value;
 		gc->guild_id = value;
@@ -1981,9 +1981,9 @@ int guild_castledatasave(int castle_id, int index, int value) {
 		}
 		}
 		break;
 		break;
 	}
 	}
-	case 2:
+	case CD_CURRENT_ECONOMY:
 		gc->economy = value; break;
 		gc->economy = value; break;
-	case 3: // defense invest change -> recalculate guardian hp
+	case CD_CURRENT_DEFENSE: // defense invest change -> recalculate guardian hp
 	{
 	{
 		int i;
 		int i;
 		gc->defense = value;
 		gc->defense = value;
@@ -1994,21 +1994,21 @@ int guild_castledatasave(int castle_id, int index, int value) {
 		}
 		}
 		break;
 		break;
 	}
 	}
-	case 4:
+	case CD_INVESTED_ECONOMY:
 		gc->triggerE = value; break;
 		gc->triggerE = value; break;
-	case 5:
+	case CD_INVESTED_DEFENSE:
 		gc->triggerD = value; break;
 		gc->triggerD = value; break;
-	case 6:
+	case CD_NEXT_TIME:
 		gc->nextTime = value; break;
 		gc->nextTime = value; break;
-	case 7:
+	case CD_PAY_TIME:
 		gc->payTime = value; break;
 		gc->payTime = value; break;
-	case 8:
+	case CD_CREATE_TIME:
 		gc->createTime = value; break;
 		gc->createTime = value; break;
-	case 9:
+	case CD_ENABLED_KAFRA:
 		gc->visibleC = value; break;
 		gc->visibleC = value; break;
 	default:
 	default:
-		if (index > 9 && index <= 9+MAX_GUARDIANS) {
-			gc->guardian[index-10].visible = value;
+		if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+			gc->guardian[index - CD_ENABLED_GUARDIAN00].visible = value;
 			break;
 			break;
 		}
 		}
 		ShowWarning("guild_castledatasave: index = '%d' is out of allowed range\n", index);
 		ShowWarning("guild_castledatasave: index = '%d' is out of allowed range\n", index);

+ 5 - 5
src/map/mob.cpp

@@ -793,11 +793,11 @@ static TIMER_FUNC(mob_spawn_guardian_sub){
 			if (md->guardian_data->castle->guild_id) //Free castle up.
 			if (md->guardian_data->castle->guild_id) //Free castle up.
 			{
 			{
 				ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
 				ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
-				guild_castledatasave(md->guardian_data->castle->castle_id, 1, 0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_GUILD_ID, 0);
 			}
 			}
 		} else {
 		} else {
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
-				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number,0);
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 		}
 		}
 		return 0;
 		return 0;
@@ -2446,7 +2446,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 	}
 	}
 
 
 	if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS )
 	if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS )
-		guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
+		guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number,0);
 
 
 	if( src ) { // Use Dead skill only if not killed by Script or Command
 	if( src ) { // Use Dead skill only if not killed by Script or Command
 		md->status.hp = 1;
 		md->status.hp = 1;
@@ -3090,7 +3090,7 @@ int mob_guardian_guildchange(struct mob_data *md)
 			md->guardian_data->guild_name[0] = '\0';
 			md->guardian_data->guild_name[0] = '\0';
 		} else {
 		} else {
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
-				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number, 0);
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 		}
 		}
 		return 0;
 		return 0;
@@ -3101,7 +3101,7 @@ int mob_guardian_guildchange(struct mob_data *md)
 	{	//Properly remove guardian info from Castle data.
 	{	//Properly remove guardian info from Castle data.
 		ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
 		ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
 		if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS)
 		if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS)
-			guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
+			guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number, 0);
 		unit_free(&md->bl,CLR_OUTSIGHT);
 		unit_free(&md->bl,CLR_OUTSIGHT);
 		return 0;
 		return 0;
 	}
 	}

+ 12 - 12
src/map/script.cpp

@@ -12849,27 +12849,27 @@ BUILDIN_FUNC(getcastledata)
 	}
 	}
 
 
 	switch (index) {
 	switch (index) {
-		case 1:
+		case CD_GUILD_ID:
 			script_pushint(st,gc->guild_id); break;
 			script_pushint(st,gc->guild_id); break;
-		case 2:
+		case CD_CURRENT_ECONOMY:
 			script_pushint(st,gc->economy); break;
 			script_pushint(st,gc->economy); break;
-		case 3:
+		case CD_CURRENT_DEFENSE:
 			script_pushint(st,gc->defense); break;
 			script_pushint(st,gc->defense); break;
-		case 4:
+		case CD_INVESTED_ECONOMY:
 			script_pushint(st,gc->triggerE); break;
 			script_pushint(st,gc->triggerE); break;
-		case 5:
+		case CD_INVESTED_DEFENSE:
 			script_pushint(st,gc->triggerD); break;
 			script_pushint(st,gc->triggerD); break;
-		case 6:
+		case CD_NEXT_TIME:
 			script_pushint(st,gc->nextTime); break;
 			script_pushint(st,gc->nextTime); break;
-		case 7:
+		case CD_PAY_TIME:
 			script_pushint(st,gc->payTime); break;
 			script_pushint(st,gc->payTime); break;
-		case 8:
+		case CD_CREATE_TIME:
 			script_pushint(st,gc->createTime); break;
 			script_pushint(st,gc->createTime); break;
-		case 9:
+		case CD_ENABLED_KAFRA:
 			script_pushint(st,gc->visibleC); break;
 			script_pushint(st,gc->visibleC); break;
 		default:
 		default:
-			if (index > 9 && index <= 9+MAX_GUARDIANS) {
-				script_pushint(st,gc->guardian[index-10].visible);
+			if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+				script_pushint(st,gc->guardian[index - CD_ENABLED_GUARDIAN00].visible);
 				break;
 				break;
 			}
 			}
 			script_pushint(st,0);
 			script_pushint(st,0);
@@ -12891,7 +12891,7 @@ BUILDIN_FUNC(setcastledata)
 		return SCRIPT_CMD_FAILURE;
 		return SCRIPT_CMD_FAILURE;
 	}
 	}
 
 
-	if (index <= 0 || index > 9+MAX_GUARDIANS) {
+	if (index <= CD_NONE || index >= CD_MAX) {
 		ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
 		ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
 		return SCRIPT_CMD_FAILURE;
 		return SCRIPT_CMD_FAILURE;
 	}
 	}

+ 20 - 0
src/map/script_constants.hpp

@@ -7338,6 +7338,26 @@
 	export_constant(GUILDSTORAGE_LOG_EMPTY);
 	export_constant(GUILDSTORAGE_LOG_EMPTY);
 	export_constant(GUILDSTORAGE_LOG_FAILED);
 	export_constant(GUILDSTORAGE_LOG_FAILED);
 
 
+	/* castle data flags */
+	export_constant(CD_NONE);
+	export_constant(CD_GUILD_ID);
+	export_constant(CD_CURRENT_ECONOMY);
+	export_constant(CD_CURRENT_DEFENSE);
+	export_constant(CD_INVESTED_ECONOMY);
+	export_constant(CD_INVESTED_DEFENSE);
+	export_constant(CD_NEXT_TIME);
+	export_constant(CD_PAY_TIME);
+	export_constant(CD_CREATE_TIME);
+	export_constant(CD_ENABLED_KAFRA);
+	for( int i = CD_ENABLED_GUARDIAN00, j = 0; i < CD_MAX; i++, j++ ){
+		char constant[32];
+
+		sprintf( constant, "CD_ENABLED_GUARDIAN%02d", j );
+
+		script_set_constant( constant, i, false, false );
+	}
+	export_constant(CD_MAX);
+
 	#undef export_constant
 	#undef export_constant
 	#undef export_constant2
 	#undef export_constant2
 	#undef export_parameter
 	#undef export_parameter