summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-07-19 17:10:09 +0200
committerHaru <haru@dotalux.com>2013-07-21 18:45:31 +0200
commit5f7320cda31036120ab11d9f719b34bf2809cbb4 (patch)
tree273a3ca6ae1c597c7eb70e8da8c6f91e79bf89e9 /src/map/unit.c
parent9bcb1423969870a6b60819e6f3846fe0235e28a9 (diff)
downloadhercules-5f7320cda31036120ab11d9f719b34bf2809cbb4.tar.gz
hercules-5f7320cda31036120ab11d9f719b34bf2809cbb4.tar.bz2
hercules-5f7320cda31036120ab11d9f719b34bf2809cbb4.tar.xz
hercules-5f7320cda31036120ab11d9f719b34bf2809cbb4.zip
Fixed various unit* script commands to work with NPCs (issue #7548)
http://hercules.ws/board/tracker/issue-7548-unitwalk-do-not-work/ Follow-up to 20bdc01. Thanks to Ind for his support and suggestions. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index ce097dda0..4a8a87920 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -44,8 +44,13 @@
const short dirx[8]={0,-1,-1,-1,0,1,1,1};
const short diry[8]={1,1,0,-1,-1,-1,0,1};
-struct unit_data* unit_bl2ud(struct block_list *bl)
-{
+/**
+ * Returns the unit_data for the given block_list. If the object is using
+ * shared unit_data (i.e. in case of BL_NPC), it returns the shared data.
+ * @param bl block_list to process
+ * @return a pointer to the given object's unit_data
+ **/
+struct unit_data* unit_bl2ud(struct block_list *bl) {
if( bl == NULL) return NULL;
if( bl->type == BL_PC) return &((struct map_session_data*)bl)->ud;
if( bl->type == BL_MOB) return &((struct mob_data*)bl)->ud;
@@ -57,6 +62,23 @@ struct unit_data* unit_bl2ud(struct block_list *bl)
return NULL;
}
+/**
+ * Returns the unit_data for the given block_list. If the object is using
+ * shared unit_data (i.e. in case of BL_NPC), it recreates a copy of the
+ * data so that it's safe to modify.
+ * @param bl block_list to process
+ * @return a pointer to the given object's unit_data
+ */
+struct unit_data* unit_bl2ud2(struct block_list *bl) {
+ if( bl && bl->type == BL_NPC && ((struct npc_data*)bl)->ud == &npc_base_ud ) {
+ struct npc_data *nd = (struct npc_data *)bl;
+ nd->ud = NULL;
+ CREATE(nd->ud, struct unit_data, 1);
+ unit_dataset(&nd->bl);
+ }
+ return unit_bl2ud(bl);
+}
+
static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data);
static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);