Categories > Board > rex_slg_movement

Introduction

Get move-able area, or moving path between two chess/tiles on an orthogonal or isometric, or hexagonal board.

Links


Categories > Board > rex_slg_movementIntroductionLinksDependenceUsagePrepareGet moveable areaMain flowFlow chart of getting costFlow chart of filter functionShuffle neighborsCache costGet moving pathMain flowFlow chart of getting costPath modeGet shortest pathGet shorter pathExact or nearestMove chess alone pathUse case of filter function and cost functionNo overlapped with other chessPick enemiesNo moving across enemiesMore samplesWrapAccumulated costFlood fillMore samplesMove on tilemap

Dependence

Usage

Prepare

This plugin picks tiles of move-able area or moving path into a group. therefor rex_board and rex_ginstgroup objects should be put into project first.

Get moveable area

Main flow

Flood fillYesNoNoYesRemaining moving point =parameter 'Moving points'Get a neighbor---Property: Shuffle neighborsGet cost of this neighbor,from parameter or eventRemaining moving point =Remaining moving point - costRemaining moving point >= 0Push this neighbor into stack,Move to this neighbor----Add the neighbor tile into result groupStack is emptyPop-up stackBack to previous tileAction:Get moveable areaFilter result----+Condition:On filterResult groupGroup in InstGroup

Flow chart of getting cost

Cost functionNoYesNoYesNoYesProperty: Cache costGet cost from events----+Condition:On costCostat (TileX, TileY) is in cache?Cost =cache valueChess: Expression:ChessUIDStart from Expression:StartTileUIDat (Expression:StartX, Expression:StartY, 0)----Move from tile:Expression:PreTileUIDat (Expression:PreTileX, Expression:PreTileY, 0)accumulation cost: Expression:PreTilePathCost----To neighbor tile:Expression:TileUIDat (Expression:TileX, Expression:TileY, 0)-Action:Set cost----value >= 0, orExpression:BLOCKINGCost= Return valueAdd cost to cacheGet cost of tileparameter 'Moving cost'is a string?Constant cost =parameter 'Moving cost'

Flow chart of filter function

For each tile in result groupNoYes+Condition:On filterTile:Expression:TileUIDat (Expression:TileX, Expression:TileY)-Action:Append filter result....Result group ofmove-able area----UID of tilesparameter 'Filter'is a string?Result group

Get move-able area

There are 5 parameters in action

Shuffle neighbors

Sample capx If property Shuffle neighbors is set to Yes, the order of visited neighbors will be random, i.e. the order of visited nodes is not the same for each request.

Here is the order of tiles in result group with parameters

rex_slg_movement_neighbor_order

Cache cost

If property Cache cost is set to Yes, Condition:On cost will only be triggered once for each tile in a request.

Get moving path

Main flow

Path findingNoYesNoNoYesYesRemaining moving point =parameter 'Moving points'A* mode andat target tile?Get a neighbor---Property: Shuffle neighborsGet cost of this neighbor,from parameter or eventRemaining moving point =Remaining moving point - costRemaining moving point >= 0, orMoving points = Expression:INFINITYPush this neighbor into stack,Move to this neighbor----Add this neighbor tile into candidateStack is emptyPop-up stackBack to previous tileAction:Get moving pathPick a path

Flow chart of getting cost

Cost functionNoYesNoYesNoYesProperty: Cache costGet cost from events----+Condition:On costCostat (TileX, TileY) is in cache?Cost =cache valueChess: Expression:ChessUIDStart from Expression:StartTileUIDat (Expression:StartX, Expression:StartY, 0)----Move from tile:Expression:PreTileUIDat (Expression:PreTileX, Expression:PreTileY, 0)accumulation cost: Expression:PreTilePathCost----To neighbor tile:Expression:TileUIDat (Expression:TileX, Expression:TileY, 0)----End at tile:Expression:EndTileUIDat (Expression:EndX, Expression:EndY, 0)-Action:Set cost----value >= 0, orExpression:BLOCKINGCost =Return value----Add cost to cacheGet cost of tileparameter 'Moving cost'is a string?Constant cost =parameter 'Moving cost'

