develop
Petr Mrázek 2011-03-11 22:38:25 +01:00
commit 4e3a66fcd8
16 changed files with 847 additions and 518 deletions

@ -68,60 +68,51 @@ void UnregisterByteBufferCallback()
extern "C" {
#endif
int (*alloc_byte_buffer_callback)(int8_t*, uint32_t) = NULL;
int (*alloc_short_buffer_callback)(int16_t*, uint32_t) = NULL;
int (*alloc_int_buffer_callback)(int32_t*, uint32_t) = NULL;
int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t) = NULL;
int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t) = NULL;
int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t) = NULL;
int (*alloc_char_buffer_callback)(char*, uint32_t) = NULL;
int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t) = NULL;
int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t) = NULL;
int (*alloc_t_feature_buffer_callback)(t_feature*, uint32_t) = NULL;
int (*alloc_t_hotkey_buffer_callback)(t_hotkey*, uint32_t) = NULL;
int (*alloc_t_screen_buffer_callback)(t_screen*, uint32_t) = NULL;
int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop*, uint32_t) = NULL;
int (*alloc_t_material_buffer_callback)(t_material*, uint32_t) = NULL;
int (*alloc_empty_colormodifier_callback)(c_colormodifier*) = NULL;
int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t) = NULL;
int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t) = NULL;
int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*)= NULL;
int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL;
int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t) = NULL;
int (*alloc_empty_creaturetype_callback)(c_creaturetype*) = NULL;
int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL;
int (*alloc_vein_buffer_callback)(t_vein*, uint32_t) = NULL;
int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t) = NULL;
int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t) = NULL;
int (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t) = NULL;
int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t) = NULL;
REG_MACRO(Byte, int8_t*, alloc_byte_buffer_callback)
REG_MACRO(Short, int16_t*, alloc_short_buffer_callback)
REG_MACRO(Int, int32_t*, alloc_int_buffer_callback)
REG_MACRO(UByte, uint8_t*, alloc_ubyte_buffer_callback)
REG_MACRO(UShort, uint16_t*, alloc_ushort_buffer_callback)
REG_MACRO(UInt, uint32_t*, alloc_uint_buffer_callback)
REG_MACRO(Char, char*, alloc_char_buffer_callback)
REG_MACRO(Matgloss, t_matgloss*, alloc_matgloss_buffer_callback)
REG_MACRO(DescriptorColor, t_descriptor_color*, alloc_descriptor_buffer_callback)
REG_MACRO(MatglossOther, t_matglossOther*, alloc_matgloss_other_buffer_callback)
REG_MACRO(Feature, t_feature*, alloc_t_feature_buffer_callback)
REG_MACRO(Hotkey, t_hotkey*, alloc_t_hotkey_buffer_callback)
REG_MACRO(Screen, t_screen*, alloc_t_screen_buffer_callback)
REG_MACRO(CustomWorkshop, t_customWorkshop*, alloc_t_customWorkshop_buffer_callback)
REG_MACRO(Material, t_material*, alloc_t_material_buffer_callback)
int (*alloc_byte_buffer_callback)(int8_t**, uint32_t) = NULL;
int (*alloc_short_buffer_callback)(int16_t**, uint32_t) = NULL;
int (*alloc_int_buffer_callback)(int32_t**, uint32_t) = NULL;
int (*alloc_ubyte_buffer_callback)(uint8_t**, uint32_t) = NULL;
int (*alloc_ushort_buffer_callback)(uint16_t**, uint32_t) = NULL;
int (*alloc_uint_buffer_callback)(uint32_t**, uint32_t) = NULL;
int (*alloc_char_buffer_callback)(char**, uint32_t) = NULL;
int (*alloc_matgloss_buffer_callback)(t_matgloss**, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t) = NULL;
int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t) = NULL;
int (*alloc_t_feature_buffer_callback)(t_feature**, uint32_t) = NULL;
int (*alloc_t_hotkey_buffer_callback)(t_hotkey**, uint32_t) = NULL;
int (*alloc_t_screen_buffer_callback)(t_screen**, uint32_t) = NULL;
int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t) = NULL;
int (*alloc_t_material_buffer_callback)(t_material**, uint32_t) = NULL;
int (*alloc_creaturetype_buffer_callback)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t) = NULL;
int (*alloc_vein_buffer_callback)(t_vein**, uint32_t) = NULL;
int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein**, uint32_t) = NULL;
int (*alloc_spattervein_buffer_callback)(t_spattervein**, uint32_t) = NULL;
int (*alloc_grassvein_buffer_callback)(t_grassvein**, uint32_t) = NULL;
int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction**, uint32_t) = NULL;
//int (*alloc_bodypart_buffer_callback)(t_bodypart**, uint32_t) = NULL;
REG_MACRO(Byte, int8_t**, alloc_byte_buffer_callback)
REG_MACRO(Short, int16_t**, alloc_short_buffer_callback)
REG_MACRO(Int, int32_t**, alloc_int_buffer_callback)
REG_MACRO(UByte, uint8_t**, alloc_ubyte_buffer_callback)
REG_MACRO(UShort, uint16_t**, alloc_ushort_buffer_callback)
REG_MACRO(UInt, uint32_t**, alloc_uint_buffer_callback)
REG_MACRO(Char, char**, alloc_char_buffer_callback)
REG_MACRO(Matgloss, t_matgloss**, alloc_matgloss_buffer_callback)
REG_MACRO(DescriptorColor, t_descriptor_color**, alloc_descriptor_buffer_callback)
REG_MACRO(MatglossOther, t_matglossOther**, alloc_matgloss_other_buffer_callback)
REG_MACRO(Feature, t_feature**, alloc_t_feature_buffer_callback)
REG_MACRO(Hotkey, t_hotkey**, alloc_t_hotkey_buffer_callback)
REG_MACRO(Screen, t_screen**, alloc_t_screen_buffer_callback)
REG_MACRO(CustomWorkshop, t_customWorkshop**, alloc_t_customWorkshop_buffer_callback)
REG_MACRO(Material, t_material**, alloc_t_material_buffer_callback)
UNREG_MACRO(Byte, alloc_byte_buffer_callback)
UNREG_MACRO(Short, alloc_short_buffer_callback)
@ -139,79 +130,18 @@ UNREG_MACRO(Screen, alloc_t_screen_buffer_callback)
UNREG_MACRO(CustomWorkshop, alloc_t_customWorkshop_buffer_callback)
UNREG_MACRO(Material, alloc_t_material_buffer_callback)
void RegisterEmptyColorModifierCallback(int (*funcptr)(c_colormodifier*))
void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t))
{
alloc_empty_colormodifier_callback = funcptr;
alloc_creaturetype_buffer_callback = funcptr;
}
void RegisterNewColorModifierCallback(int (*funcptr)(c_colormodifier*, const char*, uint32_t))
{
alloc_colormodifier_callback = funcptr;
}
REG_MACRO(ColorModifier, c_colormodifier*, alloc_colormodifier_buffer_callback)
void RegisterEmptyCreatureCasteCallback(int (*funcptr)(c_creaturecaste*))
{
alloc_empty_creaturecaste_callback = funcptr;
}
void UnregisterEmptyColorModifierCallback()
{
alloc_empty_colormodifier_callback = NULL;
}
void UnregisterNewColorModifierCallback()
{
alloc_colormodifier_callback = NULL;
}
void RegisterNewCreatureCasteCallback(int (*funcptr)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t))
{
alloc_creaturecaste_callback = funcptr;
}
REG_MACRO(CreatureCaste, c_creaturecaste*, alloc_creaturecaste_buffer_callback)
UNREG_MACRO(CreatureCaste, alloc_creaturecaste_buffer_callback)
void UnregisterEmptyCreatureCasteCallback()
{
alloc_empty_creaturecaste_callback = NULL;
}
void UnregisterNewCreatureCasteCallback()
{
alloc_creaturecaste_callback = NULL;
}
void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*))
{
alloc_empty_creaturetype_callback = funcptr;
}
void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t))
{
alloc_creaturetype_callback = funcptr;
}
REG_MACRO(CreatureType, c_creaturetype*, alloc_creaturetype_buffer_callback)
UNREG_MACRO(CreatureType, alloc_creaturetype_buffer_callback)
void UnregisterEmptyCreatureTypeCallback()
{
alloc_empty_creaturetype_callback = NULL;
}
void UnregisterNewCreatureTypeCallback()
{
alloc_creaturetype_callback = NULL;
}
REG_MACRO(Vein, t_vein*, alloc_vein_buffer_callback)
REG_MACRO(FrozenLiquidVein, t_frozenliquidvein*, alloc_frozenliquidvein_buffer_callback)
REG_MACRO(SpatterVein, t_spattervein*, alloc_spattervein_buffer_callback)
REG_MACRO(GrassVein, t_grassvein*, alloc_grassvein_buffer_callback)
REG_MACRO(WorldConstruction, t_worldconstruction*, alloc_worldconstruction_buffer_callback)
REG_MACRO(Vein, t_vein**, alloc_vein_buffer_callback)
REG_MACRO(FrozenLiquidVein, t_frozenliquidvein**, alloc_frozenliquidvein_buffer_callback)
REG_MACRO(SpatterVein, t_spattervein**, alloc_spattervein_buffer_callback)
REG_MACRO(GrassVein, t_grassvein**, alloc_grassvein_buffer_callback)
REG_MACRO(WorldConstruction, t_worldconstruction**, alloc_worldconstruction_buffer_callback)
UNREG_MACRO(Vein, alloc_vein_buffer_callback)
UNREG_MACRO(FrozenLiquidVein, alloc_frozenliquidvein_buffer_callback)
@ -263,44 +193,151 @@ int DFHack_getTileType(int index, TileRow* tPtr)
}
#endif
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
void BuildDescriptorList(std::vector<t_creaturetype> & src, c_creaturetype_descriptor** dest)
{
if(src == NULL)
return -1;
((*alloc_colormodifier_callback)(dest, src->part, src->colorlist.size()));
c_creaturetype_descriptor* descriptor = NULL;
descriptor = (c_creaturetype_descriptor*)calloc(src.size(), sizeof(c_creaturetype_descriptor));
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
for(uint32_t i = 0; i < src.size(); i++)
{
uint32_t castes_size = src[i].castes.size();
c_creaturetype_descriptor* current = &descriptor[i];
current->castesCount = castes_size;
current->caste_descriptors = (c_creaturecaste_descriptor*)calloc(castes_size, sizeof(c_creaturecaste_descriptor));
for(uint32_t j = 0; j < castes_size; j++)
{
uint32_t color_size = src[i].castes[j].ColorModifier.size();
c_creaturecaste_descriptor* current_caste = &current->caste_descriptors[j];
current_caste->colorModifierLength = color_size;
current_caste->color_descriptors = (c_colormodifier_descriptor*)calloc(color_size, sizeof(c_colormodifier_descriptor));
for(uint32_t k = 0; k < color_size; k++)
{
c_colormodifier_descriptor* current_color = &current_caste->color_descriptors[k];
current_color->colorlistLength = src[i].castes[j].ColorModifier[k].colorlist.size();
}
current_caste->bodypartLength = src[i].castes[j].bodypart.size();
}
current->extractCount = src[i].extract.size();
}
return 1;
*dest = descriptor;
}
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length)
{
if(src == NULL)
return -1;
((*alloc_creaturecaste_callback)(dest, src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
for(uint32_t i = 0; i < length; i++)
{
c_creaturetype_descriptor* desc = &d[i];
for(uint32_t j = 0; j < desc->castesCount; j++)
free(desc->caste_descriptors[j].color_descriptors);
free(desc->caste_descriptors);
}
for(unsigned int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
copy(src->bodypart.begin(), src->bodypart.end(), dest->bodypart);
return 1;
free(d);
}
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
int CreatureTypeConvert(std::vector<t_creaturetype> & src, c_creaturetype** out_buf)
{
if(src == NULL)
if(src.size() <= 0)
return 0;
else if(alloc_creaturetype_buffer_callback == NULL)
return -1;
((*alloc_creaturetype_callback)(dest, src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
for(unsigned int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]);
copy(src->extract.begin(), src->extract.end(), dest->extract);
return 1;
else
{
c_creaturetype_descriptor* descriptor;
c_creaturetype* buf;
BuildDescriptorList(src, &descriptor);
((*alloc_creaturetype_buffer_callback)(out_buf, descriptor, src.size()));
FreeDescriptorList(descriptor, src.size());
if(out_buf == NULL)
return -1;
buf = out_buf[0];
for(uint32_t i = 0; i < src.size(); i++)
{
c_creaturetype* current = &(buf[i]);
memset(current->rawname, '\0', 128);
strncpy(current->rawname, src[i].rawname, 128);
for(uint32_t j = 0; j < current->castesCount; j++)
{
c_creaturecaste* current_caste = &current->castes[j];
t_creaturecaste* src_caste = &src[i].castes[j];
memset(current_caste->rawname, '\0', 128);
memset(current_caste->singular, '\0', 128);
memset(current_caste->plural, '\0', 128);
memset(current_caste->adjective, '\0', 128);
strncpy(current_caste->rawname, src_caste->rawname, 128);
strncpy(current_caste->singular, src_caste->singular, 128);
strncpy(current_caste->plural, src_caste->plural, 128);
strncpy(current_caste->adjective, src_caste->adjective, 128);
for(uint32_t k = 0; k < src[i].castes[j].ColorModifier.size(); k++)
{
c_colormodifier* current_color = &current_caste->colorModifier[k];
memset(current_color->part, '\0', 128);
strncpy(current_color->part, src_caste->ColorModifier[k].part, 128);
copy(src_caste->ColorModifier[k].colorlist.begin(), src_caste->ColorModifier[k].colorlist.end(), current_color->colorlist);
current_color->colorlistLength = src_caste->ColorModifier[k].colorlist.size();
current_color->startdate = src_caste->ColorModifier[k].startdate;
current_color->enddate = src_caste->ColorModifier[k].enddate;
}
current_caste->colorModifierLength = src_caste->ColorModifier.size();
copy(src_caste->bodypart.begin(), src_caste->bodypart.end(), current_caste->bodypart);
current_caste->bodypartLength = src_caste->bodypart.size();
current_caste->strength = src_caste->strength;
current_caste->agility = src_caste->agility;
current_caste->toughness = src_caste->toughness;
current_caste->endurance = src_caste->endurance;
current_caste->recuperation = src_caste->recuperation;
current_caste->disease_resistance = src_caste->disease_resistance;
current_caste->analytical_ability = src_caste->analytical_ability;
current_caste->focus = src_caste->focus;
current_caste->willpower = src_caste->willpower;
current_caste->creativity = src_caste->creativity;
current_caste->intuition = src_caste->intuition;
current_caste->patience = src_caste->patience;
current_caste->memory = src_caste->memory;
current_caste->linguistic_ability = src_caste->linguistic_ability;
current_caste->spatial_sense = src_caste->spatial_sense;
current_caste->musicality = src_caste->musicality;
current_caste->kinesthetic_sense = src_caste->kinesthetic_sense;
}
copy(src[i].extract.begin(), src[i].extract.end(), current->extract);
current->extractCount = src[i].extract.size();
current->tile_character = src[i].tile_character;
current->tilecolor.fore = src[i].tilecolor.fore;
current->tilecolor.back = src[i].tilecolor.back;
current->tilecolor.bright = src[i].tilecolor.bright;
}
return 1;
}
}

@ -41,41 +41,41 @@ distribution.
extern "C" {
#endif
DFHACK_EXPORT extern int (*alloc_byte_buffer_callback)(int8_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_short_buffer_callback)(int16_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_int_buffer_callback)(int32_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_byte_buffer_callback)(int8_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_short_buffer_callback)(int16_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_int_buffer_callback)(int32_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_ubyte_buffer_callback)(uint8_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_ushort_buffer_callback)(uint16_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_uint_buffer_callback)(uint32_t**, uint32_t);
DFHACK_EXPORT extern int (*alloc_char_buffer_callback)(char*, uint32_t);
DFHACK_EXPORT extern int (*alloc_char_buffer_callback)(char**, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t);
DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss**, uint32_t);
DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_feature_buffer_callback)(t_feature*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_hotkey_buffer_callback)(t_hotkey*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_screen_buffer_callback)(t_screen*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_feature_buffer_callback)(t_feature**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_hotkey_buffer_callback)(t_hotkey**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_screen_buffer_callback)(t_screen**, uint32_t);
DFHACK_EXPORT void RegisterByteBufferCallback(int (*funcptr)(int8_t*, uint32_t));
DFHACK_EXPORT void RegisterShortBufferCallback(int (*funcptr)(int16_t*, uint32_t));
DFHACK_EXPORT void RegisterIntBufferCallback(int (*funcptr)(int32_t*, uint32_t));
DFHACK_EXPORT void RegisterByteBufferCallback(int (*funcptr)(int8_t**, uint32_t));
DFHACK_EXPORT void RegisterShortBufferCallback(int (*funcptr)(int16_t**, uint32_t));
DFHACK_EXPORT void RegisterIntBufferCallback(int (*funcptr)(int32_t**, uint32_t));
DFHACK_EXPORT void RegisterUByteBufferCallback(int (*funcptr)(uint8_t*, uint32_t));
DFHACK_EXPORT void RegisterUShortBufferCallback(int (*funcptr)(uint16_t*, uint32_t));
DFHACK_EXPORT void RegisterUIntBufferCallback(int (*funcptr)(uint32_t*, uint32_t));
DFHACK_EXPORT void RegisterUByteBufferCallback(int (*funcptr)(uint8_t**, uint32_t));
DFHACK_EXPORT void RegisterUShortBufferCallback(int (*funcptr)(uint16_t**, uint32_t));
DFHACK_EXPORT void RegisterUIntBufferCallback(int (*funcptr)(uint32_t**, uint32_t));
DFHACK_EXPORT void RegisterCharBufferCallback(int (*funcptr)(char*, uint32_t));
DFHACK_EXPORT void RegisterCharBufferCallback(int (*funcptr)(char**, uint32_t));
DFHACK_EXPORT void RegisterMatglossBufferCallback(int (*funcptr)(t_matgloss*, uint32_t));
DFHACK_EXPORT void RegisterDescriptorColorBufferCallback(int (*funcptr)(t_descriptor_color*, uint32_t));
DFHACK_EXPORT void RegisterMatglossOtherBufferCallback(int (*funcptr)(t_matglossOther*, uint32_t));
DFHACK_EXPORT void RegisterMatglossBufferCallback(int (*funcptr)(t_matgloss**, uint32_t));
DFHACK_EXPORT void RegisterDescriptorColorBufferCallback(int (*funcptr)(t_descriptor_color**, uint32_t));
DFHACK_EXPORT void RegisterMatglossOtherBufferCallback(int (*funcptr)(t_matglossOther**, uint32_t));
DFHACK_EXPORT void RegisterFeatureBufferCallback(int (*funcptr)(t_feature*, uint32_t));
DFHACK_EXPORT void RegisterHotkeyBufferCallback(int (*funcptr)(t_hotkey*, uint32_t));
DFHACK_EXPORT void RegisterScreenBufferCallback(int (*funcptr)(t_screen*, uint32_t));
DFHACK_EXPORT void RegisterFeatureBufferCallback(int (*funcptr)(t_feature**, uint32_t));
DFHACK_EXPORT void RegisterHotkeyBufferCallback(int (*funcptr)(t_hotkey**, uint32_t));
DFHACK_EXPORT void RegisterScreenBufferCallback(int (*funcptr)(t_screen**, uint32_t));
HUNREG_MACRO(Byte)
HUNREG_MACRO(Short)
@ -100,11 +100,11 @@ struct t_customWorkshop
char name[256];
};
DFHACK_EXPORT extern int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_material_buffer_callback)(t_material*, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_material_buffer_callback)(t_material**, uint32_t);
DFHACK_EXPORT void RegisterCustomWorkshopBufferCallback(int (*funcptr)(t_customWorkshop*, uint32_t));
DFHACK_EXPORT void RegisterMaterialBufferCallback(int (*funcptr)(t_material*, uint32_t));
DFHACK_EXPORT void RegisterCustomWorkshopBufferCallback(int (*funcptr)(t_customWorkshop**, uint32_t));
DFHACK_EXPORT void RegisterMaterialBufferCallback(int (*funcptr)(t_material**, uint32_t));
HUNREG_MACRO(CustomWorkshop)
HUNREG_MACRO(Material)
@ -114,19 +114,14 @@ struct c_colormodifier
char part[128];
uint32_t* colorlist;
uint32_t colorlistLength;
uint32_t startdate;
uint32_t enddate;
};
DFHACK_EXPORT extern int (*alloc_empty_colormodifier_callback)(c_colormodifier*);
DFHACK_EXPORT extern int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t);
DFHACK_EXPORT extern int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t);
DFHACK_EXPORT void RegisterEmptyColorModifierCallback(int (*funcptr)(c_colormodifier*));
DFHACK_EXPORT void RegisterNewColorModifierCallback(int (*funcptr)(c_colormodifier*, const char*, uint32_t));
DFHACK_EXPORT void RegisterColorModifierBufferCallback(int (*funcptr)(c_colormodifier*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyColorModifierCallback();
DFHACK_EXPORT void UnregisterNewColorModifierCallback();
HUNREG_MACRO(ColorModifier)
struct c_colormodifier_descriptor
{
uint32_t colorlistLength;
};
struct c_creaturecaste
{
@ -135,24 +130,37 @@ struct c_creaturecaste
char plural[128];
char adjective[128];
c_colormodifier* ColorModifier;
c_colormodifier* colorModifier;
uint32_t colorModifierLength;
t_bodypart* bodypart;
uint32_t bodypartLength;
t_attrib strength;
t_attrib agility;
t_attrib toughness;
t_attrib endurance;
t_attrib recuperation;
t_attrib disease_resistance;
t_attrib analytical_ability;
t_attrib focus;
t_attrib willpower;
t_attrib creativity;
t_attrib intuition;
t_attrib patience;
t_attrib memory;
t_attrib linguistic_ability;
t_attrib spatial_sense;
t_attrib musicality;
t_attrib kinesthetic_sense;
};
DFHACK_EXPORT extern int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*);
DFHACK_EXPORT extern int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t);
DFHACK_EXPORT void RegisterEmptyCreatureCasteCallback(int (*funcptr)(c_creaturecaste*));
DFHACK_EXPORT void RegisterNewCreatureCasteCallback(int (*funcptr)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t));
DFHACK_EXPORT void RegisterCreatureCasteBufferCallback(int (*funcptr)(c_creaturecaste*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyCreatureCasteCallback();
DFHACK_EXPORT void UnregisterNewCreatureCasteCallback();
HUNREG_MACRO(CreatureCaste)
struct c_creaturecaste_descriptor
{
c_colormodifier_descriptor* color_descriptors;
uint32_t colorModifierLength;
uint32_t bodypartLength;
};
struct c_creaturetype
{
@ -174,28 +182,29 @@ struct c_creaturetype
} tilecolor;
};
DFHACK_EXPORT extern int (*alloc_empty_creaturetype_callback)(c_creaturetype*);
DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t);
struct c_creaturetype_descriptor
{
c_creaturecaste_descriptor* caste_descriptors;
uint32_t castesCount;
uint32_t extractCount;
};
DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t);
DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t);
DFHACK_EXPORT void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*));
DFHACK_EXPORT void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t));
DFHACK_EXPORT void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype*, uint32_t));
DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein**, uint32_t);
DFHACK_EXPORT extern int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein**, uint32_t);
DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein**, uint32_t);
DFHACK_EXPORT extern int (*alloc_grassvein_buffer_callback)(t_grassvein**, uint32_t);
DFHACK_EXPORT extern int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction**, uint32_t);
DFHACK_EXPORT void RegisterVeinBufferCallback(int (*funcptr)(t_vein*, uint32_t));
DFHACK_EXPORT void RegisterFrozenLiquidVeinBufferCallback(int (*funcptr)(t_frozenliquidvein*, uint32_t));
DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervein*, uint32_t));
DFHACK_EXPORT void RegisterGrassVeinBufferCallback(int (*funcptr)(t_grassvein*, uint32_t));
DFHACK_EXPORT void RegisterWorldConstructionBufferCallback(int (*funcptr)(t_worldconstruction*, uint32_t));
DFHACK_EXPORT void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t));
DFHACK_EXPORT void RegisterVeinBufferCallback(int (*funcptr)(t_vein**, uint32_t));
DFHACK_EXPORT void RegisterFrozenLiquidVeinBufferCallback(int (*funcptr)(t_frozenliquidvein**, uint32_t));
DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervein**, uint32_t));
DFHACK_EXPORT void RegisterGrassVeinBufferCallback(int (*funcptr)(t_grassvein**, uint32_t));
DFHACK_EXPORT void RegisterWorldConstructionBufferCallback(int (*funcptr)(t_worldconstruction**, uint32_t));
DFHACK_EXPORT void UnregisterEmptyCreatureTypeCallback();
DFHACK_EXPORT void UnregisterNewCreatureTypeCallback();
HUNREG_MACRO(CreatureType)
HUNREG_MACRO(Vein)
@ -217,8 +226,9 @@ DFHACK_EXPORT int DFHack_getTileType(int index, TileRow* tPtr);
}
#endif
int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest);
int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest);
int ColorListConvert(t_colormodifier* src, c_colormodifier* dest);
void BuildDescriptorList(std::vector<t_creaturetype> & src, c_creaturetype_descriptor** dest);
void FreeDescriptorList(c_creaturetype_descriptor* d, uint32_t length);
int CreatureTypeConvert(std::vector<t_creaturetype> &, c_creaturetype**);
#endif

@ -48,22 +48,27 @@ All of the allocators are defined in dfhack/library/include/dfhack-c/DFTypes_C.h
Buffer Callback List
---------------------
- alloc_byte_buffer_callback(int8_t*, uint32_t)
- alloc_short_buffer_callback(int16_t*, uint32_t)
- alloc_int_buffer_callback(int32_t*, uint32_t)
- alloc_ubyte_buffer_callback(uint8_t*, uint32_t)
- alloc_ushort_buffer_callback(uint16_t*, uint32_t)
- alloc_uint_buffer_callback(uint32_t*, uint32_t)
- alloc_char_buffer_callback(char* uint32_t)
- alloc_matgloss_buffer_callback(t_matgloss*, uint32_t)
- alloc_descriptor_buffer_callback(t_descriptor_color*, uint32_t)
- alloc_matgloss_other_buffer_callback(t_matglossOther*, uint32_t)
- alloc_vein_buffer_callback(t_vein*, uint32_t)
- alloc_t_feature_buffer_callback(t_feature*, uint32_t)
- alloc_t_hotkey_buffer_callback(t_hotkey*, uint32_t)
- alloc_t_screen_buffer_callback(t_screen*, uint32_t)
- alloc_frozenliquidvein_buffer_callback(t_frozenliquidvein*, uint32_t)
- alloc_spattervein_buffer_callback(t_spattervein*, uint32_t)
- alloc_byte_buffer_callback(int8_t**, uint32_t)
- alloc_short_buffer_callback(int16_t**, uint32_t)
- alloc_int_buffer_callback(int32_t**, uint32_t)
- alloc_ubyte_buffer_callback(uint8_t**, uint32_t)
- alloc_ushort_buffer_callback(uint16_t**, uint32_t)
- alloc_uint_buffer_callback(uint32_t**, uint32_t)
- alloc_char_buffer_callback(char** uint32_t)
- alloc_matgloss_buffer_callback(t_matgloss**, uint32_t)
- alloc_descriptor_buffer_callback(t_descriptor_color**, uint32_t)
- alloc_matgloss_other_buffer_callback(t_matglossOther**, uint32_t)
- alloc_t_feature_buffer_callback(t_feature**, uint32_t)
- alloc_t_hotkey_buffer_callback(t_hotkey**, uint32_t)
- alloc_t_screen_buffer_callback(t_screen**, uint32_t)
- alloc_t_customWorkshop_buffer_callback(t_customWorkshop**, uint32_t)
- alloc_t_material_buffer_callback(t_material**, uint32_t)
- alloc_vein_buffer_callback(t_vein**, uint32_t)
- alloc_frozenliquidvein_buffer_callback(t_frozenliquidvein**, uint32_t)
- alloc_spattervein_buffer_callback(t_spattervein**, uint32_t)
- alloc_grassvein_buffer_callback(t_grassvein**, uint32_t)
- alloc_worldconstruction_buffer_callback(t_worldconstruction**, uint32_t)
Templates Make My Life Harder
-------------------------------
@ -96,15 +101,14 @@ The Python bindings for dfhack implement the unsigned integer allocator callback
| arr_type = t_type * count
| arr = arr_type()
|
| ptr = c_void_p()
| ptr = addressof(arr)
|
| return (arr, ptr)
| return arr
|
| def _alloc_uint_buffer(ptr, count):
| a = _allocate_array(c_uint, count)
|
| p = cast(a, POINTER(c_uint))
|
| ptr = addressof(a[0])
| ptr[0] = p
|
| return 1
|
@ -118,7 +122,11 @@ The Python bindings for dfhack implement the unsigned integer allocator callback
|
| libdfhack = cdll.libdfhack
|
| libdfhack.alloc_uint_buffer_callback = alloc_uint_buffer
| def _register_callback(name, func):
| ptr = c_void_p.in_dll(libdfhack, name)
| ptr.value = cast(func, c_void_p).value
|
| _register_callback("alloc_uint_buffer_callback", alloc_uint_buffer)
Modules
========

