-
Notifications
You must be signed in to change notification settings - Fork 481
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
adjust material size for melting for armor parts, weapons, trap components and tools... #4958
Merged
myk002
merged 18 commits into
DFHack:develop
from
Birkow:tweak/material_size_for_melting
Sep 28, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e299f4d
adjust material size for melting for armor parts, weapons, trap compo…
Birkow 41b6790
Change how material size for melting is calculated. On average weapon…
Birkow baa3337
add tweak description to .rst
Birkow e140794
move rng init to tweak plugin_init
Birkow 1c6cb58
update changelog, fix include order
Birkow 5673722
replace modf with modff
Birkow 1670409
Merge remote-tracking branch 'DFHack/develop' into tweak/material_siz…
Birkow 3f213ec
use #define to reduce repetitive code
Birkow e1e4c87
shortened long lines, improved readability
Birkow f94979a
removed duplicated code
Birkow 9fb0d9e
Update docs/plugins/tweak.rst
Birkow 7a5e0fd
Apply suggestions from code review
Birkow 119e169
remove redundant call to rng.init() from tweak.cpp, remove white spaces
Birkow b2d1501
renamed tweak from "material-size-for-melting" to "realistic-melting"
Birkow ed5fa05
Merge remote-tracking branch 'DFHack/dfhack/develop' into tweak/mater…
Birkow 076031a
Added information about production cost calculation to description
Birkow f6b1523
Merge branch 'develop' into tweak/material_size_for_melting
Birkow 6b553c6
reword description
myk002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,69 @@ | ||
#include <cmath> | ||
|
||
#include "modules/Materials.h" | ||
#include "modules/Random.h" | ||
|
||
#include "df/inorganic_raw.h" | ||
#include "df/item_armorst.h" | ||
#include "df/item_constructed.h" | ||
#include "df/item_glovesst.h" | ||
#include "df/item_helmst.h" | ||
#include "df/item_pantsst.h" | ||
#include "df/item_shieldst.h" | ||
#include "df/item_shoesst.h" | ||
#include "df/item_toolst.h" | ||
#include "df/item_trapcompst.h" | ||
#include "df/item_weaponst.h" | ||
|
||
struct Mrng { | ||
Random::MersenneRNG rng; | ||
Mrng() { rng.init(); } | ||
}; | ||
|
||
static float get_random() { | ||
static Mrng mrng; | ||
return static_cast <float> (mrng.rng.drandom1()); | ||
} | ||
|
||
static int32_t get_material_size_for_melting(df::item_constructed *item, int32_t base_material_size, float production_stack_size) { | ||
const float melt_return_per_material_size = 0.3f, base_melt_recovery = 0.95f, loss_per_wear_level = 0.1f; | ||
|
||
if (item->mat_type != 0) // bail if not INORGANIC | ||
return base_material_size; | ||
|
||
float forging_cost_per_item; | ||
if (auto inorganic = df::inorganic_raw::find(item->mat_index); | ||
inorganic && inorganic->flags.is_set(df::inorganic_flags::DEEP_SPECIAL)) | ||
{ | ||
// adamantine items | ||
forging_cost_per_item = static_cast<float>(base_material_size) / production_stack_size; | ||
} else { | ||
// non adamantine items | ||
forging_cost_per_item = std::max(std::floor(static_cast<float>(base_material_size) / 3.0f), 1.0f); | ||
forging_cost_per_item /= production_stack_size; | ||
} | ||
|
||
float calculated_size = forging_cost_per_item / melt_return_per_material_size; | ||
float melt_recovery = base_melt_recovery - static_cast<float>(item->wear) * loss_per_wear_level; | ||
calculated_size *= melt_recovery; | ||
int32_t random_part = ((modff(calculated_size, &calculated_size) > get_random()) ? 1 : 0); | ||
return static_cast<int32_t>(calculated_size) + random_part; | ||
} | ||
|
||
#define DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(TYPE, PRODUCTION_STACK_SIZE) \ | ||
struct material_size_for_melting_##TYPE##_hook : df::item_##TYPE##st {\ | ||
typedef df::item_##TYPE##st interpose_base;\ | ||
DEFINE_VMETHOD_INTERPOSE(int32_t, getMaterialSizeForMelting, ()) {\ | ||
return get_material_size_for_melting(this, INTERPOSE_NEXT(getMaterialSizeForMelting)(), PRODUCTION_STACK_SIZE);\ | ||
}\ | ||
};\ | ||
IMPLEMENT_VMETHOD_INTERPOSE(material_size_for_melting_##TYPE##_hook, getMaterialSizeForMelting); | ||
|
||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(armor, 1.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(gloves, 2.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(shoes, 2.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(helm, 1.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(pants, 1.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(weapon, 1.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(trapcomp, 1.0f) | ||
DEFINE_MATERIAL_SIZE_FOR_MELTING_TWEAK(tool, 1.0f) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can these vary if the game is modded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, will have to look into it and probably factor in if reaction-gloves tweak is enabled. It looks like it could alter how many gloves are produced in custom reactions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting forging cost for modded in items created in custom reactions should be possible. If vanilla items are created in modded reactions this can be challenging. Not sure if it is possible to determine what reaction was used to create item if multiple ones exist with different forging cost per item. Probably should use one with lowest forging unit cost as base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added information in description that melting returns are calculated for base game production cost., Might not be correct for modded items or custom reactions.