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

Jsonize vehicle parts requiring other vehicle parts to be installed #37453

Merged
merged 32 commits into from
Apr 2, 2020

Conversation

Hirmuolio
Copy link
Contributor

@Hirmuolio Hirmuolio commented Jan 28, 2020

Summary

SUMMARY: Infrastructure "Jsonize vehicle parts requiring other vehicle parts"

Purpose of change

Some vehicle parts require other vehicle parts before they can be installed. For example to install turret on a vehicle the tile must already have a turret mount.

This is controlled by flags of which the effect is hardcoded.

Install and uninstall requirements are also defined separately in different places leading to small bugs where install and uninstall requirements are different.

Describe the solution

The flags in json have a new property requires_flag.

If the flag has requires_flag property then this flag means that this part requires that flag to be installed.

If another part is blocking the removal of a part due to it requiring that another part you will see a "Remove the attached [part name]" message.
If multiple parts are blocking the removal only one of them is displayed.

This system will also work for parts that require more than one part. Just add multiple flags on the vehicle part.

Describe alternatives you've considered

Some of the "this part does something" flags could be separated from "this part requires that other part" flag. For example ALTERNATOR flag shouldn't require engine, instead the alternator part should have separate NEEDS_E_ENGINE flag for the part requirement.

requires_flag is generic name but the system applies to only vehicle parts. The same property could probably be expanded to other things (gunmods, cloth modifications, buildings).

It is possible to destroy the vehicle a vehicle part that is required by another vehicle part without destroying the other vehicle part. For example you can destroy the wheel hub withotu destroying the wheel that is connected on it. The connected part should fall off in these cases but that won't be done here.

Testing

Seems to work just fine.

Additional context

src/flag.h Outdated Show resolved Hide resolved
src/flag.h Outdated Show resolved Hide resolved
data/json/vehicleparts/vp_flags.json Outdated Show resolved Hide resolved
src/veh_type.h Outdated Show resolved Hide resolved
src/vehicle.cpp Outdated
// Check all the flags of the part to see if they require other flags
// If other flags are required check if those flags are present
for( const std::string flag : part.get_flags() ) {
if( json_flag::get( flag ).requires_flag() != "" ) {
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
if( json_flag::get( flag ).requires_flag() != "" ) {
if( !json_flag::get( flag ).requires_flag().empty() ) {

But better would be to change requires_flag_ to a cata::optional<std::string>.

src/vehicle.cpp Outdated Show resolved Hide resolved
Hirmuolio and others added 7 commits January 28, 2020 11:35
Co-Authored-By: Jianxiang Wang (王健翔) <qrox@sina.com>
Co-Authored-By: Jianxiang Wang (王健翔) <qrox@sina.com>
Co-Authored-By: BevapDin <tho_ki@gmx.de>
Co-Authored-By: BevapDin <tho_ki@gmx.de>
Co-Authored-By: BevapDin <tho_ki@gmx.de>
@I-am-Erk I-am-Erk added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Vehicles Vehicles, parts, mechanics & interactions 0.E Feature Freeze labels Jan 30, 2020
@Hirmuolio Hirmuolio marked this pull request as ready for review March 26, 2020 12:31
@kevingranade kevingranade merged commit 5899e2d into CleverRaven:master Apr 2, 2020
@Hirmuolio Hirmuolio deleted the Hirmuolio-vehicle-jsonize branch April 11, 2020 06:39
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 Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants