diff --git a/Manual/content/events_and_actions.html b/Manual/content/events_and_actions.html index e2d9dabd2..36b16483d 100644 --- a/Manual/content/events_and_actions.html +++ b/Manual/content/events_and_actions.html @@ -644,6 +644,27 @@

Obtaining information

+ + get_onion_info +
+
get_onion_info <destination_variable_name> <target> <information> [<argument1>] [<argument2>]
+
+ Sets the variable <destination_variable_name> to some special information about a given object from the Onion category. The possible target types are: + + + The possible data are: + +
+
diff --git a/Source/source/init.cpp b/Source/source/init.cpp index 5db6540d4..06ef1aee9 100644 --- a/Source/source/init.cpp +++ b/Source/source/init.cpp @@ -995,6 +995,18 @@ void init_mob_actions() { mob_action_runners::get_mob_info, mob_action_loaders::get_mob_info ); + + reg_param("destination var name", MOB_ACTION_PARAM_STRING, true, false); + reg_param("target", MOB_ACTION_PARAM_STRING, true, false); + reg_param("info", MOB_ACTION_PARAM_STRING, true, false); + reg_param("argument1", MOB_ACTION_PARAM_STRING, true, true); + reg_param("argument2", MOB_ACTION_PARAM_STRING, true, true); + reg_action( + MOB_ACTION_GET_ONION_INFO, + "get_onion_info", + mob_action_runners::get_onion_info, + mob_action_loaders::get_onion_info + ); reg_param("destination var name", MOB_ACTION_PARAM_STRING, true, false); reg_param("minimum value", MOB_ACTION_PARAM_FLOAT, false, false); diff --git a/Source/source/mob_script_action.cpp b/Source/source/mob_script_action.cpp index 7b0fb2780..f41baf16c 100644 --- a/Source/source/mob_script_action.cpp +++ b/Source/source/mob_script_action.cpp @@ -396,6 +396,43 @@ bool mob_action_loaders::get_mob_info(mob_action_call &call) { return true; } +/** + * @brief Loading code for the info getting script actions. + * + * @param call Mob action call that called this. + * @return Whether it succeeded. + */ +bool mob_action_loaders::get_onion_info(mob_action_call& call) { + + if (call.args[1] == "self") { + call.args[1] = i2s(MOB_ACTION_GET_INFO_TARGET_SELF); + } + else if (call.args[1] == "focus") { + call.args[1] = i2s(MOB_ACTION_GET_INFO_TARGET_FOCUS); + } + else if (call.args[1] == "trigger") { + call.args[1] = i2s(MOB_ACTION_GET_INFO_TARGET_TRIGGER); + } + else { + report_enum_error(call, 1); + return false; + } + + if (call.args[2] == "pikmin_inside") { + call.args[2] = i2s(MOB_ACTION_GET_ONION_INFO_PIKMIN_INSIDE); + } + else if (call.args[2] == "pikmin_types") { + call.args[2] = i2s(MOB_ACTION_GET_ONION_INFO_PIKMIN_TYPES); + } + else { + call.custom_error = + "Unknown info type \"" + call.args[0] + "\"! " + "Try using \"get_event_info\" or \"get_area_info\"."; + return false; + } + + return true; +} /** * @brief Loading code for the hold focused mob mob script action. @@ -1333,6 +1370,93 @@ void mob_action_runners::get_mob_info(mob_action_run_data &data) { } } +/** + * @brief Code for the mob info obtaining mob script action. + * + * @param data Data about the action call. + */ +void mob_action_runners::get_onion_info(mob_action_run_data& data) { + onion* target_mob = nullptr; + MOB_ACTION_GET_INFO_TARGET tt = + (MOB_ACTION_GET_INFO_TARGET)s2i(data.args[1]); + + switch (tt) { + case MOB_ACTION_GET_INFO_TARGET_SELF: { + target_mob = (onion*)data.m; + break; + } case MOB_ACTION_GET_INFO_TARGET_FOCUS: { + if (!data.m->focused_mob) return; + target_mob = (onion*)data.m->focused_mob; + break; + } case MOB_ACTION_GET_INFO_TARGET_TRIGGER: { + target_mob = (onion*)get_trigger_mob(data); + } + } + + if (!target_mob) return; + if (target_mob->type->category->name != "Onion") return; + + string* var = &(data.m->vars[data.args[0]]); + MOB_ACTION_GET_ONION_INFO_TYPE t = + (MOB_ACTION_GET_ONION_INFO_TYPE)s2i(data.args[2]); + + switch (t) { + case MOB_ACTION_GET_ONION_INFO_PIKMIN_INSIDE: { + string ttt = (data.args[3]); + for (std::size_t i = 0; i < ttt.size(); i++) + { + if (ttt[i] == '_') + { + ttt[i] = ' '; + } + } + int tttt = s2i(data.args[4]); + *var = "0"; + //Find the pikmin_type based on the name + auto it = game.mob_types.pikmin.find(ttt); + if (it == game.mob_types.pikmin.end()) { + *var = "0"; break; + } + pikmin_type* piktype = it->second; + //Get the amount of pikmin of the given maturity size. + size_t amount = 0; + for (size_t i = 0; i < target_mob->nest->nest_type->pik_types.size(); ++i) { + if (target_mob->nest->nest_type->pik_types[i] == piktype) { + amount = target_mob->nest->pikmin_inside[i][tttt]; + *var = i2s(amount); + break; + } + } + break; + } case MOB_ACTION_GET_ONION_INFO_PIKMIN_TYPES: { + string ttt = (data.args[3]); + for (std::size_t i = 0; i < ttt.size(); i++) + { + if (ttt[i] == '_') + { + ttt[i] = ' '; + } + } + //Find the pikmin_type based on the name + auto it = game.mob_types.pikmin.find(ttt); + if (it == game.mob_types.pikmin.end()) { + *var = "false"; break; + } + pikmin_type* piktype = it->second; + //Set the default value as False. + *var = "false"; + //If there's a match between the types allowed and our type, set var to "true". + for (size_t i = 0; i < target_mob->nest->nest_type->pik_types.size(); ++i) { + if (target_mob->nest->nest_type->pik_types[i] == piktype) { + *var = "true"; + break; + } + } + break; + + } + } +} /** * @brief Code for the decimal number randomization mob script action. diff --git a/Source/source/mob_script_action.h b/Source/source/mob_script_action.h index 25e1a1e0d..660066dec 100644 --- a/Source/source/mob_script_action.h +++ b/Source/source/mob_script_action.h @@ -80,6 +80,9 @@ enum MOB_ACTION { //Get information about a mob. MOB_ACTION_GET_MOB_INFO, + + //Get information about a mob of the onion category. + MOB_ACTION_GET_ONION_INFO, //Get a random decimal number. MOB_ACTION_GET_RANDOM_DECIMAL, @@ -458,6 +461,15 @@ enum MOB_ACTION_GET_MOB_INFO_TYPE { }; +//Get onion info action info types. +enum MOB_ACTION_GET_ONION_INFO_TYPE { + //Get Pikmin inside. + MOB_ACTION_GET_ONION_INFO_PIKMIN_INSIDE, + + //Get Pikmin allowed in the onion. + MOB_ACTION_GET_ONION_INFO_PIKMIN_TYPES, + +}; //Moving action sub-types. enum MOB_ACTION_MOVE_TYPE { @@ -702,6 +714,7 @@ void get_event_info(mob_action_run_data &data); void get_area_info(mob_action_run_data &data); void get_floor_z(mob_action_run_data &data); void get_mob_info(mob_action_run_data &data); +void get_onion_info(mob_action_run_data& data); void get_focus_var(mob_action_run_data &data); void get_random_decimal(mob_action_run_data &data); void get_random_int(mob_action_run_data &data); @@ -776,6 +789,7 @@ bool focus(mob_action_call &call); bool get_area_info(mob_action_call &call); bool get_event_info(mob_action_call &call); bool get_mob_info(mob_action_call &call); +bool get_onion_info(mob_action_call &call); bool hold_focus(mob_action_call &call); bool if_function(mob_action_call &call); bool move_to_target(mob_action_call &call);