From 0e38fa59227ec3892fdeb0a9dfdd1037c9225e4d Mon Sep 17 00:00:00 2001 From: Asheraf Date: Wed, 3 Oct 2018 11:30:02 +0100 Subject: Add new type for mercenary class to setquestinfo() --- doc/script_commands.txt | 1 + src/common/mmo.h | 3 ++- src/map/map.h | 1 + src/map/quest.c | 27 +++++++++++++++++++++++++++ src/map/quest.h | 1 + src/map/script.c | 12 ++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 343eb02cb..05b16f66f 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -9418,6 +9418,7 @@ supported types: values QINFO_HOMUN_LEVEL: min QINFO_HOMUN_TYPE: homunculus_type (0 - regular, 1 - evolved, 2 - S) QINFO_QUEST: quest_id, state // append to the quests list on each use + QINFO_MERCENARY_CLASS: mercenary_class --------------------------------------- diff --git a/src/common/mmo.h b/src/common/mmo.h index d6946cecc..9bcf82cc7 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -1331,7 +1331,8 @@ enum questinfo_type { QINFO_ITEM, QINFO_HOMUN_LEVEL, QINFO_HOMUN_TYPE, - QINFO_QUEST + QINFO_QUEST, + QINFO_MERCENARY_CLASS }; /* packet size constant for itemlist */ diff --git a/src/map/map.h b/src/map/map.h index d50666d4b..cb025e9c1 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -815,6 +815,7 @@ struct questinfo { struct s_homunculus homunculus; int homunculus_type; VECTOR_DECL(struct questinfo_qreq) quest_requirement; + int mercenary_class; }; diff --git a/src/map/quest.c b/src/map/quest.c index 02bf7638b..f10d6847f 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -30,6 +30,7 @@ #include "map/itemdb.h" #include "map/log.h" #include "map/map.h" +#include "map/mercenary.h" #include "map/mob.h" #include "map/npc.h" #include "map/party.h" @@ -719,6 +720,8 @@ static bool quest_questinfo_validate(struct map_session_data *sd, struct questin return false; if (VECTOR_LENGTH(qi->quest_requirement) > 0 && quest->questinfo_validate_quests(sd, qi) == false) return false; + if (qi->mercenary_class != 0 && quest->questinfo_validate_mercenary_class(sd, qi) == false) + return false; return true; } @@ -900,6 +903,29 @@ static bool quest_questinfo_validate_quests(struct map_session_data *sd, struct return true; } +/** + * Validate mercenary class required for the questinfo + * + * @param sd session data. + * @param qi questinfo data. + * + * @retval true if player have a mercenary with the given class. + * @retval false if player does NOT have a mercenary with the given class. + */ +static bool quest_questinfo_validate_mercenary_class(struct map_session_data *sd, struct questinfo *qi) +{ + nullpo_retr(false, sd); + nullpo_retr(false, qi); + + if (sd->md == NULL) + return false; + + if (sd->md->mercenary.class_ != qi->mercenary_class) + return false; + + return true; +} + /** * Clears the questinfo data vector * @@ -993,5 +1019,6 @@ void quest_defaults(void) quest->questinfo_validate_homunculus_level = quest_questinfo_validate_homunculus_level; quest->questinfo_validate_homunculus_type = quest_questinfo_validate_homunculus_type; quest->questinfo_validate_quests = quest_questinfo_validate_quests; + quest->questinfo_validate_mercenary_class = quest_questinfo_validate_mercenary_class; quest->questinfo_vector_clear = quest_questinfo_vector_clear; } diff --git a/src/map/quest.h b/src/map/quest.h index 305a48df1..206a7902f 100644 --- a/src/map/quest.h +++ b/src/map/quest.h @@ -92,6 +92,7 @@ struct quest_interface { bool (*questinfo_validate_homunculus_level) (struct map_session_data *sd, struct questinfo *qi); bool (*questinfo_validate_homunculus_type) (struct map_session_data *sd, struct questinfo *qi); bool (*questinfo_validate_quests) (struct map_session_data *sd, struct questinfo *qi); + bool (*questinfo_validate_mercenary_class) (struct map_session_data *sd, struct questinfo *qi); void (*questinfo_vector_clear) (int m); }; diff --git a/src/map/script.c b/src/map/script.c index b787d0138..70adddfe2 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -21190,6 +21190,17 @@ static BUILDIN(setquestinfo) VECTOR_PUSH(qi->quest_requirement, quest_req); break; } + case QINFO_MERCENARY_CLASS: + { + int mer_class = script_getnum(st, 3); + + if (!mercenary->class(mer_class)) { + ShowWarning("buildin_setquestinfo: invalid mercenary class given (%d).\n", mer_class); + return false; + } + qi->mercenary_class = mer_class; + break; + } default: ShowWarning("buildin_setquestinfo: invalid type given (%u).\n", type); return false; @@ -25930,6 +25941,7 @@ static void script_hardcoded_constants(void) script->set_constant("QINFO_HOMUN_LEVEL", QINFO_HOMUN_LEVEL, false, false); script->set_constant("QINFO_HOMUN_TYPE", QINFO_HOMUN_TYPE, false, false); script->set_constant("QINFO_QUEST", QINFO_QUEST, false, false); + script->set_constant("QINFO_MERCENARY_CLASS", QINFO_MERCENARY_CLASS, false, false); script->constdb_comment("function types"); script->set_constant("FUNCTION_IS_COMMAND", FUNCTION_IS_COMMAND, false, false); -- cgit v1.2.3-60-g2f50