@ -79,6 +79,17 @@ DFHACK_EXPORT t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t
DFHACK_EXPORT t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
typedef struct
{
t_vein* veins;
t_frozenliquidvein* frozen_veins;
t_spattervein* spatter_veins;
t_grassvein* grass_veins;
t_worldconstruction* world_constructions;
} c_allveins;
DFHACK_EXPORT int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, c_allveins* vein_struct);
#ifdef __cplusplus
}
#endif

@ -81,7 +81,7 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr)
if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return NULL;
(*alloc_t_customWorkshop_buffer_callback)(cw_Ptr, bTypes.size());
(*alloc_t_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size());
if(cw_Ptr == NULL)
return NULL;

@ -86,7 +86,7 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
t_material* buf = NULL;
(*alloc_t_material_buffer_callback)(buf, mat.size());
(*alloc_t_material_buffer_callback)(&buf, mat.size());
if(buf != NULL)
{
@ -117,7 +117,7 @@ uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index)
uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size());
(*alloc_uint_buffer_callback)(&buf, item.size());
if(buf != NULL)
{
@ -146,7 +146,7 @@ uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index)
uint32_t* buf = NULL;
(*alloc_uint_buffer_callback)(buf, item.size());
(*alloc_uint_buffer_callback)(&buf, item.size());
if(buf != NULL)
{

@ -59,7 +59,8 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje
if(desc.size() > 0)
{
char* buf = NULL;
(*alloc_char_buffer_callback)(buf,desc.size());
(*alloc_char_buffer_callback)(&buf, desc.size());
if(buf != NULL)
{
@ -87,7 +88,9 @@ char* Items_getItemClass(DFHackObject* items, int32_t index)
if(iclass.size() > 0)
{
char* buf = NULL;
(*alloc_char_buffer_callback)(buf, iclass.size());
(*alloc_char_buffer_callback)(&buf, iclass.size());
if(buf != NULL)
{
size_t len = iclass.copy(buf, iclass.size());

@ -63,7 +63,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
if(((DFHack::Maps*)maps)->ReadGeology(geology))
{
uint16_t* buf = NULL;
uint16_t** buf = NULL;
uint32_t geoLength = 0;
for(unsigned int i = 0; i < geology.size(); i++)
@ -78,7 +78,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
if(buf != NULL)
{
uint16_t* bufCopyPtr = buf;
uint16_t* bufCopyPtr = *buf;
for(unsigned int i = 0; i < geology.size(); i++)
{
@ -87,7 +87,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
bufCopyPtr += geology[i].size();
}
return buf;
return *buf;
}
else
return NULL;
@ -108,15 +108,15 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
if(featureVec.size() <= 0)
return NULL;
t_feature* buf = NULL;
t_feature** buf = NULL;
(*alloc_t_feature_buffer_callback)(buf, featureVec.size());
if(buf != NULL)
{
copy(featureVec.begin(), featureVec.end(), buf);
copy(featureVec.begin(), featureVec.end(), *buf);
return buf;
return *buf;
}
else
return NULL;
@ -368,7 +368,10 @@ t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint3
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(v_buf, veins.size()));
((*alloc_vein_buffer_callback)(&v_buf, veins.size()));
if(v_buf == NULL)
return NULL;
copy(veins.begin(), veins.end(), v_buf);
}
@ -399,7 +402,10 @@ t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_
if(frozen_veins.size() > 0)
{
((*alloc_frozenliquidvein_buffer_callback)(fv_buf, frozen_veins.size()));
((*alloc_frozenliquidvein_buffer_callback)(&fv_buf, frozen_veins.size()));
if(fv_buf == NULL)
return NULL;
copy(frozen_veins.begin(), frozen_veins.end(), fv_buf);
}
@ -430,7 +436,10 @@ t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y,
if(spatter_veins.size() > 0)
{
((*alloc_spattervein_buffer_callback)(sv_buf, spatter_veins.size()));
((*alloc_spattervein_buffer_callback)(&sv_buf, spatter_veins.size()));
if(sv_buf == NULL)
return NULL;
copy(spatter_veins.begin(), spatter_veins.end(), sv_buf);
}
@ -461,7 +470,10 @@ t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uin
if(grass_veins.size() > 0)
{
((*alloc_grassvein_buffer_callback)(gs_buf, grass_veins.size()));
((*alloc_grassvein_buffer_callback)(&gs_buf, grass_veins.size()));
if(gs_buf == NULL)
return NULL;
copy(grass_veins.begin(), grass_veins.end(), gs_buf);
}
@ -492,7 +504,10 @@ t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x,
if(constructions.size() > 0)
{
((*alloc_worldconstruction_buffer_callback)(ct_buf, constructions.size()));
((*alloc_worldconstruction_buffer_callback)(&ct_buf, constructions.size()));
if(ct_buf == NULL)
return NULL;
copy(constructions.begin(), constructions.end(), ct_buf);
}
@ -506,6 +521,100 @@ t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x,
return NULL;
}
int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, c_allveins* vein_struct)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL || alloc_frozenliquidvein_buffer_callback == NULL ||
alloc_spattervein_buffer_callback == NULL || alloc_grassvein_buffer_callback == NULL ||
alloc_worldconstruction_buffer_callback == NULL)
return -1;
vector<t_vein> veins;
vector<t_frozenliquidvein> frozen_veins;
vector<t_spattervein> spatter_veins;
vector<t_grassvein> grass_veins;
vector<t_worldconstruction> constructions;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, &frozen_veins, &spatter_veins, &grass_veins, &constructions);
if(result)
{
t_vein* v_buf = NULL;
t_frozenliquidvein* fv_buf = NULL;
t_spattervein* sv_buf = NULL;
t_grassvein* gs_buf = NULL;
t_worldconstruction* ct_buf = NULL;
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(&v_buf, veins.size()));
if(v_buf == NULL)
return -1;
copy(veins.begin(), veins.end(), v_buf);
vein_struct->veins = v_buf;
}
if(frozen_veins.size() > 0)
{
((*alloc_frozenliquidvein_buffer_callback)(&fv_buf, frozen_veins.size()));
if(fv_buf == NULL)
return -1;
copy(frozen_veins.begin(), frozen_veins.end(), fv_buf);
vein_struct->frozen_veins = fv_buf;
}
if(spatter_veins.size() > 0)
{
((*alloc_spattervein_buffer_callback)(&sv_buf, spatter_veins.size()));
if(sv_buf == NULL)
return -1;
copy(spatter_veins.begin(), spatter_veins.end(), sv_buf);
vein_struct->spatter_veins = sv_buf;
}
if(grass_veins.size() > 0)
{
((*alloc_grassvein_buffer_callback)(&gs_buf, grass_veins.size()));
if(gs_buf == NULL)
return -1;
copy(grass_veins.begin(), grass_veins.end(), gs_buf);
vein_struct->grass_veins = gs_buf;
}
if(constructions.size() > 0)
{
((*alloc_worldconstruction_buffer_callback)(&ct_buf, constructions.size()));
if(ct_buf == NULL)
return -1;
copy(constructions.begin(), constructions.end(), ct_buf);
vein_struct->world_constructions = ct_buf;
}
return 1;
}
else
return 0;
}
return -1;
}
#ifdef __cplusplus
}
#endif

