updated for upstream additions

develop
doomchild 2010-04-20 15:34:10 -05:00
parent 20b752f68f
commit 16d5175ee5
4 changed files with 263 additions and 45 deletions

@ -38,22 +38,40 @@ static PyObject* BuildBuilding(DFHack::t_building& building)
t_dict = PyDict_New();
temp = PyInt_FromLong(building.origin);
DICTADD(t_dict, "origin", temp);
temp = Py_BuildValue("(si)(si)(si)(sO)(s((ii)(ii)i))", \
"origin", building.origin, \
"vtable", building.vtable, \
"type", building.type, \
"material", BuildMatglossPair(building.material), \
"bounds", Py_BuildValue("(ii)(ii)i", building.x1, building.y1, building.x2, building.y2, building.z));
temp = PyInt_FromLong(building.vtable);
DICTADD(t_dict, "vtable", temp);
PyDict_MergeFromSeq2(t_dict, temp, 0);
temp = PyInt_FromLong(building.type);
DICTADD(t_dict, "type", temp);
return t_dict;
}
static DFHack::t_building ReverseBuildBuilding(PyObject* bDict)
{
PyObject* temp;
uint32_t x1, y1, x2, y2, z;
DFHack::t_building building;
temp = BuildMatglossPair(building.material);
DICTADD(t_dict, "material", temp);
building.origin = (uint32_t)PyInt_AsLong(PyDict_GetItemString(bDict, "origin"));
building.vtable = (uint32_t)PyInt_AsLong(PyDict_GetItemString(bDict, "vtable"));
building.material = ReverseBuildMatglossPair(PyDict_GetItemString(bDict, "material"));
building.type = (uint32_t)PyInt_AsLong(PyDict_GetItemString(bDict, "type"));
temp = PyTuple_Pack(2, PyTuple_Pack(2, building.x1, building.y1), PyTuple_Pack(2, building.x2, building.y2));
DICTADD(t_dict, "bounds", temp);
temp = PyDict_GetItemString(bDict, "bounds");
return t_dict;
PyArg_ParseTuple(temp, "(ii)(ii)i", &x1, &y1, &x2, &y2, &z);
building.x1 = x1;
building.y1 = y1;
building.x2 = x2;
building.y2 = y2;
building.z = z;
return building;
}
struct DF_Building
@ -151,11 +169,53 @@ static PyObject* DF_Building_Read(DF_Building* self, PyObject* args)
Py_RETURN_NONE;
}
static PyObject* DF_Building_ReadCustomWorkshopTypes(DF_Building* self, PyObject* args)
{
PyObject* bDict;
std::map<uint32_t, string> bTypes;
std::map<uint32_t, string>::iterator bIter;
if(self->b_Ptr != NULL)
{
if(self->b_Ptr->ReadCustomWorkshopTypes(bTypes))
{
bDict = PyDict_New();
for(bIter = bTypes.begin(); bIter != bTypes.end(); bIter++)
{
PyObject* temp = Py_BuildValue("is", (*bIter).first, (*bIter).second);
PyDict_MergeFromSeq2(bDict, temp, 1);
}
return bDict;
}
}
Py_RETURN_NONE;
}
static PyObject* DF_Building_GetCustomWorkshopType(DF_Building* self, PyObject* args)
{
DFHack::t_building building;
if(self->b_Ptr != NULL)
{
building = ReverseBuildBuilding(args);
return PyInt_FromLong(self->b_Ptr->GetCustomWorkshopType(building));
}
Py_RETURN_NONE;
}
static PyMethodDef DF_Building_methods[] =
{
{"Start", (PyCFunction)DF_Building_Start, METH_NOARGS, ""},
{"Finish", (PyCFunction)DF_Building_Finish, METH_NOARGS, ""},
{"Read", (PyCFunction)DF_Building_Read, METH_VARARGS, ""},
{"Read_Custom_Workshop_Types", (PyCFunction)DF_Building_ReadCustomWorkshopTypes, METH_NOARGS, ""},
{"Get_Custom_Workshop_Type", (PyCFunction)DF_Building_GetCustomWorkshopType, METH_VARARGS, ""},
{NULL} // Sentinel
};

