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

basecamps: add support for automatic calculation of blueprint ingredients #31209

Merged
merged 2 commits into from
Jun 10, 2019

Conversation

mlangsdorf
Copy link
Contributor

@mlangsdorf mlangsdorf commented Jun 7, 2019

Summary

SUMMARY: Infrastructure "basecamps: add support for automatic calculation of blueprint ingredients"

Purpose of change

Part of #31115
Add a way to have construction blueprints calculate their resource requirements from the underlying construction tasks. Doing this makes it easier to add new basecamp upgrades, since you don't have to figure out how long it takes to build things, and guarantees that basecamp construction requirements will stay in sync with any changes to construction.json.

Describe the solution

Create construction definitions for the shallow pit and deep pit, but add a new "on_display" keyword to constructions and set it to false for those pits. Constructions with "on_display": false are never displayed to the player and cannot be constructed.

add a new "blueprint_autocalculate" field to blueprint recipes. When it is present, recipe::finalize calls a function that:

  1. calls a mapgen_update function that creates a tinymap of dirt, applies the blueprint mapgen_update to that tinymap, and then returns maps of all the non-dirt ter_ids and furn_ids to their respective counts.
  2. then passes those maps to function in construction that takes all those ter_ids/furn_ids, finds the construction(s) that result in those ids, and then returns a map of requirement_ids to counts of those requirements.
  3. those requirements are then added to the reqs_internal and resolved normally.
  4. another function then eliminates any duplicated tools or qualities and consolidates similar components.

Describe alternatives you've considered

This was extremely complicated to write. I tried to optimize it with some std:: functions, but got confused and wrote it as simple and stupid as I could. Better optimization suggestions would be appreciated.

Additional context

Part of #31115

@mlangsdorf mlangsdorf added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. Player Faction Base / Camp All about the player faction base/camp/site labels Jun 7, 2019
@mlangsdorf
Copy link
Contributor Author

jenkins rebuild

Copy link
Contributor

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

This is pretty cool.

I may have missed something in get_changed_ids_from_update() as I'm not too familiar with the map/mapgen code, but the rest of it looks good to me. No awesome ways to make things way faster/cleaner came to mind while reading this, though I'll continue to cogitate on it.

Mostly minor suggestions, sorry that the review is a little disorganized/out of order.

@mlangsdorf mlangsdorf force-pushed the modular_basecamps_autocalc branch 2 times, most recently from 9ea675f to cc9c484 Compare June 7, 2019 22:59
@mlangsdorf
Copy link
Contributor Author

thanks for the review, changes made.

Copy link
Contributor

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

Looking good, I swung by for round 2

@mlangsdorf mlangsdorf force-pushed the modular_basecamps_autocalc branch from cc9c484 to cd2b7aa Compare June 8, 2019 00:29
Copy link
Contributor

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

basecamps should be able to autocalculate their upgrade build time and
requirements.  For that to happen, all common terrain constructions
need to have a construction definition, but some constructions, like
deep and shallow pits, are not meant to be selectable by the user.  add
the concept of a hidden construction, and add definitions for the
shallow pit and deep pit construction.
add a new "blueprint_autocalculate" field to blueprint recipes.  When it
is present, recipe::finalize calls a function that:
1. calls a mapgen_update function that creates a tinymap of dirt, applies
the blueprint mapgen_update to that tinymap, and then returns maps of
all the non-dirt ter_ids and furn_ids to their respective counts.
2. then passes those maps to function in construction that takes all
those ter_ids/furn_ids, finds the construction(s) that result in those
ids, and then returns a map of requirement_ids to counts of those
requirements.
3. those requirements are then added to the reqs_internal and resolved
normally.
4. one more function then eliminates any duplicated tools or qualities
and consolidates similar components.
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` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [JSON] Changes (can be) made in JSON Player Faction Base / Camp All about the player faction base/camp/site
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants