summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c44
-rw-r--r--src/map/quest.c43
-rw-r--r--src/map/quest.h11
3 files changed, 56 insertions, 42 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 268066d1a..291b5cb46 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -15829,7 +15829,8 @@ void clif_parse_PartyTick(int fd, struct map_session_data* sd)
/// Sends list of all quest states (ZC_ALL_QUEST_LIST).
/// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
-void clif_quest_send_list(struct map_session_data *sd) {
+void clif_quest_send_list(struct map_session_data *sd)
+{
int fd = sd->fd;
int i;
#if PACKETVER >= 20141022
@@ -15846,7 +15847,7 @@ void clif_quest_send_list(struct map_session_data *sd) {
WFIFOW(fd, 2) = len;
WFIFOL(fd, 4) = sd->avail_quests;
- for( i = 0; i < sd->avail_quests; i++ ) {
+ for (i = 0; i < sd->avail_quests; i++) {
#if PACKETVER >= 20141022
struct quest_db *qi = quest->db(sd->quest_log[i].quest_id);
#endif
@@ -15855,7 +15856,7 @@ void clif_quest_send_list(struct map_session_data *sd) {
#if PACKETVER >= 20141022
WFIFOL(fd, i*info_len+13) = sd->quest_log[i].time - qi->time;
WFIFOL(fd, i*info_len+17) = sd->quest_log[i].time;
- WFIFOW(fd, i*info_len+21) = qi->num_objectives;
+ WFIFOW(fd, i*info_len+21) = qi->objectives_count;
#endif
}
@@ -15865,7 +15866,8 @@ void clif_quest_send_list(struct map_session_data *sd) {
/// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
/// 02b2 <packet len>.W <num>.L { <quest id>.L <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 }*num
-void clif_quest_send_mission(struct map_session_data *sd) {
+void clif_quest_send_mission(struct map_session_data *sd)
+{
int fd = sd->fd;
int i, j;
int len = sd->avail_quests*104+8;
@@ -15876,17 +15878,17 @@ void clif_quest_send_mission(struct map_session_data *sd) {
WFIFOW(fd, 2) = len;
WFIFOL(fd, 4) = sd->avail_quests;
- for( i = 0; i < sd->avail_quests; i++ ) {
+ for (i = 0; i < sd->avail_quests; i++) {
struct quest_db *qi = quest->db(sd->quest_log[i].quest_id);
WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
- WFIFOW(fd, i*104+20) = qi->num_objectives;
+ WFIFOW(fd, i*104+20) = qi->objectives_count;
- for( j = 0 ; j < qi->num_objectives; j++ ) {
- WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
+ for (j = 0 ; j < qi->objectives_count; j++) {
+ WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
- monster = mob->db(qi->mob[j]);
+ monster = mob->db(qi->objectives[j].mob);
memcpy(WFIFOP(fd, i*104+28+j*30), monster->jname, NAME_LENGTH);
}
}
@@ -15897,7 +15899,8 @@ void clif_quest_send_mission(struct map_session_data *sd) {
/// Notification about a new quest (ZC_ADD_QUEST).
/// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
-void clif_quest_add(struct map_session_data *sd, struct quest *qd) {
+void clif_quest_add(struct map_session_data *sd, struct quest *qd)
+{
int fd = sd->fd;
int i;
struct quest_db *qi = quest->db(qd->quest_id);
@@ -15908,13 +15911,13 @@ void clif_quest_add(struct map_session_data *sd, struct quest *qd) {
WFIFOB(fd, 6) = qd->state;
WFIFOB(fd, 7) = qd->time - qi->time;
WFIFOL(fd, 11) = qd->time;
- WFIFOW(fd, 15) = qi->num_objectives;
+ WFIFOW(fd, 15) = qi->objectives_count;
- for( i = 0; i < qi->num_objectives; i++ ) {
+ for (i = 0; i < qi->objectives_count; i++) {
struct mob_db *monster;
- WFIFOL(fd, i*30+17) = qi->mob[i];
+ WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
WFIFOW(fd, i*30+21) = qd->count[i];
- monster = mob->db(qi->mob[i]);
+ monster = mob->db(qi->objectives[i].count);
memcpy(WFIFOP(fd, i*30+23), monster->jname, NAME_LENGTH);
}
@@ -15936,21 +15939,22 @@ void clif_quest_delete(struct map_session_data *sd, int quest_id) {
/// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
/// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
-void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd) {
+void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
+{
int fd = sd->fd;
int i;
struct quest_db *qi = quest->db(qd->quest_id);
- int len = qi->num_objectives*12+6;
+ int len = qi->objectives_count*12+6;
WFIFOHEAD(fd, len);
WFIFOW(fd, 0) = 0x2b5;
WFIFOW(fd, 2) = len;
- WFIFOW(fd, 4) = qi->num_objectives;
+ WFIFOW(fd, 4) = qi->objectives_count;
- for( i = 0; i < qi->num_objectives; i++ ) {
+ for (i = 0; i < qi->objectives_count; i++) {
WFIFOL(fd, i*12+6) = qd->quest_id;
- WFIFOL(fd, i*12+10) = qi->mob[i];
- WFIFOW(fd, i*12+14) = qi->count[i];
+ WFIFOL(fd, i*12+10) = qi->objectives[i].mob;
+ WFIFOW(fd, i*12+14) = qi->objectives[i].count;
WFIFOW(fd, i*12+16) = qd->count[i];
}
diff --git a/src/map/quest.c b/src/map/quest.c
index 1c8986f3c..93ec1b04c 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -251,7 +251,8 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap) {
* @param sd Character's data
* @param mob_id Monster ID
*/
-void quest_update_objective(TBL_PC *sd, int mob_id) {
+void quest_update_objective(TBL_PC *sd, int mob_id)
+{
int i,j;
for (i = 0; i < sd->avail_quests; i++) {
@@ -262,8 +263,8 @@ void quest_update_objective(TBL_PC *sd, int mob_id) {
qi = quest->db(sd->quest_log[i].quest_id);
- for (j = 0; j < qi->num_objectives; j++) {
- if (qi->mob[j] == mob_id && sd->quest_log[i].count[j] < qi->count[j]) {
+ for (j = 0; j < qi->objectives_count; j++) {
+ if (qi->objectives[j].mob == mob_id && sd->quest_log[i].count[j] < qi->objectives[j].count) {
sd->quest_log[i].count[j]++;
sd->save_quest = true;
clif->quest_update_objective(sd, &sd->quest_log[i]);
@@ -354,14 +355,15 @@ int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state qs) {
* 1 if the quest's timeout has expired
* 0 otherwise
*/
-int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) {
+int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type)
+{
int i;
ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id);
- if( i == sd->num_quests )
+ if (i == sd->num_quests)
return -1;
- switch( type ) {
+ switch (type) {
case HAVEQUEST:
return sd->quest_log[i].state;
case PLAYTIME:
@@ -370,10 +372,10 @@ int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) {
if( sd->quest_log[i].state == Q_INACTIVE || sd->quest_log[i].state == Q_ACTIVE ) {
int j;
struct quest_db *qi = quest->db(sd->quest_log[i].quest_id);
- ARR_FIND(0, MAX_QUEST_OBJECTIVES, j, sd->quest_log[i].count[j] < qi->count[j]);
- if( j == MAX_QUEST_OBJECTIVES )
+ ARR_FIND(0, qi->objectives_count, j, sd->quest_log[i].count[j] < qi->objectives[j].count);
+ if (j == qi->objectives_count)
return 2;
- if( sd->quest_log[i].time < (unsigned int)time(NULL) )
+ if (sd->quest_log[i].time < (unsigned int)time(NULL))
return 1;
}
return 0;
@@ -443,21 +445,22 @@ struct quest_db *quest_read_db_sub(config_setting_t *cs, int n, const char *sour
if ((t=libconfig->setting_get_member(cs, "Targets")) && config_setting_is_list(t)) {
int i, len = libconfig->setting_length(t);
- for (i = 0; i < len && entry->num_objectives < MAX_QUEST_OBJECTIVES; i++) {
+ for (i = 0; i < len && entry->objectives_count < MAX_QUEST_OBJECTIVES; i++) {
+ // Note: We ensure that objectives_count < MAX_QUEST_OBJECTIVES because
+ // quest_log (as well as the client) expect this maximum size.
config_setting_t *tt = libconfig->setting_get_elem(t, i);
+ int mob_id = 0, count = 0;
if (!tt)
break;
if (!config_setting_is_group(tt))
continue;
- if (libconfig->setting_lookup_int(tt, "MobId", &i32) && i32 > 0)
- entry->mob[entry->num_objectives] = i32;
- if (libconfig->setting_lookup_int(tt, "Count", &i32) && i32 > 0) {
- entry->count[entry->num_objectives] = i32;
- } else {
- entry->mob[entry->num_objectives] = 0;
+ if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id) || mob_id <= 0)
continue;
- }
- entry->num_objectives++;
+ if (!libconfig->setting_lookup_int(tt, "Count", &count) || count <= 0)
+ continue;
+ RECREATE(entry->objectives, struct quest_objective, ++entry->objectives_count);
+ entry->objectives[entry->objectives_count-1].mob = mob_id;
+ entry->objectives[entry->objectives_count-1].count = count;
}
}
@@ -515,6 +518,8 @@ int quest_read_db(void)
ShowWarning("quest_read_db: Duplicate quest %d.\n", entry->id);
if (quest->db_data[entry->id]->dropitem)
aFree(quest->db_data[entry->id]->dropitem);
+ if (quest->db_data[entry->id]->objectives)
+ aFree(quest->db_data[entry->id]->objectives);
aFree(quest->db_data[entry->id]);
}
quest->db_data[entry->id] = entry;
@@ -567,6 +572,8 @@ void quest_clear_db(void) {
for (i = 0; i < MAX_QUEST_DB; i++) {
if (quest->db_data[i]) {
+ if (quest->db_data[i]->objectives)
+ aFree(quest->db_data[i]->objectives);
if (quest->db_data[i]->dropitem)
aFree(quest->db_data[i]->dropitem);
aFree(quest->db_data[i]);
diff --git a/src/map/quest.h b/src/map/quest.h
index db9ffa142..36ac69a53 100644
--- a/src/map/quest.h
+++ b/src/map/quest.h
@@ -8,7 +8,6 @@
#include "map.h" // TBL_PC
#include "../common/cbasetypes.h"
#include "../common/conf.h"
-#include "../common/mmo.h" // MAX_QUEST_OBJECTIVES
#define MAX_QUEST_DB (60355+1) // Highest quest ID + 1
@@ -18,12 +17,16 @@ struct quest_dropitem {
int rate;
};
+struct quest_objective {
+ int mob;
+ int count;
+};
+
struct quest_db {
int id;
unsigned int time;
- int mob[MAX_QUEST_OBJECTIVES];
- int count[MAX_QUEST_OBJECTIVES];
- int num_objectives;
+ int objectives_count;
+ struct quest_objective *objectives;
int dropitem_count;
struct quest_dropitem *dropitem;
//char name[NAME_LENGTH];