Skip to content

Commit

Permalink
Merge pull request #395 from anatoliy-savchak/work
Browse files Browse the repository at this point in the history
PyObjHandle.conditions_get(int: kind = 0)
  • Loading branch information
doug1234 authored Jun 6, 2020
2 parents a17c061 + c3b1478 commit 5195adc
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions TemplePlus/python/python_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,54 @@ static PyObject* PyObjHandle_ConditionAddWithArgs(PyObject* obj, PyObject* args)
return PyInt_FromLong(result);
}

static PyObject* PyObjHandle_ConditionsGet(PyObject* obj, PyObject* args) {
auto self = GetSelf(obj);

auto dispatcher = objects.GetDispatcher(self->handle);
if (!dispatcher)
Py_RETURN_NONE;

long kind = 0;
if (PyTuple_GET_SIZE(args) > 0) {
PyObject* arg = PyTuple_GET_ITEM(args, 0);
if (PyInt_Check(arg)) {
kind = PyInt_AsLong(arg);
}
}

CondNode* node = dispatcher->conditions;
if (kind == 1) {
node = dispatcher->permanentMods;
} else
if (kind == 2) {
node = dispatcher->itemConds;
}
if (!node)
Py_RETURN_NONE;

auto list = PyList_New(0);
while (node) {
auto cname = PyString_FromString(node->condStruct->condName);
auto tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, cname);
if (node->condStruct->numArgs) {
auto tupleArgs = PyTuple_New(node->condStruct->numArgs);
for (auto i = 0; i < node->condStruct->numArgs; i++)
{
PyTuple_SET_ITEM(tupleArgs, i, PyInt_FromSize_t(node->args[i]));
}
PyTuple_SET_ITEM(tuple, 1, tupleArgs);
}

PyList_Append(list, tuple);
Py_DecRef(tuple);

node = node->nextCondNode;
}
return list;
}


static PyObject* PyObjHandle_FavoredEnemy(PyObject* obj, PyObject* args) {
auto self = GetSelf(obj);
if (!self->handle)
Expand Down Expand Up @@ -3405,6 +3453,7 @@ static PyMethodDef PyObjHandleMethods[] = {
{ "concealed_set", PyObjHandle_ConcealedSet, METH_VARARGS, NULL },
{ "condition_add_with_args", PyObjHandle_ConditionAddWithArgs, METH_VARARGS, NULL },
{ "condition_add", PyObjHandle_ConditionAddWithArgs, METH_VARARGS, NULL },
{ "conditions_get", PyObjHandle_ConditionsGet, METH_VARARGS, NULL },
{ "container_flags_get", GetFlags<obj_f_container_flags>, METH_VARARGS, NULL },
{ "container_flag_set", SetFlag<obj_f_container_flags>, METH_VARARGS, NULL },
{ "container_flag_unset", ClearFlag<obj_f_container_flags>, METH_VARARGS, NULL },
Expand Down

0 comments on commit 5195adc

Please sign in to comment.