Add a few tweaks - fix wear on cloth/leather items, disable wear on adamantine clothes

develop
Quietust 2014-05-08 14:22:45 -05:00
parent 415cdad489
commit 4b8f68dfa9
3 changed files with 133 additions and 1 deletions

@ -2180,10 +2180,18 @@ unintended inverse dependency of training speed on unit count
the units spar more.</p> the units spar more.</p>
</td> </td>
</tr> </tr>
<tr class="field"><th class="field-name">hive-crash:</th><td class="field-body"><p class="first last">The hive code crashes if there are ungathered products in a hive without bees (bug 6368). <tr class="field"><th class="field-name">hive-crash:</th><td class="field-body"><p class="first">The hive code crashes if there are ungathered products in a hive without bees (bug 6368).
This tweak prevents it by auto-gathering the products if this happens.</p> This tweak prevents it by auto-gathering the products if this happens.</p>
</td> </td>
</tr> </tr>
<tr class="field"><th class="field-name">craft-age-wear:</th><td class="field-body"><p class="first">Fixes the behavior of crafted items wearing out over time (bug 6003).
With this tweak, items made from cloth and leather will gain a level of wear every 20 years.</p>
</td>
</tr>
<tr class="field"><th class="field-name" colspan="2">adamantine-cloth-wear:</th></tr>
<tr class="field"><td>&nbsp;</td><td class="field-body"><p class="first last">Prevents adamantine clothing from wearing out while being worn (bug 6481).</p>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

@ -1371,6 +1371,11 @@ Subcommands that persist until disabled or DF quit:
:hive-crash: The hive code crashes if there are ungathered products in a hive without bees (bug 6368). :hive-crash: The hive code crashes if there are ungathered products in a hive without bees (bug 6368).
This tweak prevents it by auto-gathering the products if this happens. This tweak prevents it by auto-gathering the products if this happens.
:craft-age-wear: Fixes the behavior of crafted items wearing out over time (bug 6003).
With this tweak, items made from cloth and leather will gain a level of wear every 20 years.
:adamantine-cloth-wear: Prevents adamantine clothing from wearing out while being worn (bug 6481).
fix-armory fix-armory
---------- ----------

