Skip to content

Commit

Permalink
Merge pull request #41300 from kevingranade/lift-qual-clean
Browse files Browse the repository at this point in the history
Overhaul lifting quality handling
  • Loading branch information
ZhilkinSerg authored Jun 14, 2020
2 parents c3abd5f + 9033170 commit b4aae59
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio
}
bool b_rack_present = false;
for( const tripoint &pt : g->m.points_in_radius( u.pos(), 2 ) ) {
if( g->m.has_flag_furn( flag_BUTCHER_EQ, pt ) || u.best_nearby_lifting_assist() >= 7 ) {
if( g->m.has_flag_furn( flag_BUTCHER_EQ, pt ) || u.best_nearby_lifting_assist() >= 3500_kilogram ) {
b_rack_present = true;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,8 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
// no wheel removal yet
continue;
}
const int max_lift = p.best_nearby_lifting_assist( src_loc );
const int lvl = std::ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
const bool use_aid = max_lift >= lvl;
const units::mass max_lift = p.best_nearby_lifting_assist( src_loc );
const bool use_aid = max_lift >= base.weight();
const bool use_str = p.can_lift( base );
if( !( use_aid || use_str ) ) {
continue;
Expand Down
17 changes: 8 additions & 9 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2818,12 +2818,12 @@ units::mass Character::weight_carried() const
return weight_carried_with_tweaks( item_tweaks() );
}

int Character::best_nearby_lifting_assist() const
units::mass Character::best_nearby_lifting_assist() const
{
return best_nearby_lifting_assist( this->pos() );
}

int Character::best_nearby_lifting_assist( const tripoint &world_pos ) const
units::mass Character::best_nearby_lifting_assist( const tripoint &world_pos ) const
{
const quality_id LIFT( "LIFT" );
int mech_lift = 0;
Expand All @@ -2833,10 +2833,11 @@ int Character::best_nearby_lifting_assist( const tripoint &world_pos ) const
mech_lift = mons->mech_str_addition() + 10;
}
}
return std::max( { this->max_quality( LIFT ), mech_lift,
map_selector( this->pos(), PICKUP_RANGE ).max_quality( LIFT ),
vehicle_selector( world_pos, 4, true, true ).max_quality( LIFT )
} );
int lift_quality = std::max( { this->max_quality( LIFT ), mech_lift,
map_selector( this->pos(), PICKUP_RANGE ).max_quality( LIFT ),
vehicle_selector( world_pos, 4, true, true ).max_quality( LIFT )
} );
return lifting_quality_to_mass( lift_quality );
}

units::mass Character::weight_carried_with_tweaks( const std::vector<std::pair<item_location, int>>
Expand Down Expand Up @@ -2888,9 +2889,7 @@ units::mass Character::weight_carried_with_tweaks( const item_tweaks &tweaks ) c
}
// Exclude wielded item if using lifting tool
if( weaponweight + ret > weight_capacity() ) {
const float liftrequirement = std::ceil( units::to_gram<float>( weaponweight ) /
units::to_gram<float>( TOOL_LIFT_FACTOR ) );
if( g->new_game || best_nearby_lifting_assist() < liftrequirement ) {
if( g->new_game || best_nearby_lifting_assist() < weaponweight ) {
ret += weaponweight;
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1450,12 +1450,12 @@ class Character : public Creature, public visitable<Character>
/** True if unarmed or wielding a weapon with the UNARMED_WEAPON flag */
bool unarmed_attack() const;
/// Checks for items, tools, and vehicles with the Lifting quality near the character
/// returning the highest quality in range.
int best_nearby_lifting_assist() const;
/// returning the largest weight liftable by an item in range.
units::mass best_nearby_lifting_assist() const;

/// Alternate version if you need to specify a different orign point for nearby vehicle sources of lifting
/// used for operations on distant objects (e.g. vehicle installation/uninstallation)
int best_nearby_lifting_assist( const tripoint &world_pos ) const;
units::mass best_nearby_lifting_assist( const tripoint &world_pos ) const;

// Inventory + weapon + worn (for death, etc)
std::vector<item *> inv_dump();
Expand Down
8 changes: 0 additions & 8 deletions src/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#ifndef CATA_SRC_GAME_CONSTANTS_H
#define CATA_SRC_GAME_CONSTANTS_H

#include "units.h"

// Fixed window sizes.
#define HP_HEIGHT 14
#define HP_WIDTH 7
Expand Down Expand Up @@ -101,12 +99,6 @@ constexpr int freezer = 23; // -5 Celsius
constexpr int freezing = 32; // 0 Celsius
} // namespace temperatures

// Weight per level of LIFT/JACK tool quality.
#define TOOL_LIFT_FACTOR 500_kilogram // 500kg/level

// Cap JACK requirements to support arbitrarily large vehicles.
#define JACK_LIMIT 8500_kilogram // 8500kg ( 8.5 metric tonnes )

// Slowest speed at which a gun can be aimed.
#define MAX_AIM_COST 10

Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,7 @@ void item::qualities_info( std::vector<iteminfo> &info, const iteminfo_query *pa
str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
"is rated at <info>%3$d</info> %4$s" ),
q.second, q.first.obj().name,
static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
static_cast<int>( convert_weight( lifting_quality_to_mass( q.second ) ) ),
weight_units() );
} else {
str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
Expand Down
8 changes: 8 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,14 @@ enum class hint_rating {
cant
};

// Weight per level of LIFT/JACK tool quality.
#define TOOL_LIFT_FACTOR 500_kilogram // 500kg/level

inline units::mass lifting_quality_to_mass( int quality_level )
{
return TOOL_LIFT_FACTOR * quality_level;
}

/**
* Returns a reference to a null item (see @ref item::is_null). The reference is always valid
* and stays valid until the program ends.
Expand Down
26 changes: 15 additions & 11 deletions src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ static inline std::string health_color( bool status )
return status ? "<color_light_green>" : "<color_light_red>";
}

// Cap JACK requirements to support arbitrarily large vehicles.
#define JACK_LIMIT 8500_kilogram // 8500kg ( 8.5 metric tonnes )

// cap JACK requirements to support arbitrarily large vehicles
static double jack_quality( const vehicle &veh )
{
const units::quantity<double, units::mass::unit_type> mass = std::min( veh.total_mass(),
JACK_LIMIT );
return std::ceil( mass / TOOL_LIFT_FACTOR );
return std::ceil( mass / lifting_quality_to_mass( 1 ) );
}

/** Can part currently be reloaded with anything? */
Expand Down Expand Up @@ -483,10 +486,11 @@ void veh_interact::cache_tool_availability()
if( g->u.is_mounted() ) {
mech_jack = g->u.mounted_creature->mech_str_addition() + 10;
}
max_jack = std::max( { g->u.max_quality( qual_JACK ), mech_jack,
map_selector( g->u.pos(), PICKUP_RANGE ).max_quality( qual_JACK ),
vehicle_selector( g->u.pos(), 2, true, *veh ).max_quality( qual_JACK )
} );
int max_quality = std::max( { g->u.max_quality( qual_JACK ), mech_jack,
map_selector( g->u.pos(), PICKUP_RANGE ).max_quality( qual_JACK ),
vehicle_selector( g->u.pos(), 2, true, *veh ).max_quality( qual_JACK )
} );
max_jack = lifting_quality_to_mass( max_quality );
}

