Merge branch 'master' of git://github.com/peterix/dfhack

develop
Warmist 2011-12-07 23:15:11 +02:00
commit a25c0b81de
24 changed files with 514 additions and 127 deletions

@ -43,7 +43,7 @@ include/dfhack/extra/stopwatch.h
include/dfhack/extra/termutil.h
include/dfhack/modules/Buildings.h
include/dfhack/modules/Constructions.h
include/dfhack/modules/Creatures.h
include/dfhack/modules/Units.h
include/dfhack/modules/Engravings.h
include/dfhack/modules/Gui.h
include/dfhack/modules/Items.h
@ -55,6 +55,7 @@ include/dfhack/modules/Translation.h
include/dfhack/modules/Vegetation.h
include/dfhack/modules/Vermin.h
include/dfhack/modules/World.h
include/dfhack/modules/Graphic.h
)
SET(PROJECT_SRCS
@ -77,7 +78,7 @@ depends/tthread/tinythread.cpp
modules/Buildings.cpp
modules/Constructions.cpp
modules/Creatures.cpp
modules/Units.cpp
modules/Engravings.cpp
modules/Gui.cpp
modules/Items.cpp
@ -89,6 +90,7 @@ modules/Translation.cpp
modules/Vegetation.cpp
modules/Vermin.cpp
modules/World.cpp
modules/Graphic.cpp
)
SET(PROJECT_HDRS_LINUX

@ -45,6 +45,7 @@ using namespace std;
#include "ModuleFactory.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Graphic.h"
using namespace DFHack;
#include "dfhack/SDL_fakes/events.h"
@ -775,7 +776,7 @@ TYPE * Core::get##TYPE() \
return s_mods.p##TYPE;\
}
MODULE_GETTER(Creatures);
MODULE_GETTER(Units);
MODULE_GETTER(Engravings);
MODULE_GETTER(Maps);
MODULE_GETTER(Gui);
@ -788,3 +789,4 @@ MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions);
MODULE_GETTER(Vermin);
MODULE_GETTER(Notes);
MODULE_GETTER(Graphic);

