Merge branch 'pydfhack' of git://github.com/doomchild/dfhack into DF2010
commit
b248663e33
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFCREATURES__
|
||||||
|
#define __DFCREATURES__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "DFTypes.h"
|
||||||
|
#include "modules/Creatures.h"
|
||||||
|
#include "DF_CreatureType.cpp"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct DF_CreatureManager
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
DFHack::Creatures* creature_Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
// API type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_CreatureManager_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_CreatureManager* self;
|
||||||
|
|
||||||
|
self = (DF_CreatureManager*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
self->creature_Ptr = NULL;
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DF_CreatureManager_init(DF_CreatureManager* self, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_CreatureManager_dealloc(DF_CreatureManager* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
if(self->creature_Ptr != NULL)
|
||||||
|
{
|
||||||
|
delete self->creature_Ptr;
|
||||||
|
|
||||||
|
self->creature_Ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type methods
|
||||||
|
|
||||||
|
static PyObject* DF_CreatureManager_Start(DF_CreatureManager* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t numCreatures = 0;
|
||||||
|
|
||||||
|
if(self->creature_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->creature_Ptr->Start(numCreatures))
|
||||||
|
return PyInt_FromLong(numCreatures);
|
||||||
|
else
|
||||||
|
return PyInt_FromLong(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_CreatureManager_Finish(DF_CreatureManager* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->creature_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->creature_Ptr->Finish())
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_CreatureManager_ReadCreature(DF_CreatureManager* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t index;
|
||||||
|
DFHack::t_creature furball;
|
||||||
|
|
||||||
|
if(self->creature_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &index))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->creature_Ptr->ReadCreature(index, furball))
|
||||||
|
{
|
||||||
|
return BuildCreature(furball);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_CreatureManager_ReadCreatureInBox(DF_CreatureManager* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t index;
|
||||||
|
uint32_t x1, y1, z1, x2, y2, z2;
|
||||||
|
DFHack::t_creature furball;
|
||||||
|
|
||||||
|
if(self->creature_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "iIIIIII", &index, &x1, &y1, &z1, &x2, &y2, &z2))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->creature_Ptr->ReadCreatureInBox(index, furball, x1, y1, z1, x2, y2, z2) >= 0)
|
||||||
|
return BuildCreature(furball);
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef DF_CreatureManager_methods[] =
|
||||||
|
{
|
||||||
|
{"Start", (PyCFunction)DF_CreatureManager_Start, METH_NOARGS, ""},
|
||||||
|
{"Finish", (PyCFunction)DF_CreatureManager_Finish, METH_NOARGS, ""},
|
||||||
|
{"Read_Creature", (PyCFunction)DF_CreatureManager_ReadCreature, METH_VARARGS, ""},
|
||||||
|
{"Read_Creature_In_Box", (PyCFunction)DF_CreatureManager_ReadCreatureInBox, METH_VARARGS, ""},
|
||||||
|
{NULL} // Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyTypeObject DF_CreatureManager_type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"pydfhack.CreatureManager", /*tp_name*/
|
||||||
|
sizeof(DF_CreatureManager), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
(destructor)DF_CreatureManager_dealloc, /*tp_dealloc*/
|
||||||
|
0, /*tp_print*/
|
||||||
|
0, /*tp_getattr*/
|
||||||
|
0, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
0, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
0, /*tp_as_sequence*/
|
||||||
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
|
0, /*tp_call*/
|
||||||
|
0, /*tp_str*/
|
||||||
|
0, /*tp_getattro*/
|
||||||
|
0, /*tp_setattro*/
|
||||||
|
0, /*tp_as_buffer*/
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
|
"pydfhack CreatureManager objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
DF_CreatureManager_methods, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
0, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
(initproc)DF_CreatureManager_init, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
DF_CreatureManager_new, /* tp_new */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,282 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFCREATURETYPE__
|
||||||
|
#define __DFCREATURETYPE__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "structmember.h"
|
||||||
|
#include "DF_Imports.cpp"
|
||||||
|
#include "DF_Helpers.cpp"
|
||||||
|
#include "modules/Creatures.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct DF_Creature_Base
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
|
||||||
|
// simple type stuff
|
||||||
|
uint32_t origin;
|
||||||
|
uint32_t c_type;
|
||||||
|
uint8_t profession;
|
||||||
|
uint16_t mood;
|
||||||
|
uint32_t happiness;
|
||||||
|
uint32_t c_id;
|
||||||
|
uint32_t agility;
|
||||||
|
uint32_t strength;
|
||||||
|
uint32_t toughness;
|
||||||
|
uint32_t money;
|
||||||
|
int32_t squad_leader_id;
|
||||||
|
uint8_t sex;
|
||||||
|
uint32_t pregnancy_timer;
|
||||||
|
int32_t blood_max, blood_current;
|
||||||
|
uint32_t bleed_rate;
|
||||||
|
|
||||||
|
PyObject* custom_profession;
|
||||||
|
|
||||||
|
// composites
|
||||||
|
PyObject* position;
|
||||||
|
PyObject *name, *squad_name, *artifact_name;
|
||||||
|
PyObject* current_job;
|
||||||
|
|
||||||
|
// customs
|
||||||
|
PyObject *flags1, *flags2;
|
||||||
|
|
||||||
|
// lists
|
||||||
|
PyObject* skill_list;
|
||||||
|
PyObject* like_list;
|
||||||
|
PyObject* trait_list;
|
||||||
|
PyObject* labor_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
// API type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_Creature_Base_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_Creature_Base* self;
|
||||||
|
|
||||||
|
self = (DF_Creature_Base*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
self->origin = 0;
|
||||||
|
self->c_type = 0;
|
||||||
|
self->profession = 0;
|
||||||
|
self->mood = 0;
|
||||||
|
self->happiness = 0;
|
||||||
|
self->c_id = 0;
|
||||||
|
self->agility = 0;
|
||||||
|
self->strength = 0;
|
||||||
|
self->toughness = 0;
|
||||||
|
self->money = 0;
|
||||||
|
self->squad_leader_id = 0;
|
||||||
|
self->sex = 0;
|
||||||
|
self->pregnancy_timer = 0;
|
||||||
|
self->blood_max = 0;
|
||||||
|
self->blood_current = 0;
|
||||||
|
self->bleed_rate = 0;
|
||||||
|
|
||||||
|
self->custom_profession = PyString_FromString("");
|
||||||
|
self->name = PyString_FromString("");
|
||||||
|
self->squad_name = PyString_FromString("");
|
||||||
|
self->artifact_name = PyString_FromString("");
|
||||||
|
|
||||||
|
self->skill_list = NULL;
|
||||||
|
self->like_list = NULL;
|
||||||
|
self->trait_list = NULL;
|
||||||
|
self->labor_list = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_Creature_Base_dealloc(DF_Creature_Base* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
Py_XDECREF(self->position);
|
||||||
|
Py_XDECREF(self->flags1);
|
||||||
|
Py_XDECREF(self->flags2);
|
||||||
|
|
||||||
|
Py_XDECREF(self->custom_profession);
|
||||||
|
Py_XDECREF(self->name);
|
||||||
|
Py_XDECREF(self->squad_name);
|
||||||
|
Py_XDECREF(self->artifact_name);
|
||||||
|
Py_XDECREF(self->current_job);
|
||||||
|
|
||||||
|
Py_XDECREF(self->flags1);
|
||||||
|
Py_XDECREF(self->flags2);
|
||||||
|
|
||||||
|
Py_XDECREF(self->labor_list);
|
||||||
|
Py_XDECREF(self->trait_list);
|
||||||
|
Py_XDECREF(self->skill_list);
|
||||||
|
Py_XDECREF(self->like_list);
|
||||||
|
|
||||||
|
// if(self->labor_list != NULL)
|
||||||
|
// PyList_Clear(self->labor_list);
|
||||||
|
// if(self->trait_list != NULL)
|
||||||
|
// PyList_Clear(self->trait_list);
|
||||||
|
// if(self->skill_list != NULL)
|
||||||
|
// PyList_Clear(self->skill_list);
|
||||||
|
// if(self->like_list != NULL)
|
||||||
|
// PyList_Clear(self->like_list);
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMemberDef DF_Creature_Base_members[] =
|
||||||
|
{
|
||||||
|
{"origin", T_UINT, offsetof(DF_Creature_Base, origin), 0, ""},
|
||||||
|
{"type", T_UINT, offsetof(DF_Creature_Base, c_type), 0, ""},
|
||||||
|
{"flags1", T_OBJECT_EX, offsetof(DF_Creature_Base, flags1), 0, ""},
|
||||||
|
{"flags2", T_OBJECT_EX, offsetof(DF_Creature_Base, flags2), 0, ""},
|
||||||
|
{"name", T_OBJECT_EX, offsetof(DF_Creature_Base, name), 0, ""},
|
||||||
|
{"squad_name", T_OBJECT_EX, offsetof(DF_Creature_Base, squad_name), 0, ""},
|
||||||
|
{"artifact_name", T_OBJECT_EX, offsetof(DF_Creature_Base, artifact_name), 0, ""},
|
||||||
|
{"profession", T_INT, offsetof(DF_Creature_Base, profession), 0, ""},
|
||||||
|
{"custom_profession", T_OBJECT_EX, offsetof(DF_Creature_Base, custom_profession), 0, ""},
|
||||||
|
{"happiness", T_SHORT, offsetof(DF_Creature_Base, happiness), 0, ""},
|
||||||
|
{NULL} //Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyGetSetDef DF_Creature_Base_getterSetters[] =
|
||||||
|
{
|
||||||
|
{NULL} //Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyMethodDef DF_Creature_Base_methods[] =
|
||||||
|
{
|
||||||
|
{NULL} //Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyTypeObject DF_Creature_Base_type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"pydfhack.Creature_Base", /*tp_name*/
|
||||||
|
sizeof(DF_Creature_Base), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
(destructor)DF_Creature_Base_dealloc, /*tp_dealloc*/
|
||||||
|
0, /*tp_print*/
|
||||||
|
0, /*tp_getattr*/
|
||||||
|
0, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
0, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
0, /*tp_as_sequence*/
|
||||||
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
|
0, /*tp_call*/
|
||||||
|
0, /*tp_str*/
|
||||||
|
0, /*tp_getattro*/
|
||||||
|
0, /*tp_setattro*/
|
||||||
|
0, /*tp_as_buffer*/
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
|
"pydfhack CreatureBase objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
DF_Creature_Base_methods, /* tp_methods */
|
||||||
|
DF_Creature_Base_members, /* tp_members */
|
||||||
|
DF_Creature_Base_getterSetters, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
0, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
DF_Creature_Base_new, /* tp_new */
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyObject* BuildCreature(DFHack::t_creature& creature)
|
||||||
|
{
|
||||||
|
DF_Creature_Base* obj;
|
||||||
|
|
||||||
|
obj = (DF_Creature_Base*)PyObject_Call((PyObject*)&DF_Creature_Base_type, NULL, NULL);
|
||||||
|
|
||||||
|
if(obj != NULL)
|
||||||
|
{
|
||||||
|
obj->position = Py_BuildValue("III", creature.x, creature.y, creature.z);
|
||||||
|
obj->profession = creature.profession;
|
||||||
|
obj->c_type = creature.type;
|
||||||
|
obj->mood = creature.mood;
|
||||||
|
obj->happiness = creature.happiness;
|
||||||
|
obj->c_id = creature.id;
|
||||||
|
obj->agility = creature.agility;
|
||||||
|
obj->strength = creature.strength;
|
||||||
|
obj->toughness = creature.toughness;
|
||||||
|
obj->money = creature.money;
|
||||||
|
obj->squad_leader_id = creature.squad_leader_id;
|
||||||
|
obj->sex = creature.sex;
|
||||||
|
obj->pregnancy_timer = creature.pregnancy_timer;
|
||||||
|
obj->blood_max = creature.blood_max;
|
||||||
|
obj->blood_current = creature.blood_current;
|
||||||
|
obj->bleed_rate = creature.bleed_rate;
|
||||||
|
|
||||||
|
if(creature.custom_profession[0])
|
||||||
|
obj->custom_profession = PyString_FromString(creature.custom_profession);
|
||||||
|
|
||||||
|
obj->flags1 = PyObject_Call(CreatureFlags1_type, PyInt_FromLong(creature.flags1.whole), NULL);
|
||||||
|
obj->flags2 = PyObject_Call(CreatureFlags2_type, PyInt_FromLong(creature.flags2.whole), NULL);
|
||||||
|
|
||||||
|
obj->current_job = BuildJob(creature.current_job);
|
||||||
|
obj->name = BuildName(creature.name);
|
||||||
|
obj->squad_name = BuildName(creature.squad_name);
|
||||||
|
obj->artifact_name = BuildName(creature.artifact_name);
|
||||||
|
|
||||||
|
obj->skill_list = PyList_New(creature.numSkills);
|
||||||
|
|
||||||
|
for(int i = 0; i < creature.numSkills; i++)
|
||||||
|
PyList_SetItem(obj->skill_list, i, BuildSkill(creature.skills[i]));
|
||||||
|
|
||||||
|
obj->like_list = PyList_New(creature.numLikes);
|
||||||
|
|
||||||
|
for(int i = 0; i < creature.numLikes; i++)
|
||||||
|
PyList_SetItem(obj->like_list, i, BuildLike(creature.likes[i]));
|
||||||
|
|
||||||
|
obj->labor_list = PyList_New(NUM_CREATURE_LABORS);
|
||||||
|
|
||||||
|
for(int i = 0; i < NUM_CREATURE_LABORS; i++)
|
||||||
|
PyList_SetItem(obj->labor_list, i, PyInt_FromLong(creature.labors[i]));
|
||||||
|
|
||||||
|
obj->trait_list = PyList_New(NUM_CREATURE_TRAITS);
|
||||||
|
|
||||||
|
for(int i = 0; i < NUM_CREATURE_TRAITS; i++)
|
||||||
|
PyList_SetItem(obj->trait_list, i, PyInt_FromLong(creature.traits[i]));
|
||||||
|
|
||||||
|
Py_INCREF((PyObject*)obj);
|
||||||
|
|
||||||
|
return (PyObject*)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFCREATURES__
|
||||||
|
#define __DFCREATURES__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "DFTypes.h"
|
||||||
|
#include "DF_CreatureType.cpp"
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,213 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFHELPERS__
|
||||||
|
#define __DFHELPERS__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "DF_Imports.cpp"
|
||||||
|
#include "DFTypes.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
#include "modules/Creatures.h"
|
||||||
|
|
||||||
|
static PyObject* BuildMatglossPair(DFHack::t_matglossPair& matgloss)
|
||||||
|
{
|
||||||
|
return Py_BuildValue("ii", matgloss.type, matgloss.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static PyObject* BuildTreeDesc(DFHack::t_tree_desc& tree)
|
||||||
|
// {
|
||||||
|
// return Py_BuildValue("OO", BuildMatglossPair(tree.material), Py_BuildValue("III", tree.x, tree.y, tree.z));
|
||||||
|
// }
|
||||||
|
|
||||||
|
static PyObject* BuildSkill(DFHack::t_skill& skill)
|
||||||
|
{
|
||||||
|
return Py_BuildValue("III", skill.id, skill.experience, skill.rating);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildJob(DFHack::t_job& job)
|
||||||
|
{
|
||||||
|
return Py_BuildValue("Oi", PyBool_FromLong((int)job.active), job.jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildItemType(DFHack::t_itemType& item)
|
||||||
|
{
|
||||||
|
PyObject *id, *name;
|
||||||
|
|
||||||
|
if(item.id[0])
|
||||||
|
id = PyString_FromString(item.id);
|
||||||
|
else
|
||||||
|
id = PyString_FromString("");
|
||||||
|
|
||||||
|
if(item.name[0])
|
||||||
|
name = PyString_FromString(item.name);
|
||||||
|
else
|
||||||
|
name = PyString_FromString("");
|
||||||
|
|
||||||
|
return Py_BuildValue("OO", id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildLike(DFHack::t_like& like)
|
||||||
|
{
|
||||||
|
PyObject* item;
|
||||||
|
|
||||||
|
item = Py_BuildValue("iii", like.type, like.itemClass, like.itemIndex);
|
||||||
|
|
||||||
|
return Py_BuildValue("OOO", item, BuildMatglossPair(like.material), PyBool_FromLong((int)like.active));
|
||||||
|
}
|
||||||
|
|
||||||
|
//PyDict_SetItem and PyDict_SetItemString don't steal references, so this had to get a bit more complicated...
|
||||||
|
static PyObject* BuildNote(DFHack::t_note& note)
|
||||||
|
{
|
||||||
|
PyObject* noteDict = PyDict_New();
|
||||||
|
PyObject* temp;
|
||||||
|
|
||||||
|
temp = PyString_FromFormat("%c", note.symbol);
|
||||||
|
|
||||||
|
PyDict_SetItemString(noteDict, "symbol", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = Py_BuildValue("II", note.foreground, note.background);
|
||||||
|
|
||||||
|
PyDict_SetItemString(noteDict, "fore_back", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
if(note.name[0])
|
||||||
|
temp = PyString_FromString(note.name);
|
||||||
|
else
|
||||||
|
PyString_FromString("");
|
||||||
|
|
||||||
|
PyDict_SetItemString(noteDict, "name", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = Py_BuildValue("III", note.x, note.y, note.z);
|
||||||
|
|
||||||
|
PyDict_SetItemString(noteDict, "position", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
return noteDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
//same here...reference counting is kind of a pain, assuming I'm even doing it right...
|
||||||
|
static PyObject* BuildName(DFHack::t_name& name)
|
||||||
|
{
|
||||||
|
PyObject* nameDict;
|
||||||
|
PyObject *wordList, *speechList;
|
||||||
|
PyObject* temp;
|
||||||
|
int wordCount = 7;
|
||||||
|
|
||||||
|
nameDict = PyDict_New();
|
||||||
|
|
||||||
|
if(name.first_name[0])
|
||||||
|
temp = PyString_FromString(name.first_name);
|
||||||
|
else
|
||||||
|
temp = PyString_FromString("");
|
||||||
|
|
||||||
|
PyDict_SetItemString(nameDict, "first_name", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
if(name.nickname[0])
|
||||||
|
temp = PyString_FromString(name.nickname);
|
||||||
|
else
|
||||||
|
temp = PyString_FromString("");
|
||||||
|
|
||||||
|
PyDict_SetItemString(nameDict, "nickname", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = PyInt_FromLong(name.language);
|
||||||
|
|
||||||
|
PyDict_SetItemString(nameDict, "language", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = PyBool_FromLong((int)name.has_name);
|
||||||
|
|
||||||
|
PyDict_SetItemString(nameDict, "has_name", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
wordList = PyList_New(wordCount);
|
||||||
|
speechList = PyList_New(wordCount);
|
||||||
|
|
||||||
|
for(int i = 0; i < wordCount; i++)
|
||||||
|
{
|
||||||
|
PyList_SetItem(wordList, i, PyInt_FromLong(name.words[i]));
|
||||||
|
PyList_SetItem(wordList, i, PyInt_FromLong(name.parts_of_speech[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDict_SetItemString(nameDict, "words", wordList);
|
||||||
|
PyDict_SetItemString(nameDict, "parts_of_speech", speechList);
|
||||||
|
|
||||||
|
Py_DECREF(wordList);
|
||||||
|
Py_DECREF(speechList);
|
||||||
|
|
||||||
|
return nameDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildSettlement(DFHack::t_settlement& settlement)
|
||||||
|
{
|
||||||
|
PyObject* setDict;
|
||||||
|
PyObject *local_pos1, *local_pos2;
|
||||||
|
PyObject* temp;
|
||||||
|
|
||||||
|
setDict = PyDict_New();
|
||||||
|
|
||||||
|
temp = PyInt_FromLong(settlement.origin);
|
||||||
|
|
||||||
|
PyDict_SetItemString(setDict, "origin", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = BuildName(settlement.name);
|
||||||
|
|
||||||
|
PyDict_SetItemString(setDict, "name", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = Py_BuildValue("ii", settlement.world_x, settlement.world_y);
|
||||||
|
|
||||||
|
PyDict_SetItemString(setDict, "world_pos", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
local_pos1 = Py_BuildValue("ii", settlement.local_x1, settlement.local_y1);
|
||||||
|
local_pos2 = Py_BuildValue("ii", settlement.local_x2, settlement.local_y2);
|
||||||
|
|
||||||
|
PyDict_SetItemString(setDict, "local_pos", Py_BuildValue("OO", local_pos1, local_pos2));
|
||||||
|
|
||||||
|
Py_DECREF(local_pos1);
|
||||||
|
Py_DECREF(local_pos2);
|
||||||
|
|
||||||
|
return setDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFIMPORTS__
|
||||||
|
#define __DFIMPORTS__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
|
||||||
|
static PyObject* TypesModule = NULL;
|
||||||
|
static PyObject* CreatureFlags1_type = NULL;
|
||||||
|
static PyObject* CreatureFlags2_type = NULL;
|
||||||
|
static PyObject* DesignationFlags_type = NULL;
|
||||||
|
static PyObject* OccupancyFlags_type = NULL;
|
||||||
|
static PyObject* ItemFlags_type = NULL;
|
||||||
|
|
||||||
|
static void DoImports()
|
||||||
|
{
|
||||||
|
if(TypesModule == NULL)
|
||||||
|
{
|
||||||
|
TypesModule = PyImport_ImportModule("pydftypes");
|
||||||
|
|
||||||
|
CreatureFlags1_type = PyObject_GetAttrString(TypesModule, "CreatureFlags1");
|
||||||
|
CreatureFlags2_type = PyObject_GetAttrString(TypesModule, "CreatureFlags2");
|
||||||
|
DesignationFlags_type = PyObject_GetAttrString(TypesModule, "DesignationFlags");
|
||||||
|
OccupancyFlags_type = PyObject_GetAttrString(TypesModule, "OccupancyFlags");
|
||||||
|
ItemFlags_type = PyObject_GetAttrString(TypesModule, "ItemFlags");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,312 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFMATERIAL__
|
||||||
|
#define __DFMATERIAL__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include "modules/Materials.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct DF_Material
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
DFHack::Materials* mat_Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
|
||||||
|
static PyObject* BuildMatgloss(t_matgloss& matgloss)
|
||||||
|
{
|
||||||
|
PyObject* matDict;
|
||||||
|
PyObject* temp;
|
||||||
|
|
||||||
|
matDict = PyDict_New();
|
||||||
|
|
||||||
|
if(matgloss.id[0])
|
||||||
|
temp = PyString_FromString(matgloss.id);
|
||||||
|
else
|
||||||
|
temp = PyString_FromString("");
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "id", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = PyInt_FromLong(matgloss.fore);
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "fore", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = PyInt_FromLong(matgloss.back);
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "back", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
temp = PyInt_FromLong(matgloss.bright);
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "bright", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
if(matgloss.name[0])
|
||||||
|
temp = PyString_FromString(matgloss.name);
|
||||||
|
else
|
||||||
|
temp = PyString_FromString("");
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "name", temp);
|
||||||
|
|
||||||
|
Py_DECREF(temp);
|
||||||
|
|
||||||
|
return matDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildMatglossPlant(t_matglossPlant& matgloss)
|
||||||
|
{
|
||||||
|
PyObject* matDict;
|
||||||
|
|
||||||
|
matDict = PyDict_New();
|
||||||
|
|
||||||
|
if(matgloss.id[0])
|
||||||
|
PyDict_SetItemString(matDict, "id", PyString_FromString(matgloss.id));
|
||||||
|
else
|
||||||
|
PyDict_SetItemString(matDict, "id", PyString_FromString(""));
|
||||||
|
|
||||||
|
PyDict_SetItemString(matDict, "fore", PyInt_FromLong(matgloss.fore));
|
||||||
|
PyDict_SetItemString(matDict, "back", PyInt_FromLong(matgloss.back));
|
||||||
|
PyDict_SetItemString(matDict, "bright", PyInt_FromLong(matgloss.bright));
|
||||||
|
|
||||||
|
if(matgloss.name[0])
|
||||||
|
PyDict_SetItemString(matDict, "name", PyString_FromString(matgloss.name));
|
||||||
|
else
|
||||||
|
PyDict_SetItemString(matDict, "name", PyString_FromString(""));
|
||||||
|
|
||||||
|
if(matgloss.drink_name[0])
|
||||||
|
PyDict_SetItemString(matDict, "drink_name", PyString_FromString(matgloss.drink_name));
|
||||||
|
else
|
||||||
|
PyDict_SetItemString(matDict, "drink_name", PyString_FromString(""));
|
||||||
|
|
||||||
|
if(matgloss.food_name[0])
|
||||||
|
PyDict_SetItemString(matDict, "food_name", PyString_FromString(matgloss.food_name));
|
||||||
|
else
|
||||||
|
PyDict_SetItemString(matDict, "food_name", PyString_FromString(""));
|
||||||
|
|
||||||
|
if(matgloss.extract_name[0])
|
||||||
|
PyDict_SetItemString(matDict, "extract_name", PyString_FromString(matgloss.extract_name));
|
||||||
|
else
|
||||||
|
PyDict_SetItemString(matDict, "extract_name", PyString_FromString(""));
|
||||||
|
|
||||||
|
return matDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* BuildMatglossList(std::vector<t_matgloss> & matVec)
|
||||||
|
{
|
||||||
|
PyObject* matList;
|
||||||
|
std::vector<t_matgloss>::iterator matIter;
|
||||||
|
|
||||||
|
matList = PyList_New(0);
|
||||||
|
|
||||||
|
for(matIter = matVec.begin(); matIter != matVec.end(); matIter++)
|
||||||
|
{
|
||||||
|
PyObject* matgloss = BuildMatgloss(*matIter);
|
||||||
|
|
||||||
|
PyList_Append(matList, matgloss);
|
||||||
|
|
||||||
|
Py_DECREF(matgloss);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// API type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_Material_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_Material* self;
|
||||||
|
|
||||||
|
self = (DF_Material*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
self->mat_Ptr = NULL;
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DF_Material_init(DF_Material* self, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_Material_dealloc(DF_Material* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
delete self->mat_Ptr;
|
||||||
|
|
||||||
|
self->mat_Ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type methods
|
||||||
|
|
||||||
|
static PyObject* DF_Material_ReadInorganicMaterials(DF_Material* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
std::vector<DFHack::t_matgloss> matVec;
|
||||||
|
|
||||||
|
if(self->mat_Ptr->ReadInorganicMaterials(matVec))
|
||||||
|
{
|
||||||
|
return BuildMatglossList(matVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Material_ReadOrganicMaterials(DF_Material* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
std::vector<DFHack::t_matgloss> matVec;
|
||||||
|
|
||||||
|
if(self->mat_Ptr->ReadOrganicMaterials(matVec))
|
||||||
|
{
|
||||||
|
return BuildMatglossList(matVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Material_ReadWoodMaterials(DF_Material* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
std::vector<DFHack::t_matgloss> matVec;
|
||||||
|
|
||||||
|
if(self->mat_Ptr->ReadWoodMaterials(matVec))
|
||||||
|
{
|
||||||
|
return BuildMatglossList(matVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Material_ReadPlantMaterials(DF_Material* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
std::vector<DFHack::t_matgloss> matVec;
|
||||||
|
|
||||||
|
if(self->mat_Ptr->ReadPlantMaterials(matVec))
|
||||||
|
{
|
||||||
|
return BuildMatglossList(matVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Material_ReadCreatureTypes(DF_Material* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->mat_Ptr != NULL)
|
||||||
|
{
|
||||||
|
std::vector<DFHack::t_matgloss> matVec;
|
||||||
|
|
||||||
|
if(self->mat_Ptr->ReadCreatureTypes(matVec))
|
||||||
|
{
|
||||||
|
return BuildMatglossList(matVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef DF_Material_methods[] =
|
||||||
|
{
|
||||||
|
{"Read_Inorganic_Materials", (PyCFunction)DF_Material_ReadInorganicMaterials, METH_NOARGS, ""},
|
||||||
|
{"Read_Organic_Materials", (PyCFunction)DF_Material_ReadOrganicMaterials, METH_NOARGS, ""},
|
||||||
|
{"Read_Wood_Materials", (PyCFunction)DF_Material_ReadWoodMaterials, METH_NOARGS, ""},
|
||||||
|
{"Read_Plant_Materials", (PyCFunction)DF_Material_ReadPlantMaterials, METH_NOARGS, ""},
|
||||||
|
{"Read_Creature_Types", (PyCFunction)DF_Material_ReadCreatureTypes, METH_NOARGS, ""},
|
||||||
|
{NULL} //Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyTypeObject DF_Material_type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"pydfhack.Material", /*tp_name*/
|
||||||
|
sizeof(DF_Material), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
(destructor)DF_Material_dealloc, /*tp_dealloc*/
|
||||||
|
0, /*tp_print*/
|
||||||
|
0, /*tp_getattr*/
|
||||||
|
0, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
0, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
0, /*tp_as_sequence*/
|
||||||
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
|
0, /*tp_call*/
|
||||||
|
0, /*tp_str*/
|
||||||
|
0, /*tp_getattro*/
|
||||||
|
0, /*tp_setattro*/
|
||||||
|
0, /*tp_as_buffer*/
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
|
"pydfhack Material objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
DF_Material_methods, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
0, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
(initproc)DF_Material_init, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
DF_Material_new, /* tp_new */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,674 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DF_MEMINFO__
|
||||||
|
#define __DF_MEMINFO__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include "Export.h"
|
||||||
|
#include "DFCommonInternal.h"
|
||||||
|
#include "DFMemInfo.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct DF_MemInfo
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
DFHack::memory_info* mem_Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
// MemInfo type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_MemInfo* self;
|
||||||
|
|
||||||
|
self = (DF_MemInfo*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
self->mem_Ptr = NULL;
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DF_MemInfo_init(DF_MemInfo* self, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_MemInfo_dealloc(DF_MemInfo* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
delete self->mem_Ptr;
|
||||||
|
|
||||||
|
self->mem_Ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setters/Getters
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_getBase(DF_MemInfo* self)
|
||||||
|
{
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
return PyInt_FromLong(self->mem_Ptr->getBase());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_setBase(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
PyObject* arg = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "O", arg))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Bad argument list");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PyString_Check(arg))
|
||||||
|
self->mem_Ptr->setBase(std::string(PyString_AsString(arg)));
|
||||||
|
else if(PyInt_Check(arg))
|
||||||
|
self->mem_Ptr->setBase((uint32_t)PyInt_AsUnsignedLongMask(arg));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Argument must be string or integer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_getVersion(DF_MemInfo* self)
|
||||||
|
{
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
return PyString_FromString(self->mem_Ptr->getVersion().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_setVersion(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* v = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &v))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setVersion(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyGetSetDef DF_MemInfo_getterSetters[] =
|
||||||
|
{
|
||||||
|
{"base", (getter)DF_MemInfo_getBase, (setter)DF_MemInfo_setBase, "base", NULL},
|
||||||
|
{"version", (getter)DF_MemInfo_getVersion, (setter)DF_MemInfo_setVersion, "version", NULL},
|
||||||
|
{NULL} // Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
// Member methods
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetOffset(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyInt_FromLong(self->mem_Ptr->getOffset(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetOffset(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
// const char* s = NULL;
|
||||||
|
// const char* n = NULL;
|
||||||
|
// int32_t i;
|
||||||
|
// PyObject* obj;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr != NULL)
|
||||||
|
// {
|
||||||
|
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||||
|
// return NULL;
|
||||||
|
|
||||||
|
// if(PyString_Check(obj))
|
||||||
|
// {
|
||||||
|
// n = PyString_AsString(obj);
|
||||||
|
// self->mem_Ptr->setOffset(s, n);
|
||||||
|
// }
|
||||||
|
// else if(PyInt_Check(obj))
|
||||||
|
// {
|
||||||
|
// i = (int32_t)PyInt_AsLong(obj);
|
||||||
|
// self->mem_Ptr->setOffset(s, i);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetAddress(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyInt_FromLong(self->mem_Ptr->getAddress(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetAddress(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
// const char* s = NULL;
|
||||||
|
// const char* n = NULL;
|
||||||
|
// int32_t i;
|
||||||
|
// PyObject* obj;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr != NULL)
|
||||||
|
// {
|
||||||
|
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||||
|
// return NULL;
|
||||||
|
|
||||||
|
// if(PyString_Check(obj))
|
||||||
|
// {
|
||||||
|
// n = PyString_AsString(obj);
|
||||||
|
// self->mem_Ptr->setAddress(s, n);
|
||||||
|
// }
|
||||||
|
// else if(PyInt_Check(obj))
|
||||||
|
// {
|
||||||
|
// i = (int32_t)PyInt_AsLong(obj);
|
||||||
|
// self->mem_Ptr->setAddress(s, i);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetHexValue(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyInt_FromLong(self->mem_Ptr->getHexValue(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetHexValue(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
// const char* s = NULL;
|
||||||
|
// const char* n = NULL;
|
||||||
|
// int32_t i;
|
||||||
|
// PyObject* obj;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr != NULL)
|
||||||
|
// {
|
||||||
|
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||||
|
// return NULL;
|
||||||
|
|
||||||
|
// if(PyString_Check(obj))
|
||||||
|
// {
|
||||||
|
// n = PyString_AsString(obj);
|
||||||
|
// self->mem_Ptr->setHexValue(s, n);
|
||||||
|
// }
|
||||||
|
// else if(PyInt_Check(obj))
|
||||||
|
// {
|
||||||
|
// i = (int32_t)PyInt_AsLong(obj);
|
||||||
|
// self->mem_Ptr->setHexValue(s, i);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetString(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getString(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetString(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
// const char* s = NULL;
|
||||||
|
// const char* n = NULL;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr != NULL)
|
||||||
|
// {
|
||||||
|
// if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||||
|
// return NULL;
|
||||||
|
|
||||||
|
// self->mem_Ptr->setString(s, n);
|
||||||
|
// }
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetProfession(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getProfession(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetProfession(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
const char* n = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setProfession(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetJob(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getJob(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetJob(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
const char* n = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setJob(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetSkill(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getSkill(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetSkill(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
const char* n = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setSkill(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetTrait(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s, n;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "II", &s, &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getTrait(s, n).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// I have no idea what any of the strings are, so I can't really put meaningful names - doomchild
|
||||||
|
static PyObject* DF_MemInfo_SetTrait(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* a = NULL;
|
||||||
|
const char* b = NULL;
|
||||||
|
const char* c = NULL;
|
||||||
|
const char* d = NULL;
|
||||||
|
const char* e = NULL;
|
||||||
|
const char* f = NULL;
|
||||||
|
const char* g = NULL;
|
||||||
|
const char* h = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "ssssssss", &a, &b, &c, &d, &e, &f, &g, &h))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setTrait(a, b, c, d, e, f, g, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetTraitName(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getTraitName(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_GetLabor(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t s;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "i", &s))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PyString_FromString(self->mem_Ptr->getLabor(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_SetLabor(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* s = NULL;
|
||||||
|
const char* n = NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->setLabor(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_RebaseAddresses(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t base;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "i", &base))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->RebaseAddresses(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_RebaseAll(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t base;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "i", &base))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->RebaseAll(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_RebaseVTable(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t offset;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "i", &offset))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
self->mem_Ptr->RebaseVTable(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_ResolveObjectToClassID(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
uint32_t address;
|
||||||
|
int32_t classID;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "I", &address))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr->resolveObjectToClassID(address, classID))
|
||||||
|
return PyInt_FromLong(classID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_ResolveClassNameToClassID(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
// const char* name;
|
||||||
|
// int32_t classID;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr != NULL)
|
||||||
|
// {
|
||||||
|
// if(!PyArg_ParseTuple(args, "s", &name))
|
||||||
|
// return NULL;
|
||||||
|
|
||||||
|
// if(self->mem_Ptr->resolveClassnameToClassID(name, classID))
|
||||||
|
// return PyInt_FromLong(classID);
|
||||||
|
// }
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_ResolveClassNameToVPtr(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
const char* n;
|
||||||
|
uint32_t vPtr;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &n))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
std::string name(n);
|
||||||
|
|
||||||
|
if(self->mem_Ptr->resolveClassnameToVPtr(name, vPtr))
|
||||||
|
return PyInt_FromLong(vPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_MemInfo_ResolveClassIDToClassName(DF_MemInfo* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t id;
|
||||||
|
string name;
|
||||||
|
|
||||||
|
if(self->mem_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "i", &id))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->mem_Ptr->resolveClassIDToClassname(id, name))
|
||||||
|
return PyString_FromString(name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef DF_MemInfo_methods[] =
|
||||||
|
{
|
||||||
|
{"Rebase_Addresses", (PyCFunction)DF_MemInfo_RebaseAddresses, METH_VARARGS, ""},
|
||||||
|
{"Rebase_All", (PyCFunction)DF_MemInfo_RebaseAll, METH_VARARGS, ""},
|
||||||
|
{"Rebase_VTable", (PyCFunction)DF_MemInfo_RebaseVTable, METH_VARARGS, ""},
|
||||||
|
{"Get_Offset", (PyCFunction)DF_MemInfo_GetOffset, METH_VARARGS, ""},
|
||||||
|
{"Set_Offset", (PyCFunction)DF_MemInfo_SetOffset, METH_VARARGS, ""},
|
||||||
|
{"Get_Address", (PyCFunction)DF_MemInfo_GetAddress, METH_VARARGS, ""},
|
||||||
|
{"Set_Address", (PyCFunction)DF_MemInfo_SetAddress, METH_VARARGS, ""},
|
||||||
|
{"Get_HexValue", (PyCFunction)DF_MemInfo_GetHexValue, METH_VARARGS, ""},
|
||||||
|
{"Set_HexValue", (PyCFunction)DF_MemInfo_SetHexValue, METH_VARARGS, ""},
|
||||||
|
{"Get_String", (PyCFunction)DF_MemInfo_GetString, METH_VARARGS, ""},
|
||||||
|
{"Set_String", (PyCFunction)DF_MemInfo_SetString, METH_VARARGS, ""},
|
||||||
|
{"Get_Profession", (PyCFunction)DF_MemInfo_GetProfession, METH_VARARGS, ""},
|
||||||
|
{"Set_Profession", (PyCFunction)DF_MemInfo_SetProfession, METH_VARARGS, ""},
|
||||||
|
{"Get_Job", (PyCFunction)DF_MemInfo_GetJob, METH_VARARGS, ""},
|
||||||
|
{"Set_Job", (PyCFunction)DF_MemInfo_SetJob, METH_VARARGS, ""},
|
||||||
|
{"Get_Skill", (PyCFunction)DF_MemInfo_GetSkill, METH_VARARGS, ""},
|
||||||
|
{"Set_Skill", (PyCFunction)DF_MemInfo_SetSkill, METH_VARARGS, ""},
|
||||||
|
{"Get_Trait", (PyCFunction)DF_MemInfo_GetTrait, METH_VARARGS, ""},
|
||||||
|
{"Set_Trait", (PyCFunction)DF_MemInfo_SetTrait, METH_VARARGS, ""},
|
||||||
|
{"Get_Trait_Name", (PyCFunction)DF_MemInfo_GetTraitName, METH_VARARGS, ""},
|
||||||
|
{"Get_Labor", (PyCFunction)DF_MemInfo_GetLabor, METH_VARARGS, ""},
|
||||||
|
{"Set_Labor", (PyCFunction)DF_MemInfo_SetLabor, METH_VARARGS, ""},
|
||||||
|
{"Resolve_Object_To_Class_ID", (PyCFunction)DF_MemInfo_ResolveObjectToClassID, METH_VARARGS, ""},
|
||||||
|
{"Resolve_Classname_To_Class_ID", (PyCFunction)DF_MemInfo_ResolveClassNameToClassID, METH_VARARGS, ""},
|
||||||
|
{"Resolve_Classname_To_VPtr", (PyCFunction)DF_MemInfo_ResolveClassNameToVPtr, METH_VARARGS, ""},
|
||||||
|
{"Resolve_Class_ID_To_Classname", (PyCFunction)DF_MemInfo_ResolveClassIDToClassName, METH_VARARGS, ""},
|
||||||
|
{NULL} //Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyTypeObject DF_MemInfo_type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"pydfhack.DF_MemInfo", /*tp_name*/
|
||||||
|
sizeof(DF_MemInfo), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
(destructor)DF_MemInfo_dealloc, /*tp_dealloc*/
|
||||||
|
0, /*tp_print*/
|
||||||
|
0, /*tp_getattr*/
|
||||||
|
0, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
0, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
0, /*tp_as_sequence*/
|
||||||
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
|
0, /*tp_call*/
|
||||||
|
0, /*tp_str*/
|
||||||
|
0, /*tp_getattro*/
|
||||||
|
0, /*tp_setattro*/
|
||||||
|
0, /*tp_as_buffer*/
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
|
"pydfhack DF_MemInfo objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
DF_MemInfo_methods, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
DF_MemInfo_getterSetters, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
(initproc)DF_MemInfo_init, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
DF_MemInfo_new, /* tp_new */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFPOSITION__
|
||||||
|
#define __DFPOSITION__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "modules/Position.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct DF_Position
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
DFHack::Position* pos_Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
// API type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_Position_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_Position* self;
|
||||||
|
|
||||||
|
self = (DF_Position*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
self->pos_Ptr = NULL;
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DF_Position_init(DF_Position* self, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_Position_dealloc(DF_Position* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
delete self->pos_Ptr;
|
||||||
|
|
||||||
|
self->pos_Ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters/Setters
|
||||||
|
|
||||||
|
static PyObject* DF_Position_getViewCoords(DF_Position* self, void* closure)
|
||||||
|
{
|
||||||
|
int32_t x, y, z;
|
||||||
|
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->pos_Ptr->getViewCoords(x, y, z))
|
||||||
|
return Py_BuildValue("iii", x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Position_setViewCoords(DF_Position* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t x, y, z;
|
||||||
|
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "iii", &x, &y, &z))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->pos_Ptr->setViewCoords(x, y, z))
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Position_getCursorCoords(DF_Position* self, void* closure)
|
||||||
|
{
|
||||||
|
int32_t x, y, z;
|
||||||
|
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->pos_Ptr->getCursorCoords(x, y, z))
|
||||||
|
return Py_BuildValue("iii", x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Position_setCursorCoords(DF_Position* self, PyObject* args)
|
||||||
|
{
|
||||||
|
int32_t x, y, z;
|
||||||
|
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(!PyArg_ParseTuple(args, "iii", &x, &y, &z))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if(self->pos_Ptr->setCursorCoords(x, y, z))
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Position_getWindowSize(DF_Position* self, void* closure)
|
||||||
|
{
|
||||||
|
int32_t x, y;
|
||||||
|
|
||||||
|
if(self->pos_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->pos_Ptr->getWindowSize(x, y))
|
||||||
|
return Py_BuildValue("ii", x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyGetSetDef DF_Position_getterSetters[] =
|
||||||
|
{
|
||||||
|
{"view_coords", (getter)DF_Position_getViewCoords, (setter)DF_Position_setViewCoords, "view_coords", NULL},
|
||||||
|
{"cursor_coords", (getter)DF_Position_getCursorCoords, (setter)DF_Position_setCursorCoords, "cursor_coords", NULL},
|
||||||
|
{"window_size", (getter)DF_Position_getWindowSize, NULL, "window_size", NULL},
|
||||||
|
{NULL} // Sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyTypeObject DF_Position_type =
|
||||||
|
{
|
||||||
|
PyObject_HEAD_INIT(NULL)
|
||||||
|
0, /*ob_size*/
|
||||||
|
"pydfhack.Position", /*tp_name*/
|
||||||
|
sizeof(DF_Position), /*tp_basicsize*/
|
||||||
|
0, /*tp_itemsize*/
|
||||||
|
(destructor)DF_Position_dealloc, /*tp_dealloc*/
|
||||||
|
0, /*tp_print*/
|
||||||
|
0, /*tp_getattr*/
|
||||||
|
0, /*tp_setattr*/
|
||||||
|
0, /*tp_compare*/
|
||||||
|
0, /*tp_repr*/
|
||||||
|
0, /*tp_as_number*/
|
||||||
|
0, /*tp_as_sequence*/
|
||||||
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
|
0, /*tp_call*/
|
||||||
|
0, /*tp_str*/
|
||||||
|
0, /*tp_getattro*/
|
||||||
|
0, /*tp_setattro*/
|
||||||
|
0, /*tp_as_buffer*/
|
||||||
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
|
"pydfhack Position objects", /* tp_doc */
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
0, /* tp_methods */
|
||||||
|
0, /* tp_members */
|
||||||
|
DF_Position_getterSetters, /* tp_getset */
|
||||||
|
0, /* tp_base */
|
||||||
|
0, /* tp_dict */
|
||||||
|
0, /* tp_descr_get */
|
||||||
|
0, /* tp_descr_set */
|
||||||
|
0, /* tp_dictoffset */
|
||||||
|
(initproc)DF_Position_init, /* tp_init */
|
||||||
|
0, /* tp_alloc */
|
||||||
|
DF_Position_new, /* tp_new */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DFTRANSLATION__
|
||||||
|
#define __DFTRANSLATION__
|
||||||
|
|
||||||
|
#include "Python.h"
|
||||||
|
#include "modules/Translation.h"
|
||||||
|
|
||||||
|
using namespace
|
||||||
|
|
||||||
|
struct DF_Translation
|
||||||
|
{
|
||||||
|
PyObject_HEAD
|
||||||
|
DFHack::Translation* trans_Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
// API type Allocation, Deallocation, and Initialization
|
||||||
|
|
||||||
|
static PyObject* DF_Translation_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
DF_Translation* self;
|
||||||
|
|
||||||
|
self = (DF_Translation*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
|
if(self != NULL)
|
||||||
|
self->trans_Ptr = NULL;
|
||||||
|
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DF_Translation_init(DF_Translation* self, PyObject* args, PyObject* kwds)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DF_Translation_dealloc(DF_Translation* self)
|
||||||
|
{
|
||||||
|
if(self != NULL)
|
||||||
|
{
|
||||||
|
if(self->trans_Ptr != NULL)
|
||||||
|
{
|
||||||
|
delete self->trans_Ptr;
|
||||||
|
|
||||||
|
self->trans_Ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type methods
|
||||||
|
|
||||||
|
static PyObject* DF_Translation_Start(DF_Translation* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->trans_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->trans_Ptr->Start())
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Translation_Finish(DF_Translation* self, PyObject* args)
|
||||||
|
{
|
||||||
|
if(self->trans_Ptr != NULL)
|
||||||
|
{
|
||||||
|
if(self->trans_Ptr->Finish())
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
else
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject* DF_Translation_TranslateName(DF_Translation* self, PyObject* args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,215 +0,0 @@
|
|||||||
/*
|
|
||||||
www.sourceforge.net/projects/dfhack
|
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __UNIONBASE__
|
|
||||||
#define __UNIONBASE__
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
|
|
||||||
struct UnionBase
|
|
||||||
{
|
|
||||||
PyObject_HEAD
|
|
||||||
unsigned int whole;
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyObject* UnionBase_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
|
||||||
{
|
|
||||||
UnionBase* self;
|
|
||||||
|
|
||||||
self = (UnionBase*)type->tp_alloc(type, 0);
|
|
||||||
|
|
||||||
if(self != NULL)
|
|
||||||
self->whole = 0;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return (PyObject*)self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int UnionBase_init(UnionBase* self, PyObject* args, PyObject* kwds)
|
|
||||||
{
|
|
||||||
if(!PyArg_ParseTuple(args, "|I", &self->whole))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void UnionBase_dealloc(UnionBase* self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_GetBitMask(UnionBase* self, PyObject* args)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "I", &mask))
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
|
|
||||||
if((self->whole & mask) != 0)
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_SetBitMask(UnionBase* self, PyObject* args)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
int on;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "Ii", &mask, &on))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if(on)
|
|
||||||
self->whole |= mask;
|
|
||||||
else
|
|
||||||
self->whole &= ~mask;
|
|
||||||
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_GetSingleBit(UnionBase* self, PyObject* args)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "I", &mask))
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
|
|
||||||
if((self->whole & (1 << mask)) != 0)
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_SetSingleBit(UnionBase* self, PyObject* args)
|
|
||||||
{
|
|
||||||
unsigned int mask;
|
|
||||||
int on;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "Ii", &mask, &on))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if(on)
|
|
||||||
self->whole |= (1 << mask);
|
|
||||||
else
|
|
||||||
self->whole &= ~(1 << mask);
|
|
||||||
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_int(PyObject* self)
|
|
||||||
{
|
|
||||||
return PyInt_FromLong(((UnionBase*)self)->whole);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_long(PyObject* self)
|
|
||||||
{
|
|
||||||
return PyInt_FromLong(((UnionBase*)self)->whole);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* UnionBase_hex(PyObject* self)
|
|
||||||
{
|
|
||||||
return PyNumber_ToBase(PyInt_FromLong(((UnionBase*)self)->whole), 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef UnionBase_methods[] =
|
|
||||||
{
|
|
||||||
{"_get_mask_bit", (PyCFunction)UnionBase_GetSingleBit, METH_VARARGS, "Get mask bit"},
|
|
||||||
{"_set_mask_bit", (PyCFunction)UnionBase_SetSingleBit, METH_VARARGS, "Set mask bit"},
|
|
||||||
{"_get_mask", (PyCFunction)UnionBase_GetBitMask, METH_VARARGS, ""},
|
|
||||||
{"_set_mask", (PyCFunction)UnionBase_SetBitMask, METH_VARARGS, ""},
|
|
||||||
{NULL} //Sentinel
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyNumberMethods UnionBase_as_number[] =
|
|
||||||
{
|
|
||||||
0, // binaryfunc nb_add; /* __add__ */
|
|
||||||
0, // binaryfunc nb_subtract; /* __sub__ */
|
|
||||||
0, // binaryfunc nb_multiply; /* __mul__ */
|
|
||||||
0, // binaryfunc nb_divide; /* __div__ */
|
|
||||||
0, // binaryfunc nb_remainder; /* __mod__ */
|
|
||||||
0, // binaryfunc nb_divmod; /* __divmod__ */
|
|
||||||
0, // ternaryfunc nb_power; /* __pow__ */
|
|
||||||
0, // unaryfunc nb_negative; /* __neg__ */
|
|
||||||
0, // unaryfunc nb_positive; /* __pos__ */
|
|
||||||
0, // unaryfunc nb_absolute; /* __abs__ */
|
|
||||||
0, // inquiry nb_nonzero; /* __nonzero__ */
|
|
||||||
0, // unaryfunc nb_invert; /* __invert__ */
|
|
||||||
0, // binaryfunc nb_lshift; /* __lshift__ */
|
|
||||||
0, // binaryfunc nb_rshift; /* __rshift__ */
|
|
||||||
0, // binaryfunc nb_and; /* __and__ */
|
|
||||||
0, // binaryfunc nb_xor; /* __xor__ */
|
|
||||||
0, // binaryfunc nb_or; /* __or__ */
|
|
||||||
0, // coercion nb_coerce; /* __coerce__ */
|
|
||||||
UnionBase_int, // unaryfunc nb_int; /* __int__ */
|
|
||||||
UnionBase_long, // unaryfunc nb_long; /* __long__ */
|
|
||||||
0, // unaryfunc nb_float; /* __float__ */
|
|
||||||
0, // unaryfunc nb_oct; /* __oct__ */
|
|
||||||
UnionBase_hex, // unaryfunc nb_hex; /* __hex__ */
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyTypeObject UnionBase_type =
|
|
||||||
{
|
|
||||||
PyObject_HEAD_INIT(NULL)
|
|
||||||
0, /*ob_size*/
|
|
||||||
"pydfhack.UnionBase", /*tp_name*/
|
|
||||||
sizeof(UnionBase), /*tp_basicsize*/
|
|
||||||
0, /*tp_itemsize*/
|
|
||||||
(destructor)UnionBase_dealloc, /*tp_dealloc*/
|
|
||||||
0, /*tp_print*/
|
|
||||||
0, /*tp_getattr*/
|
|
||||||
0, /*tp_setattr*/
|
|
||||||
0, /*tp_compare*/
|
|
||||||
0, /*tp_repr*/
|
|
||||||
UnionBase_as_number, /*tp_as_number*/
|
|
||||||
0, /*tp_as_sequence*/
|
|
||||||
0, /*tp_as_mapping*/
|
|
||||||
0, /*tp_hash */
|
|
||||||
0, /*tp_call*/
|
|
||||||
0, /*tp_str*/
|
|
||||||
0, /*tp_getattro*/
|
|
||||||
0, /*tp_setattro*/
|
|
||||||
0, /*tp_as_buffer*/
|
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
|
||||||
"pydfhack UnionBase objects", /* tp_doc */
|
|
||||||
0, /* tp_traverse */
|
|
||||||
0, /* tp_clear */
|
|
||||||
0, /* tp_richcompare */
|
|
||||||
0, /* tp_weaklistoffset */
|
|
||||||
0, /* tp_iter */
|
|
||||||
0, /* tp_iternext */
|
|
||||||
UnionBase_methods, /* tp_methods */
|
|
||||||
0, /* tp_members */
|
|
||||||
0, /* tp_getset */
|
|
||||||
0, /* tp_base */
|
|
||||||
0, /* tp_dict */
|
|
||||||
0, /* tp_descr_get */
|
|
||||||
0, /* tp_descr_set */
|
|
||||||
0, /* tp_dictoffset */
|
|
||||||
(initproc)UnionBase_init, /* tp_init */
|
|
||||||
0, /* tp_alloc */
|
|
||||||
UnionBase_new, /* tp_new */
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
www.sourceforge.net/projects/dfhack
|
|
||||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MATGLOSS__
|
|
||||||
#define __MATGLOSS__
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "DFTypes.h"
|
|
||||||
|
|
||||||
using namespace DFHack;
|
|
||||||
|
|
||||||
// MatGloss
|
|
||||||
|
|
||||||
struct MatGloss
|
|
||||||
{
|
|
||||||
PyObject_HEAD
|
|
||||||
DFHack::t_matgloss native;
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyObject* MatGloss_new(PyTypeObject* type, PyObject* arg, PyObject* kwds)
|
|
||||||
{
|
|
||||||
MatGloss* self;
|
|
||||||
|
|
||||||
self = (MatGloss*)type->tp_alloc(type, 0);
|
|
||||||
|
|
||||||
self->native->id[0] = '\0';
|
|
||||||
self->native->name[0] = '\0';
|
|
||||||
|
|
||||||
return (PyObject*)self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MatGloss_dealloc(MatGloss* self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGloss_GetID(MatGloss* self, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int MatGloss_SetID(MatGloss* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->id, temp, 127);
|
|
||||||
self->native->id[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGloss_GetName(MatGloss* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGloss_SetName(MatGloss* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->name, temp, 127);
|
|
||||||
self->native->name[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyGetSetDef MatGloss_getSetters[] =
|
|
||||||
{
|
|
||||||
{"id", (getter)MatGloss_GetID, (setter)MatGloss_SetID, "id", NULL},
|
|
||||||
{"name", (getter)MatGloss_GetName, (setter)MatGloss_SetName, "name", NULL},
|
|
||||||
{NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
// MatGlossPlant
|
|
||||||
|
|
||||||
struct MatGlossPlant
|
|
||||||
{
|
|
||||||
PyObject_HEAD
|
|
||||||
DFHack::t_matglossPlant native;
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_new(PyTypeObject* type, PyObject* arg, PyObject* kwds)
|
|
||||||
{
|
|
||||||
MatGlossPlant* self;
|
|
||||||
|
|
||||||
self = (MatGlossPlant*)type->tp_alloc(type, 0);
|
|
||||||
|
|
||||||
self->native->id[0] = '\0';
|
|
||||||
self->native->name[0] = '\0';
|
|
||||||
self->native->drink_name[127] = '\0';
|
|
||||||
self->native->food_name[127] = '\0';
|
|
||||||
self->native->extract_name[127] = '\0';
|
|
||||||
|
|
||||||
return (PyObject*)self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MatGlossPlant_dealloc(MatGlossPlant* self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_GetID(MatGlossPlant* self, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int MatGlossPlant_SetID(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->id, temp, 127);
|
|
||||||
self->native->id[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_GetName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_SetName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->name, temp, 127);
|
|
||||||
self->native->name[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_GetDrinkName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->drink_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_SetDrinkName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->drink_name, temp, 127);
|
|
||||||
self->native->drink_name[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_GetFoodName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->food_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_SetFoodName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->food_name, temp, 127);
|
|
||||||
self->native->food_name[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_GetExtractName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
return PyString_FromString(self->native->extract_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject* MatGlossPlant_SetExtractName(MatGlossPlant* self, PyObject* args, void* closure)
|
|
||||||
{
|
|
||||||
char* temp;
|
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strncpy(self->native->extract_name, temp, 127);
|
|
||||||
self->native->extract_name[127] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyGetSetDef MatGlossPlant_getSetters[] =
|
|
||||||
{
|
|
||||||
{"id", (getter)MatGlossPlant_GetID, (setter)MatGlossPlant_SetID, "id", NULL},
|
|
||||||
{"name", (getter)MatGlossPlant_GetName, (setter)MatGlossPlant_SetName, "name", NULL},
|
|
||||||
{"drink_name", (getter)MatGlossPlant_GetDrinkName, (setter)MatGlossPlant_SetDrinkName, "drink_name", NULL},
|
|
||||||
{"food_name", (getter)MatGlossPlant_GetFoodName, (setter)MatGlossPlant_SetFoodName, "food_name", NULL},
|
|
||||||
{"extract_name", (getter)MatGlossPlant_GetExtractName, (setter)MatGlossPlant_SetExtractName, "extract_name", NULL},
|
|
||||||
{NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue