changes to characters and potions, work in progress
This commit is contained in:
@ -49,6 +49,8 @@ feature proc_args(int argc, char **argv,
|
|||||||
result |= FEATURE_REVISIT;
|
result |= FEATURE_REVISIT;
|
||||||
} else if (str == "-e") {
|
} else if (str == "-e") {
|
||||||
result |= FEATURE_EXTRA_STUFF;
|
result |= FEATURE_EXTRA_STUFF;
|
||||||
|
} else if (str == "-E") {
|
||||||
|
result |= FEATURE_EXTRA_LEVELS;
|
||||||
} else if (str == "-s") {
|
} else if (str == "-s") {
|
||||||
++i;
|
++i;
|
||||||
str = argv[i];
|
str = argv[i];
|
||||||
@ -168,6 +170,7 @@ void panic_args(feature panic) {
|
|||||||
default:
|
default:
|
||||||
cerr << "Something must have went really, really, wrong..."
|
cerr << "Something must have went really, really, wrong..."
|
||||||
<< endl;
|
<< endl;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (panic & FEATURE_PANIC_SEED) {
|
} else if (panic & FEATURE_PANIC_SEED) {
|
||||||
cerr << "Invalid seed" << endl;
|
cerr << "Invalid seed" << endl;
|
||||||
@ -175,3 +178,23 @@ void panic_args(feature panic) {
|
|||||||
cerr << "Something must have went really, really, wrong..."
|
cerr << "Something must have went really, really, wrong..."
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_args_list() {
|
||||||
|
|
||||||
|
|
||||||
|
static const char *ARGS_LIST = "-n : Use ncurses for I/O\n\
|
||||||
|
-r : Randomly generate maps\n\
|
||||||
|
-m : Enabled a main menu + options\n\
|
||||||
|
-c : Enemies chase the player (through doors and up stairs)\n\
|
||||||
|
-i : Enable inventory\n\
|
||||||
|
-t : Enable throw\n\
|
||||||
|
-R : Enable revisiting levels\n\
|
||||||
|
-e : Enable extra potions and races\n\
|
||||||
|
-E : Enable extra levels\n\
|
||||||
|
-s [seed] : Sets initial seed to seed\n\
|
||||||
|
-L [file] : Enable logging to file\n\
|
||||||
|
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.\n\
|
||||||
|
-O [file] : Outputs to file. CANNOT BE USED WITH -n.\n\
|
||||||
|
-h/--help : Displays options list (doesn't start a game)";
|
||||||
|
std::cout << ARGS_LIST << std::endl;
|
||||||
|
}
|
||||||
|
@ -10,22 +10,6 @@
|
|||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
/* Arguments
|
|
||||||
-n : Use ncurses for I/O
|
|
||||||
-r : Randomly generate maps
|
|
||||||
-m : Enabled a main menu + options
|
|
||||||
-c : Enemies chase the player (through doors and up stairs)
|
|
||||||
-i : Enable inventory
|
|
||||||
-t : Enable throw
|
|
||||||
-R : Enable revisiting levels
|
|
||||||
-e : Enable extra potions and races
|
|
||||||
-s [seed] : Sets initial seed to seed
|
|
||||||
-L [file] : Enable logging to file
|
|
||||||
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.
|
|
||||||
-O [file] : Outputs to file. CANNOT BE USED WITH -n.
|
|
||||||
-h/--help : Displays options list (doesn't start a game)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// IMPORTANT: Errors include the index that caused them (or'ed into them)
|
// IMPORTANT: Errors include the index that caused them (or'ed into them)
|
||||||
feature proc_args(int argc, char **argv,
|
feature proc_args(int argc, char **argv,
|
||||||
std::unique_ptr<cursor> &curse,
|
std::unique_ptr<cursor> &curse,
|
||||||
@ -36,4 +20,6 @@ feature proc_args(int argc, char **argv,
|
|||||||
|
|
||||||
void panic_args(feature panic);
|
void panic_args(feature panic);
|
||||||
|
|
||||||
|
void print_args_list();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
character::character(RNG &rng, const enum race &nrace):
|
character::character(RNG *rng, const enum race &nrace):
|
||||||
rng{rng},
|
rng{rng},
|
||||||
race{nrace}, HP{STARTING_HP[race]},
|
race{nrace}, HP{STARTING_HP[race]},
|
||||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {}
|
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]},
|
||||||
|
base_hit_rate{1, 1} {}
|
||||||
|
|
||||||
|
void character::start_turn() {
|
||||||
|
ATK = STARTING_ATK[race];
|
||||||
|
DEF = STARTING_DEF[race];
|
||||||
|
base_hit_rate = {1, 1};
|
||||||
|
}
|
||||||
|
|
||||||
enum race character::get_race() const {
|
enum race character::get_race() const {
|
||||||
return race;
|
return race;
|
||||||
@ -31,7 +38,11 @@ int character::get_gold() const {
|
|||||||
return gold;
|
return gold;
|
||||||
}
|
}
|
||||||
|
|
||||||
float character::get_hitrate() const {
|
float character::get_hitrate_real() const {
|
||||||
|
return base_hit_rate.real();
|
||||||
|
}
|
||||||
|
|
||||||
|
fraction character::get_hitrate() const {
|
||||||
return base_hit_rate;
|
return base_hit_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +70,7 @@ void character::set_gold(const int ngold) {
|
|||||||
gold = ngold;
|
gold = ngold;
|
||||||
}
|
}
|
||||||
|
|
||||||
void character::set_hitrate(const float nhitrate) {
|
void character::set_hitrate(const fraction nhitrate) {
|
||||||
base_hit_rate = nhitrate;
|
base_hit_rate = nhitrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +116,57 @@ const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result character::apply(direction &dir, const potion_list &potions) {
|
void character::apply(direction &dir, potion_list &plist) {
|
||||||
// TODO: implement this after implementing potions
|
for (size_t i = 0; i < plist.size(); ++i)
|
||||||
|
if (pos + MOVE[dir] == plist[i]->get_pos()) {
|
||||||
|
insert_potion(plist[i]);
|
||||||
|
plist.erase(plist.begin() + i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void character::insert_potion(potion *p) {
|
||||||
|
effects.push_back(p);
|
||||||
|
|
||||||
|
for (int i = effects.size() - 1; i > 0; --i)
|
||||||
|
if (p->get_priority() < effects[i - 1]->get_priority())
|
||||||
|
std::swap(effects[i], effects[i - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
result character::apply_effects() {
|
||||||
|
potion_list tmp;
|
||||||
|
tmp.reserve(effects.size());
|
||||||
|
|
||||||
|
for (auto p : effects) {
|
||||||
|
p->apply(this->race, HP, ATK, DEF, base_hit_rate);
|
||||||
|
|
||||||
|
if (HP <= 0)
|
||||||
|
return result::died;
|
||||||
|
|
||||||
|
if (p->get_duration() != 0)
|
||||||
|
tmp.push_back(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp.shrink_to_fit();
|
||||||
|
|
||||||
|
std::swap(tmp, effects);
|
||||||
|
|
||||||
return result::fine;
|
return result::fine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void character::discard_level_effects() {
|
||||||
|
potion_list tmp;
|
||||||
|
tmp.reserve(effects.size());
|
||||||
|
|
||||||
|
for (auto p : effects)
|
||||||
|
if (p->get_duration() != -1)
|
||||||
|
tmp.push_back(p);
|
||||||
|
|
||||||
|
tmp.shrink_to_fit();
|
||||||
|
|
||||||
|
std::swap(tmp, effects);
|
||||||
|
}
|
||||||
|
|
||||||
// IMPORTANT: remember to check if player is on the stairs
|
// IMPORTANT: remember to check if player is on the stairs
|
||||||
result character::move(const direction dir,
|
result character::move(const direction dir,
|
||||||
const position_list &available_positions) {
|
const position_list &available_positions) {
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "fraction.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "potion.h"
|
#include "potions.h"
|
||||||
#include "gold.h"
|
#include "gold.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
|
|
||||||
// #include "inventory.h" // Reserved for later
|
|
||||||
|
|
||||||
class character; // forward declaration
|
class character; // forward declaration
|
||||||
|
|
||||||
// Note: player should not be in the character list
|
// Note: player should not be in the character list
|
||||||
@ -20,7 +19,7 @@ typedef std::vector<character> character_list;
|
|||||||
|
|
||||||
class character {
|
class character {
|
||||||
public:
|
public:
|
||||||
character(RNG &rng, const race &nrace); // fills out the starting stats
|
character(RNG *rng, const race &nrace); // fills out the starting stats
|
||||||
|
|
||||||
// usually I wouldn't do this but considering that the map has
|
// usually I wouldn't do this but considering that the map has
|
||||||
// a super small size an O(n) solution is acceptable
|
// a super small size an O(n) solution is acceptable
|
||||||
@ -33,10 +32,13 @@ public:
|
|||||||
virtual result move_or_attack(const direction dir,
|
virtual result move_or_attack(const direction dir,
|
||||||
const position_list &available_positions,
|
const position_list &available_positions,
|
||||||
character_list &chlist);
|
character_list &chlist);
|
||||||
virtual result apply(direction &dir,
|
virtual void apply(direction &dir,
|
||||||
const potion_list &potions);
|
potion_list &potions);
|
||||||
virtual result get_hit(const enum race &race, const int atk,
|
virtual result get_hit(const enum race &race, const int atk,
|
||||||
const float hitrate) = 0;
|
const fraction hitrate) = 0;
|
||||||
|
result apply_effects();
|
||||||
|
void discard_level_effects();
|
||||||
|
void start_turn();
|
||||||
|
|
||||||
enum race get_race() const;
|
enum race get_race() const;
|
||||||
position get_position() const;
|
position get_position() const;
|
||||||
@ -44,7 +46,8 @@ public:
|
|||||||
int get_ATK() const;
|
int get_ATK() const;
|
||||||
int get_DEF() const;
|
int get_DEF() const;
|
||||||
int get_gold() const;
|
int get_gold() const;
|
||||||
float get_hitrate() const;
|
float get_hitrate_real() const;
|
||||||
|
fraction get_hitrate() const;
|
||||||
bool is_hostile() const;
|
bool is_hostile() const;
|
||||||
|
|
||||||
void set_position(const position &npos);
|
void set_position(const position &npos);
|
||||||
@ -52,7 +55,7 @@ public:
|
|||||||
void set_ATK(const int nATK);
|
void set_ATK(const int nATK);
|
||||||
void set_DEF(const int nDEF);
|
void set_DEF(const int nDEF);
|
||||||
void set_gold(const int ngold);
|
void set_gold(const int ngold);
|
||||||
void set_hitrate(const float nhitrate);
|
void set_hitrate(const fraction nhitrate);
|
||||||
void set_hostile(const bool is_hostile);
|
void set_hostile(const bool is_hostile);
|
||||||
|
|
||||||
// if stat is hostile, positive to set it to hostile,
|
// if stat is hostile, positive to set it to hostile,
|
||||||
@ -61,7 +64,7 @@ public:
|
|||||||
// void apply_buff(const stat_name statn, const float mul);
|
// void apply_buff(const stat_name statn, const float mul);
|
||||||
// reserved for later
|
// reserved for later
|
||||||
protected:
|
protected:
|
||||||
RNG &rng;
|
RNG *rng;
|
||||||
const enum race race;
|
const enum race race;
|
||||||
|
|
||||||
int HP;
|
int HP;
|
||||||
@ -69,15 +72,17 @@ protected:
|
|||||||
// IMPORTANT: keep track of ATK and DEF in game at turn time
|
// IMPORTANT: keep track of ATK and DEF in game at turn time
|
||||||
int ATK;
|
int ATK;
|
||||||
int DEF;
|
int DEF;
|
||||||
|
fraction base_hit_rate;
|
||||||
|
|
||||||
position pos;
|
position pos;
|
||||||
|
|
||||||
int gold; // characters spawn with gold
|
int gold; // characters spawn with gold
|
||||||
potion_list potions;// inventory inventory; // Reserved
|
potion_list potions; // inventory
|
||||||
|
potion_list effects; // applied potions
|
||||||
float base_hit_rate; // requires: between [0,1]
|
|
||||||
|
|
||||||
bool hostile;
|
bool hostile;
|
||||||
|
private:
|
||||||
|
void insert_potion(potion *p);
|
||||||
};
|
};
|
||||||
|
|
||||||
int calc_dmg(const int ATK, const int DEF);
|
int calc_dmg(const int ATK, const int DEF);
|
||||||
|
@ -93,6 +93,7 @@ const feature FEATURE_MENU = 1 << 8;
|
|||||||
const feature FEATURE_IN_FILE = 1 << 9;
|
const feature FEATURE_IN_FILE = 1 << 9;
|
||||||
const feature FEATURE_OUT_FILE = 1 << 10;
|
const feature FEATURE_OUT_FILE = 1 << 10;
|
||||||
const feature FEATURE_EXTRA_STUFF = 1 << 11;
|
const feature FEATURE_EXTRA_STUFF = 1 << 11;
|
||||||
|
const feature FEATURE_EXTRA_LEVELS = 1 << 12;
|
||||||
|
|
||||||
const feature FEATURE_PANIC_SEED = 1 << 27;
|
const feature FEATURE_PANIC_SEED = 1 << 27;
|
||||||
const feature FEATURE_PANIC_FILE = 1 << 28;
|
const feature FEATURE_PANIC_FILE = 1 << 28;
|
||||||
|
@ -32,7 +32,7 @@ fraction &fraction::simplify() {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fraction::real() {
|
float fraction::real() const {
|
||||||
return (float)numerator / denominator;
|
return (float)numerator / denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ struct fraction final {
|
|||||||
bool operator==(const fraction &frac);
|
bool operator==(const fraction &frac);
|
||||||
bool operator!=(const fraction &frac);
|
bool operator!=(const fraction &frac);
|
||||||
fraction &simplify();
|
fraction &simplify();
|
||||||
float real();
|
float real() const;
|
||||||
private:
|
private:
|
||||||
int gcd(int a, int b);
|
int gcd(int a, int b);
|
||||||
};
|
};
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
goblin::goblin(RNG &rng, const position_list &available_positions):
|
goblin::goblin(RNG *rng, const position_list &available_positions):
|
||||||
character{rng, race::rshade} {
|
character{rng, race::rshade} {
|
||||||
pos = available_positions[rng.rand_under(available_positions.size())];
|
pos = available_positions[rng->rand_under(available_positions.size())];
|
||||||
gold = 0;
|
gold = 0;
|
||||||
hostile = true;
|
hostile = true;
|
||||||
}
|
}
|
||||||
@ -27,8 +27,8 @@ result goblin::attack(const direction dir, character_list &chlist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result goblin::get_hit(const enum race &race, const int atk,
|
result goblin::get_hit(const enum race &race, const int atk,
|
||||||
const float hitrate) {
|
const fraction hitrate) {
|
||||||
if (rng.rand_num() <= hitrate * (float)RAND_MAX)
|
if (rng->trial(hitrate))
|
||||||
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
||||||
|
|
||||||
if (HP == 0)
|
if (HP == 0)
|
||||||
|
@ -6,12 +6,12 @@ const int GAIN_GOLD = 5;
|
|||||||
|
|
||||||
class goblin final: public character {
|
class goblin final: public character {
|
||||||
public:
|
public:
|
||||||
goblin(RNG &rng,
|
goblin(RNG *rng,
|
||||||
const position_list &available_positions);
|
const position_list &available_positions);
|
||||||
virtual result attack(const direction dir,
|
virtual result attack(const direction dir,
|
||||||
character_list &chlist) override;
|
character_list &chlist) override;
|
||||||
virtual result get_hit(const enum race &race, const int atk,
|
virtual result get_hit(const enum race &race, const int atk,
|
||||||
const float hit_rate) override;
|
const fraction hit_rate) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "cc3k.h"
|
#include "cc3k.h"
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
@ -17,6 +19,9 @@ int main(int argc, char **argv) {
|
|||||||
FEATURE_CONFLICT | FEATURE_PANIC_SEED)) {
|
FEATURE_CONFLICT | FEATURE_PANIC_SEED)) {
|
||||||
panic_args(enabled_features);
|
panic_args(enabled_features);
|
||||||
return RETURN_PANICKED;
|
return RETURN_PANICKED;
|
||||||
|
} else if (enabled_features & FEATURE_LIST_ARGS) {
|
||||||
|
print_args_list();
|
||||||
|
return RETURN_FINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CC3K game_proc(enabled_features, *in, *out, *log, *rng);
|
// CC3K game_proc(enabled_features, *in, *out, *log, *rng);
|
||||||
|
31
src/map.cc
31
src/map.cc
@ -87,16 +87,25 @@ game_map::game_map(const std::string &map_data,
|
|||||||
room_data.push_back({0, 0, 0, 0});
|
room_data.push_back({0, 0, 0, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
const position_list game_map::get_available_positions() const {
|
|
||||||
return empty_spots;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool game_map::is_available(const position &pos) const {
|
bool game_map::is_available(const position &pos) const {
|
||||||
|
if (pos.x < 0 || pos.x >= MAP_WIDTH || pos.y < 0 || pos.y >= MAP_HEIGHT)
|
||||||
|
return false;
|
||||||
|
|
||||||
int idx = remap_position(pos);
|
int idx = remap_position(pos);
|
||||||
return map[idx] < MAX_ROOM_CNT || map[idx] == '\\' || map[idx] == '>' ||
|
return map[idx] < MAX_ROOM_CNT || map[idx] == '\\' || map[idx] == '>' ||
|
||||||
map[idx] == '<' || map[idx] == '+' || map[idx] == '#';
|
map[idx] == '<' || map[idx] == '+' || map[idx] == '#';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
position_list game_map::get_available_around(const position &pos) const {
|
||||||
|
position_list result;
|
||||||
|
|
||||||
|
for (int i = 0; i < DIRECTION_CNT; ++i)
|
||||||
|
if (is_available(pos + MOVE[i]))
|
||||||
|
result.push_back(pos + MOVE[i]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void game_map::print(display *out) const {
|
void game_map::print(display *out) const {
|
||||||
for (std::size_t i = 0; i < map.size(); ++i)
|
for (std::size_t i = 0; i < map.size(); ++i)
|
||||||
out->print_char(remap_index(i), map[i] <= 9 ? '.' : map[i],
|
out->print_char(remap_index(i), map[i] <= 9 ? '.' : map[i],
|
||||||
@ -132,6 +141,20 @@ position_list game_map::get_room_list(int idx) const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<position_list> game_map::get_room_list() const {
|
||||||
|
std::vector<position_list> result;
|
||||||
|
result.reserve(room_data.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < room_data.size(); ++i)
|
||||||
|
result.push_back({});
|
||||||
|
|
||||||
|
for (size_t i = 0; i < map.size(); ++i)
|
||||||
|
if (map[i] >= 0 && map[i] < MAX_ROOM_CNT)
|
||||||
|
result[map[i]].push_back(remap_index(i));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<position, int>> game_map::gen_room_dims(RNG *rng) {
|
std::vector<std::pair<position, int>> game_map::gen_room_dims(RNG *rng) {
|
||||||
position_list room_dim_list;
|
position_list room_dim_list;
|
||||||
room_dim_list.reserve(MAX_ROOM_CNT);
|
room_dim_list.reserve(MAX_ROOM_CNT);
|
||||||
|
@ -56,10 +56,11 @@ public:
|
|||||||
game_map(const std::string &map_data, RNG *rng,
|
game_map(const std::string &map_data, RNG *rng,
|
||||||
const feature enabled_features);
|
const feature enabled_features);
|
||||||
|
|
||||||
const position_list get_available_positions() const;
|
|
||||||
bool is_available(const position &pos) const;
|
bool is_available(const position &pos) const;
|
||||||
|
position_list get_available_around(const position &pos) const;
|
||||||
|
|
||||||
position_list get_room_list(int idx) const;
|
position_list get_room_list(int idx) const;
|
||||||
|
std::vector<position_list> get_room_list() const;
|
||||||
// IMPORTANT: always print a map before anything else
|
// IMPORTANT: always print a map before anything else
|
||||||
void print(display *out) const;
|
void print(display *out) const;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "potion.h"
|
#include "potion.h"
|
||||||
|
|
||||||
potion::potion(const potion_type type, const int duration):
|
potion::potion(const potion_type type, const int duration, const position &pos):
|
||||||
type{type}, remaining_duration{duration} {}
|
type{type}, remaining_duration{duration}, pos{pos} {}
|
||||||
|
|
||||||
potion_type potion::get_type() const {
|
potion_type potion::get_type() const {
|
||||||
return type;
|
return type;
|
||||||
@ -10,3 +10,33 @@ potion_type potion::get_type() const {
|
|||||||
int potion::get_duration() const {
|
int potion::get_duration() const {
|
||||||
return remaining_duration;
|
return remaining_duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
position potion::get_pos() const {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void potion::set_pos(const position &npos) {
|
||||||
|
pos = npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
potion::potion(const potion &p):
|
||||||
|
type(p.type), remaining_duration(p.remaining_duration),
|
||||||
|
pos{p.pos} {}
|
||||||
|
|
||||||
|
potion::potion(potion &&p):
|
||||||
|
type(p.type), remaining_duration(p.remaining_duration),
|
||||||
|
pos{p.pos} {}
|
||||||
|
|
||||||
|
potion &potion::operator=(const potion &p) {
|
||||||
|
type = p.type;
|
||||||
|
remaining_duration = p.remaining_duration;
|
||||||
|
pos = p.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
potion &potion::operator=(potion &&p) {
|
||||||
|
type = p.type;
|
||||||
|
remaining_duration = p.remaining_duration;
|
||||||
|
pos = p.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
22
src/potion.h
22
src/potion.h
@ -1,8 +1,9 @@
|
|||||||
#ifndef __POTIONS_H__
|
#ifndef __POTION_H__
|
||||||
#define __POTIONS_H__
|
#define __POTION_H__
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "fraction.h"
|
||||||
|
|
||||||
// IMPORTANT: pop all potions of duration == 0, and when entering a
|
// IMPORTANT: pop all potions of duration == 0, and when entering a
|
||||||
// new level, pop all potions of duration == -1
|
// new level, pop all potions of duration == -1
|
||||||
@ -12,19 +13,26 @@ protected:
|
|||||||
// Use -1 to denote that the effect will last until leaving the level
|
// Use -1 to denote that the effect will last until leaving the level
|
||||||
// Otherwise, use a positive number
|
// Otherwise, use a positive number
|
||||||
// Single use potions have a starting duration of 1
|
// Single use potions have a starting duration of 1
|
||||||
const potion_type type;
|
potion_type type;
|
||||||
int remaining_duration;
|
int remaining_duration;
|
||||||
|
position pos;
|
||||||
public:
|
public:
|
||||||
potion(const potion_type type, const int duration);
|
potion(const potion &p);
|
||||||
|
potion(potion &&p);
|
||||||
|
potion &operator=(const potion &p);
|
||||||
|
potion &operator=(potion &&p);
|
||||||
|
potion(const potion_type type, const int duration, const position &pos);
|
||||||
// apply decrements remaining_duration if it's positive, and
|
// apply decrements remaining_duration if it's positive, and
|
||||||
// won't do anything if it's non-negative
|
// won't do anything if it's non-negative
|
||||||
virtual void apply(enum race &race, int &HP, int &ATK, int &DEF,
|
virtual void apply(const enum race &race, int &HP, int &ATK, int &DEF,
|
||||||
float &base_hit_rate) = 0;
|
fraction &base_hit_rate) = 0;
|
||||||
virtual int get_priority() const = 0;
|
virtual int get_priority() const = 0;
|
||||||
potion_type get_type() const;
|
potion_type get_type() const;
|
||||||
int get_duration() const;
|
int get_duration() const;
|
||||||
|
position get_pos() const;
|
||||||
|
void set_pos(const position &npos);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<potion> potion_list;
|
typedef std::vector<potion *> potion_list;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
restore_health::restore_health():
|
restore_health::restore_health():
|
||||||
potion{potion_type::restore_health, -1} {}
|
potion{potion_type::restore_health, -1, {0, 0}} {}
|
||||||
|
|
||||||
void restore_health::apply(enum race &race, int &HP, int &ATK, int &DEF,
|
void restore_health::apply(const enum race &race, int &HP, int &ATK, int &DEF,
|
||||||
float &base_hit_rate) {
|
fraction &base_hit_rate) {
|
||||||
if (remaining_duration > 0) {
|
if (remaining_duration > 0) {
|
||||||
if (race == rdrow)
|
if (race == rdrow)
|
||||||
HP = std::min(HP + 7, MAX_HP[race]);
|
HP = std::min(HP + 7, MAX_HP[race]);
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
class restore_health final: public potion {
|
class restore_health final: public potion {
|
||||||
public:
|
public:
|
||||||
restore_health();
|
restore_health();
|
||||||
void apply(enum race &race, int &HP, int &ATK, int &DEF,
|
void apply(const enum race &race, int &HP, int &ATK, int &DEF,
|
||||||
float &base_hit_rate) override;
|
fraction &base_hit_rate) override;
|
||||||
int get_priority() const override;
|
int get_priority() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ int RNG::get_curr_rand_num() const {
|
|||||||
return curr_rand_num;
|
return curr_rand_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RNG::trial(fraction &psuccess) {
|
bool RNG::trial(const fraction &psuccess) {
|
||||||
return (rand() % psuccess.denominator) < psuccess.numerator;
|
return (rand() % psuccess.denominator) < psuccess.numerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
unsigned int get_init_seed() const;
|
unsigned int get_init_seed() const;
|
||||||
int get_curr_rand_num() const;
|
int get_curr_rand_num() const;
|
||||||
|
|
||||||
bool trial(fraction &psuccess);
|
bool trial(const fraction &psuccess);
|
||||||
|
|
||||||
bool coin_flip() const;
|
bool coin_flip() const;
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
shade::shade(RNG &rng, const position_list &available_positions):
|
shade::shade(RNG *rng, const position_list &available_positions):
|
||||||
character{rng, race::rshade} {
|
character{rng, race::rshade} {
|
||||||
pos = available_positions[rng.rand_under(available_positions.size())];
|
pos = available_positions[rng->rand_under(available_positions.size())];
|
||||||
gold = 0;
|
gold = 0;
|
||||||
hostile = true;
|
hostile = true;
|
||||||
}
|
}
|
||||||
@ -22,8 +22,8 @@ result shade::attack(const direction dir, character_list &chlist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result shade::get_hit(const enum race &race, const int atk,
|
result shade::get_hit(const enum race &race, const int atk,
|
||||||
const float hitrate) {
|
const fraction hitrate) {
|
||||||
if (rng.rand_num() <= hitrate * (float)RAND_MAX) // This is a hit!
|
if (rng->trial(hitrate)) // This is a hit!
|
||||||
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
||||||
|
|
||||||
if (HP == 0)
|
if (HP == 0)
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
class shade final: public character {
|
class shade final: public character {
|
||||||
public:
|
public:
|
||||||
shade(RNG &rng, const position_list
|
shade(RNG *rng, const position_list
|
||||||
&available_positions); // spawn at a random place
|
&available_positions); // spawn at a random place
|
||||||
virtual result attack(const direction dir,
|
virtual result attack(const direction dir,
|
||||||
character_list &chlist) override;
|
character_list &chlist) override;
|
||||||
virtual result get_hit(const enum race &race, const int atk,
|
virtual result get_hit(const enum race &race, const int atk,
|
||||||
const float hit_rate) override;
|
const fraction hit_rate) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
vampire::vampire(RNG &rng, const position_list &available_positions):
|
vampire::vampire(RNG *rng, const position_list &available_positions):
|
||||||
character{rng, race::rshade} {
|
character{rng, race::rshade} {
|
||||||
pos = available_positions[rng.rand_under(available_positions.size())];
|
pos = available_positions[rng->rand_under(available_positions.size())];
|
||||||
gold = 0;
|
gold = 0;
|
||||||
hostile = true;
|
hostile = true;
|
||||||
}
|
}
|
||||||
@ -27,8 +27,8 @@ result vampire::attack(const direction dir, character_list &chlist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result vampire::get_hit(const enum race &race, const int atk,
|
result vampire::get_hit(const enum race &race, const int atk,
|
||||||
const float hitrate) {
|
const fraction hitrate) {
|
||||||
if (rng.rand_num() <= hitrate * (float)RAND_MAX)
|
if (rng->trial(hitrate))
|
||||||
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
||||||
|
|
||||||
if (HP == 0)
|
if (HP == 0)
|
||||||
|
@ -6,12 +6,12 @@ const int GAIN_HP = 5;
|
|||||||
|
|
||||||
class vampire final: public character {
|
class vampire final: public character {
|
||||||
public:
|
public:
|
||||||
vampire(RNG &rng,
|
vampire(RNG *rng,
|
||||||
const position_list &available_positions);
|
const position_list &available_positions);
|
||||||
virtual result attack(const direction dir,
|
virtual result attack(const direction dir,
|
||||||
character_list &chlist) override;
|
character_list &chlist) override;
|
||||||
virtual result get_hit(const enum race &race, const int atk,
|
virtual result get_hit(const enum race &race, const int atk,
|
||||||
const float hit_rate) override;
|
const fraction hit_rate) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user