@ -33,6 +33,7 @@ distribution.
#include <stdio.h>
#include "tinythread.h"
#include "dfhack/modules/Graphic.h"
/*
* Plugin loading functions
@ -284,9 +285,44 @@ DFhackCExport vPtr SDL_SetVideoMode(int width, int height, int bpp, uint32_t fla
{
return _SDL_SetVideoMode(width, height, bpp, flags);
}
static int (*_SDL_UpperBlit)(vPtr src, vPtr srcrect, vPtr dst, vPtr dstrect) = 0;
DFhackCExport int SDL_UpperBlit(vPtr src, vPtr srcrect, vPtr dst, vPtr dstrect)
{
static int (*_SDL_UpperBlit)(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) = 0;
DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect)
{
if ( dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 )
{
DFHack::Core & c = DFHack::Core::getInstance();
DFHack::Graphic* g = c.getGraphic();
DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h);
if ( ov != NULL )
{
if ( ov->paintOver )
{
_SDL_UpperBlit(src, srcrect, dst, dstrect);
}
DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect;
dstrect2->x = dstrect->x;
dstrect2->y = dstrect->y;
dstrect2->w = dstrect->w;
dstrect2->h = dstrect->h;
if ( ov->dstResize != NULL )
{
DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize;
dstrect2->x += r->x;
dstrect2->y += r->y;
dstrect2->w += r->w;
dstrect2->h += r->h;
}
int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2);
delete dstrect2;
return result;
}
}
return _SDL_UpperBlit(src, srcrect, dst, dstrect);
}
@ -745,7 +781,7 @@ bool FirstCall()
_SDL_SetVideoMode = (void*(*)(int, int, int, uint32_t))GetProcAddress(realSDLlib,"SDL_SetVideoMode");
_SDL_ShowCursor = (int (*)(int))GetProcAddress(realSDLlib,"SDL_ShowCursor");
_SDL_UnlockSurface = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnlockSurface");
_SDL_UpperBlit = (int (*)(void*, void*, void*, void*))GetProcAddress(realSDLlib,"SDL_UpperBlit");
_SDL_UpperBlit = (int (*)(DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*, DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*))GetProcAddress(realSDLlib,"SDL_UpperBlit");
_SDL_WM_SetCaption = (void (*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_WM_SetCaption");
_SDL_WM_SetIcon = (void (*)(void*, uint8_t*))GetProcAddress(realSDLlib,"SDL_WM_SetIcon");
_SDL_mutexP = (int (*)(vPtr))GetProcAddress(realSDLlib,"SDL_mutexP");
@ -781,4 +817,3 @@ bool FirstCall()
inited = true;
return 1;
}

@ -57,7 +57,7 @@ distribution.
#include "dfhack/modules/Engravings.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Constructions.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Units.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/modules/World.h"
#include "dfhack/modules/Items.h"

@ -32,6 +32,7 @@ distribution.
#include <map>
#include <stdint.h>
#include "dfhack/Console.h"
#include "dfhack/modules/Graphic.h"
struct WINDOW;
@ -46,7 +47,7 @@ namespace DFHack
{
class Process;
class Module;
class Creatures;
class Units;
class Engravings;
class Maps;
class Gui;
@ -96,7 +97,7 @@ namespace DFHack
bool isValid(void) { return !errorstate; }
/// get the creatures module
Creatures * getCreatures();
Units * getUnits();
/// get the engravings module
Engravings * getEngravings();
/// get the maps module
@ -121,6 +122,8 @@ namespace DFHack
Vermin * getVermin();
/// get the notes module
Notes * getNotes();
/// get the graphic module
Graphic * getGraphic();
/// sets the current hotkey command
bool setHotkeyCmd( std::string cmd );
/// removes the hotkey command and gives it to the caller thread
@ -158,7 +161,7 @@ namespace DFHack
// Module storage
struct
{
Creatures * pCreatures;
Units * pUnits;
Engravings * pEngravings;
Maps * pMaps;
Gui * pGui;
@ -171,6 +174,7 @@ namespace DFHack
Constructions * pConstructions;
Vermin * pVermin;
Notes * pNotes;
Graphic * pGraphic;
} s_mods;
std::vector <Module *> allModules;
DFHack::PluginManager * plug_mgr;

@ -0,0 +1,91 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
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.
*/
/*******************************************************************************
GRAPHIC
Changing tile cache
*******************************************************************************/
#pragma once
#ifndef CL_MOD_GRAPHIC
#define CL_MOD_GRAPHIC
#include <stdint.h>
#include "dfhack/Export.h"
#include "dfhack/Module.h"
namespace DFHack
{
// SDL stuff
typedef signed short SINT16;
typedef struct
{
int16_t x, y;
uint16_t w, h;
} DFSDL_Rect;
typedef struct
{
uint32_t flags;
void* format; // PixelFormat*
int w, h;
int pitch;
void* pixels;
void* userdata; // as far as i could see DF doesnt use this
int locked;
void* lock_data;
DFSDL_Rect clip_rect;
void* map;
int refcount;
} DFSDL_Surface;
// =========
struct DFTileSurface
{
bool paintOver; // draw over original tile?
DFSDL_Surface* surface; // from where it should be drawn
DFSDL_Rect* rect; // from which coords (NULL to draw whole surface)
DFSDL_Rect* dstResize; // if not NULL dst rect will be resized (x/y/w/h will be added to original dst)
};
class DFHACK_EXPORT Graphic : public Module
{
public:
Graphic();
~Graphic();
bool Finish()
{
return true;
}
bool Register(DFTileSurface* (*func)(int,int));
bool Unregister(DFTileSurface* (*func)(int,int));
DFTileSurface* Call(int x, int y);
private:
struct Private;
Private *d;
};
}
#endif

@ -42,7 +42,7 @@ namespace DFHack
class Context;
class DFContextShared;
class Creatures;
class Units;
/**
* Item flags. A bit fuzzy.
@ -162,21 +162,12 @@ public:
virtual t_materialType getMaterial();
virtual t_materialIndex getMaterialIndex();
// 0x10
/*
hm, [4] looks complicated *
takes a parameter
looks like 0x017081A4 is a vector of something
this one sets an item property at offset 0xA0
(0.31.25 Windows SDL)
*/
virtual void fn4(void);
virtual void setSubType(t_itemSubtype);
virtual void setMaterial(t_materialType mat);
virtual void setMaterialIndex (t_materialIndex submat);
// another one? really?
virtual t_materialType getMaterial2();
virtual t_materialType getMaterial2(); // weird
// 0x20
// more of the same?
virtual t_materialIndex getMaterialIndex2();
virtual t_materialIndex getMaterialIndex2(); // weird
virtual void fn9(void);
virtual void fn10(void);
virtual void fn11(void);
@ -603,7 +594,7 @@ public:
/// which items does it contain?
bool getContainedItems(const df_item * item, /*output*/ std::vector<int32_t> &items);
/// wipe out the owner records
bool removeItemOwner(df_item * item, Creatures *creatures);
bool removeItemOwner(df_item * item, Units *creatures);
/// read item references, filtered by class
bool readItemRefs(const df_item * item, const ClassNameCheck &classname,
/*output*/ std::vector<int32_t> &values);

