Merge commit 'origin' into bartavelle

develop
simon 2010-04-29 18:13:43 +02:00
commit 860b0a67af
28 changed files with 234 additions and 270 deletions

@ -33,6 +33,7 @@ include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/) include_directories (${CMAKE_SOURCE_DIR}/dfhack/depends/argstream/)
add_subdirectory (dfhack) add_subdirectory (dfhack)
add_subdirectory (dfhack/python)
#add_subdirectory (dfhack/shm) #add_subdirectory (dfhack/shm)
#FIXME: add exports for MSVC #FIXME: add exports for MSVC
#add_subdirectory (dfhack/depends/md5) #add_subdirectory (dfhack/depends/md5)

@ -1,20 +1,10 @@
Here's how you build dfhack! Here's how you build dfhack!
---------------------------- ----------------------------
First, there is one dependency, regardless of the OS you use:
cmake - it's the build system
Dependencies Dependencies
============ ============
You'll need cmake and 'a' compiler for building the main lib and the various tools. You'll need cmake and 'a' compiler for building the main lib and the various tools.
To build the libdfconnect on Linux, you'll have to make a 32bit build.
To build the fake SDL.dll on Windows, you'll have to use MSVC 2008 Express and make
a Release or RelWithDebInfo build.
The python bindings require SWIG and the python devel libs for building.
(Linux only) Veinlook requires the wide-character ncurses library (libncursesw) (Linux only) Veinlook requires the wide-character ncurses library (libncursesw)
Building on Linux: Building on Linux:
@ -86,8 +76,33 @@ MSVC generates. For example from 'output/' to 'output/Release/'
I'm afraid you are on your own. dfhack wasn't tested with any other compiler. I'm afraid you are on your own. dfhack wasn't tested with any other compiler.
Try using a different cmake generator that's intended for your tools. Try using a different cmake generator that's intended for your tools.
Build targets
-------------
dfhack has a few build targets.
If you're only after the library run 'make dfhack'.
'make' will build everything.
'make expbench' will build the expbench testing program and the library.
Build types
-----------
cmake allows you to pick a build type by changing this variable: CMAKE_BUILD_TYPE
cmake .. -DCMAKE_BUILD_TYPE:string=BUILD_TYPE
Without specifying a build type or 'None', cmake uses the CMAKE_CXX_FLAGS
variable for building.
Valid an useful build types include 'Release', 'Debug' and 'RelWithDebInfo'.
There are others, but they aren't really that useful.
Have fun.
Building the shared memory hook library (SHM) --------------------------------------------------------------------------------
**Deprecated*Deprecated*Deprecated*Deprecated*Deprecated*Deprecated*Deprecated**
--------------------------------------------------------------------------------
Building the shared memory hook library (SHM)
--------------------------------------------- ---------------------------------------------
Unlike the rest of DFHack, The SHM needs special treatment when it comes to Unlike the rest of DFHack, The SHM needs special treatment when it comes to
@ -142,26 +157,3 @@ String writing is best tested with a fresh throw-away fort and dfrenamer.
Embark, give one dwarf a very long name using dfrenamer and save/exit. Embark, give one dwarf a very long name using dfrenamer and save/exit.
If DF crashes during the save sequence, your SHM is not compatible with DF and If DF crashes during the save sequence, your SHM is not compatible with DF and
the throw-away fort is most probably lost. the throw-away fort is most probably lost.
Build targets
-------------
dfhack has a few build targets.
If you're only after the library run 'make dfhack'.
'make' will build everything.
'make expbench' will build the expbench testing program and the library.
Build types
-----------
cmake allows you to pick a build type by changing this variable: CMAKE_BUILD_TYPE
cmake .. -DCMAKE_BUILD_TYPE:string=BUILD_TYPE
Without specifying a build type or 'None', cmake uses the CMAKE_CXX_FLAGS
variable for building.
Valid an useful build types include 'Release', 'Debug' and 'RelWithDebInfo'.
There are others, but they aren't really that useful.
Have fun.

147
README