@ -32,7 +32,10 @@ int Materials_ReadInorganicMaterials(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadInorganicMaterials();
if(((DFHack::Materials*)mat)->ReadInorganicMaterials() == true)
return 1;
else
return 0;
}
return -1;
@ -42,7 +45,10 @@ int Materials_ReadOrganicMaterials(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadOrganicMaterials();
if(((DFHack::Materials*)mat)->ReadOrganicMaterials() == true)
return 1;
else
return 0;
}
return -1;
@ -52,7 +58,10 @@ int Materials_ReadWoodMaterials(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadWoodMaterials();
if(((DFHack::Materials*)mat)->ReadWoodMaterials() == true)
return 1;
else
return 0;
}
return -1;
@ -62,7 +71,10 @@ int Materials_ReadPlantMaterials(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadPlantMaterials();
if(((DFHack::Materials*)mat)->ReadPlantMaterials() == true)
return 1;
else
return 0;
}
return -1;
@ -72,7 +84,10 @@ int Materials_ReadCreatureTypes(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadCreatureTypes();
if(((DFHack::Materials*)mat)->ReadCreatureTypes() == true)
return 1;
else
return 0;
}
return -1;
@ -82,7 +97,10 @@ int Materials_ReadCreatureTypesEx(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadCreatureTypesEx();
if(((DFHack::Materials*)mat)->ReadCreatureTypesEx() == true)
return 1;
else
return 0;
}
return -1;
@ -92,7 +110,10 @@ int Materials_ReadDescriptorColors(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadDescriptorColors();
if(((DFHack::Materials*)mat)->ReadDescriptorColors() == true)
return 1;
else
return 0;
}
return -1;
@ -102,7 +123,10 @@ int Materials_ReadOthers(DFHackObject* mat)
{
if(mat != NULL)
{
return ((DFHack::Materials*)mat)->ReadOthers();
if(((DFHack::Materials*)mat)->ReadOthers() == true)
return 1;
else
return 0;
}
return -1;
@ -237,7 +261,7 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->inorganic.size()));
if(buf != NULL)
{
@ -264,7 +288,7 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->organic.size()));
if(buf != NULL)
{
@ -291,7 +315,7 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->tree.size()));
if(buf != NULL)
{
@ -318,7 +342,7 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->plant.size()));
if(buf != NULL)
{
@ -345,7 +369,7 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->race.size()));
if(buf != NULL)
{
@ -371,18 +395,9 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
{
c_creaturetype* buf = NULL;
if(alloc_creaturetype_buffer_callback == NULL)
return NULL;
((*alloc_creaturetype_buffer_callback)(buf, matSize));
CreatureTypeConvert(((DFHack::Materials*)mat)->raceEx, &buf);
if(buf != NULL)
{
for(int i = 0; i < matSize; i++)
CreatureTypeConvert(&materials->raceEx[i], &buf[i]);
return buf;
}
return buf;
}
}
@ -399,7 +414,7 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat)
{
t_descriptor_color* buf = NULL;
((*alloc_descriptor_buffer_callback)(buf, materials->color.size()));
((*alloc_descriptor_buffer_callback)(&buf, materials->color.size()));
if(buf != NULL)
{
@ -423,7 +438,7 @@ t_matglossOther* Materials_getOther(DFHackObject* mat)
{
t_matglossOther* buf = NULL;
((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size()));
((*alloc_matgloss_other_buffer_callback)(&buf, materials->other.size()));
if(buf != NULL)
{
@ -447,7 +462,7 @@ t_matgloss* Materials_getAllDesc(DFHackObject* mat)
{
t_matgloss* buf = NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->alldesc.size()));
((*alloc_matgloss_buffer_callback)(&buf, materials->alldesc.size()));
if(buf != NULL)
{

@ -104,7 +104,7 @@ t_hotkey* Position_ReadHotkeys(DFHackObject* pos)
{
t_hotkey* buf = NULL;
(*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS);
(*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS);
if(buf != NULL)
{
@ -146,7 +146,7 @@ t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t heig
{
t_screen* buf = NULL;
(*alloc_t_screen_buffer_callback)(buf, width * height);
(*alloc_t_screen_buffer_callback)(&buf, width * height);
if(buf == NULL)
return NULL;

@ -58,64 +58,6 @@ int Translation_Finish(DFHackObject* trans)
return -1;
}
// char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
// {
// if(trans != NULL)
// {
// std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, true);
// if(nameTrans.size() > 0)
// {
// char* buf = (*char_buffer_create)(nameTrans.size());
// if(buf != NULL)
// {
// size_t len = nameTrans.copy(buf, nameTrans.size());
// if(len > 0)
// buf[len] = '\0';
// else
// buf[0] = '\0';
// }
// return buf;
// }
// else
// return NULL;
// }
// return NULL;
// }
// char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int))
// {
// if(trans != NULL)
// {
// std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, false);
// if(nameTrans.size() > 0)
// {
// char* buf = (*char_buffer_create)(nameTrans.size());
// if(buf != NULL)
// {
// size_t len = nameTrans.copy(buf, nameTrans.size());
// if(len > 0)
// buf[len] = '\0';
// else
// buf[0] = '\0';
// }
// return buf;
// }
// else
// return NULL;
// }
// return NULL;
// }
char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name)
{
if(trans != NULL)
@ -126,7 +68,7 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name
{
char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size());
(*alloc_char_buffer_callback)(&buf, nameTrans.size());
if(buf != NULL)
{
@ -157,7 +99,7 @@ char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_n
{
char* buf = NULL;
(*alloc_char_buffer_callback)(buf, nameTrans.size());
(*alloc_char_buffer_callback)(&buf, nameTrans.size());
if(buf != NULL)
{

@ -4,6 +4,10 @@ import util
libdfhack.Creatures_WriteLabors.argtypes = [ c_void_p, c_uint, POINTER(c_ubyte) ]
libdfhack.Creatures_ReadJob.restype = POINTER(Material)
libdfhack.Creatures_ReadInventoryIdx.restype = POINTER(c_uint)
libdfhack.Creatures_ReadInventoryPtr.restype = POINTER(c_uint)
class Creatures(object):
def __init__(self, ptr):
print ptr
@ -45,7 +49,14 @@ class Creatures(object):
return libdfhack.Creatures_WriteLabors(self._c_ptr, c_uint(index), labors) > 0
def read_job(self, creature):
return libdfhack.Creatures_ReadJob(self._c_ptr, byref(creature))
job_ptr = libdfhack.Creatures_ReadJob(self._c_ptr, byref(creature))
jobs = None
if id(job_ptr) in dftypes.pointer_dict:
jobs = dftypes.pointer_dict[id(job_ptr)][1]
del dftypes.pointer_dict[id(job_ptr)]
return jobs
@property
def dwarf_race_index(self):

@ -1,22 +1,25 @@
from ctypes import *
from flags import *
from enum import *
import util
from util import *
libdfhack = cdll.libdfhack
libdfhack.alloc_byte_buffer_callback = alloc_byte_buffer
libdfhack.alloc_ubyte_buffer_callback = alloc_ubyte_buffer
libdfhack.alloc_short_buffer_callback = alloc_short_buffer
libdfhack.alloc_ushort_buffer_callback = alloc_ushort_buffer
libdfhack.alloc_int_buffer_callback = alloc_int_buffer
libdfhack.alloc_uint_buffer_callback = alloc_uint_buffer
libdfhack.alloc_char_buffer_callback = alloc_char_buffer
def _register_callback(name, func):
ptr = c_void_p.in_dll(libdfhack, name)
ptr.value = cast(func, c_void_p).value
int_ptr = POINTER(c_int)
uint_ptr = POINTER(c_uint)
_register_callback("alloc_byte_buffer_callback", alloc_byte_buffer)
_register_callback("alloc_ubyte_buffer_callback", alloc_ubyte_buffer)
_register_callback("alloc_short_buffer_callback", alloc_short_buffer)
_register_callback("alloc_ushort_buffer_callback", alloc_ushort_buffer)
_register_callback("alloc_int_buffer_callback", alloc_int_buffer)
_register_callback("alloc_uint_buffer_callback", alloc_uint_buffer)
_register_callback("alloc_char_buffer_callback", alloc_char_buffer)
_arr_create_func = CFUNCTYPE(c_void_p, c_int)
_dfhack_string = (c_char * 128)
TileTypes40d = ((c_int * 16) * 16)
BiomeIndices40d = c_ubyte * 16
@ -70,30 +73,28 @@ class Vein(Structure):
("flags", c_uint),
("address_of", c_uint)]
def _alloc_vein_buffer_callback(ptr, count):
allocated = _allocate_array(Vein, count)
ptr = addressof(allocated[0])
_vein_ptr = POINTER(Vein)
return 1
def _alloc_vein_buffer_callback(ptr, count):
return util._allocate_array(ptr, Vein, count)
_vein_functype = CFUNCTYPE(c_int, POINTER(Vein), c_uint)
libdfhack.alloc_vein_buffer_callback = _vein_functype(_alloc_vein_buffer_callback)
_vein_functype = CFUNCTYPE(c_int, POINTER(_vein_ptr), c_uint)
_vein_func = _vein_functype(_alloc_vein_buffer_callback)
_register_callback("alloc_vein_buffer_callback", _vein_func)
class FrozenLiquidVein(Structure):
_fields_ = [("vtable", c_uint),
("tiles", TileTypes40d),
("address_of", c_uint)]
def _alloc_frozenliquidvein_buffer_callback(ptr, count):
allocated = _allocate_array(FrozenLiquidVein, count)
ptr = addressof(allocated[0])
_frozenvein_ptr = POINTER(FrozenLiquidVein)
return 1
def _alloc_frozenliquidvein_buffer_callback(ptr, count):
return util._allocate_array(ptr, FrozenLiquidVein, count)
_frozenliquidvein_functype = CFUNCTYPE(c_int, POINTER(FrozenLiquidVein), c_uint)
libdfhack.alloc_frozenliquidvein_buffer_callback = _frozenliquidvein_functype(_alloc_frozenliquidvein_buffer_callback)
_frozenliquidvein_functype = CFUNCTYPE(c_int, POINTER(_frozenvein_ptr), c_uint)
_frozenliquidvein_func = _frozenliquidvein_functype(_alloc_frozenliquidvein_buffer_callback)
_register_callback("alloc_frozenliquidvein_buffer_callback", _frozenliquidvein_func)
class SpatterVein(Structure):
_fields_ = [("vtable", c_uint),
@ -104,15 +105,14 @@ class SpatterVein(Structure):
("intensity", ((c_ubyte * 16) * 16)),
("address_of", c_uint)]
def _alloc_spattervein_buffer_callback(ptr, count):
allocated = _allocate_array(SpatterVein, count)
ptr = addressof(allocated[0])
_spattervein_ptr = POINTER(SpatterVein)
return 1
def _alloc_spattervein_buffer_callback(ptr, count):
return util._allocate_array(ptr, SpatterVein, count)
_spattervein_functype = CFUNCTYPE(c_int, POINTER(SpatterVein), c_uint)
libdfhack.alloc_spatter_buffer_callback = _spattervein_functype(_alloc_spattervein_buffer_callback)
_spattervein_functype = CFUNCTYPE(c_int, POINTER(_spattervein_ptr), c_uint)
_spattervein_func = _spattervein_functype(_alloc_spattervein_buffer_callback)
_register_callback("alloc_spattervein_buffer_callback", _spattervein_func)
class GrassVein(Structure):
_fields_ = [("vtable", c_uint),
@ -120,15 +120,14 @@ class GrassVein(Structure):
("intensity", ((c_ubyte * 16) * 16)),
("address_of", c_uint)]
_grassvein_ptr = POINTER(GrassVein)
def _alloc_grassvein_buffer_callback(ptr, count):
allocated = _allocate_array(GrassVein, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, GrassVein, count)
_grassvein_functype = CFUNCTYPE(c_int, POINTER(GrassVein), c_uint)
libdfhack.alloc_grassvein_buffer_callback = _grassvein_functype(_alloc_grassvein_buffer_callback)
_grassvein_functype = CFUNCTYPE(c_int, POINTER(_grassvein_ptr), c_uint)
_grassvein_func = _grassvein_functype(_alloc_grassvein_buffer_callback)
_register_callback("alloc_grassvein_buffer_callback", _grassvein_func)
class WorldConstruction(Structure):
_fields_ = [("vtable", c_uint),
@ -136,15 +135,14 @@ class WorldConstruction(Structure):
("assignment", c_ushort * 16),
("address_of", c_uint)]
_worldconstruction_ptr = POINTER(WorldConstruction)
def _alloc_worldconstruction_buffer_callback(ptr, count):
allocated = _allocate_array(WorldConstruction, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, WorldConstruction, count)
_worldconstruction_functype = CFUNCTYPE(c_int, POINTER(WorldConstruction), c_uint)
libdfhack.alloc_worldconstruction_buffer_callback = _worldconstruction_functype(_alloc_worldconstructrion_buffer_callback)
_worldconstruction_functype = CFUNCTYPE(c_int, POINTER(_worldconstruction_ptr), c_uint)
_worldconstruction_func = _worldconstruction_functype(_alloc_worldconstruction_buffer_callback)
_register_callback("alloc_worldconstruction_buffer_callback", _worldconstruction_func)
class MapBlock40d(Structure):
_fields_ = [("tiletypes", TileTypes40d),
@ -161,55 +159,58 @@ class ViewScreen(Structure):
_fields_ = [("type", c_int)]
class Matgloss(Structure):
_fields_ = [("id", c_char * 128),
_fields_ = [("id", _dfhack_string),
("fore", c_byte),
("back", c_byte),
("bright", c_byte),
("name", c_char * 128)]
("name", _dfhack_string)]
def _alloc_matgloss_buffer_callback(ptr, count):
allocated = _allocate_array(Matgloss, count)
ptr = addressof(allocated[0])
_matgloss_ptr = POINTER(Matgloss)
return 1
def _alloc_matgloss_buffer_callback(ptr, count):
return util._allocate_array(ptr, Matgloss, count)
_matgloss_functype = CFUNCTYPE(c_int, POINTER(Matgloss), c_uint)
libdfhack.alloc_matgloss_buffer_callback = _matgloss_functype(_alloc_matgloss_buffer_callback)
_matgloss_functype = CFUNCTYPE(c_int, POINTER(_matgloss_ptr), c_uint)
_matgloss_func = _matgloss_functype(_alloc_matgloss_buffer_callback)
_register_callback("alloc_matgloss_buffer_callback", _matgloss_func)
class MatglossPair(Structure):
_fields_ = [("type", c_short),
("index", c_int)]
class DescriptorColor(Structure):
_fields_ = [("id", c_char * 128),
_fields_ = [("id", _dfhack_string),
("r", c_float),
("v", c_float),
("b", c_float),
("name", c_char * 128)]
("name", _dfhack_string)]
def _alloc_descriptor_buffer_callback(ptr, count):
allocated = _allocate_array(DescriptorColor, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, DescriptorColor, count)
_descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint)
libdfhack.alloc_descriptor_buffer_callback = _descriptor_functype(_alloc_descriptor_buffer_callback)
_descriptor_func = _descriptor_functype(_alloc_descriptor_buffer_callback)
_register_callback("alloc_descriptor_buffer_callback", _descriptor_func)
class MatglossPlant(Structure):
_fields_ = [("id", _dfhack_string),
("fore", c_ubyte),
("back", c_ubyte),
("bright", c_ubyte),
("name", _dfhack_string),
("drink_name", _dfhack_string),
("food_name", _dfhack_string),
("extract_name", _dfhack_string)]
class MatglossOther(Structure):
_fields_ = [("rawname", c_char * 128)]
def _alloc_matgloss_other_buffer_callback(count):
allocated = _allocate_array(MatglossOther, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, MatglossOther, count)
_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint)
libdfhack.alloc_matgloss_other_buffer_callback = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
_matgloss_other_func = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
_register_callback("alloc_matgloss_other_buffer_callback", _matgloss_other_func)
class Building(Structure):
_fields_ = [("origin", c_uint),
@ -227,14 +228,11 @@ class CustomWorkshop(Structure):
("name", c_char * 256)]
def _alloc_custom_workshop_buffer_callback(count):
allocated = _allocate_array(CustomWorkshop, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, CustomWorkshop, count)
_custom_workshop_functype = CFUNCTYPE(c_int, POINTER(CustomWorkshop), c_uint)
libdfhack.alloc_t_customWorkshop_buffer_callback = _custom_workshop_functype(_alloc_custom_workshop_buffer_callback)
_custom_workshop_func = _custom_workshop_functype(_alloc_custom_workshop_buffer_callback)
_register_callback("alloc_t_customWorkshop_buffer_callback", _custom_workshop_func)
class Construction(Structure):
_fields_ = [("x", c_ushort),
@ -266,14 +264,11 @@ class Material(Structure):
("flags", c_uint)]
def _alloc_material_buffer_callback(count):
allocated = _allocate_array(Material, count)
ptr = addressof(allocated[0])
return 1
return util._allocate_array(ptr, Material, count)
_material_functype = CFUNCTYPE(c_int, POINTER(Material), c_uint)
libdfhack.alloc_t_material_buffer_callback = _material_functype(_alloc_material_buffer_callback)
_material_func = _material_functype(_alloc_material_buffer_callback)
_register_callback("alloc_t_material_buffer_callback", _material_func)
class Skill(Structure):
_fields_ = [("id", c_uint),
@ -303,8 +298,8 @@ class Attribute(Structure):
("field_18", c_uint)]
class Name(Structure):
_fields_ = [("first_name", (c_char * 128)),
("nickname", (c_char * 128)),
_fields_ = [("first_name", _dfhack_string),
("nickname", _dfhack_string),
("words", (c_int * 7)),
("parts_of_speech", (c_ushort * 7)),
("language", c_uint),
@ -314,7 +309,7 @@ class Note(Structure):
_fields_ = [("symbol", c_char),
("foreground", c_ushort),
("background", c_ushort),
("name", (c_char * 128)),
("name", _dfhack_string),
("x", c_ushort),
("y", c_ushort),
("z", c_ushort)]
@ -366,7 +361,7 @@ class Creature(Structure):
("mood_skill", c_short),
("artifact_name", Name),
("profession", c_ubyte),
("custom_profession", (c_char * 128)),
("custom_profession", _dfhack_string),
("labors", (c_ubyte * _NUM_CREATURE_LABORS)),
("current_job", Job),
("happiness", c_uint),
@ -385,36 +380,148 @@ class Creature(Structure):
("defaultSoul", Soul),
("nbcolors", c_uint),
("color", (c_uint * _MAX_COLORS)),
("birth_year", c_uint),
("birth_year", c_int),
("birth_time", c_uint)]
class CreatureExtract(Structure):
_fields_ = [("rawname", (c_char * 128))]
_fields_ = [("rawname", _dfhack_string)]
class BodyPart(Structure):
_fields_ = [("id", (c_char * 128)),
("category", (c_char * 128)),
("single", (c_char * 128)),
("plural", (c_char * 128))]
_fields_ = [("id", _dfhack_string),
("category", _dfhack_string),
("single", _dfhack_string),
("plural", _dfhack_string)]
class ColorModifier(Structure):
_fields_ = [("part", (c_char * 128)),
_fields_ = [("part", _dfhack_string),
("colorlist", POINTER(c_uint)),
("colorlistLength", c_uint)]
("colorlistLength", c_uint),
("startdate", c_uint),
("enddate", c_uint)]
def __init__(self):
self.part[0] = '\0'
self.colorlistLength = 0
ColorModifierPtr = POINTER(ColorModifier)
def _alloc_empty_colormodifier_callback(ptr):
ptr = ColorModifierPtr(ColorModifier())
_colormodifier_ptr = POINTER(ColorModifier)
class CreatureCaste(Structure):
_fields_ = [("rawname", _dfhack_string),
("singular", _dfhack_string),
("plural", _dfhack_string),
("adjective", _dfhack_string),
("color_modifier", _colormodifier_ptr),
("color_modifier_length", c_uint),
("bodypart", POINTER(BodyPart)),
("bodypart_length", c_uint),
("strength", Attribute),
("agility", Attribute),
("toughness", Attribute),
("endurance", Attribute),
("recuperation", Attribute),
("disease_resistance", Attribute),
("analytical_ability", Attribute),
("focus", Attribute),
("willpower", Attribute),
("creativity", Attribute),
("intuition", Attribute),
("patience", Attribute),
("memory", Attribute),
("linguistic_ability", Attribute),
("spatial_sense", Attribute),
("musicality", Attribute),
("kinesthetic_sense", Attribute)]
_creaturecaste_ptr = POINTER(CreatureCaste)
class TileColor(Structure):
_fields_ = [("fore", c_ushort),
("back", c_ushort),
("bright", c_ushort)]
class ColorDescriptor(Structure):
_fields_ = [("colorlistLength", c_uint)]
class CasteDescriptor(Structure):
_fields_ = [("color_descriptors", POINTER(ColorDescriptor)),
("colorModifierLength", c_uint),
("bodypartLength", c_uint)]
class CreatureTypeDescriptor(Structure):
_fields_ = [("caste_descriptors", POINTER(CasteDescriptor)),
("castesCount", c_uint),
("extractCount", c_uint)]
class CreatureType(Structure):
_fields_ = [("rawname", _dfhack_string),
("castes", _creaturecaste_ptr),
("castes_count", c_uint),
("extract", POINTER(CreatureExtract)),
("extract_count", c_uint),
("tile_character", c_ubyte),
("tilecolor", TileColor)]
_creaturetype_ptr = POINTER(CreatureType)
def _alloc_creaturetype_buffer(ptr, descriptors, count):
arr_list = []
c_arr = (CreatureType * count)()
for i, v in enumerate(c_arr):
v.castesCount = descriptors[i].castesCount
v_caste_arr = (CreatureCaste * v.castesCount)()
for j, v_c in enumerate(v_caste_arr):
caste_descriptor = descriptors[i].caste_descriptors[j]
v_c.colorModifierLength = caste_descriptor.colorModifierLength
c_color_arr = (ColorModifier * v_c.colorModifierLength)()
for k, c_c in enumerate(c_color_arr):
color_descriptor = caste_descriptor.color_descriptors[k]
c_c.colorlistLength = color_descriptor.colorlistLength
c_color_list_arr = (c_uint * c_c.colorlistLength)()
p = cast(c_color_list_arr, POINTER(c_uint))
c_c.colorlist = p
arr_list.extend((c_color_list_arr, p))
c_p = cast(c_color_arr, POINTER(ColorModifier))
v_c.colorModifier = c_p
v_c.bodypartLength = caste_descriptor.bodypartLength
c_bodypart_arr = (BodyPart * v_c.bodypartLength)()
b_p = cast(c_bodypart_arr, POINTER(BodyPart))
v_c.bodypart = b_p
arr_list.extend((c_color_arr, c_p, c_bodypart_arr, b_p))
v.extractCount = descriptors[i].extractCount
v_extract_arr = (CreatureExtract * v.extractCount)()
caste_p = cast(v_caste_arr, POINTER(CreatureCaste))
v.castes = caste_p
extract_p = cast(v_extract_arr, POINTER(CreatureExtract))
v.extract = extract_p
arr_list.extend((v_caste_arr, caste_p, v_extract_arr, extract_p))
p = cast(c_arr, _creaturetype_ptr)
ptr[0] = p
print ""
pointer_dict[addressof(c_arr)] = (ptr, c_arr, p, arr_list)
return 1
_empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr)
libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback)
_alloc_creaturetype_buffer_functype = CFUNCTYPE(c_int, POINTER(_creaturetype_ptr), POINTER(CreatureTypeDescriptor), c_uint)
_alloc_creaturetype_buffer_func = _alloc_creaturetype_buffer_functype(_alloc_creaturetype_buffer)
_register_callback("alloc_creaturetype_buffer_callback", _alloc_creaturetype_buffer_func)
class GameModes(Structure):
_fields_ = [("control_mode", c_ubyte),

@ -23,6 +23,12 @@ libdfhack.Maps_ReadSpatterVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadGrassVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadWorldConstructions.argtypes = _default_argtypes
libdfhack.Maps_ReadStandardVeins.restype = POINTER(Vein)
libdfhack.Maps_ReadFrozenVeins.restype = POINTER(FrozenLiquidVein)
libdfhack.Maps_ReadSpatterVeins.restype = POINTER(SpatterVein)
libdfhack.Maps_ReadGrassVeins.restype = POINTER(GrassVein)
libdfhack.Maps_ReadWorldConstructions.restype = POINTER(WorldConstruction)
class Maps(object):
def __init__(self, ptr):
self._map_ptr = ptr
@ -162,27 +168,62 @@ class Maps(object):
def read_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadStandardVeins(self._map_ptr, ux, uy, uz)
veins_ptr = libdfhack.Maps_ReadStandardVeins(self._map_ptr, ux, uy, uz)
veins = None
if id(veins_ptr) in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1]
del dftypes.pointer_dict[id(veins_ptr)]
return veins
def read_frozen_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadFrozenVeins(self._map_ptr, ux, uy, uz)
veins_ptr = libdfhack.Maps_ReadFrozenVeins(self._map_ptr, ux, uy, uz)
veins = None
if id(veins_ptr) in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1]
del dftypes.pointer_dict[id(veins_ptr)]
return veins
def read_spatter_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz)
veins_ptr = libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz)
veins = None
if id(veins_ptr) in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1]
del dftypes.pointer_dict[id(veins_ptr)]
return veins
def read_grass_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz)
veins_ptr = libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz)
veins = None
if id(veins_ptr) in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1]
del dftypes.pointer_dict[id(veins_ptr)]
return veins
def read_world_constructions(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz)
veins_ptr = libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz)
veins = None
if id(veins_ptr) in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1]
del dftypes.pointer_dict[id(veins_ptr)]
return veins
@property
def size(self):

