-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActor.cpp
More file actions
127 lines (96 loc) · 3.04 KB
/
Copy pathActor.cpp
File metadata and controls
127 lines (96 loc) · 3.04 KB
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
123
124
125
126
#include "main.hpp"
Actor::Builder Actor::s_builder{};
Actor::Actor(const int t_x, const int t_y, const char t_char, const char* t_name, const TCODColor& t_color, const bool t_blocks, const bool t_fov_only, const bool t_proper_noun)
: m_x{ t_x },
m_y{ t_y },
m_char{ t_char },
m_name{ t_name },
m_color{ t_color },
m_blocks{ t_blocks },
m_fov_only{ t_fov_only },
m_proper_noun{ t_proper_noun },
m_attacker{ nullptr },
m_destructible{ nullptr },
m_ai{ nullptr },
m_pickable{ nullptr },
m_container{ nullptr } {}
void Actor::render() const
{
TCODConsole::root->setChar(m_x, m_y, m_char);
TCODConsole::root->setCharForeground(m_x, m_y, m_color);
}
void Actor::update()
{
if (m_ai)
{
m_ai->update(this);
}
}
float Actor::getDistance(const int t_x, const int t_y) const
{
return sqrtf((float)((m_x - t_x) * (m_x - t_x) + (m_y - t_y) * (m_y - t_y)));
}
Actor::Builder::Builder() {}
Actor::Builder& Actor::Builder::createActor(const int t_x, const int t_y, const ActorPreset t_preset)
{
switch (t_preset)
{
case ActorPreset::PLAYER:
{
createActor(t_x, t_y, '@', "player", TCODColor::white, true, true)
.setAttack(DamageType::PHYSICAL, "2d2", "punched")
.setDestructible<PlayerDestructible>(30.0f, "your corpse", 0)
.setAi<PlayerAi>()
.setContainer(26);
} break; // case PLAYER
case ActorPreset::ORC:
{
createActor(t_x, t_y, 'o', "orc", TCODColor::desaturatedGreen, true, true)
.setAttack(DamageType::PHYSICAL, "1d3", "scratched")
.setDestructible<MonsterDestructible>(10.0f, "dead orc", 35)
.setAi<MonsterAi>();
} break; // case ORC
case ActorPreset::TROLL:
{
createActor(t_x, t_y, 'T', "troll", TCODColor::desaturatedGreen, true, true)
.setAttack(DamageType::PHYSICAL, "1d4", "clubed")
.setDestructible<MonsterDestructible>(20.0f, "troll carcass", 100)
.setAi<MonsterAi>();
} break; // case TROLL
};
return *this;
};
Actor::Builder& Actor::Builder::createActor(const int t_x, const int t_y, const char t_char, const char* t_name, const TCODColor& t_color, const bool t_blocks, const bool t_fov_only)
{
m_actor_wip = std::make_unique<Actor>(t_x, t_y, t_char, t_name, t_color, t_blocks, t_fov_only);
return *this;
}
Actor::Builder& Actor::Builder::setAttack(DamageType t_dmgType, TCOD_dice_t t_dice, const char* t_verb)
{
m_actor_wip->m_attacker = std::make_unique<Attacker>(t_dmgType,t_dice,t_verb);
return *this;
}
Actor::Builder& Actor::Builder::setAttack(DamageType t_dmgType, const char* t_dice, const char* t_verb)
{
m_actor_wip->m_attacker = std::make_unique<Attacker>(t_dmgType,Engine::s_rng->dice(t_dice),t_verb);
return *this;
}
Actor::Builder& Actor::Builder::setContainer(const int t_size)
{
m_actor_wip->m_container = std::make_unique<Container>(t_size);
return *this;
}
Actor::Builder& Actor::Builder::setBlocks(const bool t_blocks)
{
m_actor_wip->m_blocks = t_blocks;
return *this;
}
Actor::Builder& Actor::Builder::setFovOnly(const bool t_fov_only)
{
m_actor_wip->m_fov_only = t_fov_only;
return *this;
}
std::unique_ptr<Actor> Actor::Builder::construct()
{
return std::move(m_actor_wip);
}