Moved extra junk from map_addblock/map_delblock to where it logically belongs (loadendack/unit_remove_map), removed flags and _sub macros

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12002 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2008-01-03 20:56:20 +00:00
parent ca115ffc82
commit 8f1eaa3d67
5 changed files with 63 additions and 49 deletions

View File

@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2008/01/03 2008/01/03
* Moved extra junk from map_addblock/map_delblock to where it logically
belongs (loadendack/unit_remove_map), removed flags and _sub macros
* Removed map_data's block_count, as (quote Yor/ja2160), * Removed map_data's block_count, as (quote Yor/ja2160),
"Perhaps useful for debug, but uses memory AND CPU for nothing." "Perhaps useful for debug, but uses memory AND CPU for nothing."
(block lists are linked lists, they don't need count tracking) (block lists are linked lists, they don't need count tracking)

View File

@ -7724,6 +7724,9 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
pc_setinvincibletimer(sd,battle_config.pc_invincible_time); pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
} }
if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
map_spawnmobs(sd->bl.m);
map_addblock(&sd->bl); map_addblock(&sd->bl);
clif_spawn(&sd->bl); clif_spawn(&sd->bl);
@ -7768,6 +7771,13 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
// must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange) // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
map_foreachinarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd); map_foreachinarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd);
//TODO: merge it with the code below
if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
{ //Return the pet to egg. [Skotlex]
clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
pet_menu(sd, 3); //Option 3 is return to egg.
}
// pet // pet
if(sd->pd) { if(sd->pd) {
map_addblock(&sd->pd->bl); map_addblock(&sd->pd->bl);

View File

@ -275,11 +275,9 @@ void map_delblcell(struct block_list *bl)
/*========================================== /*==========================================
* Adds a block to the map. * Adds a block to the map.
* If flag is 1, then the block was just added,
* otherwise it is part of a transition.
* Returns 0 on success, 1 on failure (illegal coordinates). * Returns 0 on success, 1 on failure (illegal coordinates).
*------------------------------------------*/ *------------------------------------------*/
int map_addblock_sub (struct block_list *bl, int flag) int map_addblock(struct block_list* bl)
{ {
int m, x, y, pos; int m, x, y, pos;
@ -287,7 +285,7 @@ int map_addblock_sub (struct block_list *bl, int flag)
if (bl->prev != NULL) { if (bl->prev != NULL) {
ShowError("map_addblock: bl->prev != NULL\n"); ShowError("map_addblock: bl->prev != NULL\n");
return 0; return 1;
} }
m = bl->m; m = bl->m;
@ -303,29 +301,15 @@ int map_addblock_sub (struct block_list *bl, int flag)
ShowError("map_addblock: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d\n", map[m].name, x, y, map[m].xs, map[m].ys); ShowError("map_addblock: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d\n", map[m].name, x, y, map[m].xs, map[m].ys);
return 1; return 1;
} }
pos = x/BLOCK_SIZE+(y/BLOCK_SIZE)*map[m].bxs; pos = x/BLOCK_SIZE+(y/BLOCK_SIZE)*map[m].bxs;
if (bl->type == BL_MOB) { if (bl->type == BL_MOB) {
bl->next = map[m].block_mob[pos]; bl->next = map[m].block_mob[pos];
bl->prev = &bl_head; bl->prev = &bl_head;
if (bl->next) bl->next->prev = bl; if (bl->next) bl->next->prev = bl;
map[m].block_mob[pos] = bl; map[m].block_mob[pos] = bl;
} else { } else {
if (bl->type == BL_PC && flag)
{
struct map_session_data* sd = (struct map_session_data*)bl;
if (!sd->state.auth) {
ShowError("map_addblock: Attempted to add a non-authed player (%d:%d)!\n", sd->status.account_id, sd->status.char_id);
return 1;
}
if (map[m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
map_spawnmobs(m);
if (battle_config.pet_no_gvg && map_flag_gvg(m) && sd->pd)
{ //Return the pet to egg. [Skotlex]
clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
pet_menu(sd, 3); //Option 3 is return to egg.
}
}
bl->next = map[m].block[pos]; bl->next = map[m].block[pos];
bl->prev = &bl_head; bl->prev = &bl_head;
if (bl->next) bl->next->prev = bl; if (bl->next) bl->next->prev = bl;
@ -341,12 +325,10 @@ int map_addblock_sub (struct block_list *bl, int flag)
/*========================================== /*==========================================
* Removes a block from the map. * Removes a block from the map.
* If flag is 1, then the block is removed for good
* otherwise it is part of a transition.
*------------------------------------------*/ *------------------------------------------*/
int map_delblock_sub (struct block_list *bl, int flag) int map_delblock(struct block_list* bl)
{ {
int b; int pos;
nullpo_retr(0, bl); nullpo_retr(0, bl);
// ?にblocklistから?けている // ?にblocklistから?けている
@ -362,20 +344,16 @@ int map_delblock_sub (struct block_list *bl, int flag)
map_delblcell(bl); map_delblcell(bl);
#endif #endif
b = bl->x/BLOCK_SIZE+(bl->y/BLOCK_SIZE)*map[bl->m].bxs; pos = bl->x/BLOCK_SIZE+(bl->y/BLOCK_SIZE)*map[bl->m].bxs;
if (bl->type == BL_PC && flag)
if (--map[bl->m].users == 0 && battle_config.dynamic_mobs) //[Skotlex]
map_removemobs(bl->m);
if (bl->next) if (bl->next)
bl->next->prev = bl->prev; bl->next->prev = bl->prev;
if (bl->prev == &bl_head) { if (bl->prev == &bl_head) {
// リストの頭なので、map[]のblock_listを更新する // リストの頭なので、map[]のblock_listを更新する
if (bl->type == BL_MOB) { if (bl->type == BL_MOB) {
map[bl->m].block_mob[b] = bl->next; map[bl->m].block_mob[pos] = bl->next;
} else { } else {
map[bl->m].block[b] = bl->next; map[bl->m].block[pos] = bl->next;
} }
} else { } else {
bl->prev->next = bl->next; bl->prev->next = bl->next;
@ -403,6 +381,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
bl->y = y1; bl->y = y1;
return 0; return 0;
} }
//TODO: Perhaps some outs of bounds checking should be placed here? //TODO: Perhaps some outs of bounds checking should be placed here?
if (bl->type&BL_CHAR) { if (bl->type&BL_CHAR) {
skill_unit_move(bl,tick,2); skill_unit_move(bl,tick,2);
@ -422,18 +401,20 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
status_change_end(bl, SC_MAGICROD, -1); status_change_end(bl, SC_MAGICROD, -1);
} }
} else } else
if (bl->type == BL_NPC) npc_unsetcells((TBL_NPC*)bl); if (bl->type == BL_NPC)
npc_unsetcells((TBL_NPC*)bl);
if (moveblock) map_delblock_sub(bl,0); if (moveblock) map_delblock(bl);
#ifdef CELL_NOSTACK #ifdef CELL_NOSTACK
else map_delblcell(bl); else map_delblcell(bl);
#endif #endif
bl->x = x1; bl->x = x1;
bl->y = y1; bl->y = y1;
if (moveblock) map_addblock_sub(bl,0); if (moveblock) map_addblock(bl);
#ifdef CELL_NOSTACK #ifdef CELL_NOSTACK
else map_addblcell(bl); else map_addblcell(bl);
#endif #endif
if (bl->type&BL_CHAR) { if (bl->type&BL_CHAR) {
skill_unit_move(bl,tick,3); skill_unit_move(bl,tick,3);
if (sc) { if (sc) {
@ -447,7 +428,9 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
} }
} }
} else } else
if (bl->type == BL_NPC) npc_setcells((TBL_NPC*)bl); if (bl->type == BL_NPC)
npc_setcells((TBL_NPC*)bl);
return 0; return 0;
} }

View File

@ -1275,10 +1275,8 @@ int map_freeblock(struct block_list *bl);
int map_freeblock_lock(void); int map_freeblock_lock(void);
int map_freeblock_unlock(void); int map_freeblock_unlock(void);
// blockŠÖ˜A // blockŠÖ˜A
int map_addblock_sub(struct block_list *, int); int map_addblock(struct block_list* bl);
int map_delblock_sub(struct block_list *, int); int map_delblock(struct block_list* bl);
#define map_addblock(bl) map_addblock_sub(bl,1)
#define map_delblock(bl) map_delblock_sub(bl,1)
int map_moveblock(struct block_list *, int, int, unsigned int); int map_moveblock(struct block_list *, int, int, unsigned int);
int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...); int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...);
int map_foreachinshootrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...); int map_foreachinshootrange(int (*func)(struct block_list*,va_list), struct block_list* center, int range, int type, ...);

