2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* SideInBattle.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "SideInBattle.h"
|
2025-03-30 18:32:07 +03:00
|
|
|
|
|
|
|
#include "../IGameCallback.h"
|
|
|
|
#include "../mapObjects/CGHeroInstance.h"
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
void SideInBattle::init(const CGHeroInstance * Hero, const CArmedInstance * Army)
|
|
|
|
{
|
2025-03-30 18:32:07 +03:00
|
|
|
armyObjectID = Army->id;
|
|
|
|
if (Hero)
|
|
|
|
heroID = Hero->id;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
2025-03-30 18:32:07 +03:00
|
|
|
switch(Army->ID.toEnum())
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
case Obj::CREATURE_GENERATOR1:
|
|
|
|
case Obj::CREATURE_GENERATOR2:
|
|
|
|
case Obj::CREATURE_GENERATOR3:
|
|
|
|
case Obj::CREATURE_GENERATOR4:
|
|
|
|
color = PlayerColor::NEUTRAL;
|
|
|
|
break;
|
|
|
|
default:
|
2025-03-30 18:32:07 +03:00
|
|
|
color = Army->getOwner();
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(color == PlayerColor::UNFLAGGABLE)
|
|
|
|
color = PlayerColor::NEUTRAL;
|
|
|
|
}
|
|
|
|
|
2025-03-30 18:32:07 +03:00
|
|
|
const CArmedInstance * SideInBattle::getArmy() const
|
|
|
|
{
|
|
|
|
if (armyObjectID.hasValue())
|
|
|
|
return dynamic_cast<const CArmedInstance*>(cb->getObjInstance(armyObjectID));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * SideInBattle::getHero() const
|
|
|
|
{
|
|
|
|
if (heroID.hasValue())
|
|
|
|
return cb->getHero(heroID);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|