Skip to content

Commit

Permalink
LockDefinition cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Jan 1, 2025
1 parent 34fa03c commit e195b51
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 88 deletions.
60 changes: 11 additions & 49 deletions OpenTESArena/src/World/LockDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,30 @@

#include "components/debug/Debug.h"

void LockDefinition::LeveledLockDef::init(int lockLevel)
void LeveledLockDefinition::init(int lockLevel)
{
this->lockLevel = lockLevel;
}

void LockDefinition::KeyLockDef::init()
void KeyLockDefinition::init()
{
// Do nothing.
}

void LockDefinition::init(SNInt x, int y, WEInt z, Type type)
void LockDefinition::initLeveledLock(SNInt x, int y, WEInt z, int lockLevel)
{
this->x = x;
this->y = y;
this->z = z;
this->type = type;
this->type = LockDefinitionType::LeveledLock;
this->leveledLock.init(lockLevel);
}

LockDefinition LockDefinition::makeLeveledLock(SNInt x, int y, WEInt z, int lockLevel)
void LockDefinition::initKeyLock(SNInt x, int y, WEInt z)
{
LockDefinition lockDef;
lockDef.init(x, y, z, Type::LeveledLock);
lockDef.leveledLock.init(lockLevel);
return lockDef;
}

LockDefinition LockDefinition::makeKeyLock(SNInt x, int y, WEInt z)
{
LockDefinition lockDef;
lockDef.init(x, y, z, Type::KeyLock);
lockDef.keyLock.init();
return lockDef;
}

SNInt LockDefinition::getX() const
{
return this->x;
}

int LockDefinition::getY() const
{
return this->y;
}

WEInt LockDefinition::getZ() const
{
return this->z;
}

LockDefinition::Type LockDefinition::getType() const
{
return this->type;
}

const LockDefinition::LeveledLockDef &LockDefinition::getLeveledLockDef() const
{
DebugAssert(this->type == Type::LeveledLock);
return this->leveledLock;
}

const LockDefinition::KeyLockDef &LockDefinition::getKeyLockDef() const
{
DebugAssert(this->type == Type::KeyLock);
return this->keyLock;
this->x = x;
this->y = y;
this->z = z;
this->type = LockDefinitionType::KeyLock;
this->keyLock.init();
}
58 changes: 25 additions & 33 deletions OpenTESArena/src/World/LockDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,42 @@

#include "../Voxels/VoxelUtils.h"

// Supports both locks that can be picked, and locks that require a key.
class LockDefinition
enum class LockDefinitionType
{
public:
enum class Type { LeveledLock, KeyLock };
LeveledLock,
KeyLock
};

class LeveledLockDef
{
private:
int lockLevel;
public:
void init(int lockLevel);
};
struct LeveledLockDefinition
{
int lockLevel;

class KeyLockDef
{
private:
// @todo: key reference somewhere
public:
void init();
};
private:
void init(int lockLevel);
};

struct KeyLockDefinition
{
// @todo: key reference somewhere

void init();
};

// Supports both locks that can be picked, and locks that require a key.
struct LockDefinition
{
SNInt x;
int y;
WEInt z;
Type type;
LockDefinitionType type;

union
{
LeveledLockDef leveledLock;
KeyLockDef keyLock;
LeveledLockDefinition leveledLock;
KeyLockDefinition keyLock;
};

void init(SNInt x, int y, WEInt z, Type type);
public:
static LockDefinition makeLeveledLock(SNInt x, int y, WEInt z, int lockLevel);
static LockDefinition makeKeyLock(SNInt x, int y, WEInt z);

SNInt getX() const;
int getY() const;
WEInt getZ() const;
Type getType() const;
const LeveledLockDef &getLeveledLockDef() const;
const KeyLockDef &getKeyLockDef() const;
void initLeveledLock(SNInt x, int y, WEInt z, int lockLevel);
void initKeyLock(SNInt x, int y, WEInt z);
};

#endif
13 changes: 7 additions & 6 deletions OpenTESArena/src/World/MapGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,12 @@ namespace MapGeneration
{
const OriginalInt2 lockPos(lock.x, lock.y);
const WorldInt2 newLockPos = VoxelUtils::originalVoxelToWorldVoxel(lockPos);
return LockDefinition::makeLeveledLock(newLockPos.x, 1, newLockPos.y, lock.lockLevel);
LockDefinition lockDef;
lockDef.initLeveledLock(newLockPos.x, 1, newLockPos.y, lock.lockLevel);
return lockDef;
}

VoxelTriggerDefinition makeTriggerDefFromArenaTrigger(const ArenaTypes::MIFTrigger &trigger,
const INFFile &inf)
VoxelTriggerDefinition makeTriggerDefFromArenaTrigger(const ArenaTypes::MIFTrigger &trigger, const INFFile &inf)
{
const OriginalInt2 triggerPos(trigger.x, trigger.y);
const WorldInt2 newTriggerPos = VoxelUtils::originalVoxelToWorldVoxel(triggerPos);
Expand Down Expand Up @@ -1552,9 +1553,9 @@ namespace MapGeneration
}

const LockDefinition &lockDef = outLevelInfoDef->getLockDef(lockDefID);
const SNInt x = lockDef.getX();
const int y = lockDef.getY();
const WEInt z = lockDef.getZ();
const SNInt x = lockDef.x;
const int y = lockDef.y;
const WEInt z = lockDef.z;
outLevelDef->addLock(lockDefID, WorldInt3(x, y, z));
}

Expand Down

0 comments on commit e195b51

Please sign in to comment.