27 #include "eng3d/pathfind.hpp"
29 #include <tbb/blocked_range.h>
30 #include <tbb/parallel_for.h>
31 #include <glm/vec3.hpp>
32 #include <glm/gtc/constants.hpp>
33 #include <glm/trigonometric.hpp>
34 #include <glm/geometric.hpp>
40 this->initialize(world);
44 tbb::parallel_for(
static_cast<size_t>(0), world.provinces.size(), [
this, &world](
const auto province_id) {
45 glm::vec2 world_size{ world.width, world.height};
46 const auto& province = world.provinces[province_id];
47 for(
size_t i = 0; i < world.provinces.size(); i++) {
48 const auto& other_province = world.provinces[i];
49 this->trade_costs[province_id][i] =
50 get_trade_cost(province, other_province, world_size);
55 if (cost_eval.empty()) {
56 for(
size_t i = 0; i < world.provinces.size(); i++) {
57 if(!world.provinces[i].is_coastal)
58 cost_eval.push_back(i);
73 float Trade::get_trade_cost(
const Province& province1,
const Province& province2, glm::vec2 world_size)
const {
74 const auto radius = 100.f;
78 auto foreign_penalty = 1.f;
80 foreign_penalty = 5.f;
85 if(relation.is_customs_union())
86 foreign_penalty = 1.f;
91 return distance * trade_cost;
94 inline void Trade::initialize(
const World& world) {
95 trade_costs.resize(world.provinces.size(), std::vector<float>(world.provinces.size(), std::numeric_limits<float>::max()));
98 neighbours.reserve(world.provinces.size());
99 for(
const auto& province : world.provinces) {
100 std::vector<Trade::Vertex> province_neighbours;
101 province_neighbours.reserve(province.neighbour_ids.size());
102 for(
const auto neighbour_id : province.neighbour_ids) {
103 const auto& neighbour = world.provinces[neighbour_id];
104 const auto trade_cost =
get_trade_cost(province, neighbour, world_size);
105 province_neighbours.emplace_back(trade_cost, neighbour_id);
107 neighbours.push_back(province_neighbours);
A single province, which is used to simulate economy in a "bulk-tiles" way instead of doing economica...
TerrainTypeId terrain_type_id
float euclidean_distance(const Province &other_province, glm::vec2 world_size, float radius) const
static World & get_instance()
void parallel_for(T range, F &&func)
float get_trade_cost(const Province &province1, const Province &province2, glm::vec2 world_size) const
std::vector< ProvinceId > cost_eval
Cost-evaluatable provinces, we discard sea and ocean provinces from this formula to save space and ti...
std::vector< std::vector< float > > trade_costs
void recalculate(const World &world)