forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timed_event.cpp
344 lines (316 loc) · 12.6 KB
/
timed_event.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "timed_event.h"
#include <array>
#include <memory>
#include <optional>
#include "avatar.h"
#include "avatar_action.h"
#include "debug.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "game.h"
#include "game_constants.h"
#include "int_id.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "memorial_logger.h"
#include "messages.h"
#include "monster.h"
#include "morale_types.h"
#include "options.h"
#include "rng.h"
#include "sounds.h"
#include "text_snippets.h"
#include "translations.h"
#include "type_id.h"
static const itype_id itype_petrified_eye( "petrified_eye" );
static const mtype_id mon_amigara_horror( "mon_amigara_horror" );
static const mtype_id mon_copbot( "mon_copbot" );
static const mtype_id mon_dark_wyrm( "mon_dark_wyrm" );
static const mtype_id mon_dermatik( "mon_dermatik" );
static const mtype_id mon_eyebot( "mon_eyebot" );
static const mtype_id mon_riotbot( "mon_riotbot" );
static const mtype_id mon_sewer_snake( "mon_sewer_snake" );
static const mtype_id mon_spider_cellar_giant( "mon_spider_cellar_giant" );
static const mtype_id mon_spider_widow_giant( "mon_spider_widow_giant" );
timed_event::timed_event( timed_event_type e_t, const time_point &w, int f_id, tripoint p )
: type( e_t )
, when( w )
, faction_id( f_id )
, map_point( p )
{
}
void timed_event::actualize()
{
switch( type ) {
case TIMED_EVENT_HELP:
debugmsg( "Currently disabled while NPC and monster factions are being rewritten." );
break;
case TIMED_EVENT_ROBOT_ATTACK: {
const auto u_pos = g->u.global_sm_location();
if( rl_dist( u_pos, map_point ) <= 4 ) {
const mtype_id &robot_type = one_in( 2 ) ? mon_copbot : mon_riotbot;
g->events().send<event_type::becomes_wanted>( g->u.getID() );
point rob( u_pos.x > map_point.x ? 0 - SEEX * 2 : SEEX * 4,
u_pos.y > map_point.y ? 0 - SEEY * 2 : SEEY * 4 );
g->place_critter_at( robot_type, tripoint( rob, g->u.posz() ) );
}
}
break;
case TIMED_EVENT_SPAWN_WYRMS: {
if( g->get_levz() >= 0 ) {
return;
}
g->memorial().add(
pgettext( "memorial_male", "Drew the attention of more dark wyrms!" ),
pgettext( "memorial_female", "Drew the attention of more dark wyrms!" ) );
// 50% chance to spawn a dark wyrm near every orifice on the level.
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == ter_id( "t_orifice" ) ) {
g->place_critter_around( mon_dark_wyrm, p, 1 );
}
}
// You could drop the flag, you know.
if( g->u.has_amount( itype_petrified_eye, 1 ) ) {
sounds::sound( g->u.pos(), 60, sounds::sound_t::alert, _( "a tortured scream!" ), false, "shout",
"scream_tortured" );
if( !g->u.is_deaf() ) {
add_msg( _( "The eye you're carrying lets out a tortured scream!" ) );
g->u.add_morale( MORALE_SCREAM, -15, 0, 30_minutes, 30_seconds );
}
}
}
break;
case TIMED_EVENT_AMIGARA: {
g->events().send<event_type::angers_amigara_horrors>();
int num_horrors = rng( 3, 5 );
std::optional<tripoint> fault_point;
bool horizontal = false;
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == t_fault ) {
fault_point = p;
horizontal = g->m.ter( p + tripoint_east ) == t_fault || g->m.ter( p + tripoint_west ) == t_fault;
break;
}
}
for( int i = 0; fault_point && i < num_horrors; i++ ) {
for( int tries = 0; tries < 10; ++tries ) {
tripoint monp = g->u.pos();
if( horizontal ) {
monp.x = rng( fault_point->x, fault_point->x + 2 * SEEX - 8 );
for( int n = -1; n <= 1; n++ ) {
if( g->m.ter( point( monp.x, fault_point->y + n ) ) == t_rock_floor ) {
monp.y = fault_point->y + n;
}
}
} else {
// Vertical fault
monp.y = rng( fault_point->y, fault_point->y + 2 * SEEY - 8 );
for( int n = -1; n <= 1; n++ ) {
if( g->m.ter( point( fault_point->x + n, monp.y ) ) == t_rock_floor ) {
monp.x = fault_point->x + n;
}
}
}
if( g->place_critter_at( mon_amigara_horror, monp ) ) {
break;
}
}
}
}
break;
case TIMED_EVENT_ROOTS_DIE:
g->events().send<event_type::destroys_triffid_grove>();
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == t_root_wall && one_in( 3 ) ) {
g->m.ter_set( p, t_underbrush );
}
}
break;
case TIMED_EVENT_TEMPLE_OPEN: {
g->events().send<event_type::opens_temple>();
bool saw_grate = false;
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == t_grate ) {
g->m.ter_set( p, t_stairs_down );
if( !saw_grate && g->u.sees( p ) ) {
saw_grate = true;
}
}
}
if( saw_grate ) {
add_msg( _( "The nearby grates open to reveal a staircase!" ) );
}
}
break;
case TIMED_EVENT_TEMPLE_FLOOD: {
bool flooded = false;
ter_id flood_buf[MAPSIZE_X][MAPSIZE_Y];
for( const tripoint &p : g->m.points_on_zlevel() ) {
flood_buf[p.x][p.y] = g->m.ter( p );
}
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == t_water_sh ) {
bool deepen = false;
for( const tripoint &w : points_in_radius( p, 1 ) ) {
if( g->m.ter( w ) == t_water_dp ) {
deepen = true;
break;
}
}
if( deepen ) {
flood_buf[p.x][p.y] = t_water_dp;
flooded = true;
}
} else if( g->m.ter( p ) == t_rock_floor ) {
bool flood = false;
for( const tripoint &w : points_in_radius( p, 1 ) ) {
if( g->m.ter( w ) == t_water_dp || g->m.ter( w ) == t_water_sh ) {
flood = true;
break;
}
}
if( flood ) {
flood_buf[p.x][p.y] = t_water_sh;
flooded = true;
}
}
}
if( !flooded ) {
// We finished flooding the entire chamber!
return;
}
// Check if we should print a message
if( flood_buf[g->u.posx()][g->u.posy()] != g->m.ter( g->u.pos() ) ) {
if( flood_buf[g->u.posx()][g->u.posy()] == t_water_sh ) {
add_msg( m_warning, _( "Water quickly floods up to your knees." ) );
g->memorial().add(
pgettext( "memorial_male", "Water level reached knees." ),
pgettext( "memorial_female", "Water level reached knees." ) );
} else {
// Must be deep water!
add_msg( m_warning, _( "Water fills nearly to the ceiling!" ) );
g->memorial().add(
pgettext( "memorial_male", "Water level reached the ceiling." ),
pgettext( "memorial_female", "Water level reached the ceiling." ) );
avatar_action::swim( g->m, g->u, g->u.pos() );
}
}
// flood_buf is filled with correct tiles; now copy them back to g->m
for( const tripoint &p : g->m.points_on_zlevel() ) {
g->m.ter_set( p, flood_buf[p.x][p.y] );
}
g->timed_events.add( TIMED_EVENT_TEMPLE_FLOOD,
calendar::turn + rng( 2_turns, 3_turns ) );
}
break;
case TIMED_EVENT_TEMPLE_SPAWN: {
static const std::array<mtype_id, 4> temple_monsters = { {
mon_sewer_snake, mon_dermatik, mon_spider_widow_giant, mon_spider_cellar_giant
}
};
const mtype_id &montype = random_entry( temple_monsters );
g->place_critter_around( montype, g->u.pos(), 2 );
}
break;
default:
// Nothing happens for other events
break;
}
}
void timed_event::per_turn()
{
switch( type ) {
case TIMED_EVENT_WANTED: {
// About once every 5 minutes. Suppress in classic zombie mode.
if( g->get_levz() >= 0 && one_in( 50 ) && !get_option<bool>( "DISABLE_ROBOT_RESPONSE" ) ) {
point place = g->m.random_outdoor_tile();
if( place.x == -1 && place.y == -1 ) {
// We're safely indoors!
return;
}
g->place_critter_at( mon_eyebot, tripoint( place, g->u.posz() ) );
if( g->u.sees( tripoint( place, g->u.posz() ) ) ) {
add_msg( m_warning, _( "An eyebot swoops down nearby!" ) );
}
// One eyebot per trigger is enough, really
when = calendar::turn;
}
}
break;
case TIMED_EVENT_SPAWN_WYRMS:
if( g->get_levz() >= 0 ) {
when -= 1_turns;
return;
}
if( calendar::once_every( time_duration::from_seconds( rng( 2, 3 ) ) ) && !g->u.is_deaf() ) {
add_msg( m_warning, _( "You hear screeches from the rock above and around you!" ) );
}
break;
case TIMED_EVENT_AMIGARA:
if( calendar::once_every( time_duration::from_seconds( rng( 2, 3 ) ) ) ) {
add_msg( m_warning, _( "The entire cavern shakes!" ) );
}
break;
case timed_event_type::AMIGARA_WHISPERS: {
bool faults = false;
for( const tripoint &p : g->m.points_on_zlevel() ) {
if( g->m.ter( p ) == t_fault ) {
faults = true;
break;
}
}
if( calendar::once_every( time_duration::from_seconds( 10 ) ) && faults ) {
add_msg( m_info, "You hear someone whispering \"%s\"",
SNIPPET.random_from_category( "amigara_whispers" ).value_or( translation() ) );
}
}
break;
case TIMED_EVENT_TEMPLE_OPEN:
if( calendar::once_every( time_duration::from_seconds( rng( 2, 3 ) ) ) ) {
add_msg( m_warning, _( "The earth rumbles." ) );
}
break;
default:
// Nothing happens for other events
break;
}
}
void timed_event_manager::process()
{
for( auto it = events.begin(); it != events.end(); ) {
it->per_turn();
if( it->when <= calendar::turn ) {
it->actualize();
it = events.erase( it );
} else {
it++;
}
}
}
void timed_event_manager::add( const timed_event_type type, const time_point &when,
const int faction_id )
{
add( type, when, faction_id, g->u.global_sm_location() );
}
void timed_event_manager::add( const timed_event_type type, const time_point &when,
const int faction_id,
const tripoint &where )
{
events.emplace_back( type, when, faction_id, where );
}
bool timed_event_manager::queued( const timed_event_type type ) const
{
return const_cast<timed_event_manager &>( *this ).get( type ) != nullptr;
}
timed_event *timed_event_manager::get( const timed_event_type type )
{
for( auto &e : events ) {
if( e.type == type ) {
return &e;
}
}
return nullptr;
}