updated creature caste and type structs

removed some (now) unneeded callbacks
made a better t_creaturetype -> c_creaturetype converter
develop
doomchild 2011-03-11 14:08:53 -06:00
parent 1de2efb162
commit b75f513238
2 changed files with 183 additions and 136 deletions

@ -89,17 +89,7 @@ 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_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;
@ -107,6 +97,7 @@ 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)
@ -139,74 +130,13 @@ 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**))
{
alloc_empty_colormodifier_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()
void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t))
{
alloc_colormodifier_callback = NULL;
alloc_creaturetype_buffer_callback = funcptr;
}
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)
@ -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;
}
}

@ -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
{
@ -140,19 +135,32 @@ struct c_creaturecaste
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,9 +182,14 @@ 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_creaturetype_buffer_callback)(c_creaturetype**, c_creaturetype_descriptor*, 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);
@ -184,9 +197,7 @@ DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein**, u
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 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 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));
@ -194,8 +205,6 @@ DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervei
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