|
@@ -336,9 +336,49 @@ int mobdb_checkid(const int id)
|
|
|
struct view_data * mob_get_viewdata(int mob_id)
|
|
|
{
|
|
|
if (mob_db(mob_id) == mob_dummy)
|
|
|
- return 0;
|
|
|
+ return NULL;
|
|
|
return &mob_db(mob_id)->vd;
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Create unique view data associated to a spawned monster.
|
|
|
+ * @param md: Mob to adjust
|
|
|
+ */
|
|
|
+void mob_set_dynamic_viewdata( struct mob_data* md ){
|
|
|
+ // If it is a valid monster and it has not already been created
|
|
|
+ if( md && !md->vd_changed ){
|
|
|
+ // Allocate a dynamic entry
|
|
|
+ struct view_data* vd = (struct view_data*)aMalloc( sizeof( struct view_data ) );
|
|
|
+
|
|
|
+ // Copy the current values
|
|
|
+ memcpy( vd, md->vd, sizeof( struct view_data ) );
|
|
|
+
|
|
|
+ // Update the pointer to the new entry
|
|
|
+ md->vd = vd;
|
|
|
+
|
|
|
+ // Flag it as changed so it is freed later on
|
|
|
+ md->vd_changed = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Free any view data associated to a spawned monster.
|
|
|
+ * @param md: Mob to free
|
|
|
+ */
|
|
|
+void mob_free_dynamic_viewdata( struct mob_data* md ){
|
|
|
+ // If it is a valid monster and it has already been allocated
|
|
|
+ if( md && md->vd_changed ){
|
|
|
+ // Free it
|
|
|
+ aFree( md->vd );
|
|
|
+
|
|
|
+ // Remove the reference
|
|
|
+ md->vd = NULL;
|
|
|
+
|
|
|
+ // Unflag it as changed
|
|
|
+ md->vd_changed = false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/*==========================================
|
|
|
* Cleans up mob-spawn data to make it "valid"
|
|
|
*------------------------------------------*/
|
|
@@ -5189,6 +5229,9 @@ static void mob_load(void)
|
|
|
mob_skill_db_set();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Initialize monster data
|
|
|
+ */
|
|
|
void mob_db_load(void){
|
|
|
memset(mob_db_data,0,sizeof(mob_db_data)); //Clear the array
|
|
|
mob_db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db)); //This mob is used for random spawns
|
|
@@ -5201,11 +5244,42 @@ void mob_db_load(void){
|
|
|
mob_load();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Apply the proper view data on monsters during mob_db reload.
|
|
|
+ * @param md: Mob to adjust
|
|
|
+ * @param args: va_list of arguments
|
|
|
+ * @return 0
|
|
|
+ */
|
|
|
+static int mob_reload_sub( struct mob_data *md, va_list args ){
|
|
|
+ if( md->bl.prev == NULL ){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // If the view data was not overwritten manually
|
|
|
+ if( !md->vd_changed ){
|
|
|
+ // Get the new view data from the mob database
|
|
|
+ md->vd = mob_get_viewdata(md->mob_id);
|
|
|
+
|
|
|
+ // Respawn all mobs on client side so that they are displayed correctly(if their view id changed)
|
|
|
+ clif_clearunit_area(&md->bl, CLR_OUTSIGHT);
|
|
|
+ clif_spawn(&md->bl);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Reload monster data
|
|
|
+ */
|
|
|
void mob_reload(void) {
|
|
|
do_final_mob();
|
|
|
mob_db_load();
|
|
|
+ map_foreachmob(mob_reload_sub);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Clear spawn data for all monsters
|
|
|
+ */
|
|
|
void mob_clear_spawninfo()
|
|
|
{ //Clears spawn related information for a script reload.
|
|
|
int i;
|