Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor map::route to extract (some) cost functions #74373

Merged
merged 10 commits into from
Jun 18, 2024
4 changes: 2 additions & 2 deletions src/active_item_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "item_pocket.h"
#include "safe_reference.h"

float item_reference::spoil_multiplier()
float item_reference::spoil_multiplier() const
{
return std::accumulate(
pocket_chain.begin(), pocket_chain.end(), 1.0F,
Expand All @@ -17,7 +17,7 @@ float item_reference::spoil_multiplier()
} );
}

bool item_reference::has_watertight_container()
bool item_reference::has_watertight_container() const
{
return std::any_of(
pocket_chain.begin(), pocket_chain.end(),
Expand Down
4 changes: 2 additions & 2 deletions src/active_item_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct item_reference {
item *parent = nullptr;
std::vector<item_pocket const *> pocket_chain;

float spoil_multiplier();
bool has_watertight_container();
float spoil_multiplier() const;
bool has_watertight_container() const;
};

enum class special_item_type : int {
Expand Down
16 changes: 16 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ template<typename T>
struct weighted_int_list;
struct field_proc_data;

enum pf_special : int;

using relic_procgen_id = string_id<relic_procgen_data>;

class map_stack : public item_stack
Expand Down Expand Up @@ -737,6 +739,20 @@ class map
// Get a straight route from f to t, only along non-rough terrain. Returns an empty vector
// if that is not possible.
std::vector<tripoint> straight_route( const tripoint &f, const tripoint &t ) const;
private:
// Pathfinding cost helper that computes the cost of moving into |p| from |cur|.
// Includes climbing, bashing and opening doors.
int cost_to_pass( const tripoint &cur, const tripoint &p, const pathfinding_settings &settings,
pf_special p_special ) const;
// Pathfinding cost helper that computes the cost of moving into |p|
// from |cur| based on perceived danger.
// Includes moving through traps.
int cost_to_avoid( const tripoint &cur, const tripoint &p, const pathfinding_settings &settings,
pf_special p_special ) const;
// Sum of cost_to_pass and cost_to_avoid.
int extra_cost( const tripoint &cur, const tripoint &p, const pathfinding_settings &settings,
pf_special p_special ) const;
public:

// Vehicles: Common to 2D and 3D
VehicleList get_vehicles();
Expand Down
Loading
Loading