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
50 changes: 25 additions & 25 deletions src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,8 @@ bool CountryInstance::modify_unit_type_unlock(UnitTypeBranched<Branch> const& un
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for unit type {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
unit_type, *this, static_cast<int64_t>(unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(unlock_level + unlock_level_change)
unit_type, *this, unlock_level,
unlock_level_change, unlock_level + unlock_level_change
);
return false;
}
Expand Down Expand Up @@ -844,7 +844,7 @@ bool CountryInstance::modify_unit_type_unlock(UnitType const& unit_type, technol
}

bool CountryInstance::unlock_unit_type(UnitType const& unit_type) {
return modify_unit_type_unlock(unit_type, 1);
return modify_unit_type_unlock(unit_type, technology_unlock_level_t { 1 });
}

bool CountryInstance::is_unit_type_unlocked(UnitType const& unit_type) const {
Expand Down Expand Up @@ -873,8 +873,8 @@ bool CountryInstance::modify_building_type_unlock(
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for building type {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
building_type, *this, static_cast<int64_t>(unlock_level), static_cast<int64_t>(unlock_level_change),
static_cast<int64_t>(unlock_level + unlock_level_change)
building_type, *this, unlock_level, unlock_level_change,
unlock_level + unlock_level_change
);
return false;
}
Expand All @@ -889,7 +889,7 @@ bool CountryInstance::modify_building_type_unlock(
}

bool CountryInstance::unlock_building_type(BuildingType const& building_type) {
return modify_building_type_unlock(building_type, 1);
return modify_building_type_unlock(building_type, technology_unlock_level_t { 1 });
}

bool CountryInstance::is_building_type_unlocked(BuildingType const& building_type) const {
Expand All @@ -903,8 +903,8 @@ bool CountryInstance::modify_crime_unlock(Crime const& crime, technology_unlock_
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for crime {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
crime, *this, static_cast<int64_t>(unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(unlock_level + unlock_level_change)
crime, *this, unlock_level,
unlock_level_change, unlock_level + unlock_level_change
);
return false;
}
Expand All @@ -915,7 +915,7 @@ bool CountryInstance::modify_crime_unlock(Crime const& crime, technology_unlock_
}

bool CountryInstance::unlock_crime(Crime const& crime) {
return modify_crime_unlock(crime, 1);
return modify_crime_unlock(crime, technology_unlock_level_t { 1 });
}

bool CountryInstance::is_crime_unlocked(Crime const& crime) const {
Expand All @@ -927,8 +927,8 @@ bool CountryInstance::modify_gas_attack_unlock(technology_unlock_level_t unlock_
if (gas_attack_unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for gas attack in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
*this, static_cast<int64_t>(gas_attack_unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(gas_attack_unlock_level + unlock_level_change)
*this, gas_attack_unlock_level,
unlock_level_change, gas_attack_unlock_level + unlock_level_change
);
return false;
}
Expand All @@ -939,7 +939,7 @@ bool CountryInstance::modify_gas_attack_unlock(technology_unlock_level_t unlock_
}

bool CountryInstance::unlock_gas_attack() {
return modify_gas_attack_unlock(1);
return modify_gas_attack_unlock(technology_unlock_level_t { 1 });
}

bool CountryInstance::is_gas_attack_unlocked() const {
Expand All @@ -951,8 +951,8 @@ bool CountryInstance::modify_gas_defence_unlock(technology_unlock_level_t unlock
if (gas_defence_unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for gas defence in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
*this, static_cast<int64_t>(gas_defence_unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(gas_defence_unlock_level + unlock_level_change)
*this, gas_defence_unlock_level,
unlock_level_change, gas_defence_unlock_level + unlock_level_change
);
return false;
}
Expand All @@ -963,7 +963,7 @@ bool CountryInstance::modify_gas_defence_unlock(technology_unlock_level_t unlock
}

bool CountryInstance::unlock_gas_defence() {
return modify_gas_defence_unlock(1);
return modify_gas_defence_unlock(technology_unlock_level_t { 1 });
}

bool CountryInstance::is_gas_defence_unlocked() const {
Expand All @@ -988,8 +988,8 @@ bool CountryInstance::modify_unit_variant_unlock(unit_variant_t unit_variant, te
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for unit variant {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
static_cast<uint64_t>(unit_variant), *this, static_cast<int64_t>(unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(unlock_level + unlock_level_change)
static_cast<uint64_t>(unit_variant), *this, unlock_level,
unlock_level_change, unlock_level + unlock_level_change
);
ret = false;
} else {
Expand All @@ -1004,7 +1004,7 @@ bool CountryInstance::modify_unit_variant_unlock(unit_variant_t unit_variant, te
}

bool CountryInstance::unlock_unit_variant(unit_variant_t unit_variant) {
return modify_unit_variant_unlock(unit_variant, 1);
return modify_unit_variant_unlock(unit_variant, technology_unlock_level_t { 1 });
}

unit_variant_t CountryInstance::get_max_unlocked_unit_variant() const {
Expand All @@ -1020,8 +1020,8 @@ bool CountryInstance::modify_technology_unlock(
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for technology {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
technology, *this, static_cast<int64_t>(unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(unlock_level + unlock_level_change)
technology, *this, unlock_level,
unlock_level_change, unlock_level + unlock_level_change
);
return false;
}
Expand Down Expand Up @@ -1053,7 +1053,7 @@ bool CountryInstance::set_technology_unlock_level(
}

bool CountryInstance::unlock_technology(Technology const& technology) {
return modify_technology_unlock(technology, 1);
return modify_technology_unlock(technology, technology_unlock_level_t { 1 });
}

bool CountryInstance::is_technology_unlocked(Technology const& technology) const {
Expand All @@ -1069,8 +1069,8 @@ bool CountryInstance::modify_invention_unlock(
if (unlock_level + unlock_level_change < 0) {
spdlog::error_s(
"Attempted to change unlock level for invention {} in country {} to invalid value: current level = {}, change = {}, invalid new value = {}",
invention, *this, static_cast<int64_t>(unlock_level),
static_cast<int64_t>(unlock_level_change), static_cast<int64_t>(unlock_level + unlock_level_change)
invention, *this, unlock_level,
unlock_level_change, unlock_level + unlock_level_change
);
return false;
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ bool CountryInstance::set_invention_unlock_level(
}

bool CountryInstance::unlock_invention(Invention const& invention) {
return modify_invention_unlock(invention, 1);
return modify_invention_unlock(invention, technology_unlock_level_t { 1 });
}

bool CountryInstance::is_invention_unlocked(Invention const& invention) const {
Expand Down Expand Up @@ -1239,7 +1239,7 @@ bool CountryInstance::apply_history_to_country(
ret &= set_technology_unlock_level(*technology, level);
}
for (auto const& [invention, activated] : entry.get_inventions()) {
ret &= set_invention_unlock_level(*invention, activated ? 1 : 0);
ret &= set_invention_unlock_level(*invention, technology_unlock_level_t { static_cast<int8_t>(activated ? 1 : 0) });
}

apply_foreign_investments(entry.get_foreign_investment(), country_instance_manager);
Expand Down
6 changes: 3 additions & 3 deletions src/openvic-simulation/country/CountryInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/IndexedFlatMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/research/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"
#include "openvic-simulation/types/UnitBranchType.hpp"
#include "openvic-simulation/types/UnitVariant.hpp"
Expand Down Expand Up @@ -389,8 +389,8 @@ namespace OpenVic {
OV_IFLATMAP_PROPERTY(RegimentType, technology_unlock_level_t, regiment_type_unlock_levels);
regiment_allowed_cultures_t PROPERTY(allowed_regiment_cultures, regiment_allowed_cultures_t::NO_CULTURES);
OV_IFLATMAP_PROPERTY(ShipType, technology_unlock_level_t, ship_type_unlock_levels);
technology_unlock_level_t PROPERTY(gas_attack_unlock_level, 0);
technology_unlock_level_t PROPERTY(gas_defence_unlock_level, 0);
technology_unlock_level_t PROPERTY(gas_attack_unlock_level, technology_unlock_level_t { 0 });
technology_unlock_level_t PROPERTY(gas_defence_unlock_level, technology_unlock_level_t { 0 });
memory::vector<technology_unlock_level_t> SPAN_PROPERTY(unit_variant_unlock_levels);

public:
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/history/CountryHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool CountryHistoryMap::_load_history_entry(
{
Technology const* technology = technology_manager.get_technology_by_identifier(key);
if (technology != nullptr) {
return expect_uint<decltype(entry.technologies)::mapped_type>(
return expect_strong_typedef<decltype(entry.technologies)::mapped_type>(
[&entry, technology](decltype(entry.technologies)::mapped_type value) -> bool {
if (value > 1) {
spdlog::warn_s(
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/history/CountryHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "openvic-simulation/types/IndexedFlatMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
#include "openvic-simulation/types/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/research/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/utility/Containers.hpp"

namespace OpenVic {
Expand Down
29 changes: 29 additions & 0 deletions src/openvic-simulation/research/TechnologyUnlockLevel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <cstdint>

#include <fmt/base.h>
#include <fmt/format.h>

#include <type_safe/strong_typedef.hpp>

namespace OpenVic {
struct technology_unlock_level_t
: type_safe::strong_typedef<technology_unlock_level_t, std::int8_t>,
type_safe::strong_typedef_op::equality_comparison<technology_unlock_level_t>,
type_safe::strong_typedef_op::relational_comparison<technology_unlock_level_t>,
type_safe::strong_typedef_op::integer_arithmetic<technology_unlock_level_t>,
type_safe::strong_typedef_op::mixed_addition<technology_unlock_level_t, std::uint8_t>,
type_safe::strong_typedef_op::mixed_subtraction<technology_unlock_level_t, std::uint8_t>,
type_safe::strong_typedef_op::mixed_relational_comparison<technology_unlock_level_t, std::int32_t>,
type_safe::strong_typedef_op::mixed_equality_comparison<technology_unlock_level_t, std::int32_t> {
using strong_typedef::strong_typedef;
};
}

template<>
struct fmt::formatter<OpenVic::technology_unlock_level_t> : fmt::formatter<std::int32_t> {
fmt::format_context::iterator format(OpenVic::technology_unlock_level_t const& value, fmt::format_context& ctx) const {
return fmt::formatter<std::int32_t>::format(type_safe::get(value), ctx);
}
};
7 changes: 0 additions & 7 deletions src/openvic-simulation/types/TechnologyUnlockLevel.hpp

This file was deleted.