1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

Merge branch 'develop' into battle-dialog

This commit is contained in:
Nordsoft91 2022-11-12 17:14:15 +04:00 committed by GitHub
commit 072e2d72bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 235 additions and 225 deletions

View File

@ -774,8 +774,10 @@ void AIGateway::makeTurn()
retrieveVisitableObjs(); retrieveVisitableObjs();
} }
#if NKAI_TRACE_LEVEL == 0
try try
{ {
#endif
nullkiller->makeTurn(); nullkiller->makeTurn();
//for debug purpose //for debug purpose
@ -784,6 +786,7 @@ void AIGateway::makeTurn()
if (h->movement) if (h->movement)
logAi->warn("Hero %s has %d MP left", h->name, h->movement); logAi->warn("Hero %s has %d MP left", h->name, h->movement);
} }
#if NKAI_TRACE_LEVEL == 0
} }
catch (boost::thread_interrupted & e) catch (boost::thread_interrupted & e)
{ {
@ -795,6 +798,7 @@ void AIGateway::makeTurn()
{ {
logAi->debug("Making turn thread has caught an exception: %s", e.what()); logAi->debug("Making turn thread has caught an exception: %s", e.what());
} }
#endif
endTurn(); endTurn();
} }

View File

@ -307,7 +307,7 @@ void Nullkiller::executeTask(Goals::TTask task)
{ {
logAi->trace("Task %s completed", task->toString()); logAi->trace("Task %s completed", task->toString());
} }
catch(std::exception & e) catch(cannotFulfillGoalException & e)
{ {
logAi->debug("Failed to realize subgoal of type %s, I will stop.", taskDescr); logAi->debug("Failed to realize subgoal of type %s, I will stop.", taskDescr);
logAi->debug("The error message was: %s", e.what()); logAi->debug("The error message was: %s", e.what());

View File

@ -1086,7 +1086,7 @@ void AINodeStorage::calculateTownPortal(
for(const CGTownInstance * targetTown : towns) for(const CGTownInstance * targetTown : towns)
{ {
// TODO: allow to hide visiting hero in garrison // TODO: allow to hide visiting hero in garrison
if(targetTown->visitingHero) if(targetTown->visitingHero && maskMap.find(targetTown->visitingHero.get()) != maskMap.end())
{ {
auto basicMask = maskMap.at(targetTown->visitingHero.get()); auto basicMask = maskMap.at(targetTown->visitingHero.get());
bool heroIsInChain = (actor->chainMask & basicMask) != 0; bool heroIsInChain = (actor->chainMask & basicMask) != 0;

View File

@ -1,6 +1,7 @@
[![GitHub](https://github.com/vcmi/vcmi/actions/workflows/github.yml/badge.svg)](https://github.com/vcmi/vcmi/actions/workflows/github.yml) [![GitHub](https://github.com/vcmi/vcmi/actions/workflows/github.yml/badge.svg)](https://github.com/vcmi/vcmi/actions/workflows/github.yml)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/github/vcmi/vcmi?branch=develop&svg=true)](https://ci.appveyor.com/project/vcmi/vcmi) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/github/vcmi/vcmi?branch=develop&svg=true)](https://ci.appveyor.com/project/vcmi/vcmi)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/vcmi/badge.svg)](https://scan.coverity.com/projects/vcmi) [![Coverity Scan Build Status](https://scan.coverity.com/projects/vcmi/badge.svg)](https://scan.coverity.com/projects/vcmi)
[![Github Downloads](https://img.shields.io/github/downloads/vcmi/vcmi/1.0.0/total)](https://github.com/vcmi/vcmi/releases/tag/1.0.0)
# VCMI Project # VCMI Project
VCMI is work-in-progress attempt to recreate engine for Heroes III, giving it new and extended possibilities. VCMI is work-in-progress attempt to recreate engine for Heroes III, giving it new and extended possibilities.

View File

@ -859,9 +859,6 @@ void CBattleInterface::reallySurrender()
void CBattleInterface::bAutofightf() void CBattleInterface::bAutofightf()
{ {
//if(bresult) //battle is already finished
//return;
if(spellDestSelectMode) //we are casting a spell if(spellDestSelectMode) //we are casting a spell
return; return;
@ -872,7 +869,7 @@ void CBattleInterface::bAutofightf()
curInt->isAutoFightOn = false; curInt->isAutoFightOn = false;
logGlobal->trace("Stopping the autofight..."); logGlobal->trace("Stopping the autofight...");
} }
else else if(!curInt->autofightingAI)
{ {
curInt->isAutoFightOn = true; curInt->isAutoFightOn = true;
blockUI(true); blockUI(true);
@ -1629,7 +1626,9 @@ void CBattleInterface::activateStack()
setActiveStack(stackToActivate); setActiveStack(stackToActivate);
stackToActivate = nullptr; stackToActivate = nullptr;
const CStack *s = activeStack; const CStack * s = activeStack;
if(!s)
return;
queue->update(); queue->update();
redrawBackgroundWithHexes(activeStack); redrawBackgroundWithHexes(activeStack);

View File

@ -536,6 +536,8 @@ void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf
for(auto & object : objects) for(auto & object : objects)
{ {
const CGObjectInstance * obj = object.obj; const CGObjectInstance * obj = object.obj;
if(!obj)
continue;
const bool sameLevel = obj->pos.z == pos.z; const bool sameLevel = obj->pos.z == pos.z;

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"specialBattlefields": { "specialBattlefields": {
"type": "array", "type": "array",
"description": "Obstacles can be placed on specified specified battlefields", "description": "Obstacles can be placed on specified specified battlefields",
"items": { "$ref" : "battlefield.json" } "items": { "type" : "string" }
}, },
"width": { "width": {
"type": "number", "type": "number",

View File

@ -729,7 +729,7 @@ CArtifactInstance::CArtifactInstance( CArtifact *Art)
void CArtifactInstance::setType( CArtifact *Art ) void CArtifactInstance::setType( CArtifact *Art )
{ {
artType = Art; artType = Art;
attachTo(Art); attachTo(*Art);
} }
std::string CArtifactInstance::nodeName() const std::string CArtifactInstance::nodeName() const
@ -852,7 +852,7 @@ void CArtifactInstance::putAt(ArtifactLocation al)
al.getHolderArtSet()->setNewArtSlot(al.slot, this, false); al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
if(al.slot < GameConstants::BACKPACK_START) if(al.slot < GameConstants::BACKPACK_START)
al.getHolderNode()->attachTo(this); al.getHolderNode()->attachTo(*this);
} }
void CArtifactInstance::removeFrom(ArtifactLocation al) void CArtifactInstance::removeFrom(ArtifactLocation al)
@ -860,7 +860,7 @@ void CArtifactInstance::removeFrom(ArtifactLocation al)
assert(al.getHolderArtSet()->getArt(al.slot) == this); assert(al.getHolderArtSet()->getArt(al.slot) == this);
al.getHolderArtSet()->eraseArtSlot(al.slot); al.getHolderArtSet()->eraseArtSlot(al.slot);
if(al.slot < GameConstants::BACKPACK_START) if(al.slot < GameConstants::BACKPACK_START)
al.getHolderNode()->detachFrom(this); al.getHolderNode()->detachFrom(*this);
//TODO delete me? //TODO delete me?
} }
@ -1054,7 +1054,7 @@ void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, Artifac
assert(vstd::contains(*artType->constituents, art->artType.get())); assert(vstd::contains(*artType->constituents, art->artType.get()));
assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType); assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
constituentsInfo.push_back(ConstituentInfo(art, slot)); constituentsInfo.push_back(ConstituentInfo(art, slot));
attachTo(art); attachTo(*art);
} }
void CCombinedArtifactInstance::putAt(ArtifactLocation al) void CCombinedArtifactInstance::putAt(ArtifactLocation al)
@ -1143,7 +1143,7 @@ CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const Artif
void CCombinedArtifactInstance::deserializationFix() void CCombinedArtifactInstance::deserializationFix()
{ {
for(ConstituentInfo &ci : constituentsInfo) for(ConstituentInfo &ci : constituentsInfo)
attachTo(ci.art); attachTo(*ci.art);
} }
bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
@ -1350,7 +1350,7 @@ void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
{ {
for(auto & elem : artifactsWorn) for(auto & elem : artifactsWorn)
if(elem.second.artifact && !elem.second.locked) if(elem.second.artifact && !elem.second.locked)
node->attachTo(elem.second.artifact); node->attachTo(*elem.second.artifact);
} }
void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map) void CArtifactSet::serializeJsonArtifacts(JsonSerializeFormat & handler, const std::string & fieldName, CMap * map)

View File

@ -1345,12 +1345,12 @@ void CCreatureHandler::buildBonusTreeForTiers()
for(CCreature * c : objects) for(CCreature * c : objects)
{ {
if(vstd::isbetween(c->level, 0, ARRAY_COUNT(creaturesOfLevel))) if(vstd::isbetween(c->level, 0, ARRAY_COUNT(creaturesOfLevel)))
c->attachTo(&creaturesOfLevel[c->level]); c->attachTo(creaturesOfLevel[c->level]);
else else
c->attachTo(&creaturesOfLevel[0]); c->attachTo(creaturesOfLevel[0]);
} }
for(CBonusSystemNode &b : creaturesOfLevel) for(CBonusSystemNode &b : creaturesOfLevel)
b.attachTo(&allCreatures); b.attachTo(allCreatures);
} }
void CCreatureHandler::afterLoadFinalization() void CCreatureHandler::afterLoadFinalization()

View File

@ -773,7 +773,7 @@ void CStackInstance::setType(const CCreature *c)
{ {
if(type) if(type)
{ {
detachFrom(const_cast<CCreature*>(type)); detachFrom(const_cast<CCreature&>(*type));
if (type->isMyUpgrade(c) && VLC->modh->modules.STACK_EXP) if (type->isMyUpgrade(c) && VLC->modh->modules.STACK_EXP)
experience = static_cast<TExpType>(experience * VLC->creh->expAfterUpgrade / 100.0); experience = static_cast<TExpType>(experience * VLC->creh->expAfterUpgrade / 100.0);
} }
@ -781,7 +781,7 @@ void CStackInstance::setType(const CCreature *c)
CStackBasicDescriptor::setType(c); CStackBasicDescriptor::setType(c);
if(type) if(type)
attachTo(const_cast<CCreature*>(type)); attachTo(const_cast<CCreature&>(*type));
} }
std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const
{ {
@ -804,12 +804,12 @@ std::string CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus>& bonus)
void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj) void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj)
{ {
if(_armyObj) if(_armyObj)
detachFrom(const_cast<CArmedInstance*>(_armyObj)); detachFrom(const_cast<CArmedInstance&>(*_armyObj));
_armyObj = ArmyObj; _armyObj = ArmyObj;
if(ArmyObj) if(ArmyObj)
attachTo(const_cast<CArmedInstance*>(_armyObj)); attachTo(const_cast<CArmedInstance&>(*_armyObj));
} }
std::string CStackInstance::getQuantityTXT(bool capitalized) const std::string CStackInstance::getQuantityTXT(bool capitalized) const

View File

@ -2724,13 +2724,13 @@ void CGameState::buildGlobalTeamPlayerTree()
for(auto k=teams.begin(); k!=teams.end(); ++k) for(auto k=teams.begin(); k!=teams.end(); ++k)
{ {
TeamState *t = &k->second; TeamState *t = &k->second;
t->attachTo(&globalEffects); t->attachTo(globalEffects);
for(PlayerColor teamMember : k->second.players) for(PlayerColor teamMember : k->second.players)
{ {
PlayerState *p = getPlayerState(teamMember); PlayerState *p = getPlayerState(teamMember);
assert(p); assert(p);
p->attachTo(t); p->attachTo(*t);
} }
} }
} }
@ -2740,7 +2740,9 @@ void CGameState::attachArmedObjects()
for(CGObjectInstance *obj : map->objects) for(CGObjectInstance *obj : map->objects)
{ {
if(CArmedInstance *armed = dynamic_cast<CArmedInstance*>(obj)) if(CArmedInstance *armed = dynamic_cast<CArmedInstance*>(obj))
armed->whatShouldBeAttached()->attachTo(armed->whereShouldBeAttached(this)); {
armed->whatShouldBeAttached().attachTo(armed->whereShouldBeAttached(this));
}
} }
} }

View File

@ -339,7 +339,7 @@ void CPathfinder::calculatePaths()
auto hlp = config->getOrCreatePathfinderHelper(source, gs); auto hlp = config->getOrCreatePathfinderHelper(source, gs);
if(hlp->isHeroPatrolLocked()) if(hlp->isHeroPatrolLocked())
break; continue;
pq.push(initialNode); pq.push(initialNode);
} }

