-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathmonster.cpp
3935 lines (3526 loc) · 138 KB
/
monster.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 "monster.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <tuple>
#include "ascii_art.h"
#include "avatar.h"
#include "bodypart.h"
#include "catacharset.h"
#include "character.h"
#include "colony.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "creature_tracker.h"
#include "cursesdef.h"
#include "debug.h"
#include "effect.h"
#include "effect_source.h"
#include "event.h"
#include "event_bus.h"
#include "explosion.h"
#include "faction.h"
#include "field_type.h"
#include "game.h"
#include "game_constants.h"
#include "harvest.h"
#include "item.h"
#include "item_group.h"
#include "itype.h"
#include "line.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "mattack_common.h"
#include "melee.h"
#include "messages.h"
#include "mission.h"
#include "mod_manager.h"
#include "mondeath.h"
#include "mondefense.h"
#include "monfaction.h"
#include "mongroup.h"
#include "morale_types.h"
#include "mtype.h"
#include "mutation.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "projectile.h"
#include "rng.h"
#include "sounds.h"
#include "string_formatter.h"
#include "text_snippets.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "units.h"
#include "viewer.h"
#include "weakpoint.h"
#include "weather.h"
static const anatomy_id anatomy_default_anatomy( "default_anatomy" );
static const damage_type_id damage_bash( "bash" );
static const damage_type_id damage_bullet( "bullet" );
static const damage_type_id damage_cut( "cut" );
static const damage_type_id damage_electric( "electric" );
static const damage_type_id damage_heat( "heat" );
static const damage_type_id damage_stab( "stab" );
static const efftype_id effect_badpoison( "badpoison" );
static const efftype_id effect_beartrap( "beartrap" );
static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_blind( "blind" );
static const efftype_id effect_bouldering( "bouldering" );
static const efftype_id effect_critter_underfed( "critter_underfed" );
static const efftype_id effect_critter_well_fed( "critter_well_fed" );
static const efftype_id effect_crushed( "crushed" );
static const efftype_id effect_deaf( "deaf" );
static const efftype_id effect_disarmed( "disarmed" );
static const efftype_id effect_docile( "docile" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_dripping_mechanical_fluid( "dripping_mechanical_fluid" );
static const efftype_id effect_emp( "emp" );
static const efftype_id effect_fake_common_cold( "fake_common_cold" );
static const efftype_id effect_fake_flu( "fake_flu" );
static const efftype_id effect_grabbing( "grabbing" );
static const efftype_id effect_has_bag( "has_bag" );
static const efftype_id effect_heavysnare( "heavysnare" );
static const efftype_id effect_hit_by_player( "hit_by_player" );
static const efftype_id effect_in_pit( "in_pit" );
static const efftype_id effect_leashed( "leashed" );
static const efftype_id effect_lightsnare( "lightsnare" );
static const efftype_id effect_maimed_arm( "maimed_arm" );
static const efftype_id effect_monster_armor( "monster_armor" );
static const efftype_id effect_monster_saddled( "monster_saddled" );
static const efftype_id effect_natures_commune( "natures_commune" );
static const efftype_id effect_no_sight( "no_sight" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pacified( "pacified" );
static const efftype_id effect_paralyzepoison( "paralyzepoison" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_photophobia( "photophobia" );
static const efftype_id effect_poison( "poison" );
static const efftype_id effect_ridden( "ridden" );
static const efftype_id effect_run( "run" );
static const efftype_id effect_slippery_terrain( "slippery_terrain" );
static const efftype_id effect_spooked( "spooked" );
static const efftype_id effect_spooked_recent( "spooked_recent" );
static const efftype_id effect_stunned( "stunned" );
static const efftype_id effect_supercharged( "supercharged" );
static const efftype_id effect_tied( "tied" );
static const efftype_id effect_tpollen( "tpollen" );
static const efftype_id effect_venom_dmg( "venom_dmg" );
static const efftype_id effect_venom_player1( "venom_player1" );
static const efftype_id effect_venom_player2( "venom_player2" );
static const efftype_id effect_venom_weaken( "venom_weaken" );
static const efftype_id effect_webbed( "webbed" );
static const efftype_id effect_worked_on( "worked_on" );
static const emit_id emit_emit_shock_cloud( "emit_shock_cloud" );
static const emit_id emit_emit_shock_cloud_big( "emit_shock_cloud_big" );
static const flag_id json_flag_DISABLE_FLIGHT( "DISABLE_FLIGHT" );
static const flag_id json_flag_GRAB( "GRAB" );
static const flag_id json_flag_GRAB_FILTER( "GRAB_FILTER" );
static const itype_id itype_milk( "milk" );
static const itype_id itype_milk_raw( "milk_raw" );
static const material_id material_bone( "bone" );
static const material_id material_flesh( "flesh" );
static const material_id material_hflesh( "hflesh" );
static const material_id material_iflesh( "iflesh" );
static const material_id material_iron( "iron" );
static const material_id material_steel( "steel" );
static const material_id material_stone( "stone" );
static const material_id material_veggy( "veggy" );
static const mfaction_str_id monfaction_acid_ant( "acid_ant" );
static const mfaction_str_id monfaction_ant( "ant" );
static const mfaction_str_id monfaction_bee( "bee" );
static const mfaction_str_id monfaction_nether_player_hate( "nether_player_hate" );
static const mfaction_str_id monfaction_wasp( "wasp" );
static const mon_flag_str_id mon_flag_ANIMAL( "ANIMAL" );
static const mon_flag_str_id mon_flag_AQUATIC( "AQUATIC" );
static const mon_flag_str_id mon_flag_ATTACK_LOWER( "ATTACK_LOWER" );
static const mon_flag_str_id mon_flag_ATTACK_UPPER( "ATTACK_UPPER" );
static const mon_flag_str_id mon_flag_BADVENOM( "BADVENOM" );
static const mon_flag_str_id mon_flag_CAN_DIG( "CAN_DIG" );
static const mon_flag_str_id mon_flag_CLIMBS( "CLIMBS" );
static const mon_flag_str_id mon_flag_CORNERED_FIGHTER( "CORNERED_FIGHTER" );
static const mon_flag_str_id mon_flag_DIGS( "DIGS" );
static const mon_flag_str_id mon_flag_EATS( "EATS" );
static const mon_flag_str_id mon_flag_ELECTRIC( "ELECTRIC" );
static const mon_flag_str_id mon_flag_ELECTRIC_FIELD( "ELECTRIC_FIELD" );
static const mon_flag_str_id mon_flag_ELECTRONIC( "ELECTRONIC" );
static const mon_flag_str_id mon_flag_FILTHY( "FILTHY" );
static const mon_flag_str_id mon_flag_FIREY( "FIREY" );
static const mon_flag_str_id mon_flag_FLIES( "FLIES" );
static const mon_flag_str_id mon_flag_GOODHEARING( "GOODHEARING" );
static const mon_flag_str_id mon_flag_GRABS( "GRABS" );
static const mon_flag_str_id mon_flag_HAS_MIND( "HAS_MIND" );
static const mon_flag_str_id mon_flag_HEARS( "HEARS" );
static const mon_flag_str_id mon_flag_HIT_AND_RUN( "HIT_AND_RUN" );
static const mon_flag_str_id mon_flag_HUMAN( "HUMAN" );
static const mon_flag_str_id mon_flag_IMMOBILE( "IMMOBILE" );
static const mon_flag_str_id mon_flag_KEEP_DISTANCE( "KEEP_DISTANCE" );
static const mon_flag_str_id mon_flag_MILKABLE( "MILKABLE" );
static const mon_flag_str_id mon_flag_NEMESIS( "NEMESIS" );
static const mon_flag_str_id mon_flag_NEVER_WANDER( "NEVER_WANDER" );
static const mon_flag_str_id mon_flag_NOHEAD( "NOHEAD" );
static const mon_flag_str_id mon_flag_NO_BREATHE( "NO_BREATHE" );
static const mon_flag_str_id mon_flag_NO_BREED( "NO_BREED" );
static const mon_flag_str_id mon_flag_NO_FUNG_DMG( "NO_FUNG_DMG" );
static const mon_flag_str_id mon_flag_PARALYZEVENOM( "PARALYZEVENOM" );
static const mon_flag_str_id mon_flag_PATH_AVOID_DANGER_1( "PATH_AVOID_DANGER_1" );
static const mon_flag_str_id mon_flag_PATH_AVOID_DANGER_2( "PATH_AVOID_DANGER_2" );
static const mon_flag_str_id mon_flag_PATH_AVOID_FALL( "PATH_AVOID_FALL" );
static const mon_flag_str_id mon_flag_PATH_AVOID_FIRE( "PATH_AVOID_FIRE" );
static const mon_flag_str_id mon_flag_PET_MOUNTABLE( "PET_MOUNTABLE" );
static const mon_flag_str_id mon_flag_PET_WONT_FOLLOW( "PET_WONT_FOLLOW" );
static const mon_flag_str_id mon_flag_PHOTOPHOBIC( "PHOTOPHOBIC" );
static const mon_flag_str_id mon_flag_PLASTIC( "PLASTIC" );
static const mon_flag_str_id mon_flag_PRIORITIZE_TARGETS( "PRIORITIZE_TARGETS" );
static const mon_flag_str_id mon_flag_QUEEN( "QUEEN" );
static const mon_flag_str_id mon_flag_REVIVES( "REVIVES" );
static const mon_flag_str_id mon_flag_REVIVES_HEALTHY( "REVIVES_HEALTHY" );
static const mon_flag_str_id mon_flag_RIDEABLE_MECH( "RIDEABLE_MECH" );
static const mon_flag_str_id mon_flag_SEES( "SEES" );
static const mon_flag_str_id mon_flag_SMELLS( "SMELLS" );
static const mon_flag_str_id mon_flag_STUN_IMMUNE( "STUN_IMMUNE" );
static const mon_flag_str_id mon_flag_SUNDEATH( "SUNDEATH" );
static const mon_flag_str_id mon_flag_SWIMS( "SWIMS" );
static const mon_flag_str_id mon_flag_VENOM( "VENOM" );
static const mon_flag_str_id mon_flag_WARM( "WARM" );
static const mon_flag_str_id mon_flag_WIELDED_WEAPON( "WIELDED_WEAPON" );
static const species_id species_AMPHIBIAN( "AMPHIBIAN" );
static const species_id species_CYBORG( "CYBORG" );
static const species_id species_FISH( "FISH" );
static const species_id species_FUNGUS( "FUNGUS" );
static const species_id species_HORROR( "HORROR" );
static const species_id species_LEECH_PLANT( "LEECH_PLANT" );
static const species_id species_MAMMAL( "MAMMAL" );
static const species_id species_MIGO( "MIGO" );
static const species_id species_MOLLUSK( "MOLLUSK" );
static const species_id species_NETHER( "NETHER" );
static const species_id species_PLANT( "PLANT" );
static const species_id species_PSI_NULL( "PSI_NULL" );
static const species_id species_ROBOT( "ROBOT" );
static const species_id species_ZOMBIE( "ZOMBIE" );
static const species_id species_nether_player_hate( "nether_player_hate" );
static const ter_str_id ter_t_gas_pump( "t_gas_pump" );
static const ter_str_id ter_t_gas_pump_a( "t_gas_pump_a" );
static const trait_id trait_ANIMALDISCORD( "ANIMALDISCORD" );
static const trait_id trait_ANIMALDISCORD2( "ANIMALDISCORD2" );
static const trait_id trait_ANIMALEMPATH( "ANIMALEMPATH" );
static const trait_id trait_ANIMALEMPATH2( "ANIMALEMPATH2" );
static const trait_id trait_BEE( "BEE" );
static const trait_id trait_FLOWERS( "FLOWERS" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );
static const trait_id trait_KILLER( "KILLER" );
static const trait_id trait_MYCUS_FRIEND( "MYCUS_FRIEND" );
static const trait_id trait_PHEROMONE_AMPHIBIAN( "PHEROMONE_AMPHIBIAN" );
static const trait_id trait_PHEROMONE_INSECT( "PHEROMONE_INSECT" );
static const trait_id trait_PHEROMONE_MAMMAL( "PHEROMONE_MAMMAL" );
static const trait_id trait_TERRIFYING( "TERRIFYING" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
struct pathfinding_settings;
// Limit the number of iterations for next upgrade_time calculations.
// This also sets the percentage of monsters that will never upgrade.
// The rough formula is 2^(-x), e.g. for x = 5 it's 0.03125 (~ 3%).
static constexpr int UPGRADE_MAX_ITERS = 5;
static const std::map<creature_size, translation> size_names {
{ creature_size::tiny, to_translation( "size adj", "tiny" ) },
{ creature_size::small, to_translation( "size adj", "small" ) },
{ creature_size::medium, to_translation( "size adj", "medium" ) },
{ creature_size::large, to_translation( "size adj", "large" ) },
{ creature_size::huge, to_translation( "size adj", "huge" ) },
};
static const std::map<monster_attitude, std::pair<std::string, color_id>> attitude_names {
{monster_attitude::MATT_FRIEND, {translate_marker( "Friendly." ), def_h_white}},
{monster_attitude::MATT_FPASSIVE, {translate_marker( "Passive." ), def_h_white}},
{monster_attitude::MATT_FLEE, {translate_marker( "Fleeing!" ), def_c_green}},
{monster_attitude::MATT_FOLLOW, {translate_marker( "Tracking." ), def_c_yellow}},
{monster_attitude::MATT_IGNORE, {translate_marker( "Ignoring." ), def_c_light_gray}},
{monster_attitude::MATT_ATTACK, {translate_marker( "Hostile!" ), def_c_red}},
{monster_attitude::MATT_NULL, {translate_marker( "BUG: Behavior unnamed." ), def_h_red}},
};
static int compute_kill_xp( const mtype_id &mon_type )
{
return mon_type->difficulty + mon_type->difficulty_base;
}
monster::monster()
{
unset_dest();
wandf = 0;
hp = 60;
moves = 0;
friendly = 0;
anger = 0;
morale = 2;
faction = mfaction_id( 0 );
no_extra_death_drops = false;
dead = false;
death_drops = true;
made_footstep = false;
hallucination = false;
ignoring = 0;
upgrades = false;
upgrade_time = -1;
stomach_timer = calendar::turn;
last_updated = calendar::turn_zero;
biosig_timer = calendar::before_time_starts;
udder_timer = calendar::turn;
horde_attraction = MHA_NULL;
aggro_character = true;
set_anatomy( anatomy_default_anatomy );
set_body();
}
monster::monster( const mtype_id &id ) : monster()
{
type = &id.obj();
moves = type->speed;
Creature::set_speed_base( type->speed );
hp = type->hp;
for( const auto &sa : type->special_attacks ) {
mon_special_attack &entry = special_attacks[sa.first];
entry.cooldown = rng( 0, sa.second->cooldown );
}
anger = type->agro;
morale = type->morale;
stomach_size = type->stomach_size;
faction = type->default_faction;
upgrades = type->upgrades && ( type->half_life || type->age_grow );
reproduces = type->reproduces && type->baby_timer && !monster::has_flag( mon_flag_NO_BREED );
biosignatures = type->biosignatures;
if( monster::has_flag( mon_flag_AQUATIC ) ) {
fish_population = dice( 1, 20 );
}
if( monster::has_flag( mon_flag_RIDEABLE_MECH ) ) {
itype_id mech_bat = itype_id( type->mech_battery );
const itype &type = *item::find_type( mech_bat );
int max_charge = type.magazine->capacity;
item mech_bat_item = item( mech_bat, calendar::turn_zero );
mech_bat_item.ammo_consume( rng( 0, max_charge ), tripoint_zero, nullptr );
battery_item = cata::make_value<item>( mech_bat_item );
}
if( monster::has_flag( mon_flag_PET_MOUNTABLE ) ) {
if( !type->mount_items.tied.is_empty() ) {
itype_id tied_item_id = itype_id( type->mount_items.tied );
item tied_item_item = item( tied_item_id, calendar::turn_zero );
add_effect( effect_leashed, 1_turns, true );
tied_item = cata::make_value<item>( tied_item_item );
}
if( !type->mount_items.tack.is_empty() ) {
itype_id tack_item_id = itype_id( type->mount_items.tack );
item tack_item_item = item( tack_item_id, calendar::turn_zero );
add_effect( effect_monster_saddled, 1_turns, true );
tack_item = cata::make_value<item>( tack_item_item );
}
if( !type->mount_items.armor.is_empty() ) {
itype_id armor_item_id = itype_id( type->mount_items.armor );
item armor_item_item = item( armor_item_id, calendar::turn_zero );
add_effect( effect_monster_armor, 1_turns, true );
armor_item = cata::make_value<item>( armor_item_item );
}
if( !type->mount_items.storage.is_empty() ) {
itype_id storage_item_id = itype_id( type->mount_items.storage );
item storage_item_item = item( storage_item_id, calendar::turn_zero );
add_effect( effect_has_bag, 1_turns, true );
tack_item = cata::make_value<item>( storage_item_item );
}
}
aggro_character = type->aggro_character;
}
monster::monster( const mtype_id &id, const tripoint &p ) : monster( id )
{
set_pos_only( p );
unset_dest();
}
monster::monster( const monster & ) = default;
monster::monster( monster && ) noexcept( map_is_noexcept ) = default;
monster::~monster() = default;
monster &monster::operator=( const monster & ) = default;
monster &monster::operator=( monster && ) noexcept( string_is_noexcept ) = default;
void monster::on_move( const tripoint_abs_ms &old_pos )
{
Creature::on_move( old_pos );
if( old_pos == get_location() ) {
return;
}
g->update_zombie_pos( *this, old_pos, get_location() );
if( has_effect( effect_ridden ) && mounted_player &&
mounted_player->get_location() != get_location() ) {
add_msg_debug( debugmode::DF_MONSTER, "Ridden monster %s moved independently and dumped player",
get_name() );
mounted_player->forced_dismount();
}
if( has_dest() && get_location() == get_dest() ) {
unset_dest();
}
}
void monster::poly( const mtype_id &id )
{
double hp_percentage = static_cast<double>( hp ) / static_cast<double>( type->hp );
if( !no_extra_death_drops ) {
generate_inventory();
}
type = &id.obj();
moves = 0;
Creature::set_speed_base( type->speed );
anger = type->agro;
morale = type->morale;
hp = static_cast<int>( hp_percentage * type->hp );
special_attacks.clear();
for( const auto &sa : type->special_attacks ) {
mon_special_attack &entry = special_attacks[sa.first];
entry.cooldown = sa.second->cooldown;
}
faction = type->default_faction;
upgrades = type->upgrades;
reproduces = type->reproduces;
biosignatures = type->biosignatures;
aggro_character = type->aggro_character;
}
bool monster::can_upgrade() const
{
return upgrades && get_option<float>( "MONSTER_UPGRADE_FACTOR" ) > 0.0;
}
// For master special attack.
void monster::hasten_upgrade()
{
if( !can_upgrade() || upgrade_time < 1 ) {
return;
}
const int scaled_half_life = type->half_life * get_option<float>( "MONSTER_UPGRADE_FACTOR" );
upgrade_time -= rng( 1, scaled_half_life );
if( upgrade_time < 0 ) {
upgrade_time = 0;
}
}
int monster::get_upgrade_time() const
{
return upgrade_time;
}
// Sets time to upgrade to 0.
void monster::allow_upgrade()
{
upgrade_time = 0;
}
// This will disable upgrades in case max iters have been reached.
// Checking for return value of -1 is necessary.
int monster::next_upgrade_time()
{
if( type->age_grow > 0 ) {
return type->age_grow;
}
const int scaled_half_life = type->half_life * get_option<float>( "MONSTER_UPGRADE_FACTOR" );
int day = 1; // 1 day of guaranteed evolve time
for( int i = 0; i < UPGRADE_MAX_ITERS; i++ ) {
if( one_in( 2 ) ) {
day += rng( 0, scaled_half_life );
return day;
} else {
day += scaled_half_life;
}
}
// didn't manage to upgrade, shouldn't ever then
upgrades = false;
return -1;
}
void monster::try_upgrade( bool pin_time )
{
if( !can_upgrade() ) {
return;
}
const int current_day = to_days<int>( calendar::turn - calendar::turn_zero );
//This should only occur when a monster is created or upgraded to a new form
if( upgrade_time < 0 ) {
upgrade_time = next_upgrade_time();
if( upgrade_time < 0 ) {
return;
}
if( pin_time || type->age_grow > 0 ) {
// offset by today, always true for growing creatures
upgrade_time += current_day;
} else {
// offset by starting season
// TODO: revisit this and make it simpler
upgrade_time += to_days<int>( calendar::start_of_cataclysm - calendar::turn_zero );
}
}
// Here we iterate until we either are before upgrade_time or can't upgrade any more.
// This is so that late into game new monsters can 'catch up' with all that half-life
// upgrades they'd get if we were simulating whole world.
while( true ) {
if( upgrade_time > current_day ) {
// not yet
return;
}
if( type->upgrade_into ) {
//If we upgrade into a blacklisted monster, treat it as though we are non-upgradeable
if( MonsterGroupManager::monster_is_blacklisted( type->upgrade_into ) ) {
return;
}
poly( type->upgrade_into );
} else {
mtype_id new_type;
if( type->upgrade_multi_range ) {
bool ret_default = false;
std::vector<MonsterGroupResult> res = MonsterGroupManager::GetResultFromGroup(
type->upgrade_group, nullptr, nullptr, false, &ret_default );
if( !res.empty() && !ret_default ) {
// Set the type to poly the current monster (preserves inventory)
new_type = res.front().name;
res.front().pack_size--;
for( const MonsterGroupResult &mgr : res ) {
if( !mgr.name ) {
continue;
}
for( int i = 0; i < mgr.pack_size; i++ ) {
tripoint spawn_pos;
if( g->find_nearby_spawn_point( pos(), mgr.name, 1, *type->upgrade_multi_range,
spawn_pos, false, false ) ) {
monster *spawned = g->place_critter_at( mgr.name, spawn_pos );
if( spawned ) {
spawned->friendly = friendly;
}
}
}
}
}
} else {
new_type = MonsterGroupManager::GetRandomMonsterFromGroup( type->upgrade_group );
}
if( !new_type.is_empty() ) {
if( new_type ) {
poly( new_type );
} else {
// "upgrading" to mon_null
if( type->upgrade_null_despawn ) {
g->remove_zombie( *this );
} else {
die( nullptr );
}
return;
}
}
}
if( !upgrades ) {
// upgraded into a non-upgradeable monster
return;
}
const int next_upgrade = next_upgrade_time();
if( next_upgrade < 0 ) {
// hit never_upgrade
return;
}
upgrade_time += next_upgrade;
}
}
void monster::try_reproduce()
{
if( !reproduces ) {
return;
}
// This can happen if the monster type has changed (from reproducing to non-reproducing monster)
if( !type->baby_timer ) {
return;
}
if( !baby_timer && amount_eaten >= stomach_size ) {
// Assume this is a freshly spawned monster (because baby_timer is not set yet), set the point when it reproduce to somewhere in the future.
// Monsters need to have eaten eat to start their pregnancy timer, but that's all.
baby_timer.emplace( calendar::turn + *type->baby_timer );
}
bool season_spawn = false;
bool season_match = true;
// only 50% of animals should reproduce
bool female = one_in( 2 );
for( const std::string &elem : type->baby_flags ) {
if( elem == "SUMMER" || elem == "WINTER" || elem == "SPRING" || elem == "AUTUMN" ) {
season_spawn = true;
}
}
map &here = get_map();
// add a decreasing chance of additional spawns when "catching up" an existing animal.
int chance = -1;
while( true ) {
if( *baby_timer > calendar::turn ) {
return;
}
if( season_spawn ) {
season_match = false;
for( const std::string &elem : type->baby_flags ) {
if( ( season_of_year( *baby_timer ) == SUMMER && elem == "SUMMER" ) ||
( season_of_year( *baby_timer ) == WINTER && elem == "WINTER" ) ||
( season_of_year( *baby_timer ) == SPRING && elem == "SPRING" ) ||
( season_of_year( *baby_timer ) == AUTUMN && elem == "AUTUMN" ) ) {
season_match = true;
}
}
}
chance += 2;
if( has_flag( mon_flag_EATS ) && has_effect( effect_critter_underfed ) ) {
chance += 1; //Reduce the chances but don't prevent birth if the animal is not eating.
}
if( season_match && female && one_in( chance ) ) {
int spawn_cnt = rng( 1, type->baby_count );
if( type->baby_monster ) {
here.add_spawn( type->baby_monster, spawn_cnt, pos() );
} else {
here.add_item_or_charges( pos(), item( type->baby_egg, *baby_timer, spawn_cnt ), true );
}
}
*baby_timer += *type->baby_timer;
}
}
void monster::refill_udders()
{
if( type->starting_ammo.empty() ) {
debugmsg( "monster %s has no starting ammo to refill udders", get_name() );
return;
}
if( ammo.empty() ) {
// legacy animals got empty ammo map, fill them up now if needed.
ammo[type->starting_ammo.begin()->first] = type->starting_ammo.begin()->second;
}
auto current_milk = ammo.find( itype_milk_raw );
if( current_milk == ammo.end() ) {
current_milk = ammo.find( itype_milk );
if( current_milk != ammo.end() ) {
// take this opportunity to update milk udders to raw_milk
ammo[itype_milk_raw] = current_milk->second;
// Erase old key-value from map
ammo.erase( current_milk );
}
}
// if we got here, we got milk.
if( current_milk->second == type->starting_ammo.begin()->second ) {
// already full up
return;
}
if( ( !has_flag( mon_flag_EATS ) || has_effect( effect_critter_well_fed ) ) ) {
if( calendar::turn - udder_timer > 1_days ) {
// You milk once a day. Monsters with the EATS flag need to be well fed or they won't refill their udders.
ammo.begin()->second = type->starting_ammo.begin()->second;
udder_timer = calendar::turn;
}
}
}
void monster::reset_digestion()
{
if( calendar::turn - stomach_timer > 3_days ) {
//If the player hasn't been around, assume critters have been operating at a subsistence level.
//Otherwise everything will constantly be underfed. We only run this on load to prevent problems.
remove_effect( effect_critter_underfed );
remove_effect( effect_critter_well_fed );
amount_eaten = 0;
stomach_timer = calendar::turn;
}
}
void monster::digest_food()
{
if( calendar::turn - stomach_timer > 1_days ) {
if( ( amount_eaten >= stomach_size ) && !has_effect( effect_critter_underfed ) ) {
add_effect( effect_critter_well_fed, 24_hours );
} else if( ( amount_eaten < ( stomach_size / 10 ) ) && !has_effect( effect_critter_well_fed ) ) {
add_effect( effect_critter_underfed, 24_hours );
}
amount_eaten = 0;
stomach_timer = calendar::turn;
}
}
void monster::try_biosignature()
{
if( is_hallucination() ) {
return;
}
if( !biosignatures ) {
return;
}
if( !type->biosig_timer ) {
return;
}
if( has_effect( effect_critter_underfed ) ) {
return;
}
if( !biosig_timer ) {
biosig_timer.emplace( calendar::turn + *type->biosig_timer );
}
map &here = get_map();
int counter = 0;
while( true ) {
// don't catch up too much, otherwise on some scenarios,
// we could have years worth of poop just deposited on the floor.
if( *biosig_timer > calendar::turn || counter > 50 ) {
return;
}
here.add_item_or_charges( pos(), item( type->biosig_item, *biosig_timer, 1 ), true );
*biosig_timer += *type->biosig_timer;
counter += 1;
}
}
void monster::spawn( const tripoint &p )
{
set_pos_only( p );
unset_dest();
}
void monster::spawn( const tripoint_abs_ms &loc )
{
set_location( loc );
unset_dest();
}
std::string monster::get_name() const
{
return name( 1 );
}
std::string monster::name( unsigned int quantity ) const
{
if( !type ) {
debugmsg( "monster::name empty type!" );
return std::string();
}
std::string result = type->nname( quantity );
if( !nickname.empty() ) {
return nickname;
}
if( !unique_name.empty() ) {
//~ %1$s: monster name, %2$s: unique name
result = string_format( pgettext( "unique monster name", "%1$s: %2$s" ),
result, unique_name );
}
if( !mission_fused.empty() ) {
//~ name when a monster fuses with a mission target
result = string_format( pgettext( "fused mission monster", "*%s" ), result );
}
return result;
}
// TODO: MATERIALS put description in materials.json?
std::string monster::name_with_armor() const
{
std::string ret;
if( made_of( material_iflesh ) ) {
ret = _( "carapace" );
} else if( made_of( material_veggy ) ) {
ret = _( "thick bark" );
} else if( made_of( material_bone ) ) {
ret = _( "exoskeleton" );
} else if( made_of( material_flesh ) || made_of( material_hflesh ) ) {
ret = _( "thick hide" );
} else if( made_of( material_iron ) || made_of( material_steel ) ) {
ret = _( "armor plating" );
} else if( made_of( phase_id::LIQUID ) ) {
ret = _( "dense jelly mass" );
} else {
ret = _( "armor" );
}
if( has_effect( effect_monster_armor ) && !inv.empty() ) {
for( const item &armor : inv ) {
if( armor.is_pet_armor( true ) ) {
ret += string_format( _( "wearing %1$s" ), armor.tname( 1 ) );
break;
}
}
}
return ret;
}
std::string monster::disp_name( bool possessive, bool capitalize_first ) const
{
if( !possessive ) {
return string_format( capitalize_first ? _( "The %s" ) : _( "the %s" ), name() );
} else {
return string_format( capitalize_first ? _( "The %s's" ) : _( "the %s's" ), name() );
}
}
std::string monster::skin_name() const
{
return name_with_armor();
}
void monster::get_HP_Bar( nc_color &color, std::string &text ) const
{
std::tie( text, color ) = ::get_hp_bar( hp, type->hp, true );
}
std::pair<std::string, nc_color> monster::get_attitude() const
{
const auto att = attitude_names.at( attitude( &get_player_character() ) );
return {
_( att.first ),
all_colors.get( att.second )
};
}
static std::pair<std::string, nc_color> hp_description( int cur_hp, int max_hp )
{
std::string damage_info;
nc_color col;
if( cur_hp >= max_hp ) {
damage_info = _( "It is uninjured." );
col = c_green;
} else if( cur_hp >= max_hp * 0.8 ) {
damage_info = _( "It is lightly injured." );
col = c_light_green;
} else if( cur_hp >= max_hp * 0.6 ) {
damage_info = _( "It is moderately injured." );
col = c_yellow;
} else if( cur_hp >= max_hp * 0.3 ) {
damage_info = _( "It is heavily injured." );
col = c_yellow;
} else if( cur_hp >= max_hp * 0.1 ) {
damage_info = _( "It is severely injured." );
col = c_light_red;
} else {
damage_info = _( "It is nearly dead!" );
col = c_red;
}
if( debug_mode ) {
damage_info += " ";
damage_info += string_format( _( "%1$d/%2$d HP" ), cur_hp, max_hp );
}
return std::make_pair( damage_info, col );
}
std::string monster::speed_description( float mon_speed_rating,
bool immobile,
const speed_description_id &speed_desc )
{
if( speed_desc.is_null() || !speed_desc.is_valid() ) {
return std::string();
}
const avatar &ply = get_avatar();
double player_runcost = ply.run_cost( 100 );
if( player_runcost <= 0.00 ) {
player_runcost = 0.01f;
}
// tpt = tiles per turn
const double player_tpt = ply.get_speed() / player_runcost;
double ratio_tpt = player_tpt == 0.00 ?
100.00 : mon_speed_rating / player_tpt;
ratio_tpt *= immobile ? 0.00 : 1.00;
for( const speed_description_value &speed_value : speed_desc->values() ) {
if( ratio_tpt >= speed_value.value() ) {
return random_entry( speed_value.descriptions(), translation() ).translated();
}
}
return std::string();
}
int monster::print_info( const catacurses::window &w, int vStart, int vLines, int column ) const
{
const int vEnd = vStart + vLines;
const int max_width = getmaxx( w ) - column - 1;
std::ostringstream oss;
oss << get_tag_from_color( c_white ) << _( "Origin: " );
oss << enumerate_as_string( type->src.begin(),
type->src.end(), []( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
oss << "</color>" << "\n";
if( debug_mode ) {
oss << colorize( type->id.str(), c_white );
}
oss << "\n";
// Print health bar, monster name, then statuses on the first line.
nc_color bar_color = c_white;
std::string bar_str;
get_HP_Bar( bar_color, bar_str );
oss << get_tag_from_color( bar_color ) << bar_str << "</color>";
oss << "<color_white>" << std::string( 5 - utf8_width( bar_str ), '.' ) << "</color> ";
oss << get_tag_from_color( basic_symbol_color() ) << name() << "</color> ";
oss << "<color_h_white>" << get_effect_status() << "</color>";
vStart += fold_and_print( w, point( column, vStart ), max_width, c_white, oss.str() );
Character &pc = get_player_character();
bool sees_player = sees( pc );
const bool player_knows = !pc.has_trait( trait_INATTENTIVE );
// Hostility indicator on the second line.
std::pair<std::string, nc_color> att = get_attitude();
if( player_knows ) {
mvwprintz( w, point( column, vStart++ ), att.second, att.first );
}
// Awareness indicator in the third line.
std::string senses_str = sees_player ? _( "Can see to your current location" ) :
_( "Can't see to your current location" );
if( player_knows ) {
vStart += fold_and_print( w, point( column, vStart ), max_width, player_knows &&
sees_player ? c_red : c_green,
senses_str );
}
const std::string speed_desc = speed_description(
speed_rating(),
has_flag( mon_flag_IMMOBILE ),
type->speed_desc );
vStart += fold_and_print( w, point( column, vStart ), max_width, c_white, speed_desc );
// Monster description on following lines.
std::vector<std::string> lines = foldstring( type->get_description(), max_width );
int numlines = lines.size();
for( int i = 0; i < numlines && vStart < vEnd; i++ ) {
mvwprintz( w, point( column, vStart++ ), c_light_gray, lines[i] );
}
if( !mission_fused.empty() ) {
// Mission monsters fused into this monster
const std::string fused_desc = string_format( _( "Parts of %s protrude from its body." ),
enumerate_as_string( mission_fused ) );
lines = foldstring( fused_desc, max_width );
numlines = lines.size();
for( int i = 0; i < numlines && vStart < vEnd; i++ ) {
mvwprintz( w, point( column, ++vStart ), c_light_gray, lines[i] );
}
}
// Riding indicator on next line after description.
if( has_effect( effect_ridden ) && mounted_player ) {
mvwprintz( w, point( column, ++vStart ), c_white, _( "Rider: %s" ), mounted_player->disp_name() );
}
// Show monster size on the last line
if( size_bonus > 0 ) {
mvwprintz( w, point( column, ++vStart ), c_light_gray, _( " It is %s." ),
size_names.at( get_size() ) );
}
if( get_option<bool>( "ENABLE_ASCII_ART" ) ) {
const ascii_art_id art = type->get_picture_id();
if( art.is_valid() ) {
for( const std::string &line : art->picture ) {
fold_and_print( w, point( column, ++vStart ), max_width, c_white, line );
}
}
}
return ++vStart;
}
std::string monster::extended_description() const
{
std::string ss;
Character &pc = get_player_character();
const bool player_knows = !pc.has_trait( trait_INATTENTIVE );
const std::pair<std::string, nc_color> att = get_attitude();
std::string att_colored = colorize( att.first, att.second );
std::string difficulty_str;
if( debug_mode ) {
difficulty_str = _( "Difficulty " ) + std::to_string( type->difficulty );
} else {
if( type->difficulty < 3 ) {
difficulty_str = _( "<color_light_gray>Minimal threat.</color>" );
} else if( type->difficulty < 10 ) {
difficulty_str = _( "<color_light_gray>Mildly dangerous.</color>" );
} else if( type->difficulty < 20 ) {
difficulty_str = _( "<color_light_red>Dangerous.</color>" );
} else if( type->difficulty < 30 ) {
difficulty_str = _( "<color_red>Very dangerous.</color>" );
} else if( type->difficulty < 50 ) {
difficulty_str = _( "<color_red>Extremely dangerous.</color>" );
} else {
difficulty_str = _( "<color_red>Fatally dangerous!</color>" );
}
}
ss += _( "Origin: " );
ss += enumerate_as_string( type->src.begin(),
type->src.end(), []( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );