Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_category_info #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Manual/content/events_and_actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ <h3 id="actions-obtain-info">Obtaining information</h3>
</ul>
</dd>
</dl></td>
</tr>
<th><code>get_onion_info</code></th>
<td><dl>
<dt><code><b>get_onion_info</b> &lt;destination_variable_name&gt; &lt;target&gt; &lt;information&gt; [&lt;argument1&gt;] [&lt;argument2&gt;]</code></dt>
<dd>
Sets the variable &lt;destination_variable_name&gt; to some special information about a given object from the Onion category. The possible target types are:
<ul>
<li><code><b>self</b></code>: The object that the script belongs to.</li>
<li><code><b>focus</b></code>: The object that is currently focused. The action does nothing if none is focused.</li>
<li><code><b>trigger</b></code>: The object that triggered the event. The action does nothing if this is not applicable.</li>
</ul>

The possible data are:
<ul>
<li><code><b>pikmin_amount</b></code>: Requires argument1 and argument2, returns the amount of a specific pikmin type and maturity stored in an onion.
e.g: pikmin_inside "Red Pikmin" 0 for leaf red pikmin inside the onion. </li>
<li><code><b>pikmin_types</b></code>: Requires argument1, returns if a specific type is allowed in the onion. Returns "true" or "false"
e.g: pikmin_types "Red Pikmin" to check if Red Pikmin are allowed in the onion </li>
</ul>
</dd>
</dl></td>
</tr>
</table>

Expand Down
12 changes: 12 additions & 0 deletions Source/source/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
124 changes: 124 additions & 0 deletions Source/source/mob_script_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions Source/source/mob_script_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down