diff --git a/library/pydfhack/matgloss.cpp b/library/pydfhack/matgloss.cpp index 26ad11984..d48c227cc 100644 --- a/library/pydfhack/matgloss.cpp +++ b/library/pydfhack/matgloss.cpp @@ -1,3 +1,27 @@ +/* +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__ @@ -6,10 +30,14 @@ #include #include "DFTypes.h" +using namespace DFHack; + +// MatGloss + struct MatGloss { PyObject_HEAD - t_matgloss native; + DFHack::t_matgloss native; }; static PyObject* MatGloss_new(PyTypeObject* type, PyObject* arg, PyObject* kwds) @@ -18,13 +46,10 @@ static PyObject* MatGloss_new(PyTypeObject* type, PyObject* arg, PyObject* kwds) self = (MatGloss*)type->tp_alloc(type, 0); - self->id[0] = '\0'; - self->name[0] = '\0'; -} - -static int MatGloss_init(MatGloss* self, PyObject* args, PyObject* kwds) -{ - return 0; + self->native->id[0] = '\0'; + self->native->name[0] = '\0'; + + return (PyObject*)self; } static void MatGloss_dealloc(MatGloss* self) @@ -45,7 +70,7 @@ static int MatGloss_SetID(MatGloss* self, PyObject* args, void* closure) return -1; strncpy(self->id, temp, 127); - self->id[127] = '\0'; + self->native->id[127] = '\0'; return 0; } @@ -62,8 +87,8 @@ static PyObject* MatGloss_SetName(MatGloss* self, PyObject* args, void* closure) if(!PyArg_ParseTuple(args, "s", &temp)) return -1; - strncpy(self->name, temp, 127); - self->name[127] = '\0'; + strncpy(self->native->name, temp, 127); + self->native->name[127] = '\0'; return 0; } @@ -75,4 +100,132 @@ static PyGetSetDef MatGloss_getSetters[] = {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 \ No newline at end of file