1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-17 13:41:07 +02:00

Merge branch 'develop' of https://github.com/vcmi/vcmi into RMG

This commit is contained in:
DjWarmonger 2014-06-30 06:45:35 +02:00
commit a556ef64e9
12 changed files with 104 additions and 38 deletions

View File

@ -1,6 +1,7 @@
#include "StdInc.h"
#include "AIUtility.h"
#include "VCAI.h"
#include "Fuzzy.h"
#include "../../lib/UnlockGuard.h"
#include "../../lib/CConfigHandler.h"

View File

@ -1,4 +1,2 @@
#pragma once
#include "../../Global.h"
#include "Fuzzy.h"

View File

@ -1,6 +1,8 @@
#include "StdInc.h"
#include "VCAI.h"
#include "Goals.h"
#include "Fuzzy.h"
#include "../../lib/UnlockGuard.h"
#include "../../lib/mapObjects/MapObjects.h"
#include "../../lib/CConfigHandler.h"

View File

@ -45,10 +45,8 @@ void CBank::initObj()
std::string CBank::getHoverText(PlayerColor player) const
{
// TODO: USE BANK_SPECIFIC NAMES
// TODO: record visited players
bool visited = (bc == nullptr);
return visitedTxt(visited);
return getObjectName() + " " + visitedTxt(bc == nullptr);
}
void CBank::setConfig(const BankConfig & config)
@ -128,8 +126,8 @@ void CBank::onHeroVisit (const CGHeroInstance * h) const
bd.player = h->getOwner();
bd.soundID = soundID;
bd.text.addTxt(MetaString::ADVOB_TXT, banktext);
//if (ID == Obj::CREATURE_BANK)
// bd.text.addReplacement(VLC->objh->creBanksNames[index]); // FIXME: USE BANK SPECIFIC NAMES
if (ID == Obj::CREATURE_BANK)
bd.text.addReplacement(getObjectName());
cb->showBlockingDialog (&bd);
}
else
@ -149,7 +147,7 @@ void CBank::onHeroVisit (const CGHeroInstance * h) const
else
{
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);
}

View File

