Skip to content

Commit

Permalink
Merge pull request CleverRaven#76962 from sparr/premature_division_2
Browse files Browse the repository at this point in the history
Eliminate some premature division #2
  • Loading branch information
Maleclypse authored Oct 24, 2024
2 parents ccbb166 + ec520a2 commit acf7a34
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4060,7 +4060,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 ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7651,7 +7651,7 @@ weighted_int_list<mutation_category_id> 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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/character_attire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( 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<bool( const item & )> filter;
if( loc->is_filthy() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7230,7 +7230,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
Expand Down Expand Up @@ -8040,7 +8040,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 )
Expand Down
2 changes: 1 addition & 1 deletion src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7702,8 +7702,8 @@ std::optional<int> 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 ) {

Expand Down
4 changes: 2 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2848,8 +2848,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<int>( 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<bool( const item & )> filter;
if( fix.is_filthy() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,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;
Expand Down
4 changes: 2 additions & 2 deletions src/talker_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,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 );

Expand Down
2 changes: 1 addition & 1 deletion src/vehicle_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,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.
Expand Down
2 changes: 1 addition & 1 deletion src/vitamin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>( percent ) / 100.0f );
return 24_hours * ( percent / 100.0f ) / rate_;
}

int vitamin::units_absorption_per_day() const
Expand Down

0 comments on commit acf7a34

Please sign in to comment.