Skip to content

Commit aeed8dd

Browse files
committed
Use ammo_effect_str_id instead of std::string
1 parent 745fada commit aeed8dd

24 files changed

+229
-127
lines changed

src/ammo_effect.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,35 @@ const ammo_effect &int_id<ammo_effect>::obj() const
3030

3131
/** @relates int_id */
3232
template<>
33-
const string_id<ammo_effect> &int_id<ammo_effect>::id() const
33+
const ammo_effect_str_id &int_id<ammo_effect>::id() const
3434
{
3535
return get_all_ammo_effects().convert( *this );
3636
}
3737

3838
/** @relates string_id */
3939
template<>
40-
bool string_id<ammo_effect>::is_valid() const
40+
bool ammo_effect_str_id::is_valid() const
4141
{
4242
return get_all_ammo_effects().is_valid( *this );
4343
}
4444

4545
/** @relates string_id */
4646
template<>
47-
const ammo_effect &string_id<ammo_effect>::obj() const
47+
const ammo_effect &ammo_effect_str_id::obj() const
4848
{
4949
return get_all_ammo_effects().obj( *this );
5050
}
5151

5252
/** @relates string_id */
5353
template<>
54-
int_id<ammo_effect> string_id<ammo_effect>::id() const
54+
int_id<ammo_effect> ammo_effect_str_id::id() const
5555
{
5656
return get_all_ammo_effects().convert( *this, AE_NULL );
5757
}
5858

5959
/** @relates int_id */
6060
template<>
61-
int_id<ammo_effect>::int_id( const string_id<ammo_effect> &id ) : _id( id.id() )
61+
int_id<ammo_effect>::int_id( const ammo_effect_str_id &id ) : _id( id.id() )
6262
{
6363
}
6464

