diff --git a/CMakeLists.txt b/CMakeLists.txt index 39affed8d..91aa1c586 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ if(WIN32) message(STATUS "Normal, not PGO, build") target_compile_options(AliceCommon INTERFACE /bigobj /wd4100 /wd4189 /wd4065 /wd4201 /wd4324 /GR- /W4 /permissive- /Zc:preprocessor /WX /arch:AVX2 /GF /w34388 /w34389 /Z7 - $<$: /EHsc /MTd /RTC1 /Od> + $<$: /EHsc /MTd /O1> # for faster debug builds, replace /RTC1 /Od with /O1 -- should be able to use /Ox, but for some reason that crashes ZSTD $<$>: /DNDEBUG /wd4530 /MT /O2 /Oi /GL /sdl- /GS- /Gy /Gw /Zc:preprocessor /Zc:inline>) target_link_options(AliceCommon INTERFACE diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index f7b77bc74..854dfff39 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -734,16 +734,6 @@ void update_ai_econ_construction(sys::state& state) { if(n.get_spending_level() < 1.0f || n.get_last_treasury() >= n.get_stockpiles(economy::money)) continue; - // buy stuff from the global market if we need it - //state.world.for_each_commodity([&](dcon::commodity_id c) { - // n.set_stockpile_targets(c, 10000.f); - // if(n.get_demand_satisfaction(c) < 1.0f) { - // n.set_drawing_on_stockpiles(c, true); - // } else { - // n.set_drawing_on_stockpiles(c, false); - // } - //}); - auto treasury = n.get_stockpiles(economy::money); int32_t max_projects = std::max(8, int32_t(treasury / 8000.0f)); auto rules = n.get_combined_issue_rules(); @@ -890,15 +880,20 @@ void update_ai_econ_construction(sys::state& state) { if((rules & issue_rule::expand_factory) != 0) { // check: if present, try to upgrade bool present_in_location = false; + bool under_cap = false; province::for_each_province_in_state_instance(state, si, [&](dcon::province_id p) { for(auto fac : state.world.province_get_factory_location(p)) { auto type = fac.get_factory().get_building_type(); if(type_selection == type) { + under_cap = fac.get_factory().get_production_scale() < 0.9f; present_in_location = true; return; } } }); + if(under_cap) { + continue; // factory doesn't need to get larger + } if(present_in_location) { auto new_up = fatten(state.world, state.world.force_create_state_building_construction(si, n)); new_up.set_is_pop_project(false); diff --git a/src/economy/economy.cpp b/src/economy/economy.cpp index e7437fa0a..933f2550f 100644 --- a/src/economy/economy.cpp +++ b/src/economy/economy.cpp @@ -49,7 +49,7 @@ bool has_factory(sys::state const& state, dcon::state_instance_id si) { return false; } -inline constexpr float inputs_base_factor = 0.5f; +inline constexpr float inputs_base_factor = 0.55f; void initialize_artisan_distribution(sys::state& state) { state.world.nation_resize_artisan_distribution(state.world.commodity_size()); diff --git a/src/gui/gui_event.cpp b/src/gui/gui_event.cpp index 0a8122d19..faaa70592 100644 --- a/src/gui/gui_event.cpp +++ b/src/gui/gui_event.cpp @@ -637,7 +637,7 @@ message_result national_event_window::get(sys::state& state, Cyto::Any& return message_result::consumed; } else if(payload.holds_type()) { if(!events.empty()) { - events.erase(events.begin() + size_t(index)); + events.erase(events.begin() + size_t(std::min(size_t(index), events.size() - 1))); impl_on_update(state); } return message_result::consumed; @@ -842,7 +842,7 @@ message_result provincial_event_window::get(sys::state& state, Cyto::Any& payloa return message_result::consumed; } else if(payload.holds_type()) { if(!events.empty()) { - events.erase(events.begin() + size_t(index)); + events.erase(events.begin() + size_t(std::min(size_t(index), events.size() - 1))); impl_on_update(state); } return message_result::consumed; diff --git a/src/gui/gui_topbar.hpp b/src/gui/gui_topbar.hpp index 68bee4877..893a78e6a 100644 --- a/src/gui/gui_topbar.hpp +++ b/src/gui/gui_topbar.hpp @@ -1503,8 +1503,8 @@ class topbar_colony_icon : public standard_nation_button { return 2; } } - // TODO - when the player clicks on the colony icon and theres colonies to expand then we want to teleport their camera to the - // colonies position & open the prov window + // TODO - when the player clicks on the colony icon and there are colonies to expand then we want to teleport their camera to the + // colony's position & open the prov window tooltip_behavior has_tooltip(sys::state& state) noexcept override { return tooltip_behavior::variable_tooltip; @@ -1517,29 +1517,21 @@ class topbar_colony_icon : public standard_nation_button { auto nation_id = any_cast(payload); auto nation_fat_id = dcon::fatten(state.world, nation_id); - auto box = text::open_layout_box(contents, 0); + if(nations::can_expand_colony(state, nation_id)) { nation_fat_id.for_each_colonization([&](dcon::colonization_id colony) { - auto colony_fat_id = dcon::fatten(state.world, colony); - auto colState = colony_fat_id.get_state(); - auto colonyName = colState.get_name(); - text::substitution_map sub; - text::add_to_substitution_map(sub, text::variable_type::region, colonyName); - text::localised_format_box(state, contents, box, std::string_view("countryalert_colonialgood_state"), sub); + auto colState = dcon::fatten(state.world, colony).get_state(); + text::add_line(state, contents, "countryalert_colonialgood_state", text::variable_type::region, colState); }); } else if(nations::is_losing_colonial_race(state, nation_id)) { nation_fat_id.for_each_colonization([&](dcon::colonization_id colony) { - auto colony_fat_id = dcon::fatten(state.world, colony); - auto colState = colony_fat_id.get_state(); - auto colonyName = colState.get_name(); - text::substitution_map sub; - text::add_to_substitution_map(sub, text::variable_type::region, colonyName); - text::localised_format_box(state, contents, box, std::string_view("countryalert_colonialbad_influence"), sub); + auto colState = dcon::fatten(state.world, colony).get_state(); + text::add_line(state, contents, "countryalert_colonialbad_influence", text::variable_type::region, colState); }); } else { - text::localised_format_box(state, contents, box, std::string_view("countryalert_no_colonial"), text::substitution_map{}); + text::add_line(state, contents, "countryalert_no_colonial"); } - text::close_layout_box(contents, box); + } } }; diff --git a/src/launcher/launcher_main.cpp b/src/launcher/launcher_main.cpp index 50f6df8b5..45ec30f8c 100644 --- a/src/launcher/launcher_main.cpp +++ b/src/launcher/launcher_main.cpp @@ -71,8 +71,8 @@ static int32_t obj_under_mouse = -1; constexpr inline ui_active_rect ui_rects[] = { ui_active_rect{ 880 - 31, 0 , 31, 31}, // close - ui_active_rect{ 28, 208, 21, 93}, // left - ui_active_rect{ 513, 208, 21, 93}, // right + ui_active_rect{ 30, 208, 21, 93}, // left + ui_active_rect{ 515, 208, 21, 93}, // right ui_active_rect{ 555, 47, 286, 33 }, // create scenario ui_active_rect{ 555, 196, 286, 33 }, // play game diff --git a/src/military/military.cpp b/src/military/military.cpp index b404b3ba7..7919376dd 100644 --- a/src/military/military.cpp +++ b/src/military/military.cpp @@ -7,6 +7,9 @@ namespace military { +constexpr inline float org_dam_mul = 0.3f; +constexpr inline float str_dam_mul = 0.25f; + int32_t total_regiments(sys::state& state, dcon::nation_id n) { return state.world.nation_get_active_regiments(n); } @@ -4977,10 +4980,10 @@ void update_land_battles(sys::state& state) { auto& att_stats = state.world.nation_get_unit_stats(tech_att_nation, state.world.regiment_get_type(att_back[i])); auto& def_stats = state.world.nation_get_unit_stats(tech_def_nation, state.world.regiment_get_type(def_front[i])); - auto str_damage = + auto str_damage = str_dam_mul * (att_stats.attack_or_gun_power * 0.1f + 1.0f) * att_stats.support * attacker_mod / (defender_fort * (state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_def_nation, sys::national_mod_offsets::military_tactics))); - auto org_damage = + auto org_damage = org_dam_mul * (att_stats.attack_or_gun_power * 0.1f + 1.0f) * att_stats.support * attacker_mod / (defender_fort * defender_org_bonus * def_stats.discipline_or_evasion * (1.0f + state.world.nation_get_modifier_values(tech_def_nation, sys::national_mod_offsets::land_organisation))); @@ -5015,8 +5018,8 @@ void update_land_battles(sys::state& state) { auto& def_stats = state.world.nation_get_unit_stats(tech_def_nation, state.world.regiment_get_type(def_back[i])); auto& att_stats = state.world.nation_get_unit_stats(tech_att_nation, state.world.regiment_get_type(att_front[i])); - auto str_damage = (def_stats.attack_or_gun_power * 0.1f + 1.0f) * def_stats.support * defender_mod / ((state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::military_tactics))); - auto org_damage = (def_stats.attack_or_gun_power * 0.1f + 1.0f) * def_stats.support * defender_mod / (attacker_org_bonus * def_stats.discipline_or_evasion * (1.0f + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::land_organisation))); + auto str_damage = str_dam_mul * (def_stats.attack_or_gun_power * 0.1f + 1.0f) * def_stats.support * defender_mod / ((state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::military_tactics))); + auto org_damage = org_dam_mul * (def_stats.attack_or_gun_power * 0.1f + 1.0f) * def_stats.support * defender_mod / (attacker_org_bonus * def_stats.discipline_or_evasion * (1.0f + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::land_organisation))); auto& cstr = state.world.regiment_get_strength(att_front[i]); str_damage = std::min(str_damage, cstr); @@ -5059,10 +5062,10 @@ void update_land_battles(sys::state& state) { auto tech_def_nation = tech_nation_for_regiment(state, att_front_target); auto& def_stats = state.world.nation_get_unit_stats(tech_def_nation, state.world.regiment_get_type(att_front_target)); - auto str_damage = + auto str_damage = str_dam_mul * (att_stats.attack_or_gun_power * 0.1f + 1.0f) * attacker_mod / (defender_fort * (state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_def_nation, sys::national_mod_offsets::military_tactics))); - auto org_damage = + auto org_damage = org_dam_mul * (att_stats.attack_or_gun_power * 0.1f + 1.0f) * attacker_mod / (defender_fort * def_stats.discipline_or_evasion * defender_org_bonus * (1.0f + state.world.nation_get_modifier_values(tech_def_nation, sys::national_mod_offsets::land_organisation))); @@ -5109,8 +5112,8 @@ void update_land_battles(sys::state& state) { auto tech_att_nation = tech_nation_for_regiment(state, def_front_target); auto& att_stats = state.world.nation_get_unit_stats(tech_att_nation, state.world.regiment_get_type(def_front_target)); - auto str_damage = (def_stats.attack_or_gun_power * 0.1f + 1.0f) * defender_mod / ((state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::military_tactics))); - auto org_damage = (def_stats.attack_or_gun_power * 0.1f + 1.0f) * defender_mod / (attacker_org_bonus * def_stats.discipline_or_evasion * (1.0f + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::land_organisation))); + auto str_damage = str_dam_mul * (def_stats.attack_or_gun_power * 0.1f + 1.0f) * defender_mod / ((state.defines.base_military_tactics + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::military_tactics))); + auto org_damage = org_dam_mul * (def_stats.attack_or_gun_power * 0.1f + 1.0f) * defender_mod / (attacker_org_bonus * def_stats.discipline_or_evasion * (1.0f + state.world.nation_get_modifier_values(tech_att_nation, sys::national_mod_offsets::land_organisation))); auto& cstr = state.world.regiment_get_strength(def_front_target); str_damage = std::min(str_damage, cstr); @@ -5507,12 +5510,12 @@ void update_naval_battles(sys::state& state) { define:NAVAL_COMBAT_DAMAGE_MULT_NO_ORG (if target has no org) / (target-max-hull x target-experience x 0.1 + 1) */ - float org_damage = (ship_stats.attack_or_gun_power + (target_is_big ? ship_stats.siege_or_torpedo_attack : 0.0f)) * + float org_damage = org_dam_mul * (ship_stats.attack_or_gun_power + (target_is_big ? ship_stats.siege_or_torpedo_attack : 0.0f)) * (is_attacker ? attacker_mod : defender_mod) * state.defines.naval_combat_damage_org_mult / ((ship_target_stats.defence_or_hull + 1.0f) * (is_attacker ? defender_org_bonus : attacker_org_bonus) * (1.0f + state.world.nation_get_modifier_values(ship_target_owner, sys::national_mod_offsets::naval_organisation))); - float str_damage = (ship_stats.attack_or_gun_power + (target_is_big ? ship_stats.siege_or_torpedo_attack : 0.0f)) * + float str_damage = str_dam_mul * (ship_stats.attack_or_gun_power + (target_is_big ? ship_stats.siege_or_torpedo_attack : 0.0f)) * (is_attacker ? attacker_mod : defender_mod) * state.defines.naval_combat_damage_str_mult / (ship_target_stats.defence_or_hull + 1.0f); @@ -5990,6 +5993,8 @@ int32_t free_transport_capacity(sys::state& state, dcon::navy_id n) { return transport_capacity(state, n) - used_total; } +constexpr inline float siege_speed_mul = 0.5f; + void update_siege_progress(sys::state& state) { concurrency::parallel_for(0, state.province_definitions.first_sea_province.index(), [&](int32_t id) { dcon::province_id prov{dcon::province_id::value_base_t(id)}; @@ -6122,7 +6127,7 @@ void update_siege_progress(sys::state& state) { (owner_involved ? 1.25f : (core_owner_involved ? 1.1f : 1.0f)) / siege_table[effective_fort_level]; auto& progress = state.world.province_get_siege_progress(prov); - progress += added_progress; + progress += siege_speed_mul * added_progress; if(progress >= 1.0f) { progress = 0.0f; diff --git a/src/parsing/parsers_declarations.cpp b/src/parsing/parsers_declarations.cpp index 267504fb2..32654b408 100644 --- a/src/parsing/parsers_declarations.cpp +++ b/src/parsing/parsers_declarations.cpp @@ -2464,10 +2464,8 @@ void foreign_investment_block::any_value(std::string_view tag, association_type, } } -void country_history_file::set_country_flag(association_type, std::string_view value, error_handler& err, int32_t line, - country_history_context& context) { - if(auto it = context.outer_context.map_of_national_flags.find(std::string(value)); - it != context.outer_context.map_of_national_flags.end()) { +void country_history_file::set_country_flag(association_type, std::string_view value, error_handler& err, int32_t line, country_history_context& context) { + if(auto it = context.outer_context.map_of_national_flags.find(std::string(value)); it != context.outer_context.map_of_national_flags.end()) { if(context.holder_id) context.outer_context.state.world.nation_set_flag_variables(context.holder_id, it->second, true); } else { @@ -2476,8 +2474,7 @@ void country_history_file::set_country_flag(association_type, std::string_view v } void country_history_file::set_global_flag(association_type, std::string_view value, error_handler& err, int32_t line, country_history_context& context) { - if(auto it = context.outer_context.map_of_global_flags.find(std::string(value)); - it != context.outer_context.map_of_global_flags.end()) { + if(auto it = context.outer_context.map_of_global_flags.find(std::string(value)); it != context.outer_context.map_of_global_flags.end()) { if(context.holder_id) context.outer_context.state.national_definitions.set_global_flag_variable(it->second, true); } else { diff --git a/src/provinces/province.hpp b/src/provinces/province.hpp index 5136f70d2..d89b6dc42 100644 --- a/src/provinces/province.hpp +++ b/src/provinces/province.hpp @@ -4,7 +4,7 @@ namespace province { -inline constexpr float world_circumference = 40075.0f / 12.0f; // in arbitrary units +inline constexpr float world_circumference = 40075.0f / 10.0f; // in arbitrary units inline constexpr uint16_t to_map_id(dcon::province_id id) { return uint16_t(id.index() + 1); diff --git a/src/scripting/events.cpp b/src/scripting/events.cpp index 5351cebe8..f4021cf63 100644 --- a/src/scripting/events.cpp +++ b/src/scripting/events.cpp @@ -324,7 +324,7 @@ void update_events(sys::state& state) { [&](dcon::nation_id n, float c, bool condition) { auto owned_range = state.world.nation_get_province_ownership(n); if(condition && owned_range.begin() != owned_range.end()) { - if(float(rng::get_random(state, uint32_t((i << 1) ^ n.index())) & 0xFFFF) / float(0xFFFF + 1) >= c) { + if(float(rng::get_random(state, uint32_t((i << 1) ^ n.index())) & 0xFFFFFF) / float(0xFFFFFF + 1) >= c) { events_triggered.local().push_back(event_nation_pair{n, id}); } } @@ -376,7 +376,7 @@ void update_events(sys::state& state) { ve::apply( [&](dcon::province_id p, dcon::nation_id o, float c, bool condition) { if(condition) { - if(float(rng::get_random(state, uint32_t((i << 1) ^ p.index())) & 0xFFFF) / float(0xFFFF + 1) >= c) { + if(float(rng::get_random(state, uint32_t((i << 1) ^ p.index())) & 0xFFFFFF) / float(0xFFFFFF + 1) >= c) { p_events_triggered.local().push_back(event_prov_pair{p, id}); } }