# Need help understanding this code

**URL:** https://discourse.cataclysmdda.org/t/need-help-understanding-this-code/12747
**Category:** The Garage
**Created:** [October 18, 2016, 12:44am UTC](https://discourse.cataclysmdda.org/t/need-help-understanding-this-code/12747 "2016-10-18T00:44:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BorkBorkGoesTheCode](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/borkborkgoesthecode/32/2343_2.png) [@BorkBorkGoesTheCode](https://discourse.cataclysmdda.org/u/BorkBorkGoesTheCode)
#### Post date: [October 18, 2016, 12:44am UTC](https://discourse.cataclysmdda.org/t/need-help-understanding-this-code/12747/1 "2016-10-18T00:44:32Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [October 18, 2016, 1:57am UTC](https://discourse.cataclysmdda.org/t/need-help-understanding-this-code/12747/2 "2016-10-18T01:57:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![BorkBorkGoesTheCode](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/borkborkgoesthecode/32/2343_2.png) [@BorkBorkGoesTheCode](https://discourse.cataclysmdda.org/u/BorkBorkGoesTheCode)
#### Post date: [October 19, 2016, 4:53am UTC](https://discourse.cataclysmdda.org/t/need-help-understanding-this-code/12747/3 "2016-10-19T04:53:13Z")

</div>

Thank you!