View File

@ -1652,7 +1652,10 @@ int unit_remove_map(struct block_list *bl, int clrtype)
skill_cleartimerskill(bl); // ƒ^ƒCƒ}<7D>[ƒXƒLƒƒNƒŠƒA skill_cleartimerskill(bl); // ƒ^ƒCƒ}<7D>[ƒXƒLƒƒNƒŠƒA
} }
if(bl->type == BL_PC) { switch( bl->type )
{
case BL_PC:
{
struct map_session_data *sd = (struct map_session_data*)bl; struct map_session_data *sd = (struct map_session_data*)bl;
//Leave/reject all invitations. //Leave/reject all invitations.
@ -1695,28 +1698,41 @@ int unit_remove_map(struct block_list *bl, int clrtype)
} }
party_send_dot_remove(sd);//minimap dot fix [Kevin] party_send_dot_remove(sd);//minimap dot fix [Kevin]
guild_send_dot_remove(sd); guild_send_dot_remove(sd);
} else if(bl->type == BL_MOB) {
if (--map[bl->m].users == 0 && battle_config.dynamic_mobs) //[Skotlex]
map_removemobs(bl->m);
break;
}
case BL_MOB:
{
struct mob_data *md = (struct mob_data*)bl; struct mob_data *md = (struct mob_data*)bl;
md->target_id=0; md->target_id=0;
md->attacked_id=0; md->attacked_id=0;
md->state.skillstate= MSS_IDLE; md->state.skillstate= MSS_IDLE;
} else if (bl->type == BL_PET) {
break;
}
case BL_PET:
{
struct pet_data *pd = (struct pet_data*)bl; struct pet_data *pd = (struct pet_data*)bl;
if(pd->pet.intimate <= 0 && if( pd->pet.intimate <= 0 && !(pd->msd && pd->msd->state.waitingdisconnect) )
!(pd->msd && pd->msd->state.waitingdisconnect) { //If logging out, this is deleted on unit_free
) { //If logging out, this is deleted on unit_free
clif_clearunit_area(bl,clrtype); clif_clearunit_area(bl,clrtype);
map_delblock(bl); map_delblock(bl);
unit_free(bl,0); unit_free(bl,0);
map_freeblock_unlock(); map_freeblock_unlock();
return 0; return 0;
} }
} else if (bl->type == BL_HOM) {
break;
}
case BL_HOM:
{
struct homun_data *hd = (struct homun_data *) bl; struct homun_data *hd = (struct homun_data *) bl;
ud->canact_tick = ud->canmove_tick; //It appears HOM do reset the can-act tick. ud->canact_tick = ud->canmove_tick; //It appears HOM do reset the can-act tick.
if(!hd->homunculus.intimacy && if(!hd->homunculus.intimacy && !(hd->master && hd->master->state.waitingdisconnect) )
!(hd->master && hd->master->state.waitingdisconnect) { //If logging out, this is deleted on unit_free
) { //If logging out, this is deleted on unit_free
clif_emotion(bl, 28) ; //sob clif_emotion(bl, 28) ; //sob
clif_clearunit_area(bl,clrtype); clif_clearunit_area(bl,clrtype);
map_delblock(bl); map_delblock(bl);
@ -1724,7 +1740,12 @@ int unit_remove_map(struct block_list *bl, int clrtype)
map_freeblock_unlock(); map_freeblock_unlock();
return 0; return 0;
} }
break;
} }
default: ;// do nothing
}
clif_clearunit_area(bl,clrtype); clif_clearunit_area(bl,clrtype);
map_delblock(bl); map_delblock(bl);
map_freeblock_unlock(); map_freeblock_unlock();