From b87137d73e40be12dbca7ba5fc6c66f1bc8571de Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Thu, 27 Nov 2014 21:11:19 +0300
Subject: Impliment invisible map flag.

---
 src/map/clif.c    | 38 +++++++++++++++++++++++++++++++++++++-
 src/map/clif.h    |  5 +++++
 src/map/init.c    |  3 +++
 src/map/mapd.c    | 38 ++++++++++++++++++++++++++++++++++++++
 src/map/mapd.h    | 12 ++++++++++++
 src/map/mapdext.h | 12 ++++++++++++
 6 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 src/map/mapd.c
 create mode 100644 src/map/mapd.h
 create mode 100644 src/map/mapdext.h

(limited to 'src')

diff --git a/src/map/clif.c b/src/map/clif.c
index 68edd81..c4766dc 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -17,6 +17,8 @@
 
 #include "map/clif.h"
 #include "map/lang.h"
+#include "map/mapd.h"
+#include "map/mapdext.h"
 #include "map/send.h"
 
 void eclif_quest_send_list(struct map_session_data *sd)
@@ -115,6 +117,9 @@ static void eclif_send_additional_slots(struct map_session_data* sd, struct map_
 
     struct item_data *item;
     short equip;
+    struct MapdExt *data = mapd_get(sd->bl.m);
+    if (data->invisible)
+        return;
 
     equipPos(EQI_HEAD_LOW, LOOK_HEAD_BOTTOM);
     equipPos(EQI_HEAD_TOP, LOOK_HEAD_TOP);
@@ -131,7 +136,6 @@ static void eclif_send_additional_slots(struct map_session_data* sd, struct map_
 
 void eclif_getareachar_unit_post(struct map_session_data* sd, struct block_list *bl)
 {
-    // need replace it to _post
     if (bl->type == BL_PC)
     {
         eclif_send_additional_slots(sd, (struct map_session_data *)bl);
@@ -143,3 +147,35 @@ void eclif_authok_post(struct map_session_data *sd)
 {
     eclif_send_additional_slots(sd, sd);
 }
+
+void eclif_handle_invisible_map(struct block_list *bl, enum send_target target)
+{
+    if (!bl || bl->type != BL_PC)
+        return;
+    struct MapdExt *data = mapd_get(bl->m);
+    if (data->invisible)
+        hookStop();
+}
+
+void eclif_sendlook(struct block_list *bl, int *id, int *type, int *val, int *val2, enum send_target *target)
+{
+    if (*target == SELF)
+        return;
+    eclif_handle_invisible_map(bl, *target);
+}
+
+bool eclif_send(const void* buf, int *len, struct block_list* bl, enum send_target *type)
+{
+    if (*type == SELF)
+        return;
+    eclif_handle_invisible_map(bl, *type);
+    return true;
+}
+
+void eclif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enum send_target *target)
+{
+    if (tsd && bl && bl->id == tsd->bl.id && *target == SELF)
+        return;
+
+    eclif_handle_invisible_map(bl, *target);
+}
diff --git a/src/map/clif.h b/src/map/clif.h
index 190df21..3180919 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -9,5 +9,10 @@ void eclif_quest_add(struct map_session_data *sd, struct quest *qd);
 void eclif_charnameack(int *fdPtr, struct block_list *bl);
 void eclif_getareachar_unit_post(struct map_session_data* sd, struct block_list *bl);
 void eclif_authok_post(struct map_session_data *sd);
+void eclif_sendlook(struct block_list *bl, int *id, int *type,
+                    int *val, int *val2, enum send_target *target);
+bool eclif_send(const void* buf, int *len, struct block_list* bl, enum send_target *type);
+void eclif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd,
+                         enum send_target *target);
 
 #endif  // EVOL_MAP_CLIF
diff --git a/src/map/init.c b/src/map/init.c
index 030e02d..cd0a5ed 100644
--- a/src/map/init.c
+++ b/src/map/init.c
@@ -87,6 +87,9 @@ HPExport void plugin_init (void)
     addHookPre("clif->quest_send_list", eclif_quest_send_list);
     addHookPre("clif->quest_add", eclif_quest_add);
     addHookPre("clif->charnameack", eclif_charnameack);
+    addHookPre("clif->sendlook", eclif_sendlook);
+    addHookPre("clif->send", eclif_send);
+    addHookPre("clif->set_unit_idle", eclif_set_unit_idle);
 
     addHookPost("clif->getareachar_unit", eclif_getareachar_unit_post);
     addHookPost("clif->authok", eclif_authok_post);
diff --git a/src/map/mapd.c b/src/map/mapd.c
new file mode 100644
index 0000000..2783f83
--- /dev/null
+++ b/src/map/mapd.c
@@ -0,0 +1,38 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 Evol developers
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../../common/HPMi.h"
+#include "../../../common/malloc.h"
+#include "../../../common/mmo.h"
+#include "../../../common/socket.h"
+#include "../../../common/strlib.h"
+#include "../../../map/map.h"
+
+#include "map/mapd.h"
+#include "map/mapdext.h"
+
+struct MapdExt *mapd_get(int m)
+{
+    struct map_data *md = &map->list[m];
+    struct MapdExt *data = getFromMAPD(md, 0);
+    if (!data)
+    {
+        data = mapd_create();
+        addToMAPD(md, data, 0, true);
+    }
+    return data;
+}
+
+struct MapdExt *mapd_create(void)
+{
+    struct MapdExt *data = NULL;
+    CREATE(data, struct MapdExt, 1);
+    if (!data)
+        return NULL;
+    data->invisible = false;
+    return data;
+}
diff --git a/src/map/mapd.h b/src/map/mapd.h
new file mode 100644
index 0000000..a0878ae
--- /dev/null
+++ b/src/map/mapd.h
@@ -0,0 +1,12 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 Evol developers
+
+#ifndef EVOL_MAP_MAPD
+#define EVOL_MAP_MAPD
+
+struct MapdExt;
+
+struct MapdExt *mapd_get(int fd);
+struct MapdExt *mapd_create(void);
+
+#endif  // EVOL_MAP_MAPD
diff --git a/src/map/mapdext.h b/src/map/mapdext.h
new file mode 100644
index 0000000..77d56f9
--- /dev/null
+++ b/src/map/mapdext.h
@@ -0,0 +1,12 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 Evol developers
+
+#ifndef EVOL_MAP_MAPDEXT
+#define EVOL_MAP_MAPDEXT
+
+struct MapdExt
+{
+    bool invisible;
+};
+
+#endif  // EVOL_MAP_MAPDEXT
-- 
cgit v1.2.3-70-g09d2