@ -117,6 +117,17 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData(size_t dataSize)
ret[i]["name"].String() = namesParser.readString();
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;
}
@ -142,12 +153,16 @@ void CObjectClassesHandler::loadObjectEntry(const JsonNode & entry, ObjectContai
logGlobal->errorStream() << "Handler with name " << obj->handlerName << " was not found!";
return;
}
auto handler = handlerConstructors.at(obj->handlerName)();
handler->init(entry);
si32 id = selectNextID(entry["index"], obj->objects, 1000);
auto handler = handlerConstructors.at(obj->handlerName)();
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())
{
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?
JsonUtils::inherit(config, objects.at(ID)->base);
config.setMeta(oldMeta);
loadObjectEntry(config, objects[ID]);
}
@ -290,6 +306,17 @@ std::string CObjectClassesHandler::getObjectName(si32 type) const
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)
{
this->type = type;
@ -304,7 +331,7 @@ static ui32 loadJsonOrMax(const JsonNode & input)
return input.Float();
}
void AObjectTypeHandler::init(const JsonNode & input)
void AObjectTypeHandler::init(const JsonNode & input, boost::optional<std::string> name)
{
base = input["base"];
@ -328,6 +355,12 @@ void AObjectTypeHandler::init(const JsonNode & input)
tmpl.readJson(entry.second);
templates.push_back(tmpl);
}
if (input["name"].isNull())
objectName = name;
else
objectName.reset(input["name"].String());
initTypeData(input);
}
@ -338,6 +371,12 @@ bool AObjectTypeHandler::objectFilter(const CGObjectInstance *, const ObjectTemp
void AObjectTypeHandler::initTypeData(const JsonNode & input)
{
// empty implementation for overrides
}
boost::optional<std::string> AObjectTypeHandler::getCustomName() const
{
return objectName;
}
void AObjectTypeHandler::addTemplate(ObjectTemplate templ)

View File

@ -98,6 +98,9 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
{
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 subtype;
@ -116,7 +119,10 @@ public:
void setType(si32 type, si32 subtype);
/// 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(JsonNode config);
@ -148,7 +154,7 @@ public:
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
std::map<si32, ObjectContainter * > objects;
@ -183,8 +187,13 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
std::map<std::string, std::function<TObjectTypeHandler()> > handlerConstructors;
/// container with H3 templates, used only during loading, no need to serialize it
typedef std::multimap<std::pair<si32, si32>, ObjectTemplate> TTemplatesContainer;
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);
ObjectContainter * loadFromJson(const JsonNode & json);
public:
@ -211,6 +220,7 @@ public:
TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) 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)
{

View File

@ -263,7 +263,7 @@ void CGObjectInstance::giveDummyBonus(ObjectInstanceID heroID, ui8 duration) con
std::string CGObjectInstance::getObjectName() const
{
return VLC->objtypeh->getObjectName(ID);
return VLC->objtypeh->getObjectName(ID, subID);
}
std::string CGObjectInstance::getHoverText(PlayerColor player) const

View File

@ -76,7 +76,8 @@ std::vector<ui32> CRewardableObject::getAvailableRewards(const CGHeroInstance *
{
const CVisitInfo & visit = info[i];
if (visit.numOfGrants < visit.limiter.numOfGrants && visit.limiter.heroAllowed(hero))
if ((visit.limiter.numOfGrants == 0 || visit.numOfGrants < visit.limiter.numOfGrants) // reward has unlimited uses or some are still available
&& visit.limiter.heroAllowed(hero))
{
logGlobal->debugStream() << "Reward " << i << " is allowed";
ret.push_back(i);
@ -183,7 +184,6 @@ void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32
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);
grantReward(list[answer - 1], hero);
}
@ -270,7 +270,10 @@ void CRewardableObject::grantRewardAfterLevelup(const CVisitInfo & info, const C
for (const Bonus & bonus : info.reward.bonuses)
{
assert(bonus.source == Bonus::OBJECT);
assert(bonus.sid == ID);
GiveBonus gb;
gb.who = GiveBonus::HERO;
gb.bonus = bonus;
gb.id = hero->id.getNum();
cb->giveHeroBonus(&gb);
@ -306,7 +309,7 @@ bool CRewardableObject::wasVisited (PlayerColor player) const
{
case VISIT_UNLIMITED:
return false;
case VISIT_ONCE:
case VISIT_ONCE: // FIXME: hide this info deeper and return same as player?
for (auto & visit : info)
{
if (visit.numOfGrants != 0)
@ -315,7 +318,7 @@ bool CRewardableObject::wasVisited (PlayerColor player) const
case VISIT_HERO:
return false;
case VISIT_PLAYER:
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(ID));
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id));
default:
return false;
}
@ -325,8 +328,10 @@ bool CRewardableObject::wasVisited (const CGHeroInstance * h) const
{
switch (visitMode)
{
case VISIT_UNLIMITED:
return h->hasBonusFrom(Bonus::OBJECT, ID);
case VISIT_HERO:
return vstd::contains(h->visitedObjects, ObjectInstanceID(ID)) || h->hasBonusFrom(Bonus::OBJECT, ID);
return h->visitedObjects.count(ObjectInstanceID(id));
default:
return wasVisited(h->tempOwner);
}
@ -337,12 +342,6 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps) const
for (auto comp : extraComponents)
comps.push_back(comp);
for (size_t i=0; i<resources.size(); i++)
{
if (resources[i] !=0)
comps.push_back(Component(Component::RESOURCE, i, resources[i], 0));
}
if (gainedExp) comps.push_back(Component(Component::EXPERIENCE, 0, gainedExp, 0));
if (gainedLevels) comps.push_back(Component(Component::EXPERIENCE, 0, gainedLevels, 0));
@ -365,6 +364,12 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps) const
for (auto & entry : creatures)
comps.push_back(Component(Component::CREATURE, entry.type->idNumber, entry.count, 0));
for (size_t i=0; i<resources.size(); i++)
{
if (resources[i] !=0)
comps.push_back(Component(Component::RESOURCE, i, resources[i], 0));
}
}
Component CRewardInfo::getDisplayedComponent() const
@ -464,7 +469,7 @@ void CGPickable::initObj()
blockVisit = true;
switch(ID)
{
case Obj::CAMPFIRE: //FIXME: campfire is not functioning correctly in game (no visible message)
case Obj::CAMPFIRE:
{
soundID = soundBase::experience;
int givenRes = cb->gameState()->getRandomGenerator().nextInt(5);
@ -658,8 +663,10 @@ void CGBonusingObject::initObj()
for (int i=0; i<5; i++)
{
configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value
configureMessage(info[i], 55, 56, soundBase::LUCK);
info[i].message.addTxt(MetaString::ADVOB_TXT, 55);
soundID = soundBase::LUCK;
}
onVisited.addTxt(MetaString::ADVOB_TXT, 56);
break;
case Obj::IDOL_OF_FORTUNE:
@ -668,8 +675,10 @@ void CGBonusingObject::initObj()
{
info[i].limiter.dayOfWeek = i+1;
configureBonus(info[i], i%2 ? Bonus::MORALE : Bonus::LUCK, 1, 68);
configureMessage(info[i], 62, 63, soundBase::experience);
info[i].message.addTxt(MetaString::ADVOB_TXT, 62);
soundID = soundBase::experience;
}
onVisited.addTxt(MetaString::ADVOB_TXT, 63);
info.back().limiter.dayOfWeek = 7;
configureBonus(info.back(), Bonus::MORALE, 1, 68); // on last day of week
configureBonus(info.back(), Bonus::LUCK, 1, 68);
@ -698,8 +707,10 @@ void CGBonusingObject::initObj()
configureBonus(info[0], Bonus::MORALE, 2, 96);
configureBonus(info[1], Bonus::MORALE, 1, 97);
configureMessage(info[0], 140, 141, soundBase::temple);
configureMessage(info[1], 140, 141, soundBase::temple);
info[0].message.addTxt(MetaString::ADVOB_TXT, 140);
info[1].message.addTxt(MetaString::ADVOB_TXT, 140);
onVisited.addTxt(MetaString::ADVOB_TXT, 141);
soundID = soundBase::temple;
break;
case Obj::WATERING_HOLE:
configureMessage(info[0], 166, 167, soundBase::MORALE);
@ -924,6 +935,8 @@ void CGVisitableOPH::initObj()
info.resize(2);
info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1;
info[1].reward.primary[PrimarySkill::KNOWLEDGE] = 1;
info[0].reward.resources[Res::GOLD] = -1000;
info[1].reward.resources[Res::GOLD] = -1000;
onSelect.addTxt(MetaString::ADVOB_TXT, 71);
onVisited.addTxt(MetaString::ADVOB_TXT, 72);
onEmpty.addTxt(MetaString::ADVOB_TXT, 73);
@ -934,6 +947,8 @@ void CGVisitableOPH::initObj()
info.resize(2);
info[0].reward.primary[PrimarySkill::ATTACK] = 1;
info[1].reward.primary[PrimarySkill::DEFENSE] = 1;
info[0].reward.resources[Res::GOLD] = -1000;
info[1].reward.resources[Res::GOLD] = -1000;
onSelect.addTxt(MetaString::ADVOB_TXT, 158);
onVisited.addTxt(MetaString::ADVOB_TXT, 159);
onEmpty.addTxt(MetaString::ADVOB_TXT, 160);

View File

@ -48,7 +48,7 @@ public:
std::vector<CStackBasicDescriptor> creatures;
CRewardLimiter():
numOfGrants(1),
numOfGrants(0),
dayOfWeek(0),
minLevel(0),
primary(4, 0)

View File

@ -195,8 +195,11 @@ void CDwellingInstanceConstructor::configureObject(CGObjectInstance * object, CR
if (guards.getType() == JsonNode::DATA_BOOL)
{
const CCreature * crea = availableCreatures.at(0).at(0);
dwelling->putStack(SlotID(0), new CStackInstance(crea->idNumber, crea->growth * 3 ));
if (guards.Bool())
{
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))
{

View File

@ -1061,7 +1061,7 @@ void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
case Obj::COVER_OF_DARKNESS:
{
iw.text.addTxt (MetaString::ADVOB_TXT, 31);
for (auto player : cb->gameState()->players)
for (auto & player : cb->gameState()->players)
{
if (cb->getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
cb->getPlayerRelations(player.first, h->tempOwner) == PlayerRelations::ENEMIES)

View File

@ -1351,7 +1351,7 @@ void CGameHandler::newTurn()
}
if (t->hasBonusOfType (Bonus::DARKNESS))
{
for (auto player : gameState()->players)
for (auto & player : gameState()->players)
{
if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)