2018-02-16 18:11:26 +01:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-12-21 12:35:52 +01:00
|
|
|
#include <stdlib.h>
|
2017-12-17 13:43:41 +01:00
|
|
|
#include <assert.h>
|
2018-01-25 10:45:05 +01:00
|
|
|
|
2017-12-13 14:26:30 +01:00
|
|
|
#include "monster.h"
|
|
|
|
#include "util.h"
|
2017-12-15 08:08:45 +01:00
|
|
|
#include "player.h"
|
|
|
|
#include "monster.h"
|
2017-12-17 13:43:41 +01:00
|
|
|
#include "random.h"
|
2018-01-23 14:11:03 +01:00
|
|
|
#include "gui.h"
|
2018-01-25 10:45:05 +01:00
|
|
|
#include "item.h"
|
|
|
|
#include "item_builder.h"
|
2018-01-29 13:48:44 +01:00
|
|
|
#include "map.h"
|
2018-02-03 23:39:49 +01:00
|
|
|
#include "particle_engine.h"
|
2018-03-03 12:56:53 +01:00
|
|
|
#include "defines.h"
|
2018-05-15 11:16:56 +02:00
|
|
|
#include "update_data.h"
|
|
|
|
#include "actiontextbuilder.h"
|
2018-05-17 21:41:23 +02:00
|
|
|
#include "texturecache.h"
|
2017-12-15 15:03:29 +01:00
|
|
|
|
2018-05-19 17:55:10 +02:00
|
|
|
static void
|
|
|
|
monster_set_sprite_clip_for_current_state(Monster *m)
|
|
|
|
{
|
|
|
|
switch (m->state.current) {
|
|
|
|
case AGRESSIVE:
|
|
|
|
m->stateIndicator.sprite->clip = CLIP16(16 * 11, 16 * 3);
|
|
|
|
break;
|
|
|
|
case STATIONARY:
|
|
|
|
case PASSIVE:
|
|
|
|
m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16);
|
|
|
|
break;
|
|
|
|
case SCARED:
|
|
|
|
m->stateIndicator.sprite->clip = CLIP16(16 * 12, 16 * 3);
|
|
|
|
break;
|
2018-05-21 21:03:59 +02:00
|
|
|
case SLEEPING:
|
|
|
|
m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16 * 4);
|
|
|
|
break;
|
|
|
|
case SCANNING:
|
|
|
|
m->stateIndicator.sprite->clip = CLIP16(16 * 13, 16 * 4);
|
2018-05-19 17:55:10 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monster_state_change(Monster *m, StateType newState)
|
|
|
|
{
|
|
|
|
if (m->state.current == newState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m->state.current = newState;
|
|
|
|
m->state.stepsSinceChange = 0;
|
|
|
|
m->stateIndicator.displayCount = 5;
|
|
|
|
|
|
|
|
monster_set_sprite_clip_for_current_state(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monster_behaviour_check_post_hit(Monster *m)
|
|
|
|
{
|
|
|
|
switch (m->behaviour) {
|
|
|
|
case PACIFIST:
|
|
|
|
case COWARD:
|
|
|
|
monster_state_change(m, SCARED);
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-21 21:03:59 +02:00
|
|
|
monster_state_change(m, AGRESSIVE);
|
2018-05-19 17:55:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monster_behaviour_check_post_attack(Monster *m)
|
|
|
|
{
|
|
|
|
switch (m->behaviour) {
|
|
|
|
case GUERILLA:
|
|
|
|
monster_state_change(m, SCARED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 21:03:59 +02:00
|
|
|
static void
|
|
|
|
handle_sentinel_behaviour(Monster *m, RoomMatrix *rm)
|
|
|
|
{
|
|
|
|
if (m->state.current == AGRESSIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Position monsterPos = m->sprite->pos;
|
|
|
|
if (!position_in_room(&monsterPos, &rm->roomPos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
monsterPos = position_to_matrix_coords(&monsterPos);
|
|
|
|
Position playerPos = rm->playerRoomPos;
|
|
|
|
unsigned int dx = abs(playerPos.x - monsterPos.x);
|
|
|
|
unsigned int dy = abs(playerPos.y - monsterPos.y);
|
|
|
|
if (dx < 3 && dy < 3)
|
|
|
|
monster_state_change(m, AGRESSIVE);
|
|
|
|
else if (dx <= 3 && dy <= 3)
|
|
|
|
monster_state_change(m, SCANNING);
|
|
|
|
else
|
|
|
|
monster_state_change(m, SLEEPING);
|
|
|
|
}
|
|
|
|
|
2018-05-19 17:55:10 +02:00
|
|
|
static void
|
|
|
|
monster_behaviour_check(Monster *m, RoomMatrix *rm)
|
|
|
|
{
|
|
|
|
switch (m->behaviour) {
|
|
|
|
case GUERILLA:
|
|
|
|
if (m->state.stepsSinceChange > 8
|
|
|
|
&& m->state.current == SCARED) {
|
|
|
|
monster_state_change(m, AGRESSIVE);
|
|
|
|
}
|
|
|
|
break;
|
2018-05-21 21:03:59 +02:00
|
|
|
case SENTINEL:
|
|
|
|
handle_sentinel_behaviour(m, rm);
|
|
|
|
break;
|
2018-05-19 17:55:10 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 14:26:30 +01:00
|
|
|
Monster*
|
2018-05-15 11:16:56 +02:00
|
|
|
monster_create(void)
|
2017-12-13 14:26:30 +01:00
|
|
|
{
|
|
|
|
Monster *m = ec_malloc(sizeof(Monster));
|
|
|
|
m->sprite = sprite_create();
|
2018-02-23 23:53:52 +01:00
|
|
|
m->sprite->dim = GAME_DIMENSION;
|
2017-12-14 12:01:05 +01:00
|
|
|
m->sprite->clip = (SDL_Rect) { 0, 0, 16, 16 };
|
2018-02-20 14:22:26 +01:00
|
|
|
|
|
|
|
m->stats = (Stats) {
|
|
|
|
12, // Max HP
|
|
|
|
12, // hp
|
|
|
|
2, // dmg
|
|
|
|
0, // atk
|
|
|
|
0, // def
|
|
|
|
1, // speed
|
|
|
|
1 // lvl
|
|
|
|
};
|
|
|
|
|
2018-01-17 09:32:49 +01:00
|
|
|
m->label = NULL;
|
2018-01-25 10:45:05 +01:00
|
|
|
m->lclabel = NULL;
|
2018-02-19 15:09:04 +01:00
|
|
|
m->steps = 0;
|
2018-05-17 21:41:23 +02:00
|
|
|
m->stateIndicator.sprite = sprite_create();
|
|
|
|
sprite_set_texture(m->stateIndicator.sprite, texturecache_add("GUI/GUI0.png"), 0);
|
|
|
|
sprite_set_texture(m->stateIndicator.sprite, texturecache_add("GUI/GUI1.png"), 1);
|
|
|
|
m->stateIndicator.sprite->dim = GAME_DIMENSION;
|
|
|
|
m->stateIndicator.displayCount = 0;
|
|
|
|
m->stateIndicator.shownOnPlayerRoomEnter = false;
|
2018-05-19 17:55:10 +02:00
|
|
|
monster_set_behaviour(m, NORMAL);
|
2017-12-15 15:03:29 +01:00
|
|
|
|
2017-12-13 14:26:30 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2017-12-15 15:03:29 +01:00
|
|
|
void
|
|
|
|
monster_update_pos(Monster *m, Position pos)
|
|
|
|
{
|
|
|
|
m->sprite->pos = pos;
|
|
|
|
|
2018-05-17 21:41:23 +02:00
|
|
|
Position indicatorPos = pos;
|
|
|
|
indicatorPos.y -= 32;
|
|
|
|
m->stateIndicator.sprite->pos = indicatorPos;
|
2017-12-15 15:03:29 +01:00
|
|
|
}
|
|
|
|
|
2017-12-17 13:43:41 +01:00
|
|
|
static bool
|
2018-05-13 23:32:44 +02:00
|
|
|
has_collided(Monster *monster, RoomMatrix *matrix, Vector2d direction)
|
2017-12-17 13:43:41 +01:00
|
|
|
{
|
|
|
|
if (!position_in_room(&monster->sprite->pos, &matrix->roomPos))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Position roomPos = position_to_matrix_coords(&monster->sprite->pos);
|
|
|
|
RoomSpace *space = &matrix->spaces[roomPos.x][roomPos.y];
|
2017-12-18 09:59:01 +01:00
|
|
|
|
2018-02-05 16:15:45 +01:00
|
|
|
if (space->player && monster->state.current == AGRESSIVE) {
|
2017-12-18 15:26:56 +01:00
|
|
|
unsigned int dmg = stats_fight(&monster->stats,
|
|
|
|
&space->player->stats);
|
2018-01-23 22:54:02 +01:00
|
|
|
|
2017-12-18 15:26:56 +01:00
|
|
|
player_hit(space->player, dmg);
|
2018-01-23 14:11:03 +01:00
|
|
|
|
2018-05-13 23:32:44 +02:00
|
|
|
if (dmg > 0) {
|
|
|
|
gui_log("%s hit you for %u damage",
|
|
|
|
monster->label, dmg);
|
|
|
|
camera_shake(direction, 300);
|
|
|
|
} else {
|
2018-01-25 10:45:05 +01:00
|
|
|
gui_log("%s missed you", monster->label);
|
2018-05-13 23:32:44 +02:00
|
|
|
}
|
2018-05-19 17:55:10 +02:00
|
|
|
monster_behaviour_check_post_attack(monster);
|
2017-12-18 09:59:01 +01:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:30:26 +02:00
|
|
|
return space->occupied || space->lethal;
|
2017-12-17 13:43:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2018-05-13 23:32:44 +02:00
|
|
|
move(Monster *m, RoomMatrix *rm, Vector2d direction)
|
2017-12-17 13:43:41 +01:00
|
|
|
{
|
2018-05-13 23:32:44 +02:00
|
|
|
m->sprite->pos.x += TILE_DIMENSION * (int) direction.x;
|
|
|
|
m->sprite->pos.y += TILE_DIMENSION * (int) direction.y;
|
|
|
|
if (has_collided(m, rm, direction)) {
|
|
|
|
m->sprite->pos.x -= TILE_DIMENSION * (int) direction.x;
|
|
|
|
m->sprite->pos.y -= TILE_DIMENSION * (int) direction.y;
|
|
|
|
return false;
|
2017-12-17 13:43:41 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-18 09:59:01 +01:00
|
|
|
static void
|
|
|
|
monster_drunk_walk(Monster *m, RoomMatrix *rm)
|
2017-12-17 13:43:41 +01:00
|
|
|
{
|
|
|
|
unsigned int i, maxMoveAttempts = 6;
|
|
|
|
|
2017-12-18 12:12:24 +01:00
|
|
|
if (get_random(5) >= 2)
|
2017-12-17 13:43:41 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < maxMoveAttempts; ++i) {
|
2018-05-13 23:32:44 +02:00
|
|
|
int moveDir = get_random(3);
|
|
|
|
if (moveDir == 0 && move(m, rm, VECTOR2D_LEFT))
|
2017-12-17 13:43:41 +01:00
|
|
|
break;
|
2018-05-13 23:32:44 +02:00
|
|
|
else if (moveDir == 1 && move(m, rm, VECTOR2D_RIGHT))
|
2017-12-17 13:43:41 +01:00
|
|
|
break;
|
2018-05-13 23:32:44 +02:00
|
|
|
else if (moveDir == 2 && move(m, rm, VECTOR2D_UP))
|
2017-12-17 13:43:41 +01:00
|
|
|
break;
|
2018-05-13 23:32:44 +02:00
|
|
|
else if (moveDir == 3 && move(m, rm, VECTOR2D_DOWN))
|
2017-12-17 13:43:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-12-18 09:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
|
|
|
{
|
|
|
|
int x_dist, y_dist;
|
|
|
|
Position mPos;
|
|
|
|
|
|
|
|
mPos = position_to_matrix_coords(&m->sprite->pos);
|
|
|
|
|
2018-03-03 12:56:53 +01:00
|
|
|
unsigned int currentScore = 100;
|
|
|
|
unsigned int chosenDirection = UP;
|
2017-12-18 09:59:01 +01:00
|
|
|
|
2018-03-03 12:56:53 +01:00
|
|
|
for (unsigned int i = 0; i < 4; ++i) {
|
|
|
|
Position next = mPos;
|
|
|
|
unsigned int nextScore = 0;
|
2017-12-18 09:59:01 +01:00
|
|
|
|
2018-03-03 12:56:53 +01:00
|
|
|
switch (i) {
|
|
|
|
case UP:
|
|
|
|
next.y -= 1;
|
|
|
|
break;
|
|
|
|
case DOWN:
|
|
|
|
next.y += 1;
|
|
|
|
break;
|
|
|
|
case LEFT:
|
|
|
|
next.x -= 1;
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
next.x += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (position_equals(&next, &rm->playerRoomPos)) {
|
|
|
|
chosenDirection = (Direction) i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!position_in_roommatrix(&next))
|
|
|
|
continue;
|
|
|
|
|
2018-03-03 13:33:14 +01:00
|
|
|
x_dist = abs(next.x - rm->playerRoomPos.x);
|
|
|
|
y_dist = abs(next.y - rm->playerRoomPos.y);
|
2018-03-03 12:56:53 +01:00
|
|
|
|
2018-03-25 23:30:26 +02:00
|
|
|
if (rm->spaces[next.x][next.y].occupied || rm->spaces[next.x][next.y].lethal) {
|
2018-03-03 12:56:53 +01:00
|
|
|
nextScore += 50;
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:33:14 +01:00
|
|
|
nextScore += x_dist > y_dist ? x_dist : y_dist;
|
2018-03-03 12:56:53 +01:00
|
|
|
if (nextScore < currentScore) {
|
|
|
|
currentScore = nextScore;
|
|
|
|
chosenDirection = (Direction)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (chosenDirection) {
|
|
|
|
case UP:
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_UP);
|
2018-03-03 12:56:53 +01:00
|
|
|
break;
|
|
|
|
case DOWN:
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_DOWN);
|
2018-03-03 12:56:53 +01:00
|
|
|
break;
|
|
|
|
case LEFT:
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_LEFT);
|
2018-03-03 12:56:53 +01:00
|
|
|
break;
|
|
|
|
case RIGHT:
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_RIGHT);
|
2018-03-03 12:56:53 +01:00
|
|
|
break;
|
2017-12-18 09:59:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monster_coward_walk(Monster *m, RoomMatrix *rm)
|
|
|
|
{
|
|
|
|
int x_dist, y_dist;
|
|
|
|
Position mPos;
|
|
|
|
|
|
|
|
mPos = position_to_matrix_coords(&m->sprite->pos);
|
|
|
|
|
|
|
|
x_dist = mPos.x - rm->playerRoomPos.x;
|
|
|
|
y_dist = mPos.y - rm->playerRoomPos.y;
|
|
|
|
|
|
|
|
|
|
|
|
if (abs(x_dist) > abs(y_dist)) {
|
|
|
|
if (x_dist > 0)
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_RIGHT);
|
2017-12-18 09:59:01 +01:00
|
|
|
else
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_LEFT);
|
2017-12-18 09:59:01 +01:00
|
|
|
} else {
|
|
|
|
if (y_dist > 0)
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_DOWN);
|
2017-12-18 09:59:01 +01:00
|
|
|
else
|
2018-05-13 23:32:44 +02:00
|
|
|
move(m, rm, VECTOR2D_UP);
|
2017-12-18 09:59:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 15:09:04 +01:00
|
|
|
bool
|
2017-12-18 09:59:01 +01:00
|
|
|
monster_move(Monster *m, RoomMatrix *rm)
|
|
|
|
{
|
|
|
|
Position monsterRoomPos;
|
|
|
|
|
2018-05-21 21:03:59 +02:00
|
|
|
monster_behaviour_check(m, rm);
|
|
|
|
|
2017-12-18 09:59:01 +01:00
|
|
|
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
|
|
|
|
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = false;
|
|
|
|
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = NULL;
|
|
|
|
|
2017-12-18 12:12:24 +01:00
|
|
|
switch (m->state.current) {
|
2017-12-18 09:59:01 +01:00
|
|
|
case PASSIVE:
|
|
|
|
monster_drunk_walk(m, rm);
|
|
|
|
break;
|
|
|
|
case AGRESSIVE:
|
|
|
|
monster_agressive_walk(m, rm);
|
|
|
|
break;
|
2017-12-18 12:12:24 +01:00
|
|
|
case SCARED:
|
2017-12-18 09:59:01 +01:00
|
|
|
monster_coward_walk(m, rm);
|
|
|
|
break;
|
2018-05-19 17:55:10 +02:00
|
|
|
case STATIONARY:
|
2018-05-21 21:03:59 +02:00
|
|
|
case SLEEPING:
|
|
|
|
case SCANNING:
|
2018-05-19 17:55:10 +02:00
|
|
|
default:
|
|
|
|
break;
|
2017-12-18 09:59:01 +01:00
|
|
|
};
|
2017-12-17 13:43:41 +01:00
|
|
|
|
|
|
|
monster_update_pos(m, m->sprite->pos);
|
|
|
|
|
|
|
|
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
|
|
|
|
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = true;
|
|
|
|
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = m;
|
2018-02-19 15:09:04 +01:00
|
|
|
|
|
|
|
m->steps++;
|
|
|
|
if (m->steps >= m->stats.speed) {
|
2018-05-17 21:41:23 +02:00
|
|
|
if (m->stateIndicator.displayCount > 0)
|
|
|
|
m->stateIndicator.displayCount -= 1;
|
2018-05-19 17:55:10 +02:00
|
|
|
m->state.stepsSinceChange += 1;
|
2018-02-19 15:09:04 +01:00
|
|
|
m->steps = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-15 11:16:56 +02:00
|
|
|
|
2018-02-19 15:09:04 +01:00
|
|
|
return false;
|
2017-12-17 13:43:41 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 11:16:56 +02:00
|
|
|
void
|
|
|
|
monster_update(Monster *m, UpdateData *data)
|
|
|
|
{
|
2018-05-17 21:41:23 +02:00
|
|
|
Position monsterRoomPos = position_to_room_coords(&m->sprite->pos);
|
|
|
|
if (position_equals(&data->matrix->roomPos, &monsterRoomPos)) {
|
|
|
|
if (m->stateIndicator.shownOnPlayerRoomEnter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m->stateIndicator.shownOnPlayerRoomEnter = true;
|
2018-05-21 21:03:59 +02:00
|
|
|
if (m->state.current != PASSIVE && m->state.current != STATIONARY)
|
2018-05-17 21:41:23 +02:00
|
|
|
m->stateIndicator.displayCount = 5;
|
|
|
|
} else {
|
|
|
|
m->stateIndicator.shownOnPlayerRoomEnter = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 12:12:24 +01:00
|
|
|
void
|
|
|
|
monster_hit(Monster *monster, unsigned int dmg)
|
|
|
|
{
|
|
|
|
if (dmg > 0) {
|
2018-02-03 23:39:49 +01:00
|
|
|
Position p = monster->sprite->pos;
|
|
|
|
p.x += 8;
|
|
|
|
p.y += 8;
|
|
|
|
Dimension d = { 8, 8 };
|
2018-02-09 13:55:57 +01:00
|
|
|
particle_engine_bloodspray(p, d, dmg);
|
2018-05-15 14:12:38 +02:00
|
|
|
char msg[10];
|
|
|
|
m_sprintf(msg, 10, "-%d", dmg);
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_create_text(msg,
|
2018-05-15 23:21:28 +02:00
|
|
|
C_RED,
|
2018-05-15 11:16:56 +02:00
|
|
|
&monster->sprite->pos);
|
2017-12-18 12:12:24 +01:00
|
|
|
} else {
|
2018-05-15 11:16:56 +02:00
|
|
|
actiontextbuilder_create_text("Dodged",
|
2018-05-15 23:21:28 +02:00
|
|
|
C_YELLOW,
|
2018-05-15 11:16:56 +02:00
|
|
|
&monster->sprite->pos);
|
2017-12-18 12:12:24 +01:00
|
|
|
}
|
2018-05-19 17:55:10 +02:00
|
|
|
monster_behaviour_check_post_hit(monster);
|
2017-12-18 12:12:24 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 15:16:14 +01:00
|
|
|
void
|
|
|
|
monster_update_stats_for_level(Monster *m, unsigned int level)
|
|
|
|
{
|
|
|
|
m->stats.lvl = level;
|
|
|
|
m->stats.maxhp *= level;
|
|
|
|
m->stats.hp = m->stats.maxhp;
|
|
|
|
m->stats.dmg *= level;
|
|
|
|
m->stats.atk *= level;
|
|
|
|
m->stats.def *= level;
|
|
|
|
}
|
|
|
|
|
2018-01-29 13:48:44 +01:00
|
|
|
void
|
2018-02-24 21:15:13 +01:00
|
|
|
monster_drop_loot(Monster *monster, Map *map, Player *player)
|
2018-01-25 10:45:05 +01:00
|
|
|
{
|
2018-02-15 14:45:20 +01:00
|
|
|
static unsigned int treasure_drop_chance = 1;
|
2018-02-24 21:15:13 +01:00
|
|
|
|
|
|
|
unsigned int item_drop_chance = 1;
|
2018-01-29 13:48:44 +01:00
|
|
|
Item *item;
|
2018-03-13 16:13:54 +01:00
|
|
|
Item *items[3];
|
2018-01-30 13:44:21 +01:00
|
|
|
unsigned int item_count = 0;
|
2018-03-02 17:07:15 +01:00
|
|
|
bool player_full_health = player->stats.hp >= player->stats.maxhp;
|
2018-02-24 21:15:13 +01:00
|
|
|
|
|
|
|
if (player->stats.hp < player->stats.maxhp / 2)
|
|
|
|
item_drop_chance = 0;
|
2018-01-29 13:48:44 +01:00
|
|
|
|
2018-02-15 14:45:20 +01:00
|
|
|
if (get_random(treasure_drop_chance) == 0) {
|
2018-01-31 09:15:33 +01:00
|
|
|
item = item_builder_build_item(TREASURE, map->level);
|
2018-01-29 13:48:44 +01:00
|
|
|
item->sprite->pos = monster->sprite->pos;
|
2018-01-30 13:44:21 +01:00
|
|
|
items[item_count++] = item;
|
2018-01-29 13:48:44 +01:00
|
|
|
}
|
2018-02-15 14:45:20 +01:00
|
|
|
if (get_random(item_drop_chance) == 0) {
|
2018-02-24 21:15:13 +01:00
|
|
|
ItemKey key;
|
2018-03-13 16:13:54 +01:00
|
|
|
key = get_random(DAGGER);
|
2018-02-24 21:15:13 +01:00
|
|
|
item = item_builder_build_item(key, map->level);
|
2018-01-29 13:48:44 +01:00
|
|
|
item->sprite->pos = monster->sprite->pos;
|
2018-01-30 13:44:21 +01:00
|
|
|
items[item_count++] = item;
|
2018-01-29 13:48:44 +01:00
|
|
|
}
|
2018-03-13 16:13:54 +01:00
|
|
|
if (!player_full_health && get_random(2) == 0) {
|
|
|
|
item = item_builder_build_item(FLESH, map->level);
|
|
|
|
item->sprite->pos = monster->sprite->pos;
|
|
|
|
items[item_count++] = item;
|
|
|
|
}
|
2018-01-25 10:45:05 +01:00
|
|
|
|
2018-01-30 13:44:21 +01:00
|
|
|
if (item_count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gui_log("%s dropped something", monster->label);
|
|
|
|
|
|
|
|
if (item_count == 1) {
|
|
|
|
linkedlist_append(&map->items, items[0]);
|
|
|
|
} else {
|
|
|
|
Item *container = item_builder_build_sack();
|
|
|
|
container->sprite->pos = monster->sprite->pos;
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < item_count; ++i) {
|
|
|
|
linkedlist_append(&container->items, items[i]);
|
|
|
|
}
|
|
|
|
linkedlist_append(&map->items, container);
|
|
|
|
}
|
2018-01-25 10:45:05 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 20:31:04 +01:00
|
|
|
void
|
|
|
|
monster_render(Monster *m, Camera *cam)
|
|
|
|
{
|
2018-05-17 23:14:42 +02:00
|
|
|
if (m->stats.hp <= 0)
|
|
|
|
return;
|
|
|
|
|
2017-12-13 20:31:04 +01:00
|
|
|
sprite_render(m->sprite, cam);
|
2018-05-17 21:41:23 +02:00
|
|
|
if (m->stateIndicator.displayCount > 0)
|
|
|
|
sprite_render(m->stateIndicator.sprite, cam);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-05-19 17:55:10 +02:00
|
|
|
monster_set_behaviour(Monster *m, MonsterBehaviour behaviour)
|
2018-05-17 21:41:23 +02:00
|
|
|
{
|
2018-05-19 17:55:10 +02:00
|
|
|
m->behaviour = behaviour;
|
|
|
|
switch (behaviour) {
|
|
|
|
case HOSTILE:
|
|
|
|
case GUERILLA:
|
|
|
|
case COWARD:
|
|
|
|
m->state.current = AGRESSIVE;
|
|
|
|
break;
|
2018-05-21 21:03:59 +02:00
|
|
|
case SENTINEL:
|
|
|
|
m->state.current = SLEEPING;
|
|
|
|
break;
|
2018-05-19 17:55:10 +02:00
|
|
|
case PACIFIST:
|
|
|
|
case NORMAL:
|
|
|
|
default:
|
|
|
|
m->state.current = PASSIVE;
|
|
|
|
break;
|
|
|
|
}
|
2018-05-17 21:41:23 +02:00
|
|
|
monster_set_sprite_clip_for_current_state(m);
|
2017-12-13 20:31:04 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 14:26:30 +01:00
|
|
|
void
|
|
|
|
monster_destroy(Monster *m)
|
|
|
|
{
|
|
|
|
sprite_destroy(m->sprite);
|
2018-01-17 09:32:49 +01:00
|
|
|
if (m->label)
|
|
|
|
free(m->label);
|
2018-01-25 10:45:05 +01:00
|
|
|
if (m->lclabel)
|
|
|
|
free(m->lclabel);
|
2018-05-17 21:41:23 +02:00
|
|
|
sprite_destroy(m->stateIndicator.sprite);
|
2017-12-13 14:26:30 +01:00
|
|
|
free(m);
|
|
|
|
}
|