Difference between revisions of "User:SXX/Pathfinding and movement"

From VCMI Project Wiki
Jump to: navigation, search
(Some basic structure)
 
(Explanation of how current movement loop works.)
Line 7: Line 7:
 
= Client specific =
 
= Client specific =
  
 +
== Step by step movement in CPlayerInterface::doMoveHero ==
 +
This is text representation of what for loop code doing except some useless things like sounds.
 +
 +
# Initialize ''outTeleportObj'' with ''nullptr''
 +
# Initialize ''tileAfterThis'' = true. This variable used to determine we want to visit object or do transit movement
 +
# Check if node after next one is present, if so:
 +
## set ''tileAfterThis'' = true.
 +
## Check if tile after next one is CGTeleport object, if so:
 +
### Set nextTeleporter = CGTeleport id. This variable used by:
 +
###:* CPlayerInterface::requestRealized to check if we're moving via teleporter. Then it's not going to set CONTINUE_MOVE as showTeleportDialog should do that.
 +
###:* CPlayerInterface::showTeleportDialog to choose where we want teleport to when it's allowed.
 +
#: 
 +
#:  -  -  -  -  -  -  -
 +
#: 
 +
# If current tile hero staying on is CGTeleport object get it as ''priorObject'' 
 +
# If next tile have visitable CGObjectInstance get is as ''nextObject''
 +
# If ''nextObject'' is CGTeleport instance then get it as ''nextObjectTeleport''
 +
# Now if we see that ''priorObject'' and ''nextObjectTeleport'' are connected teleporters it's mean we might be teleported on previous movement. Then:
 +
## Check if this is our first movement in loop. This would mean that hero is currently staying on teleporter it's need to use. Then:
 +
### Set ''nextTeleporter'' = nextObjectTeleport id. This is needed as before ''nextTeleporter'' wasn't set.
 +
### Set stillMoveHero to WAITING_MOVE which means some other code (requestRealized, showTeleportDialog, etc) should allow to say us if we continue movement or stop.
 +
### Sent normal movement request, but with destination as current hero position.
 +
### Now wait before we get TeleportDialog query and showTeleportDialog set stillMoveHero to CONTINUE_MOVE.
 +
## Execute ''continue'' to jump to next iteration.
 +
#: 
 +
#:  -  -  -  -  -  -  -
 +
#: 
 +
# Check if more than 0 turns is needed to reach next tile. Then:
 +
## set ''StillMoveHero'' to STOP_MOVE.
 +
## Execute ''break'' to stop movement loop.
 +
#: 
 +
#:  -  -  -  -  -  -  -
 +
#: 
 +
# set ''StillMoveHero'' to WAITING_MOVE. Read above to check why.
 +
# set ''endpost'' to our destination. Tricky part: for the last Z coordinate we use current hero position instead of destination Z coordinate. This is needed because only situation when destination Z and hero Z is different it's when it's movement via teleporters, but current code shouldn't ever used in case of teleportation.
 +
#: ''When I write those lines it's isn't actually this way, but it's have to be.''
 +
# Set ''guarded'' if next tile have guarded creature. It's mean we sure that movement will start the battle.
 +
#: 
 +
#:  -  -  -  -  -  -  -
 +
#: 
 +
# Now we need to check if next tile has visitable object, but we want to go through it:
 +
#: * Check ''tileAfterThis'' is true which means next tile exist
 +
#: * Check ''nextObject'' isn't nullptr which means we actually have to request transit
 +
#: * Check if ''nextObject->isAllowTransit'' is true which means next object actually allow transit through it. E.g transit via  one way teleporters and events is impossible.
 +
#: * Check if ''nextObjectTeleport'' and ''outTeleportObj'' are not connected. This is needed because we it's possible that more than 2 next objects on our may be teleporters, but we don't only want to visit latest one while transit via remaining.
 +
## set "nextTeleporter" to -1 because we now know there won't be TeleportDialog query after this movement.
 +
