This is how code should look as of now, feel free to propose any API changes.
Loop over all loaded objects:
for (auto primaryID : VLC->objtypeh->knownObjects())
{
for (auto secondaryID : VLC->objtypeh->knownSubObjects(primaryID))
{
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
// do things here
}
}
To select static object aka obstacle:
if (handler->isStaticObject()) // will return true for objects with "static" handler in config
{
for (auto template : handler->getTemplates(tile.tertype))
{
// choose obstacle based on blockmap, see ObjectTemplate methods for access to it
}
}
Note that values reported by width/height are not sizes of blockmap - instead they should correspond with that border that H3 editor displays around objects (read: much bigger). And if .msk for this object is missing this difference may be even bigger.
To select treasure object:
First we need to fill our config with RMG data (value, rarity, max per zone, etc). VCMI can read this data but as of now we don’t have it in our configs. I’m planning to ask for help with configs after dev build or do it myself a bit later if there won’t be volunteers.
Once this will be fixed code you can use method handler->getRMGInfo() to access rmg data. For static objects or those that are not “treasures” (e.g. towns) it will have 0 map limit & 0 zone limit, for valid objects without such limits these fields will be set to std::numeric_limits::max()
To create object once you selected template:
VLC->objtypeh->getHandlerFor(template.id, template.subid)->create(template);
(I really need override that accepts template instead of 2 id’s)
It will create object with already set id/subid as well as assigned template. For some objects that were already converted (banks and dwellings) it will also properly configure them - creatures/guards for dwellings, guards/reward for banks.
Ideally I want to extend this to all objects but this will take time and may not be possible for some objects like heroes/towns - they are just too complex.