-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
result<T, E>
for climbing down
- Loading branch information
Showing
3 changed files
with
69 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdexcept> | ||
|
||
#include "iexamine_ledge.h" | ||
#include "translations.h" | ||
|
||
auto get_climb_result( bool has_grapnel, int climb_cost, float fall_mod ) -> climb_result | ||
{ | ||
if( has_grapnel ) { | ||
return both_way::grapnel; | ||
} else if( climb_cost <= 0 && fall_mod > 0.8 ) { | ||
return one_way::dangerous; | ||
} else if( climb_cost <= 0 ) { | ||
return one_way::unclimbable; | ||
} else if( climb_cost < 200 ) { | ||
return both_way::easy; | ||
} else { | ||
return one_way::hard_to_climb; | ||
} | ||
}; | ||
|
||
auto get_climb_query( one_way result ) -> const char * | ||
{ | ||
switch( result ) { | ||
case one_way::dangerous: | ||
return _( "You probably won't be able to get up and jumping down may hurt. Jump?" ); | ||
case one_way::unclimbable: | ||
return _( "You probably won't be able to get back up. Climb down?" ); | ||
case one_way::hard_to_climb: | ||
return _( "You may have problems climbing back up. Climb down?" ); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_IEXAMINE_LEDGE_H | ||
#define CATA_SRC_IEXAMINE_LEDGE_H | ||
|
||
#include <variant> | ||
|
||
enum class one_way { dangerous, unclimbable, hard_to_climb }; | ||
enum class both_way { easy, grapnel }; | ||
|
||
// stores whether it's possible to climb down then get up | ||
using climb_result = std::variant<one_way, both_way>; | ||
|
||
/** | ||
* @brief Check if it's possible to climb down then get up. | ||
* | ||
* @param fall_mod Fall damage modifier. @see Character::fall_damage_mod() | ||
*/ | ||
auto get_climb_result( bool has_grapnel, int climb_cost, float fall_mod ) -> climb_result; | ||
auto get_climb_query( one_way result ) -> const char *; | ||
|
||
#endif // CATA_SRC_IEXAMINE_LEDGE_H |