Skip to content

Commit

Permalink
Use ammo_effect_str_id instead of std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed May 19, 2024
1 parent 745fada commit aeed8dd
Show file tree
Hide file tree
Showing 24 changed files with 229 additions and 127 deletions.
10 changes: 5 additions & 5 deletions src/ammo_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ const ammo_effect &int_id<ammo_effect>::obj() const

/** @relates int_id */
template<>
const string_id<ammo_effect> &int_id<ammo_effect>::id() const
const ammo_effect_str_id &int_id<ammo_effect>::id() const
{
return get_all_ammo_effects().convert( *this );
}

/** @relates string_id */
template<>
bool string_id<ammo_effect>::is_valid() const
bool ammo_effect_str_id::is_valid() const
{
return get_all_ammo_effects().is_valid( *this );
}

/** @relates string_id */
template<>
const ammo_effect &string_id<ammo_effect>::obj() const
const ammo_effect &ammo_effect_str_id::obj() const
{
return get_all_ammo_effects().obj( *this );
}

/** @relates string_id */
template<>
int_id<ammo_effect> string_id<ammo_effect>::id() const
int_id<ammo_effect> ammo_effect_str_id::id() const
{
return get_all_ammo_effects().convert( *this, AE_NULL );
}

/** @relates int_id */
template<>
int_id<ammo_effect>::int_id( const string_id<ammo_effect> &id ) : _id( id.id() )
int_id<ammo_effect>::int_id( const ammo_effect_str_id &id ) : _id( id.id() )
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/ammo_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct ammo_effect {
int trail_chance = 100;

// Used by generic_factory
string_id<ammo_effect> id;
std::vector<std::pair<string_id<ammo_effect>, mod_id>> src;
ammo_effect_str_id id;
std::vector<std::pair<ammo_effect_str_id, mod_id>> src;
bool was_loaded = false;

static size_t count();
Expand Down
54 changes: 37 additions & 17 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@
#include "units.h"
#include "vpart_position.h"

static const ammo_effect_str_id ammo_effect_id_ACT_ON_RANGED_HIT( "ACT_ON_RANGED_HIT" );
static const ammo_effect_str_id ammo_effect_id_BOUNCE( "BOUNCE" );
static const ammo_effect_str_id ammo_effect_id_BURST( "BURST" );
static const ammo_effect_str_id ammo_effect_id_DRAW_AS_LINE( "DRAW_AS_LINE" );
static const ammo_effect_str_id ammo_effect_id_HEAVY_HIT( "HEAVY_HIT" );
static const ammo_effect_str_id ammo_effect_id_JET( "JET" );
static const ammo_effect_str_id ammo_effect_id_MUZZLE_SMOKE( "MUZZLE_SMOKE" );
static const ammo_effect_str_id ammo_effect_id_NO_EMBED( "NO_EMBED" );
static const ammo_effect_str_id ammo_effect_id_NO_ITEM_DAMAGE( "NO_ITEM_DAMAGE" );
static const ammo_effect_str_id ammo_effect_id_NO_OVERSHOOT( "NO_OVERSHOOT" );
static const ammo_effect_str_id ammo_effect_id_NO_PENETRATE_OBSTACLES( "NO_PENETRATE_OBSTACLES" );
static const ammo_effect_str_id ammo_effect_id_NULL_SOURCE( "NULL_SOURCE" );
static const ammo_effect_str_id ammo_effect_id_SHATTER_SELF( "SHATTER_SELF" );
static const ammo_effect_str_id ammo_effect_id_STREAM( "STREAM" );
static const ammo_effect_str_id ammo_effect_id_STREAM_BIG( "STREAM_BIG" );
static const ammo_effect_str_id ammo_effect_id_STREAM_TINY( "STREAM_TINY" );
static const ammo_effect_str_id ammo_effect_id_TANGLE( "TANGLE" );

static const efftype_id effect_bounced( "bounced" );

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

const tripoint &pt = attack.end_point;

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

Expand Down Expand Up @@ -84,7 +102,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
return;
}

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

