Skip to content
Snippets Groups Projects
Commit 3198d513 authored by Jake Feddersen's avatar Jake Feddersen
Browse files

Finish 1.09

parent 85fab53c
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <string>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
...@@ -72,6 +73,10 @@ char item::get_symbol() { ...@@ -72,6 +73,10 @@ char item::get_symbol() {
return desc->get_symbol(); return desc->get_symbol();
} }
std::string item::get_name() {
return desc->get_name() + " - Speed:" + std::to_string(speed) + " Damage:" + damage->to_string();
}
monster::monster(uint8_t x, uint8_t y, monster_description *desc, int speed, uint32_t abilities, int hitpoints, dice *damage, char symbol) : character(speed, symbol, hitpoints) { monster::monster(uint8_t x, uint8_t y, monster_description *desc, int speed, uint32_t abilities, int hitpoints, dice *damage, char symbol) : character(speed, symbol, hitpoints) {
this->desc = desc; this->desc = desc;
desc->instances++; desc->instances++;
...@@ -99,6 +104,22 @@ void monster::die() { ...@@ -99,6 +104,22 @@ void monster::die() {
desc->invalidate(); desc->invalidate();
} }
int monster::get_speed() {
return speed;
}
int monster::get_damage() {
return damage->roll();
}
std::string monster::get_name() {
return desc->name + " - Speed:" + std::to_string(speed) + " Damage:" + damage->to_string() + " Hitpoints:" + std::to_string(hitpoints);
}
monster_description *monster::get_description() {
return desc;
}
int monster::next_color() { int monster::next_color() {
color_index++; color_index++;
color_index = (color_index % desc->color.size()); color_index = (color_index % desc->color.size());
...@@ -221,7 +242,7 @@ position monster::monster_move(dungeon &d) { ...@@ -221,7 +242,7 @@ position monster::monster_move(dungeon &d) {
return pos; return pos;
} }
player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 100) { player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 1000) {
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
...@@ -234,6 +255,18 @@ player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 10 ...@@ -234,6 +255,18 @@ player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 10
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
inventory[i] = 0; inventory[i] = 0;
} }
base_attack = new dice(0, 1, 4);
}
player_character::~player_character() {
delete base_attack;
for (int i = 0; i < 10; i++) {
if (inventory[i]) delete inventory[i];
}
for (int i = 0; i < 12; i++) {
if (equipment[i]) delete equipment[i];
}
} }
bool player_character::is_player() { bool player_character::is_player() {
...@@ -248,6 +281,28 @@ int player_character::next_color() { ...@@ -248,6 +281,28 @@ int player_character::next_color() {
return COLOR_WHITE; return COLOR_WHITE;
} }
int player_character::get_speed() {
int result = speed;
for (int i = 0; i < 12; i++) {
if (equipment[i]) result += equipment[i]->speed;
}
return std::max(result, 1);
}
int player_character::get_damage() {
int result = base_attack->roll();
if (equipment[0]) result = equipment[0]->damage->roll();
for (int i = 1; i < 12; i++) {
if (equipment[i]) result += equipment[i]->damage->roll();
}
return result;
}
int player_character::pick_up(std::vector<item *> &floor) { int player_character::pick_up(std::vector<item *> &floor) {
int i, j, k; int i, j, k;
...@@ -284,13 +339,13 @@ int player_character::pick_up(std::vector<item *> &floor) { ...@@ -284,13 +339,13 @@ int player_character::pick_up(std::vector<item *> &floor) {
for (i = top; i <= bottom; i++) { for (i = top; i <= bottom; i++) {
int row = 9 + ((i - top) * 2); int row = 9 + ((i - top) * 2);
if (i == k) { if (i == k) {
mvprintw(row, 28, "*"); mvprintw(row, 4, "*");
} }
move(row, 30); move(row, 6);
print_char(floor[i]->get_symbol(), floor[i]->get_color()); print_char(floor[i]->get_symbol(), floor[i]->get_color());
mvprintw(row, 32, floor[i]->desc->get_name().c_str()); mvprintw(row, 8, floor[i]->get_name().c_str());
} }
} }
...@@ -344,7 +399,7 @@ int player_character::print_inventory(const char *prompt) { ...@@ -344,7 +399,7 @@ int player_character::print_inventory(const char *prompt) {
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
if (inventory[i]) { if (inventory[i]) {
mvprintw(4+i, 4, "%c) %s\t%s", (char)('0'+i), inventory[i]->desc->get_type_name(), inventory[i]->desc->get_name().c_str()); mvprintw(4+i, 4, "%c) %s\t%s", (char)('0'+i), inventory[i]->desc->get_type_name(), inventory[i]->get_name().c_str());
} else { } else {
mvprintw(4+i, 4, "%c) <empty>", (char)('0'+i)); mvprintw(4+i, 4, "%c) <empty>", (char)('0'+i));
} }
...@@ -368,9 +423,9 @@ int player_character::print_equipment(const char *prompt) { ...@@ -368,9 +423,9 @@ int player_character::print_equipment(const char *prompt) {
for (i = 0; i < 12; i++) { for (i = 0; i < 12; i++) {
if (equipment[i]) { if (equipment[i]) {
mvprintw(4+i, 4, "%c) %s\t%s", (char)('0'+i), equipment[i]->desc->get_type_name(), equipment[i]->desc->get_name().c_str()); mvprintw(4+i, 4, "%c) %s\t%s", (char)('a'+i), equipment[i]->desc->get_type_name(), equipment[i]->get_name().c_str());
} else { } else {
mvprintw(4+i, 4, "%c) %s\t<empty>", (char)('0'+i), equipment_slot_names[i]); mvprintw(4+i, 4, "%c) %s\t<empty>", (char)('a'+i), equipment_slot_names[i]);
} }
} }
...@@ -464,8 +519,8 @@ void player_character::expunge() { ...@@ -464,8 +519,8 @@ void player_character::expunge() {
int slot = print_inventory("Select an item to expunge, or ESC to cancel:"); int slot = print_inventory("Select an item to expunge, or ESC to cancel:");
if (!(slot >= '0' && slot <= '9')) return; if (!(slot >= '0' && slot <= '9')) return;
item *item_to_destroy = equipment[slot-'0']; item *item_to_destroy = inventory[slot-'0'];
equipment[slot-'0'] = 0; inventory[slot-'0'] = 0;
delete item_to_destroy; delete item_to_destroy;
} }
...@@ -478,10 +533,24 @@ void player_character::list_equipment() { ...@@ -478,10 +533,24 @@ void player_character::list_equipment() {
} }
void player_character::inspect_item() { void player_character::inspect_item() {
int i, j;
int slot = print_inventory("Select an item to inspect, or ESC to cancel:"); int slot = print_inventory("Select an item to inspect, or ESC to cancel:");
if (!(slot >= '0' && slot <= '9')) return; if (!(slot >= '0' && slot <= '9')) return;
//item *item_to_inspect = equipment[slot-'0']; item *item_to_inspect = inventory[slot-'0'];
for (i = 2; i < 21; i++) {
for (j = 1; j < 79; j++) {
mvaddch(i, j, ' ');
}
}
mvprintw(2, 2, "%s", item_to_inspect->get_name().c_str());
mvprintw(4, 0, "%s", item_to_inspect->desc->get_description().c_str());
while((getch() == -1));
} }
void init_character_turn_heap(heap_t *h) { void init_character_turn_heap(heap_t *h) {
......
...@@ -39,6 +39,7 @@ class item { ...@@ -39,6 +39,7 @@ class item {
int get_color(); int get_color();
char get_symbol(); char get_symbol();
std::string get_name();
}; };
class character { class character {
...@@ -57,6 +58,9 @@ class character { ...@@ -57,6 +58,9 @@ class character {
virtual bool is_player() = 0; virtual bool is_player() = 0;
virtual int has_characteristic(int bit) = 0; virtual int has_characteristic(int bit) = 0;
virtual int next_color() = 0; virtual int next_color() = 0;
virtual int get_speed() = 0;
virtual int get_damage() = 0;
}; };
class player_character : public character { class player_character : public character {
...@@ -66,8 +70,11 @@ class player_character : public character { ...@@ -66,8 +70,11 @@ class player_character : public character {
int print_inventory(const char *prompt); int print_inventory(const char *prompt);
int print_equipment(const char *prompt); int print_equipment(const char *prompt);
dice *base_attack;
public: public:
player_character(uint8_t x, uint8_t y); player_character(uint8_t x, uint8_t y);
~player_character();
bool is_player(); bool is_player();
int has_characteristic(int bit); int has_characteristic(int bit);
...@@ -82,6 +89,9 @@ class player_character : public character { ...@@ -82,6 +89,9 @@ class player_character : public character {
void list_inventory(); void list_inventory();
void list_equipment(); void list_equipment();
void inspect_item(); void inspect_item();
int get_speed();
int get_damage();
}; };
class monster : public character { class monster : public character {
...@@ -110,6 +120,13 @@ class monster : public character { ...@@ -110,6 +120,13 @@ class monster : public character {
int next_color(); int next_color();
void die(); void die();
monster_description *get_description();
std::string get_name();
int get_speed();
int get_damage();
}; };
void init_character_turn_heap(heap_t *h); void init_character_turn_heap(heap_t *h);
......
...@@ -24,6 +24,11 @@ std::ostream &dice::print(std::ostream &o) ...@@ -24,6 +24,11 @@ std::ostream &dice::print(std::ostream &o)
return o << base << '+' << number << 'd' << sides; return o << base << '+' << number << 'd' << sides;
} }
std::string dice::to_string()
{
return std::to_string(base) + "+" + std::to_string(number) + "d" + std::to_string(sides);
}
std::ostream &operator<<(std::ostream &o, dice &d) std::ostream &operator<<(std::ostream &o, dice &d)
{ {
return d.print(o); return d.print(o);
......
...@@ -35,6 +35,7 @@ class dice { ...@@ -35,6 +35,7 @@ class dice {
this->sides = sides; this->sides = sides;
} }
int32_t roll(void) const; int32_t roll(void) const;
std::string to_string();
std::ostream &print(std::ostream &o); std::ostream &print(std::ostream &o);
inline int32_t get_base() const inline int32_t get_base() const
{ {
......
...@@ -140,6 +140,7 @@ void display_lose() { ...@@ -140,6 +140,7 @@ void display_lose() {
attron(COLOR_PAIR(COLOR_WHITE)); attron(COLOR_PAIR(COLOR_WHITE));
int i; int i;
clear();
for (i = 0; i < 23; i++) { for (i = 0; i < 23; i++) {
mvaddstr(i, 0, lose_string[i]); mvaddstr(i, 0, lose_string[i]);
} }
......
...@@ -39,6 +39,7 @@ room::room() { ...@@ -39,6 +39,7 @@ room::room() {
dungeon::dungeon() { dungeon::dungeon() {
fog_of_war = true; fog_of_war = true;
target_mode = false; target_mode = false;
look_mode = false;
int i, j; int i, j;
for (i = 0; i < MAP_HEIGHT; i++) { for (i = 0; i < MAP_HEIGHT; i++) {
...@@ -526,6 +527,92 @@ int dungeon::targeting_mode() { ...@@ -526,6 +527,92 @@ int dungeon::targeting_mode() {
} }
} }
void dungeon::look_at_monsters() {
targeting_pointer.x = player_pos.x;
targeting_pointer.y = player_pos.y;
look_mode = true;
draw();
refresh_screen();
while (true) {
char key = getch();
if (key == '7' || key == 'y') {
targeting_pointer.x--;
targeting_pointer.y--;
}
if (key == '8' || key == 'k') {
targeting_pointer.y--;
}
if (key == '9' || key == 'u') {
targeting_pointer.y--;
targeting_pointer.x++;
}
if (key == '6' || key == 'l') {
targeting_pointer.x++;
}
if (key == '3' || key == 'n') {
targeting_pointer.x++;
targeting_pointer.y++;
}
if (key == '2' || key == 'j') {
targeting_pointer.y++;
}
if (key == '1' || key == 'b') {
targeting_pointer.x--;
targeting_pointer.y++;
}
if (key == '4' || key == 'h') {
targeting_pointer.x--;
}
if (key == 't') {
if (targeting_pointer.x == player_pos.x && targeting_pointer.y == player_pos.y) {
look_mode = false;
return;
}
if ((!fog_of_war || pc_sight[targeting_pointer.y][targeting_pointer.x]) && characters[targeting_pointer.y][targeting_pointer.x]) {
int i, j;
for (i = 2; i < 21; i++) {
for (j = 1; j < 79; j++) {
mvaddch(i, j, ' ');
}
}
monster *m = (monster *)characters[targeting_pointer.y][targeting_pointer.x];
mvprintw(2, 2, "%s", m->get_name().c_str());
mvprintw(4, 0, "%s", m->get_description()->description.c_str());
while((getch() == -1));
}
look_mode = false;
return;
}
targeting_pointer.x = std::max((int)targeting_pointer.x, 1);
targeting_pointer.x = std::min((int)targeting_pointer.x, MAP_WIDTH-2);
targeting_pointer.y = std::max((int)targeting_pointer.y, 1);
targeting_pointer.y = std::min((int)targeting_pointer.y, MAP_HEIGHT-2);
draw();
refresh_screen();
}
}
int dungeon::display_monster_list() { int dungeon::display_monster_list() {
attron(COLOR_PAIR(COLOR_WHITE)); attron(COLOR_PAIR(COLOR_WHITE));
...@@ -637,6 +724,11 @@ void dungeon::draw_map_char(int y, int x) { ...@@ -637,6 +724,11 @@ void dungeon::draw_map_char(int y, int x) {
bool disp_fog_of_war = !target_mode && fog_of_war; bool disp_fog_of_war = !target_mode && fog_of_war;
if ((target_mode || look_mode) && y == targeting_pointer.y && x == targeting_pointer.x) {
print_char('*', COLOR_WHITE);
return;
}
if (disp_fog_of_war && !fow_map[y][x]) { if (disp_fog_of_war && !fow_map[y][x]) {
print_char(' ', COLOR_WHITE); print_char(' ', COLOR_WHITE);
return; return;
...@@ -670,11 +762,6 @@ void dungeon::draw_map_char(int y, int x) { ...@@ -670,11 +762,6 @@ void dungeon::draw_map_char(int y, int x) {
} }
if (pc_sight[y][x] || !disp_fog_of_war) { if (pc_sight[y][x] || !disp_fog_of_war) {
if (target_mode && y == targeting_pointer.y && x == targeting_pointer.x) {
print_char('*', COLOR_WHITE);
return;
}
if (characters[y][x]) { if (characters[y][x]) {
int color = characters[y][x]->next_color(); int color = characters[y][x]->next_color();
print_char(characters[y][x]->symbol, color); print_char(characters[y][x]->symbol, color);
...@@ -742,4 +829,12 @@ void dungeon::draw() { ...@@ -742,4 +829,12 @@ void dungeon::draw() {
draw_map_char(i, j); draw_map_char(i, j);
} }
} }
move(22, 0);
clrtoeol();
move(23, 0);
clrtoeol();
mvprintw(22, 0, "Player HP: %d", characters[player_pos.y][player_pos.x]->hitpoints);
mvprintw(23, 0, "Player Speed: %d", characters[player_pos.y][player_pos.x]->get_speed());
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#define MAX_ROOMS 12 #define MAX_ROOMS 12
#define MIN_ROOMS 6 #define MIN_ROOMS 6
#define ITEMS_PER_LEVEL 2000 #define ITEMS_PER_LEVEL 20
class character; class character;
...@@ -60,6 +60,7 @@ class dungeon { ...@@ -60,6 +60,7 @@ class dungeon {
uint8_t fow_map[MAP_HEIGHT][MAP_WIDTH]; uint8_t fow_map[MAP_HEIGHT][MAP_WIDTH];
bool target_mode; bool target_mode;
bool look_mode;
position targeting_pointer; position targeting_pointer;
void generate_rooms(); void generate_rooms();
...@@ -88,6 +89,7 @@ class dungeon { ...@@ -88,6 +89,7 @@ class dungeon {
int targeting_mode(); int targeting_mode();
int display_monster_list(); int display_monster_list();
void look_at_monsters();
}; };
#endif #endif
...@@ -10,26 +10,26 @@ ...@@ -10,26 +10,26 @@
// Not perfect, but does a decent job of line of sight // Not perfect, but does a decent job of line of sight
static uint8_t plot_line_low(int x0, int y0, int x1, int y1, dungeon &d) { static uint8_t plot_line_low(int x0, int y0, int x1, int y1, dungeon &d) {
int dx = x1 - x0; int dx = x1 - x0;
int dy = y1 - y0; int dy = y1 - y0;
int yi = 1; int yi = 1;
if (dy < 0) { if (dy < 0) {
yi = -1; yi = -1;
dy = -dy; dy = -dy;
} }
int D = 2*dy - dx; int D = 2*dy - dx;
int y = y0; int y = y0;
int x; int x;
for (x = x0; x != x1; x += sign(x1-x0)) { for (x = x0; x != x1; x += sign(x1-x0)) {
if (d.hardness[y][x]) return 0; if (d.hardness[y][x]) return 0;
if (D > 0) { if (D > 0) {
y = y + yi; y = y + yi;
D = D - 2*dx; D = D - 2*dx;
} }
D = D + 2*dy; D = D + 2*dy;
} }
return 1; return 1;
} }
static uint8_t plot_line_high(int x0, int y0, int x1, int y1, dungeon &d) { static uint8_t plot_line_high(int x0, int y0, int x1, int y1, dungeon &d) {
...@@ -39,67 +39,67 @@ static uint8_t plot_line_high(int x0, int y0, int x1, int y1, dungeon &d) { ...@@ -39,67 +39,67 @@ static uint8_t plot_line_high(int x0, int y0, int x1, int y1, dungeon &d) {
if (dx < 0) { if (dx < 0) {
xi = -1; xi = -1;
dx = -dx; dx = -dx;
} }
int D = 2*dx - dy; int D = 2*dx - dy;
int x = x0; int x = x0;
int y; int y;
for (y = y0; y != y1; y += sign(y1-y0)) { for (y = y0; y != y1; y += sign(y1-y0)) {
if (d.hardness[y][x]) return 0; if (d.hardness[y][x]) return 0;
if (D > 0) { if (D > 0) {
x = x + xi; x = x + xi;
D = D - 2*dy; D = D - 2*dy;
} }
D = D + 2*dx; D = D + 2*dx;
} }
return 1; return 1;
} }
static uint8_t test_line(int x0, int y0, int x1, int y1, dungeon &d) { static uint8_t test_line(int x0, int y0, int x1, int y1, dungeon &d) {
int i; int i;
// Vertical line // Vertical line
if (x0 == x1) { if (x0 == x1) {
for (i = y0; i != y1; i += sign(y1-y0)) { for (i = y0; i != y1; i += sign(y1-y0)) {
if (d.hardness[i][x1]) return 0; if (d.hardness[i][x1]) return 0;
} }
return 1; return 1;
} }
if (abs(y1 - y0) < abs(x1 - x0)) { if (abs(y1 - y0) < abs(x1 - x0)) {
if (x0 > x1) { if (x0 > x1) {
return plot_line_low(x1, y1, x0, y0, d); return plot_line_low(x1, y1, x0, y0, d);
} else { } else {
return plot_line_low(x0, y0, x1, y1, d); return plot_line_low(x0, y0, x1, y1, d);
} }
} else { } else {
if (y0 > y1) { if (y0 > y1) {
return plot_line_high(x1, y1, x0, y0, d); return plot_line_high(x1, y1, x0, y0, d);
} else { } else {
return plot_line_high(x0, y0, x1, y1, d); return plot_line_high(x0, y0, x1, y1, d);
} }
} }
return 1; return 1;
} }
void calc_line_of_sight(dungeon &d) { void calc_line_of_sight(dungeon &d) {
int i, j; int i, j;
int x = d.player_pos.x; int x = d.player_pos.x;
int y = d.player_pos.y; int y = d.player_pos.y;
for (i = 0; i < MAP_HEIGHT; i++) { for (i = 0; i < MAP_HEIGHT; i++) {
for (j = 0; j < MAP_WIDTH; j++) { for (j = 0; j < MAP_WIDTH; j++) {
d.pc_sight[i][j] = 0; d.pc_sight[i][j] = 0;
} }
} }
for (i = std::max(0, y-VIEW_DIST); i < std::min(MAP_HEIGHT, y+VIEW_DIST+1); i++) { for (i = std::max(0, y-VIEW_DIST); i < std::min(MAP_HEIGHT, y+VIEW_DIST+1); i++) {
for (j = std::max(0, x-VIEW_DIST); j < std::min(MAP_WIDTH, x+VIEW_DIST+1); j++) { for (j = std::max(0, x-VIEW_DIST); j < std::min(MAP_WIDTH, x+VIEW_DIST+1); j++) {
d.pc_sight[i][j] = test_line(j, i, x, y, d); d.pc_sight[i][j] = test_line(j, i, x, y, d);
} }
} }
d.update_fog_of_war(); d.update_fog_of_war();
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "dungeon.h" #include "dungeon.h"
#define VIEW_DIST 2 #define VIEW_DIST 3
void calc_line_of_sight(dungeon &d); void calc_line_of_sight(dungeon &d);
......
...@@ -13,11 +13,23 @@ ...@@ -13,11 +13,23 @@
#include "util.h" #include "util.h"
void regen_dungeon(dungeon &d, heap_t *h, int nummon) { void regen_dungeon(dungeon &d, heap_t *h, int nummon) {
// Save the PC instance
character *c = d.characters[d.player_pos.y][d.player_pos.x];
d.characters[d.player_pos.y][d.player_pos.x] = NULL;
heap_delete(h); heap_delete(h);
d.free_data(); d.free_data();
d.gen_random_dungeon(); d.gen_random_dungeon();
// Delete the new PC that was created
delete d.characters[d.player_pos.y][d.player_pos.x];
// Substitute the old PC
d.characters[d.player_pos.y][d.player_pos.x] = c;
c->pos = d.player_pos;
c->next_turn = 0;
d.gen_monsters(nummon); d.gen_monsters(nummon);
d.gen_items(randrange(10, ITEMS_PER_LEVEL)); d.gen_items(randrange(10, ITEMS_PER_LEVEL));
...@@ -72,15 +84,8 @@ int main(int argc, char* argv[]) { ...@@ -72,15 +84,8 @@ int main(int argc, char* argv[]) {
game_won = 0; game_won = 0;
break; break;
} else { } else {
((monster *)c)->die();
delete c; delete c;
if (h.size == 1) { continue;
// Only one character left and the game isn't over, the player must have won
game_won = 1;
break;
} else {
continue;
}
} }
} }
...@@ -197,7 +202,7 @@ int main(int argc, char* argv[]) { ...@@ -197,7 +202,7 @@ int main(int argc, char* argv[]) {
} }
if (key == 'L') { if (key == 'L') {
//d.look_at_monsters(); d.look_at_monsters();
} }
if (key == 'm') { if (key == 'm') {
...@@ -209,7 +214,7 @@ int main(int argc, char* argv[]) { ...@@ -209,7 +214,7 @@ int main(int argc, char* argv[]) {
refresh_screen(); refresh_screen();
} }
if (key == 't') { if (key == 'g') {
if (d.targeting_mode()) { if (d.targeting_mode()) {
game_won = -1; game_won = -1;
break; break;
...@@ -264,10 +269,56 @@ int main(int argc, char* argv[]) { ...@@ -264,10 +269,56 @@ int main(int argc, char* argv[]) {
if (game_won == -1) { if (game_won == -1) {
break; break;
} }
bool moved = false;
// If we killed another character by moving there // If we are attacking another character
if (d.characters[next_move.y][next_move.x] && d.characters[next_move.y][next_move.x] != c) { if (d.characters[next_move.y][next_move.x] && d.characters[next_move.y][next_move.x] != c) {
d.characters[next_move.y][next_move.x]->alive = 0; moved = true;
character *attacked = d.characters[next_move.y][next_move.x];
if (attacked->is_player() != c->is_player()) {
// Attack!
int damage = c->get_damage();
if (c->is_player()) {
display_message("You smite the %s for %d damage", ((monster*)attacked)->get_description()->name.c_str(), damage);
clear_message = 0;
}
attacked->hitpoints -= damage;
if (attacked->hitpoints < 0) {
if (attacked->is_player()) {
game_won = 0;
break;
} else {
monster *m = (monster *)attacked;
m->die();
m->alive = 0;
d.characters[next_move.y][next_move.x] = NULL;
if (m->has_characteristic(NPC_BOSS)) {
delete m;
game_won = 1;
break;
}
}
}
} else {
// Move the other monster out of the way
d.characters[c->pos.y][c->pos.x] = NULL;
bool found_position = false;
position new_pos;
while (!found_position) {
new_pos.x = randrange(attacked->pos.x - 1, attacked->pos.x + 1);
new_pos.y = randrange(attacked->pos.y - 1, attacked->pos.y + 1);
if (!d.hardness[new_pos.y][new_pos.x] && !d.characters[new_pos.y][new_pos.x]) found_position = true;
}
d.characters[new_pos.y][new_pos.x] = attacked;
attacked->pos = new_pos;
d.characters[next_move.y][next_move.x] = c;
c->pos = next_move;
}
} }
// Check for rock and tunneling // Check for rock and tunneling
...@@ -283,20 +334,20 @@ int main(int argc, char* argv[]) { ...@@ -283,20 +334,20 @@ int main(int argc, char* argv[]) {
} }
// If the space we want to move to has hardness zero, move there // If the space we want to move to has hardness zero, move there
if (d.hardness[next_move.y][next_move.x] == 0) { if (d.hardness[next_move.y][next_move.x] == 0 && !d.characters[next_move.y][next_move.x] && !moved) {
d.characters[c->pos.y][c->pos.x] = NULL; d.characters[c->pos.y][c->pos.x] = NULL;
d.characters[next_move.y][next_move.x] = c; d.characters[next_move.y][next_move.x] = c;
c->pos = next_move; c->pos = next_move;
if (c->is_player()) { if (c->is_player()) {
d.player_pos = next_move; d.player_pos = next_move;
} }
} else if (c->is_player()) { } else if (c->is_player() && d.hardness[next_move.y][next_move.x] != 0) {
display_message("%s", "Ouch, that was a wall."); display_message("%s", "Ouch, that was a wall.");
clear_message = 0; clear_message = 0;
} }
// Update the character's turn and reinsert into heap // Update the character's turn and reinsert into heap
c->next_turn = c->next_turn + (1000 / c->speed); c->next_turn = c->next_turn + (1000 / c->get_speed());
heap_insert(&h, c); heap_insert(&h, c);
// If the player moved, update line of sight, redraw, and sleep for the timestep // If the player moved, update line of sight, redraw, and sleep for the timestep
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment