From ec520a2d9f6a45dc44fbf66311fa647637bd17a5 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Fri, 11 Oct 2024 08:11:17 -0400 Subject: [PATCH] Eliminate some premature division --- src/activity_actor.cpp | 2 +- src/character.cpp | 2 +- src/character_attire.cpp | 2 +- src/game_inventory.cpp | 2 +- src/grab.cpp | 2 +- src/item.cpp | 5 +++-- src/item_pocket.cpp | 2 +- src/iuse.cpp | 4 ++-- src/iuse_actor.cpp | 4 ++-- src/map.cpp | 2 +- src/npc.cpp | 2 +- src/talker_character.cpp | 4 ++-- src/vehicle_move.cpp | 2 +- src/vehicle_use.cpp | 2 +- src/vitamin.cpp | 2 +- 15 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index a9ebd044a53ca..d70fb68525d23 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -4014,7 +4014,7 @@ void workout_activity_actor::do_turn( player_activity &act, Character &who ) } // morale bonus kicks in gradually after 5 minutes of exercise if( calendar::once_every( 2_minutes ) && - ( ( elapsed + act.moves_total - act.moves_left ) / 100 * 1_turns ) > 5_minutes ) { + ( ( elapsed + act.moves_total - act.moves_left ) * 1_turns / 100 ) > 5_minutes ) { who.add_morale( morale_feeling_good, intensity_modifier, 20, 6_hours, 30_minutes ); } if( calendar::once_every( 2_minutes ) ) { diff --git a/src/character.cpp b/src/character.cpp index cc048a01c1108..97955a4f3c76a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -7618,7 +7618,7 @@ weighted_int_list Character::get_vitamin_weighted_categori int Character::vitamin_RDA( const vitamin_id &vitamin, int ammount ) const { - const double multiplier = vitamin_rate( vitamin ) / 1_days * 100; + const double multiplier = vitamin_rate( vitamin ) * 100 / 1_days; return std::lround( ammount * multiplier ); } diff --git a/src/character_attire.cpp b/src/character_attire.cpp index 6d79cac02c086..ef6deec09d45a 100644 --- a/src/character_attire.cpp +++ b/src/character_attire.cpp @@ -1129,7 +1129,7 @@ int outfit::swim_modifier( const int swim_skill ) const int ret = 0; if( swim_skill < 10 ) { for( const item &i : worn ) { - ret += i.volume() / 125_ml * ( 10 - swim_skill ); + ret += i.volume() * ( 10 - swim_skill ) / 125_ml; } } return ret; diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index 0308f9b97a0b2..4d3ba6ec51df4 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -2011,7 +2011,7 @@ class repair_inventory_preset: public inventory_selector_preset append_cell( [actor, &you]( const item_location & loc ) { const int comp_needed = std::max( 1, - std::ceil( loc->base_volume() / 250_ml * actor->cost_scaling ) ); + std::ceil( loc->base_volume() * actor->cost_scaling / 250_ml ) ); const inventory &crafting_inv = you.crafting_inventory(); std::function filter; if( loc->is_filthy() ) { diff --git a/src/grab.cpp b/src/grab.cpp index 5b1539e9a8bd1..9c737aa3c4cd6 100644 --- a/src/grab.cpp +++ b/src/grab.cpp @@ -130,7 +130,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp ) for( int p : wheel_indices ) { const tripoint_bub_ms wheel_pos = vehpos + grabbed_vehicle->part( p ).precalc[0]; const int mapcost = m.move_cost( wheel_pos, grabbed_vehicle ); - mc += str_req / wheel_indices.size() * mapcost; + mc += str_req * mapcost / wheel_indices.size(); } //set strength check threshold //if vehicle has many or only one wheel (shopping cart), it is as if it had four. diff --git a/src/item.cpp b/src/item.cpp index 7cf6f0f17402f..05fc2c152be10 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -7232,7 +7232,7 @@ units::mass item::weight( bool include_contents, bool integral ) const static units::length sawn_off_reduction( const itype *type ) { int barrel_percentage = type->gun->barrel_volume / ( type->volume / 100 ); - return ( type->longest_side / 100 ) * barrel_percentage; + return type->longest_side * barrel_percentage / 100; } units::length item::length() const @@ -8042,7 +8042,8 @@ void item::calc_rot( units::temperature temp, const float spoil_modifier, temp = std::min( temperatures::fridge, temp ); } - rot += factor * time_delta / 1_hours * calc_hourly_rotpoints_at_temp( temp ) * 1_turns; + rot += factor * time_delta / 1_seconds * calc_hourly_rotpoints_at_temp( temp ) * 1_turns / + ( 1_hours / 1_seconds ); } void item::calc_rot_while_processing( time_duration processing_duration ) diff --git a/src/item_pocket.cpp b/src/item_pocket.cpp index c784ff2517f8b..b53ba70b508a7 100644 --- a/src/item_pocket.cpp +++ b/src/item_pocket.cpp @@ -2484,7 +2484,7 @@ units::volume pocket_data::max_contains_volume() const int stack_size = ammo_type->stack_size ? ammo_type->stack_size : 1; int max_count = ammo_restriction.at( ammo_type->ammo->type ); units::volume this_volume = - 1_ml * divide_round_up( ammo_type->volume / 1_ml * max_count, stack_size ); + 1_ml * divide_round_up( ammo_type->volume * max_count / 1_ml, stack_size ); max_total_volume = std::max( max_total_volume, this_volume ); } return max_total_volume; diff --git a/src/iuse.cpp b/src/iuse.cpp index 5fe4e1d27c718..4c599b915508c 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -7698,8 +7698,8 @@ std::optional iuse::multicooker( Character *p, item *it, const tripoint &po mealtime = meal->time_to_craft_moves( *p, recipe_time_flag::ignore_proficiencies ) * 2; } - const int all_charges = charges_to_start + mealtime / 1000 * units::to_watt( - it->type->tool->power_draw ) / 1000; + const int all_charges = charges_to_start + mealtime * units::to_watt( + it->type->tool->power_draw ) / 1000 / 1000; if( it->ammo_remaining( p, true ) < all_charges ) { diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index ce1237ad0ed24..3fd4a6c00b059 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -2815,8 +2815,8 @@ bool repair_item_actor::handle_components( Character &pl, const item &fix, // Round up if checking, but roll if actually consuming // TODO: should 250_ml be part of the cost_scaling? const int items_needed = std::max( 1, just_check ? - std::ceil( fix.base_volume() / 250_ml * cost_scaling ) : - roll_remainder( fix.base_volume() / 250_ml * cost_scaling ) ); + std::ceil( fix.base_volume() * cost_scaling / 250_ml ) : + roll_remainder( fix.base_volume() * cost_scaling / 250_ml ) ); std::function filter; if( fix.is_filthy() ) { diff --git a/src/map.cpp b/src/map.cpp index 248fa4378265d..dbf192e147006 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1163,7 +1163,7 @@ float map::vehicle_vehicle_collision( vehicle &veh, vehicle &veh2, const float m1 = to_kilogram( veh.total_mass() ); // Collision is perfectly inelastic for simplicity // Assume veh2 is standing still - dmg = std::abs( veh.vertical_velocity / 100 ) * m1 / 10; + dmg = std::abs( veh.vertical_velocity / 100.0f ) * m1 / 10; veh.vertical_velocity = 0; } diff --git a/src/npc.cpp b/src/npc.cpp index 1d5f8299dbbe3..6f495c622a702 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -3314,7 +3314,7 @@ const pathfinding_settings &npc::get_pathfinding_settings( bool no_bashing ) con if( climb > 1 ) { // Success is !one_in(dex), so 0%, 50%, 66%, 75%... // Penalty for failure chance is 1/success = 1/(1-failure) = 1/(1-(1/dex)) = dex/(dex-1) - path_settings->climb_cost = ( 10 - climb / 5 ) * climb / ( climb - 1 ); + path_settings->climb_cost = ( 10 - climb / 5.0f ) * climb / ( climb - 1 ); } else { // Climbing at this dexterity will always fail path_settings->climb_cost = 0; diff --git a/src/talker_character.cpp b/src/talker_character.cpp index e032ea51a0032..82a77b8ec2413 100644 --- a/src/talker_character.cpp +++ b/src/talker_character.cpp @@ -1158,8 +1158,8 @@ std::string talker_character_const::proficiency_training_text( const talker &stu const int cost = calc_proficiency_training_cost( *me_chr_const, *pupil, proficiency ); const std::string name = proficiency->name(); - const float pct_before = current_time / time_needed * 100; - const float pct_after = ( current_time + 15_minutes ) / time_needed * 100; + const float pct_before = current_time * 100.0f / time_needed; + const float pct_after = ( current_time + 15_minutes ) * 100.0f / time_needed; const std::string after_str = pct_after >= 100.0f ? pgettext( "NPC training: proficiency learned", "done" ) : string_format( "%2.0f%%", pct_after ); diff --git a/src/vehicle_move.cpp b/src/vehicle_move.cpp index a2eacbbb254fa..c66d586f327c2 100644 --- a/src/vehicle_move.cpp +++ b/src/vehicle_move.cpp @@ -1086,7 +1086,7 @@ veh_collision vehicle::part_collision( int part, const tripoint &p, if( vpi.has_flag( "SHARP" ) ) { vp.blood += 100 + 5 * dam; } else if( dam > rng( 10, 30 ) ) { - vp.blood += 50 + dam / 2 * 5; + vp.blood += 50 + dam * 5 / 2; } check_environmental_effects = true; diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 1b364179a2c16..9210ede6f9d98 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -1149,7 +1149,7 @@ void vehicle::operate_scoop() that_item_there->inc_damage(); //The scoop gets a lot louder when breaking an item. sounds::sound( position, rng( 10, - that_item_there->volume() / units::legacy_volume_factor * 2 + 10 ), + that_item_there->volume() * 2 / units::legacy_volume_factor + 10 ), sounds::sound_t::combat, _( "BEEEThump" ), false, "vehicle", "scoop_thump" ); } //This attempts to add the item to the scoop inventory and if successful, removes it from the map. diff --git a/src/vitamin.cpp b/src/vitamin.cpp index 7cc1fc59a5c27..65921e388c4b3 100644 --- a/src/vitamin.cpp +++ b/src/vitamin.cpp @@ -127,7 +127,7 @@ float vitamin::RDA_to_default( int percent ) const if( type_ != vitamin_type::VITAMIN ) { return percent; } - return ( 24_hours / rate_ ) * ( static_cast( percent ) / 100.0f ); + return 24_hours * ( percent / 100.0f ) / rate_; } int vitamin::units_absorption_per_day() const