• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Detecting/limiting traveled distance

Status
Not open for further replies.
Hey folks

I am using a turn based combat system in a map of mine.
The turn rotation and actions are working properly but I am having problems with the movement system.

The base idea is that mana works as action points and is consumed when attacking, using item, accessing the inventory and so on.
But I also need it to work for movement.

An example:
A unit has 10 mana points when it becomes his turn. In case of movement he can move 100 units per mana point, which equals to 1000 units if all mana points are to used on movement alone.
But I somehow need to detect when a 100 unit breakpoint has been reached, and at the same time not let the unit stop at odd numbers like 140 units.

I hope you get what I mean.

For now I just need some ideas, so if you have any please share.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,182
I think I would do something like this..

1. when unit is issued to move a distance you add the unit to a unit group( I don't know how you do this in your case but you said that part was working.) And store the start location in a variable, hashtable would work fine here.

2. in a another trigger we add a fast loop (0.03 I suppose) and pick every unit in that group of yours. Check distance between current position and the start pos. Then you can remove mana as you wish.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
When unit has been given a "turn", you can catch that moment and register it into your movement system aka add to specific linked list.
Now, simple struct type, periodic trigger and some math.

When unit is added into linked list via register, within callback function, after each expiration of such timer calculate distance between current position of unit and position from previous expiration via:
JASS:
    local real dx
    local real dy
    local thistype this = thistype(0).next // head of linked list

    loop
        exitwhen this == 0

        set dx = prev_x[this] - GetUnitX(this.unit)
        set dy = prev_y[this] - GetUnitY(this.unit)
        set this.distance = this.distance + (dx * dx + dy * dy)

        set prev_x[this] = GetUnitX(this.unit)
        set prev_y[this] = GetUnitY(this.unit)

        if ( this.distance /* perform your check */ ) then
            // stuff
        endif

        set this = this.next
    endloop
Unregister your unit (remove from linked list) when it's mana hit 0. This can also be done in callback function.
 
@Chaosy: That was also my initial thought. And I guess I would just change owner of the unit as long as it is moving so the player cannot screw up the movement.

@Bannar: I'm not skilled in Jass unfortunately but isn't you suggestion kinda like the one Chaosy proposed? making sure here.
Btw. I always think Baranar's Star when I see you name ;)
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Wouldn't it be better to just move the unit via trigger and play the walk animation, a custom ability replaces the move, attack-move and patrol command?
 

Attachments

  • TowerCautionRing.zip
    88.5 KB · Views: 34
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
To prevent odd-mana movements:

When an order is given, use modulo (distance, 100) to get the remainder distance after division by 100. Now subtract this from your distance, and alter the unit to move to this location instead, which will have a distance as a multiple of 100. In its simplest implementation, this method might give bad results when navigating tight mazes.
 
Then you'll have to make your own pathfinding

tumblr_n2y9h4ih2W1t6cr7go1_400.gif
 
Alright. For the time being I'll go with my own and Chaosy's idea.
Since Bannar hasn't elaborated I'll skip that idea (wink wink Bannar).

@chobibo: Thanks for attaching the model, but I'm am not going to use it. The exclamation marks and the general look does not appeal to me. If it had been a simple red circle I would have used it.

If anyone comes up with new idea please post.
Thanks to all who replied.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
I've thought of a neat way to accurately show the chosen path:
You make an invisible dummy unit with high speed (use the Move Speed X system to get it up to ~800), give it the same order and make an SFX every 100 distance traveled by the dummy.

There will be a bit of a delay, but you can use this to your advantage by having movement confirmation.

If you've ever played Heroes of Might and Magic, for example, you would have to click a location on the ground twice to move.
 
I've thought of a neat way to accurately show the chosen path:
You make an invisible dummy unit with high speed (use the Move Speed X system to get it up to ~800), give it the same order and make an SFX every 100 distance traveled by the dummy.

There will be a bit of a delay, but you can use this to your advantage by having movement confirmation.

If you've ever played Heroes of Might and Magic, for example, you would have to click a location on the ground twice to move.

HOMM is a beautiful game and I could certainly use a modified version of the movement system from there.
An interesting idea, I'll see if I can make it work. Thanks! :)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I've thought of a neat way to accurately show the chosen path:
You make an invisible dummy unit with high speed (use the Move Speed X system to get it up to ~800), give it the same order and make an SFX every 100 distance traveled by the dummy.

There will be a bit of a delay, but you can use this to your advantage by having movement confirmation.

If you've ever played Heroes of Might and Magic, for example, you would have to click a location on the ground twice to move.

very nice solution, and it can also create nice effect of the positions moving outwards.

I have tested Purge's system, and it works fine until like 1100 move speed, at which point the unit has chance to actually jump over the lowest-sized blocker
 
it seems funny that it starts at 2 :D but yea it is nice and well made

Heh yeah <prototype> :p
But thanks. It was actually easier than I had expected.
Obviously there are some things I need to correct eg. what you bring up with the counter starting at 2.

Also. I'm not sure I'll keep the movement indicator unit (the red one). I'm thinking of making it invisible.
And I haven't imported the +speed system yet.

Thought I am quite satisfied with the current outcome.

Edit:

Behold! Version 2.

When the Move ability is used on anything else than a Point Indicator the system will generate the path to the targeted location.
The number of indicators are determined by the remaining Action Points (mana) of the casting unit.
When the Move ability is used on one of these Point Indicators the unit will move to that location. The numbers above the indicators shows how many Action Points will be used.

 
Level 23
Joined
Apr 16, 2012
Messages
4,041
one suggestion, if it is single player, or even multiplayer with <12 players, make the not used player slot friendly to everything with sight and everything(unless you have team vs team) so that it doesnt go red, but only yellow(considering it to be ally instead of enemy)
 
one suggestion, if it is single player, or even multiplayer with <12 players, make the not used player slot friendly to everything with sight and everything(unless you have team vs team) so that it doesnt go red, but only yellow(considering it to be ally instead of enemy)

Absolutely. I have already thought of this. But I didn't see it a necessity for the video :)
 
Looking good.

Suggestion: Use the Circle of power model for the move indicator. The first few steps will be green, and beyond the point where you won't have enough mana for an attack, they can be yellow/orange. Red can be used for the furthest/last move point.

Aye. As with what edo494 said about alliances the indicators in the video are also just placeholders. I was considering Circle's of Power.
The color idea is pretty nice. I'll try to incorporate that.

Edit:
Btw. can you link to that +speed system?
 
Status
Not open for further replies.
Top