aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/economy/production/ProductionType.cpp43
-rw-r--r--src/openvic-simulation/economy/production/ProductionType.hpp3
2 files changed, 35 insertions, 11 deletions
diff --git a/src/openvic-simulation/economy/production/ProductionType.cpp b/src/openvic-simulation/economy/production/ProductionType.cpp
index 65f3eba..1503d4b 100644
--- a/src/openvic-simulation/economy/production/ProductionType.cpp
+++ b/src/openvic-simulation/economy/production/ProductionType.cpp
@@ -1,6 +1,7 @@
#include "ProductionType.hpp"
#include <openvic-dataloader/v2script/Parser.hpp>
+#include "dataloader/NodeTools.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -22,7 +23,7 @@ ProductionType::ProductionType(
template_type_t new_template_type,
Pop::pop_size_t new_base_workforce_size,
GoodDefinition::good_definition_map_t&& new_input_goods,
- GoodDefinition const* new_output_goods,
+ GoodDefinition const* new_output_good,
fixed_point_t new_base_output_quantity,
std::vector<bonus_t>&& new_bonuses,
GoodDefinition::good_definition_map_t&& new_maintenance_requirements,
@@ -35,7 +36,7 @@ ProductionType::ProductionType(
template_type { new_template_type },
base_workforce_size { new_base_workforce_size },
input_goods { std::move(new_input_goods) },
- output_goods { new_output_goods },
+ output_good { new_output_good },
base_output_quantity { new_base_output_quantity },
bonuses { std::move(new_bonuses) },
maintenance_requirements { std::move(new_maintenance_requirements) },
@@ -51,7 +52,9 @@ bool ProductionType::parse_scripts(DefinitionManager const& definition_manager)
return ret;
}
-ProductionTypeManager::ProductionTypeManager() : rgo_owner_sprite { 0 } {}
+ProductionTypeManager::ProductionTypeManager() :
+ good_to_rgo_production_type { nullptr },
+ rgo_owner_sprite { 0 } {}
node_callback_t ProductionTypeManager::_expect_job(
GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager, callback_t<Job&&> callback
@@ -98,7 +101,7 @@ bool ProductionTypeManager::add_production_type(
ProductionType::template_type_t template_type,
Pop::pop_size_t base_workforce_size,
GoodDefinition::good_definition_map_t&& input_goods,
- GoodDefinition const* output_goods,
+ GoodDefinition const* output_good,
fixed_point_t base_output_quantity,
std::vector<ProductionType::bonus_t>&& bonuses,
GoodDefinition::good_definition_map_t&& maintenance_requirements,
@@ -121,7 +124,7 @@ bool ProductionTypeManager::add_production_type(
return false;
}
- if (output_goods == nullptr) {
+ if (output_good == nullptr) {
Logger::error("Output good for production type ", identifier, " was null!");
return false;
}
@@ -167,13 +170,29 @@ bool ProductionTypeManager::add_production_type(
}
const bool ret = production_types.add_item({
- identifier, owner, std::move(jobs), template_type, base_workforce_size, std::move(input_goods), output_goods,
+ identifier, owner, std::move(jobs), template_type, base_workforce_size, std::move(input_goods), output_good,
base_output_quantity, std::move(bonuses), std::move(maintenance_requirements), is_coastal, is_farm, is_mine
});
+
+ if(ret && (is_farm | is_mine)) {
+ ProductionType const& production_type = production_types.get_items().back();
+ auto current_rgo_pt = good_to_rgo_production_type[*output_good];
+ if(current_rgo_pt == nullptr) {
+ // first rgo pt
+ good_to_rgo_production_type[*output_good] = &production_type;
+ }
+ else if (is_farm && current_rgo_pt->is_mine()) {
+ // farms are preferred over mines in V2
+ good_to_rgo_production_type[*output_good] = &production_type;
+ }
+ //else ignore, we already have an rgo pt
+ }
+
if (rgo_owner_sprite <= 0 && ret && template_type == RGO && owner.has_value() && owner->get_pop_type() != nullptr) {
/* Set rgo owner sprite to that of the first RGO owner we find. */
rgo_owner_sprite = owner->get_pop_type()->get_sprite();
}
+
return ret;
}
@@ -224,7 +243,10 @@ bool ProductionTypeManager::load_production_types_file(
}
)(parser.get_file_node());
+
/* Pass #3: actually load production types */
+ good_to_rgo_production_type.set_keys(&good_definition_manager.get_good_definitions());
+
reserve_more_production_types(expected_types);
ret &= expect_dictionary(
[this, &good_definition_manager, &pop_manager, &template_target_map, &template_node_map](
@@ -238,7 +260,7 @@ bool ProductionTypeManager::load_production_types_file(
std::optional<Job> owner;
std::vector<Job> jobs;
ProductionType::template_type_t template_type { FACTORY };
- GoodDefinition const* output_goods = nullptr;
+ GoodDefinition const* output_good = nullptr;
Pop::pop_size_t base_workforce_size = 0;
GoodDefinition::good_definition_map_t input_goods, maintenance_requirements;
fixed_point_t base_output_quantity = 0;
@@ -270,8 +292,8 @@ bool ProductionTypeManager::load_production_types_file(
"workforce", ZERO_OR_ONE, expect_uint(assign_variable_callback(base_workforce_size)),
"input_goods", ZERO_OR_ONE,
good_definition_manager.expect_good_definition_decimal_map(move_variable_callback(input_goods)),
- "output_goods", ZERO_OR_ONE,
- good_definition_manager.expect_good_definition_identifier(assign_variable_callback_pointer(output_goods)),
+ "output_goods", ONE_EXACTLY,
+ good_definition_manager.expect_good_definition_identifier(assign_variable_callback_pointer(output_good)),
"value", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(base_output_quantity)),
"efficiency", ZERO_OR_ONE, good_definition_manager.expect_good_definition_decimal_map(
move_variable_callback(maintenance_requirements)
@@ -300,9 +322,10 @@ bool ProductionTypeManager::load_production_types_file(
ret &= parse_node(node);
ret &= add_production_type(
- key, owner, std::move(jobs), template_type, base_workforce_size, std::move(input_goods), output_goods,
+ key, owner, std::move(jobs), template_type, base_workforce_size, std::move(input_goods), output_good,
base_output_quantity, std::move(bonuses), std::move(maintenance_requirements), is_coastal, is_farm, is_mine
);
+
return ret;
}
)(parser.get_file_node());
diff --git a/src/openvic-simulation/economy/production/ProductionType.hpp b/src/openvic-simulation/economy/production/ProductionType.hpp
index 5394938..b06c9b5 100644
--- a/src/openvic-simulation/economy/production/ProductionType.hpp
+++ b/src/openvic-simulation/economy/production/ProductionType.hpp
@@ -47,7 +47,7 @@ namespace OpenVic {
const Pop::pop_size_t PROPERTY(base_workforce_size);
GoodDefinition::good_definition_map_t PROPERTY(input_goods);
- GoodDefinition const* PROPERTY(output_goods);
+ GoodDefinition const* PROPERTY(output_good);
const fixed_point_t PROPERTY(base_output_quantity);
std::vector<bonus_t> PROPERTY(bonuses);
@@ -83,6 +83,7 @@ namespace OpenVic {
private:
IdentifierRegistry<ProductionType> IDENTIFIER_REGISTRY(production_type);
PopType::sprite_t PROPERTY(rgo_owner_sprite);
+ IndexedMap<GoodDefinition, ProductionType const*> PROPERTY(good_to_rgo_production_type);
NodeTools::node_callback_t _expect_job(
GoodDefinitionManager const& good_definition_manager, PopManager const& pop_manager,