Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Jsonize Move Modes #38299

Closed
wants to merge 8 commits into from
Closed

[WIP] Jsonize Move Modes #38299

wants to merge 8 commits into from

Conversation

Rainfey
Copy link

@Rainfey Rainfey commented Feb 24, 2020

Summary

SUMMARY: Features "Move modes converted to json"

Purpose of change

To collate move mode data (such as volume reduction, speed and flavor texts) in a single location rather than have them spread through multiple files

Describe the solution

Have the settings be loaded from a json file, and referenced from a single location where needed

Describe alternatives you've considered

Converting move modes to a collection of structs

Testing

Confirmed the move menu and cycle move mode keybinds continue to work
Confirmed that swimming costs continue to be calculated correctly (needs additional testing, confirmed using debugger rather than ingame effect)
Confirmed that volume is correctly calculated (Possible bug noticed, volume indicator on the right bar indicated 0 volume - debugger showed correct value)
Confirmed move costs are consistent with original values
TODO : Confirm stamina costs for running are consistent with original values, feels higher currently
TODO : Confirm vehicle safe auto follow speed

Additional context

N/A

MM_RUN,
MM_CROUCH;

void move_modes::set_move_mode_ids()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we don't really want this. The whole point of generic_factory is that you don't define all of them in C++. if you need to use them elsewhere you can define them there.

move_mode_str_id id;
bool was_loaded = false;

public:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest you make every single one of these private.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these members instead be accessed through functions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, absolutely. set_ and get_ and maybe functions with context names. was_loaded is an exception, it needs to be public because of generic_factory. i can't recall off hand if id is the same

@@ -46,6 +46,7 @@ MAKE_NULL_ID2( trap, "tr_null" )
MAKE_NULL_ID2( construction_category, "NULL", -1 )
MAKE_NULL_ID2( ammo_effect, "AE_NULL", 0 )
MAKE_NULL_ID2( field_type, "fd_null", 0 )
MAKE_NULL_ID2( move_mode, "MM_NULL", 0 )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we really use null ids anymore? i've made several generic_factory things and have never needed to use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, null ids are terrible. If you need a variable that can contain either an id or nothing, wrap the id into std::optional.

With null ids, you never know where a null id is allowed / supported / will trigger some special behaviour.

@KorGgenT
Copy link
Member

So a couple things with the generic factory here: there's not a need to use int_id here, which means you can also change move_mode_str_id to just move_mode_id. additionally, There isn't a need for the NULL move mode as you're just checking it in code as if you'd check an empty string, which string_id can do anyway.

@I-am-Erk I-am-Erk added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Mechanics: Character / Player Character / Player mechanics labels Feb 24, 2020
"display_colour": "light_gray",
"display_character": "W",
"minimum_required_legs": 0,
"flavor_text": "You start walking.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translatable strings in JSON require separate code in "lang/extract_json_strings.py" to extract them for translation.

move_mode new_mode = mode.obj();

if( new_mode.minimum_required_legs > get_working_leg_count() ) {
add_msg( m_bad, string_format( _( "You do not have enough functioning legs to %s." ),
Copy link
Contributor

@BevapDin BevapDin Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_msg already does formatting, you should not do it yourself.

Same for more calls to add_msg below.

mod_stamina( -( ( moves * burn_ratio ) / 100.0 ) * stamina_move_cost_modifier() );
burn_ratio = burn_ratio * current_move_mode->stamina_burn_multiplier;

mod_stamina( -( ( moves * burn_ratio ) / 100.0 ) * current_move_mode->stamina_burn_multiplier );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mod_stamina( -( ( moves * burn_ratio ) / 100.0 ) * current_move_mode->stamina_burn_multiplier );
mod_stamina( -moves * burn_ratio / 100.0 * current_move_mode->stamina_burn_multiplier );

src/avatar.cpp Outdated Show resolved Hide resolved
Co-Authored-By: BevapDin <tho_ki@gmx.de>
@ZhilkinSerg
Copy link
Contributor

Feel free to reopen if you want working on it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Mechanics: Character / Player Character / Player mechanics stale Closed for lack of activity, but still valid.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants