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

fix "using" field not working in array form for construction recipes #34533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,14 +1345,22 @@ void load_construction( JsonObject &jo )
time_duration::units ) );
}

// Warning: the IDs may change!
const requirement_id req_id( string_format( "inline_construction_%u", con.id ) );
requirement_data::load_requirement( jo, req_id );
con.requirements = req_id;

if( jo.has_string( "using" ) ) {
con.requirements = requirement_id( jo.get_string( "using" ) );
} else {
// Warning: the IDs may change!
const requirement_id req_id( string_format( "inline_construction_%u", con.id ) );
requirement_data::load_requirement( jo, req_id );
con.requirements = req_id;
con.reqs_using = { { requirement_id( jo.get_string( "using" ) ), 1} };
} else if( jo.has_array( "using" ) ) {
auto arr = jo.get_array( "using" );

while( arr.has_more() ) {
auto cur = arr.next_array();
con.reqs_using.emplace_back( requirement_id( cur.get_string( 0 ) ), cur.get_int( 1 ) );
}
}

con.pre_note = jo.get_string( "pre_note", "" );
con.pre_terrain = jo.get_string( "pre_terrain", "" );
if( con.pre_terrain.size() > 1
Expand Down Expand Up @@ -1556,6 +1564,14 @@ void finalize_constructions()
debugmsg( "Invalid construction category (%s) defined for construction (%s)", con.category.str(),
con.description );
}
requirement_data requirements_ = std::accumulate( con.reqs_using.begin(), con.reqs_using.end(),
*con.requirements,
[]( const requirement_data & lhs, const std::pair<requirement_id, int> &rhs ) {
return lhs + ( *rhs.first * rhs.second );
} );

requirement_data::save_requirement( requirements_, con.requirements );
con.reqs_using.clear();
}

constructions.erase( std::remove_if( constructions.begin(), constructions.end(),
Expand Down
2 changes: 2 additions & 0 deletions src/construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct construction {

/** Skill->skill level mapping. Can be empty. */
std::map<skill_id, int> required_skills;
// the requirements specified by "using"
std::vector<std::pair<requirement_id, int>> reqs_using;
requirement_id requirements;

// Index in construction vector
Expand Down