Continues #2 FEAR_INDUCING impl

This required changes (improvements imo) to the monster state logic.
This commit is contained in:
Linus Probert 2018-08-09 15:57:05 +02:00
parent 0aacdd2d84
commit 19e7583f3e
5 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;