Skip to content

Commit

Permalink
tweaks for alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
schombert committed Sep 22, 2023
1 parent 2601ee0 commit 8969630
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<CONFIG:Debug>: /EHsc /MTd /RTC1 /Od>
$<$<CONFIG:Debug>: /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
$<$<NOT:$<CONFIG:Debug>>: /DNDEBUG /wd4530 /MT /O2 /Oi /GL /sdl- /GS- /Gy /Gw /Zc:preprocessor /Zc:inline>)
target_link_options(AliceCommon INTERFACE
Expand Down
15 changes: 5 additions & 10 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/economy/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/gui/gui_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ message_result national_event_window<IsMajor>::get(sys::state& state, Cyto::Any&
return message_result::consumed;
} else if(payload.holds_type<option_taken_notification>()) {
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;
Expand Down Expand Up @@ -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<option_taken_notification>()) {
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;
Expand Down
26 changes: 9 additions & 17 deletions src/gui/gui_topbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1517,29 +1517,21 @@ class topbar_colony_icon : public standard_nation_button {
auto nation_id = any_cast<dcon::nation_id>(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);

}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/launcher/launcher_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 16 additions & 11 deletions src/military/military.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)};
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/parsing/parsers_declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/provinces/province.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/scripting/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}
Expand Down Expand Up @@ -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});
}
}
Expand Down

0 comments on commit 8969630

Please sign in to comment.