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

Done with programming for 1.08?...

parent 6e7f72ce
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,24 @@ character::character(int speed, char symbol, int hitpoints) {
character::~character() { }
item::item(object_description *desc, dice *damage, int hit, int dodge, int defence, int weight, int speed, int attribute, int value) :
desc(desc), damage(damage), hit(hit), dodge(dodge), defence(defence), weight(weight), speed(speed), attribute(attribute), value(value) {
desc->instances++;
}
item::~item() {
desc->instances--;
}
int item::get_color() {
return (int)desc->get_color();
}
char item::get_symbol() {
return desc->get_symbol();
}
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;
desc->instances++;
......
......@@ -19,6 +19,7 @@
class dungeon;
class monster_description;
class object_description;
class character {
public:
......@@ -78,4 +79,23 @@ class monster : public character {
void init_character_turn_heap(heap_t *h);
class item {
public:
object_description *desc;
dice *damage;
int hit;
int dodge;
int defence;
int weight;
int speed;
int attribute;
int value;
item(object_description *desc, dice *damage, int hit, int dodge, int defence, int weight, int speed, int attribute, int value);
~item();
int get_color();
char get_symbol();
};
#endif
......@@ -128,6 +128,22 @@ monster *monster_description::make_monster(uint8_t x, uint8_t y) {
return new monster(x, y, this, speed.roll(), abilities, hitpoints.roll(), &damage, symbol);
}
char object_description::get_symbol() {
return object_symbol[type];
}
item *object_description::make_item() {
if (!valid) return 0;
if (artifact && instances > 0) return 0;
if (randrange(0, 99) >= (int)rarity) return 0;
return new item(this, &damage, hit.roll(), dodge.roll(), defence.roll(), weight.roll(), speed.roll(), attribute.roll(), value.roll());
}
void object_description::invalidate() {
valid = false;
}
static inline void eat_whitespace(std::ifstream &f)
{
while (isspace(f.peek())) {
......
......@@ -13,6 +13,7 @@
class dungeon;
class monster;
class item;
uint32_t parse_descriptions(dungeon &d);
uint32_t print_descriptions(dungeon &d);
......@@ -83,12 +84,15 @@ class object_description {
dice hit, damage, dodge, defence, weight, speed, attribute, value;
bool artifact;
uint32_t rarity;
bool valid;
public:
int instances;
public:
object_description() : name(), description(), type(objtype_no_type),
color(0), hit(), damage(),
dodge(), defence(), weight(),
speed(), attribute(), value(),
artifact(false), rarity(0)
artifact(false), rarity(0), valid(true), instances(0)
{
}
void set(const std::string &name,
......@@ -120,8 +124,12 @@ class object_description {
inline const dice &get_speed() const { return speed; }
inline const dice &get_attribute() const { return attribute; }
inline const dice &get_value() const { return value; }
//object *make_object();
inline const bool get_artifact() const { return artifact; }
inline const uint32_t get_rarity() const { return rarity; }
char get_symbol();
item *make_item();
void invalidate();
};
std::ostream &operator<<(std::ostream &o, monster_description &m);
......
......@@ -58,7 +58,7 @@ dungeon::~dungeon() {
}
void dungeon::free_data() {
int i, j;
int i, j, k;
delete [] room_list;
free(upstair_list);
......@@ -71,6 +71,8 @@ void dungeon::free_data() {
delete characters[i][j];
characters[i][j] = NULL;
}
for (k = 0; k < (int)items[i][j].size(); k++) delete items[i][j][k];
items[i][j].clear();
}
}
}
......@@ -155,6 +157,24 @@ void dungeon::gen_monsters(int nummon) {
free(monster_positions);
}
void dungeon::gen_items(int numitems) {
int i;
for (i = 0; i < numitems; i++) {
int x = 0;
int y = 0;
while (hardness[y][x] != 0) {
x = randrange(1, MAP_WIDTH-2);
y = randrange(1, MAP_HEIGHT-2);
}
item *it;
while ((it = object_descriptions[randrange(0, object_descriptions.size()-1)].make_item()) == 0);
items[y][x].push_back(it);
}
}
void dungeon::init_turn_heap(heap_t *h) {
int i, j;
......@@ -662,6 +682,20 @@ void dungeon::draw_map_char(int y, int x) {
}
}
if ((!disp_fog_of_war || fow_map[y][x]) && items[y][x].size() > 0) {
char symbol;
int color;
if (items[y][x].size() > 1) {
symbol = '&';
color = items[y][x][0]->get_color();
} else {
symbol = items[y][x][0]->get_symbol();
color = items[y][x][0]->get_color();
}
print_char(symbol, color);
return;
}
if (disp_fog_of_war) {
print_char(remembered_terrain[y][x], COLOR_WHITE);
return;
......
......@@ -2,6 +2,7 @@
#define DUNGEON_H
#include <cstdint>
#include <vector>
#include "character.h"
#include "descriptions.h"
......@@ -13,6 +14,8 @@
#define MAX_ROOMS 12
#define MIN_ROOMS 6
#define ITEMS_PER_LEVEL 15
class character;
class room {
......@@ -50,6 +53,7 @@ class dungeon {
position player_pos;
character *characters[MAP_HEIGHT][MAP_WIDTH];
std::vector<item *> items[MAP_HEIGHT][MAP_WIDTH];
private:
bool fog_of_war;
......@@ -73,6 +77,7 @@ class dungeon {
void gen_random_dungeon();
void init_turn_heap(heap_t *h);
void gen_monsters(int nummon);
void gen_items(int numitems);
void draw();
......
......@@ -19,6 +19,7 @@ void regen_dungeon(dungeon &d, heap_t *h, int nummon) {
d.gen_random_dungeon();
d.gen_monsters(nummon);
d.gen_items(randrange(10, ITEMS_PER_LEVEL));
d.init_turn_heap(h);
calc_line_of_sight(d);
......@@ -41,6 +42,8 @@ int main(int argc, char* argv[]) {
}
d.gen_monsters(args.nummon);
d.gen_items(randrange(10, ITEMS_PER_LEVEL));
if (args.save) {
save_dungeon(d);
......
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