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

add divide to COMPUTE_FLAG #2972

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/lvl_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum ScriptOperator {
SOpr_INCREASE,
SOpr_DECREASE,
SOpr_MULTIPLY,
SOpr_DIVIDE,
SOpr_SQUARE,
};

enum {
Expand Down
10 changes: 6 additions & 4 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,12 @@ const struct NamedCommand campaign_flag_desc[] = {
};

const struct NamedCommand script_operator_desc[] = {
{"SET", 1},
{"INCREASE", 2},
{"DECREASE", 3},
{"MULTIPLY", 4},
{"SET", SOpr_SET},
{"INCREASE", SOpr_INCREASE},
{"DECREASE", SOpr_DECREASE},
{"MULTIPLY", SOpr_MULTIPLY},
{"DIVIDE", SOpr_DIVIDE},
{"SQUARE", SOpr_SQUARE},
{NULL, 0},
};

Expand Down
15 changes: 13 additions & 2 deletions src/lvl_script_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,19 @@ void script_process_value(unsigned long var_index, unsigned long plr_range_id, l
long current_flag_val = get_condition_value(i, flag_type, val3);
long computed = sum;
if (operation == SOpr_INCREASE) computed = current_flag_val + sum;
if (operation == SOpr_DECREASE) computed = current_flag_val - sum;
if (operation == SOpr_MULTIPLY) computed = current_flag_val * sum;
else if (operation == SOpr_DECREASE) computed = current_flag_val - sum;
else if (operation == SOpr_MULTIPLY) computed = current_flag_val * sum;
else if (operation == SOpr_SQUARE) computed = sum * sum;
else if (operation == SOpr_DIVIDE)
{
if(sum == 0)
{
WARNMSG("COMPUTE_FLAG tried to divide by 0.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a player creates this in a next_command_reusable, it will still crash the game, but with a 30 minute delay until the log file is too large.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a player creates this in a next_command_reusable, it will still crash the game, but with a 30 minute delay until the log file is too large.

so this need a check to deallocate the script value it so it shows only one time in the log?

return;
}

computed = current_flag_val / sum;
}
SCRIPTDBG(7,"Changing player%d's %d flag from %d to %d based on flag of type %d.", i, val3, current_flag_val, computed, src_flag_type);
set_variable(i, flag_type, val3, computed);
}
Expand Down