Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/openvic-simulation/country/CountryDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ bool CountryDefinitionManager::add_country(
static constexpr colour_t default_colour = colour_t::fill_as(colour_t::max_value);

return country_definitions.emplace_item(
identifier,
identifier, colour, get_country_definition_count(), *graphical_culture, std::move(parties), std::move(unit_names),
dynamic_tag, std::move(alternative_colours),
identifier, //
identifier, colour, CountryDefinition::index_t { get_country_definition_count() }, *graphical_culture,
std::move(parties), std::move(unit_names), dynamic_tag, std::move(alternative_colours),
/* Default to country colour for the chest and grey for the others. Update later if necessary. */
colour, default_colour, default_colour
);
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/country/CountryDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"

namespace OpenVic {
struct CountryDefinitionManager;
Expand All @@ -20,7 +21,7 @@ namespace OpenVic {
struct UnitType;

/* Generic information about a TAG */
struct CountryDefinition : HasIdentifierAndColour, HasIndex<CountryDefinition> {
struct CountryDefinition : HasIdentifierAndColour, HasIndex<CountryDefinition, country_index_t> {
friend struct CountryDefinitionManager;

using unit_names_map_t = ordered_map<UnitType const*, name_list_t>;
Expand Down
4 changes: 3 additions & 1 deletion src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <cstddef>
#include <cstdint>

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/country/SharedCountryValues.hpp"
#include "openvic-simulation/country/CountryDefinition.hpp"
#include "openvic-simulation/defines/CountryDefines.hpp"
Expand Down Expand Up @@ -2065,7 +2067,7 @@ void CountryInstance::manage_national_stockpile(
fixed_point_t weights_sum = 0;

for (auto [good_instance, good_data] : goods_data) {
const size_t index = good_instance.index;
const size_t index = type_safe::get(good_instance.index);
if (good_data.is_automated || !good_data.is_selling) {
const fixed_point_t quantity_to_allocate_for = good_data.is_automated
? good_data.government_needs - good_data.stockpile_amount
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/country/CountryInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "openvic-simulation/types/IndexedFlatMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"
#include "openvic-simulation/types/UnitBranchType.hpp"
#include "openvic-simulation/types/UnitVariant.hpp"
#include "openvic-simulation/types/ValueHistory.hpp"
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace OpenVic {

/* Representation of a country's mutable attributes, with a CountryDefinition that is unique at any single time
* but can be swapped with other CountryInstance's CountryDefinition when switching tags. */
struct CountryInstance : FlagStrings, HasIndex<CountryInstance>, PopsAggregate {
struct CountryInstance : FlagStrings, HasIndex<CountryInstance, country_index_t>, PopsAggregate {
friend struct CountryInstanceManager;

/*
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/dataloader/Dataloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ bool Dataloader::_load_map_dir(DefinitionManager& definition_manager) const {

bool ret = expect_dictionary_keys(
"max_provinces", ONE_EXACTLY,
expect_uint<ProvinceDefinition::index_t>(std::bind_front(&MapDefinition::set_max_provinces, &map_definition)),
expect_index<ProvinceDefinition::index_t>(std::bind_front(&MapDefinition::set_max_provinces, &map_definition)),
"sea_starts", ONE_EXACTLY,
expect_list_reserve_length(
water_province_identifiers, expect_identifier(vector_callback(water_province_identifiers))
Expand Down
25 changes: 25 additions & 0 deletions src/openvic-simulation/dataloader/NodeTools.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <concepts>
#include <cstdint>
#include <functional>
#include <optional>
Expand All @@ -13,6 +14,8 @@

#include <spdlog/common.h>

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/IndexedFlatMap.hpp"
Expand Down Expand Up @@ -195,6 +198,28 @@ using namespace std::string_view_literals;
return expect_uint(callback, base);
}

template<derived_from_specialization_of<type_safe::strong_typedef> T>
requires std::unsigned_integral<type_safe::underlying_type<T>>
NodeCallback auto expect_index(callback_t<T>& callback, int base = 10) {
using underlying_type = type_safe::underlying_type<T>;

return expect_uint64([callback](uint64_t val) mutable -> bool {
if (val <= static_cast<uint64_t>(std::numeric_limits<underlying_type>::max())) {
return callback(T(val));
}
spdlog::error_s(
"Invalid uint: {} (valid range: [0, {}])",
val, static_cast<uint64_t>(std::numeric_limits<underlying_type>::max())
);
return false;
}, base);
}
template<derived_from_specialization_of<type_safe::strong_typedef> T>
requires std::unsigned_integral<type_safe::underlying_type<T>>
NodeCallback auto expect_index(callback_t<T>&& callback, int base = 10) {
return expect_index(callback, base);
}

callback_t<std::string_view> expect_fixed_point_str(callback_t<fixed_point_t> callback);
node_callback_t expect_fixed_point(callback_t<fixed_point_t> callback);
/* Expect a list of 3 base 10 values, each either in the range [0, 1] or (1, 255], representing RGB components. */
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/economy/BuildingType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BuildingType::BuildingType(
index_t new_index,
std::string_view identifier,
building_type_args_t& building_type_args
) : HasIndex<BuildingType> { new_index },
) : HasIndex { new_index },
Modifier { identifier, std::move(building_type_args.modifier), modifier_type_t::BUILDING },
type { building_type_args.type },
on_completion { building_type_args.on_completion },
Expand Down Expand Up @@ -52,7 +52,7 @@ bool BuildingTypeManager::add_building_type(

const bool ret = building_types.emplace_item(
identifier,
get_building_type_count(), identifier, building_type_args
BuildingType::index_t { get_building_type_count() }, identifier, building_type_args
);

if (ret) {
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/economy/BuildingType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"
#include "openvic-simulation/utility/Containers.hpp"

namespace OpenVic {
Expand All @@ -19,7 +20,7 @@ namespace OpenVic {
* MAP-12, MAP-75, MAP-76
* MAP-13, MAP-78, MAP-79
*/
struct BuildingType : HasIndex<BuildingType>, Modifier {
struct BuildingType : HasIndex<BuildingType, building_type_index_t>, Modifier {
using naval_capacity_t = uint64_t;

struct building_type_args_t {
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/economy/GoodDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool GoodDefinitionManager::add_good_definition(

if (good_definitions.emplace_item(
identifier,
identifier, colour, get_good_definition_count(), category, base_price, is_available_from_start,
identifier, colour, GoodDefinition::index_t { get_good_definition_count() }, category, base_price, is_available_from_start,
is_tradeable, is_money, has_overseas_penalty
)) {
category.good_definitions.push_back(&get_back_good_definition());
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/economy/GoodDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"
#include "openvic-simulation/utility/Containers.hpp"

namespace OpenVic {
Expand Down Expand Up @@ -31,7 +32,7 @@ namespace OpenVic {
* ECON-238, ECON-239, ECON-240, ECON-241, ECON-242, ECON-243, ECON-244, ECON-245, ECON-246, ECON-247, ECON-248, ECON-249,
* ECON-250, ECON-251, ECON-252, ECON-253, ECON-254, ECON-255, ECON-256, ECON-257, ECON-258, ECON-259, ECON-260, ECON-261
*/
struct GoodDefinition : HasIdentifierAndColour, HasIndex<GoodDefinition> {
struct GoodDefinition : HasIdentifierAndColour, HasIndex<GoodDefinition, good_index_t> {

public:
GoodCategory const& category;
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/economy/GoodInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GoodInstance::GoodInstance(
GoodDefinition const* new_good_definition,
GameRulesManager const* new_game_rules_manager
) : HasIdentifierAndColour { *new_good_definition },
HasIndex<GoodInstance> { new_good_definition->index },
HasIndex { new_good_definition->index },
GoodMarket { *new_game_rules_manager, *new_good_definition }
{}

Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/economy/GoodInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#include "openvic-simulation/economy/trading/GoodMarket.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"

namespace OpenVic {
struct GoodDefinition;
struct GoodDefinitionManager;
struct GoodInstanceManager;

struct GoodInstance : HasIdentifierAndColour, HasIndex<GoodInstance>, GoodMarket {
struct GoodInstance : HasIdentifierAndColour, HasIndex<GoodInstance, good_index_t>, GoodMarket {
friend struct GoodInstanceManager;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <cstddef>

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/country/CountryInstance.hpp"
#include "openvic-simulation/defines/EconomyDefines.hpp"
#include "openvic-simulation/economy/GoodDefinition.hpp"
Expand Down Expand Up @@ -267,7 +269,7 @@ void ArtisanalProducer::artisan_tick_handler::allocate_money_for_inputs(
);
max_quantity_to_buy_per_good[&input_good] = max_quantity_to_buy;
pop.allocate_cash_for_artisanal_spending(money_to_spend);
const size_t index_in_all_goods = input_good.index;
const size_t index_in_all_goods = type_safe::get(input_good.index);
pop_max_quantity_to_buy_per_good[index_in_all_goods] += max_quantity_to_buy;
pop_money_to_spend_per_good[index_in_all_goods] += money_to_spend;
debug_cash_left -= money_to_spend;
Expand Down
6 changes: 4 additions & 2 deletions src/openvic-simulation/history/Bookmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
Expand All @@ -16,7 +18,7 @@ Bookmark::Bookmark(
std::string_view new_description,
Date new_date,
fvec2_t new_initial_camera_position
) : HasIdentifier { std::to_string(new_index) },
) : HasIdentifier { std::to_string(type_safe::get(new_index)) },
HasIndex { new_index },
name { new_name },
description { new_description },
Expand All @@ -28,7 +30,7 @@ bool BookmarkManager::add_bookmark(
) {
return bookmarks.emplace_item(
name,
bookmarks.size(), name, description, date, initial_camera_position
Bookmark::index_t { bookmarks.size() }, name, description, date, initial_camera_position
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/history/Bookmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"

namespace OpenVic {
struct Bookmark : HasIdentifier, HasIndex<Bookmark> {
struct Bookmark : HasIdentifier, HasIndex<Bookmark, bookmark_index_t> {

private:
memory::string PROPERTY(name);
Expand Down
4 changes: 3 additions & 1 deletion src/openvic-simulation/history/ProvinceHistory.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ProvinceHistory.hpp"

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/economy/GoodDefinition.hpp"
Expand Down Expand Up @@ -192,7 +194,7 @@ void ProvinceHistoryManager::lock_province_histories(MapDefinition const& map_de

memory::vector<bool> province_checklist(provinces.size());
for (auto [province, history_map] : mutable_iterator(province_histories)) {
province_checklist[province->index] = true;
province_checklist[type_safe::get(province->index)] = true;

history_map.sort_entries();
}
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/map/Crime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Crime::Crime(
icon_t new_icon,
ConditionScript&& new_trigger,
bool new_default_active
) : HasIndex<Crime> { new_index },
) : HasIndex { new_index },
TriggeredModifier { new_identifier, std::move(new_values), modifier_type_t::CRIME, new_icon, std::move(new_trigger) },
default_active { new_default_active } {}

Expand All @@ -29,7 +29,7 @@ bool CrimeManager::add_crime_modifier(
return crime_modifiers.emplace_item(
identifier,
duplicate_warning_callback,
get_crime_modifier_count(), identifier, std::move(values), icon, std::move(trigger), default_active
Crime::index_t { get_crime_modifier_count() }, identifier, std::move(values), icon, std::move(trigger), default_active
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/map/Crime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include "openvic-simulation/modifier/Modifier.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"

namespace OpenVic {
struct CrimeManager;

struct Crime final : HasIndex<Crime>, TriggeredModifier {
struct Crime final : HasIndex<Crime, crime_index_t>, TriggeredModifier {
friend struct CrimeManager;

private:
Expand Down
Loading