浏览代码

Small unit_stop_attack and unit_stop_walking cleanup (#8957)

Lemongrass3110 3 月之前
父节点
当前提交
e2ca330993

+ 1 - 1
src/map/atcommand.cpp

@@ -5918,7 +5918,7 @@ ACMD_FUNC(killer)
 		clif_displaymessage(fd, msg_txt(sd,241)); // You can now attack and kill players freely.
 	else {
 		clif_displaymessage(fd, msg_txt(sd,292)); // Killer state reset.
-		pc_stop_attack(sd);
+		unit_stop_attack( &sd->bl );
 	}
 	return 0;
 }

+ 3 - 3
src/map/chat.cpp

@@ -96,7 +96,7 @@ int32 chat_createpcchat(map_session_data* sd, const char* title, const char* pas
 		return 0;
 	}
 
-	pc_stop_walking(sd,1);
+	unit_stop_walking( &sd->bl, USW_FIXPOS );
 
 	cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL);
 
@@ -104,7 +104,7 @@ int32 chat_createpcchat(map_session_data* sd, const char* title, const char* pas
 		cd->users = 1;
 		cd->usersd[0] = sd;
 		pc_setchatid(sd,cd->bl.id);
-		pc_stop_attack(sd);
+		unit_stop_attack( &sd->bl );
 		clif_createchat( *sd, CREATEROOM_SUCCESS );
 		clif_dispchat(*cd);
 
@@ -162,7 +162,7 @@ int32 chat_joinchat(map_session_data* sd, int32 chatid, const char* pass)
 		return 0;
 	}
 
-	pc_stop_walking(sd,1);
+	unit_stop_walking( &sd->bl, USW_FIXPOS );
 	cd->usersd[cd->users] = sd;
 	cd->users++;
 

+ 6 - 4
src/map/clif.cpp

@@ -11637,9 +11637,11 @@ void clif_parse_ActionRequest_sub( map_session_data& sd, uint8 action_type, int3
 	if (action_type != DMG_NORMAL && action_type != DMG_REPEAT) {
 		if (sd.sc.cant.interact)
 			return;
-		pc_stop_walking(&sd, 1);
+
+		unit_stop_walking( &sd.bl, USW_FIXPOS );
 	}
-	pc_stop_attack(&sd);
+
+	unit_stop_attack( &sd.bl );
 
 	if(target_id<0 && -target_id == sd.bl.id) // for disguises [Valaris]
 		target_id = sd.bl.id;
@@ -12511,8 +12513,8 @@ void clif_parse_TradeCommit(int32 fd,map_session_data *sd)
 /// 0118
 void clif_parse_StopAttack(int32 fd,map_session_data *sd)
 {
-	pc_stop_attack(sd);
-	if (sd) sd->ud.state.attack_continue = 0;
+	unit_stop_attack( &sd->bl );
+	sd->ud.state.attack_continue = 0;
 }
 
 

+ 3 - 2
src/map/elemental.cpp

@@ -455,8 +455,9 @@ int32 elemental_unlocktarget(s_elemental_data *ed) {
 	nullpo_ret(ed);
 
 	ed->target_id = 0;
-	elemental_stop_attack(ed);
-	elemental_stop_walking(ed,1);
+	unit_stop_attack( &ed->bl );
+	unit_stop_walking( &ed->bl, USW_FIXPOS );
+
 	return 0;
 }
 

+ 0 - 3
src/map/elemental.hpp

@@ -129,9 +129,6 @@ int32 elemental_clean_effect(s_elemental_data *ed);
 int32 elemental_action(s_elemental_data *ed, block_list *bl, t_tick tick);
 struct s_skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16 skill_lv);
 
-#define elemental_stop_walking(ed, type) unit_stop_walking(&(ed)->bl, type)
-#define elemental_stop_attack(ed) unit_stop_attack(&(ed)->bl)
-
 void do_init_elemental(void);
 void do_final_elemental(void);
 

+ 0 - 2
src/map/homunculus.hpp

