From 5f7320cda31036120ab11d9f719b34bf2809cbb4 Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 19 Jul 2013 17:10:09 +0200 Subject: 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 --- src/map/unit.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/map/unit.c') 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); -- cgit v1.2.3-60-g2f50