Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calin Leafshade on Fri 18/02/2011 04:07:03

Title: GetWalkbehindAt?
Post by: Calin Leafshade on Fri 18/02/2011 04:07:03
Is there a GetWalkBehindAtRoom function? Or something similar.

Can't find anything in the manual but it seems like an odd thing to leave out.
Title: Re: GetWalkbehindAt?
Post by: Hernald on Mon 25/07/2011 00:59:43
I would be interested in a work-around for this as well.
Title: Re: GetWalkbehindAt?
Post by: Khris on Mon 25/07/2011 04:22:51
I'd put the current Walkbehind map in a sprite and use GetPixel.
Not terribly elegant but seems to be the only way.
Title: Re: GetWalkbehindAt?
Post by: monkey0506 on Mon 25/07/2011 05:09:08
You could use some script to determine whether there was a walkbehind, but there's not currently a way to check which:

bool IsAnyWalkbehindAtScreenXY(int x, int y)
{
 int px = player.x;
 int py = player.y;
 int pb = player.Baseline;
 bool pi = player.IgnoreWalkbehinds;
 player.x = x + GetViewportX();
 player.y = y + GetViewportY();
 player.Baseline = 1;
 player.IgnoreWalkbehinds = false;
 bool gv[] = new bool[Game.GUICount]; // the potential overallocation here is more efficient than constantly reallocating
 GUI *gp[] = new GUI[Game.GUICount];
 int gc = 0;
 bool ov[] = new bool[Room.ObjectCount];
 Object *op[] = new Object[Room.ObjectCount];
 int oc = 0;
 GUI *gat = GUI.GetAtScreenXY(x, y);
 while (gat != null)
 {
   gv[gc] = gat.Visible;
   gp[gc] = gat;
   gc++;
   gat = GUI.GetAtScreenXY(x, y);
 }
 LocationType lt = GetLocationType(x, y);
 while (lt == eLocationObject)
 {
   Object *oat = Object.GetAtScreenXY(x, y);
   ov[oc] = oat.Visible;
    op[oc] = oat;
   oc++;
   oat.Visible = false;
   lt = GetLocationType(x, y);
 }
 int i = 0;
 while ((i < gc) && (i < oc))
 {
   if (i < gc) gp[i].Visible = gv[i];
   if (i < oc) op[i].Visible = ov[i];
   i++;
 }
 player.x = px;
 player.y = py;
 player.Baseline = pb;
 player.IgnoreWalkbehinds = pi;
 return (lt != eLocationCharacter);
}


I haven't actually tested this (:=) but my general line of thinking here is that if the player is actually standing at the specified coordinates with no GUIs or Objects in front of him, and not ignoring walkbehinds, then GetLocationType should be able to tell us whether or not he is behind a walkbehind.

It has some caveats such as only working with screen coordinates (because there's no GetLocationTypeAtRoomXY), and it might explode your game if you try and check it while the player is actually moving...but depending on your purposes this might be sufficient?

Khris' way is probably more elegant than mine, and would actually allow checking IDs instead of just checking existence, but mine was more fun to come up with! :P
Title: Re: GetWalkbehindAt?
Post by: Hernald on Mon 25/07/2011 10:18:23
Thanks for your responses. This seems like the time for me to investigate DrawingSurface functions and properties.  :)
Title: Re: GetWalkbehindAt?
Post by: Wyz on Mon 25/07/2011 14:02:50
If I remember correctly the walkbehind maps are exposed to the plugin API, but again not a very elegant solution. Khis' solution sound like to most elegant so far.