2012-10-06 16:04:58 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "RedstoneSimulator.h"
|
2012-12-26 12:16:33 -05:00
|
|
|
#include "../DispenserEntity.h"
|
2012-10-13 05:53:28 -04:00
|
|
|
#include "../Piston.h"
|
|
|
|
#include "../World.h"
|
|
|
|
#include "../BlockID.h"
|
|
|
|
#include "../Torch.h"
|
2013-03-03 10:06:01 -05:00
|
|
|
#include "../Chunk.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-10-06 16:04:58 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World)
|
2012-06-14 09:06:06 -04:00
|
|
|
: super(a_World)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cRedstoneSimulator::~cRedstoneSimulator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
void cRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if (a_Chunk == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
|
|
|
|
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
|
|
|
|
|
|
|
|
// Check if any close neighbor is redstone-related:
|
|
|
|
int MinY = (a_BlockY > 0) ? -1 : 0;
|
|
|
|
int MaxY = (a_BlockY < cChunkDef::Height - 1) ? 1 : 0;
|
|
|
|
for (int y = MinY; y <= MaxY; y++) for (int x = -1; x < 2; x++) for (int z = -1; z < 2; z++)
|
|
|
|
{
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
if (!a_Chunk->UnboundedRelGetBlock(RelX + x, a_BlockY + y, RelZ + z, BlockType, BlockMeta))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_REDSTONE_LAMP_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_LAMP_ON:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
|
|
|
case E_BLOCK_LEVER:
|
|
|
|
case E_BLOCK_STONE_BUTTON:
|
|
|
|
case E_BLOCK_WOODEN_BUTTON:
|
|
|
|
case E_BLOCK_TRIPWIRE_HOOK:
|
|
|
|
{
|
|
|
|
m_Blocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // switch (BlockType)
|
|
|
|
} // for y, x, z - neighbors
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
void cRedstoneSimulator::Simulate(float a_Dt)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
// Toggle torches on/off
|
2013-03-03 10:06:01 -05:00
|
|
|
while (!m_RefreshTorchesAround.empty())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i pos = m_RefreshTorchesAround.front();
|
|
|
|
m_RefreshTorchesAround.pop_front();
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
RefreshTorchesAround(pos);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set repeaters to correct values, and decrement ticks
|
2013-03-03 10:06:01 -05:00
|
|
|
for (RepeaterList::iterator itr = m_SetRepeaters.begin(); itr != m_SetRepeaters.end();)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (--itr->Ticks > 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Not yet, move to next item in the list
|
|
|
|
++itr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(itr->Position.x, itr->Position.y, itr->Position.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
if (itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_OFF))
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_ON, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
m_Blocks.push_back(itr->Position);
|
|
|
|
}
|
|
|
|
else if (!itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_OFF, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
m_Blocks.push_back(itr->Position);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
if (itr->bPowerOffNextTime)
|
|
|
|
{
|
|
|
|
itr->bPowerOn = false;
|
|
|
|
itr->bPowerOffNextTime = false;
|
|
|
|
itr->Ticks = 10; // TODO: Look up actual ticks from block metadata
|
|
|
|
++itr;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
itr = m_SetRepeaters.erase(itr);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle changed blocks
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
cCSLock Lock(m_CS);
|
2012-12-16 02:07:30 -05:00
|
|
|
std::swap(m_Blocks, m_BlocksBuffer);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
for (BlockList::iterator itr = m_BlocksBuffer.begin(); itr != m_BlocksBuffer.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
HandleChange(*itr);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
m_BlocksBuffer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
void cRedstoneSimulator::RefreshTorchesAround(const Vector3i & a_BlockPos)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
static Vector3i Surroundings [] = {
|
|
|
|
Vector3i(-1, 0, 0),
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 0, 1),
|
|
|
|
Vector3i(0, 1, 0), // Also toggle torch on top
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE TargetBlockType = E_BLOCK_REDSTONE_TORCH_ON;
|
|
|
|
BLOCKTYPE TargetRepeaterType = E_BLOCK_REDSTONE_REPEATER_OFF;
|
2013-03-03 10:06:01 -05:00
|
|
|
if (IsPowered(a_BlockPos, true))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
TargetBlockType = E_BLOCK_REDSTONE_TORCH_OFF;
|
|
|
|
TargetRepeaterType = E_BLOCK_REDSTONE_REPEATER_ON;
|
2013-03-03 10:06:01 -05:00
|
|
|
//if (m_World.GetBlock(a_BlockPos) == E_BLOCK_DIRT)
|
2012-06-14 09:06:06 -04:00
|
|
|
//{
|
2013-03-03 10:06:01 -05:00
|
|
|
// m_World.FastSetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_STONE, 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
//}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
//if (m_World.GetBlock(a_BlockPos) == E_BLOCK_STONE)
|
2012-06-14 09:06:06 -04:00
|
|
|
//{
|
2013-03-03 10:06:01 -05:00
|
|
|
// m_World.FastSetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_DIRT, 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i TorchPos = a_BlockPos + Surroundings[i];
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(TorchPos.x, TorchPos.y, TorchPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (BlockType != TargetBlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (cTorch::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos))
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
m_Blocks.push_back(TorchPos);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if ((BlockType != TargetRepeaterType) && IsRepeaterPointingAway(TorchPos, BlockMeta, a_BlockPos))
|
|
|
|
{
|
|
|
|
SetRepeater(TorchPos, 10, (TargetRepeaterType == E_BLOCK_REDSTONE_REPEATER_ON));
|
|
|
|
}
|
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (BlockType)
|
|
|
|
} // for i - Surroundings[]
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
void cRedstoneSimulator::HandleChange(const Vector3i & a_BlockPos)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
std::deque< Vector3i > SpreadStack;
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
static const Vector3i Surroundings[] = {
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(1, 1, 0),
|
|
|
|
Vector3i(1,-1, 0),
|
|
|
|
Vector3i(-1, 0, 0),
|
|
|
|
Vector3i(-1, 1, 0),
|
|
|
|
Vector3i(-1,-1, 0),
|
|
|
|
Vector3i(0, 0, 1),
|
|
|
|
Vector3i(0, 1, 1),
|
|
|
|
Vector3i(0,-1, 1),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 1,-1),
|
|
|
|
Vector3i(0,-1,-1),
|
|
|
|
Vector3i(0,-1, 0),
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// First check whether torch should be on or off
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
static const Vector3i Surroundings [] = {
|
|
|
|
Vector3i(-1, 0, 0),
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 0, 1),
|
|
|
|
Vector3i(0,-1, 0),
|
2012-12-16 02:07:30 -05:00
|
|
|
};
|
2013-03-03 10:06:01 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
Vector3i pos = a_BlockPos + Surroundings[i];
|
2013-03-03 10:06:01 -05:00
|
|
|
BLOCKTYPE OtherBlock = m_World.GetBlock(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
if (
|
|
|
|
(OtherBlock != E_BLOCK_AIR) &&
|
|
|
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
|
|
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_OFF)
|
|
|
|
)
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
RefreshTorchesAround(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
|
|
|
} // case "torches"
|
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Check if repeater is powered by a 'powered block' (not wires/torch)
|
|
|
|
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
|
|
|
Vector3i pos = a_BlockPos - Direction; // NOTE: It's minus Direction
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE OtherBlock = m_World.GetBlock(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
if (
|
|
|
|
(OtherBlock != E_BLOCK_AIR) &&
|
|
|
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) &&
|
|
|
|
(OtherBlock != E_BLOCK_REDSTONE_TORCH_OFF) &&
|
|
|
|
(OtherBlock != E_BLOCK_REDSTONE_WIRE)
|
|
|
|
)
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
RefreshTorchesAround(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetRepeater(a_BlockPos, 10, IsPowered(a_BlockPos, false));
|
|
|
|
}
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
BlockList Sources;
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
{
|
|
|
|
// If torch is still on, use it as a source
|
|
|
|
Sources.push_back(a_BlockPos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Repeater only spreads charge right in front, and up to one block up:
|
|
|
|
static const Vector3i Surroundings [] = {
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(0, 0, 0),
|
|
|
|
Vector3i(0, 1, 0),
|
2012-12-16 02:07:30 -05:00
|
|
|
};
|
|
|
|
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
2013-03-03 10:06:01 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
Vector3i pos = a_BlockPos + Direction + Surroundings[i];
|
|
|
|
if (PowerBlock(pos, a_BlockPos, 0xf))
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
SpreadStack.push_back(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
|
|
|
} // case E_BLOCK_REDSTONE_REPEATER_ON
|
|
|
|
|
|
|
|
case E_BLOCK_LEVER:
|
|
|
|
{
|
|
|
|
// Adding lever to the source queue
|
|
|
|
if (cRedstoneSimulator::IsLeverOn(BlockMeta))
|
|
|
|
{
|
|
|
|
Sources.push_back(a_BlockPos);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} // case E_BLOCK_LEVER
|
|
|
|
} // switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Power all blocks legally connected to the sources
|
2012-12-16 02:07:30 -05:00
|
|
|
if (BlockType != E_BLOCK_REDSTONE_REPEATER_ON)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
BlockList NewSources = RemoveCurrent(a_BlockPos);
|
2013-03-03 10:06:01 -05:00
|
|
|
Sources.insert(Sources.end(), NewSources.begin(), NewSources.end());
|
|
|
|
while (!Sources.empty())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i SourcePos = Sources.back();
|
|
|
|
Sources.pop_back();
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(SourcePos.x, SourcePos.y, SourcePos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_LEVER: // Treating lever as a torch
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
static Vector3i Surroundings [] = {
|
|
|
|
Vector3i(-1, 0, 0),
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 0, 1),
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
2012-12-16 02:07:30 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i OtherPos = SourcePos + Surroundings[i];
|
2012-12-16 02:07:30 -05:00
|
|
|
if (PowerBlock(OtherPos, a_BlockPos, 0xf))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
SpreadStack.push_back(OtherPos); // Changed, so add to stack
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
static Vector3i Surroundings [] = {
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(0, 0, 0),
|
|
|
|
Vector3i(0, 1, 0),
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
2012-12-16 02:07:30 -05:00
|
|
|
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i pos = SourcePos + Direction + Surroundings[i];
|
2012-12-16 02:07:30 -05:00
|
|
|
if (PowerBlock(pos, a_BlockPos, 0xf))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
SpreadStack.push_back(pos);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (BlockType)
|
|
|
|
} // while (Sources[])
|
|
|
|
} // if (!repeater_on)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Do a floodfill
|
2012-12-16 02:07:30 -05:00
|
|
|
while (!SpreadStack.empty())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i pos = SpreadStack.back();
|
|
|
|
SpreadStack.pop_back();
|
2013-02-28 08:39:20 -05:00
|
|
|
NIBBLETYPE Meta = m_World.GetBlockMeta(pos);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i OtherPos = pos + Surroundings[i];
|
2012-12-16 02:07:30 -05:00
|
|
|
if (PowerBlock(OtherPos, pos, Meta - 1))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
SpreadStack.push_back(OtherPos); // Changed, so add to stack
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only after a redstone area has been completely simulated the redstone entities can react
|
2012-12-16 02:07:30 -05:00
|
|
|
while (!m_RefreshPistons.empty())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i pos = m_RefreshPistons.back();
|
|
|
|
m_RefreshPistons.pop_back();
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE BlockType = m_World.GetBlock(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_PISTON:
|
|
|
|
case E_BLOCK_STICKY_PISTON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (IsPowered(pos))
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
cPiston Piston(&m_World);
|
2012-12-16 02:07:30 -05:00
|
|
|
Piston.ExtendPiston(pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
cPiston Piston(&m_World);
|
2012-12-16 02:07:30 -05:00
|
|
|
Piston.RetractPiston(pos.x, pos.y, pos.z);
|
|
|
|
}
|
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (BlockType)
|
|
|
|
} // while (m_RefreshPistons[])
|
2012-12-26 12:16:33 -05:00
|
|
|
|
|
|
|
while (!m_RefreshDispensers.empty())
|
|
|
|
{
|
|
|
|
Vector3i pos = m_RefreshDispensers.back();
|
|
|
|
m_RefreshDispensers.pop_back();
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE BlockType = m_World.GetBlock(pos);
|
2012-12-26 12:16:33 -05:00
|
|
|
if (BlockType == E_BLOCK_DISPENSER)
|
|
|
|
{
|
|
|
|
if (IsPowered(pos))
|
|
|
|
{
|
|
|
|
class cActivateDispenser :
|
|
|
|
public cDispenserCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cActivateDispenser()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Item(cDispenserEntity * a_Dispenser) override
|
|
|
|
{
|
|
|
|
a_Dispenser->Activate();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
cActivateDispenser DispAct;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.DoWithDispenserAt(pos.x, pos.y, pos.z, DispAct);
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
bool cRedstoneSimulator::PowerBlock(const Vector3i & a_BlockPos, const Vector3i & a_FromBlock, char a_Power)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (BlockMeta < a_Power)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.SetBlockMeta(a_BlockPos, a_Power);
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
case E_BLOCK_PISTON:
|
|
|
|
case E_BLOCK_STICKY_PISTON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
m_RefreshPistons.push_back(a_BlockPos);
|
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-26 12:16:33 -05:00
|
|
|
|
|
|
|
case E_BLOCK_DISPENSER:
|
|
|
|
{
|
|
|
|
m_RefreshDispensers.push_back(a_BlockPos);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (IsRepeaterPointingAway(a_BlockPos, BlockMeta, a_FromBlock))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
SetRepeater(a_BlockPos, 10, true);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
default:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
2012-12-16 02:07:30 -05:00
|
|
|
(BlockType != E_BLOCK_AIR) &&
|
|
|
|
(BlockType != E_BLOCK_REDSTONE_TORCH_ON) &&
|
|
|
|
(BlockType != E_BLOCK_REDSTONE_TORCH_OFF) &&
|
|
|
|
(BlockType != E_BLOCK_LEVER) // Treating lever as a torch, for refreshing
|
2012-12-16 00:52:45 -05:00
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (IsPowered(a_BlockPos, true))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
m_RefreshTorchesAround.push_back(a_BlockPos);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
int cRedstoneSimulator::UnPowerBlock(const Vector3i & a_BlockPos, const Vector3i & a_FromBlock)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2012-12-20 08:56:42 -05:00
|
|
|
if ((a_BlockPos.y < 0) || (a_BlockPos.y >= cChunkDef::Height))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-10-06 16:04:58 -04:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-10-06 16:04:58 -04:00
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if (BlockMeta > 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.SetBlockMeta(a_BlockPos, 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
case E_BLOCK_PISTON:
|
|
|
|
case E_BLOCK_STICKY_PISTON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
m_RefreshPistons.push_back(a_BlockPos);
|
2012-10-06 16:04:58 -04:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 00:52:45 -05:00
|
|
|
|
2012-10-06 16:04:58 -04:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return 2;
|
2012-10-06 16:04:58 -04:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
2012-12-16 00:52:45 -05:00
|
|
|
case E_BLOCK_LEVER:
|
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Check if lever is ON. If it is, report it back as a source
|
|
|
|
if (cRedstoneSimulator::IsLeverOn(BlockMeta))
|
2012-12-16 00:52:45 -05:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-10-06 16:04:58 -04:00
|
|
|
if (
|
2013-03-03 10:06:01 -05:00
|
|
|
IsRepeaterPointingTo(a_BlockPos, BlockMeta, a_FromBlock) || // Repeater is next to wire
|
2012-12-16 02:07:30 -05:00
|
|
|
IsRepeaterPointingTo(a_BlockPos, BlockMeta, a_FromBlock - Vector3i(0, 1, 0)) // Repeater is below wire
|
2012-10-06 16:04:58 -04:00
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
else if (IsRepeaterPointingAway(a_BlockPos, BlockMeta, a_FromBlock))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
SetRepeater(a_BlockPos, 10, false);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
// fall-through:
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (IsRepeaterPointingAway(a_BlockPos, BlockMeta, a_FromBlock))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
SetRepeater(a_BlockPos, 10, false);
|
2012-10-06 16:04:58 -04:00
|
|
|
}
|
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
default:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (
|
|
|
|
(BlockType != E_BLOCK_AIR) &&
|
|
|
|
(BlockType != E_BLOCK_REDSTONE_TORCH_ON) &&
|
|
|
|
(BlockType != E_BLOCK_REDSTONE_TORCH_OFF) &&
|
|
|
|
(BlockType != E_BLOCK_LEVER)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-10-06 16:04:58 -04:00
|
|
|
if (!IsPowered(a_BlockPos, true))
|
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
m_RefreshTorchesAround.push_back(a_BlockPos);
|
2012-10-06 16:04:58 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-10-06 16:04:58 -04:00
|
|
|
} // switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Removes current from all powered redstone wires until it reaches an energy source.
|
|
|
|
// Also returns all energy sources it encountered
|
2013-03-03 10:06:01 -05:00
|
|
|
cRedstoneSimulator::BlockList cRedstoneSimulator::RemoveCurrent(const Vector3i & a_BlockPos)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
std::deque< Vector3i > SpreadStack;
|
|
|
|
std::deque< Vector3i > FoundSources;
|
|
|
|
|
|
|
|
Vector3i Surroundings[] = {
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(1, 1, 0),
|
|
|
|
Vector3i(1,-1, 0),
|
|
|
|
Vector3i(-1, 0, 0),
|
|
|
|
Vector3i(-1, 1, 0),
|
|
|
|
Vector3i(-1,-1, 0),
|
|
|
|
Vector3i(0, 0, 1),
|
|
|
|
Vector3i(0, 1, 1),
|
|
|
|
Vector3i(0,-1, 1),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 1,-1),
|
|
|
|
Vector3i(0,-1,-1),
|
|
|
|
Vector3i(0,-1, 0),
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Repeaters only spread to their front front and 0 or 1 block up
|
|
|
|
static Vector3i Surroundings [] = {
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(0, 0, 0),
|
|
|
|
Vector3i(0, 1, 0),
|
2012-12-16 02:07:30 -05:00
|
|
|
};
|
|
|
|
Vector3i Direction = GetRepeaterDirection(BlockMeta);
|
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
Vector3i pos = a_BlockPos + Direction + Surroundings[i];
|
|
|
|
int RetVal = UnPowerBlock(pos, a_BlockPos);
|
|
|
|
if (RetVal == 1)
|
|
|
|
{
|
|
|
|
// Changed, so add to stack
|
|
|
|
SpreadStack.push_back(pos);
|
|
|
|
}
|
|
|
|
else if (RetVal == 2)
|
|
|
|
{
|
|
|
|
FoundSources.push_back(pos);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_LEVER:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
static Vector3i Surroundings [] = { // Torches only spread on the same level
|
|
|
|
Vector3i(-1, 0, 0),
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i(1, 0, 0),
|
|
|
|
Vector3i(0, 0,-1),
|
|
|
|
Vector3i(0, 0, 1),
|
2012-12-16 02:07:30 -05:00
|
|
|
};
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
Vector3i pos = Vector3i(a_BlockPos) + Surroundings[i];
|
|
|
|
int RetVal = UnPowerBlock(pos, a_BlockPos);
|
|
|
|
if (RetVal == 1)
|
2012-12-16 02:07:30 -05:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
SpreadStack.push_back(pos); // Changed, so add to stack
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
2013-03-03 10:06:01 -05:00
|
|
|
else if (RetVal == 2)
|
2012-12-16 02:07:30 -05:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
FoundSources.push_back(pos);
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
SpreadStack.push_back(a_BlockPos);
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // switch (BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
while (!SpreadStack.empty())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i pos = SpreadStack.back();
|
|
|
|
SpreadStack.pop_back();
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Vector3i OtherPos = pos + Surroundings[i];
|
2013-03-03 10:06:01 -05:00
|
|
|
int RetVal = UnPowerBlock(OtherPos, pos);
|
|
|
|
if (RetVal == 1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
SpreadStack.push_back(OtherPos); // Changed, so add to stack
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-03-03 10:06:01 -05:00
|
|
|
else if (RetVal == 2)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
FoundSources.push_back(OtherPos);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FoundSources;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
bool cRedstoneSimulator::IsPowering(const Vector3i & a_PowerPos, const Vector3i & a_BlockPos, eRedstoneDirection a_WireDirection, bool a_bOnlyByWire)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE PowerBlock;
|
|
|
|
NIBBLETYPE PowerMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_PowerPos.x, a_PowerPos.y, a_PowerPos.z, PowerBlock, PowerMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
// Filter out powering blocks for a_bOnlyByWire
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
|
|
|
!a_bOnlyByWire && (
|
|
|
|
(PowerBlock == E_BLOCK_REDSTONE_TORCH_ON) ||
|
|
|
|
(PowerBlock == E_BLOCK_LEVER)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
switch (PowerBlock)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// A repeater pointing towards block is regarded as wire
|
|
|
|
if (IsRepeaterPointingTo(a_PowerPos, PowerMeta, a_BlockPos))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (PowerMeta > 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if (GetWireDirection(a_PowerPos) == a_WireDirection)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
break;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
} // switch (PowerBlock)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
bool cRedstoneSimulator::IsPowered(const Vector3i & a_BlockPos, bool a_bOnlyByWire /* = false */)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
if ((BlockType == E_BLOCK_REDSTONE_REPEATER_OFF) || (BlockType == E_BLOCK_REDSTONE_REPEATER_ON))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
Vector3i Behind = a_BlockPos - GetRepeaterDirection(BlockMeta);
|
|
|
|
BLOCKTYPE BehindBlock;
|
|
|
|
NIBBLETYPE BehindMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(Behind.x, Behind.y, Behind.z, BehindBlock, BehindMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
switch (BehindBlock)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_LEVER:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// _X: TODO: Shouldn't a lever be checked if it is switched on?
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
return (BehindMeta > 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
{
|
|
|
|
return IsRepeaterPointingTo(Behind, BehindMeta, a_BlockPos);
|
|
|
|
}
|
|
|
|
} // switch (BehindBlock)
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
if (IsPowering(Vector3i(a_BlockPos.x - 1, a_BlockPos.y, a_BlockPos.z), a_BlockPos, REDSTONE_X_POS, a_bOnlyByWire))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
|
|
|
if (IsPowering(Vector3i(a_BlockPos.x + 1, a_BlockPos.y, a_BlockPos.z), a_BlockPos, REDSTONE_X_NEG, a_bOnlyByWire))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
|
|
|
if (IsPowering(Vector3i(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z - 1), a_BlockPos, REDSTONE_Z_POS, a_bOnlyByWire))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
|
|
|
if (IsPowering(Vector3i(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z + 1), a_BlockPos, REDSTONE_Z_NEG, a_bOnlyByWire))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-12-16 02:07:30 -05:00
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// Only wires can power the bottom block
|
2012-12-16 02:07:30 -05:00
|
|
|
BLOCKTYPE PosYType;
|
|
|
|
NIBBLETYPE PosYMeta;
|
2013-02-28 08:39:20 -05:00
|
|
|
m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y + 1, a_BlockPos.z, PosYType, PosYMeta);
|
2012-12-16 02:07:30 -05:00
|
|
|
if (PosYType == E_BLOCK_REDSTONE_WIRE)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
return (PosYMeta > 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Believe me, it works!! TODO: Add repeaters and low/high wires
|
2012-12-16 02:07:30 -05:00
|
|
|
cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
int Dir = REDSTONE_NONE;
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ);
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
|
|
|
(NegX == E_BLOCK_REDSTONE_WIRE) ||
|
|
|
|
(NegX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
|
|
|
(NegX == E_BLOCK_LEVER)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir |= (REDSTONE_X_POS);
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ);
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
|
|
|
(PosX == E_BLOCK_REDSTONE_WIRE) ||
|
|
|
|
(PosX == E_BLOCK_REDSTONE_TORCH_ON) ||
|
|
|
|
(PosX == E_BLOCK_LEVER)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir |= (REDSTONE_X_NEG);
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1);
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
|
|
|
(NegZ == E_BLOCK_REDSTONE_WIRE) ||
|
|
|
|
(NegZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
|
|
|
(NegZ == E_BLOCK_LEVER)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir ^= REDSTONE_X_POS;
|
|
|
|
Dir |= REDSTONE_X_NEG;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir ^= REDSTONE_X_NEG;
|
|
|
|
Dir |= REDSTONE_X_POS;
|
|
|
|
}
|
|
|
|
Dir |= REDSTONE_Z_POS;
|
|
|
|
}
|
2012-12-16 02:07:30 -05:00
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1);
|
2012-12-16 00:52:45 -05:00
|
|
|
if (
|
|
|
|
(PosZ == E_BLOCK_REDSTONE_WIRE) ||
|
|
|
|
(PosZ == E_BLOCK_REDSTONE_TORCH_ON) ||
|
|
|
|
(PosZ == E_BLOCK_LEVER)
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir ^= REDSTONE_X_POS;
|
|
|
|
Dir |= REDSTONE_X_NEG;
|
|
|
|
}
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Dir ^= REDSTONE_X_NEG;
|
|
|
|
Dir |= REDSTONE_X_POS;
|
|
|
|
}
|
|
|
|
Dir |= REDSTONE_Z_NEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (eRedstoneDirection)Dir;
|
2012-10-06 16:04:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cRedstoneSimulator::IsRepeaterPointingTo(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos)
|
|
|
|
{
|
|
|
|
switch (a_MetaData & 0x3)
|
|
|
|
{
|
|
|
|
case 0x0:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(0, 0, 1)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x1:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(-1, 0, 0)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x2:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(0, 0,-1)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x3:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(1, 0, 0)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
bool cRedstoneSimulator::IsRepeaterPointingAway(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
switch (a_MetaData & 0x3)
|
|
|
|
{
|
|
|
|
case 0x0:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(0, 0,-1)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x1:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(1, 0, 0)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x2:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(0, 0, 1)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x3:
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
if ((a_RepeaterPos - a_BlockPos).Equals(Vector3i(-1, 0, 0)))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-09 09:35:43 -05:00
|
|
|
NIBBLETYPE cRedstoneSimulator::RepeaterRotationToMetaData(double a_Rotation)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
a_Rotation += 90 + 45; // So its not aligned with axis
|
2013-03-09 09:35:43 -05:00
|
|
|
if (a_Rotation > 360)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
2013-03-09 09:35:43 -05:00
|
|
|
a_Rotation -= 360;
|
2012-10-06 16:04:58 -04:00
|
|
|
}
|
|
|
|
|
2013-03-09 09:35:43 -05:00
|
|
|
if ((a_Rotation >= 0) && (a_Rotation < 90))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
return 0x1;
|
|
|
|
}
|
|
|
|
else if ((a_Rotation >= 180) && (a_Rotation < 270))
|
|
|
|
{
|
|
|
|
return 0x3;
|
|
|
|
}
|
|
|
|
else if ((a_Rotation >= 90) && (a_Rotation < 180))
|
|
|
|
{
|
|
|
|
return 0x2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3i cRedstoneSimulator::GetRepeaterDirection(NIBBLETYPE a_MetaData)
|
|
|
|
{
|
|
|
|
switch (a_MetaData & 0x3)
|
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
case 0x0: return Vector3i(0, 0,-1);
|
|
|
|
case 0x1: return Vector3i(1, 0, 0);
|
|
|
|
case 0x2: return Vector3i(0, 0, 1);
|
2012-10-06 16:04:58 -04:00
|
|
|
case 0x3: return Vector3i(-1, 0, 0);
|
|
|
|
}
|
|
|
|
return Vector3i();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
NIBBLETYPE cRedstoneSimulator::LeverDirectionToMetaData(char a_Dir)
|
2012-12-16 00:52:45 -05:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Determine lever direction:
|
2012-12-16 00:52:45 -05:00
|
|
|
switch (a_Dir)
|
|
|
|
{
|
|
|
|
case BLOCK_FACE_TOP: return 0x6;
|
|
|
|
case BLOCK_FACE_EAST: return 0x1;
|
|
|
|
case BLOCK_FACE_WEST: return 0x2;
|
|
|
|
case BLOCK_FACE_SOUTH: return 0x3;
|
|
|
|
case BLOCK_FACE_NORTH: return 0x4;
|
|
|
|
case BLOCK_FACE_BOTTOM: return 0x0;
|
|
|
|
default: return 0x6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-16 02:07:30 -05:00
|
|
|
bool cRedstoneSimulator::IsLeverOn(cWorld * a_World, const Vector3i & a_BlockPos)
|
|
|
|
{
|
|
|
|
// Extract the metadata and ask the lower level:
|
|
|
|
return IsLeverOn(a_World->GetBlockMeta(a_BlockPos));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cRedstoneSimulator::IsLeverOn(NIBBLETYPE a_BlockMeta)
|
2012-12-16 00:52:45 -05:00
|
|
|
{
|
2012-12-16 02:07:30 -05:00
|
|
|
// Extract the ON bit from metadata and return if true if it is set:
|
|
|
|
return ((a_BlockMeta & 0x8) == 0x8);
|
2012-12-16 00:52:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-03 10:06:01 -05:00
|
|
|
void cRedstoneSimulator::SetRepeater(const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
2013-03-03 10:06:01 -05:00
|
|
|
for (RepeaterList::iterator itr = m_SetRepeaters.begin(); itr != m_SetRepeaters.end(); ++itr)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
sRepeaterChange & Change = *itr;
|
2013-03-03 10:06:01 -05:00
|
|
|
if (Change.Position.Equals(a_Position))
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
2012-11-16 11:03:56 -05:00
|
|
|
if (Change.bPowerOn && !a_bPowerOn)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
Change.bPowerOffNextTime = true;
|
|
|
|
}
|
2012-11-16 11:03:56 -05:00
|
|
|
if (a_bPowerOn)
|
2012-10-06 16:04:58 -04:00
|
|
|
{
|
|
|
|
Change.bPowerOffNextTime = false;
|
|
|
|
}
|
|
|
|
Change.bPowerOn |= a_bPowerOn;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sRepeaterChange RC;
|
|
|
|
RC.Position = a_Position;
|
|
|
|
RC.Ticks = a_Ticks;
|
|
|
|
RC.bPowerOn = a_bPowerOn;
|
|
|
|
RC.bPowerOffNextTime = false;
|
2013-03-03 10:06:01 -05:00
|
|
|
m_SetRepeaters.push_back(RC);
|
2012-10-06 16:04:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|