Vegetation reading
parent
01383fd8b7
commit
839e255d17
@ -0,0 +1,45 @@
|
||||
#ifndef CL_MOD_VEGETATION
|
||||
#define CL_MOD_VEGETATION
|
||||
/*
|
||||
* DF vegetation - stuff that grows and gets cut down or trampled by dwarves
|
||||
*/
|
||||
#include "Export.h"
|
||||
namespace DFHack
|
||||
{
|
||||
/*
|
||||
types
|
||||
0: sapling?, dead sapling?, grown maple tree
|
||||
1: willow sapling?
|
||||
2: shrub
|
||||
3: shrub near water!
|
||||
*/
|
||||
struct t_tree
|
||||
{
|
||||
uint16_t type; // +0x6C
|
||||
uint16_t material; // +0x6E
|
||||
uint16_t x; // +0x70
|
||||
uint16_t y; // +0x72
|
||||
uint16_t z; // +0x74
|
||||
/*
|
||||
junk_fill<0xA> junk;
|
||||
uint32_t flags; // +0x80 maybe?
|
||||
*/
|
||||
uint32_t address;
|
||||
};
|
||||
|
||||
struct APIPrivate;
|
||||
class DFHACK_EXPORT Vegetation
|
||||
{
|
||||
public:
|
||||
Vegetation(APIPrivate * d);
|
||||
~Vegetation();
|
||||
bool Start(uint32_t & numTrees);
|
||||
bool Read (const uint32_t index, t_tree & shrubbery);
|
||||
bool Finish();
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private *d;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "DFCommonInternal.h"
|
||||
#include "../private/APIPrivate.h"
|
||||
#include "modules/Translation.h"
|
||||
#include "DFMemInfo.h"
|
||||
#include "DFProcess.h"
|
||||
#include "DFVector.h"
|
||||
#include "DFTypes.h"
|
||||
#include "modules/Vegetation.h"
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
struct Vegetation::Private
|
||||
{
|
||||
uint32_t vegetation_vector;
|
||||
uint32_t tree_desc_offset;
|
||||
// translation
|
||||
DfVector * p_veg;
|
||||
|
||||
APIPrivate *d;
|
||||
bool Inited;
|
||||
bool Started;
|
||||
};
|
||||
|
||||
Vegetation::Vegetation(APIPrivate * d_)
|
||||
{
|
||||
d = new Private;
|
||||
d->d = d_;
|
||||
d->Inited = d->Started = false;
|
||||
memory_info * mem = d->d->offset_descriptor;
|
||||
d->vegetation_vector = mem->getAddress ("vegetation_vector");
|
||||
d->tree_desc_offset = mem->getOffset ("tree_desc_offset");
|
||||
d->Inited = true;
|
||||
}
|
||||
|
||||
Vegetation::~Vegetation()
|
||||
{
|
||||
if(d->Started)
|
||||
Finish();
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool Vegetation::Start(uint32_t & numplants)
|
||||
{
|
||||
d->p_veg = new DfVector (g_pProcess, d->vegetation_vector, 4);
|
||||
numplants = d->p_veg->getSize();
|
||||
d->Started = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Vegetation::Read (const uint32_t index, t_tree & shrubbery)
|
||||
{
|
||||
if(!d->Started)
|
||||
return false;
|
||||
// read pointer from vector at position
|
||||
uint32_t temp = * (uint32_t *) d->p_veg->at (index);
|
||||
// read from memory
|
||||
g_pProcess->read (temp + d->tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery);
|
||||
shrubbery.address = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Vegetation::Finish()
|
||||
{
|
||||
if(d->p_veg)
|
||||
{
|
||||
delete d->p_veg;
|
||||
d->p_veg = 0;
|
||||
}
|
||||
d->Started = false;
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue