From 945631ba06fcba24c84017f36544667299c591fb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 23 Mar 2014 14:34:19 +0000 Subject: Sort of implementation of chunk sparsing Issues: * Chunks are flipped * Slow/inefficient/badly coded * Only blocktypes are 'compressed' --- src/Chunk.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++--------- src/Chunk.h | 2 +- 2 files changed, 93 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 957d7d575..adbe94cd0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -239,8 +239,18 @@ void cChunk::MarkLoadFailed(void) void cChunk::GetAllData(cChunkDataCallback & a_Callback) { a_Callback.HeightMap (&m_HeightMap); - a_Callback.BiomeData (&m_BiomeMap); - a_Callback.BlockTypes (m_BlockTypes); + a_Callback.BiomeData(&m_BiomeMap); + + std::vector Blocks; + Blocks.reserve(cChunkDef::NumBlocks); + for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) + { + for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) + { + Blocks.push_back(*dataitr); + } + } + a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); a_Callback.LightIsValid (m_IsLightValid); a_Callback.BlockLight (m_BlockLight); @@ -277,8 +287,42 @@ void cChunk::SetAllData( { memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } + + bool FoundNonAir = false; + m_BlockTypes.clear(); + for (int y = cChunkDef::Height - 1; y >= 0; y--) + { + if (!FoundNonAir) + { + for (int x = 0; x < cChunkDef::Width; x++) + { + for (int z = 0; z < cChunkDef::Width; z++) + { + int Index = cChunkDef::MakeIndexNoCheck(x, y, z); + + if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) + { + FoundNonAir = true; + } + } + } + } + + if (FoundNonAir) + { + std::vector Blocks; + for (int x = 0; x < cChunkDef::Width; x++) + { + for (int z = 0; z < cChunkDef::Width; z++) + { + int Index = cChunkDef::MakeIndexNoCheck(x, y, z); + Blocks.insert(Blocks.begin(), a_BlockTypes[Index]); + } + } + m_BlockTypes.insert(m_BlockTypes.begin(), Blocks); + } + } // for y - memcpy(m_BlockTypes, a_BlockTypes, sizeof(m_BlockTypes)); memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) { @@ -343,7 +387,17 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - memcpy(a_BlockTypes, m_BlockTypes, NumBlocks); + std::vector Blocks; + Blocks.reserve(cChunkDef::NumBlocks); + for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) + { + for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) + { + Blocks.push_back(*dataitr); + } + } + + memcpy(a_BlockTypes, Blocks.data(), NumBlocks); } @@ -630,7 +684,7 @@ void cChunk::Tick(float a_Dt) void cChunk::TickBlock(int a_RelX, int a_RelY, int a_RelZ) { unsigned Index = MakeIndex(a_RelX, a_RelY, a_RelZ); - cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); + cBlockHandler * Handler = BlockHandler(GetBlock(Index)); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 cChunkInterface ChunkInterface(this->GetWorld()->GetChunkMap()); cBlockInServerPluginInterface PluginInterface(*this->GetWorld()); @@ -811,7 +865,7 @@ void cChunk::TickBlocks(void) } unsigned int Index = MakeIndexNoCheck(m_BlockTickX, m_BlockTickY, m_BlockTickZ); - cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); + cBlockHandler * Handler = BlockHandler(GetBlock(Index)); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 Handler->OnUpdate(ChunkInterface, *this->GetWorld(), PluginInterface, *this, m_BlockTickX, m_BlockTickY, m_BlockTickZ); } // for i - tickblocks @@ -1296,7 +1350,7 @@ void cChunk::CreateBlockEntities(void) { for (int y = 0; y < Height; y++) { - BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z); + BLOCKTYPE BlockType = GetBlock(x, y, z); switch (BlockType) { case E_BLOCK_CHEST: @@ -1348,7 +1402,7 @@ void cChunk::WakeUpSimulators(void) int BlockZ = z + BaseZ; for (int y = GetHeight(x, z); y >= 0; y--) { - BLOCKTYPE Block = cChunkDef::GetBlock(m_BlockTypes, x, y, z); + BLOCKTYPE Block = GetBlock(x, y, z); // The redstone sim takes multiple blocks, use the inbuilt checker if (RedstoneSimulator->IsAllowedBlock(Block)) @@ -1392,7 +1446,7 @@ void cChunk::CalculateHeightmap() for (int y = Height - 1; y > -1; y--) { int index = MakeIndex( x, y, z ); - if (m_BlockTypes[index] != E_BLOCK_AIR) + if (GetBlock(index) != E_BLOCK_AIR) { m_HeightMap[x + z * Width] = (unsigned char)y; break; @@ -1515,7 +1569,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT ASSERT(IsValid()); const int index = MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - const BLOCKTYPE OldBlockType = cChunkDef::GetBlock(m_BlockTypes, index); + const BLOCKTYPE OldBlockType = GetBlock(index); const BLOCKTYPE OldBlockMeta = GetNibble(m_BlockMeta, index); if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta)) { @@ -1524,7 +1578,20 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - m_BlockTypes[index] = a_BlockType; + int Layer = (int)index / (cChunkDef::Width * cChunkDef::Width); + int SubBlock = index % ((cChunkDef::Width * cChunkDef::Width) - 1); + + if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + { + m_BlockTypes.reserve(Layer - ((int)m_BlockTypes.size() - 1)); + std::vector EmptyBlocks(cChunkDef::Width * cChunkDef::Width); + for (int lyr = ((int)m_BlockTypes.size() - 1); lyr <= Layer; ++lyr) + { + m_BlockTypes.push_back(EmptyBlocks); + } + } + + m_BlockTypes[Layer][SubBlock] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: if ( @@ -1563,7 +1630,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT { for (int y = a_RelY - 1; y > 0; --y) { - if (m_BlockTypes[MakeIndexNoCheck(a_RelX, y, a_RelZ)] != E_BLOCK_AIR) + if (GetBlock(MakeIndexNoCheck(a_RelX, y, a_RelZ)) != E_BLOCK_AIR) { m_HeightMap[a_RelX + a_RelZ * Width] = (unsigned char)y; break; @@ -2450,7 +2517,7 @@ BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const return 0; // Clip } - return m_BlockTypes[MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ)]; + return GetBlock(MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ)); } @@ -2464,8 +2531,16 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const ASSERT(!"GetBlock(idx) out of bounds!"); return 0; } - - return m_BlockTypes[ a_BlockIdx ]; + + int Layer = (int)a_BlockIdx / (cChunkDef::Width * cChunkDef::Width); + int SubBlock = a_BlockIdx % ((cChunkDef::Width * cChunkDef::Width) - 1); + + if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + { + return E_BLOCK_AIR; + } + + return m_BlockTypes[Layer][SubBlock]; } @@ -2475,7 +2550,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockType = GetBlock(Idx); a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, Idx); } @@ -2486,7 +2561,7 @@ void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_ void cChunk::GetBlockInfo(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) { int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockType = GetBlock(Idx); a_Meta = cChunkDef::GetNibble(m_BlockMeta, Idx); a_SkyLight = cChunkDef::GetNibble(m_BlockSkyLight, Idx); a_BlockLight = cChunkDef::GetNibble(m_BlockLight, Idx); diff --git a/src/Chunk.h b/src/Chunk.h index b3fa563cc..1b83bc540 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -421,7 +421,7 @@ private: cChunkMap * m_ChunkMap; // TODO: Make these pointers and don't allocate what isn't needed - BLOCKTYPE m_BlockTypes [cChunkDef::NumBlocks]; + std::vector> m_BlockTypes; NIBBLETYPE m_BlockMeta [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; -- cgit v1.2.3 From 357411a48978d6a672e4694edfa1ff87d57cfcfb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 2 Apr 2014 22:53:03 +0100 Subject: Performance improvements and chunk flipping fixed --- src/Chunk.cpp | 62 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index adbe94cd0..a73bf7ca9 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -239,17 +239,15 @@ void cChunk::MarkLoadFailed(void) void cChunk::GetAllData(cChunkDataCallback & a_Callback) { a_Callback.HeightMap (&m_HeightMap); - a_Callback.BiomeData(&m_BiomeMap); + a_Callback.BiomeData (&m_BiomeMap); std::vector Blocks; Blocks.reserve(cChunkDef::NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { - for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) - { - Blocks.push_back(*dataitr); - } + Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); a_Callback.LightIsValid (m_IsLightValid); @@ -272,56 +270,63 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) void cChunk::SetAllData( - const BLOCKTYPE * a_BlockTypes, + const BLOCKTYPE * a_BlockTypes, const NIBBLETYPE * a_BlockMeta, const NIBBLETYPE * a_BlockLight, const NIBBLETYPE * a_BlockSkyLight, const HeightMap * a_HeightMap, const BiomeMap & a_BiomeMap, cBlockEntityList & a_BlockEntities -) + ) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); - + if (a_HeightMap != NULL) { memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } bool FoundNonAir = false; + int PosYWhereNonEmptyStarts = 0; m_BlockTypes.clear(); - for (int y = cChunkDef::Height - 1; y >= 0; y--) + m_BlockTypes.reserve(Height / 2); + + for (int y = Height; y >= 0; y--) { - if (!FoundNonAir) + for (int z = 0; z < Width; z++) { - for (int x = 0; x < cChunkDef::Width; x++) + for (int x = 0; x < Width; x++) { - for (int z = 0; z < cChunkDef::Width; z++) - { - int Index = cChunkDef::MakeIndexNoCheck(x, y, z); + int Index = MakeIndexNoCheck(x, y, z); - if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) - { - FoundNonAir = true; - } + if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) + { + FoundNonAir = true; + PosYWhereNonEmptyStarts = y; + goto foundair; } } } + } - if (FoundNonAir) +foundair: + if (FoundNonAir) + { + for (int y = 0; y <= PosYWhereNonEmptyStarts; y++) { std::vector Blocks; - for (int x = 0; x < cChunkDef::Width; x++) + Blocks.reserve(Width * Width); + for (int z = 0; z < Width; z++) { - for (int z = 0; z < cChunkDef::Width; z++) + for (int x = 0; x < Width; x++) { - int Index = cChunkDef::MakeIndexNoCheck(x, y, z); - Blocks.insert(Blocks.begin(), a_BlockTypes[Index]); + int Index = MakeIndexNoCheck(x, y, z); + Blocks.push_back(a_BlockTypes[Index]); } } - m_BlockTypes.insert(m_BlockTypes.begin(), Blocks); - } - } // for y + m_BlockTypes.push_back(Blocks); + } // for y + } memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) @@ -391,10 +396,7 @@ void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) Blocks.reserve(cChunkDef::NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { - for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) - { - Blocks.push_back(*dataitr); - } + Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } memcpy(a_BlockTypes, Blocks.data(), NumBlocks); -- cgit v1.2.3 From d5faf5a38ebe164d705cc67baaa4b3c9d7eb6159 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 3 Apr 2014 19:17:04 +0100 Subject: Fixed some bugs * Fixed undefined behaviour * Fixed compression failure --- src/Chunk.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a73bf7ca9..d80e93702 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -242,11 +242,12 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.BiomeData (&m_BiomeMap); std::vector Blocks; - Blocks.reserve(cChunkDef::NumBlocks); + Blocks.reserve(NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + Blocks.resize(NumBlocks); a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); @@ -291,7 +292,7 @@ void cChunk::SetAllData( m_BlockTypes.clear(); m_BlockTypes.reserve(Height / 2); - for (int y = Height; y >= 0; y--) + for (int y = Height - 1; y >= 0; y--) { for (int z = 0; z < Width; z++) { @@ -393,11 +394,12 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { std::vector Blocks; - Blocks.reserve(cChunkDef::NumBlocks); + Blocks.reserve(NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + Blocks.resize(NumBlocks); memcpy(a_BlockTypes, Blocks.data(), NumBlocks); } -- cgit v1.2.3 From 15a0ceec2687c04191c41f7b103c26aeb98705ca Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 4 Apr 2014 13:01:05 +0100 Subject: Speed and memory improvements * Changed array to be continuous, so no more layer splitting --- src/Chunk.cpp | 75 +++++++++++------------------------------------------------ src/Chunk.h | 2 +- 2 files changed, 15 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6e6b7ed20..c2caafe45 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -241,12 +241,7 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - std::vector Blocks; - Blocks.reserve(NumBlocks); - for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); a_Callback.BlockTypes (Blocks.data()); @@ -288,46 +283,20 @@ void cChunk::SetAllData( } bool FoundNonAir = false; - int PosYWhereNonEmptyStarts = 0; + int IdxWhereNonEmptyStarts = 0; m_BlockTypes.clear(); - m_BlockTypes.reserve(Height / 2); - for (int y = Height - 1; y >= 0; y--) + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) { - for (int z = 0; z < Width; z++) + if (a_BlockTypes[Idx] != E_BLOCK_AIR) { - for (int x = 0; x < Width; x++) - { - int Index = MakeIndexNoCheck(x, y, z); - - if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) - { - FoundNonAir = true; - PosYWhereNonEmptyStarts = y; - goto foundair; - } - } + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; } } -foundair: - if (FoundNonAir) - { - for (int y = 0; y <= PosYWhereNonEmptyStarts; y++) - { - std::vector Blocks; - Blocks.reserve(Width * Width); - for (int z = 0; z < Width; z++) - { - for (int x = 0; x < Width; x++) - { - int Index = MakeIndexNoCheck(x, y, z); - Blocks.push_back(a_BlockTypes[Index]); - } - } - m_BlockTypes.push_back(Blocks); - } // for y - } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) @@ -393,12 +362,7 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - std::vector Blocks; - Blocks.reserve(NumBlocks); - for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); memcpy(a_BlockTypes, Blocks.data(), NumBlocks); @@ -1581,21 +1545,13 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT } MarkDirty(); - - int Layer = (int)index / (cChunkDef::Width * cChunkDef::Width); - int SubBlock = index % ((cChunkDef::Width * cChunkDef::Width) - 1); - if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { - m_BlockTypes.reserve(Layer - ((int)m_BlockTypes.size() - 1)); - std::vector EmptyBlocks(cChunkDef::Width * cChunkDef::Width); - for (int lyr = ((int)m_BlockTypes.size() - 1); lyr <= Layer; ++lyr) - { - m_BlockTypes.push_back(EmptyBlocks); - } + m_BlockTypes.resize(index); } - m_BlockTypes[Layer][SubBlock] = a_BlockType; + m_BlockTypes[index] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: if ( @@ -2536,15 +2492,12 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - int Layer = (int)a_BlockIdx / (cChunkDef::Width * cChunkDef::Width); - int SubBlock = a_BlockIdx % ((cChunkDef::Width * cChunkDef::Width) - 1); - - if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || (a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { return E_BLOCK_AIR; } - return m_BlockTypes[Layer][SubBlock]; + return m_BlockTypes[a_BlockIdx]; } diff --git a/src/Chunk.h b/src/Chunk.h index 1b83bc540..ef6a11006 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -421,7 +421,7 @@ private: cChunkMap * m_ChunkMap; // TODO: Make these pointers and don't allocate what isn't needed - std::vector> m_BlockTypes; + std::vector m_BlockTypes; NIBBLETYPE m_BlockMeta [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; -- cgit v1.2.3 From 3201d1bf169ca99e4cdbfad7601f6aed89b3c76c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 4 Apr 2014 23:16:52 +0100 Subject: Nibbletypes are compressed + Added nibble compression * Fixed an off by one --- src/Chunk.cpp | 49 +++++++++++++++++++++++++------------ src/Chunk.h | 2 +- src/ChunkDef.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c2caafe45..97822048d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -243,9 +243,12 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - a_Callback.BlockTypes (Blocks.data()); - a_Callback.BlockMeta (m_BlockMeta); + + std::vector Metas = m_BlockMeta; + Metas.resize(NumBlocks / 2); + a_Callback.BlockMeta (Metas.data()); + a_Callback.LightIsValid (m_IsLightValid); a_Callback.BlockLight (m_BlockLight); a_Callback.BlockSkyLight(m_BlockSkyLight); @@ -282,23 +285,40 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } - bool FoundNonAir = false; - int IdxWhereNonEmptyStarts = 0; - m_BlockTypes.clear(); + { // Blocktype compression + bool FoundNonAir = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockTypes.clear(); - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) - { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) { - FoundNonAir = true; - IdxWhereNonEmptyStarts = Idx; - break; + if (a_BlockTypes[Idx] != E_BLOCK_AIR) + { + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; + } } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + { // Blockmeta compression + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockMeta.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_BlockMeta[Idx] != 0) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts + 1]); + } - memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) { memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); @@ -1548,9 +1568,8 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { - m_BlockTypes.resize(index); + m_BlockTypes.resize(index + 1); } - m_BlockTypes[index] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: diff --git a/src/Chunk.h b/src/Chunk.h index ef6a11006..d8e4cf6e4 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -422,7 +422,7 @@ private: // TODO: Make these pointers and don't allocate what isn't needed std::vector m_BlockTypes; - NIBBLETYPE m_BlockMeta [cChunkDef::NumBlocks / 2]; + std::vector m_BlockMeta; NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 9c7753820..3793bd95a 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -230,6 +230,21 @@ public: ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); return 0; } + + + static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int a_BlockIdx) + { + if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) + { + if (a_Buffer.empty() || (a_BlockIdx / 2 > a_Buffer.size() - 1)) + { + return 0; + } + return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f; + } + ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); + return 0; + } static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z) @@ -244,6 +259,22 @@ public: } + static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int x, int y, int z) + { + if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) + { + int Index = MakeIndexNoCheck(x, y, z); + if (a_Buffer.empty() || (Index / 2 > a_Buffer.size() - 1)) + { + return 0; + } + return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + } + ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); + return 0; + } + + static void SetNibble(NIBBLETYPE * a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble) { if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks)) @@ -256,6 +287,24 @@ public: ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } + + + static void SetNibble(std::vector & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble) + { + if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks)) + { + ASSERT(!"cChunkDef::SetNibble(): index out of range!"); + return; + } + if (a_Buffer.empty() || (a_BlockIdx / 2 > a_Buffer.size() - 1)) + { + a_Buffer.resize((a_BlockIdx / 2) + 1); + } + a_Buffer[a_BlockIdx / 2] = static_cast( + (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble + ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set + ); + } static void SetNibble(NIBBLETYPE * a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) @@ -278,13 +327,37 @@ public: } - inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) + static void SetNibble(std::vector & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) + { + if ( + (x >= Width) || (x < 0) || + (y >= Height) || (y < 0) || + (z >= Width) || (z < 0) + ) + { + ASSERT(!"cChunkDef::SetNibble(): index out of range!"); + return; + } + + int Index = MakeIndexNoCheck(x, y, z); + if (a_Buffer.empty() || (Index / 2 > a_Buffer.size() - 1)) + { + a_Buffer.resize((Index / 2) + 1); + } + a_Buffer[Index / 2] = static_cast( + (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble + ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set + ); + } + + + inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos) { return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); } - inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value ) + inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value) { SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); } -- cgit v1.2.3 From a42d1f851748c0cca542d1b0038318d0cbff9fd3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Apr 2014 23:30:21 +0100 Subject: Blocklight and skylight now compressed --- src/Chunk.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++------------- src/Chunk.h | 8 ++--- src/ChunkDef.h | 8 ++--- 3 files changed, 90 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 97822048d..7a3e63bd0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -250,8 +250,14 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.BlockMeta (Metas.data()); a_Callback.LightIsValid (m_IsLightValid); - a_Callback.BlockLight (m_BlockLight); - a_Callback.BlockSkyLight(m_BlockSkyLight); + + std::vector BlockLights = m_BlockLight; + BlockLights.resize(NumBlocks / 2); + a_Callback.BlockLight (BlockLights.data()); + + std::vector BlockSkyLights = m_BlockSkyLight; + BlockSkyLights.resize(NumBlocks / 2, 0xff); + a_Callback.BlockSkyLight(BlockSkyLights.data()); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -285,47 +291,66 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } - { // Blocktype compression - bool FoundNonAir = false; + { + int IdxWhereNonEmptyStarts = 0; + { // Blocktype compression + bool FoundNonAir = false; + m_BlockTypes.clear(); + + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + { + if (a_BlockTypes[Idx] != E_BLOCK_AIR) + { + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + } + + { // Blockmeta compression + m_BlockMeta.clear(); + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[(IdxWhereNonEmptyStarts + 1) / 2]); + } + } + + if (a_BlockLight != NULL) + { + // Compress blocklight + bool FoundNonEmpty = false; int IdxWhereNonEmptyStarts = 0; - m_BlockTypes.clear(); + m_BlockLight.clear(); - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + if (a_BlockLight[Idx] != 0) { - FoundNonAir = true; + FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); } - { // Blockmeta compression + if (a_BlockSkyLight != NULL) + { + // Compress skylight bool FoundNonEmpty = false; int IdxWhereNonEmptyStarts = 0; - m_BlockMeta.clear(); + m_BlockSkyLight.clear(); for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { - if (a_BlockMeta[Idx] != 0) + if (a_BlockSkyLight[Idx] != 0xff) { FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } } - m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts + 1]); - } - - if (a_BlockLight != NULL) - { - memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); - } - if (a_BlockSkyLight != NULL) - { - memcpy(m_BlockSkyLight, a_BlockSkyLight, sizeof(m_BlockSkyLight)); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts + 1]); } m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL); @@ -371,8 +396,41 @@ void cChunk::SetLight( { // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) - memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); - memcpy(m_BlockSkyLight, a_SkyLight, sizeof(m_BlockSkyLight)); + + { // Compress blocklight + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockLight.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_BlockLight[Idx] != 0) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + } + + { // Compress skylight + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockSkyLight.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_SkyLight[Idx] != 0xff) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); + } + m_IsLightValid = true; } diff --git a/src/Chunk.h b/src/Chunk.h index d8e4cf6e4..6e2933ff8 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -326,9 +326,9 @@ public: inline void SetMeta(int a_BlockIdx, NIBBLETYPE a_Meta) { cChunkDef::SetNibble(m_BlockMeta, a_BlockIdx, a_Meta); } inline NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockLight, a_RelX, a_RelY, a_RelZ); } - inline NIBBLETYPE GetSkyLight (int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_RelX, a_RelY, a_RelZ); } + inline NIBBLETYPE GetSkyLight (int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_RelX, a_RelY, a_RelZ, true); } inline NIBBLETYPE GetBlockLight(int a_Idx) const {return cChunkDef::GetNibble(m_BlockLight, a_Idx); } - inline NIBBLETYPE GetSkyLight (int a_Idx) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_Idx); } + inline NIBBLETYPE GetSkyLight (int a_Idx) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_Idx, true); } /** Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; @@ -423,8 +423,8 @@ private: // TODO: Make these pointers and don't allocate what isn't needed std::vector m_BlockTypes; std::vector m_BlockMeta; - NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; - NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; + std::vector m_BlockLight; + std::vector m_BlockSkyLight; cChunkDef::HeightMap m_HeightMap; cChunkDef::BiomeMap m_BiomeMap; diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 3793bd95a..d744d24b2 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -232,13 +232,13 @@ public: } - static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int a_BlockIdx) + static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false) { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { if (a_Buffer.empty() || (a_BlockIdx / 2 > a_Buffer.size() - 1)) { - return 0; + return (a_IsSkyLightNibble ? 0xff : 0); } return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f; } @@ -259,14 +259,14 @@ public: } - static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int x, int y, int z) + static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false) { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); if (a_Buffer.empty() || (Index / 2 > a_Buffer.size() - 1)) { - return 0; + return (a_IsSkyLightNibble ? 0xff : 0); } return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } -- cgit v1.2.3 From 74c4789c6f8f42c6df45ed1e355e562bdced908d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Apr 2014 12:43:43 +0100 Subject: Attempt to fix errors --- src/Chunk.cpp | 4 ++-- src/ChunkDef.h | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7a3e63bd0..ede01a6cc 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1624,7 +1624,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { m_BlockTypes.resize(index + 1); } @@ -2569,7 +2569,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || (a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { return E_BLOCK_AIR; } diff --git a/src/ChunkDef.h b/src/ChunkDef.h index d744d24b2..bb9f14bbe 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -236,11 +236,11 @@ public: { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { - if (a_Buffer.empty() || (a_BlockIdx / 2 > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1)) { return (a_IsSkyLightNibble ? 0xff : 0); } - return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f; + return (a_Buffer[(size_t)(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); return 0; @@ -264,11 +264,11 @@ public: if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || (Index / 2 > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1)) { return (a_IsSkyLightNibble ? 0xff : 0); } - return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); return 0; @@ -296,11 +296,11 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - if (a_Buffer.empty() || (a_BlockIdx / 2 > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1)) { - a_Buffer.resize((a_BlockIdx / 2) + 1); + a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1)); } - a_Buffer[a_BlockIdx / 2] = static_cast( + a_Buffer[(size_t)(a_BlockIdx / 2)] = static_cast( (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); @@ -340,11 +340,11 @@ public: } int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || (Index / 2 > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1)) { - a_Buffer.resize((Index / 2) + 1); + a_Buffer.resize((size_t)((Index / 2) + 1)); } - a_Buffer[Index / 2] = static_cast( + a_Buffer[(size_t)(Index / 2)] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); -- cgit v1.2.3 From c79ba3494c1db2919c08fd17ae54399b7d8b4915 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 7 Apr 2014 16:31:15 +0300 Subject: Statistic/Achievement defs --- src/Statistics.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Statistics.h | 116 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 src/Statistics.cpp create mode 100644 src/Statistics.h (limited to 'src') diff --git a/src/Statistics.cpp b/src/Statistics.cpp new file mode 100644 index 000000000..30904db4b --- /dev/null +++ b/src/Statistics.cpp @@ -0,0 +1,139 @@ + +// Statistics.cpp + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Statistics.h" + + + +cStatInfo cStatInfo::ms_Info[statCount] = { + // Do NOT change the order + + // http://minecraft.gamepedia.com/Achievements + + /* Type | Name | Prerequisite */ + cStatInfo(achOpenInv, "openInventory"), + cStatInfo(achMineWood, "mineWood", achOpenInv), + cStatInfo(achCraftWorkbench, "buildWorkBench", achMineWood), + cStatInfo(achCraftPickaxe, "buildPickaxe", achCraftWorkbench), + cStatInfo(achCraftFurnace, "buildFurnace", achCraftPickaxe), + cStatInfo(achAcquireIron, "acquireIron", achCraftFurnace), + cStatInfo(achCraftHoe, "buildHoe", achCraftWorkbench), + cStatInfo(achMakeBread, "makeBread", achCraftHoe), + cStatInfo(achBakeCake, "bakeCake", achCraftHoe), + cStatInfo(achCraftBetterPick, "buildBetterPickaxe", achCraftPickaxe), + cStatInfo(achCookFish, "cookFish", achAcquireIron), + cStatInfo(achOnARail, "onARail", achAcquireIron), + cStatInfo(achCraftSword, "buildSword", achCraftWorkbench), + cStatInfo(achKillMonster, "killEnemy", achCraftSword), + cStatInfo(achKillCow, "killCow", achCraftSword), + cStatInfo(achFlyPig, "flyPig", achKillCow), + cStatInfo(achSnipeSkeleton, "snipeSkeleton", achKillMonster), + cStatInfo(achDiamonds, "diamonds", achAcquireIron), + cStatInfo(achEnterPortal, "portal", achDiamonds), + cStatInfo(achReturnToSender, "ghast", achEnterPortal), + cStatInfo(achBlazeRod, "blazeRod", achEnterPortal), + cStatInfo(achBrewPotion, "potion", achBlazeRod), + cStatInfo(achEnterTheEnd, "theEnd", achBlazeRod), + cStatInfo(achDefeatDragon, "theEnd2", achEnterTheEnd), + cStatInfo(achCraftEnchantTable, "enchantments", achDiamonds), + cStatInfo(achOverkill, "overkill", achCraftEnchantTable), + cStatInfo(achBookshelf, "bookcase", achCraftEnchantTable), + cStatInfo(achExploreAllBiomes, "exploreAllBiomes", achEnterTheEnd), + cStatInfo(achSpawnWither, "spawnWither", achDefeatDragon), + cStatInfo(achKillWither, "killWither", achSpawnWither), + cStatInfo(achFullBeacon, "fullBeacon", achKillWither), + cStatInfo(achBreedCow, "breedCow", achKillCow), + cStatInfo(achThrowDiamonds, "diamondsToYou", achDiamonds), + + // http://minecraft.gamepedia.com/Statistics + + /* Type | Name */ + cStatInfo(statGamesQuit, "stat.leaveGame"), + cStatInfo(statMinutesPlayed, "stat.playOneMinute"), + cStatInfo(statDistWalked, "stat.walkOnCm"), + cStatInfo(statDistSwum, "stat.swimOneCm"), + cStatInfo(statDistFallen, "stat.fallOneCm"), + cStatInfo(statDistClimbed, "stat.climbOneCm"), + cStatInfo(statDistFlown, "stat.flyOneCm"), + cStatInfo(statDistMinecart, "stat.minecartOneCm"), + cStatInfo(statDistBoat, "stat.boatOneCm"), + cStatInfo(statDistPig, "stat.pigOneCm"), + cStatInfo(statDistHorse, "stat.horseOneCm"), + cStatInfo(statJumps, "stat.jump"), + cStatInfo(statItemsDropped, "stat.drop"), + cStatInfo(statDamageDealt, "stat.damageDealth"), + cStatInfo(statDamageTaken, "stat.damageTaken"), + cStatInfo(statDeaths, "stat.deaths"), + cStatInfo(statMobKills, "stat.mobKills"), + cStatInfo(statAnimalsBred, "stat.animalsBred"), + cStatInfo(statPlayerKills, "stat.playerKills"), + cStatInfo(statFishCaught, "stat.fishCaught"), + cStatInfo(statJunkFished, "stat.junkFished"), + cStatInfo(statTreasureFished, "stat.treasureFished") +}; + + + + + + +cStatInfo::cStatInfo() + : m_Type(statInvalid) + , m_Depends(statInvalid) +{} + + + + + +cStatInfo::cStatInfo(const eStatistic a_Type, const AString & a_Name, const eStatistic a_Depends) + : m_Type(a_Type) + , m_Name(a_Name) + , m_Depends(a_Depends) +{} + + + + + +const AString & cStatInfo::GetName(const eStatistic a_Type) +{ + ASSERT((a_Type > statInvalid) && (a_Type < statCount)); + + return ms_Info[a_Type].m_Name; +} + + + + + +eStatistic cStatInfo::GetType(const AString & a_Name) +{ + for (unsigned int i = 0; i < ARRAYCOUNT(ms_Info); ++i) + { + if (NoCaseCompare(ms_Info[i].m_Name, a_Name)) + { + return ms_Info[i].m_Type; + } + } + + return statInvalid; +} + + + + + +eStatistic cStatInfo::GetPrerequisite(const eStatistic a_Type) +{ + ASSERT((a_Type > statInvalid) && (a_Type < statCount)); + + return ms_Info[a_Type].m_Depends; +} + + + + + diff --git a/src/Statistics.h b/src/Statistics.h new file mode 100644 index 000000000..c6e1cf910 --- /dev/null +++ b/src/Statistics.h @@ -0,0 +1,116 @@ + +// Statistics.h + + + + +#pragma once + + + + +enum eStatistic +{ + // Do NOT change the order + + statInvalid = -1, + + /* Achievements */ + achOpenInv, /* Taking Inventory */ + achMineWood, /* Getting Wood */ + achCraftWorkbench, /* Benchmarking */ + achCraftPickaxe, /* Time to Mine! */ + achCraftFurnace, /* Hot Topic */ + achAcquireIron, /* Acquire Hardware */ + achCraftHoe, /* Time to Farm! */ + achMakeBread, /* Bake Bread */ + achBakeCake, /* The Lie */ + achCraftBetterPick, /* Getting an Upgrade */ + achCookFish, /* Delicious Fish */ + achOnARail, /* On A Rail */ + achCraftSword, /* Time to Strike! */ + achKillMonster, /* Monster Hunter */ + achKillCow, /* Cow Tipper */ + achFlyPig, /* When Pigs Fly */ + achSnipeSkeleton, /* Sniper Duel */ + achDiamonds, /* DIAMONDS! */ + achEnterPortal, /* We Need to Go Deeper */ + achReturnToSender, /* Return to Sender */ + achBlazeRod, /* Into Fire */ + achBrewPotion, /* Local Brewery */ + achEnterTheEnd, /* The End? */ + achDefeatDragon, /* The End. */ + achCraftEnchantTable, /* Enchanter */ + achOverkill, /* Overkill */ + achBookshelf, /* Librarian */ + achExploreAllBiomes, /* Adventuring Time */ + achSpawnWither, /* The Beginning? */ + achKillWither, /* The Beginning. */ + achFullBeacon, /* Beaconator */ + achBreedCow, /* Repopulation */ + achThrowDiamonds, /* Diamonds to you! */ + + /* Statistics */ + statGamesQuit, + statMinutesPlayed, + statDistWalked, + statDistSwum, + statDistFallen, + statDistClimbed, + statDistFlown, + statDistDove, + statDistMinecart, + statDistBoat, + statDistPig, + statDistHorse, + statJumps, + statItemsDropped, + statDamageDealt, + statDamageTaken, + statDeaths, + statMobKills, + statAnimalsBred, + statPlayerKills, + statFishCaught, + statJunkFished, + statTreasureFished, + + statCount +}; + + + + + + +/** Class used to store and query statistic-related information. */ +class cStatInfo +{ +public: + + cStatInfo(); + + cStatInfo(const eStatistic a_Type, const AString & a_Name, const eStatistic a_Depends = statInvalid); + + /** Type -> Name */ + static const AString & GetName(const eStatistic a_Type); + + /** Name -> Type */ + static eStatistic GetType(const AString & a_Name); + + /** Returns stat prerequisite. (Used for achievements) */ + static eStatistic GetPrerequisite(const eStatistic a_Type); + +private: + + eStatistic m_Type; + + AString m_Name; + + eStatistic m_Depends; + + static cStatInfo ms_Info[statCount]; +}; + + + -- cgit v1.2.3 From f13cf1a0217437113ad5372ef971c3903d55a9c6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Apr 2014 20:57:14 +0100 Subject: Maybe speed improvements? * Use a single index to determine from when to begin copying data * Use heightmap to determine first nonair block --- src/Chunk.cpp | 75 ++++++++++++++++++++++------------------------------------- src/Chunk.h | 2 +- 2 files changed, 29 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ede01a6cc..7b49862f0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -291,74 +291,55 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } + if (a_HeightMap == NULL) { - int IdxWhereNonEmptyStarts = 0; - { // Blocktype compression - bool FoundNonAir = false; - m_BlockTypes.clear(); + CalculateHeightmap(a_BlockTypes); + } - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + int IdxWhereNonEmptyStarts = 0; + { // Blocktype compression + unsigned char Highest = 0; + int X = 0, Z = 0; + m_BlockTypes.clear(); + + for (int x = 0; x < Width; x++) + { + for (int z = 0; z < Width; z++) { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + unsigned char Height = m_HeightMap[x + z * Width]; + if (Height > Highest) { - FoundNonAir = true; - IdxWhereNonEmptyStarts = Idx; - break; + Highest = Height; + X = x; Z = z; } } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); } - { // Blockmeta compression - m_BlockMeta.clear(); - m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[(IdxWhereNonEmptyStarts + 1) / 2]); - } + IdxWhereNonEmptyStarts = MakeIndexNoCheck(X, Highest + 1, Z); + + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts]); + } + + { // Blockmeta compression + m_BlockMeta.clear(); + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts / 2]); } if (a_BlockLight != NULL) { // Compress blocklight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockLight[Idx] != 0) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts / 2]); } if (a_BlockSkyLight != NULL) { // Compress skylight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockSkyLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockSkyLight[Idx] != 0xff) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts + 1]); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts / 2]); } m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL); - - if (a_HeightMap == NULL) - { - CalculateHeightmap(); - } // Clear the block entities present - either the loader / saver has better, or we'll create empty ones: for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr) @@ -1483,7 +1464,7 @@ void cChunk::WakeUpSimulators(void) -void cChunk::CalculateHeightmap() +void cChunk::CalculateHeightmap(const BLOCKTYPE * a_BlockTypes) { for (int x = 0; x < Width; x++) { @@ -1492,7 +1473,7 @@ void cChunk::CalculateHeightmap() for (int y = Height - 1; y > -1; y--) { int index = MakeIndex( x, y, z ); - if (GetBlock(index) != E_BLOCK_AIR) + if (a_BlockTypes[index] != E_BLOCK_AIR) { m_HeightMap[x + z * Width] = (unsigned char)y; break; diff --git a/src/Chunk.h b/src/Chunk.h index 6e2933ff8..9100eec58 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -267,7 +267,7 @@ public: void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z); // [x, y, z] in world block coords void CalculateLighting(); // Recalculate right now - void CalculateHeightmap(); + void CalculateHeightmap(const BLOCKTYPE * a_BlockTypes); // Broadcast various packets to all clients of this chunk: // (Please keep these alpha-sorted) -- cgit v1.2.3 From 01546020fc70a940f2644e9c8f58c26b754bc653 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 10 Apr 2014 12:12:36 -0700 Subject: Replaced all the .data() calls so the code compiles in VS2008 --- src/Chunk.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7b49862f0..ee1531b5c 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -243,21 +243,21 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - a_Callback.BlockTypes (Blocks.data()); + a_Callback.BlockTypes (&Blocks[0]); std::vector Metas = m_BlockMeta; Metas.resize(NumBlocks / 2); - a_Callback.BlockMeta (Metas.data()); + a_Callback.BlockMeta (&Metas[0]); a_Callback.LightIsValid (m_IsLightValid); std::vector BlockLights = m_BlockLight; BlockLights.resize(NumBlocks / 2); - a_Callback.BlockLight (BlockLights.data()); + a_Callback.BlockLight (&BlockLights[0]); std::vector BlockSkyLights = m_BlockSkyLight; BlockSkyLights.resize(NumBlocks / 2, 0xff); - a_Callback.BlockSkyLight(BlockSkyLights.data()); + a_Callback.BlockSkyLight(&BlockSkyLights[0]); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -424,7 +424,7 @@ void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - memcpy(a_BlockTypes, Blocks.data(), NumBlocks); + memcpy(a_BlockTypes, &Blocks[0], NumBlocks); } -- cgit v1.2.3 From a967313839bab2a5f43befabe689801b949b274e Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Mon, 21 Apr 2014 13:13:25 +0400 Subject: Mobs shouldn't burn when it's Raining #906 --- src/Entities/Entity.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 56ef36ef8..c1926dafc 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -774,12 +774,19 @@ void cEntity::TickBurning(cChunk & a_Chunk) if (GetWorld()->GetWeather() == eWeather_Rain) { - if (HasBeenBurning) + + int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width, + PosY = POSY_TOINT, + PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + + if ((PosY > 0) || (PosY <= cChunkDef::Height)) { - m_TicksLeftBurning = 0; - OnFinishedBurning(); - } - return; + // Inside the world + if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) + { + m_TicksLeftBurning = 0; + } + } } // Do the burning damage: -- cgit v1.2.3 From 5deb35c5cfc97fc07601fb64ce9631c794237680 Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Wed, 23 Apr 2014 18:15:04 +0400 Subject: Mobs shouldn't burn when it's Raining #906 Mob Knockback is far too much #776 --- src/Entities/Entity.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c1926dafc..46bb499b4 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -325,9 +325,32 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } - if (IsMob() || IsPlayer()) // Knockback for only players and mobs + if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { - AddSpeed(a_TDI.Knockback * 2); + int KnockbackLevel = 0; + if (a_TDI.Attacker->GetEquippedWeapon().m_ItemType == E_ITEM_BOW) + { + KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch); + } + else + { + KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); + } + + Vector3d additionalSpeed(0, 0, 0); + switch (KnockbackLevel) + { + case 1: + additionalSpeed.Set(5, .2, 5); + break; + case 2: + additionalSpeed.Set(8, .2, 8); + break; + default: + additionalSpeed.Set(2, .2, 2); + break; + } + AddSpeed(a_TDI.Knockback * additionalSpeed); } m_World->BroadcastEntityStatus(*this, esGenericHurt); @@ -772,16 +795,14 @@ void cEntity::TickBurning(cChunk & a_Chunk) // Remember the current burning state: bool HasBeenBurning = (m_TicksLeftBurning > 0); - if (GetWorld()->GetWeather() == eWeather_Rain) + if (m_World->IsWeatherWet()) { + int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int PosY = POSY_TOINT; + int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width, - PosY = POSY_TOINT, - PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - - if ((PosY > 0) || (PosY <= cChunkDef::Height)) + if((POSY_TOINT - 1) == m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { - // Inside the world if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) { m_TicksLeftBurning = 0; -- cgit v1.2.3 From c2f2ef7cb4e4232cae18aaddcc6c86253e6c859b Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 23 Apr 2014 14:56:39 -0700 Subject: Rename mob source files to fit CamelCase. Rename Cavespider.cpp to CaveSpider.cpp Rename Cavespider.h to CaveSpider.h Rename Magmacube.cpp to MagmaCube.cpp Rename Magmacube.h to MagmaCube.h Rename Zombiepigman.cpp to ZombiePigman.cpp Rename Zombiepigman.h to ZombiePigman.h --- src/Mobs/CaveSpider.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ src/Mobs/CaveSpider.h | 25 ++++++++++++++++++++++ src/Mobs/Cavespider.cpp | 48 ----------------------------------------- src/Mobs/Cavespider.h | 26 ----------------------- src/Mobs/MagmaCube.cpp | 30 ++++++++++++++++++++++++++ src/Mobs/MagmaCube.h | 31 +++++++++++++++++++++++++++ src/Mobs/Magmacube.cpp | 31 --------------------------- src/Mobs/Magmacube.h | 32 ---------------------------- src/Mobs/ZombiePigman.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ src/Mobs/ZombiePigman.h | 25 ++++++++++++++++++++++ src/Mobs/Zombiepigman.cpp | 54 ----------------------------------------------- src/Mobs/Zombiepigman.h | 26 ----------------------- 12 files changed, 211 insertions(+), 217 deletions(-) create mode 100644 src/Mobs/CaveSpider.cpp create mode 100644 src/Mobs/CaveSpider.h delete mode 100644 src/Mobs/Cavespider.cpp delete mode 100644 src/Mobs/Cavespider.h create mode 100644 src/Mobs/MagmaCube.cpp create mode 100644 src/Mobs/MagmaCube.h delete mode 100644 src/Mobs/Magmacube.cpp delete mode 100644 src/Mobs/Magmacube.h create mode 100644 src/Mobs/ZombiePigman.cpp create mode 100644 src/Mobs/ZombiePigman.h delete mode 100644 src/Mobs/Zombiepigman.cpp delete mode 100644 src/Mobs/Zombiepigman.h (limited to 'src') diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp new file mode 100644 index 000000000..4660ae44d --- /dev/null +++ b/src/Mobs/CaveSpider.cpp @@ -0,0 +1,47 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Cavespider.h" +#include "../World.h" + + + + + +cCavespider::cCavespider(void) : + super("Cavespider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) +{ +} + + + + + +void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + // TODO: Check vanilla if cavespiders really get passive during the day / in daylight + m_EMPersonality = (GetWorld()->GetTimeOfDay() < (12000 + 1000)) ? PASSIVE : AGGRESSIVE; +} + + + + + +void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } +} + + + + diff --git a/src/Mobs/CaveSpider.h b/src/Mobs/CaveSpider.h new file mode 100644 index 000000000..c2aacd2c7 --- /dev/null +++ b/src/Mobs/CaveSpider.h @@ -0,0 +1,25 @@ +#pragma once + +#include "AggressiveMonster.h" + + + + + +class cCavespider : + public cAggressiveMonster +{ + typedef cAggressiveMonster super; + +public: + cCavespider(void); + + CLASS_PROTODEF(cCaveSpider); + + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; +} ; + + + + diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp deleted file mode 100644 index 94e93283d..000000000 --- a/src/Mobs/Cavespider.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Cavespider.h" -#include "../World.h" - - - - - -cCavespider::cCavespider(void) : - super("Cavespider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) -{ -} - - - - - -void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - - // TODO: Check vanilla if cavespiders really get passive during the day / in daylight - m_EMPersonality = (GetWorld()->GetTimeOfDay() < (12000 + 1000)) ? PASSIVE : AGGRESSIVE; -} - - - - - -void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - int LootingLevel = 0; - if (a_Killer != NULL) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) - { - AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); - } -} - - - - diff --git a/src/Mobs/Cavespider.h b/src/Mobs/Cavespider.h deleted file mode 100644 index 10ea03f7b..000000000 --- a/src/Mobs/Cavespider.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "AggressiveMonster.h" - - - - - -class cCavespider : - public cAggressiveMonster -{ - typedef cAggressiveMonster super; - -public: - cCavespider(void); - - CLASS_PROTODEF(cCaveSpider); - - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; -} ; - - - - diff --git a/src/Mobs/MagmaCube.cpp b/src/Mobs/MagmaCube.cpp new file mode 100644 index 000000000..064152072 --- /dev/null +++ b/src/Mobs/MagmaCube.cpp @@ -0,0 +1,30 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Magmacube.h" + + + + + +cMagmaCube::cMagmaCube(int a_Size) : + super("MagmaCube", mtMagmaCube, "mob.MagmaCube.big", "mob.MagmaCube.big", 0.6 * a_Size, 0.6 * a_Size), + m_Size(a_Size) +{ +} + + + + + +void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + UNUSED(a_Killer); + if (GetSize() > 1) + { + AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); + } +} + + + + diff --git a/src/Mobs/MagmaCube.h b/src/Mobs/MagmaCube.h new file mode 100644 index 000000000..43065cae5 --- /dev/null +++ b/src/Mobs/MagmaCube.h @@ -0,0 +1,31 @@ +#pragma once + +#include "AggressiveMonster.h" + + + + + +class cMagmaCube : + public cAggressiveMonster +{ + typedef cAggressiveMonster super; + +public: + /// Creates a MagmaCube of the specified size; size is 1 .. 3, with 1 being the smallest + cMagmaCube(int a_Size); + + CLASS_PROTODEF(cMagmaCube); + + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + int GetSize(void) const { return m_Size; } + +protected: + + /// Size of the MagmaCube, 1 .. 3, with 1 being the smallest + int m_Size; +} ; + + + + diff --git a/src/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp deleted file mode 100644 index 05405f082..000000000 --- a/src/Mobs/Magmacube.cpp +++ /dev/null @@ -1,31 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Magmacube.h" - - - - - -cMagmaCube::cMagmaCube(int a_Size) : - super("MagmaCube", mtMagmaCube, "mob.MagmaCube.big", "mob.MagmaCube.big", 0.6 * a_Size, 0.6 * a_Size), - m_Size(a_Size) -{ -} - - - - - -void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - UNUSED(a_Killer); - if (GetSize() > 1) - { - AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); - } -} - - - - diff --git a/src/Mobs/Magmacube.h b/src/Mobs/Magmacube.h deleted file mode 100644 index 130952970..000000000 --- a/src/Mobs/Magmacube.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -#include "AggressiveMonster.h" - - - - - -class cMagmaCube : - public cAggressiveMonster -{ - typedef cAggressiveMonster super; - -public: - /// Creates a MagmaCube of the specified size; size is 1 .. 3, with 1 being the smallest - cMagmaCube(int a_Size); - - CLASS_PROTODEF(cMagmaCube); - - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - int GetSize(void) const { return m_Size; } - -protected: - - /// Size of the MagmaCube, 1 .. 3, with 1 being the smallest - int m_Size; -} ; - - - - diff --git a/src/Mobs/ZombiePigman.cpp b/src/Mobs/ZombiePigman.cpp new file mode 100644 index 000000000..b6f95a3e1 --- /dev/null +++ b/src/Mobs/ZombiePigman.cpp @@ -0,0 +1,53 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Zombiepigman.h" +#include "../World.h" + + + + + +cZombiePigman::cZombiePigman(void) : + super("ZombiePigman", mtZombiePigman, "mob.zombiepig.zpighurt", "mob.zombiepig.zpigdeath", 0.6, 1.8) +{ +} + + + + + +void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); + + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_GOLD)); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); +} + + + + + +void cZombiePigman::KilledBy(cEntity * a_Killer) +{ + super::KilledBy(a_Killer); + + if ((a_Killer != NULL) && (a_Killer->IsPlayer())) + { + // TODO: Anger all nearby zombie pigmen + // TODO: In vanilla, if one player angers ZPs, do they attack any nearby player, or only that one attacker? + } +} + + + + diff --git a/src/Mobs/ZombiePigman.h b/src/Mobs/ZombiePigman.h new file mode 100644 index 000000000..ab3cebf6d --- /dev/null +++ b/src/Mobs/ZombiePigman.h @@ -0,0 +1,25 @@ +#pragma once + +#include "PassiveAggressiveMonster.h" + + + + + +class cZombiePigman : + public cPassiveAggressiveMonster +{ + typedef cPassiveAggressiveMonster super; + +public: + cZombiePigman(void); + + CLASS_PROTODEF(cZombiePigman); + + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void KilledBy(cEntity * a_Killer) override; +} ; + + + + diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp deleted file mode 100644 index a0142b566..000000000 --- a/src/Mobs/Zombiepigman.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Zombiepigman.h" -#include "../World.h" - - - - - -cZombiePigman::cZombiePigman(void) : - super("ZombiePigman", mtZombiePigman, "mob.zombiepig.zpighurt", "mob.zombiepig.zpigdeath", 0.6, 1.8) -{ -} - - - - - -void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - int LootingLevel = 0; - if (a_Killer != NULL) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); - AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); - - cItems RareDrops; - RareDrops.Add(cItem(E_ITEM_GOLD)); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); - AddRandomArmorDropItem(a_Drops, LootingLevel); - AddRandomWeaponDropItem(a_Drops, LootingLevel); -} - - - - - -void cZombiePigman::KilledBy(cEntity * a_Killer) -{ - super::KilledBy(a_Killer); - - if ((a_Killer != NULL) && (a_Killer->IsPlayer())) - { - // TODO: Anger all nearby zombie pigmen - // TODO: In vanilla, if one player angers ZPs, do they attack any nearby player, or only that one attacker? - } -} - - - - diff --git a/src/Mobs/Zombiepigman.h b/src/Mobs/Zombiepigman.h deleted file mode 100644 index 67991d56a..000000000 --- a/src/Mobs/Zombiepigman.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "PassiveAggressiveMonster.h" - - - - - -class cZombiePigman : - public cPassiveAggressiveMonster -{ - typedef cPassiveAggressiveMonster super; - -public: - cZombiePigman(void); - - CLASS_PROTODEF(cZombiePigman); - - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - virtual void KilledBy(cEntity * a_Killer) override; -} ; - - - - -- cgit v1.2.3 From 06819595b0a5366711bb4aa156a2198650e5c0ff Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 23 Apr 2014 15:25:10 -0700 Subject: Fixed references to renamed files. --- src/Mobs/CaveSpider.cpp | 4 ++-- src/Mobs/IncludeAllMonsters.h | 6 +++--- src/Mobs/MagmaCube.cpp | 2 +- src/Mobs/ZombiePigman.cpp | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index 4660ae44d..8e35102a4 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -1,6 +1,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "Cavespider.h" +#include "CaveSpider.h" #include "../World.h" @@ -8,7 +8,7 @@ cCavespider::cCavespider(void) : - super("Cavespider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) + super("CaveSpider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) { } diff --git a/src/Mobs/IncludeAllMonsters.h b/src/Mobs/IncludeAllMonsters.h index 1b436a11f..3460db993 100644 --- a/src/Mobs/IncludeAllMonsters.h +++ b/src/Mobs/IncludeAllMonsters.h @@ -1,6 +1,6 @@ #include "Bat.h" #include "Blaze.h" -#include "Cavespider.h" +#include "CaveSpider.h" #include "Chicken.h" #include "Cow.h" #include "Creeper.h" @@ -10,7 +10,7 @@ #include "Giant.h" #include "Horse.h" #include "IronGolem.h" -#include "Magmacube.h" +#include "MagmaCube.h" #include "Mooshroom.h" #include "Ocelot.h" #include "Pig.h" @@ -26,4 +26,4 @@ #include "Wither.h" #include "Wolf.h" #include "Zombie.h" -#include "Zombiepigman.h" +#include "ZombiePigman.h" diff --git a/src/Mobs/MagmaCube.cpp b/src/Mobs/MagmaCube.cpp index 064152072..3e9abc108 100644 --- a/src/Mobs/MagmaCube.cpp +++ b/src/Mobs/MagmaCube.cpp @@ -1,6 +1,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "Magmacube.h" +#include "MagmaCube.h" diff --git a/src/Mobs/ZombiePigman.cpp b/src/Mobs/ZombiePigman.cpp index b6f95a3e1..c9d94face 100644 --- a/src/Mobs/ZombiePigman.cpp +++ b/src/Mobs/ZombiePigman.cpp @@ -1,6 +1,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "Zombiepigman.h" +#include "ZombiePigman.h" #include "../World.h" diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 415693ae2..b6c14db9c 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -39,7 +39,7 @@ #include "../Mobs/Creeper.h" #include "../Mobs/Enderman.h" #include "../Mobs/Horse.h" -#include "../Mobs/Magmacube.h" +#include "../Mobs/MagmaCube.h" #include "../Mobs/Sheep.h" #include "../Mobs/Slime.h" #include "../Mobs/Skeleton.h" -- cgit v1.2.3 From 9cbb3a339f98f1737ea78af7f40e1ae7d25027e8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 20:41:25 +0200 Subject: Fix armor in survival mode. --- src/ClientHandle.cpp | 2 +- src/Items/ItemArmor.h | 54 ++++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 7 +++++ src/Items/ItemHandler.h | 30 +++++++++---------- src/UI/SlotArea.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 7 ++++- 6 files changed, 157 insertions(+), 17 deletions(-) create mode 100644 src/Items/ItemArmor.h (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0f26d41e7..63ae98be4 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1037,7 +1037,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e { HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } - else if (ItemHandler->IsFood()) + else if (ItemHandler->IsFood() && !m_Player->IsGameModeCreative()) { if (m_Player->IsSatiated()) { diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h new file mode 100644 index 000000000..0f40ac443 --- /dev/null +++ b/src/Items/ItemArmor.h @@ -0,0 +1,54 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemArmorHandler : + public cItemHandler +{ +public: + cItemArmorHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + int SlotNum = -1; + if (ItemCategory::IsHelmet(a_Item.m_ItemType)) + { + SlotNum = 0; + } + else if (ItemCategory::IsChestPlate(a_Item.m_ItemType)) + { + SlotNum = 1; + } + else if (ItemCategory::IsLeggings(a_Item.m_ItemType)) + { + SlotNum = 2; + } + else if (ItemCategory::IsBoots(a_Item.m_ItemType)) + { + SlotNum = 3; + } + + if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty()) + { + return false; + } + + a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne()); + a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), cItem()); + return true; + } + +} ; + + + + diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 5151eac38..2cb1471aa 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -8,6 +8,7 @@ #include "../BlockInServerPluginInterface.h" // Handlers: +#include "ItemArmor.h" #include "ItemBed.h" #include "ItemBoat.h" #include "ItemBow.h" @@ -90,6 +91,12 @@ cItemHandler * cItemHandler::GetItemHandler(int a_ItemType) cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { + // Armor + if (ItemCategory::IsArmor(a_ItemType)) + { + return new cItemArmorHandler(a_ItemType); + } + switch(a_ItemType) { default: return new cItemHandler(a_ItemType); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index f3d78335e..4993eac85 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -21,13 +21,13 @@ class cItemHandler public: cItemHandler(int a_ItemType); - // Force virtual destructor + /** Force virtual destructor */ virtual ~cItemHandler() {} - /// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False + /** Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False */ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir); - /// Called when the client sends the SHOOT status in the lclk packet + /** Called when the client sends the SHOOT status in the lclk packet */ virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) { UNUSED(a_BlockX); @@ -36,7 +36,7 @@ public: UNUSED(a_BlockFace); } - /// Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items + /** Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items */ virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) { UNUSED(a_World); @@ -44,16 +44,16 @@ public: UNUSED(a_Item); } - /// Called while the player diggs a block using this item + /** Called while the player diggs a block using this item */ virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace); - /// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block + /** Called when the player destroys a block using this item. This also calls the drop function for the destroyed block */ virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z); - /// Called after the player has eaten this item. + /** Called after the player has eaten this item. */ virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item); - /// Returns the maximum stack size for a given item + /** Returns the maximum stack size for a given item */ virtual char GetMaxStackSize(void); struct FoodInfo @@ -70,22 +70,22 @@ public: } } ; - /// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) + /** Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) */ virtual FoodInfo GetFoodInfo(); - /// Lets the player eat a selected item. Returns true if the player ate the item + /** Lets the player eat a selected item. Returns true if the player ate the item */ virtual bool EatItem(cPlayer *a_Player, cItem *a_Item); - /// Indicates if this item is a tool + /** Indicates if this item is a tool */ virtual bool IsTool(void); - /// Indicates if this item is food + /** Indicates if this item is food */ virtual bool IsFood(void); - /// Blocks simply get placed + /** Blocks simply get placed */ virtual bool IsPlaceable(void); - /** Called before a block is placed into a world. + /** Called before a block is placed into a world. The handler should return true to allow placement, false to refuse. Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block. */ @@ -96,7 +96,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ); - /// Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can´t) DEFAULT: False + /** Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can�t) DEFAULT: False */ virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType); static cItemHandler * GetItemHandler(int a_ItemType); diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 2d58388b1..ef4cf17cd 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1091,6 +1091,80 @@ void cSlotAreaArmor::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo +void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + + //Armors haven't a dbl click + if (a_ClickAction == caDblClick) + { + return; + } + + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + if (!Slot.IsSameType(a_ClickedItem)) + { + LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); + LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); + LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); + bAsync = true; + } + cItem & DraggingItem = a_Player.GetDraggingItem(); + if ((a_ClickAction != caRightClick) && (a_ClickAction != caLeftClick)) + { + LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); + m_ParentWindow.BroadcastWholeWindow(); + return; + } + + if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem)) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } +} + + + + + +bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item) +{ + switch (a_SlotNum) + { + case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType); + case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType); + case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType); + case 3: return ItemCategory::IsBoots (a_Item.m_ItemType); + } + return false; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaItemGrid: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index bab1098bb..254722822 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -145,8 +145,13 @@ public: { } - // Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.) + /** Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.) */ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + + /** Called when a player clicks in the window. Parameters taken from the click packet. */ + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + + bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item); } ; -- cgit v1.2.3 From 8fc45c57307203a86352bdd7a788fb20cff797ff Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 12:00:27 -0700 Subject: Fixed class capitalization for the cave spider. --- src/Mobs/CaveSpider.cpp | 6 +++--- src/Mobs/CaveSpider.h | 4 ++-- src/Mobs/Monster.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index 8e35102a4..56ecd2d28 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -7,7 +7,7 @@ -cCavespider::cCavespider(void) : +cCaveSpider::cCaveSpider(void) : super("CaveSpider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) { } @@ -16,7 +16,7 @@ cCavespider::cCavespider(void) : -void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) +void cCaveSpider::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); @@ -28,7 +28,7 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) -void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) +void cCaveSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { int LootingLevel = 0; if (a_Killer != NULL) diff --git a/src/Mobs/CaveSpider.h b/src/Mobs/CaveSpider.h index c2aacd2c7..be9f174f9 100644 --- a/src/Mobs/CaveSpider.h +++ b/src/Mobs/CaveSpider.h @@ -6,13 +6,13 @@ -class cCavespider : +class cCaveSpider : public cAggressiveMonster { typedef cAggressiveMonster super; public: - cCavespider(void); + cCaveSpider(void); CLASS_PROTODEF(cCaveSpider); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 248e88f5d..eb8480268 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -859,7 +859,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) case mtBat: toReturn = new cBat(); break; case mtBlaze: toReturn = new cBlaze(); break; - case mtCaveSpider: toReturn = new cCavespider(); break; + case mtCaveSpider: toReturn = new cCaveSpider(); break; case mtChicken: toReturn = new cChicken(); break; case mtCow: toReturn = new cCow(); break; case mtCreeper: toReturn = new cCreeper(); break; diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 48934d074..66144dbd5 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1757,7 +1757,7 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - std::auto_ptr Monster(new cCavespider()); + std::auto_ptr Monster(new cCaveSpider()); if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) { return; -- cgit v1.2.3 From ffce8d6907b8b93a2764a67766a40901bcad0835 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:49:56 +0100 Subject: Implemented suggestions --- src/Chunk.cpp | 28 +++++---------------- src/ChunkDef.h | 77 ++++++++-------------------------------------------------- 2 files changed, 16 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ee1531b5c..6c35f7f47 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,16 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) + int IdxWhereNonEmptyStarts = 0; { // Compress blocklight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockLight.clear(); for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { if (a_BlockLight[Idx] != 0) { - FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } @@ -396,19 +394,7 @@ void cChunk::SetLight( } { // Compress skylight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockSkyLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_SkyLight[Idx] != 0xff) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); } @@ -421,10 +407,8 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - std::vector Blocks = m_BlockTypes; - Blocks.resize(NumBlocks); - - memcpy(a_BlockTypes, &Blocks[0], NumBlocks); + std::copy(m_BlockTypes.begin(), m_BlockTypes.end(), a_BlockTypes); + std::fill_n(&a_BlockTypes[m_BlockTypes.size()], NumBlocks - m_BlockTypes.size(), E_BLOCK_AIR); } @@ -832,7 +816,7 @@ void cChunk::BroadcastPendingBlockChanges(void) void cChunk::CheckBlocks() { - if (m_ToTickBlocks.size() == 0) + if (m_ToTickBlocks.empty()) { return; } @@ -1605,7 +1589,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) { m_BlockTypes.resize(index + 1); } @@ -2550,7 +2534,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) { return E_BLOCK_AIR; } diff --git a/src/ChunkDef.h b/src/ChunkDef.h index bb9f14bbe..1b3dd3ee0 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -219,24 +219,13 @@ public: ASSERT((a_Z >= 0) && (a_Z <= Width)); a_BiomeMap[a_X + Width * a_Z] = a_Biome; } - - - static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int a_BlockIdx) - { - if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) - { - return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f; - } - ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); - return 0; - } static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false) { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { - if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())) { return (a_IsSkyLightNibble ? 0xff : 0); } @@ -245,18 +234,6 @@ public: ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); return 0; } - - - static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z) - { - if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) - { - int Index = MakeIndexNoCheck(x, y, z); - return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; - } - ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); - return 0; - } static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false) @@ -264,7 +241,7 @@ public: if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size())) { return (a_IsSkyLightNibble ? 0xff : 0); } @@ -275,17 +252,15 @@ public: } - static void SetNibble(NIBBLETYPE * a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble) + static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z) { - if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks)) + if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - ASSERT(!"cChunkDef::SetNibble(): index out of range!"); - return; + int Index = MakeIndexNoCheck(x, y, z); + return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } - a_Buffer[a_BlockIdx / 2] = static_cast( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set - ); + ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); + return 0; } @@ -296,7 +271,7 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())) { a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1)); } @@ -305,26 +280,6 @@ public: ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } - - - static void SetNibble(NIBBLETYPE * a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) - { - if ( - (x >= Width) || (x < 0) || - (y >= Height) || (y < 0) || - (z >= Width) || (z < 0) - ) - { - ASSERT(!"cChunkDef::SetNibble(): index out of range!"); - return; - } - - int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = static_cast( - (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set - ); - } static void SetNibble(std::vector & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) @@ -340,7 +295,7 @@ public: } int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1)) + if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size())) { a_Buffer.resize((size_t)((Index / 2) + 1)); } @@ -350,18 +305,6 @@ public: ); } - - inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos) - { - return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); - } - - - inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value) - { - SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); - } - } ; -- cgit v1.2.3 From acbd4e6503a8da6645c97dbe010eed7f37386194 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:52:01 +0100 Subject: Another small speed improvement? --- src/Chunk.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6c35f7f47..7af1820d2 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,24 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) - int IdxWhereNonEmptyStarts = 0; { // Compress blocklight m_BlockLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockLight[Idx] != 0) - { - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[m_BlockTypes.size()]); } { // Compress skylight m_BlockSkyLight.clear(); - m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[m_BlockTypes.size()]); } m_IsLightValid = true; -- cgit v1.2.3 From 376dc880b37e1b104c86efebef0f294c34ca3c42 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 23:03:04 +0200 Subject: Add armor to switch() in ItemHandler.cpp --- src/Items/ItemHandler.cpp | 31 +++++++++++++++++++++++++------ src/UI/SlotArea.cpp | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 2cb1471aa..ce9593a70 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -91,12 +91,6 @@ cItemHandler * cItemHandler::GetItemHandler(int a_ItemType) cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { - // Armor - if (ItemCategory::IsArmor(a_ItemType)) - { - return new cItemArmorHandler(a_ItemType); - } - switch(a_ItemType) { default: return new cItemHandler(a_ItemType); @@ -229,6 +223,31 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { return new cItemFoodHandler(a_ItemType); } + + // Armor: + case E_ITEM_LEATHER_CAP: + case E_ITEM_GOLD_HELMET: + case E_ITEM_CHAIN_HELMET: + case E_ITEM_IRON_HELMET: + case E_ITEM_DIAMOND_HELMET: + case E_ITEM_LEATHER_TUNIC: + case E_ITEM_GOLD_CHESTPLATE: + case E_ITEM_CHAIN_CHESTPLATE: + case E_ITEM_IRON_CHESTPLATE: + case E_ITEM_DIAMOND_CHESTPLATE: + case E_ITEM_LEATHER_PANTS: + case E_ITEM_GOLD_LEGGINGS: + case E_ITEM_CHAIN_LEGGINGS: + case E_ITEM_IRON_LEGGINGS: + case E_ITEM_DIAMOND_LEGGINGS: + case E_ITEM_LEATHER_BOOTS: + case E_ITEM_GOLD_BOOTS: + case E_ITEM_CHAIN_BOOTS: + case E_ITEM_IRON_BOOTS: + case E_ITEM_DIAMOND_BOOTS: + { + return new cItemArmorHandler(a_ItemType); + } } } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index ef4cf17cd..87b4032e0 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1108,7 +1108,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C return; } - //Armors haven't a dbl click + // Armors haven't a dbl click if (a_ClickAction == caDblClick) { return; -- cgit v1.2.3 From 3397f9faec43ac288fa9e7f1f555a1309a4e47a5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 22:07:20 +0100 Subject: Fixed indent --- src/Chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7af1820d2..97a8ba88b 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -282,7 +282,7 @@ void cChunk::SetAllData( const HeightMap * a_HeightMap, const BiomeMap & a_BiomeMap, cBlockEntityList & a_BlockEntities - ) +) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); -- cgit v1.2.3 From cee70390fae9c240337186e50445e50518ccdba8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 25 Apr 2014 00:09:22 +0200 Subject: Add unkown armor warning and fix armor stacks. --- src/Items/ItemArmor.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index 0f40ac443..a786990fc 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -19,7 +19,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - int SlotNum = -1; + int SlotNum; if (ItemCategory::IsHelmet(a_Item.m_ItemType)) { SlotNum = 0; @@ -36,6 +36,11 @@ public: { SlotNum = 3; } + else + { + LOGWARNING("Used unknown armor: %i", a_Item.m_ItemType); + return false; + } if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty()) { @@ -43,7 +48,14 @@ public: } a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne()); - a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), cItem()); + + cItem Item(a_Item); + Item.m_ItemCount--; + if (Item.m_ItemCount <= 0) + { + Item.Empty(); + } + a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), Item); return true; } -- cgit v1.2.3 From ccd9023202e2a9f97780fd96438c024a83618052 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 25 Apr 2014 00:10:52 +0200 Subject: Add commit what the code is doing. --- src/Items/ItemArmor.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index a786990fc..08cddb1ad 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -17,6 +17,7 @@ public: { } + /** Move the armor to the armor slot of the player's inventory */ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { int SlotNum; -- cgit v1.2.3 From b008ba5d982542d8a2857544af1aa88a41cf7b13 Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 17:24:39 -0700 Subject: Refactored SendChat(), placing the message-type formatting into its own function. Removed default case warning in the process. --- src/ClientHandle.cpp | 162 +++++++++++++++++++++++++-------------------------- src/ClientHandle.h | 3 + 2 files changed, 81 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0f26d41e7..6ff944c01 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -186,6 +186,82 @@ void cClientHandle::GenerateOfflineUUID(void) +AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData) +{ + switch (a_ChatPrefix) + { + case mtCustom: return AString(); + case mtFailure: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtInformation: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtSuccess: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Green.c_str()); + } + case mtWarning: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtFatal: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Red.c_str()); + } + case mtDeath: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Gray.c_str()); + } + case mtPrivateMessage: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + else + return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); + } + case mtJoin: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtLeave: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + } + ASSERT(!"Unhandled chat prefix type!"); +} + + + + + AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) { // Proper format for a version 3 UUID is: @@ -1848,8 +1924,6 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { - bool ShouldAppendChatPrefixes = true; - if (GetPlayer()->GetWorld() == NULL) { cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); @@ -1868,89 +1942,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi ShouldAppendChatPrefixes = false; } - AString Message; - - switch (a_ChatPrefix) - { - case mtCustom: break; - case mtFailure: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtInformation: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtSuccess: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Green.c_str()); - break; - } - case mtWarning: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtFatal: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Red.c_str()); - break; - } - case mtDeath: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Gray.c_str()); - break; - } - case mtPrivateMessage: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); - else - Message = Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); - break; - } - case mtJoin: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtLeave: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - default: ASSERT(!"Unhandled chat prefix type!"); return; - } - - Message.append(a_Message); + AString Message = FormatMessageType(ShouldAppendChatPrefixes, a_ChatPrefix, a_AdditionalData); - m_Protocol->SendChat(Message); + m_Protocol->SendChat(Message.append(a_Message)); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 3d01d8034..e2b44ce8a 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -77,6 +77,9 @@ public: This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */ static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export + + // Formats the type of message with the proper color and prefix for sending to the client. + AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData); void Kick(const AString & a_Reason); // tolua_export void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication -- cgit v1.2.3 From 624deea6c4f83f296c1bd1597e76b4704ffa4a9a Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 18:11:11 -0700 Subject: Giants! Changed mfMaxplusone to mfUnhandled for readability, and fixed a default case warning. --- src/Mobs/Monster.cpp | 17 +++++++++++------ src/Mobs/Monster.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index eb8480268..f68d2ef75 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -763,6 +763,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtCreeper: return mfHostile; case mtEnderman: return mfHostile; case mtGhast: return mfHostile; + case mtGiant: return mfHostile; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -781,9 +782,11 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtWolf: return mfHostile; case mtZombie: return mfHostile; case mtZombiePigman: return mfHostile; - } ; + + case mtInvalidType: break; + } ASSERT(!"Unhandled mob type"); - return mfMaxplusone; + return mfUnhandled; } @@ -794,10 +797,11 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) { switch (a_MobFamily) { - case mfHostile: return 40; - case mfPassive: return 40; - case mfAmbient: return 40; - case mfWater: return 400; + case mfHostile: return 40; + case mfPassive: return 40; + case mfAmbient: return 40; + case mfWater: return 400; + case mfUnhandled: break; } ASSERT(!"Unhandled mob family"); return -1; @@ -866,6 +870,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) case mtEnderDragon: toReturn = new cEnderDragon(); break; case mtEnderman: toReturn = new cEnderman(); break; case mtGhast: toReturn = new cGhast(); break; + case mtGiant: toReturn = new cGiant(); break; case mtIronGolem: toReturn = new cIronGolem(); break; case mtMooshroom: toReturn = new cMooshroom(); break; case mtOcelot: toReturn = new cOcelot(); break; diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 70b3783fc..0243f6637 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,7 +66,7 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid - mfMaxplusone, // Nothing. Be sure this is the last and the others are in order + mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; // tolua_end -- cgit v1.2.3 From 0f7bd9fc7717578d1dcfe7e110adbca6c23da7b3 Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 19:14:00 -0700 Subject: Oops, fixed that. --- src/ClientHandle.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6ff944c01..d7520f969 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1924,6 +1924,8 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { + bool ShouldAppendChatPrefixes = true; + if (GetPlayer()->GetWorld() == NULL) { cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); -- cgit v1.2.3 From ec9787bae21f92251a38338ae5823aa851c5efea Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 19:16:16 -0700 Subject: Chicken eggs and ender pearls can hit entities. Fixed warning by adding dedicated m_HasTeleported for fired arrows. --- src/Entities/ProjectileEntity.cpp | 62 +++++++++++++++++++++++++++++++++++---- src/Entities/ProjectileEntity.h | 11 ++++++- 2 files changed, 66 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 96db17ffd..2725822f3 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -562,12 +562,12 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position - if (m_HitGroundTimer != -1) // Sent a teleport already, don't do again + if (!m_HasTeleported) // Sent a teleport already, don't do again { if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case { m_World->BroadcastTeleportEntity(*this); - m_HitGroundTimer = -1; + m_HasTeleported = true; } else { @@ -610,6 +610,32 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TryForChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TryForChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { @@ -622,7 +648,6 @@ void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); } - Destroy(); } @@ -643,16 +668,40 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportUser(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportUser(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) { - // TODO: The coords might need some tweaking based on the block face m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); } - - Destroy(); } @@ -696,6 +745,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & TotalDamage = 1; } } + // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index efb7ae783..002aa09a1 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -166,6 +166,9 @@ protected: /// Timer for client arrow position confirmation via TeleportEntity float m_HitGroundTimer; + + // Whether the arrow has already been teleported into the proper position in the ground. + bool m_HasTeleported; /// If true, the arrow is in the process of being collected - don't go to anyone else bool m_bIsCollected; @@ -205,7 +208,10 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + void TryForChicken(const Vector3d & a_HitPos); + // tolua_begin } ; @@ -233,6 +239,9 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 62e5234535d1825b152c882fdaea9d2257194e6d Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 20:25:03 -0700 Subject: Small changes; warning fixing. --- src/ByteBuffer.cpp | 2 +- src/ByteBuffer.h | 2 +- src/MCLogger.cpp | 4 ++-- src/MCLogger.h | 1 + src/World.cpp | 9 +++------ src/WorldStorage/NBTChunkSerializer.cpp | 8 ++++---- 6 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 1893d89a8..c634dc308 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -143,7 +143,7 @@ protected: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cByteBuffer: -cByteBuffer::cByteBuffer(int a_BufferSize) : +cByteBuffer::cByteBuffer(size_t a_BufferSize) : m_Buffer(new char[a_BufferSize + 1]), m_BufferSize(a_BufferSize + 1), #ifdef _DEBUG diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index 1915467f3..44f43e17f 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -27,7 +27,7 @@ their own synchronization. class cByteBuffer { public: - cByteBuffer(int a_BufferSize); + cByteBuffer(size_t a_BufferSize); ~cByteBuffer(); /// Writes the bytes specified to the ringbuffer. Returns true if successful, false if not diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 80fa7b173..ca47b29db 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -9,7 +9,6 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; -bool g_ShouldColorOutput = false; #ifdef _WIN32 #include // Needed for _isatty(), not available on Linux @@ -33,7 +32,8 @@ cMCLogger * cMCLogger::GetInstance(void) -cMCLogger::cMCLogger(void) +cMCLogger::cMCLogger(void): + g_ShouldColorOutput(false) { AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(NULL)); diff --git a/src/MCLogger.h b/src/MCLogger.h index c0150c124..34955ea16 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -52,6 +52,7 @@ private: cCriticalSection m_CriticalSection; cLog * m_Log; static cMCLogger * s_MCLogger; + bool g_ShouldColorOutput; /// Sets the specified color scheme in the terminal (TODO: if coloring available) diff --git a/src/World.cpp b/src/World.cpp index 25ac9b021..21cabe434 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -316,12 +316,9 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) { return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes } - default: - { - LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather); - return -1; - } - } // switch (Weather) + } + LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather); + return -1; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index b6c14db9c..27631eded 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -621,10 +621,10 @@ void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging) m_Writer.AddInt("TileZ", a_Hanging->GetTileZ()); switch (a_Hanging->GetDirection()) { - case 0: m_Writer.AddByte("Dir", (unsigned char)2); break; - case 1: m_Writer.AddByte("Dir", (unsigned char)1); break; - case 2: m_Writer.AddByte("Dir", (unsigned char)0); break; - case 3: m_Writer.AddByte("Dir", (unsigned char)3); break; + case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break; + case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break; + case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break; + case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break; } } -- cgit v1.2.3 From a72744f5c33ec11f33637839e4d6206c4aa2fa2a Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 10:08:36 +0400 Subject: Mobs shouldn't burn when it's Raining & Mob Knockback is far too much --- src/Entities/Entity.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c09317298..89275a418 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -342,13 +342,13 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) switch (KnockbackLevel) { case 1: - additionalSpeed.Set(5, .2, 5); + additionalSpeed.Set(5, .3, 5); break; case 2: - additionalSpeed.Set(8, .2, 8); + additionalSpeed.Set(8, .3, 8); break; default: - additionalSpeed.Set(2, .2, 2); + additionalSpeed.Set(2, .3, 2); break; } AddSpeed(a_TDI.Knockback * additionalSpeed); @@ -802,12 +802,9 @@ void cEntity::TickBurning(cChunk & a_Chunk) int PosY = POSY_TOINT; int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - if((POSY_TOINT - 1) == m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) + if (PosY > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { - if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) - { - m_TicksLeftBurning = 0; - } + m_TicksLeftBurning = 0; } } -- cgit v1.2.3 From 827c3760db5da766a99c42312aa95b43dded9436 Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 10:58:48 +0400 Subject: Fix for clang --- src/Entities/Entity.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 89275a418..402f94d08 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -798,11 +798,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) if (m_World->IsWeatherWet()) { - int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int PosY = POSY_TOINT; - int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - - if (PosY > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) + if (POSY_TOINT > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { m_TicksLeftBurning = 0; } -- cgit v1.2.3 From 4cd2d57c643ec2c7dab7a664248dbf65254c1b1d Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 12:06:22 +0400 Subject: Fix formatting --- src/Entities/Entity.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 402f94d08..d0dd6fb50 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -341,15 +341,21 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) Vector3d additionalSpeed(0, 0, 0); switch (KnockbackLevel) { - case 1: - additionalSpeed.Set(5, .3, 5); - break; - case 2: - additionalSpeed.Set(8, .3, 8); - break; - default: - additionalSpeed.Set(2, .3, 2); - break; + case 1: + { + additionalSpeed.Set(5, .3, 5); + break; + } + case 2: + { + additionalSpeed.Set(8, .3, 8); + break; + } + default: + { + additionalSpeed.Set(2, .3, 2); + break; + } } AddSpeed(a_TDI.Knockback * additionalSpeed); } -- cgit v1.2.3 From cb7f1ee4bbf726b5b57fe8d1960bb7d03dc1e87a Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:39:35 -0700 Subject: Rename spawn chicken method, Initialize m_HasTeleported. --- src/Entities/ProjectileEntity.cpp | 7 ++++--- src/Entities/ProjectileEntity.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 2725822f3..89b833abf 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -440,6 +440,7 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : m_IsCritical((a_Force >= 1)), m_Timer(0), m_HitGroundTimer(0), + m_HasTeleported(false), m_bIsCollected(false), m_HitBlockPos(0, 0, 0) { @@ -611,7 +612,7 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); Destroy(); } @@ -625,7 +626,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -635,7 +636,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit -void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 002aa09a1..90d44ed91 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,7 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - void TryForChicken(const Vector3d & a_HitPos); + void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 256691461bd9c4719e94d17942372ef8302a3607 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:49:18 -0700 Subject: Comments for TrySpawnChicken() and TeleportUser(). --- src/Entities/ProjectileEntity.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 90d44ed91..5aa489ff8 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,6 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin @@ -241,6 +242,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Teleports the user where the ender pearl lands. void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 8aa82d048d4506c963846d5c02650e1037e92992 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 06:26:08 -0700 Subject: Creator not user. --- src/Entities/ProjectileEntity.cpp | 6 +++--- src/Entities/ProjectileEntity.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 89b833abf..fd3e80e5f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -671,7 +671,7 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // TODO: Tweak a_HitPos based on block face. - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); Destroy(); } @@ -685,7 +685,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -695,7 +695,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d -void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 5aa489ff8..731dd060e 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -242,8 +242,8 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // Teleports the user where the ender pearl lands. - void TeleportUser(const Vector3d & a_HitPos); + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From e47dab84f3f6606d6d6e95774b16d7d4e8d7daa6 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 09:56:15 -0700 Subject: Cmake generated projects for IDEs include headers in project files. --- src/BlockEntities/CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/Entities/CMakeLists.txt | 1 + src/Generating/CMakeLists.txt | 1 + src/Generating/Prefabs/CMakeLists.txt | 1 + src/HTTPServer/CMakeLists.txt | 1 + src/Mobs/CMakeLists.txt | 1 + src/OSSupport/CMakeLists.txt | 1 + src/Protocol/CMakeLists.txt | 1 + src/Simulator/CMakeLists.txt | 1 + src/UI/CMakeLists.txt | 1 + src/WorldStorage/CMakeLists.txt | 1 + 12 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 920767f5c..3e3d17f86 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(BlockEntities ${SOURCE}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30e9dbfd4..9cc5fcb1e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -123,6 +123,7 @@ if (NOT MSVC) file(GLOB SOURCE "*.cpp" + "*.h" ) list(REMOVE_ITEM SOURCE "${PROJECT_SOURCE_DIR}/StackWalker.cpp" "${PROJECT_SOURCE_DIR}/LeakFinder.cpp") diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 85cc45494..c9ca44d38 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Entities ${SOURCE}) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 1147744c0..3dacb5066 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Generating ${SOURCE}) diff --git a/src/Generating/Prefabs/CMakeLists.txt b/src/Generating/Prefabs/CMakeLists.txt index 1e60447e7..a1f09112d 100644 --- a/src/Generating/Prefabs/CMakeLists.txt +++ b/src/Generating/Prefabs/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Generating_Prefabs ${SOURCE}) diff --git a/src/HTTPServer/CMakeLists.txt b/src/HTTPServer/CMakeLists.txt index 3badc669f..dc894368d 100644 --- a/src/HTTPServer/CMakeLists.txt +++ b/src/HTTPServer/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(HTTPServer ${SOURCE}) diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index 87fbfd2fc..53c265803 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Mobs ${SOURCE}) diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 497cd0ba3..dee60b450 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -5,6 +5,7 @@ project (MCServer) include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(OSSupport ${SOURCE}) diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 107b79627..849ec27ca 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Protocol ${SOURCE}) diff --git a/src/Simulator/CMakeLists.txt b/src/Simulator/CMakeLists.txt index 4f3f1ad0e..b2a29d45c 100644 --- a/src/Simulator/CMakeLists.txt +++ b/src/Simulator/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Simulator ${SOURCE}) diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index cef2a9f35..5b5b8cc18 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(UI ${SOURCE}) diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index 2c83c4662..2844f7fe5 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(WorldStorage ${SOURCE}) -- cgit v1.2.3 From 0e0c9d82483e01840faf7027fc01a998d5cf2f18 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 12:24:09 -0700 Subject: Missed these CMakeLists. --- src/Blocks/CMakeLists.txt | 1 + src/Items/CMakeLists.txt | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index 082ff41ac..4b8c745ad 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Blocks ${SOURCE}) diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index 44a9f594f..a6fe6ea70 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -4,4 +4,9 @@ project (MCServer) include_directories ("${PROJECT_SOURCE_DIR}/../") -add_library(Items ItemHandler) +file(GLOB SOURCE + "*.cpp" + "*.h" +) + +add_library(Items ${SOURCE}) -- cgit v1.2.3 From 05f52192c9389f0c28cc6d772f3625c9588273a1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 25 Apr 2014 21:22:43 +0100 Subject: Implemented comments --- src/Chunk.cpp | 12 +++++------ src/Chunk.h | 8 ++++---- src/ChunkDef.h | 65 +++++++++++++++++++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 97a8ba88b..652f56905 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -241,21 +241,21 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - std::vector Blocks = m_BlockTypes; + COMPRESSED_BLOCKTYPE Blocks = m_BlockTypes; Blocks.resize(NumBlocks); a_Callback.BlockTypes (&Blocks[0]); - std::vector Metas = m_BlockMeta; + COMPRESSED_NIBBLETYPE Metas = m_BlockMeta; Metas.resize(NumBlocks / 2); a_Callback.BlockMeta (&Metas[0]); a_Callback.LightIsValid (m_IsLightValid); - std::vector BlockLights = m_BlockLight; + COMPRESSED_NIBBLETYPE BlockLights = m_BlockLight; BlockLights.resize(NumBlocks / 2); a_Callback.BlockLight (&BlockLights[0]); - std::vector BlockSkyLights = m_BlockSkyLight; + COMPRESSED_NIBBLETYPE BlockSkyLights = m_BlockSkyLight; BlockSkyLights.resize(NumBlocks / 2, 0xff); a_Callback.BlockSkyLight(&BlockSkyLights[0]); @@ -1579,7 +1579,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) + if ((size_t)index >= m_BlockTypes.size()) { m_BlockTypes.resize(index + 1); } @@ -2524,7 +2524,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) + if ((size_t)a_BlockIdx >= m_BlockTypes.size()) { return E_BLOCK_AIR; } diff --git a/src/Chunk.h b/src/Chunk.h index 9100eec58..a9c9be861 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -421,10 +421,10 @@ private: cChunkMap * m_ChunkMap; // TODO: Make these pointers and don't allocate what isn't needed - std::vector m_BlockTypes; - std::vector m_BlockMeta; - std::vector m_BlockLight; - std::vector m_BlockSkyLight; + COMPRESSED_BLOCKTYPE m_BlockTypes; + COMPRESSED_NIBBLETYPE m_BlockMeta; + COMPRESSED_NIBBLETYPE m_BlockLight; + COMPRESSED_NIBBLETYPE m_BlockSkyLight; cChunkDef::HeightMap m_HeightMap; cChunkDef::BiomeMap m_BiomeMap; diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 1b3dd3ee0..054168bdd 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -77,13 +77,19 @@ public: idx = x + Width * z // Need to verify this with the protocol spec, currently unknown! */ typedef EMCSBiome BiomeMap[Width * Width]; - + /// The type used for block type operations and storage, AXIS_ORDER ordering typedef BLOCKTYPE BlockTypes[NumBlocks]; - + /// The type used for block data in nibble format, AXIS_ORDER ordering typedef NIBBLETYPE BlockNibbles[NumBlocks / 2]; + /** The storage wrapper used for compressed blockdata residing in RAMz */ + typedef std::vector COMPRESSED_BLOCKTYPE; + + /** The storage wrapper used for compressed nibbledata residing in RAMz */ + typedef std::vector COMPRESSED_NIBBLETYPE; + /// Converts absolute block coords into relative (chunk + block) coords: inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ ) @@ -221,11 +227,11 @@ public: } - static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false) + static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false) { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { - if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())) + if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()) { return (a_IsSkyLightNibble ? 0xff : 0); } @@ -236,16 +242,16 @@ public: } - static NIBBLETYPE GetNibble(const std::vector & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false) + static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false) { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size())) + if ((size_t)(Index / 2) >= a_Buffer.size()) { return (a_IsSkyLightNibble ? 0xff : 0); } - return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; + return ExpandNibble(a_Buffer, Index); } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); return 0; @@ -257,54 +263,67 @@ public: if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { int Index = MakeIndexNoCheck(x, y, z); - return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); return 0; } - static void SetNibble(std::vector & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble) + static void SetNibble(COMPRESSED_NIBBLETYPE & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble) { if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks)) { ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())) + if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()) { a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1)); } - a_Buffer[(size_t)(a_BlockIdx / 2)] = static_cast( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set - ); + a_Buffer[(size_t)(a_BlockIdx / 2)] = PackNibble(a_Buffer, a_BlockIdx, a_Nibble); } - static void SetNibble(std::vector & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) + static void SetNibble(COMPRESSED_NIBBLETYPE & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble) { if ( - (x >= Width) || (x < 0) || + (x >= Width) || (x < 0) || (y >= Height) || (y < 0) || - (z >= Width) || (z < 0) - ) + (z >= Width) || (z < 0) + ) { ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } int Index = MakeIndexNoCheck(x, y, z); - if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size())) + if ((size_t)(Index / 2) >= a_Buffer.size()) { a_Buffer.resize((size_t)((Index / 2) + 1)); } - a_Buffer[(size_t)(Index / 2)] = static_cast( - (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set - ); + a_Buffer[(size_t)(Index / 2)] = PackNibble(a_Buffer, Index, a_Nibble); + } + + +private: + + + inline static NIBBLETYPE PackNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int a_Index, NIBBLETYPE a_Nibble) + { + return static_cast( + (a_Buffer[a_Index / 2] & (0xf0 >> ((a_Index & 1) * 4))) | // The untouched nibble + ((a_Nibble & 0x0f) << ((a_Index & 1) * 4)) // The nibble being set + ); } + + inline static NIBBLETYPE ExpandNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int a_Index) + { + return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f; + } + + } ; -- cgit v1.2.3 From 03402efc499e3167f3762d4a85c24178d8cf5252 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 25 Apr 2014 23:39:10 +0200 Subject: Should fix CIDs 43631, 43632 and 43633 --- src/Noise.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Noise.cpp b/src/Noise.cpp index efbb128c3..95a022ea3 100644 --- a/src/Noise.cpp +++ b/src/Noise.cpp @@ -744,6 +744,8 @@ void cCubicNoise::CalcFloorFrac( int * a_Same, int & a_NumSame ) const { + ASSERT(a_Size > 0); + NOISE_DATATYPE val = a_Start; NOISE_DATATYPE dif = (a_End - a_Start) / (a_Size - 1); for (int i = 0; i < a_Size; i++) -- cgit v1.2.3 From 7e76f030aa2e6d39ac7fe9fb6a8a3db44bf3dd5f Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:32:30 +0200 Subject: Add entity invulnerable --- src/Entities/Boat.cpp | 8 ++++++-- src/Entities/Boat.h | 2 +- src/Entities/Entity.cpp | 21 ++++++++++++++++++--- src/Entities/Entity.h | 17 +++++++++++++---- src/Entities/Minecart.cpp | 14 +++++++++----- src/Entities/Minecart.h | 2 +- src/Entities/Player.cpp | 21 ++++++++++++--------- src/Entities/Player.h | 2 +- src/Mobs/Creeper.cpp | 8 ++++++-- src/Mobs/Creeper.h | 2 +- src/Mobs/Monster.cpp | 8 ++++++-- src/Mobs/Monster.h | 2 +- src/Mobs/PassiveAggressiveMonster.cpp | 8 ++++++-- src/Mobs/PassiveAggressiveMonster.h | 2 +- src/Mobs/PassiveMonster.cpp | 8 ++++++-- src/Mobs/PassiveMonster.h | 2 +- src/Mobs/Villager.cpp | 9 +++++++-- src/Mobs/Villager.h | 2 +- src/Mobs/Wither.cpp | 10 +++++----- src/Mobs/Wither.h | 2 +- src/Mobs/Wolf.cpp | 9 +++++++-- src/Mobs/Wolf.h | 2 +- 22 files changed, 111 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 921252253..31bfe3dc3 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -33,9 +33,12 @@ void cBoat::SpawnOn(cClientHandle & a_ClientHandle) -void cBoat::DoTakeDamage(TakeDamageInfo & TDI) +bool cBoat::DoTakeDamage(TakeDamageInfo & TDI) { - super::DoTakeDamage(TDI); + if (!super::DoTakeDamage(TDI)) + { + return false; + } if (GetHealth() == 0) { @@ -50,6 +53,7 @@ void cBoat::DoTakeDamage(TakeDamageInfo & TDI) } Destroy(true); } + return true; } diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h index c4c9afe7a..0fcfbd602 100644 --- a/src/Entities/Boat.h +++ b/src/Entities/Boat.h @@ -26,7 +26,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6da6da54e..4403ab161 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -60,6 +60,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) + , m_InvulnerableTicks(20) { cCSLock Lock(m_CSCount); m_EntityCount++; @@ -294,17 +295,23 @@ void cEntity::SetPitchFromSpeed(void) -void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { if (cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*this, a_TDI)) { - return; + return false; } if (m_Health <= 0) { // Can't take damage if already dead - return; + return false; + } + + if (m_InvulnerableTicks > 0) + { + // Entity is invulnerable + return false; } if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) @@ -333,10 +340,13 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_World->BroadcastEntityStatus(*this, esGenericHurt); + m_InvulnerableTicks = 10; + if (m_Health <= 0) { KilledBy(a_TDI.Attacker); } + return true; } @@ -511,6 +521,11 @@ void cEntity::SetHealth(int a_Health) void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { + if (m_InvulnerableTicks > 0) + { + m_InvulnerableTicks--; + } + if (m_AttachedTo != NULL) { if ((m_Pos - m_AttachedTo->GetPosition()).Length() > 0.5) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 86efc5a98..fc4186afc 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -262,8 +262,8 @@ public: // tolua_end - /// Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied - virtual void DoTakeDamage(TakeDamageInfo & a_TDI); + /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't become any damage. */ + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); // tolua_begin @@ -391,6 +391,12 @@ public: virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } /** Gets remaining air of a monster */ int GetAirLevel(void) const { return m_AirLevel; } + + /** Gets the invulnerable ticks from the entity */ + int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; } + + /** Set the invulnerable ticks from the entity */ + void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; } // tolua_end @@ -493,11 +499,14 @@ private: // Measured in Kilograms (Kg) double m_Mass; - /// Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. + // Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. double m_Width; - /// Height of the entity (Y axis) + // Height of the entity (Y axis) double m_Height; + + // If a player hunt a entity, the entity become a invulnerable of 20 ticks + int m_InvulnerableTicks; } ; // tolua_export typedef std::list cEntityList; diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index db55eb058..7bd440d6d 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -902,18 +902,21 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) -void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) +bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) { Destroy(); TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative - super::DoTakeDamage(TDI); - return; // No drops for creative + SetInvulnerableTicks(0); + return super::DoTakeDamage(TDI); // No drops for creative } m_LastDamage = TDI.FinalDamage; - super::DoTakeDamage(TDI); + if (!super::DoTakeDamage(TDI)) + { + return false; + } m_World->BroadcastEntityMetadata(*this); @@ -952,12 +955,13 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) default: { ASSERT(!"Unhandled minecart type when spawning pickup!"); - return; + return true; } } m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); } + return true; } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index ebdb576e0..1e60f091c 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -36,7 +36,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; virtual void Destroyed() override; int LastDamage(void) const { return m_LastDamage; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fedb62527..08b7d3984 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -808,14 +808,14 @@ void cPlayer::SetFlying(bool a_IsFlying) -void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { if (IsGameModeCreative()) { // No damage / health in creative mode if not void or plugin damage - return; + return false; } } @@ -828,17 +828,19 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) if (!m_Team->AllowsFriendlyFire()) { // Friendly fire is disabled - return; + return false; } } } - super::DoTakeDamage(a_TDI); - - // Any kind of damage adds food exhaustion - AddFoodExhaustion(0.3f); - - SendHealth(); + if (super::DoTakeDamage(a_TDI)) + { + // Any kind of damage adds food exhaustion + AddFoodExhaustion(0.3f); + SendHealth(); + return true; + } + return false; } @@ -897,6 +899,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) void cPlayer::Respawn(void) { m_Health = GetMaxHealth(); + SetInvulnerableTicks(20); // Reset food level: m_FoodLevel = MAX_FOOD_LEVEL; diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 78d661015..3029abfe0 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -498,7 +498,7 @@ protected: virtual void Destroyed(void); /** Filters out damage for creative mode/friendly fire */ - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 3471b4cf1..9cf539427 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -75,9 +75,12 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) -void cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (!super::DoTakeDamage(a_TDI)) + { + return false; + } if (a_TDI.DamageType == dtLightning) { @@ -85,6 +88,7 @@ void cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI) } m_World->BroadcastEntityMetadata(*this); + return true; } diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index 9abca369b..fc7db6716 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -18,7 +18,7 @@ public: CLASS_PROTODEF(cCreeper); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Attack(float a_Dt) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void OnRightClicked(cPlayer & a_Player) override; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index eb8480268..9e4c2ba25 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -457,9 +457,12 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) -void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (!super::DoTakeDamage(a_TDI)) + { + return false; + } if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f); @@ -468,6 +471,7 @@ void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { m_Target = a_TDI.Attacker; } + return true; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 70b3783fc..5a925dfc6 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -87,7 +87,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void KilledBy(cEntity * a_Killer) override; diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp index 4b45f9a2a..24501b1ba 100644 --- a/src/Mobs/PassiveAggressiveMonster.cpp +++ b/src/Mobs/PassiveAggressiveMonster.cpp @@ -19,9 +19,12 @@ cPassiveAggressiveMonster::cPassiveAggressiveMonster(const AString & a_ConfigNam -void cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (!super::DoTakeDamage(a_TDI)) + { + return false; + } if ((m_Target != NULL) && (m_Target->IsPlayer())) { @@ -30,6 +33,7 @@ void cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) m_EMState = CHASING; } } + return true; } diff --git a/src/Mobs/PassiveAggressiveMonster.h b/src/Mobs/PassiveAggressiveMonster.h index 2c5ef30b1..a0da50e8e 100644 --- a/src/Mobs/PassiveAggressiveMonster.h +++ b/src/Mobs/PassiveAggressiveMonster.h @@ -15,7 +15,7 @@ class cPassiveAggressiveMonster : public: cPassiveAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height); - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; } ; diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index 904cd63cc..2861d7314 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -18,13 +18,17 @@ cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, eType a_MobType, -void cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (!super::DoTakeDamage(a_TDI)) + { + return false; + } if ((a_TDI.Attacker != this) && (a_TDI.Attacker != NULL)) { m_EMState = ESCAPING; } + return true; } diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h index 0b3c155da..70574585a 100644 --- a/src/Mobs/PassiveMonster.h +++ b/src/Mobs/PassiveMonster.h @@ -18,7 +18,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; /// When hit by someone, run away - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; /** Returns the item that the animal of this class follows when a player holds it in hand Return an empty item not to follow (default). */ virtual const cItem GetFollowedItem(void) const { return cItem(); } diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index d049acc1e..41283acf4 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -23,9 +23,13 @@ cVillager::cVillager(eVillagerType VillagerType) : -void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (!super::DoTakeDamage(a_TDI)) + { + return false; + } + if ((a_TDI.Attacker != NULL) && a_TDI.Attacker->IsPlayer()) { if (m_World->GetTickRandomNumber(5) == 3) @@ -33,6 +37,7 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) m_World->BroadcastEntityStatus(*this, esVillagerAngry); } } + return true; } diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index 5bba4d4ba..abde48407 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -30,7 +30,7 @@ public: CLASS_PROTODEF(cVillager); // cEntity overrides - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick (float a_Dt, cChunk & a_Chunk) override; // cVillager functions diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 8f5d28b68..144f89658 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -40,24 +40,24 @@ bool cWither::Initialize(cWorld * a_World) -void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType == dtDrowning) { - return; + return false; } if (m_InvulnerableTicks > 0) { - return; + return false; } if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) { - return; + return false; } - super::DoTakeDamage(a_TDI); + return super::DoTakeDamage(a_TDI); } diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index bc78bfaad..3b22ba4a5 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -27,7 +27,7 @@ public: // cEntity overrides virtual bool Initialize(cWorld * a_World) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; private: diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index f02b8a4fc..e6268abc7 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -25,14 +25,19 @@ cWolf::cWolf(void) : -void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) { - super::DoTakeDamage(a_TDI); + if (super::DoTakeDamage(a_TDI)) + { + return false; + } + if (!m_IsTame) { m_IsAngry = true; } m_World->BroadcastEntityMetadata(*this); // Broadcast health and possibly angry face + return true; } diff --git a/src/Mobs/Wolf.h b/src/Mobs/Wolf.h index 5925373e1..fb8a7c995 100644 --- a/src/Mobs/Wolf.h +++ b/src/Mobs/Wolf.h @@ -18,7 +18,7 @@ public: CLASS_PROTODEF(cWolf); - virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void TickFollowPlayer(); -- cgit v1.2.3 From ad1410f46e5deccc9f9a38e360fa65d6e33b82b4 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:37:09 +0200 Subject: Change m_InvulnerableTicks description --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index fc4186afc..ac9cf8b32 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hunt a entity, the entity become a invulnerable of 20 ticks + // If a player hit a entity, the entity become a invulnerable of 20 ticks int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From ed1aa02d0c0efbffbaf46c8f17dc4c52c9e6f34d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:37:40 +0200 Subject: Change m_InvulnerableTicks description again. --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ac9cf8b32..ba74a38a9 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hit a entity, the entity become a invulnerable of 20 ticks + // If a player hit a entity, the entity become a invulnerable of 10 ticks int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From e5683ede63572fe8b40703d449adf784b7d80ea7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:41:00 +0200 Subject: Change m_InvulnerableTicks description again again :D --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ba74a38a9..e76279c28 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hit a entity, the entity become a invulnerable of 10 ticks + // If a player hit a entity, the entity become a invulnerable of 10 ticks. While this ticks, a player can't hit this entity. int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From c8d5fcfffa7540898a92546094c2d3040740eb5a Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 26 Apr 2014 00:43:01 +0200 Subject: Fix for minor resource leak (CID 43616) --- src/WorldStorage/WSSCompact.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 5435e6d5a..59b8e4f6c 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -468,7 +468,15 @@ cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_ for (int i = 0; i < NumChunks; i++) { sChunkHeader * Header = new sChunkHeader; - READ(*Header); + + // Here we do not use the READ macro, as it does not free the resources + // allocated with new in case of error. + if (f.Read(Header, sizeof(*Header)) != sizeof(*Header)) + { + LOGERROR("ERROR READING %s FROM FILE %s (line %d); file offset %d", "Header", m_FileName.c_str(), __LINE__, f.Tell()); + delete Header; + return; + } m_ChunkHeaders.push_back(Header); } // for i - chunk headers -- cgit v1.2.3 From 5ffdaa8142da27c68f467f26c4f28129865b7bf9 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 12:59:55 -0700 Subject: Moved huge conditional out of InStateChasing(), improving readability Squashed a warning. --- src/Mobs/AggressiveMonster.cpp | 17 ++++++++++++++++- src/Mobs/AggressiveMonster.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 0901f85a9..cafa7ee74 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -37,7 +37,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt) } } - if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ())) + if (!IsMovingToTargetPosition()) { MoveToPosition(m_Target->GetPosition()); } @@ -106,3 +106,18 @@ void cAggressiveMonster::Attack(float a_Dt) +bool cAggressiveMonster::IsMovingToTargetPosition() +{ + float epsilon = 0.000000000001; + //Difference between destination x and target x is negligable (to 10^-12 precision) + if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) + { + return false; + } + //Difference between destination z and target z is negligable (to 10^-12 precision) + else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) + { + return false; + } + return true; +} diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 152260f95..c66452360 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -22,6 +22,10 @@ public: virtual void EventSeePlayer(cEntity *) override; virtual void Attack(float a_Dt); +protected: + /* Whether this mob's destination is the same as its target's position. */ + bool IsMovingToTargetPosition(); + } ; -- cgit v1.2.3 From f2b7cb138f6ad271d3312ff6c20ed4448f9b0d50 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 26 Apr 2014 01:21:06 +0200 Subject: Fixes resource leaks in the yggdrasil authenticator. (CID 43617) --- src/Protocol/Authenticator.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src') diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index e0fcc0007..bbc656eda 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -165,6 +165,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) { LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -175,6 +179,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if (ret < 0) { LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -182,6 +190,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0) { LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + entropy_free(&entropy); return false; } @@ -189,6 +201,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret = ssl_init(&ssl)) != 0) { LOGWARNING("cAuthenticator: ssl_init returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } ssl_set_endpoint(&ssl, SSL_IS_CLIENT); @@ -203,6 +222,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE)) { LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } } @@ -223,6 +249,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S if (ret <= 0) { LOGWARNING("cAuthenticator: ssl_write returned %d", ret); + + // Free all resources which have been initialized up to this line + x509_crt_free(&cacert); + net_close(server_fd); + ssl_free(&ssl); + entropy_free(&entropy); + memset(&ssl, 0, sizeof(ssl)); return false; } -- cgit v1.2.3 From 083cec5a09eed6e018a06734c44919419fe76620 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 16:26:24 -0700 Subject: Removed extraneous switch{} in Start() Squashed a warning. --- src/BlockID.cpp | 5 +++-- src/World.cpp | 15 --------------- 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 79e122032..bf95d0798 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -324,7 +324,7 @@ eDimension StringToDimension(const AString & a_DimensionString) { dimOverworld, "Normal"}, { dimOverworld, "World"}, { dimNether, "Nether"}, - { dimNether, "Hell"}, // Alternate name for End + { dimNether, "Hell"}, // Alternate name for Nether { dimEnd, "End"}, { dimEnd, "Sky"}, // Old name for End } ; @@ -337,7 +337,8 @@ eDimension StringToDimension(const AString & a_DimensionString) } // for i - DimensionMap[] // Not found - return (eDimension)-1000; + LOGWARNING("Unknown dimension: \"%s\". Setting to Overworld", a_DimensionString.c_str()); + return dimOverworld; } diff --git a/src/World.cpp b/src/World.cpp index 21cabe434..6582c1c07 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -518,21 +518,6 @@ void cWorld::Start(void) } AString Dimension = IniFile.GetValueSet("General", "Dimension", "Overworld"); m_Dimension = StringToDimension(Dimension); - switch (m_Dimension) - { - case dimNether: - case dimOverworld: - case dimEnd: - { - break; - } - default: - { - LOGWARNING("Unknown dimension: \"%s\". Setting to Overworld", Dimension.c_str()); - m_Dimension = dimOverworld; - break; - } - } // switch (m_Dimension) // Try to find the "SpawnPosition" key and coord values in the world configuration, set the flag if found int KeyNum = IniFile.FindKey("SpawnPosition"); -- cgit v1.2.3 From c124fc39d44f5a5e06a269d294736939aef22a32 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 16:32:20 -0700 Subject: Removed impossible default case. Squashed a warning. --- src/World.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/World.cpp b/src/World.cpp index 6582c1c07..4a71a7e4c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -574,12 +574,6 @@ void cWorld::Start(void) case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break; case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break; case dimEnd: DefaultMonsters = "enderman"; break; - default: - { - ASSERT(!"Unhandled world dimension"); - DefaultMonsters = "wither"; - break; - } } m_bAnimals = IniFile.GetValueSetB("Monsters", "AnimalsOn", true); AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters); -- cgit v1.2.3 From 26568a852e557622ce20fafb08680ccd4d7ad7ac Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 26 Apr 2014 01:35:25 +0200 Subject: Fixed a memory leak in tolua_cWorld_ChunkStay. (CID 43618) --- src/Bindings/ManualBindings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 92b410481..b3f75aff1 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1750,7 +1750,6 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) { return 0; } - cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin); // Read the params: cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); @@ -1760,8 +1759,12 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) L.LogStackTrace(); return 0; } + + cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin); + if (!ChunkStay->AddChunks(2)) { + delete ChunkStay; return 0; } -- cgit v1.2.3 From 2c0bb7b717a759204ff6c332f9ccde85a89a1aff Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 16:55:38 -0700 Subject: Moved the weather picker out of TickWeather(), squashing a warning and improving readability. --- src/World.cpp | 50 ++++++++++++++++++++++++++------------------------ src/World.h | 5 ++++- 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/World.cpp b/src/World.cpp index 4a71a7e4c..5ac8e0a6e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -663,6 +663,30 @@ void cWorld::GenerateRandomSpawn(void) +eWeather cWorld::ChooseNewWeather() +{ + // Pick a new weather. Only reasonable transitions allowed: + switch (m_Weather) + { + case eWeather_Sunny: + case eWeather_ThunderStorm: return eWeather_Rain; + + case eWeather_Rain: + { + // 1/8 chance of turning into a thunderstorm + return ((m_TickRand.randInt() % 256) < 32) ? eWeather_ThunderStorm : eWeather_Sunny; + } + } + + LOGWARNING("Unknown current weather: %d. Setting sunny.", m_Weather); + ASSERT(!"Unknown weather"); + return eWeather_Sunny; +} + + + + + void cWorld::Stop(void) { // Delete the clients that have been in this world: @@ -762,30 +786,8 @@ void cWorld::TickWeather(float a_Dt) else { // Change weather: - - // Pick a new weather. Only reasonable transitions allowed: - eWeather NewWeather = m_Weather; - switch (m_Weather) - { - case eWeather_Sunny: NewWeather = eWeather_Rain; break; - case eWeather_ThunderStorm: NewWeather = eWeather_Rain; break; - case eWeather_Rain: - { - // 1/8 chance of turning into a thunderstorm - NewWeather = ((m_TickRand.randInt() % 256) < 32) ? eWeather_ThunderStorm : eWeather_Sunny; - break; - } - - default: - { - LOGWARNING("Unknown current weather: %d. Setting sunny.", m_Weather); - ASSERT(!"Unknown weather"); - NewWeather = eWeather_Sunny; - } - } - - SetWeather(NewWeather); - } // else (m_WeatherInterval > 0) + SetWeather(ChooseNewWeather()); + } if (m_Weather == eWeather_ThunderStorm) { diff --git a/src/World.h b/src/World.h index e2be4cd35..f789916df 100644 --- a/src/World.h +++ b/src/World.h @@ -938,7 +938,10 @@ private: /** Generates a random spawnpoint on solid land by walking chunks and finding their biomes */ void GenerateRandomSpawn(void); - + + /** Chooses a reasonable transition from the current weather to a new weather **/ + eWeather ChooseNewWeather(void); + /** Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section) */ cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock); -- cgit v1.2.3 From 73edd2b96102bff9fbd74d34740fea3daa40b15f Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 17:15:12 -0700 Subject: Fixed a couple more warnings. --- src/Entities/FallingBlock.cpp | 4 +++- src/Entities/Minecart.cpp | 34 ++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index a66c7e4ae..f48fb156b 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -87,7 +87,9 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedY(MilliDt * -9.8f); AddPosition(GetSpeed() * MilliDt); - if ((GetSpeedX() != 0) || (GetSpeedZ() != 0)) + //If not static (One billionth precision) broadcast movement. + float epsilon = 0.000000001; + if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { BroadcastMovementUpdate(); } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index db55eb058..ceaa713bb 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -234,18 +234,15 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() > 0) { - if (GetSpeedZ() > 0) - { - // Going SOUTH, slow down - AddSpeedZ(-0.1); - } - else - { - // Going NORTH, slow down - AddSpeedZ(0.1); - } + // Going SOUTH, slow down + AddSpeedZ(-0.1); + } + else if (GetSpeedZ() < 0) + { + // Going NORTH, slow down + AddSpeedZ(0.1); } break; } @@ -259,16 +256,13 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() != 0) + if (GetSpeedX() > 0) { - if (GetSpeedX() > 0) - { - AddSpeedX(-0.1); - } - else - { - AddSpeedX(0.1); - } + AddSpeedX(-0.1); + } + else if (GetSpeedX() < 0) + { + AddSpeedX(0.1); } break; } -- cgit v1.2.3 From b2f40a7a114d543b6a88a8251f995f4be67e6157 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 18:18:46 -0700 Subject: Removed unused assignments. --- src/ChunkMap.cpp | 6 ++---- src/LineBlockTracer.cpp | 1 - src/WorldStorage/WSSCompact.cpp | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index ed9103174..0fb6988b5 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -346,9 +346,8 @@ void cChunkMap::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * void cChunkMap::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - int x, y, z, ChunkX, ChunkZ; + int x, z, ChunkX, ChunkZ; x = a_BlockX; - y = a_BlockY; z = a_BlockZ; cChunkDef::BlockToChunk(x, z, ChunkX, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); @@ -1146,9 +1145,8 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // First check if it isn't queued in the m_FastSetBlockQueue: { int X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; - int ChunkX, ChunkY, ChunkZ; + int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); - ChunkY = 0; cCSLock Lock(m_CSFastSetBlock); for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr) { diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index f4f29e833..b03652bab 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -171,7 +171,6 @@ bool cLineBlockTracer::MoveToNextBlock(void) double CoeffZ = (DestZ - m_StartZ) / m_DiffZ; if (CoeffZ < Coeff) { - Coeff = CoeffZ; Direction = dirZ; } } diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 5435e6d5a..c07c9e96f 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -797,7 +797,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() ++index2; } InChunkOffset += index2 / 2; - index2 = 0; AString Converted(ConvertedData, ExpectedSize); -- cgit v1.2.3 From acff6148b61a64b3d8bec791ca936457fc61a096 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 19:49:08 -0700 Subject: Moved switch{} out of GetArmorCoverAgainst(). --- src/Entities/Entity.cpp | 31 ++++++++++++++++++++++++++----- src/Entities/Entity.h | 3 +++ 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6da6da54e..49e7e45e2 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -381,11 +381,8 @@ int cEntity::GetRawDamageAgainst(const cEntity & a_Receiver) -int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) { - // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover - - // Filter out damage types that are not protected by armor: // Ref.: http://www.minecraftwiki.net/wiki/Armor#Effects as of 2012_12_20 switch (a_DamageType) { @@ -400,9 +397,33 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama case dtLightning: case dtPlugin: { - return 0; + return false; + } + + case dtAttack: + case dtArrowAttack: + case dtCactusContact: + case dtLavaContact: + case dtFireContact: + case dtEnderPearl: + case dtExplosion: + { + return true; } } + ASSERT("Invalid damage type!"); +} + + + + + +int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +{ + // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover + + // Filter out damage types that are not protected by armor: + if (!ArmorCoversAgainst(a_DamageType)) return 0; // Add up all armor points: // Ref.: http://www.minecraftwiki.net/wiki/Armor#Defense_points as of 2012_12_20 diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 86efc5a98..db40f12ed 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -270,6 +270,9 @@ public: /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); + // Returns whether armor will protect against the passed damage type + virtual bool ArmorCoversAgainst(eDamageType a_DamageType); + /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover virtual int GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage); -- cgit v1.2.3 From 80b97fd9dd584c439ca25efaa7e5172da1509628 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 20:49:55 -0700 Subject: Fixed mobs that don't naturally spawn. --- src/Mobs/Monster.cpp | 7 +++++-- src/Mobs/Monster.h | 1 + src/OSSupport/File.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f68d2ef75..14d951393 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -761,9 +761,10 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtChicken: return mfPassive; case mtCow: return mfPassive; case mtCreeper: return mfHostile; + case mtEnderDragon: return mfNoSpawn; case mtEnderman: return mfHostile; case mtGhast: return mfHostile; - case mtGiant: return mfHostile; + case mtGiant: return mfNoSpawn; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -774,11 +775,12 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtSilverfish: return mfHostile; case mtSkeleton: return mfHostile; case mtSlime: return mfHostile; + case mtSnowGolem: return mfNoSpawn; case mtSpider: return mfHostile; case mtSquid: return mfWater; case mtVillager: return mfPassive; case mtWitch: return mfHostile; - case mtWither: return mfHostile; + case mtWither: return mfNoSpawn; case mtWolf: return mfHostile; case mtZombie: return mfHostile; case mtZombiePigman: return mfHostile; @@ -801,6 +803,7 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) case mfPassive: return 40; case mfAmbient: return 40; case mfWater: return 400; + case mfNoSpawn: return -1; case mfUnhandled: break; } ASSERT(!"Unhandled mob family"); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 0243f6637..6b9c4fab8 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,6 +66,7 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid + mfNoSpawn, mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 7f0f0ad2f..f1b3bcf9e 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -67,11 +67,11 @@ bool cFile::Open(const AString & iFileName, eMode iMode) case fmRead: Mode = "rb"; break; case fmWrite: Mode = "wb"; break; case fmReadWrite: Mode = "rb+"; break; - default: - { - ASSERT(!"Unhandled file mode"); - return false; - } + } + if (Mode == NULL) + { + ASSERT(!"Unhandled file mode"); + return false; } #ifdef _WIN32 -- cgit v1.2.3 From a1765a2896714c956deb8eefcde93af074901f8e Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 26 Apr 2014 14:23:53 +0200 Subject: Fixed unitialized member in gZipFile (CID 43673) --- src/OSSupport/GZipFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp index 7a8433f4f..22d887783 100644 --- a/src/OSSupport/GZipFile.cpp +++ b/src/OSSupport/GZipFile.cpp @@ -11,7 +11,7 @@ cGZipFile::cGZipFile(void) : - m_File(NULL) + m_File(NULL), m_Mode(fmRead) { } -- cgit v1.2.3 From 49f6819829b437f776ea08f50c92cc506ee9ddcb Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 16:44:15 +0200 Subject: Fixes --- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 23 +++++++++++++---------- src/Mobs/Wither.cpp | 10 +++++----- src/Mobs/Wither.h | 6 +++--- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 8 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 0af4eafde..db657909c 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -60,7 +60,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) - , m_InvulnerableTicks(20) + , m_InvulnerableTicks(0) { cCSLock Lock(m_CSCount); m_EntityCount++; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index e76279c28..26edf8dca 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -262,7 +262,9 @@ public: // tolua_end - /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't become any damage. */ + /** Makes this entity take damage specified in the a_TDI. + The TDI is sent through plugins first, then applied. + If it returns false, the entity hasn't receive any damage. */ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); // tolua_begin @@ -481,31 +483,32 @@ protected: int m_AirTickTimer; private: - // Measured in degrees, [-180, +180) + /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - // Measured in meter/second (m/s) + /** Measured in meter/second (m/s) */ Vector3d m_Speed; - // Measured in degrees, [-180, +180) + /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; - /// Position of the entity's XZ center and Y bottom + /** Position of the entity's XZ center and Y bottom */ Vector3d m_Pos; - // Measured in meter / second + /** Measured in meter / second */ Vector3d m_WaterSpeed; - // Measured in Kilograms (Kg) + /** Measured in Kilograms (Kg) */ double m_Mass; - // Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. + /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ double m_Width; - // Height of the entity (Y axis) + /** Height of the entity (Y axis) */ double m_Height; - // If a player hit a entity, the entity become a invulnerable of 10 ticks. While this ticks, a player can't hit this entity. + /** If a player hit a entity, the entity receive a invulnerable of 10 ticks. + While this ticks, a player can't hit this entity. */ int m_InvulnerableTicks; } ; // tolua_export diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 144f89658..5b6e895e1 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -10,7 +10,7 @@ cWither::cWither(void) : super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0), - m_InvulnerableTicks(220) + m_WitherInvulnerableTicks(220) { SetMaxHealth(300); } @@ -47,7 +47,7 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } - if (m_InvulnerableTicks > 0) + if (m_WitherInvulnerableTicks > 0) { return false; } @@ -68,16 +68,16 @@ void cWither::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (m_InvulnerableTicks > 0) + if (m_WitherInvulnerableTicks > 0) { - unsigned int NewTicks = m_InvulnerableTicks - 1; + unsigned int NewTicks = m_WitherInvulnerableTicks - 1; if (NewTicks == 0) { m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); } - m_InvulnerableTicks = NewTicks; + m_WitherInvulnerableTicks = NewTicks; if ((NewTicks % 10) == 0) { diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 3b22ba4a5..08b460009 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -17,9 +17,9 @@ public: CLASS_PROTODEF(cWither); - unsigned int GetNumInvulnerableTicks(void) const { return m_InvulnerableTicks; } + unsigned int GetWitherInvulnerableTicks(void) const { return m_WitherInvulnerableTicks; } - void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; } + void SetWitherInvulnerableTicks(unsigned int a_Ticks) { m_WitherInvulnerableTicks = a_Ticks; } /** Returns whether the wither is invulnerable to arrows. */ bool IsArmored(void) const; @@ -33,7 +33,7 @@ public: private: /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ - unsigned int m_InvulnerableTicks; + unsigned int m_WitherInvulnerableTicks; } ; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3282a827f..a23afb29a 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,7 +2013,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt((Int32)((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..80b161e3e 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,7 +2820,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index b6c14db9c..46c6b8e92 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -516,7 +516,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case cMonster::mtWither: { - m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetNumInvulnerableTicks()); + m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetWitherInvulnerableTicks()); break; } case cMonster::mtWolf: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 66144dbd5..4532a925a 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2272,7 +2272,7 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a int CurrLine = a_NBT.FindChildByName(a_TagIdx, "Invul"); if (CurrLine > 0) { - Monster->SetNumInvulnerableTicks(a_NBT.GetInt(CurrLine)); + Monster->SetWitherInvulnerableTicks(a_NBT.GetInt(CurrLine)); } a_Entities.push_back(Monster.release()); -- cgit v1.2.3 From 619592b5a0ab651e714d55932bc7909e4204cee9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 17:37:35 +0200 Subject: Withers now use the new invulnerable. --- src/Mobs/Wither.cpp | 29 +++++++++-------------------- src/Mobs/Wither.h | 7 +------ 2 files changed, 10 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 5b6e895e1..fe4dbb28b 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -10,9 +10,10 @@ cWither::cWither(void) : super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0), - m_WitherInvulnerableTicks(220) + m_IsSpawnInvulnerable(true) { SetMaxHealth(300); + SetInvulnerableTicks(220); } @@ -47,11 +48,6 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } - if (m_WitherInvulnerableTicks > 0) - { - return false; - } - if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) { return false; @@ -68,21 +64,14 @@ void cWither::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (m_WitherInvulnerableTicks > 0) + if (GetInvulnerableTicks() <= 0 && m_IsSpawnInvulnerable) { - unsigned int NewTicks = m_WitherInvulnerableTicks - 1; - - if (NewTicks == 0) - { - m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); - } - - m_WitherInvulnerableTicks = NewTicks; - - if ((NewTicks % 10) == 0) - { - Heal(10); - } + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + m_IsSpawnInvulnerable = false; + } + else if (((GetInvulnerableTicks() % 10) == 0) && (GetInvulnerableTicks() > 10)) + { + Heal(10); } m_World->BroadcastEntityMetadata(*this); diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 08b460009..81c9df1b1 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -17,10 +17,6 @@ public: CLASS_PROTODEF(cWither); - unsigned int GetWitherInvulnerableTicks(void) const { return m_WitherInvulnerableTicks; } - - void SetWitherInvulnerableTicks(unsigned int a_Ticks) { m_WitherInvulnerableTicks = a_Ticks; } - /** Returns whether the wither is invulnerable to arrows. */ bool IsArmored(void) const; @@ -32,8 +28,7 @@ public: private: - /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ - unsigned int m_WitherInvulnerableTicks; + bool m_IsSpawnInvulnerable; } ; -- cgit v1.2.3 From d50f8f6f11f69e7e1e56be92fb2d72a5014a3e34 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 17:47:25 +0200 Subject: Changed the old invulnerable methods from the wither to the new. --- src/Mobs/Wither.h | 3 +++ src/Protocol/Protocol125.cpp | 9 ++++++++- src/Protocol/Protocol17x.cpp | 9 ++++++++- src/WorldStorage/NBTChunkSerializer.cpp | 9 ++++++++- src/WorldStorage/WSSAnvil.cpp | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 81c9df1b1..fbea331d3 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -19,6 +19,9 @@ public: /** Returns whether the wither is invulnerable to arrows. */ bool IsArmored(void) const; + + /** Use the wither the invulnerable from the spawn? */ + bool IsSpawnInvulnerable(void) const { return m_IsSpawnInvulnerable; } // cEntity overrides virtual bool Initialize(cWorld * a_World) override; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index a23afb29a..3951eb3e4 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,7 +2013,14 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); + if (((const cWither &)a_Mob).IsSpawnInvulnerable()) + { + WriteInt((Int32)((const cWither &)a_Mob).GetInvulnerableTicks()); + } + else + { + WriteInt((Int32)0); + } WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 80b161e3e..311e770f9 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,7 +2820,14 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); + if (((const cWither &)a_Mob).IsSpawnInvulnerable()) + { + WriteInt(((const cWither &)a_Mob).GetInvulnerableTicks()); + } + else + { + WriteInt(0); + } WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 46c6b8e92..0c4a1a430 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -516,7 +516,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case cMonster::mtWither: { - m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetWitherInvulnerableTicks()); + if (((const cWither *)a_Monster)->IsSpawnInvulnerable()) + { + m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetInvulnerableTicks()); + } + else + { + m_Writer.AddInt("Invul", 0); + } break; } case cMonster::mtWolf: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4532a925a..c21809270 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2272,7 +2272,7 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a int CurrLine = a_NBT.FindChildByName(a_TagIdx, "Invul"); if (CurrLine > 0) { - Monster->SetWitherInvulnerableTicks(a_NBT.GetInt(CurrLine)); + Monster->SetInvulnerableTicks(a_NBT.GetInt(CurrLine)); } a_Entities.push_back(Monster.release()); -- cgit v1.2.3 From aef2c8ec628aa2522364da1333bc5158e55ac6a2 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 09:21:49 -0700 Subject: Further refactored, Reverted Minecart change Other small changes. --- src/ClientHandle.cpp | 78 +++++++++------------------------ src/ClientHandle.h | 4 +- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 2 +- src/Entities/FallingBlock.cpp | 2 +- src/Entities/Minecart.cpp | 34 ++++++++------ src/MCLogger.cpp | 14 +++--- src/MCLogger.h | 2 +- src/Mobs/AggressiveMonster.cpp | 4 +- src/Mobs/AggressiveMonster.h | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++-- 11 files changed, 62 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7bfae9ca7..78402d4d3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -186,53 +186,31 @@ void cClientHandle::GenerateOfflineUUID(void) +AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2) +{ + if (ShouldAppendChatPrefixes) + return Printf("%s%s %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str()); + else + return Printf("%s", m_Color1.c_str()); +} + + + + + AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData) { switch (a_ChatPrefix) { - case mtCustom: return AString(); - case mtFailure: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Rose.c_str()); - } - case mtInformation: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Yellow.c_str()); - } - case mtSuccess: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Green.c_str()); - } - case mtWarning: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Rose.c_str()); - } - case mtFatal: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Red.c_str()); - } - case mtDeath: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Gray.c_str()); - } + case mtCustom: return AString(); + case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Rose, cChatColor::White); + case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Yellow, cChatColor::White); + case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Green, cChatColor::White); + case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "[WARN]", cChatColor::Rose, cChatColor::White); + case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "[FATAL]", cChatColor::Red, cChatColor::White); + case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "[DEATH]", cChatColor::Gray, cChatColor::White); + case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "[JOIN]", cChatColor::Yellow, cChatColor::White); + case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "[LEAVE]", cChatColor::Yellow, cChatColor::White); case mtPrivateMessage: { if (ShouldAppendChatPrefixes) @@ -240,20 +218,6 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage else return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); } - case mtJoin: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Yellow.c_str()); - } - case mtLeave: - { - if (ShouldAppendChatPrefixes) - return Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - return Printf("%s", cChatColor::Yellow.c_str()); - } } ASSERT(!"Unhandled chat prefix type!"); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index e2b44ce8a..9f8d44129 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -78,8 +78,10 @@ public: Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */ static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export - // Formats the type of message with the proper color and prefix for sending to the client. + /** Formats the type of message with the proper color and prefix for sending to the client. **/ AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData); + + AString FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2); void Kick(const AString & a_Reason); // tolua_export void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 49e7e45e2..961caf493 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -411,7 +411,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) return true; } } - ASSERT("Invalid damage type!"); + ASSERT(!"Invalid damage type!"); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index db40f12ed..9b8011b55 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -270,7 +270,7 @@ public: /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); - // Returns whether armor will protect against the passed damage type + /** Returns whether armor will protect against the passed damage type **/ virtual bool ArmorCoversAgainst(eDamageType a_DamageType); /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index f48fb156b..50140de67 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -88,7 +88,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddPosition(GetSpeed() * MilliDt); //If not static (One billionth precision) broadcast movement. - float epsilon = 0.000000001; + static const float epsilon = 0.000000001; if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { BroadcastMovementUpdate(); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index ceaa713bb..db55eb058 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -234,15 +234,18 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() > 0) - { - // Going SOUTH, slow down - AddSpeedZ(-0.1); - } - else if (GetSpeedZ() < 0) + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { - // Going NORTH, slow down - AddSpeedZ(0.1); + if (GetSpeedZ() > 0) + { + // Going SOUTH, slow down + AddSpeedZ(-0.1); + } + else + { + // Going NORTH, slow down + AddSpeedZ(0.1); + } } break; } @@ -256,13 +259,16 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() > 0) - { - AddSpeedX(-0.1); - } - else if (GetSpeedX() < 0) + if (GetSpeedX() != 0) { - AddSpeedX(0.1); + if (GetSpeedX() > 0) + { + AddSpeedX(-0.1); + } + else + { + AddSpeedX(0.1); + } } break; } diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index ca47b29db..d56c1a5a8 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -33,7 +33,7 @@ cMCLogger * cMCLogger::GetInstance(void) cMCLogger::cMCLogger(void): - g_ShouldColorOutput(false) + m_ShouldColorOutput(false) { AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(NULL)); @@ -76,15 +76,15 @@ void cMCLogger::InitLog(const AString & a_FileName) #ifdef _WIN32 // See whether we are writing to a console the default console attrib: - g_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0); - if (g_ShouldColorOutput) + m_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0); + if (m_ShouldColorOutput) { CONSOLE_SCREEN_BUFFER_INFO sbi; GetConsoleScreenBufferInfo(g_Console, &sbi); - g_DefaultConsoleAttrib = sbi.wAttributes; + m_DefaultConsoleAttrib = sbi.wAttributes; } #elif defined (__linux) && !defined(ANDROID_NDK) - g_ShouldColorOutput = isatty(fileno(stdout)); + m_ShouldColorOutput = isatty(fileno(stdout)); // TODO: Check if the terminal supports colors, somehow? #endif } @@ -178,7 +178,7 @@ void cMCLogger::Error(const char * a_Format, va_list a_ArgList) void cMCLogger::SetColor(eColorScheme a_Scheme) { - if (!g_ShouldColorOutput) + if (!m_ShouldColorOutput) { return; } @@ -211,7 +211,7 @@ void cMCLogger::SetColor(eColorScheme a_Scheme) void cMCLogger::ResetColor(void) { - if (!g_ShouldColorOutput) + if (!m_ShouldColorOutput) { return; } diff --git a/src/MCLogger.h b/src/MCLogger.h index 34955ea16..114210f63 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -52,7 +52,7 @@ private: cCriticalSection m_CriticalSection; cLog * m_Log; static cMCLogger * s_MCLogger; - bool g_ShouldColorOutput; + bool m_ShouldColorOutput; /// Sets the specified color scheme in the terminal (TODO: if coloring available) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index cafa7ee74..3e5f72dbf 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -109,12 +109,12 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { float epsilon = 0.000000000001; - //Difference between destination x and target x is negligable (to 10^-12 precision) + // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { return false; } - //Difference between destination z and target z is negligable (to 10^-12 precision) + // Difference between destination z and target z is negligible (to 10^-12 precision) else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) { return false; diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index c66452360..d70ff04a3 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -23,7 +23,7 @@ public: virtual void Attack(float a_Dt); protected: - /* Whether this mob's destination is the same as its target's position. */ + /** Whether this mob's destination is the same as its target's position. */ bool IsMovingToTargetPosition(); } ; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 27631eded..773954f73 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -621,10 +621,10 @@ void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging) m_Writer.AddInt("TileZ", a_Hanging->GetTileZ()); switch (a_Hanging->GetDirection()) { - case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break; - case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break; - case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break; - case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break; + case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break; + case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break; + case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break; + case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break; } } -- cgit v1.2.3 From 5a0625eccc5e6b3d7aa757b3596f85afa8b46640 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 11:00:59 -0700 Subject: Moar alignment. --- src/ClientHandle.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 78402d4d3..f7147fd2b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -203,13 +203,13 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage switch (a_ChatPrefix) { case mtCustom: return AString(); - case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Rose, cChatColor::White); - case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Yellow, cChatColor::White); - case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Green, cChatColor::White); - case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "[WARN]", cChatColor::Rose, cChatColor::White); - case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "[FATAL]", cChatColor::Red, cChatColor::White); - case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "[DEATH]", cChatColor::Gray, cChatColor::White); - case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "[JOIN]", cChatColor::Yellow, cChatColor::White); + case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Rose, cChatColor::White); + case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Yellow, cChatColor::White); + case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Green, cChatColor::White); + case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "[WARN]", cChatColor::Rose, cChatColor::White); + case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "[FATAL]", cChatColor::Red, cChatColor::White); + case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "[DEATH]", cChatColor::Gray, cChatColor::White); + case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "[JOIN]", cChatColor::Yellow, cChatColor::White); case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "[LEAVE]", cChatColor::Yellow, cChatColor::White); case mtPrivateMessage: { -- cgit v1.2.3 From 7841bad27ad97736ddf21b86e2409f20c6392e69 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 14:01:48 -0700 Subject: More small fixes. --- src/ClientHandle.cpp | 18 +++++++++--------- src/Entities/FallingBlock.cpp | 2 +- src/MCLogger.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f7147fd2b..fc3f98aaf 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -189,7 +189,7 @@ void cClientHandle::GenerateOfflineUUID(void) AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2) { if (ShouldAppendChatPrefixes) - return Printf("%s%s %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str()); + return Printf("%s[%s] %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str()); else return Printf("%s", m_Color1.c_str()); } @@ -203,14 +203,14 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage switch (a_ChatPrefix) { case mtCustom: return AString(); - case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Rose, cChatColor::White); - case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Yellow, cChatColor::White); - case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Green, cChatColor::White); - case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "[WARN]", cChatColor::Rose, cChatColor::White); - case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "[FATAL]", cChatColor::Red, cChatColor::White); - case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "[DEATH]", cChatColor::Gray, cChatColor::White); - case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "[JOIN]", cChatColor::Yellow, cChatColor::White); - case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "[LEAVE]", cChatColor::Yellow, cChatColor::White); + case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Rose, cChatColor::White); + case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Yellow, cChatColor::White); + case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "INFO", cChatColor::Green, cChatColor::White); + case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "WARN", cChatColor::Rose, cChatColor::White); + case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "FATAL", cChatColor::Red, cChatColor::White); + case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "DEATH", cChatColor::Gray, cChatColor::White); + case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "JOIN", cChatColor::Yellow, cChatColor::White); + case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "LEAVE", cChatColor::Yellow, cChatColor::White); case mtPrivateMessage: { if (ShouldAppendChatPrefixes) diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 50140de67..bcdac0291 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -87,7 +87,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedY(MilliDt * -9.8f); AddPosition(GetSpeed() * MilliDt); - //If not static (One billionth precision) broadcast movement. + // If not static (One billionth precision) broadcast movement. static const float epsilon = 0.000000001; if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index d56c1a5a8..583438d65 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -81,7 +81,7 @@ void cMCLogger::InitLog(const AString & a_FileName) { CONSOLE_SCREEN_BUFFER_INFO sbi; GetConsoleScreenBufferInfo(g_Console, &sbi); - m_DefaultConsoleAttrib = sbi.wAttributes; + g_DefaultConsoleAttrib = sbi.wAttributes; } #elif defined (__linux) && !defined(ANDROID_NDK) m_ShouldColorOutput = isatty(fileno(stdout)); -- cgit v1.2.3 From e2194e6e9083b54914deac3a5a6c2e3e4d262990 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 15:32:14 -0700 Subject: Added static const, initialized fields. --- src/BlockEntities/CommandBlockEntity.cpp | 3 ++- src/BlockEntities/MobHeadEntity.cpp | 2 ++ src/Entities/Entity.cpp | 2 ++ src/Mobs/AggressiveMonster.cpp | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 96ca0ac37..146ad915b 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -21,7 +21,8 @@ cCommandBlockEntity::cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World) : super(E_BLOCK_COMMAND_BLOCK, a_X, a_Y, a_Z, a_World), m_ShouldExecute(false), - m_IsPowered(false) + m_IsPowered(false), + m_Result(0) {} diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp index c0a1781f6..dc9c18d58 100644 --- a/src/BlockEntities/MobHeadEntity.cpp +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -14,6 +14,8 @@ cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Type(SKULL_TYPE_SKELETON), + m_Rotation(SKULL_ROTATION_NORTH), m_Owner("") { } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 7c8e18b51..827b88717 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -53,6 +53,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_TicksSinceLastVoidDamage(0) , m_IsSwimming(false) , m_IsSubmerged(false) + , m_AirLevel(0) + , m_AirTickTimer(0) , m_HeadYaw( 0.0 ) , m_Rot(0.0, 0.0, 0.0) , m_Pos(a_X, a_Y, a_Z) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 3e5f72dbf..4997952be 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -108,7 +108,7 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { - float epsilon = 0.000000000001; + static const float epsilon = 0.000000000001; // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { -- cgit v1.2.3 From 477b3e7861ca03aec5c46b4c192f5cc1b5f07c4d Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 16:45:39 -0700 Subject: Moved cArrowEntity out of ProjectileEntity.h --- src/Entities/ProjectileArrow.cpp | 193 +++++++++++++++++++++++++++++++ src/Entities/ProjectileArrow.h | 95 ++++++++++++++++ src/Entities/ProjectileEntity.cpp | 195 +------------------------------- src/Entities/ProjectileEntity.h | 88 -------------- src/Items/ItemBow.h | 2 +- src/Mobs/Skeleton.cpp | 1 + src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 1 + src/WorldStorage/NBTChunkSerializer.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 10 files changed, 297 insertions(+), 284 deletions(-) create mode 100644 src/Entities/ProjectileArrow.cpp create mode 100644 src/Entities/ProjectileArrow.h (limited to 'src') diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp new file mode 100644 index 000000000..bd4f2abab --- /dev/null +++ b/src/Entities/ProjectileArrow.cpp @@ -0,0 +1,193 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Player.h" +#include "ProjectileArrow.h" +#include "../Chunk.h" + + + + + +cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), +m_PickupState(psNoPickup), +m_DamageCoeff(2), +m_IsCritical(false), +m_Timer(0), +m_HitGroundTimer(0), +m_bIsCollected(false), +m_HitBlockPos(Vector3i(0, 0, 0)) +{ + SetSpeed(a_Speed); + SetMass(0.1); + SetYawFromSpeed(); + SetPitchFromSpeed(); + LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", + m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), + GetYaw(), GetPitch() + ); +} + + + + + +cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : +super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), +m_PickupState(psInSurvivalOrCreative), +m_DamageCoeff(2), +m_IsCritical((a_Force >= 1)), +m_Timer(0), +m_HitGroundTimer(0), +m_HasTeleported(false), +m_bIsCollected(false), +m_HitBlockPos(0, 0, 0) +{ +} + + + + + +bool cArrowEntity::CanPickup(const cPlayer & a_Player) const +{ + switch (m_PickupState) + { + case psNoPickup: return false; + case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); + case psInCreative: return a_Player.IsGameModeCreative(); + } + ASSERT(!"Unhandled pickup state"); + return false; +} + + + + + +void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + if (a_HitFace == BLOCK_FACE_NONE) { return; } + + super::OnHitSolidBlock(a_HitPos, a_HitFace); + int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; + + switch (a_HitFace) + { + case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed + case BLOCK_FACE_YM: + { + break; + } + default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); + } + + m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); + + // Broadcast arrow hit sound + m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); +} + + + + + +void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) + { + // Not an entity that interacts with an arrow + return; + } + + int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); + if (m_IsCritical) + { + Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); + } + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); + + // Broadcast successful hit sound + m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + + Destroy(); +} + + + + + +void cArrowEntity::CollectedBy(cPlayer * a_Dest) +{ + if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) + { + int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); + if (NumAdded > 0) // Only play effects if there was space in inventory + { + m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) + m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsCollected = true; + } + } +} + + + + + +void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + m_Timer += a_Dt; + + if (m_bIsCollected) + { + if (m_Timer > 500.f) // 0.5 seconds + { + Destroy(); + return; + } + } + else if (m_Timer > 1000 * 60 * 5) // 5 minutes + { + Destroy(); + return; + } + + if (m_IsInGround) + { + // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL + // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) + // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync + // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position + + if (!m_HasTeleported) // Sent a teleport already, don't do again + { + if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case + { + m_World->BroadcastTeleportEntity(*this); + m_HasTeleported = true; + } + else + { + m_HitGroundTimer += a_Dt; + } + } + + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; + int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); + + if (Chunk == NULL) + { + // Inside an unloaded chunk, abort + return; + } + + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + { + m_IsInGround = false; // Yes, begin simulating physics again + } + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h new file mode 100644 index 000000000..c08b7acc5 --- /dev/null +++ b/src/Entities/ProjectileArrow.h @@ -0,0 +1,95 @@ +// +// ProjectileArrow.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cArrowEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field + enum ePickupState + { + psNoPickup = 0, + psInSurvivalOrCreative = 1, + psInCreative = 2, + } ; + + // tolua_end + + CLASS_PROTODEF(cArrowEntity); + + /// Creates a new arrow with psNoPickup state and default damage modifier coeff + cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + + /// Creates a new arrow as shot by a player, initializes it from the player object + cArrowEntity(cPlayer & a_Player, double a_Force); + + // tolua_begin + + /// Returns whether the arrow can be picked up by players + ePickupState GetPickupState(void) const { return m_PickupState; } + + /// Sets a new pickup state + void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } + + /// Returns the damage modifier coeff. + double GetDamageCoeff(void) const { return m_DamageCoeff; } + + /// Sets the damage modifier coeff + void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } + + /// Returns true if the specified player can pick the arrow up + bool CanPickup(const cPlayer & a_Player) const; + + /// Returns true if the arrow is set as critical + bool IsCritical(void) const { return m_IsCritical; } + + /// Sets the IsCritical flag + void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } + + // tolua_end + +protected: + + /// Determines when the arrow can be picked up by players + ePickupState m_PickupState; + + /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow + double m_DamageCoeff; + + /// If true, the arrow deals more damage + bool m_IsCritical; + + /// Timer for pickup collection animation or five minute timeout + float m_Timer; + + /// Timer for client arrow position confirmation via TeleportEntity + float m_HitGroundTimer; + + // Whether the arrow has already been teleported into the proper position in the ground. + bool m_HasTeleported; + + /// If true, the arrow is in the process of being collected - don't go to anyone else + bool m_bIsCollected; + + /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air + Vector3i m_HitBlockPos; + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void CollectedBy(cPlayer * a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + // tolua_begin +}; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index fd3e80e5f..079adcc5f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -4,15 +4,17 @@ // Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types #include "Globals.h" + #include "../Bindings/PluginManager.h" #include "ProjectileEntity.h" #include "../ClientHandle.h" -#include "Player.h" #include "../LineBlockTracer.h" #include "../BoundingBox.h" #include "../ChunkMap.h" #include "../Chunk.h" +#include "ProjectileArrow.h" + @@ -406,197 +408,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cArrowEntity: - -cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), - m_PickupState(psNoPickup), - m_DamageCoeff(2), - m_IsCritical(false), - m_Timer(0), - m_HitGroundTimer(0), - m_bIsCollected(false), - m_HitBlockPos(Vector3i(0, 0, 0)) -{ - SetSpeed(a_Speed); - SetMass(0.1); - SetYawFromSpeed(); - SetPitchFromSpeed(); - LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", - m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetYaw(), GetPitch() - ); -} - - - - - -cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : - super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), - m_PickupState(psInSurvivalOrCreative), - m_DamageCoeff(2), - m_IsCritical((a_Force >= 1)), - m_Timer(0), - m_HitGroundTimer(0), - m_HasTeleported(false), - m_bIsCollected(false), - m_HitBlockPos(0, 0, 0) -{ -} - - - - - -bool cArrowEntity::CanPickup(const cPlayer & a_Player) const -{ - switch (m_PickupState) - { - case psNoPickup: return false; - case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); - case psInCreative: return a_Player.IsGameModeCreative(); - } - ASSERT(!"Unhandled pickup state"); - return false; -} - - - - - -void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - if (a_HitFace == BLOCK_FACE_NONE) { return; } - - super::OnHitSolidBlock(a_HitPos, a_HitFace); - int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; - - switch (a_HitFace) - { - case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed - case BLOCK_FACE_YM: - { - break; - } - default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); - } - - m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); - - // Broadcast arrow hit sound - m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); -} - - - - - -void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) - { - // Not an entity that interacts with an arrow - return; - } - - int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); - if (m_IsCritical) - { - Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); - } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); - - // Broadcast successful hit sound - m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - - Destroy(); -} - - - - - -void cArrowEntity::CollectedBy(cPlayer * a_Dest) -{ - if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) - { - int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); - if (NumAdded > 0) // Only play effects if there was space in inventory - { - m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); - // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - m_bIsCollected = true; - } - } -} - - - - - -void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt; - - if (m_bIsCollected) - { - if (m_Timer > 500.f) // 0.5 seconds - { - Destroy(); - return; - } - } - else if (m_Timer > 1000 * 60 * 5) // 5 minutes - { - Destroy(); - return; - } - - if (m_IsInGround) - { - // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL - // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) - // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync - // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position - - if (!m_HasTeleported) // Sent a teleport already, don't do again - { - if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case - { - m_World->BroadcastTeleportEntity(*this); - m_HasTeleported = true; - } - else - { - m_HitGroundTimer += a_Dt; - } - } - - int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - - if (Chunk == NULL) - { - // Inside an unloaded chunk, abort - return; - } - - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? - { - m_IsInGround = false; // Yes, begin simulating physics again - } - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownEggEntity: diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 731dd060e..2b2ed634c 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,94 +101,6 @@ protected: -class cArrowEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field - enum ePickupState - { - psNoPickup = 0, - psInSurvivalOrCreative = 1, - psInCreative = 2, - } ; - - // tolua_end - - CLASS_PROTODEF(cArrowEntity); - - /// Creates a new arrow with psNoPickup state and default damage modifier coeff - cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - - /// Creates a new arrow as shot by a player, initializes it from the player object - cArrowEntity(cPlayer & a_Player, double a_Force); - - // tolua_begin - - /// Returns whether the arrow can be picked up by players - ePickupState GetPickupState(void) const { return m_PickupState; } - - /// Sets a new pickup state - void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } - - /// Returns the damage modifier coeff. - double GetDamageCoeff(void) const { return m_DamageCoeff; } - - /// Sets the damage modifier coeff - void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } - - /// Returns true if the specified player can pick the arrow up - bool CanPickup(const cPlayer & a_Player) const; - - /// Returns true if the arrow is set as critical - bool IsCritical(void) const { return m_IsCritical; } - - /// Sets the IsCritical flag - void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } - - // tolua_end - -protected: - - /// Determines when the arrow can be picked up by players - ePickupState m_PickupState; - - /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow - double m_DamageCoeff; - - /// If true, the arrow deals more damage - bool m_IsCritical; - - /// Timer for pickup collection animation or five minute timeout - float m_Timer; - - /// Timer for client arrow position confirmation via TeleportEntity - float m_HitGroundTimer; - - // Whether the arrow has already been teleported into the proper position in the ground. - bool m_HasTeleported; - - /// If true, the arrow is in the process of being collected - don't go to anyone else - bool m_bIsCollected; - - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air - Vector3i m_HitBlockPos; - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void CollectedBy(cPlayer * a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - - // tolua_begin -} ; - - - - - class cThrownEggEntity : public cProjectileEntity { diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 410c5f512..a53d59b58 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -9,7 +9,7 @@ #pragma once -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 1685f40c5..3b9e1c5f4 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -3,6 +3,7 @@ #include "Skeleton.h" #include "../World.h" +#include "../Entities/ProjectileArrow.h" diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3282a827f..2f57d3cf1 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -26,7 +26,7 @@ Documentation: #include "../Root.h" #include "../Server.h" -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..4f2fb7158 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -31,6 +31,7 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" +#include "../Entities/ProjectileArrow.h" diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 773954f73..02ced7038 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -28,7 +28,7 @@ #include "../Entities/Boat.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 66144dbd5..b70c3a95b 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -36,7 +36,7 @@ #include "../Entities/FallingBlock.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From de23a115a5a33a864111262f4dae08b524af422f Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:02:47 -0700 Subject: Moved cThrownEggEntity out of ProjectileEntity.h --- src/Entities/ProjectileEgg.cpp | 59 +++++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileEgg.h | 39 ++++++++++++++++++++++++++ src/Entities/ProjectileEntity.cpp | 59 +-------------------------------------- src/Entities/ProjectileEntity.h | 32 --------------------- src/WorldStorage/WSSAnvil.cpp | 2 +- 5 files changed, 100 insertions(+), 91 deletions(-) create mode 100644 src/Entities/ProjectileEgg.cpp create mode 100644 src/Entities/ProjectileEgg.h (limited to 'src') diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp new file mode 100644 index 000000000..61d61e1c6 --- /dev/null +++ b/src/Entities/ProjectileEgg.cpp @@ -0,0 +1,59 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileEgg.h" +#include "../World.h" + + + + + +cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TrySpawnChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TrySpawnChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) +{ + if (m_World->GetTickRandomNumber(7) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } + else if (m_World->GetTickRandomNumber(32) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h new file mode 100644 index 000000000..464526dfc --- /dev/null +++ b/src/Entities/ProjectileEgg.h @@ -0,0 +1,39 @@ +// +// ProjectileEgg.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownEggEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEggEntity); + + cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // tolua_end + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // Randomly decides whether to spawn a chicken where the egg lands. + void TrySpawnChicken(const Vector3d & a_HitPos); + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 079adcc5f..b4c162e35 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -14,6 +14,7 @@ #include "../Chunk.h" #include "ProjectileArrow.h" +#include "ProjectileEgg.h" @@ -408,64 +409,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownEggEntity: - -cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - TrySpawnChicken(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TrySpawnChicken(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) -{ - if (m_World->GetTickRandomNumber(7) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } - else if (m_World->GetTickRandomNumber(32) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownEnderPearlEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 2b2ed634c..74f72c5d1 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,38 +101,6 @@ protected: -class cThrownEggEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEggEntity); - - cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // tolua_end - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // Randomly decides whether to spawn a chicken where the egg lands. - void TrySpawnChicken(const Vector3d & a_HitPos); - - // tolua_begin - -} ; - - - - - class cThrownEnderPearlEntity : public cProjectileEntity { diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index b70c3a95b..abf8bd56c 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -27,7 +27,6 @@ #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" - #include "../Mobs/Monster.h" #include "../Mobs/IncludeAllMonsters.h" @@ -37,6 +36,7 @@ #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" #include "../Entities/ProjectileArrow.h" +#include "../Entities/ProjectileEgg.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From bc5c28a0beef335edf3b930e069b9152ef0a912f Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:08:39 -0700 Subject: Moved cThrownEnderPearl out of ProjectileEntity.h --- src/Entities/ProjectileEnderPearl.cpp | 54 ++++++++++++++++++++++++++++++++++ src/Entities/ProjectileEnderPearl.h | 39 +++++++++++++++++++++++++ src/Entities/ProjectileEntity.cpp | 55 +---------------------------------- src/Entities/ProjectileEntity.h | 32 -------------------- src/WorldStorage/WSSAnvil.cpp | 1 + 5 files changed, 95 insertions(+), 86 deletions(-) create mode 100644 src/Entities/ProjectileEnderPearl.cpp create mode 100644 src/Entities/ProjectileEnderPearl.h (limited to 'src') diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp new file mode 100644 index 000000000..4e848f189 --- /dev/null +++ b/src/Entities/ProjectileEnderPearl.cpp @@ -0,0 +1,54 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileEnderPearl.h" + + + + + +cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportCreator(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportCreator(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) +{ + // Teleport the creator here, make them take 5 damage: + if (m_Creator != NULL) + { + m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); + m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h new file mode 100644 index 000000000..d6d052428 --- /dev/null +++ b/src/Entities/ProjectileEnderPearl.h @@ -0,0 +1,39 @@ +// +// ProjectileEnderPearl.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownEnderPearlEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEnderPearlEntity); + + cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // tolua_end + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b4c162e35..d7e1f56a7 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -15,6 +15,7 @@ #include "ProjectileArrow.h" #include "ProjectileEgg.h" +#include "ProjectileEnderPearl.h" @@ -409,60 +410,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownEnderPearlEntity : - -cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // TODO: Tweak a_HitPos based on block face. - TeleportCreator(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TeleportCreator(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) -{ - // Teleport the creator here, make them take 5 damage: - if (m_Creator != NULL) - { - m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); - m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownSnowballEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 74f72c5d1..5523e2f8b 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,38 +101,6 @@ protected: -class cThrownEnderPearlEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEnderPearlEntity); - - cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // tolua_end - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // Teleports the creator where the ender pearl lands. - void TeleportCreator(const Vector3d & a_HitPos); - - // tolua_begin - -} ; - - - - - class cThrownSnowballEntity : public cProjectileEntity { diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index abf8bd56c..fc161cb34 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -37,6 +37,7 @@ #include "../Entities/Pickup.h" #include "../Entities/ProjectileArrow.h" #include "../Entities/ProjectileEgg.h" +#include "../Entities/ProjectileEnderPearl.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From 2f9580ad650ff69e71991b87d6b554ce080624a3 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:19:45 -0700 Subject: Moved cExpBottleEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 27 +-------------------------- src/Entities/ProjectileEntity.h | 26 -------------------------- src/Entities/ProjectileExpBottle.cpp | 27 +++++++++++++++++++++++++++ src/Entities/ProjectileExpBottle.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 src/Entities/ProjectileExpBottle.cpp create mode 100644 src/Entities/ProjectileExpBottle.h (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index d7e1f56a7..6060b56df 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -16,6 +16,7 @@ #include "ProjectileArrow.h" #include "ProjectileEgg.h" #include "ProjectileEnderPearl.h" +#include "ProjectileExpBottle.h" @@ -457,32 +458,6 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cBottleOEnchantingEntity : - -cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // Spawn an experience orb with a reward between 3 and 11. - m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); - - Destroy(); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFireworkEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 5523e2f8b..de0df6cb5 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -128,32 +128,6 @@ protected: -class cExpBottleEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cExpBottleEntity); - - cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - - // tolua_begin - -}; - - - - - class cFireworkEntity : public cProjectileEntity { diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp new file mode 100644 index 000000000..3af2b4a4a --- /dev/null +++ b/src/Entities/ProjectileExpBottle.cpp @@ -0,0 +1,27 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileExpBottle.h" +#include "../World.h" + + + + + +cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // Spawn an experience orb with a reward between 3 and 11. + m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); + + Destroy(); +} \ No newline at end of file diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h new file mode 100644 index 000000000..1f9482bf2 --- /dev/null +++ b/src/Entities/ProjectileExpBottle.h @@ -0,0 +1,33 @@ +// +// ProjectileExpBottle.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cExpBottleEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cExpBottleEntity); + + cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + + // tolua_begin + +}; \ No newline at end of file -- cgit v1.2.3 From 08b77f488041e99d4b53173f85ee9b8bcc3e9493 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:24:44 -0700 Subject: Moved cThrownSnowballEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 48 +------------------------------------ src/Entities/ProjectileEntity.h | 27 --------------------- src/Entities/ProjectileSnowball.cpp | 48 +++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileSnowball.h | 34 ++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.cpp | 1 + 5 files changed, 84 insertions(+), 74 deletions(-) create mode 100644 src/Entities/ProjectileSnowball.cpp create mode 100644 src/Entities/ProjectileSnowball.h (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 6060b56df..6b137ebe7 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -17,6 +17,7 @@ #include "ProjectileEgg.h" #include "ProjectileEnderPearl.h" #include "ProjectileExpBottle.h" +#include "ProjectileSnowball.h" @@ -411,53 +412,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownSnowballEntity : - -cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); -} - - - - - -void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - if (a_EntityHit.IsMob()) - { - cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); - if (MobType == cMonster::mtBlaze) - { - TotalDamage = 3; - } - else if (MobType == cMonster::mtEnderDragon) - { - TotalDamage = 1; - } - } - // TODO: If entity is Ender Crystal, destroy it - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFireworkEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index de0df6cb5..2c461d546 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,33 +101,6 @@ protected: -class cThrownSnowballEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownSnowballEntity); - - cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // tolua_begin - -} ; - - - - - class cFireworkEntity : public cProjectileEntity { diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp new file mode 100644 index 000000000..bc056d289 --- /dev/null +++ b/src/Entities/ProjectileSnowball.cpp @@ -0,0 +1,48 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileSnowball.h" +#include "../World.h" + + + + + +cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); +} + + + + + +void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + if (a_EntityHit.IsMob()) + { + cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); + if (MobType == cMonster::mtBlaze) + { + TotalDamage = 3; + } + else if (MobType == cMonster::mtEnderDragon) + { + TotalDamage = 1; + } + } + // TODO: If entity is Ender Crystal, destroy it + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} \ No newline at end of file diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h new file mode 100644 index 000000000..5bc6f0daa --- /dev/null +++ b/src/Entities/ProjectileSnowball.h @@ -0,0 +1,34 @@ +// +// ProjectileEgg.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownSnowballEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownSnowballEntity); + + cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index fc161cb34..c8d9dd25a 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -38,6 +38,7 @@ #include "../Entities/ProjectileArrow.h" #include "../Entities/ProjectileEgg.h" #include "../Entities/ProjectileEnderPearl.h" +#include "../Entities/ProjectileSnowball.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From de7eaa573560253c9e78fbfa6614cd60763383bf Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:35:31 -0700 Subject: Moved cFireChargeEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 56 ++--------------------------------- src/Entities/ProjectileEntity.h | 28 ------------------ src/Entities/ProjectileFireCharge.cpp | 50 +++++++++++++++++++++++++++++++ src/Entities/ProjectileFireCharge.h | 36 ++++++++++++++++++++++ src/Mobs/Blaze.cpp | 1 + src/WorldStorage/WSSAnvil.cpp | 1 + 6 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 src/Entities/ProjectileFireCharge.cpp create mode 100644 src/Entities/ProjectileFireCharge.h (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 6b137ebe7..ab7753d41 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -18,6 +18,7 @@ #include "ProjectileEnderPearl.h" #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" +#include "ProjectileFireCharge.h" @@ -520,57 +521,4 @@ void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cFireChargeEntity : - -cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) - { - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); - } -} - - - - - -void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); - - // TODO: Some entities are immune to hits - a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} - - - - +} \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 2c461d546..d2cca9c75 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -165,34 +165,6 @@ protected: -class cFireChargeEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireChargeEntity); - - cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // tolua_begin - -} ; - - - - // tolua_end diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp new file mode 100644 index 000000000..38ba95724 --- /dev/null +++ b/src/Entities/ProjectileFireCharge.cpp @@ -0,0 +1,50 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileFireCharge.h" +#include "../World.h" + + + + + +cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + { + m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); + } +} + + + + + +void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + + // TODO: Some entities are immune to hits + a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning +} \ No newline at end of file diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h new file mode 100644 index 000000000..6c088c547 --- /dev/null +++ b/src/Entities/ProjectileFireCharge.h @@ -0,0 +1,36 @@ +// +// ProjectileFireCharge.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cFireChargeEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireChargeEntity); + + cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 84ff8929b..74683da94 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -3,6 +3,7 @@ #include "Blaze.h" #include "../World.h" +#include "../Entities/ProjectileFireCharge.h" diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index c8d9dd25a..43b5ab4a7 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -39,6 +39,7 @@ #include "../Entities/ProjectileEgg.h" #include "../Entities/ProjectileEnderPearl.h" #include "../Entities/ProjectileSnowball.h" +#include "../Entities/ProjectileFireCharge.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From cb93a57963257a905334489fcca8d164999dcf50 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:41:07 -0700 Subject: Moved cGhastFireballEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 44 +------------------------------- src/Entities/ProjectileEntity.h | 31 ---------------------- src/Entities/ProjectileGhastFireball.cpp | 44 ++++++++++++++++++++++++++++++++ src/Entities/ProjectileGhastFireball.h | 38 +++++++++++++++++++++++++++ src/Mobs/Ghast.cpp | 1 + src/WorldStorage/WSSAnvil.cpp | 1 + 6 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 src/Entities/ProjectileGhastFireball.cpp create mode 100644 src/Entities/ProjectileGhastFireball.h (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ab7753d41..3a5ac059b 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -19,6 +19,7 @@ #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" #include "ProjectileFireCharge.h" +#include "ProjectileGhastFireball.h" @@ -478,47 +479,4 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) } m_ExplodeTimer++; -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cGhastFireballEntity : - -cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); -} - - - - - -void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); } \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index d2cca9c75..c9b1588ef 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -134,37 +134,6 @@ private: -class cGhastFireballEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cGhastFireballEntity); - - cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // TODO: Deflecting the fireballs by arrow- or sword- hits - - // tolua_begin - -} ; - - - - - // tolua_end diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp new file mode 100644 index 000000000..b8325aea2 --- /dev/null +++ b/src/Entities/ProjectileGhastFireball.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileGhastFireball.h" +#include "../World.h" + + + + + +cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); +} + + + + + +void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} \ No newline at end of file diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h new file mode 100644 index 000000000..7aee1689a --- /dev/null +++ b/src/Entities/ProjectileGhastFireball.h @@ -0,0 +1,38 @@ +// +// ProjectileGhastFireball.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cGhastFireballEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cGhastFireballEntity); + + cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // TODO: Deflecting the fireballs by arrow- or sword- hits + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index fe18f5e76..7b82d3181 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -3,6 +3,7 @@ #include "Ghast.h" #include "../World.h" +#include "../Entities/ProjectileGhastFireball.h" diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 43b5ab4a7..e702c4f1e 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -40,6 +40,7 @@ #include "../Entities/ProjectileEnderPearl.h" #include "../Entities/ProjectileSnowball.h" #include "../Entities/ProjectileFireCharge.h" +#include "../Entities/ProjectileGhastFireball.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From e3c3795aa40e59af86d90b45b209f367563942fb Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:50:05 -0700 Subject: Moved cFireworkEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 72 +----------------------------------- src/Entities/ProjectileEntity.h | 45 +---------------------- src/Entities/ProjectileFirework.cpp | 73 +++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileFirework.h | 40 ++++++++++++++++++++ src/Protocol/Protocol17x.cpp | 1 + 5 files changed, 116 insertions(+), 115 deletions(-) create mode 100644 src/Entities/ProjectileFirework.cpp create mode 100644 src/Entities/ProjectileFirework.h (limited to 'src') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 3a5ac059b..4784d4b0c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -19,6 +19,7 @@ #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" #include "ProjectileFireCharge.h" +#include "ProjectileFirework.h" #include "ProjectileGhastFireball.h" @@ -408,75 +409,4 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) { // Overriden in arrow UNUSED(a_Dest); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cFireworkEntity : - -cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : -super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), - m_ExplodeTimer(0), - m_FireworkItem(a_Item) -{ -} - - - - - -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) -{ - int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosY = POSY_TOINT; - - if ((PosY < 0) || (PosY >= cChunkDef::Height)) - { - goto setspeed; - } - - if (m_IsInGround) - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) - { - m_IsInGround = false; - } - else - { - return; - } - } - else - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) - { - OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); - return; - } - } - -setspeed: - AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); -} - - - - - -void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - - if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) - { - m_World->BroadcastEntityStatus(*this, esFireworkExploding); - Destroy(); - } - - m_ExplodeTimer++; } \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index c9b1588ef..e98652206 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,47 +94,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; - // tolua_begin -} ; - - - - - -class cFireworkEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireworkEntity); - - cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); - const cItem & GetItem(void) const { return m_FireworkItem; } - -protected: - - // cProjectileEntity overrides: - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -private: - - int m_ExplodeTimer; - cItem m_FireworkItem; - - // tolua_begin - -}; - - - - - -// tolua_end - - - +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp new file mode 100644 index 000000000..e884361c4 --- /dev/null +++ b/src/Entities/ProjectileFirework.cpp @@ -0,0 +1,73 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileFirework.h" +#include "../World.h" +#include "../Chunk.h" + + + + + +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : +super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), +m_ExplodeTimer(0), +m_FireworkItem(a_Item) +{ +} + + + + + +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + int PosY = POSY_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) + { + goto setspeed; + } + + if (m_IsInGround) + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) + { + m_IsInGround = false; + } + else + { + return; + } + } + else + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) + { + OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); + return; + } + } + +setspeed: + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); +} + + + + + +void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) + { + m_World->BroadcastEntityStatus(*this, esFireworkExploding); + Destroy(); + } + + m_ExplodeTimer++; +} \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h new file mode 100644 index 000000000..74a50264b --- /dev/null +++ b/src/Entities/ProjectileFirework.h @@ -0,0 +1,40 @@ +// +// ProjectileFirework.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cFireworkEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireworkEntity); + + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + const cItem & GetItem(void) const { return m_FireworkItem; } + +protected: + + // cProjectileEntity overrides: + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + int m_ExplodeTimer; + cItem m_FireworkItem; + + // tolua_begin + +}; \ No newline at end of file diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4f2fb7158..468c4cf2b 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -32,6 +32,7 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" #include "../Entities/ProjectileArrow.h" +#include "../Entities/ProjectileFirework.h" -- cgit v1.2.3 From cc39d314aee46ea608dd7d06bcc482a58898202e Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:58:06 -0700 Subject: Fixed ToLua issues --- src/CMakeLists.txt | 8 ++++++++ src/Entities/ProjectileArrow.h | 3 ++- src/Entities/ProjectileEgg.h | 6 ++---- src/Entities/ProjectileEnderPearl.h | 6 ++---- src/Entities/ProjectileExpBottle.h | 4 ++-- src/Entities/ProjectileFireCharge.h | 4 ++-- src/Entities/ProjectileFirework.h | 4 ++-- src/Entities/ProjectileGhastFireball.h | 4 ++-- src/Entities/ProjectileSnowball.h | 4 ++-- 9 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cc5fcb1e..2f433c29c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,14 @@ if (NOT MSVC) Entities/Pickup.h Entities/Player.h Entities/ProjectileEntity.h + Entities/ProjectileArrow.h + Entities/ProjectileEgg.h + Entities/ProjectileEnderPearl.h + Entities/ProjectileExpBottle.h + Entities/ProjectileSnowball.h + Entities/ProjectileFireCharge.h + Entities/ProjectileFirework.h + Entities/ProjectileGhastFireball.h Entities/TNTEntity.h Entities/ExpOrb.h Entities/HangingEntity.h diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h index c08b7acc5..8be0ecb7c 100644 --- a/src/Entities/ProjectileArrow.h +++ b/src/Entities/ProjectileArrow.h @@ -10,6 +10,8 @@ +// tolua_begin + class cArrowEntity : public cProjectileEntity { @@ -91,5 +93,4 @@ protected: virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - // tolua_begin }; \ No newline at end of file diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h index 464526dfc..eac2650d0 100644 --- a/src/Entities/ProjectileEgg.h +++ b/src/Entities/ProjectileEgg.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownEggEntity : public cProjectileEntity { @@ -25,8 +27,6 @@ public: protected: - // tolua_end - // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; @@ -34,6 +34,4 @@ protected: // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h index d6d052428..3ebf0fb3f 100644 --- a/src/Entities/ProjectileEnderPearl.h +++ b/src/Entities/ProjectileEnderPearl.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownEnderPearlEntity : public cProjectileEntity { @@ -25,8 +27,6 @@ public: protected: - // tolua_end - // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; @@ -34,6 +34,4 @@ protected: // Teleports the creator where the ender pearl lands. void TeleportCreator(const Vector3d & a_HitPos); - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h index 1f9482bf2..94843c51b 100644 --- a/src/Entities/ProjectileExpBottle.h +++ b/src/Entities/ProjectileExpBottle.h @@ -10,6 +10,8 @@ +// tolua_begin + class cExpBottleEntity : public cProjectileEntity { @@ -28,6 +30,4 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - // tolua_begin - }; \ No newline at end of file diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h index 6c088c547..ba556f228 100644 --- a/src/Entities/ProjectileFireCharge.h +++ b/src/Entities/ProjectileFireCharge.h @@ -10,6 +10,8 @@ +// tolua_begin + class cFireChargeEntity : public cProjectileEntity { @@ -31,6 +33,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h index 74a50264b..fe90a44a1 100644 --- a/src/Entities/ProjectileFirework.h +++ b/src/Entities/ProjectileFirework.h @@ -10,6 +10,8 @@ +// tolua_begin + class cFireworkEntity : public cProjectileEntity { @@ -35,6 +37,4 @@ private: int m_ExplodeTimer; cItem m_FireworkItem; - // tolua_begin - }; \ No newline at end of file diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h index 7aee1689a..f37eb42c9 100644 --- a/src/Entities/ProjectileGhastFireball.h +++ b/src/Entities/ProjectileGhastFireball.h @@ -10,6 +10,8 @@ +// tolua_begin + class cGhastFireballEntity : public cProjectileEntity { @@ -33,6 +35,4 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h index 5bc6f0daa..392bd8462 100644 --- a/src/Entities/ProjectileSnowball.h +++ b/src/Entities/ProjectileSnowball.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownSnowballEntity : public cProjectileEntity { @@ -29,6 +31,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // tolua_begin - } ; \ No newline at end of file -- cgit v1.2.3 From fdac27c63d2587793de40d9d78eb76386c823b31 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 17:31:40 +0200 Subject: Another attempt at #889. The packet was being sent after the state was adjusted, so another thread *may* have sent another packet in the meantime. --- src/Protocol/Protocol17x.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e57b551cb..8f9e3abd8 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -637,9 +637,11 @@ void cProtocol172::SendLoginSuccess(void) { ASSERT(m_State == 2); // State: login? - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(m_Client->GetUUID()); - Pkt.WriteString(m_Client->GetUsername()); + { + cPacketizer Pkt(*this, 0x02); // Login success packet + Pkt.WriteString(m_Client->GetUUID()); + Pkt.WriteString(m_Client->GetUsername()); + } m_State = 3; // State = Game } -- cgit v1.2.3 From 15324f3bbdaf7529636cc1930e1c1b87ef911d86 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 09:42:31 -0700 Subject: Fixed ToLua errors, added newlines --- src/Entities/ProjectileArrow.cpp | 2 +- src/Entities/ProjectileArrow.h | 2 +- src/Entities/ProjectileEgg.cpp | 2 +- src/Entities/ProjectileEgg.h | 2 +- src/Entities/ProjectileEnderPearl.cpp | 2 +- src/Entities/ProjectileEnderPearl.h | 2 +- src/Entities/ProjectileEntity.cpp | 2 +- src/Entities/ProjectileEntity.h | 2 +- src/Entities/ProjectileExpBottle.cpp | 2 +- src/Entities/ProjectileExpBottle.h | 2 +- src/Entities/ProjectileFireCharge.cpp | 2 +- src/Entities/ProjectileFireCharge.h | 2 +- src/Entities/ProjectileFirework.cpp | 2 +- src/Entities/ProjectileFirework.h | 2 +- src/Entities/ProjectileGhastFireball.cpp | 2 +- src/Entities/ProjectileGhastFireball.h | 2 +- src/Entities/ProjectileSnowball.cpp | 2 +- src/Entities/ProjectileSnowball.h | 4 ++-- 18 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp index bd4f2abab..8bf680797 100644 --- a/src/Entities/ProjectileArrow.cpp +++ b/src/Entities/ProjectileArrow.cpp @@ -190,4 +190,4 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) m_IsInGround = false; // Yes, begin simulating physics again } } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h index 8be0ecb7c..18c30feae 100644 --- a/src/Entities/ProjectileArrow.h +++ b/src/Entities/ProjectileArrow.h @@ -93,4 +93,4 @@ protected: virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp index 61d61e1c6..3f6e6525e 100644 --- a/src/Entities/ProjectileEgg.cpp +++ b/src/Entities/ProjectileEgg.cpp @@ -56,4 +56,4 @@ void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h index eac2650d0..ba1f6420e 100644 --- a/src/Entities/ProjectileEgg.h +++ b/src/Entities/ProjectileEgg.h @@ -34,4 +34,4 @@ protected: // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp index 4e848f189..db32f47b7 100644 --- a/src/Entities/ProjectileEnderPearl.cpp +++ b/src/Entities/ProjectileEnderPearl.cpp @@ -51,4 +51,4 @@ void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h index 3ebf0fb3f..39761ff48 100644 --- a/src/Entities/ProjectileEnderPearl.h +++ b/src/Entities/ProjectileEnderPearl.h @@ -34,4 +34,4 @@ protected: // Teleports the creator where the ender pearl lands. void TeleportCreator(const Vector3d & a_HitPos); -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 4784d4b0c..b2e6d469e 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -409,4 +409,4 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) { // Overriden in arrow UNUSED(a_Dest); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e98652206..ae06b072f 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,4 +94,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp index 3af2b4a4a..936be6a72 100644 --- a/src/Entities/ProjectileExpBottle.cpp +++ b/src/Entities/ProjectileExpBottle.cpp @@ -24,4 +24,4 @@ void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); Destroy(); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h index 94843c51b..070c412e4 100644 --- a/src/Entities/ProjectileExpBottle.h +++ b/src/Entities/ProjectileExpBottle.h @@ -30,4 +30,4 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp index 38ba95724..5bdb74462 100644 --- a/src/Entities/ProjectileFireCharge.cpp +++ b/src/Entities/ProjectileFireCharge.cpp @@ -47,4 +47,4 @@ void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hi // TODO: Some entities are immune to hits a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h index ba556f228..bcf2b7af6 100644 --- a/src/Entities/ProjectileFireCharge.h +++ b/src/Entities/ProjectileFireCharge.h @@ -33,4 +33,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp index e884361c4..dcb89fce3 100644 --- a/src/Entities/ProjectileFirework.cpp +++ b/src/Entities/ProjectileFirework.cpp @@ -70,4 +70,4 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) } m_ExplodeTimer++; -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h index fe90a44a1..e7d7eacbf 100644 --- a/src/Entities/ProjectileFirework.h +++ b/src/Entities/ProjectileFirework.h @@ -37,4 +37,4 @@ private: int m_ExplodeTimer; cItem m_FireworkItem; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp index b8325aea2..cac622562 100644 --- a/src/Entities/ProjectileGhastFireball.cpp +++ b/src/Entities/ProjectileGhastFireball.cpp @@ -41,4 +41,4 @@ void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h index f37eb42c9..6dd37783e 100644 --- a/src/Entities/ProjectileGhastFireball.h +++ b/src/Entities/ProjectileGhastFireball.h @@ -35,4 +35,4 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp index bc056d289..536b9e791 100644 --- a/src/Entities/ProjectileSnowball.cpp +++ b/src/Entities/ProjectileSnowball.cpp @@ -45,4 +45,4 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h index 392bd8462..2443d05c6 100644 --- a/src/Entities/ProjectileSnowball.h +++ b/src/Entities/ProjectileSnowball.h @@ -1,5 +1,5 @@ // -// ProjectileEgg.h +// ProjectileSnowball.h // #pragma once @@ -31,4 +31,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; \ No newline at end of file +} ; // tolua_export -- cgit v1.2.3 From 75bb36574b4bb78e8b5975bf905a97402fd8a4bb Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 10:01:50 -0700 Subject: Creative players cannot throw ender pearls. --- src/Items/ItemThrowable.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index c6a4e714e..f1ebb4508 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -89,6 +89,22 @@ public: super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30) { } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + // Creative players cannot throw ender pearls. + if (a_Player->IsGameModeCreative()) + { + return false; + } + + a_Player->GetInventory().RemoveOneEquippedItem(); + Vector3d Pos = a_Player->GetThrowStartPos(); + Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; + a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed); + + return true; + } } ; -- cgit v1.2.3 From cd38e792b7aac453549d1e9fea21ad94b8ea655a Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 10:24:39 -0700 Subject: Revert "Creative players cannot throw ender pearls." This reverts commit 75bb36574b4bb78e8b5975bf905a97402fd8a4bb. --- src/Items/ItemThrowable.h | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src') diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index f1ebb4508..c6a4e714e 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -89,22 +89,6 @@ public: super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30) { } - - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override - { - // Creative players cannot throw ender pearls. - if (a_Player->IsGameModeCreative()) - { - return false; - } - - a_Player->GetInventory().RemoveOneEquippedItem(); - Vector3d Pos = a_Player->GetThrowStartPos(); - Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; - a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed); - - return true; - } } ; -- cgit v1.2.3 From bef3c6d47daaa5ed69d4c0d300d1ae324b99c6de Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 27 Apr 2014 20:26:50 +0300 Subject: Added some comments --- src/Statistics.cpp | 2 +- src/Statistics.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Statistics.cpp b/src/Statistics.cpp index 30904db4b..2c980d98e 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -8,7 +8,7 @@ cStatInfo cStatInfo::ms_Info[statCount] = { - // Do NOT change the order + // The order must match the order of enum eStatistic // http://minecraft.gamepedia.com/Achievements diff --git a/src/Statistics.h b/src/Statistics.h index c6e1cf910..540df38cc 100644 --- a/src/Statistics.h +++ b/src/Statistics.h @@ -11,7 +11,7 @@ enum eStatistic { - // Do NOT change the order + // The order must match the order of cStatInfo::ms_Info statInvalid = -1, -- cgit v1.2.3 From ee354a405ba01a18ef85a8adae08c585cf2f13e7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 12:37:08 -0700 Subject: Fixed OnPluginMessage hook not exiting early. OnPluginMessage hook would call all plugins even after one returned true. Fixes CID 43512 --- src/Bindings/PluginLua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index dcc816839..cb55715a6 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1042,7 +1042,7 @@ bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Cha cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGIN_MESSAGE]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message); + m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message, cLuaState::Return, res); if (res) { return true; -- cgit v1.2.3 From d15743df1c734aa44f791a180fe041e95590c97b Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 12:41:22 -0700 Subject: Removed old unused code --- src/WebAdmin.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index a3b3cc5be..737705d7c 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -285,11 +285,6 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque Content = GetDefaultPage(); } - if (ShouldWrapInTemplate && (URL.size() > 1)) - { - Content += "\n

