-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.cpp
122 lines (100 loc) · 2.24 KB
/
object.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <vector>
#include <cstring>
#include "object.h"
#include "dungeon.h"
#include "utils.h"
object::object(object_description &o, pair_t p, object *next) :
name(o.get_name()),
description(o.get_description()),
type(o.get_type()),
color(o.get_color()),
damage(o.get_damage()),
hit(o.get_hit().roll()),
dodge(o.get_dodge().roll()),
defence(o.get_defence().roll()),
weight(o.get_weight().roll()),
speed(o.get_speed().roll()),
attribute(o.get_attribute().roll()),
value(o.get_value().roll()),
seen(false),
next(next),
od(o)
{
position[dim_x] = p[dim_x];
position[dim_y] = p[dim_y];
od.generate();
}
object::~object()
{
od.destroy();
if (next) {
delete next;
}
}
void gen_object(dungeon_t *d)
{
object *o;
uint32_t room;
pair_t p;
std::vector<object_description> &v = d->object_descriptions;
int i;
do {
i = rand_range(0, v.size() - 1);
} while (!v[i].can_be_generated() || !v[i].pass_rarity_roll());
room = rand_range(0, d->num_rooms - 1);
do {
p[dim_y] = rand_range(d->rooms[room].position[dim_y],
(d->rooms[room].position[dim_y] +
d->rooms[room].size[dim_y] - 1));
p[dim_x] = rand_range(d->rooms[room].position[dim_x],
(d->rooms[room].position[dim_x] +
d->rooms[room].size[dim_x] - 1));
} while (mappair(p) > ter_stairs);
o = new object(v[i], p, d->objmap[p[dim_y]][p[dim_x]]);
d->objmap[p[dim_y]][p[dim_x]] = o;
}
void gen_objects(dungeon_t *d)
{
uint32_t i;
memset(d->objmap, 0, sizeof (d->objmap));
for (i = 0; i < d->max_objects; i++) {
gen_object(d);
}
d->num_objects = d->max_objects;
}
char object::get_symbol()
{
return next ? '&' : object_symbol[type];
}
uint32_t object::get_color()
{
return color;
}
const char *object::get_name()
{
return name.c_str();
}
int32_t object::get_speed()
{
return speed;
}
int32_t object::roll_dice()
{
return damage.roll();
}
void destroy_objects(dungeon_t *d)
{
uint32_t y, x;
for (y = 0; y < DUNGEON_Y; y++) {
for (x = 0; x < DUNGEON_X; x++) {
if (d->objmap[y][x]) {
delete d->objmap[y][x];
d->objmap[y][x] = 0;
}
}
}
}
int32_t object::get_type()
{
return type;
}