@@ -230,8 +230,6 @@ int32 hom_food(map_session_data *sd, struct homun_data *hd);
 int32 hom_hungry_timer_delete(struct homun_data *hd);
 int32 hom_change_name(map_session_data *sd,char *name);
 void hom_change_name_ack(map_session_data *sd, char* name, int32 flag);
-#define hom_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type)
-#define hom_stop_attack(hd) unit_stop_attack(&(hd)->bl)
 int32 hom_increase_intimacy(struct homun_data * hd, uint32 value);
 int32 hom_decrease_intimacy(struct homun_data * hd, uint32 value);
 int32 hom_skill_tree_get_max(int32 skill_id, int32 b_class);

+ 10 - 7
src/map/mob.cpp

@@ -1404,8 +1404,11 @@ static int32 mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
 		(*target) = bl;
 		md->target_id = bl->id;
 	}
-	else if (!battle_config.monster_loot_search_type)
-		mob_stop_walking(md, 1); // Stop walking immediately if item is no longer on the ground.
+	else if( !battle_config.monster_loot_search_type ){
+		// Stop walking immediately if item is no longer on the ground.
+		unit_stop_walking( &md->bl, USW_FIXPOS );
+	}
+
 	return 0;
 }
 
@@ -1485,10 +1488,10 @@ static int32 mob_ai_sub_hard_slavemob(struct mob_data *md,t_tick tick)
 
 			if (map_search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1)) {
 				if (unit_walktoxy(&md->bl, x, y, 0) == 0) { // Slave is too far from master (outside of battle_config.max_walk_path range), stay put
-					mob_stop_walking(md, USW_FIXPOS);
+					unit_stop_walking( &md->bl, USW_FIXPOS );
 					return 0; // Fail here so target will be picked back up when in range
 				} else { // Slave will walk back to master if in range
-					mob_stop_attack(md);
+					unit_stop_attack( &md->bl );
 					return 1;
 				}
 			}
@@ -1565,7 +1568,7 @@ int32 mob_unlocktarget(struct mob_data *md, t_tick tick)
 				md->next_walktime = tick+rnd()%1000;
 		break;
 	default:
-		mob_stop_attack(md);
+		unit_stop_attack( &md->bl );
 		unit_stop_walking_soon(md->bl); //Stop chasing.
 		if (status_has_mode(&md->status,MD_ANGRY) && !md->state.aggressive)
 			md->state.aggressive = 1; //Restore angry state when switching to idle
@@ -3525,8 +3528,8 @@ int32 mob_class_change (struct mob_data *md, int32 mob_id)
 
 	status_change_end(&md->bl,SC_KEEPING); // End before calling status_calc_mob().
 	status_change_end(&md->bl,SC_BARRIER);
-	mob_stop_attack(md);
-	mob_stop_walking(md, 0);
+	unit_stop_attack( &md->bl );
+	unit_stop_walking( &md->bl, USW_NONE );
 	unit_skillcastcancel(&md->bl, 0);
 	status_set_viewdata(&md->bl, mob_id);
 	clif_class_change( md->bl, md->vd->class_ );

+ 0 - 3
src/map/mob.hpp

@@ -521,9 +521,6 @@ int32 mob_dead(struct mob_data *md, struct block_list *src, int32 type);
 void mob_revive(struct mob_data *md, uint32 hp);
 void mob_heal(struct mob_data *md,uint32 heal);
 
-#define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
-#define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
-
 void mob_clear_spawninfo();
 void do_init_mob(void);
 void do_final_mob(bool is_reload);

+ 5 - 4
src/map/pc.cpp

@@ -2995,7 +2995,7 @@ int32 pc_disguise(map_session_data *sd, int32 class_)
 	}
 
 	if (sd->bl.prev != nullptr) {
-		pc_stop_walking(sd, 0);
+		unit_stop_walking( &sd->bl, USW_NONE );
 		clif_clearunit_area( sd->bl, CLR_OUTSIGHT );
 	}
 
@@ -6126,7 +6126,7 @@ bool pc_takeitem(map_session_data *sd,struct flooritem_data *fitem)
 	}
 
 	//Display pickup animation.
