mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Fixed missing names for dwellings and creature banks
This commit is contained in:
parent
f01ab0d48f
commit
a1fff864e6
@ -45,10 +45,8 @@ void CBank::initObj()
|
|||||||
|
|
||||||
std::string CBank::getHoverText(PlayerColor player) const
|
std::string CBank::getHoverText(PlayerColor player) const
|
||||||
{
|
{
|
||||||
// TODO: USE BANK_SPECIFIC NAMES
|
|
||||||
// TODO: record visited players
|
// TODO: record visited players
|
||||||
bool visited = (bc == nullptr);
|
return getObjectName() + " " + visitedTxt(bc == nullptr);
|
||||||
return visitedTxt(visited);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBank::setConfig(const BankConfig & config)
|
void CBank::setConfig(const BankConfig & config)
|
||||||
@ -128,8 +126,8 @@ void CBank::onHeroVisit (const CGHeroInstance * h) const
|
|||||||
bd.player = h->getOwner();
|
bd.player = h->getOwner();
|
||||||
bd.soundID = soundID;
|
bd.soundID = soundID;
|
||||||
bd.text.addTxt(MetaString::ADVOB_TXT, banktext);
|
bd.text.addTxt(MetaString::ADVOB_TXT, banktext);
|
||||||
//if (ID == Obj::CREATURE_BANK)
|
if (ID == Obj::CREATURE_BANK)
|
||||||
// bd.text.addReplacement(VLC->objh->creBanksNames[index]); // FIXME: USE BANK SPECIFIC NAMES
|
bd.text.addReplacement(getObjectName());
|
||||||
cb->showBlockingDialog (&bd);
|
cb->showBlockingDialog (&bd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -149,7 +147,7 @@ void CBank::onHeroVisit (const CGHeroInstance * h) const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
iw.text << VLC->generaltexth->advobtxt[33];// This was X, now is completely empty
|
iw.text << VLC->generaltexth->advobtxt[33];// This was X, now is completely empty
|
||||||
//iw.text.addReplacement(VLC->objh->creBanksNames[index]); // FIXME: USE BANK SPECIFIC NAMES
|
iw.text.addReplacement(getObjectName());
|
||||||
}
|
}
|
||||||
cb->showInfoDialog(&iw);
|
cb->showInfoDialog(&iw);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,17 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData(size_t dataSize)
|
|||||||
ret[i]["name"].String() = namesParser.readString();
|
ret[i]["name"].String() = namesParser.readString();
|
||||||
namesParser.endLine();
|
namesParser.endLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLegacyConfigParser cregen1Parser("data/crgen1");
|
||||||
|
do
|
||||||
|
customNames[Obj::CREATURE_GENERATOR1].push_back(cregen1Parser.readString());
|
||||||
|
while(cregen1Parser.endLine());
|
||||||
|
|
||||||
|
CLegacyConfigParser cregen4Parser("data/crgen4");
|
||||||
|
do
|
||||||
|
customNames[Obj::CREATURE_GENERATOR4].push_back(cregen4Parser.readString());
|
||||||
|
while(cregen4Parser.endLine());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,12 +153,16 @@ void CObjectClassesHandler::loadObjectEntry(const JsonNode & entry, ObjectContai
|
|||||||
logGlobal->errorStream() << "Handler with name " << obj->handlerName << " was not found!";
|
logGlobal->errorStream() << "Handler with name " << obj->handlerName << " was not found!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto handler = handlerConstructors.at(obj->handlerName)();
|
|
||||||
handler->init(entry);
|
|
||||||
|
|
||||||
si32 id = selectNextID(entry["index"], obj->objects, 1000);
|
si32 id = selectNextID(entry["index"], obj->objects, 1000);
|
||||||
|
|
||||||
|
auto handler = handlerConstructors.at(obj->handlerName)();
|
||||||
handler->setType(obj->id, id);
|
handler->setType(obj->id, id);
|
||||||
|
|
||||||
|
if (customNames.count(obj->id) && customNames.at(obj->id).size() > id)
|
||||||
|
handler->init(entry, customNames.at(obj->id).at(id));
|
||||||
|
else
|
||||||
|
handler->init(entry);
|
||||||
|
|
||||||
if (handler->getTemplates().empty())
|
if (handler->getTemplates().empty())
|
||||||
{
|
{
|
||||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, id));
|
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, id));
|
||||||
@ -208,6 +223,7 @@ void CObjectClassesHandler::loadSubObject(std::string name, JsonNode config, si3
|
|||||||
std::string oldMeta = config.meta; // FIXME: move into inheritNode?
|
std::string oldMeta = config.meta; // FIXME: move into inheritNode?
|
||||||
JsonUtils::inherit(config, objects.at(ID)->base);
|
JsonUtils::inherit(config, objects.at(ID)->base);
|
||||||
config.setMeta(oldMeta);
|
config.setMeta(oldMeta);
|
||||||
|
|
||||||
loadObjectEntry(config, objects[ID]);
|
loadObjectEntry(config, objects[ID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,6 +306,17 @@ std::string CObjectClassesHandler::getObjectName(si32 type) const
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CObjectClassesHandler::getObjectName(si32 type, si32 subtype) const
|
||||||
|
{
|
||||||
|
if (knownSubObjects(type).count(subtype))
|
||||||
|
{
|
||||||
|
auto name = getHandlerFor(type, subtype)->getCustomName();
|
||||||
|
if (name)
|
||||||
|
return name.get();
|
||||||
|
}
|
||||||
|
return getObjectName(type);
|
||||||
|
}
|
||||||
|
|
||||||
void AObjectTypeHandler::setType(si32 type, si32 subtype)
|
void AObjectTypeHandler::setType(si32 type, si32 subtype)
|
||||||
{
|
{
|
||||||
this->type = type;
|
this->type = type;
|
||||||
@ -304,7 +331,7 @@ static ui32 loadJsonOrMax(const JsonNode & input)
|
|||||||
return input.Float();
|
return input.Float();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AObjectTypeHandler::init(const JsonNode & input)
|
void AObjectTypeHandler::init(const JsonNode & input, boost::optional<std::string> name)
|
||||||
{
|
{
|
||||||
base = input["base"];
|
base = input["base"];
|
||||||
|
|
||||||
@ -328,6 +355,12 @@ void AObjectTypeHandler::init(const JsonNode & input)
|
|||||||
tmpl.readJson(entry.second);
|
tmpl.readJson(entry.second);
|
||||||
templates.push_back(tmpl);
|
templates.push_back(tmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input["name"].isNull())
|
||||||
|
objectName = name;
|
||||||
|
else
|
||||||
|
objectName.reset(input["name"].String());
|
||||||
|
|
||||||
initTypeData(input);
|
initTypeData(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,6 +371,12 @@ bool AObjectTypeHandler::objectFilter(const CGObjectInstance *, const ObjectTemp
|
|||||||
|
|
||||||
void AObjectTypeHandler::initTypeData(const JsonNode & input)
|
void AObjectTypeHandler::initTypeData(const JsonNode & input)
|
||||||
{
|
{
|
||||||
|
// empty implementation for overrides
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::optional<std::string> AObjectTypeHandler::getCustomName() const
|
||||||
|
{
|
||||||
|
return objectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AObjectTypeHandler::addTemplate(ObjectTemplate templ)
|
void AObjectTypeHandler::addTemplate(ObjectTemplate templ)
|
||||||
|
@ -98,6 +98,9 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
|
|||||||
{
|
{
|
||||||
RandomMapInfo rmgInfo;
|
RandomMapInfo rmgInfo;
|
||||||
|
|
||||||
|
/// Human-readable name of this object, used for objects like banks and dwellings, if set
|
||||||
|
boost::optional<std::string> objectName;
|
||||||
|
|
||||||
si32 type;
|
si32 type;
|
||||||
si32 subtype;
|
si32 subtype;
|
||||||
|
|
||||||
@ -116,7 +119,10 @@ public:
|
|||||||
void setType(si32 type, si32 subtype);
|
void setType(si32 type, si32 subtype);
|
||||||
|
|
||||||
/// loads generic data from Json structure and passes it towards type-specific constructors
|
/// loads generic data from Json structure and passes it towards type-specific constructors
|
||||||
void init(const JsonNode & input);
|
void init(const JsonNode & input, boost::optional<std::string> name = boost::optional<std::string>());
|
||||||
|
|
||||||
|
/// Returns object-specific name, if set
|
||||||
|
boost::optional<std::string> getCustomName() const;
|
||||||
|
|
||||||
void addTemplate(ObjectTemplate templ);
|
void addTemplate(ObjectTemplate templ);
|
||||||
void addTemplate(JsonNode config);
|
void addTemplate(JsonNode config);
|
||||||
@ -148,7 +154,7 @@ public:
|
|||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & type & subtype & templates & rmgInfo;
|
h & type & subtype & templates & rmgInfo & objectName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -174,8 +180,6 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::multimap<std::pair<si32, si32>, ObjectTemplate> TTemplatesContainer;
|
|
||||||
|
|
||||||
/// list of object handlers, each of them handles only one type
|
/// list of object handlers, each of them handles only one type
|
||||||
std::map<si32, ObjectContainter * > objects;
|
std::map<si32, ObjectContainter * > objects;
|
||||||
|
|
||||||
@ -183,8 +187,13 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
|
|||||||
std::map<std::string, std::function<TObjectTypeHandler()> > handlerConstructors;
|
std::map<std::string, std::function<TObjectTypeHandler()> > handlerConstructors;
|
||||||
|
|
||||||
/// container with H3 templates, used only during loading, no need to serialize it
|
/// container with H3 templates, used only during loading, no need to serialize it
|
||||||
|
typedef std::multimap<std::pair<si32, si32>, ObjectTemplate> TTemplatesContainer;
|
||||||
TTemplatesContainer legacyTemplates;
|
TTemplatesContainer legacyTemplates;
|
||||||
|
|
||||||
|
/// contains list of custom names for H3 objects (e.g. Dwellings), used to load H3 data
|
||||||
|
/// format: customNames[primaryID][secondaryID] -> name
|
||||||
|
std::map<si32, std::vector<std::string>> customNames;
|
||||||
|
|
||||||
void loadObjectEntry(const JsonNode & entry, ObjectContainter * obj);
|
void loadObjectEntry(const JsonNode & entry, ObjectContainter * obj);
|
||||||
ObjectContainter * loadFromJson(const JsonNode & json);
|
ObjectContainter * loadFromJson(const JsonNode & json);
|
||||||
public:
|
public:
|
||||||
@ -211,6 +220,7 @@ public:
|
|||||||
TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const;
|
TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const;
|
||||||
|
|
||||||
std::string getObjectName(si32 type) const;
|
std::string getObjectName(si32 type) const;
|
||||||
|
std::string getObjectName(si32 type, si32 subtype) const;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +272,7 @@ void CGObjectInstance::giveDummyBonus(ObjectInstanceID heroID, ui8 duration) con
|
|||||||
|
|
||||||
std::string CGObjectInstance::getObjectName() const
|
std::string CGObjectInstance::getObjectName() const
|
||||||
{
|
{
|
||||||
return VLC->objtypeh->getObjectName(ID);
|
return VLC->objtypeh->getObjectName(ID, subID);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CGObjectInstance::getHoverText(PlayerColor player) const
|
std::string CGObjectInstance::getHoverText(PlayerColor player) const
|
||||||
|
@ -184,7 +184,6 @@ void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32
|
|||||||
|
|
||||||
if (answer > 0 && answer-1 < info.size())
|
if (answer > 0 && answer-1 < info.size())
|
||||||
{
|
{
|
||||||
//NOTE: this relies on assumption that there won't be any changes in player/hero during blocking dialog
|
|
||||||
auto list = getAvailableRewards(hero);
|
auto list = getAvailableRewards(hero);
|
||||||
grantReward(list[answer - 1], hero);
|
grantReward(list[answer - 1], hero);
|
||||||
}
|
}
|
||||||
@ -470,7 +469,7 @@ void CGPickable::initObj()
|
|||||||
blockVisit = true;
|
blockVisit = true;
|
||||||
switch(ID)
|
switch(ID)
|
||||||
{
|
{
|
||||||
case Obj::CAMPFIRE: //FIXME: campfire is not functioning correctly in game (no visible message)
|
case Obj::CAMPFIRE:
|
||||||
{
|
{
|
||||||
soundID = soundBase::experience;
|
soundID = soundBase::experience;
|
||||||
int givenRes = cb->gameState()->getRandomGenerator().nextInt(5);
|
int givenRes = cb->gameState()->getRandomGenerator().nextInt(5);
|
||||||
|
@ -195,8 +195,11 @@ void CDwellingInstanceConstructor::configureObject(CGObjectInstance * object, CR
|
|||||||
|
|
||||||
if (guards.getType() == JsonNode::DATA_BOOL)
|
if (guards.getType() == JsonNode::DATA_BOOL)
|
||||||
{
|
{
|
||||||
const CCreature * crea = availableCreatures.at(0).at(0);
|
if (guards.Bool())
|
||||||
dwelling->putStack(SlotID(0), new CStackInstance(crea->idNumber, crea->growth * 3 ));
|
{
|
||||||
|
const CCreature * crea = availableCreatures.at(0).at(0);
|
||||||
|
dwelling->putStack(SlotID(0), new CStackInstance(crea->idNumber, crea->growth * 3 ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else for (auto & stack : JsonRandom::loadCreatures(guards, rng))
|
else for (auto & stack : JsonRandom::loadCreatures(guards, rng))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user