|
|
|
@ -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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|