Skip to content

Commit 6fe5fa9

Browse files
authored
Merge pull request #1995 from ZombieFreak115/mp_player_network_refactor
MP player network refactor, support co-op, and some minor military changes
2 parents 882d478 + ff184ff commit 6fe5fa9

27 files changed

+905
-478
lines changed

assets/alice.gui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
guiTypes = {
2+
guiButtonType = {
3+
name = "observer_button"
4+
extends = "lobby"
5+
position = { x = 17 y = -200 }
6+
quadTextureSprite ="GFX_frontend_play_button"
7+
buttonText = "alice_observer_btn_text"
8+
buttonFont = "vic_32_black"
9+
Orientation = "LOWER_LEFT"
10+
}
11+
212
iconType = {
313
name = "gfx_storage_unit_types"
414
spriteType = "GFX_unit_strip"

assets/localisation/en-US/alice.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ disband_all;Disband all selected units
10431043
alice_play_checksum_host;Checksum mismatch with host, ensure you have the same mods and savefiles
10441044
alice_play_save_stream;Host is streaming a save to you, wait until it completes
10451045
alice_no_start_game_player_loading;Cannot start the game while players are loading
1046+
alice_no_start_game_invalid_nations;Cannot start the game while players are on non-existant nations
10461047
ai_will_accept_po;They will accept this offer
10471048
ai_will_not_accept_po;They will NOT accept this offer
10481049
close_and_del;Close & Delete Factory
@@ -1564,6 +1565,8 @@ alice_host_has_resync;Host has resynced the lobby
15641565
alice_naval_coordination_penalty;The $x$ are receiving a naval coordination penalty of ?R$y$?W from outnumbering their enemy, which reduces their target selection by ?R$val$?W
15651566
alice_naval_coordination_bonus;The $x$ are receiving a naval coordination bonus of ?G$y$?W from being outnumbered, which increases their target selection by ?G$val$?W
15661567
alice_naval_stacking_penalty;The $x$ are receiving a damage multiplier of ?R$y$?W from stacking penalties.
1568+
alice_observer_btn_text;Play as observer
1569+
alice_observer_already_observer_tooltip;You are already on the observer tag.
15671570
alice_labor_no_education;Unskilled
15681571
alice_labor_basic_education;Skilled
15691572
alice_labor_high_education;Expert

assets/localisation/en-US/mapmodes.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ mapmode_tooltip_34;Player: $x$
9595
mapmode_tooltip_34_you_sp;This is you!
9696
mapmode_tooltip_34_you;Player: $x$ (This is you!)
9797
mapmode_tooltip_34_ai;AI controlled
98+
mapmode_tooltip_34_no_ai;Not AI controlled
9899
mapmode_tooltip_35;Life needs satisfied: $x$
99100
mapmode_tooltip_36;Everyday needs satisfied: $x$
100101
mapmode_tooltip_37;Luxury needs satisfied: $x$

src/common_types/container_types.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ struct player_value {
302302
return *this;
303303
}
304304

305+
bool is_equal(player_value<_Size> other) {
306+
return other.data == data;
307+
}
308+
305309
std::string to_string() noexcept {
306310
return std::string(to_string_view());
307311
}

src/gamestate/commands.cpp

Lines changed: 201 additions & 149 deletions
Large diffs are not rendered by default.

src/gamestate/commands.hpp

Lines changed: 137 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -34,105 +34,106 @@ enum class command_type : uint8_t {
3434
add_to_sphere = 24,
3535
remove_from_sphere = 25,
3636
upgrade_colony_to_state = 26,
37-
invest_in_colony = 27,
38-
abandon_colony = 28,
39-
finish_colonization = 29,
40-
intervene_in_war = 30,
41-
suppress_movement = 31,
42-
civilize_nation = 32,
43-
appoint_ruling_party = 33,
44-
change_issue_option = 34,
45-
change_reform_option = 35,
46-
become_interested_in_crisis = 36,
47-
take_sides_in_crisis = 37,
48-
begin_land_unit_construction = 38,
49-
cancel_land_unit_construction = 39,
50-
change_stockpile_settings = 40,
51-
take_decision = 41,
52-
make_n_event_choice = 42,
53-
make_f_n_event_choice = 43,
54-
make_p_event_choice = 44,
55-
make_f_p_event_choice = 45,
56-
fabricate_cb = 46,
57-
cancel_cb_fabrication = 47,
58-
ask_for_military_access = 48,
59-
ask_for_alliance = 49,
60-
call_to_arms = 50,
61-
respond_to_diplomatic_message = 51,
62-
cancel_military_access = 52,
63-
cancel_alliance = 53,
64-
cancel_given_military_access = 54,
65-
declare_war = 55,
66-
add_war_goal = 56,
67-
start_peace_offer = 58,
68-
add_peace_offer_term = 59,
69-
send_peace_offer = 60,
70-
move_army = 61,
71-
move_navy = 62,
72-
embark_army = 63,
73-
merge_armies = 64,
74-
merge_navies = 65,
75-
split_army = 66,
76-
split_navy = 67,
77-
delete_army = 68,
78-
delete_navy = 69,
79-
designate_split_regiments = 70,
80-
designate_split_ships = 71,
81-
naval_retreat = 72,
82-
land_retreat = 73,
83-
start_crisis_peace_offer = 74,
84-
invite_to_crisis = 75,
85-
add_wargoal_to_crisis_offer = 76,
86-
send_crisis_peace_offer = 77,
87-
change_admiral = 78,
88-
change_general = 79,
89-
toggle_mobilization = 80,
90-
give_military_access = 81,
91-
set_rally_point = 82,
92-
save_game = 83,
93-
cancel_factory_building_construction = 84,
94-
disband_undermanned = 85,
95-
even_split_army = 86,
96-
even_split_navy = 87,
97-
toggle_hunt_rebels = 88,
98-
toggle_select_province = 89,
99-
toggle_immigrator_province = 90,
100-
state_transfer = 91,
101-
release_subject = 92,
102-
enable_debt = 93,
103-
move_capital = 94,
104-
toggle_unit_ai_control = 95,
105-
toggle_mobilized_is_ai_controlled = 96,
106-
toggle_interested_in_alliance = 97,
107-
pbutton_script = 98,
108-
nbutton_script = 99,
109-
set_factory_type_priority = 100,
110-
crisis_add_wargoal = 101,
111-
change_unit_type = 102,
112-
take_province = 103,
113-
grant_province = 104,
114-
ask_for_free_trade_agreement = 105,
115-
switch_embargo_status = 106,
116-
revoke_trade_rights = 107,
117-
toggle_local_administration = 108,
118-
119-
// network
120-
notify_player_ban = 110,
121-
notify_player_kick = 111,
122-
notify_player_picks_nation = 112,
123-
notify_player_joins = 113,
124-
notify_player_leaves = 114,
125-
notify_player_oos = 115,
126-
notify_save_loaded = 116,
127-
notify_start_game = 117, // for synchronized "start game"
128-
notify_stop_game = 118, // "go back to lobby"
129-
notify_pause_game = 119, // visual aid mostly
130-
notify_reload = 120,
131-
advance_tick = 121,
132-
chat_message = 122,
133-
network_inactivity_ping = 123,
134-
notify_player_fully_loaded = 124, // client sends this to the host to notify that they are fully loaded in, and host transmits it to all clients
135-
notify_player_is_loading = 125, // host sends this to all clients to notify that a specific client has begun loading
37+
invest_in_colony = 27,
38+
abandon_colony = 28,
39+
finish_colonization = 29,
40+
intervene_in_war = 30,
41+
suppress_movement = 31,
42+
civilize_nation = 32,
43+
appoint_ruling_party = 33,
44+
change_issue_option = 34,
45+
change_reform_option = 35,
46+
become_interested_in_crisis = 36,
47+
take_sides_in_crisis = 37,
48+
begin_land_unit_construction = 38,
49+
cancel_land_unit_construction = 39,
50+
change_stockpile_settings = 40,
51+
take_decision = 41,
52+
make_n_event_choice = 42,
53+
make_f_n_event_choice = 43,
54+
make_p_event_choice = 44,
55+
make_f_p_event_choice = 45,
56+
fabricate_cb = 46,
57+
cancel_cb_fabrication = 47,
58+
ask_for_military_access = 48,
59+
ask_for_alliance = 49,
60+
call_to_arms = 50,
61+
respond_to_diplomatic_message = 51,
62+
cancel_military_access = 52,
63+
cancel_alliance = 53,
64+
cancel_given_military_access = 54,
65+
declare_war = 55,
66+
add_war_goal = 56,
67+
start_peace_offer = 58,
68+
add_peace_offer_term = 59,
69+
send_peace_offer = 60,
70+
move_army = 61,
71+
move_navy = 62,
72+
embark_army = 63,
73+
merge_armies = 64,
74+
merge_navies = 65,
75+
split_army = 66,
76+
split_navy = 67,
77+
delete_army = 68,
78+
delete_navy = 69,
79+
designate_split_regiments = 70,
80+
designate_split_ships = 71,
81+
naval_retreat = 72,
82+
land_retreat = 73,
83+
start_crisis_peace_offer = 74,
84+
invite_to_crisis = 75,
85+
add_wargoal_to_crisis_offer = 76,
86+
send_crisis_peace_offer = 77,
87+
change_admiral = 78,
88+
change_general = 79,
89+
toggle_mobilization = 80,
90+
give_military_access = 81,
91+
set_rally_point = 82,
92+
save_game = 83,
93+
cancel_factory_building_construction = 84,
94+
disband_undermanned = 85,
95+
even_split_army = 86,
96+
even_split_navy = 87,
97+
toggle_hunt_rebels = 88,
98+
toggle_select_province = 89,
99+
toggle_immigrator_province = 90,
100+
state_transfer = 91,
101+
release_subject = 92,
102+
enable_debt = 93,
103+
move_capital = 94,
104+
toggle_unit_ai_control = 95,
105+
toggle_mobilized_is_ai_controlled = 96,
106+
toggle_interested_in_alliance = 97,
107+
pbutton_script = 98,
108+
nbutton_script = 99,
109+
set_factory_type_priority = 100,
110+
crisis_add_wargoal = 101,
111+
change_unit_type = 102,
112+
take_province = 103,
113+
grant_province = 104,
114+
ask_for_free_trade_agreement = 105,
115+
switch_embargo_status = 106,
116+
revoke_trade_rights = 107,
117+
toggle_local_administration = 108,
118+
119+
// network
120+
notify_player_ban = 110,
121+
notify_player_kick = 111,
122+
notify_player_picks_nation = 112,
123+
notify_player_joins = 113,
124+
notify_player_leaves = 114,
125+
notify_player_oos = 115,
126+
notify_save_loaded = 116,
127+
notify_start_game = 117, // for synchronized "start game"
128+
notify_stop_game = 118, // "go back to lobby"
129+
notify_pause_game = 119, // visual aid mostly
130+
notify_reload = 120,
131+
advance_tick = 121,
132+
chat_message = 122,
133+
network_inactivity_ping = 123,
134+
notify_player_fully_loaded = 124, // client sends this to the host to notify that they are fully loaded in, and host transmits it to all clients
135+
notify_player_is_loading = 125, // host sends this to all clients to notify that a specific client has begun loading
136+
change_ai_nation_state = 126, // host sends this to new clients to inform them of no-ai nations, which arent players.
136137

137138
// console cheats
138139
network_populate = 254,
@@ -209,6 +210,7 @@ struct factory_data {
209210

210211
struct tag_target_data {
211212
dcon::national_identity_id ident;
213+
sys::player_name player_name;
212214
};
213215

214216
struct influence_action_data {
@@ -457,10 +459,12 @@ struct set_factory_priority_data {
457459
struct chat_message_data {
458460
char body[ui::max_chat_message_len];
459461
dcon::nation_id target;
462+
sys::player_name sender;
460463
};
461464

462465
struct nation_pick_data {
463466
dcon::nation_id target;
467+
sys::player_name player_name;
464468
};
465469

466470
struct advance_tick_data {
@@ -484,13 +488,28 @@ struct notify_reload_data {
484488
};
485489
struct notify_leaves_data {
486490
bool make_ai;
491+
sys::player_name player_name;
487492
};
488493
struct notify_player_fully_loaded_data {
489494
sys::player_name name;
490495
};
491496
struct notify_player_is_loading_data {
492497
sys::player_name name;
493498
};
499+
struct notify_player_ban_data {
500+
bool make_ai;
501+
sys::player_name player_name;
502+
};
503+
struct notify_player_kick_data {
504+
bool make_ai;
505+
sys::player_name player_name;
506+
};
507+
struct notify_player_oos_data {
508+
sys::player_name player_name;
509+
};
510+
struct change_ai_nation_state_data {
511+
bool no_ai;
512+
};
494513

495514
struct payload {
496515
union dtype {
@@ -559,6 +578,10 @@ struct payload {
559578
pbutton_data pbutton;
560579
cheat_invention_data_t cheat_invention_data;
561580
set_factory_priority_data set_factory_priority;
581+
notify_player_ban_data notify_player_ban;
582+
notify_player_kick_data notify_player_kick;
583+
notify_player_oos_data notify_player_oos;
584+
change_ai_nation_state_data change_ai_nation_state;
562585

563586
dtype() { }
564587
} data;
@@ -621,8 +644,8 @@ bool can_change_factory_settings(sys::state& state, dcon::nation_id source, dcon
621644
void make_vassal(sys::state& state, dcon::nation_id source, dcon::national_identity_id t);
622645
bool can_make_vassal(sys::state& state, dcon::nation_id source, dcon::national_identity_id t);
623646

624-
void release_and_play_as(sys::state& state, dcon::nation_id source, dcon::national_identity_id t);
625-
bool can_release_and_play_as(sys::state& state, dcon::nation_id source, dcon::national_identity_id t);
647+
void release_and_play_as(sys::state& state, dcon::nation_id source, dcon::national_identity_id t, sys::player_name& player_name);
648+
bool can_release_and_play_as(sys::state& state, dcon::nation_id source, dcon::national_identity_id t, sys::player_name& player_name);
626649

627650
void give_war_subsidies(sys::state& state, dcon::nation_id source, dcon::nation_id target);
628651
bool can_give_war_subsidies(sys::state& state, dcon::nation_id source, dcon::nation_id target);
@@ -922,8 +945,8 @@ void toggle_immigrator_province(sys::state& state, dcon::nation_id source, dcon:
922945
bool can_toggle_immigrator_province(sys::state& state, dcon::nation_id source, dcon::province_id prov);
923946

924947
void post_chat_message(sys::state& state, ui::chat_message& m);
925-
void chat_message(sys::state& state, dcon::nation_id source, std::string_view body, dcon::nation_id target);
926-
bool can_chat_message(sys::state& state, dcon::nation_id source, std::string_view body, dcon::nation_id target);
948+
void chat_message(sys::state& state, dcon::nation_id source, std::string_view body, dcon::nation_id target, sys::player_name& sender);
949+
bool can_chat_message(sys::state& state, dcon::nation_id source, std::string_view body, dcon::nation_id target, sys::player_name& sender);
927950

928951
void release_subject(sys::state& state, dcon::nation_id source, dcon::nation_id target);
929952
bool can_release_subject(sys::state& state, dcon::nation_id source, dcon::nation_id target);
@@ -932,23 +955,25 @@ void state_transfer(sys::state& state, dcon::nation_id asker, dcon::nation_id ta
932955
bool can_state_transfer(sys::state& state, dcon::nation_id asker, dcon::nation_id target, dcon::state_definition_id sid);
933956

934957
void advance_tick(sys::state& state, dcon::nation_id source);
935-
void notify_player_ban(sys::state& state, dcon::nation_id source, dcon::nation_id target);
936-
bool can_notify_player_ban(sys::state& state, dcon::nation_id source, dcon::nation_id target);
937-
void notify_player_kick(sys::state& state, dcon::nation_id source, dcon::nation_id target);
938-
bool can_notify_player_kick(sys::state& state, dcon::nation_id source, dcon::nation_id target);
958+
void notify_player_ban(sys::state& state, dcon::nation_id source, bool make_ai, sys::player_name& name);
959+
bool can_notify_player_ban(sys::state& state, dcon::nation_id source, sys::player_name& name);
960+
void notify_player_kick(sys::state& state, dcon::nation_id source, bool make_ai, sys::player_name& name);
961+
bool can_notify_player_kick(sys::state& state, dcon::nation_id source, sys::player_name& name);
939962
void notify_player_joins(sys::state& state, dcon::nation_id source, sys::player_name& name, sys::player_password_raw& password);
940963
bool can_notify_player_joins(sys::state& state, dcon::nation_id source, sys::player_name& name);
941-
void notify_player_leaves(sys::state& state, dcon::nation_id source, bool make_ai);
942-
bool can_notify_player_leaves(sys::state& state, dcon::nation_id source, bool make_ai);
943-
void notify_player_picks_nation(sys::state& state, dcon::nation_id source, dcon::nation_id target);
944-
bool can_notify_player_picks_nation(sys::state& state, dcon::nation_id source, dcon::nation_id target);
945-
void notify_player_oos(sys::state& state, dcon::nation_id source);
964+
void notify_player_leaves(sys::state& state, dcon::nation_id source, bool make_ai, sys::player_name& player_name);
965+
bool can_notify_player_leaves(sys::state& state, dcon::nation_id source, bool make_ai, sys::player_name& player_name);
966+
void notify_player_picks_nation(sys::state& state, dcon::nation_id source, dcon::nation_id target, sys::player_name& name);
967+
bool can_notify_player_picks_nation(sys::state& state, dcon::nation_id source, dcon::nation_id target, sys::player_name& name);
968+
void notify_player_oos(sys::state& state, dcon::nation_id source, sys::player_name& name);
946969
void notify_save_loaded(sys::state& state, dcon::nation_id source);
947970
void notify_reload(sys::state& state, dcon::nation_id source);
971+
bool can_notify_start_game(sys::state& state, dcon::nation_id source);
948972
void notify_start_game(sys::state& state, dcon::nation_id source);
949973
void notify_player_is_loading(sys::state& state, dcon::nation_id source, sys::player_name& name);
950974
void execute_notify_player_is_loading(sys::state& state, dcon::nation_id source, sys::player_name& name);
951975
void notify_player_fully_loaded(sys::state& state, dcon::nation_id source, sys::player_name& name);
976+
bool can_notify_stop_game(sys::state& state, dcon::nation_id source);
952977
void notify_stop_game(sys::state& state, dcon::nation_id source);
953978
void notify_pause_game(sys::state& state, dcon::nation_id source);
954979
// returns true if the command was performed, false if not

src/gamestate/dcon_generated.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5785,7 +5785,7 @@ relationship{
57855785
link{
57865786
object{nation}
57875787
name{nation}
5788-
type{unique}
5788+
type{many}
57895789
}
57905790
link{
57915791
object{mp_player}

0 commit comments

Comments
 (0)