2022-08-09 07:54:32 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
class CGObjectInstance;
|
2023-09-30 01:19:18 +02:00
|
|
|
class CRandomGenerator;
|
2022-08-09 07:54:32 +02:00
|
|
|
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;
|
2023-12-06 10:49:41 +02:00
|
|
|
bool isBlockedVisitable() const;
|
2023-12-06 21:49:28 +02:00
|
|
|
bool isRemovable() const;
|
2022-08-09 07:54:32 +02:00
|
|
|
const Area & getAccessibleArea() const;
|
2023-09-30 01:19:18 +02:00
|
|
|
void setTemplate(TerrainId terrain, CRandomGenerator &); //cache invalidation
|
|
|
|
void setAnyTemplate(CRandomGenerator &); //cache invalidation
|
2022-08-09 07:54:32 +02:00
|
|
|
|
2023-04-10 19:26:53 +02:00
|
|
|
int3 getTopTile() const;
|
2022-08-09 07:54:32 +02:00
|
|
|
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();
|
|
|
|
|
2023-09-30 01:19:18 +02:00
|
|
|
void finalize(RmgMap & map, CRandomGenerator &); //cache invalidation
|
2022-08-09 07:54:32 +02:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
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;
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
int3 getVisitablePosition() const;
|
|
|
|
const Area & getAccessibleArea(bool exceptLast = false) const;
|
2023-12-06 10:49:41 +02:00
|
|
|
const Area & getBlockVisitableArea() const;
|
2023-12-21 13:29:45 +02:00
|
|
|
const Area & getVisitableArea() const;
|
2023-12-06 21:49:28 +02:00
|
|
|
const Area & getRemovableArea() const;
|
|
|
|
const Area getEntrableArea() const;
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
const int3 & getPosition() const;
|
|
|
|
void setPosition(const int3 & position);
|
2023-09-30 01:19:18 +02:00
|
|
|
void setTemplate(const TerrainId & terrain, CRandomGenerator &);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
const Area & getArea() const; //lazy cache invalidation
|
2023-04-10 19:26:53 +02:00
|
|
|
const int3 getVisibleTop() const;
|
2023-06-08 19:51:21 +02:00
|
|
|
|
|
|
|
bool isGuarded() const;
|
|
|
|
void setGuardedIfMonster(const Instance & object);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
2023-09-30 01:19:18 +02:00
|
|
|
void finalize(RmgMap & map, CRandomGenerator &);
|
2023-12-06 10:49:41 +02:00
|
|
|
void clearCachedArea() const;
|
2022-08-09 07:54:32 +02:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::list<Instance> dInstances;
|
|
|
|
mutable Area dFullAreaCache;
|
|
|
|
mutable Area dAccessibleAreaCache, dAccessibleAreaFullCache;
|
2023-12-06 10:49:41 +02:00
|
|
|
mutable Area dBlockVisitableCache;
|
2023-12-21 13:29:45 +02:00
|
|
|
mutable Area dVisitableCache;
|
2023-12-06 21:49:28 +02:00
|
|
|
mutable Area dRemovableAreaCache;
|
2022-08-09 07:54:32 +02:00
|
|
|
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;
|
2023-06-08 19:51:21 +02:00
|
|
|
bool guarded;
|
2022-08-09 07:54:32 +02:00
|
|
|
};
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|