2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2011-06-16 15:53:39 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2017-06-10 18:32:36 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
/*
|
2017-06-10 18:32:36 -06:00
|
|
|
* Units
|
2012-01-24 10:32:34 -07:00
|
|
|
*/
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "modules/Items.h"
|
2012-01-24 10:32:34 -07:00
|
|
|
#include "DataDefs.h"
|
2015-12-19 09:07:35 -07:00
|
|
|
|
|
|
|
#include "df/caste_raw_flags.h"
|
2020-08-04 16:01:28 -06:00
|
|
|
#include "df/goal_type.h"
|
2015-12-19 09:07:35 -07:00
|
|
|
#include "df/job_skill.h"
|
|
|
|
#include "df/mental_attribute_type.h"
|
2012-09-09 02:27:40 -06:00
|
|
|
#include "df/misc_trait_type.h"
|
2012-09-09 02:51:08 -06:00
|
|
|
#include "df/physical_attribute_type.h"
|
2015-12-19 09:07:35 -07:00
|
|
|
#include "df/unit.h"
|
2022-11-09 12:08:06 -07:00
|
|
|
#include "df/unit_action.h"
|
2022-11-18 15:10:14 -07:00
|
|
|
#include "df/unit_action_type_group.h"
|
2012-01-21 12:03:39 -07:00
|
|
|
|
2012-04-07 09:08:30 -06:00
|
|
|
namespace df
|
|
|
|
{
|
2017-04-28 15:25:58 -06:00
|
|
|
struct activity_entry;
|
|
|
|
struct activity_event;
|
2012-04-07 09:08:30 -06:00
|
|
|
struct nemesis_record;
|
2012-04-11 09:42:05 -06:00
|
|
|
struct burrow;
|
2014-07-29 15:30:22 -06:00
|
|
|
struct identity;
|
2012-04-26 02:03:56 -06:00
|
|
|
struct historical_entity;
|
|
|
|
struct entity_position_assignment;
|
|
|
|
struct entity_position;
|
2012-09-09 02:27:40 -06:00
|
|
|
struct unit_misc_trait;
|
2012-04-07 09:08:30 -06:00
|
|
|
}
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
2011-12-02 02:56:40 -07:00
|
|
|
* \defgroup grp_units Unit module parts
|
2011-03-18 04:09:26 -06:00
|
|
|
* @ingroup grp_modules
|
|
|
|
*/
|
2010-04-04 16:48:19 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-01-24 10:32:34 -07:00
|
|
|
namespace Units
|
|
|
|
{
|
2017-06-10 15:21:34 -06:00
|
|
|
|
|
|
|
static const int MAX_COLORS = 15;
|
|
|
|
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2012-01-24 10:32:34 -07:00
|
|
|
/**
|
2017-06-10 18:32:36 -06:00
|
|
|
* The Units module - allows reading all non-vermin units and their properties
|
2012-01-24 10:32:34 -07:00
|
|
|
*/
|
2010-06-24 23:11:26 -06:00
|
|
|
|
2022-11-12 17:40:20 -07:00
|
|
|
DFHACK_EXPORT bool isUnitInBox(df::unit* u,
|
2022-11-13 12:35:01 -07:00
|
|
|
int16_t x1, int16_t y1, int16_t z1,
|
|
|
|
int16_t x2, int16_t y2, int16_t z2);
|
2022-11-12 17:40:20 -07:00
|
|
|
|
|
|
|
DFHACK_EXPORT bool isActive(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isVisible(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isCitizen(df::unit *unit, bool ignore_sanity = false);
|
|
|
|
DFHACK_EXPORT bool isFortControlled(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isOwnCiv(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isOwnGroup(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isOwnRace(df::unit* unit);
|
|
|
|
|
|
|
|
DFHACK_EXPORT bool isAlive(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isDead(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isKilled(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isSane(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isCrazed(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isGhost(df::unit *unit);
|
|
|
|
/// is unit hidden to the player? accounts for ambushing
|
|
|
|
DFHACK_EXPORT bool isHidden(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isHidingCurse(df::unit *unit);
|
|
|
|
|
|
|
|
DFHACK_EXPORT bool isMale(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isFemale(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isBaby(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isChild(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isAdult(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isGay(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isNaked(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isVisiting(df::unit* unit);
|
|
|
|
|
|
|
|
DFHACK_EXPORT bool isTrainableHunting(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isTrainableWar(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isTrained(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isHunter(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isWar(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isTame(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isTamable(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isDomesticated(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isMarkedForSlaughter(df::unit* unit);
|
2023-02-11 01:59:31 -07:00
|
|
|
DFHACK_EXPORT bool isMarkedForGelding(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isGeldable(df::unit* unit);
|
2022-11-12 17:40:20 -07:00
|
|
|
DFHACK_EXPORT bool isGelded(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isEggLayer(df::unit* unit);
|
2023-07-16 13:30:12 -06:00
|
|
|
DFHACK_EXPORT bool isEggLayerRace(df::unit* unit);
|
2022-11-12 17:40:20 -07:00
|
|
|
DFHACK_EXPORT bool isGrazer(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isMilkable(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isForest(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isMischievous(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isAvailableForAdoption(df::unit* unit);
|
2023-02-11 01:59:31 -07:00
|
|
|
DFHACK_EXPORT bool isPet(df::unit* unit);
|
2022-11-12 17:40:20 -07:00
|
|
|
|
|
|
|
DFHACK_EXPORT bool hasExtravision(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isOpposedToLife(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isBloodsucker(df::unit *unit);
|
|
|
|
|
|
|
|
DFHACK_EXPORT bool isDwarf(df::unit *unit);
|
|
|
|
DFHACK_EXPORT bool isAnimal(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isMerchant(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isDiplomat(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isVisitor(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isInvader(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isUndead(df::unit* unit, bool include_vamps = false);
|
|
|
|
DFHACK_EXPORT bool isNightCreature(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isSemiMegabeast(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isMegabeast(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isTitan(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isDemon(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isDanger(df::unit* unit);
|
|
|
|
DFHACK_EXPORT bool isGreatDanger(df::unit* unit);
|
|
|
|
|
2012-01-24 10:32:34 -07:00
|
|
|
/* Read Functions */
|
2017-06-10 18:32:36 -06:00
|
|
|
// Read units in a box, starting with index. Returns -1 if no more units
|
|
|
|
// found. Call repeatedly do get all units in a specified box (uses tile coords)
|
|
|
|
DFHACK_EXPORT int32_t getNumUnits();
|
|
|
|
DFHACK_EXPORT df::unit *getUnit(const int32_t index);
|
|
|
|
DFHACK_EXPORT bool getUnitsInBox(std::vector<df::unit*> &units,
|
|
|
|
int16_t x1, int16_t y1, int16_t z1,
|
|
|
|
int16_t x2, int16_t y2, int16_t z2);
|
2023-07-03 14:47:43 -06:00
|
|
|
DFHACK_EXPORT bool getUnitsByNobleRole(std::vector<df::unit *> &units, std::string noble);
|
|
|
|
DFHACK_EXPORT df::unit *getUnitByNobleRole(std::string noble);
|
2023-01-29 17:26:14 -07:00
|
|
|
DFHACK_EXPORT bool getCitizens(std::vector<df::unit *> &citizens, bool ignore_sanity = false);
|
2011-04-13 10:36:10 -06:00
|
|
|
|
2017-06-10 15:21:34 -06:00
|
|
|
DFHACK_EXPORT int32_t findIndexById(int32_t id);
|
2011-05-12 11:09:49 -06:00
|
|
|
|
2012-04-13 06:10:19 -06:00
|
|
|
/// Returns the true position of the unit (non-trivial in case of caged).
|
|
|
|
DFHACK_EXPORT df::coord getPosition(df::unit *unit);
|
|
|
|
|
2021-06-06 09:48:32 -06:00
|
|
|
// moves unit and any riders to the target coordinates
|
|
|
|
DFHACK_EXPORT bool teleport(df::unit *unit, df::coord target_pos);
|
|
|
|
|
2012-11-12 08:17:32 -07:00
|
|
|
DFHACK_EXPORT df::general_ref *getGeneralRef(df::unit *unit, df::general_ref_type type);
|
|
|
|
DFHACK_EXPORT df::specific_ref *getSpecificRef(df::unit *unit, df::specific_ref_type type);
|
|
|
|
|
2012-04-13 06:10:19 -06:00
|
|
|
DFHACK_EXPORT df::item *getContainer(df::unit *unit);
|
2022-03-13 18:19:35 -06:00
|
|
|
/// what is the outermost object it is contained in? Possible ref types: UNIT, ITEM_GENERAL, VERMIN_EVENT
|
|
|
|
DFHACK_EXPORT void getOuterContainerRef(df::specific_ref &spec_ref, df::unit *unit, bool init_ref=true);
|
|
|
|
DFHACK_EXPORT inline df::specific_ref getOuterContainerRef(df::unit *unit) { df::specific_ref s; getOuterContainerRef(s, unit); return s; }
|
2012-04-13 06:10:19 -06:00
|
|
|
|
2012-04-07 09:08:30 -06:00
|
|
|
DFHACK_EXPORT void setNickname(df::unit *unit, std::string nick);
|
2012-04-06 01:21:28 -06:00
|
|
|
DFHACK_EXPORT df::language_name *getVisibleName(df::unit *unit);
|
2012-03-18 05:35:38 -06:00
|
|
|
|
2014-07-29 15:30:22 -06:00
|
|
|
DFHACK_EXPORT df::identity *getIdentity(df::unit *unit);
|
2012-04-07 09:08:30 -06:00
|
|
|
DFHACK_EXPORT df::nemesis_record *getNemesis(df::unit *unit);
|
|
|
|
|
2012-09-09 02:51:08 -06:00
|
|
|
DFHACK_EXPORT int getPhysicalAttrValue(df::unit *unit, df::physical_attribute_type attr);
|
|
|
|
DFHACK_EXPORT int getMentalAttrValue(df::unit *unit, df::mental_attribute_type attr);
|
2015-12-19 09:07:35 -07:00
|
|
|
DFHACK_EXPORT bool casteFlagSet(int race, int caste, df::caste_raw_flags flag);
|
2012-09-09 02:51:08 -06:00
|
|
|
|
2022-11-13 12:39:20 -07:00
|
|
|
DFHACK_EXPORT df::unit_misc_trait *getMiscTrait(df::unit *unit, df::misc_trait_type type, bool create = false);
|
2015-01-28 14:26:17 -07:00
|
|
|
|
2015-01-29 14:35:53 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceNameById(int32_t race_id);
|
2015-01-28 14:26:17 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceName(df::unit* unit);
|
2019-12-14 10:34:46 -07:00
|
|
|
DFHACK_EXPORT std::string getPhysicalDescription(df::unit* unit);
|
2015-01-29 14:35:53 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceNamePluralById(int32_t race_id);
|
2015-01-28 14:26:17 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceNamePlural(df::unit* unit);
|
2023-01-13 22:20:01 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceReadableNameById(int32_t race_id);
|
|
|
|
DFHACK_EXPORT std::string getRaceReadableName(df::unit* unit);
|
2015-01-29 14:35:53 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceBabyNameById(int32_t race_id);
|
2015-01-28 14:26:17 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceBabyName(df::unit* unit);
|
2015-01-29 14:35:53 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceChildNameById(int32_t race_id);
|
2015-01-28 14:26:17 -07:00
|
|
|
DFHACK_EXPORT std::string getRaceChildName(df::unit* unit);
|
|
|
|
|
2012-04-14 04:12:59 -06:00
|
|
|
|
2012-04-23 11:30:53 -06:00
|
|
|
DFHACK_EXPORT double getAge(df::unit *unit, bool true_age = false);
|
2016-02-25 13:21:14 -07:00
|
|
|
DFHACK_EXPORT int getKillCount(df::unit *unit);
|
2012-04-21 05:43:52 -06:00
|
|
|
|
2012-09-29 05:18:04 -06:00
|
|
|
DFHACK_EXPORT int getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust = false);
|
2012-09-09 02:27:40 -06:00
|
|
|
DFHACK_EXPORT int getEffectiveSkill(df::unit *unit, df::job_skill skill_id);
|
2012-11-16 11:48:49 -07:00
|
|
|
DFHACK_EXPORT int getExperience(df::unit *unit, df::job_skill skill_id, bool total = false);
|
|
|
|
|
2015-10-30 16:41:09 -06:00
|
|
|
DFHACK_EXPORT bool isValidLabor(df::unit *unit, df::unit_labor labor);
|
2021-02-05 17:45:39 -07:00
|
|
|
DFHACK_EXPORT bool setLaborValidity(df::unit_labor labor, bool isValid);
|
2015-10-30 16:41:09 -06:00
|
|
|
|
2012-09-09 07:04:58 -06:00
|
|
|
DFHACK_EXPORT int computeMovementSpeed(df::unit *unit);
|
2014-04-15 02:32:41 -06:00
|
|
|
DFHACK_EXPORT float computeSlowdownFactor(df::unit *unit);
|
2012-09-09 02:27:40 -06:00
|
|
|
|
2012-04-26 02:03:56 -06:00
|
|
|
struct NoblePosition {
|
|
|
|
df::historical_entity *entity;
|
|
|
|
df::entity_position_assignment *assignment;
|
|
|
|
df::entity_position *position;
|
|
|
|
};
|
|
|
|
|
|
|
|
DFHACK_EXPORT bool getNoblePositions(std::vector<NoblePosition> *pvec, df::unit *unit);
|
|
|
|
|
|
|
|
DFHACK_EXPORT std::string getProfessionName(df::unit *unit, bool ignore_noble = false, bool plural = false);
|
2012-04-23 11:30:53 -06:00
|
|
|
DFHACK_EXPORT std::string getCasteProfessionName(int race, int caste, df::profession pid, bool plural = false);
|
2012-08-22 15:54:00 -06:00
|
|
|
|
|
|
|
DFHACK_EXPORT int8_t getProfessionColor(df::unit *unit, bool ignore_noble = false);
|
|
|
|
DFHACK_EXPORT int8_t getCasteProfessionColor(int race, int caste, df::profession pid);
|
2014-06-09 19:51:52 -06:00
|
|
|
|
2020-08-08 12:34:47 -06:00
|
|
|
DFHACK_EXPORT df::goal_type getGoalType(df::unit *unit, size_t goalIndex = 0);
|
|
|
|
DFHACK_EXPORT std::string getGoalName(df::unit *unit, size_t goalIndex = 0);
|
|
|
|
DFHACK_EXPORT bool isGoalAchieved(df::unit *unit, size_t goalIndex = 0);
|
2020-08-04 16:01:28 -06:00
|
|
|
|
2017-04-28 15:25:58 -06:00
|
|
|
DFHACK_EXPORT df::activity_entry *getMainSocialActivity(df::unit *unit);
|
|
|
|
DFHACK_EXPORT df::activity_event *getMainSocialEvent(df::unit *unit);
|
|
|
|
|
2018-07-09 13:59:12 -06:00
|
|
|
// stress categories - 0 is highest stress
|
|
|
|
DFHACK_EXPORT extern const std::vector<int32_t> stress_cutoffs;
|
|
|
|
DFHACK_EXPORT int getStressCategory(df::unit *unit);
|
|
|
|
DFHACK_EXPORT int getStressCategoryRaw(int32_t stress_level);
|
|
|
|
|
2022-11-27 10:07:47 -07:00
|
|
|
DFHACK_EXPORT void subtractActionTimers(color_ostream &out, df::unit *unit, int32_t amount, df::unit_action_type affectedActionType);
|
2022-12-01 16:24:04 -07:00
|
|
|
DFHACK_EXPORT void subtractGroupActionTimers(color_ostream &out, df::unit *unit, int32_t amount, df::unit_action_type_group affectedActionTypeGroup);
|
2022-11-27 10:07:47 -07:00
|
|
|
DFHACK_EXPORT void multiplyActionTimers(color_ostream &out, df::unit *unit, float amount, df::unit_action_type affectedActionType);
|
2022-12-01 16:24:04 -07:00
|
|
|
DFHACK_EXPORT void multiplyGroupActionTimers(color_ostream &out, df::unit *unit, float amount, df::unit_action_type_group affectedActionTypeGroup);
|
2022-11-27 10:07:47 -07:00
|
|
|
DFHACK_EXPORT void setActionTimers(color_ostream &out, df::unit *unit, int32_t amount, df::unit_action_type affectedActionType);
|
2022-12-01 16:24:04 -07:00
|
|
|
DFHACK_EXPORT void setGroupActionTimers(color_ostream &out, df::unit *unit, int32_t amount, df::unit_action_type_group affectedActionTypeGroup);
|
2022-11-07 16:01:00 -07:00
|
|
|
|
2012-01-24 10:32:34 -07:00
|
|
|
}
|
|
|
|
}
|