View File

@ -82,13 +82,14 @@ void CStack::localInit(BattleInfo * battleInfo)
exportBonuses(); exportBonuses();
if(base) //stack originating from "real" stack in garrison -> attach to it if(base) //stack originating from "real" stack in garrison -> attach to it
{ {
attachTo(const_cast<CStackInstance *>(base)); attachTo(const_cast<CStackInstance&>(*base));
} }
else //attach directly to obj to which stack belongs and creature type else //attach directly to obj to which stack belongs and creature type
{ {
CArmedInstance * army = battle->battleGetArmyObject(side); CArmedInstance * army = battle->battleGetArmyObject(side);
attachTo(army); assert(army);
attachTo(const_cast<CCreature *>(type)); attachTo(*army);
attachTo(const_cast<CCreature&>(*type));
} }
nativeTerrain = type->getNativeTerrain(); //save nativeTerrain in the variable on the battle start to avoid dead lock nativeTerrain = type->getNativeTerrain(); //save nativeTerrain in the variable on the battle start to avoid dead lock
CUnitState::localInit(this); //it causes execution of the CStack::isOnNativeTerrain where nativeTerrain will be considered CUnitState::localInit(this); //it causes execution of the CStack::isOnNativeTerrain where nativeTerrain will be considered

View File

@ -1150,53 +1150,53 @@ CBonusSystemNode::~CBonusSystemNode()
if(children.size()) if(children.size())
{ {
while(children.size()) while(children.size())
children.front()->detachFrom(this); children.front()->detachFrom(*this);
} }
} }
void CBonusSystemNode::attachTo(CBonusSystemNode *parent) void CBonusSystemNode::attachTo(CBonusSystemNode & parent)
{ {
assert(!vstd::contains(parents, parent)); assert(!vstd::contains(parents, &parent));
parents.push_back(parent); parents.push_back(&parent);
if(!isHypothetic()) if(!isHypothetic())
{ {
if(parent->actsAsBonusSourceOnly()) if(parent.actsAsBonusSourceOnly())
parent->newRedDescendant(this); parent.newRedDescendant(*this);
else else
newRedDescendant(parent); newRedDescendant(parent);
parent->newChildAttached(this); parent.newChildAttached(*this);
} }
CBonusSystemNode::treeHasChanged(); CBonusSystemNode::treeHasChanged();
} }
void CBonusSystemNode::detachFrom(CBonusSystemNode *parent) void CBonusSystemNode::detachFrom(CBonusSystemNode & parent)
{ {
assert(vstd::contains(parents, parent)); assert(vstd::contains(parents, &parent));
if(!isHypothetic()) if(!isHypothetic())
{ {
if(parent->actsAsBonusSourceOnly()) if(parent.actsAsBonusSourceOnly())
parent->removedRedDescendant(this); parent.removedRedDescendant(*this);
else else
removedRedDescendant(parent); removedRedDescendant(parent);
} }
if (vstd::contains(parents, parent)) if (vstd::contains(parents, &parent))
{ {
parents -= parent; parents -= &parent;
} }
else else
{ {
logBonus->error("Error on Detach. Node %s (nodeType=%d) has not parent %s (nodeType=%d)" logBonus->error("Error on Detach. Node %s (nodeType=%d) has not parent %s (nodeType=%d)"
, nodeShortInfo(), nodeType, parent->nodeShortInfo(), parent->nodeType); , nodeShortInfo(), nodeType, parent.nodeShortInfo(), parent.nodeType);
} }
if(!isHypothetic()) if(!isHypothetic())
{ {
parent->childDetached(this); parent.childDetached(*this);
} }
CBonusSystemNode::treeHasChanged(); CBonusSystemNode::treeHasChanged();
} }
@ -1304,27 +1304,27 @@ void CBonusSystemNode::unpropagateBonus(std::shared_ptr<Bonus> b)
child->unpropagateBonus(b); child->unpropagateBonus(b);
} }
void CBonusSystemNode::newChildAttached(CBonusSystemNode *child) void CBonusSystemNode::newChildAttached(CBonusSystemNode & child)
{ {
assert(!vstd::contains(children, child)); assert(!vstd::contains(children, &child));
children.push_back(child); children.push_back(&child);
} }
void CBonusSystemNode::childDetached(CBonusSystemNode *child) void CBonusSystemNode::childDetached(CBonusSystemNode & child)
{ {
if(vstd::contains(children, child)) if(vstd::contains(children, &child))
children -= child; children -= &child;
else else
{ {
logBonus->error("Error on Detach. Node %s (nodeType=%d) is not a child of %s (nodeType=%d)" logBonus->error("Error on Detach. Node %s (nodeType=%d) is not a child of %s (nodeType=%d)"
, child->nodeShortInfo(), child->nodeType, nodeShortInfo(), nodeType); , child.nodeShortInfo(), child.nodeType, nodeShortInfo(), nodeType);
} }
} }
void CBonusSystemNode::detachFromAll() void CBonusSystemNode::detachFromAll()
{ {
while(parents.size()) while(parents.size())
detachFrom(parents.front()); detachFrom(*parents.front());
} }
bool CBonusSystemNode::isIndependentNode() const bool CBonusSystemNode::isIndependentNode() const
@ -1393,12 +1393,12 @@ void CBonusSystemNode::getRedChildren(TNodes &out)
} }
} }
void CBonusSystemNode::newRedDescendant(CBonusSystemNode * descendant) void CBonusSystemNode::newRedDescendant(CBonusSystemNode & descendant)
{ {
for(auto b : exportedBonuses) for(auto b : exportedBonuses)
{ {
if(b->propagator) if(b->propagator)
descendant->propagateBonus(b, *this); descendant.propagateBonus(b, *this);
} }
TNodes redParents; TNodes redParents;
getRedAncestors(redParents); //get all red parents recursively getRedAncestors(redParents); //get all red parents recursively
@ -1408,16 +1408,16 @@ void CBonusSystemNode::newRedDescendant(CBonusSystemNode * descendant)
for(auto b : parent->exportedBonuses) for(auto b : parent->exportedBonuses)
{ {
if(b->propagator) if(b->propagator)
descendant->propagateBonus(b, *this); descendant.propagateBonus(b, *this);
} }
} }
} }
void CBonusSystemNode::removedRedDescendant(CBonusSystemNode *descendant) void CBonusSystemNode::removedRedDescendant(CBonusSystemNode & descendant)
{ {
for(auto b : exportedBonuses) for(auto b : exportedBonuses)
if(b->propagator) if(b->propagator)
descendant->unpropagateBonus(b); descendant.unpropagateBonus(b);
TNodes redParents; TNodes redParents;
getRedAncestors(redParents); //get all red parents recursively getRedAncestors(redParents); //get all red parents recursively
@ -1426,7 +1426,7 @@ void CBonusSystemNode::removedRedDescendant(CBonusSystemNode *descendant)
{ {
for(auto b : parent->exportedBonuses) for(auto b : parent->exportedBonuses)
if(b->propagator) if(b->propagator)
descendant->unpropagateBonus(b); descendant.unpropagateBonus(b);
} }
} }