@ -1,6 +1,16 @@
from ctypes import *
from dftypes import libdfhack
from util import *
import dftypes
from dftypes import libdfhack, Matgloss, CreatureType, DescriptorColor, MatglossOther
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
class Materials(object):
def __init__(self, ptr):
@ -16,21 +26,60 @@ class Materials(object):
self.other = None
def _get_inorganic(self):
self.inorganic = libdfhack.Materials_getInorganic(self._mat_ptr)
inorganic = libdfhack.Materials_getInorganic(self._mat_ptr)
if inorganic in dftypes.pointer_dict:
self.inorganic = [i for i in dftypes.pointer_dict[inorganic][1]]
del dftypes.pointer_dict[inorganic]
def _get_organic(self):
self.organic = libdfhack.Materials_getOrganic(self._mat_ptr)
organic = libdfhack.Materials_getOrganic(self._mat_ptr)
if organic in dftypes.pointer_dict:
self.organic = [i for i in dftypes.pointer_dict[organic][1]]
del dftypes.pointer_dict[organic]
def _get_tree(self):
self.tree = libdfhack.Materials_getTree(self._mat_ptr)
tree = libdfhack.Materials_getTree(self._mat_ptr)
if tree in dftypes.pointer_dict:
self.tree = [i for i in dftypes.pointer_dict[tree][1]]
del dftypes.pointer_dict[tree]
def _get_plant(self):
self.plant = libdfhack.Materials_getPlant(self._mat_ptr)
plant = libdfhack.Materials_getPlant(self._mat_ptr)
if plant in dftypes.pointer_dict:
self.plant = [i for i in dftypes.pointer_dict[plant][1]]
del dftypes.pointer_dict[plant]
def _get_race(self):
self.race = libdfhack.Materials_getRace(self._mat_ptr)
race = libdfhack.Materials_getRace(self._mat_ptr)
if race in dftypes.pointer_dict:
self.race = [i for i in dftypes.pointer_dict[race][1]]
del dftypes.pointer_dict[race]
def _get_race_ex(self):
self.race_ex = libdfhack.Materials_getRaceEx(self._mat_ptr)
race_ex = libdfhack.Materials_getRaceEx(self._mat_ptr)
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]
def _get_color(self):
self.color = libdfhack.Materials_getColor(self._mat_ptr)
color = libdfhack.Materials_getColor(self._mat_ptr)
if color in dftypes.pointer_dict:
self.color = [i for i in dftypes.pointer_dict[color][1]]
del dftypes.pointer_dict[color]
def _get_other(self):
self.other = libdfhack.Materials_getOther(self._mat_ptr)
other = libdfhack.Materials_getOther(self._mat_ptr)
if other in dftypes.pointer_dict:
self.other = [i for i in dftypes.pointer_dict[other][1]]
del dftypes.pointer_dict[other]
def _get_all(self):
self._get_inorganic()

