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

Merge remote-tracking branch 'origin/beta' into fix_rmg_object_pos

This commit is contained in:
Tomasz Zieliński 2023-08-11 10:58:26 +02:00
commit 83d97626fe
13 changed files with 58 additions and 33 deletions

View File

@ -170,7 +170,7 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
std::vector<SlotInfo> newArmy;
uint64_t newValue = 0;
newArmyInstance.clear();
newArmyInstance.clearSlots();
for(auto & slot : sortedSlots)
{

View File

@ -636,7 +636,9 @@ void BattleResultWindow::show(Canvas & to)
void BattleResultWindow::buttonPressed(int button)
{
resultCallback(button);
if (resultCallback)
resultCallback(button);
CPlayerInterface &intTmp = owner; //copy reference because "this" will be destructed soon
close();

View File

@ -127,13 +127,26 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
void BattleObstacleController::showAbsoluteObstacles(Canvas & canvas)
{
//Blit absolute obstacles
for(auto & oi : owner.curInt->cb->battleGetAllObstacles())
for(auto & obstacle : owner.curInt->cb->battleGetAllObstacles())
{
if(oi->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
if(obstacle->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE)
{
auto img = getObstacleImage(*oi);
auto img = getObstacleImage(*obstacle);
if(img)
canvas.draw(img, Point(oi->getInfo().width, oi->getInfo().height));
canvas.draw(img, Point(obstacle->getInfo().width, obstacle->getInfo().height));
}
if (obstacle->obstacleType == CObstacleInstance::USUAL)
{
if (obstacle->getInfo().isForegroundObstacle)
continue;
auto img = getObstacleImage(*obstacle);
if(img)
{
Point p = getObstaclePosition(img, *obstacle);
canvas.draw(img, p);
}
}
}
}
@ -148,11 +161,10 @@ void BattleObstacleController::collectRenderableObjects(BattleRenderer & rendere
if (obstacle->obstacleType == CObstacleInstance::MOAT)
continue;
bool isForeground = obstacle->obstacleType == CObstacleInstance::USUAL && obstacle->getInfo().isForegroundObstacle;
if (obstacle->obstacleType == CObstacleInstance::USUAL && !obstacle->getInfo().isForegroundObstacle)
continue;
auto layer = isForeground ? EBattleFieldLayer::OBSTACLES_FG : EBattleFieldLayer::OBSTACLES_BG;
renderer.insert(layer, obstacle->pos, [this, obstacle]( BattleRenderer::RendererRef canvas ){
renderer.insert(EBattleFieldLayer::OBSTACLES, obstacle->pos, [this, obstacle]( BattleRenderer::RendererRef canvas ){
auto img = getObstacleImage(*obstacle);
if(img)
{

View File

@ -16,12 +16,11 @@ class BattleInterface;
enum class EBattleFieldLayer {
// confirmed ordering requirements:
OBSTACLES_BG = 0,
CORPSES = 0,
WALLS = 1,
HEROES = 2,
STACKS = 2, // after corpses, obstacles, walls
OBSTACLES_FG = 3, // after stacks
OBSTACLES = 3, // after stacks
STACK_AMOUNTS = 3, // after stacks, obstacles, corpses
EFFECTS = 4, // after obstacles, battlements
};

View File

@ -307,15 +307,13 @@ void BattleSiegeController::collectRenderableObjects(BattleRenderer & renderer)
renderer.insert( EBattleFieldLayer::STACKS, getWallPiecePosition(wallPiece), [this, wallPiece](BattleRenderer::RendererRef canvas){
owner.stacksController->showStack(canvas, getTurretStack(wallPiece));
});
renderer.insert( EBattleFieldLayer::OBSTACLES_FG, getWallPiecePosition(wallPiece), [this, wallPiece](BattleRenderer::RendererRef canvas){
renderer.insert( EBattleFieldLayer::OBSTACLES, getWallPiecePosition(wallPiece), [this, wallPiece](BattleRenderer::RendererRef canvas){
showWallPiece(canvas, wallPiece);
});
}
renderer.insert( EBattleFieldLayer::WALLS, getWallPiecePosition(wallPiece), [this, wallPiece](BattleRenderer::RendererRef canvas){
showWallPiece(canvas, wallPiece);
});
}
}

View File

@ -445,7 +445,7 @@ void CCreatureSet::setStackExp(const SlotID & slot, TExpType exp)
stacks[slot]->experience = exp;
}
void CCreatureSet::clear()
void CCreatureSet::clearSlots()
{
while(!stacks.empty())
{
@ -533,12 +533,12 @@ void CCreatureSet::changeStackCount(const SlotID & slot, TQuantity toAdd)
CCreatureSet::~CCreatureSet()
{
clear();
clearSlots();
}
void CCreatureSet::setToArmy(CSimpleArmy &src)
{
clear();
clearSlots();
while(src)
{
auto i = src.army.begin();
@ -1050,7 +1050,7 @@ void CStackBasicDescriptor::serializeJson(JsonSerializeFormat & handler)
}
}
void CSimpleArmy::clear()
void CSimpleArmy::clearSlots()
{
army.clear();
}

View File

@ -181,7 +181,7 @@ using TCreatureQueue = std::priority_queue<TPairCreatureSlot, std::vector<TPairC
class IArmyDescriptor
{
public:
virtual void clear() = 0;
virtual void clearSlots() = 0;
virtual bool setCreature(SlotID slot, CreatureID cre, TQuantity count) = 0;
};
@ -190,7 +190,7 @@ class DLL_LINKAGE CSimpleArmy : public IArmyDescriptor
{
public:
TSimpleSlots army;
void clear() override;
void clearSlots() override;
bool setCreature(SlotID slot, CreatureID cre, TQuantity count) override;
operator bool() const;
@ -226,7 +226,7 @@ public:
void addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
void addToSlot(const SlotID & slot, CStackInstance * stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
void clear() override;
void clearSlots() override;
void setFormation(bool tight);
CArmedInstance *castToArmyObj();

View File

@ -335,7 +335,7 @@ struct DLL_LINKAGE SetAvailableHero : public CPackForClient
{
SetAvailableHero()
{
army.clear();
army.clearSlots();
}
void applyGs(CGameState * gs);

View File

@ -38,6 +38,8 @@
VCMI_LIB_NAMESPACE_BEGIN
#define THROW_IF_NO_BATTLE if (!gs->curB) throw std::runtime_error("Trying to apply pack when no battle!");
void CPack::visit(ICPackVisitor & visitor)
{
visitBasic(visitor);
@ -2127,16 +2129,19 @@ void BattleStart::applyGs(CGameState * gs) const
void BattleNextRound::applyGs(CGameState * gs) const
{
THROW_IF_NO_BATTLE
gs->curB->nextRound(round);
}
void BattleSetActiveStack::applyGs(CGameState * gs) const
{
THROW_IF_NO_BATTLE
gs->curB->nextTurn(stack);
}
void BattleTriggerEffect::applyGs(CGameState * gs) const
{
THROW_IF_NO_BATTLE
CStack * st = gs->curB->getStack(stackID);
assert(st);
switch(static_cast<BonusType>(effect))
@ -2232,6 +2237,7 @@ void BattleLogMessage::applyBattle(IBattleState * battleState)
void BattleStackMoved::applyGs(CGameState *gs)
{
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
@ -2242,6 +2248,7 @@ void BattleStackMoved::applyBattle(IBattleState * battleState)
void BattleStackAttacked::applyGs(CGameState * gs)
{
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
@ -2252,6 +2259,7 @@ void BattleStackAttacked::applyBattle(IBattleState * battleState)
void BattleAttack::applyGs(CGameState * gs)
{
THROW_IF_NO_BATTLE
CStack * attacker = gs->curB->getStack(stackAttacking);
assert(attacker);
@ -2265,6 +2273,8 @@ void BattleAttack::applyGs(CGameState * gs)
void StartAction::applyGs(CGameState *gs)
{
THROW_IF_NO_BATTLE
CStack *st = gs->curB->getStack(ba.stackNumber);
if(ba.actionType == EActionType::END_TACTIC_PHASE)
@ -2313,7 +2323,7 @@ void StartAction::applyGs(CGameState *gs)
void BattleSpellCast::applyGs(CGameState * gs) const
{
assert(gs->curB);
THROW_IF_NO_BATTLE
if(castByHero)
{
@ -2326,6 +2336,7 @@ void BattleSpellCast::applyGs(CGameState * gs) const
void SetStackEffect::applyGs(CGameState *gs)
{
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
@ -2344,6 +2355,7 @@ void SetStackEffect::applyBattle(IBattleState * battleState)
void StacksInjured::applyGs(CGameState *gs)
{
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
@ -2355,6 +2367,7 @@ void StacksInjured::applyBattle(IBattleState * battleState)
void BattleUnitsChanged::applyGs(CGameState *gs)
{
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
@ -2385,8 +2398,8 @@ void BattleUnitsChanged::applyBattle(IBattleState * battleState)
void BattleObstaclesChanged::applyGs(CGameState * gs)
{
if(gs->curB)
applyBattle(gs->curB);
THROW_IF_NO_BATTLE;
applyBattle(gs->curB);
}
void BattleObstaclesChanged::applyBattle(IBattleState * battleState)
@ -2417,8 +2430,8 @@ CatapultAttack::~CatapultAttack() = default;
void CatapultAttack::applyGs(CGameState * gs)
{
if(gs->curB)
applyBattle(gs->curB);
THROW_IF_NO_BATTLE
applyBattle(gs->curB);
}
void CatapultAttack::visitTyped(ICPackVisitor & visitor)
@ -2444,6 +2457,7 @@ void CatapultAttack::applyBattle(IBattleState * battleState)
void BattleSetStackProperty::applyGs(CGameState * gs) const
{
THROW_IF_NO_BATTLE
CStack * stack = gs->curB->getStack(stackID);
switch(which)
{

View File

@ -58,7 +58,7 @@ std::string CBank::getHoverText(PlayerColor player) const
void CBank::setConfig(const BankConfig & config)
{
bc = std::make_unique<BankConfig>(config);
clear(); // remove all stacks, if any
clearSlots(); // remove all stacks, if any
for(const auto & stack : config.guards)
setCreature (SlotID(stacksCount()), stack.type->getId(), stack.count);

View File

@ -1736,7 +1736,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(const int3 & mapPosition, const Objec
{
if(!object->spells.empty())
{
object->clear();
object->spells.clear();
logGlobal->debug("Hero %s subID=%d has spells set twice (in map properties and on adventure map instance). Using the latter set...", object->getNameTextID(), object->subID);
}

View File

@ -222,7 +222,7 @@ bool RewardsWidget::commitChanges()
pandora->resources = ResourceSet();
pandora->artifacts.clear();
pandora->spells.clear();
pandora->creatures.clear();
pandora->creatures.clearSlots();
for(int row = 0; row < rewards; ++row)
{

View File

@ -112,7 +112,7 @@ void HeroPoolProcessor::onHeroEscaped(const PlayerColor & color, const CGHeroIns
sah.slotID = selectSlotForRole(color, sah.roleID);
sah.player = color;
sah.hid = hero->subID;
sah.army.clear();
sah.army.clearSlots();
sah.army.setCreature(SlotID(0), hero->type->initialArmy.at(0).creature, 1);
gameHandler->sendAndApply(&sah);
@ -148,7 +148,7 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
else
{
sah.roleID = TavernSlotRole::SINGLE_UNIT;
sah.army.clear();
sah.army.clearSlots();
sah.army.setCreature(SlotID(0), newHero->type->initialArmy[0].creature, 1);
}
}