View File

@ -791,21 +791,21 @@ public:
static PlayerColor retrieveNodeOwner(const CBonusSystemNode * node); static PlayerColor retrieveNodeOwner(const CBonusSystemNode * node);
std::shared_ptr<Bonus> getBonusLocalFirst(const CSelector & selector); std::shared_ptr<Bonus> getBonusLocalFirst(const CSelector & selector);
void attachTo(CBonusSystemNode *parent); void attachTo(CBonusSystemNode & parent);
void detachFrom(CBonusSystemNode *parent); void detachFrom(CBonusSystemNode & parent);
void detachFromAll(); void detachFromAll();
virtual void addNewBonus(const std::shared_ptr<Bonus>& b); virtual void addNewBonus(const std::shared_ptr<Bonus>& b);
void accumulateBonus(const std::shared_ptr<Bonus>& b); //add value of bonus with same type/subtype or create new void accumulateBonus(const std::shared_ptr<Bonus>& b); //add value of bonus with same type/subtype or create new
void newChildAttached(CBonusSystemNode *child); void newChildAttached(CBonusSystemNode & child);
void childDetached(CBonusSystemNode *child); void childDetached(CBonusSystemNode & child);
void propagateBonus(std::shared_ptr<Bonus> b, const CBonusSystemNode & source); void propagateBonus(std::shared_ptr<Bonus> b, const CBonusSystemNode & source);
void unpropagateBonus(std::shared_ptr<Bonus> b); void unpropagateBonus(std::shared_ptr<Bonus> b);
void removeBonus(const std::shared_ptr<Bonus>& b); void removeBonus(const std::shared_ptr<Bonus>& b);
void removeBonuses(const CSelector & selector); void removeBonuses(const CSelector & selector);
void removeBonusesRecursive(const CSelector & s); void removeBonusesRecursive(const CSelector & s);
void newRedDescendant(CBonusSystemNode *descendant); //propagation needed void newRedDescendant(CBonusSystemNode & descendant); //propagation needed
void removedRedDescendant(CBonusSystemNode *descendant); //de-propagation needed void removedRedDescendant(CBonusSystemNode & descendant); //de-propagation needed
bool isIndependentNode() const; //node is independent when it has no parents nor children bool isIndependentNode() const; //node is independent when it has no parents nor children
bool actsAsBonusSourceOnly() const; bool actsAsBonusSourceOnly() const;

