diff --git a/source/source/area/area.cpp b/source/source/area/area.cpp index 42102624b..e2b0a0b52 100644 --- a/source/source/area/area.cpp +++ b/source/source/area/area.cpp @@ -414,6 +414,7 @@ void area_data::clone(area_data &other) { other.mission.gold_req = mission.gold_req; other.mission.platinum_req = mission.platinum_req; + other.save_data = data_node(this->save_data); other.problems.non_simples.clear(); other.problems.lone_edges.clear(); other.problems.lone_edges.reserve(problems.lone_edges.size()); diff --git a/source/source/area/area.h b/source/source/area/area.h index 69be29a97..041158ee0 100644 --- a/source/source/area/area.h +++ b/source/source/area/area.h @@ -257,6 +257,9 @@ struct area_data : public content { //Path to the user data folder for this area. string user_data_path; + + //SaveDataNode for this area. + data_node save_data; //--- Function declarations --- diff --git a/source/source/const.h b/source/source/const.h index e5a6c07ec..0a841d310 100644 --- a/source/source/const.h +++ b/source/source/const.h @@ -140,6 +140,9 @@ namespace FILE_NAMES { //Area main data file. const string AREA_MAIN_DATA = "data.txt"; +//Area save data file. +const string AREA_SAVE_DATA = "save.txt"; + //Area geometry file. const string AREA_GEOMETRY = "geometry.txt"; diff --git a/source/source/content_manager.cpp b/source/source/content_manager.cpp index 14a4ef2fb..1bc2a7f8e 100644 --- a/source/source/content_manager.cpp +++ b/source/source/content_manager.cpp @@ -227,6 +227,12 @@ void content_manager::reload_packs() { */ void content_manager::unload_current_area(CONTENT_LOAD_LEVEL level) { if(!game.cur_area_data) return; + if (level == CONTENT_LOAD_LEVEL_FULL){ + + string save_data_file_path = game.cur_area_data->user_data_path + + "/" + FILE_NAMES::AREA_SAVE_DATA; + game.cur_area_data->save_data.save_file(save_data_file_path); + } game.cur_area_data->clear(); delete game.cur_area_data; game.cur_area_data = nullptr; diff --git a/source/source/content_type_manager.cpp b/source/source/content_type_manager.cpp index 9192af4a2..0bf206a79 100644 --- a/source/source/content_type_manager.cpp +++ b/source/source/content_type_manager.cpp @@ -153,6 +153,17 @@ bool area_content_manager::load_area( //Main data. if(game.perf_mon) game.perf_mon->start_measurement("Area -- Data"); + string save_data_file_path = area_ptr->user_data_path + + "/" + FILE_NAMES::AREA_SAVE_DATA; + if (file_exists(save_data_file_path)){ + data_node save_file= load_data_file(save_data_file_path); + if(!save_file.file_was_opened) return false; + area_ptr->save_data = save_file; + }else{ + data_node save_file = data_node(); + area_ptr->save_data = save_file; + + } area_ptr->load_main_data_from_data_node(&data_file, level); area_ptr->load_mission_data_from_data_node(&data_file); if(game.perf_mon) game.perf_mon->finish_measurement(); diff --git a/source/source/init.cpp b/source/source/init.cpp index 28b34d669..8feb607e8 100644 --- a/source/source/init.cpp +++ b/source/source/init.cpp @@ -1524,7 +1524,34 @@ void init_mob_actions() { mob_action_runners::turn_to_target, mob_action_loaders::turn_to_target ); + + reg_param("data", MOB_ACTION_PARAM_STRING, false, false); + reg_param("save section", MOB_ACTION_PARAM_STRING, false, false); + reg_action( + MOB_ACTION_WRITE_TO_SAVE, + "write_to_save", + mob_action_runners::write_to_save, + nullptr + ); + + reg_param("destination var name", MOB_ACTION_PARAM_STRING, true, false); + reg_param("save section", MOB_ACTION_PARAM_STRING, false, false); + reg_action( + MOB_ACTION_READ_FROM_SAVE, + "read_from_save", + mob_action_runners::read_from_save, + nullptr + ); + + reg_param("destination var name", MOB_ACTION_PARAM_STRING, true, false); + reg_param("save section", MOB_ACTION_PARAM_STRING, false, false); + reg_action( + MOB_ACTION_CHECK_FOR_SAVE, + "check_for_save", + mob_action_runners::check_for_save, + nullptr + ); #undef param #undef reg_action diff --git a/source/source/mob_script_action.cpp b/source/source/mob_script_action.cpp index f3b15fd49..8ac61848c 100644 --- a/source/source/mob_script_action.cpp +++ b/source/source/mob_script_action.cpp @@ -2331,6 +2331,45 @@ void mob_action_runners::turn_to_target(mob_action_run_data &data) { } } +void mob_action_runners::write_to_save(mob_action_run_data &data) { + string data2 = data.args[0]; + string section = data.args[1]; + data_node* section_data; + size_t has_child =game.cur_area_data->save_data.get_nr_of_children_by_name(section); + if (has_child > 0){ + section_data = game.cur_area_data->save_data.get_child_by_name(section); + section_data->value = data2; + } + else{ + game.cur_area_data->save_data.add(new data_node(section,data2)); + } +} + +void mob_action_runners::read_from_save(mob_action_run_data &data) { + string dest_var = data.args[0]; + string section = data.args[1]; + + size_t has_child =game.cur_area_data->save_data.get_nr_of_children_by_name(section); + if (has_child > 0){ + data.m->set_var(dest_var,game.cur_area_data->save_data.get_child_by_name(section)->value); + }else{ + game.errors.report("Save data section("+ section+") does not exist! please check for it or create it first!"); + } + +} + +void mob_action_runners::check_for_save(mob_action_run_data &data) { + string dest_var = data.args[0]; + string section = data.args[1]; + size_t has_child =game.cur_area_data->save_data.get_nr_of_children_by_name(section); + if (has_child > 0){ + data.m->set_var(dest_var,b2s(true)); + }else{ + + data.m->set_var(dest_var,b2s(false)); + } + +} /** * @brief Confirms if the "if", "else", "end_if", "goto", and "label" actions in diff --git a/source/source/mob_script_action.h b/source/source/mob_script_action.h index 04425993d..43987c934 100644 --- a/source/source/mob_script_action.h +++ b/source/source/mob_script_action.h @@ -273,6 +273,15 @@ enum MOB_ACTION { //Turn towards a target. MOB_ACTION_TURN_TO_TARGET, + //Write A value to Save Data + MOB_ACTION_WRITE_TO_SAVE, + + //Turn towards a target. + MOB_ACTION_READ_FROM_SAVE, + + //Turn towards a target. + MOB_ACTION_CHECK_FOR_SAVE, + //Total amount of mob actions. N_MOB_ACTIONS, @@ -757,6 +766,10 @@ void throw_focus(mob_action_run_data &data); void turn_to_absolute(mob_action_run_data &data); void turn_to_relative(mob_action_run_data &data); void turn_to_target(mob_action_run_data &data); + +void write_to_save(mob_action_run_data &data); +void read_from_save(mob_action_run_data &data); +void check_for_save(mob_action_run_data &data); }; diff --git a/source/vs_code/c_cpp_properties.json b/source/vs_code/c_cpp_properties.json deleted file mode 100644 index 4999d4212..000000000 --- a/source/vs_code/c_cpp_properties.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**", - "/usr/include/allegro5/**" - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "c11", - "cppStandard": "c++11", - "intelliSenseMode": "gcc-x64", - "compilerArgs": [ - "-std=c++0x", - "-rdynamic", - "-D_GLIBCXX_USE_CXX11_ABI=0", - "-lm `pkg-config --libs allegro-5 allegro_main-5 allegro_acodec-5 allegro_audio-5 allegro_color-5 allegro_dialog-5 allegro_font-5 allegro_image-5 allegro_primitives-5`" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/source/vs_code/launch.json b/source/vs_code/launch.json deleted file mode 100644 index 140311b0b..000000000 --- a/source/vs_code/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Pikifen with GDB", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/pikifen", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable GDB pretty-printing.", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "Build Pikifen - Debug" - } - ] -} \ No newline at end of file diff --git a/source/vs_code/tasks.json b/source/vs_code/tasks.json deleted file mode 100644 index f8b5060f0..000000000 --- a/source/vs_code/tasks.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "shell", - "label": "Build Pikifen - Debug", - "command": "make", - "args": [ - "debug", - "-j6", - "-f", - "source/gnu_make/makefile" - ], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "echo": true - }, - "detail": "Use make to compile the whole project in a debug build." - }, - { - "type": "shell", - "label": "Build Pikifen - Release", - "command": "make", - "args": [ - "-j6", - "-f", - "source/gnu_make/makefile" - ], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [ - "$gcc" - ], - "presentation": { - "reveal": "always", - "echo": true - }, - "detail": "Use make to compile the whole project in a release build." - }, - { - "type": "shell", - "label": "Clean Pikifen", - "command": "make", - "args": [ - "clean", - "-f", - "source/gnu_make/makefile" - ], - "options": { - "cwd": "${workspaceFolder}" - }, - "problemMatcher": [ - "$gcc" - ], - "presentation": { - "reveal": "always", - "echo": true - }, - "detail": "Use make to clean the project." - }, - { - "label": "Rebuild Pikifen (Debug)", - "dependsOn": [ - "Clean Pikifen", - "Build Pikifen - Debug" - ], - "dependsOrder": "sequence", - "problemMatcher": [ - "$gcc" - ], - "detail": "Use make to clean the project, and then to compile in a debug build." - } - ] -}