1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/rmg/RmgObject.h

124 lines
3.3 KiB
C++
Raw Normal View History

/*
* RmgObject.h, 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
*
*/
#pragma once
#include "../GameConstants.h"
#include "../int3.h"
#include "RmgArea.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CGObjectInstance;
class RmgMap;
namespace rmg {
class Object
{
public:
class Instance
{
public:
Instance(const Object& parent, CGObjectInstance & object);
Instance(const Object& parent, CGObjectInstance & object, const int3 & position);
const Area & getBlockedArea() const;
int3 getVisitablePosition() const;
bool isVisitableFrom(const int3 & tile) const;
bool isBlockedVisitable() const;
bool isRemovable() const;
const Area & getAccessibleArea() const;
2024-05-01 12:15:07 +02:00
Area getBorderAbove() const;
void setTemplate(TerrainId terrain, vstd::RNG &); //cache invalidation
void setAnyTemplate(vstd::RNG &); //cache invalidation
int3 getTopTile() const;
int3 getPosition(bool isAbsolute = false) const;
void setPosition(const int3 & position); //cache invalidation
void setPositionRaw(const int3 & position); //no cache invalidation
const CGObjectInstance & object() const;
CGObjectInstance & object();
void finalize(RmgMap & map, vstd::RNG &); //cache invalidation
void clear();
2024-01-19 17:26:51 +02:00
std::function<void(CGObjectInstance *)> onCleared;
private:
mutable Area dBlockedAreaCache;
int3 dPosition;
mutable Area dAccessibleAreaCache;
CGObjectInstance & dObject;
const Object & dParent;
};
Object() = default;
Object(const Object & object);
Object(CGObjectInstance & object);
Object(CGObjectInstance & object, const int3 & position);
void addInstance(Instance & object);
Instance & addInstance(CGObjectInstance & object);
Instance & addInstance(CGObjectInstance & object, const int3 & position);
2023-12-13 23:20:23 +02:00
std::list<Instance*> & instances();
std::list<const Instance*> & instances() const;
int3 getVisitablePosition() const;
const Area & getAccessibleArea(bool exceptLast = false) const;
const Area & getBlockVisitableArea() const;
2023-12-21 13:29:45 +02:00
const Area & getVisitableArea() const;
const Area & getRemovableArea() const;
const Area getEntrableArea() const;
2024-05-01 12:15:07 +02:00
const Area & getBorderAbove() const;
const int3 & getPosition() const;
void setPosition(const int3 & position);
void setTemplate(const TerrainId & terrain, vstd::RNG &);
const Area & getArea() const; //lazy cache invalidation
const int3 getVisibleTop() const;
bool isGuarded() const;
int3 getGuardPos() const;
void setGuardedIfMonster(const Instance & object);
2024-05-01 11:34:34 +02:00
void setValue(uint32_t value);
uint32_t getValue() const;
void finalize(RmgMap & map, vstd::RNG &);
void clearCachedArea() const;
void clear();
private:
std::list<Instance> dInstances;
mutable Area dFullAreaCache;
mutable Area dAccessibleAreaCache;
mutable Area dAccessibleAreaFullCache;
mutable Area dBlockVisitableCache;
2023-12-21 13:29:45 +02:00
mutable Area dVisitableCache;
mutable Area dRemovableAreaCache;
2024-05-01 12:15:07 +02:00
mutable Area dBorderAboveCache;
int3 dPosition;
2023-12-13 23:20:23 +02:00
mutable std::optional<int3> visibleTopOffset;
mutable std::list<Object::Instance*> cachedInstanceList;
mutable std::list<const Object::Instance*> cachedInstanceConstList;
bool guarded;
2024-05-01 11:34:34 +02:00
uint32_t value;
};
}
VCMI_LIB_NAMESPACE_END