Need help understanding this code

I am trying to find a way to convert the hardcoded swim fin movement bonus into a flag. What does this code do? action.cpp

[code]bool can_move_vertical_at( const tripoint &p, int movez )
476 {
477 // TODO: unify this with game::move_vertical
478 if( g->m.has_flag( “SWIMMABLE”, p ) && g->m.has_flag( TFLAG_DEEP_WATER, p ) ) {
479 if( movez == -1 ) {
480 return !g->u.is_underwater() && !g->u.worn_with_flag( “FLOTATION” );
481 } else {
482 return g->u.swim_speed() < 500 || g->u.is_wearing( “swim_fins” );
483 }
484 }
485

486 if( movez == -1 ) {
487 return g->m.has_flag( “GOES_DOWN”, p );
488 } else {
489 return g->m.has_flag( “GOES_UP”, p );
490 }
491 }
492
[/code]

478:
If the tile we’re on is swimmable (any water tile) and deep (deep enough that you can’t walk on it)
479:
If we’re moving down (“movez” is direction of movement in z-level direction, minus meaning down)
480:
If player isn’t underwater AND is not wearing flotation vest, we can move down - in this case dive.
482:
We can only dive up if player’s swimming speed (actually swimming cost) is less than 500 or player is wearing swimming fins

Otherwise player can move up or down if standing on relevant stairs.

Thank you!