dragons will now attack if player goes near its hoard

This commit is contained in:
2024-07-22 17:25:42 -04:00
parent 0780c816b1
commit 87f1b8b2ca
4 changed files with 11 additions and 1 deletions

View File

@ -8,7 +8,7 @@
########## Variables ##########
CXX = g++ # compiler
CXXFLAGS = -std=c++20 -g -Wall -Wold-style-cast -MMD -O0 # compiler flags
CXXFLAGS = -std=c++20 -g -Wall -MMD -O0 # compiler flags
MAKEFILE_NAME = ${firstword ${MAKEFILE_LIST}} # makefile name
SOURCES = $(wildcard *.cc) $(wildcard */*.cc) # source files (*.cc)

View File

@ -26,3 +26,7 @@ int dragon::dies(level *lvl) {
return 0;
}
position dragon::get_guards() const {
return guards;
}

View File

@ -11,6 +11,7 @@ public:
const char *get_race_name() const override;
long_result act(level *lvl, character *pc, bool hostile) override;
int dies(level *lvl) override;
position get_guards() const;
};
#endif

View File

@ -3,6 +3,7 @@
#include "constants.h"
#include "player.h"
#include "level.h"
#include "enemies/dragon.h"
enemy_base::enemy_base(RNG *rng, const feature enabled_features,
const enum race &nrace, const position &pos,
@ -17,6 +18,10 @@ int enemy_base::get_room_num() const {
long_result enemy_base::act(level *lvl, character *pc, bool hostile) {
if (is_adjacent(pos, pc->get_pos()) && hostile)
return attack(pc);
else if (race == DRAGON &&
is_adjacent(static_cast<dragon * >(this)->get_guards(),
pc->get_pos()))
return attack(pc);
if (enabled_features & FEATURE_ENEMIES_CHASE && hostile &&
distance_sqr(pos, pc->get_pos()) <= DIST_THRESHOLD_SQR) {