@ -1,90 +1,76 @@
from ctypes import *
uint_ptr = POINTER(c_uint)
int_ptr = POINTER(c_int)
uint_ptr = POINTER(c_uint)
def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z))
def _allocate_array(t_type, count):
arr_type = t_type * count
arr = arr_type()
short_ptr = POINTER(c_short)
ushort_ptr = POINTER(c_ushort)
ptr = c_void_p()
ptr = addressof(arr)
byte_ptr = POINTER(c_byte)
ubyte_ptr = POINTER(c_ubyte)
return (arr, ptr)
pointer_dict = {}
def _alloc_int_buffer(ptr, count):
a = _allocate_array(c_int, count)
def _uintify(x, y, z):
return (c_uint(x), c_uint(y), c_uint(z))
ptr = addressof(a[0])
def _allocate_array(ptr, t_type, count):
arr = (t_type * count)()
p = cast(arr, POINTER(t_type))
ptr[0] = p
pointer_dict[addressof(arr)] = (ptr, arr, p)
return 1
_int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
def _alloc_int_buffer(ptr, count):
return _allocate_array(ptr, c_int, count)
_int_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_int)), c_uint)
alloc_int_buffer = _int_functype(_alloc_int_buffer)
def _alloc_uint_buffer(ptr, count):
a = _allocate_array(c_uint, count)
ptr = addressof(a[0])
return 1
return _allocate_array(ptr, c_uint, count)
_uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
_uint_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_uint)), c_uint)
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
def _alloc_short_buffer(ptr, count):
a = _allocate_array(c_short, count)
return _allocate_array(ptr, c_short, count)
ptr = addressof(a[0])
return 1
_short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
_short_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_short)), c_uint)
alloc_short_buffer = _short_functype(_alloc_short_buffer)
def _alloc_ushort_buffer(ptr, count):
a = _allocate_array(c_ushort, count)
ptr = addressof(a[0])
return _allocate_array(ptr, c_ushort, count)
return 1
_ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
_ushort_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ushort)), c_uint)
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
def _alloc_byte_buffer(ptr, count):
a = _allocate_array(c_byte, count)
ptr = addressof(a[0])
return _allocate_array(ptr, c_byte, count)
return 1
_byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
_byte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_byte)), c_uint)
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
def _alloc_ubyte_buffer(ptr, count):
a = _allocate_array(c_ubyte, count)
ptr = addressof(a[0])
return _allocate_array(ptr, c_ubyte, count)
return 1
_ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
_ubyte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ubyte)), c_uint)
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
def _alloc_char_buffer(ptr, count):
c = create_string_buffer(count)
p = cast(c, POINTER(c_char))
if ptr is None:
ptr = c_void_p
ptr = addressof(c)
ptr[0] = p
pointer_dict[id(ptr[0])] = (ptr, c, p)
return 1
_char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
_char_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_char)), c_uint)
alloc_char_buffer = _char_functype(_alloc_char_buffer)