diff options
author | shennetsind <ind@henn.et> | 2013-09-16 12:31:37 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-09-16 12:31:37 -0300 |
commit | 8fb81341feedb5d00175d83e816f4d2ec2d4eb36 (patch) | |
tree | 367f9ad9d60537832c6afdfa674ab94aa011207d /src | |
parent | 7f933ea6cb66e4deb2dc53c7aa3a96d82cb2884d (diff) | |
download | hercules-8fb81341feedb5d00175d83e816f4d2ec2d4eb36.tar.gz hercules-8fb81341feedb5d00175d83e816f4d2ec2d4eb36.tar.bz2 hercules-8fb81341feedb5d00175d83e816f4d2ec2d4eb36.tar.xz hercules-8fb81341feedb5d00175d83e816f4d2ec2d4eb36.zip |
HPM: Quest.c Interface
Fully Integrated
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r-- | src/map/atcommand.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 32 | ||||
-rw-r--r-- | src/map/intif.c | 4 | ||||
-rw-r--r-- | src/map/map.c | 4 | ||||
-rw-r--r-- | src/map/mob.c | 4 | ||||
-rw-r--r-- | src/map/quest.c | 78 | ||||
-rw-r--r-- | src/map/quest.h | 37 | ||||
-rw-r--r-- | src/map/script.c | 10 |
8 files changed, 100 insertions, 71 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 2b1426180..f13ad0a4e 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8689,7 +8689,7 @@ ACMD(set) { return true; } ACMD(reloadquestdb) { - do_reload_quest(); + quest->reload(); clif->message(fd, msg_txt(1377)); // Quest database has been reloaded. return true; } diff --git a/src/map/clif.c b/src/map/clif.c index 5fe08438e..da8af5543 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -15514,15 +15514,15 @@ void clif_quest_send_mission(struct map_session_data * sd) for( i = 0; i < sd->avail_quests; i++ ) { WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id; - WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time; + WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest->db[sd->quest_index[i]].time; WFIFOL(fd, i*104+16) = sd->quest_log[i].time; - WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives; + WFIFOW(fd, i*104+20) = quest->db[sd->quest_index[i]].num_objectives; - for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ ) + for( j = 0 ; j < quest->db[sd->quest_index[i]].num_objectives; j++ ) { - WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j]; + WFIFOL(fd, i*104+22+j*30) = quest->db[sd->quest_index[i]].mob[j]; WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j]; - monster = mob->db(quest_db[sd->quest_index[i]].mob[j]); + monster = mob->db(quest->db[sd->quest_index[i]].mob[j]); memcpy(WFIFOP(fd, i*104+28+j*30), monster?monster->jname:"NULL", NAME_LENGTH); } } @@ -15543,14 +15543,14 @@ void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index) WFIFOW(fd, 0) = 0x2b3; WFIFOL(fd, 2) = qd->quest_id; WFIFOB(fd, 6) = qd->state; - WFIFOB(fd, 7) = qd->time - quest_db[index].time; + WFIFOB(fd, 7) = qd->time - quest->db[index].time; WFIFOL(fd, 11) = qd->time; - WFIFOW(fd, 15) = quest_db[index].num_objectives; + WFIFOW(fd, 15) = quest->db[index].num_objectives; - for( i = 0; i < quest_db[index].num_objectives; i++ ) { - WFIFOL(fd, i*30+17) = quest_db[index].mob[i]; + for( i = 0; i < quest->db[index].num_objectives; i++ ) { + WFIFOL(fd, i*30+17) = quest->db[index].mob[i]; WFIFOW(fd, i*30+21) = qd->count[i]; - monster = mob->db(quest_db[index].mob[i]); + monster = mob->db(quest->db[index].mob[i]); memcpy(WFIFOP(fd, i*30+23), monster?monster->jname:"NULL", NAME_LENGTH); } @@ -15577,17 +15577,17 @@ void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd { int fd = sd->fd; int i; - int len = quest_db[index].num_objectives*12+6; + int len = quest->db[index].num_objectives*12+6; WFIFOHEAD(fd, len); WFIFOW(fd, 0) = 0x2b5; WFIFOW(fd, 2) = len; - WFIFOW(fd, 4) = quest_db[index].num_objectives; + WFIFOW(fd, 4) = quest->db[index].num_objectives; - for( i = 0; i < quest_db[index].num_objectives; i++ ) { + for( i = 0; i < quest->db[index].num_objectives; i++ ) { WFIFOL(fd, i*12+6) = qd->quest_id; - WFIFOL(fd, i*12+10) = quest_db[index].mob[i]; - WFIFOW(fd, i*12+14) = quest_db[index].count[i]; + WFIFOL(fd, i*12+10) = quest->db[index].mob[i]; + WFIFOW(fd, i*12+14) = quest->db[index].count[i]; WFIFOW(fd, i*12+16) = qd->count[i]; } @@ -15599,7 +15599,7 @@ void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd /// 02b6 <quest id>.L <active>.B void clif_parse_questStateAck(int fd, struct map_session_data * sd) { - quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE); + quest->update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE); } diff --git a/src/map/intif.c b/src/map/intif.c index 180195e4c..ac1471d23 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1419,7 +1419,7 @@ int intif_parse_questlog(int fd) { memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest)); - sd->quest_index[i] = quest_search_db(sd->quest_log[i].quest_id); + sd->quest_index[i] = quest->search_db(sd->quest_log[i].quest_id); if( sd->quest_index[i] < 0 ) { @@ -1434,7 +1434,7 @@ int intif_parse_questlog(int fd) sd->avail_quests--; } - quest_pc_login(sd); + quest->pc_login(sd); return 0; } diff --git a/src/map/map.c b/src/map/map.c index e4d3e4869..5cc475ad7 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5174,6 +5174,7 @@ void map_hp_symbols(void) { HPM->share(mapreg,"mapreg"); HPM->share(pet,"pet"); HPM->share(path,"path"); + HPM->share(quest,"quest"); /* partial */ HPM->share(mapit,"mapit"); @@ -5224,6 +5225,7 @@ void map_load_defaults(void) { mapreg_defaults(); pet_defaults(); path_defaults(); + quest_defaults(); } int do_init(int argc, char *argv[]) { @@ -5422,7 +5424,7 @@ int do_init(int argc, char *argv[]) homun->init(); mercenary->init(); elemental->do_init_elemental(); - do_init_quest(); + quest->init(); npc->init(); unit->init(); do_init_battleground(); diff --git a/src/map/mob.c b/src/map/mob.c index 701a89b6c..3b3ff0797 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -2568,9 +2568,9 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) } if( sd->status.party_id ) - iMap->foreachinrange(quest_update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->class_); + iMap->foreachinrange(quest->update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->class_); else if( sd->avail_quests ) - quest_update_objective(sd, md->class_); + quest->update_objective(sd, md->class_); if( sd->md && src && src->type != BL_HOM && mob->db(md->class_)->lv > sd->status.base_level/2 ) mercenary->kills(sd->md); diff --git a/src/map/quest.c b/src/map/quest.c index cf78430a4..9055b61fe 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/cbasetypes.h" #include "../common/socket.h" @@ -32,14 +33,13 @@ #include <time.h> -struct s_quest_db quest_db[MAX_QUEST_DB]; - +struct quest_interface quest_s; int quest_search_db(int quest_id) { int i; - ARR_FIND(0, MAX_QUEST_DB,i,quest_id == quest_db[i].id); + ARR_FIND(0, MAX_QUEST_DB,i,quest_id == quest->db[i].id); if( i == MAX_QUEST_DB ) return -1; @@ -74,13 +74,13 @@ int quest_add(TBL_PC * sd, int quest_id) return 1; } - if( quest_check(sd, quest_id, HAVEQUEST) >= 0 ) + if( quest->check(sd, quest_id, HAVEQUEST) >= 0 ) { ShowError("quest_add: Character %d already has quest %d.\n", sd->status.char_id, quest_id); return -1; } - if( (j = quest_search_db(quest_id)) < 0 ) + if( (j = quest->search_db(quest_id)) < 0 ) { ShowError("quest_add: quest %d not found in DB.\n", quest_id); return -1; @@ -91,9 +91,9 @@ int quest_add(TBL_PC * sd, int quest_id) memmove(sd->quest_index+i+1, sd->quest_index+i, sizeof(int)*(sd->num_quests-sd->avail_quests)); memset(&sd->quest_log[i], 0, sizeof(struct quest)); - sd->quest_log[i].quest_id = quest_db[j].id; - if( quest_db[j].time ) - sd->quest_log[i].time = (unsigned int)(time(NULL) + quest_db[j].time); + sd->quest_log[i].quest_id = quest->db[j].id; + if( quest->db[j].time ) + sd->quest_log[i].time = (unsigned int)(time(NULL) + quest->db[j].time); sd->quest_log[i].state = Q_ACTIVE; sd->quest_index[i] = j; @@ -114,19 +114,19 @@ int quest_change(TBL_PC * sd, int qid1, int qid2) int i, j; - if( quest_check(sd, qid2, HAVEQUEST) >= 0 ) + if( quest->check(sd, qid2, HAVEQUEST) >= 0 ) { ShowError("quest_change: Character %d already has quest %d.\n", sd->status.char_id, qid2); return -1; } - if( quest_check(sd, qid1, HAVEQUEST) < 0 ) + if( quest->check(sd, qid1, HAVEQUEST) < 0 ) { ShowError("quest_change: Character %d doesn't have quest %d.\n", sd->status.char_id, qid1); return -1; } - if( (j = quest_search_db(qid2)) < 0 ) + if( (j = quest->search_db(qid2)) < 0 ) { ShowError("quest_change: quest %d not found in DB.\n",qid2); return -1; @@ -140,9 +140,9 @@ int quest_change(TBL_PC * sd, int qid1, int qid2) } memset(&sd->quest_log[i], 0, sizeof(struct quest)); - sd->quest_log[i].quest_id = quest_db[j].id; - if( quest_db[j].time ) - sd->quest_log[i].time = (unsigned int)(time(NULL) + quest_db[j].time); + sd->quest_log[i].quest_id = quest->db[j].id; + if( quest->db[j].time ) + sd->quest_log[i].time = (unsigned int)(time(NULL) + quest->db[j].time); sd->quest_log[i].state = Q_ACTIVE; sd->quest_index[i] = j; @@ -205,7 +205,7 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap) if( sd->status.party_id != party ) return 0; - quest_update_objective(sd, mob); + quest->update_objective(sd, mob); return 1; } @@ -219,7 +219,7 @@ void quest_update_objective(TBL_PC * sd, int mob) { continue; for( j = 0; j < MAX_QUEST_OBJECTIVES; j++ ) - if( quest_db[sd->quest_index[i]].mob[j] == mob && sd->quest_log[i].count[j] < quest_db[sd->quest_index[i]].count[j] ) { + if( quest->db[sd->quest_index[i]].mob[j] == mob && sd->quest_log[i].count[j] < quest->db[sd->quest_index[i]].count[j] ) { sd->quest_log[i].count[j]++; sd->save_quest = true; clif->quest_update_objective(sd,&sd->quest_log[i],sd->quest_index[i]); @@ -275,7 +275,7 @@ int quest_check(TBL_PC * sd, int quest_id, quest_check_type type) { case HUNTING: { if( sd->quest_log[i].state == 0 || sd->quest_log[i].state == 1 ) { int j; - ARR_FIND(0, MAX_QUEST_OBJECTIVES, j, sd->quest_log[i].count[j] < quest_db[sd->quest_index[i]].count[j]); + ARR_FIND(0, MAX_QUEST_OBJECTIVES, j, sd->quest_log[i].count[j] < quest->db[sd->quest_index[i]].count[j]); if( j == MAX_QUEST_OBJECTIVES ) return 2; if( sd->quest_log[i].time < (unsigned int)time(NULL) ) @@ -331,20 +331,20 @@ int quest_read_db(void) { if(str[0]==NULL) continue; - memset(&quest_db[k], 0, sizeof(quest_db[0])); + memset(&quest->db[k], 0, sizeof(quest->db[0])); - quest_db[k].id = atoi(str[0]); - quest_db[k].time = atoi(str[1]); + quest->db[k].id = atoi(str[0]); + quest->db[k].time = atoi(str[1]); for( i = 0; i < MAX_QUEST_OBJECTIVES; i++ ) { - quest_db[k].mob[i] = atoi(str[2*i+2]); - quest_db[k].count[i] = atoi(str[2*i+3]); + quest->db[k].mob[i] = atoi(str[2*i+2]); + quest->db[k].count[i] = atoi(str[2*i+3]); - if( !quest_db[k].mob[i] || !quest_db[k].count[i] ) + if( !quest->db[k].mob[i] || !quest->db[k].count[i] ) break; } - quest_db[k].num_objectives = i; + quest->db[k].num_objectives = i; k++; } @@ -354,10 +354,30 @@ int quest_read_db(void) { } void do_init_quest(void) { - quest_read_db(); + quest->read_db(); } void do_reload_quest(void) { - memset(&quest_db, 0, sizeof(quest_db)); - quest_read_db(); + memset(&quest->db, 0, sizeof(quest->db)); + quest->read_db(); +} + +void quest_defaults(void) { + quest = &quest_s; + + memset(&quest->db, 0, sizeof(quest->db)); + /* */ + quest->init = do_init_quest; + quest->reload = do_reload_quest; + /* */ + quest->search_db = quest_search_db; + quest->pc_login = quest_pc_login; + quest->add = quest_add; + quest->change = quest_change; + quest->delete = quest_delete; + quest->update_objective_sub = quest_update_objective_sub; + quest->update_objective = quest_update_objective; + quest->update_status = quest_update_status; + quest->check = quest_check; + quest->read_db = quest_read_db; } diff --git a/src/map/quest.h b/src/map/quest.h index 7f638a54c..85c987f54 100644 --- a/src/map/quest.h +++ b/src/map/quest.h @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _QUEST_H_ #define _QUEST_H_ @@ -12,23 +13,29 @@ struct s_quest_db { int num_objectives; //char name[NAME_LENGTH]; }; -extern struct s_quest_db quest_db[MAX_QUEST_DB]; typedef enum quest_check_type { HAVEQUEST, PLAYTIME, HUNTING } quest_check_type; -int quest_pc_login(TBL_PC * sd); - -int quest_add(TBL_PC * sd, int quest_id); -int quest_delete(TBL_PC * sd, int quest_id); -int quest_change(TBL_PC * sd, int qid1, int qid2); -int quest_update_objective_sub(struct block_list *bl, va_list ap); -void quest_update_objective(TBL_PC * sd, int mob); -int quest_update_status(TBL_PC * sd, int quest_id, quest_state status); -int quest_check(TBL_PC * sd, int quest_id, quest_check_type type); +struct quest_interface { + struct s_quest_db db[MAX_QUEST_DB]; + /* */ + void (*init) (void); + void (*reload) (void); + /* */ + int (*search_db) (int quest_id); + int (*pc_login) (TBL_PC *sd); + int (*add) (TBL_PC *sd, int quest_id); + int (*change) (TBL_PC *sd, int qid1, int qid2); + int (*delete) (TBL_PC *sd, int quest_id); + int (*update_objective_sub) (struct block_list *bl, va_list ap); + void (*update_objective) (TBL_PC *sd, int mob); + int (*update_status) (TBL_PC *sd, int quest_id, quest_state status); + int (*check) (TBL_PC *sd, int quest_id, quest_check_type type); + int (*read_db) (void); +}; -int quest_search_db(int quest_id); +struct quest_interface *quest; -void do_init_quest(); -void do_reload_quest(void); +void quest_defaults(void); #endif diff --git a/src/map/script.c b/src/map/script.c index feebef478..3ea26694e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15645,7 +15645,7 @@ BUILDIN(setquest) struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - quest_add(sd, script_getnum(st, 2)); + quest->add(sd, script_getnum(st, 2)); return true; } @@ -15654,7 +15654,7 @@ BUILDIN(erasequest) struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - quest_delete(sd, script_getnum(st, 2)); + quest->delete(sd, script_getnum(st, 2)); return true; } @@ -15663,7 +15663,7 @@ BUILDIN(completequest) struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE); + quest->update_status(sd, script_getnum(st, 2), Q_COMPLETE); return true; } @@ -15672,7 +15672,7 @@ BUILDIN(changequest) struct map_session_data *sd = script_rid2sd(st); nullpo_ret(sd); - quest_change(sd, script_getnum(st, 2),script_getnum(st, 3)); + quest->change(sd, script_getnum(st, 2),script_getnum(st, 3)); return true; } @@ -15686,7 +15686,7 @@ BUILDIN(checkquest) if( script_hasdata(st, 3) ) type = (quest_check_type)script_getnum(st, 3); - script_pushint(st, quest_check(sd, script_getnum(st, 2), type)); + script_pushint(st, quest->check(sd, script_getnum(st, 2), type)); return true; } |