From 9bcdb353a459a90db31a341c542643bb71e2e28f Mon Sep 17 00:00:00 2001
From: Kevin <Kevin@54d463be-8e91-2dee-dedb-b68131a5f0ec>
Date: Fri, 11 Apr 2008 01:38:41 +0000
Subject: [PATCH] More questlog code.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12556 54d463be-8e91-2dee-dedb-b68131a5f0ec
---
 Changelog-Trunk.txt              |   1 +
 src/map/Makefile.in              |   4 +-
 src/map/chrif.c                  |   1 +
 src/map/clif.c                   |   4 +-
 src/map/clif.h                   |   5 ++
 src/map/pc.c                     |   6 ++
 src/map/quest.c                  | 137 +++++++++++++++++++++++++++++++
 src/map/quest.h                  |  11 +++
 vcproj-6/map-server_sql.dsp      |   8 ++
 vcproj-6/map-server_txt.dsp      |   8 ++
 vcproj-7.1/map-server_sql.vcproj |   6 ++
 vcproj-7.1/map-server_txt.vcproj |   6 ++
 vcproj-8/map-server_sql.vcproj   |   8 ++
 vcproj-8/map-server_txt.vcproj   |   8 ++
 vcproj-9/map-server_sql.vcproj   |  10 ++-
 vcproj-9/map-server_txt.vcproj   |   8 ++
 16 files changed, 226 insertions(+), 5 deletions(-)
 create mode 100644 src/map/quest.c
 create mode 100644 src/map/quest.h

diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 8293b92a6d..e8fb335cde 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2008/04/10
+	* More quest log code. [Kevin]
 	* Client not marked online until map receives auth request from the client
 	- and is approved. Also added some online/offline sets to the auth system
 	- that were being skipped.(r12552) [Kevin]
diff --git a/src/map/Makefile.in b/src/map/Makefile.in
index 7799b43cea..c923180602 100644
--- a/src/map/Makefile.in
+++ b/src/map/Makefile.in
@@ -17,14 +17,14 @@ MAP_OBJ = map.o chrif.o clif.o pc.o status.o npc.o \
 	npc_chat.o chat.o path.o itemdb.o mob.o script.o \
 	storage.o skill.o atcommand.o charcommand.o battle.o \
 	intif.o trade.o party.o vending.o guild.o pet.o \
-	log.o mail.o date.o irc.o unit.o mercenary.o
+	log.o mail.o date.o irc.o unit.o mercenary.o quest.o
 MAP_TXT_OBJ = $(MAP_OBJ:%=obj_txt/%)
 MAP_SQL_OBJ = $(MAP_OBJ:%=obj_sql/%)
 MAP_H = map.h chrif.h clif.h pc.h status.h npc.h \
 	chat.h itemdb.h mob.h script.h path.h \
 	storage.h skill.h atcommand.h charcommand.h battle.h \
 	intif.h trade.h party.h vending.h guild.h pet.h \
-	log.h mail.h date.h irc.h unit.h mercenary.h
+	log.h mail.h date.h irc.h unit.h mercenary.h quest.h
 
 HAVE_MYSQL=@HAVE_MYSQL@
 ifeq ($(HAVE_MYSQL),yes)
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 78b8c1733a..cc75359efe 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -20,6 +20,7 @@
 #include "status.h"
 #include "mercenary.h"
 #include "chrif.h"
+#include "quest.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/src/map/clif.c b/src/map/clif.c
index 21d246cfa2..01417b2dd2 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -37,6 +37,7 @@
 #include "irc.h"
 #include "clif.h"
 #include "mail.h"
+#include "quest.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -7968,8 +7969,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 		mail_clear(sd);
 #endif
 
-	//Send quest log [Kevin]
-	clif_send_questlog(sd);
+	quest_pc_login(sd);
 
 	if(map[sd->bl.m].flag.loadevent) // Lance
 		npc_script_event(sd, NPCE_LOADMAP);
diff --git a/src/map/clif.h b/src/map/clif.h
index 684ee0fc0d..832829a047 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -396,6 +396,11 @@ void clif_equipcheckbox(struct map_session_data* sd);
 
 //quest system [Kevin]
 void clif_send_questlog(struct map_session_data * sd);
+void clif_send_questlog_info(struct map_session_data * sd);
+void clif_send_quest_info(struct map_session_data * sd, struct quest * qd);
+void clif_send_quest_delete(struct map_session_data * sd, int quest_id);
+void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active);
+
 
 int clif_foreachclient(int (*)(struct map_session_data*,va_list),...);
 int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type);
