Skip to content

Commit

Permalink
HPM: Quest.c Interface
Browse files Browse the repository at this point in the history
Fully Integrated

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Sep 16, 2013
1 parent 7f933ea commit 8fb8134
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/map/atcommand.c
Expand Up @@ -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;
}
Expand Down
32 changes: 16 additions & 16 deletions src/map/clif.c
Expand Up @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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];
}

Expand All @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/map/intif.c
Expand Up @@ -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 )
{
Expand All @@ -1434,7 +1434,7 @@ int intif_parse_questlog(int fd)
sd->avail_quests--;
}

quest_pc_login(sd);
quest->pc_login(sd);

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/map/map.c
Expand Up @@ -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");
Expand Down Expand Up @@ -5224,6 +5225,7 @@ void map_load_defaults(void) {
mapreg_defaults();
pet_defaults();
path_defaults();
quest_defaults();
}
int do_init(int argc, char *argv[])
{
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/map/mob.c
Expand Up @@ -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);
Expand Down
78 changes: 49 additions & 29 deletions 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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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]);
Expand Down Expand Up @@ -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) )
Expand Down Expand Up @@ -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++;
}
Expand All @@ -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;
}
37 changes: 22 additions & 15 deletions 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_
Expand All @@ -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

0 comments on commit 8fb8134

Please sign in to comment.