2010-04-02 19:52:46 -06:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
2010-04-02 19:52:46 -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-06-16 15:53:39 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
2011-04-23 18:49:49 -06:00
|
|
|
#include <stddef.h>
|
2011-04-10 02:19:15 -06:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <cstring>
|
2011-09-18 05:49:10 -06:00
|
|
|
#include <algorithm>
|
2011-04-10 02:19:15 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2011-06-12 15:17:40 -06:00
|
|
|
#include "dfhack/Process.h"
|
|
|
|
#include "dfhack/Vector.h"
|
|
|
|
#include "dfhack/Error.h"
|
|
|
|
#include "dfhack/Types.h"
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2010-04-06 19:38:22 -06:00
|
|
|
// we connect to those
|
2010-05-26 00:42:09 -06:00
|
|
|
#include "dfhack/modules/Materials.h"
|
|
|
|
#include "dfhack/modules/Creatures.h"
|
2011-06-17 07:02:43 -06:00
|
|
|
#include "dfhack/modules/Translation.h"
|
2011-03-18 01:53:59 -06:00
|
|
|
#include "ModuleFactory.h"
|
2011-06-17 07:02:43 -06:00
|
|
|
#include <dfhack/Core.h>
|
2010-04-06 19:38:22 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
using namespace DFHack;
|
2010-04-04 04:29:56 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
struct Creatures::Private
|
|
|
|
{
|
|
|
|
bool Inited;
|
|
|
|
bool Started;
|
2011-09-21 05:47:12 -06:00
|
|
|
|
2010-04-16 05:28:07 -06:00
|
|
|
uint32_t dwarf_race_index_addr;
|
2010-04-19 06:36:21 -06:00
|
|
|
uint32_t dwarf_civ_id_addr;
|
2011-04-11 04:32:53 -06:00
|
|
|
bool IdMapReady;
|
|
|
|
std::map<int32_t, int32_t> IdMap;
|
2011-09-21 05:47:12 -06:00
|
|
|
|
2010-04-18 13:30:02 -06:00
|
|
|
Process *owner;
|
2011-06-17 07:02:43 -06:00
|
|
|
Translation * trans;
|
2010-04-04 16:48:19 -06:00
|
|
|
};
|
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Module* DFHack::createCreatures()
|
2011-03-18 01:53:59 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
return new Creatures();
|
2011-03-18 01:53:59 -06:00
|
|
|
}
|
|
|
|
|
2011-06-17 07:02:43 -06:00
|
|
|
Creatures::Creatures()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-06-17 07:02:43 -06:00
|
|
|
Core & c = Core::getInstance();
|
2010-04-04 16:48:19 -06:00
|
|
|
d = new Private;
|
2011-06-17 07:02:43 -06:00
|
|
|
d->owner = c.p;
|
|
|
|
VersionInfo * minfo = c.vinfo;
|
2010-04-04 16:48:19 -06:00
|
|
|
d->Inited = false;
|
|
|
|
d->Started = false;
|
2011-04-11 04:32:53 -06:00
|
|
|
d->IdMapReady = false;
|
2011-06-17 07:02:43 -06:00
|
|
|
d->trans = c.getTranslation();
|
2011-09-21 05:47:12 -06:00
|
|
|
d->trans->InitReadNames(); // FIXME: throws on error
|
2011-06-17 07:02:43 -06:00
|
|
|
|
2010-09-02 18:15:09 -06:00
|
|
|
OffsetGroup *OG_Creatures = minfo->getGroup("Creatures");
|
|
|
|
|
2011-09-21 05:47:12 -06:00
|
|
|
creatures = 0;
|
2010-04-02 19:52:46 -06:00
|
|
|
try
|
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
creatures = (vector <df_creature *> *) OG_Creatures->getAddress ("vector");
|
2010-09-02 18:15:09 -06:00
|
|
|
d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race");
|
|
|
|
d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ");
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-09-02 18:15:09 -06:00
|
|
|
catch(Error::All&){};
|
|
|
|
d->Inited = true;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
Creatures::~Creatures()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-04 16:48:19 -06:00
|
|
|
if(d->Started)
|
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Creatures::Start( uint32_t &numcreatures )
|
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(creatures)
|
2011-02-17 18:51:17 -07:00
|
|
|
{
|
|
|
|
d->Started = true;
|
2011-09-18 05:49:10 -06:00
|
|
|
numcreatures = creatures->size();
|
2011-09-21 05:47:12 -06:00
|
|
|
d->IdMap.clear();
|
2011-04-11 04:32:53 -06:00
|
|
|
d->IdMapReady = false;
|
2011-02-17 18:51:17 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Creatures::Finish()
|
|
|
|
{
|
|
|
|
d->Started = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
df_creature * Creatures::GetCreature (const int32_t index)
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started) return nullptr;
|
2010-06-17 17:17:46 -06:00
|
|
|
|
2010-04-02 19:52:46 -06:00
|
|
|
// read pointer from vector at position
|
2011-09-18 05:49:10 -06:00
|
|
|
if(index > creatures->size())
|
|
|
|
return nullptr;
|
|
|
|
return creatures->at(index);
|
|
|
|
}
|
2010-06-17 17:17:46 -06:00
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
// returns index of creature actually read or -1 if no creature can be found
|
|
|
|
int32_t Creatures::GetCreatureInBox (int32_t index, df_creature ** 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;
|
|
|
|
uint16_t coords[3];
|
|
|
|
uint32_t size = creatures->size();
|
|
|
|
while (uint32_t(index) < size)
|
2010-04-26 05:23:57 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
// read pointer from vector at position
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
if (temp->x >= x1 && temp->x < x2)
|
2010-09-02 19:01:37 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if (temp->y >= y1 && temp->y < y2)
|
|
|
|
{
|
|
|
|
if (temp->z >= z1 && temp->z < z2)
|
|
|
|
{
|
|
|
|
*furball = temp;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
2010-09-02 19:01:37 -06:00
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
*furball = nullptr;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
void Creatures::CopyCreature(df_creature * source, t_creature & furball)
|
|
|
|
{
|
|
|
|
if(!d->Started) return;
|
|
|
|
// read pointer from vector at position
|
|
|
|
furball.origin = source;
|
|
|
|
|
|
|
|
//read creature from memory
|
|
|
|
// name
|
|
|
|
d->trans->readName(furball.name,&source->name);
|
|
|
|
|
|
|
|
// basic stuff
|
|
|
|
furball.id = source->id;
|
|
|
|
furball.x = source->x;
|
|
|
|
furball.y = source->y;
|
|
|
|
furball.z = source->z;
|
|
|
|
furball.race = source->race;
|
|
|
|
furball.civ = source->civ;
|
|
|
|
furball.sex = source->sex;
|
|
|
|
furball.caste = source->caste;
|
|
|
|
furball.flags1.whole = source->flags1.whole;
|
|
|
|
furball.flags2.whole = source->flags2.whole;
|
|
|
|
furball.flags3.whole = source->flags3.whole;
|
|
|
|
// custom profession
|
|
|
|
furball.custom_profession = source->custom_profession;
|
|
|
|
// profession
|
|
|
|
furball.profession = source->profession;
|
|
|
|
// happiness
|
|
|
|
furball.happiness = source->happiness;
|
|
|
|
// physical attributes
|
|
|
|
memcpy(&furball.strength, source->physical, sizeof(source->physical));
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// labors
|
|
|
|
memcpy(&furball.labors, &source->labors, sizeof(furball.labors));
|
|
|
|
|
|
|
|
furball.birth_year = source->birth_year;
|
|
|
|
furball.birth_time = source->birth_time;
|
|
|
|
furball.pregnancy_timer = source->pregnancy_timer;
|
|
|
|
// appearance
|
|
|
|
furball.nbcolors = source->appearance.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];
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
|
|
|
|
//likes. FIXME: where do they fit in now? The soul?
|
|
|
|
/*
|
|
|
|
DfVector <uint32_t> likes(d->p, temp + offs.creature_likes_offset);
|
|
|
|
furball.numLikes = likes.getSize();
|
|
|
|
for(uint32_t i = 0;i<furball.numLikes;i++)
|
|
|
|
{
|
|
|
|
uint32_t temp2 = *(uint32_t *) likes[i];
|
|
|
|
p->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/*
|
2010-09-02 19:01:37 -06:00
|
|
|
if(d->Ft_soul)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-05-07 19:21:34 -06:00
|
|
|
uint32_t soul = p->readDWord(addr_cr + offs.default_soul_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
furball.has_default_soul = false;
|
|
|
|
|
|
|
|
if(soul)
|
|
|
|
{
|
|
|
|
furball.has_default_soul = true;
|
|
|
|
// get first soul's skills
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> skills(soul + offs.soul_skills_vector_offset);
|
2010-09-02 19:01:37 -06:00
|
|
|
furball.defaultSoul.numSkills = skills.size();
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-09-02 19:01:37 -06:00
|
|
|
for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++)
|
|
|
|
{
|
|
|
|
uint32_t temp2 = skills[i];
|
|
|
|
// a byte: this gives us 256 skills maximum.
|
|
|
|
furball.defaultSoul.skills[i].id = p->readByte (temp2);
|
|
|
|
furball.defaultSoul.skills[i].rating =
|
|
|
|
p->readByte (temp2 + offsetof(t_skill, rating));
|
|
|
|
furball.defaultSoul.skills[i].experience =
|
|
|
|
p->readWord (temp2 + offsetof(t_skill, experience));
|
|
|
|
}
|
2010-06-15 17:55:12 -06:00
|
|
|
|
2010-09-02 19:01:37 -06:00
|
|
|
// mental attributes are part of the soul
|
|
|
|
p->read(soul + offs.soul_mental_offset,
|
|
|
|
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
|
|
|
|
(uint8_t *)&furball.defaultSoul.analytical_ability);
|
2010-06-15 17:55:12 -06:00
|
|
|
|
2010-09-02 19:01:37 -06:00
|
|
|
// traits as well
|
|
|
|
p->read(soul + offs.soul_traits_offset,
|
|
|
|
sizeof (uint16_t) * NUM_CREATURE_TRAITS,
|
|
|
|
(uint8_t *) &furball.defaultSoul.traits);
|
2010-04-12 19:11:26 -06:00
|
|
|
}
|
2010-04-06 18:46:46 -06:00
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
furball.current_job.occupationPtr = p->readDWord (addr_cr + offs.current_job_offset);
|
|
|
|
if(furball.current_job.occupationPtr)
|
2010-05-05 06:08:18 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
furball.current_job.active = true;
|
|
|
|
furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + offs.job_type_offset );
|
|
|
|
furball.current_job.jobId = p->readWord (furball.current_job.occupationPtr + offs.job_id_offset);
|
2010-05-05 06:08:18 -06:00
|
|
|
}
|
2011-05-07 19:21:34 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
furball.current_job.active = false;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
*/
|
|
|
|
// no jobs for now...
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
furball.current_job.active = false;
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 04:32:53 -06:00
|
|
|
int32_t Creatures::FindIndexById(int32_t creature_id)
|
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if (!d->Started)
|
2011-04-11 04:32:53 -06:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!d->IdMapReady)
|
|
|
|
{
|
|
|
|
d->IdMap.clear();
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
uint32_t size = creatures->size();
|
2011-04-11 04:32:53 -06:00
|
|
|
for (uint32_t index = 0; index < size; index++)
|
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
int32_t id = temp->id;
|
2011-04-11 04:32:53 -06:00
|
|
|
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;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
/*
|
2010-04-06 19:38:22 -06:00
|
|
|
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
|
|
|
|
p->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors);
|
|
|
|
uint32_t pickup_equip;
|
|
|
|
p->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
|
|
|
|
pickup_equip |= 1u;
|
|
|
|
p->writeDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
|
|
|
|
return true;
|
2010-06-14 17:59:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Creatures::WriteHappiness(const uint32_t index, const uint32_t happinessValue)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeDWord (temp + d->creatures.happiness_offset, happinessValue);
|
|
|
|
return true;
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
2010-04-06 19:38:22 -06:00
|
|
|
|
2010-06-15 10:28:05 -06:00
|
|
|
bool Creatures::WriteFlags(const uint32_t index,
|
2010-06-17 17:17:46 -06:00
|
|
|
const uint32_t flags1,
|
|
|
|
const uint32_t flags2)
|
2010-06-15 10:28:05 -06:00
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_basic) return false;
|
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeDWord (temp + d->creatures.flags1_offset, flags1);
|
2010-06-19 13:09:16 -06:00
|
|
|
p->writeDWord (temp + d->creatures.flags2_offset, flags2);
|
2010-06-17 17:17:46 -06:00
|
|
|
return true;
|
2010-06-15 10:28:05 -06:00
|
|
|
}
|
|
|
|
|
2011-07-10 05:00:52 -06:00
|
|
|
bool Creatures::WriteFlags(const uint32_t index,
|
|
|
|
const uint32_t flags1,
|
|
|
|
const uint32_t flags2,
|
|
|
|
const uint32_t flags3)
|
|
|
|
{
|
|
|
|
if(!d->Started || !d->Ft_basic) return false;
|
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeDWord (temp + d->creatures.flags1_offset, flags1);
|
|
|
|
p->writeDWord (temp + d->creatures.flags2_offset, flags2);
|
|
|
|
p->writeDWord (temp + d->creatures.flags3_offset, flags3);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-15 17:19:19 -06:00
|
|
|
bool Creatures::WriteSkills(const uint32_t index, const t_soul &soul)
|
2010-06-15 15:23:24 -06:00
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_soul) return false;
|
2010-06-17 17:17:46 -06:00
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
|
|
|
|
|
|
|
|
if(!souloff)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector<uint32_t> skills(souloff + d->creatures.soul_skills_vector_offset);
|
2010-06-15 15:23:24 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
for (uint32_t i=0; i<soul.numSkills; i++)
|
2010-06-15 15:23:24 -06:00
|
|
|
{
|
|
|
|
uint32_t temp2 = skills[i];
|
2010-06-17 17:17:46 -06:00
|
|
|
p->writeByte(temp2 + offsetof(t_skill, rating), soul.skills[i].rating);
|
|
|
|
p->writeWord(temp2 + offsetof(t_skill, experience), soul.skills[i].experience);
|
2010-06-15 15:23:24 -06:00
|
|
|
}
|
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
return true;
|
2010-06-15 15:23:24 -06:00
|
|
|
}
|
|
|
|
|
2010-06-15 17:19:19 -06:00
|
|
|
bool Creatures::WriteAttributes(const uint32_t index, const t_creature &creature)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_advanced || !d->Ft_soul) return false;
|
2010-06-15 17:19:19 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
|
2010-06-15 17:19:19 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
if(!souloff)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-15 17:19:19 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
// physical attributes
|
|
|
|
p->write(temp + d->creatures.physical_offset,
|
|
|
|
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
|
|
|
|
(uint8_t *)&creature.strength);
|
2010-06-15 17:19:19 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
// mental attributes are part of the soul
|
|
|
|
p->write(souloff + d->creatures.soul_mental_offset,
|
|
|
|
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
|
|
|
|
(uint8_t *)&creature.defaultSoul.analytical_ability);
|
2010-06-15 17:19:19 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
return true;
|
2010-06-15 17:19:19 -06:00
|
|
|
}
|
|
|
|
|
2010-06-16 13:47:05 -06:00
|
|
|
bool Creatures::WriteSex(const uint32_t index, const uint8_t sex)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_basic ) return false;
|
2010-06-16 13:47:05 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeByte (temp + d->creatures.sex_offset, sex);
|
2010-11-17 12:50:50 -07:00
|
|
|
|
|
|
|
return true;
|
2010-06-16 13:47:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Creatures::WriteTraits(const uint32_t index, const t_soul &soul)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_soul) return false;
|
2010-06-17 17:17:46 -06:00
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
|
2010-06-16 13:47:05 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
if(!souloff)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-16 13:47:05 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
p->write(souloff + d->creatures.soul_traits_offset,
|
|
|
|
sizeof (uint16_t) * NUM_CREATURE_TRAITS,
|
|
|
|
(uint8_t *) &soul.traits);
|
2010-06-16 13:47:05 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
return true;
|
2010-06-16 13:47:05 -06:00
|
|
|
}
|
|
|
|
|
2010-06-17 16:18:01 -06:00
|
|
|
bool Creatures::WriteMood(const uint32_t index, const uint16_t mood)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
2010-06-17 16:18:01 -06:00
|
|
|
|
2010-06-17 17:17:46 -06:00
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeWord(temp + d->creatures.mood_offset, mood);
|
|
|
|
return true;
|
2010-06-17 16:18:01 -06:00
|
|
|
}
|
|
|
|
|
2010-06-22 10:21:09 -06:00
|
|
|
bool Creatures::WriteMoodSkill(const uint32_t index, const uint16_t moodSkill)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started || !d->Ft_advanced) return false;
|
2010-06-22 10:21:09 -06:00
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeWord(temp + d->creatures.mood_skill_offset, moodSkill);
|
|
|
|
return true;
|
2010-08-09 12:28:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Creatures::WriteJob(const t_creature * furball, std::vector<t_material> const& mat)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Inited || !d->Ft_job_materials) return false;
|
2010-08-09 12:28:35 -06:00
|
|
|
if(!furball->current_job.active) return false;
|
2011-04-03 13:27:47 -06:00
|
|
|
|
|
|
|
unsigned int i;
|
2010-08-09 12:28:35 -06:00
|
|
|
Process * p = d->owner;
|
2011-04-03 13:27:47 -06:00
|
|
|
Private::t_offsets & off = d->creatures;
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> cmats(furball->current_job.occupationPtr + off.job_materials_vector);
|
2010-08-09 12:28:35 -06:00
|
|
|
|
|
|
|
for(i=0;i<cmats.size();i++)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
p->writeWord(cmats[i] + off.job_material_itemtype_o, mat[i].itemType);
|
|
|
|
p->writeWord(cmats[i] + off.job_material_subtype_o, mat[i].subType);
|
|
|
|
p->writeWord(cmats[i] + off.job_material_subindex_o, mat[i].subIndex);
|
|
|
|
p->writeDWord(cmats[i] + off.job_material_index_o, mat[i].index);
|
|
|
|
p->writeDWord(cmats[i] + off.job_material_flags_o, mat[i].flags);
|
2010-08-09 12:28:35 -06:00
|
|
|
}
|
|
|
|
return true;
|
2010-06-22 10:21:09 -06:00
|
|
|
}
|
|
|
|
|
2010-06-22 11:27:27 -06:00
|
|
|
bool Creatures::WritePos(const uint32_t index, const t_creature &creature)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started) return false;
|
2010-06-22 11:27:27 -06:00
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
2011-04-03 13:27:47 -06:00
|
|
|
p->write (temp + d->creatures.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (creature.x));
|
|
|
|
return true;
|
2010-06-22 11:27:27 -06:00
|
|
|
}
|
|
|
|
|
2010-06-22 20:32:33 -06:00
|
|
|
bool Creatures::WriteCiv(const uint32_t index, const int32_t civ)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Started) return false;
|
2010-06-22 20:32:33 -06:00
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeDWord(temp + d->creatures.civ_offset, civ);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-11 03:48:10 -06:00
|
|
|
bool Creatures::WritePregnancy(const uint32_t index, const uint32_t pregTimer)
|
|
|
|
{
|
|
|
|
if(!d->Started) return false;
|
|
|
|
|
|
|
|
uint32_t temp = d->p_cre->at (index);
|
|
|
|
Process * p = d->owner;
|
|
|
|
p->writeDWord(temp + d->creatures.pregnancy_offset, pregTimer);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
*/
|
2010-04-16 05:28:07 -06:00
|
|
|
uint32_t Creatures::GetDwarfRaceIndex()
|
|
|
|
{
|
|
|
|
if(!d->Inited) return 0;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
return p->readDWord(d->dwarf_race_index_addr);
|
2010-04-16 05:28:07 -06:00
|
|
|
}
|
|
|
|
|
2010-04-19 06:36:21 -06:00
|
|
|
int32_t Creatures::GetDwarfCivId()
|
|
|
|
{
|
|
|
|
if(!d->Inited) return -1;
|
|
|
|
Process * p = d->owner;
|
|
|
|
return p->readDWord(d->dwarf_civ_id_addr);
|
|
|
|
}
|
2010-04-04 04:29:56 -06:00
|
|
|
/*
|
2010-04-18 13:30:02 -06:00
|
|
|
bool Creatures::getCurrentCursorCreature(uint32_t & creature_index)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
|
|
|
if(!d->cursorWindowInited) return false;
|
2010-04-18 13:30:02 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
creature_index = p->readDWord(d->current_cursor_creature_offset);
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
2010-04-19 06:36:21 -06:00
|
|
|
*/
|
2011-09-18 05:49:10 -06:00
|
|
|
/*
|
2010-04-26 05:23:57 -06:00
|
|
|
bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2011-04-03 13:27:47 -06:00
|
|
|
if(!d->Inited || !d->Ft_job_materials) return false;
|
2010-04-26 05:23:57 -06:00
|
|
|
if(!furball->current_job.active) return false;
|
|
|
|
|
2011-04-03 13:27:47 -06:00
|
|
|
Process * p = d->owner;
|
|
|
|
Private::t_offsets & off = d->creatures;
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <uint32_t> cmats(furball->current_job.occupationPtr + off.job_materials_vector);
|
2010-04-26 05:23:57 -06:00
|
|
|
mat.resize(cmats.size());
|
|
|
|
for(i=0;i<cmats.size();i++)
|
|
|
|
{
|
2011-04-03 13:27:47 -06:00
|
|
|
mat[i].itemType = p->readWord(cmats[i] + off.job_material_itemtype_o);
|
|
|
|
mat[i].subType = p->readWord(cmats[i] + off.job_material_subtype_o);
|
|
|
|
mat[i].subIndex = p->readWord(cmats[i] + off.job_material_subindex_o);
|
|
|
|
mat[i].index = p->readDWord(cmats[i] + off.job_material_index_o);
|
|
|
|
mat[i].flags = p->readDWord(cmats[i] + off.job_material_flags_o);
|
2010-04-26 05:23:57 -06:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
*/
|
2011-10-24 20:48:06 -06:00
|
|
|
bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item)
|
2010-08-17 07:21:54 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started) return false;
|
|
|
|
if(index >= creatures->size()) return false;
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
return this->ReadInventoryByPtr(temp, item);
|
2010-08-17 07:21:54 -06:00
|
|
|
}
|
|
|
|
|
2011-10-24 20:48:06 -06:00
|
|
|
bool Creatures::ReadInventoryByPtr(const df_creature * temp, std::vector<df_item *> & items)
|
2010-08-17 07:21:54 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started) return false;
|
|
|
|
items = temp->inventory;
|
2010-08-17 07:21:54 -06:00
|
|
|
return true;
|
2010-08-27 20:39:03 -06:00
|
|
|
}
|
2011-04-13 10:36:10 -06:00
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
bool Creatures::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item)
|
2011-05-09 04:49:44 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started ) return false;
|
|
|
|
if(index >= creatures->size()) return false;
|
|
|
|
df_creature * temp = creatures->at(index);
|
|
|
|
return this->ReadOwnedItemsByPtr(temp, item);
|
2011-05-09 04:49:44 -06:00
|
|
|
}
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
bool Creatures::ReadOwnedItemsByPtr(const df_creature * temp, std::vector<int32_t> & items)
|
2011-05-09 04:49:44 -06:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started) return false;
|
|
|
|
items = temp->owned_items;
|
2011-05-09 04:49:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
bool Creatures::RemoveOwnedItemByIdx(const uint32_t index, int32_t id)
|
2011-05-12 11:09:49 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started)
|
2011-05-28 02:18:50 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
cerr << "!d->Started FAIL" << endl;
|
2011-05-28 02:18:50 -06:00
|
|
|
return false;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
df_creature * temp = creatures->at (index);
|
|
|
|
return this->RemoveOwnedItemByPtr(temp, id);
|
2011-05-12 11:09:49 -06:00
|
|
|
}
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
bool Creatures::RemoveOwnedItemByPtr(df_creature * temp, int32_t id)
|
2011-05-12 11:09:49 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
if(!d->Started) return false;
|
2011-05-12 11:09:49 -06:00
|
|
|
Process * p = d->owner;
|
2011-09-18 05:49:10 -06:00
|
|
|
vector <int32_t> & vec = temp->owned_items;
|
|
|
|
vec.erase(std::remove(vec.begin(), vec.end(), id), vec.end());
|
|
|
|
/*
|
2011-06-12 17:14:10 -06:00
|
|
|
DfVector <int32_t> citem(temp + d->creatures.owned_items_offset);
|
2011-05-12 11:09:49 -06:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < citem.size(); i++) {
|
|
|
|
if (citem[i] != id)
|
|
|
|
continue;
|
|
|
|
if (!citem.remove(i--))
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-18 05:49:10 -06:00
|
|
|
*/
|
2011-05-12 11:09:49 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-18 05:49:10 -06:00
|
|
|
void Creatures::CopyNameTo(df_creature * creature, df_name * target)
|
2011-04-13 10:36:10 -06:00
|
|
|
{
|
2011-09-18 05:49:10 -06:00
|
|
|
d->trans->copyName(&creature->name, target);
|
2011-04-13 10:36:10 -06:00
|
|
|
}
|
|
|
|
|