The Daily Click ::. Forums ::. Klik Coding Help ::. Turn Based Strategy Movement Help
 

Post Reply  Post Oekaki 
 

Posted By Message

JJames



Registered
  22/04/2005
Points
  15
10th June, 2011 at 08:17:04 -

I'm working on a tactical RPG game, something along the lines of Fire Emblem. I've got a good idea how to work the movement itself and partially, the AI. What I'm having trouble with is, oddly, one of the first things that needs to be done. More specifically, it's the movement prediction that's been bothering me. What I'm specifically trying to do is simulate the area coloration that happens when you check a unit's movement, such as tiles turning blue to signify those tiles are what the unit can walk to. I tried doing this by using the Fast Function object to recursively send out "probes" counting at the unit's movement limits and checking which tiles can be walked on and which can't. Unfortunately, this has had some...unpredictable results:

http://i56.tinypic.com/35d6iko.png

This is mainly caused by a limitation in MMF where there are no "local" variables, where whenever a variable is changed, it's seen across the entire scope. It makes multi-threading events like this impossible, where the function would start with four different probes, each of which would send out three more probes. So I was wondering if there's a single threaded approach to doing a recursive event like this.

Knowing myself, the solution is probably very simple and easy and will make me feel like a total dunce for not thinking of it sooner and letting it stall my work an entire day.

Thanks in advance.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
10th June, 2011 at 10:01:14 -

What's your current algorithm, pseudocode or code for what you are trying to achieve?

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

JJames



Registered
  22/04/2005
Points
  15
10th June, 2011 at 10:19:21 -

It was something along the lines of...

IF User clicked on [Unit]
Run Function "probe" in four cardinal directions passing the direction and how many tiles left to move to it

On Function "probe" IF second number passed was greater then zero AND position of origin + direction given was passable
Create "blue tile" and set position to position of origin + direction and set new position of origin to this position, then Run Function "probe" again

I used basic sub-string comparisons at first since Fast Function only allows single number passing, so I passed both numbers in a string and cleaved the string in half to receive both numbers separated. I started using String Parser 2 along with delimiters to better separate the numbers once things got complicated.

I use MMF2's basic Array object to tell if a tile is passable or not. When the user has clicked on [Unit] then the "index" of the Array object used is set to the position of [Unit] on the map (which isn't necessarily it's real position, it's modified to be accurate according to the Array) and the index is used to pin point the position of the probes. The problem with this is that each time the probe function runs, the index on the Array changes, and since the function is run recursively, by the time the function starts returning, the original position is lost and it starts doing...well, what you see in the screenshot. I tried putting the original position in together with the direction and move points left in the function's string parameter, but that requires it to be read by the String Parser object, which only holds one string at a time, and just reproduces the Array object's problem...

I wasn't really able to find any reasonable way to keep a variable local to a single event line, even when it wasn't being actively processed, due to the way fast functions/loops work, so I came to the conclusion that I was doing it wrong and that I should seek help, and here I am.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
10th June, 2011 at 12:56:03 -

This seems like a difficult and possibly inefficient way to go. I just use one of the pathfinding extensions for this - makes it pretty easy.

I'll see if I can whip up an example, since I've just had an idea for an Advance Wars / X-Com hybrid myself.


 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
10th June, 2011 at 17:06:23 -

Alright, as promised, I have made a quick demo.
It actually turned out to be pretty complicated though - I'm sure I don't normally use this much code. I think it's partly because I normally use a different pathfinding extension, and store more stuff in arrays (instead of alterable values).

Anyway, here it is: http://cid-b1e7ee094271bbda.office.live.com/self.aspx/Public/TBSMove.mfa

It includes 3 terrain types and 2 unit types, but you can easily add more.
Terrain has a varying movement cost, depending on the unit - Forests have a movement cost of 1 for infantry, but 2 for tanks; Plains have a movement cost of 1 for both tanks and infantry; Mountains have a movement cost of 2 for infantry, and are impassable to tanks.

 
n/a

JJames



Registered
  22/04/2005
Points
  15
10th June, 2011 at 22:31:46 -

http://i53.tinypic.com/t4zmna.png

I can't tell you enough how thankful I am for this. Not only was this a learning experience, I have a newfound keenness for the Pathfinding object now; I didn't think it could be used like that. I'll definitely have to look into it more, since I was originally only going to use it for the AI, but after this I think I could really amplify it's usefulness. I also optimized the code a bit by using a second array in place of alterable values, where it looks up the movement class of the unit as the X position and the terrain type of the map tile as the Y position in the extra array and the value in that specific position returns the movement cost for that unit on that map tile. All in all, I got it to work in 7 events, which I think is pretty cool in my book.

I'll confess, while I'm experienced in programming itself, particularly in MMF, math is a big weakness of mine, which is bad considering the kinds of things I often do in MMF. So I probably wouldn't have been able to do such a well optimized good job with this, even if I had known the Pathfinding object could do this. So yeah, thanks a huge, huge bunch!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
10th June, 2011 at 23:37:42 -

No worries. Glad you found it useful.

An array of movement classes is definitely the way to go, like you said.
It sounds like you've done a great job of optimizing the code too - 7 lines is pretty impressive.

Anyway, I'm really looking forward to seeing the game you make with this - it's one of my favourite genres.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click