Expand All @@ -103,7 +121,8 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
// We can only embed in monsters
bool mon_there = mon != nullptr && !mon->is_dead_state();
// And if we actually want to embed
bool embed = mon_there && effects.count( "NO_EMBED" ) == 0 && effects.count( "TANGLE" ) == 0;
bool embed = mon_there && effects.count( ammo_effect_id_NO_EMBED ) == 0 &&
effects.count( ammo_effect_id_TANGLE ) == 0;
// Don't embed in small creatures
if( embed ) {
const creature_size critter_size = mon->get_size();
Expand Down Expand Up @@ -131,10 +150,10 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
// if they aren't friendly they will try and break out of the net/bolas/lasso
// players and NPCs just get the downed effect, and item is dropped.
// TODO: storing the item on player until they recover from downed
if( effects.count( "TANGLE" ) && mon_there ) {
if( effects.count( ammo_effect_id_TANGLE ) && mon_there ) {
do_drop = false;
}
if( effects.count( "ACT_ON_RANGED_HIT" ) ) {
if( effects.count( ammo_effect_id_ACT_ON_RANGED_HIT ) ) {
// Don't drop if it exploded
do_drop = !dropped_item.activate_thrown( attack.end_point );
}
Expand All @@ -144,7 +163,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
here.add_item_or_charges( attack.end_point, dropped_item );
}

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

const bool stream = proj_effects.count( "STREAM" ) > 0 ||
proj_effects.count( "STREAM_TINY" ) > 0 ||
proj_effects.count( "STREAM_BIG" ) > 0 ||
proj_effects.count( "JET" ) > 0;
const bool stream = proj_effects.count( ammo_effect_id_STREAM ) > 0 ||
proj_effects.count( ammo_effect_id_STREAM_TINY ) > 0 ||
proj_effects.count( ammo_effect_id_STREAM_BIG ) > 0 ||
proj_effects.count( ammo_effect_id_JET ) > 0;
const char bullet = stream ? '#' : '*';
const bool no_item_damage = proj_effects.count( "NO_ITEM_DAMAGE" ) > 0;
const bool do_draw_line = proj_effects.count( "DRAW_AS_LINE" ) > 0;
const bool null_source = proj_effects.count( "NULL_SOURCE" ) > 0;
const bool no_item_damage = proj_effects.count( ammo_effect_id_NO_ITEM_DAMAGE ) > 0;
const bool do_draw_line = proj_effects.count( ammo_effect_id_DRAW_AS_LINE ) > 0;
const bool null_source = proj_effects.count( ammo_effect_id_NULL_SOURCE ) > 0;
// Determines whether it can penetrate obstacles
const bool is_bullet = proj_arg.speed >= 200 && !proj_effects.count( "NO_PENETRATE_OBSTACLES" );
const bool is_bullet = proj_arg.speed >= 200 &&
!proj_effects.count( ammo_effect_id_NO_PENETRATE_OBSTACLES );

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

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

static emit_id muzzle_smoke( "emit_smaller_smoke_plume" );
if( proj_effects.count( "MUZZLE_SMOKE" ) ) {
if( proj_effects.count( ammo_effect_id_MUZZLE_SMOKE ) ) {
here.emit_field( trajectory.front(), muzzle_smoke );
}

Expand Down Expand Up @@ -498,7 +518,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
}

// TODO: Move this outside now that we have hit point in return values?
if( proj.proj_effects.count( "BOUNCE" ) ) {
if( proj.proj_effects.count( ammo_effect_id_BOUNCE ) ) {
// Add effect so the shooter is not targeted itself.
if( origin && !origin->has_effect( effect_bounced ) ) {
origin->add_effect( effect_bounced, 1_turns );
Expand Down
7 changes: 6 additions & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ static const trait_id trait_PROF_MED( "PROF_MED" );
static const trait_id trait_PYROMANIA( "PYROMANIA" );
static const trait_id trait_THRESH_MEDICAL( "THRESH_MEDICAL" );

static const ammo_effect_str_id ammo_effect_id_DRAW_AS_LINE( "DRAW_AS_LINE" );
static const ammo_effect_str_id ammo_effect_id_JET( "JET" );
static const ammo_effect_str_id ammo_effect_id_NO_DAMAGE_SCALING( "NO_DAMAGE_SCALING" );
static const ammo_effect_str_id ammo_effect_id_NO_ITEM_DAMAGE( "NO_ITEM_DAMAGE" );

struct Character::bionic_fuels {
std::vector<vehicle *> connected_vehicles;
std::vector<item *> connected_solar;
Expand Down Expand Up @@ -1016,7 +1021,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
proj.impact.add_damage( STATIC( damage_type_id( "bash" ) ), pr.first.weight() / 250_gram );
// make the projectile stop one tile short to prevent hitting the player
proj.range = rl_dist( pr.second, pos() ) - 1;
proj.proj_effects = {{ "NO_ITEM_DAMAGE", "DRAW_AS_LINE", "NO_DAMAGE_SCALING", "JET" }};
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 }};

dealt_projectile_attack dealt = projectile_attack(
proj, pr.second, pos(), dispersion_sources{ 0 }, this );
Expand Down
45 changes: 30 additions & 15 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@

struct mutation_branch;

static const ammo_effect_str_id ammo_effect_id_APPLY_SAP( "APPLY_SAP" );
static const ammo_effect_str_id ammo_effect_id_BEANBAG( "BEANBAG" );
static const ammo_effect_str_id ammo_effect_id_BLINDS_EYES( "BLINDS_EYES" );
static const ammo_effect_str_id ammo_effect_id_BOUNCE( "BOUNCE" );
static const ammo_effect_str_id ammo_effect_id_FOAMCRETE( "FOAMCRETE" );
static const ammo_effect_str_id ammo_effect_id_LARGE_BEANBAG( "LARGE_BEANBAG" );
static const ammo_effect_str_id ammo_effect_id_MAGIC( "MAGIC" );
static const ammo_effect_str_id ammo_effect_id_NO_DAMAGE_SCALING( "NO_DAMAGE_SCALING" );
static const ammo_effect_str_id ammo_effect_id_NOGIB( "NOGIB" );
static const ammo_effect_str_id ammo_effect_id_PARALYZEPOISON( "PARALYZEPOISON" );
static const ammo_effect_str_id ammo_effect_id_ROBOT_DAZZLE( "ROBOT_DAZZLE" );
static const ammo_effect_str_id ammo_effect_id_TANGLE( "TANGLE" );
static const ammo_effect_str_id ammo_effect_id_IGNITE( "IGNITE" );
static const ammo_effect_str_id ammo_effect_id_INCENDIARY( "INCENDIARY" );

static const anatomy_id anatomy_human_anatomy( "human_anatomy" );

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

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

Character &player_character = get_player_character();
if( proj_effects.count( "INCENDIARY" ) ) {
if( proj_effects.count( ammo_effect_id_INCENDIARY ) ) {
if( x_in_y( 1, 100 ) ) { // 1% chance
if( target.made_of( material_veggy ) || target.made_of_any( Creature::cmat_flammable ) ) {
target.add_effect( effect_source( source ), effect_onfire, rng( 2_turns, 6_turns ),
Expand All @@ -896,7 +911,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
player_character.rem_morale( MORALE_PYROMANIA_NOFIRE );
}
}
} else if( proj_effects.count( "IGNITE" ) ) {
} else if( proj_effects.count( ammo_effect_id_IGNITE ) ) {
if( x_in_y( 1, 2 ) ) { // 50% chance
if( target.made_of( material_veggy ) || target.made_of_any( Creature::cmat_flammable ) ) {
target.add_effect( effect_source( source ), effect_onfire, 10_turns, dealt_dam.bp_hit );
Expand All @@ -914,7 +929,7 @@ void projectile::apply_effects_damage( Creature &target, Creature *source,
}
}

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

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

if( proj_effects.count( "APPLY_SAP" ) ) {
if( proj_effects.count( ammo_effect_id_APPLY_SAP ) ) {
target.add_effect( effect_source( source ), effect_sap, 1_turns * dealt_dam.total_damage() );
}
if( proj_effects.count( "PARALYZEPOISON" ) && dealt_dam.total_damage() > 0 &&
if( proj_effects.count( ammo_effect_id_PARALYZEPOISON ) && dealt_dam.total_damage() > 0 &&
!dealt_dam.bp_hit->has_flag( json_flag_BIONIC_LIMB ) ) {
target.add_msg_if_player( m_bad, _( "You feel poison coursing through your body!" ) );
target.add_effect( effect_source( source ), effect_paralyzepoison, 5_minutes );
}

if( proj_effects.count( "FOAMCRETE" ) && effect_foamcrete_slow.is_valid() ) {
if( proj_effects.count( ammo_effect_id_FOAMCRETE ) && effect_foamcrete_slow.is_valid() ) {
target.add_msg_if_player( m_bad, _( "The foamcrete stiffens around you!" ) );
target.add_effect( effect_source( source ), effect_foamcrete_slow, 5_minutes );
}

int stun_strength = 0;
if( proj_effects.count( "BEANBAG" ) ) {
if( proj_effects.count( ammo_effect_id_BEANBAG ) ) {
stun_strength = 4;
}
if( proj_effects.count( "LARGE_BEANBAG" ) ) {
if( proj_effects.count( ammo_effect_id_LARGE_BEANBAG ) ) {
stun_strength = 16;
}
if( stun_strength > 0 ) {
Expand Down Expand Up @@ -995,7 +1010,7 @@ projectile_attack_results Creature::select_body_part_projectile_attack(
const projectile &proj, const double goodhit, const double missed_by ) const
{
projectile_attack_results ret( proj );
const bool magic = proj.proj_effects.count( "MAGIC" ) > 0;
const bool magic = proj.proj_effects.count( ammo_effect_id_MAGIC ) > 0;
double hit_value = missed_by + rng_float( -0.5, 0.5 );
if( magic ) {
// Best possible hit
Expand Down Expand Up @@ -1121,7 +1136,7 @@ void Creature::messaging_projectile_attack( const Creature *source,
void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack &attack,
bool print_messages, const weakpoint_attack &wp_attack )
{
const bool magic = attack.proj.proj_effects.count( "MAGIC" ) > 0;
const bool magic = attack.proj.proj_effects.count( ammo_effect_id_MAGIC ) > 0;
const double missed_by = attack.missed_by;
if( missed_by >= 1.0 && !magic ) {
// Total miss
Expand Down Expand Up @@ -1188,13 +1203,13 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack

// copy it, since we're mutating.
damage_instance impact = proj.impact;
if( hit_selection.damage_mult > 0.0f && proj_effects.count( "NO_DAMAGE_SCALING" ) ) {
if( hit_selection.damage_mult > 0.0f && proj_effects.count( ammo_effect_id_NO_DAMAGE_SCALING ) ) {
hit_selection.damage_mult = 1.0f;
}

impact.mult_damage( hit_selection.damage_mult );

if( proj_effects.count( "NOGIB" ) > 0 ) {
if( proj_effects.count( ammo_effect_id_NOGIB ) > 0 ) {
float dmg_ratio = static_cast<float>( impact.total_damage() ) / get_hp_max( hit_selection.bp_hit );
if( dmg_ratio > 1.25f ) {
impact.mult_damage( 1.0f / dmg_ratio );
Expand Down
4 changes: 3 additions & 1 deletion src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#include "vehicle.h"
#include "vpart_position.h"

static const ammo_effect_str_id ammo_effect_id_NULL_SOURCE( "NULL_SOURCE" );

static const damage_type_id damage_bash( "bash" );
static const damage_type_id damage_bullet( "bullet" );
static const damage_type_id damage_heat( "heat" );
Expand Down Expand Up @@ -396,7 +398,7 @@ static std::vector<tripoint> shrapnel( const Creature *source, const tripoint &s
projectile proj;
proj.speed = fragment_velocity;
proj.range = range;
proj.proj_effects.insert( "NULL_SOURCE" );
proj.proj_effects.insert( ammo_effect_id_NULL_SOURCE );

struct local_caches {
cata::mdarray<fragment_cloud, point_bub_ms> obstacle_cache;
Expand Down
Loading

0 comments on commit aeed8dd

Please sign in to comment.