-	pc_stop_attack(sd);
+	unit_stop_attack( &sd->bl );
 	clif_takeitem(sd->bl,fitem->bl);
 
 	if (fitem->mob_id &&
@@ -8083,7 +8083,7 @@ int32 pc_stop_following (map_session_data *sd)
 	sd->followtarget = -1;
 	sd->ud.target_to = 0;
 
-	unit_stop_walking(&sd->bl, 1);
+	unit_stop_walking( &sd->bl, USW_FIXPOS );
 
 	return 0;
 }
@@ -11090,7 +11090,8 @@ void pc_setoption(map_session_data *sd,int32 type, int32 subtype)
 		new_look = sd->vd.class_;
 	}
 
-	pc_stop_attack(sd); //Stop attacking on new view change (to prevent wedding/santa attacks.
+	// Stop attacking on new view change (to prevent wedding/santa attacks).
+	unit_stop_attack( &sd->bl );
 	clif_changelook(&sd->bl,LOOK_BASE,new_look);
 	if (sd->vd.cloth_color)
 		clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);

+ 1 - 4
src/map/pc.hpp

@@ -1131,7 +1131,7 @@ extern JobDatabase job_db;
 #endif
 
 #define pc_setdead(sd)        ( (sd)->state.dead_sit = (sd)->vd.dead_sit = 1 )
-#define pc_setsit(sd)         { pc_stop_walking((sd), 1|4); pc_stop_attack((sd)); (sd)->state.dead_sit = (sd)->vd.dead_sit = 2; }
+#define pc_setsit(sd)         { unit_stop_walking( &(sd)->bl, USW_FIXPOS|USW_MOVE_FULL_CELL ); unit_stop_attack( &(sd)->bl ); (sd)->state.dead_sit = (sd)->vd.dead_sit = 2; }
 #define pc_isdead(sd)         ( (sd)->state.dead_sit == 1 )
 #define pc_issit(sd)          ( (sd)->vd.dead_sit == 2 )
 #define pc_isidle_party(sd)   ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share )
@@ -1199,9 +1199,6 @@ enum e_mado_type : uint16 {
 // Rune Knight Dragon
 #define pc_isridingdragon(sd) ( (sd)->sc.option&OPTION_DRAGON )
 
-#define pc_stop_walking(sd, type) unit_stop_walking(&(sd)->bl, type)
-#define pc_stop_attack(sd) unit_stop_attack(&(sd)->bl)
-
 //Weapon check considering dual wielding.
 #define pc_check_weapontype(sd, type) ((type)&((sd)->status.weapon < MAX_WEAPON_TYPE? \
 	1<<(sd)->status.weapon:(1<<(sd)->weapontype1)|(1<<(sd)->weapontype2)|(1<<(sd)->status.weapon)))

+ 9 - 9
src/map/pet.cpp

@@ -695,8 +695,8 @@ void pet_unlocktarget(struct pet_data *pd)
 	nullpo_retv(pd);
 
 	pd->target_id = 0;