Get shortest moving path between source chess to destination chess/tile

There are 5 parameters in action

Path mode

Configure property Path mode to get a shorter path or shortest path.

Get shortest path

Set property Path mode to

Get shorter path

Set property Path mode to A*-,

Exact or nearest

Set parameter Exact to nearest to get moving path from start tile to nearest target tile. Get the nearest target tile UID by Expression:NearestTileUID. The result of instance group is empty if Exact is set to "" and no path found from start tile to target tile.

Move chess alone path

Using rex_grid_move behavior to move chess alone path after Action:Get moving path.

  1. Pick path into group by Action:Get moving path
  2. Call C2 function Move to next tile

Add events of C2 function Move to next tile :

  1. Pick next tile by Condition:Pop one instance of Instance group plugin
  2. Move to tile by Action:Move to chess of grid move behavior
  3. chess has moved to the last tile of the path If picking nothing (system condition:Else)

Add events to move to next tile when reached to target tile by Condition:On hit target position of grid move behavior

  1. Call C2 function Move to next tile
Function: Move to next tile On moved to tileElseOn function: 'Move to next tile'Instance group plugin+Condition:Pop one instanceGrid move behavior-Action:Move to chessGrid move behavior+Condition:On hit target position-Call function: 'Move to next tile'slg_movement pluginAction:Get moving path----Pick path in group-Call function: 'Move to next tile'Moved tothe last tile of path

Sets propertyForce move toYes in grid move behavior, since the move-able (solid) had been determined by this Action:Get moving path.

Uses Expression: PrivateGroup (Instance group plugin) to pick path into private group of chess instance when picking path of multiple chess.

Use case of filter function and cost function

Sample capx This sample capx shows how to implement the filter function and cost function to get move-able area, moving path, and the enemies in a range.

No overlapped with other chess

Filter tiles which the cell of chess is empty, to exclude the tiles which has been occupied by other chess.

  1. If (Expression:TileX, Expression:TileY, 0) is empty (Condition:Is empty of board object) under Condition:On filter

    1. Append tile UID Expression:TileUID by Action:Append filter result

Pick enemies

Append enemy instances which stand on tiles, to pick pick enemies in a range.

  1. Pick enemy chess by Condition:Pick chess above tile (board object) under Condition:On filter

    1. Append chess UID by Action:Append filter result

No moving across enemies

Return Expression:BLOCKING if the enemy instance stands on tile under in cost function

  1. Pick enemy chess by (Expression:TileX, Expression:TileY, 1) (board object) under Condition:On cost

    1. Return Expression:BLOCKING if true

More samples


Wrap

Sample capx Set property Wrap to Yes in board object to wrap the logical boundary. It will also effect the result of picking move-able area and moving path. Chess could move from left boundary to right boundary directly.

Accumulated cost

Get accumulated cost from start tile to a specific chess/tile after Action:Get moveable area or Action:Get moving path by Expression:UID2PathCost (sample capx). Return -1 if this specific chess/tile is not in the last scan of request.

rex_slg_movement_accumulated cost


Flood fill

Sample capx Action:Get moveable area uses flood fill to find move-able area by Condition:On cost. This feature also could be used to picking neighbor chess/tile which have the same color.

The steps of picking are -

  1. Save target color in variable.

  2. Call Action:Get moveable area, sets the parameter of Moving point to 1.

  3. In Condition:On cost, pick tile/chess instance by Expression:TileUID or (Expression:TileX, Expression:TileY, 0).

  4. Compare the color of picked instance with target color

    • Return cost to 0 by Action:Set cost if the color of picked instance is equal to target color, .
    • Otherwise do nothing, the cost will be Expression:BLOCKING by default.
  5. Add the source tile into result group by Action:Add instances of (Instance group plugin) after Action:Get moveable area.

More samples


Move on tilemap

Sample capx Sets all tiles (LZ=0) by string symbols, and sets the squareTx to align to the tilemap object. Then uses these string symbol tile in input parameter of Action:Get moveable area or Action:Get moving path, it will pick tiles by string symbols. Since the results group are not UID of instance in this case, uses