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
2 changes: 1 addition & 1 deletion src/openvic-simulation/country/CountryDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool CountryDefinitionManager::add_country(

return country_definitions.emplace_item(
identifier, //
identifier, colour, CountryDefinition::index_t { get_country_definition_count() }, *graphical_culture,
identifier, colour, index_from_count<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/economy/BuildingType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ bool BuildingTypeManager::add_building_type(

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

if (ret) {
Expand Down
10 changes: 7 additions & 3 deletions src/openvic-simulation/economy/GoodDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;

GoodCategory::GoodCategory(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
GoodCategory::GoodCategory(std::string_view new_identifier, index_t new_index)
: HasIdentifier { new_identifier }, HasIndex { new_index } {}

GoodDefinition::GoodDefinition(
std::string_view new_identifier,
Expand All @@ -34,7 +35,10 @@ bool GoodDefinitionManager::add_good_category(std::string_view identifier, size_
return false;
}

if (good_categories.emplace_item(identifier, identifier)) {
if (good_categories.emplace_item(
identifier,
identifier, index_from_count<GoodCategory::index_t>(get_good_category_count())
)) {
good_categories.back().good_definitions.reserve(expected_goods_in_category);
return true;
} else {
Expand Down Expand Up @@ -64,7 +68,7 @@ bool GoodDefinitionManager::add_good_definition(

if (good_definitions.emplace_item(
identifier,
identifier, colour, GoodDefinition::index_t { get_good_definition_count() }, category, base_price, is_available_from_start,
identifier, colour, index_from_count<GoodDefinition::index_t>(get_good_definition_count()), category, base_price, is_available_from_start,
is_tradeable, is_money, has_overseas_penalty
)) {
category.good_definitions.emplace_back(get_back_good_definition());
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/economy/GoodDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ namespace OpenVic {
struct GoodDefinitionManager;
struct GoodDefinition;

struct GoodCategory : HasIdentifier {
struct GoodCategory : HasIdentifier, HasIndex<GoodCategory, good_category_index_t> {
friend struct GoodDefinitionManager;

private:
memory::vector<std::reference_wrapper<const GoodDefinition>> SPAN_PROPERTY(good_definitions);
public:
GoodCategory(std::string_view new_identifier);
GoodCategory(std::string_view new_identifier, index_t new_index);
GoodCategory(GoodCategory&&) = default;
};

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/history/Bookmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool BookmarkManager::add_bookmark(
) {
return bookmarks.emplace_item(
name,
Bookmark::index_t { bookmarks.size() }, name, description, date, initial_camera_position
index_from_count<Bookmark::index_t>(bookmarks.size()), name, description, date, initial_camera_position
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/map/Crime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ bool CrimeManager::add_crime_modifier(
return crime_modifiers.emplace_item(
identifier,
duplicate_warning_callback,
Crime::index_t { get_crime_modifier_count() }, identifier, std::move(values), icon, std::move(trigger), default_active
index_from_count<Crime::index_t>(get_crime_modifier_count()), identifier, std::move(values), icon,
std::move(trigger), default_active
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/openvic-simulation/map/Mapmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Mapmode::Mapmode(
is_parchment_mapmode_allowed { new_is_parchment_mapmode_allowed } {}

const Mapmode Mapmode::ERROR_MAPMODE {
"mapmode_error", index_t { std::numeric_limits<std::size_t>::max() }, [](
"mapmode_error", Mapmode::ERROR_INDEX, [](
MapInstance const& map_instance, ProvinceInstance const& province,
CountryInstance const* player_country, ProvinceInstance const* selected_province
) -> base_stripe_t {
Expand Down Expand Up @@ -63,7 +63,8 @@ bool MapmodeManager::add_mapmode(
}
return mapmodes.emplace_item(
identifier,
identifier, Mapmode::index_t { get_mapmode_count() }, colour_func, localisation_key, parchment_mapmode_allowed
identifier, index_from_count<Mapmode::index_t>(get_mapmode_count()), colour_func, localisation_key,
parchment_mapmode_allowed
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/openvic-simulation/map/Mapmode.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

#include <limits>

#include <function2/function2.hpp>

#include <type_safe/strong_typedef.hpp>

#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
Expand Down Expand Up @@ -36,6 +40,9 @@ namespace OpenVic {
memory::string PROPERTY(localisation_key);

public:
static constexpr index_t ERROR_INDEX {
std::numeric_limits<type_safe::underlying_type<index_t>>::max()
};
static const Mapmode ERROR_MAPMODE;
const bool is_parchment_mapmode_allowed;

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/map/TerrainType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool TerrainTypeManager::add_terrain_type(

return terrain_types.emplace_item(
identifier,
TerrainType::index_t { get_terrain_type_count() }, identifier,
index_from_count<TerrainType::index_t>(get_terrain_type_count()), identifier,
colour, std::move(values), movement_cost, defence_bonus, combat_width_percentage_change, is_water
);
}
Expand Down
18 changes: 11 additions & 7 deletions src/openvic-simulation/military/UnitType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ using enum unit_branch_t;
using enum UnitType::unit_category_t;

UnitType::UnitType(
std::string_view new_identifier, unit_branch_t new_branch, unit_type_args_t& unit_args
std::string_view new_identifier, unit_type_index_t new_unit_type_index, unit_branch_t new_branch,
unit_type_args_t& unit_args
) : HasIdentifier { new_identifier },
unit_type_index { new_unit_type_index },
branch { new_branch },
icon { unit_args.icon },
sprite { unit_args.sprite },
Expand Down Expand Up @@ -47,9 +49,9 @@ UnitType::UnitType(
}

UnitTypeBranched<LAND>::UnitTypeBranched(
index_t new_index, std::string_view new_identifier,
index_t new_index, unit_type_index_t new_unit_type_index, std::string_view new_identifier,
unit_type_args_t& unit_args, regiment_type_args_t const& regiment_type_args
) : UnitType { new_identifier, LAND, unit_args },
) : UnitType { new_identifier, new_unit_type_index, LAND, unit_args },
HasIndex { new_index },
allowed_cultures { regiment_type_args.allowed_cultures },
sprite_override { regiment_type_args.sprite_override },
Expand All @@ -64,9 +66,9 @@ UnitTypeBranched<LAND>::UnitTypeBranched(
siege { regiment_type_args.siege } {}

UnitTypeBranched<NAVAL>::UnitTypeBranched(
index_t new_index, std::string_view new_identifier,
index_t new_index, unit_type_index_t new_unit_type_index, std::string_view new_identifier,
unit_type_args_t& unit_args, ship_type_args_t const& ship_type_args
) : UnitType { new_identifier, NAVAL, unit_args },
) : UnitType { new_identifier, new_unit_type_index, NAVAL, unit_args },
HasIndex { new_index },
naval_icon { ship_type_args.naval_icon },
can_sail { ship_type_args.sail },
Expand Down Expand Up @@ -135,7 +137,8 @@ bool UnitTypeManager::add_regiment_type(

bool ret = regiment_types.emplace_item(
identifier,
RegimentType::index_t { get_regiment_type_count() }, identifier,
index_from_count<RegimentType::index_t>(get_regiment_type_count()),
index_from_count<unit_type_index_t>(get_unit_type_count()), identifier,
unit_args, std::move(regiment_type_args)
);
if (ret) {
Expand Down Expand Up @@ -168,7 +171,8 @@ bool UnitTypeManager::add_ship_type(

bool ret = ship_types.emplace_item(
identifier,
ShipType::index_t { get_ship_type_count() }, identifier,
index_from_count<ShipType::index_t>(get_ship_type_count()),
index_from_count<unit_type_index_t>(get_unit_type_count()), identifier,
unit_args, ship_type_args
);
if (ret) {
Expand Down
31 changes: 28 additions & 3 deletions src/openvic-simulation/military/UnitType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ namespace OpenVic {

protected:
/* Non-const reference unit_args so variables can be moved from it. */
UnitType(std::string_view new_identifier, unit_branch_t new_branch, unit_type_args_t& unit_args);
UnitType(
std::string_view new_identifier, unit_type_index_t new_unit_type_index, unit_branch_t new_branch,
unit_type_args_t& unit_args
);

public:
const unit_type_index_t unit_type_index; // Position in the combined unit type registry
const unit_branch_t branch; /* type in defines */
const unit_category_t unit_category;
const bool starts_unlocked;
Expand Down Expand Up @@ -116,7 +120,7 @@ namespace OpenVic {
const fixed_point_t siege;

UnitTypeBranched(
index_t new_index, std::string_view new_identifier,
index_t new_index, unit_type_index_t new_unit_type_index, std::string_view new_identifier,
unit_type_args_t& unit_args, regiment_type_args_t const& regiment_type_args
);
UnitTypeBranched(UnitTypeBranched&&) = default;
Expand Down Expand Up @@ -155,7 +159,7 @@ namespace OpenVic {
const fixed_point_t torpedo_attack;

UnitTypeBranched(
index_t new_index, std::string_view new_identifier,
index_t new_index, unit_type_index_t new_unit_type_index, std::string_view new_identifier,
unit_type_args_t& unit_args, ship_type_args_t const& ship_type_args
);
UnitTypeBranched(UnitTypeBranched&&) = default;
Expand Down Expand Up @@ -193,6 +197,27 @@ namespace OpenVic {
return NodeTools::expect_identifier(expect_branch_str(callback));
}

constexpr NodeTools::NodeCallback auto expect_unit_type_index(
NodeTools::Callback<unit_type_index_t> auto callback, bool warn = false
) const {
return expect_unit_type_identifier(
[callback](UnitType const& unit_type) -> bool {
return callback(unit_type.unit_type_index);
},
warn
);
}
constexpr NodeTools::Callback<std::string_view> auto expect_unit_type_index_str(
NodeTools::Callback<unit_type_index_t> auto callback, bool allow_empty = false, bool warn = false
) const {
return expect_unit_type_str(
[callback](UnitType const& unit_type) -> bool {
return callback(unit_type.unit_type_index);
},
allow_empty, warn
);
}

bool load_unit_type_file(
GoodDefinitionManager const& good_definition_manager, TerrainTypeManager const& terrain_type_manager,
ModifierManager const& modifier_manager, ovdl::v2script::Parser const& parser
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/politics/Government.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool GovernmentTypeManager::add_government_type(

const bool ret = government_types.emplace_item(
identifier,
GovernmentType::index_t { get_government_type_count() }, identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration, flag_type
index_from_count<GovernmentType::index_t>(get_government_type_count()), identifier, std::move(ideologies), elections, appoint_ruling_party, term_duration, flag_type
);

/* flag_type can be empty here for default/non-ideological flag */
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/politics/Ideology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool IdeologyManager::add_ideology(
return false;
}

const Ideology::index_t new_index = Ideology::index_t { ideologies.size() };
const Ideology::index_t new_index = index_from_count<Ideology::index_t>(ideologies.size());
return ideologies.emplace_item(
identifier,
identifier,
Expand Down
8 changes: 4 additions & 4 deletions src/openvic-simulation/politics/IssueManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool IssueManager::add_party_policy_group(std::string_view identifier) {

return party_policy_groups.emplace_item(
identifier,
identifier, PartyPolicyGroup::index_t { get_party_policy_group_count() }
identifier, index_from_count<PartyPolicyGroup::index_t>(get_party_policy_group_count())
);
}

Expand All @@ -29,7 +29,7 @@ bool IssueManager::add_party_policy(

if (!party_policies.emplace_item(
identifier,
PartyPolicy::index_t { get_party_policy_count() }, identifier,
index_from_count<PartyPolicy::index_t>(get_party_policy_count()), identifier,
new_colour, std::move(values), party_policy_group, std::move(rules), jingoism
)) {
return false;
Expand Down Expand Up @@ -61,7 +61,7 @@ bool IssueManager::add_reform_group(

if (!reform_groups.emplace_item(
identifier,
identifier, ReformGroup::index_t { get_reform_group_count() }, reform_type, ordered, administrative
identifier, index_from_count<ReformGroup::index_t>(get_reform_group_count()), reform_type, ordered, administrative
)) {
return false;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ bool IssueManager::add_reform(

if (!reforms.emplace_item(
identifier,
Reform::index_t { get_reform_count() }, identifier,
index_from_count<Reform::index_t>(get_reform_count()), identifier,
new_colour, std::move(values), reform_group, ordinal, administrative_multiplier, std::move(rules),
technology_cost, std::move(allow), std::move(on_execute_trigger), std::move(on_execute_effect)
)) {
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/politics/Rebel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool RebelManager::add_rebel_type(

return rebel_types.emplace_item(
new_identifier,
RebelType::index_t { get_rebel_type_count() }, new_identifier,
index_from_count<RebelType::index_t>(get_rebel_type_count()), new_identifier,
icon, area, break_alliance_on_win, std::move(desired_governments), defection, independence,
defect_delay, ideology, allow_all_cultures, allow_all_culture_groups, allow_all_religions, allow_all_ideologies,
resilient, reinforcing, general, smart, unit_transfer, occupation_mult, std::move(will_rise), std::move(spawn_chance),
Expand Down
5 changes: 3 additions & 2 deletions src/openvic-simulation/population/Culture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;

GraphicalCultureType::GraphicalCultureType(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
GraphicalCultureType::GraphicalCultureType(std::string_view new_identifier, index_t new_index)
: HasIdentifier { new_identifier }, HasIndex { new_index } {}

CultureGroup::CultureGroup(
std::string_view new_identifier, std::string_view new_leader, GraphicalCultureType const& new_unit_graphical_culture_type,
Expand All @@ -35,7 +36,7 @@ bool CultureManager::add_graphical_culture_type(std::string_view identifier) {
}
return graphical_culture_types.emplace_item(
identifier,
identifier
identifier, index_from_count<GraphicalCultureType::index_t>(get_graphical_culture_type_count())
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/openvic-simulation/population/Culture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/UnitBranchType.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"

namespace OpenVic {
struct CultureManager;
struct CountryDefinition;
struct CountryDefinitionManager;
class Dataloader;

struct GraphicalCultureType : HasIdentifier {
struct GraphicalCultureType : HasIdentifier, HasIndex<GraphicalCultureType, graphical_culture_index_t> {
friend struct CultureManager;

public:
GraphicalCultureType(std::string_view new_identifier);
GraphicalCultureType(std::string_view new_identifier, index_t new_index);
GraphicalCultureType(GraphicalCultureType&&) = default;
};

Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/population/PopManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool PopManager::add_strata(std::string_view identifier) {
}
return stratas.emplace_item(
identifier,
identifier, Strata::index_t { get_strata_count() }
identifier, index_from_count<Strata::index_t>(get_strata_count())
);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ bool PopManager::add_pop_type(
identifier,
identifier,
colour,
PopType::index_t { get_pop_type_count() },
index_from_count<PopType::index_t>(get_pop_type_count()),
*strata,
sprite,
std::move(life_needs),
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/research/Invention.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool InventionManager::add_invention(
}

return inventions.emplace_item(
identifier, Invention::index_t { get_invention_count() }, identifier, std::move(values), news,
identifier, index_from_count<Invention::index_t>(get_invention_count()), identifier, std::move(values), news,
std::move(activated_units), std::move(activated_buildings), std::move(enabled_crimes), unlock_gas_attack,
unlock_gas_defence, std::move(limit), std::move(chance),
std::move(raw_associated_tech_identifiers)
Expand Down
Loading
Loading