Go back

"; - } - int MemUsageKiB = cRoot::GetPhysicalRAMUsage(); if (MemUsageKiB > 0) { -- cgit v1.2.3 From 35dc88e4ff6ea3e1076b4ac167cb19002b182977 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 12:42:29 -0700 Subject: Removed Old Asserts Removed asserts about non-negative numbers on what are now unsigned types Fixes CID 43608 --- src/ByteBuffer.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index c634dc308..24f91b195 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -887,9 +887,7 @@ void cByteBuffer::AdvanceReadPos(size_t a_Count) void cByteBuffer::CheckValid(void) const { - ASSERT(m_ReadPos >= 0); ASSERT(m_ReadPos < m_BufferSize); - ASSERT(m_WritePos >= 0); ASSERT(m_WritePos < m_BufferSize); } -- cgit v1.2.3 From 25d933883a24c97b67f90ae6839ce3d6b8d630d5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:07:21 -0700 Subject: Removed unneeded assert Fixed CID 43610 --- src/Generating/Prefab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index c0c9e8a13..44d5097de 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -283,7 +283,7 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) if ((NumElements >= 3) && !CharDef[2].empty()) { BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str()); - ASSERT((BlockMeta >= 0) && (BlockMeta <= 15)); + ASSERT((BlockMeta <= 15)); } a_CharMapOut[Src].m_BlockMeta = BlockMeta; } // for itr - Lines[] -- cgit v1.2.3 From a2b1fa6520355e9f073fcb44897c6ee21a69df75 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:12:36 -0700 Subject: Initialised MetaArrays in BlockArea Fixes CID 43621 --- src/BlockArea.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 40cca8882..49c564ca5 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -663,8 +663,12 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R if (IsDummyMetas) { - SrcMetas = new NIBBLETYPE[a_Src.GetBlockCount()]; - DstMetas = new NIBBLETYPE[GetBlockCount()]; + size_t SrcCount = a_Src.GetBlockCount(); + size_t DestCount = GetBlockCount(); + SrcMetas = new NIBBLETYPE[SrcCount]; + DstMetas = new NIBBLETYPE[DestCount]; + memset(SrcMetas, 0, SrcCount); + memset(DstMetas, 0, DestCount); } switch (a_Strategy) -- cgit v1.2.3 From 71c51783f3fc73d7370714ebbb0cdd4c8206843c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:15:19 -0700 Subject: Initalize counter in fastrandom Fixes CID 43622 --- src/FastRandom.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp index c45261947..42bf5f3f9 100644 --- a/src/FastRandom.cpp +++ b/src/FastRandom.cpp @@ -91,7 +91,8 @@ int cFastRandom::m_SeedCounter = 0; cFastRandom::cFastRandom(void) : - m_Seed(m_SeedCounter++) + m_Seed(m_SeedCounter++), + m_Counter(0) { } -- cgit v1.2.3 From 077179277c5f3db46c5b805ae61506b99de7e851 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:20:00 -0700 Subject: Fixes to uninitallsed array access in Noise.cpp CID 43634, 43634 --- src/Noise.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Noise.cpp b/src/Noise.cpp index 95a022ea3..13a194938 100644 --- a/src/Noise.cpp +++ b/src/Noise.cpp @@ -608,6 +608,8 @@ void cCubicNoise::Generate2D( NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY ///< Noise-space coords of the array in the Y direction ) const { + ASSERT(a_SizeX > 0); + ASSERT(a_SizeY > 0); ASSERT(a_SizeX < MAX_SIZE); ASSERT(a_SizeY < MAX_SIZE); ASSERT(a_StartX < a_EndX); -- cgit v1.2.3 From 744e00c904ebde6c89aa4763f06118635694d396 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 27 Apr 2014 13:43:59 -0700 Subject: Worked around const pointer --- src/BlockArea.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 49c564ca5..e4b122fa2 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -665,9 +665,10 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R { size_t SrcCount = a_Src.GetBlockCount(); size_t DestCount = GetBlockCount(); - SrcMetas = new NIBBLETYPE[SrcCount]; + NIBBLETYPE * tempSrcMetas = new NIBBLETYPE[SrcCount]; + memset(tempSrcMetas, 0, SrcCount); + SrcMetas = tempSrcMetas; DstMetas = new NIBBLETYPE[DestCount]; - memset(SrcMetas, 0, SrcCount); memset(DstMetas, 0, DestCount); } -- cgit v1.2.3 From 4c165f8a6ddd40cee7769b622d4b357e1d35c26a Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 23:11:21 +0200 Subject: Fixed player spawning #953. --- src/ChunkMap.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 0fb6988b5..537d491c9 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1654,7 +1654,10 @@ void cChunkMap::AddEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); - if ((Chunk == NULL) || !Chunk->IsValid()) + if ( + (Chunk == NULL) || // Chunk not present at all + (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953) + ) { LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", a_Entity, a_Entity->GetClass(), a_Entity->GetUniqueID() -- cgit v1.2.3 From 9dc9713a9c3015d2b67fc18fc2fb8f3b5ce8d734 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 23:12:52 +0200 Subject: Fixed warnings. --- src/Entities/Entity.cpp | 1 + src/Mobs/AggressiveMonster.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 827b88717..2d325805b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -443,6 +443,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) } } ASSERT(!"Invalid damage type!"); + return false; } diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 4997952be..447bf3549 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -108,14 +108,14 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { - static const float epsilon = 0.000000000001; + static const float epsilon = 0.000000000001f; // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { return false; } // Difference between destination z and target z is negligible (to 10^-12 precision) - else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) + else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) { return false; } -- cgit v1.2.3 From 9b0cb3fd97701370915a9a5b3d5b237fa7f90e06 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 17:03:06 -0700 Subject: Fixed projectile source filenames, indentations --- src/CMakeLists.txt | 16 +-- src/Entities/ArrowEntity.cpp | 193 +++++++++++++++++++++++++++++++ src/Entities/ArrowEntity.h | 96 +++++++++++++++ src/Entities/ExpBottleEntity.cpp | 27 +++++ src/Entities/ExpBottleEntity.h | 33 ++++++ src/Entities/FireChargeEntity.cpp | 50 ++++++++ src/Entities/FireChargeEntity.h | 36 ++++++ src/Entities/FireworkEntity.cpp | 73 ++++++++++++ src/Entities/FireworkEntity.h | 40 +++++++ src/Entities/GhastFireballEntity.cpp | 44 +++++++ src/Entities/GhastFireballEntity.h | 38 ++++++ src/Entities/ProjectileArrow.cpp | 193 ------------------------------- src/Entities/ProjectileArrow.h | 96 --------------- src/Entities/ProjectileEgg.cpp | 59 ---------- src/Entities/ProjectileEgg.h | 37 ------ src/Entities/ProjectileEnderPearl.cpp | 54 --------- src/Entities/ProjectileEnderPearl.h | 37 ------ src/Entities/ProjectileEntity.cpp | 16 +-- src/Entities/ProjectileExpBottle.cpp | 27 ----- src/Entities/ProjectileExpBottle.h | 33 ------ src/Entities/ProjectileFireCharge.cpp | 50 -------- src/Entities/ProjectileFireCharge.h | 36 ------ src/Entities/ProjectileFirework.cpp | 73 ------------ src/Entities/ProjectileFirework.h | 40 ------- src/Entities/ProjectileGhastFireball.cpp | 44 ------- src/Entities/ProjectileGhastFireball.h | 38 ------ src/Entities/ProjectileSnowball.cpp | 48 -------- src/Entities/ProjectileSnowball.h | 34 ------ src/Entities/ThrownEggEntity.cpp | 59 ++++++++++ src/Entities/ThrownEggEntity.h | 37 ++++++ src/Entities/ThrownEnderPearlEntity.cpp | 54 +++++++++ src/Entities/ThrownEnderPearlEntity.h | 37 ++++++ src/Entities/ThrownSnowballEntity.cpp | 48 ++++++++ src/Entities/ThrownSnowballEntity.h | 34 ++++++ src/Items/ItemBow.h | 2 +- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Protocol/Protocol125.cpp | 2 +- src/Protocol/Protocol17x.cpp | 4 +- src/WorldStorage/NBTChunkSerializer.cpp | 2 +- src/WorldStorage/WSSAnvil.cpp | 12 +- 42 files changed, 929 insertions(+), 929 deletions(-) create mode 100644 src/Entities/ArrowEntity.cpp create mode 100644 src/Entities/ArrowEntity.h create mode 100644 src/Entities/ExpBottleEntity.cpp create mode 100644 src/Entities/ExpBottleEntity.h create mode 100644 src/Entities/FireChargeEntity.cpp create mode 100644 src/Entities/FireChargeEntity.h create mode 100644 src/Entities/FireworkEntity.cpp create mode 100644 src/Entities/FireworkEntity.h create mode 100644 src/Entities/GhastFireballEntity.cpp create mode 100644 src/Entities/GhastFireballEntity.h delete mode 100644 src/Entities/ProjectileArrow.cpp delete mode 100644 src/Entities/ProjectileArrow.h delete mode 100644 src/Entities/ProjectileEgg.cpp delete mode 100644 src/Entities/ProjectileEgg.h delete mode 100644 src/Entities/ProjectileEnderPearl.cpp delete mode 100644 src/Entities/ProjectileEnderPearl.h delete mode 100644 src/Entities/ProjectileExpBottle.cpp delete mode 100644 src/Entities/ProjectileExpBottle.h delete mode 100644 src/Entities/ProjectileFireCharge.cpp delete mode 100644 src/Entities/ProjectileFireCharge.h delete mode 100644 src/Entities/ProjectileFirework.cpp delete mode 100644 src/Entities/ProjectileFirework.h delete mode 100644 src/Entities/ProjectileGhastFireball.cpp delete mode 100644 src/Entities/ProjectileGhastFireball.h delete mode 100644 src/Entities/ProjectileSnowball.cpp delete mode 100644 src/Entities/ProjectileSnowball.h create mode 100644 src/Entities/ThrownEggEntity.cpp create mode 100644 src/Entities/ThrownEggEntity.h create mode 100644 src/Entities/ThrownEnderPearlEntity.cpp create mode 100644 src/Entities/ThrownEnderPearlEntity.h create mode 100644 src/Entities/ThrownSnowballEntity.cpp create mode 100644 src/Entities/ThrownSnowballEntity.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f433c29c..9fbaed926 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,14 +57,14 @@ if (NOT MSVC) Entities/Pickup.h Entities/Player.h Entities/ProjectileEntity.h - Entities/ProjectileArrow.h - Entities/ProjectileEgg.h - Entities/ProjectileEnderPearl.h - Entities/ProjectileExpBottle.h - Entities/ProjectileSnowball.h - Entities/ProjectileFireCharge.h - Entities/ProjectileFirework.h - Entities/ProjectileGhastFireball.h + Entities/ArrowEntity.h + Entities/ThrownEggEntity.h + Entities/ThrownEnderPearlEntity.h + Entities/ExpBottleEntity.h + Entities/ThrownSnowballEntity.h + Entities/FireChargeEntity.h + Entities/FireworkEntity.h + Entities/GhastFireballEntity.h Entities/TNTEntity.h Entities/ExpOrb.h Entities/HangingEntity.h diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp new file mode 100644 index 000000000..847b39bbc --- /dev/null +++ b/src/Entities/ArrowEntity.cpp @@ -0,0 +1,193 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Player.h" +#include "ArrowEntity.h" +#include "../Chunk.h" + + + + + +cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), + m_PickupState(psNoPickup), + m_DamageCoeff(2), + m_IsCritical(false), + m_Timer(0), + m_HitGroundTimer(0), + m_bIsCollected(false), + m_HitBlockPos(Vector3i(0, 0, 0)) +{ + SetSpeed(a_Speed); + SetMass(0.1); + SetYawFromSpeed(); + SetPitchFromSpeed(); + LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", + m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), + GetYaw(), GetPitch() + ); +} + + + + + +cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : + super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), + m_PickupState(psInSurvivalOrCreative), + m_DamageCoeff(2), + m_IsCritical((a_Force >= 1)), + m_Timer(0), + m_HitGroundTimer(0), + m_HasTeleported(false), + m_bIsCollected(false), + m_HitBlockPos(0, 0, 0) +{ +} + + + + + +bool cArrowEntity::CanPickup(const cPlayer & a_Player) const +{ + switch (m_PickupState) + { + case psNoPickup: return false; + case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); + case psInCreative: return a_Player.IsGameModeCreative(); + } + ASSERT(!"Unhandled pickup state"); + return false; +} + + + + + +void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + if (a_HitFace == BLOCK_FACE_NONE) { return; } + + super::OnHitSolidBlock(a_HitPos, a_HitFace); + int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; + + switch (a_HitFace) + { + case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed + case BLOCK_FACE_YM: + { + break; + } + default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); + } + + m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); + + // Broadcast arrow hit sound + m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); +} + + + + + +void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) + { + // Not an entity that interacts with an arrow + return; + } + + int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); + if (m_IsCritical) + { + Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); + } + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); + + // Broadcast successful hit sound + m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + + Destroy(); +} + + + + + +void cArrowEntity::CollectedBy(cPlayer * a_Dest) +{ + if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) + { + int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); + if (NumAdded > 0) // Only play effects if there was space in inventory + { + m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) + m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsCollected = true; + } + } +} + + + + + +void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + m_Timer += a_Dt; + + if (m_bIsCollected) + { + if (m_Timer > 500.f) // 0.5 seconds + { + Destroy(); + return; + } + } + else if (m_Timer > 1000 * 60 * 5) // 5 minutes + { + Destroy(); + return; + } + + if (m_IsInGround) + { + // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL + // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) + // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync + // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position + + if (!m_HasTeleported) // Sent a teleport already, don't do again + { + if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case + { + m_World->BroadcastTeleportEntity(*this); + m_HasTeleported = true; + } + else + { + m_HitGroundTimer += a_Dt; + } + } + + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; + int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); + + if (Chunk == NULL) + { + // Inside an unloaded chunk, abort + return; + } + + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + { + m_IsInGround = false; // Yes, begin simulating physics again + } + } +} diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h new file mode 100644 index 000000000..1fe3032ee --- /dev/null +++ b/src/Entities/ArrowEntity.h @@ -0,0 +1,96 @@ +// +// ArrowEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cArrowEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field + enum ePickupState + { + psNoPickup = 0, + psInSurvivalOrCreative = 1, + psInCreative = 2, + } ; + + // tolua_end + + CLASS_PROTODEF(cArrowEntity); + + /// Creates a new arrow with psNoPickup state and default damage modifier coeff + cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + + /// Creates a new arrow as shot by a player, initializes it from the player object + cArrowEntity(cPlayer & a_Player, double a_Force); + + // tolua_begin + + /// Returns whether the arrow can be picked up by players + ePickupState GetPickupState(void) const { return m_PickupState; } + + /// Sets a new pickup state + void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } + + /// Returns the damage modifier coeff. + double GetDamageCoeff(void) const { return m_DamageCoeff; } + + /// Sets the damage modifier coeff + void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } + + /// Returns true if the specified player can pick the arrow up + bool CanPickup(const cPlayer & a_Player) const; + + /// Returns true if the arrow is set as critical + bool IsCritical(void) const { return m_IsCritical; } + + /// Sets the IsCritical flag + void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } + + // tolua_end + +protected: + + /// Determines when the arrow can be picked up by players + ePickupState m_PickupState; + + /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow + double m_DamageCoeff; + + /// If true, the arrow deals more damage + bool m_IsCritical; + + /// Timer for pickup collection animation or five minute timeout + float m_Timer; + + /// Timer for client arrow position confirmation via TeleportEntity + float m_HitGroundTimer; + + // Whether the arrow has already been teleported into the proper position in the ground. + bool m_HasTeleported; + + /// If true, the arrow is in the process of being collected - don't go to anyone else + bool m_bIsCollected; + + /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air + Vector3i m_HitBlockPos; + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void CollectedBy(cPlayer * a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +}; // tolua_export diff --git a/src/Entities/ExpBottleEntity.cpp b/src/Entities/ExpBottleEntity.cpp new file mode 100644 index 000000000..202dde942 --- /dev/null +++ b/src/Entities/ExpBottleEntity.cpp @@ -0,0 +1,27 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ExpBottleEntity.h" +#include "../World.h" + + + + + +cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // Spawn an experience orb with a reward between 3 and 11. + m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); + + Destroy(); +} diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h new file mode 100644 index 000000000..b2043d8f1 --- /dev/null +++ b/src/Entities/ExpBottleEntity.h @@ -0,0 +1,33 @@ +// +// ExpBottleEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cExpBottleEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cExpBottleEntity); + + cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + +}; // tolua_export diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp new file mode 100644 index 000000000..aba32602f --- /dev/null +++ b/src/Entities/FireChargeEntity.cpp @@ -0,0 +1,50 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "FireChargeEntity.h" +#include "../World.h" + + + + + +cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + { + m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); + } +} + + + + + +void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + + // TODO: Some entities are immune to hits + a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning +} diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h new file mode 100644 index 000000000..3924c337c --- /dev/null +++ b/src/Entities/FireChargeEntity.h @@ -0,0 +1,36 @@ +// +// FireChargeEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cFireChargeEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireChargeEntity); + + cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + +} ; // tolua_export diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp new file mode 100644 index 000000000..403a53c84 --- /dev/null +++ b/src/Entities/FireworkEntity.cpp @@ -0,0 +1,73 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "FireworkEntity.h" +#include "../World.h" +#include "../Chunk.h" + + + + + +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : + super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), + m_ExplodeTimer(0), + m_FireworkItem(a_Item) +{ +} + + + + + +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + int PosY = POSY_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) + { + goto setspeed; + } + + if (m_IsInGround) + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) + { + m_IsInGround = false; + } + else + { + return; + } + } + else + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) + { + OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); + return; + } + } + +setspeed: + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); +} + + + + + +void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) + { + m_World->BroadcastEntityStatus(*this, esFireworkExploding); + Destroy(); + } + + m_ExplodeTimer++; +} diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h new file mode 100644 index 000000000..c62ca9402 --- /dev/null +++ b/src/Entities/FireworkEntity.h @@ -0,0 +1,40 @@ +// +// FireworkEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cFireworkEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireworkEntity); + + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + const cItem & GetItem(void) const { return m_FireworkItem; } + +protected: + + // cProjectileEntity overrides: + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + int m_ExplodeTimer; + cItem m_FireworkItem; + +}; // tolua_export diff --git a/src/Entities/GhastFireballEntity.cpp b/src/Entities/GhastFireballEntity.cpp new file mode 100644 index 000000000..9e4cb387e --- /dev/null +++ b/src/Entities/GhastFireballEntity.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "GhastFireballEntity.h" +#include "../World.h" + + + + + +cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); +} + + + + + +void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h new file mode 100644 index 000000000..9e4572c78 --- /dev/null +++ b/src/Entities/GhastFireballEntity.h @@ -0,0 +1,38 @@ +// +// GhastFireballEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cGhastFireballEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cGhastFireballEntity); + + cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // TODO: Deflecting the fireballs by arrow- or sword- hits + +} ; // tolua_export diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp deleted file mode 100644 index 8bf680797..000000000 --- a/src/Entities/ProjectileArrow.cpp +++ /dev/null @@ -1,193 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Player.h" -#include "ProjectileArrow.h" -#include "../Chunk.h" - - - - - -cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), -m_PickupState(psNoPickup), -m_DamageCoeff(2), -m_IsCritical(false), -m_Timer(0), -m_HitGroundTimer(0), -m_bIsCollected(false), -m_HitBlockPos(Vector3i(0, 0, 0)) -{ - SetSpeed(a_Speed); - SetMass(0.1); - SetYawFromSpeed(); - SetPitchFromSpeed(); - LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", - m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetYaw(), GetPitch() - ); -} - - - - - -cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : -super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), -m_PickupState(psInSurvivalOrCreative), -m_DamageCoeff(2), -m_IsCritical((a_Force >= 1)), -m_Timer(0), -m_HitGroundTimer(0), -m_HasTeleported(false), -m_bIsCollected(false), -m_HitBlockPos(0, 0, 0) -{ -} - - - - - -bool cArrowEntity::CanPickup(const cPlayer & a_Player) const -{ - switch (m_PickupState) - { - case psNoPickup: return false; - case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); - case psInCreative: return a_Player.IsGameModeCreative(); - } - ASSERT(!"Unhandled pickup state"); - return false; -} - - - - - -void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - if (a_HitFace == BLOCK_FACE_NONE) { return; } - - super::OnHitSolidBlock(a_HitPos, a_HitFace); - int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; - - switch (a_HitFace) - { - case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed - case BLOCK_FACE_YM: - { - break; - } - default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); - } - - m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); - - // Broadcast arrow hit sound - m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); -} - - - - - -void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) - { - // Not an entity that interacts with an arrow - return; - } - - int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); - if (m_IsCritical) - { - Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); - } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); - - // Broadcast successful hit sound - m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - - Destroy(); -} - - - - - -void cArrowEntity::CollectedBy(cPlayer * a_Dest) -{ - if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) - { - int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); - if (NumAdded > 0) // Only play effects if there was space in inventory - { - m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); - // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - m_bIsCollected = true; - } - } -} - - - - - -void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt; - - if (m_bIsCollected) - { - if (m_Timer > 500.f) // 0.5 seconds - { - Destroy(); - return; - } - } - else if (m_Timer > 1000 * 60 * 5) // 5 minutes - { - Destroy(); - return; - } - - if (m_IsInGround) - { - // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL - // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) - // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync - // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position - - if (!m_HasTeleported) // Sent a teleport already, don't do again - { - if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case - { - m_World->BroadcastTeleportEntity(*this); - m_HasTeleported = true; - } - else - { - m_HitGroundTimer += a_Dt; - } - } - - int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - - if (Chunk == NULL) - { - // Inside an unloaded chunk, abort - return; - } - - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? - { - m_IsInGround = false; // Yes, begin simulating physics again - } - } -} diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h deleted file mode 100644 index 18c30feae..000000000 --- a/src/Entities/ProjectileArrow.h +++ /dev/null @@ -1,96 +0,0 @@ -// -// ProjectileArrow.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cArrowEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field - enum ePickupState - { - psNoPickup = 0, - psInSurvivalOrCreative = 1, - psInCreative = 2, - } ; - - // tolua_end - - CLASS_PROTODEF(cArrowEntity); - - /// Creates a new arrow with psNoPickup state and default damage modifier coeff - cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - - /// Creates a new arrow as shot by a player, initializes it from the player object - cArrowEntity(cPlayer & a_Player, double a_Force); - - // tolua_begin - - /// Returns whether the arrow can be picked up by players - ePickupState GetPickupState(void) const { return m_PickupState; } - - /// Sets a new pickup state - void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } - - /// Returns the damage modifier coeff. - double GetDamageCoeff(void) const { return m_DamageCoeff; } - - /// Sets the damage modifier coeff - void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } - - /// Returns true if the specified player can pick the arrow up - bool CanPickup(const cPlayer & a_Player) const; - - /// Returns true if the arrow is set as critical - bool IsCritical(void) const { return m_IsCritical; } - - /// Sets the IsCritical flag - void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } - - // tolua_end - -protected: - - /// Determines when the arrow can be picked up by players - ePickupState m_PickupState; - - /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow - double m_DamageCoeff; - - /// If true, the arrow deals more damage - bool m_IsCritical; - - /// Timer for pickup collection animation or five minute timeout - float m_Timer; - - /// Timer for client arrow position confirmation via TeleportEntity - float m_HitGroundTimer; - - // Whether the arrow has already been teleported into the proper position in the ground. - bool m_HasTeleported; - - /// If true, the arrow is in the process of being collected - don't go to anyone else - bool m_bIsCollected; - - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air - Vector3i m_HitBlockPos; - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void CollectedBy(cPlayer * a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -}; // tolua_export diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp deleted file mode 100644 index 3f6e6525e..000000000 --- a/src/Entities/ProjectileEgg.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileEgg.h" -#include "../World.h" - - - - - -cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - TrySpawnChicken(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TrySpawnChicken(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) -{ - if (m_World->GetTickRandomNumber(7) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } - else if (m_World->GetTickRandomNumber(32) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } -} diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h deleted file mode 100644 index ba1f6420e..000000000 --- a/src/Entities/ProjectileEgg.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// ProjectileEgg.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownEggEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEggEntity); - - cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // Randomly decides whether to spawn a chicken where the egg lands. - void TrySpawnChicken(const Vector3d & a_HitPos); - -} ; // tolua_export diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp deleted file mode 100644 index db32f47b7..000000000 --- a/src/Entities/ProjectileEnderPearl.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileEnderPearl.h" - - - - - -cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // TODO: Tweak a_HitPos based on block face. - TeleportCreator(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TeleportCreator(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) -{ - // Teleport the creator here, make them take 5 damage: - if (m_Creator != NULL) - { - m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); - m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); - } -} diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h deleted file mode 100644 index 39761ff48..000000000 --- a/src/Entities/ProjectileEnderPearl.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// ProjectileEnderPearl.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownEnderPearlEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEnderPearlEntity); - - cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // Teleports the creator where the ender pearl lands. - void TeleportCreator(const Vector3d & a_HitPos); - -} ; // tolua_export diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b2e6d469e..3e48d310c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -13,14 +13,14 @@ #include "../ChunkMap.h" #include "../Chunk.h" -#include "ProjectileArrow.h" -#include "ProjectileEgg.h" -#include "ProjectileEnderPearl.h" -#include "ProjectileExpBottle.h" -#include "ProjectileSnowball.h" -#include "ProjectileFireCharge.h" -#include "ProjectileFirework.h" -#include "ProjectileGhastFireball.h" +#include "ArrowEntity.h" +#include "ThrownEggEntity.h" +#include "ThrownEnderPearlEntity.h" +#include "ExpBottleEntity.h" +#include "ThrownSnowballEntity.h" +#include "FireChargeEntity.h" +#include "FireworkEntity.h" +#include "GhastFireballEntity.h" diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp deleted file mode 100644 index 936be6a72..000000000 --- a/src/Entities/ProjectileExpBottle.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileExpBottle.h" -#include "../World.h" - - - - - -cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // Spawn an experience orb with a reward between 3 and 11. - m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); - - Destroy(); -} diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h deleted file mode 100644 index 070c412e4..000000000 --- a/src/Entities/ProjectileExpBottle.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// ProjectileExpBottle.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cExpBottleEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cExpBottleEntity); - - cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - -}; // tolua_export diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp deleted file mode 100644 index 5bdb74462..000000000 --- a/src/Entities/ProjectileFireCharge.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileFireCharge.h" -#include "../World.h" - - - - - -cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) - { - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); - } -} - - - - - -void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); - - // TODO: Some entities are immune to hits - a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h deleted file mode 100644 index bcf2b7af6..000000000 --- a/src/Entities/ProjectileFireCharge.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// ProjectileFireCharge.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cFireChargeEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireChargeEntity); - - cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - -} ; // tolua_export diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp deleted file mode 100644 index dcb89fce3..000000000 --- a/src/Entities/ProjectileFirework.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileFirework.h" -#include "../World.h" -#include "../Chunk.h" - - - - - -cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : -super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), -m_ExplodeTimer(0), -m_FireworkItem(a_Item) -{ -} - - - - - -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) -{ - int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosY = POSY_TOINT; - - if ((PosY < 0) || (PosY >= cChunkDef::Height)) - { - goto setspeed; - } - - if (m_IsInGround) - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) - { - m_IsInGround = false; - } - else - { - return; - } - } - else - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) - { - OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); - return; - } - } - -setspeed: - AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); -} - - - - - -void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - - if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) - { - m_World->BroadcastEntityStatus(*this, esFireworkExploding); - Destroy(); - } - - m_ExplodeTimer++; -} diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h deleted file mode 100644 index e7d7eacbf..000000000 --- a/src/Entities/ProjectileFirework.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// ProjectileFirework.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cFireworkEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireworkEntity); - - cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); - const cItem & GetItem(void) const { return m_FireworkItem; } - -protected: - - // cProjectileEntity overrides: - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -private: - - int m_ExplodeTimer; - cItem m_FireworkItem; - -}; // tolua_export diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp deleted file mode 100644 index cac622562..000000000 --- a/src/Entities/ProjectileGhastFireball.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileGhastFireball.h" -#include "../World.h" - - - - - -cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); -} - - - - - -void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h deleted file mode 100644 index 6dd37783e..000000000 --- a/src/Entities/ProjectileGhastFireball.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// ProjectileGhastFireball.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cGhastFireballEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cGhastFireballEntity); - - cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // TODO: Deflecting the fireballs by arrow- or sword- hits - -} ; // tolua_export diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp deleted file mode 100644 index 536b9e791..000000000 --- a/src/Entities/ProjectileSnowball.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileSnowball.h" -#include "../World.h" - - - - - -cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); -} - - - - - -void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - if (a_EntityHit.IsMob()) - { - cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); - if (MobType == cMonster::mtBlaze) - { - TotalDamage = 3; - } - else if (MobType == cMonster::mtEnderDragon) - { - TotalDamage = 1; - } - } - // TODO: If entity is Ender Crystal, destroy it - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h deleted file mode 100644 index 2443d05c6..000000000 --- a/src/Entities/ProjectileSnowball.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// ProjectileSnowball.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownSnowballEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownSnowballEntity); - - cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - -} ; // tolua_export diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp new file mode 100644 index 000000000..224019091 --- /dev/null +++ b/src/Entities/ThrownEggEntity.cpp @@ -0,0 +1,59 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownEggEntity.h" +#include "../World.h" + + + + + +cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TrySpawnChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TrySpawnChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) +{ + if (m_World->GetTickRandomNumber(7) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } + else if (m_World->GetTickRandomNumber(32) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } +} diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h new file mode 100644 index 000000000..5ba8f051b --- /dev/null +++ b/src/Entities/ThrownEggEntity.h @@ -0,0 +1,37 @@ +// +// ThrownEggEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownEggEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEggEntity); + + cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // Randomly decides whether to spawn a chicken where the egg lands. + void TrySpawnChicken(const Vector3d & a_HitPos); + +} ; // tolua_export diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp new file mode 100644 index 000000000..c37161145 --- /dev/null +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -0,0 +1,54 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownEnderPearlEntity.h" + + + + + +cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportCreator(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportCreator(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) +{ + // Teleport the creator here, make them take 5 damage: + if (m_Creator != NULL) + { + m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); + m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); + } +} diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h new file mode 100644 index 000000000..ddee5babe --- /dev/null +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -0,0 +1,37 @@ +// +// ThrownEnderPearlEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownEnderPearlEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEnderPearlEntity); + + cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); + +} ; // tolua_export diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp new file mode 100644 index 000000000..427f630f7 --- /dev/null +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -0,0 +1,48 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownSnowballEntity.h" +#include "../World.h" + + + + + +cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); +} + + + + + +void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + if (a_EntityHit.IsMob()) + { + cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); + if (MobType == cMonster::mtBlaze) + { + TotalDamage = 3; + } + else if (MobType == cMonster::mtEnderDragon) + { + TotalDamage = 1; + } + } + // TODO: If entity is Ender Crystal, destroy it + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h new file mode 100644 index 000000000..a09512e37 --- /dev/null +++ b/src/Entities/ThrownSnowballEntity.h @@ -0,0 +1,34 @@ +// +// ThrownSnowballEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownSnowballEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownSnowballEntity); + + cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + +} ; // tolua_export diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index a53d59b58..8c0b3a0a3 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -9,7 +9,7 @@ #pragma once -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 74683da94..326b42f07 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -3,7 +3,7 @@ #include "Blaze.h" #include "../World.h" -#include "../Entities/ProjectileFireCharge.h" +#include "../Entities/FireChargeEntity.h" diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 7b82d3181..d8a7663f8 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -3,7 +3,7 @@ #include "Ghast.h" #include "../World.h" -#include "../Entities/ProjectileGhastFireball.h" +#include "../Entities/GhastFireballEntity.h" diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 3b9e1c5f4..1e62d7987 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -3,7 +3,7 @@ #include "Skeleton.h" #include "../World.h" -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 2f57d3cf1..9502f9bec 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -26,7 +26,7 @@ Documentation: #include "../Root.h" #include "../Server.h" -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 468c4cf2b..2cc0adbfb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -31,8 +31,8 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" -#include "../Entities/ProjectileArrow.h" -#include "../Entities/ProjectileFirework.h" +#include "../Entities/ArrowEntity.h" +#include "../Entities/FireworkEntity.h" diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 02ced7038..41e0d89fd 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -28,7 +28,7 @@ #include "../Entities/Boat.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e702c4f1e..809cb9e42 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -35,12 +35,12 @@ #include "../Entities/FallingBlock.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" -#include "../Entities/ProjectileArrow.h" -#include "../Entities/ProjectileEgg.h" -#include "../Entities/ProjectileEnderPearl.h" -#include "../Entities/ProjectileSnowball.h" -#include "../Entities/ProjectileFireCharge.h" -#include "../Entities/ProjectileGhastFireball.h" +#include "../Entities/ArrowEntity.h" +#include "../Entities/ThrownEggEntity.h" +#include "../Entities/ThrownEnderPearlEntity.h" +#include "../Entities/ThrownSnowballEntity.h" +#include "../Entities/FireChargeEntity.h" +#include "../Entities/GhastFireballEntity.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" -- cgit v1.2.3 From 26e935cb2028e041623424d474ccf1b127d55e97 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 28 Apr 2014 13:51:22 +0200 Subject: Revert "Changed the old invulnerable methods from the wither to the new." This reverts commit d50f8f6f11f69e7e1e56be92fb2d72a5014a3e34. --- src/Mobs/Wither.h | 3 --- src/Protocol/Protocol125.cpp | 9 +-------- src/Protocol/Protocol17x.cpp | 9 +-------- src/WorldStorage/NBTChunkSerializer.cpp | 9 +-------- src/WorldStorage/WSSAnvil.cpp | 2 +- 5 files changed, 4 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index fbea331d3..81c9df1b1 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -19,9 +19,6 @@ public: /** Returns whether the wither is invulnerable to arrows. */ bool IsArmored(void) const; - - /** Use the wither the invulnerable from the spawn? */ - bool IsSpawnInvulnerable(void) const { return m_IsSpawnInvulnerable; } // cEntity overrides virtual bool Initialize(cWorld * a_World) override; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3951eb3e4..a23afb29a 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -2013,14 +2013,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - if (((const cWither &)a_Mob).IsSpawnInvulnerable()) - { - WriteInt((Int32)((const cWither &)a_Mob).GetInvulnerableTicks()); - } - else - { - WriteInt((Int32)0); - } + WriteInt((Int32)((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 311e770f9..80b161e3e 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2820,14 +2820,7 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - if (((const cWither &)a_Mob).IsSpawnInvulnerable()) - { - WriteInt(((const cWither &)a_Mob).GetInvulnerableTicks()); - } - else - { - WriteInt(0); - } + WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 0c4a1a430..46c6b8e92 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -516,14 +516,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case cMonster::mtWither: { - if (((const cWither *)a_Monster)->IsSpawnInvulnerable()) - { - m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetInvulnerableTicks()); - } - else - { - m_Writer.AddInt("Invul", 0); - } + m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetWitherInvulnerableTicks()); break; } case cMonster::mtWolf: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index c21809270..4532a925a 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2272,7 +2272,7 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a int CurrLine = a_NBT.FindChildByName(a_TagIdx, "Invul"); if (CurrLine > 0) { - Monster->SetInvulnerableTicks(a_NBT.GetInt(CurrLine)); + Monster->SetWitherInvulnerableTicks(a_NBT.GetInt(CurrLine)); } a_Entities.push_back(Monster.release()); -- cgit v1.2.3 From acd2804f316114a50b7103158a6bff5d3d14f673 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 28 Apr 2014 13:51:40 +0200 Subject: Revert "Withers now use the new invulnerable." This reverts commit 619592b5a0ab651e714d55932bc7909e4204cee9. --- src/Mobs/Wither.cpp | 29 ++++++++++++++++++++--------- src/Mobs/Wither.h | 7 ++++++- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index fe4dbb28b..5b6e895e1 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -10,10 +10,9 @@ cWither::cWither(void) : super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0), - m_IsSpawnInvulnerable(true) + m_WitherInvulnerableTicks(220) { SetMaxHealth(300); - SetInvulnerableTicks(220); } @@ -48,6 +47,11 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } + if (m_WitherInvulnerableTicks > 0) + { + return false; + } + if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) { return false; @@ -64,14 +68,21 @@ void cWither::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (GetInvulnerableTicks() <= 0 && m_IsSpawnInvulnerable) + if (m_WitherInvulnerableTicks > 0) { - m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); - m_IsSpawnInvulnerable = false; - } - else if (((GetInvulnerableTicks() % 10) == 0) && (GetInvulnerableTicks() > 10)) - { - Heal(10); + unsigned int NewTicks = m_WitherInvulnerableTicks - 1; + + if (NewTicks == 0) + { + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + } + + m_WitherInvulnerableTicks = NewTicks; + + if ((NewTicks % 10) == 0) + { + Heal(10); + } } m_World->BroadcastEntityMetadata(*this); diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 81c9df1b1..08b460009 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -17,6 +17,10 @@ public: CLASS_PROTODEF(cWither); + unsigned int GetWitherInvulnerableTicks(void) const { return m_WitherInvulnerableTicks; } + + void SetWitherInvulnerableTicks(unsigned int a_Ticks) { m_WitherInvulnerableTicks = a_Ticks; } + /** Returns whether the wither is invulnerable to arrows. */ bool IsArmored(void) const; @@ -28,7 +32,8 @@ public: private: - bool m_IsSpawnInvulnerable; + /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ + unsigned int m_WitherInvulnerableTicks; } ; -- cgit v1.2.3 From a42480cf8266a1e066209823aab42c9a3829adbc Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 28 Apr 2014 10:31:07 -0700 Subject: Template Magic Removed need to allocate a fake meta block by using templates to provide a version of the code that does not use metas. Also changed the function to a template argument to make sure that the compilier is able to inline it. --- src/BlockArea.cpp | 343 +++++++++++++++++++++++++------------------------ src/BlockArea.h | 5 +- src/OSSupport/File.cpp | 4 +- src/OSSupport/File.h | 4 +- 4 files changed, 183 insertions(+), 173 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index e4b122fa2..359f5cb81 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -13,18 +13,20 @@ - // This wild construct allows us to pass a function argument and still have it inlined by the compiler :) /// Merges two blocktypes and blockmetas of the specified sizes and offsets using the specified combinator function -template void InternalMergeBlocks( + +typedef void (CombinatorFunc)(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta); + +template +void InternalMergeBlocks( BLOCKTYPE * a_DstTypes, const BLOCKTYPE * a_SrcTypes, NIBBLETYPE * a_DstMetas, const NIBBLETYPE * a_SrcMetas, int a_SizeX, int a_SizeY, int a_SizeZ, int a_SrcOffX, int a_SrcOffY, int a_SrcOffZ, int a_DstOffX, int a_DstOffY, int a_DstOffZ, int a_SrcSizeX, int a_SrcSizeY, int a_SrcSizeZ, - int a_DstSizeX, int a_DstSizeY, int a_DstSizeZ, - Combinator a_Combinator + int a_DstSizeX, int a_DstSizeY, int a_DstSizeZ ) { UNUSED(a_SrcSizeY); @@ -41,7 +43,15 @@ template void InternalMergeBlocks( int DstIdx = DstBaseZ + a_DstOffX; for (int x = 0; x < a_SizeX; x++) { - a_Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], a_DstMetas[DstIdx], a_SrcMetas[SrcIdx]); + if (MetasValid) + { + Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], a_DstMetas[DstIdx], a_SrcMetas[SrcIdx]); + } + else + { + BLOCKTYPE FakeDestMeta = 0; + Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], FakeDestMeta, (NIBBLETYPE)0); + } ++DstIdx; ++SrcIdx; } // for x @@ -51,13 +61,12 @@ template void InternalMergeBlocks( - - /// Combinator used for cBlockArea::msOverwrite merging +template static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; } @@ -65,12 +74,13 @@ static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_S /// Combinator used for cBlockArea::msFillAir merging +template static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_DstType == E_BLOCK_AIR) { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; } // "else" is the default, already in place } @@ -80,12 +90,13 @@ static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msImprint merging +template static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_SrcType != E_BLOCK_AIR) { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; } // "else" is the default, already in place } @@ -95,6 +106,7 @@ static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msLake merging +template static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge is the NOP block @@ -107,7 +119,7 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp if (a_SrcType == E_BLOCK_AIR) { a_DstType = E_BLOCK_AIR; - a_DstMeta = 0; + if (MetaValid) a_DstMeta = 0; return; } @@ -132,7 +144,7 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp case E_BLOCK_STATIONARY_LAVA: { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; return; } } @@ -146,7 +158,7 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp case E_BLOCK_MYCELIUM: { a_DstType = E_BLOCK_STONE; - a_DstMeta = 0; + if (MetaValid) a_DstMeta = 0; return; } } @@ -159,13 +171,14 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp /** Combinator used for cBlockArea::msSpongePrint merging */ +template static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge overwrites nothing, everything else overwrites anything if (a_SrcType != E_BLOCK_SPONGE) { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; } } @@ -174,17 +187,18 @@ static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a /** Combinator used for cBlockArea::msDifference merging */ +template static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { - if ((a_DstType == a_SrcType) && (a_DstMeta == a_SrcMeta)) + if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta))) { a_DstType = E_BLOCK_AIR; - a_DstMeta = 0; + if (MetaValid) a_DstMeta = 0; } else { a_DstType = a_SrcType; - a_DstMeta = a_SrcMeta; + if (MetaValid) a_DstMeta = a_SrcMeta; } } @@ -193,13 +207,14 @@ static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_ /** Combinator used for cBlockArea::msMask merging */ +template static inline void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // If the blocks are the same, keep the dest; otherwise replace with air - if ((a_SrcType != a_DstType) || (a_SrcMeta != a_DstMeta)) + if ((a_SrcType != a_DstType) || !MetaValid || (a_SrcMeta != a_DstMeta)) { a_DstType = E_BLOCK_AIR; - a_DstMeta = 0; + if (MetaValid) a_DstMeta = 0; } } @@ -484,7 +499,7 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const a_Into.Clear(); a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes()); a_Into.m_Origin = m_Origin; - int BlockCount = GetBlockCount(); + size_t BlockCount = GetBlockCount(); if (HasBlockTypes()) { memcpy(a_Into.m_BlockTypes, m_BlockTypes, BlockCount * sizeof(BLOCKTYPE)); @@ -532,7 +547,7 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) f.Write(&SizeZ, 4); unsigned char DataTypes = (unsigned char)GetDataTypes(); f.Write(&DataTypes, 1); - int NumBlocks = GetBlockCount(); + size_t NumBlocks = GetBlockCount(); if (HasBlockTypes()) { f.Write(m_BlockTypes, NumBlocks * sizeof(BLOCKTYPE)); @@ -637,160 +652,19 @@ void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMa void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy) { - // Block types are compulsory, block metas are voluntary - if (!HasBlockTypes() || !a_Src.HasBlockTypes()) - { - LOGWARNING("%s: cannot merge because one of the areas doesn't have blocktypes.", __FUNCTION__); - return; - } - - // Dst is *this, Src is a_Src - int SrcOffX = std::max(0, -a_RelX); // Offset in Src where to start reading - int DstOffX = std::max(0, a_RelX); // Offset in Dst where to start writing - int SizeX = std::min(a_Src.GetSizeX() - SrcOffX, GetSizeX() - DstOffX); // How many blocks to copy - - int SrcOffY = std::max(0, -a_RelY); // Offset in Src where to start reading - int DstOffY = std::max(0, a_RelY); // Offset in Dst where to start writing - int SizeY = std::min(a_Src.GetSizeY() - SrcOffY, GetSizeY() - DstOffY); // How many blocks to copy - - int SrcOffZ = std::max(0, -a_RelZ); // Offset in Src where to start reading - int DstOffZ = std::max(0, a_RelZ); // Offset in Dst where to start writing - int SizeZ = std::min(a_Src.GetSizeZ() - SrcOffZ, GetSizeZ() - DstOffZ); // How many blocks to copy const NIBBLETYPE * SrcMetas = a_Src.GetBlockMetas(); NIBBLETYPE * DstMetas = m_BlockMetas; + bool IsDummyMetas = ((SrcMetas == NULL) || (DstMetas == NULL)); if (IsDummyMetas) { - size_t SrcCount = a_Src.GetBlockCount(); - size_t DestCount = GetBlockCount(); - NIBBLETYPE * tempSrcMetas = new NIBBLETYPE[SrcCount]; - memset(tempSrcMetas, 0, SrcCount); - SrcMetas = tempSrcMetas; - DstMetas = new NIBBLETYPE[DestCount]; - memset(DstMetas, 0, DestCount); + MergeByStrategy(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); } - - switch (a_Strategy) - { - case msOverwrite: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorOverwrite - ); - break; - } // case msOverwrite - - case msFillAir: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorFillAir - ); - break; - } // case msFillAir - - case msImprint: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorImprint - ); - break; - } // case msImprint - - case msLake: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorLake - ); - break; - } // case msLake - - case msSpongePrint: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorSpongePrint - ); - break; - } // case msSpongePrint - - case msDifference: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorDifference - ); - break; - } // case msDifference - - case msMask: - { - InternalMergeBlocks( - m_BlockTypes, a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z, - MergeCombinatorMask - ); - break; - } // case msMask - - default: - { - LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); - ASSERT(!"Unknown block area merge strategy"); - break; - } - } // switch (a_Strategy) - - if (IsDummyMetas) + else { - delete[] SrcMetas; - delete[] DstMetas; + MergeByStrategy(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); } } @@ -2084,7 +1958,7 @@ void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, i int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; - int BlockCount = NewSizeX * NewSizeY * NewSizeZ; + size_t BlockCount = (size_t)NewSizeX * NewSizeY * NewSizeZ; BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount]; memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE)); int OldIndex = 0; @@ -2114,7 +1988,7 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; - int BlockCount = NewSizeX * NewSizeY * NewSizeZ; + size_t BlockCount = (size_t)NewSizeX * NewSizeY * NewSizeZ; NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount]; memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE)); int OldIndex = 0; @@ -2166,4 +2040,137 @@ void cBlockArea::RelSetData( +template +void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas) +{ + // Block types are compulsory, block metas are voluntary + if (!HasBlockTypes() || !a_Src.HasBlockTypes()) + { + LOGWARNING("%s: cannot merge because one of the areas doesn't have blocktypes.", __FUNCTION__); + return; + } + + // Dst is *this, Src is a_Src + int SrcOffX = std::max(0, -a_RelX); // Offset in Src where to start reading + int DstOffX = std::max(0, a_RelX); // Offset in Dst where to start writing + int SizeX = std::min(a_Src.GetSizeX() - SrcOffX, GetSizeX() - DstOffX); // How many blocks to copy + + int SrcOffY = std::max(0, -a_RelY); // Offset in Src where to start reading + int DstOffY = std::max(0, a_RelY); // Offset in Dst where to start writing + int SizeY = std::min(a_Src.GetSizeY() - SrcOffY, GetSizeY() - DstOffY); // How many blocks to copy + + int SrcOffZ = std::max(0, -a_RelZ); // Offset in Src where to start reading + int DstOffZ = std::max(0, a_RelZ); // Offset in Dst where to start writing + int SizeZ = std::min(a_Src.GetSizeZ() - SrcOffZ, GetSizeZ() - DstOffZ); // How many blocks to copy + + switch (a_Strategy) + { + case cBlockArea::msOverwrite: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msOverwrite + + case cBlockArea::msFillAir: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msFillAir + + case cBlockArea::msImprint: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msImprint + + case cBlockArea::msLake: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msLake + + case cBlockArea::msSpongePrint: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msSpongePrint + + case cBlockArea::msDifference: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msDifference + + case cBlockArea::msMask: + { + InternalMergeBlocks >( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + break; + } // case msMask + + default: + { + LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); + ASSERT(!"Unknown block area merge strategy"); + break; + } + } // switch (a_Strategy) +} + + diff --git a/src/BlockArea.h b/src/BlockArea.h index c48175b8c..4c4dfb8ff 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -294,7 +294,7 @@ public: NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! - int GetBlockCount(void) const { return m_Size.x * m_Size.y * m_Size.z; } + size_t GetBlockCount(void) const { return m_Size.x * m_Size.y * m_Size.z; } int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; protected: @@ -363,6 +363,9 @@ protected: int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight ); + + template + void MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas); // tolua_begin } ; // tolua_end diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index f1b3bcf9e..33b9cfc3f 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -143,7 +143,7 @@ bool cFile::IsEOF(void) const -int cFile::Read (void * iBuffer, int iNumBytes) +int cFile::Read (void * iBuffer, size_t iNumBytes) { ASSERT(IsOpen()); @@ -159,7 +159,7 @@ int cFile::Read (void * iBuffer, int iNumBytes) -int cFile::Write(const void * iBuffer, int iNumBytes) +int cFile::Write(const void * iBuffer, size_t iNumBytes) { ASSERT(IsOpen()); diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index b394c5cb9..2a7ecf0ed 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -80,10 +80,10 @@ public: bool IsEOF(void) const; /** Reads up to iNumBytes bytes into iBuffer, returns the number of bytes actually read, or -1 on failure; asserts if not open */ - int Read (void * iBuffer, int iNumBytes); + int Read (void * iBuffer, size_t iNumBytes); /** Writes up to iNumBytes bytes from iBuffer, returns the number of bytes actually written, or -1 on failure; asserts if not open */ - int Write(const void * iBuffer, int iNumBytes); + int Write(const void * iBuffer, size_t iNumBytes); /** Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open */ int Seek (int iPosition); -- cgit v1.2.3 From 05fe6d6c58172dc1f28c9dde06b18e7e309e5212 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 28 Apr 2014 10:52:48 -0700 Subject: Removed inlines from combinators gcc requires external linkage for functions provided to template parameters --- src/BlockArea.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 359f5cb81..0c1c176d5 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -63,7 +63,7 @@ void InternalMergeBlocks( /// Combinator used for cBlockArea::msOverwrite merging template -static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; if (MetaValid) a_DstMeta = a_SrcMeta; @@ -75,7 +75,7 @@ static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_S /// Combinator used for cBlockArea::msFillAir merging template -static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_DstType == E_BLOCK_AIR) { @@ -91,7 +91,7 @@ static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msImprint merging template -static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_SrcType != E_BLOCK_AIR) { @@ -107,7 +107,7 @@ static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msLake merging template -static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge is the NOP block if (a_SrcType == E_BLOCK_SPONGE) @@ -172,7 +172,7 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp /** Combinator used for cBlockArea::msSpongePrint merging */ template -static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge overwrites nothing, everything else overwrites anything if (a_SrcType != E_BLOCK_SPONGE) @@ -188,7 +188,7 @@ static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a /** Combinator used for cBlockArea::msDifference merging */ template -static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta))) { @@ -208,7 +208,7 @@ static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_ /** Combinator used for cBlockArea::msMask merging */ template -static inline void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // If the blocks are the same, keep the dest; otherwise replace with air if ((a_SrcType != a_DstType) || !MetaValid || (a_SrcMeta != a_DstMeta)) -- cgit v1.2.3 From 6d520e398b7da7d04f8b7377bca0db0a684452f1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 28 Apr 2014 11:00:43 -0700 Subject: Fixed unbraced ifs --- src/BlockArea.cpp | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 0c1c176d5..b7b76da26 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -66,7 +66,10 @@ template static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } } @@ -80,7 +83,10 @@ static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N if (a_DstType == E_BLOCK_AIR) { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } } // "else" is the default, already in place } @@ -96,7 +102,10 @@ static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N if (a_SrcType != E_BLOCK_AIR) { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } } // "else" is the default, already in place } @@ -119,7 +128,10 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB if (a_SrcType == E_BLOCK_AIR) { a_DstType = E_BLOCK_AIR; - if (MetaValid) a_DstMeta = 0; + if (MetaValid) + { + a_DstMeta = 0; + } return; } @@ -144,7 +156,10 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB case E_BLOCK_STATIONARY_LAVA: { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } return; } } @@ -158,7 +173,10 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB case E_BLOCK_MYCELIUM: { a_DstType = E_BLOCK_STONE; - if (MetaValid) a_DstMeta = 0; + if (MetaValid) + { + a_DstMeta = 0; + } return; } } @@ -178,7 +196,10 @@ static void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp if (a_SrcType != E_BLOCK_SPONGE) { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } } } @@ -193,12 +214,18 @@ static void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta))) { a_DstType = E_BLOCK_AIR; - if (MetaValid) a_DstMeta = 0; + if (MetaValid) + { + a_DstMeta = 0; + } } else { a_DstType = a_SrcType; - if (MetaValid) a_DstMeta = a_SrcMeta; + if (MetaValid) + { + a_DstMeta = a_SrcMeta; + } } } @@ -214,7 +241,10 @@ static void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB if ((a_SrcType != a_DstType) || !MetaValid || (a_SrcMeta != a_DstMeta)) { a_DstType = E_BLOCK_AIR; - if (MetaValid) a_DstMeta = 0; + if (MetaValid) + { + a_DstMeta = 0; + } } } -- cgit v1.2.3 From ad5cdf9f2d4a5e87489a2ad460bf353b17f72b6d Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 28 Apr 2014 11:07:06 -0700 Subject: Removed static from combinators. THis allows us to use the functions in template params at the cost of polluting the global namespace. --- src/BlockArea.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index b7b76da26..f03fc6042 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -63,7 +63,7 @@ void InternalMergeBlocks( /// Combinator used for cBlockArea::msOverwrite merging template -static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; if (MetaValid) @@ -78,7 +78,7 @@ static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, /// Combinator used for cBlockArea::msFillAir merging template -static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_DstType == E_BLOCK_AIR) { @@ -97,7 +97,7 @@ static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msImprint merging template -static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_SrcType != E_BLOCK_AIR) { @@ -116,7 +116,7 @@ static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msLake merging template -static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge is the NOP block if (a_SrcType == E_BLOCK_SPONGE) @@ -190,7 +190,7 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB /** Combinator used for cBlockArea::msSpongePrint merging */ template -static void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge overwrites nothing, everything else overwrites anything if (a_SrcType != E_BLOCK_SPONGE) @@ -209,7 +209,7 @@ static void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp /** Combinator used for cBlockArea::msDifference merging */ template -static void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta))) { @@ -235,7 +235,7 @@ static void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType /** Combinator used for cBlockArea::msMask merging */ template -static void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // If the blocks are the same, keep the dest; otherwise replace with air if ((a_SrcType != a_DstType) || !MetaValid || (a_SrcMeta != a_DstMeta)) -- cgit v1.2.3 From f04957321d063f8755d4634551ab9eece05f009e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Apr 2014 20:37:12 +0200 Subject: Fixed missing return value warning in MSVC. --- src/ClientHandle.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index fc3f98aaf..efcc89bab 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -220,6 +220,7 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage } } ASSERT(!"Unhandled chat prefix type!"); + return ""; } -- cgit v1.2.3 From 8ab8fb344f49c2c4ce857594159e9cdba3336853 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Apr 2014 20:37:22 +0200 Subject: Fixed braces. --- src/ClientHandle.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index efcc89bab..f3588c253 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -214,13 +214,17 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage case mtPrivateMessage: { if (ShouldAppendChatPrefixes) + { return Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + } else + { return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); + } } } ASSERT(!"Unhandled chat prefix type!"); - return ""; + return AString(); } -- cgit v1.2.3