2010-06-17 14:29:29 -06:00
|
|
|
from ctypes import *
|
2011-03-09 11:27:07 -07:00
|
|
|
import dftypes
|
|
|
|
from dftypes import libdfhack, Matgloss, CreatureType, DescriptorColor, MatglossOther
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
libdfhack.Materials_getInorganic.restype = c_void_p
|
|
|
|
libdfhack.Materials_getOrganic.restype = c_void_p
|
|
|
|
libdfhack.Materials_getTree.restype = c_void_p
|
|
|
|
libdfhack.Materials_getPlant.restype = c_void_p
|
|
|
|
libdfhack.Materials_getRace.restype = c_void_p
|
|
|
|
libdfhack.Materials_getRaceEx.restype = c_void_p
|
|
|
|
libdfhack.Materials_getColor.restype = c_void_p
|
|
|
|
libdfhack.Materials_getOther.restype = c_void_p
|
|
|
|
libdfhack.Materials_getAllDesc.restype = c_void_p
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
class Materials(object):
|
|
|
|
def __init__(self, ptr):
|
|
|
|
self._mat_ptr = ptr
|
|
|
|
|
|
|
|
self.inorganic = None
|
|
|
|
self.organic = None
|
|
|
|
self.tree = None
|
|
|
|
self.plant = None
|
|
|
|
self.race = None
|
|
|
|
self.race_ex = None
|
|
|
|
self.color = None
|
|
|
|
self.other = None
|
2011-03-03 13:19:20 -07:00
|
|
|
|
|
|
|
def _get_inorganic(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
inorganic = libdfhack.Materials_getInorganic(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if inorganic in dftypes.pointer_dict:
|
|
|
|
self.inorganic = [i for i in dftypes.pointer_dict[inorganic][1]]
|
|
|
|
del dftypes.pointer_dict[inorganic]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_organic(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
organic = libdfhack.Materials_getOrganic(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if organic in dftypes.pointer_dict:
|
|
|
|
self.organic = [i for i in dftypes.pointer_dict[organic][1]]
|
|
|
|
del dftypes.pointer_dict[organic]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_tree(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
tree = libdfhack.Materials_getTree(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if tree in dftypes.pointer_dict:
|
|
|
|
self.tree = [i for i in dftypes.pointer_dict[tree][1]]
|
|
|
|
del dftypes.pointer_dict[tree]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_plant(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
plant = libdfhack.Materials_getPlant(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if plant in dftypes.pointer_dict:
|
|
|
|
self.plant = [i for i in dftypes.pointer_dict[plant][1]]
|
|
|
|
del dftypes.pointer_dict[plant]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_race(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
race = libdfhack.Materials_getRace(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if race in dftypes.pointer_dict:
|
|
|
|
self.race = [i for i in dftypes.pointer_dict[race][1]]
|
|
|
|
del dftypes.pointer_dict[race]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_race_ex(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
race_ex = libdfhack.Materials_getRaceEx(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if race_ex in dftypes.pointer_dict:
|
|
|
|
self.race_ex = [i for i in dftypes.pointer_dict[race_ex][1]]
|
|
|
|
del dftypes.pointer_dict[race_ex]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_color(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
color = libdfhack.Materials_getColor(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if color in dftypes.pointer_dict:
|
|
|
|
self.color = [i for i in dftypes.pointer_dict[color][1]]
|
|
|
|
del dftypes.pointer_dict[color]
|
2011-03-09 11:27:07 -07:00
|
|
|
|
2011-03-03 13:19:20 -07:00
|
|
|
def _get_other(self):
|
2011-03-09 11:27:07 -07:00
|
|
|
other = libdfhack.Materials_getOther(self._mat_ptr)
|
|
|
|
|
2011-03-11 13:12:07 -07:00
|
|
|
if other in dftypes.pointer_dict:
|
|
|
|
self.other = [i for i in dftypes.pointer_dict[other][1]]
|
|
|
|
del dftypes.pointer_dict[other]
|
2011-03-03 13:19:20 -07:00
|
|
|
|
|
|
|
def _get_all(self):
|
|
|
|
self._get_inorganic()
|
|
|
|
self._get_organic()
|
|
|
|
self._get_tree()
|
|
|
|
self._get_plant()
|
|
|
|
self._get_race()
|
|
|
|
self._get_race_ex()
|
|
|
|
self._get_color()
|
|
|
|
self._get_other()
|
|
|
|
def _clear_all(self):
|
|
|
|
self.inorganic = None
|
|
|
|
self.organic = None
|
|
|
|
self.tree = None
|
|
|
|
self.plant = None
|
|
|
|
self.race = None
|
|
|
|
self.race_ex = None
|
|
|
|
self.color = None
|
|
|
|
self.other = None
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_inorganic(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_inorganic()
|
|
|
|
else:
|
|
|
|
self.inorganic = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_organic(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_organic()
|
|
|
|
else:
|
|
|
|
self.organic = None
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def read_tree(self):
|
|
|
|
result = libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_tree()
|
|
|
|
else:
|
|
|
|
self.tree = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_plant(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_plant()
|
|
|
|
else:
|
|
|
|
self.plant = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_creature_types(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_race()
|
|
|
|
else:
|
|
|
|
self.race = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_creature_types_ex(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_race_ex()
|
|
|
|
else:
|
|
|
|
self.race_ex = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_descriptor_colors(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_color()
|
|
|
|
else:
|
|
|
|
self.color = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_others(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadOthers(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_other()
|
|
|
|
else:
|
|
|
|
self.other = None
|
|
|
|
|
|
|
|
return result
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def read_all(self):
|
2011-03-03 13:19:20 -07:00
|
|
|
result = libdfhack.Materials_ReadAllMaterials(self._mat_ptr) > 0
|
|
|
|
|
|
|
|
if result == True:
|
|
|
|
self._get_all()
|
|
|
|
else:
|
|
|
|
self._clear_all()
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def get_type(self, material):
|
|
|
|
return libdfhack.Materials_getType(self._mat_ptr, byref(material))
|
2010-06-17 14:29:29 -06:00
|
|
|
|
|
|
|
def get_description(self, material):
|
2011-03-03 13:19:20 -07:00
|
|
|
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material))
|