summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
authorpanikon <panikon@zoho.com>2014-07-08 16:28:46 -0300
committerpanikon <panikon@zoho.com>2014-07-08 16:28:46 -0300
commitd1d99a96485a164f850e09c2fff6d0c30657ea9e (patch)
tree58265553753580a2cfde36c919b8d37262d485f3 /src/map/mob.c
parent36712df4cf1f7fbc1a78eb4a7afee1630fa4c4be (diff)
downloadhercules-d1d99a96485a164f850e09c2fff6d0c30657ea9e.tar.gz
hercules-d1d99a96485a164f850e09c2fff6d0c30657ea9e.tar.bz2
hercules-d1d99a96485a164f850e09c2fff6d0c30657ea9e.tar.xz
hercules-d1d99a96485a164f850e09c2fff6d0c30657ea9e.zip
Removed redundant data from guardian_data, saving up to 40 bytes per guardian (10240 bytes total)
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c93
1 files changed, 40 insertions, 53 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 6bfe3abb9..38ddffa37 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -487,20 +487,17 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const
if (!md)
continue;
- if (class_ == MOBID_EMPERIUM && !no_guardian_data) {
+ if ( class_ == MOBID_EMPERIUM && !no_guardian_data ) {
struct guild_castle* gc = guild->mapindex2gc(map_id2index(m));
struct guild* g = (gc) ? guild->search(gc->guild_id) : NULL;
- if (gc) {
+ if( gc ) {
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->castle = gc;
md->guardian_data->number = MAX_GUARDIANS;
- md->guardian_data->guild_id = gc->guild_id;
- if (g) {
- md->guardian_data->emblem_id = g->emblem_id;
- memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
- }
- else if (gc->guild_id) //Guild not yet available, retry in 5.
- timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
+ if( g )
+ md->guardian_data->g = g;
+ else if( gc->guild_id ) //Guild not yet available, retry in 5.
+ timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
}
} // end addition [Valaris]
@@ -570,21 +567,23 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0
return id; // id of last spawned mob
}
-/*==========================================
- * Set a Guardian's guild data [Skotlex]
- *------------------------------------------*/
+
+/**
+ * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data
+ * @param data (int)guild_id
+ * @retval Always 0
+ * @author Skotlex
+ **/
int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data) {
- //Needed because the guild_data may not be available at guardian spawn time.
+ //Needed because the guild data may not be available at guardian spawn time.
struct block_list* bl = map->id2bl(id);
struct mob_data* md;
struct guild* g;
- int guardup_lv;
- if (bl == NULL) //It is possible mob was already removed from map when the castle has no owner. [Skotlex]
+ if( bl == NULL ) //It is possible mob was already removed from map when the castle has no owner. [Skotlex]
return 0;
- if (bl->type != BL_MOB)
- {
+ if( bl->type != BL_MOB ) {
ShowError("mob_spawn_guardian_sub: Block error!\n");
return 0;
}
@@ -593,30 +592,28 @@ int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data) {
nullpo_ret(md->guardian_data);
g = guild->search((int)data);
- if (g == NULL)
- { //Liberate castle, if the guild is not found this is an error! [Skotlex]
+ if( g == NULL ) { //Liberate castle, if the guild is not found this is an error! [Skotlex]
ShowError("mob_spawn_guardian_sub: Couldn't load guild %d!\n", (int)data);
- if (md->class_ == MOBID_EMPERIUM && md->guardian_data)
- { //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
- md->guardian_data->guild_id = 0;
- if (md->guardian_data->castle->guild_id) //Free castle up.
- {
+ //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
+ if( md->class_ == MOBID_EMPERIUM && md->guardian_data ) {
+ md->guardian_data->g = NULL;
+ if( md->guardian_data->castle->guild_id ) {//Free castle up.
ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
guild->castledatasave(md->guardian_data->castle->castle_id, 1, 0);
}
} else {
- if (md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
+ if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS
+ && md->guardian_data->castle->guardian[md->guardian_data->number].visible )
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- unit->free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
+
+ unit->free(&md->bl,CLR_OUTSIGHT); // Remove guardian.
}
return 0;
}
- guardup_lv = guild->checkskill(g,GD_GUARDUP);
- md->guardian_data->emblem_id = g->emblem_id;
- memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
- md->guardian_data->guardup_lv = guardup_lv;
- if( guardup_lv )
- status_calc_mob(md, SCO_NONE); //Give bonuses.
+
+ if( guild->checkskill(g,GD_GUARDUP) )
+ status_calc_mob(md, SCO_NONE); // Give bonuses.
+
return 0;
}
@@ -692,7 +689,6 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
md = mob->spawn_dataset(&data);
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->number = guardian;
- md->guardian_data->guild_id = gc->guild_id;
md->guardian_data->castle = gc;
if( has_index )
{// permanent guardian
@@ -709,13 +705,10 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
}
gc->temp_guardians[i] = md->bl.id;
}
- if (g)
- {
- md->guardian_data->emblem_id = g->emblem_id;
- memcpy (md->guardian_data->guild_name, g->name, NAME_LENGTH);
- md->guardian_data->guardup_lv = guild->checkskill(g,GD_GUARDUP);
- } else if (md->guardian_data->guild_id)
- timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
+ if( g )
+ md->guardian_data->g = g;
+ else if( gc->guild_id )
+ timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
mob->spawn(md);
return md->bl.id;
@@ -2669,14 +2662,11 @@ int mob_guardian_guildchange(struct mob_data *md)
if (!md->guardian_data)
return 0;
- if (md->guardian_data->castle->guild_id == 0)
+ if( md->guardian_data->castle->guild_id == 0 )
{ //Castle with no owner? Delete the guardians.
- if (md->class_ == MOBID_EMPERIUM)
- { //But don't delete the emperium, just clear it's guild-data
- md->guardian_data->guild_id = 0;
- md->guardian_data->emblem_id = 0;
- md->guardian_data->guild_name[0] = '\0';
- } else {
+ if( md->class_ == MOBID_EMPERIUM ) //But don't delete the emperium, just clear it's guild-data
+ md->guardian_data->g = NULL;
+ else {
if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
unit->free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
@@ -2685,19 +2675,16 @@ int mob_guardian_guildchange(struct mob_data *md)
}
g = guild->search(md->guardian_data->castle->guild_id);
- if (g == NULL)
+ if( g == NULL )
{ //Properly remove guardian info from Castle data.
- ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
+ ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->castle->guild_id);
if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS)
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
unit->free(&md->bl,CLR_OUTSIGHT);
return 0;
}
- md->guardian_data->guild_id = g->guild_id;
- md->guardian_data->emblem_id = g->emblem_id;
- md->guardian_data->guardup_lv = guild->checkskill(g,GD_GUARDUP);
- memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
+ md->guardian_data->g = g;
return 1;
}