HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

A tile algorithm question

05-06-2003, 03:29 AM#1
Ari
I'm trying to create a movement system for a grid-based (wc3) game. For the sake of argument, let's say that a unit can move 3 squares per turn. The squares can be in any direction, but moving diagonal costs 2 moves (I think this is refered to as a "Manhattan distance" because you walk in blocks). In a simple case, with no obstacles, and with all squares costing the same amount of points to move in to, the allowable squares form a diamond pattern around the unit



However, in cases where certain terrain affects movement (a swamp might cost 2 points to enter, instead of 1), things get more complicated. Also, enemy units can act as obstacles (as can other things), forcing a unit to move around them (and expend more points than it would normally take to reach a destination). In the case where a unit is surrounded on all 4 sides by enemies, movement is normally impossible.

Is there some sort of algorithm that can tell me the "cost" of moving to each square on the playing board (or tell me which squares are separated from the unit by a "wall")? I've done a little research into A* pathfinding, but I'm not sure it's what I'm looking for (I'm also not 100% sure I understand it in the first place). Is there anything else I could use? Thanks for any help.
05-06-2003, 02:30 PM#2
Ari
I more or less have it figured out. I used this algorithm:

make an array of all tiles on the board. Set all to zero except the unit's position which gets the units mvoe radius +1.
loop [move] times:
go through each tile, and if it's not zero, set all surrounding tiles that aren't obstacles to it's value -1 (so a 5 is surrounded by 4's for example).

That more or less solved the prob. I'll try to put up a screenshot of the new system when I make one. If anyobdy's curious about any of this, let me know, and I'll try to explain in more detail.

Edit: here we go - note the restricted movement:
05-15-2003, 05:14 AM#3
Guest
I was wondering what you do in order to change the tiles on the ground. Can you explain me ?
06-02-2003, 02:56 PM#4
Earth-Fury
he editred the splat texture of buldings.