@ -155,12 +155,34 @@ static PyObject* DF_CreatureManager_ReadCreatureInBox(DF_CreatureManager* self,
Py_RETURN_NONE;
}
static PyObject* DF_CreatureManager_GetDwarfRaceIndex(DF_CreatureManager* self, PyObject* args)
{
if(self->creature_Ptr != NULL)
{
return PyInt_FromLong(self->creature_Ptr->GetDwarfRaceIndex());
}
Py_RETURN_NONE;
}
static PyObject* DF_CreatureManager_GetDwarfCivId(DF_CreatureManager* self, PyObject* args)
{
if(self->creature_Ptr != NULL)
{
return PyInt_FromLong(self->creature_Ptr->GetDwarfCivId());
}
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, ""},
{"Get_Dwarf_Race_Index", (PyCFunction)DF_CreatureManager_GetDwarfRaceIndex, METH_NOARGS, ""},
{"Get_Dwarf_Civ_id", (PyCFunction)DF_CreatureManager_GetDwarfCivId, METH_NOARGS, ""},
{NULL} // Sentinel
};

@ -43,6 +43,16 @@ static PyObject* BuildMatglossPair(DFHack::t_matglossPair& matgloss)
return Py_BuildValue("ii", matgloss.type, matgloss.index);
}
static DFHack::t_matglossPair ReverseBuildMatglossPair(PyObject* mObj)
{
DFHack::t_matglossPair mPair;
mPair.type = (int16_t)PyInt_AsLong(PyTuple_GetItem(mObj, 0));
mPair.index = (int32_t)PyInt_AsLong(PyTuple_GetItem(mObj, 1));
return mPair;
}
static PyObject* BuildSkill(DFHack::t_skill& skill)
{
return Py_BuildValue("III", skill.id, skill.experience, skill.rating);

@ -45,45 +45,20 @@ struct DF_Material
static PyObject* BuildMatgloss(t_matgloss& matgloss)
{
PyObject* matDict;
PyObject* temp;
PyObject* list;
matDict = PyDict_New();
list = PyList_New(5);
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);
PyList_SET_ITEM(list, 0, Py_BuildValue("ss", "id", matgloss.id));
PyList_SET_ITEM(list, 1, Py_BuildValue("si", "fore", matgloss.fore));
PyList_SET_ITEM(list, 2, Py_BuildValue("si", "back", matgloss.back));
PyList_SET_ITEM(list, 3, Py_BuildValue("si", "bright", matgloss.bright));
PyList_SET_ITEM(list, 4, Py_BuildValue("ss", "name", matgloss.name));
temp = PyInt_FromLong(matgloss.back);
PyDict_MergeFromSeq2(matDict, list, 0);
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);
Py_DECREF(list);
return matDict;
}
@ -145,6 +120,125 @@ static PyObject* BuildMatglossList(std::vector<t_matgloss> & matVec)
return matList;
}
static PyObject* BuildDescriptorColor(t_descriptor_color& color)
{
PyObject* matDict;
PyObject* list;
matDict = PyDict_New();
list = PyList_New(5);
PyList_SET_ITEM(list, 0, Py_BuildValue("ss", "id", color.id));
PyList_SET_ITEM(list, 1, Py_BuildValue("sf", "r", color.r));
PyList_SET_ITEM(list, 2, Py_BuildValue("sf", "v", color.v));
PyList_SET_ITEM(list, 3, Py_BuildValue("sf", "b", color.b));
PyList_SET_ITEM(list, 4, Py_BuildValue("ss", "name", color.name));
PyDict_MergeFromSeq2(matDict, list, 0);
Py_DECREF(list);
return matDict;
}
static PyObject* BuildDescriptorColorList(std::vector<t_descriptor_color>& colors)
{
PyObject* colorList;
std::vector<t_descriptor_color>::iterator colorIter;
colorList = PyList_New(0);
for(colorIter = colors.begin(); colorIter != colors.end(); colorIter++)
{
PyObject* color = BuildDescriptorColor(*colorIter);
PyList_Append(colorList, color);
Py_DECREF(colorList);
}
return colorList;
}
static PyObject* BuildCreatureCaste(t_creaturecaste& caste)
{
PyObject* matDict;
PyObject* list;
matDict = PyDict_New();
list = PyList_New(4);
PyList_SET_ITEM(list, 0, Py_BuildValue("ss", "rawname", caste.rawname));
PyList_SET_ITEM(list, 1, Py_BuildValue("ss", "singular", caste.singular));
PyList_SET_ITEM(list, 2, Py_BuildValue("ss", "plural", caste.plural));
PyList_SET_ITEM(list, 3, Py_BuildValue("ss", "adjective", caste.adjective));
PyDict_MergeFromSeq2(matDict, list, 0);
Py_DECREF(list);
return matDict;
}
static PyObject* BuildCreatureCasteList(std::vector<t_creaturecaste>& castes)
{
PyObject* casteList;
std::vector<t_creaturecaste>::iterator casteIter;
casteList = PyList_New(0);
for(casteIter = castes.begin(); casteIter != castes.end(); casteIter++)
{
PyObject* caste = BuildCreatureCaste(*casteIter);
PyList_Append(casteList, caste);
Py_DECREF(caste);
}
return casteList;
}
static PyObject* BuildCreatureTypeEx(t_creaturetype& creature)
{
PyObject* c_type;
PyObject* list;
c_type = PyDict_New();
list = PyList_New(6);
PyList_SET_ITEM(list, 0, Py_BuildValue("ss", "rawname", creature.rawname));
PyList_SET_ITEM(list, 1, Py_BuildValue("sO", "castes", BuildCreatureCasteList(creature.castes)));
PyList_SET_ITEM(list, 2, Py_BuildValue("si", "tile_character", creature.tile_character));
PyList_SET_ITEM(list, 3, Py_BuildValue("si", "fore", creature.tilecolor.fore));
PyList_SET_ITEM(list, 4, Py_BuildValue("si", "back", creature.tilecolor.back));
PyList_SET_ITEM(list, 5, Py_BuildValue("si", "bright", creature.tilecolor.bright));
PyDict_MergeFromSeq2(c_type, list, 0);
Py_DECREF(list);
return c_type;
}
static PyObject* BuildCreatureTypeExList(std::vector<t_creaturetype>& creatures)
{
PyObject* creatureList;
std::vector<t_creaturetype>::iterator creatureIter;
creatureList = PyList_New(0);
for(creatureIter = creatures.begin(); creatureIter != creatures.end(); creatureIter++)
{
PyObject* creature = BuildCreatureTypeEx(*creatureIter);
PyList_Append(creatureList, creature);
Py_DECREF(creature);
}
return creatureList;
}
// API type Allocation, Deallocation, and Initialization
static PyObject* DF_Material_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
@ -266,6 +360,36 @@ static PyObject* DF_Material_ReadCreatureTypes(DF_Material* self, PyObject* args
Py_RETURN_NONE;
}
static PyObject* DF_Material_ReadCreatureTypesEx(DF_Material* self, PyObject* args)
{
if(self->mat_Ptr != NULL)
{
std::vector<DFHack::t_creaturetype> creatureVec;
if(self->mat_Ptr->ReadCreatureTypesEx(creatureVec))
{
return BuildCreatureTypeExList(creatureVec);
}
}
Py_RETURN_NONE;
}
static PyObject* DF_Material_ReadDescriptorColors(DF_Material* self, PyObject* args)
{
if(self->mat_Ptr != NULL)
{
std::vector<DFHack::t_descriptor_color> colorVec;
if(self->mat_Ptr->ReadDescriptorColors(colorVec))
{
return BuildDescriptorColorList(colorVec);
}
}
Py_RETURN_NONE;
}
static PyMethodDef DF_Material_methods[] =
{
{"Read_Inorganic_Materials", (PyCFunction)DF_Material_ReadInorganicMaterials, METH_NOARGS, ""},
@ -273,6 +397,8 @@ static PyMethodDef DF_Material_methods[] =
{"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, ""},
{"Read_Creature_Types_Ex", (PyCFunction)DF_Material_ReadCreatureTypesEx, METH_NOARGS, ""},
{"Read_Descriptor_Colors", (PyCFunction)DF_Material_ReadDescriptorColors, METH_NOARGS, ""},
{NULL} //Sentinel
};