Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle core (on/off) command for a specific TAG #1244

Merged
merged 3 commits into from
Apr 7, 2024
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
28 changes: 25 additions & 3 deletions src/gamestate/cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ void c_change_owner(sys::state& state, dcon::nation_id source, dcon::province_id
p.data.cheat_location.n = new_owner;
add_to_command_queue(state, p);
}
void execute_c_change_owner(sys::state& state, dcon::nation_id source, dcon::province_id pr, dcon::nation_id new_owner) {
province::change_province_owner(state, pr, new_owner);
}

void c_change_controller(sys::state& state, dcon::nation_id source, dcon::province_id pr, dcon::nation_id new_controller) {
payload p;
memset(&p, 0, sizeof(payload));
Expand All @@ -296,13 +300,11 @@ void c_change_controller(sys::state& state, dcon::nation_id source, dcon::provin
p.data.cheat_location.n = new_controller;
add_to_command_queue(state, p);
}
void execute_c_change_owner(sys::state& state, dcon::nation_id source, dcon::province_id pr, dcon::nation_id new_owner) {
province::change_province_owner(state, pr, new_owner);
}
void execute_c_change_controller(sys::state& state, dcon::nation_id source, dcon::province_id pr, dcon::nation_id new_controller) {
province::set_province_controller(state, pr, new_controller);
military::eject_ships(state, pr);
}

void c_instant_research(sys::state& state, dcon::nation_id source) {
payload p;
memset(&p, 0, sizeof(payload));
Expand Down Expand Up @@ -379,4 +381,24 @@ void execute_c_innovate(sys::state& state, dcon::nation_id source, dcon::inventi
culture::apply_invention(state, source, invention);
}

void c_toggle_core(sys::state& state, dcon::nation_id source, dcon::province_id pr, dcon::nation_id n) {
payload p;
memset(&p, 0, sizeof(payload));
p.type = command_type::c_toggle_core;
p.source = source;
p.data.cheat_location.prov = pr;
p.data.cheat_location.n = n;
add_to_command_queue(state, p);
}
void execute_c_toggle_core(sys::state& state, dcon::nation_id source, dcon::province_id p, dcon::nation_id n) {
auto const nid = state.world.nation_get_identity_from_identity_holder(n);
for(const auto a : state.world.province_get_core(p)) {
if(a.get_identity() == nid) {
province::remove_core(state, p, nid);
return; //early exit
}
}
province::add_core(state, p, nid);
}

}
1 change: 1 addition & 0 deletions src/gamestate/cheats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ void c_add_population(sys::state& state, dcon::nation_id source, int32_t ammount
void c_instant_army(sys::state& state, dcon::nation_id source);
void c_instant_industry(sys::state& state, dcon::nation_id source);
void c_innovate(sys::state& state, dcon::nation_id source, dcon::invention_id invention);
void c_toggle_core(sys::state& state, dcon::nation_id source, dcon::province_id p, dcon::nation_id n);
} // namespace command
5 changes: 5 additions & 0 deletions src/gamestate/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5016,6 +5016,7 @@ bool can_perform_command(sys::state& state, payload& c) {
case command_type::c_instant_army:
case command_type::c_instant_industry:
case command_type::c_innovate:
case command_type::c_toggle_core:
return true;
}
return false;
Expand Down Expand Up @@ -5446,6 +5447,10 @@ void execute_command(sys::state& state, payload& c) {
break;
case command_type::c_innovate:
execute_c_innovate(state, c.source, c.data.cheat_invention_data.invention);
break;
case command_type::c_toggle_core:
execute_c_toggle_core(state, c.source, c.data.cheat_location.prov, c.data.cheat_location.n);
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/gamestate/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ enum class command_type : uint8_t {
c_instant_army = 149,
c_instant_industry = 150,
c_innovate = 151,
c_toggle_core = 152,
};

struct national_focus_data {
Expand Down
15 changes: 15 additions & 0 deletions src/gui/gui_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct command_info {
change_owner,
change_control,
change_control_and_owner,
toggle_core,
province_id_tooltip,
wasd,
next_song,
Expand Down Expand Up @@ -212,6 +213,9 @@ inline constexpr command_info possible_commands[] = {
command_info{ "doos", command_info::type::daily_oos_check, "Toggle daily OOS check",
{command_info::argument_info{}, command_info::argument_info{},
command_info::argument_info{}, command_info::argument_info{}} },
command_info{ "tcore", command_info::type::toggle_core, "Toggle add/remove core",
{command_info::argument_info{"province", command_info::argument_info::type::numeric, false}, command_info::argument_info{"country", command_info::argument_info::type::tag, true},
command_info::argument_info{}, command_info::argument_info{}} },
command_info{ "innovate", command_info::type::innovate, "Instantly discovers an innovation. Just use the normal innovation's name with '_' instead of spaces.",
{command_info::argument_info{"innovation", command_info::argument_info::type::text }, command_info::argument_info{ },
command_info::argument_info{}, command_info::argument_info{}} },
Expand Down Expand Up @@ -1528,6 +1532,17 @@ void ui::console_edit::edit_box_enter(sys::state& state, std::string_view s) noe
}
break;
}
case command_info::type::toggle_core:
{
auto province_id = dcon::province_id((uint16_t)std::get<std::int32_t>(pstate.arg_slots[0]));
auto nid = state.world.nation_get_identity_from_identity_holder(state.local_player_nation);
if(std::holds_alternative<std::string>(pstate.arg_slots[1])) {
auto tag = std::get<std::string>(pstate.arg_slots[1]);
nid = smart_get_national_identity_from_tag(state, parent, tag);
}
command::c_toggle_core(state, state.local_player_nation, province_id, state.world.national_identity_get_nation_from_identity_holder(nid));
break;
}
case command_info::type::change_control_and_owner:
{
auto province_id = dcon::province_id((uint16_t)std::get<std::int32_t>(pstate.arg_slots[0]));
Expand Down
Loading