View File

@ -414,7 +414,7 @@ DLL_LINKAGE void RemoveObject::applyGs(CGameState *gs)
PlayerState * p = gs->getPlayerState(beatenHero->tempOwner); PlayerState * p = gs->getPlayerState(beatenHero->tempOwner);
gs->map->heroesOnMap -= beatenHero; gs->map->heroesOnMap -= beatenHero;
p->heroes -= beatenHero; p->heroes -= beatenHero;
beatenHero->detachFrom(beatenHero->whereShouldBeAttachedOnSiege(gs)); beatenHero->detachFrom(*beatenHero->whereShouldBeAttachedOnSiege(gs));
beatenHero->tempOwner = PlayerColor::NEUTRAL; //no one owns beaten hero beatenHero->tempOwner = PlayerColor::NEUTRAL; //no one owns beaten hero
vstd::erase_if(beatenHero->artifactsInBackpack, [](const ArtSlotInfo& asi) vstd::erase_if(beatenHero->artifactsInBackpack, [](const ArtSlotInfo& asi)
{ {
@ -683,7 +683,7 @@ DLL_LINKAGE void HeroRecruited::applyGs(CGameState *gs)
gs->map->heroesOnMap.push_back(h); gs->map->heroesOnMap.push_back(h);
p->heroes.push_back(h); p->heroes.push_back(h);
h->attachTo(p); h->attachTo(*p);
if(fresh) if(fresh)
{ {
h->initObj(gs->getRandomGenerator()); h->initObj(gs->getRandomGenerator());
@ -701,8 +701,8 @@ DLL_LINKAGE void GiveHero::applyGs(CGameState *gs)
CGHeroInstance *h = gs->getHero(id); CGHeroInstance *h = gs->getHero(id);
//bonus system //bonus system
h->detachFrom(&gs->globalEffects); h->detachFrom(gs->globalEffects);
h->attachTo(gs->getPlayerState(player)); h->attachTo(*gs->getPlayerState(player));
h->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, h->type->heroClass->getIndex())->getTemplates().front(); h->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, h->type->heroClass->getIndex())->getTemplates().front();
gs->map->removeBlockVisTiles(h,true); gs->map->removeBlockVisTiles(h,true);
@ -1153,7 +1153,7 @@ DLL_LINKAGE void DisassembledArtifact::applyGs(CGameState *gs)
{ {
ArtifactLocation constituentLoc = al; ArtifactLocation constituentLoc = al;
constituentLoc.slot = (ci.slot >= 0 ? ci.slot : al.slot); //-1 is slot of main constituent -> it'll replace combined artifact in its pos constituentLoc.slot = (ci.slot >= 0 ? ci.slot : al.slot); //-1 is slot of main constituent -> it'll replace combined artifact in its pos
disassembled->detachFrom(ci.art); disassembled->detachFrom(*ci.art);
ci.art->putAt(constituentLoc); ci.art->putAt(constituentLoc);
} }
@ -1281,10 +1281,10 @@ DLL_LINKAGE void SetObjectProperty::applyGs(CGameState *gs)
} }
} }
CBonusSystemNode *nodeToMove = cai->whatShouldBeAttached(); CBonusSystemNode & nodeToMove = cai->whatShouldBeAttached();
nodeToMove->detachFrom(cai->whereShouldBeAttached(gs)); nodeToMove.detachFrom(cai->whereShouldBeAttached(gs));
obj->setProperty(what,val); obj->setProperty(what,val);
nodeToMove->attachTo(cai->whereShouldBeAttached(gs)); nodeToMove.attachTo(cai->whereShouldBeAttached(gs));
} }
else //not an armed instance else //not an armed instance
{ {

View File

@ -85,7 +85,7 @@ ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const Js
info->animation = json["animation"].String(); info->animation = json["animation"].String();
info->width = json["width"].Integer(); info->width = json["width"].Integer();
info->height = json["height"].Integer(); info->height = json["height"].Integer();
for(auto & t : json["allowedTerrain"].Vector()) for(auto & t : json["allowedTerrains"].Vector())
info->allowedTerrains.emplace_back(VLC->terrainTypeHandler->getInfoByName(t.String())->id); info->allowedTerrains.emplace_back(VLC->terrainTypeHandler->getInfoByName(t.String())->id);
for(auto & t : json["specialBattlefields"].Vector()) for(auto & t : json["specialBattlefields"].Vector())
info->allowedSpecialBfields.emplace_back(t.String()); info->allowedSpecialBfields.emplace_back(t.String());

View File

@ -84,7 +84,7 @@ void BattleInfo::localInit()
{ {
auto armyObj = battleGetArmyObject(i); auto armyObj = battleGetArmyObject(i);
armyObj->battle = this; armyObj->battle = this;
armyObj->attachTo(this); armyObj->attachTo(*this);
} }
for(CStack * s : stacks) for(CStack * s : stacks)

View File

@ -142,17 +142,18 @@ void CArmedInstance::armyChanged()
updateMoraleBonusFromArmy(); updateMoraleBonusFromArmy();
} }
CBonusSystemNode * CArmedInstance::whereShouldBeAttached(CGameState *gs) CBonusSystemNode & CArmedInstance::whereShouldBeAttached(CGameState * gs)
{ {
if(tempOwner < PlayerColor::PLAYER_LIMIT) if(tempOwner < PlayerColor::PLAYER_LIMIT)
return gs->getPlayerState(tempOwner); if(auto * where = gs->getPlayerState(tempOwner))
else return *where;
return &gs->globalEffects;
return gs->globalEffects;
} }
CBonusSystemNode * CArmedInstance::whatShouldBeAttached() CBonusSystemNode & CArmedInstance::whatShouldBeAttached()
{ {
return this; return *this;
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -33,8 +33,8 @@ public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// int valOfGlobalBonuses(CSelector selector) const; //used only for castle interface ??? // int valOfGlobalBonuses(CSelector selector) const; //used only for castle interface ???
virtual CBonusSystemNode *whereShouldBeAttached(CGameState *gs); virtual CBonusSystemNode & whereShouldBeAttached(CGameState * gs);
virtual CBonusSystemNode *whatShouldBeAttached(); virtual CBonusSystemNode & whatShouldBeAttached();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
CArmedInstance(); CArmedInstance();

View File

@ -1062,17 +1062,17 @@ CBonusSystemNode * CGHeroInstance::whereShouldBeAttachedOnSiege(CGameState * gs)
if(visitedTown) if(visitedTown)
return whereShouldBeAttachedOnSiege(visitedTown->isBattleOutsideTown(this)); return whereShouldBeAttachedOnSiege(visitedTown->isBattleOutsideTown(this));
return CArmedInstance::whereShouldBeAttached(gs); return &CArmedInstance::whereShouldBeAttached(gs);
} }
CBonusSystemNode * CGHeroInstance::whereShouldBeAttached(CGameState * gs) CBonusSystemNode & CGHeroInstance::whereShouldBeAttached(CGameState * gs)
{ {
if(visitedTown) if(visitedTown)
{ {
if(inTownGarrison) if(inTownGarrison)
return visitedTown; return *visitedTown;
else else
return &visitedTown->townAndVis; return visitedTown->townAndVis;
} }
else else
return CArmedInstance::whereShouldBeAttached(gs); return CArmedInstance::whereShouldBeAttached(gs);

View File

@ -240,7 +240,7 @@ public:
ArtBearer::ArtBearer bearerType() const override; ArtBearer::ArtBearer bearerType() const override;
///IBonusBearer ///IBonusBearer
CBonusSystemNode * whereShouldBeAttached(CGameState *gs) override; CBonusSystemNode & whereShouldBeAttached(CGameState * gs) override;
std::string nodeName() const override; std::string nodeName() const override;
CBonusSystemNode * whereShouldBeAttachedOnSiege(const bool isBattleOutsideTown) const; CBonusSystemNode * whereShouldBeAttachedOnSiege(const bool isBattleOutsideTown) const;

View File

@ -1146,7 +1146,7 @@ std::string CGTownInstance::nodeName() const
void CGTownInstance::deserializationFix() void CGTownInstance::deserializationFix()
{ {
attachTo(&townAndVis); attachTo(townAndVis);
//Hero is already handled by CGameState::attachArmedObjects //Hero is already handled by CGameState::attachArmedObjects
@ -1216,8 +1216,8 @@ void CGTownInstance::setVisitingHero(CGHeroInstance *h)
{ {
PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner); PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner);
assert(p); assert(p);
h->detachFrom(p); h->detachFrom(*p);
h->attachTo(&townAndVis); h->attachTo(townAndVis);
visitingHero = h; visitingHero = h;
h->visitedTown = this; h->visitedTown = this;
h->inTownGarrison = false; h->inTownGarrison = false;
@ -1226,8 +1226,8 @@ void CGTownInstance::setVisitingHero(CGHeroInstance *h)
{ {
PlayerState *p = cb->gameState()->getPlayerState(visitingHero->tempOwner); PlayerState *p = cb->gameState()->getPlayerState(visitingHero->tempOwner);
visitingHero->visitedTown = nullptr; visitingHero->visitedTown = nullptr;
visitingHero->detachFrom(&townAndVis); visitingHero->detachFrom(townAndVis);
visitingHero->attachTo(p); visitingHero->attachTo(*p);
visitingHero = nullptr; visitingHero = nullptr;
} }
} }
@ -1239,8 +1239,8 @@ void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
{ {
PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner); PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner);
assert(p); assert(p);
h->detachFrom(p); h->detachFrom(*p);
h->attachTo(this); h->attachTo(*this);
garrisonHero = h; garrisonHero = h;
h->visitedTown = this; h->visitedTown = this;
h->inTownGarrison = true; h->inTownGarrison = true;
@ -1250,8 +1250,8 @@ void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
PlayerState *p = cb->gameState()->getPlayerState(garrisonHero->tempOwner); PlayerState *p = cb->gameState()->getPlayerState(garrisonHero->tempOwner);
garrisonHero->visitedTown = nullptr; garrisonHero->visitedTown = nullptr;
garrisonHero->inTownGarrison = false; garrisonHero->inTownGarrison = false;
garrisonHero->detachFrom(this); garrisonHero->detachFrom(*this);
garrisonHero->attachTo(p); garrisonHero->attachTo(*p);
garrisonHero = nullptr; garrisonHero = nullptr;
} }
updateMoraleBonusFromArmy(); //avoid giving morale bonus for same army twice updateMoraleBonusFromArmy(); //avoid giving morale bonus for same army twice
@ -1290,9 +1290,9 @@ int CGTownInstance::getTownLevel() const
return level; return level;
} }
CBonusSystemNode * CGTownInstance::whatShouldBeAttached() CBonusSystemNode & CGTownInstance::whatShouldBeAttached()
{ {
return &townAndVis; return townAndVis;
} }
const CArmedInstance * CGTownInstance::getUpperArmy() const const CArmedInstance * CGTownInstance::getUpperArmy() const

View File

@ -274,7 +274,7 @@ public:
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
CBonusSystemNode *whatShouldBeAttached() override; CBonusSystemNode & whatShouldBeAttached() override;
std::string nodeName() const override; std::string nodeName() const override;
void updateMoraleBonusFromArmy() override; void updateMoraleBonusFromArmy() override;
void deserializationFix(); void deserializationFix();

View File

@ -1011,7 +1011,7 @@ void MainWindow::onSelectionMade(int level, bool anythingSelected)
{ {
if (level == mapLevel) if (level == mapLevel)
{ {
auto info = QString::asprintf("Selection on layer %d: %b", level, anythingSelected ? "true" : "false"); auto info = QString::asprintf("Selection on layer %d: %s", level, anythingSelected ? "true" : "false");
setStatusMessage(info); setStatusMessage(info);
ui->actionErase->setEnabled(anythingSelected); ui->actionErase->setEnabled(anythingSelected);