summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-11-13 21:26:21 -0200
committershennetsind <ind@henn.et>2013-11-13 21:26:21 -0200
commit8fda38dcdabbb9d252b0e11fb07b2ad37f9e659f (patch)
tree4b08262c9ef18f9a2dd39d56ae2509320ab26e8c /src/map
parentb4d197c667353f417069c406b85a696e3e2e5b6c (diff)
downloadhercules-8fda38dcdabbb9d252b0e11fb07b2ad37f9e659f.tar.gz
hercules-8fda38dcdabbb9d252b0e11fb07b2ad37f9e659f.tar.bz2
hercules-8fda38dcdabbb9d252b0e11fb07b2ad37f9e659f.tar.xz
hercules-8fda38dcdabbb9d252b0e11fb07b2ad37f9e659f.zip
HPM Custom Data Struct Makeover!
- Modified how the core handles it, making it easier to add new points. - Modified how plugins call it, calls were made shorter, e.g. 'HPMi->getFromSession(session[fd],HPMi->pid,0)' => 'getFromSession(session[fd],0)' -- check src/common/HPMi.h #defines for all the options - Added support for npc_data (getFromNPCD and so on) as requested in http://hercules.ws/board/topic/2923-hpm-custom-struct-npcs/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/HPMmap.c81
-rw-r--r--src/map/HPMmap.h5
-rw-r--r--src/map/map.c4
-rw-r--r--src/map/npc.c11
-rw-r--r--src/map/npc.h6
-rw-r--r--src/map/unit.c2
6 files changed, 36 insertions, 73 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index 8a69cba97..8d7c74ef2 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -46,76 +46,27 @@ struct HPM_atcommand_list {
struct HPM_atcommand_list *atcommand_list = NULL;
unsigned int atcommand_list_items = 0;
-void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, unsigned int type, bool autofree) {
- struct HPluginData *HPData;
- unsigned int i;
-
- for(i = 0; i < sd->hdatac; i++) {
- if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) {
- ShowError("HPMi->addToMSD:%s: error! attempting to insert duplicate struct of type %u on '%s'\n",HPM->pid2name(id),type,sd->status.name);
- return;
- }
- }
-
- CREATE(HPData, struct HPluginData, 1);
-
- HPData->pluginID = id;
- HPData->type = type;
- HPData->flag.free = autofree ? 1 : 0;
- HPData->data = data;
-
- RECREATE(sd->hdata,struct HPluginData *,++sd->hdatac);
- sd->hdata[sd->hdatac - 1] = HPData;
-}
-void *HPM_map_getFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type) {
- unsigned int i;
-
- for(i = 0; i < sd->hdatac; i++) {
- if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) {
+void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) {
+ /* record address */
+ switch( type ) {
+ case HPDT_MSD:
+ ret->HPDataSRCPtr = (void**)(&((struct map_session_data *)ptr)->hdata);
+ ret->hdatac = &((struct map_session_data *)ptr)->hdatac;
break;
- }
- }
-
- if( i != sd->hdatac )
- return sd->hdata[i]->data;
-
- return NULL;
-}
-void HPM_map_removeFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type) {
- unsigned int i;
-
- for(i = 0; i < sd->hdatac; i++) {
- if( sd->hdata[i]->pluginID == id && sd->hdata[i]->type == type ) {
+ case HPDT_NPCD:
+ ret->HPDataSRCPtr = (void**)(&((struct npc_data *)ptr)->hdata);
+ ret->hdatac = &((struct npc_data *)ptr)->hdatac;
break;
- }
- }
-
- if( i != sd->hdatac ) {
- unsigned int cursor;
-
- aFree(sd->hdata[i]->data);
- aFree(sd->hdata[i]);
- sd->hdata[i] = NULL;
-
- for(i = 0, cursor = 0; i < sd->hdatac; i++) {
- if( sd->hdata[i] == NULL )
- continue;
- if( i != cursor )
- sd->hdata[cursor] = sd->hdata[i];
- cursor++;
- }
-
- sd->hdatac = cursor;
+ default:
+ ret->HPDataSRCPtr = NULL;
+ ret->hdatac = NULL;
+ return;
}
-
}
+
void HPM_map_plugin_load_sub(struct hplugin *plugin) {
- plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx);
- plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx);
- /* */
- plugin->hpi->addToMSD = HPM->import_symbol("addToMSD",plugin->idx);
- plugin->hpi->getFromMSD = HPM->import_symbol("getFromMSD",plugin->idx);
- plugin->hpi->removeFromMSD = HPM->import_symbol("removeFromMSD",plugin->idx);
+ plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx);
+ plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx);
}
bool HPM_map_add_atcommand(char *name, AtCommandFunc func) {
diff --git a/src/map/HPMmap.h b/src/map/HPMmap.h
index 96515772b..f5fe70276 100644
--- a/src/map/HPMmap.h
+++ b/src/map/HPMmap.h
@@ -6,13 +6,12 @@
#include "../common/cbasetypes.h"
#include "../map/atcommand.h"
+#include "../common/HPM.h"
struct hplugin;
struct map_session_data;
-void HPM_map_addToMSD(struct map_session_data *sd, void *data, unsigned int id, unsigned int type, bool autofree);
-void *HPM_map_getFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type);
-void HPM_map_removeFromMSD(struct map_session_data *sd, unsigned int id, unsigned int type);
+void HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr);
bool HPM_map_add_atcommand(char *name, AtCommandFunc func);
void HPM_map_atcommands(void);
diff --git a/src/map/map.c b/src/map/map.c
index 3469a60ce..b846d6125 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5372,9 +5372,6 @@ void map_hp_symbols(void) {
/* specific */
HPM->share(atcommand->create,"addCommand");
HPM->share(script->addScript,"addScript");
- HPM->share(HPM_map_addToMSD,"addToMSD");
- HPM->share(HPM_map_getFromMSD,"getFromMSD");
- HPM->share(HPM_map_removeFromMSD,"removeFromMSD");
/* vars */
HPM->share(map->list,"map->list");
}
@@ -5436,6 +5433,7 @@ int do_init(int argc, char *argv[])
HPM->load_sub = HPM_map_plugin_load_sub;
HPM->symbol_defaults_sub = map_hp_symbols;
+ HPM->grabHPDataSub = HPM_map_grabHPData;
HPM->config_read();
HPM->event(HPET_PRE_INIT);
diff --git a/src/map/npc.c b/src/map/npc.c
index 5ca96d587..effc36a4e 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1763,6 +1763,8 @@ void npc_unload_duplicates(struct npc_data* nd) {
//Removes an npc from map and db.
//Single is to free name (for duplicates).
int npc_unload(struct npc_data* nd, bool single) {
+ unsigned int i;
+
nullpo_ret(nd);
npc->remove_map(nd);
@@ -1850,6 +1852,15 @@ int npc_unload(struct npc_data* nd, bool single) {
nd->ud = NULL;
}
+ for( i = 0; i < nd->hdatac; i++ ) {
+ if( nd->hdata[i]->flag.free ) {
+ aFree(nd->hdata[i]->data);
+ }
+ aFree(nd->hdata[i]);
+ }
+ if( nd->hdata )
+ aFree(nd->hdata);
+
aFree(nd);
return 0;
diff --git a/src/map/npc.h b/src/map/npc.h
index 10f3406b4..33be957fb 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -5,6 +5,8 @@
#ifndef _NPC_H_
#define _NPC_H_
+#include "../common/HPM.h" //struct HPluginData
+
#include "map.h" // struct block_list
#include "status.h" // struct status_change
#include "unit.h" // struct unit_data
@@ -74,10 +76,12 @@ struct npc_data {
char killer_name[NAME_LENGTH];
} tomb;
} u;
+ /* HPData Support for npc_data */
+ struct HPluginData **hdata;
+ unsigned int hdatac;
};
-
#define START_NPC_NUM 110000000
enum actor_classes {
diff --git a/src/map/unit.c b/src/map/unit.c
index eed9fe3be..04af6c117 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2397,8 +2397,8 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
for( k = 0; k < sd->hdatac; k++ ) {
if( sd->hdata[k]->flag.free ) {
aFree(sd->hdata[k]->data);
- aFree(sd->hdata[k]);
}
+ aFree(sd->hdata[k]);
}
if( sd->hdata )
aFree(sd->hdata);