Cleanup the Units module

develop
Quietust 2012-01-21 13:03:39 -06:00
parent 118e5c6617
commit 8052305c2e
5 changed files with 75 additions and 659 deletions

@ -31,144 +31,14 @@ distribution.
#include "Export.h"
#include "Module.h"
#include "modules/Items.h"
#include "df/unit.h"
/**
* \defgroup grp_units Unit module parts
* @ingroup grp_modules
*/
namespace DFHack
{
/**
* easy access to first crature flags block
* \ingroup grp_units
*/
union t_unitflags1
{
uint32_t whole;/*!< Access all flags as a single 32bit number. */
struct
{
unsigned int move_state : 1; /*!< 0 : Can the dwarf move or are they waiting for their movement timer */
unsigned int dead : 1; /*!< 1 : Dead (might also be set for incoming/leaving critters that are alive) */
unsigned int has_mood : 1; /*!< 2 : Currently in mood */
unsigned int had_mood : 1; /*!< 3 : Had a mood already */
unsigned int marauder : 1; /*!< 4 : wide class of invader/inside creature attackers */
unsigned int drowning : 1; /*!< 5 : Is currently drowning */
unsigned int merchant : 1; /*!< 6 : An active merchant */
unsigned int forest : 1; /*!< 7 : used for units no longer linked to merchant/diplomacy, they just try to leave mostly */
unsigned int left : 1; /*!< 8 : left the map */
unsigned int rider : 1; /*!< 9 : Is riding an another creature */
unsigned int incoming : 1; /*!< 10 */
unsigned int diplomat : 1; /*!< 11 */
unsigned int zombie : 1; /*!< 12 */
unsigned int skeleton : 1; /*!< 13 */
unsigned int can_swap : 1; /*!< 14: Can swap tiles during movement (prevents multiple swaps) */
unsigned int on_ground : 1; /*!< 15: The creature is laying on the floor, can be conscious */
unsigned int projectile : 1; /*!< 16: Launched into the air? Funny. */
unsigned int active_invader : 1; /*!< 17: Active invader (for organized ones) */
unsigned int hidden_in_ambush : 1; /*!< 18 */
unsigned int invader_origin : 1; /*!< 19: Invader origin (could be inactive and fleeing) */
unsigned int coward : 1; /*!< 20: Will flee if invasion turns around */
unsigned int hidden_ambusher : 1; /*!< 21: Active marauder/invader moving inward? */
unsigned int invades : 1; /*!< 22: Marauder resident/invader moving in all the way */
unsigned int check_flows : 1; /*!< 23: Check against flows next time you get a chance */
unsigned int ridden : 1; /*!< 24*/
unsigned int caged : 1; /*!< 25*/
unsigned int tame : 1; /*!< 26*/
unsigned int chained : 1; /*!< 27*/
unsigned int royal_guard : 1; /*!< 28*/
unsigned int fortress_guard : 1; /*!< 29*/
unsigned int suppress_wield : 1; /*!< 30: Suppress wield for beatings/etc */
unsigned int important_historical_figure : 1; /*!< 31: Is an important historical figure */
} bits;
};
union t_unitflags2
{
uint32_t whole; /*!< Access all flags as a single 32bit number. */
struct
{
unsigned int swimming : 1;
unsigned int sparring : 1;
unsigned int no_notify : 1; /*!< Do not notify about level gains (for embark etc)*/
unsigned int unused : 1;
unsigned int calculated_nerves : 1;
unsigned int calculated_bodyparts : 1;
unsigned int important_historical_figure : 1; /*!< Is important historical figure (slight variation)*/
unsigned int killed : 1; /*!< Has been killed by kill function (slightly different from dead, not necessarily violent death)*/
unsigned int cleanup_1 : 1; /*!< Must be forgotten by forget function (just cleanup) */
unsigned int cleanup_2 : 1; /*!< Must be deleted (cleanup) */
unsigned int cleanup_3 : 1; /*!< Recently forgotten (cleanup) */
unsigned int for_trade : 1; /*!< Offered for trade */
unsigned int trade_resolved : 1;
unsigned int has_breaks : 1;
unsigned int gutted : 1;
unsigned int circulatory_spray : 1;
unsigned int locked_in_for_trading : 1; /*!< Locked in for trading (it's a projectile on the other set of flags, might be what the flying was) */
unsigned int slaughter : 1; /*!< marked for slaughter */
unsigned int underworld : 1; /*!< Underworld creature */
unsigned int resident : 1; /*!< Current resident */
unsigned int cleanup_4 : 1; /*!< Marked for special cleanup as unused load from unit block on disk */
unsigned int calculated_insulation : 1; /*!< Insulation from clothing calculated */
unsigned int visitor_uninvited : 1; /*!< Uninvited guest */
unsigned int visitor : 1; /*!< visitor */
unsigned int calculated_inventory : 1; /*!< Inventory order calculated */
unsigned int vision_good : 1; /*!< Vision -- have good part */
unsigned int vision_damaged : 1; /*!< Vision -- have damaged part */
unsigned int vision_missing : 1; /*!< Vision -- have missing part */
unsigned int breathing_good : 1; /*!< Breathing -- have good part */
unsigned int breathing_problem : 1; /*!< Breathing -- having a problem */
unsigned int roaming_wilderness_population_source : 1;
unsigned int roaming_wilderness_population_source_not_a_map_feature : 1;
} bits;
};
union t_unitflags3
{
uint32_t whole; /*!< Access all flags as a single 32bit number. */
struct
{
unsigned int unk0 : 1; /*!< Is 1 for new and dead creatures,
periodicaly set to 0 for non-dead creatures.
*/
unsigned int unk1 : 1; /*!< Is 1 for new creatures, periodically set
to 0 for non-dead creatures. */
unsigned int unk2 : 1; /*!< Is set to 1 every tick for non-dead
creatures. */
unsigned int unk3 : 1; /*!< Is periodically set to 0 for non-dead
creatures. */
unsigned int announce_titan : 1; /*!< Announces creature like an
FB or titan. */
unsigned int unk5 : 1;
unsigned int unk6 : 1;
unsigned int unk7 : 1;
unsigned int unk8 : 1; /*!< Is set to 1 every tick for non-dead
creatures. */
unsigned int unk9 : 1; /*!< Is set to 0 every tick for non-dead
creatures. */
unsigned int scuttle : 1; /*!< Scuttle creature: causes creature
to be killed, leaving a behind corpse
and generating negative thoughts like
a real kill. */
unsigned int unk11 : 1;
unsigned int ghostly : 1; /*!< Creature is a ghost. */
unsigned int unk13_31 : 19;
} bits;
};
// FIXME: WTF IS THIS SHIT?
/*
struct t_labor
@ -308,16 +178,16 @@ namespace DFHack
*/
struct t_unit
{
df_unit * origin;
df::unit * origin;
uint16_t x;
uint16_t y;
uint16_t z;
uint32_t race;
int32_t civ;
t_unitflags1 flags1;
t_unitflags2 flags2;
t_unitflags3 flags3;
df::unit_flags1 flags1;
df::unit_flags2 flags2;
df::unit_flags3 flags3;
t_name name;
@ -353,404 +223,6 @@ namespace DFHack
uint32_t birth_time;
};
/**
* Unit attribute descriptor
* \ingroup grp_units
*/
struct df_attrib
{
uint32_t unk_0;
uint32_t unk_4;
uint32_t unk_8;
uint32_t unk_c;
uint32_t unk_10;
uint32_t unk_14;
uint32_t unk_18;
};
/**
* Unit skill descriptor
* \ingroup grp_units
*/
struct df_skill
{
uint16_t id; // 0
int32_t rating; // 4
uint32_t experience; // 8
uint32_t unk_c;
uint32_t rusty; // 10
uint32_t unk_14;
uint32_t unk_18;
uint32_t unk_1c;
};
/**
* Unit like descriptor
* \ingroup grp_units
*/
struct df_like
{
int16_t type;
int16_t itemClass;
int16_t itemIndex;
int16_t material_type;
int32_t material_index;
bool active;
uint32_t mystery;
};
/**
* A creature's soul, as it appears in DF memory
* \ingroup grp_units
*/
struct df_soul
{
uint32_t creature_id;
df_name name; // 4
uint32_t unk_70;
uint16_t unk_74;
uint16_t unk_76;
int32_t unk_78;
int32_t unk_7c;
int32_t unk_80;
int32_t unk_84;
df_attrib mental[NUM_CREATURE_MENTAL_ATTRIBUTES]; // 88..1f3
std::vector<df_skill*> skills; // 1f4;
std::vector<df_like*> likes; // pointers to 14 0x14-byte structures ... likes?
uint16_t traits[NUM_CREATURE_TRAITS]; // 214
std::vector<int16_t*> unk_250; // 1 pointer to 2 shorts
uint32_t unk_260;
uint32_t unk_264;
uint32_t unk_268;
uint32_t unk_26c;
};
/**
* A creature job - what it's supposed to be doing.
* \ingroup grp_units
*/
struct df_job
{
};
/**
* A creature though - dwarves staring at waterfalls!
* \ingroup grp_units
*/
struct df_thought
{
// needs enum
int16_t type;
// possible int16_t here
int32_t age;
int32_t subtype;
int32_t severity;
//possibly more.
};
/**
* A creature, as it appears in DF memory
* \ingroup grp_units
*/
struct df_unit
{
df_name name; // 0
std::string custom_profession; // 6c (MSVC)
uint8_t profession; // 88
uint32_t race; // 8c
uint16_t x; // 90
uint16_t y; // 92
uint16_t z; // 94
uint16_t unk_x96; // 96
uint16_t unk_y98; // 98
uint16_t unk_z9a; // 9a
uint32_t unk_9c;
uint16_t unk_a0;
int16_t unk_a2;
uint32_t unk_a4;
uint16_t dest_x; // a8
uint16_t dest_y; // aa
uint16_t dest_z; // ac
uint16_t unk_ae; // -1
std::vector<uint32_t> unk_b0; // b0->df (3*4 in MSVC) -> 68->8b (3*3 in glibc)
std::vector<uint32_t> unk_c0;
std::vector<uint32_t> unk_d0;
t_unitflags1 flags1; // e0
t_unitflags2 flags2; // e4
t_unitflags3 flags3; // e8
void ** unk_ec;
int32_t unk_f0;
int16_t unk_f4;
int16_t unk_f6;
uint16_t caste; // f8
uint8_t sex; // fa
uint32_t id; // fc
uint16_t unk_100;
uint16_t unk_102;
int32_t unk_104;
uint32_t civ; // 108
uint32_t unk_10c;
int32_t unk_110;
std::vector<uint32_t> unk_114;
std::vector<uint32_t> unk_124;
std::vector<uint32_t> unk_134;
uint32_t unk_144;
std::vector<void*> unk_148;
std::vector<void*> unk_158;
int32_t unk_168;
int32_t unk_16c;
uint32_t unk_170;
uint32_t unk_174;
uint16_t unk_178;
std::vector<uint32_t> unk_17c;
std::vector<uint32_t> unk_18c;
std::vector<uint32_t> unk_19c;
std::vector<uint32_t> unk_1ac;
uint32_t pickup_equipment_bit; // 1bc
std::vector<uint32_t> unk_1c0;
std::vector<uint32_t> unk_1d0;
std::vector<uint32_t> unk_1e0;
int32_t unk_1f0;
int16_t unk_1f4;
int32_t unk_1f8;
int32_t unk_1fc;
int32_t unk_200;
int16_t unk_204;
uint32_t unk_208;
uint32_t unk_20c;
int16_t mood; // 210
uint32_t pregnancy_timer; // 214
void* pregnancy_ptr; // 218
int32_t unk_21c;
uint32_t unk_220;
uint32_t birth_year; // 224
uint32_t birth_time; // 228
uint32_t unk_22c;
uint32_t unk_230;
df_unit * unk_234; // suspiciously close to the pregnancy/birth stuff. Mother?
uint32_t unk_238;
int32_t unk_23c;
int32_t unk_240;
int32_t unk_244;
int32_t unk_248;
int32_t unk_24c;
int32_t unk_250;
int32_t unk_254;
int32_t unk_258;
int32_t unk_25c;
int32_t unk_260;
int16_t unk_264;
int32_t unk_268;
int32_t unk_26c;
int16_t unk_270;
int32_t unk_274;
int32_t unk_278;
int32_t unk_27c;
int16_t unk_280;
int32_t unk_284;
std::vector<df::item *> inventory; // 288 - vector of item pointers
std::vector<int32_t> owned_items; // 298 - vector of item IDs
std::vector<uint32_t> unk_2a8;
std::vector<uint32_t> unk_2b8;
std::vector<uint32_t> unk_2c8;
uint32_t unk_2d8;
uint32_t unk_2dc;
uint32_t unk_2e0;
uint32_t unk_2e4;
uint32_t unk_2e8;
uint32_t unk_2ec;
uint32_t unk_2f0;
df_job * current_job; // 2f4
uint32_t unk_2f8; // possibly current skill?
uint32_t unk_2fc;
uint32_t unk_300;
uint32_t unk_304;
std::vector<uint32_t> unk_308;
std::vector<uint32_t> unk_318;
std::vector<uint32_t> unk_328;
std::vector<uint32_t> unk_338;
std::vector<uint32_t> unk_348;
std::vector<uint32_t> unk_358;
std::vector<uint32_t> unk_368;
std::vector<uint32_t> unk_378;
std::vector<uint32_t> unk_388;
uint32_t unk_398;
int32_t unk_39c;
int32_t unk_3a0;
int32_t unk_3a4;
int32_t unk_3a8;
int32_t unk_3ac;
int32_t unk_3b0;
int32_t unk_3b4;
int32_t unk_3b8;
int32_t unk_3bc;
int32_t unk_3c0;
uint32_t unk_3c4;
uint32_t unk_3c8;
df_attrib physical[NUM_CREATURE_PHYSICAL_ATTRIBUTES]; // 3cc..473
uint32_t unk_474;
uint32_t unk_478;
uint32_t unk_47c;
uint32_t unk_480;
uint32_t unk_484;
uint32_t unk_488;
uint32_t unk_48c; // blood_max?
uint32_t blood_count; // 490
uint32_t unk_494;
// dirt, grime, FB blood, mud and plain old filth stuck to the poor thing's parts and pieces
std::vector<void*> contaminants;
std::vector<uint16_t> unk_4a8;
std::vector<uint16_t> unk_4b8;
uint32_t unk_4c8;
std::vector<int16_t> unk_4cc;
std::vector<int32_t> unk_4dc;
std::vector<int32_t> unk_4ec;
std::vector<int32_t> unk_4fc;
std::vector<uint16_t> unk_50c;
void* unk_51c;
uint16_t unk_520;
uint16_t unk_522;
uint16_t* unk_524;
uint16_t unk_528;
uint16_t unk_52a;
std::vector<uint32_t> appearance; // 52c
int16_t unk_53c;
int16_t unk_53e;
int16_t job_counter; // tick until next job update?
int16_t unk_542;
int16_t unk_544;
int16_t unk_546;
int16_t unk_548;
int16_t unk_54a;
int16_t unk_54c;
int16_t unk_54e;
int16_t unk_550;
int16_t unk_552;
int16_t unk_x554; // coords ? (-30.000x3)
int16_t unk_y556;
int16_t unk_z558;
int16_t unk_x55a; // coords again
int16_t unk_y55c;
int16_t unk_z55e;
int16_t unk_560;
int16_t unk_562;
uint32_t unk_564;
uint32_t unk_568;
uint32_t unk_56c;
uint32_t unk_570;
uint32_t unk_574;
uint32_t unk_578;
uint32_t unk_57c;
uint32_t unk_580;
uint32_t unk_584;
uint32_t unk_588;
uint32_t unk_58c;
uint32_t unk_590;
uint32_t unk_594;
uint32_t unk_598;
uint32_t unk_59c;
std::vector<void*> unk_5a0;
void* unk_5b0; // pointer to X (12?) vector<int16_t>
uint32_t unk_5b4; // 0x3e8 (1000)
uint32_t unk_5b8; // 0x3e8 (1000)
std::vector<uint32_t> unk_5bc;
std::vector<uint32_t> unk_5cc;
int16_t unk_5dc;
int16_t unk_5de;
df_name artifact_name; // 5e0
std::vector<df_soul*> souls; // 64c
df_soul* current_soul; // 65c
std::vector<uint32_t> unk_660;
uint8_t labors[NUM_CREATURE_LABORS]; // 670..6cf
std::vector<uint32_t> unk_6d0;
std::vector<uint32_t> unk_6e0;
std::vector<df_thought *> thoughts;
std::vector<uint32_t> unk_700;
uint32_t happiness; // 710
uint16_t unk_714;
uint16_t unk_716;
std::vector<void*> unk_718;
std::vector<void*> unk_728;
std::vector<void*> unk_738;
std::vector<void*> unk_748;
uint16_t unk_758;
uint16_t unk_x75a; // coords (-30000*3)
uint16_t unk_y75c;
uint16_t unk_z75e;
std::vector<uint16_t> unk_760;
std::vector<uint16_t> unk_770;
std::vector<uint16_t> unk_780;
uint32_t hist_figure_id; // 790
uint16_t able_stand; // 794
uint16_t able_stand_impair; // 796
uint16_t able_grasp; // 798
uint16_t able_grasp_impair; // 79a
uint32_t unk_79c; // able_fly/impair (maybe)
uint32_t unk_7a0; // able_fly/impair (maybe)
std::vector<void*> unk_7a4;
uint32_t unk_7b4;
uint32_t unk_7b8;
uint32_t unk_7bc;
int32_t unk_7c0;
std::vector<uint32_t> unk_7c4;
std::vector<uint32_t> unk_7d4;
std::vector<uint32_t> unk_7e4;
std::vector<uint32_t> unk_7f4;
std::vector<uint32_t> unk_804;
std::vector<uint32_t> unk_814;
uint32_t unk_824;
void* unk_828;
void* unk_82c;
uint32_t unk_830;
void* unk_834;
void* unk_838;
void* unk_83c;
std::vector<void*> unk_840;
std::vector<uint32_t> unk_850;
std::vector<uint32_t> unk_860;
uint32_t unk_870;
uint32_t unk_874;
std::vector<uint8_t> unk_878;
std::vector<uint8_t> unk_888;
std::vector<uint32_t> unk_898;
std::vector<uint8_t> unk_8a8;
std::vector<uint16_t> unk_8b8;
std::vector<uint16_t> unk_8c8;
std::vector<uint32_t> unk_8d8;
std::vector<uint32_t> unk_8e8;
std::vector<uint32_t> unk_8f8;
std::vector<uint32_t> unk_908;
int32_t unk_918;
uint16_t unk_91c;
uint16_t unk_91e;
uint16_t unk_920;
uint16_t unk_922;
uint32_t unk_924;
uint32_t unk_928;
std::vector<uint16_t> unk_92c;
uint32_t unk_93c;
};
/**
* The Creatures module - allows reading all non-vermin creatures and their properties
* \ingroup grp_modules
@ -758,8 +230,6 @@ namespace DFHack
*/
class DFHACK_EXPORT Units : public Module
{
public:
std::vector <df_unit *> * creatures;
public:
Units();
~Units();
@ -769,19 +239,19 @@ namespace DFHack
/* Read Functions */
// Read creatures in a box, starting with index. Returns -1 if no more creatures
// found. Call repeatedly do get all creatures in a specified box (uses tile coords)
int32_t GetCreatureInBox(const int32_t index, df_unit ** furball,
int32_t GetCreatureInBox(const int32_t index, df::unit ** furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2);
df_unit * GetCreature(const int32_t index);
void CopyCreature(df_unit * source, t_unit & target);
df::unit * GetCreature(const int32_t index);
void CopyCreature(df::unit * source, t_unit & target);
bool ReadJob(const df_unit * unit, std::vector<t_material> & mat);
bool ReadJob(const df::unit * unit, std::vector<t_material> & mat);
bool ReadInventoryByIdx(const uint32_t index, std::vector<df::item *> & item);
bool ReadInventoryByPtr(const df_unit * unit, std::vector<df::item *> & item);
bool ReadInventoryByPtr(const df::unit * unit, std::vector<df::item *> & item);
bool ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item);
bool ReadOwnedItemsByPtr(const df_unit * unit, std::vector<int32_t> & item);
bool ReadOwnedItemsByPtr(const df::unit * unit, std::vector<int32_t> & item);
int32_t FindIndexById(int32_t id);
@ -789,26 +259,10 @@ namespace DFHack
uint32_t GetDwarfRaceIndex ( void );
int32_t GetDwarfCivId ( void );
/* Write Functions */
//bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
//bool WriteHappiness(const uint32_t index, const uint32_t happinessValue);
//bool WriteFlags(const uint32_t index, const uint32_t flags1, const uint32_t flags2);
//bool WriteFlags(const uint32_t index, const uint32_t flags1, const uint32_t flags2, uint32_t flags3);
//bool WriteSkills(const uint32_t index, const t_soul &soul);
//bool WriteAttributes(const uint32_t index, const t_creature &creature);
//bool WriteSex(const uint32_t index, const uint8_t sex);
//bool WriteTraits(const uint32_t index, const t_soul &soul);
//bool WriteMood(const uint32_t index, const uint16_t mood);
//bool WriteMoodSkill(const uint32_t index, const uint16_t moodSkill);
//bool WriteJob(const t_creature * furball, std::vector<t_material> const& mat);
//bool WritePos(const uint32_t index, const t_creature &creature);
//bool WriteCiv(const uint32_t index, const int32_t civ);
//bool WritePregnancy(const uint32_t index, const uint32_t pregTimer);
void CopyNameTo(df_unit *creature, df_name * target);
void CopyNameTo(df::unit *creature, df_name * target);
bool RemoveOwnedItemByIdx(const uint32_t index, int32_t id);
bool RemoveOwnedItemByPtr(df_unit * unit, int32_t id);
bool RemoveOwnedItemByPtr(df::unit * unit, int32_t id);
private:
struct Private;

@ -474,7 +474,7 @@ bool Items::removeItemOwner(df::item * item, Units *creatures)
if (ref->getType() != df::general_ref_type::UNIT_ITEMOWNER)
continue;
df_unit *unit = (df_unit *)ref->getUnit();
df::unit *unit = ref->getUnit();
if (unit == NULL || !creatures->RemoveOwnedItemByPtr(unit, item->id))
{

@ -46,15 +46,19 @@ using namespace std;
#include "ModuleFactory.h"
#include "Core.h"
#include "df/world.h"
#include "df/ui.h"
#include "df/unit_inventory_item.h"
using namespace DFHack;
using df::global::world;
using df::global::ui;
struct Units::Private
{
bool Inited;
bool Started;
void * dwarf_race_index_addr;
void * dwarf_civ_id_addr;
bool IdMapReady;
std::map<int32_t, int32_t> IdMap;
@ -81,14 +85,6 @@ Units::Units()
OffsetGroup *OG_Creatures = minfo->getGroup("Creatures");
creatures = 0;
try
{
creatures = (vector <df_unit *> *) OG_Creatures->getAddress ("vector");
d->dwarf_race_index_addr = (void *) OG_Creatures->getAddress("current_race");
d->dwarf_civ_id_addr = (void *) OG_Creatures->getAddress("current_civ");
}
catch(Error::All&){};
d->Inited = true;
}
@ -100,15 +96,11 @@ Units::~Units()
bool Units::Start( uint32_t &numcreatures )
{
if(creatures)
{
d->Started = true;
numcreatures = creatures->size();
numcreatures = world->units.all.size();
d->IdMap.clear();
d->IdMapReady = false;
return true;
}
return false;
}
bool Units::Finish()
@ -117,35 +109,34 @@ bool Units::Finish()
return true;
}
df_unit * Units::GetCreature (const int32_t index)
df::unit * Units::GetCreature (const int32_t index)
{
if(!d->Started) return NULL;
// read pointer from vector at position
if(index > creatures->size())
if(index > world->units.all.size())
return 0;
return creatures->at(index);
return world->units.all[index];
}
// returns index of creature actually read or -1 if no creature can be found
int32_t Units::GetCreatureInBox (int32_t index, df_unit ** furball,
int32_t Units::GetCreatureInBox (int32_t index, df::unit ** furball,
const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2)
{
if (!d->Started)
return -1;
Process *p = d->owner;
uint32_t size = creatures->size();
uint32_t size = world->units.all.size();
while (uint32_t(index) < size)
{
// read pointer from vector at position
df_unit * temp = creatures->at(index);
if (temp->x >= x1 && temp->x < x2)
df::unit * temp = world->units.all[index];
if (temp->pos.x >= x1 && temp->pos.x < x2)
{
if (temp->y >= y1 && temp->y < y2)
if (temp->pos.y >= y1 && temp->pos.y < y2)
{
if (temp->z >= z1 && temp->z < z2)
if (temp->pos.z >= z1 && temp->pos.z < z2)
{
*furball = temp;
return index;
@ -158,7 +149,7 @@ int32_t Units::GetCreatureInBox (int32_t index, df_unit ** furball,
return -1;
}
void Units::CopyCreature(df_unit * source, t_unit & furball)
void Units::CopyCreature(df::unit * source, t_unit & furball)
{
if(!d->Started) return;
// read pointer from vector at position
@ -166,15 +157,15 @@ void Units::CopyCreature(df_unit * source, t_unit & furball)
//read creature from memory
// name
d->trans->readName(furball.name,&source->name);
d->trans->readName(furball.name,(df_name *)&source->name);
// basic stuff
furball.id = source->id;
furball.x = source->x;
furball.y = source->y;
furball.z = source->z;
furball.x = source->pos.x;
furball.y = source->pos.y;
furball.z = source->pos.z;
furball.race = source->race;
furball.civ = source->civ;
furball.civ = source->civ_id;
furball.sex = source->sex;
furball.caste = source->caste;
furball.flags1.whole = source->flags1.whole;
@ -185,28 +176,28 @@ void Units::CopyCreature(df_unit * source, t_unit & furball)
// profession
furball.profession = source->profession;
// happiness
furball.happiness = source->happiness;
furball.happiness = source->status.happiness;
// physical attributes
memcpy(&furball.strength, source->physical, sizeof(source->physical));
memcpy(&furball.strength, source->body.physical_attrs, sizeof(source->body.physical_attrs));
// mood stuff
furball.mood = source->mood;
furball.mood_skill = source->unk_2f8; // FIXME: really? More like currently used skill anyway.
d->trans->readName(furball.artifact_name, &source->artifact_name);
furball.mood_skill = source->job.unk_2f8; // FIXME: really? More like currently used skill anyway.
d->trans->readName(furball.artifact_name, (df_name *)&source->status.artifact_name);
// labors
memcpy(&furball.labors, &source->labors, sizeof(furball.labors));
memcpy(&furball.labors, &source->status.labors, sizeof(furball.labors));
furball.birth_year = source->birth_year;
furball.birth_time = source->birth_time;
furball.pregnancy_timer = source->pregnancy_timer;
furball.birth_year = source->relations.birth_year;
furball.birth_time = source->relations.birth_time;
furball.pregnancy_timer = source->relations.pregnancy_timer;
// appearance
furball.nbcolors = source->appearance.size();
furball.nbcolors = source->appearance.colors.size();
if(furball.nbcolors>MAX_COLORS)
furball.nbcolors = MAX_COLORS;
for(uint32_t i = 0; i < furball.nbcolors; i++)
{
furball.color[i] = source->appearance[i];
furball.color[i] = source->appearance.colors[i];
}
//likes. FIXME: where do they fit in now? The soul?
@ -275,28 +266,7 @@ void Units::CopyCreature(df_unit * source, t_unit & furball)
}
int32_t Units::FindIndexById(int32_t creature_id)
{
if (!d->Started)
return -1;
if (!d->IdMapReady)
{
d->IdMap.clear();
uint32_t size = creatures->size();
for (uint32_t index = 0; index < size; index++)
{
df_unit * temp = creatures->at(index);
int32_t id = temp->id;
d->IdMap[id] = index;
}
}
std::map<int32_t,int32_t>::iterator it;
it = d->IdMap.find(creature_id);
if(it == d->IdMap.end())
return -1;
else
return it->second;
return df::unit::binsearch_index(world->units.all, creature_id);
}
/*
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
@ -507,16 +477,12 @@ bool Creatures::WritePregnancy(const uint32_t index, const uint32_t pregTimer)
*/
uint32_t Units::GetDwarfRaceIndex()
{
if(!d->Inited) return 0;
Process * p = d->owner;
return p->readDWord(d->dwarf_race_index_addr);
return ui->race_id;
}
int32_t Units::GetDwarfCivId()
{
if(!d->Inited) return -1;
Process * p = d->owner;
return p->readDWord(d->dwarf_civ_id_addr);
return ui->civ_id;
}
/*
bool Creatures::getCurrentCursorCreature(uint32_t & creature_index)
@ -551,28 +517,28 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
*/
bool Units::ReadInventoryByIdx(const uint32_t index, std::vector<df::item *> & item)
{
if(!d->Started) return false;
if(index >= creatures->size()) return false;
df_unit * temp = creatures->at(index);
if(index >= world->units.all.size()) return false;
df::unit * temp = world->units.all[index];
return this->ReadInventoryByPtr(temp, item);
}
bool Units::ReadInventoryByPtr(const df_unit * temp, std::vector<df::item *> & items)
bool Units::ReadInventoryByPtr(const df::unit * temp, std::vector<df::item *> & items)
{
if(!d->Started) return false;
items = temp->inventory;
items.clear();
for (uint32_t i = 0; i < temp->inventory.size(); i++)
items.push_back(temp->inventory[i]->item);
return true;
}
bool Units::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item)
{
if(!d->Started ) return false;
if(index >= creatures->size()) return false;
df_unit * temp = creatures->at(index);
if(index >= world->units.all.size()) return false;
df::unit * temp = world->units.all[index];
return this->ReadOwnedItemsByPtr(temp, item);
}
bool Units::ReadOwnedItemsByPtr(const df_unit * temp, std::vector<int32_t> & items)
bool Units::ReadOwnedItemsByPtr(const df::unit * temp, std::vector<int32_t> & items)
{
if(!d->Started) return false;
items = temp->owned_items;
@ -581,16 +547,12 @@ bool Units::ReadOwnedItemsByPtr(const df_unit * temp, std::vector<int32_t> & ite
bool Units::RemoveOwnedItemByIdx(const uint32_t index, int32_t id)
{
if(!d->Started)
{
cerr << "!d->Started FAIL" << endl;
return false;
}
df_unit * temp = creatures->at (index);
if(index >= world->units.all.size()) return false;
df::unit * temp = world->units.all[index];
return this->RemoveOwnedItemByPtr(temp, id);
}
bool Units::RemoveOwnedItemByPtr(df_unit * temp, int32_t id)
bool Units::RemoveOwnedItemByPtr(df::unit * temp, int32_t id)
{
if(!d->Started) return false;
Process * p = d->owner;
@ -609,8 +571,8 @@ bool Units::RemoveOwnedItemByPtr(df_unit * temp, int32_t id)
return true;
}
void Units::CopyNameTo(df_unit * creature, df_name * target)
void Units::CopyNameTo(df::unit * creature, df_name * target)
{
d->trans->copyName(&creature->name, target);
d->trans->copyName((df_name *)&creature->name, target);
}

@ -188,12 +188,12 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
if (owner_index >= 0)
{
DFHack::df_unit * temp = Creatures->GetCreature(owner_index);
df::unit * temp = Creatures->GetCreature(owner_index);
info = temp->name.first_name;
if (!temp->name.nick_name.empty())
info += std::string(" '") + temp->name.nick_name + "'";
if (!temp->name.nickname.empty())
info += std::string(" '") + temp->name.nickname + "'";
info += " ";
info += Tran->TranslateName(&temp->name,false);
info += Tran->TranslateName((df_name *)&temp->name,false);
c->con.print(", owner %s", info.c_str());
}

@ -68,10 +68,10 @@ DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
cr->Start(ncr);
for(auto i = 0; i < ncr; i++)
{
df_unit * unit = cr->GetCreature( i );
if(unit->x == cursorX && unit->y == cursorY && unit->z == cursorZ)
df::unit * unit = cr->GetCreature( i );
if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
{
con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ, unit->civ);
con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ_id, unit->civ_id);
break;
}
}