diff options
author | panikon <panikon@zoho.com> | 2014-07-08 16:28:46 -0300 |
---|---|---|
committer | panikon <panikon@zoho.com> | 2014-07-08 16:28:46 -0300 |
commit | d1d99a96485a164f850e09c2fff6d0c30657ea9e (patch) | |
tree | 58265553753580a2cfde36c919b8d37262d485f3 /src | |
parent | 36712df4cf1f7fbc1a78eb4a7afee1630fa4c4be (diff) | |
download | hercules-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')
-rw-r--r-- | src/map/battle.c | 6 | ||||
-rw-r--r-- | src/map/clif.c | 4 | ||||
-rw-r--r-- | src/map/guild.c | 4 | ||||
-rw-r--r-- | src/map/guild.h | 12 | ||||
-rw-r--r-- | src/map/mob.c | 93 | ||||
-rw-r--r-- | src/map/status.c | 29 |
6 files changed, 72 insertions, 76 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index 6d1a98b54..e40d44549 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6149,7 +6149,8 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f { struct mob_data *md = BL_CAST(BL_MOB, t_bl); - if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id ) + if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) + && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) return 0; // Disable guardians/emperiums owned by Guilds on non-woe times. break; } @@ -6209,7 +6210,8 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f case BL_MOB: { struct mob_data *md = BL_CAST(BL_MOB, s_bl); - if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id ) + if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) + && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) return 0; // Disable guardians/emperium owned by Guilds on non-woe times. if( !md->special_state.ai ) diff --git a/src/map/clif.c b/src/map/clif.c index d8714dda0..bc3e0ce9f 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8602,11 +8602,11 @@ void clif_charnameack (int fd, struct block_list *bl) nullpo_retv(md); memcpy(WBUFP(buf,6), md->name, NAME_LENGTH); - if( md->guardian_data && md->guardian_data->guild_id ) + if( md->guardian_data && md->guardian_data->g ) { WBUFW(buf, 0) = cmd = 0x195; WBUFB(buf,30) = 0; - memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH); + memcpy(WBUFP(buf,54), md->guardian_data->g->name, NAME_LENGTH); memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH); } else if( battle_config.show_mob_info ) diff --git a/src/map/guild.c b/src/map/guild.c index 209f29103..642c8993c 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -1213,7 +1213,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) TBL_MOB* md = (gc->guardian[i].id ? map->id2md(gc->guardian[i].id) : NULL); if( md == NULL || md->guardian_data == NULL ) continue; - md->guardian_data->emblem_id = emblem_id; + clif->guild_emblem_area(&md->bl); } // update temporary guardians @@ -1221,7 +1221,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) TBL_MOB* md = (gc->temp_guardians[i] ? map->id2md(gc->temp_guardians[i]) : NULL); if( md == NULL || md->guardian_data == NULL ) continue; - md->guardian_data->emblem_id = emblem_id; + clif->guild_emblem_area(&md->bl); } } diff --git a/src/map/guild.h b/src/map/guild.h index 34e27a56c..f9d97241d 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -24,13 +24,15 @@ struct eventlist { char name[EVENT_NAME_LENGTH]; struct eventlist *next; }; -//For quick linking to a guardian's info. [Skotlex] + +/** + * Guardian data + * For quick linking to a guardian's info. [Skotlex] + **/ struct guardian_data { int number; //0-MAX_GUARDIANS-1 = Guardians. MAX_GUARDIANS = Emperium. - int guild_id; - int emblem_id; - int guardup_lv; //Level of GD_GUARDUP skill. - char guild_name[NAME_LENGTH]; + + struct guild *g; struct guild_castle* castle; }; struct guild_expcache { 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; } diff --git a/src/map/status.c b/src/map/status.c index 54a3208d2..d108d8cfa 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2068,6 +2068,7 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { struct status_data *mstatus; struct block_list *mbl = NULL; int flag=0; + int guardup_lv = 0; if(opt&SCO_FIRST) { //Set basic level on respawn. if (md->level > 0 && md->level <= MAX_LEVEL && md->level != md->db->lv) @@ -2083,7 +2084,8 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { if (md->special_state.size) flag|=2; - if (md->guardian_data && md->guardian_data->guardup_lv) + if( md->guardian_data && md->guardian_data->g + && (guardup_lv = guild->checkskill(md->guardian_data->g,GD_GUARDUP)) ) flag|=4; if (battle_config.slaves_inherit_speed && md->master_id) @@ -2218,10 +2220,10 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { mstatus->mdef += (gc->defense+2)/3; } if(md->class_ != MOBID_EMPERIUM) { - mstatus->batk += mstatus->batk * 10*md->guardian_data->guardup_lv/100; - mstatus->rhw.atk += mstatus->rhw.atk * 10*md->guardian_data->guardup_lv/100; - mstatus->rhw.atk2 += mstatus->rhw.atk2 * 10*md->guardian_data->guardup_lv/100; - mstatus->aspd_rate -= 100*md->guardian_data->guardup_lv; + mstatus->batk += mstatus->batk * 10*guardup_lv/100; + mstatus->rhw.atk += mstatus->rhw.atk * 10*guardup_lv/100; + mstatus->rhw.atk2 += mstatus->rhw.atk2 * 10*guardup_lv/100; + mstatus->aspd_rate -= 100*guardup_lv; } } @@ -5980,15 +5982,18 @@ int status_get_guild_id(struct block_list *bl) { if (((TBL_PET*)bl)->msd) return ((TBL_PET*)bl)->msd->status.guild_id; break; - case BL_MOB: { + case BL_MOB: + { struct map_session_data *msd; struct mob_data *md = (struct mob_data *)bl; - if (md->guardian_data) //Guardian's guild [Skotlex] - return md->guardian_data->guild_id; - if (md->special_state.ai && (msd = map->id2sd(md->master_id)) != NULL) + if( md->guardian_data ) { //Guardian's guild [Skotlex] + // Guardian guild data may not been available yet, castle data is always set + return (md->guardian_data->g)?md->guardian_data->g->guild_id:md->guardian_data->castle->guild_id; + } + if( md->special_state.ai && (msd = map->id2sd(md->master_id)) != NULL ) return msd->status.guild_id; //Alchemist's mobs [Skotlex] - } - break; + break; + } case BL_HOM: if (((TBL_HOM*)bl)->master) return ((TBL_HOM*)bl)->master->status.guild_id; @@ -6024,7 +6029,7 @@ int status_get_emblem_id(struct block_list *bl) { struct map_session_data *msd; struct mob_data *md = (struct mob_data *)bl; if (md->guardian_data) //Guardian's guild [Skotlex] - return md->guardian_data->emblem_id; + return (md->guardian_data->g) ? md->guardian_data->g->emblem_id:0; if (md->special_state.ai && (msd = map->id2sd(md->master_id)) != NULL) return msd->guild_emblem_id; //Alchemist's mobs [Skotlex] } |