diff options
author | Kenpachi Developer <Kenpachi.Developer@gmx.de> | 2020-01-03 11:41:40 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2020-02-09 20:21:40 +0100 |
commit | e9914cef348c2388a2f9d8b02c9d8a8ff7a75ab5 (patch) | |
tree | 97d6b775c618d3e121b70384a4da8e557e799110 /src/map/mob.c | |
parent | d9f5cbfc29206990189ee3b691a00a1d86470662 (diff) | |
download | hercules-e9914cef348c2388a2f9d8b02c9d8a8ff7a75ab5.tar.gz hercules-e9914cef348c2388a2f9d8b02c9d8a8ff7a75ab5.tar.bz2 hercules-e9914cef348c2388a2f9d8b02c9d8a8ff7a75ab5.tar.xz hercules-e9914cef348c2388a2f9d8b02c9d8a8ff7a75ab5.zip |
Applied code style and some minor improvements.
* Added new message 1517 (Script could not be unloaded.)
* Applied code style to several functions I touched.
* Added some minor improments to the function where I applied code style.
Diffstat (limited to 'src/map/mob.c')
-rw-r--r-- | src/map/mob.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index 8495dfa06..d65108a62 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -342,10 +342,12 @@ static int mob_parse_dataset(struct spawn_data *data) *------------------------------------------*/ static struct mob_data *mob_spawn_dataset(struct spawn_data *data, int npc_id) { - struct mob_data *md = NULL; nullpo_retr(NULL, data); - CREATE(md, struct mob_data, 1); - md->bl.id= npc->get_new_npc_id(); + + struct mob_data *md = (struct mob_data *)aCalloc(1, sizeof(struct mob_data)); + + memcpy(md->name, data->name, NAME_LENGTH); + md->bl.id = npc->get_new_npc_id(); md->bl.type = BL_MOB; md->bl.m = data->m; md->bl.x = data->x; @@ -353,25 +355,29 @@ static struct mob_data *mob_spawn_dataset(struct spawn_data *data, int npc_id) md->class_ = data->class_; md->state.boss = data->state.boss; md->db = mob->db(md->class_); + md->npc_id = npc_id; + md->spawn_timer = INVALID_TIMER; + md->deletetimer = INVALID_TIMER; + md->skill_idx = -1; + if (data->level > 0 && data->level <= MAX_LEVEL) md->level = data->level; - memcpy(md->name, data->name, NAME_LENGTH); - if (data->state.ai) + + if (data->state.ai > 0) md->special_state.ai = data->state.ai; - if (data->state.size) + + if (data->state.size > 0) md->special_state.size = data->state.size; - if (data->eventname[0] && strlen(data->eventname) >= 4) + + if (data->eventname[0] != '\0' && strlen(data->eventname) >= 4) memcpy(md->npc_event, data->eventname, 50); - if(md->db->status.mode&MD_LOOTER) - md->lootitem = (struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item)); - md->npc_id = npc_id; - md->spawn_timer = INVALID_TIMER; - md->deletetimer = INVALID_TIMER; - md->skill_idx = -1; + + if ((md->db->status.mode & MD_LOOTER) == MD_LOOTER) + md->lootitem = (struct item *)aCalloc(LOOTITEM_SIZE, sizeof(struct item)); + status->set_viewdata(&md->bl, md->class_); status->change_init(&md->bl); unit->dataset(&md->bl); - map->addiddb(&md->bl); return md; } @@ -522,21 +528,21 @@ static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 else strcpy(data.name, DEFAULT_MOB_JNAME); - if (event) + if (event != NULL) safestrncpy(data.eventname, event, sizeof(data.eventname)); - // Locate spot next to player. - if (bl && (x < 0 || y < 0)) + /** Locate spot next to player. */ + if (bl != NULL && (x < 0 || y < 0)) map->search_freecell(bl, m, &x, &y, 1, 1, 0); - // if none found, pick random position on map + /** If none found, pick random position on map. */ if (x <= 0 || x >= map->list[m].xs || y <= 0 || y >= map->list[m].ys) map->search_freecell(NULL, m, &x, &y, -1, -1, 1); data.x = x; data.y = y; - if (!mob->parse_dataset(&data)) + if (mob->parse_dataset(&data) == 0) return NULL; return mob->spawn_dataset(&data, npc_id); |