@ -20,20 +20,6 @@ and the arch-games repository.
The package name is dfhack-git :) The package name is dfhack-git :)
Clarification
-------------
'fake SDL.dll', 'SHM', 'libdfconnect' and 'shim library' are basically the same
thing. A library that sits between DFHack and DF, provides some extra features,
synchronisation and access control. You should use it for everything that writes
data back to DF.
You'll need the SHM to attach more than one tool to DF on Linux.
The DFHack version of Dwarf Therapist requires it for writing creature names
and professions.
See 'Using DFHack Tools' for instructions on installing it.
Compatibility Compatibility
------------- -------------
@ -46,17 +32,10 @@ OSX is also not supported due to lack of developers with a Mac.
Currently supported Dwarf Fortress versions: Currently supported Dwarf Fortress versions:
* Windows * Windows
38a - 40d19_2 0.31.01 - 0.31.03
* Linux * Linux
40d2 - 40d19 wine together with the Windows versions
Currently supported DF versions *by the SHM*:
* Windows
40d15 - 40d19
* Linux
40d9 - 40d19 (40d2 - 40d8 might work, but are untested)
Using the library as a developer Using the library as a developer
-------------------------------- --------------------------------
@ -72,112 +51,34 @@ At the time of writing there's no API reference or documentation. The code does
have a lot of comments though (and getting better all the time). have a lot of comments though (and getting better all the time).
Using DFHack Tools
------------------
The project comes with a special extra library you should add to your DF
installation. It's used to boost the transfer speed between DF and DFHack, and
provide data consistency and synchronization. DFHack will work without the
library, but at suboptimal speeds and the consistency of data written back
to DF is questionable.
!!! on Windows this currently only works with DF 40d15 - 40d19_2 !!!
On Linux, it works with DF 40d9 - 40d19
!!! use the pre-compiled library intended for your OS and version of DF !!!
You can find them in the 'precompiled' folder.
** Installing on Windows
- Open your DF folder, locate SDL.dll and rename it to SDLreal.dll (making
a backup of it is a good idea)
- Copy the right DFHack SDL.dll into your DF folder.
- Restart DF if it is running
** Unistalling on Windows
- Open your DF folder, locate SDL.dll and delete it
- Rename SDLreal.dll to SDL.dll
- Restart DF if it is running
** Installing on Linux
- Open your DF folder and the libs folder within it
- copy DFHack libdfconnect.so to the libs folder
- copy the df-hacked script to your DF folder
- Use this new startup script to start DF
** Replacing libdfconnect.so
- Make sure you close DF before you replace this file! DF crashes whn you don't
close it first!
** Uninstalling on Linux
- Open your DF and DF/libs folders
- Delete libdfconnect.so and the dfhacked startup script
- Go back to using the df startup script
Tools Tools
----- -----
All the DFHack tools are terminal programs. This might seem strange to Windows All the DFHack tools are terminal programs. This might seem strange to Windows
users, but these are meant mostly as examples for developers. Still, they can users, but these are meant mostly as examples for developers. Still, they can
be useful and are cross-platform just like the library itself. be useful and are cross-platform just like the library itself.
If the tool writes back to DF's memory, make sure you are using the shared - dfcleanmap : Cleans all the splatter that get scattered all over the map.
memory interface mentioned in the previous section! Only exception is mud. It leaves mud alone.
- dfexpbench : Just a simple benchmark of the data export speed.
* catsplosion- Makes all cats pregnant and due in 100 game steps. Use with care. - dfliquids : A command prompt for liquid creation and manipulation
(the Moses effect included!)
* magma_create - creates 7/7 magma at the DF's cursor Also allows painting obsidian walls directly.
Note:
* reveal - plain old reveal tool. It reveals all the map blocks already Spawning and deleting liquids can F up pathing data and
initialized by DF. temperatures (creating heat traps). You've been warned.
- dfposition : Prints the current DF window properties and cursor position.
* veinlook - a silly map viewer. It can mass-dig veins in a map square. - dfprospector: Lists all available minerals on the map and how much
(Linux only) of them there is.
- dfreveal : Reveals the whole map, waits for input and hides it again.
* prospector - scans the map for minerals. by default it only scans only visible If you close the tool while it waits, the map remains revealed.
veins. You can make it show hidden things with '-a' and base rock - dfsuspend : Test of the process suspend/resume mechanism.
and soil layers with '-b'. These can be combined ('-ab') - dfunstuck : Use if you prematurely close any of the tools and DF
appears to be stuck.
* cleanmap - cleans mud, vomit, snow and all kinds of mess from the map. - dfvdig : Designates a whole vein for digging. Point the cursor at a vein
It will clean your irrigated farms too, so consider yourself and run this thing :)
warned.
- Your tool here: Write one ;)
* incrementalsearch - incremental search utility (Linux only).
* bauxite - converts all mechanisms into bauxite mechanisms.
* itemdesignator - Allows mass-designating items by type and material - dump,
forbid, melt and set on fire ;)
* digger - allows designating tiles for digging/cutting/ramp removal
A list of accepted tile classes:
1 = WALL
2 = PILLAR
3 = FORTIFICATION
4 = STAIR_UP
5 = STAIR_DOWN
6 = STAIR_UPDOWN
7 = RAMP
8 = RAMP_TOP
9 = FLOOR
10 = TREE_DEAD
11 = TREE_OK
12 = SAPLING_DEAD
13 = SAPLING_OK
14 = SHRUB_DEAD
15 = SHRUB_OK
16 = BOULDER
17 = PEBBLES
Example : dfdigger -o 100,100,15 -t 9,10 -m 10
This will start looking for trees at coords 100,100,15 and designate ten of them for cutting.
Memory offset definitions Memory offset definitions
------------------------- -------------------------