@ -32,16 +32,16 @@ distribution.
#include "dfhack/Module.h"
#include "dfhack/modules/Items.h"
/**
* \defgroup grp_creatures Creatures module parts
* \defgroup grp_units Unit module parts
* @ingroup grp_modules
*/
namespace DFHack
{
/**
* easy access to first crature flags block
* \ingroup grp_creatures
* \ingroup grp_units
*/
union t_creaturflags1
union t_unitflags1
{
uint32_t whole;/*!< Access all flags as a single 32bit number. */
struct
@ -88,7 +88,7 @@ namespace DFHack
} bits;
};
union t_creaturflags2
union t_unitflags2
{
uint32_t whole; /*!< Access all flags as a single 32bit number. */
struct
@ -135,7 +135,7 @@ namespace DFHack
} bits;
};
union t_creaturflags3
union t_unitflags3
{
uint32_t whole; /*!< Access all flags as a single 32bit number. */
struct
@ -239,7 +239,7 @@ namespace DFHack
};
*/
/**
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct t_skill
{
@ -248,7 +248,7 @@ namespace DFHack
uint32_t experience;
};
/**
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct t_job
{
@ -258,7 +258,7 @@ namespace DFHack
uint32_t occupationPtr;
};
/**
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct t_like
{
@ -276,8 +276,8 @@ namespace DFHack
#define NUM_CREATURE_MENTAL_ATTRIBUTES 13
#define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6
/**
* structure for holding a copy of a creature's soul
* \ingroup grp_creatures
* Structure for holding a copy of a DF unit's soul
* \ingroup grp_units
*/
struct t_soul
{
@ -301,23 +301,23 @@ namespace DFHack
t_attrib social_awareness;
};
#define MAX_COLORS 15
struct df_creature;
struct df_unit;
/**
* structure for holding a copy of a creature
* \ingroup grp_creatures
* Structure for holding a limited copy of a DF unit
* \ingroup grp_units
*/
struct t_creature
struct t_unit
{
df_creature * origin;
df_unit * origin;
uint16_t x;
uint16_t y;
uint16_t z;
uint32_t race;
int32_t civ;
t_creaturflags1 flags1;
t_creaturflags2 flags2;
t_creaturflags3 flags3;
t_unitflags1 flags1;
t_unitflags2 flags2;
t_unitflags3 flags3;
t_name name;
@ -354,8 +354,8 @@ namespace DFHack
};
/**
* Creature attribute descriptor
* \ingroup grp_creatures
* Unit attribute descriptor
* \ingroup grp_units
*/
struct df_attrib
{
@ -368,8 +368,8 @@ namespace DFHack
uint32_t unk_18;
};
/**
* Creature skill descriptor
* \ingroup grp_creatures
* Unit skill descriptor
* \ingroup grp_units
*/
struct df_skill
{
@ -383,8 +383,8 @@ namespace DFHack
uint32_t unk_1c;
};
/**
* Creature like descriptor
* \ingroup grp_creatures
* Unit like descriptor
* \ingroup grp_units
*/
struct df_like
{
@ -398,7 +398,7 @@ namespace DFHack
};
/**
* A creature's soul, as it appears in DF memory
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct df_soul
{
@ -423,7 +423,7 @@ namespace DFHack
};
/**
* A creature job - what it's supposed to be doing.
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct df_job
{
@ -431,7 +431,7 @@ namespace DFHack
};
/**
* A creature though - dwarves staring at waterfalls!
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct df_thought
{
@ -445,9 +445,9 @@ namespace DFHack
};
/**
* A creature, as it appears in DF memory
* \ingroup grp_creatures
* \ingroup grp_units
*/
struct df_creature
struct df_unit
{
df_name name; // 0
std::string custom_profession; // 6c (MSVC)
@ -475,9 +475,9 @@ namespace DFHack
std::vector<uint32_t> unk_c0;
std::vector<uint32_t> unk_d0;
t_creaturflags1 flags1; // e0
t_creaturflags2 flags2; // e4
t_creaturflags3 flags3; // e8
t_unitflags1 flags1; // e0
t_unitflags2 flags2; // e4
t_unitflags3 flags3; // e8
void ** unk_ec;
int32_t unk_f0;
@ -535,7 +535,7 @@ namespace DFHack
uint32_t birth_time; // 228
uint32_t unk_22c;
uint32_t unk_230;
df_creature * unk_234; // suspiciously close to the pregnancy/birth stuff. Mother?
df_unit * unk_234; // suspiciously close to the pregnancy/birth stuff. Mother?
uint32_t unk_238;
int32_t unk_23c;
int32_t unk_240;
@ -754,34 +754,34 @@ namespace DFHack
/**
* The Creatures module - allows reading all non-vermin creatures and their properties
* \ingroup grp_modules
* \ingroup grp_creatures
* \ingroup grp_units
*/
class DFHACK_EXPORT Creatures : public Module
class DFHACK_EXPORT Units : public Module
{
public:
std::vector <df_creature *> * creatures;
std::vector <df_unit *> * creatures;
public:
Creatures();
~Creatures();
Units();
~Units();
bool Start( uint32_t & numCreatures );
bool Finish();
/* 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_creature ** 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_creature * GetCreature(const int32_t index);
void CopyCreature(df_creature * source, t_creature & target);
df_unit * GetCreature(const int32_t index);
void CopyCreature(df_unit * source, t_unit & target);
bool ReadJob(const df_creature * 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_creature * 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_creature * unit, std::vector<int32_t> & item);
bool ReadOwnedItemsByPtr(const df_unit * unit, std::vector<int32_t> & item);
int32_t FindIndexById(int32_t id);
@ -805,12 +805,12 @@ namespace DFHack
//bool WriteCiv(const uint32_t index, const int32_t civ);
//bool WritePregnancy(const uint32_t index, const uint32_t pregTimer);
void CopyNameTo(df_creature *creature, df_name * target);
void CopyNameTo(df_unit *creature, df_name * target);
protected:
friend class Items;
bool RemoveOwnedItemByIdx(const uint32_t index, int32_t id);
bool RemoveOwnedItemByPtr(df_creature * unit, int32_t id);
bool RemoveOwnedItemByPtr(df_unit * unit, int32_t id);
private:
struct Private;

@ -0,0 +1,112 @@
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
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 "Internal.h"
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cassert>
#include <cstdlib>
using namespace std;
#include "dfhack/modules/Graphic.h"
#include "dfhack/Error.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/Process.h"
#include "dfhack/Vector.h"
#include "ModuleFactory.h"
#include <dfhack/Core.h>
using namespace DFHack;
Module* DFHack::createGraphic()
{
return new Graphic();
}
struct Graphic::Private
{
bool Started;
vector<DFTileSurface* (*)(int,int)> funcs;
};
Graphic::Graphic()
{
d = new Private;
d->Started = true;
}
Graphic::~Graphic()
{
delete d;
}
bool Graphic::Register(DFTileSurface* (*func)(int,int))
{
d->funcs.push_back(func);
return true;
}
bool Graphic::Unregister(DFTileSurface* (*func)(int,int))
{
if ( d->funcs.empty() ) return false;
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
while ( it != d->funcs.end() )
{
if ( *it == func )
{
d->funcs.erase(it);
return true;
}
it++;
}
return false;
}
// This will return first DFTileSurface it can get (or NULL if theres none)
DFTileSurface* Graphic::Call(int x, int y)
{
if ( d->funcs.empty() ) return NULL;
DFTileSurface* temp = NULL;
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
while ( it != d->funcs.end() )
{
temp = (*it)(x,y);
if ( temp != NULL )
{
return temp;
}
it++;
}
return NULL;
}

@ -39,7 +39,7 @@ using namespace std;
#include "dfhack/Vector.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Units.h"
#include "ModuleFactory.h"
#include <dfhack/Core.h>
#include <dfhack/Virtual.h>
@ -265,7 +265,7 @@ bool Items::unknownRefs(const df_item * item, std::vector<std::pair<std::string,
return (refs.size() > 0);
}
bool Items::removeItemOwner(df_item * item, Creatures *creatures)
bool Items::removeItemOwner(df_item * item, Units *creatures)
{
std::vector <t_itemref *> &p_refs = item->itemrefs;
for (uint32_t i=0; i<p_refs.size(); i++)

@ -42,14 +42,14 @@ using namespace std;
// we connect to those
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Units.h"
#include "dfhack/modules/Translation.h"
#include "ModuleFactory.h"
#include <dfhack/Core.h>
using namespace DFHack;
struct Creatures::Private
struct Units::Private
{
bool Inited;
bool Started;
@ -63,12 +63,12 @@ struct Creatures::Private
Translation * trans;
};
Module* DFHack::createCreatures()
Module* DFHack::createUnits()
{
return new Creatures();
return new Units();
}
Creatures::Creatures()
Units::Units()
{
Core & c = Core::getInstance();
d = new Private;
@ -85,7 +85,7 @@ Creatures::Creatures()
creatures = 0;
try
{
creatures = (vector <df_creature *> *) OG_Creatures->getAddress ("vector");
creatures = (vector <df_unit *> *) OG_Creatures->getAddress ("vector");
d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race");
d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ");
}
@ -93,13 +93,13 @@ Creatures::Creatures()
d->Inited = true;
}
Creatures::~Creatures()
Units::~Units()
{
if(d->Started)
Finish();
}
bool Creatures::Start( uint32_t &numcreatures )
bool Units::Start( uint32_t &numcreatures )
{
if(creatures)
{
@ -112,13 +112,13 @@ bool Creatures::Start( uint32_t &numcreatures )
return false;
}
bool Creatures::Finish()
bool Units::Finish()
{
d->Started = false;
return true;
}
df_creature * Creatures::GetCreature (const int32_t index)
df_unit * Units::GetCreature (const int32_t index)
{
if(!d->Started) return NULL;
@ -129,7 +129,7 @@ df_creature * Creatures::GetCreature (const int32_t index)
}
// returns index of creature actually read or -1 if no creature can be found
int32_t Creatures::GetCreatureInBox (int32_t index, df_creature ** 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)
{
@ -142,7 +142,7 @@ int32_t Creatures::GetCreatureInBox (int32_t index, df_creature ** furball,
while (uint32_t(index) < size)
{
// read pointer from vector at position
df_creature * temp = creatures->at(index);
df_unit * temp = creatures->at(index);
if (temp->x >= x1 && temp->x < x2)
{
if (temp->y >= y1 && temp->y < y2)
@ -160,7 +160,7 @@ int32_t Creatures::GetCreatureInBox (int32_t index, df_creature ** furball,
return -1;
}
void Creatures::CopyCreature(df_creature * source, t_creature & furball)
void Units::CopyCreature(df_unit * source, t_unit & furball)
{
if(!d->Started) return;
// read pointer from vector at position
@ -275,7 +275,7 @@ void Creatures::CopyCreature(df_creature * source, t_creature & furball)
furball.current_job.active = false;
}
}
int32_t Creatures::FindIndexById(int32_t creature_id)
int32_t Units::FindIndexById(int32_t creature_id)
{
if (!d->Started)
return -1;
@ -287,7 +287,7 @@ int32_t Creatures::FindIndexById(int32_t creature_id)
uint32_t size = creatures->size();
for (uint32_t index = 0; index < size; index++)
{
df_creature * temp = creatures->at(index);
df_unit * temp = creatures->at(index);
int32_t id = temp->id;
d->IdMap[id] = index;
}
@ -507,14 +507,14 @@ bool Creatures::WritePregnancy(const uint32_t index, const uint32_t pregTimer)
return true;
}
*/
uint32_t Creatures::GetDwarfRaceIndex()
uint32_t Units::GetDwarfRaceIndex()
{
if(!d->Inited) return 0;
Process * p = d->owner;
return p->readDWord(d->dwarf_race_index_addr);
}
int32_t Creatures::GetDwarfCivId()
int32_t Units::GetDwarfCivId()
{
if(!d->Inited) return -1;
Process * p = d->owner;
@ -551,30 +551,30 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
return true;
}
*/
bool Creatures::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item)
bool Units::ReadInventoryByIdx(const uint32_t index, std::vector<df_item *> & item)
{
if(!d->Started) return false;
if(index >= creatures->size()) return false;
df_creature * temp = creatures->at(index);
df_unit * temp = creatures->at(index);
return this->ReadInventoryByPtr(temp, item);
}
bool Creatures::ReadInventoryByPtr(const df_creature * 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;
return true;
}
bool Creatures::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item)
bool Units::ReadOwnedItemsByIdx(const uint32_t index, std::vector<int32_t> & item)
{
if(!d->Started ) return false;
if(index >= creatures->size()) return false;
df_creature * temp = creatures->at(index);
df_unit * temp = creatures->at(index);
return this->ReadOwnedItemsByPtr(temp, item);
}
bool Creatures::ReadOwnedItemsByPtr(const df_creature * temp, std::vector<int32_t> & items)
bool Units::ReadOwnedItemsByPtr(const df_unit * temp, std::vector<int32_t> & items)
{
unsigned int i;
if(!d->Started) return false;
@ -582,18 +582,18 @@ bool Creatures::ReadOwnedItemsByPtr(const df_creature * temp, std::vector<int32_
return true;
}
bool Creatures::RemoveOwnedItemByIdx(const uint32_t index, int32_t id)
bool Units::RemoveOwnedItemByIdx(const uint32_t index, int32_t id)
{
if(!d->Started)
{
cerr << "!d->Started FAIL" << endl;
return false;
}
df_creature * temp = creatures->at (index);
df_unit * temp = creatures->at (index);
return this->RemoveOwnedItemByPtr(temp, id);
}
bool Creatures::RemoveOwnedItemByPtr(df_creature * temp, int32_t id)
bool Units::RemoveOwnedItemByPtr(df_unit * temp, int32_t id)
{
if(!d->Started) return false;
Process * p = d->owner;
@ -612,7 +612,7 @@ bool Creatures::RemoveOwnedItemByPtr(df_creature * temp, int32_t id)
return true;
}
void Creatures::CopyNameTo(df_creature * creature, df_name * target)
void Units::CopyNameTo(df_unit * creature, df_name * target)
{
d->trans->copyName(&creature->name, target);
}

@ -15,7 +15,7 @@ using namespace std;
#include "dfhack/Vector.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Items.h"
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Units.h"
#include "dfhack/modules/kitchen.h"
#include "ModuleFactory.h"
#include <dfhack/Core.h>

@ -30,7 +30,7 @@ distribution.
namespace DFHack
{
class Module;
Module* createCreatures();
Module* createUnits();
Module* createEngravings();
Module* createGui();
Module* createWorld();
@ -43,5 +43,6 @@ namespace DFHack
Module* createMaps();
Module* createVermin();
Module* createNotes();
Module* createGraphic();
}
#endif

@ -67,7 +67,7 @@ case "$1" in
esac
# Reset terminal to sane state in case of a crash
reset $DF_RESET_OPTS
# reset $DF_RESET_OPTS
if [ -n "$DF_POST_CMD" ]; then
eval $DF_POST_CMD

@ -57,6 +57,7 @@ DFHACK_PLUGIN(deramp deramp.cpp)
DFHACK_PLUGIN(flows flows.cpp)
DFHACK_PLUGIN(filltraffic filltraffic.cpp)
DFHACK_PLUGIN(seedwatch seedwatch.cpp)
DFHACK_PLUGIN(versionosd versionosd.cpp)
# this is the skeleton plugin. If you want to make your own, make a copy and then change it
OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF)

