1515#include " event.h"
1616#include " event_bus.h"
1717#include " filesystem.h"
18+ #include " map_helpers.h"
1819#include " memorial_logger.h"
1920#include " mutation.h"
2021#include " player_helpers.h"
@@ -33,13 +34,18 @@ static const spell_id spell_pain_damage( "pain_damage" );
3334
3435static const trap_str_id tr_pit ( " tr_pit" );
3536
36- template <event_type Type, typename ... Args>
37- void check_memorial ( memorial_logger &m, event_bus &b, const std::string &ref, Args... args )
37+ // Requires a custom sender for eg. using event types that need to be sent differently for EOCS to work
38+ template <event_type Type, typename Sender>
39+ void check_memorial_custom_sender (
40+ memorial_logger &m,
41+ const std::string &ref,
42+ Sender &&sender
43+ )
3844{
3945 CAPTURE ( io::enum_to_string ( Type ) );
4046 CAPTURE ( ref );
4147 m.clear ();
42- b. send ( cata::event::make<Type>( args... ) );
48+ sender ( );
4349
4450 std::string result = m.dump ();
4551 CAPTURE ( result );
@@ -67,6 +73,21 @@ void check_memorial( memorial_logger &m, event_bus &b, const std::string &ref, A
6773 CHECK ( ref_lines.empty () );
6874}
6975
76+ // Send the event via event_bus::send as a sane default
77+ template <event_type Type, typename ... Args>
78+ void check_memorial (
79+ memorial_logger &m,
80+ const std::string &ref,
81+ Args... args
82+ )
83+ {
84+ check_memorial_custom_sender<Type>(
85+ m,
86+ ref,
87+ [&] { get_event_bus ().send ( cata::event::make<Type>( args... ) ); }
88+ );
89+ }
90+
7091TEST_CASE ( " memorials" , " [memorial]" )
7192{
7293 memorial_logger &m = get_memorial ();
@@ -75,15 +96,15 @@ TEST_CASE( "memorials", "[memorial]" )
7596 get_stats ().clear ();
7697 get_achievements ().clear ();
7798
78- event_bus &b = get_event_bus ();
79-
8099 avatar &player_character = get_avatar ();
81100 player_character.male = false ;
82101 character_id ch = player_character.getID ();
83102 std::string u_name = player_character.name ;
84103 character_id ch2 = character_id ( ch.get_value () + 1 );
85104 mutagen_technique mutagen = mutagen_technique::injected_purifier;
86105 mtype_id mon ( " mon_zombie_kevlar_2" );
106+ tripoint_bub_ms loc = get_avatar ().pos_bub () + tripoint::east;
107+ monster &dummy_monster = spawn_test_monster ( " mon_dragon_dummy" , loc );
87108 efftype_id eff ( " onfire" );
88109 itype_id it ( " marloss_seed" );
89110 trait_id mut ( " CARNIVORE" );
@@ -93,201 +114,205 @@ TEST_CASE( "memorials", "[memorial]" )
93114 proficiency_id prof ( " prof_wound_care" );
94115
95116 check_memorial<event_type::activates_artifact>(
96- m, b, " Activated the art_name." , ch, " art_name" );
117+ m, " Activated the art_name." , ch, " art_name" );
97118
98119 check_memorial<event_type::activates_mininuke>(
99- m, b, " Activated a mininuke." , ch );
120+ m, " Activated a mininuke." , ch );
100121
101122 check_memorial<event_type::administers_mutagen>(
102- m, b, " Injected purifier." , ch, mutagen );
123+ m, " Injected purifier." , ch, mutagen );
103124
104125 check_memorial<event_type::angers_amigara_horrors>(
105- m, b, " Angered a group of amigara horrors!" );
126+ m, " Angered a group of amigara horrors!" );
106127
107128 check_memorial<event_type::awakes_dark_wyrms>(
108- m, b, " Awoke a group of dark wyrms!" );
129+ m, " Awoke a group of dark wyrms!" );
109130
110131 check_memorial<event_type::becomes_wanted>(
111- m, b, " Became wanted by the police!" , ch );
132+ m, " Became wanted by the police!" , ch );
112133
113134 check_memorial<event_type::broken_bone>(
114- m, b, " Broke her right arm." , ch, bodypart_id ( " arm_r" ) );
135+ m, " Broke her right arm." , ch, bodypart_id ( " arm_r" ) );
115136
116137 check_memorial<event_type::broken_bone_mends>(
117- m, b, " Broken right arm began to mend." , ch, bodypart_id ( " arm_r" ) );
138+ m, " Broken right arm began to mend." , ch, bodypart_id ( " arm_r" ) );
118139
119140 check_memorial<event_type::buries_corpse>(
120- m, b, " You buried monster_name." , ch, mon, " monster_name" );
141+ m, " You buried monster_name." , ch, mon, " monster_name" );
121142
122143 check_memorial<event_type::causes_resonance_cascade>(
123- m, b, " Caused a resonance cascade." );
144+ m, " Caused a resonance cascade." );
124145
125146 check_memorial<event_type::character_gains_effect>(
126- m, b, " Caught on fire." , ch, bodypart_id ( " arm_r" ), eff, 1 );
147+ m, " Caught on fire." , ch, bodypart_id ( " arm_r" ), eff, 1 );
127148
128149 check_memorial<event_type::character_kills_character>(
129- m, b, " Killed an innocent person, victim_name, in cold blood and felt terrible "
150+ m, " Killed an innocent person, victim_name, in cold blood and felt terrible "
130151 " afterwards." , ch, ch2, " victim_name" );
131152
132- check_memorial<event_type::character_kills_monster>(
133- m, b, " Killed a Kevlar hulk." , ch, mon, 0 );
153+ check_memorial_custom_sender<event_type::character_kills_monster>(
154+ m, " Killed a Kevlar hulk." ,
155+ [&] {
156+ const cata::event e = cata::event::make<event_type::character_kills_monster>( ch, mon, 0 );
157+ get_event_bus ().send_with_talker ( player_character.as_character (), dummy_monster.as_monster (), e );
158+ } );
134159
135160 check_memorial<event_type::character_loses_effect>(
136- m, b, " Put out the fire." , ch, bodypart_id ( " arm_r" ), eff );
161+ m, " Put out the fire." , ch, bodypart_id ( " arm_r" ), eff );
137162
138163 check_memorial<event_type::character_triggers_trap>(
139- m, b, " Fell in a pit." , ch, tr_pit );
164+ m, " Fell in a pit." , ch, tr_pit );
140165
141166 check_memorial<event_type::consumes_marloss_item>(
142- m, b, " Consumed a Marloss seed." , ch, it );
167+ m, " Consumed a Marloss seed." , ch, it );
143168
144169 check_memorial<event_type::crosses_marloss_threshold>(
145- m, b, " Opened the Marloss Gateway." , ch );
170+ m, " Opened the Marloss Gateway." , ch );
146171
147172 check_memorial<event_type::crosses_mutation_threshold>(
148- m, b, " Became one with the bears." , ch, mutation_category_URSINE );
173+ m, " Became one with the bears." , ch, mutation_category_URSINE );
149174
150175 check_memorial<event_type::crosses_mycus_threshold>(
151- m, b, " Became one with the Mycus." , ch );
176+ m, " Became one with the Mycus." , ch );
152177
153178 check_memorial<event_type::dermatik_eggs_hatch>(
154- m, b, " Dermatik eggs hatched." , ch );
179+ m, " Dermatik eggs hatched." , ch );
155180
156181 check_memorial<event_type::dermatik_eggs_injected>(
157- m, b, " Injected with dermatik eggs." , ch );
182+ m, " Injected with dermatik eggs." , ch );
158183
159184 check_memorial<event_type::destroys_triffid_grove>(
160- m, b, " Destroyed a triffid grove." );
185+ m, " Destroyed a triffid grove." );
161186
162187 check_memorial<event_type::dies_from_asthma_attack>(
163- m, b, " Succumbed to an asthma attack." , ch );
188+ m, " Succumbed to an asthma attack." , ch );
164189
165190 check_memorial<event_type::dies_from_drug_overdose>(
166- m, b, " Died of a drug overdose." , ch, eff );
191+ m, " Died of a drug overdose." , ch, eff );
167192
168193 check_memorial<event_type::dies_from_bleeding>(
169- m, b, " Bled to death." , ch );
194+ m, " Bled to death." , ch );
170195
171196 check_memorial<event_type::dies_from_hypovolemia>(
172- m, b, " Died of hypovolemic shock." , ch );
197+ m, " Died of hypovolemic shock." , ch );
173198
174199 check_memorial<event_type::dies_from_redcells_loss>(
175- m, b, " Died from loss of red blood cells." , ch );
200+ m, " Died from loss of red blood cells." , ch );
176201
177202 check_memorial<event_type::dies_of_infection>(
178- m, b, " Succumbed to the infection." , ch );
203+ m, " Succumbed to the infection." , ch );
179204
180205 check_memorial<event_type::dies_of_starvation>(
181- m, b, " Died of starvation." , ch );
206+ m, " Died of starvation." , ch );
182207
183208 check_memorial<event_type::dies_of_thirst>(
184- m, b, " Died of thirst." , ch );
209+ m, " Died of thirst." , ch );
185210
186211 check_memorial<event_type::digs_into_lava>(
187- m, b, " Dug a shaft into lava." );
212+ m, " Dug a shaft into lava." );
188213
189214 check_memorial<event_type::disarms_nuke>(
190- m, b, " Disarmed a nuclear missile." );
215+ m, " Disarmed a nuclear missile." );
191216
192217 check_memorial<event_type::eats_sewage>(
193- m, b, " Ate a sewage sample." );
218+ m, " Ate a sewage sample." );
194219
195220 check_memorial<event_type::evolves_mutation>(
196- m, b, " 'Carnivore' mutation turned into 'Saprophage'" , ch, mut, mut2 );
221+ m, " 'Carnivore' mutation turned into 'Saprophage'" , ch, mut, mut2 );
197222
198223 check_memorial<event_type::exhumes_grave>(
199- m, b, " Exhumed a grave." , ch );
224+ m, " Exhumed a grave." , ch );
200225
201226 check_memorial<event_type::fails_to_install_cbm>(
202- m, b, " Failed install of bionic: Alarm System." , ch, cbm );
227+ m, " Failed install of bionic: Alarm System." , ch, cbm );
203228
204229 check_memorial<event_type::fails_to_remove_cbm>(
205- m, b, " Failed to remove bionic: Alarm System." , ch, cbm );
230+ m, " Failed to remove bionic: Alarm System." , ch, cbm );
206231
207232 check_memorial<event_type::falls_asleep_from_exhaustion>(
208- m, b, " Succumbed to lack of sleep." , ch );
233+ m, " Succumbed to lack of sleep." , ch );
209234
210235 check_memorial<event_type::fuel_tank_explodes>(
211- m, b, " The fuel tank of the vehicle_name exploded!" , " vehicle_name" );
236+ m, " The fuel tank of the vehicle_name exploded!" , " vehicle_name" );
212237
213238 check_memorial<event_type::gains_addiction>(
214- m, b, " Became addicted to alcohol." , ch, addiction_alcohol );
239+ m, " Became addicted to alcohol." , ch, addiction_alcohol );
215240
216241 check_memorial<event_type::gains_mutation>(
217- m, b, " Gained the mutation 'Carnivore'." , ch, mut );
242+ m, " Gained the mutation 'Carnivore'." , ch, mut );
218243
219244 check_memorial<event_type::gains_proficiency>(
220- m, b, " Gained the proficiency 'Wound Care'." , ch, prof );
245+ m, " Gained the proficiency 'Wound Care'." , ch, prof );
221246
222247 check_memorial<event_type::gains_skill_level>(
223- m, b, " Reached skill level 8 in vehicles." , ch, skill_driving, 8 );
248+ m, " Reached skill level 8 in vehicles." , ch, skill_driving, 8 );
224249
225250 check_memorial<event_type::game_avatar_death>(
226- m, b, u_name + " was killed.\n Last words: last_words" , ch, u_name, false , " last_words" );
251+ m, u_name + " was killed.\n Last words: last_words" , ch, u_name, false , " last_words" );
227252
228253 check_memorial<event_type::game_avatar_new>(
229- m, b, u_name + " began their journey into the Cataclysm." , true , false , ch, u_name,
254+ m, u_name + " began their journey into the Cataclysm." , true , false , ch, u_name,
230255 player_character.custom_profession );
231256
232257 check_memorial<event_type::installs_cbm>(
233- m, b, " Installed bionic: Alarm System." , ch, cbm );
258+ m, " Installed bionic: Alarm System." , ch, cbm );
234259
235260 check_memorial<event_type::installs_faulty_cbm>(
236- m, b, " Installed bad bionic: Alarm System." , ch, cbm );
261+ m, " Installed bad bionic: Alarm System." , ch, cbm );
237262
238263 check_memorial<event_type::learns_martial_art>(
239- m, b, " Learned Aikido." , ch, style_aikido );
264+ m, " Learned Aikido." , ch, style_aikido );
240265
241266 check_memorial<event_type::loses_addiction>(
242- m, b, " Overcame addiction to alcohol." , ch, addiction_alcohol );
267+ m, " Overcame addiction to alcohol." , ch, addiction_alcohol );
243268
244269 check_memorial<event_type::npc_becomes_hostile>(
245- m, b, " npc_name became hostile." , ch2, " npc_name" );
270+ m, " npc_name became hostile." , ch2, " npc_name" );
246271
247272 check_memorial<event_type::opens_portal>(
248- m, b, " Opened a portal." );
273+ m, " Opened a portal." );
249274
250275 check_memorial<event_type::opens_temple>(
251- m, b, " Opened a strange temple." );
276+ m, " Opened a strange temple." );
252277
253278 check_memorial<event_type::character_forgets_spell>(
254- m, b, " Forgot the spell Pain." , ch, spell_pain_damage );
279+ m, " Forgot the spell Pain." , ch, spell_pain_damage );
255280
256281 check_memorial<event_type::character_learns_spell>(
257- m, b, " Learned the spell Pain." , ch, spell_pain_damage );
282+ m, " Learned the spell Pain." , ch, spell_pain_damage );
258283
259284 check_memorial<event_type::player_levels_spell>(
260- m, b, " Gained a spell level on Pain." , ch, spell_pain_damage, 5 , mut3 );
285+ m, " Gained a spell level on Pain." , ch, spell_pain_damage, 5 , mut3 );
261286
262287 check_memorial<event_type::releases_subspace_specimens>(
263- m, b, " Released subspace specimens." );
288+ m, " Released subspace specimens." );
264289
265290 check_memorial<event_type::removes_cbm>(
266- m, b, " Removed bionic: Alarm System." , ch, cbm );
291+ m, " Removed bionic: Alarm System." , ch, cbm );
267292
268293 check_memorial<event_type::seals_hazardous_material_sarcophagus>(
269- m, b, " Sealed a Hazardous Material Sarcophagus." );
294+ m, " Sealed a Hazardous Material Sarcophagus." );
270295
271296 check_memorial<event_type::telefrags_creature>(
272- m, b, " Telefragged a telefragged_name." , ch, " telefragged_name" );
297+ m, " Telefragged a telefragged_name." , ch, " telefragged_name" );
273298
274299 check_memorial<event_type::teleglow_teleports>(
275- m, b, " Spontaneous teleport." , ch );
300+ m, " Spontaneous teleport." , ch );
276301
277302 check_memorial<event_type::teleports_into_wall>(
278- m, b, " Teleported into a obstacle_name." , ch, " obstacle_name" );
303+ m, " Teleported into a obstacle_name." , ch, " obstacle_name" );
279304
280305 check_memorial<event_type::terminates_subspace_specimens>(
281- m, b, " Terminated subspace specimens." );
306+ m, " Terminated subspace specimens." );
282307
283308 check_memorial<event_type::throws_up>(
284- m, b, " Threw up." , ch );
309+ m, " Threw up." , ch );
285310
286311 check_memorial<event_type::triggers_alarm>(
287- m, b, " Set off an alarm." , ch );
312+ m, " Set off an alarm." , ch );
288313
289314 check_memorial<event_type::uses_debug_menu>(
290- m, b, " Used the debug menu (WISH)." , debug_menu::debug_menu_index::WISH );
315+ m, " Used the debug menu (WISH)." , debug_menu::debug_menu_index::WISH );
291316}
292317
293318TEST_CASE ( " convert_legacy_memorial_log" , " [memorial]" )
0 commit comments