added BuildSoul

develop
doomchild 2010-04-11 21:07:23 -05:00
parent 6aef446c57
commit 5c9711c641
1 changed files with 83 additions and 50 deletions

@ -33,6 +33,8 @@ using namespace DFHack;
#include "modules/Creatures.h" #include "modules/Creatures.h"
#define DICTADD(d, name, item) PyDict_SetItemString(d, name, item); Py_DECREF(item)
static PyObject* BuildMatglossPair(DFHack::t_matglossPair& matgloss) static PyObject* BuildMatglossPair(DFHack::t_matglossPair& matgloss)
{ {
return Py_BuildValue("ii", matgloss.type, matgloss.index); return Py_BuildValue("ii", matgloss.type, matgloss.index);
@ -48,11 +50,26 @@ static PyObject* BuildSkill(DFHack::t_skill& skill)
return Py_BuildValue("III", skill.id, skill.experience, skill.rating); return Py_BuildValue("III", skill.id, skill.experience, skill.rating);
} }
static PyObject* BuildSkillList(DFHack::t_skill (&skills)[256], uint8_t numSkills)
{
PyObject* list = PyList_New(numSkills);
for(int i = 0; i < numSkills; i++)
PyList_SET_ITEM(list, i, BuildSkill(skills[i]));
return list;
}
static PyObject* BuildJob(DFHack::t_job& job) static PyObject* BuildJob(DFHack::t_job& job)
{ {
return Py_BuildValue("Oi", PyBool_FromLong((int)job.active), job.jobId); return Py_BuildValue("Oi", PyBool_FromLong((int)job.active), job.jobId);
} }
static PyObject* BuildAttribute(DFHack::t_attrib& at)
{
return Py_BuildValue("IIIIIII", at.level, at.field_4, at.field_8, at.field_C, at.leveldiff, at.field_14, at.field_18);
}
static PyObject* BuildItemType(DFHack::t_itemType& item) static PyObject* BuildItemType(DFHack::t_itemType& item)
{ {
PyObject *id, *name; PyObject *id, *name;
@ -86,31 +103,20 @@ static PyObject* BuildNote(DFHack::t_note& note)
PyObject* temp; PyObject* temp;
temp = PyString_FromFormat("%c", note.symbol); temp = PyString_FromFormat("%c", note.symbol);
DICTADD(noteDict, "symbol", temp);
PyDict_SetItemString(noteDict, "symbol", temp);
Py_DECREF(temp);
temp = Py_BuildValue("II", note.foreground, note.background); temp = Py_BuildValue("II", note.foreground, note.background);
DICTADD(noteDict, "fore_back", temp);
PyDict_SetItemString(noteDict, "fore_back", temp);
Py_DECREF(temp);
if(note.name[0]) if(note.name[0])
temp = PyString_FromString(note.name); temp = PyString_FromString(note.name);
else else
PyString_FromString(""); PyString_FromString("");
PyDict_SetItemString(noteDict, "name", temp);
Py_DECREF(temp); DICTADD(noteDict, "name", temp);
temp = Py_BuildValue("III", note.x, note.y, note.z); temp = Py_BuildValue("III", note.x, note.y, note.z);
DICTADD(noteDict, "position", temp);
PyDict_SetItemString(noteDict, "position", temp);
Py_DECREF(temp);
return noteDict; return noteDict;
} }
@ -129,46 +135,33 @@ static PyObject* BuildName(DFHack::t_name& name)
temp = PyString_FromString(name.first_name); temp = PyString_FromString(name.first_name);
else else
temp = PyString_FromString(""); temp = PyString_FromString("");
PyDict_SetItemString(nameDict, "first_name", temp);
Py_DECREF(temp); DICTADD(nameDict, "first_name", temp);
if(name.nickname[0]) if(name.nickname[0])
temp = PyString_FromString(name.nickname); temp = PyString_FromString(name.nickname);
else else
temp = PyString_FromString(""); temp = PyString_FromString("");
PyDict_SetItemString(nameDict, "nickname", temp);
Py_DECREF(temp); DICTADD(nameDict, "nickname", temp);
temp = PyInt_FromLong(name.language); temp = PyInt_FromLong(name.language);
DICTADD(nameDict, "language", temp);
PyDict_SetItemString(nameDict, "language", temp);
Py_DECREF(temp);
temp = PyBool_FromLong((int)name.has_name); temp = PyBool_FromLong((int)name.has_name);
DICTADD(nameDict, "has_name", temp);
PyDict_SetItemString(nameDict, "has_name", temp);
Py_DECREF(temp);
wordList = PyList_New(wordCount); wordList = PyList_New(wordCount);
speechList = PyList_New(wordCount); speechList = PyList_New(wordCount);
for(int i = 0; i < wordCount; i++) for(int i = 0; i < wordCount; i++)
{ {
PyList_SetItem(wordList, i, PyInt_FromLong(name.words[i])); PyList_SET_ITEM(wordList, i, PyInt_FromLong(name.words[i]));
PyList_SetItem(wordList, i, PyInt_FromLong(name.parts_of_speech[i])); PyList_SET_ITEM(speechList, i, PyInt_FromLong(name.parts_of_speech[i]));
} }
PyDict_SetItemString(nameDict, "words", wordList); DICTADD(nameDict, "words", wordList);
PyDict_SetItemString(nameDict, "parts_of_speech", speechList); DICTADD(nameDict, "parts_of_speech", speechList);
Py_DECREF(wordList);
Py_DECREF(speechList);
return nameDict; return nameDict;
} }
@ -182,32 +175,72 @@ static PyObject* BuildSettlement(DFHack::t_settlement& settlement)
setDict = PyDict_New(); setDict = PyDict_New();
temp = PyInt_FromLong(settlement.origin); temp = PyInt_FromLong(settlement.origin);
DICTADD(setDict, "origin", temp);
PyDict_SetItemString(setDict, "origin", temp); temp = BuildName(settlement.name);
DICTADD(setDict, "name", temp);
Py_DECREF(temp); temp = Py_BuildValue("ii", settlement.world_x, settlement.world_y);
DICTADD(setDict, "world_pos", temp);
temp = BuildName(settlement.name); 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, "name", temp); temp = Py_BuildValue("OO", local_pos1, local_pos2);
DICTADD(setDict, "local_pos", temp);
Py_DECREF(temp); return setDict;
}
static PyObject* BuildSoul(DFHack::t_soul& soul)
{
PyObject *soulDict, *skillList, *temp;
temp = Py_BuildValue("ii", settlement.world_x, settlement.world_y); soulDict = PyDict_New();
PyDict_SetItemString(setDict, "world_pos", temp); skillList = BuildSkillList(soul.skills, soul.numSkills);
DICTADD(soulDict, "skills", skillList);
Py_DECREF(temp); temp = BuildAttribute(soul.analytical_ability);
DICTADD(soulDict, "analytical_ability", temp);
local_pos1 = Py_BuildValue("ii", settlement.local_x1, settlement.local_y1); temp = BuildAttribute(soul.focus);
local_pos2 = Py_BuildValue("ii", settlement.local_x2, settlement.local_y2); DICTADD(soulDict, "focus", temp);
PyDict_SetItemString(setDict, "local_pos", Py_BuildValue("OO", local_pos1, local_pos2)); temp = BuildAttribute(soul.willpower);
DICTADD(soulDict, "willpower", temp);
Py_DECREF(local_pos1); temp = BuildAttribute(soul.creativity);
Py_DECREF(local_pos2); DICTADD(soulDict, "creativity", temp);
return setDict; temp = BuildAttribute(soul.intuition);
DICTADD(soulDict, "intuition", temp);
temp = BuildAttribute(soul.patience);
DICTADD(soulDict, "patience", temp);
temp = BuildAttribute(soul.memory);
DICTADD(soulDict, "memory", temp);
temp = BuildAttribute(soul.linguistic_ability);
DICTADD(soulDict, "linguistic_ability", temp);
temp = BuildAttribute(soul.spatial_sense);
DICTADD(soulDict, "spatial_sense", temp);
temp = BuildAttribute(soul.musicality);
DICTADD(soulDict, "musicality", temp);
temp = BuildAttribute(soul.kinesthetic_sense);
DICTADD(soulDict, "kinesthetic_sense", temp);
temp = BuildAttribute(soul.empathy);
DICTADD(soulDict, "empathy", temp);
temp = BuildAttribute(soul.social_awareness);
DICTADD(soulDict, "social_awareness", temp);
return soulDict;
} }
#endif #endif