• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

[Solved] Movement Range Issue When Porting to GMS

C

Chaoswizard98

Guest
Hey everyone. I've been working on a Turn Based Tactics game in GM8.1 for a few years now and I'm looking to port it to the newer version of GMS. For the most part, I've solved just about every issue, however one of my scripts no longer works as intended, and only the starting tile ever gets flagged to allow movement.

This code is modified from Mnementh's code at http://gmc.yoyogames.com/index.php?showtopic=368996
/*
arg0 -- starting cell id
arg1 -- movement range
*/

{
var _start, CurrentCharacter, _moverange;
_start = argument0;
CurrentCharacter = argument1;
_moverange = Get_Battle_Stat_Total(CurrentCharacter,'MoveRange');
//Type = CurrentCharacter.MovementType;

var _priorityOpen, _listClosed, _mapDist;
_priorityOpen = ds_priority_create();
_listClosed = ds_list_create();
_mapDist = ds_map_create();

ds_priority_add( _priorityOpen, _start, 0 );
ds_map_add( _mapDist, _start, 0 );
_start.Parent = 0;
_start.Reachable = true;
_start.solid = false;

while ( ds_priority_size( _priorityOpen ) )
{
var _current;
_current = ds_priority_delete_min( _priorityOpen );
ds_list_add( _listClosed, _current );

var _predist;
_predist = ds_map_find_value( _mapDist, _current );
with ( _current.Down )
{
var _dist, TempCost;
TempCost = FindNewCost(x,y,CurrentCharacter,TerrainType,false);
_dist = _predist + TempCost;
if ( ds_list_find_index( _listClosed, id ) == -1 && TempCost && _predist + TempCost <= _moverange )
{
if ( ds_priority_find_priority( _priorityOpen, id ) == 0 )
{
ds_priority_add( _priorityOpen, id, _dist );
ds_map_add( _mapDist, id, _dist );
Parent = _current;
Reachable = true;
solid = false;
}
else
{
if ( _dist < ds_priority_find_priority( _mapDist, id ) )
{
ds_priority_change_priority( _priorityOpen, id, _dist );
ds_map_replace( _mapDist, id, _dist );
Parent = _current;
}
}
}
}
with ( _current.Right )
{
var _dist, TempCost;

TempCost = FindNewCost(x,y,CurrentCharacter,TerrainType,false);


_dist = _predist + TempCost;
if ( ds_list_find_index( _listClosed, id ) == -1 && TempCost && _dist <= _moverange )
{


if ( ds_priority_find_priority( _priorityOpen, id ) == 0 )
{
ds_priority_add( _priorityOpen, id, _dist );
ds_map_add( _mapDist, id, _dist );
Parent = _current;
Reachable = true;
solid = false;
}
else
{
if ( _dist < ds_priority_find_priority( _mapDist, id ) )
{
ds_priority_change_priority( _priorityOpen, id, _dist );
ds_map_replace( _mapDist, id, _dist );
Parent = _current;
}
}


}
}

with ( _current.Up )
{
var _dist, TempCost;
TempCost = FindNewCost(x,y,CurrentCharacter,TerrainType,false);
_dist = _predist + TempCost;
if ( ds_list_find_index( _listClosed, id ) == -1 && TempCost && _dist <= _moverange )
{
if ( ds_priority_find_priority( _priorityOpen, id ) == 0 )
{
ds_priority_add( _priorityOpen, id, _dist );
ds_map_add( _mapDist, id, _dist );
Parent = _current;
Reachable = true;
solid = false;
}
else
{
if ( _dist < ds_priority_find_priority( _mapDist, id ) )
{
ds_priority_change_priority( _priorityOpen, id, _dist );
ds_map_replace( _mapDist, id, _dist );
Parent = _current;
}
}
}
}

with ( _current.Left )
{
var _dist, TempCost;
TempCost = FindNewCost(x,y,CurrentCharacter,TerrainType,false);
_dist = _predist + TempCost;
if ( ds_list_find_index( _listClosed, id ) == -1 && TempCost && _predist + TempCost <= _moverange )
{
if ( ds_priority_find_priority( _priorityOpen, id ) == 0 )
{
ds_priority_add( _priorityOpen, id, _dist );
ds_map_add( _mapDist, id, _dist );
Parent = _current;
Reachable = true;
solid = false;
}
else
{
if ( _dist < ds_priority_find_priority( _mapDist, id ) )
{
ds_priority_change_priority( _priorityOpen, id, _dist );
ds_map_replace( _mapDist, id, _dist );
Parent = _current;
}
}
}
}
}


ds_priority_destroy( _priorityOpen );
ds_list_destroy( _listClosed );
ds_map_destroy( _mapDist );
}

I am familiar with the algorithm behind this function, however I am not familiar at all with how ds_maps work in gamemaker. I know maps were changed between 8.1 and Studio so that is likely what is causing the issue. Can anyone point me in the right direction?

Thanks!
 

TheouAegis

Member
Throw a bunch of show_message()'s in there and make sure the data you fetch from each data structure is the correct data. I'm not sure how maps changed between Studio and GM8 (I saw the warning in the docs but haven't seen any clarification anywhere yet), but I kinda doubt the map structure is the one at fault here.
 
C

Chaoswizard98

Guest
I've seen and solved this issue before, it has to do with ds_priority_find_priority() returning undefined instead of 0 on GMS.

Look for those comparisons ending with == 0 and change them all to is_undefined() checks.
My apologies, I didn't realize that this was already solved. I spent a few days searching for a solution both here and via google and never saw the thread.
Nonetheless, this solved the issue.

Thanks for the help!
 
Top