added extra enemies

This commit is contained in:
2024-07-18 18:37:01 -04:00
parent 1a9c04ad5a
commit ea691a3bb1
11 changed files with 175 additions and 18 deletions

View File

@ -58,7 +58,7 @@ enum race : int {rshade = 0, rdrow, rvampire, rtroll,
static const char CHAR_REP[RACE_CNT] = {
's', 'd', 'v', 't', 'g', 'H', 'W', 'E', 'O', 'M', 'D', 'L',
't', 'g', 'm', 'b', 'a',
'V', 'S', 'l', 'W', 'h', 'B'
'V', 'S', 'l', 'Z', 'h', 'B'
};
static const int MAX_HP[RACE_CNT] = {
@ -68,13 +68,13 @@ static const int MAX_HP[RACE_CNT] = {
};
static const int STARTING_HP[RACE_CNT] = {
125, 150, 50, 120, 110, 140, 100, 140, 180, 30, 150, 100,
800, 130, 150, 120, 100,
800, 130, 100, 120, 100,
150, 100, 60, 100, 90, 140
};
static const int STARTING_ATK[RACE_CNT] = {
25, 25, 25, 25, 15, 20, 20, 30, 30, 70, 20, 15,
40, 25, 80, 15, 30,
30, 25, 10, 20, 15, 25
40, 25, 70, 15, 30,
30, 25, 10, 20, 15, 20
};
static const int STARTING_DEF[RACE_CNT] = {
25, 15, 25, 15, 20, 20, 30, 10, 25, 5, 20, 20,

View File

@ -8,6 +8,12 @@
#include "enemies/human.h"
#include "enemies/merchant.h"
#include "enemies/orc.h"
#include "enemies/viking.h"
#include "enemies/swordsman.h"
#include "enemies/leprechaun.h"
#include "enemies/witch.h"
#include "enemies/hacker.h"
#include "enemies/baby_dragon.h"
std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
const position &fallback,
@ -23,9 +29,10 @@ std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
fallback, which_room);
}
const int EXCNT = 6;
const int EXCNT = 12;
const race EXCHOICES[EXCNT] = {
rhuman, rdwarf, rhalfling, relf, rorc, rmerchant
rhuman, rdwarf, rhalfling, relf, rorc, rmerchant,
rviking, rswordsman, rleprechaun, rwitch, rhacker, rbaby_dragon
};
const int CNT = 18;
const race CHOICES[CNT] = {
@ -61,32 +68,50 @@ std::unique_ptr<enemy_base> new_enemy(RNG *rng, const position &pos,
case rdwarf:
return make_unique<dwarf>(rng, enabled_features,
pos, which_room);
break;
case rhuman:
return make_unique<human>(rng, enabled_features,
pos, which_room);
break;
case relf:
return make_unique<elf>(rng, enabled_features,
pos, which_room);
break;
case rorc:
return make_unique<orc>(rng, enabled_features,
pos, which_room);
break;
case rmerchant:
return make_unique<merchant>(rng, enabled_features,
pos, which_room);
break;
case rhalfling:
return make_unique<halfling>(rng, enabled_features,
pos, which_room);
break;
case rviking:
return make_unique<viking>(rng, enabled_features,
pos, which_room);
case rswordsman:
return make_unique<swordsman>(rng, enabled_features,
pos, which_room);
case rleprechaun:
return make_unique<leprechaun>(rng, enabled_features,
pos, which_room);
case rwitch:
return make_unique<witch>(rng, enabled_features,
pos, which_room);
case rhacker:
return make_unique<hacker>(rng, enabled_features,
pos, which_room);
case rbaby_dragon:
return make_unique<baby_dragon>(rng, enabled_features,
pos, which_room);
default:
break;

View File

@ -0,0 +1,15 @@
#include "baby_dragon.h"
#include "../constants.h"
baby_dragon::baby_dragon(RNG *rng, const feature enabled_features,
const position &pos, const int gen_room_num):
enemy_base{rng, enabled_features, rbaby_dragon, pos, gen_room_num, "B"} {}
const char *baby_dragon::get_race_name() const {
return "Baby_Dragon";
}
void baby_dragon::apply_effect(std::unique_ptr<potion> effect) {
return;
}

14
src/enemies/baby_dragon.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __BABY_DRAGON_H__
#define __BABY_DRAGON_H__
#include "../enemy.h"
class baby_dragon final: public enemy_base {
public:
baby_dragon(RNG *rng, const feature enabled_features, const position &pos,
const int gen_room_num);
const char *get_race_name() const override;
void apply_effect(std::unique_ptr<potion> effect) override;
};
#endif

40
src/enemies/hacker.cc Normal file
View File

@ -0,0 +1,40 @@
#include "hacker.h"
#include "../constants.h"
hacker::hacker(RNG *rng, const feature enabled_features, const position &pos,
const int gen_room_num):
enemy_base{rng, enabled_features, rhacker, pos, gen_room_num, "h"} {}
const char *hacker::get_race_name() const {
return "Hacker";
}
long_result hacker::get_hit(character *ch, const int tATK,
const fraction &hit_rate) {
if (rng->trial(hit_rate)) {
int tmp = calc_dmg(tATK, DEF);
tmp = tmp > HP ? HP : tmp;
HP -= tmp;
if (HP == 0)
return {result::hit, rand_str()};
return {result::hit, rand_str()};
}
return {miss, rand_str()};
}
std::string hacker::rand_str() {
size_t len = rng->rand_between(RAND_STR_LEN_MIN, RAND_STR_LEN_MAX);
std::string result{""};
for (size_t i = 0; i < len; ++i)
result += static_cast<char>(rng->rand_between(PRINT_CHAR_MIN,
PRINT_CHAR_MAX + 1));
result += ' ';
return result;
}

20
src/enemies/hacker.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __HACKER_H__
#define __HACKER_H__
#include "../enemy.h"
class hacker final: public enemy_base {
static const int RAND_STR_LEN_MIN = 10;
static const int RAND_STR_LEN_MAX = 30;
static const int PRINT_CHAR_MIN = 33;
static const int PRINT_CHAR_MAX = 126;
std::string rand_str();
public:
hacker(RNG *rng, const feature enabled_features, const position &pos,
const int gen_room_num);
const char *get_race_name() const override;
long_result get_hit(character *ch, const int tATK,
const fraction &hit_rate) override;
};
#endif

View File

@ -25,11 +25,13 @@ long_result halfling::get_hit(character *ch, const int tATK,
if (HP == 0)
return {result::hit,
"PC deals " + std::to_string(tmp) +
" damage to " + abbrev + ". " + abbrev +
" is slain by PC. "};
" damage to " + abbrev + " (" +
std::to_string(HP) + " HP). " +
abbrev + " is slain by PC. "};
return {result::hit, "PC deals " +
std::to_string(tmp) + " damage to " + abbrev + ". "};
std::to_string(tmp) + " damage to " + abbrev + " (" +
std::to_string(HP) + " HP). "};
}
return {miss, "PC tried to hit " + abbrev +

27
src/enemies/witch.cc Normal file
View File

@ -0,0 +1,27 @@
#include "witch.h"
#include "../constants.h"
witch::witch(RNG *rng, const feature enabled_features, const position &pos,
const int gen_room_num):
enemy_base{rng, enabled_features, rwitch, pos, gen_room_num, "Z"} {}
const char *witch::get_race_name() const {
return "Witch";
}
long_result witch::attack(character *ch) {
auto res = ch->get_hit(this, ATK, base_hit_rate);
if (res.res == hit && rng->trial(POTION_RATE)) {
res.msg += "W's potion spilled onto PC. ";
potion_type type =
static_cast<potion_type>(rng->rand_under(
(enabled_features & FEATURE_EXTRA_STUFF) ?
POTION_TYPE_CNT :
DEFAULT_POTION_TYPE_CNT));
ch->apply_effect(new_potion(type, {0, 0}));
}
return res;
}

15
src/enemies/witch.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __WITCH_H__
#define __WITCH_H__
#include "../enemy.h"
class witch final: public enemy_base {
constexpr static const fraction POTION_RATE = {1, 5};
public:
witch(RNG *rng, const feature enabled_features, const position &pos,
const int gen_room_num);
const char *get_race_name() const override;
long_result attack(character *ch) override;
};
#endif

View File

@ -75,8 +75,7 @@ long_result enemy_base::get_hit(character *ch, const int tATK,
"PC deals " + std::to_string(tmp) +
" damage to " + abbrev + " (" +
std::to_string(HP) + " HP). " +
abbrev +
" is slain by PC. "};
abbrev + " is slain by PC. "};
return {result::hit, "PC deals " +
std::to_string(tmp) + " damage to " + abbrev + " (" +

View File

@ -92,7 +92,7 @@ game_result game::run() {
in->get_command());
msg = res.msg;
if (!hostile_merchants && res.msg.find('M') != std::string::npos) {
if (!hostile_merchants && res.msg.find(" M ") != std::string::npos) {
hostile_merchants = true;
msg += "PC has angered the merchants. ";
}