forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.cpp
2071 lines (1837 loc) · 70 KB
/
avatar.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "avatar.h"
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include "action.h"
#include "activity_type.h"
#include "activity_actor_definitions.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_assert.h"
#include "catacharset.h"
#include "character.h"
#include "character_id.h"
#include "character_martial_arts.h"
#include "clzones.h"
#include "color.h"
#include "cursesdef.h"
#include "debug.h"
#include "diary.h"
#include "effect.h"
#include "enums.h"
#include "event.h"
#include "event_bus.h"
#include "faction.h"
#include "field_type.h"
#include "game.h"
#include "game_constants.h"
#include "help.h"
#include "inventory.h"
#include "item.h"
#include "item_location.h"
#include "itype.h"
#include "iuse.h"
#include "kill_tracker.h"
#include "make_static.h"
#include "magic_enchantment.h"
#include "map.h"
#include "map_memory.h"
#include "martialarts.h"
#include "messages.h"
#include "mission.h"
#include "morale.h"
#include "morale_types.h"
#include "move_mode.h"
#include "mutation.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "pathfinding.h"
#include "pimpl.h"
#include "player_activity.h"
#include "profession.h"
#include "ranged.h"
#include "ret_val.h"
#include "rng.h"
#include "scenario.h"
#include "skill.h"
#include "stomach.h"
#include "string_formatter.h"
#include "talker.h"
#include "talker_avatar.h"
#include "translations.h"
#include "timed_event.h"
#include "trap.h"
#include "type_id.h"
#include "ui.h"
#include "units.h"
#include "value_ptr.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vpart_position.h"
static const bionic_id bio_cloak( "bio_cloak" );
static const bionic_id bio_soporific( "bio_soporific" );
static const efftype_id effect_alarm_clock( "alarm_clock" );
static const efftype_id effect_boomered( "boomered" );
static const efftype_id effect_depressants( "depressants" );
static const efftype_id effect_happy( "happy" );
static const efftype_id effect_irradiated( "irradiated" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pkill( "pkill" );
static const efftype_id effect_psi_stunned( "psi_stunned" );
static const efftype_id effect_relax_gas( "relax_gas" );
static const efftype_id effect_sad( "sad" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_sleep_deprived( "sleep_deprived" );
static const efftype_id effect_slept_through_alarm( "slept_through_alarm" );
static const efftype_id effect_stim( "stim" );
static const efftype_id effect_stim_overdose( "stim_overdose" );
static const efftype_id effect_stunned( "stunned" );
static const faction_id faction_your_followers( "your_followers" );
static const itype_id itype_guidebook( "guidebook" );
static const itype_id itype_mut_longpull( "mut_longpull" );
static const json_character_flag json_flag_ALARMCLOCK( "ALARMCLOCK" );
static const json_character_flag json_flag_PAIN_IMMUNE( "PAIN_IMMUNE" );
static const json_character_flag json_flag_WEBBED_HANDS( "WEBBED_HANDS" );
static const move_mode_id move_mode_crouch( "crouch" );
static const move_mode_id move_mode_prone( "prone" );
static const move_mode_id move_mode_run( "run" );
static const move_mode_id move_mode_walk( "walk" );
static const string_id<monfaction> monfaction_player( "player" );
static const trait_id trait_ARACHNID_ARMS( "ARACHNID_ARMS" );
static const trait_id trait_ARACHNID_ARMS_OK( "ARACHNID_ARMS_OK" );
static const trait_id trait_CENOBITE( "CENOBITE" );
static const trait_id trait_CHITIN2( "CHITIN2" );
static const trait_id trait_CHITIN3( "CHITIN3" );
static const trait_id trait_CHITIN_FUR3( "CHITIN_FUR3" );
static const trait_id trait_CHLOROMORPH( "CHLOROMORPH" );
static const trait_id trait_COMPOUND_EYES( "COMPOUND_EYES" );
static const trait_id trait_DEBUG_CLOAK( "DEBUG_CLOAK" );
static const trait_id trait_INSECT_ARMS( "INSECT_ARMS" );
static const trait_id trait_INSECT_ARMS_OK( "INSECT_ARMS_OK" );
static const trait_id trait_M_SKIN3( "M_SKIN3" );
static const trait_id trait_PROF_DICEMASTER( "PROF_DICEMASTER" );
static const trait_id trait_SHELL2( "SHELL2" );
static const trait_id trait_SHELL3( "SHELL3" );
static const trait_id trait_STIMBOOST( "STIMBOOST" );
static const trait_id trait_THICK_SCALES( "THICK_SCALES" );
static const trait_id trait_THRESH_SPIDER( "THRESH_SPIDER" );
static const trait_id trait_UNDINE_SLEEP_WATER( "UNDINE_SLEEP_WATER" );
static const trait_id trait_WATERSLEEP( "WATERSLEEP" );
static const trait_id trait_WEB_SPINNER( "WEB_SPINNER" );
static const trait_id trait_WEB_WALKER( "WEB_WALKER" );
static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" );
static const trait_id trait_WHISKERS( "WHISKERS" );
static const trait_id trait_WHISKERS_RAT( "WHISKERS_RAT" );
avatar::avatar()
{
player_map_memory = std::make_unique<map_memory>();
show_map_memory = true;
active_mission = nullptr;
grab_type = object_type::NONE;
calorie_diary.emplace_front( );
a_diary = nullptr;
}
avatar::~avatar() = default;
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
avatar::avatar( avatar && ) = default;
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
avatar &avatar::operator=( avatar && ) = default;
void avatar::control_npc( npc &np, const bool debug )
{
if( !np.is_player_ally() ) {
debugmsg( "control_npc() called on non-allied npc %s", np.name );
return;
}
character_id new_character = np.getID();
const std::function<void( npc & )> update_npc = [new_character]( npc & guy ) {
guy.update_missions_target( get_avatar().getID(), new_character );
};
overmap_buffer.foreach_npc( update_npc );
mission().update_world_missions_character( get_avatar().getID(), new_character );
// move avatar character data into shadow npc
swap_character( get_shadow_npc() );
// swap target npc with shadow npc
std::swap( get_shadow_npc(), np );
// move shadow npc character data into avatar
swap_character( get_shadow_npc() );
// the avatar character is no longer a follower NPC
g->remove_npc_follower( getID() );
// the previous avatar character is now a follower
g->add_npc_follower( np.getID() );
np.set_fac( faction_your_followers );
// perception and mutations may have changed, so reset light level caches
g->reset_light_level();
// center the map on the new avatar character
const bool z_level_changed = g->vertical_shift( posz() );
g->update_map( *this, z_level_changed );
character_mood_face( true );
profession_id prof_id = prof ? prof->ident() : profession::generic()->ident();
get_event_bus().send<event_type::game_avatar_new>( /*is_new_game=*/false, debug,
getID(), name, male, prof_id, custom_profession );
}
void avatar::control_npc_menu( const bool debug )
{
std::vector<shared_ptr_fast<npc>> followers;
uilist charmenu;
int charnum = 0;
for( const character_id &elem : g->get_follower_list() ) {
shared_ptr_fast<npc> follower = overmap_buffer.find_npc( elem );
if( follower ) {
followers.emplace_back( follower );
charmenu.addentry( charnum++, true, MENU_AUTOASSIGN, follower->get_name() );
}
}
if( followers.empty() ) {
popup( _( "There's no one to take control of!" ) );
return;
}
charmenu.w_y_setup = 0;
charmenu.query();
if( charmenu.ret < 0 || static_cast<size_t>( charmenu.ret ) >= followers.size() ) {
return;
}
get_avatar().control_npc( *followers[charmenu.ret], debug );
}
void avatar::longpull( const std::string &name )
{
item wtmp( itype_mut_longpull );
g->temp_exit_fullscreen();
target_handler::trajectory traj = target_handler::mode_throw( *this, wtmp, false );
g->reenter_fullscreen();
if( traj.empty() ) {
return; // cancel
}
Creature::longpull( name, traj.back() );
}
void avatar::toggle_map_memory()
{
show_map_memory = !show_map_memory;
}
bool avatar::is_map_memory_valid() const
{
return player_map_memory->is_valid();
}
bool avatar::should_show_map_memory() const
{
if( get_timed_events().get( timed_event_type::OVERRIDE_PLACE ) ) {
return false;
}
return show_map_memory;
}
bool avatar::save_map_memory()
{
return player_map_memory->save( get_map().getglobal( pos() ) );
}
void avatar::load_map_memory()
{
player_map_memory->load( get_map().getglobal( pos() ) );
}
void avatar::prepare_map_memory_region( const tripoint_abs_ms &p1, const tripoint_abs_ms &p2 )
{
player_map_memory->prepare_region( p1, p2 );
}
const memorized_tile &avatar::get_memorized_tile( const tripoint_abs_ms &p ) const
{
if( should_show_map_memory() ) {
return player_map_memory->get_tile( p );
}
return mm_submap::default_tile;
}
void avatar::memorize_terrain( const tripoint_abs_ms &p, const std::string_view id,
int subtile, int rotation )
{
player_map_memory->set_tile_terrain( p, id, subtile, rotation );
}
void avatar::memorize_decoration( const tripoint_abs_ms &p, const std::string_view id,
int subtile, int rotation )
{
player_map_memory->set_tile_decoration( p, id, subtile, rotation );
}
void avatar::memorize_symbol( const tripoint_abs_ms &p, char32_t symbol )
{
player_map_memory->set_tile_symbol( p, symbol );
}
void avatar::memorize_clear_decoration( const tripoint_abs_ms &p, std::string_view prefix )
{
player_map_memory->clear_tile_decoration( p, prefix );
}
std::vector<mission *> avatar::get_active_missions() const
{
return active_missions;
}
std::vector<mission *> avatar::get_completed_missions() const
{
return completed_missions;
}
std::vector<mission *> avatar::get_failed_missions() const
{
return failed_missions;
}
mission *avatar::get_active_mission() const
{
return active_mission;
}
void avatar::reset_all_missions()
{
active_mission = nullptr;
active_missions.clear();
completed_missions.clear();
failed_missions.clear();
}
tripoint_abs_omt avatar::get_active_mission_target() const
{
if( active_mission == nullptr ) {
return overmap::invalid_tripoint;
}
return active_mission->get_target();
}
void avatar::set_active_mission( mission &cur_mission )
{
const auto iter = std::find( active_missions.begin(), active_missions.end(), &cur_mission );
if( iter == active_missions.end() ) {
debugmsg( "new active mission %d is not in the active_missions list", cur_mission.get_id() );
} else {
active_mission = &cur_mission;
}
}
void avatar::on_mission_assignment( mission &new_mission )
{
active_missions.push_back( &new_mission );
set_active_mission( new_mission );
}
void avatar::on_mission_finished( mission &cur_mission )
{
if( cur_mission.has_failed() ) {
if( !cur_mission.get_type().invisible_on_complete ) {
failed_missions.push_back( &cur_mission );
}
add_msg_if_player( m_bad, _( "Mission \"%s\" is failed." ), cur_mission.name() );
} else {
if( !cur_mission.get_type().invisible_on_complete ) {
completed_missions.push_back( &cur_mission );
}
add_msg_if_player( m_good, _( "Mission \"%s\" is successfully completed." ),
cur_mission.name() );
}
const auto iter = std::find( active_missions.begin(), active_missions.end(), &cur_mission );
if( iter == active_missions.end() ) {
debugmsg( "completed mission %d was not in the active_missions list", cur_mission.get_id() );
} else {
active_missions.erase( iter );
}
if( &cur_mission == active_mission ) {
if( active_missions.empty() ) {
active_mission = nullptr;
} else {
active_mission = active_missions.front();
}
}
}
bool avatar::has_mission_id( const mission_type_id &miss_id )
{
for( mission *miss : active_missions ) {
if( miss->mission_id() == miss_id ) {
return true;
}
}
return false;
}
void avatar::remove_active_mission( mission &cur_mission )
{
cur_mission.remove_active_world_mission( cur_mission );
const auto iter = std::find( active_missions.begin(), active_missions.end(), &cur_mission );
if( iter == active_missions.end() ) {
debugmsg( "removed mission %d was not in the active_missions list", cur_mission.get_id() );
} else {
active_missions.erase( iter );
}
if( &cur_mission == active_mission ) {
if( active_missions.empty() ) {
active_mission = nullptr;
} else {
active_mission = active_missions.front();
}
}
}
diary *avatar::get_avatar_diary()
{
if( a_diary == nullptr ) {
a_diary = std::make_unique<diary>();
}
return a_diary.get();
}
bool avatar::read( item_location &book, item_location ereader )
{
if( !book ) {
add_msg( m_info, _( "Never mind." ) );
return false;
}
std::vector<std::string> fail_messages;
const Character *reader = get_book_reader( *book, fail_messages );
if( reader == nullptr ) {
// We can't read, and neither can our followers
for( const std::string &reason : fail_messages ) {
add_msg( m_bad, reason );
}
return false;
}
// spells are handled in a different place
// src/iuse_actor.cpp -> learn_spell_actor::use
if( book->get_use( "learn_spell" ) ) {
book->get_use( "learn_spell" )->call( this, *book, pos() );
return true;
}
bool continuous = false;
const time_duration time_taken = time_to_read( *book, *reader );
add_msg_debug( debugmode::DF_ACT_READ, "avatar::read time_taken = %s",
to_string_writable( time_taken ) );
// If the player hasn't read this book before, skim it to get an idea of what's in it.
if( !has_identified( book->typeId() ) ) {
if( reader != this ) {
add_msg( m_info, fail_messages[0] );
add_msg( m_info, _( "%s reads aloud…" ), reader->disp_name() );
}
assign_activity( read_activity_actor( time_taken, book, ereader, false ) );
return true;
}
if( book->typeId() == itype_guidebook ) {
// special guidebook effect: print a misc. hint when read
if( reader != this ) {
add_msg( m_info, fail_messages[0] );
dynamic_cast<const npc &>( *reader ).say( get_hint() );
} else {
add_msg( m_info, get_hint() );
}
get_event_bus().send<event_type::reads_book>( getID(), book->typeId() );
mod_moves( -100 );
return false;
}
const cata::value_ptr<islot_book> &type = book->type->book;
const skill_id &skill = type->skill;
const std::string skill_name = skill ? skill.obj().name() : "";
// Find NPCs to join the study session:
std::map<Character *, std::string> learners;
//reading only for fun
std::map<Character *, std::string> fun_learners;
std::map<Character *, std::string> nonlearners;
for( Character *elem : get_crafting_helpers() ) {
const book_mastery mastery = elem->get_book_mastery( *book );
const bool morale_req = elem->fun_to_read( *book ) || elem->has_morale_to_read();
// Note that the reader cannot be a nonlearner
// since a reader should always have enough morale to read
// and at the very least be able to understand the book
if( elem->is_deaf() && elem != reader ) {
nonlearners.insert( { elem, _( " (deaf)" ) } );
} else if( mastery == book_mastery::MASTERED && elem->fun_to_read( *book ) ) {
fun_learners.insert( {elem, elem == reader ? _( " (reading aloud to you)" ) : "" } );
} else if( mastery == book_mastery::LEARNING && morale_req ) {
learners.insert( {elem, elem == reader ? _( " (reading aloud to you)" ) : ""} );
} else {
std::string reason = _( " (uninterested)" );
if( !morale_req ) {
reason = _( " (too sad)" );
} else if( mastery == book_mastery::CANT_UNDERSTAND ) {
reason = string_format( _( " (needs %d %s)" ), type->req, skill_name );
} else if( mastery == book_mastery::MASTERED ) {
reason = string_format( _( " (already has %d %s)" ), type->level, skill_name );
}
nonlearners.insert( { elem, reason } );
}
}
int learner_id = -1;
const bool is_martialarts = book->type->use_methods.count( "MA_MANUAL" );
//only show the menu if there's useful information or multiple options
if( ( skill || !nonlearners.empty() || !fun_learners.empty() ) && !is_martialarts ) {
uilist menu;
// Some helpers to reduce repetition:
auto length = []( const std::pair<Character *, std::string> &elem ) {
return utf8_width( elem.first->disp_name() ) + utf8_width( elem.second );
};
auto max_length = [&length]( const std::map<Character *, std::string> &m ) {
auto max_ele = std::max_element( m.begin(),
m.end(), [&length]( const std::pair<Character *, std::string> &left,
const std::pair<Character *, std::string> &right ) {
return length( left ) < length( right );
} );
return max_ele == m.end() ? 0 : length( *max_ele );
};
auto get_text = [&]( const std::map<Character *, std::string> &m,
const std::pair<Character *, std::string> &elem
) {
const int lvl = elem.first->get_knowledge_level( skill );
const std::string lvl_text = skill ? string_format( _( " | current level: %d" ), lvl ) : "";
const std::string name_text = elem.first->disp_name() + elem.second;
return string_format( "%s%s", left_justify( name_text, max_length( m ) ), lvl_text );
};
auto add_header = [&menu]( const std::string & str ) {
menu.addentry( -1, false, -1, "" );
uilist_entry header( -1, false, -1, str, c_yellow, c_yellow );
header.force_color = true;
menu.entries.push_back( header );
};
menu.title = !skill ? string_format( _( "Reading %s" ), book->type_name() ) :
//~ %1$s: book name, %2$s: skill name, %3$d and %4$d: skill levels
string_format( _( "Reading %1$s (can train %2$s from %3$d to %4$d)" ), book->type_name(),
skill_name, type->req, type->level );
menu.addentry( 0, true, '0', _( "Read once" ) );
const int lvl = get_knowledge_level( skill );
menu.addentry( 2 + getID().get_value(), lvl < type->level, '1',
string_format( _( "Read until you gain a level | current level: %d" ), lvl ) );
// select until player gets level by default
if( lvl < type->level ) {
menu.selected = 1;
}
if( !learners.empty() ) {
add_header( _( "Read until this character gains a level:" ) );
for( const std::pair<Character *const, std::string> &elem : learners ) {
menu.addentry( 2 + elem.first->getID().get_value(), true, -1,
get_text( learners, elem ) );
}
}
if( !fun_learners.empty() ) {
add_header( _( "Reading for fun:" ) );
for( const std::pair<Character *const, std::string> &elem : fun_learners ) {
menu.addentry( -1, false, -1, get_text( fun_learners, elem ) );
}
}
if( !nonlearners.empty() ) {
add_header( _( "Not participating:" ) );
for( const std::pair<Character *const, std::string> &elem : nonlearners ) {
menu.addentry( -1, false, -1, get_text( nonlearners, elem ) );
}
}
menu.query( true );
if( menu.ret == UILIST_CANCEL ) {
add_msg( m_info, _( "Never mind." ) );
return false;
} else if( menu.ret >= 2 ) {
continuous = true;
learner_id = menu.ret - 2;
}
}
if( is_martialarts ) {
if( martial_arts_data->has_martialart( martial_art_learned_from( *book->type ) ) ) {
add_msg_if_player( m_info, _( "You already know all this book has to teach." ) );
return false;
}
uilist menu;
menu.title = string_format( _( "Train %s from manual:" ),
martial_art_learned_from( *book->type )->name );
menu.addentry( 1, true, '1', _( "Train once" ) );
menu.addentry( 2, true, '0', _( "Train until tired or success" ) );
menu.query( true );
if( menu.ret == UILIST_CANCEL ) {
add_msg( m_info, _( "Never mind." ) );
return false;
} else if( menu.ret == 1 ) {
continuous = false;
} else { // menu.ret == 2
continuous = true;
}
}
add_msg( m_info, _( "Now reading %s, %s to stop early." ),
book->type_name(), press_x( ACTION_PAUSE ) );
// Print some informational messages
if( reader != this ) {
add_msg( m_info, fail_messages[0] );
add_msg( m_info, _( "%s reads aloud…" ), reader->disp_name() );
} else if( !learners.empty() || !fun_learners.empty() ) {
add_msg( m_info, _( "You read aloud…" ) );
}
if( learners.size() == 1 ) {
add_msg( m_info, _( "%s studies with you." ), learners.begin()->first->disp_name() );
} else if( !learners.empty() ) {
const std::string them = enumerate_as_string( learners.begin(),
learners.end(), [&]( const std::pair<Character *, std::string> &elem ) {
return elem.first->disp_name();
} );
add_msg( m_info, _( "%s study with you." ), them );
}
// Don't include the reader as it would be too redundant.
std::set<std::string> readers;
for( const std::pair<Character *const, std::string> &elem : fun_learners ) {
if( elem.first != reader ) {
readers.insert( elem.first->disp_name() );
}
}
if( readers.size() == 1 ) {
add_msg( m_info, _( "%s reads with you for fun." ), readers.begin()->c_str() );
} else if( !readers.empty() ) {
const std::string them = enumerate_as_string( readers );
add_msg( m_info, _( "%s read with you for fun." ), them );
}
if( std::min( fine_detail_vision_mod(), reader->fine_detail_vision_mod() ) > 1.0 ) {
add_msg( m_warning,
_( "It's difficult for %s to see fine details right now. Reading will take longer than usual." ),
reader->disp_name() );
}
const int intelligence = get_int();
const bool complex_penalty = type->intel > std::min( intelligence, reader->get_int() ) &&
!reader->has_trait( trait_PROF_DICEMASTER );
const Character *complex_player = reader->get_int() < intelligence ? reader : this;
if( complex_penalty ) {
add_msg( m_warning,
_( "This book is too complex for %s to easily understand. It will take longer to read." ),
complex_player->disp_name() );
}
// push an identifier of martial art book to the action handling
if( is_martialarts &&
get_stamina() < get_stamina_max() / 10 ) {
add_msg( m_info, _( "You are too exhausted to train martial arts." ) );
return false;
}
assign_activity( read_activity_actor( time_taken, book, ereader, continuous, learner_id ) );
return true;
}
void avatar::grab( object_type grab_type_new, const tripoint &grab_point_new )
{
const auto update_memory =
[this]( const object_type gtype, const tripoint & gpoint, const bool erase ) {
map &m = get_map();
if( gtype == object_type::VEHICLE ) {
if( const optional_vpart_position ovp = m.veh_at( pos() + gpoint ) ) {
for( const tripoint &target : ovp->vehicle().get_points() ) {
if( erase ) {
memorize_clear_decoration( m.getglobal( target ), /* prefix = */ "vp_" );
}
m.memory_cache_dec_set_dirty( target, true );
}
}
} else if( gtype != object_type::NONE ) {
if( erase ) {
memorize_clear_decoration( m.getglobal( pos() + gpoint ) );
}
m.memory_cache_dec_set_dirty( pos() + gpoint, true );
}
};
// Mark the area covered by the previous vehicle/furniture/etc for re-memorizing.
update_memory( grab_type, grab_point, /* erase = */ false );
grab_type = grab_type_new;
grab_point = grab_point_new;
// Clear the map memory for the area covered by the vehicle/furniture/etc to
// eliminate ghost vehicles/furnitures/etc.
update_memory( grab_type, grab_point, /* erase = */ true );
path_settings->avoid_rough_terrain = grab_type != object_type::NONE;
}
object_type avatar::get_grab_type() const
{
return grab_type;
}
bool avatar::has_identified( const itype_id &item_id ) const
{
return items_identified.count( item_id ) > 0;
}
void avatar::identify( const item &item )
{
if( has_identified( item.typeId() ) ) {
return;
}
if( !item.is_book() ) {
debugmsg( "tried to identify non-book item" );
return;
}
const ::item &book = item; // alias
cata_assert( !has_identified( item.typeId() ) );
items_identified.insert( item.typeId() );
cata_assert( has_identified( item.typeId() ) );
const auto &reading = item.type->book;
const skill_id &skill = reading->skill;
add_msg( _( "You skim %s to find out what's in it." ), book.type_name() );
if( skill && get_skill_level_object( skill ).can_train() ) {
add_msg( m_info, _( "Can bring your %s knowledge to %d." ),
skill.obj().name(), reading->level );
if( reading->req != 0 ) {
add_msg( m_info, _( "Requires %1$s knowledge level %2$d to understand." ),
skill.obj().name(), reading->req );
}
}
if( reading->intel != 0 ) {
add_msg( m_info, _( "Requires intelligence of %d to easily read." ), reading->intel );
}
//It feels wrong to use a pointer to *this, but I can't find any other player pointers in this method.
if( book_fun_for( book, *this ) != 0 ) {
add_msg( m_info, _( "Reading this book affects your morale by %d." ), book_fun_for( book, *this ) );
}
if( book.type->use_methods.count( "MA_MANUAL" ) ) {
const matype_id style_to_learn = martial_art_learned_from( *book.type );
add_msg( m_info, _( "You can learn %s style from it." ), style_to_learn->name );
add_msg( m_info, _( "This fighting style is %s to learn." ),
martialart_difficulty( style_to_learn ) );
add_msg( m_info, _( "It would be easier to master if you'd have skill expertise in %s." ),
style_to_learn->primary_skill->name() );
add_msg( m_info, _( "A training session with this book takes %s." ),
to_string_clipped( reading->time ) );
} else {
add_msg( m_info, _( "A chapter of this book takes %s to read." ),
to_string_clipped( reading->time ) );
}
std::vector<std::string> crafting_recipes;
std::vector<std::string> practice_recipes;
for( const islot_book::recipe_with_description_t &elem : reading->recipes ) {
// If the player knows it, they recognize it even if it's not clearly stated.
if( elem.is_hidden() && !knows_recipe( elem.recipe ) ) {
continue;
}
if( elem.recipe->is_practice() ) {
practice_recipes.emplace_back( elem.recipe->result_name() );
} else {
crafting_recipes.emplace_back( elem.name() );
}
}
if( !crafting_recipes.empty() ) {
add_msg( m_info, string_format( _( "This book can help you craft: %s" ),
enumerate_as_string( crafting_recipes ) ) );
}
if( !practice_recipes.empty() ) {
add_msg( m_info, string_format( _( "This book can help you practice: %s" ),
enumerate_as_string( practice_recipes ) ) );
}
const std::size_t num_total_recipes = crafting_recipes.size() + practice_recipes.size();
if( num_total_recipes < reading->recipes.size() ) {
add_msg( m_info, _( "It might help you figuring out some more recipes." ) );
}
}
void avatar::clear_nutrition()
{
calorie_diary.clear();
calorie_diary.emplace_front();
consumption_history.clear();
}
void avatar::clear_identified()
{
items_identified.clear();
}
void avatar::wake_up()
{
if( has_effect( effect_sleep ) ) {
// alarm was set and player hasn't slept through the alarm.
if( has_effect( effect_alarm_clock ) && !has_effect( effect_slept_through_alarm ) ) {
add_msg( _( "It looks like you woke up before your alarm." ) );
// effects will be removed in Character::wake_up.
} else if( has_effect( effect_slept_through_alarm ) ) {
if( has_flag( json_flag_ALARMCLOCK ) ) {
add_msg( m_warning, _( "It looks like you've slept through your internal alarm…" ) );
} else {
add_msg( m_warning, _( "It looks like you've slept through the alarm…" ) );
}
}
}
Character::wake_up();
}
void avatar::add_snippet( snippet_id snippet )
{
if( has_seen_snippet( snippet ) ) {
return;
}
snippets_read.emplace( snippet );
}
bool avatar::has_seen_snippet( const snippet_id &snippet ) const
{
return snippets_read.count( snippet ) > 0;
}
const std::set<snippet_id> &avatar::get_snippets()
{
return snippets_read;
}
void avatar::vomit()
{
if( stomach.contains() != 0_ml ) {
// Remove all joy from previously eaten food and apply the penalty
rem_morale( MORALE_FOOD_GOOD );
rem_morale( MORALE_FOOD_HOT );
// bears must suffer too
rem_morale( MORALE_HONEY );
// 1.5 times longer
add_morale( MORALE_VOMITED, -2 * units::to_milliliter( stomach.contains() / 50 ), -40, 90_minutes,
45_minutes, false );
} else {
add_msg( m_warning, _( "You retched, but your stomach is empty." ) );
}
Character::vomit();
}
bool avatar::try_break_relax_gas( const std::string &msg_success, const std::string &msg_failure )
{
const effect &pacify = get_effect( effect_relax_gas, body_part_mouth );
if( pacify.is_null() ) {
return true;
} else if( one_in( pacify.get_intensity() ) ) {
add_msg( m_good, msg_success );
return true;
} else {
mod_moves( std::max( 0, pacify.get_intensity() * 10 + rng( -30, 30 ) ) );
add_msg( m_bad, msg_failure );
return false;
}
}
nc_color avatar::basic_symbol_color() const
{
bool in_shell = has_active_mutation( trait_SHELL2 ) ||
has_active_mutation( trait_SHELL3 );
if( has_effect( effect_onfire ) ) {
return c_red;
}
if( has_effect( effect_stunned ) ) {
return c_light_blue;
}
if( has_effect( effect_psi_stunned ) ) {
return c_light_blue;
}
if( has_effect( effect_boomered ) ) {
return c_pink;
}
if( in_shell ) {
return c_magenta;
}
if( underwater ) {
return c_blue;
}
if( has_active_bionic( bio_cloak ) ||
is_wearing_active_optcloak() || has_trait( trait_DEBUG_CLOAK ) ) {
return c_dark_gray;
}
return move_mode->symbol_color();
}
int avatar::print_info( const catacurses::window &w, int vStart, int, int column ) const
{
return vStart + fold_and_print( w, point( column, vStart ), getmaxx( w ) - column - 1, c_dark_gray,
_( "You (%s)" ),
get_name() ) - 1;
}
mfaction_id avatar::get_monster_faction() const
{
return monfaction_player.id();
}
void avatar::disp_morale()
{
int equilibrium = calc_focus_equilibrium();
int fatigue_penalty = 0;
const int fatigue_cap = focus_equilibrium_fatigue_cap( equilibrium );
if( fatigue_cap < equilibrium ) {
fatigue_penalty = equilibrium - fatigue_cap;
equilibrium = fatigue_cap;
}
int pain_penalty = 0;
if( get_perceived_pain() && !has_trait( trait_CENOBITE ) ) {
pain_penalty = calc_focus_equilibrium( true ) - equilibrium - fatigue_penalty;
}
morale->display( equilibrium, pain_penalty, fatigue_penalty );
}
void avatar::reset_stats()
{
const int current_stim = get_stim();
// Trait / mutation buffs
if( has_trait( trait_THICK_SCALES ) ) {
add_miss_reason( _( "Your thick scales get in the way." ), 2 );
}
if( has_trait( trait_CHITIN2 ) || has_trait( trait_CHITIN3 ) || has_trait( trait_CHITIN_FUR3 ) ) {
add_miss_reason( _( "Your chitin gets in the way." ), 1 );
}
if( has_trait( trait_COMPOUND_EYES ) && !wearing_something_on( bodypart_id( "eyes" ) ) ) {
mod_per_bonus( 2 );
}
if( has_trait( trait_INSECT_ARMS ) ) {
add_miss_reason( _( "Your insect limbs get in the way." ), 2 );
}
if( has_trait( trait_INSECT_ARMS_OK ) ) {
if( !wearing_fitting_on( bodypart_id( "torso" ) ) ) {
mod_dex_bonus( 1 );
} else {
add_miss_reason( _( "Your clothing restricts your insect arms." ), 1 );
}
}
if( has_flag( json_flag_WEBBED_HANDS ) ) {
add_miss_reason( _( "Your webbed hands get in the way." ), 1 );
}
if( has_trait( trait_ARACHNID_ARMS ) ) {
add_miss_reason( _( "Your arachnid limbs get in the way." ), 4 );
}
if( has_trait( trait_ARACHNID_ARMS_OK ) ) {
if( !wearing_fitting_on( bodypart_id( "torso" ) ) ) {
mod_dex_bonus( 2 );
} else {
add_miss_reason( _( "Your clothing constricts your arachnid limbs." ), 2 );
}
}
const auto set_fake_effect_dur = [this]( const efftype_id & type, const time_duration & dur ) {
effect &eff = get_effect( type );
if( eff.get_duration() == dur ) {
return;
}
if( eff.is_null() && dur > 0_turns ) {
add_effect( type, dur, true );
} else if( dur > 0_turns ) {
eff.set_duration( dur );
} else {
remove_effect( type );
}
};