src/ammo_effect.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ struct ammo_effect {
5252
int trail_chance = 100;
5353

5454
// Used by generic_factory
55-
string_id<ammo_effect> id;
56-
std::vector<std::pair<string_id<ammo_effect>, mod_id>> src;
55+
ammo_effect_str_id id;
56+
std::vector<std::pair<ammo_effect_str_id, mod_id>> src;
5757
bool was_loaded = false;
5858

5959
static size_t count();

src/ballistics.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@
3838
#include "units.h"
3939
#include "vpart_position.h"
4040

41+
static const ammo_effect_str_id ammo_effect_id_ACT_ON_RANGED_HIT( "ACT_ON_RANGED_HIT" );
42+
static const ammo_effect_str_id ammo_effect_id_BOUNCE( "BOUNCE" );
43+
static const ammo_effect_str_id ammo_effect_id_BURST( "BURST" );
44+
static const ammo_effect_str_id ammo_effect_id_DRAW_AS_LINE( "DRAW_AS_LINE" );
45+
static const ammo_effect_str_id ammo_effect_id_HEAVY_HIT( "HEAVY_HIT" );
46+
static const ammo_effect_str_id ammo_effect_id_JET( "JET" );
47+
static const ammo_effect_str_id ammo_effect_id_MUZZLE_SMOKE( "MUZZLE_SMOKE" );
48+
static const ammo_effect_str_id ammo_effect_id_NO_EMBED( "NO_EMBED" );
49+
static const ammo_effect_str_id ammo_effect_id_NO_ITEM_DAMAGE( "NO_ITEM_DAMAGE" );
50+
static const ammo_effect_str_id ammo_effect_id_NO_OVERSHOOT( "NO_OVERSHOOT" );
51+
static const ammo_effect_str_id ammo_effect_id_NO_PENETRATE_OBSTACLES( "NO_PENETRATE_OBSTACLES" );
52+
static const ammo_effect_str_id ammo_effect_id_NULL_SOURCE( "NULL_SOURCE" );
53+
static const ammo_effect_str_id ammo_effect_id_SHATTER_SELF( "SHATTER_SELF" );
54+
static const ammo_effect_str_id ammo_effect_id_STREAM( "STREAM" );
55+
static const ammo_effect_str_id ammo_effect_id_STREAM_BIG( "STREAM_BIG" );
56+
static const ammo_effect_str_id ammo_effect_id_STREAM_TINY( "STREAM_TINY" );
57+
static const ammo_effect_str_id ammo_effect_id_TANGLE( "TANGLE" );
58+
4159
static const efftype_id effect_bounced( "bounced" );
4260

4361
static const itype_id itype_glass_shard( "glass_shard" );
@@ -55,7 +73,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
5573

5674
const tripoint &pt = attack.end_point;
5775

58-
if( effects.count( "SHATTER_SELF" ) ) {
76+
if( effects.count( ammo_effect_id_SHATTER_SELF ) ) {
5977
// Drop the contents, not the thrown item
6078
add_msg_if_player_sees( pt, _( "The %s shatters!" ), drop_item.tname() );
6179

@@ -84,7 +102,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
84102
return;
85103
}
86104

87-
if( effects.count( "BURST" ) ) {
105+
if( effects.count( ammo_effect_id_BURST ) ) {
88106
// Drop the contents, not the thrown item
89107
add_msg_if_player_sees( pt, _( "The %s bursts!" ), drop_item.tname() );
90108

@@ -103,7 +121,8 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
103121
// We can only embed in monsters
104122
bool mon_there = mon != nullptr && !mon->is_dead_state();
105123
// And if we actually want to embed
106-
bool embed = mon_there && effects.count( "NO_EMBED" ) == 0 && effects.count( "TANGLE" ) == 0;
124+
bool embed = mon_there && effects.count( ammo_effect_id_NO_EMBED ) == 0 &&
125+
effects.count( ammo_effect_id_TANGLE ) == 0;
107126
// Don't embed in small creatures
108127
if( embed ) {
109128
const creature_size critter_size = mon->get_size();
@@ -131,10 +150,10 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
131150
// if they aren't friendly they will try and break out of the net/bolas/lasso
132151
// players and NPCs just get the downed effect, and item is dropped.
133152
// TODO: storing the item on player until they recover from downed
134-
if( effects.count( "TANGLE" ) && mon_there ) {
153+
if( effects.count( ammo_effect_id_TANGLE ) && mon_there ) {
135154
do_drop = false;
136155
}
137-
if( effects.count( "ACT_ON_RANGED_HIT" ) ) {
156+
if( effects.count( ammo_effect_id_ACT_ON_RANGED_HIT ) ) {
138157
// Don't drop if it exploded
139158
do_drop = !dropped_item.activate_thrown( attack.end_point );
140159
}
@@ -144,7 +163,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
144163
here.add_item_or_charges( attack.end_point, dropped_item );
145164
}
146165

147-
if( effects.count( "HEAVY_HIT" ) ) {
166+
if( effects.count( ammo_effect_id_HEAVY_HIT ) ) {
148167
if( here.has_flag( ter_furn_flag::TFLAG_LIQUID, pt ) ) {
149168
sounds::sound( pt, 10, sounds::sound_t::combat, _( "splash!" ), false, "bullet_hit", "hit_water" );
150169
} else {
@@ -239,20 +258,21 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
239258
projectile &proj = attack.proj;
240259
const auto &proj_effects = proj.proj_effects;
241260

242-
const bool stream = proj_effects.count( "STREAM" ) > 0 ||
243-
proj_effects.count( "STREAM_TINY" ) > 0 ||
244-
proj_effects.count( "STREAM_BIG" ) > 0 ||
245-
proj_effects.count( "JET" ) > 0;
261+
const bool stream = proj_effects.count( ammo_effect_id_STREAM ) > 0 ||
262+
proj_effects.count( ammo_effect_id_STREAM_TINY ) > 0 ||
263+
proj_effects.count( ammo_effect_id_STREAM_BIG ) > 0 ||
264+
proj_effects.count( ammo_effect_id_JET ) > 0;
246265
const char bullet = stream ? '#' : '*';
247-
const bool no_item_damage = proj_effects.count( "NO_ITEM_DAMAGE" ) > 0;
248-
const bool do_draw_line = proj_effects.count( "DRAW_AS_LINE" ) > 0;
249-
const bool null_source = proj_effects.count( "NULL_SOURCE" ) > 0;
266+
const bool no_item_damage = proj_effects.count( ammo_effect_id_NO_ITEM_DAMAGE ) > 0;
267+
const bool do_draw_line = proj_effects.count( ammo_effect_id_DRAW_AS_LINE ) > 0;
268+
const bool null_source = proj_effects.count( ammo_effect_id_NULL_SOURCE ) > 0;
250269
// Determines whether it can penetrate obstacles
251-
const bool is_bullet = proj_arg.speed >= 200 && !proj_effects.count( "NO_PENETRATE_OBSTACLES" );
270+
const bool is_bullet = proj_arg.speed >= 200 &&
271+
!proj_effects.count( ammo_effect_id_NO_PENETRATE_OBSTACLES );
252272

253273
// If we were targeting a tile rather than a monster, don't overshoot
254274
// Unless the target was a wall, then we are aiming high enough to overshoot
255-
const bool no_overshoot = proj_effects.count( "NO_OVERSHOOT" ) ||
275+
const bool no_overshoot = proj_effects.count( ammo_effect_id_NO_OVERSHOOT ) ||
256276
( creatures.creature_at( target_arg ) == nullptr && here.passable( target_arg ) );
257277

258278
double extend_to_range = no_overshoot ? range : proj_arg.range;
@@ -313,7 +333,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
313333
trajectory.insert( trajectory.begin(), source );
314334

315335
static emit_id muzzle_smoke( "emit_smaller_smoke_plume" );
316-
if( proj_effects.count( "MUZZLE_SMOKE" ) ) {
336+
if( proj_effects.count( ammo_effect_id_MUZZLE_SMOKE ) ) {
317337
here.emit_field( trajectory.front(), muzzle_smoke );
318338
}
319339

@@ -498,7 +518,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
498518
}
499519

500520
// TODO: Move this outside now that we have hit point in return values?
501-
if( proj.proj_effects.count( "BOUNCE" ) ) {
521+
if( proj.proj_effects.count( ammo_effect_id_BOUNCE ) ) {
502522
// Add effect so the shooter is not targeted itself.
503523
if( origin && !origin->has_effect( effect_bounced ) ) {
504524
origin->add_effect( effect_bounced, 1_turns );

src/bionics.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ static const trait_id trait_PROF_MED( "PROF_MED" );
176176
static const trait_id trait_PYROMANIA( "PYROMANIA" );
177177
static const trait_id trait_THRESH_MEDICAL( "THRESH_MEDICAL" );
178178

179+
static const ammo_effect_str_id ammo_effect_id_DRAW_AS_LINE( "DRAW_AS_LINE" );
180+
static const ammo_effect_str_id ammo_effect_id_JET( "JET" );
181+
static const ammo_effect_str_id ammo_effect_id_NO_DAMAGE_SCALING( "NO_DAMAGE_SCALING" );
182+
static const ammo_effect_str_id ammo_effect_id_NO_ITEM_DAMAGE( "NO_ITEM_DAMAGE" );
183+
179184
struct Character::bionic_fuels {
180185
std::vector<vehicle *> connected_vehicles;
181186
std::vector<item *> connected_solar;
@@ -1016,7 +1021,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
10161021
proj.impact.add_damage( STATIC( damage_type_id( "bash" ) ), pr.first.weight() / 250_gram );
10171022
// make the projectile stop one tile short to prevent hitting the player
10181023
proj.range = rl_dist( pr.second, pos() ) - 1;
1019-
proj.proj_effects = {{ "NO_ITEM_DAMAGE", "DRAW_AS_LINE", "NO_DAMAGE_SCALING", "JET" }};
1024+
proj.proj_effects = {{ ammo_effect_id_NO_ITEM_DAMAGE, ammo_effect_id_DRAW_AS_LINE, ammo_effect_id_NO_DAMAGE_SCALING, ammo_effect_id_JET }};
10201025

10211026
dealt_projectile_attack dealt = projectile_attack(
10221027
proj, pr.second, pos(), dispersion_sources{ 0 }, this );

src/creature.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@
7777

7878
struct mutation_branch;
7979

80+
static const ammo_effect_str_id ammo_effect_id_APPLY_SAP( "APPLY_SAP" );
81+
static const ammo_effect_str_id ammo_effect_id_BEANBAG( "BEANBAG" );
82+
static const ammo_effect_str_id ammo_effect_id_BLINDS_EYES( "BLINDS_EYES" );
83+
static const ammo_effect_str_id ammo_effect_id_BOUNCE( "BOUNCE" );
84+
static const ammo_effect_str_id ammo_effect_id_FOAMCRETE( "FOAMCRETE" );
85+
static const ammo_effect_str_id ammo_effect_id_LARGE_BEANBAG( "LARGE_BEANBAG" );
86+
static const ammo_effect_str_id ammo_effect_id_MAGIC( "MAGIC" );
87+
static const ammo_effect_str_id ammo_effect_id_NO_DAMAGE_SCALING( "NO_DAMAGE_SCALING" );
88+
static const ammo_effect_str_id ammo_effect_id_NOGIB( "NOGIB" );
89+
static const ammo_effect_str_id ammo_effect_id_PARALYZEPOISON( "PARALYZEPOISON" );
90+
static const ammo_effect_str_id ammo_effect_id_ROBOT_DAZZLE( "ROBOT_DAZZLE" );
91+
static const ammo_effect_str_id ammo_effect_id_TANGLE( "TANGLE" );
92+
static const ammo_effect_str_id ammo_effect_id_IGNITE( "IGNITE" );
93+
static const ammo_effect_str_id ammo_effect_id_INCENDIARY( "INCENDIARY" );
94+
8095
static const anatomy_id anatomy_human_anatomy( "human_anatomy" );
8196

8297
static const damage_type_id damage_acid( "acid" );
@@ -846,7 +861,7 @@ double Creature::accuracy_projectile_attack( dealt_projectile_attack &attack ) c
846861

847862
void projectile::apply_effects_nodamage( Creature &target, Creature *source ) const
848863
{
849-
if( proj_effects.count( "BOUNCE" ) ) {
864+
if( proj_effects.count( ammo_effect_id_BOUNCE ) ) {
850865
target.add_effect( effect_source( source ), effect_bounced, 1_turns );
851866
}
852867
}
@@ -855,7 +870,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
855870
const dealt_damage_instance &dealt_dam, bool critical ) const
856871
{
857872
// Apply ammo effects to target.
858-
if( proj_effects.count( "TANGLE" ) ) {
873+
if( proj_effects.count( ammo_effect_id_TANGLE ) ) {
859874
// if its a tameable animal, its a good way to catch them if they are running away, like them ranchers do!
860875
// we assume immediate success, then certain monster types immediately break free in monster.cpp move_effects()
861876
if( target.is_monster() ) {
@@ -878,7 +893,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
878893
}
879894

880895
Character &player_character = get_player_character();
881-
if( proj_effects.count( "INCENDIARY" ) ) {
896+
if( proj_effects.count( ammo_effect_id_INCENDIARY ) ) {
882897
if( x_in_y( 1, 100 ) ) { // 1% chance
883898
if( target.made_of( material_veggy ) || target.made_of_any( Creature::cmat_flammable ) ) {
884899
target.add_effect( effect_source( source ), effect_onfire, rng( 2_turns, 6_turns ),
@@ -896,7 +911,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
896911
player_character.rem_morale( MORALE_PYROMANIA_NOFIRE );
897912
}
898913
}
899-
} else if( proj_effects.count( "IGNITE" ) ) {
914+
} else if( proj_effects.count( ammo_effect_id_IGNITE ) ) {
900915
if( x_in_y( 1, 2 ) ) { // 50% chance
901916
if( target.made_of( material_veggy ) || target.made_of_any( Creature::cmat_flammable ) ) {
902917
target.add_effect( effect_source( source ), effect_onfire, 10_turns, dealt_dam.bp_hit );
@@ -914,7 +929,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
914929
}
915930
}
916931

917-
if( proj_effects.count( "ROBOT_DAZZLE" ) ) {
932+
if( proj_effects.count( ammo_effect_id_ROBOT_DAZZLE ) ) {
918933
if( critical && target.in_species( species_ROBOT ) ) {
919934
time_duration duration = rng( 6_turns, 8_turns );
920935
target.add_effect( effect_source( source ), effect_stunned, duration );
@@ -927,31 +942,31 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
927942
}
928943

929944
if( dealt_dam.bp_hit->has_type( body_part_type::type::head ) &&
930-
proj_effects.count( "BLINDS_EYES" ) ) {
945+
proj_effects.count( ammo_effect_id_BLINDS_EYES ) ) {
931946
// TODO: Change this to require bp_eyes
932947
target.add_env_effect( effect_blind,
933948
target.get_random_body_part_of_type( body_part_type::type::sensor ), 5, rng( 3_turns, 10_turns ) );
934949
}
935950

936-
if( proj_effects.count( "APPLY_SAP" ) ) {
951+
if( proj_effects.count( ammo_effect_id_APPLY_SAP ) ) {
937952
target.add_effect( effect_source( source ), effect_sap, 1_turns * dealt_dam.total_damage() );
938953
}
939-
if( proj_effects.count( "PARALYZEPOISON" ) && dealt_dam.total_damage() > 0 &&
954+
if( proj_effects.count( ammo_effect_id_PARALYZEPOISON ) && dealt_dam.total_damage() > 0 &&
940955
!dealt_dam.bp_hit->has_flag( json_flag_BIONIC_LIMB ) ) {
941956
target.add_msg_if_player( m_bad, _( "You feel poison coursing through your body!" ) );
942957
target.add_effect( effect_source( source ), effect_paralyzepoison, 5_minutes );
943958
}
944959

945-
if( proj_effects.count( "FOAMCRETE" ) && effect_foamcrete_slow.is_valid() ) {
960+
if( proj_effects.count( ammo_effect_id_FOAMCRETE ) && effect_foamcrete_slow.is_valid() ) {
946961
target.add_msg_if_player( m_bad, _( "The foamcrete stiffens around you!" ) );
947962
target.add_effect( effect_source( source ), effect_foamcrete_slow, 5_minutes );
948963
}
949964

950965
int stun_strength = 0;
951-
if( proj_effects.count( "BEANBAG" ) ) {
966+
if( proj_effects.count( ammo_effect_id_BEANBAG ) ) {
952967
stun_strength = 4;
953968
}
954-
if( proj_effects.count( "LARGE_BEANBAG" ) ) {
969+
if( proj_effects.count( ammo_effect_id_LARGE_BEANBAG ) ) {
955970
stun_strength = 16;
956971
}
957972
if( stun_strength > 0 ) {
@@ -995,7 +1010,7 @@ projectile_attack_results Creature::select_body_part_projectile_attack(
9951010
const projectile &proj, const double goodhit, const double missed_by ) const
9961011
{
9971012
projectile_attack_results ret( proj );
998-
const bool magic = proj.proj_effects.count( "MAGIC" ) > 0;
1013+
const bool magic = proj.proj_effects.count( ammo_effect_id_MAGIC ) > 0;
9991014
double hit_value = missed_by + rng_float( -0.5, 0.5 );
10001015
if( magic ) {
10011016
// Best possible hit
@@ -1121,7 +1136,7 @@ void Creature::messaging_projectile_attack( const Creature *source,
11211136
void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack &attack,
11221137
bool print_messages, const weakpoint_attack &wp_attack )
11231138
{
1124-
const bool magic = attack.proj.proj_effects.count( "MAGIC" ) > 0;
1139+
const bool magic = attack.proj.proj_effects.count( ammo_effect_id_MAGIC ) > 0;
11251140
const double missed_by = attack.missed_by;
11261141
if( missed_by >= 1.0 && !magic ) {
11271142
// Total miss
@@ -1188,13 +1203,13 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack
11881203

11891204
// copy it, since we're mutating.
11901205
damage_instance impact = proj.impact;
1191-
if( hit_selection.damage_mult > 0.0f && proj_effects.count( "NO_DAMAGE_SCALING" ) ) {
1206+
if( hit_selection.damage_mult > 0.0f && proj_effects.count( ammo_effect_id_NO_DAMAGE_SCALING ) ) {
11921207
hit_selection.damage_mult = 1.0f;
11931208
}
11941209

11951210
impact.mult_damage( hit_selection.damage_mult );
11961211

1197-
if( proj_effects.count( "NOGIB" ) > 0 ) {
1212+
if( proj_effects.count( ammo_effect_id_NOGIB ) > 0 ) {
11981213
float dmg_ratio = static_cast<float>( impact.total_damage() ) / get_hp_max( hit_selection.bp_hit );
11991214
if( dmg_ratio > 1.25f ) {
12001215
impact.mult_damage( 1.0f / dmg_ratio );

src/explosion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#include "vehicle.h"
6565
#include "vpart_position.h"
6666

67+
static const ammo_effect_str_id ammo_effect_id_NULL_SOURCE( "NULL_SOURCE" );
68+
6769
static const damage_type_id damage_bash( "bash" );
6870
static const damage_type_id damage_bullet( "bullet" );
6971
static const damage_type_id damage_heat( "heat" );
@@ -396,7 +398,7 @@ static std::vector<tripoint> shrapnel( const Creature *source, const tripoint &s
396398
projectile proj;
397399
proj.speed = fragment_velocity;
398400
proj.range = range;
399-
proj.proj_effects.insert( "NULL_SOURCE" );
401+
proj.proj_effects.insert( ammo_effect_id_NULL_SOURCE );
400402

401403
struct local_caches {
402404
cata::mdarray<fragment_cloud, point_bub_ms> obstacle_cache;

0 commit comments

Comments
 (0)