From 0bd4a0178cd5beb8bee955777afe32392d75afa9 Mon Sep 17 00:00:00 2001
From: dastgir <dastgirpojee@rocketmail.com>
Date: Wed, 11 Feb 2015 10:01:41 -0500
Subject: Battleground Data to HPM Struct

---
 src/map/HPMmap.c       |  4 ++++
 src/map/battleground.c | 23 ++++++++++++++++++++++-
 src/map/battleground.h |  4 ++++
 3 files changed, 30 insertions(+), 1 deletion(-)

(limited to 'src/map')

diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index 3da49c3b9..d6a1bd8ef 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -114,6 +114,10 @@ bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType
 			ret->HPDataSRCPtr = (void**)(&((struct item_data *)ptr)->hdata);
 			ret->hdatac = &((struct item_data *)ptr)->hdatac;
 			break;
+		case HPDT_BGDATA:
+			ret->HPDataSRCPtr = (void**)(&((struct battleground_data *)ptr)->hdata);
+			ret->hdatac = &((struct battleground_data *)ptr)->hdatac;
+			break;
 		default:
 			return false;
 	}
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 2d4ba6bf1..f0bad2b3d 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -22,6 +22,7 @@
 #include "pet.h"
 #include "../common/cbasetypes.h"
 #include "../common/conf.h"
+#include "../common/HPM.h"
 #include "../common/malloc.h"
 #include "../common/nullpo.h"
 #include "../common/showmsg.h"
@@ -856,9 +857,27 @@ void do_init_battleground(bool minimal) {
 	bg->config_read();
 }
 
+/**
+ * @see DBApply
+ */
+int bg_team_db_final(DBKey key, DBData *data, va_list ap) {
+	struct battleground_data* bgd = DB->data2ptr(data);
+	int i;
+	for(i = 0; i < bgd->hdatac; i++ ) {
+		if( bgd->hdata[i]->flag.free ) {
+			aFree(bgd->hdata[i]->data);
+		}
+		aFree(bgd->hdata[i]);
+	}
+	if( bgd->hdata )
+		aFree(bgd->hdata);
+		
+	return 0;
+}
+
 void do_final_battleground(void)
 {
-	db_destroy(bg->team_db);
+	bg->team_db->destroy(bg->team_db,bg->team_db_final);
 
 	if (bg->arena) {
 		int i;
@@ -868,6 +887,7 @@ void do_final_battleground(void)
 		}
 		aFree(bg->arena);
 	}
+	
 }
 void battleground_defaults(void) {
 	bg = &bg_s;
@@ -911,6 +931,7 @@ void battleground_defaults(void) {
 	bg->send_xy_timer_sub = bg_send_xy_timer_sub;
 	bg->send_xy_timer = bg_send_xy_timer;
 	bg->afk_timer = bg_afk_timer;
+	bg->team_db_final = bg_team_db_final;
 	/* */
 	bg->str2teamtype = bg_str2teamtype;
 	/* */
diff --git a/src/map/battleground.h b/src/map/battleground.h
index 9878d6be0..87d56516a 100644
--- a/src/map/battleground.h
+++ b/src/map/battleground.h
@@ -48,6 +48,9 @@ struct battleground_data {
 	// Logout Event
 	char logout_event[EVENT_NAME_LENGTH];
 	char die_event[EVENT_NAME_LENGTH];
+	/* HPM Custom Struct */
+	struct HPluginData **hdata;
+	unsigned int hdatac;
 };
 
 struct bg_arena {
@@ -112,6 +115,7 @@ struct battleground_interface {
 	int (*send_xy_timer_sub) (DBKey key, DBData *data, va_list ap);
 	int (*send_xy_timer) (int tid, int64 tick, int id, intptr_t data);
 	int (*afk_timer) (int tid, int64 tick, int id, intptr_t data);
+	int (*team_db_final) (DBKey key, DBData *data, va_list ap);
 	/* */
 	enum bg_queue_types (*str2teamtype) (const char *str);
 	/* */
-- 
cgit v1.2.3-70-g09d2