Project Alice
Loading...
Searching...
No Matches
system_state.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <stdint.h>
5#include <atomic>
6#include <chrono>
7//#include <fstream>
8
9#include "window.hpp"
10#include "constants.hpp"
11#include "dcon_generated.hpp"
12#include "gui_graphics.hpp"
13#include "game_scene.hpp"
14#include "simple_fs.hpp"
15#include "text.hpp"
16#include "opengl_wrapper.hpp"
17#include "fonts.hpp"
18#include "sound.hpp"
19#include "map_state.hpp"
20#include "economy.hpp"
21#include "culture.hpp"
22#include "military.hpp"
23#include "nations.hpp"
24#include "date_interface.hpp"
25#include "defines.hpp"
26#include "province.hpp"
27#include "events.hpp"
28#include "SPSCQueue.h"
29#include "commands.hpp"
31#include "events.hpp"
32#include "notifications.hpp"
33#include "network.hpp"
34#include "fif.hpp"
35
36// this header will eventually contain the highest-level objects
37// that represent the overall state of the program
38// it will also include the game state itself eventually as a member
39
40namespace sys {
41
42enum class gui_modes : uint8_t { faithful = 0, nouveau = 1, dummycabooseval = 2 };
44
46 float ui_scale = 1.0f;
47 float master_volume = 0.5f;
48 float music_volume = 1.0f;
49 float effects_volume = 1.0f;
50 float interface_volume = 1.0f;
51 bool prefer_fullscreen = false;
54 bool bind_tooltip_mouse = true;
55 bool use_classic_fonts = false;
57 bool outliner_views[14] = {true, true, true, true, true, true, true, true, true, true, true, true, true, true};
60 message_response::standard_pause,//war_on_nation = 1,
61 message_response::standard_log,//war_by_nation = 2,
62 message_response::standard_popup,//wargoal_added = 3,
63 message_response::ignore,//siegeover_by_nation = 4,
64 message_response::ignore,//siegeover_on_nation = 5,
65 message_response::standard_popup,//colony_finished = 6,
66 message_response::ignore,//reform_gained = 7,
67 message_response::ignore,//reform_lost = 8,
68 message_response::ignore,//ruling_party_change = 9,
69 message_response::standard_popup,//upperhouse = 10,
70 message_response::standard_popup,//electionstart = 11,
71 message_response::standard_popup,//electiondone = 12,
72 message_response::standard_popup,//breakcountry = 13,
73 message_response::ignore,//peace_accepted_from_nation = 14,
74 message_response::standard_popup,//peace_rejected_from_nation = 15,
75 message_response::standard_log,//peace_accepted_by_nation = 16,
76 message_response::standard_log,//peace_rejected_by_nation = 17,
77 message_response::standard_popup,//mobilization_start = 18,
78 message_response::standard_popup,//mobilization_end = 19,
79 message_response::standard_log,//factory_complete = 20,
80 message_response::standard_log,//rr_complete = 21,
81 message_response::standard_log,//fort_complete = 22,
82 message_response::standard_log,//naval_base_complete = 23,
83 message_response::standard_log,//province_event = 24,
84 message_response::standard_log,//national_event = 25,
85 message_response::standard_log,//major_event = 26,
86 message_response::standard_popup,//invention = 27,
88 message_response::standard_log,//leader_dies = 29,
89 message_response::ignore,//land_combat_starts_on_nation = 30,
90 message_response::ignore,//naval_combat_starts_on_nation = 31,
91 message_response::ignore,//land_combat_starts_by_nation = 32,
92 message_response::ignore,//naval_combat_starts_by_nation = 33,
93 message_response::ignore,//movement_finishes = 34,
94 message_response::ignore,//decision = 35,
95 message_response::standard_popup,//lose_great_power = 36,
96 message_response::standard_popup,//become_great_power = 37,
97 message_response::ignore,//war_subsidies_start_by_nation = 38,
98 message_response::standard_popup,//war_subsidies_start_on_nation = 39,
99 message_response::standard_popup,//war_subsidies_end_by_nation = 40,
100 message_response::standard_popup,//war_subsidies_end_on_nation = 41,
101 message_response::ignore,//reparations_start_by_nation = 42,
102 message_response::ignore,//reparations_start_on_nation = 43,
103 message_response::standard_popup,//reparations_end_by_nation = 44,
104 message_response::standard_popup,//reparations_end_on_nation = 45,
105 message_response::ignore,//mil_access_start_by_nation = 46,
106 message_response::ignore,//mil_access_start_on_nation = 47,
107 message_response::ignore,//mil_access_end_by_nation = 48,
108 message_response::standard_popup,//mil_access_end_on_nation = 49,
109 message_response::ignore,//mil_access_declined_by_nation = 50,
110 message_response::standard_popup,//mil_access_declined_on_nation = 51,
111 message_response::ignore,//alliance_starts = 52,
112 message_response::standard_popup,//alliance_ends = 53,
113 message_response::ignore,//alliance_declined_by_nation = 54,
114 message_response::standard_popup,//alliance_declined_on_nation = 55,
115 message_response::ignore,//ally_called_accepted_by_nation = 56,
116 message_response::standard_popup,//ally_called_declined_by_nation = 57,
117 message_response::ignore,//discredit_by_nation = 58,
118 message_response::ignore,//ban_by_nation = 59,
119 message_response::ignore,//expell_by_nation = 60,
120 message_response::standard_popup,//discredit_on_nation = 61,
121 message_response::standard_popup,//ban_on_nation = 62,
122 message_response::standard_popup,//expell_on_nation = 63,
123 message_response::ignore,//increase_opinion = 64,
124 message_response::ignore,//decrease_opinion_by_nation = 65,
125 message_response::standard_popup,//decrease_opinion_on_nation = 66,
126 message_response::ignore,//rem_sphere_by_nation = 67,
127 message_response::standard_popup,//rem_sphere_on_nation = 68,
128 message_response::standard_popup,//removed_from_sphere = 69,
129 message_response::ignore,//add_sphere = 70,
130 message_response::standard_popup,//added_to_sphere = 71,
131 message_response::ignore,//increase_relation_by_nation = 72,
132 message_response::standard_popup,//increase_relation_on_nation = 73,
133 message_response::ignore,//decrease_relation_by_nation = 74,
134 message_response::standard_popup,//decrease_relation_on_nation = 75,
135 message_response::ignore,//join_war_by_nation = 76,
136 message_response::standard_popup,//join_war_on_nation = 77,
137 message_response::standard_popup,//gw_unlocked = 78,
138 message_response::standard_popup,//war_becomes_great = 79,
139 message_response::ignore,//cb_detected_on_nation = 80,
140 message_response::standard_popup,//cb_detected_by_nation = 81,
141 message_response::ignore,//crisis_join_offer_accepted_by_nation = 82,
142 message_response::ignore,//crisis_join_offer_declined_by_nation = 83,
143 message_response::ignore,//crisis_join_offer_accepted_from_nation = 84,
144 message_response::standard_popup,//crisis_join_offer_declined_from_nation = 85,
145 message_response::standard_popup,//crisis_resolution_accepted = 86,
146 message_response::standard_popup,//crisis_becomes_war = 87,
147 message_response::standard_popup,//crisis_resolution_declined_from_nation = 88,
148 message_response::standard_popup,//crisis_starts = 89,
149 message_response::ignore,//crisis_attacker_backer = 90,
150 message_response::ignore,//crisis_defender_backer = 91,
151 message_response::standard_popup,//crisis_fizzle = 92,
152 message_response::ignore,//war_join_by = 93,
153 message_response::standard_popup,//war_join_on = 94,
154 message_response::standard_popup,//cb_fab_finished = 95,
155 message_response::standard_popup,//cb_fab_cancelled = 96,
156 message_response::ignore,//crisis_voluntary_joi_on = 97,
157 message_response::standard_log,//army_built = 98,
158 message_response::standard_log,//navy_built = 99,
159 message_response::standard_popup,//bankruptcy = 100,
160 message_response::standard_popup,//entered_automatic_alliance = 101,
161 message_response::standard_log,//chat_message = 102,
162 };
165 message_response::standard_log,//war_on_nation = 1,
166 message_response::standard_log,//war_by_nation = 2,
167 message_response::standard_log,//wargoal_added = 3,
168 message_response::ignore,//siegeover_by_nation = 4,
169 message_response::ignore,//siegeover_on_nation = 5,
170 message_response::standard_log,//colony_finished = 6,
171 message_response::ignore,//reform_gained = 7,
172 message_response::ignore,//reform_lost = 8,
173 message_response::ignore,//ruling_party_change = 9,
174 message_response::standard_log,//upperhouse = 10,
175 message_response::standard_log,//electionstart = 11,
176 message_response::standard_log,//electiondone = 12,
177 message_response::standard_log,//breakcountry = 13,
178 message_response::ignore,//peace_accepted_from_nation = 14,
179 message_response::standard_log,//peace_rejected_from_nation = 15,
180 message_response::ignore,//peace_accepted_by_nation = 16,
181 message_response::ignore,//peace_rejected_by_nation = 17,
182 message_response::standard_popup,//mobilization_start = 18,
183 message_response::standard_popup,//mobilization_end = 19,
184 message_response::ignore,//factory_complete = 20,
185 message_response::ignore,//rr_complete = 21,
186 message_response::ignore,//fort_complete = 22,
187 message_response::ignore,//naval_base_complete = 23,
188 message_response::standard_log,//province_event = 24,
189 message_response::standard_log,//national_event = 25,
190 message_response::standard_popup,//major_event = 26,
191 message_response::standard_log,//invention = 27,
193 message_response::ignore,//leader_dies = 29,
194 message_response::ignore,//land_combat_starts_on_nation = 30,
195 message_response::ignore,//naval_combat_starts_on_nation = 31,
196 message_response::ignore,//land_combat_starts_by_nation = 32,
197 message_response::ignore,//naval_combat_starts_by_nation = 33,
198 message_response::ignore,//movement_finishes = 34,
199 message_response::ignore,//decision = 35,
200 message_response::standard_log,//lose_great_power = 36,
201 message_response::standard_log,//become_great_power = 37,
202 message_response::standard_log,//war_subsidies_start_by_nation = 38,
203 message_response::standard_log,//war_subsidies_start_on_nation = 39,
204 message_response::standard_log,//war_subsidies_end_by_nation = 40,
205 message_response::standard_log,//war_subsidies_end_on_nation = 41,
206 message_response::standard_log,//reparations_start_by_nation = 42,
207 message_response::standard_log,//reparations_start_on_nation = 43,
208 message_response::standard_log,//reparations_end_by_nation = 44,
209 message_response::standard_log,//reparations_end_on_nation = 45,
210 message_response::ignore,//mil_access_start_by_nation = 46,
211 message_response::ignore,//mil_access_start_on_nation = 47,
212 message_response::ignore,//mil_access_end_by_nation = 48,
213 message_response::ignore,//mil_access_end_on_nation = 49,
214 message_response::ignore,//mil_access_declined_by_nation = 50,
215 message_response::ignore,//mil_access_declined_on_nation = 51,
216 message_response::standard_log,//alliance_starts = 52,
217 message_response::standard_log,//alliance_ends = 53,
218 message_response::ignore,//alliance_declined_by_nation = 54,
219 message_response::ignore,//alliance_declined_on_nation = 55,
220 message_response::ignore,//ally_called_accepted_by_nation = 56,
221 message_response::ignore,//ally_called_declined_by_nation = 57,
222 message_response::ignore,//discredit_by_nation = 58,
223 message_response::standard_log,//ban_by_nation = 59,
224 message_response::standard_log,//expell_by_nation = 60,
225 message_response::standard_log,//discredit_on_nation = 61,
226 message_response::ignore,//ban_on_nation = 62,
227 message_response::ignore,//expell_on_nation = 63,
228 message_response::ignore,//increase_opinion = 64,
229 message_response::standard_log,//decrease_opinion_by_nation = 65,
230 message_response::standard_log,//decrease_opinion_on_nation = 66,
231 message_response::standard_log,//rem_sphere_by_nation = 67,
232 message_response::standard_log,//rem_sphere_on_nation = 68,
233 message_response::standard_log,//removed_from_sphere = 69,
234 message_response::standard_log,//add_sphere = 70,
235 message_response::standard_log,//added_to_sphere = 71,
236 message_response::standard_log,//increase_relation_by_nation = 72,
237 message_response::standard_log,//increase_relation_on_nation = 73,
238 message_response::standard_log,//decrease_relation_by_nation = 74,
239 message_response::standard_log,//decrease_relation_on_nation = 75,
240 message_response::standard_log,//join_war_by_nation = 76,
241 message_response::standard_log,//join_war_on_nation = 77,
242 message_response::ignore,//gw_unlocked = 78,
243 message_response::ignore,//war_becomes_great = 79,
244 message_response::ignore,//cb_detected_on_nation = 80,
245 message_response::standard_popup,//cb_detected_by_nation = 81,
246 message_response::standard_log,//crisis_join_offer_accepted_by_nation = 82,
247 message_response::ignore,//crisis_join_offer_declined_by_nation = 83,
248 message_response::ignore,//crisis_join_offer_accepted_from_nation = 84,
249 message_response::ignore,//crisis_join_offer_declined_from_nation = 85,
250 message_response::ignore,//crisis_resolution_accepted = 86,
251 message_response::ignore,//crisis_becomes_war = 87,
252 message_response::ignore,//crisis_resolution_declined_from_nation = 88,
253 message_response::ignore,//crisis_starts = 89,
254 message_response::standard_popup,//crisis_attacker_backer = 90,
255 message_response::standard_popup,//crisis_defender_backer = 91,
256 message_response::ignore,//crisis_fizzle = 92,
257 message_response::standard_log,//war_join_by = 93,
258 message_response::ignore,//war_join_on = 94,
259 message_response::ignore,//cb_fab_finished = 95,
260 message_response::ignore,//cb_fab_cancelled = 96,
261 message_response::standard_popup,//crisis_voluntary_join_on = 97,
262 message_response::ignore,//army_built = 98,
263 message_response::ignore,//navy_built = 99,
264 message_response::standard_popup,//bankruptcy = 100,
265 message_response::ignore,//entered_automatic_alliance = 101,
266 message_response::standard_log,//chat_message = 102,
267 };
269 message_response::ignore,//revolt = 0,
270 message_response::ignore,//war_on_nation = 1,
271 message_response::ignore,//war_by_nation = 2,
272 message_response::ignore,//wargoal_added = 3,
273 message_response::ignore,//siegeover_by_nation = 4,
274 message_response::ignore,//siegeover_on_nation = 5,
275 message_response::ignore,//colony_finished = 6,
276 message_response::ignore,//reform_gained = 7,
277 message_response::ignore,//reform_lost = 8,
278 message_response::ignore,//ruling_party_change = 9,
279 message_response::ignore,//upperhouse = 10,
280 message_response::ignore,//electionstart = 11,
281 message_response::ignore,//electiondone = 12,
282 message_response::ignore,//breakcountry = 13,
283 message_response::ignore,//peace_accepted_from_nation = 14,
284 message_response::ignore,//peace_rejected_from_nation = 15,
285 message_response::ignore,//peace_accepted_by_nation = 16,
286 message_response::ignore,//peace_rejected_by_nation = 17,
287 message_response::standard_popup,//mobilization_start = 18,
288 message_response::standard_popup,//mobilization_end = 19,
289 message_response::ignore,//factory_complete = 20,
290 message_response::ignore,//rr_complete = 21,
291 message_response::ignore,//fort_complete = 22,
292 message_response::ignore,//naval_base_complete = 23,
293 message_response::ignore,//province_event = 24,
294 message_response::ignore,//national_event = 25,
295 message_response::standard_popup,//major_event = 26,
296 message_response::ignore,//invention = 27,
297 message_response::ignore,//tech = 28,
298 message_response::ignore,//leader_dies = 29,
299 message_response::ignore,//land_combat_starts_on_nation = 30,
300 message_response::ignore,//naval_combat_starts_on_nation = 31,
301 message_response::ignore,//land_combat_starts_by_nation = 32,
302 message_response::ignore,//naval_combat_starts_by_nation = 33,
303 message_response::ignore,//movement_finishes = 34,
304 message_response::ignore,//decision = 35,
305 message_response::ignore,//lose_great_power = 36,
306 message_response::standard_popup,//become_great_power = 37,
307 message_response::ignore,//war_subsidies_start_by_nation = 38,
308 message_response::ignore,//war_subsidies_start_on_nation = 39,
309 message_response::ignore,//war_subsidies_end_by_nation = 40,
310 message_response::ignore,//war_subsidies_end_on_nation = 41,
311 message_response::ignore,//reparations_start_by_nation = 42,
312 message_response::ignore,//reparations_start_on_nation = 43,
313 message_response::ignore,//reparations_end_by_nation = 44,
314 message_response::ignore,//reparations_end_on_nation = 45,
315 message_response::ignore,//mil_access_start_by_nation = 46,
316 message_response::ignore,//mil_access_start_on_nation = 47,
317 message_response::ignore,//mil_access_end_by_nation = 48,
318 message_response::ignore,//mil_access_end_on_nation = 49,
319 message_response::ignore,//mil_access_declined_by_nation = 50,
320 message_response::ignore,//mil_access_declined_on_nation = 51,
321 message_response::ignore,//alliance_starts = 52,
322 message_response::ignore,//alliance_ends = 53,
323 message_response::ignore,//alliance_declined_by_nation = 54,
324 message_response::ignore,//alliance_declined_on_nation = 55,
325 message_response::ignore,//ally_called_accepted_by_nation = 56,
326 message_response::ignore,//ally_called_declined_by_nation = 57,
327 message_response::ignore,//discredit_by_nation = 58,
328 message_response::ignore,//ban_by_nation = 59,
329 message_response::ignore,//expell_by_nation = 60,
330 message_response::ignore,//discredit_on_nation = 61,
331 message_response::ignore,//ban_on_nation = 62,
332 message_response::ignore,//expell_on_nation = 63,
333 message_response::ignore,//increase_opinion = 64,
334 message_response::ignore,//decrease_opinion_by_nation = 65,
335 message_response::ignore,//decrease_opinion_on_nation = 66,
336 message_response::ignore,//rem_sphere_by_nation = 67,
337 message_response::ignore,//rem_sphere_on_nation = 68,
338 message_response::ignore,//removed_from_sphere = 69,
339 message_response::ignore,//add_sphere = 70,
340 message_response::ignore,//added_to_sphere = 71,
341 message_response::ignore,//increase_relation_by_nation = 72,
342 message_response::ignore,//increase_relation_on_nation = 73,
343 message_response::ignore,//decrease_relation_by_nation = 74,
344 message_response::ignore,//decrease_relation_on_nation = 75,
345 message_response::ignore,//join_war_by_nation = 76,
346 message_response::ignore,//join_war_on_nation = 77,
347 message_response::ignore,//gw_unlocked = 78,
348 message_response::ignore,//war_becomes_great = 79,
349 message_response::ignore,//cb_detected_on_nation = 80,
350 message_response::standard_log,//cb_detected_by_nation = 81,
351 message_response::ignore,//crisis_join_offer_accepted_by_nation = 82,
352 message_response::ignore,//crisis_join_offer_declined_by_nation = 83,
353 message_response::ignore,//crisis_join_offer_accepted_from_nation = 84,
354 message_response::ignore,//crisis_join_offer_declined_from_nation = 85,
355 message_response::ignore,//crisis_resolution_accepted = 86,
356 message_response::ignore,//crisis_becomes_war = 87,
357 message_response::ignore,//crisis_resolution_declined_from_nation = 88,
358 message_response::ignore,//crisis_starts = 89,
359 message_response::standard_popup,//crisis_attacker_backer = 90,
360 message_response::standard_popup, //crisis_defender_backer = 91,
361 message_response::ignore, //crisis_fizzle = 92,
362 message_response::ignore, //war_join_by = 93,
363 message_response::ignore,//war_join_on = 94,
364 message_response::ignore,//cb_fab_finished = 95,
365 message_response::ignore,//cb_fab_cancelled = 96,
366 message_response::standard_popup,//crisis_voluntary_join_on = 97,
367 message_response::ignore,//army_built = 98,
368 message_response::ignore,//navy_built = 99,
369 message_response::standard_popup,//bankruptcy = 100,
370 message_response::ignore,//entered_automatic_alliance = 101,
371 message_response::standard_log,//chat_message = 102,
372 };
373 bool fow_enabled = false;
377 float gamma = 1.f;
378 bool railroads_enabled = true;
379 bool rivers_enabled = true;
382 bool render_models = false;
384 bool black_map_font = true;
385 bool spoilers = true;
386 float zoom_speed = 20.f;
393 char locale[16] = "en-US";
394};
395
396struct global_scenario_data_s { // this struct holds miscellaneous global properties of the scenario
397};
398
404 bool instant_army = false;
405 bool instant_industry = false;
406 std::vector<dcon::nation_id> instant_research_nations;
407 bool daily_oos_check = false;
408 bool province_names = false;
409
410 bool ecodump = false;
411
417
418 bool instant_navy = false;
421};
422
424 dcon::nation_id id;
425
427
428 bool supports_attacker = false;
429 bool merely_interested = false;
430};
431static_assert(sizeof(crisis_member_def) ==
436
437enum class crisis_type : uint32_t { none = 0, claim = 1, liberation = 2, colonial = 3, influence = 4 };
439
442 dcon::nation_id nation;
443
445 great_nation() = default;
446};
447static_assert(sizeof(great_nation) ==
449 + sizeof(great_nation::nation));
450
451// used by state selector visually
454 std::vector<dcon::state_definition_id> selectable_states;
455 std::function<void(sys::state&, dcon::state_definition_id)> on_select;
456 std::function<void(sys::state&)> on_cancel;
457};
458
459struct player_data { // currently this data is serialized via memcpy, to make sure no pointers end up in here
460 std::array<float, 32> treasury_record = {0.0f}; // current day's value = date.value & 31
461 std::array<float, 32> population_record = { 0.0f }; // current day's value = date.value & 31
462};
463
464// the state struct will eventually include (at least pointers to)
465// the state of the sound system, the state of the windowing system,
466// and the game data / state itself
467
468// ultimately it is the system struct that gets passed around everywhere
469// so that bits of the ui, for example, can control the overall state of
470// the game
471
472struct alignas(64) state {
473 dcon::data_container world;
474
475 // scenario data
476
478
484
487
488 std::vector<uint16_t> trigger_data;
489 std::vector<int32_t> trigger_data_indices;
490 std::vector<uint16_t> effect_data;
491 std::vector<int32_t> effect_data_indices;
492 std::vector<value_modifier_segment> value_modifier_segments;
494
495 std::vector<char> key_data;
496 std::vector<char> locale_text_data;
497 ankerl::unordered_dense::set<dcon::text_key, text::vector_backed_ci_hash, text::vector_backed_ci_eq> untrans_key_to_text_sequence;
498 ankerl::unordered_dense::map<dcon::text_key, uint32_t, text::vector_backed_ci_hash, text::vector_backed_ci_eq> locale_key_to_text_sequence;
499
503 std::vector<dcon::nation_id> nations_by_rank;
504 std::vector<dcon::nation_id> nations_by_industrial_score;
505 std::vector<dcon::nation_id> nations_by_military_score;
506 std::vector<dcon::nation_id> nations_by_prestige_score;
507 std::vector<great_nation> great_nations;
508
509 uint64_t scenario_time_stamp = 0; // for identifying the scenario file
510 uint32_t scenario_counter = 0; // as above
511 int32_t autosave_counter = 0; // which autosave file is next
512 sys::checksum_key scenario_checksum;// for checksum for savefiles
513 sys::checksum_key session_host_checksum;// for checking that the client can join a session
516
517#ifdef USE_LLVM
518 std::unique_ptr<fif::environment> jit_environment;
519#endif
520
521 //
522 // Crisis data
523 //
524
525 dcon::state_instance_id crisis_state;
526 std::vector<crisis_member_def> crisis_participants;
529 dcon::nation_id primary_crisis_attacker;
530 dcon::nation_id primary_crisis_defender;
533 dcon::war_id crisis_war;
534 sys::date last_crisis_end_date{0}; // initial grace period
535 dcon::national_identity_id crisis_liberation_tag;
536 dcon::state_definition_id crisis_colony;
537
538 //
539 // Messages
540 //
541
542 std::array<diplomatic_message::message, 128> pending_messages = {};
543
544 //
545 // Event data
546 //
547
548 std::vector<event::pending_human_n_event> pending_n_event;
549 std::vector<event::pending_human_f_n_event> pending_f_n_event;
550 std::vector<event::pending_human_p_event> pending_p_event;
551 std::vector<event::pending_human_f_p_event> pending_f_p_event;
552
553 std::vector<event::pending_human_n_event> future_n_event;
554 std::vector<event::pending_human_p_event> future_p_event;
555
556 std::vector<int32_t> unit_names_indices; // indices for the names
557 std::vector<char> unit_names;
558 // a second text buffer, this time for just the unit names
559 // why a second text buffer? Partly because unit names don't need the extra redirection possibilities of
560 // ordinary game text, partly because I envision the possibility that we may stick dynamic names into
561 // this We also may push this into the save game if we handle unit renaming using this
562
563 ui::definitions ui_defs; // definitions for graphics and ui
564
565 std::vector<uint8_t> flag_type_map; // flag_type remapper for saving space while also allowing
566 // mods to add flags not present in vanilla
567 std::vector<culture::flag_type> flag_types; // List of unique flag types
568
569 //
570 // persistent user settings
571 //
572
574
575 //
576 // current program / ui state
577 //
578
580 dcon::nation_id local_player_nation;
583 uint32_t game_seed = 0; // do *not* alter this value, ever
584 float inflation = 1.0f;
586 std::vector<dcon::army_id> selected_armies;
587 std::vector<dcon::navy_id> selected_navies;
589
590 //control groups
591 std::array<std::vector<dcon::army_id>, 10> ctrl_armies;
592 std::array<std::vector<dcon::navy_id>, 10> ctrl_navies;
593
594 //army group
595 dcon::automated_army_group_id selected_army_group{};
596
598
599 //current ui
601
602 std::optional<state_selection_data> state_selection;
604
605 simple_fs::file_system common_fs; // file system for looking up graphics assets, etc
606 std::unique_ptr<window::window_data_impl> win_ptr = nullptr; // platform-dependent window information
607 std::unique_ptr<sound::sound_impl> sound_ptr = nullptr; // platform-dependent sound information
608 ui::state ui_state; // transient information for the state of the ui
610
611 // synchronization data (between main update logic and ui thread)
612 std::atomic<bool> game_state_updated = false; // game state -> ui signal
613 std::atomic<bool> province_ownership_changed = true; // game state -> ui signal
614 std::atomic<bool> save_list_updated = false; // game state -> ui signal
615 std::atomic<bool> quit_signaled = false; // ui -> game state signal
616 std::atomic<int32_t> actual_game_speed = 0; // ui -> game state message
617 rigtorp::SPSCQueue<command::payload> incoming_commands; // ui or network -> local gamestate
618 std::atomic<bool> ui_pause = false; // force pause by an important message being open
619 std::atomic<bool> railroad_built = true; // game state -> map
620
621 // synchronization: notifications from the gamestate to ui
630
631 // internal game timer / update logic
632 std::chrono::time_point<std::chrono::steady_clock> last_update = std::chrono::steady_clock::now();
633 bool internally_paused = false; // should NOT be set from the ui context (but may be read)
634
635 // common data for the window
636 int32_t x_size = 0;
637 int32_t y_size = 0;
638 bool drag_selecting = false;
639 int32_t mouse_x_position = 0;
640 int32_t mouse_y_position = 0;
641 bool is_dragging = false;
642 int32_t x_drag_start = 0;
643 int32_t y_drag_start = 0;
644 std::chrono::time_point<std::chrono::steady_clock> tooltip_timer = std::chrono::steady_clock::now();
645
646 // map data
648
649 // graphics data
651
652#ifdef DIRECTX_11
653 directx::data directx;
654#endif
655
656 // cheat data
658
659 // network data
661
662 // console interpreter
667 std::unique_ptr<fif::environment> fif_environment;
668 int32_t type_text_key = -1;
669 int32_t type_localized_key = -1;
670
671 // the following functions will be invoked by the window subsystem
672
673 void on_create(); // called once after the window is created and opengl is ready
674 void on_rbutton_down(int32_t x, int32_t y, key_modifiers mod);
675 void on_mbutton_down(int32_t x, int32_t y, key_modifiers mod);
676 void on_lbutton_down(int32_t x, int32_t y, key_modifiers mod);
677 void on_rbutton_up(int32_t x, int32_t y, key_modifiers mod);
678 void on_mbutton_up(int32_t x, int32_t y, key_modifiers mod);
679 void on_lbutton_up(int32_t x, int32_t y, key_modifiers mod);
680 void on_mouse_move(int32_t x, int32_t y, key_modifiers mod);
681 void on_mouse_drag(int32_t x, int32_t y, key_modifiers mod); // called when the left button is held down
682 void on_drag_finished(int32_t x, int32_t y, key_modifiers mod); // called when the left button is released after one or more drag events
683 void on_resize(int32_t x, int32_t y, window::window_state win_state);
684 void on_mouse_wheel(int32_t x, int32_t y, key_modifiers mod, float amount); // an amount of 1.0 is one "click" of the wheel
685 void on_key_down(virtual_key keycode, key_modifiers mod);
686 void on_key_up(virtual_key keycode, key_modifiers mod);
687 void on_text(char32_t c); // c is a win1250 codepage value
688 void render(); // called to render the frame may (and should) delay returning until the frame is rendered, including waiting
689 // for vsync
690
691 void single_game_tick();
692 // this function runs the internal logic of the game. It will return *only* after a quit notification is sent to it
693 void game_loop();
695 void debug_save_oos_dump();
697
699 void state_select(dcon::state_definition_id sdef);
700
701 // the following function are for interacting with the string pool
702
703 std::string_view to_string_view(dcon::text_key tag) const;
704 std::string_view locale_string_view(uint32_t tag) const;
705 bool key_is_localized(dcon::text_key tag) const;
706 bool key_is_localized(std::string_view key) const;
707 dcon::text_key lookup_key(std::string_view text) const;
708
709 void reset_locale_pool();
710 void load_locale_strings(std::string_view locale_name);
711
712 dcon::text_key add_key_win1252(std::string const& text);
713 dcon::text_key add_key_win1252(std::string_view text);
714 dcon::text_key add_key_utf8(std::string const& text);
715 dcon::text_key add_key_utf8(std::string_view text);
716 uint32_t add_locale_data_win1252(std::string const& text);
717 uint32_t add_locale_data_win1252(std::string_view text);
718 uint32_t add_locale_data_utf8(std::string const& text);
719 uint32_t add_locale_data_utf8(std::string_view text);
720
721 dcon::unit_name_id add_unit_name(std::string_view text); // returns the newly added text
722 std::string_view to_string_view(dcon::unit_name_id tag) const; // takes a stored tag and give you the text
723
724 dcon::trigger_key commit_trigger_data(std::vector<uint16_t> data);
725 dcon::effect_key commit_effect_data(std::vector<uint16_t> data);
726
727 state() : untrans_key_to_text_sequence(0, text::vector_backed_ci_hash(key_data), text::vector_backed_ci_eq(key_data)), locale_key_to_text_sequence(0, text::vector_backed_ci_hash(key_data), text::vector_backed_ci_eq(key_data)), current_scene(game_scene::nation_picker()), incoming_commands(1024), new_n_event(1024), new_f_n_event(1024), new_p_event(1024), new_f_p_event(1024), new_requests(256), new_messages(2048), naval_battle_reports(256), land_battle_reports(256) {
728
729 key_data.push_back(0);
730 }
731
732 ~state() = default;
733
734 void save_user_settings() const;
735 void load_user_settings();
736 void update_ui_scale(float new_scale);
737
738 void load_scenario_data(parsers::error_handler& err, sys::year_month_day bookmark_date); // loads all scenario files other than map data
739 void fill_unsaved_data(); // reconstructs derived values that are not directly saved after a save has been loaded
740 void on_scenario_load(); // called when the scenario file is loaded (not when saves are loaded)
741 void preload(); // clears data that will be later reconstructed from saved values
742
743 void console_log(std::string_view message);
744
745 void open_diplomacy(dcon::nation_id target); // Open the diplomacy window with target selected
746
747 bool is_selected(dcon::army_id a) {
748 return std::find(selected_armies.begin(), selected_armies.end(), a) != selected_armies.end();
749 }
750 bool is_selected(dcon::navy_id a) {
751 return std::find(selected_navies.begin(), selected_navies.end(), a) != selected_navies.end();
752 }
753 void select(dcon::army_id a) {
754 if(!is_selected(a)) {
755 selected_armies.push_back(a);
756 game_state_updated.store(true, std::memory_order_release);
757 }
758 }
759 void select(dcon::navy_id a) {
760 if(!is_selected(a)) {
761 selected_navies.push_back(a);
762 game_state_updated.store(true, std::memory_order_release);
763 }
764 }
765 void deselect(dcon::army_id a) {
766 for(size_t i = selected_armies.size(); i-- > 0;) {
767 if(selected_armies[i] == a) {
769 selected_armies.pop_back();
770 game_state_updated.store(true, std::memory_order_release);
771 return;
772 }
773 }
774 }
775 void deselect(dcon::navy_id a) {
776 for(size_t i = selected_navies.size(); i-- > 0;) {
777 if(selected_navies[i] == a) {
779 selected_navies.pop_back();
780 game_state_updated.store(true, std::memory_order_release);
781 return;
782 }
783 }
784 }
785
786 void new_army_group(dcon::province_id hq);
787 void delete_army_group(dcon::automated_army_group_id group);
788 void toggle_designated_port(dcon::automated_army_group_id group, dcon::province_id position);
789 void toggle_defensive_position(dcon::automated_army_group_id group, dcon::province_id position);
790 void toggle_enforce_control_position(dcon::automated_army_group_id group, dcon::province_id position);
791 void update_armies_and_fleets(dcon::automated_army_group_id group);
792 void regiment_reset_order(dcon::regiment_automation_data_id regiment);
793 bool army_group_recalculate_distribution(dcon::automated_army_group_id group, std::vector<float>& regiments_distribution);
794 void army_group_update_tasks(dcon::automated_army_group_id group);
795 dcon::province_id get_port_for_landing(dcon::automated_army_group_id group, dcon::province_id target);
796 void army_group_distribute_tasks(dcon::automated_army_group_id group);
797 float army_group_available_supply(dcon::automated_army_group_id group, dcon::province_id province);
798 dcon::province_id find_available_ferry_origin(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment);
799 bool move_to_available_port(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment);
800 void remove_navy_from_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id navy_to_delete);
801 void army_group_update_regiment_status(dcon::automated_army_group_id group);
802 void army_group_add_regiment(dcon::automated_army_group_id group, dcon::regiment_id id);
803 void remove_regiment_from_army_group(dcon::automated_army_group_id selected_group, dcon::regiment_id selected_regiment);
804 void remove_regiment_from_all_army_groups(dcon::regiment_id regiment_to_delete);
805 void remove_army_army_group_clean(dcon::automated_army_group_id group, dcon::army_id army_to_delete);
806 void add_army_to_army_group(dcon::automated_army_group_id selected_group, dcon::army_id selected_army);
807 void add_navy_to_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id selected_navy);
808 void smart_select_army_group(dcon::automated_army_group_id selected_group);
809 void select_army_group(dcon::automated_army_group_id selected_group);
810 void deselect_army_group();
811 dcon::regiment_automation_data_id fill_province_up_to_supply_limit(
812 dcon::automated_army_group_id group_id,
813 dcon::province_id target,
814 std::vector<float>& regiments_distribution,
815 float overestimate_supply_limit,
816 bool ignore_enemy_regiments_in_supply_calculations
817 );
818 dcon::regiment_automation_data_id fill_province(
819 dcon::automated_army_group_id group_id,
820 dcon::province_id target,
821 std::vector<float>& regiments_expectation_ideal
822 );
823
825 dcon::province_id p1,
826 bool is_land,
827 std::vector<dcon::province_id> & provinces
828 );
829
831 macro_builder_template& target_template,
832 dcon::province_id target_province,
833 std::vector<dcon::province_id>& available_provinces,
834 std::array<uint8_t, sys::macro_builder_template::max_types>& current_distribution
835 );
836};
837} // namespace sys
constexpr uint8_t standard_popup
Definition: constants.hpp:543
constexpr uint8_t standard_log
Definition: constants.hpp:542
constexpr uint8_t standard_pause
Definition: constants.hpp:544
constexpr uint8_t ignore
Definition: constants.hpp:535
Definition: constants.hpp:4
virtual_key
Definition: constants.hpp:5
key_modifiers
Definition: constants.hpp:156
network_mode_type
Definition: constants.hpp:548
map_zoom_mode
Definition: constants.hpp:185
autosave_frequency
Definition: constants.hpp:169
projection_mode
color_blind_mode
Definition: constants.hpp:554
map_label_mode
Definition: constants.hpp:178
map_vassal_color_mode
Definition: constants.hpp:193
army_group_order
Definition: constants.hpp:216
Definition: bmfont.cpp:118
window_state
Definition: window.hpp:46
std::string native_string
uint uint32_t
ulong uint64_t
uchar uint8_t
std::vector< dcon::nation_id > instant_research_nations
std::string national_economy_dump_buffer
std::string prices_dump_buffer
std::string supply_dump_buffer
std::string demand_by_category_dump_buffer
std::string demand_dump_buffer
crisis_join_offer joined_with_offer
dcon::nation_id nation
great_nation(sys::date last_greatness, dcon::nation_id nation)
great_nation()=default
sys::date last_greatness
std::array< float, 32 > population_record
std::array< float, 32 > treasury_record
std::vector< dcon::state_definition_id > selectable_states
std::function< void(sys::state &, dcon::state_definition_id)> on_select
std::function< void(sys::state &)> on_cancel
void debug_scenario_oos_dump()
void select_army_group(dcon::automated_army_group_id selected_group)
uint64_t scenario_time_stamp
text::font_manager font_collection
bool drag_selecting
uint32_t add_locale_data_win1252(std::string const &text)
dcon::national_identity_id crisis_liberation_tag
culture::global_cultural_state culture_definitions
network_mode_type network_mode
std::string console_command_pending
void toggle_defensive_position(dcon::automated_army_group_id group, dcon::province_id position)
std::vector< char > key_data
user_settings_s user_settings
bool adjacency_data_out_of_date
void build_up_to_template_land(macro_builder_template &target_template, dcon::province_id target_province, std::vector< dcon::province_id > &available_provinces, std::array< uint8_t, sys::macro_builder_template::max_types > &current_distribution)
std::vector< event::pending_human_p_event > future_p_event
int32_t mouse_x_position
void select(dcon::navy_id a)
std::atomic< bool > save_list_updated
void save_user_settings() const
rigtorp::SPSCQueue< command::payload > incoming_commands
std::vector< dcon::nation_id > nations_by_rank
std::vector< event::pending_human_p_event > pending_p_event
dcon::text_key add_key_win1252(std::string const &text)
dcon::trigger_key commit_trigger_data(std::vector< uint16_t > data)
std::vector< value_modifier_segment > value_modifier_segments
std::atomic< bool > ui_pause
std::vector< dcon::army_id > selected_armies
ankerl::unordered_dense::set< dcon::text_key, text::vector_backed_ci_hash, text::vector_backed_ci_eq > untrans_key_to_text_sequence
void on_resize(int32_t x, int32_t y, window::window_state win_state)
std::vector< dcon::navy_id > selected_navies
dcon::data_container world
std::atomic< bool > railroad_built
std::vector< crisis_member_def > crisis_participants
uint32_t add_locale_data_utf8(std::string const &text)
bool is_selected(dcon::army_id a)
void army_group_add_regiment(dcon::automated_army_group_id group, dcon::regiment_id id)
void on_lbutton_down(int32_t x, int32_t y, key_modifiers mod)
std::vector< event::pending_human_f_p_event > pending_f_p_event
rigtorp::SPSCQueue< event::pending_human_p_event > new_p_event
void army_group_distribute_tasks(dcon::automated_army_group_id group)
void fill_vector_of_connected_provinces(dcon::province_id p1, bool is_land, std::vector< dcon::province_id > &provinces)
std::vector< uint16_t > effect_data
sys::checksum_key session_host_checksum
std::atomic< int32_t > actual_game_speed
dcon::state_definition_id crisis_colony
void on_rbutton_down(int32_t x, int32_t y, key_modifiers mod)
void toggle_enforce_control_position(dcon::automated_army_group_id group, dcon::province_id position)
dcon::nation_id local_player_nation
std::atomic< bool > game_state_updated
int32_t type_localized_key
std::chrono::time_point< std::chrono::steady_clock > tooltip_timer
std::unique_ptr< sound::sound_impl > sound_ptr
int32_t type_text_key
parsing::defines defines
dcon::effect_key commit_effect_data(std::vector< uint16_t > data)
std::vector< char > unit_names
std::vector< int32_t > trigger_data_indices
std::string_view to_string_view(dcon::text_key tag) const
uint32_t crisis_last_checked_gp
void toggle_designated_port(dcon::automated_army_group_id group, dcon::province_id position)
std::vector< uint8_t > flag_type_map
std::string_view locale_string_view(uint32_t tag) const
tagged_vector< value_modifier_description, dcon::value_modifier_key > value_modifiers
economy::global_economy_state economy_definitions
sys::checksum_key get_save_checksum()
void on_mouse_wheel(int32_t x, int32_t y, key_modifiers mod, float amount)
void on_create()
std::vector< char > locale_text_data
dcon::province_id get_port_for_landing(dcon::automated_army_group_id group, dcon::province_id target)
simple_fs::file_system common_fs
game_scene::scene_properties current_scene
std::unique_ptr< fif::environment > fif_environment
int32_t y_drag_start
void deselect_army_group()
absolute_time_point start_date
absolute_time_point end_date
uint32_t game_seed
army_group_order selected_army_group_order
rigtorp::SPSCQueue< military::land_battle_report > land_battle_reports
std::vector< culture::flag_type > flag_types
int32_t mouse_y_position
void new_army_group(dcon::province_id hq)
bool internally_paused
void army_group_update_tasks(dcon::automated_army_group_id group)
military::global_military_state military_definitions
rigtorp::SPSCQueue< notification::message > new_messages
void remove_regiment_from_all_army_groups(dcon::regiment_id regiment_to_delete)
void smart_select_army_group(dcon::automated_army_group_id selected_group)
sys::date current_date
void remove_army_army_group_clean(dcon::automated_army_group_id group, dcon::army_id army_to_delete)
sys::checksum_key scenario_checksum
float army_group_available_supply(dcon::automated_army_group_id group, dcon::province_id province)
void open_diplomacy(dcon::nation_id target)
dcon::province_id find_available_ferry_origin(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment)
dcon::unit_name_id add_unit_name(std::string_view text)
void remove_navy_from_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id navy_to_delete)
void start_state_selection(state_selection_data &data)
int32_t x_size
std::vector< int32_t > unit_names_indices
bool diplomatic_cached_values_out_of_date
std::vector< dcon::nation_id > nations_by_military_score
std::atomic< bool > quit_signaled
void on_text(char32_t c)
void on_drag_finished(int32_t x, int32_t y, key_modifiers mod)
void on_rbutton_up(int32_t x, int32_t y, key_modifiers mod)
void single_game_tick()
void add_navy_to_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id selected_navy)
native_string loaded_save_file
dcon::automated_army_group_id selected_army_group
player_data player_data_cache
bool national_cached_values_out_of_date
void on_key_up(virtual_key keycode, key_modifiers mod)
void remove_regiment_from_army_group(dcon::automated_army_group_id selected_group, dcon::regiment_id selected_regiment)
void on_mouse_move(int32_t x, int32_t y, key_modifiers mod)
dcon::regiment_automation_data_id fill_province_up_to_supply_limit(dcon::automated_army_group_id group_id, dcon::province_id target, std::vector< float > &regiments_distribution, float overestimate_supply_limit, bool ignore_enemy_regiments_in_supply_calculations)
std::vector< dcon::nation_id > nations_by_industrial_score
std::string console_command_result
dcon::text_key lookup_key(std::string_view text) const
bool move_to_available_port(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment)
void debug_save_oos_dump()
std::mutex ugly_ui_game_interaction_hack
dcon::nation_id primary_crisis_defender
std::array< diplomatic_message::message, 128 > pending_messages
std::vector< event::pending_human_n_event > future_n_event
~state()=default
map_mode::mode stored_map_mode
dcon::regiment_automation_data_id fill_province(dcon::automated_army_group_id group_id, dcon::province_id target, std::vector< float > &regiments_expectation_ideal)
cheat_data_s cheat_data
void load_user_settings()
bool army_group_recalculate_distribution(dcon::automated_army_group_id group, std::vector< float > &regiments_distribution)
void on_lbutton_up(int32_t x, int32_t y, key_modifiers mod)
std::array< std::vector< dcon::army_id >, 10 > ctrl_armies
std::array< std::vector< dcon::navy_id >, 10 > ctrl_navies
void game_loop()
void deselect(dcon::navy_id a)
ankerl::unordered_dense::map< dcon::text_key, uint32_t, text::vector_backed_ci_hash, text::vector_backed_ci_eq > locale_key_to_text_sequence
void reset_locale_pool()
network::network_state network_state
sys::date ui_date
void on_mouse_drag(int32_t x, int32_t y, key_modifiers mod)
void update_armies_and_fleets(dcon::automated_army_group_id group)
uint32_t scenario_counter
std::vector< great_nation > great_nations
void on_key_down(virtual_key keycode, key_modifiers mod)
dcon::war_id crisis_war
crisis_type current_crisis
rigtorp::SPSCQueue< event::pending_human_f_p_event > new_f_p_event
native_string loaded_scenario_file
ogl::data open_gl
ui::state ui_state
void add_army_to_army_group(dcon::automated_army_group_id selected_group, dcon::army_id selected_army)
void load_locale_strings(std::string_view locale_name)
map::map_state map_state
void on_mbutton_up(int32_t x, int32_t y, key_modifiers mod)
province::global_provincial_state province_definitions
int32_t autosave_counter
sys::date last_crisis_end_date
void army_group_update_regiment_status(dcon::automated_army_group_id group)
std::string console_command_error
void delete_army_group(dcon::automated_army_group_id group)
rigtorp::SPSCQueue< diplomatic_message::message > new_requests
rigtorp::SPSCQueue< event::pending_human_n_event > new_n_event
void select(dcon::army_id a)
void load_scenario_data(parsers::error_handler &err, sys::year_month_day bookmark_date)
std::vector< event::pending_human_f_n_event > pending_f_n_event
std::vector< dcon::nation_id > nations_by_prestige_score
void fill_unsaved_data()
void regiment_reset_order(dcon::regiment_automation_data_id regiment)
void on_scenario_load()
int32_t y_size
void on_mbutton_down(int32_t x, int32_t y, key_modifiers mod)
int32_t x_drag_start
dcon::state_instance_id crisis_state
dcon::text_key add_key_utf8(std::string const &text)
bool key_is_localized(dcon::text_key tag) const
dcon::nation_id primary_crisis_attacker
std::vector< int32_t > effect_data_indices
void deselect(dcon::army_id a)
ui::definitions ui_defs
std::vector< event::pending_human_n_event > pending_n_event
std::mutex lock_console_strings
bool is_selected(dcon::navy_id a)
rigtorp::SPSCQueue< military::naval_battle_report > naval_battle_reports
void state_select(dcon::state_definition_id sdef)
std::chrono::time_point< std::chrono::steady_clock > last_update
std::vector< uint16_t > trigger_data
float crisis_temperature
std::unique_ptr< window::window_data_impl > win_ptr
crisis_mode current_crisis_mode
void console_log(std::string_view message)
void update_ui_scale(float new_scale)
std::optional< state_selection_data > state_selection
rigtorp::SPSCQueue< event::pending_human_f_n_event > new_f_n_event
std::atomic< bool > province_ownership_changed
nations::global_national_state national_definitions
bool left_mouse_click_hold_and_release
projection_mode map_is_globe
map_zoom_mode zoom_mode
uint8_t interesting_message_settings[int32_t(sys::message_setting_type::count)]
autosave_frequency autosaves
uint8_t self_message_settings[int32_t(sys::message_setting_type::count)]
map_label_mode map_label
uint8_t other_message_settings[int32_t(sys::message_setting_type::count)]
map_vassal_color_mode vassal_color