forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_mode.cpp
213 lines (171 loc) · 5.48 KB
/
move_mode.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "move_mode.h"
#include <algorithm>
#include <cstddef>
#include <set>
#include <string>
#include "assign.h"
#include "debug.h"
#include "game_constants.h"
#include "generic_factory.h"
#include "json.h"
static std::vector<move_mode_id> move_modes_sorted;
const std::vector<move_mode_id> &move_modes_by_speed()
{
return move_modes_sorted;
}
namespace
{
generic_factory<move_mode> move_mode_factory( "move_mode" );
} // namespace
template<>
const move_mode &move_mode_id::obj() const
{
return move_mode_factory.obj( *this );
}
template<>
bool move_mode_id::is_valid() const
{
return move_mode_factory.is_valid( *this );
}
static const std::unordered_map<std::string, move_mode_type> move_types {
{ "prone", move_mode_type::PRONE },
{ "crouching", move_mode_type::CROUCHING },
{ "walking", move_mode_type::WALKING },
{ "running", move_mode_type::RUNNING }
};
void move_mode::load_move_mode( const JsonObject &jo, const std::string &src )
{
move_mode_factory.load( jo, src );
}
void move_mode::load( const JsonObject &jo, const std::string &/*src*/ )
{
mandatory( jo, was_loaded, "character", _letter, unicode_codepoint_from_symbol_reader );
mandatory( jo, was_loaded, "name", _name );
mandatory( jo, was_loaded, "panel_char", _panel_letter, unicode_codepoint_from_symbol_reader );
assign( jo, "panel_color", _panel_color );
assign( jo, "symbol_color", _symbol_color );
std::string exert = jo.get_string( "exertion_level" );
if( !activity_levels_map.count( exert ) ) {
jo.throw_error_at( id.str(), "Invalid activity level for move mode " + id.str() );
}
_exertion_level = activity_levels_map.at( exert );
mandatory( jo, was_loaded, "change_good_none", change_messages_success[steed_type::NONE] );
mandatory( jo, was_loaded, "change_good_animal", change_messages_success[steed_type::ANIMAL] );
mandatory( jo, was_loaded, "change_good_mech", change_messages_success[steed_type::MECH] );
optional( jo, was_loaded, "change_bad_none", change_messages_fail[steed_type::NONE],
to_translation( "You feel bugs crawl over your skin." ) );
optional( jo, was_loaded, "change_bad_animal", change_messages_fail[steed_type::ANIMAL],
to_translation( "You feel bugs crawl over your skin." ) );
optional( jo, was_loaded, "change_bad_mech", change_messages_fail[steed_type::MECH],
to_translation( "You feel bugs crawl over your skin." ) );
mandatory( jo, was_loaded, "move_type", _type, make_flag_reader( move_types, "move type" ) );
optional( jo, was_loaded, "stamina_multiplier", _stamina_multiplier, 1.0 );
optional( jo, was_loaded, "sound_multiplier", _sound_multiplier, 1.0 );
optional( jo, was_loaded, "move_speed_multiplier", _move_speed_mult, 1.0 );
optional( jo, was_loaded, "mech_power_use", _mech_power_use, 2 );
optional( jo, was_loaded, "swim_speed_mod", _swim_speed_mod, 0 );
optional( jo, was_loaded, "stop_hauling", _stop_hauling );
}
void move_mode::reset()
{
move_mode_factory.reset();
move_modes_sorted.clear();
}
void move_mode::finalize()
{
for( const move_mode &mode : move_mode_factory.get_all() ) {
move_modes_sorted.emplace_back( mode.ident() );
}
// Sort it fastest to slowest
auto stamina_sorter = [&]( const move_mode_id & lhs, const move_mode_id & rhs ) {
return lhs->move_speed_mult() < rhs->move_speed_mult();
};
std::sort( move_modes_sorted.begin(), move_modes_sorted.end(), stamina_sorter );
// Cycle to the move mode above ours
for( size_t i = move_modes_sorted.size(); i > 0; --i ) {
const move_mode &curr = *move_modes_sorted[i - 1];
if( i == move_modes_sorted.size() ) {
curr.set_cycle( move_modes_sorted[0] );
} else {
curr.set_cycle( move_modes_sorted[i] );
}
}
}
std::string move_mode::name() const
{
return _name.translated();
}
std::string move_mode::change_message( bool success, steed_type steed ) const
{
if( steed == steed_type::NUM ) {
debugmsg( "Attempted to switch to bad movement mode!" );
//~ This should never occur - this is the message when the character switches to
//~ an invalid move mode or there's not a message for failing to switch to a move
//~ mode
return _( "You feel bugs crawl over your skin." );
}
if( success ) {
return change_messages_success.at( steed ).translated();
}
return change_messages_fail.at( steed ).translated();
}
move_mode_id move_mode::cycle() const
{
return cycle_to;
}
move_mode_id move_mode::ident() const
{
return id;
}
float move_mode::sound_mult() const
{
return _sound_multiplier;
}
float move_mode::stamina_mult() const
{
return _stamina_multiplier;
}
float move_mode::exertion_level() const
{
return _exertion_level;
}
float move_mode::move_speed_mult() const
{
return _move_speed_mult;
}
int move_mode::mech_power_use() const
{
return _mech_power_use;
}
int move_mode::swim_speed_mod() const
{
return _swim_speed_mod;
}
nc_color move_mode::panel_color() const
{
return _panel_color;
}
nc_color move_mode::symbol_color() const
{
return _symbol_color;
}
char move_mode::panel_letter() const
{
return _panel_letter;
}
char move_mode::letter() const
{
return _letter;
}
bool move_mode::stop_hauling() const
{
return _stop_hauling;
}
move_mode_type move_mode::type() const
{
return _type;
}
void move_mode::set_cycle( const move_mode_id &mode ) const
{
cycle_to = mode;
}