@ -1,7 +0,0 @@
#ifndef CONFIG_H
#define CONFIG_H
#define MEMXML_DATA_PATH .
#define HAVE_64_BIT
#endif // CONFIG_H

@ -375,7 +375,7 @@ namespace DFHack
bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]); bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
uint32_t GetDwarfRaceIndex ( void ); uint32_t GetDwarfRaceIndex ( void );
int32_t GetDwarfCivId ( void ); int32_t GetDwarfCivId ( void );
bool ReadJob(const t_creature * furball, vector<t_material> & mat); bool ReadJob(const t_creature * furball, std::vector<t_material> & mat);
private: private:
struct Private; struct Private;
Private *d; Private *d;

@ -19,7 +19,7 @@ namespace DFHack
feature_Underworld, feature_Underworld,
feature_Hell_Temple feature_Hell_Temple
}; };
static char * sa_feature[]= static const char * sa_feature[]=
{ {
(char*)"Other", (char*)"Other",
(char*)"Adamantine Tube", (char*)"Adamantine Tube",

@ -19,11 +19,11 @@ namespace DFHack
struct t_descriptor_color struct t_descriptor_color
{ {
char id[128]; // id in the raws char id[128]; // id in the raws
float r; float r;
float v; float v;
float b; float b;
char name[128]; //displayed name char name[128]; //displayed name
}; };
struct t_matglossPlant struct t_matglossPlant

@ -199,7 +199,24 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
bool Materials::ReadInorganicMaterials (void) bool Materials::ReadInorganicMaterials (void)
{ {
return ReadNamesOnly(d->owner, d->owner->getDescriptor()->getAddress ("mat_inorganics"), inorganic ); Process * p = d->owner;
DfVector <uint32_t> p_matgloss (p, d->owner->getDescriptor()->getAddress ("mat_inorganics"));
uint32_t size = p_matgloss.size();
inorganic.clear();
inorganic.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
p->readSTLString (p_matgloss[i], mat.id, 128);
//p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128);
mat.name[0] = 0;
mat.fore = 0;
mat.back = 0;
mat.bright = 0;
inorganic.push_back(mat);
}
return true;
} }
bool Materials::ReadOrganicMaterials (void) bool Materials::ReadOrganicMaterials (void)

@ -0,0 +1,42 @@
PROJECT (pydfhack)
FIND_PACKAGE(PythonLibs)
SET(PYTHON_MODULE_PREFIX "")
SET(PROJECT_LIBS ${PYTHON_LIBRARIES} dfhack )
IF(UNIX)
add_definitions(-DLINUX_BUILD)
add_definitions(-DUSE_CONFIG_H)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -pedantic")
SET(PYTHON_MODULE_SUFFIX ".so")
ENDIF(UNIX)
IF(WIN32)
#windows
SET(PYTHON_MODULE_SUFFIX ".pyd")
ENDIF(WIN32)
IF(PYTHONLIBS_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
PYTHON_ADD_MODULE(pydfhack
DF_API.cpp
DF_Buildings.cpp
DF_Constructions.cpp
DF_CreatureManager.cpp
DF_GUI.cpp
DF_Maps.cpp
DF_Material.cpp
DF_Position.cpp
DF_Translate.cpp
DF_Vegetation.cpp
pydfhack.cpp
)
SET_TARGET_PROPERTIES(pydfhack PROPERTIES PREFIX "")
# fix suffix on windows
SET_TARGET_PROPERTIES(pydfhack PROPERTIES SUFFIX ${PYTHON_MODULE_SUFFIX})
TARGET_LINK_LIBRARIES(pydfhack ${PROJECT_LIBS})
ELSE(PYTHONLIBS_FOUND)
MESSAGE("UNABLE TO BUILD PYTHON BINDINGS!")
ENDIF(PYTHONLIBS_FOUND)

@ -27,6 +27,8 @@ distribution.
#include "Python.h" #include "Python.h"
#include <string> #include <string>
#include "integers.h"
#include "DFTypes.h" #include "DFTypes.h"
#include "DFHackAPI.h" #include "DFHackAPI.h"
#include "DF_Imports.cpp" #include "DF_Imports.cpp"
@ -144,7 +146,7 @@ static void DF_API_dealloc(DF_API* self)
if(self->api_Ptr != NULL) if(self->api_Ptr != NULL)
{ {
PySys_WriteStdout("api_Ptr = %i\n", (int)self->api_Ptr); PySys_WriteStdout("api_Ptr = 0x%x\n", self->api_Ptr);
delete self->api_Ptr; delete self->api_Ptr;
@ -692,4 +694,4 @@ static PyTypeObject DF_API_type =
DF_API_new, /* tp_new */ DF_API_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -28,6 +28,7 @@ distribution.
#include "Python.h" #include "Python.h"
#include <map> #include <map>
#include <string> #include <string>
#include "integers.h"
using namespace std; using namespace std;
@ -113,7 +114,7 @@ static void DF_Building_dealloc(DF_Building* self)
if(self->b_Ptr != NULL) if(self->b_Ptr != NULL)
{ {
PySys_WriteStdout("b_Ptr = %i\n", (int)self->b_Ptr); PySys_WriteStdout("b_Ptr = 0x%x\n", self->b_Ptr);
delete self->b_Ptr; delete self->b_Ptr;
@ -268,4 +269,4 @@ static PyTypeObject DF_Building_type =
DF_Building_new, /* tp_new */ DF_Building_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,6 +26,7 @@ distribution.
#define __DFCONSTRUCTIONS__ #define __DFCONSTRUCTIONS__
#include "Python.h" #include "Python.h"
#include "integers.h"
#include "modules/Constructions.h" #include "modules/Constructions.h"
#include "DF_Helpers.cpp" #include "DF_Helpers.cpp"
@ -104,7 +105,7 @@ static void DF_Construction_dealloc(DF_Construction* self)
if(self->c_Ptr != NULL) if(self->c_Ptr != NULL)
{ {
PySys_WriteStdout("c_Ptr = %i\n", (int)self->c_Ptr); PySys_WriteStdout("c_Ptr = 0x%x\n", self->c_Ptr);
delete self->c_Ptr; delete self->c_Ptr;
@ -217,4 +218,4 @@ static PyTypeObject DF_Construction_type =
DF_Construction_new, /* tp_new */ DF_Construction_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -27,6 +27,8 @@ distribution.
#include "Python.h" #include "Python.h"
#include "stdio.h" #include "stdio.h"
#include <vector>
#include "integers.h"
#include "DFTypes.h" #include "DFTypes.h"
#include "modules/Creatures.h" #include "modules/Creatures.h"
#include "DF_CreatureType.cpp" #include "DF_CreatureType.cpp"
@ -68,7 +70,7 @@ static void DF_CreatureManager_dealloc(DF_CreatureManager* self)
if(self->creature_Ptr != NULL) if(self->creature_Ptr != NULL)
{ {
PySys_WriteStdout("creature_Ptr = %i\n", (int)self->creature_Ptr); PySys_WriteStdout("creature_Ptr = 0x%x\n", self->creature_Ptr);
delete self->creature_Ptr; delete self->creature_Ptr;
@ -272,4 +274,4 @@ static PyTypeObject DF_CreatureManager_type =
DF_CreatureManager_new, /* tp_new */ DF_CreatureManager_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -253,4 +253,4 @@ static PyObject* BuildCreature(DFHack::t_creature& creature)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,6 +26,7 @@ distribution.
#define __DFGUI__ #define __DFGUI__
#include "Python.h" #include "Python.h"
#include "integers.h"
#include "DFTypes.h" #include "DFTypes.h"
#include "modules/Gui.h" #include "modules/Gui.h"
@ -64,7 +65,7 @@ static void DF_GUI_dealloc(DF_GUI* self)
if(self->g_Ptr != NULL) if(self->g_Ptr != NULL)
{ {
PySys_WriteStdout("g_Ptr = %i\n", (int)self->g_Ptr); PySys_WriteStdout("g_Ptr = 0x%x\n", self->g_Ptr);
delete self->g_Ptr; delete self->g_Ptr;
@ -203,4 +204,4 @@ static PyTypeObject DF_GUI_type =
DF_GUI_new, /* tp_new */ DF_GUI_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -90,9 +90,19 @@ static PyObject* BuildMatglossPair(DFHack::t_matglossPair& matgloss)
static DFHack::t_matglossPair ReverseBuildMatglossPair(PyObject* mObj) static DFHack::t_matglossPair ReverseBuildMatglossPair(PyObject* mObj)
{ {
DFHack::t_matglossPair mPair; DFHack::t_matglossPair mPair;
PyObject* temp;
temp = PyTuple_GetItem(mObj, 0);
mPair.type = (int16_t)PyInt_AsLong(temp);
Py_DECREF(temp);
mPair.type = (int16_t)PyInt_AsLong(PyTuple_GetItem(mObj, 0)); temp = PyTuple_GetItem(mObj, 1);
mPair.index = (int32_t)PyInt_AsLong(PyTuple_GetItem(mObj, 1));
mPair.index = (int32_t)PyInt_AsLong(temp);
Py_DECREF(temp);
return mPair; return mPair;
} }
@ -172,46 +182,28 @@ static PyObject* BuildNote(DFHack::t_note& note)
return noteObj; return noteObj;
} }
static int NAME_WORD_COUNT = 7;
static PyObject* BuildName(DFHack::t_name& name) static PyObject* BuildName(DFHack::t_name& name)
{ {
PyObject* nameObj; PyObject* nameObj;
PyObject *wordList, *speechList; PyObject *wordList, *speechList, *args;
PyObject* temp;
int wordCount = 7;
nameObj = PyObject_CallObject(Name_type, NULL);
if(name.first_name[0])
temp = PyString_FromString(name.first_name);
else
temp = PyString_FromString("");
OBJSET(nameObj, "first_name", temp);
if(name.nickname[0])
temp = PyString_FromString(name.nickname);
else
temp = PyString_FromString("");
OBJSET(nameObj, "nickname", temp);
temp = PyInt_FromLong(name.language); wordList = PyList_New(NAME_WORD_COUNT);
OBJSET(nameObj, "language", temp); speechList = PyList_New(NAME_WORD_COUNT);
temp = PyBool_FromLong((int)name.has_name); for(int i = 0; i < NAME_WORD_COUNT; i++)
OBJSET(nameObj, "has_name", temp);
wordList = PyList_New(wordCount);
speechList = PyList_New(wordCount);
for(int i = 0; i < wordCount; i++)
{ {
PyList_SET_ITEM(wordList, i, PyInt_FromLong(name.words[i])); PyList_SET_ITEM(wordList, i, PyInt_FromLong(name.words[i]));
PyList_SET_ITEM(speechList, i, PyInt_FromLong(name.parts_of_speech[i])); PyList_SET_ITEM(speechList, i, PyInt_FromLong(name.parts_of_speech[i]));
} }
OBJSET(nameObj, "words", wordList); args = Py_BuildValue("ssiOOO", name.first_name, name.nickname, name.language, \
OBJSET(nameObj, "parts_of_speech", speechList); PyBool_FromLong((int)name.has_name), wordList, speechList);
nameObj = PyObject_CallObject(Name_type, args);
Py_DECREF(args);
return nameObj; return nameObj;
} }
@ -219,8 +211,8 @@ static PyObject* BuildName(DFHack::t_name& name)
static DFHack::t_name ReverseBuildName(PyObject* nameObj) static DFHack::t_name ReverseBuildName(PyObject* nameObj)
{ {
PyObject *temp, *listTemp; PyObject *temp, *listTemp;
int boolTemp, arrLength; int boolTemp;
Py_ssize_t listLength, strLength; Py_ssize_t strLength;
char* strTemp; char* strTemp;
DFHack::t_name name; DFHack::t_name name;
@ -231,38 +223,33 @@ static DFHack::t_name ReverseBuildName(PyObject* nameObj)
boolTemp = (int)PyInt_AsLong(temp); boolTemp = (int)PyInt_AsLong(temp);
Py_DECREF(temp);
if(boolTemp != 0) if(boolTemp != 0)
name.has_name = true; name.has_name = true;
else else
name.has_name = false; name.has_name = false;
//I seriously doubt the name arrays will change length, but why take chances?
listTemp = PyObject_GetAttrString(nameObj, "words"); listTemp = PyObject_GetAttrString(nameObj, "words");
arrLength = sizeof(name.words) / sizeof(uint32_t); for(int i = 0; i < NAME_WORD_COUNT; i++)
listLength = PyList_Size(listTemp);
if(listLength < arrLength)
arrLength = listLength;
for(int i = 0; i < arrLength; i++)
name.words[i] = (uint32_t)PyInt_AsLong(PyList_GetItem(listTemp, i)); name.words[i] = (uint32_t)PyInt_AsLong(PyList_GetItem(listTemp, i));
listTemp = PyObject_GetAttrString(nameObj, "parts_of_speech"); Py_DECREF(listTemp);
arrLength = sizeof(name.parts_of_speech) / sizeof(uint16_t);
listLength = PyList_Size(listTemp);
if(listLength < arrLength) listTemp = PyObject_GetAttrString(nameObj, "parts_of_speech");
arrLength = listLength;
for(int i = 0; i < arrLength; i++) for(int i = 0; i < NAME_WORD_COUNT; i++)
name.parts_of_speech[i] = (uint16_t)PyInt_AsLong(PyList_GetItem(listTemp, i)); name.parts_of_speech[i] = (uint16_t)PyInt_AsLong(PyList_GetItem(listTemp, i));
Py_DECREF(listTemp);
temp = PyObject_GetAttrString(nameObj, "first_name"); temp = PyObject_GetAttrString(nameObj, "first_name");
strLength = PyString_Size(temp); strLength = PyString_Size(temp);
strTemp = PyString_AsString(temp); strTemp = PyString_AsString(temp);
Py_DECREF(temp);
if(strLength > 128) if(strLength > 128)
{ {
strncpy(name.first_name, strTemp, 127); strncpy(name.first_name, strTemp, 127);
@ -278,6 +265,8 @@ static DFHack::t_name ReverseBuildName(PyObject* nameObj)
strLength = PyString_Size(temp); strLength = PyString_Size(temp);
strTemp = PyString_AsString(temp); strTemp = PyString_AsString(temp);
Py_DECREF(temp);
if(strLength > 128) if(strLength > 128)
{ {
strncpy(name.nickname, strTemp, 127); strncpy(name.nickname, strTemp, 127);
@ -376,4 +365,4 @@ static PyObject* BuildSoul(DFHack::t_soul& soul)
return soulObj; return soulObj;
} }
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -97,4 +97,4 @@ static void DoImports()
} }
} }
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -28,10 +28,12 @@ distribution.
#include "Python.h" #include "Python.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include "integers.h"
using namespace std; using namespace std;
#include "DFTypes.h" #include "DFTypes.h"
#include <map>
#include "modules/Maps.h" #include "modules/Maps.h"
#include "DF_Imports.cpp" #include "DF_Imports.cpp"
#include "DF_Helpers.cpp" #include "DF_Helpers.cpp"
@ -391,7 +393,7 @@ static void DF_Map_dealloc(DF_Map* self)
if(self->m_Ptr != NULL) if(self->m_Ptr != NULL)
{ {
PySys_WriteStdout("m_Ptr = %i\n", (int)self->m_Ptr); PySys_WriteStdout("m_Ptr = 0x%x\n", self->m_Ptr);
delete self->m_Ptr; delete self->m_Ptr;
@ -857,4 +859,4 @@ static PyTypeObject DF_Map_type =
DF_Map_new, /* tp_new */ DF_Map_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -27,6 +27,7 @@ distribution.
#include "Python.h" #include "Python.h"
#include <vector> #include <vector>
#include "integers.h"
using namespace std; using namespace std;
@ -244,7 +245,7 @@ static void DF_Material_dealloc(DF_Material* self)
if(self->mat_Ptr != NULL) if(self->mat_Ptr != NULL)
{ {
PySys_WriteStdout("mat_Ptr = %i\n", (int)self->mat_Ptr); PySys_WriteStdout("mat_Ptr = 0x%x\n", self->mat_Ptr);
delete self->mat_Ptr; delete self->mat_Ptr;
@ -421,4 +422,4 @@ static PyTypeObject DF_Material_type =
DF_Material_new, /* tp_new */ DF_Material_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -71,7 +71,7 @@ static void DF_MemInfo_dealloc(DF_MemInfo* self)
if(self->mem_Ptr != NULL) if(self->mem_Ptr != NULL)
{ {
PySys_WriteStdout("mem_Ptr = %i\n", (int)self->mem_Ptr); PySys_WriteStdout("mem_Ptr = 0x%x\n", self->mem_Ptr);
delete self->mem_Ptr; delete self->mem_Ptr;
@ -681,4 +681,4 @@ static PyTypeObject DF_MemInfo_type =
DF_MemInfo_new, /* tp_new */ DF_MemInfo_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,6 +26,7 @@ distribution.
#define __DFPOSITION__ #define __DFPOSITION__
#include "Python.h" #include "Python.h"
#include "integers.h"
#include "modules/Position.h" #include "modules/Position.h"
using namespace DFHack; using namespace DFHack;
@ -198,4 +199,4 @@ static PyTypeObject DF_Position_type =
DF_Position_new, /* tp_new */ DF_Position_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -28,6 +28,7 @@ distribution.
#include "Python.h" #include "Python.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include "integers.h"
using namespace std; using namespace std;
@ -75,7 +76,7 @@ static void DF_Translate_dealloc(DF_Translate* self)
{ {
Py_XDECREF(self->dict); Py_XDECREF(self->dict);
PySys_WriteStdout("tran_Ptr = %i\n", (int)self->tran_Ptr); PySys_WriteStdout("tran_Ptr = 0x%x\n", self->tran_Ptr);
delete self->tran_Ptr; delete self->tran_Ptr;
@ -196,6 +197,12 @@ static PyObject* DF_Translate_TranslateName(DF_Translate* self, PyObject* args)
if(PyArg_ParseTuple(args, "O|i", &nameObj, &inEnglish)) if(PyArg_ParseTuple(args, "O|i", &nameObj, &inEnglish))
return NULL; return NULL;
if(PyObject_IsInstance(nameObj, Name_type) != 1)
{
PyErr_SetString(PyExc_TypeError, "argument 1 must be a Name object");
return NULL;
}
name = ReverseBuildName(nameObj); name = ReverseBuildName(nameObj);
std::string nameStr = self->tran_Ptr->TranslateName(name, (bool)inEnglish); std::string nameStr = self->tran_Ptr->TranslateName(name, (bool)inEnglish);
@ -278,4 +285,4 @@ static PyTypeObject DF_Translate_type =
DF_Translate_new, /* tp_new */ DF_Translate_new, /* tp_new */
}; };
#endif #endif

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,6 +26,7 @@ distribution.
#define __DFVEGETATION__ #define __DFVEGETATION__
#include "Python.h" #include "Python.h"
#include "integers.h"
#include "modules/Vegetation.h" #include "modules/Vegetation.h"
#include "DF_Helpers.cpp" #include "DF_Helpers.cpp"
@ -78,7 +79,7 @@ static void DF_Vegetation_dealloc(DF_Vegetation* self)
if(self->veg_Ptr != NULL) if(self->veg_Ptr != NULL)
{ {
PySys_WriteStdout("veg_Ptr = %i\n", (int)self->veg_Ptr); PySys_WriteStdout("veg_Ptr = 0x%x\n", self->veg_Ptr);
delete self->veg_Ptr; delete self->veg_Ptr;
@ -191,4 +192,4 @@ static PyTypeObject DF_Vegetation_type =
DF_Vegetation_new, /* tp_new */ DF_Vegetation_new, /* tp_new */
}; };
#endif #endif

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from distutils.core import setup, Extension
e = Extension("pydfhack",
sources=["DF_API.cpp", "DF_Buildings.cpp", "DF_Constructions.cpp", "DF_CreatureManager.cpp", "DF_GUI.cpp", "DF_Maps.cpp", "DF_Material.cpp", "DF_Position.cpp", "DF_Translate.cpp", "DF_Vegetation.cpp", "pydfhack.cpp"],
include_dirs=["../", "../include", "../depends/md5", "../depends/tinyxml"],
library_dirs=["../../output"],
extra_compile_args=["-DLINUX_BUILD"],
libraries=["dfhack-debug"],
export_symbols=["initpydfhack", "ReadRaw", "WriteRaw"])
setup(name="PyDFHack", version="1.0", ext_modules=[e])

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -132,4 +132,4 @@ PyMODINIT_FUNC initpydfhack(void)
DoImports(); DoImports();
} }

@ -17,9 +17,7 @@ Matgloss = namedtuple("Matgloss", "id, fore, back, bright, name")
DescriptorColor = namedtuple("DescriptorColor", "id, r, v, b, name") DescriptorColor = namedtuple("DescriptorColor", "id, r, v, b, name")
CreatureTypeEx = namedtuple("CreatureTypeEx", "rawname, castes, tile_character, tilecolor") CreatureTypeEx = namedtuple("CreatureTypeEx", "rawname, castes, tile_character, tilecolor")
TileColor = namedtuple("TileColor", "fore, back, bright") TileColor = namedtuple("TileColor", "fore, back, bright")
Name = namedtuple("Name", "first_name, nickname, language, has_name, words, parts_of_speech")
class Name(object):
__slots__ = ["first_name", "nickname", "language", "has_name", "words", "parts_of_speech"]
class Soul(object): class Soul(object):
def __init__(self, *args, **kwds): def __init__(self, *args, **kwds):

@ -3,7 +3,7 @@ from distutils.core import setup, Extension
e = Extension("pydfhack", e = Extension("pydfhack",
sources=["DF_API.cpp", "DF_Buildings.cpp", "DF_Constructions.cpp", "DF_CreatureManager.cpp", "DF_GUI.cpp", "DF_Maps.cpp", "DF_Material.cpp", "DF_Position.cpp", "DF_Translate.cpp", "DF_Vegetation.cpp", "pydfhack.cpp"], sources=["DF_API.cpp", "DF_Buildings.cpp", "DF_Constructions.cpp", "DF_CreatureManager.cpp", "DF_GUI.cpp", "DF_Maps.cpp", "DF_Material.cpp", "DF_Position.cpp", "DF_Translate.cpp", "DF_Vegetation.cpp", "pydfhack.cpp"],
include_dirs=["..\\", "..\\include", "..\\depends\\md5", "..\\depends\\tinyxml"], include_dirs=["../", "../include", "../depends/md5", "../depends/tinyxml"],
library_dirs=["..\\..\\output"], library_dirs=["..\\..\\output"],
#extra_compile_args=["-w"], #extra_compile_args=["-w"],
libraries=["libdfhack"], libraries=["libdfhack"],

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pydfhack import pydfhack
DF = pydfhack.API("Memory.xml") DF = pydfhack._API("Memory.xml")
if DF.Attach(): if DF.Attach():
success,stones = DF.ReadStoneMatgloss() Mats = DF.materials
if success: stones = Mats.Read_Inorganic_Materials()
print "Dumping all stone" print "Dumping all stone"
for matgloss in stones: for matgloss in stones:
print "ID %s, name %s" % (matgloss.id, matgloss.name) print "ID %s, name %s" % (matgloss.id, matgloss.name)
DF.Detach() DF.Detach()