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 assets/alice.gui
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ guiTypes = {

windowType = {
name = "show_all_saves_setting_container"
extends = "lobby"
position = { 0 -410 }
extends = "playable_countries_window"
position = { 0 590 }
size = { 212 32 }
Orientation = "LOWER_LEFT"
Orientation = "UPPER_LEFT"

iconType = {
name = "background"
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ float estimate_win_probability(sys::state& state, std::vector<dcon::army_id> con
if(!candidate) {
continue;
}
auto score = military::get_leader_select_score(state, candidate, true);
auto score = military::get_leader_battle_select_score(state, candidate, true);
if(score > a_score) {
a_lid = candidate;
a_score = score;
Expand All @@ -1574,7 +1574,7 @@ float estimate_win_probability(sys::state& state, std::vector<dcon::army_id> con
if(!candidate) {
continue;
}
auto score = military::get_leader_select_score(state, candidate, false);
auto score = military::get_leader_battle_select_score(state, candidate, false);
if(score > d_score) {
d_lid = candidate;
d_score = score;
Expand Down
42 changes: 21 additions & 21 deletions src/gamestate/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,31 +688,33 @@ bool can_begin_factory_building_construction(sys::state& state, dcon::nation_id

// If Foreign target
if(owner != source) {
return false; // Foreign investment is disabled temporarily due to the ownership model/logistics not supporting it at the moment

/*
For foreign investment: the target nation must allow foreign investment, the nation doing the investing must be a great
power while the target is not a great power, and the nation doing the investing must not be at war with the target nation.
The nation being invested in must be civilized.
Overlord can invest in its subjects ignoring GP and owner's rules.
*/
auto rel = state.world.nation_get_overlord_as_subject(owner);
auto overlord = state.world.overlord_get_ruler(rel);
if(overlord != source) {
if(state.world.nation_get_is_great_power(source) == false || state.world.nation_get_is_great_power(owner) == true)
return false;
auto rules = state.world.nation_get_combined_issue_rules(owner);
if((rules & issue_rule::allow_foreign_investment) == 0)
return false;
}
if(state.world.nation_get_is_civilized(owner) == false)
return false;

if(military::are_at_war(state, source, owner))
return false;

// Refit in foreign countries is not allowed
if(refit_target) {
return false;
}
//auto rel = state.world.nation_get_overlord_as_subject(owner);
//auto overlord = state.world.overlord_get_ruler(rel);
//if(overlord != source) {
// if(state.world.nation_get_is_great_power(source) == false || state.world.nation_get_is_great_power(owner) == true)
// return false;
// auto rules = state.world.nation_get_combined_issue_rules(owner);
// if((rules & issue_rule::allow_foreign_investment) == 0)
// return false;
//}
//if(state.world.nation_get_is_civilized(owner) == false)
// return false;

//if(military::are_at_war(state, source, owner))
// return false;

//// Refit in foreign countries is not allowed
//if(refit_target) {
// return false;
//}
}
// Else Internal target
else {
Expand Down Expand Up @@ -6311,8 +6313,6 @@ void execute_notify_start_game(sys::state& state, dcon::nation_id source) {
state.game_state_resetting_cv.notify_all();

state.ui_state.invoke_on_ui_thread([](sys::state& state, ui::ui_function_argument) {
state.selected_armies.clear();
state.selected_navies.clear();
state.set_selected_province(dcon::province_id{});
for(auto& v : state.ctrl_armies) v.clear();
for(auto& v : state.ctrl_navies) v.clear();
Expand Down
62 changes: 55 additions & 7 deletions src/gamestate/game_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "immediate_mode.hpp"
#include "commands.hpp"


namespace game_scene {

void highlight_given_state(sys::state& state, std::vector<uint32_t>& data, dcon::province_id selected_province);
Expand Down Expand Up @@ -93,7 +94,8 @@ void switch_scene(sys::state& state, scene_id ui_scene) {
.lbutton_up = do_nothing,
.on_province_selected = select_production_state,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = production_screen_hotkeys,
.handle_hotkeys_key_down = production_screen_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,
.render_ui = render_unitless_ui_ingame,
.recalculate_mouse_probe = recalculate_mouse_probe_unitless,
Expand Down Expand Up @@ -413,11 +415,19 @@ void on_lbutton_up_ui_click_hold_and_release(sys::state& state, int32_t x, int32
}
}
}
void deselect_armies(sys::state& state) {
state.selected_armies.clear();
state.ui_state.pending_shift_selected_armies.clear();
}
void deselect_navies(sys::state& state) {
state.selected_navies.clear();
state.ui_state.pending_shift_selected_navies.clear();
}

// Should be called only from the UI thread
void deselect_units(sys::state& state) {
state.selected_armies.clear();
state.selected_navies.clear();
deselect_armies(state);
deselect_navies(state);
}

bool province_mid_point_is_in_selection(sys::state& state, int32_t x, int32_t y, dcon::province_id province) {
Expand Down Expand Up @@ -566,7 +576,6 @@ void handle_drag_stop(sys::state& state, int32_t x, int32_t y, sys::key_modifier
state.drag_selecting = false;
window::change_cursor(state, window::cursor_type::normal);
send_selected_province_to_province_window(state);
deselect_units(state);
state.game_state_updated.store(true, std::memory_order_release);
} else {
// stop dragging and select units
Expand Down Expand Up @@ -851,6 +860,25 @@ void in_game_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modif
}
}

void in_game_hotkeys_key_up(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod) {
if(sys::is_shift(keycode)) {
if(!state.ui_state.pending_shift_selected_armies.empty()) {
state.selected_armies.clear();
for(auto army : state.ui_state.pending_shift_selected_armies) {
state.select(army);
}
state.ui_state.pending_shift_selected_armies.clear();
}
else if(!state.ui_state.pending_shift_selected_navies.empty()) {
state.selected_navies.clear();
for(auto navy : state.ui_state.pending_shift_selected_navies) {
state.select(navy);
}
state.ui_state.pending_shift_selected_navies.clear();
}
}
}

void do_nothing_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod) {
return;
}
Expand All @@ -861,10 +889,18 @@ void on_key_down(sys::state& state, sys::virtual_key keycode, sys::key_modifiers
state.ui_state.edit_target_internal->impl_on_key_down(state, keycode, mod);
} else {
keycode = replace_keycodes(state, keycode, mod);
state.current_scene.handle_hotkeys(state, keycode, mod);
state.current_scene.handle_hotkeys_key_down(state, keycode, mod);
}
}

void on_key_up(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod) {
state.map_state.on_key_up(keycode, mod);
// No need for on_key_up for regular up elements for now. If it becomes nessecary, add it here and in the base ui classes
keycode = replace_keycodes(state, keycode, mod);
state.current_scene.handle_hotkeys_key_up(state, keycode, mod);

}

void console_log_other(sys::state& state, std::string_view message) {
auto msg = std::string(message);
auto dt = state.current_date.to_ymd(state.start_date);
Expand Down Expand Up @@ -1173,11 +1209,11 @@ void clean_up_selected_armies_and_navies(sys::state& state) {
// Allow player to select single enemy army or enemy navy to view them
if(state.selected_armies.size() == 1) {
if(!state.world.army_is_valid(state.selected_armies[0])) {
state.selected_armies.clear();
deselect_armies(state);
}
} else if(state.selected_navies.size() == 1) {
if(!state.world.navy_is_valid(state.selected_navies[0])) {
state.selected_navies.clear();
deselect_navies(state);
}
} else {
for(auto i = state.selected_armies.size(); i-- > 0; ) {
Expand All @@ -1186,12 +1222,24 @@ void clean_up_selected_armies_and_navies(sys::state& state) {
state.selected_armies.pop_back();
}
}
for(auto i = state.ui_state.pending_shift_selected_armies.size(); i-- > 0; ) {
if(!state.world.army_is_valid(state.ui_state.pending_shift_selected_armies[i]) || military::get_effective_unit_commander(state, state.ui_state.pending_shift_selected_armies[i]) != state.local_player_nation) {
state.ui_state.pending_shift_selected_armies[i] = state.ui_state.pending_shift_selected_armies.back();
state.ui_state.pending_shift_selected_armies.pop_back();
}
}
for(auto i = state.selected_navies.size(); i-- > 0; ) {
if(!state.world.navy_is_valid(state.selected_navies[i]) || military::get_effective_unit_commander(state, state.selected_navies[i]) != state.local_player_nation) {
state.selected_navies[i] = state.selected_navies.back();
state.selected_navies.pop_back();
}
}
for(auto i = state.ui_state.pending_shift_selected_navies.size(); i-- > 0; ) {
if(!state.world.navy_is_valid(state.ui_state.pending_shift_selected_navies[i]) || military::get_effective_unit_commander(state, state.ui_state.pending_shift_selected_navies[i]) != state.local_player_nation) {
state.ui_state.pending_shift_selected_navies[i] = state.ui_state.pending_shift_selected_navies.back();
state.ui_state.pending_shift_selected_navies.pop_back();
}
}
}
}

Expand Down
31 changes: 23 additions & 8 deletions src/gamestate/game_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ void on_rbutton_down(sys::state& state, int32_t x, int32_t y, sys::key_modifiers
void on_lbutton_down(sys::state& state, int32_t x, int32_t y, sys::key_modifiers mod);
void on_lbutton_up(sys::state& state, int32_t x, int32_t y, sys::key_modifiers mod);

void deselect_armies(sys::state& state);
void deselect_navies(sys::state& state);

void deselect_units(sys::state& state);

void switch_scene(sys::state& state, scene_id ui_scene);

void selected_units_control(
Expand Down Expand Up @@ -48,6 +53,7 @@ sys::virtual_key replace_keycodes_identity(sys::state& state, sys::virtual_key k
void nation_picker_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void do_nothing_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void in_game_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void in_game_hotkeys_key_up(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void military_screen_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void state_selector_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void nation_identity_selector_hotkeys(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
Expand All @@ -63,6 +69,7 @@ void render_ui_selection_screen(sys::state& state);


void on_key_down(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);
void on_key_up(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod);

ui::mouse_probe recalculate_mouse_probe_basic(sys::state& state, ui::mouse_probe mouse_probe, ui::mouse_probe tooltip_probe);
ui::mouse_probe recalculate_tooltip_probe_basic(sys::state& state, ui::mouse_probe mouse_probe, ui::mouse_probe tooltip_probe);
Expand Down Expand Up @@ -120,7 +127,8 @@ inline scene_properties nation_picker() {
.lbutton_up = do_nothing,
.on_province_selected = select_player_nation_from_selected_province,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = nation_picker_hotkeys,
.handle_hotkeys_key_down = nation_picker_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,
.open_chat = open_chat_before_game,
.update_highlight_texture = highlight_player_nation,
Expand All @@ -143,7 +151,8 @@ inline scene_properties basic_game() {
.lbutton_up = do_nothing,
.on_province_selected = do_nothing,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = in_game_hotkeys,
.handle_hotkeys_key_down = in_game_hotkeys,
.handle_hotkeys_key_up = in_game_hotkeys_key_up,
.console_log = console_log_other,

.render_ui = render_ui_ingame,
Expand All @@ -170,7 +179,8 @@ inline scene_properties battleplan_editor() { return scene_properties{
.lbutton_up = military_screen_on_lbutton_up,
.on_province_selected = do_nothing,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = military_screen_hotkeys,
.handle_hotkeys_key_down = military_screen_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,

.render_ui = render_ui_military,
Expand All @@ -196,7 +206,8 @@ inline scene_properties battleplan_editor_add_army() {
.lbutton_up = do_nothing,
.on_province_selected = do_nothing,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = military_screen_hotkeys,
.handle_hotkeys_key_down = military_screen_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,

.render_ui = render_ui_selection_screen,
Expand Down Expand Up @@ -224,7 +235,8 @@ inline scene_properties economy_viewer_scene() {
.lbutton_up = do_nothing,
.on_province_selected = do_nothing,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = economy_screen_hotkeys,
.handle_hotkeys_key_down = economy_screen_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,

.render_ui = economy_viewer::render,
Expand All @@ -251,7 +263,8 @@ inline scene_properties state_wargoal_selector() {
.lbutton_up = do_nothing,
.on_province_selected = select_wargoal_state_from_selected_province,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = state_selector_hotkeys,
.handle_hotkeys_key_down = state_selector_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other
};
}
Expand All @@ -272,7 +285,8 @@ inline scene_properties national_identity_selector() {
.lbutton_up = do_nothing,
.on_province_selected = select_national_identity_from_selected_province,
.keycode_mapping = replace_keycodes_map_movement,
.handle_hotkeys = nation_identity_selector_hotkeys,
.handle_hotkeys_key_down = nation_identity_selector_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other
};
}
Expand All @@ -296,7 +310,8 @@ inline scene_properties end_screen() {
.lbutton_up = do_nothing,
.on_province_selected = do_nothing,
.keycode_mapping = replace_keycodes_identity,
.handle_hotkeys = do_nothing_hotkeys,
.handle_hotkeys_key_down = do_nothing_hotkeys,
.handle_hotkeys_key_up = do_nothing_hotkeys,
.console_log = console_log_other,

.render_map = do_nothing,
Expand Down
3 changes: 2 additions & 1 deletion src/gamestate/game_scene_default.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct scene_properties {

//key presses related
std::function <sys::virtual_key(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod)> keycode_mapping;
std::function <void(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod)> handle_hotkeys;
std::function <void(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod)> handle_hotkeys_key_down;
std::function <void(sys::state& state, sys::virtual_key keycode, sys::key_modifiers mod)> handle_hotkeys_key_up;

//logger
std::function <void(sys::state& state, std::string_view message)> console_log;
Expand Down
Loading
Loading