9static std::vector<parsers::mod_file> mod_list;
11static uint32_t max_scenario_count = 0;
12static std::vector<scenario_file> scenario_files;
20 for(int32_t i = 0; i < int32_t(mod_list.size()); ++i) {
21 if(mod_list[i].mod_selected ==
false)
24 mod_list[i].add_to_file_system(dummy);
32 auto root = get_root(fs_root);
36 for (
auto& f : mod_files) {
39 auto content = view_contents(*of);
49 auto root = get_root(fs_root);
52 for(
auto& f : s_files) {
55 auto content = view_contents(*of);
58 max_scenario_count = std::max(desc.count, max_scenario_count);
65 return a.ident.count > b.ident.count;
73 ret += digits[v & 0x0F];
88 auto root = get_root(fs_root);
89 auto common = open_directory(root,
NATIVE(
"common"));
91 if(
auto f = open_file(common,
NATIVE(
"bookmarks.txt")); f) {
95 parsers::parse_bookmark_file(gen, err, bookmark_context);
107 auto game_state = std::make_unique<sys::state>();
112 if(date_index == 0) {
115 auto time_stamp =
uint64_t(std::time(0));
116 auto base_name =
to_hex(time_stamp);
120 ++max_scenario_count;
121 selected_scenario_file = base_name +
NATIVE(
"-") + std::to_string(append) +
NATIVE(
".bin");
124 auto content = view_contents(*of);
126 if(desc.count != 0) {
127 scenario_files.push_back(
scenario_file{ selected_scenario_file , desc });
131 return a.ident.count > b.ident.count;
144 auto assembled_msg = std::string(
"You can still play the mod, but it might be unstable\r\nThe following problems were encountered while creating the scenario:\r\n\r\nErrors:\r\n") + err.
accumulated_errors +
"\r\n\r\nWarnings:\r\n" + err.
accumulated_warnings;
146 auto fname =
NATIVE(
"scenario_errors.log");
150 window::emit_error_message(
"Some errors were found during generation of scenario file. Please open " +
NATIVE(fnamepath) +
" to check the errors.\n",
false);
157 selected_scenario_file =
NATIVE(
"");
159 for(
auto& f : scenario_files) {
160 if(f.ident.mod_path == mod_path){
161 selected_scenario_file = f.file_name;
169 if(dep == modb.
name_)
172 for(int32_t i = 0; i < int32_t(mod_list.size()); ++i) {
173 if(seen_indices[i] ==
false && mod_list[i].name_ == dep) {
174 seen_indices[i] =
true;
184 std::vector<bool> seen_indices;
185 seen_indices.resize(mod_list.size());
192 if(a.mod_selected && b.mod_selected) {
193 return transitively_depends_on(b, a);
199 return a.name_ < b.name_;
204int main (
int argc,
char *argv[]) {
213 for (
int i = 1; i < argc; ++i ) {
220 std::string fullpath = argv[ i + 1];
221 int idx = fullpath.rfind(
"/");
222 std::string dir = fullpath.substr(0, idx);
223 if(dir !=
NATIVE(
"mod")) {
226 std::string filename = fullpath.substr(idx + 1);
230 auto root = get_root(fs_root);
236 std::vector<parsers::mod_file> selected_mod;
238 auto content = view_contents(*of);
243 for(int32_t modindex = 0; modindex < int32_t(mod_list.size()); ++modindex){
244 if(mod_list[modindex].name_ == selected_mod[0].name_) {
245 mod_list[modindex].mod_selected =
true;
252 selected_scenario_file =
"development_test_file.bin";
254 window::emit_error_message(
"Development test file not found. Proceeding to generate file, this process may take a few minutes to complete.\n",
false);
257 if(!err.accumulated_errors.empty() || !err.accumulated_warnings.empty()) {
258 auto assembled_msg = std::string(
"You can still play the mod, but it might be unstable\r\nThe following problems were encountered while creating the scenario:\r\n\r\nErrors:\r\n") + err.accumulated_errors +
"\r\n\r\nWarnings:\r\n" + err.accumulated_warnings;
262 selected_scenario_file =
"development_test_file.bin";
294 for (int32_t modindex = 0; modindex < int32_t(mod_list.size()); ++modindex){
295 if(mod_list[modindex].mod_selected){
302 if (selected_scenario_file ==
NATIVE(
"development_test_file.bin")){
307 if (!selected_scenario_file.empty()) {
311 window::emit_error_message(
"Scenario file with selected mods cannot be found. Proceeding to build.\nThis process may take a few minutes to finish.\n",
false);
318 if (!selected_scenario_file.empty()) {
338 std::thread update_thread([&]() { game_state.
game_loop(); });
341 game_state.
quit_signaled.store(
true, std::memory_order_release);
342 update_thread.join();
std::string accumulated_errors
std::string accumulated_warnings
#define assert(condition)
int main(int argc, char *argv[])
native_string produce_mod_path()
void build_scenario_file()
void enforce_list_order()
bool transitively_depends_on_internal(parsers::mod_file const &moda, parsers::mod_file const &modb, std::vector< bool > &seen_indices)
void check_scenario_folder()
bool transitively_depends_on(parsers::mod_file const &moda, parsers::mod_file const &modb)
void find_scenario_file()
native_string to_hex(uint64_t v)
void finish(sys::state &state, bool notify_host)
void init(sys::state &state)
std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
void add_root(file_system &fs, native_string_view root_path)
directory open_directory(directory const &dir, native_string_view directory_name)
native_string extract_state(file_system const &fs)
void restore_state(file_system &fs, native_string_view data)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
native_string get_full_name(directory const &f)
std::optional< file > open_file(directory const &dir, native_string_view file_name)
std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
std::string native_to_utf8(native_string_view data_in)
file_contents view_contents(file const &f)
native_string get_file_name(unopened_file const &f)
directory get_or_create_scenario_directory()
mod_identifier extract_mod_information(uint8_t const *ptr_in, uint64_t file_size)
void write_scenario_file(sys::state &state, native_string_view name, uint32_t count)
void write_save_file(sys::state &state, save_type type, std::string const &name)
bool try_read_scenario_and_save_file(sys::state &state, native_string_view name)
void populate_definitions_map(sys::state &state)
void emit_error_message(std::string const &content, bool fatal)
void create_window(sys::state &game_state, creation_parameters const ¶ms)
std::string native_string
sys::player_name nickname
std::vector< bookmark_definition > bookmark_dates
std::vector< std::string > dependent_mods
sys::mod_identifier ident
network_mode_type network_mode
user_settings_s user_settings
simple_fs::file_system common_fs
sys::checksum_key scenario_checksum
std::atomic< bool > quit_signaled
void load_user_settings()
network::network_state network_state
native_string loaded_scenario_file
void load_scenario_data(parsers::error_handler &err, sys::year_month_day bookmark_date)