From fa589b57645985b6abbdffb0f96714d31a401a41 Mon Sep 17 00:00:00 2001 From: Tachytaenius Date: Wed, 9 Nov 2022 19:08:06 +0000 Subject: [PATCH] Make progress with action timer API --- library/include/modules/Units.h | 15 +++++++------- library/modules/Units.cpp | 36 ++++++++++++++++++--------------- plugins/fastdwarf.cpp | 3 ++- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h index ffbeaac67..ba71215f5 100644 --- a/library/include/modules/Units.h +++ b/library/include/modules/Units.h @@ -38,6 +38,8 @@ distribution. #include "df/misc_trait_type.h" #include "df/physical_attribute_type.h" #include "df/unit.h" +#include "df/unit_action.h" +#include "df/action_type_group.h" namespace df { @@ -224,13 +226,12 @@ DFHACK_EXPORT extern const std::vector stress_cutoffs; DFHACK_EXPORT int getStressCategory(df::unit *unit); DFHACK_EXPORT int getStressCategoryRaw(int32_t stress_level); -enum ActionTypeGroup {All, Movement, MovementFeet, Offensive, Work}; -DFHACK_EXPORT void subtractActionTimer(df::unit *unit, int amount, int affectedActionType); -DFHACK_EXPORT void subtractActionTimerCategory(df::unit *unit, int amount, int affectedActionTypes); -DFHACK_EXPORT void multiplyActionTimer(df::unit *unit, float amount, int affectedActionType); -DFHACK_EXPORT void multiplyActionTimerCategory(df::unit *unit, float amount, int affectedActionTypes); -DFHACK_EXPORT void setActionTimer(df::unit *unit, int amount, int affectedActionType); -DFHACK_EXPORT void setActionTimerCategory(df::unit *unit, int amount, int affectedActionTypes); +DFHACK_EXPORT void subtractActionTimer(df::unit *unit, int amount, df::unit_action_type affectedActionType); +DFHACK_EXPORT void subtractActionTimerCategory(df::unit *unit, int amount, df::action_type_group affectedActionTypes); +DFHACK_EXPORT void multiplyActionTimer(df::unit *unit, float amount, df::unit_action_type affectedActionType); +DFHACK_EXPORT void multiplyActionTimerCategory(df::unit *unit, float amount, df::action_type_group affectedActionTypes); +DFHACK_EXPORT void setActionTimer(df::unit *unit, int amount, df::unit_action_type affectedActionType); +DFHACK_EXPORT void setActionTimerCategory(df::unit *unit, int amount, df::action_type_group affectedActionTypes); } } diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 468c0dc40..fe9a79fa7 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -81,6 +81,7 @@ using namespace std; #include "df/unit_wound.h" #include "df/world.h" #include "df/unit_action.h" +#include "df/action_type_group.h" using namespace DFHack; using namespace df::enums; @@ -1957,9 +1958,16 @@ struct AffectedActionTypesGroupContainer AffectedActionTypesGroupContainer() { + const int NUM_ACTION_TYPES = ENUM_LAST_ITEM(unit_action_type) - ENUM_FIRST_ITEM(unit_action_type) + 1; + // Length of df::unit_action_type, including unknowns + const int NUM_ACTION_TYPE_GROUPS = ENUM_LAST_ITEM(action_type_group) - ENUM_FIRST_ITEM(action_type_group) + 1; + // Length of df::action_type_group + groups = std::vector>(NUM_ACTION_TYPE_GROUPS, std::vector(NUM_ACTION_TYPES, false)); + + // "None" category can be left alone + // "All" category - std::vector & allVector = groups[Units::ActionTypeGroup::All]; - // reinitialise allVector to the length of the df::unit_action_type enum + std::vector & allVector = groups[df::action_type_group::All]; allVector[df::unit_action_type::Move] = true; allVector[df::unit_action_type::Attack] = true; allVector[df::unit_action_type::HoldTerrain] = true; @@ -1976,8 +1984,7 @@ struct AffectedActionTypesGroupContainer allVector[df::unit_action_type::SuckBlood] = true; // "Movement" category - std::vector & movementVector = groups[Units::ActionTypeGroup::Movement]; - // reinitialise movementVector to falses with the length of the df::unit_action_type enum + std::vector & movementVector = groups[df::action_type_group::Movement]; movementVector[df::unit_action_type::Move] = true; movementVector[df::unit_action_type::HoldTerrain] = true; movementVector[df::unit_action_type::Climb] = true; @@ -1989,8 +1996,7 @@ struct AffectedActionTypesGroupContainer movementVector[df::unit_action_type::PushObject] = true; // "MovementFeet" category - std::vector & movementFeetVector = groups[Units::ActionTypeGroup::MovementFeet]; - // reinitialise movementFeetVector to falses with the length of the df::unit_action_type enum + std::vector & movementFeetVector = groups[df::action_type_group::MovementFeet]; movementFeetVector[df::unit_action_type::Move] = true; // Include Unsteady? movementFeetVector[df::unit_action_type::Dodge] = true; @@ -1998,14 +2004,12 @@ struct AffectedActionTypesGroupContainer movementFeetVector[df::unit_action_type::PushObject] = true; // "Offensive" category - std::vector & offensiveVector = groups[Units::ActionTypeGroup::Offensive]; - // reinitialise offensiveVector to falses with the length of the df::unit_action_type enum + std::vector & offensiveVector = groups[df::action_type_group::Offensive]; offensiveVector[df::unit_action_type::Attack] = true; offensiveVector[df::unit_action_type::SuckBlood] = true; // "Work" category - std::vector & workVector = groups[Units::ActionTypeGroup::Work]; - // reinitialise workVector to falses with the length of the df::unit_action_type enum + std::vector & workVector = groups[df::action_type_group::Work]; workVector[df::unit_action_type::Job] = true; workVector[df::unit_action_type::Job2] = true; workVector[df::unit_action_type::PushObject] = true; @@ -2065,7 +2069,7 @@ int *getActionTimerPointer(df::unit_action *action) { return nullptr; } -void Units::subtractActionTimer(df::unit *unit, int amount, int affectedActionType) +void Units::subtractActionTimer(df::unit *unit, int amount, df::unit_action_type affectedActionType) { CHECK_NULL_POINTER(unit); for (auto action : unit->actions) { @@ -2077,7 +2081,7 @@ void Units::subtractActionTimer(df::unit *unit, int amount, int affectedActionTy } } -void Units::subtractActionTimerCategory(df::unit *unit, int amount, int affectedActionTypes) +void Units::subtractActionTimerCategory(df::unit *unit, int amount, df::action_type_group affectedActionTypes) { CHECK_NULL_POINTER(unit); static AffectedActionTypesGroupContainer groupContainer; @@ -2090,7 +2094,7 @@ void Units::subtractActionTimerCategory(df::unit *unit, int amount, int affected } } -void Units::multiplyActionTimer(df::unit *unit, float amount, int affectedActionType) +void Units::multiplyActionTimer(df::unit *unit, float amount, df::unit_action_type affectedActionType) { CHECK_NULL_POINTER(unit); for (auto action : unit->actions) { @@ -2102,7 +2106,7 @@ void Units::multiplyActionTimer(df::unit *unit, float amount, int affectedAction } } -void Units::multiplyActionTimerCategory(df::unit *unit, float amount, int affectedActionTypes) +void Units::multiplyActionTimerCategory(df::unit *unit, float amount, df::action_type_group affectedActionTypes) { CHECK_NULL_POINTER(unit); static AffectedActionTypesGroupContainer groupContainer; @@ -2115,7 +2119,7 @@ void Units::multiplyActionTimerCategory(df::unit *unit, float amount, int affect } } -void Units::setActionTimer(df::unit *unit, int amount, int affectedActionType) +void Units::setActionTimer(df::unit *unit, int amount, df::unit_action_type affectedActionType) { CHECK_NULL_POINTER(unit); for (auto action : unit->actions) { @@ -2127,7 +2131,7 @@ void Units::setActionTimer(df::unit *unit, int amount, int affectedActionType) } } -void Units::setActionTimerCategory(df::unit *unit, int amount, int affectedActionTypes) +void Units::setActionTimerCategory(df::unit *unit, int amount, df::action_type_group affectedActionTypes) { CHECK_NULL_POINTER(unit); static AffectedActionTypesGroupContainer groupContainer; diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index cb6a3e310..ad4d6069d 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -12,6 +12,7 @@ #include "df/unit_relationship_type.h" #include "df/units_other_id.h" #include "df/world.h" +#include "df/action_type_group.h" using std::string; using std::vector; @@ -82,7 +83,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (enable_fastdwarf) { - Units::setActionTimerCategory(unit, 1, Units::ActionTypeGroup::All); + Units::setActionTimerCategory(unit, 1, df::action_type_group::All); } } return CR_OK;