diff --git a/src/monster.c b/src/monster.c index 2012dae..4c995bf 100644 --- a/src/monster.c +++ b/src/monster.c @@ -80,6 +80,7 @@ monster_state_change(Monster *m, StateType newState) m->state.last = m->state.current; m->state.current = newState; m->state.stepsSinceChange = 0; + m->state.forceCount = 0; monster_set_state_display_time(m); @@ -96,7 +97,7 @@ monster_state_change(Monster *m, StateType newState) static void monster_behaviour_check_post_hit(Monster *m) { - if (m->state.current == STUNNED) + if (m->state.stepsSinceChange < m->state.forceCount) return; switch (m->behaviour) { @@ -194,6 +195,7 @@ monster_create(void) m->stateIndicator.sprite->dim = GAME_DIMENSION; m->stateIndicator.displayCount = 0; m->stateIndicator.shownOnPlayerRoomEnter = false; + m->state.forceCount = 0; monster_set_behaviour(m, NORMAL); return m; @@ -376,17 +378,18 @@ monster_coward_walk(Monster *m, RoomMatrix *rm) bool monster_move(Monster *m, RoomMatrix *rm) { - - if (m->state.current == STUNNED) { - if (m->state.stepsSinceChange < 3) { - m->state.stepsSinceChange += 1; - return true; - } else { + if (m->state.forceCount) { + if (m->state.stepsSinceChange >= m->state.forceCount) { monster_state_change(m, m->state.last); monster_behaviour_check_post_hit(m); } } + if (m->state.current == STUNNED) { + m->state.stepsSinceChange += 1; + return true; + } + monster_behaviour_check(m, rm); Position originalPosition = @@ -595,9 +598,10 @@ monster_set_behaviour(Monster *m, MonsterBehaviour behaviour) } void -monster_set_state(Monster *m, StateType state) +monster_set_state(Monster *m, StateType state, Uint8 forceCount) { monster_state_change(m, state); + m->state.forceCount = forceCount; } void diff --git a/src/monster.h b/src/monster.h index 7242b20..6749ee5 100644 --- a/src/monster.h +++ b/src/monster.h @@ -51,6 +51,7 @@ typedef struct State { StateType current; StateType last; unsigned int stepsSinceChange; + Uint8 forceCount; } State; typedef struct MonsterStateIndicator { @@ -59,7 +60,7 @@ typedef struct MonsterStateIndicator { int displayCount; } MonsterStateIndicator; -typedef struct Monster_t { +typedef struct Monster { char *label; char *lclabel; Sprite *sprite; @@ -97,7 +98,7 @@ void monster_set_behaviour(Monster *, MonsterBehaviour behaviour); void -monster_set_state(Monster *m, StateType state); +monster_set_state(Monster *m, StateType state, Uint8 forceCount); void monster_push(Monster *, RoomMatrix*, Vector2d dir); diff --git a/src/player.c b/src/player.c index 4ab42b5..c0da27a 100644 --- a/src/player.c +++ b/src/player.c @@ -158,7 +158,7 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction) if (get_random(10) < player_has_artifact(player, FEAR_INDUCING)) { gui_log("%s shivers with fear at the sight of you", space->monster->label); - monster_set_state(space->monster, SCARED); + monster_set_state(space->monster, SCARED, 3); } } diff --git a/src/roommatrix.h b/src/roommatrix.h index 5a447b9..01884c4 100644 --- a/src/roommatrix.h +++ b/src/roommatrix.h @@ -28,7 +28,7 @@ typedef struct Sprite Sprite; typedef struct Map_t Map; -typedef struct Monster_t Monster; +typedef struct Monster Monster; typedef struct Player Player; typedef struct Item_t Item; typedef struct Node LinkedList; diff --git a/src/skill.c b/src/skill.c index fb833d4..9664307 100644 --- a/src/skill.c +++ b/src/skill.c @@ -205,7 +205,7 @@ skill_bash(Skill *skill, SkillData *data) gui_log("You hit for %u damage", dmg); if (monster->stats.hp > 0) { gui_log("%s seems dazed and confused", monster->label); - monster_set_state(monster, STUNNED); + monster_set_state(monster, STUNNED, 3); } mixer_play_effect(SLAM); data->player->stat_data.hits += 1;