diff --git a/src/map/pc.c b/src/map/pc.c
index 3d75723261..32f102b6e0 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -32,6 +32,7 @@
 #include "status.h" // struct status_data
 #include "vending.h" // vending_closevending()
 #include "pc.h"
+#include "quest.h"
 
 #ifndef TXT_ONLY // mail system [Valaris]
 #include "mail.h"
@@ -372,6 +373,8 @@ int pc_makesavestatus(struct map_session_data *sd)
 		else
 			memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
 	}
+
+	quest_make_savedata(sd);
 	return 0;
 }
 
@@ -863,6 +866,9 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
 		clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
 	}
 
+	//Get quest data out of char dat
+	quest_load_info(sd, st);
+
 	// Request all registries (auth is considered completed whence they arrive)
 	intif_request_registry(sd,7);
 	return true;
diff --git a/src/map/quest.c b/src/map/quest.c
new file mode 100644
index 0000000000..499d78d6c1
--- /dev/null
+++ b/src/map/quest.c
@@ -0,0 +1,137 @@
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#include "../common/cbasetypes.h"
+#include "../common/socket.h"
+#include "../common/timer.h"
+#include "../common/malloc.h"
+#include "../common/version.h"
+#include "../common/nullpo.h"
+#include "../common/showmsg.h"
+#include "../common/strlib.h"
+#include "../common/utils.h"
+
+#include "map.h"
+#include "chrif.h"
+#include "pc.h"
+#include "npc.h"
+#include "itemdb.h"
+#include "script.h"
+#include "intif.h"
+#include "battle.h"
+#include "mob.h"
+#include "party.h"
+#include "unit.h"
+#include "log.h"
+#include "clif.h"
+#include "quest.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+
+//Send quest info on login
+int quest_pc_login(TBL_PC * sd)
+{
+	clif_send_questlog(sd);
+	clif_send_questlog_info(sd);
+	return 0;
+}
+
+struct quest * quest_make(int id, time_t time, int num_objs, struct quest_objective ** qo_arr)
+{
+	return NULL;
+}
+
+int quest_add(TBL_PC * sd, struct quest * qd)
+{
+
+	int i;
+
+	//Search to see if this quest exists
+	ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == qd->quest_id);
+
+	//Already have this quest
+	if(i!=MAX_QUEST)
+		return 1;
+
+	//Find empty quest log spot
+	ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == 0);
+
+	//Quest log is full
+	if(i == MAX_QUEST)
+		return -1;
+
+	//Copy over quest data
+	memcpy(&sd->quest_log[i], qd, sizeof(struct quest));
+	sd->num_quests++;
+
+	//Notify client
+	clif_send_quest_info(sd, &sd->quest_log[i]);
+
+	return 0;
+
+}
+
+int quest_delete(TBL_PC * sd, int quest_id)
+{
+
+	int i;
+
+	//Search for quest
+	ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id);
+
+	//Quest not found
+	if(i != MAX_QUEST)
+		return -1;
+
+	//Zero quest
+	memset(&sd->quest_log[i], 0, sizeof(struct quest));
+
+	//Notify client
+	clif_send_quest_delete(sd, quest_id);
+
+	return 0;
+
+}
+
+int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, struct quest_objective qod)
+{
+
+	int i;
+
+	//Search for quest
+	ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id);
+
+	//Quest not found
+	if(i != MAX_QUEST)
+		return -1;
+
+	memcpy(sd->quest_log[i].objectives[objective_num].name, qod.name, NAME_LENGTH);
+	sd->quest_log[i].objectives[objective_num].count = qod.count;
+
+	//Notify client
+	clif_send_quest_info(sd, &sd->quest_log[i]);
+
+	return 0;
+
+}
+
+int quest_load_info(TBL_PC * sd, struct mmo_charstatus * st)
+{
+	sd->num_quests = st->num_quests;
+	memcpy(sd->quest_log, st->quest_log, sizeof(st->quest_log));
+
+	return 0;
+}
+
+int quest_make_savedata(TBL_PC * sd)
+{
+	sd->status.num_quests = sd->num_quests;
+	memcpy(sd->status.quest_log, sd->quest_log, sizeof(sd->quest_log));
+
+	return 0;
+}
+
diff --git a/src/map/quest.h b/src/map/quest.h
new file mode 100644
index 0000000000..efcfbc2d01
--- /dev/null
+++ b/src/map/quest.h
@@ -0,0 +1,11 @@
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#ifndef _QUEST_H_
+#define _QUEST_H_
+
+int quest_pc_login(TBL_PC * sd);
+int quest_load_info(TBL_PC * sd, struct mmo_charstatus * st);
+int quest_make_savedata(TBL_PC * sd);
+
+#endif
diff --git a/vcproj-6/map-server_sql.dsp b/vcproj-6/map-server_sql.dsp
index a80ded6f14..cfcf61a39c 100644
--- a/vcproj-6/map-server_sql.dsp
+++ b/vcproj-6/map-server_sql.dsp
@@ -425,6 +425,14 @@ SOURCE=..\src\map\vending.c
 
 SOURCE=..\src\map\vending.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\src\map\quest.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\map\quest.h
