summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskyleo <skyleo@skyleo.de>2019-12-02 19:58:08 +0100
committerHaru <haru@dotalux.com>2020-03-08 20:59:35 +0100
commit1d17449c0cb809cec8ca16f2ac860f6377bfa305 (patch)
tree590cc4b95caf3f63770a993d7e29383621cc6905
parentddd62450518afd71bd72f914196b6a2eac7e6bd3 (diff)
downloadhercules-1d17449c0cb809cec8ca16f2ac860f6377bfa305.tar.gz
hercules-1d17449c0cb809cec8ca16f2ac860f6377bfa305.tar.bz2
hercules-1d17449c0cb809cec8ca16f2ac860f6377bfa305.tar.xz
hercules-1d17449c0cb809cec8ca16f2ac860f6377bfa305.zip
Add unit->cbl2ud for when using const block_list
-rw-r--r--src/map/unit.c33
-rw-r--r--src/map/unit.h1
2 files changed, 34 insertions, 0 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index 418bbe4b0..acf64e820 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -100,6 +100,38 @@ static struct unit_data *unit_bl2ud(struct block_list *bl)
}
/**
+ * Returns the const unit_data for the given const block_list. If the object is using
+ * shared unit_data (i.e. in case of BL_NPC), it returns the shared data.
+ *
+ * __Warning:__ if bl->type is not known or NULL,
+ * an assertion will be triggered and NULL returned.
+ * @param bl block_list to process, it is expected to be not NULL.
+ * @return a pointer to the given object's unit_data
+ **/
+static const struct unit_data *unit_cbl2ud(const struct block_list *bl)
+{
+ Assert_retr(NULL, bl != NULL);
+ switch (bl->type) {
+ case BL_PC:
+ return &BL_UCCAST(BL_PC, bl)->ud;
+ case BL_MOB:
+ return &BL_UCCAST(BL_MOB, bl)->ud;
+ case BL_PET:
+ return &BL_UCCAST(BL_PET, bl)->ud;
+ case BL_NPC:
+ return BL_UCCAST(BL_NPC, bl)->ud;
+ case BL_HOM:
+ return &BL_UCCAST(BL_HOM, bl)->ud;
+ case BL_MER:
+ return &BL_UCCAST(BL_MER, bl)->ud;
+ case BL_ELEM:
+ return &BL_UCCAST(BL_ELEM, bl)->ud;
+ default:
+ Assert_retr(NULL, false);
+ }
+}
+
+/**
* 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.
@@ -3054,6 +3086,7 @@ void unit_defaults(void)
unit->final = do_final_unit;
/* */
unit->bl2ud = unit_bl2ud;
+ unit->cbl2ud = unit_cbl2ud;
unit->bl2ud2 = unit_bl2ud2;
unit->init_ud = unit_init_ud;
unit->attack_timer = unit_attack_timer;
diff --git a/src/map/unit.h b/src/map/unit.h
index 57f04b57a..7bf94d3e1 100644
--- a/src/map/unit.h
+++ b/src/map/unit.h
@@ -103,6 +103,7 @@ struct unit_interface {
int (*final) (void);
/* */
struct unit_data* (*bl2ud) (struct block_list *bl);
+ const struct unit_data* (*cbl2ud) (const struct block_list *bl);
struct unit_data* (*bl2ud2) (struct block_list *bl);
void (*init_ud) (struct unit_data *ud);
int (*attack_timer) (int tid, int64 tick, int id, intptr_t data);