Maint: Removed duplicate code

This commit is contained in:
Linus Probert 2018-09-13 13:46:29 +02:00
parent 0fc1fed278
commit dbf9fe3931
1 changed files with 20 additions and 16 deletions

View File

@ -154,19 +154,29 @@ create_default(const char *s_label, Sprite *s)
return skill;
}
static bool
check_skill_validity(Position *playerPos, Position *targetPos, SkillData *data)
{
*playerPos = position_to_matrix_coords(&data->player->sprite->pos);
*targetPos = *playerPos;
targetPos->x += (int) data->direction.x;
targetPos->y += (int) data->direction.y;
player_turn(data->player, &data->direction);
if (!position_in_roommatrix(targetPos)) {
return false;
}
return true;
}
static bool
skill_use_flurry(Skill *skill, SkillData *data)
{
UNUSED (skill);
Position playerPos = position_to_matrix_coords(&data->player->sprite->pos);
Position targetPos = playerPos;
targetPos.x += (int) data->direction.x;
targetPos.y += (int) data->direction.y;
player_turn(data->player, &data->direction);
if (!position_in_roommatrix(&targetPos)) {
Position playerPos, targetPos;
if (!check_skill_validity(&playerPos, &targetPos, data)) {
return false;
}
@ -285,14 +295,8 @@ skill_bash(Skill *skill, SkillData *data)
{
UNUSED (skill);
Position playerPos = position_to_matrix_coords(&data->player->sprite->pos);
Position targetPos = playerPos;
targetPos.x += (int) data->direction.x;
targetPos.y += (int) data->direction.y;
player_turn(data->player, &data->direction);
if (!position_in_roommatrix(&targetPos)) {
Position playerPos, targetPos;
if (!check_skill_validity(&playerPos, &targetPos, data)) {
return false;
}