@ -4,7 +4,7 @@
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/Items.h>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
#include <dfhack/modules/Gui.h>
using namespace DFHack;
@ -135,7 +135,7 @@ command_result cleanitems (Core * c)
command_result cleanunits (Core * c)
{
DFHack::Creatures * Creatures = c->getCreatures();
DFHack::Units * Creatures = c->getUnits();
uint32_t num_creatures;
if (!Creatures->Start(num_creatures))
@ -147,7 +147,7 @@ command_result cleanunits (Core * c)
int cleaned_units = 0, cleaned_total = 0;
for (std::size_t i = 0; i < num_creatures; i++)
{
df_creature *unit = Creatures->creatures->at(i);
df_unit *unit = Creatures->creatures->at(i);
int num = unit->contaminants.size();
if (num)
{

@ -16,7 +16,7 @@ using namespace std;
#include <string>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/Items.h>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
#include <dfhack/modules/Materials.h>
#include <dfhack/modules/Translation.h>
using namespace DFHack;
@ -90,7 +90,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
c->Suspend();
DFHack::Materials *Materials = c->getMaterials();
DFHack::Items *Items = c->getItems();
DFHack::Creatures *Creatures = c->getCreatures();
DFHack::Units *Creatures = c->getUnits();
DFHack::Translation *Tran = c->getTranslation();
uint32_t num_creatures;
@ -195,7 +195,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
if (owner_index >= 0)
{
DFHack::df_creature * temp = Creatures->GetCreature(owner_index);
DFHack::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 + "'";

@ -329,14 +329,14 @@ DFhackCExport command_result kittens (Core * c, vector <string> & parameters)
}
}
#include "dfhack/modules/Creatures.h"
#include "dfhack/modules/Units.h"
#include "dfhack/VersionInfo.h"
#include <stddef.h>
command_result test_creature_offsets(Core* c, vector< string >& parameters)
{
uint32_t off_vinfo = c->vinfo->getGroup("Creatures")->getGroup("creature")->/*getGroup("advanced")->*/getOffset("custom_profession");
uint32_t off_struct = offsetof(df_creature,custom_profession);
uint32_t off_vinfo = c->vinfo->getGroup("Creatures")->getGroup("creature")->/*getGroup("advanced")->*/getOffset("custom_profession");
uint32_t off_struct = offsetof(df_unit,custom_profession);
c->con.print("Struct 0x%x, vinfo 0x%x\n", off_struct, off_vinfo);
return CR_OK;
};
@ -344,7 +344,7 @@ command_result test_creature_offsets(Core* c, vector< string >& parameters)
command_result creat_job (Core * c, vector< string >& parameters)
{
c->Suspend();
Creatures * cr = c->getCreatures();
Units * cr = c->getUnits();
Gui * g = c-> getGui();
uint32_t num_cr = 0;
int32_t cx,cy,cz;
@ -364,7 +364,7 @@ command_result creat_job (Core * c, vector< string >& parameters)
auto iter = cr->creatures->begin();
while (iter != cr->creatures->end())
{
df_creature * unit = *iter;
df_unit * unit = *iter;
if(cx == unit->x && cy == unit->y && cz == unit->z)
{
c->con.print("%d:%s - address 0x%x - job 0x%x\n"
@ -372,8 +372,8 @@ command_result creat_job (Core * c, vector< string >& parameters)
unit->id,
unit->name.first_name.c_str(),
unit,
uint32_t(unit) + offsetof(df_creature,current_job),
uint32_t(unit) + offsetof(df_creature,current_soul),
uint32_t(unit) + offsetof(df_unit,current_job),
uint32_t(unit) + offsetof(df_unit,current_soul),
uint32_t(unit->current_soul) + offsetof(df_soul,likes)
);
df_soul * s = unit->current_soul;

@ -13,7 +13,7 @@ using namespace std;
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/VersionInfo.h>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
using namespace DFHack;
// dfhack interface
@ -33,9 +33,9 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
{
if (!enable_fastdwarf)
return CR_OK;
df_creature *cre;
DFHack::Creatures * cr = c->getCreatures();
static vector <df_creature*> *v = cr->creatures;
df_unit *cre;
DFHack::Units * cr = c->getUnits();
static vector <df_unit*> *v = cr->creatures;
uint32_t race = cr->GetDwarfRaceIndex();
uint32_t civ = cr->GetDwarfCivId();
if (!v)

@ -15,7 +15,7 @@ using namespace std;
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/Gui.h>
#include <dfhack/modules/Materials.h>
@ -57,7 +57,7 @@ DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
BEGIN_PROBE:
c->Suspend();
DFHack::Gui *Gui = c->getGui();
DFHack::Creatures * cr = c->getCreatures();
DFHack::Units * cr = c->getUnits();
int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
@ -70,7 +70,7 @@ DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
cr->Start(ncr);
for(auto i = 0; i < ncr; i++)
{
df_creature * unit = cr->GetCreature( i );
df_unit * unit = cr->GetCreature( i );
if(unit->x == cursorX && unit->y == cursorY && unit->z == cursorZ)
{
con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ, unit->civ);

@ -1 +1 @@
Subproject commit 71d28909ec397d0a772e6135a822cc1c4a5fd3a7
Subproject commit dbfeaf935df92644b72746842166baf700450e15

@ -0,0 +1,148 @@
// This tool display dfhack version on df screen
#include <Windows.h>
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <string.h>
using namespace std;
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Graphic.h>
#include <dfhack/modules/Gui.h>
using namespace DFHack;
DFhackCExport command_result df_versionosd (Core * c, vector <string> & parameters);
static DFSDL_Surface* (*_IMG_LoadPNG_RW)(void* src) = 0;
static vPtr (*_SDL_RWFromFile)(const char* file, const char *mode) = 0;
static int (*_SDL_SetAlpha)(vPtr surface, uint32_t flag, uint8_t alpha) = 0;
static int (*_SDL_SetColorKey)(vPtr surface, uint32_t flag, uint32_t key) = 0;
static uint32_t (*_SDL_MapRGB)(vPtr pixelformat, uint8_t r, uint8_t g, uint8_t b) = 0;
DFTileSurface* gettile(int x, int y);
bool On = true;
DFSDL_Surface* surface;
DFTileSurface* tiles[10];
char* file = "Cooz_curses_square_16x16.png";
Gui* gui;
DFhackCExport const char * plugin_name ( void )
{
return "versionosd";
}
DFTileSurface* createTile(int x, int y)
{
DFTileSurface* tile = new DFTileSurface;
tile->paintOver = true;
tile->rect = new DFSDL_Rect;
tile->rect->x = x*16;
tile->rect->y = y*16;
tile->rect->w = 16;
tile->rect->h = 16;
tile->surface = surface;
tile->dstResize = NULL;
return tile;
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("versionosd",
"Toggles displaying version in DF window",
df_versionosd));
HMODULE SDLImageLib = LoadLibrary("SDL_image.dll");
_IMG_LoadPNG_RW = (DFHack::DFSDL_Surface* (*)(void*))GetProcAddress(SDLImageLib, "IMG_LoadPNG_RW");
HMODULE realSDLlib = LoadLibrary("SDLreal.dll");
_SDL_RWFromFile = (void*(*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_RWFromFile");
_SDL_SetAlpha = (int (*)(void*, uint32_t, uint8_t))GetProcAddress(realSDLlib,"SDL_SetAlpha");
_SDL_SetColorKey = (int (*)(void*, uint32_t, uint32_t))GetProcAddress(realSDLlib,"SDL_SetColorKey");
_SDL_MapRGB = (uint32_t (*)(void*, uint8_t, uint8_t, uint8_t))GetProcAddress(realSDLlib,"SDL_MapRGB");
void* RWop = _SDL_RWFromFile(file, "rb");
surface = _IMG_LoadPNG_RW(RWop);
if ( !surface )
{
c->con.print("Couldnt load image from file %s", file);
return CR_FAILURE;
}
UINT32 pink = _SDL_MapRGB(vPtr(surface->format), 0xff, 0x00, 0xff);
_SDL_SetColorKey((vPtr)surface, 4096, pink);
_SDL_SetAlpha((vPtr)surface, 65536, 255);
// setup tiles
tiles[0] = createTile(4, 4); // D
tiles[1] = createTile(6, 4); // F
tiles[2] = createTile(8, 4); // H
tiles[3] = createTile(1, 6); // a
tiles[4] = createTile(3, 6); // c
tiles[5] = createTile(11, 6); // k
tiles[6] = createTile(0, 0); // " "
// FIXME: it should get REAL version not hardcoded one
tiles[7] = createTile(2, 7); // r
tiles[8] = createTile(8, 3); // 8
tiles[9] = createTile(9, 0); // o
gui = c->getGui();
Graphic* g = c->getGraphic();
g->Register(gettile);
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
Graphic* g = c->getGraphic();
g->Unregister(gettile);
delete surface;
for (int i=0; i<10; i++)
{
delete tiles[i];
}
delete [] tiles;
return CR_OK;
}
DFhackCExport command_result df_versionosd (Core * c, vector <string> & parameters)
{
On = !On;
c->Suspend();
c->con.print("Version OSD is %s\n", On ? "On" : "Off");
c->Resume();
return CR_OK;
}
DFTileSurface* gettile (int x, int y)
{
if ( !On ) return NULL;
if ( x == 0 && y-4 >= 0 && y-4 < 9 )
{
return tiles[y-4];
}
int32_t cx, cy, cz;
int32_t vx, vy, vz;
if ( !gui->getViewCoords(vx, vy, vz) ) return NULL;
if ( !gui->getCursorCoords(cx, cy, cz) ) return NULL;
if ( cx-vx+1 == x && cy-vy+1 == y )
{
return tiles[9];
}
return NULL;
}

@ -70,7 +70,7 @@ using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
/* Note about magic numbers:
* If you have an idea how to better solve this, tell me. Currently I'd be

@ -9,7 +9,7 @@ using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
#include <dfhack/modules/Materials.h>
#include <dfhack/modules/Creatures.h>
#include <dfhack/modules/Units.h>
#include <dfhack/modules/Translation.h>
vector< vector<string> > englishWords;