+# End Source File
 # End Group
 # Begin Group "zlib"
 
diff --git a/vcproj-6/map-server_txt.dsp b/vcproj-6/map-server_txt.dsp
index 2f56c5a629..4f2e4409ed 100644
--- a/vcproj-6/map-server_txt.dsp
+++ b/vcproj-6/map-server_txt.dsp
@@ -421,6 +421,14 @@ SOURCE=..\src\map\unit.h
 
 SOURCE=..\src\map\vending.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\src\map\quest.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\map\quest.h
+# End Source File
 # End Group
 # Begin Group "zlib"
 
diff --git a/vcproj-7.1/map-server_sql.vcproj b/vcproj-7.1/map-server_sql.vcproj
index c80671cff4..91e1906b4d 100644
--- a/vcproj-7.1/map-server_sql.vcproj
+++ b/vcproj-7.1/map-server_sql.vcproj
@@ -322,6 +322,12 @@
 			<File
 				RelativePath="..\src\map\vending.h">
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c">
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h">
+			</File>
 		</Filter>
 		<Filter
 			Name="common"
diff --git a/vcproj-7.1/map-server_txt.vcproj b/vcproj-7.1/map-server_txt.vcproj
index e88722e62a..e389684da5 100644
--- a/vcproj-7.1/map-server_txt.vcproj
+++ b/vcproj-7.1/map-server_txt.vcproj
@@ -322,6 +322,12 @@
 			<File
 				RelativePath="..\src\map\vending.h">
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c">
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h">
+			</File>
 		</Filter>
 		<Filter
 			Name="common"
diff --git a/vcproj-8/map-server_sql.vcproj b/vcproj-8/map-server_sql.vcproj
index e752872d88..d6cbf3f2d1 100644
--- a/vcproj-8/map-server_sql.vcproj
+++ b/vcproj-8/map-server_sql.vcproj
@@ -590,6 +590,14 @@
 				RelativePath="..\src\map\vending.h"
 				>
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h"
+				>
+			</File>
 		</Filter>
 	</Files>
 	<Globals>
diff --git a/vcproj-8/map-server_txt.vcproj b/vcproj-8/map-server_txt.vcproj
index f0a6f17a13..db7453962b 100644
--- a/vcproj-8/map-server_txt.vcproj
+++ b/vcproj-8/map-server_txt.vcproj
@@ -437,6 +437,14 @@
 				RelativePath="..\src\map\vending.h"
 				>
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="zlib"
diff --git a/vcproj-9/map-server_sql.vcproj b/vcproj-9/map-server_sql.vcproj
index d752dda681..15e1527b68 100644
--- a/vcproj-9/map-server_sql.vcproj
+++ b/vcproj-9/map-server_sql.vcproj
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="9,00"
+	Version="9.00"
 	Name="map-server_sql"
 	ProjectGUID="{D356871D-58E1-450B-967A-E6E9646175AF}"
 	RootNamespace="map-server_sql"
@@ -530,6 +530,14 @@
 				RelativePath="..\src\map\pet.h"
 				>
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h"
+				>
+			</File>
 			<File
 				RelativePath="..\src\map\script.c"
 				>
diff --git a/vcproj-9/map-server_txt.vcproj b/vcproj-9/map-server_txt.vcproj
index e80547c57a..61a985d5f3 100644
--- a/vcproj-9/map-server_txt.vcproj
+++ b/vcproj-9/map-server_txt.vcproj
@@ -433,6 +433,14 @@
 				RelativePath="..\src\map\vending.h"
 				>
 			</File>
+			<File
+				RelativePath="..\src\map\quest.c"
+				>
+			</File>
+			<File
+				RelativePath="..\src\map\quest.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="zlib"