summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-17 16:56:04 -0300
committershennetsind <ind@henn.et>2013-09-17 16:56:04 -0300
commit78c7c6bf04a6c96d92524ae37ad165e65f599eb8 (patch)
treefc7d3a562c6c47b4f8836c984b5aef1c70b64d7c /src/map
parent2884b361c247a66c91188cfeb924e1794d58da55 (diff)
downloadhercules-78c7c6bf04a6c96d92524ae37ad165e65f599eb8.tar.gz
hercules-78c7c6bf04a6c96d92524ae37ad165e65f599eb8.tar.bz2
hercules-78c7c6bf04a6c96d92524ae37ad165e65f599eb8.tar.xz
hercules-78c7c6bf04a6c96d92524ae37ad165e65f599eb8.zip
HPM: npc_chat.c Interfaced
Fully Integrated, closes #117 Also updated buildin_ functions to match latest script.c/.h macros. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/map.c7
-rw-r--r--src/map/npc.c2
-rw-r--r--src/map/npc.h60
-rw-r--r--src/map/npc_chat.c117
5 files changed, 108 insertions, 80 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index f55dcdf08..c61630bb5 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10000,7 +10000,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
WFIFOSET(fd, WFIFOW(fd,2));
#ifdef PCRE_SUPPORT
// trigger listening npcs
- iMap->foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
+ iMap->foreachinrange(npc_chat->sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
#endif
// Chat logging type 'O' / Global Chat
diff --git a/src/map/map.c b/src/map/map.c
index a1c78f35b..d4568766a 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5175,7 +5175,9 @@ void map_hp_symbols(void) {
HPM->share(pet,"pet");
HPM->share(path,"path");
HPM->share(quest,"quest");
-
+#ifdef PCRE_SUPPORT
+ HPM->share(npc_chat,"npc_chat");
+#endif
/* partial */
HPM->share(mapit,"mapit");
/* sql link */
@@ -5226,6 +5228,9 @@ void map_load_defaults(void) {
pet_defaults();
path_defaults();
quest_defaults();
+#ifdef PCRE_SUPPORT
+ npc_chat_defaults();
+#endif
}
int do_init(int argc, char *argv[])
{
diff --git a/src/map/npc.c b/src/map/npc.c
index 13a625f07..51d01d711 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1794,7 +1794,7 @@ int npc_unload(struct npc_data* nd, bool single) {
chat->deletenpcchat(nd);
#ifdef PCRE_SUPPORT
- npc_chat_finalize(nd); // deallocate npc PCRE data structures
+ npc_chat->finalize(nd); // deallocate npc PCRE data structures
#endif
if( single && nd->path ) {
diff --git a/src/map/npc.h b/src/map/npc.h
index 0fc773dfc..6c1ca0972 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -98,10 +98,6 @@ enum actor_classes {
//Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001)
#define npcdb_checkid(id) ( ( (id) >= 46 && (id) <= 125) || (id) == HIDDEN_WARP_CLASS || ( (id) > 400 && (id) < MAX_NPC_CLASS ) || (id) == INVISIBLE_CLASS || ( (id) > MAX_NPC_CLASS2_START && (id) < MAX_NPC_CLASS2_END ) )
-#ifdef PCRE_SUPPORT
-void npc_chat_finalize(struct npc_data* nd);
-#endif
-
//Script NPC events.
enum npce_event {
NPCE_LOGIN,
@@ -131,10 +127,6 @@ struct npc_path_data {
unsigned short references;
};
-/* comes from npc_chat.c */
-int npc_chat_sub (struct block_list* bl, va_list ap);
-
-
/* npc.c interface */
struct npc_interface {
/* */
@@ -246,4 +238,56 @@ struct npc_interface *npc;
void npc_defaults(void);
+
+/* comes from npc_chat.c */
+#ifdef PCRE_SUPPORT
+#include "../../3rdparty/pcre/include/pcre.h"
+/* Structure containing all info associated with a single pattern block */
+struct pcrematch_entry {
+ struct pcrematch_entry* next;
+ char* pattern;
+ pcre* pcre_;
+ pcre_extra* pcre_extra_;
+ char* label;
+};
+
+/* A set of patterns that can be activated and deactived with a single command */
+struct pcrematch_set {
+ struct pcrematch_set* prev;
+ struct pcrematch_set* next;
+ struct pcrematch_entry* head;
+ int setid;
+};
+
+/*
+ * Entire data structure hung off a NPC
+ *
+ * The reason I have done it this way (a void * in npc_data and then
+ * this) was to reduce the number of patches that needed to be applied
+ * to a ragnarok distribution to bring this code online. I
+ * also wanted people to be able to grab this one file to get updates
+ * without having to do a large number of changes.
+ */
+struct npc_parse {
+ struct pcrematch_set* active;
+ struct pcrematch_set* inactive;
+};
+
+struct npc_chat_interface {
+ int (*sub) (struct block_list* bl, va_list ap);
+ void (*finalize) (struct npc_data* nd);
+ void (*def_pattern) (struct npc_data* nd, int setid, const char* pattern, const char* label);
+ struct pcrematch_entry* (*create_pcrematch_entry) (struct pcrematch_set* set);
+ void (*delete_pcreset) (struct npc_data* nd, int setid);
+ void (*deactivate_pcreset) (struct npc_data* nd, int setid);
+ void (*activate_pcreset) (struct npc_data* nd, int setid);
+ struct pcrematch_set* (*lookup_pcreset) (struct npc_data* nd, int setid);
+ void (*finalize_pcrematch_entry) (struct pcrematch_entry* e);
+};
+
+struct npc_chat_interface *npc_chat;
+
+void npc_chat_defaults(void);
+#endif
+
#endif /* _NPC_H_ */
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c
index f6459e1ae..848347888 100644
--- a/src/map/npc_chat.c
+++ b/src/map/npc_chat.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <stdarg.h>
+struct npc_chat_interface npc_chat_s;
/**
* Written by MouseJstr in a vision... (2/21/2005)
@@ -70,37 +71,6 @@
* deletes a pset
*/
-/* Structure containing all info associated with a single pattern block */
-struct pcrematch_entry {
- struct pcrematch_entry* next;
- char* pattern;
- pcre* pcre_;
- pcre_extra* pcre_extra_;
- char* label;
-};
-
-/* A set of patterns that can be activated and deactived with a single command */
-struct pcrematch_set {
- struct pcrematch_set* prev;
- struct pcrematch_set* next;
- struct pcrematch_entry* head;
- int setid;
-};
-
-/*
- * Entire data structure hung off a NPC
- *
- * The reason I have done it this way (a void * in npc_data and then
- * this) was to reduce the number of patches that needed to be applied
- * to a ragnarok distribution to bring this code online. I
- * also wanted people to be able to grab this one file to get updates
- * without having to do a large number of changes.
- */
-struct npc_parse {
- struct pcrematch_set* active;
- struct pcrematch_set* inactive;
-};
-
/**
* delete everythign associated with a entry
@@ -118,7 +88,7 @@ void finalize_pcrematch_entry(struct pcrematch_entry* e)
/**
* Lookup (and possibly create) a new set of patterns by the set id
*/
-static struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
+struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -159,7 +129,7 @@ static struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
*
* if the setid does not exist, this will silently return
*/
-static void activate_pcreset(struct npc_data* nd, int setid)
+void activate_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -192,7 +162,7 @@ static void activate_pcreset(struct npc_data* nd, int setid)
*
* if the setid does not exist, this will silently return
*/
-static void deactivate_pcreset(struct npc_data* nd, int setid)
+void deactivate_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -200,7 +170,7 @@ static void deactivate_pcreset(struct npc_data* nd, int setid)
return; // Nothing to deactivate...
if (setid == -1) {
while(npcParse->active != NULL)
- deactivate_pcreset(nd, npcParse->active->setid);
+ npc_chat->deactivate_pcreset(nd, npcParse->active->setid);
return;
}
pcreset = npcParse->active;
@@ -228,7 +198,7 @@ static void deactivate_pcreset(struct npc_data* nd, int setid)
/**
* delete a set of patterns.
*/
-static void delete_pcreset(struct npc_data* nd, int setid)
+void delete_pcreset(struct npc_data* nd, int setid)
{
int active = 1;
struct pcrematch_set *pcreset;
@@ -268,7 +238,7 @@ static void delete_pcreset(struct npc_data* nd, int setid)
while (pcreset->head) {
struct pcrematch_entry* n = pcreset->head->next;
- finalize_pcrematch_entry(pcreset->head);
+ npc_chat->finalize_pcrematch_entry(pcreset->head);
aFree(pcreset->head); // Cleanin' the last ones.. [Lance]
pcreset->head = n;
}
@@ -279,7 +249,7 @@ static void delete_pcreset(struct npc_data* nd, int setid)
/**
* create a new pattern entry
*/
-static struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set)
+struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set)
{
struct pcrematch_entry * e = (struct pcrematch_entry *) aCalloc(sizeof(struct pcrematch_entry), 1);
struct pcrematch_entry * last = set->head;
@@ -313,8 +283,8 @@ void npc_chat_def_pattern(struct npc_data* nd, int setid, const char* pattern, c
const char *err;
int erroff;
- struct pcrematch_set * s = lookup_pcreset(nd, setid);
- struct pcrematch_entry *e = create_pcrematch_entry(s);
+ struct pcrematch_set * s = npc_chat->lookup_pcreset(nd, setid);
+ struct pcrematch_entry *e = npc_chat->create_pcrematch_entry(s);
e->pattern = aStrdup(pattern);
e->label = aStrdup(label);
e->pcre_ = pcre_compile(pattern, PCRE_CASELESS, &err, &erroff, NULL);
@@ -334,10 +304,10 @@ void npc_chat_finalize(struct npc_data* nd)
return;
while(npcParse->active)
- delete_pcreset(nd, npcParse->active->setid);
+ npc_chat->delete_pcreset(nd, npcParse->active->setid);
while(npcParse->inactive)
- delete_pcreset(nd, npcParse->inactive->setid);
+ npc_chat->delete_pcreset(nd, npcParse->inactive->setid);
// Additional cleaning up [Lance]
aFree(npcParse);
@@ -390,7 +360,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
lst = nd->u.scr.label_list;
ARR_FIND(0, nd->u.scr.label_list_num, i, strncmp(lst[i].name, e->label, sizeof(lst[i].name)) == 0);
if (i == nd->u.scr.label_list_num) {
- ShowWarning("Unable to find label: %s\n", e->label);
+ ShowWarning("npc_chat_sub: Unable to find label: %s\n", e->label);
return 0;
}
@@ -405,47 +375,56 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
}
// Various script builtins used to support these functions
-
-int buildin_defpattern(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
- const char* pattern = script->conv_str(st,& (st->stack->stack_data[st->start+3]));
- const char* label = script->conv_str(st,& (st->stack->stack_data[st->start+4]));
+BUILDIN(defpattern) {
+ int setid = script_getnum(st,2);
+ const char* pattern = script_getstr(st,3);
+ const char* label = script_getstr(st,4);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- npc_chat_def_pattern(nd, setid, pattern, label);
-
- return 1;
+ npc_chat->def_pattern(nd, setid, pattern, label);
+
+ return true;
}
-int buildin_activatepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(activatepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- activate_pcreset(nd, setid);
-
- return 1;
+ npc_chat->activate_pcreset(nd, setid);
+
+ return true;
}
-int buildin_deactivatepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(deactivatepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- deactivate_pcreset(nd, setid);
+ npc_chat->deactivate_pcreset(nd, setid);
- return 1;
+ return true;
}
-int buildin_deletepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(deletepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- delete_pcreset(nd, setid);
-
- return 1;
+ npc_chat->delete_pcreset(nd, setid);
+
+ return true;
+}
+
+void npc_chat_defaults(void) {
+ npc_chat = &npc_chat_s;
+
+ npc_chat->sub = npc_chat_sub;
+ npc_chat->finalize = npc_chat_finalize;
+ npc_chat->def_pattern = npc_chat_def_pattern;
+ npc_chat->create_pcrematch_entry = create_pcrematch_entry;
+ npc_chat->delete_pcreset = delete_pcreset;
+ npc_chat->deactivate_pcreset = deactivate_pcreset;
+ npc_chat->activate_pcreset = activate_pcreset;
+ npc_chat->lookup_pcreset = lookup_pcreset;
+ npc_chat->finalize_pcrematch_entry = finalize_pcrematch_entry;
}
#endif //PCRE_SUPPORT