summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Blocks/BlockPiston.cpp20
-rw-r--r--source/Blocks/BlockRedstone.cpp45
-rw-r--r--source/Blocks/BlockRedstoneRepeater.cpp41
-rw-r--r--source/Chunk.cpp1
-rw-r--r--source/ClientHandle.cpp1
-rw-r--r--source/Piston.cpp14
-rw-r--r--source/Redstone.cpp374
-rw-r--r--source/Redstone.h122
-rw-r--r--source/RedstoneSimulator.cpp287
-rw-r--r--source/RedstoneSimulator.h50
-rw-r--r--source/Root.cpp7
-rw-r--r--source/World.cpp15
12 files changed, 342 insertions, 635 deletions
diff --git a/source/Blocks/BlockPiston.cpp b/source/Blocks/BlockPiston.cpp
index e20f5c600..2e532b649 100644
--- a/source/Blocks/BlockPiston.cpp
+++ b/source/Blocks/BlockPiston.cpp
@@ -1,16 +1,25 @@
+
#include "Globals.h"
#include "BlockPiston.h"
#include "../Item.h"
#include "../World.h"
-#include "../Redstone.h"
#include "../Player.h"
#include "../Piston.h"
-#define AddPistonDir(x, y, z, dir, amount) switch (dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\
- case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\
- case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; }
+
+
+#define AddPistonDir(x, y, z, dir, amount) \
+ switch (dir) \
+ { \
+ case 0: (y) -= (amount); break; \
+ case 1: (y) += (amount); break; \
+ case 2: (z) -= (amount); break; \
+ case 3: (z) += (amount); break; \
+ case 4: (x) -= (amount); break; \
+ case 5: (x) += (amount); break; \
+ }
@@ -56,9 +65,6 @@ void cBlockPistonHandler::PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBL
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), a_Player->GetPitch()));
OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
-
- cRedstone Redstone(a_World);
- Redstone.ChangeRedstone(a_BlockX, a_BlockY, a_BlockZ, false);
}
diff --git a/source/Blocks/BlockRedstone.cpp b/source/Blocks/BlockRedstone.cpp
index dac4aecb7..21a5e1c61 100644
--- a/source/Blocks/BlockRedstone.cpp
+++ b/source/Blocks/BlockRedstone.cpp
@@ -1,41 +1,56 @@
+
#include "Globals.h"
#include "BlockRedstone.h"
#include "../Item.h"
#include "../World.h"
-#include "../Redstone.h"
#include "../Torch.h"
+
+
+
+
cBlockRedstoneHandler::cBlockRedstoneHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
+
+
+
+
void cBlockRedstoneHandler::OnPlaced(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, int a_Dir)
{
- cRedstone Redstone(a_World);
- bool Added = false;
- if(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_REDSTONE_TORCH_ON)
- Added = true;
-
- Redstone.ChangeRedstone(a_BlockX, a_BlockY, a_BlockZ, Added);
+ // Nothing needed yet
}
+
+
+
+
void cBlockRedstoneHandler::OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- cRedstone Redstone(a_World);
- Redstone.ChangeRedstone(a_BlockX, a_BlockY, a_BlockZ, false);
+ // Nothing needed yet
}
+
+
+
+
void cBlockRedstoneHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
{
switch(m_BlockType)
{
- case E_BLOCK_REDSTONE_TORCH_ON:
- case E_BLOCK_REDSTONE_TORCH_OFF:
- a_BlockMeta = cTorch::DirectionToMetaData(a_Dir);
- break;
-
+ case E_BLOCK_REDSTONE_TORCH_ON:
+ case E_BLOCK_REDSTONE_TORCH_OFF:
+ {
+ a_BlockMeta = cTorch::DirectionToMetaData(a_Dir);
+ break;
+ }
}
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, a_BlockMeta);
OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
-} \ No newline at end of file
+}
+
+
+
+
diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp
index 797c8c4d2..5af5edb1e 100644
--- a/source/Blocks/BlockRedstoneRepeater.cpp
+++ b/source/Blocks/BlockRedstoneRepeater.cpp
@@ -1,39 +1,66 @@
+
#include "Globals.h"
#include "BlockRedstoneRepeater.h"
#include "../Item.h"
#include "../World.h"
-#include "../Redstone.h"
#include "../Player.h"
+#include "../RedstoneSimulator.h"
+
+
+
+
cBlockRedstoneRepeaterHandler::cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
+
+
+
+
void cBlockRedstoneRepeaterHandler::OnPlaced(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ, int a_Dir)
{
- cRedstone Redstone(a_World);
- Redstone.ChangeRedstone(a_BlockX, a_BlockY, a_BlockZ, false);
+ // Noting needed yet
}
+
+
+
+
void cBlockRedstoneRepeaterHandler::OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
{
- cRedstone Redstone(a_World);
- Redstone.ChangeRedstone(a_BlockX, a_BlockY, a_BlockZ, false);
+ // Nothing needed yet
}
+
+
+
+
void cBlockRedstoneRepeaterHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f));
}
+
+
+
+
void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ);
}
+
+
+
+
void cBlockRedstoneRepeaterHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
{
- a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, cRedstone::RepeaterRotationToMetaData(a_Player->GetRotation()));
+ a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation()));
OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
-} \ No newline at end of file
+}
+
+
+
+
diff --git a/source/Chunk.cpp b/source/Chunk.cpp
index 72b065bdd..50bba66cf 100644
--- a/source/Chunk.cpp
+++ b/source/Chunk.cpp
@@ -21,7 +21,6 @@
#include "Torch.h"
#include "Ladder.h"
#include "Pickup.h"
-#include "Redstone.h"
#include "Item.h"
#include "Noise.h"
#include "Root.h"
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 6292df107..ad9401e79 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -17,7 +17,6 @@
#include "Ladder.h"
#include "Vine.h"
#include "Sign.h"
-#include "Redstone.h"
#include "Piston.h"
#include "Mobs/Monster.h"
#include "ChatColor.h"
diff --git a/source/Piston.cpp b/source/Piston.cpp
index a235da879..9aa09a56e 100644
--- a/source/Piston.cpp
+++ b/source/Piston.cpp
@@ -2,7 +2,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Piston.h"
-#include "Redstone.h"
#include "ChunkDef.h"
#include "Pickup.h"
#include "Item.h"
@@ -52,10 +51,9 @@ unsigned short cPiston::FirstPassthroughBlock( int pistonX, int pistonY, int pis
void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
{
- char pistonBlock = m_World->GetBlock( pistx, pisty, pistz );
- char pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
+ BLOCKTYPE pistonBlock = m_World->GetBlock( pistx, pisty, pistz );
+ NIBBLETYPE pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
char isSticky = (char)(pistonBlock == E_BLOCK_STICKY_PISTON) * 8;
- bool recalc = false;
if ( (pistonMeta & 0x8) == 0x0 ) // only extend if piston is not already extended
{
unsigned short dist = FirstPassthroughBlock(pistx, pisty, pistz, pistonMeta);
@@ -71,7 +69,6 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
{
Handler->DropBlock(m_World, pistx, pisty, pistz);
}
- recalc = true;
}
int oldx = pistx, oldy = pisty, oldz = pistz;
char currBlockMeta;
@@ -95,13 +92,6 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
AddDir(extx, exty, extz, pistonMeta & 7, 1)
m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta & 7);
-
- if (recalc)
- {
- cRedstone Redstone(m_World);
- Redstone.ChangeRedstone(extx, exty, extz, false); // recalculate redstone around current device
- Redstone.ChangeRedstone(pistx, pisty, pistz, false); // recalculate redstone around current device
- }
}
}
diff --git a/source/Redstone.cpp b/source/Redstone.cpp
deleted file mode 100644
index 01a343223..000000000
--- a/source/Redstone.cpp
+++ /dev/null
@@ -1,374 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Redstone.h"
-#include "Piston.h"
-#include "Root.h"
-#include "World.h"
-#include "BlockID.h"
-#include <iostream>
-
-
-
-
-
-bool cRedstone::s_UseRedstone = false;
-
-
-
-
-
-cRedstone::cRedstone( cWorld* a_World )
- :m_World ( a_World )
- ,m_Metadata ( 0 )
- ,m_Direction ( 0 )
-{
-
-}
-
-
-
-
-
-void cRedstone::ChangeRedstone( int fillx, int filly, int fillz, bool added )
-{
- s_UseRedstone = false;
- if( !s_UseRedstone ) return;
-
- char before;
- //int tempX;
- //int tempY;
- //int tempZ;
- //int state;
- //m_Direction
- // 0 = x+
- // 1 = x-
- // 2 = z+
- // 3 = z-
- // 4 = y+
- // 5 = v-
-
-
- if (added) {
- m_Metadata = 15;
- } else {
- m_Metadata = 0;
- }
- before = m_Metadata;
-
- //printf("etb1\n");
- CalculateRedstone( fillx, filly, fillz ); //calculate all item centers.
- //printf("etb2\n");
-
- int Block = (int)m_World->GetBlock( fillx, filly, fillz );
-
- switch (Block)//these blocks won't trigger the normal calculaton because they are affected by the redstone around them. So we check each possible channel around them instead.
- {
- case E_BLOCK_REDSTONE_TORCH_ON:
- case E_BLOCK_REDSTONE_TORCH_OFF:
- case E_BLOCK_AIR:
- case E_BLOCK_PISTON_EXTENSION:
- case E_BLOCK_PISTON:
- case E_BLOCK_STICKY_PISTON:
- {
- m_Metadata = 0;
- m_Direction = 0;
- CalculateRedstone( fillx+1, filly, fillz );
- m_Metadata = 0;
- m_Direction = 1;
- CalculateRedstone( fillx-1, filly, fillz );
- m_Metadata = 0;
- m_Direction = 2;
- CalculateRedstone( fillx, filly, fillz+1 );
- m_Metadata = 0;
- m_Direction = 3;
- CalculateRedstone( fillx, filly, fillz-1 );
- m_Metadata = 0;
- CalculateRedstone( fillx, filly-1, fillz );
- break;
- }
- case E_BLOCK_REDSTONE_WIRE: //special case for redstone wire.
- {
- m_Direction = 0;
- CalculateRedstone( fillx+1, filly, fillz );
- m_Direction = 1;
- CalculateRedstone( fillx-1, filly, fillz );
- m_Direction = 2;
- CalculateRedstone( fillx, filly, fillz+1 );
- m_Direction = 3;
- CalculateRedstone( fillx, filly, fillz-1 );
- m_Metadata = 0;
- CalculateRedstone( fillx, filly-1, fillz );
-
- m_Direction = 4;
- CalculateRedstone( fillx+1, filly+1, fillz );
- CalculateRedstone( fillx-1, filly+1, fillz );
- CalculateRedstone( fillx, filly+1, fillz+1 );
- CalculateRedstone( fillx, filly+1, fillz-1 );
-
- m_Direction = 5;
- CalculateRedstone( fillx+1, filly-1, fillz );
- CalculateRedstone( fillx-1, filly-1, fillz );
- CalculateRedstone( fillx, filly-1, fillz+1 );
- CalculateRedstone( fillx, filly-1, fillz-1 );
- break;
- }
- }
-
- //printf("done here\n");
-}
-
-
-
-
-
-void cRedstone::CalculateRedstone( int fillx, int filly, int fillz)
-{
-
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) {
- char pistonMeta = m_World->GetBlockMeta( fillx, filly, fillz );
- if (m_Metadata > 0) {
- if (pistonMeta < 6) { // only extend if piston is not already extended
- cPiston Piston(m_World);
- Piston.ExtendPiston(fillx, filly, fillz);
- }
- } else {
- if (pistonMeta > 6) { // only retract if piston is not already retracted
- cPiston Piston(m_World);
- Piston.RetractPiston(fillx, filly, fillz);
- }
- }
-
- } else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_ITEM_LEVER ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_ITEM_STONE_BUTTON ) ) {
-
- if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) > 6 ) { //button powered
- m_Metadata = 15; //change meta to 15 only if redstone power device in on possition is found.
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
- } else {
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
- }
-
- } else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STONE_PRESSURE_PLATE ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STONE_BUTTON ) ) {
-
- if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) == 1 ) { //plate powered
- m_Metadata = 15; //change meta to 15 only if redstone power device in on possition is found.
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
-
- } else {
-
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
- }
-
- } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //If torch is on
- //printf("found torch on\n");
- m_Metadata = 15; //change meta to 15 only if redstone torch in on possition is found.
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
-
- } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //if the torch is off
- //printf("found torch off\n");
- // no need to change meta here.
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx-1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- CalculateRedstone(fillx+1,filly,fillz);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz-1);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- CalculateRedstone(fillx,filly,fillz+1);
- }
-
- } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //simple fill algorithm for redstone wire.
-
- if ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != m_Metadata ) {
- m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata );
- m_Direction = 0;
- CalculateRedstone( fillx+1, filly, fillz );
- m_Direction = 1;
- CalculateRedstone( fillx-1, filly, fillz );
- m_Direction = 2;
- CalculateRedstone( fillx, filly, fillz+1 );
- m_Direction = 3;
- CalculateRedstone( fillx, filly, fillz-1 );
- CalculateRedstone( fillx, filly-1, fillz ); //check one block below //similar to same plane
-
- m_Direction = 4;
- CalculateRedstone( fillx+1, filly+1, fillz );
- CalculateRedstone( fillx-1, filly+1, fillz );
- CalculateRedstone( fillx, filly+1, fillz+1 );
- CalculateRedstone( fillx, filly+1, fillz-1 );
-
- m_Direction = 5;
- CalculateRedstone( fillx+1, filly-1, fillz );
- CalculateRedstone( fillx-1, filly-1, fillz );
- CalculateRedstone( fillx, filly-1, fillz+1 );
- CalculateRedstone( fillx, filly-1, fillz-1 );
- }
-
- } else { //default, check item for torch attached to it. If meta > 0 then turn that torch off, otherwise turn it on. This change needs to be passed to the next world tick.
- //check for torch to east with meta 1 //turn off
- //check for torch to west with meta 2 //turn off
- //check for torch to south with meta 3 //turn off
- //check for torch to north with meta 4 //turn off
- //check for torch above with meta 5 //turn off
- if ( (int)m_World->GetBlock( fillx, filly, fillz ) != E_BLOCK_AIR ) {
- if (m_Direction < 4) { //redstone wire can only power blocks on the same plane or directly below
- if ( (int)m_Metadata > 0 ) { //wire powered
-
- //printf("bird: %i dog: %i \n",(int)m_World->GetBlock( fillx, filly+1, fillz ),(int)m_World->GetBlockMeta( fillx, filly+1, fillz));
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) == 1 ) ) { //east
- m_World->m_RSList.push_back(fillx+1);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(00000);
- }
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) == 2 ) ) { //west
- m_World->m_RSList.push_back(fillx-1);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(00000);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) == 3 ) ) { //south
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz+1);
- m_World->m_RSList.push_back(00000);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) == 4 ) ) { //north
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz-1);
- m_World->m_RSList.push_back(00000);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly+1, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) && ( (int)m_World->GetBlockMeta( fillx, filly+1, fillz) == 5 ) ) { //top
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly+1);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(00000);
- }
-
- } else { //wire not powered
-
- bool BlockPowered = IsBlockPowered( fillx, filly, fillz ); //chck this block for other wire turned on or torch turned on below:
- if (BlockPowered == false) { //if block is not bowered by something else then I need to check for off torches and turn them on.
-
- //printf("echo: %i cruiser: %i \n",(int)m_World->GetBlock( fillx, filly+1, fillz ),(int)m_World->GetBlockMeta( fillx, filly+1, fillz));
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) == 1 ) ) { //east
- m_World->m_RSList.push_back(fillx+1);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(11111);
- }
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) == 2 ) ) { //west
- m_World->m_RSList.push_back(fillx-1);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(11111);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) == 3 ) ) { //south
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz+1);
- m_World->m_RSList.push_back(11111);;
- }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) == 4 ) ) { //north
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly);
- m_World->m_RSList.push_back(fillz-1);
- m_World->m_RSList.push_back(11111);
- }
- if ( ( (int)m_World->GetBlock( fillx, filly+1, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF) && ( (int)m_World->GetBlockMeta( fillx, filly+1, fillz) == 5 ) ) { //top
- m_World->m_RSList.push_back(fillx);
- m_World->m_RSList.push_back(filly+1);
- m_World->m_RSList.push_back(fillz);
- m_World->m_RSList.push_back(11111);
- }
-
- }
-
- }
-
- }
-
- }
-
- }
-
-}
-
-
-
-
-
-bool cRedstone::IsBlockPowered( int fillx, int filly, int fillz )
-{
-
- if ( (int)m_World->GetBlock( fillx, filly-1, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; }
- if ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; }
- if ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; }
- if ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; }
- if ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_TORCH_ON) { return true; }
- if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) > 0 ) ) { return true; }
- if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) > 0 ) ) { return true; }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) > 0 ) ) { return true; }
- if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) > 0 ) ) { return true; }
- if ( ( (int)m_World->GetBlock( fillx, filly+1, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly+1, fillz) > 0 ) ) { return true; }
- return false;
-} \ No newline at end of file
diff --git a/source/Redstone.h b/source/Redstone.h
deleted file mode 100644
index a5377e8a7..000000000
--- a/source/Redstone.h
+++ /dev/null
@@ -1,122 +0,0 @@
-#pragma once
-
-#include "Vector3i.h"
-
-class cWorld;
-class cRedstone
-{
-public:
-
- cRedstone( cWorld* a_World );
-
- static char RepeaterRotationToMetaData( float a_Rotation )
- {
- a_Rotation += 90 + 45; // So its not aligned with axis
- if( a_Rotation > 360.f ) a_Rotation -= 360.f;
- if( a_Rotation >= 0.f && a_Rotation < 90.f )
- 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;
- }
-
- static bool IsRepeaterPointingTo( const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos )
- {
- switch( a_MetaData & 0x3 )
- {
- case 0x0:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0, 1 ) ) )
- {
- return true;
- }
- break;
- case 0x1:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i(-1, 0, 0 ) ) )
- {
- return true;
- }
- break;
- case 0x2:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0,-1 ) ) )
- {
- return true;
- }
- break;
- case 0x3:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 1, 0, 0 ) ) )
- {
- return true;
- }
- break;
- default:
- break;
- }
- return false;
- }
-
- static bool IsRepeaterPointingAway( const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos )
- {
- switch( a_MetaData & 0x3 )
- {
- case 0x0:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0,-1 ) ) )
- {
- return true;
- }
- break;
- case 0x1:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 1, 0, 0 ) ) )
- {
- return true;
- }
- break;
- case 0x2:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0, 1 ) ) )
- {
- return true;
- }
- break;
- case 0x3:
- if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i(-1, 0, 0 ) ) )
- {
- return true;
- }
- break;
- default:
- break;
- }
- return false;
- }
-
- static Vector3i GetRepeaterDirection( char a_MetaData )
- {
- switch( a_MetaData & 0x3 )
- {
- case 0x0:
- return Vector3i( 0, 0,-1 );
- case 0x1:
- return Vector3i( 1, 0, 0 );
- case 0x2:
- return Vector3i( 0, 0, 1 );
- case 0x3:
- return Vector3i(-1, 0, 0 );
- default:
- break;
- }
- return Vector3i();
- }
-
- void CalculateRedstone( int, int, int );
- void ChangeRedstone( int, int, int, bool );
- bool IsBlockPowered( int, int, int );
-
- cWorld* m_World;
-
- char m_Metadata;
- char m_Direction;
-
- static bool s_UseRedstone;
-};
diff --git a/source/RedstoneSimulator.cpp b/source/RedstoneSimulator.cpp
index 3d5fd51f0..6c3e27228 100644
--- a/source/RedstoneSimulator.cpp
+++ b/source/RedstoneSimulator.cpp
@@ -1,3 +1,4 @@
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "RedstoneSimulator.h"
@@ -6,7 +7,7 @@
#include "BlockID.h"
#include "Torch.h"
-#include "Redstone.h"
+
@@ -29,8 +30,6 @@ cRedstoneSimulator::~cRedstoneSimulator()
void cRedstoneSimulator::WakeUp( int a_X, int a_Y, int a_Z )
{
- if( cRedstone::s_UseRedstone ) return; // Using the other/broken simulator
-
cCSLock Lock( m_CS );
m_Blocks.push_back( Vector3i( a_X, a_Y, a_Z ) );
}
@@ -41,8 +40,6 @@ void cRedstoneSimulator::WakeUp( int a_X, int a_Y, int a_Z )
void cRedstoneSimulator::Simulate( float a_Dt )
{
- if( cRedstone::s_UseRedstone ) return; // Using the other/broken simulator
-
// Toggle torches on/off
while( !m_RefreshTorchesAround.empty() )
{
@@ -152,7 +149,7 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos )
break;
case E_BLOCK_REDSTONE_REPEATER_ON:
case E_BLOCK_REDSTONE_REPEATER_OFF:
- if( Block != TargetRepeaterID && cRedstone::IsRepeaterPointingAway( TorchPos, m_World->GetBlockMeta( TorchPos ), a_BlockPos ) )
+ if ((Block != TargetRepeaterID) && IsRepeaterPointingAway( TorchPos, m_World->GetBlockMeta( TorchPos ), a_BlockPos ) )
{
SetRepeater( TorchPos, 10, TargetRepeaterID == E_BLOCK_REDSTONE_REPEATER_ON );
}
@@ -212,7 +209,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
}
else if( Block == E_BLOCK_REDSTONE_REPEATER_ON || Block == E_BLOCK_REDSTONE_REPEATER_OFF ) // Check if repeater is powered by a 'powered block' (not wires/torch)
{
- Vector3i Direction = cRedstone::GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
+ Vector3i Direction = GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
Vector3i pos = a_BlockPos - Direction; // NOTE: It's minus Direction
char OtherBlock = m_World->GetBlock( pos );
if( (OtherBlock != E_BLOCK_AIR) && (OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) && (OtherBlock != E_BLOCK_REDSTONE_TORCH_OFF) && (OtherBlock != E_BLOCK_REDSTONE_WIRE) )
@@ -238,7 +235,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
Vector3i( 0, 0, 0),
Vector3i( 0, 1, 0),
};
- Vector3i Direction = cRedstone::GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
+ Vector3i Direction = GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i )
{
Vector3i pos = a_BlockPos + Direction + Surroundings[i];
@@ -288,7 +285,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos )
Vector3i( 0, 0, 0),
Vector3i( 0, 1, 0),
};
- Vector3i Direction = cRedstone::GetRepeaterDirection( m_World->GetBlockMeta( SourcePos ) );
+ Vector3i Direction = GetRepeaterDirection( m_World->GetBlockMeta( SourcePos ) );
for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i )
{
Vector3i pos = SourcePos + Direction + Surroundings[i];
@@ -379,7 +376,7 @@ bool cRedstoneSimulator::PowerBlock( const Vector3i & a_BlockPos, const Vector3i
case E_BLOCK_REDSTONE_REPEATER_OFF:
case E_BLOCK_REDSTONE_REPEATER_ON:
{
- if( cRedstone::IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ) )
+ if (IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ))
{
SetRepeater( a_BlockPos, 10, true );
}
@@ -405,59 +402,71 @@ bool cRedstoneSimulator::PowerBlock( const Vector3i & a_BlockPos, const Vector3i
-int cRedstoneSimulator::UnPowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock )
+int cRedstoneSimulator::UnPowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock)
{
- char Block = m_World->GetBlock( a_BlockPos );
- switch( Block )
+ BLOCKTYPE BlockType = m_World->GetBlock(a_BlockPos);
+ switch (BlockType)
{
- case E_BLOCK_REDSTONE_WIRE:
+ case E_BLOCK_REDSTONE_WIRE:
{
if( m_World->GetBlockMeta( a_BlockPos ) > 0 )
{
m_World->SetBlockMeta( a_BlockPos, 0 );
return 1;
}
+ break;
}
- break;
- case E_BLOCK_PISTON:
- case E_BLOCK_STICKY_PISTON:
+
+ case E_BLOCK_PISTON:
+ case E_BLOCK_STICKY_PISTON:
{
m_RefreshPistons.push_back( a_BlockPos );
+ break;
}
- break;
- case E_BLOCK_REDSTONE_TORCH_ON:
+
+ case E_BLOCK_REDSTONE_TORCH_ON:
{
return 2;
+ break;
}
- break;
- case E_BLOCK_REDSTONE_REPEATER_ON:
+
+ case E_BLOCK_REDSTONE_REPEATER_ON:
{
- if( cRedstone::IsRepeaterPointingTo( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock )
- || cRedstone::IsRepeaterPointingTo( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock - Vector3i(0, 1, 0) ) ) // Check if repeater is next/below wire
+ if (
+ IsRepeaterPointingTo(a_BlockPos, m_World->GetBlockMeta(a_BlockPos), a_FromBlock ) || // Repeater is next to wire
+ IsRepeaterPointingTo(a_BlockPos, m_World->GetBlockMeta(a_BlockPos), a_FromBlock - Vector3i(0, 1, 0)) // Repeater is below wire
+ )
{
return 2;
}
- else if( cRedstone::IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ) )
+ else if (IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ) )
{
SetRepeater( a_BlockPos, 10, false );
}
+ // fall-through:
}
- case E_BLOCK_REDSTONE_REPEATER_OFF:
- if( cRedstone::IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ) )
+
+ case E_BLOCK_REDSTONE_REPEATER_OFF:
{
- SetRepeater( a_BlockPos, 10, false );
+ if (IsRepeaterPointingAway( a_BlockPos, m_World->GetBlockMeta( a_BlockPos ), a_FromBlock ))
+ {
+ SetRepeater( a_BlockPos, 10, false );
+ }
+ break;
}
- break;
- default:
- if( Block != E_BLOCK_AIR && Block != E_BLOCK_REDSTONE_TORCH_ON && Block != E_BLOCK_REDSTONE_TORCH_OFF )
+
+ default:
{
- if( !IsPowered( a_BlockPos, true ) )
+ if ((BlockType != E_BLOCK_AIR) && (BlockType != E_BLOCK_REDSTONE_TORCH_ON) && (BlockType != E_BLOCK_REDSTONE_TORCH_OFF))
{
- m_RefreshTorchesAround.push_back( a_BlockPos );
+ if (!IsPowered(a_BlockPos, true))
+ {
+ m_RefreshTorchesAround.push_back( a_BlockPos );
+ }
}
+ break;
}
- break;
- };
+ } // switch (BlockType)
return 0;
}
@@ -498,7 +507,7 @@ cRedstoneSimulator::BlockList cRedstoneSimulator::RemoveCurrent( const Vector3i
Vector3i( 0, 0, 0),
Vector3i( 0, 1, 0),
};
- Vector3i Direction = cRedstone::GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
+ Vector3i Direction = GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i )
{
Vector3i pos = a_BlockPos + Direction + Surroundings[i];
@@ -571,20 +580,20 @@ cRedstoneSimulator::BlockList cRedstoneSimulator::RemoveCurrent( const Vector3i
bool cRedstoneSimulator::IsPowering( const Vector3i & a_PowerPos, const Vector3i & a_BlockPos, eRedstoneDirection a_WireDirection, bool a_bOnlyByWire )
{
- char PowerBlock = m_World->GetBlock( a_PowerPos );
- if( !a_bOnlyByWire && PowerBlock == E_BLOCK_REDSTONE_TORCH_ON ) return true;
- if( PowerBlock == E_BLOCK_REDSTONE_REPEATER_ON ) // A repeater pointing towards block is regarded as wire
+ BLOCKTYPE PowerBlock = m_World->GetBlock( a_PowerPos );
+ if (!a_bOnlyByWire && (PowerBlock == E_BLOCK_REDSTONE_TORCH_ON)) return true;
+ if (PowerBlock == E_BLOCK_REDSTONE_REPEATER_ON ) // A repeater pointing towards block is regarded as wire
{
- if( cRedstone::IsRepeaterPointingTo( a_PowerPos, m_World->GetBlockMeta( a_PowerPos ), a_BlockPos ) )
+ if (IsRepeaterPointingTo( a_PowerPos, m_World->GetBlockMeta( a_PowerPos ), a_BlockPos ) )
{
return true;
}
}
- if( PowerBlock == E_BLOCK_REDSTONE_WIRE )
+ if (PowerBlock == E_BLOCK_REDSTONE_WIRE)
{
- if( m_World->GetBlockMeta( a_PowerPos ) > 0 )
+ if (m_World->GetBlockMeta(a_PowerPos) > 0)
{
- if( GetDirection( a_PowerPos ) == a_WireDirection )
+ if (GetDirection(a_PowerPos) == a_WireDirection)
{
return true;
}
@@ -600,25 +609,25 @@ bool cRedstoneSimulator::IsPowering( const Vector3i & a_PowerPos, const Vector3i
bool cRedstoneSimulator::IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByWire /* = false */ )
{
- char Block = m_World->GetBlock( a_BlockPos );
- if( Block == E_BLOCK_REDSTONE_REPEATER_OFF || Block == E_BLOCK_REDSTONE_REPEATER_ON )
+ BLOCKTYPE Block = m_World->GetBlock( a_BlockPos );
+ if ((Block == E_BLOCK_REDSTONE_REPEATER_OFF) || (Block == E_BLOCK_REDSTONE_REPEATER_ON))
{
- Vector3i Behind = a_BlockPos - cRedstone::GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
- char BehindBlock = m_World->GetBlock( Behind );
- if( BehindBlock == E_BLOCK_REDSTONE_TORCH_ON )
+ Vector3i Behind = a_BlockPos - GetRepeaterDirection( m_World->GetBlockMeta( a_BlockPos ) );
+ BLOCKTYPE BehindBlock = m_World->GetBlock( Behind );
+ if (BehindBlock == E_BLOCK_REDSTONE_TORCH_ON)
{
return true;
}
- if( BehindBlock == E_BLOCK_REDSTONE_WIRE )
+ if (BehindBlock == E_BLOCK_REDSTONE_WIRE)
{
if( m_World->GetBlockMeta( Behind ) > 0 )
{
return true;
}
}
- if( BehindBlock == E_BLOCK_REDSTONE_REPEATER_ON )
+ if (BehindBlock == E_BLOCK_REDSTONE_REPEATER_ON)
{
- if( cRedstone::IsRepeaterPointingTo( Behind, m_World->GetBlockMeta( Behind ), a_BlockPos ) )
+ if (IsRepeaterPointingTo( Behind, m_World->GetBlockMeta( Behind ), a_BlockPos))
{
return true;
}
@@ -698,4 +707,180 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetDirection( int a_X
}
return (eRedstoneDirection)Dir;
-} \ No newline at end of file
+}
+
+
+
+
+
+bool cRedstoneSimulator::IsRepeaterPointingTo(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos)
+{
+ switch (a_MetaData & 0x3)
+ {
+ case 0x0:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0, 1 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x1:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i(-1, 0, 0 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x2:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0,-1 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x3:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 1, 0, 0 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cRedstoneSimulator::IsRepeaterPointingAway( const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos )
+{
+ switch (a_MetaData & 0x3)
+ {
+ case 0x0:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0,-1 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x1:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 1, 0, 0 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x2:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i( 0, 0, 1 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+
+ case 0x3:
+ {
+ if( (a_RepeaterPos - a_BlockPos).Equals( Vector3i(-1, 0, 0 ) ) )
+ {
+ return true;
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+NIBBLETYPE cRedstoneSimulator::RepeaterRotationToMetaData(float a_Rotation)
+{
+ a_Rotation += 90 + 45; // So its not aligned with axis
+ if (a_Rotation > 360.f)
+ {
+ a_Rotation -= 360.f;
+ }
+
+ if ((a_Rotation >= 0.f) && (a_Rotation < 90.f))
+ {
+ 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)
+ {
+ case 0x0: return Vector3i( 0, 0,-1);
+ case 0x1: return Vector3i( 1, 0, 0);
+ case 0x2: return Vector3i( 0, 0, 1);
+ case 0x3: return Vector3i(-1, 0, 0);
+ }
+ return Vector3i();
+}
+
+
+
+
+
+void cRedstoneSimulator::SetRepeater( const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn )
+{
+ for( RepeaterList::iterator itr = m_SetRepeaters.begin(); itr != m_SetRepeaters.end(); ++itr )
+ {
+ sRepeaterChange & Change = *itr;
+ if( Change.Position.Equals( a_Position ) )
+ {
+ if( Change.bPowerOn && a_bPowerOn == false )
+ {
+ Change.bPowerOffNextTime = true;
+ }
+ if( a_bPowerOn == true )
+ {
+ 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;
+ m_SetRepeaters.push_back( RC );
+}
+
+
+
+
diff --git a/source/RedstoneSimulator.h b/source/RedstoneSimulator.h
index 2235e200b..c1996bb4e 100644
--- a/source/RedstoneSimulator.h
+++ b/source/RedstoneSimulator.h
@@ -1,9 +1,15 @@
+
#pragma once
#include "Simulator.h"
#include "Vector3i.h"
-class cRedstoneSimulator : public cSimulator
+
+
+
+
+class cRedstoneSimulator :
+ public cSimulator
{
typedef cSimulator super;
public:
@@ -25,6 +31,13 @@ public:
};
eRedstoneDirection GetDirection( int a_X, int a_Y, int a_Z );
eRedstoneDirection GetDirection( const Vector3i & a_Pos ) { return GetDirection( a_Pos.x, a_Pos.y, a_Pos.z ); }
+
+ static bool IsRepeaterPointingTo (const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
+ static bool IsRepeaterPointingAway(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
+ static NIBBLETYPE RepeaterRotationToMetaData(float a_Rotation);
+ static Vector3i GetRepeaterDirection(NIBBLETYPE a_MetaData);
+
+
private:
struct sRepeaterChange
{
@@ -38,33 +51,8 @@ private:
typedef std::deque< sRepeaterChange > RepeaterList;
RepeaterList m_SetRepeaters;
- void SetRepeater( const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn )
- {
- for( RepeaterList::iterator itr = m_SetRepeaters.begin(); itr != m_SetRepeaters.end(); ++itr )
- {
- sRepeaterChange & Change = *itr;
- if( Change.Position.Equals( a_Position ) )
- {
- if( Change.bPowerOn && a_bPowerOn == false )
- {
- Change.bPowerOffNextTime = true;
- }
- if( a_bPowerOn == true )
- {
- 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;
- m_SetRepeaters.push_back( RC );
- }
+
+ void SetRepeater(const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn);
virtual void AddBlock(int a_X, int a_Y, int a_Z) {}
@@ -87,4 +75,8 @@ private:
void RefreshTorchesAround( const Vector3i & a_BlockPos );
cCriticalSection m_CS;
-}; \ No newline at end of file
+};
+
+
+
+
diff --git a/source/Root.cpp b/source/Root.cpp
index 1b7f90d60..750478c10 100644
--- a/source/Root.cpp
+++ b/source/Root.cpp
@@ -10,7 +10,6 @@
#include "CraftingRecipes.h"
#include "PluginManager.h"
#include "MonsterConfig.h"
-#include "Redstone.h"
#include "Player.h"
#include "Blocks/BlockHandler.h"
#include "Items/ItemHandler.h"
@@ -203,11 +202,7 @@ void cRoot::Start()
void cRoot::LoadGlobalSettings()
{
- cIniFile IniFile("settings.ini");
- if( IniFile.ReadFile() )
- {
- cRedstone::s_UseRedstone = IniFile.GetValueB("Redstone", "SimulateRedstone", true );
- }
+ // Nothing needed yet
}
diff --git a/source/World.cpp b/source/World.cpp
index 961d99d7c..055a0a75e 100644
--- a/source/World.cpp
+++ b/source/World.cpp
@@ -3,7 +3,6 @@
#include "BlockID.h"
#include "World.h"
-#include "Redstone.h"
#include "ChunkDef.h"
#include "ClientHandle.h"
#include "Pickup.h"
@@ -508,24 +507,20 @@ void cWorld::Tick(float a_Dt)
m_RSList.clear();
std::vector<int>::const_iterator cii; // FIXME - Please rename this variable, WTF is cii??? Use human readable variable names or common abbreviations (i, idx, itr, iter)
- for(cii=m_RSList_copy.begin(); cii!=m_RSList_copy.end();)
+ for (cii = m_RSList_copy.begin(); cii != m_RSList_copy.end();)
{
- int tempX = *cii;cii++;
- int tempY = *cii;cii++;
- int tempZ = *cii;cii++;
- int state = *cii;cii++;
+ int tempX = *cii; cii++;
+ int tempY = *cii; cii++;
+ int tempZ = *cii; cii++;
+ int state = *cii; cii++;
if ( (state == 11111) && ( (int)GetBlock( tempX, tempY, tempZ ) == E_BLOCK_REDSTONE_TORCH_OFF ) )
{
FastSetBlock( tempX, tempY, tempZ, E_BLOCK_REDSTONE_TORCH_ON, (int)GetBlockMeta( tempX, tempY, tempZ ) );
- cRedstone Redstone(this);
- Redstone.ChangeRedstone( tempX, tempY, tempZ, true );
}
else if ( (state == 00000) && ( (int)GetBlock( tempX, tempY, tempZ ) == E_BLOCK_REDSTONE_TORCH_ON ) )
{
FastSetBlock( tempX, tempY, tempZ, E_BLOCK_REDSTONE_TORCH_OFF, (int)GetBlockMeta( tempX, tempY, tempZ ) );
- cRedstone Redstone(this);
- Redstone.ChangeRedstone( tempX, tempY, tempZ, false );
}
}
m_RSList_copy.erase(m_RSList_copy.begin(),m_RSList_copy.end());