Corrected getfreecell command for flag 2 (#4491)

* Little simplification of the code
* Extends the target type for flag 2 to match the docs (target applicable for player, monster, pet, homunculus)
Thanks to @Lemongrass3110
This commit is contained in:
Atemo 2020-02-04 19:58:04 +01:00 committed by GitHub
parent 99f42b26a4
commit ac0d17f4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19138,37 +19138,43 @@ BUILDIN_FUNC(setcell)
*/
BUILDIN_FUNC(getfreecell)
{
const char *mapn = script_getstr(st, 2), *name;
char prefix;
struct map_session_data *sd;
int64 num;
const char *mapn = script_getstr(st, 2), *name_x, *name_y;
struct script_data
*data_x = script_getdata(st, 3),
*data_y = script_getdata(st, 4);
struct block_list* bl = map_id2bl(st->rid);
struct map_session_data *sd = nullptr;
int16 m, x = 0, y = 0;
int rx = -1, ry = -1, flag = 1;
sd = map_id2sd(st->rid);
if (!data_isreference(script_getdata(st, 3))) {
if (!data_isreference(data_x)) {
ShowWarning("script: buildin_getfreecell: rX is not a variable.\n");
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
if (!data_isreference(script_getdata(st, 4))) {
if (!data_isreference(data_y)) {
ShowWarning("script: buildin_getfreecell: rY is not a variable.\n");
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
name_x = reference_getname(data_x),
name_y = reference_getname(data_y);
if (is_string_variable(reference_getname(script_getdata(st, 3)))) {
if (is_string_variable(name_x)) {
ShowWarning("script: buildin_getfreecell: rX is a string, must be an INT.\n");
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
if (is_string_variable(name_y)) {
ShowWarning("script: buildin_getfreecell: rY is a string, must be an INT.\n");
return SCRIPT_CMD_FAILURE;
}
if (is_string_variable(reference_getname(script_getdata(st, 4)))) {
ShowWarning("script: buildin_getfreecell: rY is a string, must be an INT.\n");
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
if (not_server_variable(*name_x) || not_server_variable(*name_y)) {
if (!script_rid2sd(sd)) {
if (not_server_variable(*name_x))
ShowError( "buildin_getfreecell: variable '%s' for mapX is not a server variable, but no player is attached!", name_x );
else
ShowError( "buildin_getfreecell: variable '%s' for mapY is not a server variable, but no player is attached!", name_y );
return SCRIPT_CMD_FAILURE;
}
}
if (script_hasdata(st, 5))
@ -19186,42 +19192,15 @@ BUILDIN_FUNC(getfreecell)
if (script_hasdata(st, 9))
flag = script_getnum(st, 9);
if (sd && strcmp(mapn, "this") == 0)
m = sd->bl.m;
if (bl && strcmp(mapn, "this") == 0)
m = bl->m;
else
m = map_mapname2mapid(mapn);
map_search_freecell(NULL, m, &x, &y, rx, ry, flag);
map_search_freecell(bl, m, &x, &y, rx, ry, flag);
// Set MapX
num = st->stack->stack_data[st->start + 3].u.num;
name = get_str(num&0x00ffffff);
prefix = *name;
if (not_server_variable(prefix)){
if( !script_rid2sd(sd) ){
ShowError( "buildin_getfreecell: variable '%s' for mapX is not a server variable, but no player is attached!", name );
return SCRIPT_CMD_FAILURE;
}
}else
sd = NULL;
set_reg_num( st, sd, num, name, x, script_getref( st, 3 ) );
// Set MapY
num = st->stack->stack_data[st->start + 4].u.num;
name = get_str(num&0x00ffffff);
prefix = *name;
if (not_server_variable(prefix)){
if( !script_rid2sd(sd) ){
ShowError( "buildin_getfreecell: variable '%s' for mapY is not a server variable, but no player is attached!", name );
return SCRIPT_CMD_FAILURE;
}
}else
sd = NULL;
set_reg_num( st, sd, num, name, y, script_getref( st, 4 ) );
set_reg_num(st, sd, reference_getuid(data_x), name_x, x, data_x->ref);
set_reg_num(st, sd, reference_getuid(data_y), name_y, y, data_y->ref);
return SCRIPT_CMD_SUCCESS;
}