@ -11,6 +11,7 @@
#include "modules/Units.h" #include "modules/Units.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/Job.h" #include "modules/Job.h"
#include "modules/Materials.h"
#include "MiscUtils.h" #include "MiscUtils.h"
@ -35,6 +36,12 @@
#include "df/ui_build_selector.h" #include "df/ui_build_selector.h"
#include "df/building_trapst.h" #include "df/building_trapst.h"
#include "df/item_actual.h" #include "df/item_actual.h"
#include "df/item_crafted.h"
#include "df/item_armorst.h"
#include "df/item_helmst.h"
#include "df/item_glovesst.h"
#include "df/item_shoesst.h"
#include "df/item_pantsst.h"
#include "df/item_liquid_miscst.h" #include "df/item_liquid_miscst.h"
#include "df/item_powder_miscst.h" #include "df/item_powder_miscst.h"
#include "df/item_barst.h" #include "df/item_barst.h"
@ -140,6 +147,10 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" Speed up melee squad training, removing inverse dependency on unit count.\n" " Speed up melee squad training, removing inverse dependency on unit count.\n"
" tweak hive-crash [disable]\n" " tweak hive-crash [disable]\n"
" Prevents crash if bees die in a hive with uncollected products (bug 6368).\n" " Prevents crash if bees die in a hive with uncollected products (bug 6368).\n"
" tweak craft-age-wear [disable]\n"
" Makes cloth and leather items wear out at the correct rate (bug 6003).\n"
" tweak adamantine-cloth-wear [disable]\n"
" Stops adamantine clothing from wearing out while being worn (bug 6481).\n"
)); ));
return CR_OK; return CR_OK;
} }
@ -977,6 +988,102 @@ struct hive_crash_hook : df::building_hivest {
IMPLEMENT_VMETHOD_INTERPOSE(hive_crash_hook, updateAction); IMPLEMENT_VMETHOD_INTERPOSE(hive_crash_hook, updateAction);
struct craft_age_wear_hook : df::item_crafted {
typedef df::item_crafted interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, ageItem, (int amount))
{
int orig_age = age;
age += amount;
if (age > 200000000)
age = 200000000;
if (age == orig_age)
return;
MaterialInfo mat(mat_type, mat_index);
if (!mat.isValid())
return;
int wear = 0;
if (mat.material->flags.is_set(material_flags::WOOD))
wear = 5;
else if (mat.material->flags.is_set(material_flags::LEATHER) ||
mat.material->flags.is_set(material_flags::THREAD_PLANT) ||
mat.material->flags.is_set(material_flags::SILK) ||
mat.material->flags.is_set(material_flags::YARN))
wear = 1;
else
return;
wear = ((orig_age % wear) + (age - orig_age)) / wear;
if (wear > 0)
addWear(wear, false, false);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(craft_age_wear_hook, ageItem);
static bool inc_wear_timer (df::item_constructed *item, int amount)
{
if (item->flags.bits.artifact)
return false;
MaterialInfo mat(item->mat_type, item->mat_index);
if (mat.isInorganic() && mat.inorganic->flags.is_set(inorganic_flags::DEEP_SPECIAL))
return false;
item->wear_timer += amount;
return (item->wear_timer > 806400);
}
struct adamantine_cloth_wear_armor_hook : df::item_armorst {
typedef df::item_armorst interpose_base;
DEFINE_VMETHOD_INTERPOSE(bool, incWearTimer, (int amount))
{
return inc_wear_timer(this, amount);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(adamantine_cloth_wear_armor_hook, incWearTimer);
struct adamantine_cloth_wear_helm_hook : df::item_helmst {
typedef df::item_helmst interpose_base;
DEFINE_VMETHOD_INTERPOSE(bool, incWearTimer, (int amount))
{
return inc_wear_timer(this, amount);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(adamantine_cloth_wear_helm_hook, incWearTimer);
struct adamantine_cloth_wear_gloves_hook : df::item_glovesst {
typedef df::item_glovesst interpose_base;
DEFINE_VMETHOD_INTERPOSE(bool, incWearTimer, (int amount))
{
return inc_wear_timer(this, amount);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(adamantine_cloth_wear_gloves_hook, incWearTimer);
struct adamantine_cloth_wear_shoes_hook : df::item_shoesst {
typedef df::item_shoesst interpose_base;
DEFINE_VMETHOD_INTERPOSE(bool, incWearTimer, (int amount))
{
return inc_wear_timer(this, amount);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(adamantine_cloth_wear_shoes_hook, incWearTimer);
struct adamantine_cloth_wear_pants_hook : df::item_pantsst {
typedef df::item_pantsst interpose_base;
DEFINE_VMETHOD_INTERPOSE(bool, incWearTimer, (int amount))
{
return inc_wear_timer(this, amount);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(adamantine_cloth_wear_pants_hook, incWearTimer);
static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector <string> &parameters) static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector <string> &parameters)
{ {
if (vector_get(parameters, 1) == "disable") if (vector_get(parameters, 1) == "disable")
@ -1161,6 +1268,18 @@ static command_result tweak(color_ostream &out, vector <string> &parameters)
{ {
enable_hook(out, INTERPOSE_HOOK(hive_crash_hook, updateAction), parameters); enable_hook(out, INTERPOSE_HOOK(hive_crash_hook, updateAction), parameters);
} }
else if (cmd == "craft-age-wear")
{
enable_hook(out, INTERPOSE_HOOK(craft_age_wear_hook, ageItem), parameters);
}
else if (cmd == "adamantine-cloth-wear")
{
enable_hook(out, INTERPOSE_HOOK(adamantine_cloth_wear_armor_hook, incWearTimer), parameters);
enable_hook(out, INTERPOSE_HOOK(adamantine_cloth_wear_helm_hook, incWearTimer), parameters);
enable_hook(out, INTERPOSE_HOOK(adamantine_cloth_wear_gloves_hook, incWearTimer), parameters);
enable_hook(out, INTERPOSE_HOOK(adamantine_cloth_wear_shoes_hook, incWearTimer), parameters);
enable_hook(out, INTERPOSE_HOOK(adamantine_cloth_wear_pants_hook, incWearTimer), parameters);
}
else else
return CR_WRONG_USAGE; return CR_WRONG_USAGE;