void veh_interact::cache_tool_availability_update_lifting( const tripoint &world_cursor_pos )
Expand Down Expand Up @@ -766,15 +770,15 @@ bool veh_interact::can_install_part()
qual = qual_JACK;
lvl = jack_quality( *veh );
str = veh->lift_strength();
use_aid = ( max_jack >= lvl ) || can_self_jack();
use_aid = ( max_jack >= lifting_quality_to_mass( lvl ) ) || can_self_jack();
use_str = g->u.can_lift( *veh );
} else {
item base( sel_vpart_info->item );
qual = qual_LIFT;
lvl = std::ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
lifting_quality_to_mass( 1 ) );
str = base.lift_strength();
use_aid = max_lift >= lvl;
use_aid = max_lift >= base.weight();
use_str = g->u.can_lift( base );
}

Expand Down Expand Up @@ -1766,15 +1770,15 @@ bool veh_interact::can_remove_part( int idx, const player &p )
qual = qual_JACK;
lvl = jack_quality( *veh );
str = veh->lift_strength();
use_aid = ( max_jack >= lvl ) || can_self_jack();
use_aid = ( max_jack >= lifting_quality_to_mass( lvl ) ) || can_self_jack();
use_str = g->u.can_lift( *veh );
} else {
item base( sel_vpart_info->item );
qual = qual_LIFT;
lvl = std::ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
lifting_quality_to_mass( 1 ) );
str = base.lift_strength();
use_aid = max_lift >= lvl;
use_aid = max_lift >= base.weight();
use_str = g->u.can_lift( base );
}

Expand Down
9 changes: 5 additions & 4 deletions src/veh_interact.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "player_activity.h"
#include "point.h"
#include "type_id.h"
#include "units.h"

class player;
class vpart_info;
Expand Down Expand Up @@ -104,10 +105,10 @@ class veh_interact
inventory crafting_inv;
input_context main_context;

// maximum level of available lifting equipment (if any)
int max_lift;
// maximum level of available jacking equipment (if any)
int max_jack;
// maximum weight capacity of available lifting equipment (if any)
units::mass max_lift;
// maximum weight_capacity of available jacking equipment (if any)
units::mass max_jack;

shared_ptr_fast<ui_adaptor> create_or_get_ui_adaptor();

Expand Down
2 changes: 1 addition & 1 deletion src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ int vpart_info::format_description( std::string &msg, const nc_color &format_col
_( "Has level <color_cyan>%1$d %2$s</color> quality" ), qual.second, qual.first.obj().name );
if( qual.first == quality_jack || qual.first == quality_lift ) {
msg += string_format( _( " and is rated at <color_cyan>%1$d %2$s</color>" ),
static_cast<int>( convert_weight( qual.second * TOOL_LIFT_FACTOR ) ),
static_cast<int>( convert_weight( lifting_quality_to_mass( qual.second ) ) ),
weight_units() );
}
msg += ".\n";
Expand Down

0 comments on commit b4aae59

Please sign in to comment.