## call moveHero with transit argument.
 +
# If previous check isn't pass then
 +
## Just call moveHero without transit argument.
 +
# Now wait before we get TeleportDialog query and showTeleportDialog set stillMoveHero to CONTINUE_MOVE.
 +
#: 
 +
#:  -  -  -  -  -  -  -
 +
#: 
 +
# Check if ''guarded'' is true or there dialog appear, then:
 +
## Execute "break" to stop movement loop.
  
 
= Server specific =
 
= Server specific =

Revision as of 10:03, 27 February 2015

Introduction

Shared code (lib)

Client specific

Step by step movement in CPlayerInterface::doMoveHero

This is text representation of what for loop code doing except some useless things like sounds.

  1. Initialize outTeleportObj with nullptr
  2. Initialize tileAfterThis = true. This variable used to determine we want to visit object or do transit movement
  3. Check if node after next one is present, if so:
    1. set tileAfterThis = true.
    2. Check if tile after next one is CGTeleport object, if so:
      1. Set nextTeleporter = CGTeleport id. This variable used by:
        • CPlayerInterface::requestRealized to check if we're moving via teleporter. Then it's not going to set CONTINUE_MOVE as showTeleportDialog should do that.
        • CPlayerInterface::showTeleportDialog to choose where we want teleport to when it's allowed.
    - - - - - - -
  4. If current tile hero staying on is CGTeleport object get it as priorObject
  5. If next tile have visitable CGObjectInstance get is as nextObject
  6. If nextObject is CGTeleport instance then get it as nextObjectTeleport
  7. Now if we see that priorObject and nextObjectTeleport are connected teleporters it's mean we might be teleported on previous movement. Then:
    1. Check if this is our first movement in loop. This would mean that hero is currently staying on teleporter it's need to use. Then:
      1. Set nextTeleporter = nextObjectTeleport id. This is needed as before nextTeleporter wasn't set.
      2. Set stillMoveHero to WAITING_MOVE which means some other code (requestRealized, showTeleportDialog, etc) should allow to say us if we continue movement or stop.
      3. Sent normal movement request, but with destination as current hero position.
      4. Now wait before we get TeleportDialog query and showTeleportDialog set stillMoveHero to CONTINUE_MOVE.
    2. Execute continue to jump to next iteration.
    - - - - - - -
  8. Check if more than 0 turns is needed to reach next tile. Then:
    1. set StillMoveHero to STOP_MOVE.
    2. Execute break to stop movement loop.
    - - - - - - -
  9. set StillMoveHero to WAITING_MOVE. Read above to check why.
  10. set endpost to our destination. Tricky part: for the last Z coordinate we use current hero position instead of destination Z coordinate. This is needed because only situation when destination Z and hero Z is different it's when it's movement via teleporters, but current code shouldn't ever used in case of teleportation.
    When I write those lines it's isn't actually this way, but it's have to be.
  11. Set guarded if next tile have guarded creature. It's mean we sure that movement will start the battle.
    - - - - - - -
  12. Now we need to check if next tile has visitable object, but we want to go through it:
    * Check tileAfterThis is true which means next tile exist
    * Check nextObject isn't nullptr which means we actually have to request transit
    * Check if nextObject->isAllowTransit is true which means next object actually allow transit through it. E.g transit via one way teleporters and events is impossible.
    * Check if nextObjectTeleport and outTeleportObj are not connected. This is needed because we it's possible that more than 2 next objects on our may be teleporters, but we don't only want to visit latest one while transit via remaining.
    1. set "nextTeleporter" to -1 because we now know there won't be TeleportDialog query after this movement.
    2. call moveHero with transit argument.
  13. If previous check isn't pass then
    1. Just call moveHero without transit argument.
  14. Now wait before we get TeleportDialog query and showTeleportDialog set stillMoveHero to CONTINUE_MOVE.
    - - - - - - -
  15. Check if guarded is true or there dialog appear, then:
    1. Execute "break" to stop movement loop.

Server specific