mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-07 00:58:39 +02:00
Use CompoundMapObjectID in ObjectInfo
This commit is contained in:
@ -32,16 +32,12 @@ void ObjectConfig::addBannedObject(const CompoundMapObjectID & objid)
|
|||||||
|
|
||||||
void ObjectConfig::addCustomObject(const ObjectInfo & object, const CompoundMapObjectID & objid)
|
void ObjectConfig::addCustomObject(const ObjectInfo & object, const CompoundMapObjectID & objid)
|
||||||
{
|
{
|
||||||
// FIXME: Need id / subId
|
|
||||||
|
|
||||||
// FIXME: Add templates and possibly other info
|
|
||||||
customObjects.push_back(object);
|
customObjects.push_back(object);
|
||||||
auto & lastObject = customObjects.back();
|
auto & lastObject = customObjects.back();
|
||||||
lastObject.setAllTemplates(objid.primaryID, objid.secondaryID);
|
lastObject.setAllTemplates(objid.primaryID, objid.secondaryID);
|
||||||
|
|
||||||
assert(lastObject.templates.size() > 0);
|
assert(lastObject.templates.size() > 0);
|
||||||
auto temp = lastObject.templates.front();
|
logGlobal->info("Added custom object of type %d.%d", objid.primaryID, objid.secondaryID);
|
||||||
logGlobal->info("Added custom object of type %d.%d", temp->id, temp->subid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectConfig::serializeJson(JsonSerializeFormat & handler)
|
void ObjectConfig::serializeJson(JsonSerializeFormat & handler)
|
||||||
@ -154,7 +150,7 @@ void ObjectConfig::serializeJson(JsonSerializeFormat & handler)
|
|||||||
VLC->objtypeh->resolveObjectCompoundId(objectName,
|
VLC->objtypeh->resolveObjectCompoundId(objectName,
|
||||||
[this, objectValue, objectProbability, objectMaxPerZone](CompoundMapObjectID objid)
|
[this, objectValue, objectProbability, objectMaxPerZone](CompoundMapObjectID objid)
|
||||||
{
|
{
|
||||||
ObjectInfo object;
|
ObjectInfo object(objid.primaryID, objid.secondaryID);
|
||||||
|
|
||||||
// TODO: Configure basic generateObject function
|
// TODO: Configure basic generateObject function
|
||||||
|
|
||||||
|
@ -18,15 +18,24 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
ObjectInfo::ObjectInfo():
|
ObjectInfo::ObjectInfo(si32 ID, si32 subID):
|
||||||
|
primaryID(ID),
|
||||||
|
secondaryID(subID),
|
||||||
destroyObject([](CGObjectInstance * obj){}),
|
destroyObject([](CGObjectInstance * obj){}),
|
||||||
maxPerZone(std::numeric_limits<ui32>::max())
|
maxPerZone(std::numeric_limits<ui32>::max())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectInfo::ObjectInfo(CompoundMapObjectID id):
|
||||||
|
ObjectInfo(id.primaryID, id.secondaryID)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ObjectInfo::ObjectInfo(const ObjectInfo & other)
|
ObjectInfo::ObjectInfo(const ObjectInfo & other)
|
||||||
{
|
{
|
||||||
templates = other.templates;
|
templates = other.templates;
|
||||||
|
primaryID = other.primaryID;
|
||||||
|
secondaryID = other.secondaryID;
|
||||||
value = other.value;
|
value = other.value;
|
||||||
probability = other.probability;
|
probability = other.probability;
|
||||||
maxPerZone = other.maxPerZone;
|
maxPerZone = other.maxPerZone;
|
||||||
@ -40,6 +49,8 @@ ObjectInfo & ObjectInfo::operator=(const ObjectInfo & other)
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
templates = other.templates;
|
templates = other.templates;
|
||||||
|
primaryID = other.primaryID;
|
||||||
|
secondaryID = other.secondaryID;
|
||||||
value = other.value;
|
value = other.value;
|
||||||
probability = other.probability;
|
probability = other.probability;
|
||||||
maxPerZone = other.maxPerZone;
|
maxPerZone = other.maxPerZone;
|
||||||
@ -66,4 +77,9 @@ void ObjectInfo::setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainI
|
|||||||
templates = templHandler->getTemplates(terrainType);
|
templates = templHandler->getTemplates(terrainType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompoundMapObjectID ObjectInfo::getCompoundID() const
|
||||||
|
{
|
||||||
|
return CompoundMapObjectID(primaryID, secondaryID);
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
@ -20,11 +20,14 @@ class CGObjectInstance;
|
|||||||
|
|
||||||
struct DLL_LINKAGE ObjectInfo
|
struct DLL_LINKAGE ObjectInfo
|
||||||
{
|
{
|
||||||
ObjectInfo();
|
ObjectInfo(si32 ID, si32 subID);
|
||||||
|
ObjectInfo(CompoundMapObjectID id);
|
||||||
ObjectInfo(const ObjectInfo & other);
|
ObjectInfo(const ObjectInfo & other);
|
||||||
ObjectInfo & operator=(const ObjectInfo & other);
|
ObjectInfo & operator=(const ObjectInfo & other);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<const ObjectTemplate>> templates;
|
std::vector<std::shared_ptr<const ObjectTemplate>> templates;
|
||||||
|
si32 primaryID;
|
||||||
|
si32 secondaryID;
|
||||||
ui32 value = 0;
|
ui32 value = 0;
|
||||||
ui16 probability = 0;
|
ui16 probability = 0;
|
||||||
ui32 maxPerZone = 1;
|
ui32 maxPerZone = 1;
|
||||||
@ -35,6 +38,7 @@ struct DLL_LINKAGE ObjectInfo
|
|||||||
void setAllTemplates(MapObjectID type, MapObjectSubID subtype);
|
void setAllTemplates(MapObjectID type, MapObjectSubID subtype);
|
||||||
void setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrain);
|
void setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrain);
|
||||||
|
|
||||||
|
CompoundMapObjectID getCompoundID() const;
|
||||||
//bool matchesId(const CompoundMapObjectID & id) const;
|
//bool matchesId(const CompoundMapObjectID & id) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ void ObjectDistributor::init()
|
|||||||
|
|
||||||
void ObjectDistributor::distributeLimitedObjects()
|
void ObjectDistributor::distributeLimitedObjects()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
|
||||||
auto zones = map.getZones();
|
auto zones = map.getZones();
|
||||||
|
|
||||||
for (auto primaryID : VLC->objtypeh->knownObjects())
|
for (auto primaryID : VLC->objtypeh->knownObjects())
|
||||||
@ -81,6 +80,8 @@ void ObjectDistributor::distributeLimitedObjects()
|
|||||||
RandomGeneratorUtil::randomShuffle(matchingZones, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(matchingZones, zone.getRand());
|
||||||
for (auto& zone : matchingZones)
|
for (auto& zone : matchingZones)
|
||||||
{
|
{
|
||||||
|
ObjectInfo oi(primaryID, secondaryID);
|
||||||
|
|
||||||
oi.generateObject = [cb=map.mapInstance->cb, primaryID, secondaryID]() -> CGObjectInstance *
|
oi.generateObject = [cb=map.mapInstance->cb, primaryID, secondaryID]() -> CGObjectInstance *
|
||||||
{
|
{
|
||||||
return VLC->objtypeh->getHandlerFor(primaryID, secondaryID)->create(cb, nullptr);
|
return VLC->objtypeh->getHandlerFor(primaryID, secondaryID)->create(cb, nullptr);
|
||||||
|
@ -47,6 +47,16 @@ void TreasurePlacer::process()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tierValues = generator.getConfig().pandoraCreatureValues;
|
||||||
|
// Add all native creatures
|
||||||
|
for(auto const & cre : VLC->creh->objects)
|
||||||
|
{
|
||||||
|
if(!cre->special && cre->getFaction() == zone.getTownType())
|
||||||
|
{
|
||||||
|
creatures.push_back(cre.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get default objects
|
// Get default objects
|
||||||
addAllPossibleObjects();
|
addAllPossibleObjects();
|
||||||
// Override with custom objects
|
// Override with custom objects
|
||||||
@ -64,19 +74,6 @@ void TreasurePlacer::init()
|
|||||||
DEPENDENCY(ConnectionsPlacer);
|
DEPENDENCY(ConnectionsPlacer);
|
||||||
DEPENDENCY_ALL(PrisonHeroPlacer);
|
DEPENDENCY_ALL(PrisonHeroPlacer);
|
||||||
DEPENDENCY(RoadPlacer);
|
DEPENDENCY(RoadPlacer);
|
||||||
|
|
||||||
// FIXME: Starting zones get Pandoras with neutral creatures
|
|
||||||
|
|
||||||
// Add all native creatures
|
|
||||||
for(auto const & cre : VLC->creh->objects)
|
|
||||||
{
|
|
||||||
if(!cre->special && cre->getFaction() == zone.getTownType())
|
|
||||||
{
|
|
||||||
creatures.push_back(cre.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tierValues = generator.getConfig().pandoraCreatureValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreasurePlacer::addObjectToRandomPool(const ObjectInfo& oi)
|
void TreasurePlacer::addObjectToRandomPool(const ObjectInfo& oi)
|
||||||
@ -112,8 +109,6 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
|
|
||||||
void TreasurePlacer::addCommonObjects()
|
void TreasurePlacer::addCommonObjects()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
|
||||||
|
|
||||||
for(auto primaryID : VLC->objtypeh->knownObjects())
|
for(auto primaryID : VLC->objtypeh->knownObjects())
|
||||||
{
|
{
|
||||||
for(auto secondaryID : VLC->objtypeh->knownSubObjects(primaryID))
|
for(auto secondaryID : VLC->objtypeh->knownSubObjects(primaryID))
|
||||||
@ -127,12 +122,13 @@ void TreasurePlacer::addCommonObjects()
|
|||||||
//Skip objects with per-map limit here
|
//Skip objects with per-map limit here
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ObjectInfo oi(primaryID, secondaryID);
|
||||||
setBasicProperties(oi, CompoundMapObjectID(primaryID, secondaryID));
|
setBasicProperties(oi, CompoundMapObjectID(primaryID, secondaryID));
|
||||||
|
|
||||||
oi.value = rmgInfo.value;
|
oi.value = rmgInfo.value;
|
||||||
oi.probability = rmgInfo.rarity;
|
oi.probability = rmgInfo.rarity;
|
||||||
|
|
||||||
oi.maxPerZone = rmgInfo.zoneLimit;
|
oi.maxPerZone = rmgInfo.zoneLimit;
|
||||||
|
|
||||||
if(!oi.templates.empty())
|
if(!oi.templates.empty())
|
||||||
addObjectToRandomPool(oi);
|
addObjectToRandomPool(oi);
|
||||||
}
|
}
|
||||||
@ -172,7 +168,7 @@ void TreasurePlacer::addPrisons()
|
|||||||
size_t prisonsLeft = getMaxPrisons();
|
size_t prisonsLeft = getMaxPrisons();
|
||||||
for (int i = prisonsLevels - 1; i >= 0; i--)
|
for (int i = prisonsLevels - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
ObjectInfo oi; // Create new instance which will hold destructor operation
|
ObjectInfo oi(Obj::PRISON, 0); // Create new instance which will hold destructor operation
|
||||||
|
|
||||||
oi.value = generator.getConfig().prisonValues[i];
|
oi.value = generator.getConfig().prisonValues[i];
|
||||||
if (oi.value > zone.getMaxTreasureValue())
|
if (oi.value > zone.getMaxTreasureValue())
|
||||||
@ -217,8 +213,6 @@ void TreasurePlacer::addDwellings()
|
|||||||
if(zone.getType() == ETemplateZoneType::WATER)
|
if(zone.getType() == ETemplateZoneType::WATER)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ObjectInfo oi;
|
|
||||||
|
|
||||||
//dwellings
|
//dwellings
|
||||||
auto dwellingTypes = {Obj::CREATURE_GENERATOR1, Obj::CREATURE_GENERATOR4};
|
auto dwellingTypes = {Obj::CREATURE_GENERATOR1, Obj::CREATURE_GENERATOR4};
|
||||||
|
|
||||||
@ -245,6 +239,9 @@ void TreasurePlacer::addDwellings()
|
|||||||
if(cre->getFaction() == zone.getTownType())
|
if(cre->getFaction() == zone.getTownType())
|
||||||
{
|
{
|
||||||
auto nativeZonesCount = static_cast<float>(map.getZoneCount(cre->getFaction()));
|
auto nativeZonesCount = static_cast<float>(map.getZoneCount(cre->getFaction()));
|
||||||
|
ObjectInfo oi(dwellingType, secondaryID);
|
||||||
|
setBasicProperties(oi, CompoundMapObjectID(dwellingType, secondaryID));
|
||||||
|
|
||||||
oi.value = static_cast<ui32>(cre->getAIValue() * cre->getGrowth() * (1 + (nativeZonesCount / map.getTotalZoneCount()) + (nativeZonesCount / 2)));
|
oi.value = static_cast<ui32>(cre->getAIValue() * cre->getGrowth() * (1 + (nativeZonesCount / map.getTotalZoneCount()) + (nativeZonesCount / 2)));
|
||||||
oi.probability = 40;
|
oi.probability = 40;
|
||||||
|
|
||||||
@ -254,7 +251,6 @@ void TreasurePlacer::addDwellings()
|
|||||||
obj->tempOwner = PlayerColor::NEUTRAL;
|
obj->tempOwner = PlayerColor::NEUTRAL;
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
oi.setTemplates(dwellingType, secondaryID, zone.getTerrainType());
|
|
||||||
if(!oi.templates.empty())
|
if(!oi.templates.empty())
|
||||||
addObjectToRandomPool(oi);
|
addObjectToRandomPool(oi);
|
||||||
}
|
}
|
||||||
@ -267,7 +263,7 @@ void TreasurePlacer::addScrolls()
|
|||||||
if(zone.getType() == ETemplateZoneType::WATER)
|
if(zone.getType() == ETemplateZoneType::WATER)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::SPELL_SCROLL, 0);
|
||||||
|
|
||||||
for(int i = 0; i < generator.getConfig().scrollValues.size(); i++)
|
for(int i = 0; i < generator.getConfig().scrollValues.size(); i++)
|
||||||
{
|
{
|
||||||
@ -308,8 +304,7 @@ void TreasurePlacer::addPandoraBoxes()
|
|||||||
|
|
||||||
void TreasurePlacer::addPandoraBoxesWithGold()
|
void TreasurePlacer::addPandoraBoxesWithGold()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::PANDORAS_BOX, 0);
|
||||||
//pandora box with gold
|
|
||||||
for(int i = 1; i < 5; i++)
|
for(int i = 1; i < 5; i++)
|
||||||
{
|
{
|
||||||
oi.generateObject = [this, i]() -> CGObjectInstance *
|
oi.generateObject = [this, i]() -> CGObjectInstance *
|
||||||
@ -334,8 +329,7 @@ void TreasurePlacer::addPandoraBoxesWithGold()
|
|||||||
|
|
||||||
void TreasurePlacer::addPandoraBoxesWithExperience()
|
void TreasurePlacer::addPandoraBoxesWithExperience()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::PANDORAS_BOX, 0);
|
||||||
//pandora box with experience
|
|
||||||
for(int i = 1; i < 5; i++)
|
for(int i = 1; i < 5; i++)
|
||||||
{
|
{
|
||||||
oi.generateObject = [this, i]() -> CGObjectInstance *
|
oi.generateObject = [this, i]() -> CGObjectInstance *
|
||||||
@ -360,9 +354,7 @@ void TreasurePlacer::addPandoraBoxesWithExperience()
|
|||||||
|
|
||||||
void TreasurePlacer::addPandoraBoxesWithCreatures()
|
void TreasurePlacer::addPandoraBoxesWithCreatures()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::PANDORAS_BOX, 0);
|
||||||
//pandora box with creatures
|
|
||||||
|
|
||||||
for(auto * creature : creatures)
|
for(auto * creature : creatures)
|
||||||
{
|
{
|
||||||
int creaturesAmount = creatureToCount(creature);
|
int creaturesAmount = creatureToCount(creature);
|
||||||
@ -391,7 +383,7 @@ void TreasurePlacer::addPandoraBoxesWithCreatures()
|
|||||||
|
|
||||||
void TreasurePlacer::addPandoraBoxesWithSpells()
|
void TreasurePlacer::addPandoraBoxesWithSpells()
|
||||||
{
|
{
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::PANDORAS_BOX, 0);
|
||||||
//Pandora with 12 spells of certain level
|
//Pandora with 12 spells of certain level
|
||||||
for(int i = 1; i <= GameConstants::SPELL_LEVELS; i++)
|
for(int i = 1; i <= GameConstants::SPELL_LEVELS; i++)
|
||||||
{
|
{
|
||||||
@ -494,7 +486,7 @@ void TreasurePlacer::addSeerHuts()
|
|||||||
{
|
{
|
||||||
//Seer huts with creatures or generic rewards
|
//Seer huts with creatures or generic rewards
|
||||||
|
|
||||||
ObjectInfo oi;
|
ObjectInfo oi(Obj::SEER_HUT, 0);
|
||||||
|
|
||||||
if(zone.getConnectedZoneIds().size()) //Unlikely, but...
|
if(zone.getConnectedZoneIds().size()) //Unlikely, but...
|
||||||
{
|
{
|
||||||
@ -1120,7 +1112,7 @@ void TreasurePlacer::ObjectPool::updateObject(MapObjectID id, MapObjectSubID sub
|
|||||||
- Pandora Boxes
|
- Pandora Boxes
|
||||||
*/
|
*/
|
||||||
// FIXME: This will drop all templates
|
// FIXME: This will drop all templates
|
||||||
customObjects[CompoundMapObjectID(id, subid)] = info;
|
customObjects.insert(std::make_pair(CompoundMapObjectID(id, subid), info));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, TreasurePlacer * tp)
|
void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, TreasurePlacer * tp)
|
||||||
@ -1147,8 +1139,7 @@ void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, Treasure
|
|||||||
|
|
||||||
vstd::erase_if(possibleObjects, [this, &categoriesSet](const ObjectInfo & oi) -> bool
|
vstd::erase_if(possibleObjects, [this, &categoriesSet](const ObjectInfo & oi) -> bool
|
||||||
{
|
{
|
||||||
auto temp = oi.templates.front();
|
auto category = getObjectCategory(oi.getCompoundID());
|
||||||
auto category = getObjectCategory(CompoundMapObjectID(temp->id, temp->subid));
|
|
||||||
if (categoriesSet.count(category))
|
if (categoriesSet.count(category))
|
||||||
{
|
{
|
||||||
logGlobal->info("Removing object %s from possible objects", oi.templates.front()->stringID);
|
logGlobal->info("Removing object %s from possible objects", oi.templates.front()->stringID);
|
||||||
@ -1168,7 +1159,7 @@ void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, Treasure
|
|||||||
{
|
{
|
||||||
for (const auto & templ : object.templates)
|
for (const auto & templ : object.templates)
|
||||||
{
|
{
|
||||||
CompoundMapObjectID key(templ->id, templ->subid);
|
CompoundMapObjectID key = object.getCompoundID();
|
||||||
if (bannedObjectsSet.count(key))
|
if (bannedObjectsSet.count(key))
|
||||||
{
|
{
|
||||||
// FIXME: Stopped working, nothing is banned
|
// FIXME: Stopped working, nothing is banned
|
||||||
@ -1184,10 +1175,9 @@ void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, Treasure
|
|||||||
// FIXME: Access TreasurePlacer from ObjectPool
|
// FIXME: Access TreasurePlacer from ObjectPool
|
||||||
for (auto & object : configuredObjects)
|
for (auto & object : configuredObjects)
|
||||||
{
|
{
|
||||||
auto temp = object.templates.front();
|
tp->setBasicProperties(object, object.getCompoundID());
|
||||||
tp->setBasicProperties(object, CompoundMapObjectID(temp->id, temp->subid));
|
|
||||||
addObject(object);
|
addObject(object);
|
||||||
logGlobal->info("Added custom object of type %d.%d", temp->id, temp->subid);
|
logGlobal->info("Added custom object of type %d.%d", object.primaryID, object.secondaryID);
|
||||||
}
|
}
|
||||||
// TODO: Overwrite or add to possibleObjects
|
// TODO: Overwrite or add to possibleObjects
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user