-	pet_stop_attack(pd);
-	pet_stop_walking(pd,1);
+	unit_stop_attack( &pd->bl );
+	unit_stop_walking( &pd->bl, USW_FIXPOS );
 }
 
 /**
@@ -862,7 +862,7 @@ static TIMER_FUNC(pet_hungry){
 	pd->pet.hungry -= pet_db_ptr->fullness;
 
 	if( pd->pet.hungry < PET_HUNGRY_NONE ) {
-		pet_stop_attack(pd);
+		unit_stop_attack( &pd->bl );
 		pd->pet.hungry = PET_HUNGRY_NONE;
 		pet_set_intimate(pd, pd->pet.intimate + pet_db_ptr->hungry_intimacy_dec);
 
@@ -936,7 +936,7 @@ int32 pet_hungry_timer_delete(struct pet_data *pd)
  */
 static int32 pet_performance(map_session_data *sd, struct pet_data *pd)
 {
-	pet_stop_walking(pd,2000<<8);
+	unit_stop_walking( &pd->bl, USW_NONE, 2000 );
 	clif_send_petdata( nullptr, *pd, CHANGESTATEPET_PERFORMANCE );
 	pet_lootitem_drop( *pd, nullptr );
 
@@ -1652,7 +1652,7 @@ int32 pet_food(map_session_data *sd, struct pet_data *pd)
 	if (pd->pet.hungry > PET_HUNGRY_SATISFIED) {
 		pet_set_intimate(pd, pd->pet.intimate + pet_db_ptr->r_full);
 		if (pd->pet.intimate <= PET_INTIMATE_NONE) {
-			pet_stop_attack(pd);
+			unit_stop_attack( &pd->bl );
 			pd->status.speed = pd->get_pet_walk_speed();
 		}
 	}
@@ -2132,8 +2132,8 @@ TIMER_FUNC(pet_heal_timer){
 		return 0;
 	}
 
-	pet_stop_attack(pd);
-	pet_stop_walking(pd,1);
+	unit_stop_attack( &pd->bl );
+	unit_stop_walking( &pd->bl, USW_FIXPOS );
 	clif_skill_nodamage(&pd->bl,sd->bl,AL_HEAL,pd->s_skill->lv);
 	status_heal(&sd->bl, pd->s_skill->lv,0, 0);
 	pd->s_skill->timer = add_timer(tick+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
@@ -2180,8 +2180,8 @@ TIMER_FUNC(pet_skill_support_timer){
 		return 0;
 	}
 
-	pet_stop_attack(pd);
-	pet_stop_walking(pd,1);
+	unit_stop_attack( &pd->bl );
+	unit_stop_walking( &pd->bl, USW_FIXPOS );
 	pd->s_skill->timer=add_timer(tick+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
 
 	if (skill_get_inf(pd->s_skill->id) & INF_GROUND_SKILL)

+ 0 - 3
src/map/pet.hpp

@@ -255,9 +255,6 @@ void pet_evolution(map_session_data *sd, int16 pet_id);
 int32 pet_food(map_session_data *sd, struct pet_data *pd);
 void pet_clear_support_bonuses(map_session_data *sd);
 
-#define pet_stop_walking(pd, type) unit_stop_walking(&(pd)->bl, type)
-#define pet_stop_attack(pd) unit_stop_attack(&(pd)->bl)
-
 bool pet_addautobonus(std::vector<std::shared_ptr<s_petautobonus>> &bonus, const std::string &script, int16 rate, uint32 dur, uint16 atk_type, const std::string &other_script, bool onskill);
 void pet_exeautobonus(map_session_data &sd, std::vector<std::shared_ptr<s_petautobonus>> *bonus, std::shared_ptr<s_petautobonus> &autobonus);
 void pet_delautobonus(map_session_data &sd, std::vector<std::shared_ptr<s_petautobonus>> &bonus, bool restore);

+ 3 - 3
src/map/script.cpp

@@ -20032,7 +20032,7 @@ BUILDIN_FUNC(unitstopwalk)
 		if (ud != nullptr)
 			ud->state.force_walk = false;
 
-		if (unit_stop_walking(bl, flag) == 0 && flag != USW_FORCE_STOP) {
+		if( !unit_stop_walking( bl, flag ) && flag != USW_FORCE_STOP ){
 			ShowWarning("buildin_unitstopwalk: Unable to find unit or unit is not walking.\n");
 			return SCRIPT_CMD_FAILURE;
 		}
@@ -21296,8 +21296,8 @@ BUILDIN_FUNC(bg_monster_set_team)
 	md = (TBL_MOB *)mbl;
 	md->bg_id = bg_id;
 
-	mob_stop_attack(md);
-	mob_stop_walking(md, 0);
+	unit_stop_attack( &md->bl );
+	unit_stop_walking( &md->bl, USW_NONE );
 	md->target_id = md->attacked_id = 0;
 	clif_name_area(&md->bl);
 

+ 7 - 5
src/map/skill.cpp

@@ -2344,8 +2344,10 @@ int32 skill_additional_effect( struct block_list* src, struct block_list *bl, ui
 			if (skill == PF_SPIDERWEB) //Special case, due to its nature of coding.
 				type = CAST_GROUND;
 #ifndef RENEWAL
-			else if (skill == AS_SONICBLOW)
-				pc_stop_attack(sd); //Special case, Sonic Blow autospell should stop the player attacking.
+			else if( skill == AS_SONICBLOW ){
+				// Special case, Sonic Blow autospell should stop the player attacking.
+				unit_stop_attack( &sd->bl );
+			}
 #endif
 
 			sd->state.autocast = 1;
@@ -13867,7 +13869,7 @@ TIMER_FUNC(skill_castend_id){
 		}
 
 		if (ud->walktimer != INVALID_TIMER && ud->skill_id != TK_RUN && ud->skill_id != RA_WUGDASH)
-			unit_stop_walking(src,1);
+			unit_stop_walking( src, USW_FIXPOS );
 
 		if (!sd || sd->skillitem != ud->skill_id || skill_get_delay(ud->skill_id, ud->skill_lv))
 			ud->canact_tick = i64max(tick + skill_delayfix(src, ud->skill_id, ud->skill_lv), ud->canact_tick - SECURITY_CASTTIME);
@@ -14130,7 +14132,7 @@ TIMER_FUNC(skill_castend_pos){
 				src->type, src->id, ud->skill_id, ud->skill_lv, ud->skillx, ud->skilly);
 
 		if (ud->walktimer != INVALID_TIMER)
-			unit_stop_walking(src,1);
+			unit_stop_walking( src, USW_FIXPOS );
 
 		if (!sd || sd->skillitem != ud->skill_id || skill_get_delay(ud->skill_id, ud->skill_lv))
 			ud->canact_tick = i64max(tick + skill_delayfix(src, ud->skill_id, ud->skill_lv), ud->canact_tick - SECURITY_CASTTIME);
@@ -15350,7 +15352,7 @@ int32 skill_castend_map (map_session_data *sd, uint16 skill_id, const char *mapn
 		return 0;
 	}
 
-	pc_stop_attack(sd);
+	unit_stop_attack( &sd->bl );
 
 	if(battle_config.skill_log && battle_config.skill_log&BL_PC)
 		ShowInfo("PC %d skill castend skill =%d map=%s\n",sd->bl.id,skill_id,mapname);

+ 9 - 9
src/map/status.cpp

@@ -1607,7 +1607,7 @@ int32 status_damage(struct block_list *src,struct block_list *target,int64 dhp,
 		mob_log_damage(reinterpret_cast<mob_data*>(src), target, 0, dhp);
 
 	if( src && target->type == BL_PC && ((TBL_PC*)target)->disguise ) { // Stop walking when attacked in disguise to prevent walk-delay bug
-		unit_stop_walking( target, 1 );
+		unit_stop_walking( target, USW_FIXPOS );
 	}
 
 	if( status->hp || (flag&8) ) { // Still lives or has been dead before this damage.
@@ -5884,7 +5884,7 @@ void status_calc_bl_main(struct block_list& bl, std::bitset<SCB_MAX> flag)
 		if (!status_has_mode(status,MD_CANATTACK))
 			unit_stop_attack(&bl);
 		if (!status_has_mode(status,MD_CANMOVE))
-			unit_stop_walking(&bl,1);
+			unit_stop_walking( &bl, USW_FIXPOS );
 	}
 
 	/**
@@ -10604,7 +10604,7 @@ int32 status_change_start(struct block_list* src, struct block_list* bl,enum sc_
 			if (val1 > 4) val2--;
 			//Suiton is a special case, stop effect is forced and only happens when target enters it
 			if (!unit_blown_immune(bl, 0x1))
-				unit_stop_walking(bl, 9);
+				unit_stop_walking( bl, USW_FIXPOS|USW_FORCE_STOP );
 			break;
 		case SC_ONEHAND:
 		case SC_TWOHANDQUICKEN:
@@ -12664,11 +12664,11 @@ int32 status_change_start(struct block_list* src, struct block_list* bl,enum sc_
 		switch (type) {
 			case SC__MANHOLE:
 				if (bl->type == BL_PC || !unit_blown_immune(bl,0x1))
-					unit_stop_walking(bl,1);
+					unit_stop_walking( bl, USW_FIXPOS );
 				break;
 			case SC_VACUUM_EXTREME:
 				if (bl->type != BL_PC && unit_blown_immune(bl, 0x1) == UB_KNOCKABLE) {
-					unit_stop_walking(bl,1);
+					unit_stop_walking( bl, USW_FIXPOS );
 					unit_stop_attack(bl);
 				}
 				break;
@@ -12676,13 +12676,13 @@ int32 status_change_start(struct block_list* src, struct block_list* bl,enum sc_
 			case SC_STUN:
 			case SC_STONE:
 				if (sc->getSCE(SC_DANCING)) {
-					unit_stop_walking(bl, 1);
+					unit_stop_walking( bl, USW_FIXPOS );
 					status_change_end(bl, SC_DANCING);
 				}
 				break;
 			default:
 				if (!unit_blown_immune(bl,0x1))
-					unit_stop_walking(bl,1);
+					unit_stop_walking( bl, USW_FIXPOS );
 				break;
 		}
 	}
@@ -13089,7 +13089,7 @@ int32 status_change_end(struct block_list* bl, enum sc_type type, int32 tid)
 					begin_spurt = false;
 				ud->state.running = 0;
 				if (ud->walktimer != INVALID_TIMER)
-					unit_stop_walking(bl,1);
+					unit_stop_walking( bl, USW_FIXPOS );
 			}
 			if (begin_spurt && sce->val1 >= 7 &&
 				DIFF_TICK(gettick(), starttick) <= 1000 &&
@@ -13370,7 +13370,7 @@ int32 status_change_end(struct block_list* bl, enum sc_type type, int32 tid)
 				if (ud) {
 					ud->state.running = 0;
 					if (ud->walktimer != INVALID_TIMER)
-						unit_stop_walking(bl,1);
+						unit_stop_walking( bl, USW_FIXPOS );
 				}
 			}
 			break;

+ 25 - 17
src/map/unit.cpp

@@ -1137,7 +1137,7 @@ bool unit_movepos(struct block_list *bl, short dst_x, short dst_y, int32 easy, b
 	if(ud == nullptr)
 		return false;
 
-	unit_stop_walking(bl, 1);
+	unit_stop_walking( bl, USW_FIXPOS );
 	unit_stop_attack(bl);
 
 	if( checkpath && (map_getcell(bl->m,dst_x,dst_y,CELL_CHKNOPASS) || !path_search(nullptr,bl->m,bl->x,bl->y,dst_x,dst_y,easy,CELL_CHKNOREACH)) )
@@ -1267,7 +1267,7 @@ int32 unit_blown(struct block_list* bl, int32 dx, int32 dy, int32 count, enum e_
 		ny = result&0xffff;
 
 		if(!su)
-			unit_stop_walking(bl, 0);
+			unit_stop_walking( bl, USW_NONE );
 
 		if( sd ) {
 			unit_stop_stepaction(bl); //Stop stepaction when knocked back
@@ -1534,20 +1534,21 @@ void unit_stop_walking_soon(struct block_list& bl)
  * Stops a unit from walking
  * @param bl: Object to stop walking
  * @param type: Options, see e_unit_stop_walking
- * @return Success(1); Failed(0);
+ * @return Success(true); Failed(false);
  */
-int32 unit_stop_walking(struct block_list *bl,int32 type)
-{
+bool unit_stop_walking( block_list* bl, int32 type, t_tick canmove_delay ){
 	struct unit_data *ud;
 	const struct TimerData* td = nullptr;
 	t_tick tick;
 
-	nullpo_ret(bl);
+	if( bl == nullptr ){
+		return false;
+	}
 
 	ud = unit_bl2ud(bl);
 
 	if(!ud || (!(type&USW_FORCE_STOP) && ud->walktimer == INVALID_TIMER))
-		return 0;
+		return false;
 
 	// NOTE: We are using timer data after deleting it because we know the
 	// delete_timer function does not mess with it. If the function's
@@ -1582,8 +1583,9 @@ int32 unit_stop_walking(struct block_list *bl,int32 type)
 	if (type&USW_RELEASE_TARGET)
 		ud->target_to = 0;
 
-	if(bl->type == BL_PET && type&~USW_ALL)
-		ud->canmove_tick = gettick() + (type>>8);
+	if( canmove_delay > 0 ){
+		ud->canmove_tick = gettick() + canmove_delay;
+	}
 
 	// Re-added, the check in unit_set_walkdelay means dmg during running won't fall through to this place in code [Kevin]
 	if (ud->state.running) {
@@ -1591,7 +1593,7 @@ int32 unit_stop_walking(struct block_list *bl,int32 type)
 		status_change_end(bl, SC_WUGDASH);
 	}
 
-	return 1;
+	return true;
 }
 
 /**
@@ -1731,7 +1733,10 @@ int32 unit_set_walkdelay(struct block_list *bl, t_tick tick, t_tick delay, int32
 				if (md && md->state.can_escape == 1) // Mob needs to escape, don't stop it
 					return 0;
 			}
-			unit_stop_walking(bl,4); //Unit might still be moving even though it can't move
+
+			// Unit might still be moving even though it can't move
+			unit_stop_walking( bl, USW_MOVE_FULL_CELL );
+
 			return 0;
 		}
 		//Immune to being stopped for double the flinch time
@@ -1743,13 +1748,13 @@ int32 unit_set_walkdelay(struct block_list *bl, t_tick tick, t_tick delay, int32
 
 	if (ud->walktimer != INVALID_TIMER) { // Stop walking, if chasing, readjust timers.
 		if (delay == 1) // Minimal delay (walk-delay) disabled. Just stop walking.
-			unit_stop_walking(bl,0);
+			unit_stop_walking( bl, USW_NONE );
 		else {
 			// Resume running after can move again [Kevin]
 			if(ud->state.running)
 				add_timer(ud->canmove_tick, unit_resume_running, bl->id, (intptr_t)ud);
 			else {
-				unit_stop_walking(bl,4);
+				unit_stop_walking( bl, USW_MOVE_FULL_CELL );
 
 				if(ud->target_to != 0)
 					add_timer(ud->canmove_tick+1, unit_walktobl_sub, bl->id, ud->target_to);
@@ -2164,8 +2169,11 @@ int32 unit_skilluse_id2(struct block_list *src, int32 target_id, uint16 skill_id
 	casttime = skill_vfcastfix(src, casttime, skill_id, skill_lv);
 #endif
 
-	if(!ud->state.running) // Need TK_RUN or WUGDASH handler to be done before that, see bugreport:6026
-		unit_stop_walking(src, 1); // Even though this is not how official works but this will do the trick. bugreport:6829
+	// Need TK_RUN or WUGDASH handler to be done before that, see bugreport:6026
+	if(!ud->state.running){
+		// Even though this is not how official works but this will do the trick. bugreport:6829
+		unit_stop_walking( src, USW_FIXPOS );
+	}
 
 	// SC_MAGICPOWER needs to switch states at start of cast
 #ifndef RENEWAL
@@ -2426,7 +2434,7 @@ int32 unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y,
 		}
 	}
 
-	unit_stop_walking(src,1);
+	unit_stop_walking( src, USW_FIXPOS );
 
 	// SC_MAGICPOWER needs to switch states at start of cast
 #ifndef RENEWAL
@@ -2942,7 +2950,7 @@ static int32 unit_attack_timer_sub(struct block_list* src, int32 tid, t_tick tic
 			unit_setdir(src, map_calc_dir(src, target->x, target->y), false);
 
 		if(ud->walktimer != INVALID_TIMER)
-			unit_stop_walking(src,1);
+			unit_stop_walking( src, USW_FIXPOS );
 
 		if(md) {
 			// Berserk skills can replace normal attacks except for the first attack

+ 1 - 1
src/map/unit.hpp

@@ -118,7 +118,7 @@ TIMER_FUNC(unit_delay_walktobl_timer);
 
 void unit_stop_walking_soon(struct block_list& bl);
 // Causes the target object to stop moving.
-int32 unit_stop_walking(struct block_list *bl,int32 type);
+bool unit_stop_walking( block_list* bl, int32 type, t_tick canmove_delay = 0 );
 bool unit_can_move(struct block_list *bl);
 int32 unit_is_walking(struct block_list *bl);
 int32 unit_set_walkdelay(struct block_list *bl, t_tick tick, t_tick delay, int32 type);