diff options
Diffstat (limited to '')
274 files changed, 16184 insertions, 7330 deletions
diff --git a/.gitmodules b/.gitmodules index 2c7ec209b..2aaee3624 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,4 +9,4 @@ url = https://github.com/bearbin/transapi.git [submodule "lib/polarssl"] path = lib/polarssl - url = https://github.com/polarssl/polarssl + url = https://github.com/mc-server/polarssl diff --git a/COMPILING.md b/COMPILING.md index 139f1a0ee..ea6b580d5 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -45,7 +45,30 @@ It is possible to use an external profiler to learn more about how the code perf There's a script file, `MCServer/profile_run.cmd` that encapsulates most of the profiling work, have a look at the comments at the top of that script for details on how to get it to work. You'll need to change to a profiled configuration (both debug and release can be profiled). -## Linux, MacOS, FreeBSD etc. ## +## OSX ## +Install git from its [website](http://git-scm.com) or homebrew: `brew install git`. + +Install Xcode (commandline tools are recommended) from the App Store or https://developer.apple.com/downloads. + +Install CMake from its [website](http://cmake.org) or homebrew: `brew install cmake`. + +### Getting the sources ### +``` +mkdir MCServer +cd MCServer +git clone https://github.com/mc-server/MCServer.git . +git submodule init +git submodule update +``` + +### Building ### + +Follow the instructions at [CMake on Unix-based platforms](#cmake-on-unix-based-platforms), using Xcode as cmake's generator. If no generator is specified, CMake will use the Makefile generator, in which case you must build with the `make` command. + +After doing so, run the command `xcodebuild lib/polarssl/POLARSSL.xcodeproj` in the build directory, in order to build polarssl, a library that is required by MCServer. Lastly, run the command `xcodebuild` to build MCServer. Optionally, you may open the project files for polarssl and then MCServer in Xcode and build there. + + +## Linux, FreeBSD etc. ## Install git, cmake and gcc or clang, using your platform's package manager: ``` @@ -61,6 +84,14 @@ git submodule init git submodule update ``` +### Building ### + +Follow the instructions at [CMake on Unix-based platforms](#cmake-on-unix-based-platforms). + +After doing so, run the command `make` in the build directory, and MCServer will build. + +## CMake on Unix-based platforms ### + ### Release Mode ### Release mode is preferred for almost all cases, it has much better speed and less console spam. However, if you are developing MCServer actively, debug mode might be better. @@ -69,8 +100,10 @@ Assuming you are in the MCServer folder created in the initial setup step, you n ``` mkdir Release cd Release -cmake -DCMAKE_BUILD_TYPE=RELEASE .. && make +cmake -DCMAKE_BUILD_TYPE=RELEASE .. ``` +NOTE: CMake can generate project files for many different programs, such as Xcode, eclipse, and ninja. To use a different generator, first type `cmake --help`, and at the end, cmake will output the different generators that are available. To specify one, add `-G` followed by the name of the generator, in the `cmake` command. Note that the name is case-sensitive. + The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer`. ### Debug Mode ### @@ -81,8 +114,10 @@ Assuming you are in the MCServer folder created in the Getting the sources step, ``` mkdir Debug cd Debug -cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make +cmake -DCMAKE_BUILD_TYPE=DEBUG .. ``` +NOTE: CMake can generate project files for many different programs, such as Xcode, eclipse, and ninja. To use a different generator, first type `cmake --help`, and at the end, cmake will output the different generators that are available. To specify one, add `-G` followed by the name of the generator, in the `cmake` command. Note that the name is case-sensitive. + The executable will be built in the `MCServer/MCServer` folder and will be named `MCServer_debug`. ### 32 Bit Mode switch ### diff --git a/CoverityModel.cpp b/CoverityModel.cpp new file mode 100644 index 000000000..3ee6447ee --- /dev/null +++ b/CoverityModel.cpp @@ -0,0 +1,17 @@ + + +extern "C" { + struct lua_State; + struct tolua_Error + { + int index; + int array; + const char* type; + }; + + void tolua_error (lua_State* L, const char* msg, tolua_Error* err) + { + __coverity_panic__(); + } + +} diff --git a/MCServer/.gitignore b/MCServer/.gitignore index 69826ef06..32a634a03 100644 --- a/MCServer/.gitignore +++ b/MCServer/.gitignore @@ -28,3 +28,5 @@ motd.txt *.deuser *.dmp *.xml +mcserver_api.lua + diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 233bdbc46..1423d64bc 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -699,7 +699,7 @@ end</pre> GetLevel = { Params = "EnchantmentNumID", Return = "number", Notes = "Returns the level of the specified enchantment stored in this object; 0 if not stored" }, IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if the object stores no enchantments" }, SetLevel = { Params = "EnchantmentNumID, Level", Return = "", Notes = "Sets the level for the specified enchantment, adding it if not stored before or removing it if level < = 0" }, - StringToEnchantmentID = { Params = "EnchantmentTextID", Return = "number", Notes = "(static) Returns the enchantment numerical ID, -1 if not understood. Case insensitive" }, + StringToEnchantmentID = { Params = "EnchantmentTextID", Return = "number", Notes = "(static) Returns the enchantment numerical ID, -1 if not understood. Case insensitive. Also understands plain numbers." }, ToString = { Params = "", Return = "string", Notes = "Returns the string description of all the enchantments stored in this object, in numerical-ID form" }, }, Constants = @@ -2929,9 +2929,10 @@ end { -- No sorting is provided for these, they will be output in the same order as defined here { FileName = "Writing-a-MCServer-plugin.html", Title = "Writing a MCServer plugin" }, - { FileName = "SettingUpDecoda.html", Title = "Setting up the Decoda Lua IDE" }, - { FileName = "SettingUpZeroBrane.html", Title = "Setting up the ZeroBrane Studio Lua IDE" }, - { FileName = "WebWorldThreads.html", Title = "Webserver vs World threads" }, + { FileName = "SettingUpDecoda.html", Title = "Setting up the Decoda Lua IDE" }, + { FileName = "SettingUpZeroBrane.html", Title = "Setting up the ZeroBrane Studio Lua IDE" }, + { FileName = "UsingChunkStays.html", Title = "Using ChunkStays" }, + { FileName = "WebWorldThreads.html", Title = "Webserver vs World threads" }, } } ; diff --git a/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua b/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua index a3301a8c6..204cb63d2 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnDisconnect.lua @@ -2,23 +2,33 @@ return { HOOK_DISCONNECT = { - CalledWhen = "A player has explicitly disconnected.", + CalledWhen = [[ + A client has disconnected, either by explicitly sending the disconnect packet (in older protocols) or + their connection was terminated + ]], DefaultFnName = "OnDisconnect", -- also used as pagename Desc = [[ - This hook is called when a client is about to be disconnected from the server, for whatever reason. - - <p><b>Note that this hook will be removed after <1.7 protocol support is removed, as it was originally a hook for - the client sending the server a disconnect packet, which no longer happens.</b></p> + This hook is called when a client has disconnected from the server, for whatever reason. It is also + called when the client sends the Disconnect packet (only in pre-1.7 protocols). This hook is not called + for server ping connections.</p> + <p> + Note that the hook is called even for connections to players who failed to auth. In such a case there's + no {{cPlayer}} object associated with the client.</p> + <p> + See also the {{OnHandshake|HOOK_HANDSHAKE}} hook which is called when the client connects (and presents + a handshake message, so that they are not just status-pinging). If you need to store a per-player + object, use the {{OnPlayerJoined|HOOK_PLAYER_JOINED}} and {{OnPlayerDestroyed|HOOK_PLAYER_DESTROYED}} + hooks instead, those are guaranteed to have the {{cPlayer}} object associated. ]], Params = { - { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who has disconnected" }, + { Name = "Client", Type = "{{cClientHandle}}", Notes = "The client who has disconnected" }, { Name = "Reason", Type = "string", Notes = "The reason that the client has sent in the disconnect packet" }, }, Returns = [[ If the function returns false or no value, MCServer calls other plugins' callbacks for this event. If the function returns true, no other plugins are called for this event. In either case, - the player is disconnected. + the client is disconnected. ]], }, -- HOOK_DISCONNECT } diff --git a/MCServer/Plugins/APIDump/UsingChunkStays.html b/MCServer/Plugins/APIDump/UsingChunkStays.html new file mode 100644 index 000000000..d3ecc6674 --- /dev/null +++ b/MCServer/Plugins/APIDump/UsingChunkStays.html @@ -0,0 +1,167 @@ +<!DOCTYPE html> +<html> + <head> + <title>MCServer - Using ChunkStays</title> + <link rel="stylesheet" type="text/css" href="main.css" /> + <link rel="stylesheet" type="text/css" href="prettify.css" /> + <script src="prettify.js"></script> + <script src="lang-lua.js"></script> + <meta charset="UTF-8"> + </head> + <body> + <div id="content"> + <h1>Using ChunkStays</h1> + <p> + A plugin may need to manipulate data in arbitrary chunks, and it needs a way to make the server + guarantee that the chunks are available in memory.</p> + + <h2>The problem</h2> + <p> + Usually when plugins want to manipulate larger areas of world data, they need to make sure that the + server has the appropriate chunks loaded in the memory. When the data being manipulated can be further + away from the connected players, or the data is being manipulated from a console handler, there is a + real chance that the chunks are not loaded.</p> + <p> + This gets even more important when using the <a href="cBlockArea.html">cBlockArea</a> class for reading + and writing. Those functions will fail when any of the required chunks aren't valid. This means that + either the block area has incomplete data (Read() failed) or incomplete data has been written to the + world (Write() failed). Recovery from this is near impossible - you can't simply read or write again + later, because the world may have changed in the meantime.</p> + + <h2>The solution</h2> + <p> + The naive solution would be to monitor chunk loads and unloads, and postpone the operations until all + the chunks are available. This would be quite ineffective and also very soon it would become very + difficult to maintain, if there were multiple code paths requiring this handling.</p> + <p> + An alternate approach has been implemented, accessible through a single (somewhat hidden) function + call: <a href="cWorld.html">cWorld:ChunkStay()</a>. All that this call basically does is, it tells the + server "Load these chunks for me, and call this callback function once you have them all." And the + server does exactly that - it remembers the callback and asks the world loader / generator to provide + the chunks. Once the chunks become available, it calls the callback function for the plugin.</p> + <p> + There are a few gotcha-s, though. If the code that was requesting the read or write had access to some + of the volatile objects, such as <a href="cPlayer.html">cPlayer</a> or + <a href="cEntity.html">cEntity</a> objects, those cannot be accessed by the callback anymore, because + they may have become invalid in the meantime - the player may have disconnected, the entity may have + despawned. So the callback must use the longer way to access such objects, such as calling + <a href="cWorld.html">cWorld:DoWithEntityByID()</a> or + <a href="cWorld.html">cWorld:DoWithPlayer()</a>.</p> + + <h2>The example</h2> + <p> + As a simple example, consider a theoretical plugin that allows a player to save the immediate + surroundings of the spawn into a schematic file. The player issues a command to initiate the save, and + the plugin reads a 50 x 50 x 50 block area around the spawn into a cBlockArea and saves it on the disk + as "<PlayerName>_spawn.schematic". When it's done with the saving, it wants to send a message to the + player to let them know the command has succeeded.</p> + <p> + The first attempt shows the naive approach. It simply reads the block area and saves it, then sends the + message. I'll repeat once more, this code is <b>the wrong way</b> to do it!</p> +<pre class="prettyprint lang-lua"> +function HandleCommandSaveSpawn(a_Split, a_Player) + -- Get the coords for the spawn: + local SpawnX = a_Player:GetWorld():GetSpawnX() + local SpawnY = a_Player:GetWorld():GetSpawnY() + local SpawnZ = a_Player:GetWorld():GetSpawnZ() + local Bounds = cCuboid(SpawnX - 25, SpawnY - 25, SpawnZ - 25, SpawnX + 25, SpawnY + 25, SpawnZ + 25) + Bounds:ClampY(0, 255) + + -- Read the area around spawn into a cBlockArea, save to file: + local Area = cBlockArea() + local FileName = a_Player:GetName() .. "_spawn.schematic" + Area:Read(a_Player:GetWorld(), Bounds, cBlockArea.baTypes + cBlockArea.baMetas) + Area:SaveToSchematicFile(FileName) + + -- Notify the player: + a_Player:SendMessage(cCompositeChat("The spawn has been saved", mtInfo)) + return true +end +</pre> + <p> + Now if the player goes exploring far and uses the command to save their spawn, the chunks aren't + loaded, so the BlockArea reading fails, the BlockArea contains bad data. Note that the plugin fails to + do any error checking and if the area isn't read from the world, it happily saves the incomplete data + and says "hey, everything's right", althought it has just trashed any previous backup of the spawn + schematic with nonsense data.</p> + <hr/> + <p> + The following script uses the ChunkStay method to alleviate chunk-related problems. This is <b>the + right way</b> of doing it:</p> +<pre class="prettyprint lang-lua"> +function HandleCommandSaveSpawn(a_Split, a_Player) + -- Get the coords for the spawn: + local SpawnX = a_Player:GetWorld():GetSpawnX() + local SpawnY = a_Player:GetWorld():GetSpawnY() + local SpawnZ = a_Player:GetWorld():GetSpawnZ() + local Bounds = cCuboid(SpawnX - 25, SpawnY - 25, SpawnZ - 25, SpawnX + 25, SpawnY + 25, SpawnZ + 25) + Bounds:ClampY(0, 255) + + -- Get a list of chunks that we need loaded: + local MinChunkX = math.floor((SpawnX - 25) / 16) + local MaxChunkX = math.ceil ((SpawnX + 25) / 16) + local MinChunkZ = math.floor((SpawnZ - 25) / 16) + local MaxChunkZ = math.ceil ((SpawnZ + 25) / 16) + local Chunks = {} + for x = MinChunkX, MaxChunkX do + for z = MinChunkZ, MaxChunkZ do + table.insert(Chunks, {x, z}) + end + end -- for x + + -- Store the player's name and world to use in the callback, because the a_Player object may no longer be valid: + local PlayerName = a_Player:GetName() + local World = a_Player:GetWorld() + + -- This is the callback that is executed once all the chunks are loaded: + local OnAllChunksAvailable = function() + -- Read the area around spawn into a cBlockArea, save to file: + local Area = cBlockArea() + local FileName = PlayerName .. "_spawn.schematic" + if (Area:Read(World, Bounds, cBlockArea.baTypes + cBlockArea.baMetas)) then + Area:SaveToSchematicFile(FileName) + Msg = cCompositeChat("The spawn has been saved", mtInfo) + else + Msg = cCompositeChat("Cannot save the spawn", mtFailure) + end + + -- Notify the player: + -- Note that we cannot use a_Player here, because it may no longer be valid (if the player disconnected before the command completes) + World:DoWithPlayer(PlayerName, + function (a_CBPlayer) + a_CBPlayer:SendMessage(Msg) + end + ) + end + + -- Ask the server to load our chunks and notify us once it's done: + World:ChunkStay(Chunks, nil, OnAllChunksAvailable) + + -- Note that code here may get executed before the callback is called! + -- The ChunkStay says "once you have the chunks", not "wait until you have the chunks" + -- So you can't notify the player here, because the saving needn't have occurred yet. + + return true +end +</pre> + <p> + Note that this code does its error checking of the Area:Read() function, and it will not overwrite the + previous file unless it actually has the correct data. If you're wondering how the reading could fail + when we've got the chunks loaded, there's still the issue of free RAM - if the memory for the area + cannot be allocated, it cannot be read even with all the chunks present. So we still do need that + check.</p> + + <h2>The conclusion</h2> + <p> + Although it makes the code a little bit longer and is a bit more difficult to grasp at first, the + ChunkStay is a useful technique to add to your repertoire. It is to be used whenever you need access to + chunks that may potentially be inaccessible, and you really need the data.</p> + <p>Possibly the biggest hurdle in using the ChunkStay is the fact that it does its work in the + background, thus invalidating all cPlayer and cEntity objects your function may hold, so you need to + re-acquire them from their IDs and names. This is the penalty for using multi-threaded code.</p> + <script> + prettyPrint(); + </script> + </div> + </body> +</html> diff --git a/MCServer/Plugins/APIDump/WebWorldThreads.html b/MCServer/Plugins/APIDump/WebWorldThreads.html index fc80a6178..ee0b172e6 100644 --- a/MCServer/Plugins/APIDump/WebWorldThreads.html +++ b/MCServer/Plugins/APIDump/WebWorldThreads.html @@ -39,31 +39,31 @@ <h2>Example</h2> The Core has the facility to kick players using the web interface. It used the following code for the kicking (inside the webadmin handler): - <pre class="prettyprint lang-lua"> - local KickPlayerName = Request.Params["players-kick"] - local FoundPlayerCallback = function(Player) - if (Player:GetName() == KickPlayerName) then - Player:GetClientHandle():Kick("You were kicked from the game!") - end +<pre class="prettyprint lang-lua"> +local KickPlayerName = Request.Params["players-kick"] +local FoundPlayerCallback = function(Player) + if (Player:GetName() == KickPlayerName) then + Player:GetClientHandle():Kick("You were kicked from the game!") + end +end +cRoot:Get():FindAndDoWithPlayer(KickPlayerName, FoundPlayerCallback) +</pre> +The cRoot:FindAndDoWithPlayer() is unsafe and could have caused a deadlock. The new solution is queue a task; but since we don't know in which world the player is, we need to queue the task to all worlds: +<pre class="prettyprint lang-lua"> +cRoot:Get():ForEachWorld( -- For each world... + function(World) + World:QueueTask( -- ... queue a task... + function(a_World) + a_World:DoWithPlayer(KickPlayerName, -- ... to walk the playerlist... + function (a_Player) + a_Player:GetClientHandle():Kick("You were kicked from the game!") -- ... and kick the player end - cRoot:Get():FindAndDoWithPlayer(KickPlayerName, FoundPlayerCallback) - </pre> - The cRoot:FindAndDoWithPlayer() is unsafe and could have caused a deadlock. The new solution is queue a task; but since we don't know in which world the player is, we need to queue the task to all worlds: - <pre class="prettyprint lang-lua"> - cRoot:Get():ForEachWorld( -- For each world... - function(World) - World:QueueTask( -- ... queue a task... - function(a_World) - a_World:DoWithPlayer(KickPlayerName, -- ... to walk the playerlist... - function (a_Player) - a_Player:GetClientHandle():Kick("You were kicked from the game!") -- ... and kick the player - end - ) - end - ) - end - ) - </pre> + ) + end + ) + end +) +</pre> <script> prettyPrint(); </script> diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 52199740b..a25bab9cf 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -27,10 +27,14 @@ local function LoadAPIFiles(a_Folder, a_DstTable) -- We only want .lua files from the folder: if (cFile:IsFile(FileName) and fnam:match(".*%.lua$")) then local TablesFn, Err = loadfile(FileName); - if (TablesFn == nil) then + if (type(TablesFn) ~= "function") then LOGWARNING("Cannot load API descriptions from " .. FileName .. ", Lua error '" .. Err .. "'."); else local Tables = TablesFn(); + if (type(Tables) ~= "table") then + LOGWARNING("Cannot load API descriptions from " .. FileName .. ", returned object is not a table (" .. type(Tables) .. ")."); + break + end for k, cls in pairs(Tables) do a_DstTable[k] = cls; end diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua index 27e63aa5b..da5a9972c 100644 --- a/MCServer/Plugins/InfoReg.lua +++ b/MCServer/Plugins/InfoReg.lua @@ -16,22 +16,22 @@ local function ListSubcommands(a_Player, a_Subcommands, a_CmdString) end -- Enum all the subcommands: - local Verbs = {}; + local Verbs = {} for cmd, info in pairs(a_Subcommands) do - if (a_Player:HasPermission(info.Permission or "")) then - table.insert(Verbs, " " .. a_CmdString .. " " .. cmd); + if ((a_Player == nil) or (a_Player:HasPermission(info.Permission or ""))) then + table.insert(Verbs, a_CmdString .. " " .. cmd) end end - table.sort(Verbs); + table.sort(Verbs) -- Send the list: if (a_Player == nil) then for idx, verb in ipairs(Verbs) do - LOGINFO(verb); + LOGINFO(" " .. verb) end else for idx, verb in ipairs(Verbs) do - a_Player:SendMessage(verb); + a_Player:SendMessage(cCompositeChat(" ", mtInfo):AddSuggestCommandPart(verb, verb)) end end end diff --git a/MCServer/monsters.ini b/MCServer/monsters.ini index 8cd956157..b631fc1a9 100644 --- a/MCServer/monsters.ini +++ b/MCServer/monsters.ini @@ -47,14 +47,15 @@ AttackDamage=4.0 SightDistance=25.0 MaxHealth=40 -[Zombiepigman] +[ZombiePigman] AttackRange=2.0 AttackRate=1 AttackDamage=7.0 SightDistance=25.0 MaxHealth=20 +IsFireproof=1 -[Cavespider] +[CaveSpider] AttackRange=2.0 AttackRate=1 AttackDamage=2.0 @@ -74,6 +75,7 @@ AttackRate=1 AttackDamage=0.0 SightDistance=50.0 MaxHealth=10 +IsFireproof=1 [Silverfish] AttackRange=2.0 @@ -115,6 +117,7 @@ AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=20 +IsFireproof=1 [Villager] AttackRange=2.0 @@ -122,6 +125,7 @@ AttackRate=1 AttackDamage=0.0 SightDistance=25.0 MaxHealth=20 +IsFireproof=0 [Witch] AttackRange=2.0 @@ -145,12 +149,13 @@ AttackDamage=0.0 SightDistance=25.0 MaxHealth=10 -[Magmacube] +[MagmaCube] AttackRange=2.0 AttackRate=1 AttackDamage=6.0 SightDistance=25.0 MaxHealth=16 +IsFireproof=1 [Horse] AttackRange=2.0 diff --git a/MakeLuaAPI.cmd b/MakeLuaAPI.cmd index 7054977a0..90b8cf53e 100644 --- a/MakeLuaAPI.cmd +++ b/MakeLuaAPI.cmd @@ -30,7 +30,7 @@ if "a%ftpsite%" == "a" ( cd MCServer copy /Y settings_apidump.ini settings.ini -echo stop | MCServer +echo api | MCServer cd .. diff --git a/SetFlags.cmake b/SetFlags.cmake index c5a3a0697..4eed529bd 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -45,6 +45,8 @@ macro(set_flags) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") + add_flags_cxx("-stdlib=libc++") + add_flags_lnk("-stdlib=libc++") else() add_flags_cxx("-pthread") endif() diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index 01f1e88ad..a136c95df 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -36,14 +36,24 @@ set(SHARED_SRC ../../src/StringUtils.cpp ../../src/Log.cpp ../../src/MCLogger.cpp - ../../src/Crypto.cpp + ../../src/PolarSSL++/AesCfb128Decryptor.cpp + ../../src/PolarSSL++/AesCfb128Encryptor.cpp + ../../src/PolarSSL++/CtrDrbgContext.cpp + ../../src/PolarSSL++/EntropyContext.cpp + ../../src/PolarSSL++/PublicKey.cpp + ../../src/PolarSSL++/RsaPrivateKey.cpp ) set(SHARED_HDR ../../src/ByteBuffer.h ../../src/StringUtils.h ../../src/Log.h ../../src/MCLogger.h - ../../src/Crypto.h + ../../src/PolarSSL++/AesCfb128Decryptor.h + ../../src/PolarSSL++/AesCfb128Encryptor.h + ../../src/PolarSSL++/CtrDrbgContext.h + ../../src/PolarSSL++/EntropyContext.h + ../../src/PolarSSL++/PublicKey.h + ../../src/PolarSSL++/RsaPrivateKey.h ) set(SHARED_OSS_SRC ../../src/OSSupport/CriticalSection.cpp diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index d9b8e3dd1..26aed2206 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -7,6 +7,7 @@ #include "Connection.h" #include "Server.h" #include <iostream> +#include "PolarSSL++/PublicKey.h" #ifdef _WIN32 #include <direct.h> // For _mkdir() @@ -471,7 +472,7 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a -bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer) { DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer); const Byte * Data = (const Byte *)a_Data; @@ -495,7 +496,7 @@ bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryp -bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer) { AString All; a_Data.ReadAll(All); @@ -2197,11 +2198,39 @@ bool cConnection::HandleServerSpawnMob(void) +struct sSpawnData +{ + AString m_Name; + AString m_Value; + AString m_Signature; + sSpawnData(const AString & a_Name, const AString & a_Value, const AString & a_Signature) : + m_Name(a_Name), + m_Value(a_Value), + m_Signature(a_Signature) + { + } +}; + +typedef std::vector<sSpawnData> sSpawnDatas; + + + + + bool cConnection::HandleServerSpawnNamedEntity(void) { HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, EntityID); HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, EntityUUID); HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, EntityName); + HANDLE_SERVER_PACKET_READ(ReadVarInt, UInt32, DataCount); + sSpawnDatas Data; + for (UInt32 i = 0; i < DataCount; i++) + { + HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Name) + HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Value) + HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Signature) + Data.push_back(sSpawnData(Name, Value, Signature)); + } HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosX); HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosY); HANDLE_SERVER_PACKET_READ(ReadBEInt, int, PosZ); @@ -2219,6 +2248,13 @@ bool cConnection::HandleServerSpawnNamedEntity(void) Log(" EntityID = %u (0x%x)", EntityID, EntityID); Log(" UUID = \"%s\"", EntityUUID.c_str()); Log(" Name = \"%s\"", EntityName.c_str()); + Log(" NumData = %u", DataCount); + for (sSpawnDatas::const_iterator itr = Data.begin(), end = Data.end(); itr != end; ++itr) + { + Log(" Name = \"%s\", Value = \"%s\", Signature = \"%s\"", + itr->m_Name.c_str(), itr->m_Value.c_str(), itr->m_Signature.c_str() + ); + } // for itr - Data[] Log(" Pos = %s", PrintableAbsIntTriplet(PosX, PosY, PosZ).c_str()); Log(" Rotation = <yaw %d, pitch %d>", Yaw, Pitch); Log(" CurrentItem = %d", CurrentItem); diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index 9e04994b7..1fc9536de 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -11,6 +11,8 @@ #include "ByteBuffer.h" #include "OSSupport/Timer.h" +#include "PolarSSL++/AesCfb128Decryptor.h" +#include "PolarSSL++/AesCfb128Encryptor.h" @@ -66,8 +68,8 @@ protected: cByteBuffer m_ClientBuffer; cByteBuffer m_ServerBuffer; - cAESCFBDecryptor m_ServerDecryptor; - cAESCFBEncryptor m_ServerEncryptor; + cAesCfb128Decryptor m_ServerDecryptor; + cAesCfb128Encryptor m_ServerEncryptor; AString m_ServerEncryptionBuffer; // Buffer for the data to be sent to the server once encryption is established @@ -109,10 +111,10 @@ protected: bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); /// Decodes packets coming from the client, sends appropriate counterparts to the server; returns false if the connection is to be dropped bool DecodeClientsPackets(const char * a_Data, int a_Size); diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index e2f5aa860..a9b5aa1b1 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -216,6 +216,20 @@ typedef unsigned char Byte; // Pretty much the same as ASSERT() but stays in Release builds #define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) ) +// Allow both Older versions of MSVC and newer versions of everything use a shared_ptr: +// Note that we cannot typedef, because C++ doesn't allow (partial) templates to be typedeffed. +#if (defined(_MSC_VER) && (_MSC_VER < 1600)) + // MSVC before 2010 doesn't have std::shared_ptr, but has std::tr1::shared_ptr, defined in <memory> included earlier + #define SharedPtr std::tr1::shared_ptr +#elif (defined(_MSC_VER) || (__cplusplus >= 201103L)) + // C++11 has std::shared_ptr in <memory>, included earlier + #define SharedPtr std::shared_ptr +#else + // C++03 has std::tr1::shared_ptr in <tr1/memory> + #include <tr1/memory> + #define SharedPtr std::tr1::shared_ptr +#endif + @@ -232,12 +246,6 @@ public: -#include "../../src/Crypto.h" - - - - - #define LOGERROR printf #define LOGINFO printf #define LOGWARNING printf diff --git a/Tools/ProtoProxy/ProtoProxy.txt b/Tools/ProtoProxy/ProtoProxy.txt index e25d513f3..ee52f393e 100644 --- a/Tools/ProtoProxy/ProtoProxy.txt +++ b/Tools/ProtoProxy/ProtoProxy.txt @@ -20,7 +20,7 @@ You need to set the server *not* to verify usernames ("online-mode=false" in ser ProtoProxy is not much dependent on the protocol - it will work with unknown packets, it just won't parse them into human-readable format. -The latest protocol which has been tested is 1.6.1 (#73). +The latest protocol which has been tested is 1.7.9 (#5). */ diff --git a/Tools/ProtoProxy/Server.h b/Tools/ProtoProxy/Server.h index 85f817a4d..8adc7093d 100644 --- a/Tools/ProtoProxy/Server.h +++ b/Tools/ProtoProxy/Server.h @@ -9,6 +9,8 @@ #pragma once +#include "PolarSSL++/RsaPrivateKey.h" + @@ -17,7 +19,7 @@ class cServer { SOCKET m_ListenSocket; - cRSAPrivateKey m_PrivateKey; + cRsaPrivateKey m_PrivateKey; AString m_PublicKeyDER; short m_ConnectPort; @@ -27,7 +29,7 @@ public: int Init(short a_ListenPort, short a_ConnectPort); void Run(void); - cRSAPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } + cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } const AString & GetPublicKeyDER (void) { return m_PublicKeyDER; } short GetConnectPort(void) const { return m_ConnectPort; } diff --git a/lib/expat/CMakeLists.txt b/lib/expat/CMakeLists.txt index 667804b9a..a23f16609 100644 --- a/lib/expat/CMakeLists.txt +++ b/lib/expat/CMakeLists.txt @@ -4,12 +4,11 @@ project (expat) file(GLOB SOURCE "*.c" + "*.h" ) -# add headers to MSVC project files: -if (WIN32) - file(GLOB HEADERS "*.h") - set(SOURCE ${SOURCE} ${HEADERS}) +# Set files to go to a "Sources" folder in MSVC project files: +if (MSVC) source_group("Sources" FILES ${SOURCE}) endif() diff --git a/lib/inifile/CMakeLists.txt b/lib/inifile/CMakeLists.txt index efbd09796..321d501d7 100644 --- a/lib/inifile/CMakeLists.txt +++ b/lib/inifile/CMakeLists.txt @@ -1,7 +1,11 @@ - cmake_minimum_required (VERSION 2.6) project (iniFile) include_directories ("${PROJECT_SOURCE_DIR}/../../src/") -add_library(iniFile iniFile) +file(GLOB SOURCE + "*.h" + "*.cpp" +) + +add_library(iniFile ${SOURCE}) diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp index cf8b63987..19db9723a 100644 --- a/lib/inifile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp @@ -154,7 +154,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) case ';': case '#': { - if (names.size() == 0) + if (names.empty()) { AddHeaderComment(line.substr(pLeft + 1)); } @@ -168,8 +168,9 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) } // while (getline()) f.close(); - if (names.size() == 0) + if (keys.empty() && names.empty() && comments.empty()) { + // File be empty or unreadable, equivalent to nonexistant return false; } diff --git a/lib/luaexpat/CMakeLists.txt b/lib/luaexpat/CMakeLists.txt index 7eef5c8ce..f6b21c1d7 100644 --- a/lib/luaexpat/CMakeLists.txt +++ b/lib/luaexpat/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.c" + "*.h" ) add_library(luaexpat ${SOURCE}) diff --git a/lib/md5/CMakeLists.txt b/lib/md5/CMakeLists.txt index 8ba09a0dd..cd9fe6320 100644 --- a/lib/md5/CMakeLists.txt +++ b/lib/md5/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../src/") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(md5 ${SOURCE}) diff --git a/lib/polarssl b/lib/polarssl -Subproject 2cb1a0c4009ecf368ecc74eb428394e10f9e6d0 +Subproject 1ed82759c68f92c4acc7e3f33b850cf9f01c8ab diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index e5c8ce3e8..e68a0e15b 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -26,7 +26,11 @@ if(NOT XXD_EXECUTABLE STREQUAL "XXD_EXECUTABLE-NOTFOUND") COMMAND ${XXD_EXECUTABLE} -i lua/declaration.lua | sed 's/unsigned char/static const unsigned char/g' >declaration_lua.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/declaration.lua) - set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/src/bin/container_lua.h + COMMAND ${XXD_EXECUTABLE} -i lua/container.lua | sed 's/unsigned char/static const unsigned char/g' >container_lua.h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bin/ + DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/lua/container.lua) + set_property(SOURCE src/bin/toluabind.c APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/bin/enumerate_lua.h ${PROJECT_SOURCE_DIR}/src/bin/basic_lua.h ${PROJECT_SOURCE_DIR}/src/bin/function_lua.h ${PROJECT_SOURCE_DIR}/src/bin/declaration_lua.h ${PROJECT_SOURCE_DIR}/src/bin/container_lua.h) else() message("xxd not found, changes to tolua scripts will be ignored") endif() diff --git a/lib/tolua++/src/bin/container_lua.h b/lib/tolua++/src/bin/container_lua.h new file mode 100644 index 000000000..4c7cf6a67 --- /dev/null +++ b/lib/tolua++/src/bin/container_lua.h @@ -0,0 +1,1476 @@ +static const unsigned char lua_container_lua[] = { + 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x3a, 0x20, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x61, 0x62, 0x73, 0x74, + 0x72, 0x61, 0x63, 0x74, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x2d, + 0x2d, 0x20, 0x57, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x62, 0x79, + 0x20, 0x57, 0x61, 0x6c, 0x64, 0x65, 0x6d, 0x61, 0x72, 0x20, 0x43, 0x65, + 0x6c, 0x65, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x54, 0x65, 0x43, 0x47, 0x72, + 0x61, 0x66, 0x2f, 0x50, 0x55, 0x43, 0x2d, 0x52, 0x69, 0x6f, 0x0a, 0x2d, + 0x2d, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x31, 0x39, 0x39, 0x38, 0x0a, 0x2d, + 0x2d, 0x20, 0x24, 0x49, 0x64, 0x3a, 0x20, 0x24, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, + 0x61, 0x72, 0x65, 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, 0x6e, + 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x65, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x20, 0x69, 0x74, 0x2e, 0x0a, 0x2d, + 0x2d, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, + 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, + 0x68, 0x65, 0x72, 0x65, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x20, 0x69, 0x73, + 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x61, 0x73, 0x20, 0x69, + 0x73, 0x22, 0x20, 0x62, 0x61, 0x73, 0x69, 0x73, 0x2c, 0x20, 0x61, 0x6e, + 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x20, 0x68, 0x61, 0x73, 0x20, 0x6e, 0x6f, 0x20, 0x6f, + 0x62, 0x6c, 0x69, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, + 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x20, 0x6d, 0x61, 0x69, + 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x2c, 0x20, 0x73, 0x75, + 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x73, 0x2c, 0x0a, 0x2d, 0x2d, 0x20, 0x65, 0x6e, 0x68, 0x61, 0x6e, + 0x63, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2c, 0x20, 0x6f, 0x72, 0x20, + 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x20, 0x74, 0x6f, 0x20, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x2f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x20, + 0x69, 0x6e, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x73, 0x63, + 0x6f, 0x70, 0x65, 0x0a, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, + 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x0a, 0x2d, 0x2d, 0x20, 0x52, 0x65, 0x70, 0x72, 0x65, 0x73, + 0x65, 0x6e, 0x74, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x20, 0x6f, 0x66, 0x20, 0x66, 0x65, 0x61, 0x74, + 0x75, 0x72, 0x65, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65, 0x20, 0x62, + 0x6f, 0x75, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x74, 0x6f, 0x20, 0x6c, + 0x75, 0x61, 0x2e, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x3d, 0x0a, 0x7b, 0x0a, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x0a, + 0x7d, 0x0a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x5f, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, + 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, + 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2c, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x29, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x74, + 0x61, 0x67, 0x73, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x28, 0x29, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x64, 0x65, 0x63, 0x6c, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x6f, + 0x70, 0x28, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, + 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x73, 0x75, 0x70, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, 0x6c, + 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, + 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, 0x66, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x5f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x73, + 0x75, 0x70, 0x63, 0x6f, 0x64, 0x65, 0x28, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x70, 0x6f, 0x70, 0x28, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x68, 0x61, 0x73, 0x76, 0x61, 0x72, + 0x20, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x3a, 0x69, 0x73, + 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x31, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, + 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5f, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x74, 0x6f, 0x6c, + 0x75, 0x61, 0x5f, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, + 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x74, 0x6f, 0x6c, 0x75, + 0x61, 0x5f, 0x6e, 0x3d, 0x30, 0x7d, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x75, + 0x73, 0x68, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x75, + 0x73, 0x68, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x78, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, + 0x0a, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x6f, + 0x70, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x70, + 0x20, 0x28, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, + 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x66, + 0x6f, 0x72, 0x65, 0x61, 0x63, 0x68, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2c, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x22, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, + 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x22, 0x29, 0x0a, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x63, 0x75, + 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x67, 0x65, 0x74, 0x63, 0x75, 0x72, 0x72, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, + 0x72, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, + 0x65, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, + 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x29, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, + 0x75, 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x74, 0x6f, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, + 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x75, 0x72, 0x72, 0x65, + 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x29, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x65, + 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x2d, 0x2d, 0x20, 0x73, 0x75, 0x62, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, + 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x6d, 0x6f, 0x64, + 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x61, + 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, + 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x69, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x66, 0x69, 0x6e, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, + 0x20, 0x69, 0x73, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, + 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x69, 0x73, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x66, 0x75, + 0x6c, 0x6c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x77, 0x69, 0x74, 0x68, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x29, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x75, 0x6c, + 0x6c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x77, 0x68, + 0x69, 0x6c, 0x65, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x64, 0x6f, 0x0a, + 0x09, 0x20, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, + 0x73, 0x5b, 0x74, 0x5d, 0x0a, 0x09, 0x09, 0x20, 0x65, 0x6c, 0x73, 0x65, + 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x75, + 0x72, 0x72, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x75, 0x72, 0x72, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x74, + 0x5d, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x73, 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x72, 0x65, + 0x71, 0x75, 0x69, 0x72, 0x65, 0x73, 0x20, 0x63, 0x6f, 0x6c, 0x6c, 0x65, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, + 0x65, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x28, 0x74, 0x29, 0x0a, 0x20, 0x70, 0x75, 0x73, 0x68, 0x28, 0x73, 0x65, + 0x6c, 0x66, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, + 0x3d, 0x31, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x20, + 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x77, 0x68, 0x69, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x5b, 0x69, 0x5d, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x5b, 0x69, 0x5d, 0x3a, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x29, + 0x20, 0x6f, 0x72, 0x20, 0x72, 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, + 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x70, 0x6f, + 0x70, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x72, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, + 0x65, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x61, 0x70, 0x63, 0x65, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, + 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, + 0x63, 0x75, 0x72, 0x72, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, + 0x20, 0x27, 0x27, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, + 0x75, 0x72, 0x72, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x69, 0x66, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x20, + 0x20, 0x20, 0x28, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, + 0x3d, 0x20, 0x28, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6f, 0x72, 0x69, 0x67, + 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, + 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, + 0x2e, 0x2e, 0x20, 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x20, + 0x2d, 0x2d, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, + 0x3d, 0x20, 0x63, 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x2e, 0x2e, 0x20, 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x28, 0x6f, 0x6e, 0x6c, 0x79, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x29, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, + 0x6f, 0x6e, 0x6c, 0x79, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x20, 0x28, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x27, + 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x63, 0x75, 0x72, 0x72, + 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, + 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x63, + 0x75, 0x72, 0x72, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2e, 0x2e, 0x20, + 0x27, 0x3a, 0x3a, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x20, 0x63, 0x75, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x63, 0x75, 0x72, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x69, 0x66, 0x20, 0x69, + 0x73, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x3a, 0x69, 0x73, + 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, + 0x64, 0x20, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x74, 0x6f, + 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x0a, 0x20, 0x74, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, 0x75, + 0x72, 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, + 0x5f, 0x6e, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x2e, + 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x73, 0x5b, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x3d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, + 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x0a, + 0x09, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x73, 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, + 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x74, 0x2e, 0x66, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x29, 0x20, 0x6f, 0x72, 0x20, + 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x2d, 0x2d, 0x70, 0x72, + 0x69, 0x6e, 0x74, 0x28, 0x22, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, + 0x6e, 0x67, 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x22, + 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, + 0x20, 0x61, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x73, + 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, + 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x66, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x74, 0x2e, 0x66, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, 0x74, + 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, + 0x74, 0x2e, 0x66, 0x74, 0x79, 0x70, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x28, 0x74, 0x2e, 0x66, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, + 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x2e, 0x2e, + 0x74, 0x2e, 0x75, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x74, + 0x72, 0x75, 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x20, + 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x3a, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, 0x20, 0x3d, 0x3d, 0x20, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, + 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, + 0x6f, 0x78, 0x0a, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x66, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x29, 0x20, 0x2e, 0x2e, 0x20, + 0x74, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x74, + 0x5d, 0x20, 0x3d, 0x20, 0x66, 0x74, 0x0a, 0x09, 0x5f, 0x75, 0x73, 0x65, + 0x72, 0x74, 0x79, 0x70, 0x65, 0x5b, 0x66, 0x74, 0x5d, 0x20, 0x3d, 0x20, + 0x66, 0x74, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, + 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x0a, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x61, 0x70, + 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, + 0x6e, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x20, 0x2b, + 0x20, 0x31, 0x0a, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x65, 0x6e, 0x75, 0x6d, + 0x73, 0x2e, 0x74, 0x6f, 0x6c, 0x75, 0x61, 0x5f, 0x6e, 0x5d, 0x20, 0x3d, + 0x20, 0x74, 0x0a, 0x09, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x2e, 0x2e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, + 0x3d, 0x20, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, + 0x64, 0x65, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x75, + 0x61, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x28, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, + 0x20, 0x30, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, + 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, 0x61, 0x6d, + 0x65, 0x5d, 0x20, 0x2b, 0x20, 0x31, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x6d, + 0x61, 0x74, 0x28, 0x22, 0x25, 0x30, 0x32, 0x64, 0x22, 0x2c, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x5b, 0x6c, 0x6e, + 0x61, 0x6d, 0x65, 0x5d, 0x29, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x73, 0x20, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x3a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x27, 0x74, 0x68, 0x65, 0x20, + 0x66, 0x61, 0x63, 0x74, 0x6f, 0x27, 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, + 0x69, 0x65, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x20, 0x28, 0x6d, 0x6f, 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x66, 0x6f, 0x75, 0x6e, 0x64, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x22, 0x2e, 0x2e, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6d, 0x6f, 0x64, 0x31, 0x2c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x31, 0x20, + 0x3d, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, 0x65, 0x5d, 0x2e, + 0x6d, 0x6f, 0x64, 0x2c, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x2e, 0x66, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x2c, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x32, 0x20, 0x3d, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x28, 0x6d, 0x6f, 0x64, 0x2e, + 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x6d, 0x6f, 0x64, 0x31, 0x2c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x20, 0x2e, + 0x2e, 0x20, 0x27, 0x20, 0x27, 0x20, 0x2e, 0x2e, 0x20, 0x6d, 0x6f, 0x64, + 0x31, 0x2c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x32, 0x0a, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x32, 0x2c, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x32, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x64, 0x6f, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6d, 0x6f, + 0x64, 0x2c, 0x74, 0x79, 0x70, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x20, 0x69, 0x66, 0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x0a, 0x66, 0x75, 0x6e, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x69, 0x73, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x29, + 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x76, 0x20, + 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, + 0x65, 0x20, 0x65, 0x6e, 0x76, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x69, 0x5d, 0x2e, + 0x75, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x76, 0x20, 0x3d, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, + 0x69, 0x6e, 0x64, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x76, 0x61, 0x72, + 0x28, 0x76, 0x61, 0x72, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x74, + 0x6f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x28, 0x76, 0x61, 0x72, 0x29, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x76, 0x61, 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x63, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, + 0x63, 0x75, 0x72, 0x72, 0x0a, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, + 0x63, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x63, 0x29, 0x0a, 0x09, 0x09, + 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, + 0x61, 0x69, 0x72, 0x73, 0x28, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x28, 0x76, 0x61, 0x72, 0x2c, 0x20, 0x76, 0x2c, 0x20, + 0x6e, 0x73, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x0a, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x63, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, + 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x63, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x63, 0x3a, 0x66, 0x69, + 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x63, 0x2e, 0x62, 0x61, 0x73, + 0x65, 0x29, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x63, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x61, 0x72, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x20, + 0x69, 0x66, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x72, 0x65, 0x67, 0x69, + 0x73, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3a, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x75, 0x6c, 0x6c, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x6e, 0x69, 0x6c, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x3a, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x20, 0x28, 0x74, + 0x29, 0x0a, 0x0a, 0x09, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x2c, 0x20, 0x22, + 0x3d, 0x2e, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x5f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x5b, 0x74, 0x5d, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x74, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, 0x65, 0x6d, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x74, 0x2c, 0x20, 0x22, 0x28, 0x5b, 0x26, 0x25, 0x2a, 0x5d, + 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x29, 0x0a, 0x09, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x74, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x26, 0x25, + 0x2a, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x0a, 0x09, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, + 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x70, 0x20, 0x61, 0x6e, 0x64, + 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, 0x29, 0x3d, 0x3d, 0x27, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x27, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x67, 0x65, + 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x28, 0x70, + 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, 0x6f, 0x20, 0x2d, + 0x2d, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, + 0x20, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x74, 0x2c, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x73, 0x74, + 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x2e, + 0x28, 0x65, 0x6d, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x69, 0x66, 0x20, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x7e, + 0x3d, 0x20, 0x27, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x2e, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x74, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x28, 0x22, 0x74, 0x79, 0x70, 0x65, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, + 0x2e, 0x74, 0x2e, 0x2e, 0x22, 0x2c, 0x20, 0x70, 0x20, 0x69, 0x73, 0x20, + 0x22, 0x2e, 0x2e, 0x70, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x2e, 0x22, + 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x20, 0x69, + 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x74, 0x79, + 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x69, 0x73, 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x09, + 0x70, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x70, 0x3a, 0x66, 0x69, + 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, 0x2e, 0x62, 0x61, 0x73, + 0x65, 0x29, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x70, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x29, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x6e, 0x20, 0x3d, 0x20, + 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x6e, 0x20, 0x2b, 0x31, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, + 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x74, 0x0a, 0x09, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5f, 0x68, 0x61, + 0x73, 0x68, 0x5b, 0x74, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x0a, 0x09, 0x69, + 0x66, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x20, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, + 0x70, 0x70, 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, + 0x74, 0x79, 0x70, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, + 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x0a, 0x09, + 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x6c, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x6c, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x5f, + 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x28, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x2e, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x29, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, 0x73, 0x5b, + 0x74, 0x5d, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x0a, 0x09, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x65, + 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x0a, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x66, 0x6c, 0x61, 0x67, + 0x73, 0x20, 0x3d, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x2e, 0x66, 0x6c, + 0x61, 0x67, 0x73, 0x20, 0x6f, 0x72, 0x20, 0x7b, 0x7d, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x63, + 0x68, 0x69, 0x6c, 0x64, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x72, 0x65, + 0x67, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x73, 0x74, 0x29, 0x0a, 0x2d, + 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x66, 0x69, 0x6e, 0x64, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x22, 0x2e, 0x2e, 0x63, 0x68, 0x69, 0x6c, + 0x64, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x2c, 0x20, 0x22, 0x2e, + 0x2e, 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x2e, 0x2e, 0x22, 0x2c, + 0x20, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x72, 0x65, 0x67, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x20, 0x2d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x2c, 0x20, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, + 0x09, 0x69, 0x66, 0x20, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x72, 0x65, 0x67, 0x74, + 0x79, 0x70, 0x65, 0x29, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x28, 0x62, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x20, 0x6f, 0x72, 0x20, + 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, + 0x72, 0x65, 0x67, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x62, 0x2d, 0x31, + 0x2c, 0x20, 0x62, 0x2d, 0x31, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x3a, + 0x27, 0x20, 0x61, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x72, 0x65, 0x67, + 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x62, 0x2d, 0x31, + 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x62, + 0x2d, 0x31, 0x29, 0x29, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, + 0x70, 0x65, 0x5f, 0x6f, 0x6e, 0x5f, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x73, + 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2c, 0x20, 0x74, 0x29, 0x0a, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, + 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x65, + 0x6c, 0x66, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x66, + 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, + 0x61, 0x69, 0x72, 0x73, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x29, 0x20, 0x64, + 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x2e, 0x63, 0x6c, + 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x27, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x27, 0x20, 0x6f, 0x72, 0x20, 0x76, 0x2e, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x27, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x76, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, + 0x2e, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x73, 0x5b, 0x74, 0x5d, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, + 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x5b, 0x74, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x76, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x73, 0x5b, + 0x74, 0x5d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x20, 0x3d, 0x20, + 0x66, 0x69, 0x6e, 0x64, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x6f, 0x6e, 0x5f, + 0x63, 0x68, 0x69, 0x6c, 0x64, 0x73, 0x28, 0x76, 0x2c, 0x20, 0x74, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x63, 0x68, 0x69, + 0x6c, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x74, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x0a, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x3a, 0x69, 0x73, 0x65, 0x6e, 0x75, 0x6d, 0x20, 0x28, 0x74, 0x79, + 0x70, 0x65, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x67, 0x6c, 0x6f, 0x62, + 0x61, 0x6c, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x5b, 0x74, 0x79, 0x70, + 0x65, 0x5d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x20, 0x65, 0x6c, + 0x73, 0x65, 0x0a, 0x20, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x61, 0x73, 0x65, 0x74, + 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, + 0x79, 0x70, 0x65, 0x2c, 0x22, 0x5e, 0x2e, 0x2a, 0x3a, 0x3a, 0x22, 0x2c, + 0x22, 0x22, 0x29, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x65, + 0x6e, 0x76, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x0a, 0x20, 0x77, + 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x20, 0x20, + 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, + 0x75, 0x6d, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x5b, 0x69, 0x5d, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x3d, 0x20, 0x62, 0x61, 0x73, 0x65, 0x74, 0x79, 0x70, 0x65, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x20, 0x3d, + 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x76, 0x20, + 0x3d, 0x20, 0x65, 0x6e, 0x76, 0x2e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, + 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, + 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x20, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, + 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x63, + 0x68, 0x75, 0x6e, 0x6b, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x64, 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, + 0x20, 0x28, 0x73, 0x29, 0x0a, 0x2d, 0x2d, 0x70, 0x72, 0x69, 0x6e, 0x74, + 0x20, 0x28, 0x22, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x22, 0x2e, 0x2e, + 0x73, 0x29, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x72, 0x20, 0x68, + 0x6f, 0x6f, 0x6b, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x73, 0x75, 0x62, 0x20, 0x3d, 0x20, 0x70, 0x61, + 0x72, 0x73, 0x65, 0x72, 0x5f, 0x68, 0x6f, 0x6f, 0x6b, 0x28, 0x73, 0x29, + 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x73, 0x75, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x73, 0x75, 0x62, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x20, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x0a, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x20, 0x76, 0x65, 0x72, + 0x62, 0x61, 0x74, 0x69, 0x6d, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x24, 0x5c, 0x6e, 0x22, 0x29, 0x0a, + 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x4c, 0x75, 0x61, 0x20, + 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x31, + 0x5c, 0x32, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x64, + 0x65, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x63, 0x6f, 0x64, + 0x65, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x62, 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x33, 0x5c, 0x34, 0x29, 0x22, 0x29, + 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x7b, 0x27, + 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x63, 0x6f, 0x64, + 0x65, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x2e, 0x2e, 0x27, 0x5c, 0x6e, + 0x7d, 0x5c, 0x6e, 0x27, 0x0a, 0x09, 0x56, 0x65, 0x72, 0x62, 0x61, 0x74, + 0x69, 0x6d, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x27, 0x72, 0x27, 0x29, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x76, + 0x65, 0x72, 0x62, 0x61, 0x74, 0x69, 0x6d, 0x20, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x66, 0x6f, 0x72, 0x20, 0x27, 0x72, 0x27, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x20, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, + 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, + 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, + 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x43, 0x20, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x65, 0x61, 0x6d, 0x62, + 0x6c, 0x65, 0x20, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x5c, 0x35, 0x5c, + 0x36, 0x29, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x63, 0x6f, 0x64, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, + 0x62, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x2d, + 0x32, 0x29, 0x2e, 0x2e, 0x22, 0x5c, 0x6e, 0x22, 0x0a, 0x09, 0x09, 0x56, + 0x65, 0x72, 0x62, 0x61, 0x74, 0x69, 0x6d, 0x28, 0x63, 0x6f, 0x64, 0x65, + 0x2c, 0x20, 0x27, 0x27, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x20, 0x64, + 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x2c, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x50, 0x52, 0x4f, 0x50, 0x45, + 0x52, 0x54, 0x59, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x25, 0x73, 0x2a, 0x25, + 0x28, 0x2b, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x29, 0x25, 0x73, + 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x2b, 0x25, 0x73, 0x2a, + 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x22, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x09, 0x70, 0x74, 0x79, + 0x70, 0x65, 0x20, 0x3d, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, + 0x74, 0x22, 0x0a, 0x20, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x09, + 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, + 0x70, 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x09, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, + 0x74, 0x72, 0x79, 0x20, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, + 0x64, 0x5f, 0x64, 0x65, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, + 0x20, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x0a, 0x20, + 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, + 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x54, 0x4f, 0x4c, 0x55, 0x41, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x45, + 0x43, 0x54, 0x45, 0x44, 0x5f, 0x44, 0x45, 0x53, 0x54, 0x52, 0x55, 0x43, + 0x54, 0x4f, 0x52, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x09, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x73, 0x65, 0x74, 0x5f, + 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x64, 0x65, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x20, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x73, + 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, + 0x5f, 0x64, 0x65, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x6f, 0x72, 0x28, + 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, 0x09, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, + 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x27, 0x65, + 0x78, 0x74, 0x65, 0x72, 0x6e, 0x27, 0x20, 0x6b, 0x65, 0x79, 0x77, 0x6f, + 0x72, 0x64, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x25, + 0x73, 0x2b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x64, 0x6f, + 0x20, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x0a, 0x20, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x27, 0x76, 0x69, 0x72, 0x74, 0x75, + 0x61, 0x6c, 0x27, 0x20, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x6b, 0x64, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x25, 0x73, + 0x2b, 0x22, 0x29, 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x09, 0x09, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, + 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x20, 0x28, 0x70, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2c, 0x20, 0x70, 0x72, 0x69, 0x76, 0x61, + 0x74, 0x65, 0x2c, 0x20, 0x65, 0x74, 0x63, 0x29, 0x0a, 0x20, 0x64, 0x6f, + 0x0a, 0x20, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x25, + 0x77, 0x2a, 0x25, 0x73, 0x2a, 0x3a, 0x5b, 0x5e, 0x3a, 0x5d, 0x22, 0x29, + 0x0a, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x65, 0x29, 0x20, + 0x2d, 0x2d, 0x20, 0x70, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x5b, 0x5e, 0x3a, 0x5d, 0x0a, 0x20, 0x09, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x0a, + 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, + 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x6e, 0x61, 0x6d, + 0x65, 0x73, 0x61, 0x70, 0x63, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x25, + 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x25, 0x77, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, + 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x73, + 0x70, 0x61, 0x63, 0x65, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, + 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, + 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, + 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x23, 0x64, 0x65, + 0x66, 0x69, 0x6e, 0x65, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, + 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x5b, 0x5e, 0x5c, 0x6e, 0x5d, 0x2a, 0x5c, + 0x6e, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, + 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x44, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x65, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x73, 0x0a, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, + 0x64, 0x79, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x65, 0x6e, 0x75, 0x6d, 0x25, 0x73, 0x2b, 0x28, + 0x25, 0x53, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x73, 0x3b, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, + 0x23, 0x53, 0x6f, 0x72, 0x72, 0x79, 0x2c, 0x20, 0x64, 0x65, 0x63, 0x6c, + 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x65, + 0x6e, 0x75, 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, + 0x65, 0x20, 0x73, 0x61, 0x6d, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x5c, 0x6e, + 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x65, 0x20, 0x79, 0x6f, 0x75, 0x72, + 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x73, 0x65, + 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x6c, 0x79, 0x20, 0x28, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3a, 0x20, 0x27, 0x22, 0x2e, 0x2e, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x3b, 0x27, 0x29, 0x22, + 0x29, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, + 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, + 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x45, + 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, + 0x6d, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x2d, 0x2d, 0x20, 0x64, 0x6f, 0x0a, 0x2d, 0x2d, + 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x65, 0x6e, 0x75, 0x6d, 0x25, 0x73, 0x2b, 0x28, 0x25, + 0x53, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x2d, + 0x2d, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x2d, 0x2d, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x2d, 0x2d, 0x20, + 0x20, 0x20, 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, + 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x2d, + 0x2d, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x2d, 0x2d, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x2d, 0x2d, 0x20, 0x65, + 0x6e, 0x64, 0x20, 0x0a, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x25, 0x73, 0x2b, 0x65, 0x6e, + 0x75, 0x6d, 0x5b, 0x5e, 0x7b, 0x5d, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x77, 0x5f, 0x5d, 0x5b, 0x5e, + 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x45, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x61, 0x74, 0x65, 0x28, 0x6e, 0x61, + 0x6d, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, + 0x69, 0x6e, 0x64, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, + 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x2c, 0x5d, 0x2d, 0x25, 0x73, 0x2b, 0x6f, 0x70, 0x65, 0x72, 0x61, + 0x74, 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x73, + 0x5d, 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, + 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x25, 0x73, 0x2a, 0x3b, + 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x69, 0x6e, 0x6c, 0x69, + 0x6e, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, + 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x61, 0x72, 0x67, 0x2c, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, + 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x73, 0x25, + 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x2c, 0x5d, 0x2d, 0x25, 0x73, 0x2b, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x5b, 0x5e, 0x25, 0x73, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, + 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, + 0x5b, 0x25, 0x73, 0x5c, 0x6e, 0x5d, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, + 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x63, 0x61, 0x73, 0x74, 0x20, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x0a, 0x20, 0x20, 0x09, 0x62, + 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, + 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x20, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x29, 0x25, 0x73, 0x2b, 0x28, 0x5b, 0x25, 0x77, 0x5f, 0x3a, + 0x25, 0x64, 0x3c, 0x3e, 0x25, 0x2a, 0x25, 0x26, 0x25, 0x73, 0x5d, 0x2b, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, + 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, + 0x29, 0x22, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x09, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x69, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x22, + 0x2c, 0x20, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x69, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x09, 0x09, 0x09, 0x65, 0x20, 0x3d, 0x20, 0x69, 0x65, 0x0a, 0x20, 0x20, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x09, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, + 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, + 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x6b, 0x69, 0x6e, 0x64, 0x2c, 0x61, + 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, + 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x5d, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, 0x2a, + 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, + 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x25, 0x73, 0x2a, + 0x3d, 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, + 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, + 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x2c, 0x76, 0x69, 0x72, 0x74, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x5c, + 0x6e, 0x5d, 0x2b, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, + 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, + 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x28, 0x3d, 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, + 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, + 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x69, + 0x74, 0x68, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x0a, + 0x20, 0x20, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x5d, + 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x25, 0x62, 0x3c, 0x3e, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, + 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x3d, + 0x3f, 0x25, 0x73, 0x2a, 0x30, 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, + 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, + 0x61, 0x20, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x20, 0x6c, 0x65, 0x74, + 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, + 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, + 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, + 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, + 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, + 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, + 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x0a, + 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x3b, 0x5c, 0x6e, 0x5d, + 0x2b, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, + 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x20, 0x22, 0x25, 0x28, 0x25, 0x73, + 0x2a, 0x25, 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x29, 0x5d, 0x2a, 0x29, 0x25, + 0x73, 0x2a, 0x25, 0x29, 0x22, 0x2c, 0x20, 0x22, 0x20, 0x25, 0x31, 0x20, + 0x22, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x69, 0x66, 0x20, 0x76, 0x69, + 0x72, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x76, 0x69, 0x72, 0x74, 0x2c, + 0x20, 0x22, 0x5b, 0x3d, 0x30, 0x5d, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x20, 0x20, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x65, 0x6c, + 0x66, 0x2e, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x20, 0x20, 0x09, 0x09, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x66, + 0x6c, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x75, 0x72, 0x65, 0x5f, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x20, 0x20, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x09, + 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, + 0x20, 0x69, 0x66, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x3d, + 0x20, 0x27, 0x6f, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x27, + 0x27, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x20, + 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x65, 0x63, + 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, + 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, + 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, + 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x69, 0x6e, 0x6c, + 0x69, 0x6e, 0x65, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, + 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x28, 0x5b, 0x5e, 0x25, 0x28, 0x5c, 0x6e, 0x5d, 0x2b, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x63, 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, + 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, + 0x3f, 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, + 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x5b, 0x5e, 0x3b, 0x7b, + 0x5d, 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, + 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x7e, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x77, 0x25, 0x73, 0x25, 0x2a, 0x26, 0x3a, 0x3c, 0x3e, 0x5d, + 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x3e, 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x28, + 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, 0x3f, 0x6f, + 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x5b, 0x5e, 0x3b, 0x5d, + 0x2a, 0x25, 0x62, 0x7b, 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, + 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x2d, + 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6e, 0x67, + 0x6c, 0x65, 0x20, 0x6c, 0x65, 0x74, 0x74, 0x65, 0x72, 0x20, 0x66, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x0a, + 0x20, 0x20, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x2c, + 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x29, 0x25, 0x73, + 0x2a, 0x28, 0x25, 0x62, 0x28, 0x29, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x63, + 0x3f, 0x6f, 0x3f, 0x6e, 0x3f, 0x73, 0x3f, 0x74, 0x3f, 0x29, 0x76, 0x3f, + 0x65, 0x3f, 0x72, 0x3f, 0x72, 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, + 0x25, 0x73, 0x2a, 0x6f, 0x3f, 0x76, 0x3f, 0x65, 0x3f, 0x72, 0x3f, 0x72, + 0x3f, 0x69, 0x3f, 0x64, 0x3f, 0x65, 0x3f, 0x2e, 0x2d, 0x25, 0x62, 0x7b, + 0x7d, 0x25, 0x73, 0x2a, 0x3b, 0x3f, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, + 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x3d, 0x3d, 0x20, 0x27, 0x6f, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, + 0x20, 0x27, 0x27, 0x0a, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, + 0x65, 0x63, 0x6c, 0x2c, 0x61, 0x72, 0x67, 0x2c, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, + 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, + 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x0a, + 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x20, + 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x27, 0x27, 0x0a, 0x09, 0x09, + 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x5b, + 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, + 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, + 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x09, 0x69, + 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x0a, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, + 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, + 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, + 0x77, 0x40, 0x5d, 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x20, + 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, + 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, + 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, + 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x25, 0x73, 0x2a, + 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, + 0x2a, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, + 0x25, 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, 0x62, + 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, + 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x25, 0x73, 0x2b, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x09, 0x62, 0x2c, 0x65, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x2c, + 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x25, 0x73, 0x2a, 0x28, + 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, + 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5e, 0x7b, 0x5d, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x22, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, + 0x27, 0x27, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x62, 0x2c, + 0x65, 0x2c, 0x62, 0x6f, 0x64, 0x79, 0x2c, 0x6e, 0x61, 0x6d, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, + 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, + 0x25, 0x73, 0x25, 0x73, 0x2a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x25, + 0x73, 0x25, 0x73, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x2a, 0x25, 0x73, + 0x2a, 0x28, 0x25, 0x62, 0x7b, 0x7d, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x5b, + 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, 0x25, 0x77, 0x40, 0x5d, 0x2a, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, + 0x09, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, + 0x3d, 0x20, 0x31, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6c, + 0x73, 0x65, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x31, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, + 0x61, 0x73, 0x65, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x74, 0x68, + 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, + 0x2a, 0x3a, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x62, + 0x61, 0x73, 0x65, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x70, 0x6c, 0x69, 0x74, 0x28, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x20, + 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x2d, 0x2d, 0x62, 0x2c, 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x62, 0x61, + 0x73, 0x65, 0x2c, 0x22, 0x2e, 0x2d, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, + 0x5b, 0x5f, 0x25, 0x77, 0x3c, 0x3e, 0x2c, 0x3a, 0x5d, 0x2a, 0x29, 0x24, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, + 0x09, 0x09, 0x09, 0x62, 0x61, 0x73, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x7d, + 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x5f, + 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, 0x65, + 0x29, 0x0a, 0x09, 0x09, 0x09, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x2c, 0x62, 0x61, 0x73, 0x65, 0x2c, 0x62, 0x6f, 0x64, + 0x79, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, + 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x76, 0x61, 0x72, 0x62, 0x2c, 0x76, 0x61, 0x72, + 0x65, 0x2c, 0x76, 0x61, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, + 0x77, 0x5d, 0x2b, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x22, 0x2c, 0x20, 0x65, + 0x2b, 0x31, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, + 0x61, 0x72, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x6e, + 0x61, 0x6d, 0x65, 0x2e, 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x76, 0x61, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x65, 0x20, 0x3d, 0x20, 0x76, 0x61, 0x72, 0x65, 0x0a, 0x09, 0x09, 0x09, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x74, 0x79, 0x70, 0x65, + 0x64, 0x65, 0x66, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, + 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, 0x74, 0x79, 0x70, 0x65, 0x64, + 0x65, 0x66, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2d, 0x29, 0x25, + 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, 0x69, + 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x20, + 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, 0x2c, + 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x54, 0x79, 0x70, 0x65, 0x64, 0x65, + 0x66, 0x28, 0x74, 0x79, 0x70, 0x65, 0x73, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x74, 0x72, 0x79, 0x20, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, + 0x65, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5f, + 0x40, 0x25, 0x73, 0x25, 0x77, 0x25, 0x64, 0x25, 0x2a, 0x26, 0x3a, 0x3c, + 0x3e, 0x2c, 0x5d, 0x2a, 0x5b, 0x5f, 0x25, 0x77, 0x25, 0x64, 0x5d, 0x29, + 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, 0x20, 0x20, + 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x62, + 0x2c, 0x65, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6c, 0x69, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x64, 0x65, + 0x63, 0x6c, 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x56, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x6c, 0x69, 0x73, 0x74, 0x5b, + 0x31, 0x5d, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x69, 0x73, 0x74, + 0x2e, 0x6e, 0x20, 0x3e, 0x20, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x5f, 0x2c, 0x5f, 0x2c, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, + 0x6e, 0x64, 0x28, 0x6c, 0x69, 0x73, 0x74, 0x5b, 0x31, 0x5d, 0x2c, 0x20, + 0x22, 0x28, 0x2e, 0x2d, 0x29, 0x25, 0x73, 0x2b, 0x28, 0x5b, 0x5e, 0x25, + 0x73, 0x5d, 0x2a, 0x29, 0x24, 0x22, 0x29, 0x3b, 0x0a, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x20, 0x3d, 0x32, 0x3b, 0x0a, + 0x09, 0x09, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x6c, 0x69, 0x73, 0x74, + 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x56, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x79, 0x70, 0x65, 0x2e, + 0x2e, 0x22, 0x20, 0x22, 0x2e, 0x2e, 0x6c, 0x69, 0x73, 0x74, 0x5b, 0x69, + 0x5d, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x3d, 0x69, 0x2b, 0x31, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x20, + 0x20, 0x20, 0x2d, 0x2d, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, + 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x65, + 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, + 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, + 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x74, + 0x72, 0x79, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x0a, 0x20, 0x64, + 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x62, 0x2c, + 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, 0x5e, 0x25, 0x73, 0x2a, + 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x3f, 0x5b, 0x5f, 0x25, 0x73, 0x25, + 0x77, 0x25, 0x64, 0x5d, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x25, 0x73, 0x2b, + 0x5b, 0x5f, 0x40, 0x25, 0x77, 0x25, 0x64, 0x5d, 0x2a, 0x25, 0x73, 0x2a, + 0x25, 0x5b, 0x25, 0x73, 0x2a, 0x25, 0x53, 0x2b, 0x25, 0x73, 0x2a, 0x25, + 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x56, 0x61, 0x72, + 0x69, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, + 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, + 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x72, 0x79, 0x20, 0x61, 0x72, 0x72, 0x61, + 0x79, 0x0a, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x20, 0x62, 0x2c, 0x65, 0x2c, 0x64, 0x65, 0x63, 0x6c, 0x20, 0x3d, + 0x20, 0x73, 0x74, 0x72, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x73, 0x2c, 0x22, + 0x5e, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x5f, 0x25, 0x77, 0x5d, 0x5b, 0x5d, + 0x5b, 0x5f, 0x40, 0x25, 0x73, 0x25, 0x77, 0x25, 0x64, 0x25, 0x2a, 0x26, + 0x3a, 0x3c, 0x3e, 0x5d, 0x2a, 0x5b, 0x5d, 0x5f, 0x25, 0x77, 0x25, 0x64, + 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x3b, 0x25, 0x73, 0x2a, 0x22, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x66, 0x20, 0x62, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x20, 0x20, 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x73, + 0x2c, 0x62, 0x2c, 0x65, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x41, 0x72, 0x72, + 0x61, 0x79, 0x28, 0x64, 0x65, 0x63, 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x73, 0x75, + 0x62, 0x28, 0x73, 0x2c, 0x65, 0x2b, 0x31, 0x29, 0x0a, 0x20, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x2d, 0x2d, + 0x20, 0x6e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x69, 0x6e, 0x67, + 0x0a, 0x20, 0x69, 0x66, 0x20, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x22, 0x25, 0x73, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x22, 0x22, 0x29, 0x20, + 0x7e, 0x3d, 0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, + 0x20, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, + 0x3d, 0x20, 0x73, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, + 0x22, 0x23, 0x70, 0x61, 0x72, 0x73, 0x65, 0x20, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x22, 0x29, 0x0a, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x70, 0x61, 0x72, + 0x73, 0x65, 0x20, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x2d, 0x2d, 0x73, + 0x65, 0x6c, 0x66, 0x2e, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x6d, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x3d, + 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, + 0x20, 0x73, 0x20, 0x7e, 0x3d, 0x20, 0x27, 0x27, 0x20, 0x64, 0x6f, 0x0a, + 0x20, 0x20, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x3a, 0x64, + 0x6f, 0x70, 0x61, 0x72, 0x73, 0x65, 0x28, 0x73, 0x29, 0x0a, 0x20, 0x20, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x69, 0x73, 0x76, 0x69, 0x72, 0x74, + 0x75, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, + 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x2d, + 0x2d, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x20, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, + 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x0a, + 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x2e, 0x63, + 0x75, 0x72, 0x72, 0x3a, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, + 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x3a, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x70, + 0x74, 0x79, 0x70, 0x65, 0x29, 0x0a, 0x09, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, + 0x75, 0x62, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, 0x2c, 0x20, 0x22, 0x5e, + 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x70, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x70, 0x74, 0x79, 0x70, 0x65, + 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, + 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, + 0x20, 0x70, 0x74, 0x79, 0x70, 0x65, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x3a, + 0x67, 0x65, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x28, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, + 0x72, 0x20, 0x28, 0x73, 0x65, 0x6c, 0x66, 0x2e, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x65, 0x6c, 0x66, 0x2e, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x3a, 0x67, 0x65, 0x74, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x28, 0x29, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x22, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a +}; +unsigned int lua_container_lua_len = 17673; diff --git a/lib/tolua++/src/bin/function_lua.h b/lib/tolua++/src/bin/function_lua.h index bcb0bfca2..b34f106d2 100644 --- a/lib/tolua++/src/bin/function_lua.h +++ b/lib/tolua++/src/bin/function_lua.h @@ -990,14 +990,15 @@ static const unsigned char lua_function_lua[] = { 0x5f, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x73, 0x65, 0x74, 0x6d, 0x65, 0x74, 0x61, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x28, 0x74, 0x2c, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x0a, 0x20, 0x69, - 0x66, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, - 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, - 0x27, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, - 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x61, 0x6e, 0x64, 0x20, + 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x27, + 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x20, 0x20, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x28, 0x22, 0x23, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x20, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x27, 0x20, 0x73, 0x70, 0x65, + 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, + 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x29, 0x0a, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x28, 0x74, 0x29, 0x0a, 0x20, 0x69, 0x66, 0x20, 0x74, 0x3a, 0x69, 0x6e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x28, 0x29, 0x20, 0x74, @@ -1072,139 +1073,139 @@ static const unsigned char lua_function_lua[] = { 0x0a, 0x20, 0x2d, 0x2d, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x28, 0x73, 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, - 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x20, - 0x6e, 0x6f, 0x74, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, - 0x27, 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, - 0x2e, 0x25, 0x2e, 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, - 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, - 0x6e, 0x69, 0x6e, 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, - 0x69, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, - 0x6e, 0x74, 0x73, 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, - 0x61, 0x72, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, - 0x6f, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, - 0x2e, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, - 0x20, 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, - 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, - 0x3d, 0x30, 0x7d, 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, - 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, - 0x5d, 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, - 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, - 0x74, 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, - 0x29, 0x29, 0x3b, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, - 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, - 0x20, 0x31, 0x2c, 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x6c, 0x65, 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, - 0x29, 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, - 0x73, 0x20, 0x3d, 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, - 0x22, 0x2c, 0x22, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, - 0x2d, 0x31, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, - 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x67, 0x73, 0x75, 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, - 0x2a, 0x2c, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x2e, 0x2e, 0x27, 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, - 0x61, 0x75, 0x6c, 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, - 0x73, 0x2c, 0x20, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, - 0x69, 0x3d, 0x31, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, - 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, - 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, - 0x5b, 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, - 0x20, 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, - 0x5b, 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, - 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, - 0x2c, 0x27, 0x76, 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, - 0x0a, 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, - 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, - 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, - 0x0a, 0x20, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, - 0x0a, 0x20, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, - 0x63, 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, - 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, - 0x6e, 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, - 0x2c, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, - 0x74, 0x29, 0x0a, 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, - 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, - 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, - 0x20, 0x6f, 0x72, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, - 0x74, 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, - 0x20, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, - 0x22, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, - 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, - 0x66, 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, - 0x74, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, - 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, - 0x6c, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, - 0x09, 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, - 0x09, 0x09, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, - 0x65, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, - 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, - 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, - 0x70, 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x73, 0x28, 0x73, 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, - 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, - 0x20, 0x69, 0x3d, 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, - 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, - 0x61, 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, - 0x74, 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, - 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, - 0x09, 0x09, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, - 0x75, 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, - 0x2d, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, - 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, - 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, - 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, - 0x2d, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, - 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, - 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, - 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, - 0x2c, 0x20, 0x22, 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, - 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, - 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, - 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, - 0x2c, 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, - 0x20, 0x22, 0x22, 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, - 0x69, 0x3d, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, - 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, - 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, - 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, - 0x74, 0x2e, 0x2e, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, - 0x0a, 0x09, 0x09, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, - 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, - 0x72, 0x6e, 0x20, 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, - 0x2e, 0x22, 0x29, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a + 0x32, 0x2c, 0x2d, 0x32, 0x29, 0x29, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, + 0x6f, 0x74, 0x20, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x5b, 0x27, 0x57, 0x27, + 0x5d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x2c, 0x20, 0x22, 0x25, 0x2e, + 0x25, 0x2e, 0x25, 0x2e, 0x25, 0x73, 0x2a, 0x25, 0x29, 0x22, 0x29, 0x20, + 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x0a, 0x09, 0x09, 0x77, 0x61, 0x72, 0x6e, + 0x69, 0x6e, 0x67, 0x28, 0x22, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x76, 0x61, 0x72, 0x69, + 0x61, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x20, 0x28, 0x60, 0x2e, 0x2e, 0x2e, 0x27, 0x29, 0x20, 0x61, + 0x72, 0x65, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x64, 0x2e, 0x20, 0x49, 0x67, 0x6e, 0x6f, 0x72, 0x69, + 0x6e, 0x67, 0x20, 0x22, 0x2e, 0x2e, 0x64, 0x2e, 0x2e, 0x61, 0x2e, 0x2e, + 0x63, 0x29, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6e, 0x69, 0x6c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a, 0x20, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x3d, 0x31, 0x0a, 0x20, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x20, 0x3d, 0x20, 0x7b, 0x6e, 0x3d, + 0x30, 0x7d, 0x0a, 0x0a, 0x20, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, + 0x20, 0x22, 0x25, 0x73, 0x2a, 0x28, 0x5b, 0x25, 0x28, 0x25, 0x29, 0x5d, + 0x29, 0x25, 0x73, 0x2a, 0x22, 0x2c, 0x20, 0x22, 0x25, 0x31, 0x22, 0x29, + 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x2c, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x73, + 0x74, 0x72, 0x69, 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x74, + 0x72, 0x73, 0x75, 0x62, 0x28, 0x61, 0x2c, 0x32, 0x2c, 0x2d, 0x32, 0x29, + 0x29, 0x3b, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, + 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x73, 0x75, 0x62, 0x28, 0x73, 0x74, 0x72, 0x73, + 0x75, 0x62, 0x28, 0x61, 0x2c, 0x31, 0x2c, 0x2d, 0x32, 0x29, 0x2c, 0x20, + 0x31, 0x2c, 0x20, 0x2d, 0x28, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x6c, 0x65, 0x6e, 0x28, 0x6c, 0x61, 0x73, 0x74, 0x29, 0x2b, 0x31, 0x29, + 0x29, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x73, + 0x20, 0x3d, 0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x22, + 0x2c, 0x22, 0x2c, 0x20, 0x31, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x2d, + 0x31, 0x29, 0x0a, 0x0a, 0x09, 0x09, 0x6e, 0x73, 0x20, 0x3d, 0x20, 0x22, + 0x28, 0x22, 0x2e, 0x2e, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, + 0x73, 0x75, 0x62, 0x28, 0x6e, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x73, 0x2a, + 0x2c, 0x25, 0x73, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x2e, + 0x2e, 0x27, 0x29, 0x27, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x6e, 0x73, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x73, 0x28, 0x6e, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, 0x3d, 0x20, 0x46, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x64, 0x2c, 0x20, 0x6e, 0x73, + 0x2c, 0x20, 0x63, 0x29, 0x0a, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, + 0x3d, 0x31, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x09, + 0x09, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, + 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, + 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x5b, + 0x69, 0x5d, 0x20, 0x64, 0x6f, 0x0a, 0x20, 0x20, 0x6c, 0x2e, 0x6e, 0x20, + 0x3d, 0x20, 0x6c, 0x2e, 0x6e, 0x2b, 0x31, 0x0a, 0x20, 0x20, 0x6c, 0x5b, + 0x6c, 0x2e, 0x6e, 0x5d, 0x20, 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x27, 0x76, 0x61, 0x72, 0x27, 0x2c, 0x74, 0x72, 0x75, 0x65, 0x29, 0x0a, + 0x20, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x69, 0x2b, 0x31, 0x0a, 0x20, 0x65, + 0x6e, 0x64, 0x0a, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x20, + 0x3d, 0x20, 0x44, 0x65, 0x63, 0x6c, 0x61, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x28, 0x64, 0x2c, 0x27, 0x66, 0x75, 0x6e, 0x63, 0x27, 0x29, 0x0a, + 0x20, 0x66, 0x2e, 0x61, 0x72, 0x67, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x0a, + 0x20, 0x66, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x63, + 0x0a, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x46, 0x75, + 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x29, 0x0a, 0x65, 0x6e, + 0x64, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, + 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x70, 0x2c, + 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2c, 0x20, 0x6c, 0x61, 0x73, 0x74, + 0x29, 0x0a, 0x0a, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x3d, 0x20, + 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x0a, 0x09, + 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x20, + 0x6f, 0x72, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x67, 0x65, 0x74, + 0x6e, 0x28, 0x74, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, + 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a, 0x09, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x22, + 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x6f, 0x6f, + 0x70, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x66, + 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, + 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6f, 0x0a, 0x0a, 0x09, 0x09, + 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, 0x2e, 0x2e, 0x6c, + 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, 0x09, 0x09, + 0x6c, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x73, 0x65, 0x70, 0x0a, 0x09, + 0x09, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, + 0x74, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x72, 0x65, 0x74, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, + 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, + 0x6c, 0x69, 0x74, 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, + 0x28, 0x73, 0x2c, 0x20, 0x27, 0x2c, 0x27, 0x29, 0x0a, 0x09, 0x6c, 0x6f, + 0x63, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, + 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, + 0x69, 0x3d, 0x74, 0x2e, 0x6e, 0x2c, 0x31, 0x2c, 0x2d, 0x31, 0x20, 0x64, + 0x6f, 0x0a, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, + 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x28, 0x74, + 0x5b, 0x69, 0x5d, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, + 0x09, 0x6c, 0x61, 0x73, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x0a, 0x09, 0x09, + 0x09, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, + 0x65, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x70, 0x20, 0x74, 0x68, 0x65, + 0x6e, 0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x09, 0x74, 0x5b, 0x69, 0x5d, 0x20, + 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, + 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, 0x20, 0x22, 0x3d, 0x2e, 0x2a, + 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x2d, 0x2d, + 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x2c, 0x73, 0x74, 0x72, 0x69, + 0x70, 0x2c, 0x6c, 0x61, 0x73, 0x74, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, + 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x73, + 0x28, 0x73, 0x29, 0x0a, 0x0a, 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x5e, 0x25, 0x28, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, + 0x09, 0x73, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, + 0x67, 0x73, 0x75, 0x62, 0x28, 0x73, 0x2c, 0x20, 0x22, 0x25, 0x29, 0x24, + 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, 0x0a, 0x0a, 0x09, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x20, 0x74, 0x20, 0x3d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, + 0x5f, 0x63, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x28, 0x73, 0x2c, + 0x20, 0x22, 0x2c, 0x22, 0x29, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x20, 0x73, 0x65, 0x70, 0x2c, 0x20, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, + 0x22, 0x22, 0x2c, 0x22, 0x22, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, + 0x3d, 0x31, 0x2c, 0x74, 0x2e, 0x6e, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, + 0x74, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x2e, 0x67, 0x73, 0x75, 0x62, 0x28, 0x74, 0x5b, 0x69, 0x5d, 0x2c, + 0x20, 0x22, 0x3d, 0x2e, 0x2a, 0x24, 0x22, 0x2c, 0x20, 0x22, 0x22, 0x29, + 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x74, + 0x2e, 0x2e, 0x73, 0x65, 0x70, 0x2e, 0x2e, 0x74, 0x5b, 0x69, 0x5d, 0x0a, + 0x09, 0x09, 0x73, 0x65, 0x70, 0x20, 0x3d, 0x20, 0x22, 0x2c, 0x22, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, + 0x6e, 0x20, 0x22, 0x28, 0x22, 0x2e, 0x2e, 0x72, 0x65, 0x74, 0x2e, 0x2e, + 0x22, 0x29, 0x22, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x0a }; -unsigned int lua_function_lua_len = 14483; +unsigned int lua_function_lua_len = 14494; diff --git a/lib/tolua++/src/bin/lua/container.lua b/lib/tolua++/src/bin/lua/container.lua index 2d11db7df..99488479e 100644 --- a/lib/tolua++/src/bin/lua/container.lua +++ b/lib/tolua++/src/bin/lua/container.lua @@ -58,7 +58,7 @@ function classContainer:hasvar () while self[i] do if self[i]:isvariable() then return 1 - end + end i = i+1 end return 0 @@ -568,7 +568,7 @@ function classContainer:doparse (s) -- Enumerate(name,body) -- return strsub(s,e+1) -- end --- end +-- end do local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*") @@ -606,14 +606,14 @@ function classContainer:doparse (s) -- try function do --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") - local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*") + local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*(=?%s*0?)%s*;%s*") if not b then -- try function with template - b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*=?%s*0?%s*;%s*") end if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*;%s*") end if not b then -- try function pointer @@ -629,6 +629,9 @@ function classContainer:doparse (s) end end _curr_code = strsub(s,b,e) + if const == 'o' then + const = '' + end Function(decl,arg,const) return strsub(s,e+1) end @@ -636,14 +639,17 @@ function classContainer:doparse (s) -- try inline function do - local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*") + local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?[^;{]*%b{}%s*;?%s*") --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*") if not b then -- try a single letter function name - b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*") + b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?.-%b{}%s*;?%s*") end if b then _curr_code = strsub(s,b,e) + if const == 'o' then + const = '' + end Function(decl,arg,const) return strsub(s,e+1) end diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 3b6b53c5e..9338e0fbc 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -458,9 +458,8 @@ end -- Internal constructor function _Function (t) setmetatable(t,classFunction) - if t.const ~= 'const' and t.const ~= '' then - error("#invalid 'const' specification") + error("#invalid 'const' specification: " .. t.const) end append(t) @@ -489,7 +488,6 @@ end function Function (d,a,c) --local t = split(strsub(a,2,-2),',') -- eliminate braces --local t = split_params(strsub(a,2,-2)) - if not flags['W'] and string.find(a, "%.%.%.%s*%)") then warning("Functions with variable arguments (`...') are not supported. Ignoring "..d..a..c) diff --git a/lib/tolua++/src/bin/toluabind.c b/lib/tolua++/src/bin/toluabind.c index 06b371f70..e72b4b13c 100644 --- a/lib/tolua++/src/bin/toluabind.c +++ b/lib/tolua++/src/bin/toluabind.c @@ -1013,1170 +1013,8 @@ TOLUA_API int tolua_tolua_open (lua_State* tolua_S) { /* begin embedded lua code */ int top = lua_gettop(tolua_S); - static unsigned char B[] = { - 45, 45, 32,116,111,108,117, 97, 58, 32, 99,111,110,116, 97, - 105,110,101,114, 32, 97, 98,115,116,114, 97, 99,116, 32, 99, - 108, 97,115,115, 10, 45, 45, 32, 87,114,105,116,116,101,110, - 32, 98,121, 32, 87, 97,108,100,101,109, 97,114, 32, 67,101, - 108,101,115, 10, 45, 45, 32, 84,101, 67, 71,114, 97,102, 47, - 80, 85, 67, 45, 82,105,111, 10, 45, 45, 32, 74,117,108, 32, - 49, 57, 57, 56, 10, 45, 45, 32, 36, 73,100, 58, 32, 36, 10, - 10, 45, 45, 32, 84,104,105,115, 32, 99,111,100,101, 32,105, - 115, 32,102,114,101,101, 32,115,111,102,116,119, 97,114,101, - 59, 32,121,111,117, 32, 99, 97,110, 32,114,101,100,105,115, - 116,114,105, 98,117,116,101, 32,105,116, 32, 97,110,100, 47, - 111,114, 32,109,111,100,105,102,121, 32,105,116, 46, 10, 45, - 45, 32, 84,104,101, 32,115,111,102,116,119, 97,114,101, 32, - 112,114,111,118,105,100,101,100, 32,104,101,114,101,117,110, - 100,101,114, 32,105,115, 32,111,110, 32, 97,110, 32, 34, 97, - 115, 32,105,115, 34, 32, 98, 97,115,105,115, 44, 32, 97,110, - 100, 10, 45, 45, 32,116,104,101, 32, 97,117,116,104,111,114, - 32,104, 97,115, 32,110,111, 32,111, 98,108,105,103, 97,116, - 105,111,110, 32,116,111, 32,112,114,111,118,105,100,101, 32, - 109, 97,105,110,116,101,110, 97,110, 99,101, 44, 32,115,117, - 112,112,111,114,116, 44, 32,117,112,100, 97,116,101,115, 44, - 10, 45, 45, 32,101,110,104, 97,110, 99,101,109,101,110,116, - 115, 44, 32,111,114, 32,109,111,100,105,102,105, 99, 97,116, - 105,111,110,115, 46, 10, 10, 45, 45, 32,116, 97, 98,108,101, - 32,116,111, 32,115,116,111,114,101, 32,110, 97,109,101,115, - 112, 97, 99,101,100, 32,116,121,112,101,100,101,102,115, 47, - 101,110,117,109,115, 32,105,110, 32,103,108,111, 98, 97,108, - 32,115, 99,111,112,101, 10,103,108,111, 98, 97,108, 95,116, - 121,112,101,100,101,102,115, 32, 61, 32,123,125, 10,103,108, - 111, 98, 97,108, 95,101,110,117,109,115, 32, 61, 32,123,125, - 10, 10, 45, 45, 32, 67,111,110,116, 97,105,110,101,114, 32, - 99,108, 97,115,115, 10, 45, 45, 32, 82,101,112,114,101,115, - 101,110,116,115, 32, 97, 32, 99,111,110,116, 97,105,110,101, - 114, 32,111,102, 32,102,101, 97,116,117,114,101,115, 32,116, - 111, 32, 98,101, 32, 98,111,117,110,100, 10, 45, 45, 32,116, - 111, 32,108,117, 97, 46, 10, 99,108, 97,115,115, 67,111,110, - 116, 97,105,110,101,114, 32, 61, 10,123, 10, 32, 99,117,114, - 114, 32, 61, 32,110,105,108, 44, 10,125, 10, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 95, 95,105,110, - 100,101,120, 32, 61, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 10,115,101,116,109,101,116, 97,116, 97, - 98,108,101, 40, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 44, 99,108, 97,115,115, 70,101, 97,116,117,114, - 101, 41, 10, 10, 45, 45, 32,111,117,116,112,117,116, 32,116, - 97,103,115, 10,102,117,110, 99,116,105,111,110, 32, 99,108, - 97,115,115, 67,111,110,116, 97,105,110,101,114, 58,100,101, - 99,108,116,121,112,101, 32, 40, 41, 10, 32,112,117,115,104, - 40,115,101,108,102, 41, 10, 32,108,111, 99, 97,108, 32,105, - 61, 49, 10, 32,119,104,105,108,101, 32,115,101,108,102, 91, - 105, 93, 32,100,111, 10, 32, 32,115,101,108,102, 91,105, 93, - 58,100,101, 99,108,116,121,112,101, 40, 41, 10, 32, 32,105, - 32, 61, 32,105, 43, 49, 10, 32,101,110,100, 10, 32,112,111, - 112, 40, 41, 10,101,110,100, 10, 10, 10, 45, 45, 32,119,114, - 105,116,101, 32,115,117,112,112,111,114,116, 32, 99,111,100, - 101, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 58,115,117,112, 99, - 111,100,101, 32, 40, 41, 10, 10, 9,105,102, 32,110,111,116, - 32,115,101,108,102, 58, 99,104,101, 99,107, 95,112,117, 98, - 108,105, 99, 95, 97, 99, 99,101,115,115, 40, 41, 32,116,104, - 101,110, 10, 9, 9,114,101,116,117,114,110, 10, 9,101,110, - 100, 10, 10, 32,112,117,115,104, 40,115,101,108,102, 41, 10, - 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32,119,104,105, - 108,101, 32,115,101,108,102, 91,105, 93, 32,100,111, 10, 32, - 32,105,102, 32,115,101,108,102, 91,105, 93, 58, 99,104,101, - 99,107, 95,112,117, 98,108,105, 99, 95, 97, 99, 99,101,115, - 115, 40, 41, 32,116,104,101,110, 10, 32, 32, 9,115,101,108, - 102, 91,105, 93, 58,115,117,112, 99,111,100,101, 40, 41, 10, - 32, 32,101,110,100, 10, 32, 32,105, 32, 61, 32,105, 43, 49, - 10, 32,101,110,100, 10, 32,112,111,112, 40, 41, 10,101,110, - 100, 10, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 58,104, 97,115, - 118, 97,114, 32, 40, 41, 10, 32,108,111, 99, 97,108, 32,105, - 61, 49, 10, 32,119,104,105,108,101, 32,115,101,108,102, 91, - 105, 93, 32,100,111, 10, 32, 32,105,102, 32,115,101,108,102, - 91,105, 93, 58,105,115,118, 97,114,105, 97, 98,108,101, 40, - 41, 32,116,104,101,110, 10, 9, 9, 32,114,101,116,117,114, - 110, 32, 49, 10, 9, 9,101,110,100, 10, 32, 32,105, 32, 61, - 32,105, 43, 49, 10, 32,101,110,100, 10, 9,114,101,116,117, - 114,110, 32, 48, 10,101,110,100, 10, 10, 45, 45, 32, 73,110, - 116,101,114,110, 97,108, 32, 99,111,110,116, 97,105,110,101, - 114, 32, 99,111,110,115,116,114,117, 99,116,111,114, 10,102, - 117,110, 99,116,105,111,110, 32, 95, 67,111,110,116, 97,105, - 110,101,114, 32, 40,115,101,108,102, 41, 10, 32,115,101,116, - 109,101,116, 97,116, 97, 98,108,101, 40,115,101,108,102, 44, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 41, - 10, 32,115,101,108,102, 46,110, 32, 61, 32, 48, 10, 32,115, - 101,108,102, 46,116,121,112,101,100,101,102,115, 32, 61, 32, - 123,116,111,108,117, 97, 95,110, 61, 48,125, 10, 32,115,101, - 108,102, 46,117,115,101,114,116,121,112,101,115, 32, 61, 32, - 123,125, 10, 32,115,101,108,102, 46,101,110,117,109,115, 32, - 61, 32,123,116,111,108,117, 97, 95,110, 61, 48,125, 10, 32, - 115,101,108,102, 46,108,110, 97,109,101,115, 32, 61, 32,123, - 125, 10, 32,114,101,116,117,114,110, 32,115,101,108,102, 10, - 101,110,100, 10, 10, 45, 45, 32,112,117,115,104, 32, 99,111, - 110,116, 97,105,110,101,114, 10,102,117,110, 99,116,105,111, - 110, 32,112,117,115,104, 32, 40,116, 41, 10, 9,116, 46,112, - 114,111,120, 32, 61, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 46, 99,117,114,114, 10, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114, - 114, 32, 61, 32,116, 10,101,110,100, 10, 10, 45, 45, 32,112, - 111,112, 32, 99,111,110,116, 97,105,110,101,114, 10,102,117, - 110, 99,116,105,111,110, 32,112,111,112, 32, 40, 41, 10, 45, - 45,112,114,105,110,116, 40, 34,110, 97,109,101, 34, 44, 99, - 108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, 99, - 117,114,114, 46,110, 97,109,101, 41, 10, 45, 45,102,111,114, - 101, 97, 99,104, 40, 99,108, 97,115,115, 67,111,110,116, 97, - 105,110,101,114, 46, 99,117,114,114, 46,117,115,101,114,116, - 121,112,101,115, 44,112,114,105,110,116, 41, 10, 45, 45,112, - 114,105,110,116, 40, 34, 95, 95, 95, 95, 95, 95, 95, 95, 95, - 95, 95, 95, 95, 95, 34, 41, 10, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 32, 61, - 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 46,112,114,111,120, 10,101,110,100, 10, - 10, 45, 45, 32,103,101,116, 32, 99,117,114,114,101,110,116, - 32,110, 97,109,101,115,112, 97, 99,101, 10,102,117,110, 99, - 116,105,111,110, 32,103,101,116, 99,117,114,114,110, 97,109, - 101,115,112, 97, 99,101, 32, 40, 41, 10, 9,114,101,116,117, - 114,110, 32,103,101,116,110, 97,109,101,115,112, 97, 99,101, - 40, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 41, 10,101,110,100, 10, 10, 45, 45, 32, - 97,112,112,101,110,100, 32,116,111, 32, 99,117,114,114,101, - 110,116, 32, 99,111,110,116, 97,105,110,101,114, 10,102,117, - 110, 99,116,105,111,110, 32, 97,112,112,101,110,100, 32, 40, - 116, 41, 10, 32,114,101,116,117,114,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, - 58, 97,112,112,101,110,100, 40,116, 41, 10,101,110,100, 10, - 10, 45, 45, 32, 97,112,112,101,110,100, 32,116,121,112,101, - 100,101,102, 32,116,111, 32, 99,117,114,114,101,110,116, 32, - 99,111,110,116, 97,105,110,101,114, 10,102,117,110, 99,116, - 105,111,110, 32, 97,112,112,101,110,100,116,121,112,101,100, - 101,102, 32, 40,116, 41, 10, 32,114,101,116,117,114,110, 32, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, - 99,117,114,114, 58, 97,112,112,101,110,100,116,121,112,101, - 100,101,102, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, 32, - 97,112,112,101,110,100, 32,117,115,101,114,116,121,112,101, - 32,116,111, 32, 99,117,114,114,101,110,116, 32, 99,111,110, - 116, 97,105,110,101,114, 10,102,117,110, 99,116,105,111,110, - 32, 97,112,112,101,110,100,117,115,101,114,116,121,112,101, - 32, 40,116, 41, 10, 32,114,101,116,117,114,110, 32, 99,108, - 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, 99,117, - 114,114, 58, 97,112,112,101,110,100,117,115,101,114,116,121, - 112,101, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, 32, 97, - 112,112,101,110,100, 32,101,110,117,109, 32,116,111, 32, 99, - 117,114,114,101,110,116, 32, 99,111,110,116, 97,105,110,101, - 114, 10,102,117,110, 99,116,105,111,110, 32, 97,112,112,101, - 110,100,101,110,117,109, 32, 40,116, 41, 10, 32,114,101,116, - 117,114,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 46, 99,117,114,114, 58, 97,112,112,101,110,100, - 101,110,117,109, 40,116, 41, 10,101,110,100, 10, 10, 45, 45, - 32,115,117, 98,115,116,105,116,117,116,101, 32,116,121,112, - 101,100,101,102, 10,102,117,110, 99,116,105,111,110, 32, 97, - 112,112,108,121,116,121,112,101,100,101,102, 32, 40,109,111, - 100, 44,116,121,112,101, 41, 10, 32,114,101,116,117,114,110, - 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, - 46, 99,117,114,114, 58, 97,112,112,108,121,116,121,112,101, - 100,101,102, 40,109,111,100, 44,116,121,112,101, 41, 10,101, - 110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105,102, - 32,105,115, 32,116,121,112,101, 10,102,117,110, 99,116,105, - 111,110, 32,102,105,110,100,116,121,112,101, 32, 40,116,121, - 112,101, 41, 10, 32,108,111, 99, 97,108, 32,116, 32, 61, 32, - 99,108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 46, - 99,117,114,114, 58,102,105,110,100,116,121,112,101, 40,116, - 121,112,101, 41, 10, 9,114,101,116,117,114,110, 32,116, 10, - 101,110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105, - 102, 32,105,115, 32,116,121,112,101,100,101,102, 10,102,117, - 110, 99,116,105,111,110, 32,105,115,116,121,112,101,100,101, - 102, 32, 40,116,121,112,101, 41, 10, 32,114,101,116,117,114, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 46, 99,117,114,114, 58,105,115,116,121,112,101,100,101, - 102, 40,116,121,112,101, 41, 10,101,110,100, 10, 10, 45, 45, - 32,103,101,116, 32,102,117,108,108,116,121,112,101, 32, 40, - 119,105,116,104, 32,110, 97,109,101,115,112, 97, 99,101, 41, - 10,102,117,110, 99,116,105,111,110, 32,102,117,108,108,116, - 121,112,101, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, 32, - 99,117,114,114, 32, 61, 32, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 46, 99,117,114,114, 10, 9,119, - 104,105,108,101, 32, 99,117,114,114, 32,100,111, 10, 9, 32, - 105,102, 32, 99,117,114,114, 32,116,104,101,110, 10, 9, 9, - 32,105,102, 32, 99,117,114,114, 46,116,121,112,101,100,101, - 102,115, 32, 97,110,100, 32, 99,117,114,114, 46,116,121,112, - 101,100,101,102,115, 91,116, 93, 32,116,104,101,110, 10, 9, - 9, 32, 32,114,101,116,117,114,110, 32, 99,117,114,114, 46, - 116,121,112,101,100,101,102,115, 91,116, 93, 10, 9, 9, 32, - 101,108,115,101,105,102, 32, 99,117,114,114, 46,117,115,101, - 114,116,121,112,101,115, 32, 97,110,100, 32, 99,117,114,114, - 46,117,115,101,114,116,121,112,101,115, 91,116, 93, 32,116, - 104,101,110, 10, 9, 9, 32, 32,114,101,116,117,114,110, 32, - 99,117,114,114, 46,117,115,101,114,116,121,112,101,115, 91, - 116, 93, 10, 9, 9, 9,101,110,100, 10, 9, 9,101,110,100, - 10, 9, 32, 99,117,114,114, 32, 61, 32, 99,117,114,114, 46, - 112,114,111,120, 10, 9,101,110,100, 10, 9,114,101,116,117, - 114,110, 32,116, 10,101,110,100, 10, 10, 45, 45, 32, 99,104, - 101, 99,107,115, 32,105,102, 32,105,116, 32,114,101,113,117, - 105,114,101,115, 32, 99,111,108,108,101, 99,116,105,111,110, - 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 58,114,101,113,117,105, - 114,101, 99,111,108,108,101, 99,116,105,111,110, 32, 40,116, - 41, 10, 32,112,117,115,104, 40,115,101,108,102, 41, 10, 32, - 108,111, 99, 97,108, 32,105, 61, 49, 10, 9,108,111, 99, 97, - 108, 32,114, 32, 61, 32,102, 97,108,115,101, 10, 32,119,104, - 105,108,101, 32,115,101,108,102, 91,105, 93, 32,100,111, 10, - 32, 32,114, 32, 61, 32,115,101,108,102, 91,105, 93, 58,114, - 101,113,117,105,114,101, 99,111,108,108,101, 99,116,105,111, - 110, 40,116, 41, 32,111,114, 32,114, 10, 32, 32,105, 32, 61, - 32,105, 43, 49, 10, 32,101,110,100, 10, 9,112,111,112, 40, - 41, 10, 9,114,101,116,117,114,110, 32,114, 10,101,110,100, - 10, 10, 10, 45, 45, 32,103,101,116, 32,110, 97,109,101,115, - 97,112, 99,101, 10,102,117,110, 99,116,105,111,110, 32,103, - 101,116,110, 97,109,101,115,112, 97, 99,101, 32, 40, 99,117, - 114,114, 41, 10, 9,108,111, 99, 97,108, 32,110, 97,109,101, - 115,112, 97, 99,101, 32, 61, 32, 39, 39, 10, 9,119,104,105, - 108,101, 32, 99,117,114,114, 32,100,111, 10, 9, 32,105,102, - 32, 99,117,114,114, 32, 97,110,100, 10, 9, 9, 32, 32, 32, - 40, 32, 99,117,114,114, 46, 99,108, 97,115,115,116,121,112, - 101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32,111,114, - 32, 99,117,114,114, 46, 99,108, 97,115,115,116,121,112,101, - 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, 99,101, 39, - 41, 10, 9, 9,116,104,101,110, 10, 9, 9, 32,110, 97,109, - 101,115,112, 97, 99,101, 32, 61, 32, 40, 99,117,114,114, 46, - 111,114,105,103,105,110, 97,108, 95,110, 97,109,101, 32,111, - 114, 32, 99,117,114,114, 46,110, 97,109,101, 41, 32, 46, 46, - 32, 39, 58, 58, 39, 32, 46, 46, 32,110, 97,109,101,115,112, - 97, 99,101, 10, 9, 9, 32, 45, 45,110, 97,109,101,115,112, - 97, 99,101, 32, 61, 32, 99,117,114,114, 46,110, 97,109,101, - 32, 46, 46, 32, 39, 58, 58, 39, 32, 46, 46, 32,110, 97,109, - 101,115,112, 97, 99,101, 10, 9, 9,101,110,100, 10, 9, 32, - 99,117,114,114, 32, 61, 32, 99,117,114,114, 46,112,114,111, - 120, 10, 9,101,110,100, 10, 9,114,101,116,117,114,110, 32, - 110, 97,109,101,115,112, 97, 99,101, 10,101,110,100, 10, 10, - 45, 45, 32,103,101,116, 32,110, 97,109,101,115,112, 97, 99, - 101, 32, 40,111,110,108,121, 32,110, 97,109,101,115,112, 97, - 99,101, 41, 10,102,117,110, 99,116,105,111,110, 32,103,101, - 116,111,110,108,121,110, 97,109,101,115,112, 97, 99,101, 32, - 40, 41, 10, 32,108,111, 99, 97,108, 32, 99,117,114,114, 32, - 61, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 46, 99,117,114,114, 10, 9,108,111, 99, 97,108, 32,110, - 97,109,101,115,112, 97, 99,101, 32, 61, 32, 39, 39, 10, 9, - 119,104,105,108,101, 32, 99,117,114,114, 32,100,111, 10, 9, - 9,105,102, 32, 99,117,114,114, 46, 99,108, 97,115,115,116, - 121,112,101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32, - 116,104,101,110, 10, 9, 9, 32,114,101,116,117,114,110, 32, - 110, 97,109,101,115,112, 97, 99,101, 10, 9, 9,101,108,115, - 101,105,102, 32, 99,117,114,114, 46, 99,108, 97,115,115,116, - 121,112,101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, - 99,101, 39, 32,116,104,101,110, 10, 9, 9, 32,110, 97,109, - 101,115,112, 97, 99,101, 32, 61, 32, 99,117,114,114, 46,110, - 97,109,101, 32, 46, 46, 32, 39, 58, 58, 39, 32, 46, 46, 32, - 110, 97,109,101,115,112, 97, 99,101, 10, 9, 9,101,110,100, - 10, 9, 32, 99,117,114,114, 32, 61, 32, 99,117,114,114, 46, - 112,114,111,120, 10, 9,101,110,100, 10, 9,114,101,116,117, - 114,110, 32,110, 97,109,101,115,112, 97, 99,101, 10,101,110, - 100, 10, 10, 45, 45, 32, 99,104,101, 99,107, 32,105,102, 32, - 105,115, 32,101,110,117,109, 10,102,117,110, 99,116,105,111, - 110, 32,105,115,101,110,117,109, 32, 40,116,121,112,101, 41, - 10, 32,114,101,116,117,114,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 58,105, - 115,101,110,117,109, 40,116,121,112,101, 41, 10,101,110,100, - 10, 10, 45, 45, 32, 97,112,112,101,110,100, 32,102,101, 97, - 116,117,114,101, 32,116,111, 32, 99,111,110,116, 97,105,110, - 101,114, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97, - 115,115, 67,111,110,116, 97,105,110,101,114, 58, 97,112,112, - 101,110,100, 32, 40,116, 41, 10, 32,115,101,108,102, 46,110, - 32, 61, 32,115,101,108,102, 46,110, 32, 43, 32, 49, 10, 32, - 115,101,108,102, 91,115,101,108,102, 46,110, 93, 32, 61, 32, - 116, 10, 32,116, 46,112, 97,114,101,110,116, 32, 61, 32,115, - 101,108,102, 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112, - 101,110,100, 32,116,121,112,101,100,101,102, 10,102,117,110, - 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111,110,116, - 97,105,110,101,114, 58, 97,112,112,101,110,100,116,121,112, - 101,100,101,102, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, - 32,110, 97,109,101,115,112, 97, 99,101, 32, 61, 32,103,101, - 116,110, 97,109,101,115,112, 97, 99,101, 40, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, - 41, 10, 32,115,101,108,102, 46,116,121,112,101,100,101,102, - 115, 46,116,111,108,117, 97, 95,110, 32, 61, 32,115,101,108, - 102, 46,116,121,112,101,100,101,102,115, 46,116,111,108,117, - 97, 95,110, 32, 43, 32, 49, 10, 32,115,101,108,102, 46,116, - 121,112,101,100,101,102,115, 91,115,101,108,102, 46,116,121, - 112,101,100,101,102,115, 46,116,111,108,117, 97, 95,110, 93, - 32, 61, 32,116, 10, 9,115,101,108,102, 46,116,121,112,101, - 100,101,102,115, 91,116, 46,117,116,121,112,101, 93, 32, 61, - 32,110, 97,109,101,115,112, 97, 99,101, 32, 46, 46, 32,116, - 46,117,116,121,112,101, 10, 9,103,108,111, 98, 97,108, 95, - 116,121,112,101,100,101,102,115, 91,110, 97,109,101,115,112, - 97, 99,101, 46, 46,116, 46,117,116,121,112,101, 93, 32, 61, - 32,116, 10, 9,116, 46,102,116,121,112,101, 32, 61, 32,102, - 105,110,100,116,121,112,101, 40,116, 46,116,121,112,101, 41, - 32,111,114, 32,116, 46,116,121,112,101, 10, 9, 45, 45,112, - 114,105,110,116, 40, 34, 97,112,112,101,110,100,105,110,103, - 32,116,121,112,101,100,101,102, 32, 34, 46, 46,116, 46,117, - 116,121,112,101, 46, 46, 34, 32, 97,115, 32, 34, 46, 46,110, - 97,109,101,115,112, 97, 99,101, 46, 46,116, 46,117,116,121, - 112,101, 46, 46, 34, 32,119,105,116,104, 32,102,116,121,112, - 101, 32, 34, 46, 46,116, 46,102,116,121,112,101, 41, 10, 9, - 97,112,112,101,110,100, 95,103,108,111, 98, 97,108, 95,116, - 121,112,101, 40,110, 97,109,101,115,112, 97, 99,101, 46, 46, - 116, 46,117,116,121,112,101, 41, 10, 9,105,102, 32,116, 46, - 102,116,121,112,101, 32, 97,110,100, 32,105,115,101,110,117, - 109, 40,116, 46,102,116,121,112,101, 41, 32,116,104,101,110, - 10, 10, 9, 9,103,108,111, 98, 97,108, 95,101,110,117,109, - 115, 91,110, 97,109,101,115,112, 97, 99,101, 46, 46,116, 46, - 117,116,121,112,101, 93, 32, 61, 32,116,114,117,101, 10, 9, - 101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112, - 101,110,100, 32,117,115,101,114,116,121,112,101, 58, 32,114, - 101,116,117,114,110, 32,102,117,108,108, 32,116,121,112,101, - 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 58, 97,112,112,101,110, - 100,117,115,101,114,116,121,112,101, 32, 40,116, 41, 10, 9, - 108,111, 99, 97,108, 32, 99,111,110,116, 97,105,110,101,114, - 10, 9,105,102, 32,116, 32, 61, 61, 32, 40,115,101,108,102, - 46,111,114,105,103,105,110, 97,108, 95,110, 97,109,101, 32, - 111,114, 32,115,101,108,102, 46,110, 97,109,101, 41, 32,116, - 104,101,110, 10, 9, 9, 99,111,110,116, 97,105,110,101,114, - 32, 61, 32,115,101,108,102, 46,112,114,111,120, 10, 9,101, - 108,115,101, 10, 9, 9, 99,111,110,116, 97,105,110,101,114, - 32, 61, 32,115,101,108,102, 10, 9,101,110,100, 10, 9,108, - 111, 99, 97,108, 32,102,116, 32, 61, 32,103,101,116,110, 97, - 109,101,115,112, 97, 99,101, 40, 99,111,110,116, 97,105,110, - 101,114, 41, 32, 46, 46, 32,116, 10, 9, 99,111,110,116, 97, - 105,110,101,114, 46,117,115,101,114,116,121,112,101,115, 91, - 116, 93, 32, 61, 32,102,116, 10, 9, 95,117,115,101,114,116, - 121,112,101, 91,102,116, 93, 32, 61, 32,102,116, 10, 9,114, - 101,116,117,114,110, 32,102,116, 10,101,110,100, 10, 10, 45, - 45, 32, 97,112,112,101,110,100, 32,101,110,117,109, 10,102, - 117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 58, 97,112,112,101,110,100,101, - 110,117,109, 32, 40,116, 41, 10, 32,108,111, 99, 97,108, 32, - 110, 97,109,101,115,112, 97, 99,101, 32, 61, 32,103,101,116, - 110, 97,109,101,115,112, 97, 99,101, 40, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 41, - 10, 32,115,101,108,102, 46,101,110,117,109,115, 46,116,111, - 108,117, 97, 95,110, 32, 61, 32,115,101,108,102, 46,101,110, - 117,109,115, 46,116,111,108,117, 97, 95,110, 32, 43, 32, 49, - 10, 32,115,101,108,102, 46,101,110,117,109,115, 91,115,101, - 108,102, 46,101,110,117,109,115, 46,116,111,108,117, 97, 95, - 110, 93, 32, 61, 32,116, 10, 9,103,108,111, 98, 97,108, 95, - 101,110,117,109,115, 91,110, 97,109,101,115,112, 97, 99,101, - 46, 46,116, 46,110, 97,109,101, 93, 32, 61, 32,116, 10,101, - 110,100, 10, 10, 45, 45, 32,100,101,116,101,114,109,105,110, - 101, 32,108,117, 97, 32,102,117,110, 99,116,105,111,110, 32, - 110, 97,109,101, 32,111,118,101,114,108,111, 97,100, 10,102, - 117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67,111, - 110,116, 97,105,110,101,114, 58,111,118,101,114,108,111, 97, - 100, 32, 40,108,110, 97,109,101, 41, 10, 32,105,102, 32,110, - 111,116, 32,115,101,108,102, 46,108,110, 97,109,101,115, 91, - 108,110, 97,109,101, 93, 32,116,104,101,110, 10, 32, 32,115, - 101,108,102, 46,108,110, 97,109,101,115, 91,108,110, 97,109, - 101, 93, 32, 61, 32, 48, 10, 32,101,108,115,101, 10, 32, 32, - 115,101,108,102, 46,108,110, 97,109,101,115, 91,108,110, 97, - 109,101, 93, 32, 61, 32,115,101,108,102, 46,108,110, 97,109, - 101,115, 91,108,110, 97,109,101, 93, 32, 43, 32, 49, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,102,111,114, - 109, 97,116, 40, 34, 37, 48, 50,100, 34, 44,115,101,108,102, - 46,108,110, 97,109,101,115, 91,108,110, 97,109,101, 93, 41, - 10,101,110,100, 10, 10, 45, 45, 32, 97,112,112,108,105,101, - 115, 32,116,121,112,101,100,101,102, 58, 32,114,101,116,117, - 114,110,115, 32,116,104,101, 32, 39,116,104,101, 32,102, 97, - 99,116,111, 39, 32,109,111,100,105,102,105,101,114, 32, 97, - 110,100, 32,116,121,112,101, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 58, 97,112,112,108,121,116,121,112,101,100,101,102, 32, - 40,109,111,100, 44,116,121,112,101, 41, 10, 9,105,102, 32, - 103,108,111, 98, 97,108, 95,116,121,112,101,100,101,102,115, - 91,116,121,112,101, 93, 32,116,104,101,110, 10, 9, 9, 45, - 45,112,114,105,110,116, 40, 34,102,111,117,110,100, 32,116, - 121,112,101,100,101,102, 32, 34, 46, 46,103,108,111, 98, 97, - 108, 95,116,121,112,101,100,101,102,115, 91,116,121,112,101, - 93, 46,116,121,112,101, 41, 10, 9, 9,108,111, 99, 97,108, - 32,109,111,100, 49, 44, 32,116,121,112,101, 49, 32, 61, 32, - 103,108,111, 98, 97,108, 95,116,121,112,101,100,101,102,115, - 91,116,121,112,101, 93, 46,109,111,100, 44, 32,103,108,111, - 98, 97,108, 95,116,121,112,101,100,101,102,115, 91,116,121, - 112,101, 93, 46,102,116,121,112,101, 10, 9, 9,108,111, 99, - 97,108, 32,109,111,100, 50, 44, 32,116,121,112,101, 50, 32, - 61, 32, 97,112,112,108,121,116,121,112,101,100,101,102, 40, - 109,111,100, 46, 46, 34, 32, 34, 46, 46,109,111,100, 49, 44, - 32,116,121,112,101, 49, 41, 10, 9, 9, 45, 45,114,101,116, - 117,114,110, 32,109,111,100, 50, 32, 46, 46, 32, 39, 32, 39, - 32, 46, 46, 32,109,111,100, 49, 44, 32,116,121,112,101, 50, - 10, 9, 9,114,101,116,117,114,110, 32,109,111,100, 50, 44, - 32,116,121,112,101, 50, 10, 9,101,110,100, 10, 9,100,111, - 32,114,101,116,117,114,110, 32,109,111,100, 44,116,121,112, - 101, 32,101,110,100, 10,101,110,100, 10, 10, 45, 45, 32, 99, - 104,101, 99,107, 32,105,102, 32,105,116, 32,105,115, 32, 97, - 32,116,121,112,101,100,101,102, 10,102,117,110, 99,116,105, - 111,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110, - 101,114, 58,105,115,116,121,112,101,100,101,102, 32, 40,116, - 121,112,101, 41, 10, 32,108,111, 99, 97,108, 32,101,110,118, - 32, 61, 32,115,101,108,102, 10, 32,119,104,105,108,101, 32, - 101,110,118, 32,100,111, 10, 32, 32,105,102, 32,101,110,118, - 46,116,121,112,101,100,101,102,115, 32,116,104,101,110, 10, - 32, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, 10, 32, 32, - 32,119,104,105,108,101, 32,101,110,118, 46,116,121,112,101, - 100,101,102,115, 91,105, 93, 32,100,111, 10, 32, 32, 32, 32, - 105,102, 32,101,110,118, 46,116,121,112,101,100,101,102,115, - 91,105, 93, 46,117,116,121,112,101, 32, 61, 61, 32,116,121, - 112,101, 32,116,104,101,110, 10, 32, 32, 32, 32, 32, 32, 32, - 32, 32,114,101,116,117,114,110, 32,116,121,112,101, 10, 32, - 32, 32, 32, 32, 32, 32, 32,101,110,100, 10, 32, 32, 32, 32, - 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 32, 32,101,110,118, - 32, 61, 32,101,110,118, 46,112, 97,114,101,110,116, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,110,105,108, - 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, 32, - 102,105,110,100, 95,101,110,117,109, 95,118, 97,114, 40,118, - 97,114, 41, 10, 10, 9,105,102, 32,116,111,110,117,109, 98, - 101,114, 40,118, 97,114, 41, 32,116,104,101,110, 32,114,101, - 116,117,114,110, 32,118, 97,114, 32,101,110,100, 10, 10, 9, - 108,111, 99, 97,108, 32, 99, 32, 61, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 10, - 9,119,104,105,108,101, 32, 99, 32,100,111, 10, 9, 9,108, - 111, 99, 97,108, 32,110,115, 32, 61, 32,103,101,116,110, 97, - 109,101,115,112, 97, 99,101, 40, 99, 41, 10, 9, 9,102,111, - 114, 32,107, 44,118, 32,105,110, 32,112, 97,105,114,115, 40, - 95,103,108,111, 98, 97,108, 95,101,110,117,109,115, 41, 32, - 100,111, 10, 9, 9, 9,105,102, 32,109, 97,116, 99,104, 95, - 116,121,112,101, 40,118, 97,114, 44, 32,118, 44, 32,110,115, - 41, 32,116,104,101,110, 10, 9, 9, 9, 9,114,101,116,117, - 114,110, 32,118, 10, 9, 9, 9,101,110,100, 10, 9, 9,101, - 110,100, 10, 9, 9,105,102, 32, 99, 46, 98, 97,115,101, 32, - 97,110,100, 32, 99, 46, 98, 97,115,101, 32,126, 61, 32, 39, - 39, 32,116,104,101,110, 10, 9, 9, 9, 99, 32, 61, 32, 95, - 103,108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91, - 99, 58,102,105,110,100,116,121,112,101, 40, 99, 46, 98, 97, - 115,101, 41, 93, 10, 9, 9,101,108,115,101, 10, 9, 9, 9, - 99, 32, 61, 32,110,105,108, 10, 9, 9,101,110,100, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,118, 97, - 114, 10,101,110,100, 10, 10, 45, 45, 32, 99,104,101, 99,107, - 32,105,102, 32,105,115, 32, 97, 32,114,101,103,105,115,116, - 101,114,101,100, 32,116,121,112,101, 58, 32,114,101,116,117, - 114,110, 32,102,117,108,108, 32,116,121,112,101, 32,111,114, - 32,110,105,108, 10,102,117,110, 99,116,105,111,110, 32, 99, - 108, 97,115,115, 67,111,110,116, 97,105,110,101,114, 58,102, - 105,110,100,116,121,112,101, 32, 40,116, 41, 10, 10, 9,116, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 116, 44, 32, 34, 61, 46, 42, 34, 44, 32, 34, 34, 41, 10, 9, - 105,102, 32, 95, 98, 97,115,105, 99, 91,116, 93, 32,116,104, - 101,110, 10, 9, 32,114,101,116,117,114,110, 32,116, 10, 9, - 101,110,100, 10, 10, 9,108,111, 99, 97,108, 32, 95, 44, 95, - 44,101,109, 32, 61, 32,115,116,114,105,110,103, 46,102,105, - 110,100, 40,116, 44, 32, 34, 40, 91, 38, 37, 42, 93, 41, 37, - 115, 42, 36, 34, 41, 10, 9,116, 32, 61, 32,115,116,114,105, - 110,103, 46,103,115,117, 98, 40,116, 44, 32, 34, 37,115, 42, - 40, 91, 38, 37, 42, 93, 41, 37,115, 42, 36, 34, 44, 32, 34, - 34, 41, 10, 9,112, 32, 61, 32,115,101,108,102, 10, 9,119, - 104,105,108,101, 32,112, 32, 97,110,100, 32,116,121,112,101, - 40,112, 41, 61, 61, 39,116, 97, 98,108,101, 39, 32,100,111, - 10, 9, 9,108,111, 99, 97,108, 32,115,116, 32, 61, 32,103, - 101,116,110, 97,109,101,115,112, 97, 99,101, 40,112, 41, 10, - 10, 9, 9,102,111,114, 32,105, 61, 95,103,108,111, 98, 97, - 108, 95,116,121,112,101,115, 46,110, 44, 49, 44, 45, 49, 32, - 100,111, 32, 45, 45, 32,105,110, 32,114,101,118,101,114,115, - 101, 32,111,114,100,101,114, 10, 10, 9, 9, 9,105,102, 32, - 109, 97,116, 99,104, 95,116,121,112,101, 40,116, 44, 32, 95, - 103,108,111, 98, 97,108, 95,116,121,112,101,115, 91,105, 93, - 44, 32,115,116, 41, 32,116,104,101,110, 10, 9, 9, 9, 9, - 114,101,116,117,114,110, 32, 95,103,108,111, 98, 97,108, 95, - 116,121,112,101,115, 91,105, 93, 46, 46, 40,101,109, 32,111, - 114, 32, 34, 34, 41, 10, 9, 9, 9,101,110,100, 10, 9, 9, - 101,110,100, 10, 9, 9,105,102, 32,112, 46, 98, 97,115,101, - 32, 97,110,100, 32,112, 46, 98, 97,115,101, 32,126, 61, 32, - 39, 39, 32, 97,110,100, 32,112, 46, 98, 97,115,101, 32,126, - 61, 32,116, 32,116,104,101,110, 10, 9, 9, 9, 45, 45,112, - 114,105,110,116, 40, 34,116,121,112,101, 32,105,115, 32, 34, - 46, 46,116, 46, 46, 34, 44, 32,112, 32,105,115, 32, 34, 46, - 46,112, 46, 98, 97,115,101, 46, 46, 34, 32,115,101,108,102, - 46,116,121,112,101, 32,105,115, 32, 34, 46, 46,115,101,108, - 102, 46,116,121,112,101, 46, 46, 34, 32,115,101,108,102, 46, - 110, 97,109,101, 32,105,115, 32, 34, 46, 46,115,101,108,102, - 46,110, 97,109,101, 41, 10, 9, 9, 9,112, 32, 61, 32, 95, - 103,108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91, - 112, 58,102,105,110,100,116,121,112,101, 40,112, 46, 98, 97, - 115,101, 41, 93, 10, 9, 9,101,108,115,101, 10, 9, 9, 9, - 112, 32, 61, 32,110,105,108, 10, 9, 9,101,110,100, 10, 9, - 101,110,100, 10, 10, 9,114,101,116,117,114,110, 32,110,105, - 108, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32, 97,112,112,101,110,100, 95,103,108,111, 98, 97,108, 95, - 116,121,112,101, 40,116, 44, 32, 99,108, 97,115,115, 41, 10, - 9, 95,103,108,111, 98, 97,108, 95,116,121,112,101,115, 46, - 110, 32, 61, 32, 95,103,108,111, 98, 97,108, 95,116,121,112, - 101,115, 46,110, 32, 43, 49, 10, 9, 95,103,108,111, 98, 97, - 108, 95,116,121,112,101,115, 91, 95,103,108,111, 98, 97,108, - 95,116,121,112,101,115, 46,110, 93, 32, 61, 32,116, 10, 9, - 95,103,108,111, 98, 97,108, 95,116,121,112,101,115, 95,104, - 97,115,104, 91,116, 93, 32, 61, 32, 49, 10, 9,105,102, 32, - 99,108, 97,115,115, 32,116,104,101,110, 32, 97,112,112,101, - 110,100, 95, 99,108, 97,115,115, 95,116,121,112,101, 40,116, - 44, 32, 99,108, 97,115,115, 41, 32,101,110,100, 10,101,110, - 100, 10, 10,102,117,110, 99,116,105,111,110, 32, 97,112,112, - 101,110,100, 95, 99,108, 97,115,115, 95,116,121,112,101, 40, - 116, 44, 99,108, 97,115,115, 41, 10, 9,105,102, 32, 95,103, - 108,111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91,116, - 93, 32,116,104,101,110, 10, 9, 9, 99,108, 97,115,115, 46, - 102,108, 97,103,115, 32, 61, 32, 95,103,108,111, 98, 97,108, - 95, 99,108, 97,115,115,101,115, 91,116, 93, 46,102,108, 97, - 103,115, 10, 9, 9, 99,108, 97,115,115, 46,108,110, 97,109, - 101,115, 32, 61, 32, 95,103,108,111, 98, 97,108, 95, 99,108, - 97,115,115,101,115, 91,116, 93, 46,108,110, 97,109,101,115, - 10, 9, 9,105,102, 32, 95,103,108,111, 98, 97,108, 95, 99, - 108, 97,115,115,101,115, 91,116, 93, 46, 98, 97,115,101, 32, - 97,110,100, 32, 40, 95,103,108,111, 98, 97,108, 95, 99,108, - 97,115,115,101,115, 91,116, 93, 46, 98, 97,115,101, 32,126, - 61, 32, 39, 39, 41, 32,116,104,101,110, 10, 9, 9, 9, 99, - 108, 97,115,115, 46, 98, 97,115,101, 32, 61, 32, 95,103,108, - 111, 98, 97,108, 95, 99,108, 97,115,115,101,115, 91,116, 93, - 46, 98, 97,115,101, 32,111,114, 32, 99,108, 97,115,115, 46, - 98, 97,115,101, 10, 9, 9,101,110,100, 10, 9,101,110,100, - 10, 9, 95,103,108,111, 98, 97,108, 95, 99,108, 97,115,115, - 101,115, 91,116, 93, 32, 61, 32, 99,108, 97,115,115, 10, 9, - 99,108, 97,115,115, 46,102,108, 97,103,115, 32, 61, 32, 99, - 108, 97,115,115, 46,102,108, 97,103,115, 32,111,114, 32,123, - 125, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,109, 97,116, 99,104, 95,116,121,112,101, 40, 99,104,105, - 108,100,116,121,112,101, 44, 32,114,101,103,116,121,112,101, - 44, 32,115,116, 41, 10, 45, 45,112,114,105,110,116, 40, 34, - 102,105,110,100,116,121,112,101, 32, 34, 46, 46, 99,104,105, - 108,100,116,121,112,101, 46, 46, 34, 44, 32, 34, 46, 46,114, - 101,103,116,121,112,101, 46, 46, 34, 44, 32, 34, 46, 46,115, - 116, 41, 10, 9,108,111, 99, 97,108, 32, 98, 44,101, 32, 61, - 32,115,116,114,105,110,103, 46,102,105,110,100, 40,114,101, - 103,116,121,112,101, 44, 32, 99,104,105,108,100,116,121,112, - 101, 44, 32, 45,115,116,114,105,110,103, 46,108,101,110, 40, - 99,104,105,108,100,116,121,112,101, 41, 44, 32,116,114,117, - 101, 41, 10, 9,105,102, 32, 98, 32,116,104,101,110, 10, 10, - 9, 9,105,102, 32,101, 32, 61, 61, 32,115,116,114,105,110, - 103, 46,108,101,110, 40,114,101,103,116,121,112,101, 41, 32, - 97,110,100, 10, 9, 9, 9, 9, 40, 98, 32, 61, 61, 32, 49, - 32,111,114, 32, 40,115,116,114,105,110,103, 46,115,117, 98, - 40,114,101,103,116,121,112,101, 44, 32, 98, 45, 49, 44, 32, - 98, 45, 49, 41, 32, 61, 61, 32, 39, 58, 39, 32, 97,110,100, - 10, 9, 9, 9, 9,115,116,114,105,110,103, 46,115,117, 98, - 40,114,101,103,116,121,112,101, 44, 32, 49, 44, 32, 98, 45, - 49, 41, 32, 61, 61, 32,115,116,114,105,110,103, 46,115,117, - 98, 40,115,116, 44, 32, 49, 44, 32, 98, 45, 49, 41, 41, 41, - 32,116,104,101,110, 10, 9, 9, 9,114,101,116,117,114,110, - 32,116,114,117,101, 10, 9, 9,101,110,100, 10, 9,101,110, - 100, 10, 10, 9,114,101,116,117,114,110, 32,102, 97,108,115, - 101, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111,110, - 32,102,105,110,100,116,121,112,101, 95,111,110, 95, 99,104, - 105,108,100,115, 40,115,101,108,102, 44, 32,116, 41, 10, 10, - 9,108,111, 99, 97,108, 32,116, 99,104,105,108,100, 10, 9, - 105,102, 32,115,101,108,102, 46, 99,108, 97,115,115,116,121, - 112,101, 32, 61, 61, 32, 39, 99,108, 97,115,115, 39, 32,111, - 114, 32,115,101,108,102, 46, 99,108, 97,115,115,116,121,112, - 101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, 97, 99,101, - 39, 32,116,104,101,110, 10, 9, 9,102,111,114, 32,107, 44, - 118, 32,105,110, 32,105,112, 97,105,114,115, 40,115,101,108, - 102, 41, 32,100,111, 10, 9, 9, 9,105,102, 32,118, 46, 99, - 108, 97,115,115,116,121,112,101, 32, 61, 61, 32, 39, 99,108, - 97,115,115, 39, 32,111,114, 32,118, 46, 99,108, 97,115,115, - 116,121,112,101, 32, 61, 61, 32, 39,110, 97,109,101,115,112, - 97, 99,101, 39, 32,116,104,101,110, 10, 9, 9, 9, 9,105, - 102, 32,118, 46,116,121,112,101,100,101,102,115, 32, 97,110, - 100, 32,118, 46,116,121,112,101,100,101,102,115, 91,116, 93, - 32,116,104,101,110, 10, 9, 9, 9, 9, 32,114,101,116,117, - 114,110, 32,118, 46,116,121,112,101,100,101,102,115, 91,116, - 93, 10, 9, 9, 9, 9,101,108,115,101,105,102, 32,118, 46, - 117,115,101,114,116,121,112,101,115, 32, 97,110,100, 32,118, - 46,117,115,101,114,116,121,112,101,115, 91,116, 93, 32,116, - 104,101,110, 10, 9, 9, 9, 9, 32,114,101,116,117,114,110, - 32,118, 46,117,115,101,114,116,121,112,101,115, 91,116, 93, - 10, 9, 9, 9, 9,101,110,100, 10, 9, 9, 9, 9,116, 99, - 104,105,108,100, 32, 61, 32,102,105,110,100,116,121,112,101, - 95,111,110, 95, 99,104,105,108,100,115, 40,118, 44, 32,116, - 41, 10, 9, 9, 9, 9,105,102, 32,116, 99,104,105,108,100, - 32,116,104,101,110, 32,114,101,116,117,114,110, 32,116, 99, - 104,105,108,100, 32,101,110,100, 10, 9, 9, 9,101,110,100, - 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 9,114,101, - 116,117,114,110, 32,110,105,108, 10, 10,101,110,100, 10, 10, - 102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 58,105,115,101,110,117,109, - 32, 40,116,121,112,101, 41, 10, 32,105,102, 32,103,108,111, - 98, 97,108, 95,101,110,117,109,115, 91,116,121,112,101, 93, - 32,116,104,101,110, 10, 9,114,101,116,117,114,110, 32,116, - 121,112,101, 10, 32,101,108,115,101, 10, 32, 9,114,101,116, - 117,114,110, 32,102, 97,108,115,101, 10, 32,101,110,100, 10, - 10, 32,108,111, 99, 97,108, 32, 98, 97,115,101,116,121,112, - 101, 32, 61, 32,103,115,117, 98, 40,116,121,112,101, 44, 34, - 94, 46, 42, 58, 58, 34, 44, 34, 34, 41, 10, 32,108,111, 99, - 97,108, 32,101,110,118, 32, 61, 32,115,101,108,102, 10, 32, - 119,104,105,108,101, 32,101,110,118, 32,100,111, 10, 32, 32, - 105,102, 32,101,110,118, 46,101,110,117,109,115, 32,116,104, - 101,110, 10, 32, 32, 32,108,111, 99, 97,108, 32,105, 61, 49, - 10, 32, 32, 32,119,104,105,108,101, 32,101,110,118, 46,101, - 110,117,109,115, 91,105, 93, 32,100,111, 10, 32, 32, 32, 32, - 105,102, 32,101,110,118, 46,101,110,117,109,115, 91,105, 93, - 46,110, 97,109,101, 32, 61, 61, 32, 98, 97,115,101,116,121, - 112,101, 32,116,104,101,110, 10, 32, 32, 32, 32, 32, 32, 32, - 32, 32,114,101,116,117,114,110, 32,116,114,117,101, 10, 32, - 32, 32, 32, 32, 32, 32, 32,101,110,100, 10, 32, 32, 32, 32, - 32, 32, 32, 32,105, 32, 61, 32,105, 43, 49, 10, 32, 32, 32, - 101,110,100, 10, 32, 32,101,110,100, 10, 32, 32,101,110,118, - 32, 61, 32,101,110,118, 46,112, 97,114,101,110,116, 10, 32, - 101,110,100, 10, 32,114,101,116,117,114,110, 32,102, 97,108, - 115,101, 10,101,110,100, 10, 10,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,102, 97,108,115, - 101, 32, 45, 45, 32, 97, 32,103,108,111, 98, 97,108, 10, 10, - 45, 45, 32,112, 97,114,115,101, 32, 99,104,117,110,107, 10, - 102,117,110, 99,116,105,111,110, 32, 99,108, 97,115,115, 67, - 111,110,116, 97,105,110,101,114, 58,100,111,112, 97,114,115, - 101, 32, 40,115, 41, 10, 45, 45,112,114,105,110,116, 32, 40, - 34,112, 97,114,115,101, 32, 34, 46, 46,115, 41, 10, 10, 32, - 45, 45, 32,116,114,121, 32,116,104,101, 32,112, 97,114,115, - 101,114, 32,104,111,111,107, 10, 32,100,111, 10, 32, 9,108, - 111, 99, 97,108, 32,115,117, 98, 32, 61, 32,112, 97,114,115, - 101,114, 95,104,111,111,107, 40,115, 41, 10, 32, 9,105,102, - 32,115,117, 98, 32,116,104,101,110, 10, 32, 9, 9,114,101, - 116,117,114,110, 32,115,117, 98, 10, 32, 9,101,110,100, 10, - 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,116, - 104,101, 32,110,117,108,108, 32,115,116, 97,116,101,109,101, - 110,116, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114,105, - 110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, - 42, 59, 34, 41, 10, 32, 9,105,102, 32, 98, 32,116,104,101, - 110, 10, 32, 9, 9,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 9,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32,101,109,112,116,121, 32,118,101,114, 98, 97,116,105,109, - 32,108,105,110,101, 10, 32,100,111, 10, 32, 9,108,111, 99, - 97,108, 32, 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, - 94, 37,115, 42, 36, 92,110, 34, 41, 10, 32, 9,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 9, 9,114,101,116,117,114, - 110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, - 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, - 45, 32,116,114,121, 32, 76,117, 97, 32, 99,111,100,101, 10, - 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, - 44, 99,111,100,101, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42, 40, 37, 98, 92, 49, 92, 50, - 41, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 32, 67,111,100,101, 40,115,116,114,115,117, 98, - 40, 99,111,100,101, 44, 50, 44, 45, 50, 41, 41, 10, 32, 32, - 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40, - 115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101, - 110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32, 67, 32, 99, - 111,100,101, 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, - 32, 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114, - 102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 37, 98, - 92, 51, 92, 52, 41, 34, 41, 10, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 9, 99,111,100,101, 32, 61, 32, 39,123, - 39, 46, 46,115,116,114,115,117, 98, 40, 99,111,100,101, 44, - 50, 44, 45, 50, 41, 46, 46, 39, 92,110,125, 92,110, 39, 10, - 9, 86,101,114, 98, 97,116,105,109, 40, 99,111,100,101, 44, - 39,114, 39, 41, 32, 32, 32, 32, 32, 32, 32, 32, 45, 45, 32, - 118,101,114, 98, 97,116,105,109, 32, 99,111,100,101, 32,102, - 111,114, 32, 39,114, 39,101,103,105,115,116,101,114, 32,102, - 114, 97,103,109,101,110,116, 10, 9,114,101,116,117,114,110, - 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, - 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, - 32,116,114,121, 32, 67, 32, 99,111,100,101, 32,102,111,114, - 32,112,114,101, 97,109, 98,108,101, 32,115,101, 99,116,105, - 111,110, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 44, 99,111,100,101, 32, 61, 32,115,116,114,105, - 110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, - 42, 40, 37, 98, 92, 53, 92, 54, 41, 34, 41, 10, 32, 9,105, - 102, 32, 98, 32,116,104,101,110, 10, 32, 9, 9, 99,111,100, - 101, 32, 61, 32,115,116,114,105,110,103, 46,115,117, 98, 40, - 99,111,100,101, 44, 32, 50, 44, 32, 45, 50, 41, 46, 46, 34, - 92,110, 34, 10, 9, 9, 86,101,114, 98, 97,116,105,109, 40, - 99,111,100,101, 44, 32, 39, 39, 41, 10, 9, 9,114,101,116, - 117,114,110, 32,115,116,114,105,110,103, 46,115,117, 98, 40, - 115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,100,101, - 102, 97,117,108,116, 95,112,114,111,112,101,114,116,121, 32, - 100,105,114,101, 99,116,105,118,101, 10, 32,100,111, 10, 32, - 9,108,111, 99, 97,108, 32, 98, 44,101, 44,112,116,121,112, - 101, 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 32, - 34, 94, 37,115, 42, 84, 79, 76, 85, 65, 95, 80, 82, 79, 80, - 69, 82, 84, 89, 95, 84, 89, 80, 69, 37,115, 42, 37, 40, 43, - 37,115, 42, 40, 91, 94, 37, 41, 37,115, 93, 42, 41, 37,115, - 42, 37, 41, 43, 37,115, 42, 59, 63, 34, 41, 10, 32, 9,105, - 102, 32, 98, 32,116,104,101,110, 10, 32, 9, 9,105,102, 32, - 110,111,116, 32,112,116,121,112,101, 32,111,114, 32,112,116, - 121,112,101, 32, 61, 61, 32, 34, 34, 32,116,104,101,110, 10, - 32, 9, 9, 9,112,116,121,112,101, 32, 61, 32, 34,100,101, - 102, 97,117,108,116, 34, 10, 32, 9, 9,101,110,100, 10, 32, - 9, 9,115,101,108,102, 58,115,101,116, 95,112,114,111,112, - 101,114,116,121, 95,116,121,112,101, 40,112,116,121,112,101, - 41, 10, 9, 32, 9,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44, 32,101, 43, 49, 41, 10, 32, 9,101, - 110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114, - 121, 32,112,114,111,116,101, 99,116,101,100, 95,100,101,115, - 116,114,117, 99,116,111,114, 32,100,105,114,101, 99,116,105, - 118,101, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, - 98, 44,101, 32, 61, 32,115,116,114,105,110,103, 46,102,105, - 110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 84, 79, 76, 85, - 65, 95, 80, 82, 79, 84, 69, 67, 84, 69, 68, 95, 68, 69, 83, - 84, 82, 85, 67, 84, 79, 82, 37,115, 42, 59, 63, 34, 41, 10, - 9,105,102, 32, 98, 32,116,104,101,110, 10, 9, 9,105,102, - 32,115,101,108,102, 46,115,101,116, 95,112,114,111,116,101, - 99,116,101,100, 95,100,101,115,116,114,117, 99,116,111,114, - 32,116,104,101,110, 10, 9, 32, 9, 9,115,101,108,102, 58, - 115,101,116, 95,112,114,111,116,101, 99,116,101,100, 95,100, - 101,115,116,114,117, 99,116,111,114, 40,116,114,117,101, 41, - 10, 9, 32, 9,101,110,100, 10, 32, 9, 9,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44, 32,101, 43, - 49, 41, 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, 10, - 32, 45, 45, 32,116,114,121, 32, 39,101,120,116,101,114,110, - 39, 32,107,101,121,119,111,114,100, 10, 32,100,111, 10, 32, - 9,108,111, 99, 97,108, 32, 98, 44,101, 32, 61, 32,115,116, - 114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, 94, - 37,115, 42,101,120,116,101,114,110, 37,115, 43, 34, 41, 10, - 32, 9,105,102, 32, 98, 32,116,104,101,110, 10, 9, 9, 45, - 45, 32,100,111, 32,110,111,116,104,105,110,103, 10, 32, 9, - 9,114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40, - 115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32, 39,118, - 105,114,116,117, 97,108, 39, 32,107,101,121,119,111,114,107, - 100, 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, 98, - 44,101, 32, 61, 32,115,116,114,105,110,103, 46,102,105,110, - 100, 40,115, 44, 32, 34, 94, 37,115, 42,118,105,114,116,117, - 97,108, 37,115, 43, 34, 41, 10, 32, 9,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 9, 9,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,116,114,117,101, - 10, 32, 9, 9,114,101,116,117,114,110, 32,115,116,114,115, - 117, 98, 40,115, 44, 32,101, 43, 49, 41, 10, 32, 9,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32,108, 97, 98,101,108,115, 32, 40,112,117, 98,108,105, 99, - 44, 32,112,114,105,118, 97,116,101, 44, 32,101,116, 99, 41, - 10, 32,100,111, 10, 32, 9,108,111, 99, 97,108, 32, 98, 44, - 101, 32, 61, 32,115,116,114,105,110,103, 46,102,105,110,100, - 40,115, 44, 32, 34, 94, 37,115, 42, 37,119, 42, 37,115, 42, - 58, 91, 94, 58, 93, 34, 41, 10, 32, 9,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 9, 9,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44, 32,101, 41, 32, 45, 45, - 32,112,114,101,115,101,114,118,101, 32,116,104,101, 32, 91, - 94, 58, 93, 10, 32, 9,101,110,100, 10, 32,101,110,100, 10, - 10, 32, 45, 45, 32,116,114,121, 32,109,111,100,117,108,101, - 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44, - 101, 44,110, 97,109,101, 44, 98,111,100,121, 32, 61, 32,115, - 116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42,109, - 111,100,117,108,101, 37,115, 37,115, 42, 40, 91, 95, 37,119, - 93, 91, 95, 37,119, 93, 42, 41, 37,115, 42, 40, 37, 98,123, - 125, 41, 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99, - 111,100,101, 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, - 98, 44,101, 41, 10, 32, 32, 32, 77,111,100,117,108,101, 40, - 110, 97,109,101, 44, 98,111,100,121, 41, 10, 32, 32, 32,114, - 101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, 44, - 101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, - 10, 10, 32, 45, 45, 32,116,114,121, 32,110, 97,109,101,115, - 97,112, 99,101, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,110, 97,109,101, 44, 98,111,100,121, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42,110, 97,109,101,115,112, 97, 99,101, 37,115, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 93, 42, 41, - 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 59, 63, 34, - 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, - 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32, - 115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, - 32, 32, 78, 97,109,101,115,112, 97, 99,101, 40,110, 97,109, - 101, 44, 98,111,100,121, 41, 10, 32, 32, 32,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, - 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, - 45, 45, 32,116,114,121, 32,100,101,102,105,110,101, 10, 32, - 100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44, - 110, 97,109,101, 32, 61, 32,115,116,114,102,105,110,100, 40, - 115, 44, 34, 94, 37,115, 42, 35,100,101,102,105,110,101, 37, - 115, 37,115, 42, 40, 91, 94, 37,115, 93, 42, 41, 91, 94, 92, - 110, 93, 42, 92,110, 37,115, 42, 34, 41, 10, 32, 32,105,102, - 32, 98, 32,116,104,101,110, 10, 32, 32, 32, 95, 99,117,114, - 114, 95, 99,111,100,101, 32, 61, 32,115,116,114,115,117, 98, - 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, 68,101,102,105, - 110,101, 40,110, 97,109,101, 41, 10, 32, 32, 32,114,101,116, - 117,114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, - 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, 10, 10, - 32, 45, 45, 32,116,114,121, 32,101,110,117,109,101,114, 97, - 116,101,115, 10, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,110, 97,109,101, 44, 98,111,100,121, - 44,118, 97,114,110, 97,109,101, 32, 61, 32,115,116,114,102, - 105,110,100, 40,115, 44, 34, 94, 37,115, 42,101,110,117,109, - 37,115, 43, 40, 37, 83, 42, 41, 37,115, 42, 40, 37, 98,123, - 125, 41, 37,115, 42, 40, 91, 94, 37,115, 59, 93, 42, 41, 37, - 115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 32, 32, 45, 45,101,114,114, - 111,114, 40, 34, 35, 83,111,114,114,121, 44, 32,100,101, 99, - 108, 97,114, 97,116,105,111,110, 32,111,102, 32,101,110,117, - 109,115, 32, 97,110,100, 32,118, 97,114,105, 97, 98,108,101, - 115, 32,111,110, 32,116,104,101, 32,115, 97,109,101, 32,115, - 116, 97,116,101,109,101,110,116, 32,105,115, 32,110,111,116, - 32,115,117,112,112,111,114,116,101,100, 46, 92,110, 68,101, - 99,108, 97,114,101, 32,121,111,117,114, 32,118, 97,114,105, - 97, 98,108,101, 32,115,101,112, 97,114, 97,116,101,108,121, - 32, 40,101,120, 97,109,112,108,101, 58, 32, 39, 34, 46, 46, - 110, 97,109,101, 46, 46, 34, 32, 34, 46, 46,118, 97,114,110, - 97,109,101, 46, 46, 34, 59, 39, 41, 34, 41, 10, 32, 32, 32, - 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116, - 114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, - 69,110,117,109,101,114, 97,116,101, 40,110, 97,109,101, 44, - 98,111,100,121, 44,118, 97,114,110, 97,109,101, 41, 10, 32, - 32, 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, - 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 10, 45, 45, 32,100,111, 10, 45, 45, 32, 32, - 108,111, 99, 97,108, 32, 98, 44,101, 44,110, 97,109,101, 44, - 98,111,100,121, 32, 61, 32,115,116,114,102,105,110,100, 40, - 115, 44, 34, 94, 37,115, 42,101,110,117,109, 37,115, 43, 40, - 37, 83, 42, 41, 37,115, 42, 40, 37, 98,123,125, 41, 37,115, - 42, 59, 63, 37,115, 42, 34, 41, 10, 45, 45, 32, 32,105,102, - 32, 98, 32,116,104,101,110, 10, 45, 45, 32, 32, 32, 95, 99, - 117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116,114,115, - 117, 98, 40,115, 44, 98, 44,101, 41, 10, 45, 45, 32, 32, 32, - 69,110,117,109,101,114, 97,116,101, 40,110, 97,109,101, 44, - 98,111,100,121, 41, 10, 45, 45, 32, 32,114,101,116,117,114, - 110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, - 10, 45, 45, 32, 32,101,110,100, 10, 45, 45, 32,101,110,100, - 10, 10, 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, - 44,101, 44, 98,111,100,121, 44,110, 97,109,101, 32, 61, 32, - 115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, - 116,121,112,101,100,101,102, 37,115, 43,101,110,117,109, 91, - 94,123, 93, 42, 40, 37, 98,123,125, 41, 37,115, 42, 40, 91, - 37,119, 95, 93, 91, 94, 37,115, 93, 42, 41, 37,115, 42, 59, - 37,115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104, - 101,110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100, - 101, 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44, - 101, 41, 10, 32, 32, 32, 69,110,117,109,101,114, 97,116,101, - 40,110, 97,109,101, 44, 98,111,100,121, 41, 10, 32, 32, 32, - 114,101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, - 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110, - 100, 10, 10, 32, 45, 45, 32,116,114,121, 32,111,112,101,114, - 97,116,111,114, 10, 32,100,111, 10, 32, 32,108,111, 99, 97, - 108, 32, 98, 44,101, 44,100,101, 99,108, 44,107,105,110,100, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, - 95, 37,119, 93, 91, 95, 37,119, 37,115, 37, 42, 38, 58, 60, - 62, 44, 93, 45, 37,115, 43,111,112,101,114, 97,116,111,114, - 41, 37,115, 42, 40, 91, 94, 37,115, 93, 91, 94, 37,115, 93, - 42, 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, - 99, 63,111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 59, - 37,115, 42, 34, 41, 10, 32, 32,105,102, 32,110,111,116, 32, - 98, 32,116,104,101,110, 10, 9, 9, 32, 45, 45, 32,116,114, - 121, 32,105,110,108,105,110,101, 10, 32, 32, 32, 98, 44,101, - 44,100,101, 99,108, 44,107,105,110,100, 44, 97,114,103, 44, - 99,111,110,115,116, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, 91, - 95, 37,119, 37,115, 37, 42, 38, 58, 60, 62, 44, 93, 45, 37, - 115, 43,111,112,101,114, 97,116,111,114, 41, 37,115, 42, 40, - 91, 94, 37,115, 93, 91, 94, 37,115, 93, 42, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 37,115, 92,110, 93, 42, 37, 98, - 123,125, 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32,110,111,116, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 9, 45, 45, 32,116,114,121, 32, - 99, 97,115,116, 32,111,112,101,114, 97,116,111,114, 10, 32, - 32, 9, 98, 44,101, 44,100,101, 99,108, 44,107,105,110,100, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 40, - 111,112,101,114, 97,116,111,114, 41, 37,115, 43, 40, 91, 37, - 119, 95, 58, 37,100, 60, 62, 37, 42, 37, 38, 37,115, 93, 43, - 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, - 63,111, 63,110, 63,115, 63,116, 63, 41, 34, 41, 59, 10, 32, - 32, 9,105,102, 32, 98, 32,116,104,101,110, 10, 32, 32, 9, - 9,108,111, 99, 97,108, 32, 95, 44,105,101, 32, 61, 32,115, - 116,114,105,110,103, 46,102,105,110,100, 40,115, 44, 32, 34, - 94, 37,115, 42, 37, 98,123,125, 34, 44, 32,101, 43, 49, 41, - 10, 32, 32, 9, 9,105,102, 32,105,101, 32,116,104,101,110, - 10, 32, 32, 9, 9, 9,101, 32, 61, 32,105,101, 10, 32, 32, - 9, 9,101,110,100, 10, 32, 32, 9,101,110,100, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, - 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, - 10, 32, 32, 32, 79,112,101,114, 97,116,111,114, 40,100,101, - 99,108, 44,107,105,110,100, 44, 97,114,103, 44, 99,111,110, - 115,116, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115, - 116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32, - 101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116, - 114,121, 32,102,117,110, 99,116,105,111,110, 10, 32,100,111, - 10, 32, 32, 45, 45,108,111, 99, 97,108, 32, 98, 44,101, 44, - 100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91,126, 95, 37,119, 93, 91, 95, 64, 37,119, 37, - 115, 37, 42, 38, 58, 60, 62, 93, 42, 91, 95, 37,119, 93, 41, - 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63, - 111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 61, 63, 37, - 115, 42, 48, 63, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, - 44, 97,114,103, 44, 99,111,110,115,116, 44,118,105,114,116, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42, 40, 91, 94, 37, 40, 92,110, 93, 43, 41, 37,115, - 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63, - 110, 63,115, 63,116, 63, 41, 37,115, 42, 40, 61, 63, 37,115, - 42, 48, 63, 41, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, - 32, 32, 9, 45, 45, 32,116,114,121, 32,102,117,110, 99,116, - 105,111,110, 32,119,105,116,104, 32,116,101,109,112,108, 97, - 116,101, 10, 32, 32, 9, 98, 44,101, 44,100,101, 99,108, 44, - 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116,114, - 102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91,126, - 95, 37,119, 93, 91, 95, 64, 37,119, 37,115, 37, 42, 38, 58, - 60, 62, 93, 42, 91, 95, 37,119, 93, 37, 98, 60, 62, 41, 37, - 115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, - 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 61, 63, 37,115, - 42, 48, 63, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32,110,111,116, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 45, 45, 32,116,114,121, 32, - 97, 32,115,105,110,103,108,101, 32,108,101,116,116,101,114, - 32,102,117,110, 99,116,105,111,110, 32,110, 97,109,101, 10, - 32, 32, 32, 98, 44,101, 44,100,101, 99,108, 44, 97,114,103, - 44, 99,111,110,115,116, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, - 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, - 63,111, 63,110, 63,115, 63,116, 63, 41, 37,115, 42, 59, 37, - 115, 42, 34, 41, 10, 32, 32,101,110,100, 10, 32, 32,105,102, - 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, - 45, 45, 32,116,114,121, 32,102,117,110, 99,116,105,111,110, - 32,112,111,105,110,116,101,114, 10, 32, 32, 32, 98, 44,101, - 44,100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, - 32, 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, - 37,115, 42, 40, 91, 94, 37, 40, 59, 92,110, 93, 43, 37, 98, - 40, 41, 41, 37,115, 42, 40, 37, 98, 40, 41, 41, 37,115, 42, - 59, 37,115, 42, 34, 41, 10, 32, 32, 32,105,102, 32, 98, 32, - 116,104,101,110, 10, 32, 32, 32, 32,100,101, 99,108, 32, 61, - 32,115,116,114,105,110,103, 46,103,115,117, 98, 40,100,101, - 99,108, 44, 32, 34, 37, 40, 37,115, 42, 37, 42, 40, 91, 94, - 37, 41, 93, 42, 41, 37,115, 42, 37, 41, 34, 44, 32, 34, 32, - 37, 49, 32, 34, 41, 10, 32, 32, 32,101,110,100, 10, 32, 32, - 101,110,100, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, - 10, 32, 32, 9,105,102, 32,118,105,114,116, 32, 97,110,100, - 32,115,116,114,105,110,103, 46,102,105,110,100, 40,118,105, - 114,116, 44, 32, 34, 91, 61, 48, 93, 34, 41, 32,116,104,101, - 110, 10, 32, 32, 9, 9,105,102, 32,115,101,108,102, 46,102, - 108, 97,103,115, 32,116,104,101,110, 10, 32, 32, 9, 9, 9, - 115,101,108,102, 46,102,108, 97,103,115, 46,112,117,114,101, - 95,118,105,114,116,117, 97,108, 32, 61, 32,116,114,117,101, - 10, 32, 32, 9, 9,101,110,100, 10, 32, 32, 9,101,110,100, - 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, - 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, - 10, 32, 32, 32, 70,117,110, 99,116,105,111,110, 40,100,101, - 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 41, 10, 32, - 32, 32,114,101,116,117,114,110, 32,115,116,114,115,117, 98, - 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32, - 101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, 32,105,110, - 108,105,110,101, 32,102,117,110, 99,116,105,111,110, 10, 32, - 100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44, - 100,101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91, 94, 37, 40, 92,110, 93, 43, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 94, 59,123, 93, 42, 37, 98,123, - 125, 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32, 45, - 45,108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, - 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, 32,115,116, - 114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, 40, 91, - 126, 95, 37,119, 93, 91, 95, 64, 37,119, 37,115, 37, 42, 38, - 58, 60, 62, 93, 42, 91, 95, 37,119, 62, 93, 41, 37,115, 42, - 40, 37, 98, 40, 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, - 63,115, 63,116, 63, 41, 91, 94, 59, 93, 42, 37, 98,123,125, - 37,115, 42, 59, 63, 37,115, 42, 34, 41, 10, 32, 32,105,102, - 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, - 45, 45, 32,116,114,121, 32, 97, 32,115,105,110,103,108,101, - 32,108,101,116,116,101,114, 32,102,117,110, 99,116,105,111, - 110, 32,110, 97,109,101, 10, 32, 32, 32, 98, 44,101, 44,100, - 101, 99,108, 44, 97,114,103, 44, 99,111,110,115,116, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42, 40, 91, 95, 37,119, 93, 41, 37,115, 42, 40, 37, 98, 40, - 41, 41, 37,115, 42, 40, 99, 63,111, 63,110, 63,115, 63,116, - 63, 41, 46, 45, 37, 98,123,125, 37,115, 42, 59, 63, 37,115, - 42, 34, 41, 10, 32, 32,101,110,100, 10, 32, 32,105,102, 32, - 98, 32,116,104,101,110, 10, 32, 32, 32, 95, 99,117,114,114, - 95, 99,111,100,101, 32, 61, 32,115,116,114,115,117, 98, 40, - 115, 44, 98, 44,101, 41, 10, 32, 32, 32, 70,117,110, 99,116, - 105,111,110, 40,100,101, 99,108, 44, 97,114,103, 44, 99,111, - 110,115,116, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, - 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, - 116,114,121, 32, 99,108, 97,115,115, 10, 32,100,111, 10, 9, - 32,108,111, 99, 97,108, 32, 98, 44,101, 44,110, 97,109,101, - 44, 98, 97,115,101, 44, 98,111,100,121, 10, 9, 9, 98, 97, - 115,101, 32, 61, 32, 39, 39, 32, 98,111,100,121, 32, 61, 32, - 39, 39, 10, 9, 9, 98, 44,101, 44,110, 97,109,101, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42, 99,108, 97,115,115, 37,115, 42, 40, 91, 95, 37,119, 93, - 91, 95, 37,119, 64, 93, 42, 41, 37,115, 42, 59, 34, 41, 32, - 32, 45, 45, 32,100,117,109,109,121, 32, 99,108, 97,115,115, - 10, 9, 9,108,111, 99, 97,108, 32,100,117,109,109,121, 32, - 61, 32,102, 97,108,115,101, 10, 9, 9,105,102, 32,110,111, - 116, 32, 98, 32,116,104,101,110, 10, 9, 9, 9, 98, 44,101, - 44,110, 97,109,101, 32, 61, 32,115,116,114,102,105,110,100, - 40,115, 44, 34, 94, 37,115, 42,115,116,114,117, 99,116, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, 93, 42, - 41, 37,115, 42, 59, 34, 41, 32, 32, 32, 32, 45, 45, 32,100, - 117,109,109,121, 32,115,116,114,117, 99,116, 10, 9, 9, 9, - 105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 9, - 9, 9, 9, 98, 44,101, 44,110, 97,109,101, 44, 98, 97,115, - 101, 44, 98,111,100,121, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42, 99,108, 97,115,115, 37, - 115, 42, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, 93, 42, - 41, 37,115, 42, 40, 91, 94,123, 93, 45, 41, 37,115, 42, 40, - 37, 98,123,125, 41, 37,115, 42, 34, 41, 10, 9, 9, 9, 9, - 105,102, 32,110,111,116, 32, 98, 32,116,104,101,110, 10, 9, - 9, 9, 9, 9, 98, 44,101, 44,110, 97,109,101, 44, 98, 97, - 115,101, 44, 98,111,100,121, 32, 61, 32,115,116,114,102,105, - 110,100, 40,115, 44, 34, 94, 37,115, 42,115,116,114,117, 99, - 116, 37,115, 43, 40, 91, 95, 37,119, 93, 91, 95, 37,119, 64, - 93, 42, 41, 37,115, 42, 40, 91, 94,123, 93, 45, 41, 37,115, - 42, 40, 37, 98,123,125, 41, 37,115, 42, 34, 41, 10, 9, 9, - 9, 9, 9,105,102, 32,110,111,116, 32, 98, 32,116,104,101, - 110, 10, 9, 9, 9, 9, 9, 9, 98, 44,101, 44,110, 97,109, - 101, 44, 98, 97,115,101, 44, 98,111,100,121, 32, 61, 32,115, - 116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42,117, - 110,105,111,110, 37,115, 42, 40, 91, 95, 37,119, 93, 91, 95, - 37,119, 64, 93, 42, 41, 37,115, 42, 40, 91, 94,123, 93, 45, - 41, 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 34, 41, - 10, 9, 9, 9, 9, 9, 9,105,102, 32,110,111,116, 32, 98, - 32,116,104,101,110, 10, 9, 9, 9, 9, 9, 9, 9, 98, 97, - 115,101, 32, 61, 32, 39, 39, 10, 9, 9, 9, 9, 9, 9, 9, - 98, 44,101, 44, 98,111,100,121, 44,110, 97,109,101, 32, 61, - 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, - 42,116,121,112,101,100,101,102, 37,115, 37,115, 42,115,116, - 114,117, 99,116, 37,115, 37,115, 42, 91, 95, 37,119, 93, 42, - 37,115, 42, 40, 37, 98,123,125, 41, 37,115, 42, 40, 91, 95, - 37,119, 93, 91, 95, 37,119, 64, 93, 42, 41, 37,115, 42, 59, - 34, 41, 10, 9, 9, 9, 9, 9, 9,101,110,100, 10, 9, 9, - 9, 9, 9,101,110,100, 10, 9, 9, 9, 9,101,110,100, 10, - 9, 9, 9,101,108,115,101, 32,100,117,109,109,121, 32, 61, - 32, 49, 32,101,110,100, 10, 9, 9,101,108,115,101, 32,100, - 117,109,109,121, 32, 61, 32, 49, 32,101,110,100, 10, 9, 9, - 105,102, 32, 98, 32,116,104,101,110, 10, 9, 9, 9,105,102, - 32, 98, 97,115,101, 32,126, 61, 32, 39, 39, 32,116,104,101, - 110, 10, 9, 9, 9, 9, 98, 97,115,101, 32, 61, 32,115,116, - 114,105,110,103, 46,103,115,117, 98, 40, 98, 97,115,101, 44, - 32, 34, 94, 37,115, 42, 58, 37,115, 42, 34, 44, 32, 34, 34, - 41, 10, 9, 9, 9, 9, 98, 97,115,101, 32, 61, 32,115,116, - 114,105,110,103, 46,103,115,117, 98, 40, 98, 97,115,101, 44, - 32, 34, 37,115, 42,112,117, 98,108,105, 99, 37,115, 42, 34, - 44, 32, 34, 34, 41, 10, 9, 9, 9, 9, 98, 97,115,101, 32, - 61, 32,115,112,108,105,116, 40, 98, 97,115,101, 44, 32, 34, - 44, 34, 41, 10, 9, 9, 9, 9, 45, 45,108,111, 99, 97,108, - 32, 98, 44,101, 10, 9, 9, 9, 9, 45, 45, 98, 44,101, 44, - 98, 97,115,101, 32, 61, 32,115,116,114,102,105,110,100, 40, - 98, 97,115,101, 44, 34, 46, 45, 40, 91, 95, 37,119, 93, 91, - 95, 37,119, 60, 62, 44, 58, 93, 42, 41, 36, 34, 41, 10, 9, - 9, 9,101,108,115,101, 10, 9, 9, 9, 9, 98, 97,115,101, - 32, 61, 32,123,125, 10, 9, 9, 9,101,110,100, 10, 9, 9, - 9, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115, - 116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 9, 9, - 9, 67,108, 97,115,115, 40,110, 97,109,101, 44, 98, 97,115, - 101, 44, 98,111,100,121, 41, 10, 9, 9, 9,105,102, 32,110, - 111,116, 32,100,117,109,109,121, 32,116,104,101,110, 10, 9, - 9, 9, 9,118, 97,114, 98, 44,118, 97,114,101, 44,118, 97, - 114,110, 97,109,101, 32, 61, 32,115,116,114,105,110,103, 46, - 102,105,110,100, 40,115, 44, 32, 34, 94, 37,115, 42, 40, 91, - 95, 37,119, 93, 43, 41, 37,115, 42, 59, 34, 44, 32,101, 43, - 49, 41, 10, 9, 9, 9, 9,105,102, 32,118, 97,114, 98, 32, - 116,104,101,110, 10, 9, 9, 9, 9, 9, 86, 97,114,105, 97, - 98,108,101, 40,110, 97,109,101, 46, 46, 34, 32, 34, 46, 46, - 118, 97,114,110, 97,109,101, 41, 10, 9, 9, 9, 9, 9,101, - 32, 61, 32,118, 97,114,101, 10, 9, 9, 9, 9,101,110,100, - 10, 9, 9, 9,101,110,100, 10, 9, 9, 9,114,101,116,117, - 114,110, 32,115,116,114,115,117, 98, 40,115, 44,101, 43, 49, - 41, 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 10, 32, - 45, 45, 32,116,114,121, 32,116,121,112,101,100,101,102, 10, - 32,100,111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, - 44,116,121,112,101,115, 32, 61, 32,115,116,114,102,105,110, - 100, 40,115, 44, 34, 94, 37,115, 42,116,121,112,101,100,101, - 102, 37,115, 37,115, 42, 40, 46, 45, 41, 37,115, 42, 59, 37, - 115, 42, 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101, - 110, 10, 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, - 32, 61, 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, - 41, 10, 32, 32, 32, 84,121,112,101,100,101,102, 40,116,121, - 112,101,115, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32, - 115,116,114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, - 32,101,110,100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32, - 116,114,121, 32,118, 97,114,105, 97, 98,108,101, 10, 32,100, - 111, 10, 32, 32,108,111, 99, 97,108, 32, 98, 44,101, 44,100, - 101, 99,108, 32, 61, 32,115,116,114,102,105,110,100, 40,115, - 44, 34, 94, 37,115, 42, 40, 91, 95, 37,119, 93, 91, 95, 64, - 37,115, 37,119, 37,100, 37, 42, 38, 58, 60, 62, 44, 93, 42, - 91, 95, 37,119, 37,100, 93, 41, 37,115, 42, 59, 37,115, 42, - 34, 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, - 32, 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, - 32,115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, - 10, 9,108,111, 99, 97,108, 32,108,105,115,116, 32, 61, 32, - 115,112,108,105,116, 95, 99, 95,116,111,107,101,110,115, 40, - 100,101, 99,108, 44, 32, 34, 44, 34, 41, 10, 9, 86, 97,114, - 105, 97, 98,108,101, 40,108,105,115,116, 91, 49, 93, 41, 10, - 9,105,102, 32,108,105,115,116, 46,110, 32, 62, 32, 49, 32, - 116,104,101,110, 10, 9, 9,108,111, 99, 97,108, 32, 95, 44, - 95, 44,116,121,112,101, 32, 61, 32,115,116,114,102,105,110, - 100, 40,108,105,115,116, 91, 49, 93, 44, 32, 34, 40, 46, 45, - 41, 37,115, 43, 40, 91, 94, 37,115, 93, 42, 41, 36, 34, 41, - 59, 10, 10, 9, 9,108,111, 99, 97,108, 32,105, 32, 61, 50, - 59, 10, 9, 9,119,104,105,108,101, 32,108,105,115,116, 91, - 105, 93, 32,100,111, 10, 9, 9, 9, 86, 97,114,105, 97, 98, - 108,101, 40,116,121,112,101, 46, 46, 34, 32, 34, 46, 46,108, - 105,115,116, 91,105, 93, 41, 10, 9, 9, 9,105, 61,105, 43, - 49, 10, 9, 9,101,110,100, 10, 9,101,110,100, 10, 32, 32, - 32, 45, 45, 86, 97,114,105, 97, 98,108,101, 40,100,101, 99, - 108, 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115,116, - 114,115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32,101, - 110,100, 10, 32,101,110,100, 10, 10, 9, 45, 45, 32,116,114, - 121, 32,115,116,114,105,110,103, 10, 32,100,111, 10, 32, 32, - 108,111, 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, 32, - 61, 32,115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37, - 115, 42, 40, 91, 95, 37,119, 93, 63, 91, 95, 37,115, 37,119, - 37,100, 93, 45, 99,104, 97,114, 37,115, 43, 91, 95, 64, 37, - 119, 37,100, 93, 42, 37,115, 42, 37, 91, 37,115, 42, 37, 83, - 43, 37,115, 42, 37, 93, 41, 37,115, 42, 59, 37,115, 42, 34, - 41, 10, 32, 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, - 32, 32, 95, 99,117,114,114, 95, 99,111,100,101, 32, 61, 32, - 115,116,114,115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, - 32, 32, 86, 97,114,105, 97, 98,108,101, 40,100,101, 99,108, - 41, 10, 32, 32, 32,114,101,116,117,114,110, 32,115,116,114, - 115,117, 98, 40,115, 44,101, 43, 49, 41, 10, 32, 32,101,110, - 100, 10, 32,101,110,100, 10, 10, 32, 45, 45, 32,116,114,121, - 32, 97,114,114, 97,121, 10, 32,100,111, 10, 32, 32,108,111, - 99, 97,108, 32, 98, 44,101, 44,100,101, 99,108, 32, 61, 32, - 115,116,114,102,105,110,100, 40,115, 44, 34, 94, 37,115, 42, - 40, 91, 95, 37,119, 93, 91, 93, 91, 95, 64, 37,115, 37,119, - 37,100, 37, 42, 38, 58, 60, 62, 93, 42, 91, 93, 95, 37,119, - 37,100, 93, 41, 37,115, 42, 59, 37,115, 42, 34, 41, 10, 32, - 32,105,102, 32, 98, 32,116,104,101,110, 10, 32, 32, 32, 95, - 99,117,114,114, 95, 99,111,100,101, 32, 61, 32,115,116,114, - 115,117, 98, 40,115, 44, 98, 44,101, 41, 10, 32, 32, 32, 65, - 114,114, 97,121, 40,100,101, 99,108, 41, 10, 32, 32, 32,114, - 101,116,117,114,110, 32,115,116,114,115,117, 98, 40,115, 44, - 101, 43, 49, 41, 10, 32, 32,101,110,100, 10, 32,101,110,100, - 10, 10, 32, 45, 45, 32,110,111, 32,109, 97,116, 99,104,105, - 110,103, 10, 32,105,102, 32,103,115,117, 98, 40,115, 44, 34, - 37,115, 37,115, 42, 34, 44, 34, 34, 41, 32,126, 61, 32, 34, - 34, 32,116,104,101,110, 10, 32, 32, 95, 99,117,114,114, 95, - 99,111,100,101, 32, 61, 32,115, 10, 32, 32,101,114,114,111, - 114, 40, 34, 35,112, 97,114,115,101, 32,101,114,114,111,114, - 34, 41, 10, 32,101,108,115,101, 10, 32, 32,114,101,116,117, - 114,110, 32, 34, 34, 10, 32,101,110,100, 10, 10,101,110,100, - 10, 10,102,117,110, 99,116,105,111,110, 32, 99,108, 97,115, - 115, 67,111,110,116, 97,105,110,101,114, 58,112, 97,114,115, - 101, 32, 40,115, 41, 10, 10, 9, 45, 45,115,101,108,102, 46, - 99,117,114,114, 95,109,101,109, 98,101,114, 95, 97, 99, 99, - 101,115,115, 32, 61, 32,110,105,108, 10, 10, 32,119,104,105, - 108,101, 32,115, 32,126, 61, 32, 39, 39, 32,100,111, 10, 32, - 32,115, 32, 61, 32,115,101,108,102, 58,100,111,112, 97,114, - 115,101, 40,115, 41, 10, 32, 32,109,101,116,104,111,100,105, - 115,118,105,114,116,117, 97,108, 32, 61, 32,102, 97,108,115, - 101, 10, 32,101,110,100, 10,101,110,100, 10, 10, 10, 45, 45, - 32,112,114,111,112,101,114,116,121, 32,116,121,112,101,115, - 10, 10,102,117,110, 99,116,105,111,110, 32,103,101,116, 95, - 112,114,111,112,101,114,116,121, 95,116,121,112,101, 40, 41, - 10, 10, 9,114,101,116,117,114,110, 32, 99,108, 97,115,115, - 67,111,110,116, 97,105,110,101,114, 46, 99,117,114,114, 58, - 103,101,116, 95,112,114,111,112,101,114,116,121, 95,116,121, - 112,101, 40, 41, 10,101,110,100, 10, 10,102,117,110, 99,116, - 105,111,110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105, - 110,101,114, 58,115,101,116, 95,112,114,111,112,101,114,116, - 121, 95,116,121,112,101, 40,112,116,121,112,101, 41, 10, 9, - 112,116,121,112,101, 32, 61, 32,115,116,114,105,110,103, 46, - 103,115,117, 98, 40,112,116,121,112,101, 44, 32, 34, 94, 37, - 115, 42, 34, 44, 32, 34, 34, 41, 10, 9,112,116,121,112,101, - 32, 61, 32,115,116,114,105,110,103, 46,103,115,117, 98, 40, - 112,116,121,112,101, 44, 32, 34, 37,115, 42, 36, 34, 44, 32, - 34, 34, 41, 10, 10, 9,115,101,108,102, 46,112,114,111,112, - 101,114,116,121, 95,116,121,112,101, 32, 61, 32,112,116,121, - 112,101, 10,101,110,100, 10, 10,102,117,110, 99,116,105,111, - 110, 32, 99,108, 97,115,115, 67,111,110,116, 97,105,110,101, - 114, 58,103,101,116, 95,112,114,111,112,101,114,116,121, 95, - 116,121,112,101, 40, 41, 10, 9,114,101,116,117,114,110, 32, - 115,101,108,102, 46,112,114,111,112,101,114,116,121, 95,116, - 121,112,101, 32,111,114, 32, 40,115,101,108,102, 46,112, 97, - 114,101,110,116, 32, 97,110,100, 32,115,101,108,102, 46,112, - 97,114,101,110,116, 58,103,101,116, 95,112,114,111,112,101, - 114,116,121, 95,116,121,112,101, 40, 41, 41, 32,111,114, 32, - 34,100,101,102, 97,117,108,116, 34, 10,101,110,100,32 - }; - tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: src/bin/lua/container.lua"); + #include "container_lua.h" + tolua_dobuffer(tolua_S,(char*)lua_container_lua,sizeof(lua_container_lua),"tolua embedded: src/bin/lua/container.lua"); lua_settop(tolua_S, top); } /* end of embedded lua code */ diff --git a/lib/zlib/CMakeLists.txt b/lib/zlib/CMakeLists.txt index 6c52578ee..74cf94f8b 100644 --- a/lib/zlib/CMakeLists.txt +++ b/lib/zlib/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../src/") file(GLOB SOURCE "*.c" + "*.h" ) if(NOT TARGET zlib) diff --git a/src/Authenticator.cpp b/src/Authenticator.cpp deleted file mode 100644 index bd6db1c11..000000000 --- a/src/Authenticator.cpp +++ /dev/null @@ -1,267 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Authenticator.h" -#include "OSSupport/BlockingTCPLink.h" -#include "Root.h" -#include "Server.h" - -#include "inifile/iniFile.h" - -#include <sstream> - - - - - -#define DEFAULT_AUTH_SERVER "session.minecraft.net" -#define DEFAULT_AUTH_ADDRESS "/game/checkserver.jsp?user=%USERNAME%&serverId=%SERVERID%" -#define MAX_REDIRECTS 10 - - - - - -cAuthenticator::cAuthenticator(void) : - super("cAuthenticator"), - m_Server(DEFAULT_AUTH_SERVER), - m_Address(DEFAULT_AUTH_ADDRESS), - m_ShouldAuthenticate(true) -{ -} - - - - - -cAuthenticator::~cAuthenticator() -{ - Stop(); -} - - - - - -void cAuthenticator::ReadINI(cIniFile & IniFile) -{ - m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER); - m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS); - m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true); -} - - - - - -void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash) -{ - if (!m_ShouldAuthenticate) - { - cRoot::Get()->AuthenticateUser(a_ClientID); - return; - } - - cCSLock Lock(m_CS); - m_Queue.push_back(cUser(a_ClientID, a_UserName, a_ServerHash)); - m_QueueNonempty.Set(); -} - - - - - -void cAuthenticator::Start(cIniFile & IniFile) -{ - ReadINI(IniFile); - m_ShouldTerminate = false; - super::Start(); -} - - - - - -void cAuthenticator::Stop(void) -{ - m_ShouldTerminate = true; - m_QueueNonempty.Set(); - Wait(); -} - - - - - -void cAuthenticator::Execute(void) -{ - for (;;) - { - cCSLock Lock(m_CS); - while (!m_ShouldTerminate && (m_Queue.size() == 0)) - { - cCSUnlock Unlock(Lock); - m_QueueNonempty.Wait(); - } - if (m_ShouldTerminate) - { - return; - } - ASSERT(!m_Queue.empty()); - - int ClientID = m_Queue.front().m_ClientID; - AString UserName = m_Queue.front().m_Name; - AString ActualAddress = m_Address; - ReplaceString(ActualAddress, "%USERNAME%", UserName); - ReplaceString(ActualAddress, "%SERVERID%", m_Queue.front().m_ServerID); - m_Queue.pop_front(); - Lock.Unlock(); - - if (!AuthFromAddress(m_Server, ActualAddress, UserName)) - { - cRoot::Get()->KickUser(ClientID, "Failed to authenticate account!"); - } - else - { - cRoot::Get()->AuthenticateUser(ClientID); - } - } // for (-ever) -} - - - - - -bool cAuthenticator::AuthFromAddress(const AString & a_Server, const AString & a_Address, const AString & a_UserName, int a_Level /* = 1 */) -{ - // Returns true if the user authenticated okay, false on error; iLevel is the recursion deptht (bails out if too deep) - - cBlockingTCPLink Link; - if (!Link.Connect(a_Server.c_str(), 80)) - { - LOGWARNING("%s: cannot connect to auth server \"%s\", kicking user \"%s\"", - __FUNCTION__, a_Server.c_str(), a_UserName.c_str() - ); - return false; - } - - Link.SendMessage( AString( "GET " + a_Address + " HTTP/1.1\r\n" ).c_str()); - Link.SendMessage( AString( "User-Agent: MCServer\r\n" ).c_str()); - Link.SendMessage( AString( "Host: " + a_Server + "\r\n" ).c_str()); - //Link.SendMessage( AString( "Host: session.minecraft.net\r\n" ).c_str()); - Link.SendMessage( AString( "Accept: */*\r\n" ).c_str()); - Link.SendMessage( AString( "Connection: close\r\n" ).c_str()); //Close so we don´t have to mess with the Content-Length :) - Link.SendMessage( AString( "\r\n" ).c_str()); - AString DataRecvd; - Link.ReceiveData(DataRecvd); - Link.CloseSocket(); - - std::stringstream ss(DataRecvd); - - // Parse the data received: - std::string temp; - ss >> temp; - bool bRedirect = false; - bool bOK = false; - if ((temp.compare("HTTP/1.1") == 0) || (temp.compare("HTTP/1.0") == 0)) - { - int code; - ss >> code; - if (code == 302) - { - // redirect blabla - LOGD("%s: Need to redirect, current level %d!", __FUNCTION__, a_Level); - if (a_Level > MAX_REDIRECTS) - { - LOGERROR("cAuthenticator: received too many levels of redirection from auth server \"%s\" for user \"%s\", bailing out and kicking the user", a_Server.c_str(), a_UserName.c_str()); - return false; - } - bRedirect = true; - } - else if (code == 200) - { - LOGD("cAuthenticator: Received status 200 OK! :D"); - bOK = true; - } - } - else - { - LOGERROR("cAuthenticator: cannot parse auth reply from server \"%s\" for user \"%s\", kicking the user.", a_Server.c_str(), a_UserName.c_str()); - return false; - } - - if( bRedirect ) - { - AString Location; - // Search for "Location:" - bool bFoundLocation = false; - while( !bFoundLocation && ss.good() ) - { - char c = 0; - while( c != '\n' ) - { - ss.get( c ); - } - AString Name; - ss >> Name; - if (Name.compare("Location:") == 0) - { - bFoundLocation = true; - ss >> Location; - } - } - if (!bFoundLocation) - { - LOGERROR("cAuthenticator: received invalid redirection from auth server \"%s\" for user \"%s\", kicking user.", a_Server.c_str(), a_UserName.c_str()); - return false; - } - - Location = Location.substr(strlen("http://"), std::string::npos); // Strip http:// - std::string Server = Location.substr( 0, Location.find( "/" ) ); // Only leave server address - Location = Location.substr( Server.length(), std::string::npos); - return AuthFromAddress(Server, Location, a_UserName, a_Level + 1); - } - - if (!bOK) - { - LOGERROR("cAuthenticator: received an error from auth server \"%s\" for user \"%s\", kicking user.", a_Server.c_str(), a_UserName.c_str()); - return false; - } - - // Header says OK, so receive the rest. - // Go past header, double \n means end of headers - char c = 0; - while (ss.good()) - { - while (c != '\n') - { - ss.get(c); - } - ss.get(c); - if( c == '\n' || c == '\r' || ss.peek() == '\r' || ss.peek() == '\n' ) - break; - } - if (!ss.good()) - { - LOGERROR("cAuthenticator: error while parsing response body from auth server \"%s\" for user \"%s\", kicking user.", a_Server.c_str(), a_UserName.c_str()); - return false; - } - - std::string Result; - ss >> Result; - LOGD("cAuthenticator: Authentication result was %s", Result.c_str()); - - if (Result.compare("YES") == 0) //Works well - { - LOGINFO("Authentication result \"YES\", player authentication success!"); - return true; - } - - - LOGINFO("Authentication result was \"%s\", player authentication failure!", Result.c_str()); - return false; -} - - - - diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index db865cfa4..985a18a95 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -42,7 +42,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos) // Add each set of coords: int NumChunks = luaL_getn(L, a_ChunkCoordTableStackPos); - m_Chunks.reserve(NumChunks); + m_Chunks.reserve((size_t)NumChunks); for (int idx = 1; idx <= NumChunks; idx++) { // Push the idx-th element of the array onto stack top, check that it's a table: diff --git a/src/Bindings/LuaFunctions.h b/src/Bindings/LuaFunctions.h index 4f9eab86d..629e2d77d 100644 --- a/src/Bindings/LuaFunctions.h +++ b/src/Bindings/LuaFunctions.h @@ -4,12 +4,12 @@ #include <time.h> // tolua_begin -unsigned int GetTime() +inline unsigned int GetTime() { return (unsigned int)time(0); } -std::string GetChar( std::string & a_Str, unsigned int a_Idx ) +inline std::string GetChar( std::string & a_Str, unsigned int a_Idx ) { return std::string(1, a_Str[ a_Idx ]); } diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 92b410481..10e560ac0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -37,7 +37,7 @@ /**************************** * Better error reporting for Lua **/ -int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaError) +static int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaError) { // Retrieve current function name lua_Debug entry; @@ -57,7 +57,7 @@ int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaErro -int lua_do_error(lua_State* L, const char * a_pFormat, ...) +static int lua_do_error(lua_State* L, const char * a_pFormat, ...) { // Retrieve current function name lua_Debug entry; @@ -235,7 +235,7 @@ static int tolua_Base64Decode(lua_State * tolua_S) -cPluginLua * GetLuaPlugin(lua_State * L) +static cPluginLua * GetLuaPlugin(lua_State * L) { // Get the plugin identification out of LuaState: lua_getglobal(L, LUA_PLUGIN_INSTANCE_VAR_NAME); @@ -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; } @@ -1773,20 +1776,20 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) -static int tolua_cPlayer_GetGroups(lua_State* tolua_S) +static int tolua_cPlayer_GetGroups(lua_State * tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); + cPlayer * self = (cPlayer *)tolua_tousertype(tolua_S, 1, NULL); const cPlayer::GroupList & AllGroups = self->GetGroups(); - lua_createtable(tolua_S, AllGroups.size(), 0); + lua_createtable(tolua_S, (int)AllGroups.size(), 0); int newTable = lua_gettop(tolua_S); int index = 1; cPlayer::GroupList::const_iterator iter = AllGroups.begin(); - while(iter != AllGroups.end()) + while (iter != AllGroups.end()) { - const cGroup* Group = *iter; - tolua_pushusertype( tolua_S, (void*)Group, "const cGroup" ); + const cGroup * Group = *iter; + tolua_pushusertype(tolua_S, (void *)Group, "const cGroup"); lua_rawseti(tolua_S, newTable, index); ++iter; ++index; @@ -1798,20 +1801,20 @@ static int tolua_cPlayer_GetGroups(lua_State* tolua_S) -static int tolua_cPlayer_GetResolvedPermissions(lua_State* tolua_S) +static int tolua_cPlayer_GetResolvedPermissions(lua_State * tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); + cPlayer * self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); cPlayer::StringList AllPermissions = self->GetResolvedPermissions(); - lua_createtable(tolua_S, AllPermissions.size(), 0); + lua_createtable(tolua_S, (int)AllPermissions.size(), 0); int newTable = lua_gettop(tolua_S); int index = 1; cPlayer::StringList::iterator iter = AllPermissions.begin(); - while(iter != AllPermissions.end()) + while (iter != AllPermissions.end()) { - std::string& Permission = *iter; - tolua_pushstring( tolua_S, Permission.c_str() ); + std::string & Permission = *iter; + lua_pushlstring(tolua_S, Permission.c_str(), Permission.length()); lua_rawseti(tolua_S, newTable, index); ++iter; ++index; @@ -2073,18 +2076,18 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) { - cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S, 1, NULL); + cWebAdmin * self = (cWebAdmin *)tolua_tousertype(tolua_S, 1, NULL); const cWebAdmin::PluginList & AllPlugins = self->GetPlugins(); - lua_createtable(tolua_S, AllPlugins.size(), 0); + lua_createtable(tolua_S, (int)AllPlugins.size(), 0); int newTable = lua_gettop(tolua_S); int index = 1; cWebAdmin::PluginList::const_iterator iter = AllPlugins.begin(); - while(iter != AllPlugins.end()) + while (iter != AllPlugins.end()) { - const cWebPlugin* Plugin = *iter; - tolua_pushusertype( tolua_S, (void*)Plugin, "const cWebPlugin" ); + const cWebPlugin * Plugin = *iter; + tolua_pushusertype(tolua_S, (void *)Plugin, "const cWebPlugin"); lua_rawseti(tolua_S, newTable, index); ++iter; ++index; diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index df0bd4dcc..0bd9270c4 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -56,7 +56,7 @@ public: virtual bool OnChunkUnloading (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0; virtual bool OnCollectingPickup (cPlayer * a_Player, cPickup * a_Pickup) = 0; virtual bool OnCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; - virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) = 0; + virtual bool OnDisconnect (cClientHandle & a_Client, const AString & a_Reason) = 0; virtual bool OnExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split) = 0; virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0; virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index dcc816839..59708bf59 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -400,14 +400,14 @@ bool cPluginLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGri -bool cPluginLua::OnDisconnect(cPlayer * a_Player, const AString & a_Reason) +bool cPluginLua::OnDisconnect(cClientHandle & a_Client, const AString & a_Reason) { cCSLock Lock(m_CriticalSection); bool res = false; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_DISCONNECT]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), a_Player, a_Reason, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), &a_Client, a_Reason, cLuaState::Return, res); if (res) { return true; @@ -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; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 59542d23a..3357dd87b 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -79,7 +79,7 @@ public: virtual bool OnChunkUnloading (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override; virtual bool OnCollectingPickup (cPlayer * a_Player, cPickup * a_Pickup) override; virtual bool OnCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; - virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override; + virtual bool OnDisconnect (cClientHandle & a_Client, const AString & a_Reason) override; virtual bool OnExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split) override; virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override; virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 6a5356c0b..aaccc606d 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -442,7 +442,7 @@ bool cPluginManager::CallHookCraftingNoRecipe(const cPlayer * a_Player, const cC -bool cPluginManager::CallHookDisconnect(cPlayer * a_Player, const AString & a_Reason) +bool cPluginManager::CallHookDisconnect(cClientHandle & a_Client, const AString & a_Reason) { HookMap::iterator Plugins = m_Hooks.find(HOOK_DISCONNECT); if (Plugins == m_Hooks.end()) @@ -451,7 +451,7 @@ bool cPluginManager::CallHookDisconnect(cPlayer * a_Player, const AString & a_Re } for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnDisconnect(a_Player, a_Reason)) + if ((*itr)->OnDisconnect(a_Client, a_Reason)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 512bc1351..58c1cebb4 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -172,7 +172,7 @@ public: // tolua_export bool CallHookChunkUnloading (cWorld * a_World, int a_ChunkX, int a_ChunkZ); bool CallHookCollectingPickup (cPlayer * a_Player, cPickup & a_Pickup); bool CallHookCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); - bool CallHookDisconnect (cPlayer * a_Player, const AString & a_Reason); + bool CallHookDisconnect (cClientHandle & a_Client, const AString & a_Reason); bool CallHookExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split); // If a_Player == NULL, it is a console cmd bool CallHookExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData); bool CallHookExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData); diff --git a/src/Bindings/tolua++.exe b/src/Bindings/tolua++.exe Binary files differindex 1e3cc7789..ba3a6b0c7 100644 --- a/src/Bindings/tolua++.exe +++ b/src/Bindings/tolua++.exe diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 3fba93e8a..9852b3dd9 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -7,6 +7,88 @@ #include "BiomeDef.h" + + +// The "map" used for biome <-> string conversions: +static struct { + EMCSBiome m_Biome; + const char * m_String; +} g_BiomeMap[] = +{ + {biOcean, "Ocean"} , + {biPlains, "Plains"}, + {biDesert, "Desert"}, + {biExtremeHills, "ExtremeHills"}, + {biForest, "Forest"}, + {biTaiga, "Taiga"}, + {biSwampland, "Swampland"}, + {biRiver, "River"}, + {biNether, "Hell"}, + {biNether, "Nether"}, + {biEnd, "Sky"}, + {biEnd, "End"}, + {biFrozenOcean, "FrozenOcean"}, + {biFrozenRiver, "FrozenRiver"}, + {biIcePlains, "IcePlains"}, + {biIcePlains, "Tundra"}, + {biIceMountains, "IceMountains"}, + {biMushroomIsland, "MushroomIsland"}, + {biMushroomShore, "MushroomShore"}, + {biBeach, "Beach"}, + {biDesertHills, "DesertHills"}, + {biForestHills, "ForestHills"}, + {biTaigaHills, "TaigaHills"}, + {biExtremeHillsEdge, "ExtremeHillsEdge"}, + {biJungle, "Jungle"}, + {biJungleHills, "JungleHills"}, + + // Release 1.7 biomes: + {biJungleEdge, "JungleEdge"}, + {biDeepOcean, "DeepOcean"}, + {biStoneBeach, "StoneBeach"}, + {biColdBeach, "ColdBeach"}, + {biBirchForest, "BirchForest"}, + {biBirchForestHills, "BirchForestHills"}, + {biRoofedForest, "RoofedForest"}, + {biColdTaiga, "ColdTaiga"}, + {biColdTaigaHills, "ColdTaigaHills"}, + {biMegaTaiga, "MegaTaiga"}, + {biMegaTaigaHills, "MegaTaigaHills"}, + {biExtremeHillsPlus, "ExtremeHillsPlus"}, + {biSavanna, "Savanna"}, + {biSavannaPlateau, "SavannaPlateau"}, + {biMesa, "Mesa"}, + {biMesaPlateauF, "MesaPlateauF"}, + {biMesaPlateau, "MesaPlateau"}, + + // Release 1.7 variants: + {biSunflowerPlains, "SunflowerPlains"}, + {biDesertM, "DesertM"}, + {biExtremeHillsM, "ExtremeHillsM"}, + {biFlowerForest, "FlowerForest"}, + {biTaigaM, "TaigaM"}, + {biSwamplandM, "SwamplandM"}, + {biIcePlainsSpikes, "IcePlainsSpikes"}, + {biJungleM, "JungleM"}, + {biJungleEdgeM, "JungleEdgeM"}, + {biBirchForestM, "BirchForestM"}, + {biBirchForestHillsM, "BirchForestHillsM"}, + {biRoofedForestM, "RoofedForestM"}, + {biColdTaigaM, "ColdTaigaM"}, + {biMegaSpruceTaiga, "MegaSpruceTaiga"}, + {biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"}, + {biExtremeHillsPlusM, "ExtremeHillsPlusM"}, + {biSavannaM, "SavannaM"}, + {biSavannaPlateauM, "SavannaPlateauM"}, + {biMesaBryce, "MesaBryce"}, + {biMesaPlateauFM, "MesaPlateauFM"}, + {biMesaPlateauM, "MesaPlateauM"}, +} ; + + + + + EMCSBiome StringToBiome(const AString & a_BiomeString) { // If it is a number, return it: @@ -25,87 +107,11 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) return biInvalidBiome; } - // Convert using the built-in map: - static struct { - EMCSBiome m_Biome; - const char * m_String; - } BiomeMap[] = - { - {biOcean, "Ocean"} , - {biPlains, "Plains"}, - {biDesert, "Desert"}, - {biExtremeHills, "ExtremeHills"}, - {biForest, "Forest"}, - {biTaiga, "Taiga"}, - {biSwampland, "Swampland"}, - {biRiver, "River"}, - {biNether, "Hell"}, - {biNether, "Nether"}, - {biEnd, "Sky"}, - {biEnd, "End"}, - {biFrozenOcean, "FrozenOcean"}, - {biFrozenRiver, "FrozenRiver"}, - {biIcePlains, "IcePlains"}, - {biIcePlains, "Tundra"}, - {biIceMountains, "IceMountains"}, - {biMushroomIsland, "MushroomIsland"}, - {biMushroomShore, "MushroomShore"}, - {biBeach, "Beach"}, - {biDesertHills, "DesertHills"}, - {biForestHills, "ForestHills"}, - {biTaigaHills, "TaigaHills"}, - {biExtremeHillsEdge, "ExtremeHillsEdge"}, - {biJungle, "Jungle"}, - {biJungleHills, "JungleHills"}, - - // Release 1.7 biomes: - {biJungleEdge, "JungleEdge"}, - {biDeepOcean, "DeepOcean"}, - {biStoneBeach, "StoneBeach"}, - {biColdBeach, "ColdBeach"}, - {biBirchForest, "BirchForest"}, - {biBirchForestHills, "BirchForestHills"}, - {biRoofedForest, "RoofedForest"}, - {biColdTaiga, "ColdTaiga"}, - {biColdTaigaHills, "ColdTaigaHills"}, - {biMegaTaiga, "MegaTaiga"}, - {biMegaTaigaHills, "MegaTaigaHills"}, - {biExtremeHillsPlus, "ExtremeHillsPlus"}, - {biSavanna, "Savanna"}, - {biSavannaPlateau, "SavannaPlateau"}, - {biMesa, "Mesa"}, - {biMesaPlateauF, "MesaPlateauF"}, - {biMesaPlateau, "MesaPlateau"}, - - // Release 1.7 variants: - {biSunflowerPlains, "SunflowerPlains"}, - {biDesertM, "DesertM"}, - {biExtremeHillsM, "ExtremeHillsM"}, - {biFlowerForest, "FlowerForest"}, - {biTaigaM, "TaigaM"}, - {biSwamplandM, "SwamplandM"}, - {biIcePlainsSpikes, "IcePlainsSpikes"}, - {biJungleM, "JungleM"}, - {biJungleEdgeM, "JungleEdgeM"}, - {biBirchForestM, "BirchForestM"}, - {biBirchForestHillsM, "BirchForestHillsM"}, - {biRoofedForestM, "RoofedForestM"}, - {biColdTaigaM, "ColdTaigaM"}, - {biMegaSpruceTaiga, "MegaSpruceTaiga"}, - {biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"}, - {biExtremeHillsPlusM, "ExtremeHillsPlusM"}, - {biSavannaM, "SavannaM"}, - {biSavannaPlateauM, "SavannaPlateauM"}, - {biMesaBryce, "MesaBryce"}, - {biMesaPlateauFM, "MesaPlateauFM"}, - {biMesaPlateauM, "MesaPlateauM"}, - } ; - - for (size_t i = 0; i < ARRAYCOUNT(BiomeMap); i++) + for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++) { - if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0) + if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0) { - return BiomeMap[i].m_Biome; + return g_BiomeMap[i].m_Biome; } } // for i - BiomeMap[] return biInvalidBiome; @@ -115,6 +121,22 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) +AString BiomeToString(int a_Biome) +{ + for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++) + { + if (g_BiomeMap[i].m_Biome == a_Biome) + { + return g_BiomeMap[i].m_String; + } + } + return AString(); +} + + + + + bool IsBiomeNoDownfall(EMCSBiome a_Biome) { switch (a_Biome) diff --git a/src/BiomeDef.h b/src/BiomeDef.h index 474d4df76..67916890d 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -104,10 +104,13 @@ enum EMCSBiome biMaxVariantBiome = biNumVariantBiomes - 1, // The maximum biome value } ; -/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. +/** Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. */ extern EMCSBiome StringToBiome(const AString & a_BiomeString); -/// Returns true if the biome has no downfall - deserts and savannas +/** Translates biome enum into biome string. Returns empty string on failure (unknown biome). */ +extern AString BiomeToString(int a_Biome); + +/** Returns true if the biome has no downfall - deserts and savannas */ extern bool IsBiomeNoDownfall(EMCSBiome a_Biome); diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 40cca8882..897af27c4 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -14,17 +14,29 @@ +// Disable MSVC warnings: "conditional expression is constant" +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4127) +#endif + + + + + +typedef void (CombinatorFunc)(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta); + // 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<typename Combinator> void InternalMergeBlocks( +template<bool MetasValid, CombinatorFunc Combinator> +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 +53,15 @@ template<typename Combinator> 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 @@ -54,10 +74,14 @@ template<typename Combinator> void InternalMergeBlocks( /// Combinator used for cBlockArea::msOverwrite merging -static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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 +89,16 @@ static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_S /// Combinator used for cBlockArea::msFillAir merging -static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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 +108,16 @@ static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msImprint merging -static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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,7 +127,8 @@ static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_Src /// Combinator used for cBlockArea::msLake merging -static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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) @@ -107,7 +140,10 @@ 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 +168,10 @@ 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 +185,10 @@ 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 +201,17 @@ static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcTyp /** Combinator used for cBlockArea::msSpongePrint merging */ -static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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 +220,24 @@ static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a /** Combinator used for cBlockArea::msDifference merging */ -static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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,16 +246,25 @@ static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_ /** Combinator used for cBlockArea::msMask merging */ -static inline void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +template<bool MetaValid> +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; + } } } +// Re-enable previously disabled MSVC warnings +#ifdef _MSC_VER + #pragma warning(pop) +#endif + @@ -484,7 +546,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 +594,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,155 +699,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) { - SrcMetas = new NIBBLETYPE[a_Src.GetBlockCount()]; - DstMetas = new NIBBLETYPE[GetBlockCount()]; + MergeByStrategy<false>(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<true>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); } } @@ -2079,7 +2005,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; @@ -2109,7 +2035,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; @@ -2161,4 +2087,137 @@ void cBlockArea::RelSetData( +template<bool MetasValid> +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<MetasValid, MergeCombinatorOverwrite<MetasValid> >( + 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<MetasValid, MergeCombinatorFillAir<MetasValid> >( + 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<MetasValid, MergeCombinatorImprint<MetasValid> >( + 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<MetasValid, MergeCombinatorLake<MetasValid> >( + 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<MetasValid, MergeCombinatorSpongePrint<MetasValid> >( + 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<MetasValid, MergeCombinatorDifference<MetasValid> >( + 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<MetasValid, MergeCombinatorMask<MetasValid> >( + 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..6dba0f12e 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 (size_t)(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<bool MetasValid> + 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/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp new file mode 100644 index 000000000..0914353eb --- /dev/null +++ b/src/BlockEntities/BeaconEntity.cpp @@ -0,0 +1,116 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BeaconEntity.h" +#include "../BlockArea.h" + + + + + +cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, a_World) +{ +} + + + + + +int cBeaconEntity::GetPyramidLevel(void) +{ + cBlockArea Area; + int MinY = GetPosY() - 4; + if (MinY < 0) + { + MinY = 0; + } + int MaxY = GetPosY() - 1; + if (MaxY < 0) + { + MaxY = 0; + } + + Area.Read( + m_World, + GetPosX() - 4, GetPosX() + 4, + MinY, MaxY, + GetPosZ() - 4, GetPosZ() + 4, + cBlockArea::baTypes + ); + + int Layer = 1; + int MiddleXZ = 4; + + for (int Y = Area.GetSizeY() - 1; Y > 0; Y--) + { + for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++) + { + for (int Z = MiddleXZ - Layer; Z <= (MiddleXZ + Layer); Z++) + { + if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z))) + { + return Layer - 1; + } + } + } + Layer++; + } + + return Layer - 1; +} + + + + + +bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) +{ + switch(a_BlockType) + { + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_EMERALD_BLOCK: + { + return true; + } + } + return false; +} + + + + + +bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + return false; +} + + + + + +void cBeaconEntity::SaveToJson(Json::Value& a_Value) +{ +} + + + + +void cBeaconEntity::SendTo(cClientHandle & a_Client) +{ +} + + + + + +void cBeaconEntity::UsedBy(cPlayer * a_Player) +{ +} + + + + diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h new file mode 100644 index 000000000..b1df68bc4 --- /dev/null +++ b/src/BlockEntities/BeaconEntity.h @@ -0,0 +1,44 @@ + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +class cBeaconEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + /** The initial constructor */ + cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + /** Returns the amount of layers the pyramid below the beacon has. */ + int GetPyramidLevel(void); + + /** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */ + static bool IsMineralBlock(BLOCKTYPE a_BlockType); + + // cBlockEntity overrides: + virtual void SaveToJson(Json::Value& a_Value ) override; + virtual void SendTo(cClientHandle & a_Client) override; + virtual void UsedBy(cPlayer * a_Player) override; + virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) override; +} ; + + + + diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index b42318c2f..430f04551 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -4,6 +4,7 @@ // Implements the cBlockEntity class that is the common ancestor for all block entities #include "Globals.h" +#include "BeaconEntity.h" #include "BlockEntity.h" #include "ChestEntity.h" #include "CommandBlockEntity.h" @@ -26,6 +27,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { + case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); 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/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/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index e03bf776d..2a32f69d9 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -128,10 +128,11 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) if (DispChunk->GetBlock(DispX, DispY, DispZ) == E_BLOCK_AIR) { DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_FIRE, 0); - m_Contents.SetSlot(a_SlotNum, m_Contents.GetSlot(a_SlotNum).m_ItemType, m_Contents.GetSlot(a_SlotNum).m_ItemCount, m_Contents.GetSlot(a_SlotNum).m_ItemDamage + 1); - // If the durability has run out destroy the item. - if (m_Contents.GetSlot(a_SlotNum).m_ItemDamage > 64) - { + + bool ItemBroke = m_Contents.DamageItem(a_SlotNum, 1); + + if (ItemBroke) + { m_Contents.ChangeSlotCount(a_SlotNum, -1); } } diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 7d6d1f89e..1b1741713 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -413,19 +413,20 @@ bool cFurnaceEntity::CanCookInputToOutput(void) const return false; } - if (m_Contents.GetSlot(fsOutput).IsEmpty()) + const cItem & Slot = m_Contents.GetSlot(fsOutput); + if (Slot.IsEmpty()) { // The output is empty, can cook return true; } - if (!m_Contents.GetSlot(fsOutput).IsEqual(*m_CurrentRecipe->Out)) + if (!Slot.IsEqual(*m_CurrentRecipe->Out)) { // The output slot is blocked with something that cannot be stacked with the recipe's output return false; } - if (m_Contents.GetSlot(fsOutput).IsFullStack()) + if (Slot.IsFullStack()) { // Cannot add any more items to the output slot return false; diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 41fb9f811..7f001c739 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -234,24 +234,27 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) bool TrySuckPickupIn(cPickup * a_Pickup) { + cItem & Item = a_Pickup->GetItem(); + for (int i = 0; i < ContentsWidth * ContentsHeight; i++) { if (m_Contents.IsSlotEmpty(i)) { m_bFoundPickupsAbove = true; - m_Contents.SetSlot(i, a_Pickup->GetItem()); + m_Contents.SetSlot(i, Item); a_Pickup->Destroy(); // Kill pickup return true; } - else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack()) + else if (m_Contents.GetSlot(i).IsEqual(Item) && !m_Contents.GetSlot(i).IsFullStack()) { m_bFoundPickupsAbove = true; int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; - a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added - if (a_Pickup->GetItem().IsEmpty()) + Item.m_ItemCount -= m_Contents.ChangeSlotCount(i, Item.m_ItemCount) - PreviousCount; // Set count to however many items were added + + if (Item.IsEmpty()) { a_Pickup->Destroy(); // Kill pickup if all items were added } 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/BlockID.cpp b/src/BlockID.cpp index 79e122032..bfe826f40 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -102,7 +102,7 @@ public: return true; } - a_Item.m_ItemDamage = atoi(Split[1].c_str()); + a_Item.m_ItemDamage = (short)atoi(Split[1].c_str()); if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) { // Parsing the number failed @@ -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/BlockID.h b/src/BlockID.h index 2fec512e2..a227245aa 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -503,6 +503,10 @@ enum E_META_PLANKS_CONIFER = 1, E_META_PLANKS_BIRCH = 2, E_META_PLANKS_JUNGLE = 3, + + // E_BLOCK_(XXX_WEIGHTED)_PRESSURE_PLATE metas: + E_META_PRESSURE_PLATE_RAISED = 0, + E_META_PRESSURE_PLATE_DEPRESSED = 1, // E_BLOCK_QUARTZ_BLOCK metas: E_META_QUARTZ_NORMAL = 0, diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 64fce20bf..e8d9a7ec4 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -133,6 +133,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; ms_Info[E_BLOCK_ICE ].m_Transparent = true; ms_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true; + ms_Info[E_BLOCK_LADDER ].m_Transparent = true; ms_Info[E_BLOCK_LAVA ].m_Transparent = true; ms_Info[E_BLOCK_LEAVES ].m_Transparent = true; ms_Info[E_BLOCK_LEVER ].m_Transparent = true; diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index 93a796ef7..35a356678 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -23,6 +23,13 @@ public: { a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2)); } + + + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + cWindow * Window = new cAnvilWindow(a_BlockX, a_BlockY, a_BlockZ); + a_Player->OpenWindow(Window); + } virtual bool GetPlacementBlockTypeMeta( diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index a1ded4c26..c9a769c75 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -56,6 +56,7 @@ public: (Area.GetRelBlockType(2, 0, 1) == E_BLOCK_CHEST) ) { + // FIXME: This is unreachable, as the condition is the same as the above one a_BlockMeta = (yaw < 0) ? 4 : 5; return true; } diff --git a/src/Blocks/BlockEnchantmentTable.h b/src/Blocks/BlockEnchantmentTable.h new file mode 100644 index 000000000..81d2cb9a0 --- /dev/null +++ b/src/Blocks/BlockEnchantmentTable.h @@ -0,0 +1,37 @@ + +#pragma once + +#include "BlockHandler.h" +#include "../UI/Window.h" +#include "../Entities/Player.h" + + + + + +class cBlockEnchantmentTableHandler : + public cBlockHandler +{ +public: + cBlockEnchantmentTableHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + cWindow * Window = new cEnchantingWindow(a_BlockX, a_BlockY, a_BlockZ); + a_Player->OpenWindow(Window); + } + + + virtual bool IsUseable(void) override + { + return true; + } +}; + + + + diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index c8f158e7e..f9f32eb50 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -68,7 +68,6 @@ public: { return 0; } - for (int newY = Y + 1; newY < cChunkDef::Height; newY++) { @@ -84,7 +83,7 @@ public: // This is because the frame is a solid obsidian pillar if ((MaxY != 0) && (newY == Y + 1)) { - return EvaluatePortalBorder(X, newY, Z, MaxY, a_ChunkInterface); + return EvaluatePortalBorder(X, newY, Z, MaxY, a_ChunkInterface) ? -1 /* -1 = found a frame */ : 0; } else { @@ -99,18 +98,18 @@ public: } /// Evaluates if coords have a valid border on top, based on MaxY - int EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface & a_ChunkInterface) + bool EvaluatePortalBorder(int X, int FoundObsidianY, int Z, int MaxY, cChunkInterface & a_ChunkInterface) { for (int checkBorder = FoundObsidianY + 1; checkBorder <= MaxY - 1; checkBorder++) // FoundObsidianY + 1: FoundObsidianY has already been checked in FindObsidianCeiling; MaxY - 1: portal doesn't need corners { if (a_ChunkInterface.GetBlock(X, checkBorder, Z) != E_BLOCK_OBSIDIAN) { // Base obsidian, base + 1 obsidian, base + x NOT obsidian -> not complete portal - return 0; + return false; } } // Everything was obsidian, found a border! - return -1; // Return -1 for a frame border + return true; } /// Finds entire frame in any direction with the coordinates of a base block and fills hole with nether portal (START HERE) @@ -169,7 +168,7 @@ public: { return false; // Not valid slice, no portal can be formed } - } XZP = X1 - 1; // Set boundary of frame interior, note that for some reason, the loop of X and the loop of Z go to different numbers, hence -1 here and -2 there + } XZP = X1 - 1; // Set boundary of frame interior for (; ((a_ChunkInterface.GetBlock(X2, Y, Z) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X2, Y + 1, Z) == E_BLOCK_OBSIDIAN)); X2--) // Go the other direction (XM) { int Value = FindObsidianCeiling(X2, Y, Z, a_ChunkInterface, MaxY); @@ -199,13 +198,13 @@ public: if ((Value == -1) || (ValueTwo == -1)) { FoundFrameZP = true; - continue; + break; } else if ((Value != MaxY) && (ValueTwo != MaxY)) { return false; } - } XZP = Z1 - 2; + } XZP = Z1 - 1; for (; ((a_ChunkInterface.GetBlock(X, Y, Z2) == E_BLOCK_OBSIDIAN) || (a_ChunkInterface.GetBlock(X, Y + 1, Z2) == E_BLOCK_OBSIDIAN)); Z2--) { int Value = FindObsidianCeiling(X, Y, Z2, a_ChunkInterface, MaxY); @@ -213,13 +212,13 @@ public: if ((Value == -1) || (ValueTwo == -1)) { FoundFrameZM = true; - continue; + break; } else if ((Value != MaxY) && (ValueTwo != MaxY)) { return false; } - } XZM = Z2 + 2; + } XZM = Z2 + 1; return (FoundFrameZP && FoundFrameZM); } }; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 344f056a1..850bae6b9 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -25,6 +25,7 @@ #include "BlockDirt.h" #include "BlockDoor.h" #include "BlockDropSpenser.h" +#include "BlockEnchantmentTable.h" #include "BlockEnderchest.h" #include "BlockEntity.h" #include "BlockFarmland.h" @@ -119,6 +120,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_DOUBLE_WOODEN_SLAB: return new cBlockDoubleSlabHandler (a_BlockType); case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType); case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_ENCHANTMENT_TABLE: return new cBlockEnchantmentTableHandler(a_BlockType); case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType); case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler ( ); case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType); diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 8af14686e..d21227b07 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -16,6 +16,7 @@ { \ case E_BLOCK_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \ case E_BLOCK_LOG: return true; \ + case E_BLOCK_NEW_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \ case E_BLOCK_NEW_LOG: return true; \ } diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index ad78d290a..358b5ca11 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -141,7 +141,7 @@ public: NIBBLETYPE Meta = 0; char RailsCnt = 0; bool Neighbors[8]; // 0 - EAST, 1 - WEST, 2 - NORTH, 3 - SOUTH, 4 - EAST UP, 5 - WEST UP, 6 - NORTH UP, 7 - SOUTH UP - memset(Neighbors, false, sizeof(Neighbors)); + memset(Neighbors, 0, sizeof(Neighbors)); Neighbors[0] = (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN)); Neighbors[1] = (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_WEST, E_PURE_DOWN)); Neighbors[2] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN)); 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/BoundingBox.cpp b/src/BoundingBox.cpp index 482f9923f..ce831c200 100644 --- a/src/BoundingBox.cpp +++ b/src/BoundingBox.cpp @@ -288,7 +288,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d & Coeff = c; } c = a_Line1.LineCoeffToXZPlane(a_Line2, a_Max.y); - if ((c >= 0) && (c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) + if ((c >= 0) && (c < Coeff) && IsInside(a_Min, a_Max, a_Line1 + (a_Line2 - a_Line1) * c)) { Face = (a_Line1.y > a_Line2.y) ? BLOCK_FACE_YP : BLOCK_FACE_YM; Coeff = c; diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 1893d89a8..4de89f7c1 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 @@ -171,7 +171,7 @@ cByteBuffer::~cByteBuffer() -bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) +bool cByteBuffer::Write(const void * a_Bytes, size_t a_Count) { CHECK_THREAD; CheckValid(); @@ -187,13 +187,14 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) } ASSERT(m_BufferSize >= m_WritePos); size_t TillEnd = m_BufferSize - m_WritePos; + const char * Bytes = (const char *)a_Bytes; if (TillEnd <= a_Count) { // Need to wrap around the ringbuffer end if (TillEnd > 0) { - memcpy(m_Buffer + m_WritePos, a_Bytes, TillEnd); - a_Bytes += TillEnd; + memcpy(m_Buffer + m_WritePos, Bytes, TillEnd); + Bytes += TillEnd; a_Count -= TillEnd; WrittenBytes = TillEnd; } @@ -203,7 +204,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count) // We're guaranteed that we'll fit in a single write op if (a_Count > 0) { - memcpy(m_Buffer + m_WritePos, a_Bytes, a_Count); + memcpy(m_Buffer + m_WritePos, Bytes, a_Count); m_WritePos += a_Count; WrittenBytes += a_Count; } @@ -326,7 +327,7 @@ bool cByteBuffer::ReadBEShort(short & a_Value) CheckValid(); NEEDBYTES(2); ReadBuf(&a_Value, 2); - a_Value = ntohs(a_Value); + a_Value = (short)ntohs((u_short)a_Value); return true; } @@ -340,7 +341,7 @@ bool cByteBuffer::ReadBEInt(int & a_Value) CheckValid(); NEEDBYTES(4); ReadBuf(&a_Value, 4); - a_Value = ntohl(a_Value); + a_Value = (int)ntohl((u_long)a_Value); return true; } @@ -419,7 +420,7 @@ bool cByteBuffer::ReadBEUTF16String16(AString & a_Value) ASSERT(!"Negative string length? Are you sure?"); return true; } - return ReadUTF16String(a_Value, Length); + return ReadUTF16String(a_Value, (size_t)Length); } @@ -437,7 +438,7 @@ bool cByteBuffer::ReadVarInt(UInt32 & a_Value) { NEEDBYTES(1); ReadBuf(&b, 1); - Value = Value | (((Int64)(b & 0x7f)) << Shift); + Value = Value | (((UInt32)(b & 0x7f)) << Shift); Shift += 7; } while ((b & 0x80) != 0); a_Value = Value; @@ -461,7 +462,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value) { LOGWARNING("%s: String too large: %u (%u KiB)", __FUNCTION__, Size, Size / 1024); } - return ReadString(a_Value, (int)Size); + return ReadString(a_Value, (size_t)Size); } @@ -516,7 +517,7 @@ bool cByteBuffer::WriteBEShort(short a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(2); - short Converted = htons(a_Value); + u_short Converted = htons((u_short)a_Value); return WriteBuf(&Converted, 2); } @@ -529,7 +530,7 @@ bool cByteBuffer::WriteBEInt(int a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(4); - int Converted = HostToNetwork4(&a_Value); + UInt32 Converted = HostToNetwork4(&a_Value); return WriteBuf(&Converted, 4); } @@ -542,7 +543,7 @@ bool cByteBuffer::WriteBEInt64(Int64 a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(8); - Int64 Converted = HostToNetwork8(&a_Value); + UInt64 Converted = HostToNetwork8(&a_Value); return WriteBuf(&Converted, 8); } @@ -555,7 +556,7 @@ bool cByteBuffer::WriteBEFloat(float a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(4); - int Converted = HostToNetwork4(&a_Value); + UInt32 Converted = HostToNetwork4(&a_Value); return WriteBuf(&Converted, 4); } @@ -568,7 +569,7 @@ bool cByteBuffer::WriteBEDouble(double a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(8); - Int64 Converted = HostToNetwork8(&a_Value); + UInt64 Converted = HostToNetwork8(&a_Value); return WriteBuf(&Converted, 8); } @@ -612,7 +613,7 @@ bool cByteBuffer::WriteVarInt(UInt32 a_Value) // A 32-bit integer can be encoded by at most 5 bytes: unsigned char b[5]; - int idx = 0; + size_t idx = 0; do { b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00); @@ -631,7 +632,7 @@ bool cByteBuffer::WriteVarUTF8String(const AString & a_Value) CHECK_THREAD; CheckValid(); PUTBYTES(a_Value.size() + 1); // This is a lower-bound on the bytes that will be actually written. Fail early. - bool res = WriteVarInt(a_Value.size()); + bool res = WriteVarInt((UInt32)(a_Value.size())); if (!res) { return false; @@ -756,7 +757,7 @@ bool cByteBuffer::ReadString(AString & a_String, size_t a_Count) -bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) +bool cByteBuffer::ReadUTF16String(AString & a_String, size_t a_NumChars) { // Reads 2 * a_NumChars bytes and interprets it as a UTF16 string, converting it into UTF8 string a_String CHECK_THREAD; @@ -887,9 +888,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); } diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index 1915467f3..929c93167 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -27,11 +27,11 @@ 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 - bool Write(const char * a_Bytes, size_t a_Count); + bool Write(const void * a_Bytes, size_t a_Count); /// Returns the number of bytes that can be successfully written to the ringbuffer size_t GetFreeSpace(void) const; @@ -101,7 +101,7 @@ public: bool ReadString(AString & a_String, size_t a_Count); /// Reads 2 * a_NumChars bytes and interprets it as a UTF16-BE string, converting it into UTF8 string a_String - bool ReadUTF16String(AString & a_String, int a_NumChars); + bool ReadUTF16String(AString & a_String, size_t a_NumChars); /// Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer bool SkipRead(size_t a_Count); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30e9dbfd4..900577526 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/") include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/jsoncpp/include") include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") -set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating) +set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating PolarSSL++) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities Generating/Prefabs) @@ -57,6 +57,14 @@ if (NOT MSVC) Entities/Pickup.h Entities/Player.h Entities/ProjectileEntity.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 @@ -123,6 +131,7 @@ if (NOT MSVC) file(GLOB SOURCE "*.cpp" + "*.h" ) list(REMOVE_ITEM SOURCE "${PROJECT_SOURCE_DIR}/StackWalker.cpp" "${PROJECT_SOURCE_DIR}/LeakFinder.cpp") @@ -233,7 +242,7 @@ endif () if (NOT MSVC) target_link_libraries(${EXECUTABLE} OSSupport HTTPServer Bindings Items Blocks) target_link_libraries(${EXECUTABLE} Protocol Generating Generating_Prefabs WorldStorage) - target_link_libraries(${EXECUTABLE} Mobs Entities Simulator UI BlockEntities) + target_link_libraries(${EXECUTABLE} Mobs Entities Simulator UI BlockEntities PolarSSL++) endif () if (WIN32) target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 22b33c595..ca536e89a 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -240,11 +240,24 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) { a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - a_Callback.BlockTypes (m_BlockTypes); - a_Callback.BlockMeta (m_BlockMeta); + + COMPRESSED_BLOCKTYPE Blocks = m_BlockTypes; + Blocks.resize(NumBlocks); + a_Callback.BlockTypes (&Blocks[0]); + + COMPRESSED_NIBBLETYPE Metas = m_BlockMeta; + Metas.resize(NumBlocks / 2); + a_Callback.BlockMeta (&Metas[0]); + a_Callback.LightIsValid (m_IsLightValid); - a_Callback.BlockLight (m_BlockLight); - a_Callback.BlockSkyLight(m_BlockSkyLight); + + COMPRESSED_NIBBLETYPE BlockLights = m_BlockLight; + BlockLights.resize(NumBlocks / 2); + a_Callback.BlockLight (&BlockLights[0]); + + COMPRESSED_NIBBLETYPE BlockSkyLights = m_BlockSkyLight; + BlockSkyLights.resize(NumBlocks / 2, 0xff); + a_Callback.BlockSkyLight(&BlockSkyLights[0]); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -262,7 +275,7 @@ 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, @@ -272,29 +285,61 @@ void cChunk::SetAllData( ) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); - + if (a_HeightMap != NULL) { memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } + + if (a_HeightMap == NULL) + { + CalculateHeightmap(a_BlockTypes); + } + + 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++) + { + unsigned char Height = m_HeightMap[x + z * Width]; + if (Height > Highest) + { + Highest = Height; + X = x; Z = z; + } + } + } + + 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]); + } - memcpy(m_BlockTypes, a_BlockTypes, sizeof(m_BlockTypes)); - memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) { - memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); + // Compress blocklight + m_BlockLight.clear(); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts / 2]); } + if (a_BlockSkyLight != NULL) { - memcpy(m_BlockSkyLight, a_BlockSkyLight, sizeof(m_BlockSkyLight)); + // Compress skylight + m_BlockSkyLight.clear(); + 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) @@ -332,8 +377,17 @@ 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 + m_BlockLight.clear(); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[m_BlockTypes.size() / 2]); + } + + { // Compress skylight + m_BlockSkyLight.clear(); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[m_BlockTypes.size() / 2]); + } + m_IsLightValid = true; } @@ -343,7 +397,8 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - memcpy(a_BlockTypes, m_BlockTypes, 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); } @@ -452,7 +507,7 @@ void cChunk::CollectMobCensus(cMobCensus& toFill) { cMonster& Monster = (cMonster&)(**itr); currentPosition = Monster.GetPosition(); - for (std::list<const Vector3d*>::const_iterator itr2 = playerPositions.begin(); itr2 != playerPositions.end(); itr2 ++) + for (std::list<const Vector3d*>::const_iterator itr2 = playerPositions.begin(); itr2 != playerPositions.end(); ++itr2) { toFill.CollectMob(Monster,*this,(currentPosition-**itr2).SqrLength()); } @@ -600,7 +655,7 @@ void cChunk::Tick(float a_Dt) delete ToDelete; continue; } - itr++; + ++itr; } // for itr - m_Entitites[] // If any entity moved out of the chunk, move it to the neighbor: @@ -630,7 +685,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()); @@ -694,7 +749,7 @@ void cChunk::ProcessQueuedSetBlocks(void) { if (itr->m_Tick <= CurrTick) { - if (itr->m_PreviousType != E_BLOCK_AIR) // PreviousType defaults to -1 if not specified + if (itr->m_PreviousType != E_BLOCK_AIR) // PreviousType defaults to 0 if not specified { if (GetBlock(itr->m_RelX, itr->m_RelY, itr->m_RelZ) == itr->m_PreviousType) { @@ -751,7 +806,7 @@ void cChunk::BroadcastPendingBlockChanges(void) void cChunk::CheckBlocks() { - if (m_ToTickBlocks.size() == 0) + if (m_ToTickBlocks.empty()) { return; } @@ -811,7 +866,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,9 +1351,10 @@ 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_BEACON: case E_BLOCK_CHEST: case E_BLOCK_COMMAND_BLOCK: case E_BLOCK_DISPENSER: @@ -1348,7 +1404,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)) @@ -1383,7 +1439,7 @@ void cChunk::WakeUpSimulators(void) -void cChunk::CalculateHeightmap() +void cChunk::CalculateHeightmap(const BLOCKTYPE * a_BlockTypes) { for (int x = 0; x < Width; x++) { @@ -1392,7 +1448,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 (a_BlockTypes[index] != E_BLOCK_AIR) { m_HeightMap[x + z * Width] = (unsigned char)y; break; @@ -1429,6 +1485,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, // If the new block is a block entity, create the entity object: switch (a_BlockType) { + case E_BLOCK_BEACON: case E_BLOCK_CHEST: case E_BLOCK_COMMAND_BLOCK: case E_BLOCK_DISPENSER: @@ -1515,7 +1572,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)) { @@ -1523,7 +1580,11 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT } MarkDirty(); - + + if ((size_t)index >= m_BlockTypes.size()) + { + m_BlockTypes.resize(index + 1); + } m_BlockTypes[index] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: @@ -1563,7 +1624,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; @@ -1577,6 +1638,24 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT +void cChunk::SetMeta(int a_BlockIdx, NIBBLETYPE a_Meta) +{ + if (GetNibble(m_BlockMeta, a_BlockIdx) == a_Meta) + { + return; + } + + MarkDirty(); + SetNibble(m_BlockMeta, a_BlockIdx, a_Meta); + Vector3i Coords(IndexToCoordinate(a_BlockIdx)); + + m_PendingSendBlocks.push_back(sSetBlock(m_PosX, m_PosZ, Coords.x, Coords.y, Coords.z, GetBlock(a_BlockIdx), a_Meta)); +} + + + + + void cChunk::SendBlockTo(int a_RelX, int a_RelY, int a_RelZ, cClientHandle * a_Client) { // The coords must be valid, because the upper level already does chunk lookup. No need to check them again. @@ -2450,7 +2529,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 +2543,13 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const ASSERT(!"GetBlock(idx) out of bounds!"); return 0; } - - return m_BlockTypes[ a_BlockIdx ]; + + if ((size_t)a_BlockIdx >= m_BlockTypes.size()) + { + return E_BLOCK_AIR; + } + + return m_BlockTypes[a_BlockIdx]; } @@ -2475,7 +2559,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 +2570,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); @@ -2511,7 +2595,7 @@ cChunk * cChunk::GetNeighborChunk(int a_BlockX, int a_BlockZ) cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ) { // If the relative coords are too far away, use the parent's chunk lookup instead: - if ((a_RelX < 128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128)) + if ((a_RelX < -128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128)) { int BlockX = m_PosX * cChunkDef::Width + a_RelX; int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ; diff --git a/src/Chunk.h b/src/Chunk.h index b3fa563cc..84ec35496 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) @@ -320,15 +320,15 @@ public: m_BlockTickZ = a_RelZ; } - inline NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ); } - inline NIBBLETYPE GetMeta(int a_BlockIdx) const {return cChunkDef::GetNibble(m_BlockMeta, a_BlockIdx); } - inline void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta) { cChunkDef::SetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ, a_Meta); } - inline void SetMeta(int a_BlockIdx, NIBBLETYPE a_Meta) { cChunkDef::SetNibble(m_BlockMeta, a_BlockIdx, a_Meta); } + inline NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const { return cChunkDef::GetNibble(m_BlockMeta, a_RelX, a_RelY, a_RelZ); } + inline NIBBLETYPE GetMeta(int a_BlockIdx) const { return cChunkDef::GetNibble(m_BlockMeta, a_BlockIdx); } + inline void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta) { SetMeta(MakeIndex(a_RelX, a_RelY, a_RelZ), a_Meta); } + void SetMeta(int a_BlockIdx, NIBBLETYPE 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; @@ -382,14 +382,14 @@ private: struct sSetBlockQueueItem { + Int64 m_Tick; int m_RelX, m_RelY, m_RelZ; BLOCKTYPE m_BlockType; NIBBLETYPE m_BlockMeta; - Int64 m_Tick; BLOCKTYPE m_PreviousType; sSetBlockQueueItem(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) : - m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta), m_Tick(a_Tick), m_PreviousType(a_PreviousBlockType) + m_Tick(a_Tick), m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta), m_PreviousType(a_PreviousBlockType) { } } ; @@ -420,11 +420,10 @@ private: cWorld * m_World; cChunkMap * m_ChunkMap; - // TODO: Make these pointers and don't allocate what isn't needed - BLOCKTYPE m_BlockTypes [cChunkDef::NumBlocks]; - NIBBLETYPE m_BlockMeta [cChunkDef::NumBlocks / 2]; - NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; - NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; + 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 9c7753820..83f3c8f5f 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<BLOCKTYPE> COMPRESSED_BLOCKTYPE; + + /** The storage wrapper used for compressed nibbledata residing in RAMz */ + typedef std::vector<NIBBLETYPE> 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 ) @@ -219,46 +225,67 @@ 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) + + + static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false) { if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks)) { - return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f; + if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()) + { + return (a_IsSkyLightNibble ? 0xff : 0); + } + return (a_Buffer[(size_t)(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!"); return 0; } - - + + + 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)) + { + size_t Index = (size_t)MakeIndexNoCheck(x, y, z); + if ((Index / 2) >= a_Buffer.size()) + { + return (a_IsSkyLightNibble ? 0xff : 0); + } + return ExpandNibble(a_Buffer, Index); + } + ASSERT(!"cChunkDef::GetNibble(): coords 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; + return (a_Buffer[(size_t)(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) + 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; } - a_Buffer[a_BlockIdx / 2] = static_cast<NIBBLETYPE>( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set - ); + 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)] = PackNibble(a_Buffer, (size_t)a_BlockIdx, a_Nibble); } - - - static void SetNibble(NIBBLETYPE * 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) || @@ -270,25 +297,33 @@ public: return; } - int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = static_cast<NIBBLETYPE>( - (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set - ); + size_t Index = (size_t)MakeIndexNoCheck(x, y, z); + if ((Index / 2) >= a_Buffer.size()) + { + a_Buffer.resize(((Index / 2) + 1)); + } + a_Buffer[(Index / 2)] = PackNibble(a_Buffer, Index, a_Nibble); } - inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) +private: + + + inline static NIBBLETYPE PackNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, size_t a_Index, NIBBLETYPE a_Nibble) { - return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); + return static_cast<NIBBLETYPE>( + (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 void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value ) + + + inline static NIBBLETYPE ExpandNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, size_t a_Index) { - SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); + return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f; } + } ; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index e695f0ab2..d7164a6a5 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); @@ -916,19 +915,21 @@ void cChunkMap::SetChunkData( } // Notify relevant ChunkStays: - for (cChunkStays::iterator itr = m_ChunkStays.begin(); itr != m_ChunkStays.end(); ) + cChunkStays ToBeDisabled; + for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr) { if ((*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ)) { - cChunkStays::iterator cur = itr; - ++itr; - m_ChunkStays.erase(cur); - } - else - { - ++itr; + // The chunkstay wants to be disabled, add it to a list of to-be-disabled chunkstays for later processing: + ToBeDisabled.push_back(*itr); } } // for itr - m_ChunkStays[] + + // Disable (and possibly remove) the chunkstays that chose to get disabled: + for (cChunkStays::iterator itr = ToBeDisabled.begin(), end = ToBeDisabled.end(); itr != end; ++itr) + { + (*itr)->Disable(); + } } // Notify plugins of the chunk becoming available @@ -1144,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) { @@ -1248,8 +1248,6 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP if ((Chunk != NULL) && Chunk->IsValid()) { Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); - Chunk->MarkDirty(); - Chunk->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, NULL); } } @@ -1654,7 +1652,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() @@ -1689,7 +1690,7 @@ void cChunkMap::RemoveEntity(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->IsValid()) { return; } @@ -1721,7 +1722,7 @@ bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -1971,7 +1972,7 @@ bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEnti { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -1986,7 +1987,7 @@ bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2001,7 +2002,7 @@ bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCa { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2016,7 +2017,7 @@ bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallba { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2031,7 +2032,7 @@ bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpens { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2046,7 +2047,7 @@ bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallba { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2064,7 +2065,7 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2082,7 +2083,7 @@ bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCa cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2100,7 +2101,7 @@ bool cChunkMap::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDis cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2118,7 +2119,7 @@ bool cChunkMap::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropp cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2136,7 +2137,7 @@ bool cChunkMap::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cD cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2154,7 +2155,7 @@ bool cChunkMap::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurna cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2171,7 +2172,7 @@ bool cChunkMap::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNot cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2188,7 +2189,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2206,7 +2207,7 @@ bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHe cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2224,7 +2225,7 @@ bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlo cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2242,7 +2243,7 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + if ((Chunk == NULL) || !Chunk->IsValid()) { return false; } @@ -2974,7 +2975,12 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay) Chunk->Stay(true); if (Chunk->IsValid()) { - a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ); + if (a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ)) + { + // The chunkstay wants to be deactivated, disable it and bail out: + a_ChunkStay.Disable(); + return; + } } } // for itr - WantedChunks[] } @@ -3017,6 +3023,7 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay) } Chunk->Stay(false); } // for itr - Chunks[] + a_ChunkStay.OnDisabled(); } diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp index 6b1d5ee34..b5002a63d 100644 --- a/src/ChunkStay.cpp +++ b/src/ChunkStay.cpp @@ -31,10 +31,7 @@ cChunkStay::~cChunkStay() void cChunkStay::Clear(void) { - if (m_ChunkMap != NULL) - { - Disable(); - } + ASSERT(m_ChunkMap == NULL); m_Chunks.clear(); } @@ -97,8 +94,9 @@ void cChunkStay::Disable(void) { ASSERT(m_ChunkMap != NULL); - m_ChunkMap->DelChunkStay(*this); + cChunkMap * ChunkMap = m_ChunkMap; m_ChunkMap = NULL; + ChunkMap->DelChunkStay(*this); } diff --git a/src/ChunkStay.h b/src/ChunkStay.h index 2510cb490..29893befc 100644 --- a/src/ChunkStay.h +++ b/src/ChunkStay.h @@ -36,8 +36,12 @@ class cChunkStay { public: cChunkStay(void); + + /** Deletes the object. Note that this calls Clear(), which means that the ChunkStay needs to be disabled. */ virtual ~cChunkStay(); + /** Clears all the chunks that have been added. + To be used only while the ChunkStay object is not enabled. */ void Clear(void); /** Adds a chunk to be locked from unloading. diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 5876e55c7..94f031ed6 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -24,13 +24,15 @@ #include "Root.h" -#include "Authenticator.h" +#include "Protocol/Authenticator.h" #include "MersenneTwister.h" #include "Protocol/ProtocolRecognizer.h" #include "CompositeChat.h" #include "Items/ItemSword.h" +#include "md5/md5.h" + /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ @@ -175,6 +177,84 @@ void cClientHandle::Destroy(void) +void cClientHandle::GenerateOfflineUUID(void) +{ + m_UUID = GenerateOfflineUUID(m_Username); +} + + + + + +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 ""; + 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) + { + 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 ""; +} + + + + + +AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) +{ + // Proper format for a version 3 UUID is: + // xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B + + // Generate an md5 checksum, and use it as base for the ID: + MD5 Checksum(a_Username); + AString UUID = Checksum.hexdigest(); + UUID[12] = '3'; // Version 3 UUID + UUID[16] = '8'; // Variant 1 UUID + + // Now the digest doesn't have the UUID slashes, but the client requires them, so add them into the appropriate positions: + UUID.insert(8, "-"); + UUID.insert(13, "-"); + UUID.insert(18, "-"); + UUID.insert(23, "-"); + + return UUID; +} + + + + + void cClientHandle::Kick(const AString & a_Reason) { if (m_State >= csAuthenticating) // Don't log pings @@ -188,7 +268,7 @@ void cClientHandle::Kick(const AString & a_Reason) -void cClientHandle::Authenticate(void) +void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID) { if (m_State != csAuthenticating) { @@ -197,6 +277,12 @@ void cClientHandle::Authenticate(void) ASSERT( m_Player == NULL ); + m_Username = a_Name; + m_UUID = a_UUID; + + // Send login success (if the protocol supports it): + m_Protocol->SendLoginSuccess(); + // Spawn player (only serversided, so data is loaded) m_Player = new cPlayer(this, GetUsername()); @@ -250,6 +336,11 @@ void cClientHandle::Authenticate(void) // Send scoreboard data World->GetScoreBoard().SendTo(*this); + + // Delay the first ping until the client "settles down" + // This should fix #889, "BadCast exception, cannot convert bit to fm" error in client + cTimer t1; + m_LastPingTime = t1.GetNowTime() + 3000; // Send the first KeepAlive packet in 3 seconds cRoot::Get()->GetPluginManager()->CallHookPlayerSpawned(*m_Player); } @@ -412,14 +503,16 @@ void cClientHandle::HandlePing(void) { // Somebody tries to retrieve information about the server AString Reply; + const cServer & Server = *cRoot::Get()->GetServer(); + Printf(Reply, "%s%s%i%s%i", - cRoot::Get()->GetServer()->GetDescription().c_str(), + Server.GetDescription().c_str(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetNumPlayers(), + Server.GetNumPlayers(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetMaxPlayers() + Server.GetMaxPlayers() ); - Kick(Reply.c_str()); + Kick(Reply); } @@ -540,6 +633,10 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString // Client <-> Server branding exchange SendPluginMessage("MC|Brand", "MCServer"); } + else if (a_Channel == "MC|ItemName") + { + HandleAnvilItemName(a_Message.c_str(), a_Message.size()); + } else if (a_Channel == "REGISTER") { if (HasPluginChannel(a_Channel)) @@ -623,7 +720,7 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList -void cClientHandle::HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length) +void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Length) { if (a_Length < 14) { @@ -681,6 +778,29 @@ void cClientHandle::HandleCommandBlockMessage(const char * a_Data, unsigned int +void cClientHandle::HandleAnvilItemName(const char * a_Data, size_t a_Length) +{ + if (a_Length < 1) + { + return; + } + + if ((m_Player->GetWindow() == NULL) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) + { + return; + } + + AString Name(a_Data, a_Length); + if (Name.length() <= 30) + { + ((cAnvilWindow *)m_Player->GetWindow())->SetRepairedItemName(Name, m_Player); + } +} + + + + + void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status) { LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", @@ -994,7 +1114,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()) { @@ -1175,8 +1295,8 @@ void cClientHandle::HandleChat(const AString & a_Message) Color = AString("@") + Color[2]; } else - { - Color.empty(); + { + Color.clear(); } Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); Msg.ParseText(a_Message); @@ -1417,7 +1537,7 @@ void cClientHandle::HandleDisconnect(const AString & a_Reason) { LOGD("Received d/c packet from %s with reason \"%s\"", m_Username.c_str(), a_Reason.c_str()); - cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, a_Reason); + cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, a_Reason); m_HasSentDC = true; Destroy(); @@ -1565,7 +1685,7 @@ void cClientHandle::SendData(const char * a_Data, size_t a_Size) { // There is a queued overflow. Append to it, then send as much from its front as possible m_OutgoingDataOverflow.append(a_Data, a_Size); - int CanFit = m_OutgoingData.GetFreeSpace(); + size_t CanFit = m_OutgoingData.GetFreeSpace(); if (CanFit > 128) { // No point in moving the data over if it's not large enough - too much effort for too little an effect @@ -1677,13 +1797,16 @@ void cClientHandle::Tick(float a_Dt) } // Send a ping packet: - cTimer t1; - if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime())) + if (m_State == csPlaying) { - m_PingID++; - m_PingStartTime = t1.GetNowTime(); - m_Protocol->SendKeepAlive(m_PingID); - m_LastPingTime = m_PingStartTime; + cTimer t1; + if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime())) + { + m_PingID++; + m_PingStartTime = t1.GetNowTime(); + m_Protocol->SendKeepAlive(m_PingID); + m_LastPingTime = m_PingStartTime; + } } // Handle block break animation: @@ -1803,7 +1926,7 @@ 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()); @@ -1822,89 +1945,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi ShouldAppendChatPrefixes = false; } - AString Message; + AString Message = FormatMessageType(ShouldAppendChatPrefixes, a_ChatPrefix, a_AdditionalData); - 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); - - m_Protocol->SendChat(Message); + m_Protocol->SendChat(Message.append(a_Message)); } @@ -2101,7 +2144,7 @@ void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_Blo } // Update the statistics: - m_NumExplosionsThisTick += 1; + m_NumExplosionsThisTick++; m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion); } @@ -2673,9 +2716,9 @@ void cClientHandle::SocketClosed(void) LOGD("Player %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); - if (m_Username != "") // Ignore client pings + if (!m_Username.empty()) // Ignore client pings { - cRoot::Get()->GetPluginManager()->CallHookDisconnect(m_Player, "Player disconnected"); + cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } Destroy(); @@ -2685,4 +2728,27 @@ void cClientHandle::SocketClosed(void) +void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment) +{ + cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow(); + cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player); + int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment); + + if (Item.EnchantByXPLevels(BaseEnchantmentLevel)) + { + if (m_Player->IsGameModeCreative() || m_Player->DeltaExperience(-m_Player->XpForLevel(BaseEnchantmentLevel)) >= 0) + { + Window->m_SlotArea->SetSlot(0, *m_Player, Item); + Window->SendSlot(*m_Player, Window->m_SlotArea, 0); + Window->BroadcastWholeWindow(); + + Window->SetProperty(0, 0, *m_Player); + Window->SetProperty(1, 0, *m_Player); + Window->SetProperty(2, 0, *m_Player); + } + } +} + + + diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 0c367ec7d..4dc6ab074 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -18,6 +18,8 @@ #include "ByteBuffer.h" #include "Scoreboard.h" #include "Map.h" +#include "Enchantments.h" +#include "UI/SlotArea.h" @@ -62,8 +64,27 @@ public: cPlayer* GetPlayer() { return m_Player; } // tolua_export + const AString & GetUUID(void) const { return m_UUID; } // tolua_export + void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; } + + /** Generates an UUID based on the username stored for this client, and stores it in the m_UUID member. + 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. + Internally calls the GenerateOfflineUUID static function. */ + void GenerateOfflineUUID(void); + + /** Generates an UUID based on the player name provided. + 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); + + AString FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2); + void Kick(const AString & a_Reason); // tolua_export - void Authenticate(void); // Called by cAuthenticator when the user passes authentication + void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication void StreamChunks(void); @@ -230,6 +251,9 @@ public: /** Called when the player moves into a different world; queues sreaming the new chunks */ void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket); + /** Called when the player will enchant a Item */ + void HandleEnchantItem(Byte & WindowID, Byte & Enchantment); + private: /** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */ @@ -326,6 +350,7 @@ private: static int s_ClientCount; int m_UniqueID; + AString m_UUID; /** Set to true when the chunk where the player is is sent to the client. Used for spawning the player */ bool m_HasSentPlayerChunk; @@ -359,7 +384,10 @@ private: void UnregisterPluginChannels(const AStringVector & a_ChannelList); /** Handles the "MC|AdvCdm" plugin message */ - void HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length); + void HandleCommandBlockMessage(const char * a_Data, size_t a_Length); + + /** Handles the "MC|ItemName" plugin message */ + void HandleAnvilItemName(const char * a_Data, size_t a_Length); // cSocketThreads::cCallback overrides: virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 30e7a8733..53a638ee5 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -661,14 +661,16 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti ASSERT(itrS->x + a_OffsetX < a_GridWidth); ASSERT(itrS->y + a_OffsetY < a_GridHeight); int GridID = (itrS->x + a_OffsetX) + a_GridStride * (itrS->y + a_OffsetY); + + const cItem & Item = itrS->m_Item; if ( (itrS->x >= a_GridWidth) || (itrS->y >= a_GridHeight) || - (itrS->m_Item.m_ItemType != a_CraftingGrid[GridID].m_ItemType) || // same item type? - (itrS->m_Item.m_ItemCount > a_CraftingGrid[GridID].m_ItemCount) || // not enough items + (Item.m_ItemType != a_CraftingGrid[GridID].m_ItemType) || // same item type? + (Item.m_ItemCount > a_CraftingGrid[GridID].m_ItemCount) || // not enough items ( - (itrS->m_Item.m_ItemDamage > 0) && // should compare damage values? - (itrS->m_Item.m_ItemDamage != a_CraftingGrid[GridID].m_ItemDamage) + (Item.m_ItemDamage > 0) && // should compare damage values? + (Item.m_ItemDamage != a_CraftingGrid[GridID].m_ItemDamage) ) ) { @@ -800,7 +802,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe break; } case E_ITEM_PAPER: break; - default: LOG("Unexpected item in firework rocket a_Recipe, was the crafting file fireworks section changed?"); break; + default: LOG("Unexpected item in firework rocket recipe, was the crafting file's fireworks section changed?"); break; } } } @@ -824,7 +826,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe case E_ITEM_DYE: { int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); - DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage)); + DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye((NIBBLETYPE)(a_CraftingGrid[GridID].m_ItemDamage & 0x0f))); break; } case E_ITEM_GUNPOWDER: break; @@ -835,7 +837,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe case E_ITEM_GOLD_NUGGET: a_Recipe->m_Result.m_FireworkItem.m_Type = 2; break; case E_ITEM_FEATHER: a_Recipe->m_Result.m_FireworkItem.m_Type = 4; break; case E_ITEM_HEAD: a_Recipe->m_Result.m_FireworkItem.m_Type = 3; break; - default: LOG("Unexpected item in firework star a_Recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins + default: LOG("Unexpected item in firework star recipe, was the crafting file's fireworks section changed?"); break; // ermahgerd BARD ardmins } } diff --git a/src/Crypto.cpp b/src/Crypto.cpp deleted file mode 100644 index 26500f263..000000000 --- a/src/Crypto.cpp +++ /dev/null @@ -1,509 +0,0 @@ - -// Crypto.cpp - -// Implements classes that wrap the cryptographic code library - -#include "Globals.h" -#include "Crypto.h" - -#include "polarssl/pk.h" - - - - - -/* -// Self-test the hash formatting for known values: -// sha1(Notch) : 4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48 -// sha1(jeb_) : -7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1 -// sha1(simon) : 88e16a1019277b15d58faf0541e11910eb756f6 - -class Test -{ -public: - Test(void) - { - AString DigestNotch, DigestJeb, DigestSimon; - Byte Digest[20]; - cSHA1Checksum Checksum; - Checksum.Update((const Byte *)"Notch", 5); - Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, DigestNotch); - Checksum.Restart(); - Checksum.Update((const Byte *)"jeb_", 4); - Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, DigestJeb); - Checksum.Restart(); - Checksum.Update((const Byte *)"simon", 5); - Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, DigestSimon); - printf("Notch: \"%s\"\n", DigestNotch.c_str()); - printf("jeb_: \"%s\"\n", DigestJeb.c_str()); - printf("simon: \"%s\"\n", DigestSimon.c_str()); - assert(DigestNotch == "4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48"); - assert(DigestJeb == "-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1"); - assert(DigestSimon == "88e16a1019277b15d58faf0541e11910eb756f6"); - } -} test; -*/ - - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cRSAPrivateKey: - -cRSAPrivateKey::cRSAPrivateKey(void) -{ - rsa_init(&m_Rsa, RSA_PKCS_V15, 0); - InitRnd(); -} - - - - - -cRSAPrivateKey::cRSAPrivateKey(const cRSAPrivateKey & a_Other) -{ - rsa_init(&m_Rsa, RSA_PKCS_V15, 0); - rsa_copy(&m_Rsa, &a_Other.m_Rsa); - InitRnd(); -} - - - - - -cRSAPrivateKey::~cRSAPrivateKey() -{ - entropy_free(&m_Entropy); - rsa_free(&m_Rsa); -} - - - - - -void cRSAPrivateKey::InitRnd(void) -{ - entropy_init(&m_Entropy); - const unsigned char pers[] = "rsa_genkey"; - ctr_drbg_init(&m_Ctr_drbg, entropy_func, &m_Entropy, pers, sizeof(pers) - 1); -} - - - - - -bool cRSAPrivateKey::Generate(unsigned a_KeySizeBits) -{ - if (rsa_gen_key(&m_Rsa, ctr_drbg_random, &m_Ctr_drbg, a_KeySizeBits, 65537) != 0) - { - // Key generation failed - return false; - } - - return true; -} - - - - - -AString cRSAPrivateKey::GetPubKeyDER(void) -{ - class cPubKey - { - public: - cPubKey(rsa_context * a_Rsa) : - m_IsValid(false) - { - pk_init(&m_Key); - if (pk_init_ctx(&m_Key, pk_info_from_type(POLARSSL_PK_RSA)) != 0) - { - ASSERT(!"Cannot init PrivKey context"); - return; - } - if (rsa_copy(pk_rsa(m_Key), a_Rsa) != 0) - { - ASSERT(!"Cannot copy PrivKey to PK context"); - return; - } - m_IsValid = true; - } - - ~cPubKey() - { - if (m_IsValid) - { - pk_free(&m_Key); - } - } - - operator pk_context * (void) { return &m_Key; } - - protected: - bool m_IsValid; - pk_context m_Key; - } PkCtx(&m_Rsa); - - unsigned char buf[3000]; - int res = pk_write_pubkey_der(PkCtx, buf, sizeof(buf)); - if (res < 0) - { - return AString(); - } - return AString((const char *)(buf + sizeof(buf) - res), (size_t)res); -} - - - - - -int cRSAPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) -{ - if (a_EncryptedLength < m_Rsa.len) - { - LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) - ); - ASSERT(!"Invalid a_DecryptedMaxLength!"); - return -1; - } - if (a_DecryptedMaxLength < m_Rsa.len) - { - LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) - ); - ASSERT(!"Invalid a_DecryptedMaxLength!"); - return -1; - } - size_t DecryptedLength; - int res = rsa_pkcs1_decrypt( - &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE, &DecryptedLength, - a_EncryptedData, a_DecryptedData, a_DecryptedMaxLength - ); - if (res != 0) - { - return -1; - } - return (int)DecryptedLength; -} - - - - - -int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) -{ - if (a_EncryptedMaxLength < m_Rsa.len) - { - LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len) - ); - ASSERT(!"Invalid a_DecryptedMaxLength!"); - return -1; - } - if (a_EncryptedMaxLength < m_Rsa.len) - { - LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) - ); - ASSERT(!"Invalid a_PlainLength!"); - return -1; - } - int res = rsa_pkcs1_encrypt( - &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE, - a_PlainLength, a_PlainData, a_EncryptedData - ); - if (res != 0) - { - return -1; - } - return (int)m_Rsa.len; -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPublicKey: - -cPublicKey::cPublicKey(const AString & a_PublicKeyDER) -{ - pk_init(&m_Pk); - if (pk_parse_public_key(&m_Pk, (const Byte *)a_PublicKeyDER.data(), a_PublicKeyDER.size()) != 0) - { - ASSERT(!"Cannot parse PubKey"); - return; - } - InitRnd(); -} - - - - - -cPublicKey::~cPublicKey() -{ - pk_free(&m_Pk); -} - - - - - -int cPublicKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) -{ - size_t DecryptedLen = a_DecryptedMaxLength; - int res = pk_decrypt(&m_Pk, - a_EncryptedData, a_EncryptedLength, - a_DecryptedData, &DecryptedLen, a_DecryptedMaxLength, - ctr_drbg_random, &m_Ctr_drbg - ); - if (res != 0) - { - return res; - } - return (int)DecryptedLen; -} - - - - - -int cPublicKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) -{ - size_t EncryptedLength = a_EncryptedMaxLength; - int res = pk_encrypt(&m_Pk, - a_PlainData, a_PlainLength, a_EncryptedData, &EncryptedLength, a_EncryptedMaxLength, - ctr_drbg_random, &m_Ctr_drbg - ); - if (res != 0) - { - return res; - } - return (int)EncryptedLength; -} - - - - - -void cPublicKey::InitRnd(void) -{ - entropy_init(&m_Entropy); - const unsigned char pers[] = "rsa_genkey"; - ctr_drbg_init(&m_Ctr_drbg, entropy_func, &m_Entropy, pers, sizeof(pers) - 1); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cAESCFBDecryptor: - -cAESCFBDecryptor::cAESCFBDecryptor(void) : - m_IVOffset(0), - m_IsValid(false) -{ -} - - - - - -cAESCFBDecryptor::~cAESCFBDecryptor() -{ - // Clear the leftover in-memory data, so that they can't be accessed by a backdoor - memset(&m_Aes, 0, sizeof(m_Aes)); -} - - - - - -void cAESCFBDecryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) -{ - ASSERT(!IsValid()); // Cannot Init twice - - memcpy(m_IV, a_IV, 16); - aes_setkey_enc(&m_Aes, a_Key, 128); - m_IsValid = true; -} - - - - - -void cAESCFBDecryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length) -{ - ASSERT(IsValid()); // Must Init() first - - // PolarSSL doesn't support AES-CFB8, need to implement it manually: - for (size_t i = 0; i < a_Length; i++) - { - Byte Buffer[sizeof(m_IV)]; - aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); - for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) - { - m_IV[idx] = m_IV[idx + 1]; - } - m_IV[sizeof(m_IV) - 1] = a_EncryptedIn[i]; - a_DecryptedOut[i] = a_EncryptedIn[i] ^ Buffer[0]; - } -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cAESCFBEncryptor: - -cAESCFBEncryptor::cAESCFBEncryptor(void) : - m_IVOffset(0), - m_IsValid(false) -{ -} - - - - - -cAESCFBEncryptor::~cAESCFBEncryptor() -{ - // Clear the leftover in-memory data, so that they can't be accessed by a backdoor - memset(&m_Aes, 0, sizeof(m_Aes)); -} - - - - - -void cAESCFBEncryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) -{ - ASSERT(!IsValid()); // Cannot Init twice - ASSERT(m_IVOffset == 0); - - memcpy(m_IV, a_IV, 16); - aes_setkey_enc(&m_Aes, a_Key, 128); - m_IsValid = true; -} - - - - - -void cAESCFBEncryptor::ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length) -{ - ASSERT(IsValid()); // Must Init() first - - // PolarSSL doesn't do AES-CFB8, so we need to implement it ourselves: - for (size_t i = 0; i < a_Length; i++) - { - Byte Buffer[sizeof(m_IV)]; - aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); - for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) - { - m_IV[idx] = m_IV[idx + 1]; - } - a_EncryptedOut[i] = a_PlainIn[i] ^ Buffer[0]; - m_IV[sizeof(m_IV) - 1] = a_EncryptedOut[i]; - } -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cSHA1Checksum: - -cSHA1Checksum::cSHA1Checksum(void) : - m_DoesAcceptInput(true) -{ - sha1_starts(&m_Sha1); -} - - - - - -void cSHA1Checksum::Update(const Byte * a_Data, size_t a_Length) -{ - ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed - - sha1_update(&m_Sha1, a_Data, a_Length); -} - - - - - -void cSHA1Checksum::Finalize(cSHA1Checksum::Checksum & a_Output) -{ - ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed - - sha1_finish(&m_Sha1, a_Output); - m_DoesAcceptInput = false; -} - - - - - -void cSHA1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out) -{ - Checksum Digest; - memcpy(Digest, a_Digest, sizeof(Digest)); - - bool IsNegative = (Digest[0] >= 0x80); - if (IsNegative) - { - // Two's complement: - bool carry = true; // Add one to the whole number - for (int i = 19; i >= 0; i--) - { - Digest[i] = ~Digest[i]; - if (carry) - { - carry = (Digest[i] == 0xff); - Digest[i]++; - } - } - } - a_Out.clear(); - a_Out.reserve(40); - for (int i = 0; i < 20; i++) - { - AppendPrintf(a_Out, "%02x", Digest[i]); - } - while ((a_Out.length() > 0) && (a_Out[0] == '0')) - { - a_Out.erase(0, 1); - } - if (IsNegative) - { - a_Out.insert(0, "-"); - } -} - - - - - - -void cSHA1Checksum::Restart(void) -{ - sha1_starts(&m_Sha1); - m_DoesAcceptInput = true; -} - - - - diff --git a/src/Crypto.h b/src/Crypto.h deleted file mode 100644 index a9ec2c6d4..000000000 --- a/src/Crypto.h +++ /dev/null @@ -1,198 +0,0 @@ - -// Crypto.h - -// Declares classes that wrap the cryptographic code library - - - - - -#pragma once - -#include "polarssl/rsa.h" -#include "polarssl/aes.h" -#include "polarssl/entropy.h" -#include "polarssl/ctr_drbg.h" -#include "polarssl/sha1.h" -#include "polarssl/pk.h" - - - - - -/** Encapsulates an RSA private key used in PKI cryptography */ -class cRSAPrivateKey -{ -public: - /** Creates a new empty object, the key is not assigned */ - cRSAPrivateKey(void); - - /** Deep-copies the key from a_Other */ - cRSAPrivateKey(const cRSAPrivateKey & a_Other); - - ~cRSAPrivateKey(); - - /** Generates a new key within this object, with the specified size in bits. - Returns true on success, false on failure. */ - bool Generate(unsigned a_KeySizeBits = 1024); - - /** Returns the public key part encoded in ASN1 DER encoding */ - AString GetPubKeyDER(void); - - /** Decrypts the data using RSAES-PKCS#1 algorithm. - Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. - Returns the number of bytes decrypted, or negative number for error. */ - int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); - - /** Encrypts the data using RSAES-PKCS#1 algorithm. - Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. - Returns the number of bytes decrypted, or negative number for error. */ - int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); - -protected: - rsa_context m_Rsa; - entropy_context m_Entropy; - ctr_drbg_context m_Ctr_drbg; - - /** Initializes the m_Entropy and m_Ctr_drbg contexts - Common part of this object's construction, called from all constructors. */ - void InitRnd(void); -} ; - - - - - -class cPublicKey -{ -public: - cPublicKey(const AString & a_PublicKeyDER); - ~cPublicKey(); - - /** Decrypts the data using the stored public key - Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. - Returns the number of bytes decrypted, or negative number for error. */ - int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); - - /** Encrypts the data using the stored public key - Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. - Returns the number of bytes decrypted, or negative number for error. */ - int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); - -protected: - pk_context m_Pk; - entropy_context m_Entropy; - ctr_drbg_context m_Ctr_drbg; - - /** Initializes the m_Entropy and m_Ctr_drbg contexts - Common part of this object's construction, called from all constructors. */ - void InitRnd(void); -} ; - - - - - -/** Decrypts data using the AES / CFB (128) algorithm */ -class cAESCFBDecryptor -{ -public: - Byte test; - - cAESCFBDecryptor(void); - ~cAESCFBDecryptor(); - - /** Initializes the decryptor with the specified Key / IV */ - void Init(const Byte a_Key[16], const Byte a_IV[16]); - - /** Decrypts a_Length bytes of the encrypted data; produces a_Length output bytes */ - void ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length); - - /** Returns true if the object has been initialized with the Key / IV */ - bool IsValid(void) const { return m_IsValid; } - -protected: - aes_context m_Aes; - - /** The InitialVector, used by the CFB mode decryption */ - Byte m_IV[16]; - - /** Current offset in the m_IV, used by the CFB mode decryption */ - size_t m_IVOffset; - - /** Indicates whether the object has been initialized with the Key / IV */ - bool m_IsValid; -} ; - - - - - -/** Encrypts data using the AES / CFB (128) algorithm */ -class cAESCFBEncryptor -{ -public: - cAESCFBEncryptor(void); - ~cAESCFBEncryptor(); - - /** Initializes the decryptor with the specified Key / IV */ - void Init(const Byte a_Key[16], const Byte a_IV[16]); - - /** Encrypts a_Length bytes of the plain data; produces a_Length output bytes */ - void ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length); - - /** Returns true if the object has been initialized with the Key / IV */ - bool IsValid(void) const { return m_IsValid; } - -protected: - aes_context m_Aes; - - /** The InitialVector, used by the CFB mode encryption */ - Byte m_IV[16]; - - /** Current offset in the m_IV, used by the CFB mode encryption */ - size_t m_IVOffset; - - /** Indicates whether the object has been initialized with the Key / IV */ - bool m_IsValid; -} ; - - - - - -/** Calculates a SHA1 checksum for data stream */ -class cSHA1Checksum -{ -public: - typedef Byte Checksum[20]; // The type used for storing the checksum - - cSHA1Checksum(void); - - /** Adds the specified data to the checksum */ - void Update(const Byte * a_Data, size_t a_Length); - - /** Calculates and returns the final checksum */ - void Finalize(Checksum & a_Output); - - /** Returns true if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ - bool DoesAcceptInput(void) const { return m_DoesAcceptInput; } - - /** Converts a raw 160-bit SHA1 digest into a Java Hex representation - According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802 - */ - static void DigestToJava(const Checksum & a_Digest, AString & a_JavaOut); - - /** Clears the current context and start a new checksum calculation */ - void Restart(void); - -protected: - /** True if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ - bool m_DoesAcceptInput; - - sha1_context m_Sha1; -} ; - - - - diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp index 322084dc4..f73a45555 100644 --- a/src/DeadlockDetect.cpp +++ b/src/DeadlockDetect.cpp @@ -109,21 +109,24 @@ void cDeadlockDetect::CheckWorldAge(const AString & a_WorldName, Int64 a_Age) WorldAges::iterator itr = m_WorldAges.find(a_WorldName); if (itr == m_WorldAges.end()) { - ASSERT(!"Unknown world in cDeadlockDetect"); + SetWorldAge(a_WorldName, a_Age); return; } - if (itr->second.m_Age == a_Age) + + cDeadlockDetect::sWorldAge & WorldAge = itr->second; + + if (WorldAge.m_Age == a_Age) { - itr->second.m_NumCyclesSame += 1; - if (itr->second.m_NumCyclesSame > (1000 * m_IntervalSec) / CYCLE_MILLISECONDS) + WorldAge.m_NumCyclesSame += 1; + if (WorldAge.m_NumCyclesSame > (1000 * m_IntervalSec) / CYCLE_MILLISECONDS) { DeadlockDetected(); } } else { - itr->second.m_Age = a_Age; - itr->second.m_NumCyclesSame = 0; + WorldAge.m_Age = a_Age; + WorldAge.m_NumCyclesSame = 0; } } diff --git a/src/Defines.h b/src/Defines.h index 1a8b3fa4a..9fa3b3a8e 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -493,15 +493,17 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) { - if (fabs(a_X) < std::numeric_limits<double>::epsilon()) + double r = sqrt((a_X * a_X) + (a_Z * a_Z)); + if (r < std::numeric_limits<double>::epsilon()) { - a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; + a_Pan = 0; } else { - a_Pan = 0; + a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; } - a_Pitch = atan2(a_Y, sqrt((a_X * a_X) + (a_Z * a_Z))) * 180 / PI; + + a_Pitch = atan2(a_Y, r) * 180 / PI; } diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 1d8188e96..264878c22 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "Enchantments.h" #include "WorldStorage/FastNBT.h" +#include "FastRandom.h" @@ -28,6 +29,18 @@ cEnchantments::cEnchantments(const AString & a_StringSpec) +void cEnchantments::Add(const cEnchantments & a_Other) +{ + for (cEnchantments::cMap::const_iterator itr = a_Other.m_Enchantments.begin(), end = a_Other.m_Enchantments.end(); itr != end; ++itr) + { + SetLevel(itr->first, itr->second); + } // for itr - a_Other.m_Enchantments[] +} + + + + + void cEnchantments::AddFromString(const AString & a_StringSpec) { // Add enchantments in the stringspec; if a specified enchantment already exists, overwrites it @@ -49,21 +62,17 @@ void cEnchantments::AddFromString(const AString & a_StringSpec) LOG("%s: Malformed enchantment decl: \"%s\", skipping.", __FUNCTION__, itr->c_str()); continue; } - int id = atoi(Split[0].c_str()); - if ((id == 0) && (Split[0] != "0")) + int id = StringToEnchantmentID(Split[0]); + if (id < 0) { - id = StringToEnchantmentID(Split[0]); + LOG("%s: Failed to parse enchantment \"%s\", skipping.", __FUNCTION__, Split[0].c_str()); + continue; } int lvl = atoi(Split[1].c_str()); - if ( - ((id <= 0) && (Split[0] != "0")) || - ((lvl == 0) && (Split[1] != "0")) - ) - { - // Numbers failed to parse - LOG("%s: Failed to parse enchantment declaration for numbers: \"%s\" and \"%s\", skipping.", - __FUNCTION__, Split[0].c_str(), Split[1].c_str() - ); + if ((lvl == 0) && (Split[1] != "0")) + { + // Level failed to parse + LOG("%s: Failed to parse enchantment level \"%s\", skipping.", __FUNCTION__, Split[1].c_str()); continue; } SetLevel(id, lvl); @@ -74,6 +83,15 @@ void cEnchantments::AddFromString(const AString & a_StringSpec) +size_t cEnchantments::Count(void) +{ + return m_Enchantments.size(); +} + + + + + AString cEnchantments::ToString(void) const { // Serialize all the enchantments into a string @@ -150,7 +168,7 @@ bool cEnchantments::IsEmpty(void) const int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName) { - struct + static const struct { int m_Value; const char * m_Name; @@ -181,6 +199,15 @@ int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName) { enchLuckOfTheSea, "LuckOfTheSea"}, { enchLure, "Lure"}, } ; + + // First try to parse as a number: + int id = atoi(a_EnchantmentName.c_str()); + if ((id != 0) || (a_EnchantmentName == "0")) + { + return id; + } + + // It wasn't a number, do a lookup: for (size_t i = 0; i < ARRAYCOUNT(EnchantmentNames); i++) { if (NoCaseCompare(EnchantmentNames[i].m_Name, a_EnchantmentName) == 0) @@ -213,7 +240,781 @@ bool cEnchantments::operator !=(const cEnchantments & a_Other) const +void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel) +{ + if (ItemCategory::IsSword(a_ItemType)) + { + // Sharpness + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); + } + + // Smite + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); + } + + // Bane of Arthropods + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); + } + + // Knockback + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); + } + + // Fire Aspect + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); + } + + // Looting + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); + } + } + + else if (ItemCategory::IsTool(a_ItemType)) + { + // Efficiency + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); + } + + // Silk Touch + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); + } + + // Fortune + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); + } + } + + else if (ItemCategory::IsArmor(a_ItemType)) + { + // Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); + } + // Fire Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); + } + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); + } + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); + } + + // Blast Protection + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); + } + + // Projectile Protection + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); + } + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); + } + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); + } + + // Thorns + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); + } + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); + } + + + if (ItemCategory::IsHelmet(a_ItemType)) + { + // Respiration + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); + } + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); + } + + // Aqua Affinity + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); + } + } + + else if (ItemCategory::IsBoots(a_ItemType)) + { + // Feather Fall + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); + } + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); + } + } + } + + else if (a_ItemType == E_ITEM_BOW) + { + // Power + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); + } + + // Punch + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); + } + + // Flame and Infinity + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 1); + } + } + + else if (a_ItemType == E_ITEM_FISHING_ROD) + { + // Luck of the Sea and Lure + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); + } + } + + else if (a_ItemType == E_ITEM_BOOK) + { + // All Enchantments + + // Sharpness + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); + } + + // Smite + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); + } + + // Bane of Arthropods + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); + } + + // Knockback + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); + } + + // Fire Aspect + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); + } + + // Looting + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); + } + + // Efficiency + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); + } + + // Silk Touch + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); + } + + // Fortune + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); + } + + // Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); + } + + // Fire Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); + } + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); + } + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); + } + + // Blast Protection + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); + } + + // Projectile Protection + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); + } + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); + } + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); + } + + // Thorns + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); + } + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); + } + + // Respiration + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); + } + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); + } + + // Aqua Affinity + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); + } + + // Feather Fall + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); + } + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); + } + + // Power + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); + } + + // Punch + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); + } + + // Flame and Infinity + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 1); + } + + // Luck of the Sea and Lure + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); + } + } + + // Unbreaking + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 63)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 1); + } +} + + + + + +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) +{ + cWeightedEnchantment weightedenchantment; + weightedenchantment.m_Weight = a_Weight; + cEnchantments enchantment; + enchantment.SetLevel(a_EnchantmentID, a_EnchantmentLevel); + weightedenchantment.m_Enchantments = enchantment; + a_Enchantments.push_back(weightedenchantment); +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + if ((*it).m_Enchantments.GetLevel(a_EnchantmentID) > 0) + { + a_Enchantments.erase(it); + break; + } + } +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + if ((*it).m_Enchantments == a_Enchantment) + { + a_Enchantments.erase(it); + break; + } + } +} + + + + + +void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment) +{ + if (a_FirstEnchantment.GetLevel(cEnchantments::enchProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFireProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBlastProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchProjectileProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + } + + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSharpness) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSmite) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBaneOfArthropods) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSilkTouch) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFortune); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFortune) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSilkTouch); + } +} + + + + + +cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments) +{ + cFastRandom Random; + + int AllWeights = 0; + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + AllWeights += (*it).m_Weight; + } + int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1); + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + RandomNumber -= (*it).m_Weight; + if (RandomNumber < 0) + { + return (*it).m_Enchantments; + } + } + + return cEnchantments(); +} diff --git a/src/Enchantments.h b/src/Enchantments.h index f77b535d8..85a316414 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -8,6 +8,7 @@ #pragma once +#include "Defines.h" #include "WorldStorage/EnchantmentSerializer.h" @@ -18,6 +19,11 @@ class cFastNBTWriter; class cParsedNBT; +// fwd: +struct cWeightedEnchantment; + +typedef std::vector<cWeightedEnchantment> cWeightedEnchantments; + @@ -28,11 +34,14 @@ mapping each enchantment's id onto its level. ID may be either a number or the e Level value of 0 means no such enchantment, and it will not be stored in the m_Enchantments. Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs. */ + + // tolua_begin class cEnchantments { public: - /// Individual enchantment IDs, corresponding to their NBT IDs ( http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs ) + /** Individual enchantment IDs, corresponding to their NBT IDs ( http://www.minecraftwiki.net/wiki/Data_Values#Enchantment_IDs ) + */ enum { @@ -61,56 +70,90 @@ public: enchLuckOfTheSea = 61, enchLure = 62, } ; - - /// Creates an empty enchantments container + + /** Creates an empty enchantments container */ cEnchantments(void); - /// Creates an enchantments container filled with enchantments parsed from stringspec + /** Creates an enchantments container filled with enchantments parsed from stringspec */ cEnchantments(const AString & a_StringSpec); - /// Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it + /** Adds the enchantments contained in a_Other into this object. + Existing enchantments are preserved, unless a_Other specifies a different level, in which case the level is changed. */ + void Add(const cEnchantments & a_Other); + + /** Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it */ void AddFromString(const AString & a_StringSpec); - /// Serializes all the enchantments into a string + /** Get the count of enchantments */ + size_t Count(void); + + /** Serializes all the enchantments into a string */ AString ToString(void) const; - /// Returns the level for the specified enchantment; 0 if not stored + /** Returns the level for the specified enchantment; 0 if not stored */ int GetLevel(int a_EnchantmentID) const; - /// Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0 + /** Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0 */ void SetLevel(int a_EnchantmentID, int a_Level); - /// Removes all enchantments + /** Removes all enchantments */ void Clear(void); - /// Returns true if there are no enchantments + /** Returns true if there are no enchantments */ bool IsEmpty(void) const; - /// Converts enchantment name to the numeric representation; returns -1 if enchantment name not found; case insensitive + /** Converts enchantment name or ID (number in string) to the numeric representation; returns -1 if enchantment name not found; case insensitive */ static int StringToEnchantmentID(const AString & a_EnchantmentName); - /// Returns true if a_Other contains exactly the same enchantments and levels + /** Returns true if a_Other contains exactly the same enchantments and levels */ bool operator ==(const cEnchantments & a_Other) const; - + // tolua_end + + /** Add enchantment weights from item to the vector */ + static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel); + + /** Add a enchantment with weight to the vector */ + static void AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel); + + /** Remove the entire enchantment (with weight) from the vector */ + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID); - /// Returns true if a_Other doesn't contain exactly the same enchantments and levels + /** Remove the entire enchantment (with weight) from the vector */ + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment); + + /** Check enchantment conflicts from enchantments from the vector */ + static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment); + + /** Gets random enchantment from Vector and returns it */ + static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments); + + /** Returns true if a_Other doesn't contain exactly the same enchantments and levels */ bool operator !=(const cEnchantments & a_Other) const; - /// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments") + /** Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments") */ friend void EnchantmentSerializer::WriteToNBTCompound(cEnchantments const& a_Enchantments, cFastNBTWriter & a_Writer, const AString & a_ListTagName); - /// Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) + /** Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) */ friend void EnchantmentSerializer::ParseFromNBT(cEnchantments& a_Enchantments, const cParsedNBT & a_NBT, int a_EnchListTagIdx); - + protected: - /// Maps enchantment ID -> enchantment level + /** Maps enchantment ID -> enchantment level */ typedef std::map<int, int> cMap; - /// Currently stored enchantments + /** Currently stored enchantments */ cMap m_Enchantments; } ; // tolua_export +// Define the cWeightedEnchantment struct for the Enchanting System to store the EnchantmentWeights: +struct cWeightedEnchantment +{ + int m_Weight; + cEnchantments m_Enchantments; +}; + + + 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/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/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/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8ef45f1a5..4cf10a219 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Entity.h" @@ -10,7 +11,6 @@ #include "../Simulator/FluidSimulator.h" #include "../Bindings/PluginManager.h" #include "../Tracer.h" -#include "Minecart.h" #include "Player.h" @@ -32,19 +32,14 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Attachee(NULL) , m_bDirtyHead(true) , m_bDirtyOrientation(true) - , m_bDirtyPosition(true) - , m_bDirtySpeed(true) - , m_bOnGround( false ) - , m_Gravity( -9.81f ) - , m_LastPosX( 0.0 ) - , m_LastPosY( 0.0 ) - , m_LastPosZ( 0.0 ) - , m_TimeLastTeleportPacket(0) - , m_TimeLastMoveReltPacket(0) - , m_TimeLastSpeedPacket(0) + , m_bHasSentNoSpeed(true) + , m_bOnGround(false) + , m_Gravity(-9.81f) + , m_LastPos(a_X, a_Y, a_Z) , m_IsInitialized(false) , m_EntityType(a_EntityType) , m_World(NULL) + , m_IsFireproof(false) , m_TicksSinceLastBurnDamage(0) , m_TicksSinceLastLavaDamage(0) , m_TicksSinceLastFireDamage(0) @@ -52,13 +47,16 @@ 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_HeadYaw( 0.0 ) + , 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) , m_WaterSpeed(0, 0, 0) , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) + , m_InvulnerableTicks(0) { cCSLock Lock(m_CSCount); m_EntityCount++; @@ -293,17 +291,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())) @@ -325,17 +329,49 @@ 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, .3, 5); + break; + } + case 2: + { + additionalSpeed.Set(8, .3, 8); + break; + } + default: + { + additionalSpeed.Set(2, .3, 2); + break; + } + } + AddSpeed(a_TDI.Knockback * additionalSpeed); } - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); + m_World->BroadcastEntityStatus(*this, esGenericHurt); + + m_InvulnerableTicks = 10; if (m_Health <= 0) { KilledBy(a_TDI.Attacker); } + return true; } @@ -380,11 +416,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) { @@ -399,9 +432,34 @@ 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!"); + return false; +} + + + + + +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 @@ -479,7 +537,7 @@ void cEntity::KilledBy(cEntity * a_Killer) GetDrops(Drops, a_Killer); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_DEAD); + m_World->BroadcastEntityStatus(*this, esGenericDead); } @@ -510,6 +568,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) @@ -519,37 +582,36 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) } else { - if (a_Chunk.IsValid()) + if (!a_Chunk.IsValid()) { - cChunk * NextChunk = a_Chunk.GetNeighborChunk(POSX_TOINT, POSZ_TOINT); + return; + } - if ((NextChunk == NULL) || !NextChunk->IsValid()) - { - return; - } + // Position changed -> super::Tick() called + GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, POSX_TOINT, POSZ_TOINT) - TickBurning(*NextChunk); + TickBurning(*NextChunk); - if (GetPosY() < VOID_BOUNDARY) - { - TickInVoid(*NextChunk); - } - else - { - m_TicksSinceLastVoidDamage = 0; - } - - if (IsMob() || IsPlayer()) - { - // Set swimming state - SetSwimState(*NextChunk); + if (GetPosY() < VOID_BOUNDARY) + { + TickInVoid(*NextChunk); + } + else + { + m_TicksSinceLastVoidDamage = 0; + } - // Handle drowning - HandleAir(); - } + if (IsMob() || IsPlayer()) + { + // Set swimming state + SetSwimState(*NextChunk); - HandlePhysics(a_Dt, *NextChunk); + // Handle drowning + HandleAir(); } + + // None of the above functions change position, we remain in the chunk of NextChunk + HandlePhysics(a_Dt, *NextChunk); } } @@ -559,34 +621,30 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { + int BlockX = POSX_TOINT; + int BlockY = POSY_TOINT; + int BlockZ = POSZ_TOINT; + + // Position changed -> super::HandlePhysics() called + GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ) + // TODO Add collision detection with entities. a_Dt /= 1000; // Convert from msec to sec - Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); - Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); - int BlockX = (int) floor(NextPos.x); - int BlockY = (int) floor(NextPos.y); - int BlockZ = (int) floor(NextPos.z); + Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); + Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { - // Outside of the world - - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - // See if we can commit our changes. If not, we will discard them. - if (NextChunk != NULL) - { - SetSpeed(NextSpeed); - NextPos += (NextSpeed * a_Dt); - SetPosition(NextPos); - } - + // Outside of the world + AddSpeedY(m_Gravity * a_Dt); + AddPosition(GetSpeed() * a_Dt); return; } - int RelBlockX = BlockX - (a_Chunk.GetPosX() * cChunkDef::Width); - int RelBlockZ = BlockZ - (a_Chunk.GetPosZ() * cChunkDef::Width); - BLOCKTYPE BlockIn = a_Chunk.GetBlock( RelBlockX, BlockY, RelBlockZ ); - BLOCKTYPE BlockBelow = (BlockY > 0) ? a_Chunk.GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); + int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); + BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); + BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground @@ -616,7 +674,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) bool IsNoAirSurrounding = true; for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - if (!a_Chunk.UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) + if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) { // The pickup is too close to an unloaded chunk, bail out of any physics handling return; @@ -730,30 +788,43 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextSpeed += m_WaterSpeed; - if( NextSpeed.SqrLength() > 0.f ) + if (NextSpeed.SqrLength() > 0.f) { - cTracer Tracer( GetWorld() ); - bool HasHit = Tracer.Trace( NextPos, NextSpeed, 2 ); - if (HasHit) // Oh noez! we hit something + cTracer Tracer(GetWorld()); + // Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse + int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2); + bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace); + + if (HasHit) { - // Set to hit position + // Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current) + // This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) { + // Block hit was within our projected path + // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. + // For example: HitNormal.y = -1 : BLOCK_FACE_YM; HitNormal.y = 1 : BLOCK_FACE_YP if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f; if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; - if (Tracer.HitNormal.y > 0) // means on ground + if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground { m_bOnGround = true; } - NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); - NextPos.x += Tracer.HitNormal.x * 0.3f; - NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot - NextPos.z += Tracer.HitNormal.z * 0.3f; + + // Now, set our position to the hit block (i.e. move part way along our intended trajectory) + NextPos.Set(Tracer.RealHit.x, Tracer.RealHit.y, Tracer.RealHit.z); + NextPos.x += Tracer.HitNormal.x * 0.1; + NextPos.y += Tracer.HitNormal.y * 0.05; + NextPos.z += Tracer.HitNormal.z * 0.1; } else { + // We have hit a block but overshot our intended trajectory, move normally, safe in the warm cocoon of knowledge that we won't appear to teleport forwards on clients, + // and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never + // be henceforth seen again in the time of programmers and man alike + // </&sensationalist> NextPos += (NextSpeed * a_Dt); } } @@ -764,20 +835,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } } - BlockX = (int) floor(NextPos.x); - BlockZ = (int) floor(NextPos.z); - - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - // See if we can commit our changes. If not, we will discard them. - if (NextChunk != NULL) - { - if (NextPos.x != GetPosX()) SetPosX(NextPos.x); - if (NextPos.y != GetPosY()) SetPosY(NextPos.y); - if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); - if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); - if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); - if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); - } + SetPosition(NextPos); + SetSpeed(NextSpeed); } @@ -788,6 +847,14 @@ void cEntity::TickBurning(cChunk & a_Chunk) { // Remember the current burning state: bool HasBeenBurning = (m_TicksLeftBurning > 0); + + if (m_World->IsWeatherWet()) + { + if (POSY_TOINT > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) + { + m_TicksLeftBurning = 0; + } + } // Do the burning damage: if (m_TicksLeftBurning > 0) @@ -795,7 +862,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastBurnDamage++; if (m_TicksSinceLastBurnDamage >= BURN_TICKS_PER_DAMAGE) { - TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + if (!m_IsFireproof) + { + TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + } m_TicksSinceLastBurnDamage = 0; } m_TicksLeftBurning--; @@ -806,7 +876,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) int MaxRelX = (int)floor(GetPosX() + m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width; int MinRelZ = (int)floor(GetPosZ() - m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; int MaxRelZ = (int)floor(GetPosZ() + m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; - int MinY = std::max(0, std::min(cChunkDef::Height - 1, (int)floor(GetPosY()))); + int MinY = std::max(0, std::min(cChunkDef::Height - 1, POSY_TOINT)); int MaxY = std::max(0, std::min(cChunkDef::Height - 1, (int)ceil (GetPosY() + m_Height))); bool HasWater = false; bool HasLava = false; @@ -863,7 +933,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastLavaDamage++; if (m_TicksSinceLastLavaDamage >= LAVA_TICKS_PER_DAMAGE) { - TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + if (!m_IsFireproof) + { + TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + } m_TicksSinceLastLavaDamage = 0; } } @@ -881,7 +954,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastFireDamage++; if (m_TicksSinceLastFireDamage >= FIRE_TICKS_PER_DAMAGE) { - TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + if (!m_IsFireproof) + { + TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + } m_TicksSinceLastFireDamage = 0; } } @@ -941,9 +1017,9 @@ void cEntity::SetSwimState(cChunk & a_Chunk) { // This sometimes happens on Linux machines // Ref.: http://forum.mc-server.org/showthread.php?tid=1244 - LOGD("SetSwimState failure: RelX = %d, RelZ = %d, LastPos = {%.02f, %.02f}, Pos = %.02f, %.02f}", - RelX, RelY, m_LastPosX, m_LastPosZ, GetPosX(), GetPosZ() - ); + LOGD("SetSwimState failure: RelX = %d, RelZ = %d, Pos = %.02f, %.02f}", + RelX, RelY, GetPosX(), GetPosZ() + ); m_IsSwimming = false; m_IsSubmerged = false; return; @@ -981,13 +1057,13 @@ void cEntity::HandleAir(void) } else { - m_AirTickTimer -= 1; + m_AirTickTimer--; } } else { // Reduce air supply - m_AirLevel -= 1; + m_AirLevel--; } } else @@ -1040,6 +1116,16 @@ void cEntity::SetMaxHealth(int a_MaxHealth) +/// Sets whether the entity is fireproof +void cEntity::SetIsFireproof(bool a_IsFireproof) +{ + m_IsFireproof = a_IsFireproof; +} + + + + + /// Puts the entity on fire for the specified amount of ticks void cEntity::StartBurning(int a_TicksLeftBurning) { @@ -1099,72 +1185,70 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) { - //We need to keep updating the clients when there is movement or if there was a change in speed and after 2 ticks - if( (m_Speed.SqrLength() > 0.0004f || m_bDirtySpeed) && (m_World->GetWorldAge() - m_TimeLastSpeedPacket >= 2)) + // Process packet sending every two ticks + if (GetWorld()->GetWorldAge() % 2 == 0) { - m_World->BroadcastEntityVelocity(*this,a_Exclude); - m_bDirtySpeed = false; - m_TimeLastSpeedPacket = m_World->GetWorldAge(); - } - - //Have to process position related packets this every two ticks - if (m_World->GetWorldAge() % 2 == 0) - { - int DiffX = (int) (floor(GetPosX() * 32.0) - floor(m_LastPosX * 32.0)); - int DiffY = (int) (floor(GetPosY() * 32.0) - floor(m_LastPosY * 32.0)); - int DiffZ = (int) (floor(GetPosZ() * 32.0) - floor(m_LastPosZ * 32.0)); - Int64 DiffTeleportPacket = m_World->GetWorldAge() - m_TimeLastTeleportPacket; - // 4 blocks is max Relative So if the Diff is greater than 127 or. Send an absolute position every 20 seconds - if (DiffTeleportPacket >= 400 || - ((DiffX > 127) || (DiffX < -128) || - (DiffY > 127) || (DiffY < -128) || - (DiffZ > 127) || (DiffZ < -128))) + double SpeedSqr = GetSpeed().SqrLength(); + if (SpeedSqr == 0.0) { - // - m_World->BroadcastTeleportEntity(*this,a_Exclude); - m_TimeLastTeleportPacket = m_World->GetWorldAge(); - m_TimeLastMoveReltPacket = m_TimeLastTeleportPacket; //Must synchronize. - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_bDirtyPosition = false; - m_bDirtyOrientation = false; + // Speed is zero, send this to clients once only as well as an absolute position + if (!m_bHasSentNoSpeed) + { + m_World->BroadcastEntityVelocity(*this, a_Exclude); + m_World->BroadcastTeleportEntity(*this, a_Exclude); + m_bHasSentNoSpeed = true; + } } else { - Int64 DiffMoveRelPacket = m_World->GetWorldAge() - m_TimeLastMoveReltPacket; - //if the change is big enough. - if ((abs(DiffX) >= 4 || abs(DiffY) >= 4 || abs(DiffZ) >= 4 || DiffMoveRelPacket >= 60) && m_bDirtyPosition) + // Movin' + m_World->BroadcastEntityVelocity(*this, a_Exclude); + m_bHasSentNoSpeed = false; + } + + // TODO: Pickups move disgracefully if relative move packets are sent as opposed to just velocity. Have a system to send relmove only when SetPosXXX() is called with a large difference in position + int DiffX = (int)(floor(GetPosX() * 32.0) - floor(m_LastPos.x * 32.0)); + int DiffY = (int)(floor(GetPosY() * 32.0) - floor(m_LastPos.y * 32.0)); + int DiffZ = (int)(floor(GetPosZ() * 32.0) - floor(m_LastPos.z * 32.0)); + + if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved? + { + if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte { + // Difference within Byte limitations, use a relative move packet if (m_bDirtyOrientation) { - m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude); + m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude); m_bDirtyOrientation = false; } else { - m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude); + m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude); } - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_bDirtyPosition = false; - m_TimeLastMoveReltPacket = m_World->GetWorldAge(); + // Clients seem to store two positions, one for the velocity packet and one for the teleport/relmove packet + // The latter is only changed with a relmove/teleport, and m_LastPos stores this position + m_LastPos = GetPosition(); } else { - if (m_bDirtyOrientation) - { - m_World->BroadcastEntityLook(*this,a_Exclude); - m_bDirtyOrientation = false; - } - } + // Too big a movement, do a teleport + m_World->BroadcastTeleportEntity(*this, a_Exclude); + m_LastPos = GetPosition(); // See above + m_bDirtyOrientation = false; + } } + if (m_bDirtyHead) { - m_World->BroadcastEntityHeadLook(*this,a_Exclude); + m_World->BroadcastEntityHeadLook(*this, a_Exclude); m_bDirtyHead = false; } + if (m_bDirtyOrientation) + { + // Send individual update in case above (sending with rel-move packet) wasn't done + GetWorld()->BroadcastEntityLook(*this, a_Exclude); + m_bDirtyOrientation = false; + } } } @@ -1304,7 +1388,7 @@ void cEntity::SetRoll(double a_Roll) void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1314,7 +1398,7 @@ void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) void cEntity::SetSpeedX(double a_SpeedX) { m_Speed.x = a_SpeedX; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1324,7 +1408,7 @@ void cEntity::SetSpeedX(double a_SpeedX) void cEntity::SetSpeedY(double a_SpeedY) { m_Speed.y = a_SpeedY; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1334,7 +1418,7 @@ void cEntity::SetSpeedY(double a_SpeedY) void cEntity::SetSpeedZ(double a_SpeedZ) { m_Speed.z = a_SpeedZ; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1354,7 +1438,7 @@ void cEntity::SetWidth(double a_Width) void cEntity::AddPosX(double a_AddPosX) { m_Pos.x += a_AddPosX; - m_bDirtyPosition = true; + } @@ -1363,7 +1447,7 @@ void cEntity::AddPosX(double a_AddPosX) void cEntity::AddPosY(double a_AddPosY) { m_Pos.y += a_AddPosY; - m_bDirtyPosition = true; + } @@ -1372,7 +1456,7 @@ void cEntity::AddPosY(double a_AddPosY) void cEntity::AddPosZ(double a_AddPosZ) { m_Pos.z += a_AddPosZ; - m_bDirtyPosition = true; + } @@ -1383,7 +1467,7 @@ void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) m_Pos.x += a_AddPosX; m_Pos.y += a_AddPosY; m_Pos.z += a_AddPosZ; - m_bDirtyPosition = true; + } @@ -1393,8 +1477,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed { m_Speed.x += a_AddSpeedX; m_Speed.y += a_AddSpeedY; - m_Speed.z += a_AddSpeedZ; - m_bDirtySpeed = true; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1404,8 +1487,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed void cEntity::AddSpeedX(double a_AddSpeedX) { - m_Speed.x += a_AddSpeedX; - m_bDirtySpeed = true; + m_Speed.x += a_AddSpeedX; WrapSpeed(); } @@ -1415,8 +1497,7 @@ void cEntity::AddSpeedX(double a_AddSpeedX) void cEntity::AddSpeedY(double a_AddSpeedY) { - m_Speed.y += a_AddSpeedY; - m_bDirtySpeed = true; + m_Speed.y += a_AddSpeedY; WrapSpeed(); } @@ -1426,8 +1507,7 @@ void cEntity::AddSpeedY(double a_AddSpeedY) void cEntity::AddSpeedZ(double a_AddSpeedZ) { - m_Speed.z += a_AddSpeedZ; - m_bDirtySpeed = true; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1482,8 +1562,7 @@ Vector3d cEntity::GetLookVector(void) const // Set position void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) { - m_Pos.Set(a_PosX, a_PosY, a_PosZ); - m_bDirtyPosition = true; + m_Pos.Set(a_PosX, a_PosY, a_PosZ); } @@ -1492,8 +1571,7 @@ void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) void cEntity::SetPosX(double a_PosX) { - m_Pos.x = a_PosX; - m_bDirtyPosition = true; + m_Pos.x = a_PosX; } @@ -1502,8 +1580,7 @@ void cEntity::SetPosX(double a_PosX) void cEntity::SetPosY(double a_PosY) { - m_Pos.y = a_PosY; - m_bDirtyPosition = true; + m_Pos.y = a_PosY; } @@ -1513,7 +1590,6 @@ void cEntity::SetPosY(double a_PosY) void cEntity::SetPosZ(double a_PosZ) { m_Pos.z = a_PosZ; - m_bDirtyPosition = true; } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 6e3f8292b..df03d635b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -32,6 +32,8 @@ #define POSZ_TOINT (int)floor(GetPosZ()) #define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT) +#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; } + @@ -88,23 +90,42 @@ public: } ; // tolua_end - - enum + + enum eEntityStatus { - ENTITY_STATUS_HURT = 2, - ENTITY_STATUS_DEAD = 3, - ENTITY_STATUS_WOLF_TAMING = 6, - ENTITY_STATUS_WOLF_TAMED = 7, - ENTITY_STATUS_WOLF_SHAKING = 8, - ENTITY_STATUS_EATING_ACCEPTED = 9, - ENTITY_STATUS_SHEEP_EATING = 10, - ENTITY_STATUS_GOLEM_ROSING = 11, - ENTITY_STATUS_VILLAGER_HEARTS = 12, - ENTITY_STATUS_VILLAGER_ANGRY = 13, - ENTITY_STATUS_VILLAGER_HAPPY = 14, - ENTITY_STATUS_WITCH_MAGICKING = 15, + // TODO: Investiagate 0, 1, and 5 as Wiki.vg is not certain + + // Entity becomes coloured red + esGenericHurt = 2, + // Entity plays death animation (entity falls to ground) + esGenericDead = 3, + // Iron Golem plays attack animation (arms lift and fall) + esIronGolemAttacking = 4, + // Wolf taming particles spawn (smoke) + esWolfTaming = 6, + // Wolf tamed particles spawn (hearts) + esWolfTamed = 7, + // Wolf plays water removal animation (shaking and water particles) + esWolfDryingWater = 8, + // Informs client that eating was accepted + esPlayerEatingAccepted = 9, + // Sheep plays eating animation (head lowers to ground) + esSheepEating = 10, + // Iron Golem holds gift to villager children + esIronGolemGivingPlant = 11, + // Villager spawns heart particles + esVillagerBreeding = 12, + // Villager spawns thunderclound particles + esVillagerAngry = 13, + // Villager spawns green crosses + esVillagerHappy = 14, + // Witch spawns magic particle (TODO: investigation into what this is) + esWitchMagicking = 15, + // It seems 16 (zombie conversion) is now done with metadata - ENTITY_STATUS_FIREWORK_EXPLODE= 17, + + // Informs client to explode a firework based on its metadata + esFireworkExploding = 17, } ; enum @@ -118,7 +139,8 @@ public: BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have DROWNING_TICKS = 20, ///< Number of ticks per heart of damage - VOID_BOUNDARY = -46 ///< At what position Y to begin applying void damage + VOID_BOUNDARY = -46, ///< At what position Y to begin applying void damage + FALL_DAMAGE_HEIGHT = 4 ///< At what position Y fall damage is applied } ; cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); @@ -240,14 +262,19 @@ 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 receive any damage. */ + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); // tolua_begin /// 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); @@ -307,6 +334,11 @@ public: int GetMaxHealth(void) const { return m_MaxHealth; } + /// Sets whether the entity is fireproof + void SetIsFireproof(bool a_IsFireproof); + + bool IsFireproof(void) const { return m_IsFireproof; } + /// Puts the entity on fire for the specified amount of ticks void StartBurning(int a_TicksLeftBurning); @@ -364,6 +396,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 @@ -392,27 +430,37 @@ protected: /// The entity which is attached to this entity (rider), NULL if none cEntity * m_Attachee; - // Flags that signal that we haven't updated the clients with the latest. - bool m_bDirtyHead; - bool m_bDirtyOrientation; - bool m_bDirtyPosition; - bool m_bDirtySpeed; - - bool m_bOnGround; - float m_Gravity; + /** Stores whether head yaw has been set manually */ + bool m_bDirtyHead; - // Last Position. - double m_LastPosX, m_LastPosY, m_LastPosZ; + /** Stores whether our yaw/pitch/roll (body orientation) has been set manually */ + bool m_bDirtyOrientation; + + /** Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client + Ensures that said packet is sent only once */ + bool m_bHasSentNoSpeed; - // This variables keep track of the last time a packet was sent - Int64 m_TimeLastTeleportPacket, m_TimeLastMoveReltPacket, m_TimeLastSpeedPacket; // In ticks + /** Stores if the entity is on the ground */ + bool m_bOnGround; + + /** Stores gravity that is applied to an entity every tick + For realistic effects, this should be negative. For spaaaaaaace, this can be zero or even positive */ + float m_Gravity; + + /** Last position sent to client via the Relative Move or Teleport packets (not Velocity) + Only updated if cEntity::BroadcastMovementUpdate() is called! */ + Vector3d m_LastPos; - bool m_IsInitialized; // Is set to true when it's initialized, until it's destroyed (Initialize() till Destroy() ) + /** True when entity is initialised (Initialize()) and false when destroyed pending deletion (Destroy()) */ + bool m_IsInitialized; eEntityType m_EntityType; cWorld * m_World; + /// Whether the entity is capable of taking fire or lava damage. + bool m_IsFireproof; + /// Time, in ticks, since the last damage dealt by being on fire. Valid only if on fire (IsOnFire()) int m_TicksSinceLastBurnDamage; @@ -428,12 +476,14 @@ protected: /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. int m_TicksSinceLastVoidDamage; + virtual void Destroyed(void) {} // Called after the entity has been destroyed void SetWorld(cWorld * a_World) { m_World = a_World; } /** Called in each tick to handle air-related processing i.e. drowning */ virtual void HandleAir(); + /** Called once per tick to set IsSwimming and IsSubmerged */ virtual void SetSwimState(cChunk & a_Chunk); @@ -445,29 +495,33 @@ 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 receive a invulnerable of 10 ticks. + While this ticks, a player can't hit this entity. */ + int m_InvulnerableTicks; } ; // tolua_export typedef std::list<cEntity *> cEntityList; 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/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 3623c869a..10f79aedc 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -34,8 +34,6 @@ cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) void cExpOrb::SpawnOn(cClientHandle & a_Client) { a_Client.SendExperienceOrb(*this); - m_bDirtyPosition = false; - m_bDirtySpeed = false; m_bDirtyOrientation = false; m_bDirtyHead = false; } diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index a66c7e4ae..beb58f207 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -87,7 +87,8 @@ 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 + if ((fabs(GetSpeedX()) > std::numeric_limits<double>::epsilon()) || (fabs(GetSpeedZ()) > std::numeric_limits<double>::epsilon())) { BroadcastMovementUpdate(); } 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/Minecart.cpp b/src/Entities/Minecart.cpp index 7f38aa35a..7bd440d6d 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -132,7 +132,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) return; } - int PosY = (int)floor(GetPosY()); + int PosY = POSY_TOINT; if ((PosY <= 0) || (PosY >= cChunkDef::Height)) { // Outside the world, just process normal falling physics @@ -141,8 +141,8 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) return; } - int RelPosX = (int)floor(GetPosX()) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = (int)floor(GetPosZ()) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelPosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelPosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); if (Chunk == NULL) { @@ -195,7 +195,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) super::HandlePhysics(a_Dt, *Chunk); } - if (m_bIsOnDetectorRail && !Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())).Equals(m_DetectorRailPosition)) + if (m_bIsOnDetectorRail && !Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT).Equals(m_DetectorRailPosition)) { m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); m_bIsOnDetectorRail = false; @@ -203,7 +203,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) else if (WasDetectorRail) { m_bIsOnDetectorRail = true; - m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + m_DetectorRailPosition = Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT); } // Broadcast positioning changes to client @@ -719,11 +719,11 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedZ() > 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -736,10 +736,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } else if (GetSpeedZ() < 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -756,10 +756,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedX() > 0) { - BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -772,10 +772,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } else if (GetSpeedX() < 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -793,10 +793,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) case E_META_RAIL_CURVED_ZP_XM: case E_META_RAIL_CURVED_ZP_XP: { - BLOCKTYPE BlockXM = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - BLOCKTYPE BlockXP = m_World->GetBlock((int)floor(GetPosX()) + 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); - BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); + BLOCKTYPE BlockXM = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); + BLOCKTYPE BlockXP = m_World->GetBlock(POSX_TOINT + 1, POSY_TOINT, POSZ_TOINT); + BLOCKTYPE BlockZM = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); + BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1); if ( (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || @@ -805,7 +805,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) ) { SetSpeed(0, 0, 0); - SetPosition((int)floor(GetPosX()) + 0.5, GetPosY(), (int)floor(GetPosZ()) + 0.5); + SetPosition(POSX_TOINT + 0.5, GetPosY(), POSZ_TOINT + 0.5); return true; } break; @@ -822,7 +822,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) { cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); int ChunkX, ChunkZ; - cChunkDef::BlockToChunk((int)floor(GetPosX()), (int)floor(GetPosZ()), ChunkX, ChunkZ); + cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ); m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback); if (!MinecartCollisionCallback.FoundIntersection()) @@ -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/Pickup.cpp b/src/Entities/Pickup.cpp index 7fc89b62b..497b41683 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -98,45 +98,44 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) if (!m_bCollected) { - int BlockY = (int) floor(GetPosY()); + int BlockY = POSY_TOINT; + int BlockX = POSX_TOINT; + int BlockZ = POSZ_TOINT; + if ((BlockY >= 0) && (BlockY < cChunkDef::Height)) // Don't do anything except for falling when outside the world { - int BlockX = (int) floor(GetPosX()); - int BlockZ = (int) floor(GetPosZ()); // Position might have changed due to physics. So we have to make sure we have the correct chunk. - cChunk * CurrentChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - if (CurrentChunk != NULL) // Make sure the chunk is loaded - { - int RelBlockX = BlockX - (CurrentChunk->GetPosX() * cChunkDef::Width); - int RelBlockZ = BlockZ - (CurrentChunk->GetPosZ() * cChunkDef::Width); + GET_AND_VERIFY_CURRENT_CHUNK(CurrentChunk, BlockX, BlockZ) + + int RelBlockX = BlockX - (CurrentChunk->GetPosX() * cChunkDef::Width); + int RelBlockZ = BlockZ - (CurrentChunk->GetPosZ() * cChunkDef::Width); - // If the pickup is on the bottommost block position, make it think the void is made of air: (#131) - BLOCKTYPE BlockBelow = (BlockY > 0) ? CurrentChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; - BLOCKTYPE BlockIn = CurrentChunk->GetBlock(RelBlockX, BlockY, RelBlockZ); - - if ( - IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE) || - IsBlockLava(BlockIn) || (BlockIn == E_BLOCK_FIRE) - ) + // If the pickup is on the bottommost block position, make it think the void is made of air: (#131) + BLOCKTYPE BlockBelow = (BlockY > 0) ? CurrentChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + BLOCKTYPE BlockIn = CurrentChunk->GetBlock(RelBlockX, BlockY, RelBlockZ); + + if ( + IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE) || + IsBlockLava(BlockIn) || (BlockIn == E_BLOCK_FIRE) + ) + { + m_bCollected = true; + m_Timer = 0; // We have to reset the timer. + m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. + if (m_Timer > 500.f) { - m_bCollected = true; - m_Timer = 0; // We have to reset the timer. - m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. - if (m_Timer > 500.f) - { - Destroy(true); - return; - } + Destroy(true); + return; } + } - if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + { + cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); + m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries + if (PickupCombiningCallback.FoundMatchingPickup()) { - cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); - m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries - if (PickupCombiningCallback.FoundMatchingPickup()) - { - m_World->BroadcastEntityMetadata(*this); - } + m_World->BroadcastEntityMetadata(*this); } } } @@ -156,7 +155,7 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) return; } - if (GetPosY() < -8) // Out of this world and no more visible! + if (GetPosY() < VOID_BOUNDARY) // Out of this world and no more visible! { Destroy(true); return; diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 74b917bce..2dcbecaaf 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -49,9 +49,6 @@ public: bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export private: - Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;) - - Vector3d m_WaterSpeed; /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ float m_Timer; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7f2e5b4c2..6ac11c270 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -76,18 +76,16 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); - - m_TimeLastTeleportPacket = 0; m_PlayerName = a_PlayerName; - m_bDirtyPosition = true; // So chunks are streamed to player at spawn if (!LoadFromDisk()) { m_Inventory.Clear(); - SetPosX(cRoot::Get()->GetDefaultWorld()->GetSpawnX()); - SetPosY(cRoot::Get()->GetDefaultWorld()->GetSpawnY()); - SetPosZ(cRoot::Get()->GetDefaultWorld()->GetSpawnZ()); + cWorld * DefaultWorld = cRoot::Get()->GetDefaultWorld(); + SetPosX(DefaultWorld->GetSpawnX()); + SetPosY(DefaultWorld->GetSpawnY()); + SetPosZ(DefaultWorld->GetSpawnZ()); LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}", a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ() @@ -208,25 +206,22 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) m_BowCharge += 1; } - //handle updating experience + // Handle updating experience if (m_bDirtyExperience) { SendExperience(); } - if (m_bDirtyPosition) + if (GetPosition() != m_LastPos) // Change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this); - BroadcastMovementUpdate(m_ClientHandle); m_ClientHandle->StreamChunks(); } - else - { - BroadcastMovementUpdate(m_ClientHandle); - } + + BroadcastMovementUpdate(m_ClientHandle); if (m_Health > 0) // make sure player is alive { @@ -437,7 +432,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) cWorld * World = GetWorld(); if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height)) { - BLOCKTYPE BlockType = World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE BlockType = World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT); if (BlockType != E_BLOCK_AIR) { m_bTouchGround = true; @@ -466,7 +461,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) TakeDamage(dtFalling, NULL, Damage, Damage, 0); // Fall particles - GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); + GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); } m_LastGroundHeight = (float)GetPosY(); @@ -590,7 +585,7 @@ void cPlayer::FinishEating(void) m_EatingFinishTick = -1; // Send the packets: - m_ClientHandle->SendEntityStatus(*this, ENTITY_STATUS_EATING_ACCEPTED); + m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); m_World->BroadcastEntityAnimation(*this, 0); m_World->BroadcastEntityMetadata(*this); @@ -807,14 +802,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; } } @@ -827,17 +822,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; } @@ -896,6 +893,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) void cPlayer::Respawn(void) { m_Health = GetMaxHealth(); + SetInvulnerableTicks(20); // Reset food level: m_FoodLevel = MAX_FOOD_LEVEL; @@ -1165,9 +1163,9 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ForceSetSpeed(Vector3d a_Direction) +void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) { - SetSpeed(a_Direction); + SetSpeed(a_Speed); m_ClientHandle->SendEntityVelocity(*this); } @@ -1519,22 +1517,16 @@ void cPlayer::LoadPermissionsFromDisk() cIniFile IniFile; if (IniFile.ReadFile("users.ini")) { - std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); - if (!Groups.empty()) + AString Groups = IniFile.GetValueSet(m_PlayerName, "Groups", "Default"); + AStringVector Split = StringSplitAndTrim(Groups, ","); + + for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr) { - AStringVector Split = StringSplitAndTrim(Groups, ","); - for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr) + if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr)) { - if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr)) - { - LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str()); - } - AddToGroup(*itr); + LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str()); } - } - else - { - AddToGroup("Default"); + AddToGroup(*itr); } AString Color = IniFile.GetValue(m_PlayerName, "Color", "-"); @@ -1546,8 +1538,10 @@ void cPlayer::LoadPermissionsFromDisk() else { cGroupManager::GenerateDefaultUsersIni(IniFile); + IniFile.AddValue("Groups", m_PlayerName, "Default"); AddToGroup("Default"); } + IniFile.WriteFile("users.ini"); ResolvePermissions(); } @@ -1596,10 +1590,7 @@ bool cPlayer::LoadFromDisk() SetPosX(JSON_PlayerPosition[(unsigned int)0].asDouble()); SetPosY(JSON_PlayerPosition[(unsigned int)1].asDouble()); SetPosZ(JSON_PlayerPosition[(unsigned int)2].asDouble()); - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_LastFoodPos = GetPosition(); + m_LastPos = GetPosition(); } Json::Value & JSON_PlayerRotation = root["rotation"]; @@ -1860,17 +1851,16 @@ void cPlayer::ApplyFoodExhaustionFromMovement() { return; } - - // Calculate the distance travelled, update the last pos: - Vector3d Movement(GetPosition() - m_LastFoodPos); - Movement.y = 0; // Only take XZ movement into account - m_LastFoodPos = GetPosition(); - + // If riding anything, apply no food exhaustion if (m_AttachedTo != NULL) { return; } + + // Calculate the distance travelled, update the last pos: + Vector3d Movement(GetPosition() - m_LastPos); + Movement.y = 0; // Only take XZ movement into account // Apply the exhaustion based on distance travelled: double BaseExhaustion = Movement.Length(); @@ -1899,9 +1889,9 @@ void cPlayer::ApplyFoodExhaustionFromMovement() void cPlayer::Detach() { super::Detach(); - int PosX = (int)floor(GetPosX()); - int PosY = (int)floor(GetPosY()); - int PosZ = (int)floor(GetPosZ()); + int PosX = POSX_TOINT; + int PosY = POSY_TOINT; + int PosZ = POSZ_TOINT; // Search for a position within an area to teleport player after detachment // Position must be solid land, and occupied by a nonsolid block diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 05377a117..6fc7e2875 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -181,7 +181,7 @@ public: void LoginSetGameMode(eGameMode a_GameMode); /** Forces the player to move in the given direction. */ - void ForceSetSpeed(Vector3d a_Direction); // tolua_export + void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export @@ -423,9 +423,6 @@ protected: /** Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned */ int m_FoodPoisonedTicksRemaining; - /** Last position that has been recorded for food-related processing: */ - Vector3d m_LastFoodPos; - float m_LastJumpHeight; float m_LastGroundHeight; bool m_bTouchGround; @@ -498,7 +495,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/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index e86bb48bd..3e48d310c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -4,15 +4,24 @@ // 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 "ArrowEntity.h" +#include "ThrownEggEntity.h" +#include "ThrownEnderPearlEntity.h" +#include "ExpBottleEntity.h" +#include "ThrownSnowballEntity.h" +#include "FireChargeEntity.h" +#include "FireworkEntity.h" +#include "GhastFireballEntity.h" + @@ -401,495 +410,3 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) // Overriden in arrow UNUSED(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_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_HitGroundTimer != -1) // 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; - } - 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: - -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) -{ - 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); - } - Destroy(); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// 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) -{ - // 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(); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// 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; - } - } - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// 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 : - -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, ENTITY_STATUS_FIREWORK_EXPLODE); - Destroy(); - } - - 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)); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// 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 -} - - - - diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index efb7ae783..ae06b072f 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,300 +94,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; - // 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; - - /// 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 -{ - 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; - - // 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: - - // tolua_end - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - - // 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_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_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 - -}; - - - - - -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 - -} ; - - - - - -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 - - - +} ; // tolua_export diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 02f31f5bb..fd9a4e7ac 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -30,8 +30,6 @@ cTNTEntity::cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks) : void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle) { a_ClientHandle.SendSpawnObject(*this, 50, 1, 0, 0); // 50 means TNT - m_bDirtyPosition = false; - m_bDirtySpeed = false; m_bDirtyOrientation = false; m_bDirtyHead = false; } 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/FastRandom.cpp b/src/FastRandom.cpp index e6634bb0d..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) { } @@ -172,3 +173,13 @@ float cFastRandom::NextFloat(float a_Range, int a_Salt) + +int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End) +{ + cFastRandom Random; + return Random.NextInt(a_End - a_Begin + 1) + a_Begin; +} + + + + diff --git a/src/FastRandom.h b/src/FastRandom.h index bf70822cf..567198a31 100644 --- a/src/FastRandom.h +++ b/src/FastRandom.h @@ -43,6 +43,9 @@ public: /// Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness float NextFloat(float a_Range, int a_Salt); + + /** Returns a random int in the range [a_Begin .. a_End] */ + int GenerateRandomInteger(int a_Begin, int a_End); protected: int m_Seed; diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index 1810d7c49..bd7fd8079 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -56,7 +56,6 @@ void cFurnaceRecipe::ReloadRecipes(void) std::ifstream f; char a_File[] = "furnace.txt"; f.open(a_File, std::ios::in); - std::string input; if (!f.good()) { 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/Caves.cpp b/src/Generating/Caves.cpp index 98b7c8681..5cad11d2a 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -200,13 +200,14 @@ void cCaveTunnel::Randomize(cNoise & a_Noise) for (int i = 0; i < 4; i++) { // For each already present point, insert a point in between it and its predecessor, shifted randomly. - int PrevX = m_Points.front().m_BlockX; - int PrevY = m_Points.front().m_BlockY; - int PrevZ = m_Points.front().m_BlockZ; - int PrevR = m_Points.front().m_Radius; + cCaveDefPoint & Point = m_Points.front(); + int PrevX = Point.m_BlockX; + int PrevY = Point.m_BlockY; + int PrevZ = Point.m_BlockZ; + int PrevR = Point.m_Radius; cCaveDefPoints Pts; Pts.reserve(m_Points.size() * 2 + 1); - Pts.push_back(m_Points.front()); + Pts.push_back(Point); for (cCaveDefPoints::const_iterator itr = m_Points.begin() + 1, end = m_Points.end(); itr != end; ++itr) { int Random = a_Noise.IntNoise3DInt(PrevX, PrevY, PrevZ + i) / 11; @@ -244,11 +245,12 @@ bool cCaveTunnel::RefineDefPoints(const cCaveDefPoints & a_Src, cCaveDefPoints & a_Dst.clear(); a_Dst.reserve(Num * 2 + 2); cCaveDefPoints::const_iterator itr = a_Src.begin() + 1; - a_Dst.push_back(a_Src.front()); - int PrevX = a_Src.front().m_BlockX; - int PrevY = a_Src.front().m_BlockY; - int PrevZ = a_Src.front().m_BlockZ; - int PrevR = a_Src.front().m_Radius; + const cCaveDefPoint & Source = a_Src.front(); + a_Dst.push_back(Source); + int PrevX = Source.m_BlockX; + int PrevY = Source.m_BlockY; + int PrevZ = Source.m_BlockZ; + int PrevR = Source.m_Radius; for (int i = 0; i <= Num; ++i, ++itr) { int dx = itr->m_BlockX - PrevX; @@ -310,9 +312,10 @@ void cCaveTunnel::FinishLinear(void) std::swap(Pts, m_Points); m_Points.reserve(Pts.size() * 3); - int PrevX = Pts.front().m_BlockX; - int PrevY = Pts.front().m_BlockY; - int PrevZ = Pts.front().m_BlockZ; + cCaveDefPoint & PrevPoint = Pts.front(); + int PrevX = PrevPoint.m_BlockX; + int PrevY = PrevPoint.m_BlockY; + int PrevZ = PrevPoint.m_BlockZ; for (cCaveDefPoints::const_iterator itr = Pts.begin() + 1, end = Pts.end(); itr != end; ++itr) { int x1 = itr->m_BlockX; @@ -433,9 +436,10 @@ void cCaveTunnel::FinishLinear(void) void cCaveTunnel::CalcBoundingBox(void) { - m_MinBlockX = m_MaxBlockX = m_Points.front().m_BlockX; - m_MinBlockY = m_MaxBlockY = m_Points.front().m_BlockY; - m_MinBlockZ = m_MaxBlockZ = m_Points.front().m_BlockZ; + cCaveDefPoint & Point = m_Points.front(); + m_MinBlockX = m_MaxBlockX = Point.m_BlockX; + m_MinBlockY = m_MaxBlockY = Point.m_BlockY; + m_MinBlockZ = m_MaxBlockZ = Point.m_BlockZ; for (cCaveDefPoints::const_iterator itr = m_Points.begin() + 1, end = m_Points.end(); itr != end; ++itr) { m_MinBlockX = std::min(m_MinBlockX, itr->m_BlockX - itr->m_Radius); diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index 02779a8a3..d90fdeb0a 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -71,6 +71,40 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Performance test of the NetherFort generator: + +/* +#include "OSSupport/Timer.h" +static class cNetherFortPerfTest +{ +public: + cNetherFortPerfTest(void) + { + cTimer Timer; + long long StartTime = Timer.GetNowTime(); + + const int GridSize = 512; + const int MaxDepth = 12; + const int NumIterations = 100; + for (int i = 0; i < NumIterations; i++) + { + cNetherFortGen FortGen(i, GridSize, MaxDepth); + delete new cNetherFortGen::cNetherFort(FortGen, 0, 0, GridSize, MaxDepth, i); + } + + long long EndTime = Timer.GetNowTime(); + printf("%d forts took %lld msec (%f sec) to generate\n", NumIterations, EndTime - StartTime, ((double)(EndTime - StartTime)) / 1000); + exit(0); + } + +} g_PerfTest; +//*/ + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cNetherFortGen: cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : @@ -80,9 +114,9 @@ cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : m_MaxDepth(a_MaxDepth) { // Initialize the prefabs: - for (size_t i = 0; i < g_NetherFortPrefabs1Count; i++) + for (size_t i = 0; i < g_NetherFortPrefabsCount; i++) { - cPrefab * Prefab = new cPrefab(g_NetherFortPrefabs1[i]); + cPrefab * Prefab = new cPrefab(g_NetherFortPrefabs[i]); m_AllPieces.push_back(Prefab); if (Prefab->HasConnectorType(0)) { @@ -95,15 +129,17 @@ cNetherFortGen::cNetherFortGen(int a_Seed, int a_GridSize, int a_MaxDepth) : } // Initialize the starting piece prefabs: - for (size_t i = 0; i < g_NetherFortStartingPrefabs1Count; i++) + for (size_t i = 0; i < g_NetherFortStartingPrefabsCount; i++) { - m_StartingPieces.push_back(new cPrefab(g_NetherFortStartingPrefabs1[i])); + m_StartingPieces.push_back(new cPrefab(g_NetherFortStartingPrefabs[i])); } + /* // DEBUG: Try one round of placement: cPlacedPieces Pieces; cBFSPieceGenerator pg(*this, a_Seed); pg.PlacePieces(0, 64, 0, a_MaxDepth, Pieces); + */ } @@ -256,6 +292,15 @@ cPieces cNetherFortGen::GetStartingPieces(void) +int cNetherFortGen::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) +{ + return ((const cPrefab &)a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); +} + + + + + void cNetherFortGen::PiecePlaced(const cPiece & a_Piece) { UNUSED(a_Piece); diff --git a/src/Generating/NetherFortGen.h b/src/Generating/NetherFortGen.h index 10ba01396..d51596b9e 100644 --- a/src/Generating/NetherFortGen.h +++ b/src/Generating/NetherFortGen.h @@ -26,6 +26,7 @@ public: virtual ~cNetherFortGen(); protected: + friend class cNetherFortPerfTest; // fwd: NetherFortGen.cpp class cNetherFort; // fwd: NetherFortGen.cpp typedef std::list<cNetherFort *> cNetherForts; @@ -77,6 +78,7 @@ protected: // cPiecePool overrides: virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetStartingPieces(void) override; + virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override; virtual void PiecePlaced(const cPiece & a_Piece) override; virtual void Reset(void) override; } ; diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 8999a5ff7..db45cd08b 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -388,22 +388,26 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // Get a list of available connections: const int * RotTable = DirectionRotationTable[a_Connector.m_Direction]; cConnections Connections; - cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type); + int WantedConnectorType = -a_Connector.m_Type; + cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); Connections.reserve(AvailablePieces.size()); Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction); - - /* - // DEBUG: - printf("Placing piece at connector pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str()); - //*/ - + int WeightTotal = 0; for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) { + // Get the relative chance of this piece being generated in this path: + int Weight = m_PiecePool.GetPieceWeight(a_ParentPiece, a_Connector, **itrP); + if (Weight <= 0) + { + continue; + } + + // Try fitting each of the piece's connector: cPiece::cConnectors Connectors = (*itrP)->GetConnectors(); for (cPiece::cConnectors::iterator itrC = Connectors.begin(), endC = Connectors.end(); itrC != endC; ++itrC) { - if (itrC->m_Type != a_Connector.m_Type) + if (itrC->m_Type != WantedConnectorType) { continue; } @@ -419,7 +423,9 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // Doesn't fit in this rotation continue; } - Connections.push_back(cConnection(**itrP, *itrC, NumCCWRotations)); + // Fits, add it to list of possibile connections: + Connections.push_back(cConnection(**itrP, *itrC, NumCCWRotations, Weight)); + WeightTotal += Weight; } // for itrC - Connectors[] } // for itrP - AvailablePieces[] if (Connections.empty()) @@ -427,21 +433,23 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // No available connections, bail out return false; } + ASSERT(WeightTotal > 0); - // Choose a random connection from the list: - int rnd = m_Noise.IntNoise3DInt(a_Connector.m_Pos.x, a_Connector.m_Pos.y, a_Connector.m_Pos.z) / 7; - cConnection & Conn = Connections[rnd % Connections.size()]; + // Choose a random connection from the list, based on the weights: + int rnd = (m_Noise.IntNoise3DInt(a_Connector.m_Pos.x, a_Connector.m_Pos.y, a_Connector.m_Pos.z) / 7) % WeightTotal; + size_t ChosenIndex = 0; + for (cConnections::const_iterator itr = Connections.begin(), end = Connections.end(); itr != end; ++itr, ++ChosenIndex) + { + rnd -= itr->m_Weight; + if (rnd <= 0) + { + // This is the piece to choose + break; + } + } + cConnection & Conn = Connections[ChosenIndex]; // Place the piece: - /* - // DEBUG - printf("Chosen connector at {%d, %d, %d}, direction %s, needs %d rotations\n", - Conn.m_Connector.m_Pos.x, Conn.m_Connector.m_Pos.y, Conn.m_Connector.m_Pos.z, - BlockFaceToString(Conn.m_Connector.m_Direction).c_str(), - Conn.m_NumCCWRotations - ); - //*/ - Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations); ConnPos -= NewPos; cPlacedPiece * PlacedPiece = new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations); @@ -449,12 +457,6 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // Add the new piece's connectors to the list of free connectors: cPiece::cConnectors Connectors = Conn.m_Piece->GetConnectors(); - - /* - // DEBUG: - printf("Adding %u connectors to the pool\n", Connectors.size() - 1); - //*/ - for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr) { if (itr->m_Pos.Equals(Conn.m_Connector.m_Pos)) @@ -524,10 +526,11 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPieceGenerator::cConnection: -cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations) : +cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight) : m_Piece(&a_Piece), m_Connector(a_Connector), - m_NumCCWRotations(a_NumCCWRotations) + m_NumCCWRotations(a_NumCCWRotations), + m_Weight(a_Weight) { } diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index bef9d3463..16bec3bb4 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -38,7 +38,8 @@ public: /** Position relative to the piece */ Vector3i m_Pos; - /** Type of the connector. Any arbitrary number; the generator connects only connectors of the same type. */ + /** Type of the connector. Any arbitrary number; the generator connects only connectors of opposite + (negative) types. */ int m_Type; /** Direction in which the connector is facing. @@ -85,6 +86,13 @@ typedef std::vector<cPiece *> cPieces; +// fwd: +class cPlacedPiece; + + + + + /** This class is an interface that provides pieces for the generator. It can keep track of what pieces were placed and adjust the returned piece vectors. */ class cPiecePool @@ -101,6 +109,16 @@ public: Multiple starting points are supported, one of the returned piece will be chosen. */ virtual cPieces GetStartingPieces(void) = 0; + /** Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through a_ExistingConnector. + This allows the pool to tweak the piece's chances, based on the previous pieces in the tree and the connector used. + The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will never be chosen. + */ + virtual int GetPieceWeight( + const cPlacedPiece & a_PlacedPiece, + const cPiece::cConnector & a_ExistingConnector, + const cPiece & a_NewPiece + ) { return 1; } + /** Called after a piece is placed, to notify the pool that it has been used. The pool may adjust the pieces it will return the next time. */ virtual void PiecePlaced(const cPiece & a_Piece) = 0; @@ -157,8 +175,9 @@ protected: cPiece * m_Piece; // The piece being connected cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) int m_NumCCWRotations; // Number of rotations necessary to match the two connectors + int m_Weight; // Relative chance that this connection will be chosen - cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations); + cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight); }; typedef std::vector<cConnection> cConnections; diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 131b6acb2..0f20603be 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -23,6 +23,10 @@ static const cPrefab::sDef g_TestPrefabDef = // Size: 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 6, 5, 6, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* 0 */ "a:112: 0\n" /* netherbrick */ @@ -91,7 +95,19 @@ static const cPrefab::sDef g_TestPrefabDef = 7, /* 1, 2, 3 CCW rotations */ // Merge strategy: - cBlockArea::msImprint + cBlockArea::msImprint, + + // ShouldExtendFloor: + false, + + // DefaultWeight: + 10, + + // DepthWeight: + "", + + // AddWeightIfSame: + 1000, }; static cPrefab g_TestPrefab(g_TestPrefabDef); @@ -103,15 +119,22 @@ static cPrefab g_TestPrefab(g_TestPrefabDef); cPrefab::cPrefab(const cPrefab::sDef & a_Def) : m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ), - m_HitBox(0, 0, 0, a_Def.m_SizeX - 1, a_Def.m_SizeY - 1, a_Def.m_SizeZ - 1), + m_HitBox( + a_Def.m_HitboxMinX, a_Def.m_HitboxMinY, a_Def.m_HitboxMinZ, + a_Def.m_HitboxMaxX, a_Def.m_HitboxMaxY, a_Def.m_HitboxMaxZ + ), m_AllowedRotations(a_Def.m_AllowedRotations), - m_MergeStrategy(a_Def.m_MergeStrategy) + m_MergeStrategy(a_Def.m_MergeStrategy), + m_ShouldExtendFloor(a_Def.m_ShouldExtendFloor), + m_DefaultWeight(a_Def.m_DefaultWeight), + m_AddWeightIfSame(a_Def.m_AddWeightIfSame) { m_BlockArea[0].Create(m_Size); CharMap cm; ParseCharMap(cm, a_Def.m_CharMap); ParseBlockImage(cm, a_Def.m_Image); ParseConnectors(a_Def.m_Connectors); + ParseDepthWeight(a_Def.m_DepthWeight); // 1 CCW rotation: if ((m_AllowedRotations & 0x01) != 0) @@ -142,12 +165,56 @@ cPrefab::cPrefab(const cPrefab::sDef & a_Def) : void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const { + // Draw the basic image: Vector3i Placement = a_Placement->GetCoords(); int ChunkStartX = a_Dest.GetChunkX() * cChunkDef::Width; int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; Placement.Move(-ChunkStartX, 0, -ChunkStartZ); - a_Dest.WriteBlockArea(m_BlockArea[a_Placement->GetNumCCWRotations()], Placement.x, Placement.y, Placement.z, m_MergeStrategy); + const cBlockArea & Image = m_BlockArea[a_Placement->GetNumCCWRotations()]; + a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); + // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) + if (m_ShouldExtendFloor) + { + int MaxX = Image.GetSizeX(); + int MaxZ = Image.GetSizeZ(); + for (int z = 0; z < MaxZ; z++) + { + int RelZ = Placement.z + z; + if ((RelZ < 0) || (RelZ >= cChunkDef::Width)) + { + // Z coord outside the chunk + continue; + } + for (int x = 0; x < MaxX; x++) + { + int RelX = Placement.x + x; + if ((RelX < 0) || (RelX >= cChunkDef::Width)) + { + // X coord outside the chunk + continue; + } + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + Image.GetRelBlockTypeMeta(x, 0, z, BlockType, BlockMeta); + if ((BlockType == E_BLOCK_AIR) || (BlockType == E_BLOCK_SPONGE)) + { + // Do not expand air nor sponge blocks + continue; + } + for (int y = Placement.y - 1; y >= 0; y--) + { + BLOCKTYPE ExistingBlock = a_Dest.GetBlockType(RelX, y, RelZ); + if (ExistingBlock != E_BLOCK_AIR) + { + // End the expansion for this column, reached the end + break; + } + a_Dest.SetBlockTypeMeta(RelX, y, RelZ, BlockType, BlockMeta); + } // for y + } // for x + } // for z + } } @@ -170,6 +237,26 @@ bool cPrefab::HasConnectorType(int a_ConnectorType) const +int cPrefab::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector) const +{ + // Use the default or per-depth weight: + cDepthWeight::const_iterator itr = m_DepthWeight.find(a_PlacedPiece.GetDepth() + 1); + int res = (itr == m_DepthWeight.end()) ? m_DefaultWeight : itr->second; + + // If the piece is the same as the parent, apply the m_AddWeightIfSame modifier: + const cPiece * ParentPiece = &a_PlacedPiece.GetPiece(); + const cPiece * ThisPiece = this; + if (ThisPiece == ParentPiece) + { + res += m_AddWeightIfSame; + } + return res; +} + + + + + void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) { ASSERT(a_CharMapDef != NULL); @@ -199,7 +286,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[] @@ -277,6 +364,54 @@ void cPrefab::ParseConnectors(const char * a_ConnectorsDef) +void cPrefab::ParseDepthWeight(const char * a_DepthWeightDef) +{ + // The member needn't be defined at all, if so, skip: + if (a_DepthWeightDef == NULL) + { + return; + } + + // Split into individual records: "Record | Record | Record" + AStringVector Defs = StringSplitAndTrim(a_DepthWeightDef, "|"); + + // Add each record's contents: + for (AStringVector::const_iterator itr = Defs.begin(), end = Defs.end(); itr != end; ++itr) + { + // Split into components: "Depth : Weight" + AStringVector Components = StringSplitAndTrim(*itr, ":"); + if (Components.size() != 2) + { + LOGWARNING("Bad prefab DepthWeight record: \"%s\", skipping.", itr->c_str()); + continue; + } + + // Parse depth: + int Depth = atoi(Components[0].c_str()); + if ((Depth == 0) && (Components[0] != "0")) + { + LOGWARNING("Bad prefab DepthWeight record, cannot parse depth \"%s\", skipping.", Components[0].c_str()); + continue; + } + + // Parse weight: + int Weight = atoi(Components[1].c_str()); + if ((Weight == 0) && (Components[1] != "0")) + { + LOGWARNING("Bad prefab DepthWeight record, cannot parse weight \"%s\", skipping.", Components[1].c_str()); + continue; + } + + // Save to map: + ASSERT(m_DepthWeight.find(Depth) == m_DepthWeight.end()); // Not a duplicate + m_DepthWeight[Depth] = Weight; + } // for itr - Defs[] +} + + + + + cPiece::cConnectors cPrefab::GetConnectors(void) const { return m_Connectors; diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 04c4f09da..37db2ff16 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -37,11 +37,51 @@ public: int m_SizeX; int m_SizeY; int m_SizeZ; + + /** The hitbox used for collision-checking between prefabs. Relative to the bounds. */ + int m_HitboxMinX, m_HitboxMinY, m_HitboxMinZ; + int m_HitboxMaxX, m_HitboxMaxY, m_HitboxMaxZ; + + /** The mapping between characters in m_Image and the blocktype / blockmeta. + Format: "Char: BlockType: BlockMeta \n Char: BlockType : BlockMeta \n ..." */ const char * m_CharMap; + + /** The actual image to be used for the prefab. Organized YZX (Y changes the least often). + Each character represents a single block, the type is mapped through m_CharMap. */ const char * m_Image; + + /** List of connectors. + Format: "Type: X, Y, Z : Direction \n Type : X, Y, Z : Direction \n ...". + Type is an arbitrary number, Direction is the BlockFace constant value (0 .. 5). */ const char * m_Connectors; + + /** Bitmask specifying the allowed rotations. + N rotations CCW are allowed if bit N is set. */ int m_AllowedRotations; + + /** The merge strategy to use while drawing the prefab. */ cBlockArea::eMergeStrategy m_MergeStrategy; + + /** If set to true, the prefab will extend its lowermost blocks until a solid block is found, + thus creating a foundation for the prefab. This is used for houses to be "on the ground", as well as + nether fortresses not to float. */ + bool m_ShouldExtendFloor; + + /** Chance of this piece being used, if no other modifier is active. */ + int m_DefaultWeight; + + /** Chances of this piece being used, per depth of the generated piece tree. + The starting piece has a depth of 0, the pieces connected to it are depth 1, etc. + The specified depth stands for the depth of the new piece (not the existing already-placed piece), + so valid depths start at 1. + Format: "Depth : Weight | Depth : Weight | Depth : Weight ..." + Depths that are not specified will use the m_DefaultWeight value. */ + const char * m_DepthWeight; + + /** The weight to add to this piece's base per-depth chance if the previous piece is the same. + Can be positive or negative. + This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each other. */ + int m_AddWeightIfSame; }; cPrefab(const sDef & a_Def); @@ -51,6 +91,10 @@ public: /** Returns true if the prefab has any connector of the specified type. */ bool HasConnectorType(int a_ConnectorType) const; + + /** Returns the weight (chance) of this prefab generating as the next piece after the specified placed piece. + PiecePool implementations can use this for their GetPieceWeight() implementations. */ + int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector) const; protected: /** Packs complete definition of a single block, for per-letter assignment. */ @@ -60,9 +104,12 @@ protected: NIBBLETYPE m_BlockMeta; }; - /** Maps letters in the sDef::m_Image onto a number, BlockType * 16 | BlockMeta */ + /** Maps letters in the sDef::m_Image onto a sBlockTypeDef block type definition. */ typedef sBlockTypeDef CharMap[256]; + /** Maps generator tree depth to weight. */ + typedef std::map<int, int> cDepthWeight; + /** The cBlockArea that contains the block definitions for the prefab. The index identifies the number of CCW rotations applied (0 = no rotation, 1 = 1 CCW rotation, ...). */ @@ -71,7 +118,7 @@ protected: /** The size of the prefab */ Vector3i m_Size; - /** The hitbox of the prefab. In first version is the same as the m_BlockArea dimensions */ + /** The hitbox used for collision-checking between prefabs. */ cCuboid m_HitBox; /** The connectors through which the piece connects to other pieces */ @@ -82,6 +129,26 @@ protected: /** The merge strategy to use when drawing the prefab into a block area */ cBlockArea::eMergeStrategy m_MergeStrategy; + + /** If set to true, the prefab will extend its lowermost blocks until a solid block is found, + thus creating a foundation for the prefab. This is used for houses to be "on the ground", as well as + nether fortresses not to float. */ + bool m_ShouldExtendFloor; + + /** Chance of this piece being used, if no other modifier is active. */ + int m_DefaultWeight; + + /** Chances of this piece being used, per depth of the generated piece tree. + The starting piece has a depth of 0, the pieces connected to it are depth 1, etc. + The specified depth stands for the depth of the new piece (not the existing already-placed piece), + so valid depths start at 1. + Depths that are not specified will use the m_DefaultWeight value. */ + cDepthWeight m_DepthWeight; + + /** The weight to add to this piece's base per-depth chance if the previous piece is the same. + Can be positive or negative. + This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each other. */ + int m_AddWeightIfSame; // cPiece overrides: @@ -98,6 +165,9 @@ protected: /** Parses the connectors definition text into m_Connectors member. */ void ParseConnectors(const char * a_ConnectorsDef); + + /** Parses the per-depth weight into m_DepthWeight member. */ + void ParseDepthWeight(const char * a_DepthWeightDef); }; 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/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index 5e8685e32..088340391 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -1,7 +1,10 @@ // NetherFortPrefabs.cpp -// Defines all the prefabs for nether forts +// Defines the prefabs in the group NetherFort + +// NOTE: This file has been generated automatically by GalExport! +// Any manual changes will be overwritten by the next automatic export! #include "Globals.h" #include "NetherFortPrefabs.h" @@ -10,347 +13,442 @@ -/* -The nether fortress has two types of connectors, Outer and Inner. Outer is Type 0, Inner is Type 1. -*/ - - - - - -const cPrefab::sDef g_NetherFortPrefabs1[] = +const cPrefab::sDef g_NetherFortPrefabs[] = { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BalconyCorridor: - // The data has been exported from gallery Nether, area index 37, ID 288 + // The data has been exported from the gallery Nether, area index 37, ID 288, created by Aloe_vera { // Size: 13, 7, 9, // SizeX = 13, SizeY = 7, SizeZ = 9 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 6, 8, // MaxX, MaxY, MaxZ + // Block definitions: + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ - "b: 19: 0\n" /* sponge */ - "c:114: 4\n" /* netherbrickstairs */ - "d:114: 7\n" /* netherbrickstairs */ - "e:114: 5\n" /* netherbrickstairs */ - "f: 44: 6\n" /* step */ - "g:113: 0\n" /* netherbrickfence */ - "h:114: 2\n" /* netherbrickstairs */ - "i:114: 3\n" /* netherbrickstairs */ - "j:114: 0\n" /* netherbrickstairs */ - "k:114: 1\n" /* netherbrickstairs */ - ".: 0: 0\n" /* air */, + "b:114: 4\n" /* netherbrickstairs */ + "c:114: 7\n" /* netherbrickstairs */ + "d:114: 5\n" /* netherbrickstairs */ + "e: 44: 6\n" /* step */ + "f:113: 0\n" /* netherbrickfence */ + "g:114: 2\n" /* netherbrickstairs */ + "h:114: 3\n" /* netherbrickstairs */ + "i:114: 0\n" /* netherbrickstairs */ + "j:114: 1\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "mmmmaaaaammmm" + /* 6 */ "mmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmm" + // Level 1 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "bbbbaaaaabbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaa.aaa.aaaa" + /* 5 */ "mmbcaaaaacdmm" + /* 6 */ "mmmbcccccdmmm" + /* 7 */ "mmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmm" // Level 2 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaa.aaa.aaaa" - "bbcdaaaaadebb" - "bbbcdddddebbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "aaaa.eee.aaaa" + /* 5 */ "mmaaaaaaaaamm" + /* 6 */ "mmaaaaaaaaamm" + /* 7 */ "mmaaaaaaaaamm" + /* 8 */ "mmaaaaaaaaamm" // Level 3 - "aaaaaaaaaaaaa" - "............." - "............." - "............." - "aaaa.fff.aaaa" - "bbaaaaaaaaabb" - "bbaaaaaaaaabb" - "bbaaaaaaaaabb" - "bbaaaaaaaaabb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "afafafafafafa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "afaa.....aafa" + /* 5 */ "mmaaa...aaamm" + /* 6 */ "mmf.......fmm" + /* 7 */ "mmf.......fmm" + /* 8 */ "mmfffffffffmm" // Level 4 - "agagagagagaga" - "............." - "............." - "............." - "agaa.....aaga" - "bbaaa...aaabb" - "bbg.......gbb" - "bbg.......gbb" - "bbgggggggggbb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "afafafafafafa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "afaa.....aafa" + /* 5 */ "mmaaa...aaamm" + /* 6 */ "mm.........mm" + /* 7 */ "mm.........mm" + /* 8 */ "mm.........mm" // Level 5 - "agagagagagaga" - "............." - "............." - "............." - "agaa.....aaga" - "bbaaa...aaabb" - "bb.........bb" - "bb.........bb" - "bb.........bb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "afafafafafafa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "afaa.....aafa" + /* 5 */ "mmaaa...aaamm" + /* 6 */ "mm.........mm" + /* 7 */ "mm.........mm" + /* 8 */ "mm.........mm" // Level 6 - "agagagagagaga" - "............." - "............." - "............." - "agaa.....aaga" - "bbaaa...aaabb" - "bb.........bb" - "bb.........bb" - "bb.........bb" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "ggggggggggggg" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "hhiaaaaaaahhh" + /* 5 */ "mmihhhhhhhjmm" + /* 6 */ "mmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmm", + + // Connectors: + "1: 12, 2, 2: 5\n" /* Type 1, direction X+ */ + "1: 0, 2, 2: 4\n" /* Type 1, direction X- */ + "-1: 12, 2, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 2, 2: 4\n" /* Type -1, direction X- */, - // Level 7 - "hhhhhhhhhhhhh" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "iijaaaaaaaiii" - "bbjiiiiiiikbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb", - - // Connections: - "1: 0, 2, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 12, 2, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 20, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // BalconyCorridor + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BalconyTee2: - // The data has been exported from gallery Nether, area index 38, ID 289 + // The data has been exported from the gallery Nether, area index 38, ID 289, created by Aloe_vera { // Size: 13, 7, 11, // SizeX = 13, SizeY = 7, SizeZ = 11 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 6, 10, // MaxX, MaxY, MaxZ + // Block definitions: - "a: 19: 0\n" /* sponge */ - "b:112: 0\n" /* netherbrick */ - "c:114: 4\n" /* netherbrickstairs */ - "d:114: 7\n" /* netherbrickstairs */ - "e:114: 5\n" /* netherbrickstairs */ - "f: 44: 6\n" /* step */ - "g:113: 0\n" /* netherbrickfence */ - "h:114: 0\n" /* netherbrickstairs */ - "i:114: 1\n" /* netherbrickstairs */ - "j:114: 2\n" /* netherbrickstairs */ - "k:114: 3\n" /* netherbrickstairs */ - ".: 0: 0\n" /* air */, + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 4\n" /* netherbrickstairs */ + "c:114: 7\n" /* netherbrickstairs */ + "d:114: 5\n" /* netherbrickstairs */ + "e: 44: 6\n" /* step */ + "f:113: 0\n" /* netherbrickfence */ + "g:114: 0\n" /* netherbrickstairs */ + "h:114: 1\n" /* netherbrickstairs */ + "i:114: 2\n" /* netherbrickstairs */ + "j:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmaaaaammmm" + /* 1 */ "mmmmaaaaammmm" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "mmmmaaaaammmm" + /* 8 */ "mmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmm" + // Level 1 - "aaaabbbbbaaaa" - "aaaabbbbbaaaa" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "aaaabbbbbaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmaaaaammmm" + /* 1 */ "mmmmaaaaammmm" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaa.aaa.aaaa" + /* 7 */ "mmbcaaaaacdmm" + /* 8 */ "mmmbcccccdmmm" + /* 9 */ "mmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmm" // Level 2 - "aaaabbbbbaaaa" - "aaaabbbbbaaaa" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbb.bbb.bbbb" - "aacdbbbbbdeaa" - "aaacdddddeaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmma...ammmm" + /* 2 */ "aaaaa...aaaaa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "aaaa.eee.aaaa" + /* 7 */ "mmaaaaaaaaamm" + /* 8 */ "mmaaaaaaaaamm" + /* 9 */ "mmaaaaaaaaamm" + /* 10 */ "mmaaaaaaaaamm" // Level 3 - "aaaab...baaaa" - "aaaab...baaaa" - "bbbbb...bbbbb" - "............." - "............." - "............." - "bbbb.fff.bbbb" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmf...fmmmm" + /* 2 */ "afafa...afafa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "afaa.....aafa" + /* 7 */ "mmaaa...aaamm" + /* 8 */ "mmf.......fmm" + /* 9 */ "mmf.......fmm" + /* 10 */ "mmfffffffffmm" // Level 4 - "aaaab...baaaa" - "aaaag...gaaaa" - "bgbgb...bgbgb" - "............." - "............." - "............." - "bgbb.....bbgb" - "aabbb...bbbaa" - "aag.......gaa" - "aag.......gaa" - "aagggggggggaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmf...fmmmm" + /* 2 */ "afafa...afafa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "afaa.....aafa" + /* 7 */ "mmaaa...aaamm" + /* 8 */ "mm.........mm" + /* 9 */ "mm.........mm" + /* 10 */ "mm.........mm" // Level 5 - "aaaab...baaaa" - "aaaag...gaaaa" - "bgbgb...bgbgb" - "............." - "............." - "............." - "bgbb.....bbgb" - "aabbb...bbbaa" - "aa.........aa" - "aa.........aa" - "aa.........aa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmf...fmmmm" + /* 2 */ "afafa...afafa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "afaa.....aafa" + /* 7 */ "mmaaa...aaamm" + /* 8 */ "mm.........mm" + /* 9 */ "mm.........mm" + /* 10 */ "mm.........mm" // Level 6 - "aaaab...baaaa" - "aaaag...gaaaa" - "bgbgb...bgbgb" - "............." - "............." - "............." - "bgbb.....bbgb" - "aabbb...bbbaa" - "aa.........aa" - "aa.........aa" - "aa.........aa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmgaaahmmmm" + /* 1 */ "mmmmgaaahmmmm" + /* 2 */ "iiiiiaaaiiiii" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "jjgaaaaaaajjj" + /* 7 */ "mmgjjjjjjjhmm" + /* 8 */ "mmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmm", + + // Connectors: + "1: 12, 2, 4: 5\n" /* Type 1, direction X+ */ + "1: 6, 2, 0: 2\n" /* Type 1, direction Z- */ + "1: 0, 2, 4: 4\n" /* Type 1, direction X- */ + "-1: 12, 2, 4: 5\n" /* Type -1, direction X+ */ + "-1: 6, 2, 0: 2\n" /* Type -1, direction Z- */ + "-1: 0, 2, 4: 4\n" /* Type -1, direction X- */, - // Level 7 - "aaaahbbbiaaaa" - "aaaahbbbiaaaa" - "jjjjjbbbjjjjj" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "bbbbbbbbbbbbb" - "kkhbbbbbbbkkk" - "aahkkkkkkkiaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa", - - // Connections: - "1: 0, 2, 4: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 12, 2, 4: 5\n" /* Type 1, BLOCK_FACE_XP */ - "1: 6, 2, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 20, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // BalconyTee2 + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // BlazePlatform - // The data has been exported from gallery Nether, area index 26, ID 276 + // BlazePlatform: + // The data has been exported from the gallery Nether, area index 26, ID 276, created by tonibm1999 { // Size: 10, 7, 7, // SizeX = 10, SizeY = 7, SizeZ = 7 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 9, 6, 6, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b: 52: 0\n" /* mobspawner */ - "c:113: 0\n" /* netherbrickfence */, + "c:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmmmmmmm" + /* 1 */ "aaaaaaaaaa" + /* 2 */ "aaaaaaaaaa" + /* 3 */ "aaaaaaaaaa" + /* 4 */ "aaaaaaaaaa" + /* 5 */ "aaaaaaaaaa" + /* 6 */ "mmmmmmmmmm" + // Level 1 - ".........." - "aaaaaaaaaa" - "aaaaaaaaaa" - "aaaaaaaaaa" - "aaaaaaaaaa" - "aaaaaaaaaa" - ".........." + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmmmmmmm" + /* 1 */ "aaaaaaaaaa" + /* 2 */ "..aaaaaaaa" + /* 3 */ "..aaaaaaaa" + /* 4 */ "..aaaaaaaa" + /* 5 */ "aaaaaaaaaa" + /* 6 */ "mmmmmmmmmm" // Level 2 - ".........." - "aaaaaaaaaa" - "..aaaaaaaa" - "..aaaaaaaa" - "..aaaaaaaa" - "aaaaaaaaaa" - ".........." + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmaaaaaa" + /* 1 */ "aaaaaaaaaa" + /* 2 */ "...aaaaaaa" + /* 3 */ "...aaaaaaa" + /* 4 */ "...aaaaaaa" + /* 5 */ "aaaaaaaaaa" + /* 6 */ "mmmmaaaaaa" // Level 3 - "....aaaaaa" - "aaaaaaaaaa" - "...aaaaaaa" - "...aaaaaaa" - "...aaaaaaa" - "aaaaaaaaaa" - "....aaaaaa" + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmaaaaaa" + /* 1 */ "mmaaa....a" + /* 2 */ ".........a" + /* 3 */ "......b..a" + /* 4 */ ".........a" + /* 5 */ "mmaaa....a" + /* 6 */ "mmmmaaaaaa" // Level 4 - "....aaaaaa" - "..aaa....a" - ".........a" - "......b..a" - ".........a" - "..aaa....a" - "....aaaaaa" + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmcccccc" + /* 1 */ "mmmcc....c" + /* 2 */ ".........c" + /* 3 */ ".........c" + /* 4 */ ".........c" + /* 5 */ "mmmcc....c" + /* 6 */ "mmmmcccccc" // Level 5 - "....cccccc" - "...cc....c" - ".........c" - ".........c" - ".........c" - "...cc....c" - "....cccccc" + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmmmmmmm" + /* 1 */ "mmmmm....c" + /* 2 */ "m........c" + /* 3 */ "m........c" + /* 4 */ "m........c" + /* 5 */ "mmmmm....c" + /* 6 */ "mmmmmmmmmm" // Level 6 - ".........." - ".........c" - ".........c" - ".........c" - ".........c" - ".........c" - ".........." + /* z\x* */ + /* * 0123456789 */ + /* 0 */ "mmmmmmmmmm" + /* 1 */ "mmmmm....m" + /* 2 */ "mm.......c" + /* 3 */ "mm.......c" + /* 4 */ "mm.......c" + /* 5 */ "mmmmm....m" + /* 6 */ "mmmmmmmmmm", + + // Connectors: + "0: 0, 1, 3: 4\n" /* Type 0, direction X- */, - // Level 7 - ".........." - ".........." - ".........c" - ".........c" - ".........c" - ".........." - "..........", - - // Connections: - "0: 0, 1, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|2:0|3:0|4:0|5:0", + + // AddWeightIfSame: + 0, }, // BlazePlatform + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BlazePlatformOverhang: - // The data has been exported from gallery Nether, area index 20, ID 162 + // The data has been exported from the gallery Nether, area index 20, ID 162, created by STR_Warrior { // Size: - 14, 9, 7, // SizeX = 14, SizeY = 9, SizeZ = 7 + 14, 11, 7, // SizeX = 14, SizeY = 11, SizeZ = 7 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 13, 20, 6, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ @@ -366,105 +464,362 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "mmmmmmmmmmmmmm" + /* 2 */ "aammmmmmmmmmmm" + /* 3 */ "aammmmmmmmmmmm" + /* 4 */ "aammmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmm" + // Level 1 - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" - "aammmmmmmmmmmm" - "aammmmmmmmmmmm" - "aammmmmmmmmmmm" - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "mmmmmmmmmmmmmm" + /* 2 */ "aabcmmmmmmmmmm" + /* 3 */ "aabcmmmmmmmmmm" + /* 4 */ "aabcmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmm" // Level 2 - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" - "aabcmmmmmmmmmm" - "aabcmmmmmmmmmm" - "aabcmmmmmmmmmm" - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "mmmmmmmmmmmmmm" + /* 2 */ "aaaaabmmmmmmmm" + /* 3 */ "aaaaabmmmmmmmm" + /* 4 */ "aaaaabmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmm" // Level 3 - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" - "aaaaabmmmmmmmm" - "aaaaabmmmmmmmm" - "aaaaabmmmmmmmm" - "mmmmmmmmmmmmmm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "dddddddmmmmmmm" + /* 2 */ "aaaaaabmmmmmmm" + /* 3 */ "aaaaaabmmmmmmm" + /* 4 */ "aaaaaabmmmmmmm" + /* 5 */ "eeeeeeemmmmmmm" + /* 6 */ "mmmmmmmmmmmmmm" // Level 4 - "mmmmmmmmmmmmmm" - "dddddddmmmmmmm" - "aaaaaabmmmmmmm" - "aaaaaabmmmmmmm" - "aaaaaabmmmmmmm" - "eeeeeeemmmmmmm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "aaaaaaadmmmmmm" + /* 2 */ "aaaaaaabmmmmmm" + /* 3 */ "aaaaaaabmmmmmm" + /* 4 */ "aaaaaaabmmmmmm" + /* 5 */ "aaaaaaaemmmmmm" + /* 6 */ "mmmmmmmmmmmmmm" // Level 5 - "mmmmmmmmmmmmmm" - "aaaaaaadmmmmmm" - "aaaaaaabmmmmmm" - "aaaaaaabmmmmmm" - "aaaaaaabmmmmmm" - "aaaaaaaemmmmmm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmmmmmmm" + /* 1 */ "aaaaaaaabddddm" + /* 2 */ "......faaaaabm" + /* 3 */ "......faaaaabm" + /* 4 */ "......faaaaabm" + /* 5 */ "aaaaaaaaabeebm" + /* 6 */ "mmmmmmmmmmmmmm" // Level 6 - "mmmmmmmmmmmmmm" - "aaaaaaaabddddm" - "......faaaaabm" - "......faaaaabm" - "......faaaaabm" - "aaaaaaaaabeebm" - "mmmmmmmmmmmmmm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmgdddbm" + /* 1 */ "mmmmmmaaaaaaad" + /* 2 */ ".......faaaaab" + /* 3 */ ".......faaaaab" + /* 4 */ ".......faaaaab" + /* 5 */ "mmmmmmaaaaaaae" + /* 6 */ "mmmmmmmmgeeebm" // Level 7 - "mmmmmmmmgdddbm" - "......aaaaaaad" - ".......faaaaab" - ".......faaaaab" - ".......faaaaab" - "......aaaaaaae" - "mmmmmmmmgeeebm" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmaaaaam" + /* 1 */ "mmmmmmhaa...aa" + /* 2 */ ".............a" + /* 3 */ "..........i..a" + /* 4 */ ".............a" + /* 5 */ "mmmmmmhaa...aa" + /* 6 */ "mmmmmmmmaaaaam" // Level 8 - "mmmmmmmmaaaaam" - "......haa...aa" - ".............a" - "..........i..a" - ".............a" - "......haa...aa" - "mmmmmmmmaaaaam" + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmmhhhhhm" + /* 1 */ "mmmmmmhhh...hh" + /* 2 */ "mm...........h" + /* 3 */ "mm...........h" + /* 4 */ "mm...........h" + /* 5 */ "mmmmmmhhh...hh" + /* 6 */ "mmmmmmmmhhhhhm" // Level 9 - "mmmmmmmmhhhhhm" - "......hhh...hh" - ".............h" - ".............h" - ".............h" - "......hhh...hh" - "mmmmmmmmhhhhhm", + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmm.....m" + /* 1 */ "mmmmmm........" + /* 2 */ "mmmm.........." + /* 3 */ "mmmm.........." + /* 4 */ "mmmm.........." + /* 5 */ "mmmmmm........" + /* 6 */ "mmmmmmmm.....m" - // Connections: - "0: 0, 5, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, + // Level 10 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "mmmmmmmm.....m" + /* 1 */ "mmmmmm........" + /* 2 */ "mmmmmm........" + /* 3 */ "mmmmmm........" + /* 4 */ "mmmmmm........" + /* 5 */ "mmmmmm........" + /* 6 */ "mmmmmmmm.....m", + + // Connectors: + "0: 0, 5, 3: 4\n" /* Type 0, direction X- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|2:0|3:0|4:0|5:0", + + // AddWeightIfSame: + 0, }, // BlazePlatformOverhang + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeCircleCrossing: + // The data has been exported from the gallery Nether, area index 49, ID 308, created by Aloe_vera + { + // Size: + 15, 8, 15, // SizeX = 15, SizeY = 8, SizeZ = 15 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 17, 14, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 7\n" /* netherbrickstairs */ + "c:114: 5\n" /* netherbrickstairs */ + "d:114: 4\n" /* netherbrickstairs */ + "e:114: 6\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmmaaammmmmm" + /* 2 */ "mmmmmmmmmmmmmmm" + /* 3 */ "mmmmmmmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "aammmmmmmmmmmaa" + /* 7 */ "aammmmmmmmmmmaa" + /* 8 */ "aammmmmmmmmmmaa" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + /* 12 */ "mmmmmmmmmmmmmmm" + /* 13 */ "mmmmmmaaammmmmm" + /* 14 */ "mmmmmmaaammmmmm" + + // Level 1 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmmaaammmmmm" + /* 2 */ "mmmmmmbbbmmmmmm" + /* 3 */ "mmmmmmmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "aacmmmmmmmmmdaa" + /* 7 */ "aacmmmmmmmmmdaa" + /* 8 */ "aacmmmmmmmmmdaa" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + /* 12 */ "mmmmmmeeemmmmmm" + /* 13 */ "mmmmmmaaammmmmm" + /* 14 */ "mmmmmmaaammmmmm" + + // Level 2 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmeaaammmmmm" + /* 2 */ "mmmmmdaaammmmmm" + /* 3 */ "mmmmmdbbbmmmmmm" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mdeemmmmmmmeecm" + /* 6 */ "aaacmmmmmmmdaaa" + /* 7 */ "aaacmmmmmmmdaaa" + /* 8 */ "aaacmmmmmmmdaaa" + /* 9 */ "mdbcmmmmmmmbbcm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmdeeecmmmmm" + /* 12 */ "mmmmmdaaacmmmmm" + /* 13 */ "mmmmmbaaabmmmmm" + /* 14 */ "mmmmmmaaammmmmm" + + // Level 3 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "deeeedaaaceeeec" + /* 1 */ "daaaaaaaaaaaaac" + /* 2 */ "daaaaaaaaaaaaac" + /* 3 */ "daaaaaaaaaaaaac" + /* 4 */ "daaacbbaabdaaac" + /* 5 */ "eaaacmmmmmdaaae" + /* 6 */ "aaaacmmmmmdaaaa" + /* 7 */ "aaaacmmmmmdaaaa" + /* 8 */ "aaaacmmmmmdaaaa" + /* 9 */ "baaacmmmmmdaaab" + /* 10 */ "daaaceeeeedaaac" + /* 11 */ "daaaaaaaaaaaaac" + /* 12 */ "daaaaaaaaaaaaac" + /* 13 */ "daaaaaaaaaaaaac" + /* 14 */ "dbbbbdaaacbbbbb" + + // Level 4 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaa" + /* 5 */ "aaaaammmmmaaaaa" + /* 6 */ "aaaaammmmmaaaaa" + /* 7 */ "aaaaammmmmaaaaa" + /* 8 */ "aaaaammmmmaaaaa" + /* 9 */ "aaaaammmmmaaaaa" + /* 10 */ "aaaaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaaaaa" + + // Level 5 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaa...aaaaaa" + /* 1 */ "a.............a" + /* 2 */ "a.............a" + /* 3 */ "a.............a" + /* 4 */ "a...aaaaaaa...a" + /* 5 */ "a...ammmmma...a" + /* 6 */ "....ammmmma...." + /* 7 */ "....ammmmma...." + /* 8 */ "....ammmmma...." + /* 9 */ "a...ammmmma...a" + /* 10 */ "a...aaaaaaa...a" + /* 11 */ "a.............a" + /* 12 */ "a.............a" + /* 13 */ "a.............a" + /* 14 */ "aaaaaa...aaaaaa" + + // Level 6 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmm...mmmmmm" + /* 1 */ "m.............m" + /* 2 */ "m.............m" + /* 3 */ "m.............m" + /* 4 */ "m.............m" + /* 5 */ "m....mmmmm....m" + /* 6 */ ".....mmmmm....." + /* 7 */ ".....mmmmm....." + /* 8 */ ".....mmmmm....." + /* 9 */ "m....mmmmm....m" + /* 10 */ "m.............m" + /* 11 */ "m.............m" + /* 12 */ "m.............m" + /* 13 */ "m.............m" + /* 14 */ "mmmmmm...mmmmmm" + + // Level 7 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmm...mmmmmm" + /* 1 */ "m.............m" + /* 2 */ "m.............m" + /* 3 */ "m.............m" + /* 4 */ "m.............m" + /* 5 */ "m....mmmmm....m" + /* 6 */ ".....mmmmm....." + /* 7 */ ".....mmmmm....." + /* 8 */ ".....mmmmm....." + /* 9 */ "m....mmmmm....m" + /* 10 */ "m.............m" + /* 11 */ "m.............m" + /* 12 */ "m.............m" + /* 13 */ "m.............m" + /* 14 */ "mmmmmm...mmmmmm", + + // Connectors: + "0: 0, 5, 7: 4\n" /* Type 0, direction X- */ + "0: 7, 5, 0: 2\n" /* Type 0, direction Z- */ + "0: 14, 5, 7: 5\n" /* Type 0, direction X+ */ + "0: 7, 5, 14: 3\n" /* Type 0, direction Z+ */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 5, + + // DepthWeight: + "", + + // AddWeightIfSame: + -1000, + }, // BridgeCircleCrossing + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BridgeCrossing: - // The data has been exported from gallery Nether, area index 17, ID 159 + // The data has been exported from the gallery Nether, area index 17, ID 159, created by Aloe_vera { // Size: 15, 8, 15, // SizeX = 15, SizeY = 8, SizeZ = 15 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 17, 14, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -476,300 +831,808 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmmaaammmmmm" + /* 2 */ "mmmmmmmmmmmmmmm" + /* 3 */ "mmmmmmmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "aammmmmmmmmmmaa" + /* 7 */ "aammmmmmmmmmmaa" + /* 8 */ "aammmmmmmmmmmaa" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + /* 12 */ "mmmmmmmmmmmmmmm" + /* 13 */ "mmmmmmaaammmmmm" + /* 14 */ "mmmmmmaaammmmmm" + // Level 1 - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmmaaammmmmm" + /* 2 */ "mmmmmmbbbmmmmmm" + /* 3 */ "mmmmmmmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "aacmmmmmmmmmdaa" + /* 7 */ "aacmmmmmmmmmdaa" + /* 8 */ "aacmmmmmmmmmdaa" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + /* 12 */ "mmmmmmeeemmmmmm" + /* 13 */ "mmmmmmaaammmmmm" + /* 14 */ "mmmmmmaaammmmmm" // Level 2 - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmbbbmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "aacmmmmmmmmmdaa" - "aacmmmmmmmmmdaa" - "aacmmmmmmmmmdaa" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmeeemmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmaaammmmmm" + /* 1 */ "mmmmmmaaammmmmm" + /* 2 */ "mmmmmmaaammmmmm" + /* 3 */ "mmmmmmbbbmmmmmm" + /* 4 */ "mmmmmmfffmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "aaacfmmmmmfdaaa" + /* 7 */ "aaacfmmmmmfdaaa" + /* 8 */ "aaacfmmmmmfdaaa" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmfffmmmmmm" + /* 11 */ "mmmmmmeeemmmmmm" + /* 12 */ "mmmmmmaaammmmmm" + /* 13 */ "mmmmmmaaammmmmm" + /* 14 */ "mmmmmmaaammmmmm" // Level 3 - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmbbbmmmmmm" - "mmmmmmfffmmmmmm" - "mmmmmmmmmmmmmmm" - "aaacfmmmmmfdaaa" - "aaacfmmmmmfdaaa" - "aaacfmmmmmfdaaa" - "mmmmmmmmmmmmmmm" - "mmmmmmfffmmmmmm" - "mmmmmmeeemmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmdaaacmmmmm" + /* 1 */ "mmmmmdaaacmmmmm" + /* 2 */ "mmmmmdaaacmmmmm" + /* 3 */ "mmmmmdaaacmmmmm" + /* 4 */ "mmmmmdaaacmmmmm" + /* 5 */ "eeeeeeaaaeeeeee" + /* 6 */ "aaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaa" + /* 9 */ "bbbbbdaaacbbbbb" + /* 10 */ "mmmmmdaaacmmmmm" + /* 11 */ "mmmmmdaaacmmmmm" + /* 12 */ "mmmmmdaaacmmmmm" + /* 13 */ "mmmmmdaaacmmmmm" + /* 14 */ "mmmmmdaaacmmmmm" // Level 4 - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "eeeeeeaaaeeeeee" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "bbbbbdaaacbbbbb" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" - "mmmmmdaaacmmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmaaaaammmmm" + /* 1 */ "mmmmmaaaaammmmm" + /* 2 */ "mmmmmaaaaammmmm" + /* 3 */ "mmmmmaaaaammmmm" + /* 4 */ "mmmmmaaaaammmmm" + /* 5 */ "aaaaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaaaa" + /* 10 */ "mmmmmaaaaammmmm" + /* 11 */ "mmmmmaaaaammmmm" + /* 12 */ "mmmmmaaaaammmmm" + /* 13 */ "mmmmmaaaaammmmm" + /* 14 */ "mmmmmaaaaammmmm" // Level 5 - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmma...ammmmm" + /* 1 */ "mmmmma...ammmmm" + /* 2 */ "mmmmma...ammmmm" + /* 3 */ "mmmmma...ammmmm" + /* 4 */ "mmmmma...ammmmm" + /* 5 */ "aaaaaa...aaaaaa" + /* 6 */ "..............." + /* 7 */ "..............." + /* 8 */ "..............." + /* 9 */ "aaaaaa...aaaaaa" + /* 10 */ "mmmmma...ammmmm" + /* 11 */ "mmmmma...ammmmm" + /* 12 */ "mmmmma...ammmmm" + /* 13 */ "mmmmma...ammmmm" + /* 14 */ "mmmmma...ammmmm" // Level 6 - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "aaaaaa...aaaaaa" - "..............." - "..............." - "..............." - "aaaaaa...aaaaaa" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmm...mmmmmm" + /* 1 */ "mmmmmm...mmmmmm" + /* 2 */ "mmmmmm...mmmmmm" + /* 3 */ "mmmmmm...mmmmmm" + /* 4 */ "mmmmmm...mmmmmm" + /* 5 */ "mmmmmm...mmmmmm" + /* 6 */ "..............." + /* 7 */ "..............." + /* 8 */ "..............." + /* 9 */ "mmmmmm...mmmmmm" + /* 10 */ "mmmmmm...mmmmmm" + /* 11 */ "mmmmmm...mmmmmm" + /* 12 */ "mmmmmm...mmmmmm" + /* 13 */ "mmmmmm...mmmmmm" + /* 14 */ "mmmmmm...mmmmmm" // Level 7 - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "..............." - "..............." - "..............." - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - - // Level 8 - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "..............." - "..............." - "..............." - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm", - - // Connections: - "0: 0, 5, 7: 4\n" /* Type 0, BLOCK_FACE_XM */ - "0: 7, 5, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "0: 14, 5, 7: 5\n" /* Type 0, BLOCK_FACE_XP */ - "0: 7, 5, 14: 3\n" /* Type 0, BLOCK_FACE_ZP */, + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmm...mmmmmm" + /* 1 */ "mmmmmm...mmmmmm" + /* 2 */ "mmmmmm...mmmmmm" + /* 3 */ "mmmmmm...mmmmmm" + /* 4 */ "mmmmmm...mmmmmm" + /* 5 */ "mmmmmm...mmmmmm" + /* 6 */ "..............." + /* 7 */ "..............." + /* 8 */ "..............." + /* 9 */ "mmmmmm...mmmmmm" + /* 10 */ "mmmmmm...mmmmmm" + /* 11 */ "mmmmmm...mmmmmm" + /* 12 */ "mmmmmm...mmmmmm" + /* 13 */ "mmmmmm...mmmmmm" + /* 14 */ "mmmmmm...mmmmmm", + + // Connectors: + "0: 0, 5, 7: 4\n" /* Type 0, direction X- */ + "0: 7, 5, 0: 2\n" /* Type 0, direction Z- */ + "0: 7, 5, 14: 3\n" /* Type 0, direction Z+ */ + "0: 14, 5, 7: 5\n" /* Type 0, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "1:1000", + + // AddWeightIfSame: + 0, }, // BridgeCrossing + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BridgeCrumble1: - // The data has been exported from gallery Nether, area index 19, ID 161 + // The data has been exported from the gallery Nether, area index 19, ID 161, created by Aloe_vera { // Size: 9, 6, 5, // SizeX = 9, SizeY = 6, SizeZ = 5 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 8, 15, 4, // MaxX, MaxY, MaxZ + // Block definitions: - ".: 19: 0\n" /* sponge */ + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:114: 5\n" /* netherbrickstairs */ "c: 44:14\n" /* step */ "d:114: 6\n" /* netherbrickstairs */ - "e:114: 7\n" /* netherbrickstairs */, + "e:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 012345678 */ + /* 0 */ "mmmmmmmmm" + /* 1 */ "aammmmmmm" + /* 2 */ "aammmmmmm" + /* 3 */ "aammmmmmm" + /* 4 */ "mmmmmmmmm" + // Level 1 - "........." - "aa......." - "aa......." - "aa......." - "........." + /* z\x* 012345678 */ + /* 0 */ "mmmmmmmmm" + /* 1 */ "aabmmmmmm" + /* 2 */ "aabmmmmmm" + /* 3 */ "aabmmmmmm" + /* 4 */ "mmmmmmmmm" // Level 2 - "........." - "aab......" - "aab......" - "aab......" - "........." + /* z\x* 012345678 */ + /* 0 */ "mmmmmmmmm" + /* 1 */ "aaabcmmmm" + /* 2 */ "aaabcmmmm" + /* 3 */ "aaabcmmmm" + /* 4 */ "mmmmmmmmm" // Level 3 - "........." - "aaabc...." - "aaabc...." - "aaabc...." - "........." + /* z\x* 012345678 */ + /* 0 */ "dddddddmm" + /* 1 */ "aaaaaaaam" + /* 2 */ "aaaaaaaaa" + /* 3 */ "aaaaaaamm" + /* 4 */ "eeeeemmmm" // Level 4 - "ddddddd.." - "aaaaaaaa." - "aaaaaaaaa" - "aaaaaaa.." - "eeeee...." + /* z\x* 012345678 */ + /* 0 */ "aaaaaaaaa" + /* 1 */ "aaaaammmm" + /* 2 */ "aaaaaammm" + /* 3 */ "aaaaaammm" + /* 4 */ "aaaaaaaam" // Level 5 - "aaaaaaaaa" - "aaaaa...." - "aaaaaa..." - "aaaaaa..." - "aaaaaaaa." + /* z\x* 012345678 */ + /* 0 */ "aaaaaammm" + /* 1 */ "mmmmmmmmm" + /* 2 */ "mmmmmmmmm" + /* 3 */ "mmmmmmmmm" + /* 4 */ "aaaaaaamm", - // Level 6 - "aaaaaa..." - "........." - "........." - "........." - "aaaaaaa..", - - // Connections: - "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */, + // Connectors: + "1: 0, 5, 2: 4\n" /* Type 1, direction X- */ + "0: 0, 5, 2: 4\n" /* Type 0, direction X- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|2:0|3:0|4:0|5:0", + + // AddWeightIfSame: + 0, }, // BridgeCrumble1 + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // BridgeCrumble2 - // The data has been exported from gallery Nether, area index 18, ID 160 + // BridgeCrumble2: + // The data has been exported from the gallery Nether, area index 18, ID 160, created by Aloe_vera { // Size: 13, 6, 5, // SizeX = 13, SizeY = 6, SizeZ = 5 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 15, 4, // MaxX, MaxY, MaxZ + // Block definitions: - ".: 19: 0\n" /* sponge */ + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:114: 5\n" /* netherbrickstairs */ "c: 44:14\n" /* step */ "d:114: 6\n" /* netherbrickstairs */ - "e:114: 7\n" /* netherbrickstairs */, + "e:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmm" + /* 2 */ "aammmmmmmmmmm" + /* 3 */ "aammmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmm" + + // Level 1 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmmmmmmmmmm" + /* 1 */ "aabmmmmmmmmmm" + /* 2 */ "aabmmmmmmmmmm" + /* 3 */ "aabmmmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmm" + + // Level 2 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmmmmmmmmmm" + /* 1 */ "aaabcmmmmmmmm" + /* 2 */ "aaabcmmmmmmmm" + /* 3 */ "aaabcmmmmmmmm" + /* 4 */ "mmmmmmmmmmmmm" + + // Level 3 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "dddddddddmmmm" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaammmm" + /* 3 */ "aaaaaaaaaaaam" + /* 4 */ "eeeeeeeeemmmm" + + // Level 4 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaam" + /* 1 */ "aaaaaaaaaammm" + /* 2 */ "aaaaaaaaaaamm" + /* 3 */ "aaaaaaaaammmm" + /* 4 */ "aaaaaaaaaaaaa" + + // Level 5 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaammmm" + /* 1 */ "mmmmmmmmmmmmm" + /* 2 */ "mmmmmmmmmmmmm" + /* 3 */ "mmmmmmmmmmmmm" + /* 4 */ "aaaaaaaaaammm", + + // Connectors: + "0: 0, 5, 2: 4\n" /* Type 0, direction X- */ + "1: 0, 5, 2: 4\n" /* Type 1, direction X- */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|2:0|3:0|4:0|5:0", + + // AddWeightIfSame: + 0, + }, // BridgeCrumble2 + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeDoubleCrumble: + // The data has been exported from the gallery Nether, area index 46, ID 305, created by STR_Warrior + { + // Size: + 5, 7, 16, // SizeX = 5, SizeY = 7, SizeZ = 16 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 4, 16, 15, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 7\n" /* netherbrickstairs */ + "c:114: 6\n" /* netherbrickstairs */ + "d:114: 4\n" /* netherbrickstairs */ + "e:114: 5\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 01234 */ + /* 0 */ "maaam" + /* 1 */ "maaam" + /* 2 */ "mmmmm" + /* 3 */ "mmmmm" + /* 4 */ "mmmmm" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmmm" + /* 11 */ "mmmmm" + /* 12 */ "mmmmm" + /* 13 */ "mmmmm" + /* 14 */ "maaam" + /* 15 */ "maaam" + // Level 1 - "............." - "aa..........." - "aa..........." - "aa..........." - "............." + /* z\x* 01234 */ + /* 0 */ "maaam" + /* 1 */ "maaam" + /* 2 */ "mbbbm" + /* 3 */ "mmmmm" + /* 4 */ "mmmmm" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmmm" + /* 11 */ "mmmmm" + /* 12 */ "mmmmm" + /* 13 */ "mcccm" + /* 14 */ "maaam" + /* 15 */ "maaam" // Level 2 - "............." - "aab.........." - "aab.........." - "aab.........." - "............." + /* z\x* 01234 */ + /* 0 */ "daaae" + /* 1 */ "daaae" + /* 2 */ "daaae" + /* 3 */ "daaae" + /* 4 */ "daaae" + /* 5 */ "mamae" + /* 6 */ "mmmam" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmae" + /* 11 */ "dmaae" + /* 12 */ "daaae" + /* 13 */ "daaae" + /* 14 */ "daaae" + /* 15 */ "daaae" // Level 3 - "............." - "aaabc........" - "aaabc........" - "aaabc........" - "............." + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaama" + /* 4 */ "mamaa" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmma" + /* 11 */ "mmmaa" + /* 12 */ "amaaa" + /* 13 */ "aaaaa" + /* 14 */ "aaaaa" + /* 15 */ "aaaaa" // Level 4 - "ddddddddd...." - "aaaaaaaaaaaaa" - "aaaaaaaaa...." - "aaaaaaaaaaaa." - "eeeeeeeee...." + /* z\x* 01234 */ + /* 0 */ "ammma" + /* 1 */ "ammma" + /* 2 */ "ammma" + /* 3 */ "mmmma" + /* 4 */ "mmmmm" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmmm" + /* 11 */ "mmmma" + /* 12 */ "mmmmm" + /* 13 */ "ammma" + /* 14 */ "ammma" + /* 15 */ "ammma" // Level 5 - "aaaaaaaaaaaa." - "aaaaaaaaaa..." - "aaaaaaaaaaa.." - "aaaaaaaaa...." - "aaaaaaaaaaaaa" + /* z\x* 01234 */ + /* 0 */ "mmmmm" + /* 1 */ "mmmmm" + /* 2 */ "mmmmm" + /* 3 */ "mmmmm" + /* 4 */ "mmmmm" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmmm" + /* 11 */ "mmmmm" + /* 12 */ "mmmmm" + /* 13 */ "mmmmm" + /* 14 */ "mmmmm" + /* 15 */ "mmmmm" // Level 6 - "aaaaaaaaa...." - "............." - "............." - "............." - "aaaaaaaaaa...", + /* z\x* 01234 */ + /* 0 */ "mmmmm" + /* 1 */ "mmmmm" + /* 2 */ "mmmmm" + /* 3 */ "mmmmm" + /* 4 */ "mmmmm" + /* 5 */ "mmmmm" + /* 6 */ "mmmmm" + /* 7 */ "mmmmm" + /* 8 */ "mmmmm" + /* 9 */ "mmmmm" + /* 10 */ "mmmmm" + /* 11 */ "mmmmm" + /* 12 */ "mmmmm" + /* 13 */ "mmmmm" + /* 14 */ "mmmmm" + /* 15 */ "mmmmm", + + // Connectors: + "0: 2, 4, 0: 2\n" /* Type 0, direction Z- */ + "0: 2, 4, 15: 3\n" /* Type 0, direction Z+ */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, - // Connections: - "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */, + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "", + + // AddWeightIfSame: + 1000, + }, // BridgeDoubleCrumble + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeFunnelDown: + // The data has been exported from the gallery Nether, area index 0, ID 2, created by Aloe_vera + { + // Size: + 15, 12, 12, // SizeX = 15, SizeY = 12, SizeZ = 12 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 21, 11, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 6\n" /* netherbrickstairs */ + "c:114: 4\n" /* netherbrickstairs */ + "d:114: 5\n" /* netherbrickstairs */ + "e: 44:14\n" /* step */ + "f:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmaaammmmmm" + /* 10 */ "mmmmmmaaammmmmm" + /* 11 */ "mmmmmmaaammmmmm" + + // Level 1 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmbbbmmmmmm" + /* 9 */ "mmmmmmaaammmmmm" + /* 10 */ "mmmmmmaaammmmmm" + /* 11 */ "mmmmmmaaammmmmm" + + // Level 2 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmcbbbdmmmmm" + /* 8 */ "mmmmmcaaadmmmmm" + /* 9 */ "mmmmmcaaadmmmmm" + /* 10 */ "mmmmmcaaadmmmmm" + /* 11 */ "mmmmmcaaadmmmmm" + + // Level 3 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmaaaaammmmm" + /* 8 */ "mmmmmaaaaammmmm" + /* 9 */ "mmmmmaaaaammmmm" + /* 10 */ "mmmmmaaaaammmmm" + /* 11 */ "mmmmmaaaaammmmm" + + // Level 4 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmcbbbbbdmmmm" + /* 7 */ "mmmmaaaaaaammmm" + /* 8 */ "mmmma.....ammmm" + /* 9 */ "mmmmaa...aammmm" + /* 10 */ "mmmmma...ammmmm" + /* 11 */ "mmmmma...ammmmm" + + // Level 5 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aadmmmmmmmmmcaa" + /* 2 */ "aadmmmmmmmmmcaa" + /* 3 */ "aadmmmmmmmmmcaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmcbbbbbbbdmmm" + /* 6 */ "mmmaaaaaaaaaamm" + /* 7 */ "mmma.......ammm" + /* 8 */ "mmmaa.....aammm" + /* 9 */ "mmmmam...mammmm" + /* 10 */ "mmmmmm...mmmmmm" + /* 11 */ "mmmmmm...mmmmmm" + + // Level 6 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aaademmmmmecaaa" + /* 2 */ "aaademmmmmecaaa" + /* 3 */ "aaademmmmmecaaa" + /* 4 */ "mmaaabbbbbaaaam" + /* 5 */ "mmaaaaaaaaaaaam" + /* 6 */ "mma.........amm" + /* 7 */ "mmaa.......aamm" + /* 8 */ "mmmam.....mammm" + /* 9 */ "mmmmmm...mmmmmm" + /* 10 */ "mmmmmm...mmmmmm" + /* 11 */ "mmmmmm...mmmmmm" + + // Level 7 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "bbbbbbbbbbbbbbb" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "faaaaaaaaaaaaaa" + /* 5 */ "ma...........am" + /* 6 */ "maa.........aam" + /* 7 */ "mmam.......mamm" + /* 8 */ "mmmmm.....mmmmm" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + + // Level 8 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "a.............a" + /* 5 */ "aa...........aa" + /* 6 */ "mam.........mam" + /* 7 */ "mmmm.......mmmm" + /* 8 */ "mmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + + // Level 9 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "a.............a" + /* 5 */ "am............a" + /* 6 */ "mmm.........mmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + + // Level 10 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "m.............m" + /* 5 */ "mm............m" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm" + + // Level 11 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "m.............m" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmm", + + // Connectors: + "0: 7, 4, 11: 3\n" /* Type 0, direction Z+ */ + "0: 0, 9, 2: 4\n" /* Type 0, direction X- */ + "0: 14, 9, 2: 5\n" /* Type 0, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, - }, // BridgeCrumble2 + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 5, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // BridgeFunnelDown + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // BridgeSegment: - // The data has been exported from gallery Nether, area index 16, ID 158 + // BridgeLevelCrossing: + // The data has been exported from the gallery Nether, area index 61, ID 321, created by Aloe_vera { // Size: - 15, 8, 5, // SizeX = 15, SizeY = 8, SizeZ = 5 + 16, 14, 16, // SizeX = 16, SizeY = 14, SizeZ = 16 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 15, 23, 15, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ @@ -782,80 +1645,443 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" + // Level 1 - "mmmmmmmmmmmmmmm" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "mmmmmmmmmmmmmmm" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmmmmm" + /* 1 */ "aabmmmmmmmmmmcaa" + /* 2 */ "aabmmmmmmmmmmcaa" + /* 3 */ "aabmmmmmmmmmmcaa" + /* 4 */ "mmmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 2 - "mmmmmmmmmmmmmmm" - "aabmmmmmmmmmcaa" - "aabmmmmmmmmmcaa" - "aabmmmmmmmmmcaa" - "mmmmmmmmmmmmmmm" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmmmmm" + /* 1 */ "aaabdmmmmmmdcaaa" + /* 2 */ "aaabdmmmmmmdcaaa" + /* 3 */ "aaabdmmmmmmdcaaa" + /* 4 */ "mmmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 3 - "mmmmmmmmmmmmmmm" - "aaabdmmmmmdcaaa" - "aaabdmmmmmdcaaa" - "aaabdmmmmmdcaaa" - "mmmmmmmmmmmmmmm" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "eeeeeeeeeeeeeeee" + /* 1 */ "aaaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaaa" + /* 4 */ "ffffffffffffffff" + /* 5 */ "mmmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 4 - "eeeeeeeeeeeeeee" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "fffffffffffffff" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaaa" + /* 5 */ "faaabmmmmmmmmmmm" + /* 6 */ "caaabmmmmmmmmmmm" + /* 7 */ "caaabmmmmmmmmmmm" + /* 8 */ "mmmmmmmmmmmmmmmm" + /* 9 */ "mmmmmmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 5 - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "................" + /* 2 */ "................" + /* 3 */ "................" + /* 4 */ "a...aaaaaaaaaaaa" + /* 5 */ "a...ammmmmmmmmmm" + /* 6 */ "aaaaammmmmmmmmmm" + /* 7 */ "aaaaammmmmmmmmmm" + /* 8 */ "caaabmmmmmmmmmmm" + /* 9 */ "caaabmmmmmmmmmmm" + /* 10 */ "mmmmmmmmmmmmmmmm" + /* 11 */ "mmmmmmmmmmmmmmmm" + /* 12 */ "maaammmmmmmmmmmm" + /* 13 */ "maaammmmmmmmmmmm" + /* 14 */ "maaammmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 6 - "aaaaaaaaaaaaaaa" - "..............." - "..............." - "..............." - "aaaaaaaaaaaaaaa" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmaaam" + /* 1 */ "................" + /* 2 */ "................" + /* 3 */ "................" + /* 4 */ "m...mmmmmmmmaaam" + /* 5 */ "a...ammmmmmmmmmm" + /* 6 */ "a...ammmmmmmmmmm" + /* 7 */ "a...ammmmmmmmmmm" + /* 8 */ "aaaaammmmmmmmmmm" + /* 9 */ "aaaaammmmmmmmmmm" + /* 10 */ "caaabmmmmmmmmmmm" + /* 11 */ "caaabmmmmmmmmmmm" + /* 12 */ "maaabmmmmmmmmmmm" + /* 13 */ "maaabmmmmmmmmmmm" + /* 14 */ "maaafmmmmmmmaaam" + /* 15 */ "mmmmmmmmmmmmaaam" // Level 7 - "mmmmmmmmmmmmmmm" - "..............." - "..............." - "..............." - "mmmmmmmmmmmmmmm" + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmaaam" + /* 1 */ "................" + /* 2 */ "................" + /* 3 */ "................" + /* 4 */ "m...mmmmmmmmaaam" + /* 5 */ "m...mmmmmmmmmmmm" + /* 6 */ "m...mmmmmmmmmmmm" + /* 7 */ "a...ammmmmmmmmmm" + /* 8 */ "a...ammmmmmmmmmm" + /* 9 */ "a...ammmmmmmmmmm" + /* 10 */ "aaaaammmmmmmmmmm" + /* 11 */ "aaaaaeemmmmmmmmm" + /* 12 */ "caaaaaammmmmmmmm" + /* 13 */ "caaaaaammmmmmmmm" + /* 14 */ "caaaaaammmmmaaam" + /* 15 */ "fffffffmmmmmaaam" // Level 8 - "mmmmmmmmmmmmmmm" - "..............." - "..............." - "..............." - "mmmmmmmmmmmmmmm", + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmmaaam" + /* 1 */ "mmmmmmmmmmmmmmmm" + /* 2 */ "mmmmmmmmmmmmmmmm" + /* 3 */ "mmmmmmmmmmmmmmmm" + /* 4 */ "m...mmmmmmmmaaam" + /* 5 */ "m...mmmmmmmmmmmm" + /* 6 */ "m...mmmmmmmmmmmm" + /* 7 */ "m...mmmmmmmmmmmm" + /* 8 */ "m...mmmmmmmmmmmm" + /* 9 */ "a...ammmmmmmmmmm" + /* 10 */ "a...ammmmmmmmmmm" + /* 11 */ "a...aaaeemmmmmmm" + /* 12 */ "a.....aaammmmmmm" + /* 13 */ "a.....aaammmmmmm" + /* 14 */ "a.....aaammmaaam" + /* 15 */ "aaaaaaaffmmmaaam" + + // Level 9 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmcaaab" + /* 1 */ "mmmmmmmmmmmcaaab" + /* 2 */ "mmmmmmmmmmmcaaab" + /* 3 */ "mmmmmmmmmmmcaaab" + /* 4 */ "mmmmmmmmmmmcaaab" + /* 5 */ "mmmmmmmmmmmcaaab" + /* 6 */ "m...mmmmmmmcaaab" + /* 7 */ "m...mmmmmmmcaaab" + /* 8 */ "m...mmmmmmmcaaab" + /* 9 */ "m...mmmmmmmcaaab" + /* 10 */ "m...mmmmmmmcaaab" + /* 11 */ "m...maaaaeecaaab" + /* 12 */ "m.......aaaaaaab" + /* 13 */ "m.......aaaaaaab" + /* 14 */ "m.......aaaaaaab" + /* 15 */ "mmmmmaaaafffaaab" + + // Level 10 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmaaaaa" + /* 1 */ "mmmmmmmmmmmaaaaa" + /* 2 */ "mmmmmmmmmmmaaaaa" + /* 3 */ "mmmmmmmmmmmaaaaa" + /* 4 */ "mmmmmmmmmmmaaaaa" + /* 5 */ "mmmmmmmmmmmaaaaa" + /* 6 */ "mmmmmmmmmmmaaaaa" + /* 7 */ "mmmmmmmmmmmaaaaa" + /* 8 */ "m...mmmmmmmaaaaa" + /* 9 */ "m...mmmmmmmaaaaa" + /* 10 */ "m...mmmmmmmaaaaa" + /* 11 */ "m...mmmaaaaaaaaa" + /* 12 */ "m.........aaaaaa" + /* 13 */ "m.........aaaaaa" + /* 14 */ "m.........aaaaaa" + /* 15 */ "mmmmmmmaaaaaaaaa" + + // Level 11 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmma...a" + /* 1 */ "mmmmmmmmmmma...a" + /* 2 */ "mmmmmmmmmmma...a" + /* 3 */ "mmmmmmmmmmma...a" + /* 4 */ "mmmmmmmmmmma...a" + /* 5 */ "mmmmmmmmmmma...a" + /* 6 */ "mmmmmmmmmmma...a" + /* 7 */ "mmmmmmmmmmma...a" + /* 8 */ "mmmmmmmmmmma...a" + /* 9 */ "mmmmmmmmmmma...a" + /* 10 */ "mmmmmmmmmmma...a" + /* 11 */ "mmmmmmmmmaaa...a" + /* 12 */ "mmmm...........a" + /* 13 */ "mmmm...........a" + /* 14 */ "mmmm...........a" + /* 15 */ "mmmmmmmmmaaa...a" + + // Level 12 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmm...m" + /* 1 */ "mmmmmmmmmmmm...m" + /* 2 */ "mmmmmmmmmmmm...m" + /* 3 */ "mmmmmmmmmmmm...m" + /* 4 */ "mmmmmmmmmmmm...m" + /* 5 */ "mmmmmmmmmmmm...m" + /* 6 */ "mmmmmmmmmmmm...m" + /* 7 */ "mmmmmmmmmmmm...m" + /* 8 */ "mmmmmmmmmmmm...m" + /* 9 */ "mmmmmmmmmmmm...m" + /* 10 */ "mmmmmmmmmmmm...m" + /* 11 */ "mmmmmmmmmmmm...m" + /* 12 */ "mmmmmm.........m" + /* 13 */ "mmmmmm.........m" + /* 14 */ "mmmmmm.........m" + /* 15 */ "mmmmmmmmmmmm...m" + + // Level 13 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "mmmmmmmmmmmm...m" + /* 1 */ "mmmmmmmmmmmm...m" + /* 2 */ "mmmmmmmmmmmm...m" + /* 3 */ "mmmmmmmmmmmm...m" + /* 4 */ "mmmmmmmmmmmm...m" + /* 5 */ "mmmmmmmmmmmm...m" + /* 6 */ "mmmmmmmmmmmm...m" + /* 7 */ "mmmmmmmmmmmm...m" + /* 8 */ "mmmmmmmmmmmm...m" + /* 9 */ "mmmmmmmmmmmm...m" + /* 10 */ "mmmmmmmmmmmm...m" + /* 11 */ "mmmmmmmmmmmm...m" + /* 12 */ "mmmmmmmm.......m" + /* 13 */ "mmmmmmmm.......m" + /* 14 */ "mmmmmmmm.......m" + /* 15 */ "mmmmmmmmmmmm...m", + + // Connectors: + "0: 0, 5, 2: 4\n" /* Type 0, direction X- */ + "0: 15, 5, 2: 5\n" /* Type 0, direction X+ */ + "0: 13, 11, 0: 2\n" /* Type 0, direction Z- */ + "0: 13, 11, 15: 3\n" /* Type 0, direction Z+ */, - // Connections: - "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */ - "0: 14, 5, 2: 5\n" /* Type 0, BLOCK_FACE_XP */, + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 20, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // BridgeLevelCrossing + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // BridgeSegment: + // The data has been exported from the gallery Nether, area index 16, ID 158, created by Aloe_vera + { + // Size: + 15, 8, 5, // SizeX = 15, SizeY = 8, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 17, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 5\n" /* netherbrickstairs */ + "c:114: 4\n" /* netherbrickstairs */ + "d: 44:14\n" /* step */ + "e:114: 6\n" /* netherbrickstairs */ + "f:114: 7\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + + // Level 1 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aabmmmmmmmmmcaa" + /* 2 */ "aabmmmmmmmmmcaa" + /* 3 */ "aabmmmmmmmmmcaa" + /* 4 */ "mmmmmmmmmmmmmmm" + + // Level 2 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aaabdmmmmmdcaaa" + /* 2 */ "aaabdmmmmmdcaaa" + /* 3 */ "aaabdmmmmmdcaaa" + /* 4 */ "mmmmmmmmmmmmmmm" + + // Level 3 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "eeeeeeeeeeeeeee" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "fffffffffffffff" + + // Level 4 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaa" + + // Level 5 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "aaaaaaaaaaaaaaa" + + // Level 6 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "mmmmmmmmmmmmmmm" + + // Level 7 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "mmmmmmmmmmmmmmm", + + // Connectors: + "0: 0, 5, 2: 4\n" /* Type 0, direction X- */ + "0: 14, 5, 2: 5\n" /* Type 0, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 500, + + // DepthWeight: + "4:-3000|8:-3000|12:-3000|16:-3000|20:-3000", + + // AddWeightIfSame: + 1000, }, // BridgeSegment + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BridgeTee: - // The data has been exported from gallery Nether, area index 39, ID 290 + // The data has been exported from the gallery Nether, area index 39, ID 290, created by STR_Warrior { // Size: 15, 8, 10, // SizeX = 15, SizeY = 8, SizeZ = 10 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 17, 9, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -867,258 +2093,452 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aammmmmmmmmmmaa" + /* 2 */ "aammmmmmmmmmmaa" + /* 3 */ "aammmmmmmmmmmaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmmmmmmmmmm" + /* 8 */ "mmmmmmaaammmmmm" + /* 9 */ "mmmmmmaaammmmmm" + // Level 1 - "mmmmmmmmmmmmmmm" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "aammmmmmmmmmmaa" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aabmmmmmmmmmcaa" + /* 2 */ "aabmmmmmmmmmcaa" + /* 3 */ "aabmmmmmmmmmcaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmmmmmmmmmm" + /* 6 */ "mmmmmmmmmmmmmmm" + /* 7 */ "mmmmmmdddmmmmmm" + /* 8 */ "mmmmmmaaammmmmm" + /* 9 */ "mmmmmmaaammmmmm" // Level 2 - "mmmmmmmmmmmmmmm" - "aabmmmmmmmmmcaa" - "aabmmmmmmmmmcaa" - "aabmmmmmmmmmcaa" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmmmmmmmmmm" - "mmmmmmdddmmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "aaabemmmmmecaaa" + /* 2 */ "aaabemmmmmecaaa" + /* 3 */ "aaabemmmmmecaaa" + /* 4 */ "mmmmmmmmmmmmmmm" + /* 5 */ "mmmmmmeeemmmmmm" + /* 6 */ "mmmmmmdddmmmmmm" + /* 7 */ "mmmmmmaaammmmmm" + /* 8 */ "mmmmmmaaammmmmm" + /* 9 */ "mmmmmmaaammmmmm" // Level 3 - "mmmmmmmmmmmmmmm" - "aaabemmmmmecaaa" - "aaabemmmmmecaaa" - "aaabemmmmmecaaa" - "mmmmmmmmmmmmmmm" - "mmmmmmeeemmmmmm" - "mmmmmmdddmmmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" - "mmmmmmaaammmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "ddddddddddddddd" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "fffffcaaabfffff" + /* 5 */ "mmmmmcaaabmmmmm" + /* 6 */ "mmmmmcaaabmmmmm" + /* 7 */ "mmmmmcaaabmmmmm" + /* 8 */ "mmmmmcaaabmmmmm" + /* 9 */ "mmmmmcaaabmmmmm" // Level 4 - "ddddddddddddddd" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "fffffcaaabfffff" - "mmmmmcaaabmmmmm" - "mmmmmcaaabmmmmm" - "mmmmmcaaabmmmmm" - "mmmmmcaaabmmmmm" - "mmmmmcaaabmmmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaa" + /* 5 */ "mmmmmaaaaammmmm" + /* 6 */ "mmmmmaaaaammmmm" + /* 7 */ "mmmmmaaaaammmmm" + /* 8 */ "mmmmmaaaaammmmm" + /* 9 */ "mmmmmaaaaammmmm" // Level 5 - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" - "mmmmmaaaaammmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "aaaaaa...aaaaaa" + /* 5 */ "mmmmma...ammmmm" + /* 6 */ "mmmmma...ammmmm" + /* 7 */ "mmmmma...ammmmm" + /* 8 */ "mmmmma...ammmmm" + /* 9 */ "mmmmma...ammmmm" // Level 6 - "aaaaaaaaaaaaaaa" - "..............." - "..............." - "..............." - "aaaaaa...aaaaaa" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" - "mmmmma...ammmmm" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "mmmmmm...mmmmmm" + /* 5 */ "mmmmmm...mmmmmm" + /* 6 */ "mmmmmm...mmmmmm" + /* 7 */ "mmmmmm...mmmmmm" + /* 8 */ "mmmmmm...mmmmmm" + /* 9 */ "mmmmmm...mmmmmm" // Level 7 - "mmmmmmmmmmmmmmm" - "..............." - "..............." - "..............." - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - - // Level 8 - "mmmmmmmmmmmmmmm" - "..............." - "..............." - "..............." - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm" - "mmmmmm...mmmmmm", - - // Connections: - "0: 0, 5, 2: 4\n" /* Type 0, BLOCK_FACE_XM */ - "0: 14, 5, 2: 5\n" /* Type 0, BLOCK_FACE_XP */ - "0: 7, 5, 9: 3\n" /* Type 0, BLOCK_FACE_ZP */, + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "mmmmmmmmmmmmmmm" + /* 1 */ "..............." + /* 2 */ "..............." + /* 3 */ "..............." + /* 4 */ "mmmmmm...mmmmmm" + /* 5 */ "mmmmmm...mmmmmm" + /* 6 */ "mmmmmm...mmmmmm" + /* 7 */ "mmmmmm...mmmmmm" + /* 8 */ "mmmmmm...mmmmmm" + /* 9 */ "mmmmmm...mmmmmm", + + // Connectors: + "0: 0, 5, 2: 4\n" /* Type 0, direction X- */ + "0: 7, 5, 9: 3\n" /* Type 0, direction Z+ */ + "0: 14, 5, 2: 5\n" /* Type 0, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "1:500", + + // AddWeightIfSame: + 0, }, // BridgeTee + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Corridor11: - // The data has been exported from gallery Nether, area index 36, ID 287 + // The data has been exported from the gallery Nether, area index 36, ID 287, created by Aloe_vera { // Size: 11, 6, 5, // SizeX = 11, SizeY = 6, SizeZ = 5 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 10, 5, 4, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:113: 0\n" /* netherbrickfence */ "c:114: 2\n" /* netherbrickstairs */ - "d:114: 3\n" /* netherbrickstairs */, + "d:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "..........." + /* 2 */ "..........." + /* 3 */ "..........." + /* 4 */ "aaaaaaaaaaa" // Level 2 - "aaaaaaaaaaa" - "..........." - "..........." - "..........." - "aaaaaaaaaaa" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "..........." + /* 2 */ "..........." + /* 3 */ "..........." + /* 4 */ "abababababa" // Level 3 - "abababababa" - "..........." - "..........." - "..........." - "abababababa" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "..........." + /* 2 */ "..........." + /* 3 */ "..........." + /* 4 */ "abababababa" // Level 4 - "abababababa" - "..........." - "..........." - "..........." - "abababababa" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "..........." + /* 2 */ "..........." + /* 3 */ "..........." + /* 4 */ "abababababa" // Level 5 - "abababababa" - "..........." - "..........." - "..........." - "abababababa" - - // Level 6 - "ccccccccccc" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "ddddddddddd", - - // Connections: - "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "ccccccccccc" + /* 1 */ "aaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaa" + /* 4 */ "ddddddddddd", + + // Connectors: + "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 300, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // Corridor11 + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Corridor13: - // The data has been exported from gallery Nether, area index 35, ID 286 + // The data has been exported from the gallery Nether, area index 35, ID 286, created by Aloe_vera { // Size: 13, 6, 5, // SizeX = 13, SizeY = 6, SizeZ = 5 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 5, 4, // MaxX, MaxY, MaxZ + // Block definitions: - "a:112: 0\n" /* netherbrick */ ".: 0: 0\n" /* air */ - "c:113: 0\n" /* netherbrickfence */ - "d:114: 2\n" /* netherbrickstairs */ - "e:114: 3\n" /* netherbrickstairs */, + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "aaaaaaaaaaaaa" // Level 2 - "aaaaaaaaaaaaa" - "............." - "............." - "............." - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "ababababababa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "ababababababa" // Level 3 - "acacacacacaca" - "............." - "............." - "............." - "acacacacacaca" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "ababababababa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "ababababababa" // Level 4 - "acacacacacaca" - "............." - "............." - "............." - "acacacacacaca" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "ababababababa" + /* 1 */ "............." + /* 2 */ "............." + /* 3 */ "............." + /* 4 */ "ababababababa" // Level 5 - "acacacacacaca" - "............." - "............." - "............." - "acacacacacaca" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "ccccccccccccc" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "ddddddddddddd", + + // Connectors: + "1: 12, 1, 2: 5\n" /* Type 1, direction X+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 12, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, - // Level 6 - "ddddddddddddd" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "eeeeeeeeeeeee", - - // Connections: - "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 12, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 300, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // Corridor13 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Corridor5: + // The data has been exported from the gallery Nether, area index 65, ID 330, created by xoft + { + // Size: + 5, 6, 5, // SizeX = 5, SizeY = 6, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 4, 5, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "aaaaa" + + // Level 1 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "aaaaa" + + // Level 2 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "ababa" + + // Level 3 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "ababa" + + // Level 4 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "ababa" + + // Level 5 + /* z\x* 01234 */ + /* 0 */ "ccccc" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "ddddd", + + // Connectors: + "1: 4, 1, 2: 5\n" /* Type 1, direction X+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 4, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 500, + + // DepthWeight: + "6:0|12:0|18:0", + + // AddWeightIfSame: + 500, + }, // Corridor5 + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CorridorCorner5: - // The data has been exported from gallery Nether, area index 10, ID 40 + // The data has been exported from the gallery Nether, area index 10, ID 40, created by xoft { // Size: 11, 6, 11, // SizeX = 11, SizeY = 6, SizeZ = 11 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 10, 5, 10, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -1130,211 +2550,399 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaa" + /* 5 */ "aaaaa......" + /* 6 */ "aaaaa......" + /* 7 */ "aaaaa......" + /* 8 */ "aaaaa......" + /* 9 */ "aaaaa......" + /* 10 */ "aaaaa......" + // Level 1 - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "a.........." + /* 2 */ "a.........." + /* 3 */ "a.........." + /* 4 */ "a...aaaaaaa" + /* 5 */ "a...a......" + /* 6 */ "a...a......" + /* 7 */ "a...a......" + /* 8 */ "a...a......" + /* 9 */ "a...a......" + /* 10 */ "a...a......" // Level 2 - "aaaaaaaaaaa" - "a.........." - "a.........." - "a.........." - "a...aaaaaaa" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "b.........." + /* 2 */ "a.........." + /* 3 */ "b.........." + /* 4 */ "a...abababa" + /* 5 */ "b...b......" + /* 6 */ "a...a......" + /* 7 */ "b...b......" + /* 8 */ "a...a......" + /* 9 */ "b...b......" + /* 10 */ "a...a......" // Level 3 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "b.........." + /* 2 */ "a.........." + /* 3 */ "b.........." + /* 4 */ "a...abababa" + /* 5 */ "b...b......" + /* 6 */ "a...a......" + /* 7 */ "b...b......" + /* 8 */ "a...a......" + /* 9 */ "b...b......" + /* 10 */ "a...a......" // Level 4 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "abababababa" + /* 1 */ "b.........." + /* 2 */ "a.........." + /* 3 */ "b.........." + /* 4 */ "a...abababa" + /* 5 */ "b...b......" + /* 6 */ "a...a......" + /* 7 */ "b...b......" + /* 8 */ "a...a......" + /* 9 */ "b...b......" + /* 10 */ "a...a......" // Level 5 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - - // Level 6 - "ccccccccccc" - "daaaaaaaaaa" - "daaaaaaaaaa" - "daaaaaaaaaa" - "daaaeeeeeee" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm", - - // Connections: - "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */ - "1: 2, 1, 10: 3\n" /* Type 1, BLOCK_FACE_ZP */, + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "ccccccccccc" + /* 1 */ "daaaaaaaaaa" + /* 2 */ "daaaaaaaaaa" + /* 3 */ "daaaaaaaaaa" + /* 4 */ "daaaeeeeeee" + /* 5 */ "daaaf......" + /* 6 */ "daaaf......" + /* 7 */ "daaaf......" + /* 8 */ "daaaf......" + /* 9 */ "daaaf......" + /* 10 */ "daaaf......", + + // Connectors: + "1: 2, 1, 10: 3\n" /* Type 1, direction Z+ */ + "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ + "-1: 2, 1, 10: 3\n" /* Type -1, direction Z+ */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // CorridorCorner5 - // CorridorCorner5: - // The data has been exported from gallery Nether, area index 10, ID 40 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // CorridorCornerChest5: + // The data has been exported from the gallery Nether, area index 42, ID 293, created by STR_Warrior { // Size: 11, 6, 11, // SizeX = 11, SizeY = 6, SizeZ = 11 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 10, 5, 10, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ - "b:113: 0\n" /* netherbrickfence */ - "c:114: 2\n" /* netherbrickstairs */ + "b: 54: 5\n" /* chest */ + "c:113: 0\n" /* netherbrickfence */ "d:114: 0\n" /* netherbrickstairs */ - "e:114: 3\n" /* netherbrickstairs */ + "e:114: 2\n" /* netherbrickstairs */ "f:114: 1\n" /* netherbrickstairs */ - "g: 54: 5\n" /* chest */ + "g:114: 3\n" /* netherbrickstairs */ "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaa" + /* 5 */ "aaaaammmmmm" + /* 6 */ "aaaaammmmmm" + /* 7 */ "aaaaammmmmm" + /* 8 */ "aaaaammmmmm" + /* 9 */ "aaaaammmmmm" + /* 10 */ "aaaaammmmmm" + // Level 1 - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaaaaaaaa" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" - "aaaaammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "aaaaaaaaaaa" + /* 1 */ "ab........." + /* 2 */ "a.........." + /* 3 */ "a.........." + /* 4 */ "a...aaaaaaa" + /* 5 */ "a...ammmmmm" + /* 6 */ "a...ammmmmm" + /* 7 */ "a...ammmmmm" + /* 8 */ "a...ammmmmm" + /* 9 */ "a...ammmmmm" + /* 10 */ "a...ammmmmm" // Level 2 - "aaaaaaaaaaa" - "ag........." - "a.........." - "a.........." - "a...aaaaaaa" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "acacacacaca" + /* 1 */ "c.........." + /* 2 */ "a.........." + /* 3 */ "c.........." + /* 4 */ "a...acacaca" + /* 5 */ "c...cmmmmmm" + /* 6 */ "a...ammmmmm" + /* 7 */ "c...cmmmmmm" + /* 8 */ "a...ammmmmm" + /* 9 */ "c...cmmmmmm" + /* 10 */ "a...ammmmmm" // Level 3 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "acacacacaca" + /* 1 */ "c.........." + /* 2 */ "a.........." + /* 3 */ "c.........." + /* 4 */ "a...acacaca" + /* 5 */ "c...cmmmmmm" + /* 6 */ "a...ammmmmm" + /* 7 */ "c...cmmmmmm" + /* 8 */ "a...ammmmmm" + /* 9 */ "c...cmmmmmm" + /* 10 */ "a...ammmmmm" // Level 4 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "acacacacaca" + /* 1 */ "c.........." + /* 2 */ "a.........." + /* 3 */ "c.........." + /* 4 */ "a...acacaca" + /* 5 */ "c...cmmmmmm" + /* 6 */ "a...ammmmmm" + /* 7 */ "c...cmmmmmm" + /* 8 */ "a...ammmmmm" + /* 9 */ "c...cmmmmmm" + /* 10 */ "a...ammmmmm" // Level 5 - "abababababa" - "b.........." - "a.........." - "b.........." - "a...abababa" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" - "b...bmmmmmm" - "a...ammmmmm" + /* z\x* 1 */ + /* * 01234567890 */ + /* 0 */ "deeeeeeeeee" + /* 1 */ "daaaaaaaaaa" + /* 2 */ "daaaaaaaaaa" + /* 3 */ "daaaaaaaaaa" + /* 4 */ "daaafgggggg" + /* 5 */ "daaafmmmmmm" + /* 6 */ "daaafmmmmmm" + /* 7 */ "daaafmmmmmm" + /* 8 */ "daaafmmmmmm" + /* 9 */ "daaafmmmmmm" + /* 10 */ "daaafmmmmmm", + + // Connectors: + "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ + "1: 2, 1, 10: 3\n" /* Type 1, direction Z+ */ + "-1: 2, 1, 10: 3\n" /* Type -1, direction Z+ */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */, - // Level 6 - "ccccccccccc" - "daaaaaaaaaa" - "daaaaaaaaaa" - "daaaaaaaaaa" - "daaaeeeeeee" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm" - "daaafmmmmmm", - - // Connections: - "1: 10, 1, 2: 5\n" /* Type 1, BLOCK_FACE_XP */ - "1: 2, 1, 10: 3\n" /* Type 1, BLOCK_FACE_ZP */, + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // CorridorCornerChest5 + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // CorridorCrossing: + // The data has been exported from the gallery Nether, area index 63, ID 328, created by xoft + { + // Size: + 9, 6, 9, // SizeX = 9, SizeY = 6, SizeZ = 9 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 8, 5, 8, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 0\n" /* netherbrickstairs */ + "d:114: 1\n" /* netherbrickstairs */ + "e:114: 2\n" /* netherbrickstairs */ + "f:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 012345678 */ + /* 0 */ "mmaaaaamm" + /* 1 */ "mmaaaaamm" + /* 2 */ "aaaaaaaaa" + /* 3 */ "aaaaaaaaa" + /* 4 */ "aaaaaaaaa" + /* 5 */ "aaaaaaaaa" + /* 6 */ "aaaaaaaaa" + /* 7 */ "mmaaaaamm" + /* 8 */ "mmaaaaamm" + + // Level 1 + /* z\x* 012345678 */ + /* 0 */ "mma...amm" + /* 1 */ "mma...amm" + /* 2 */ "aaa...aaa" + /* 3 */ "........." + /* 4 */ "........." + /* 5 */ "........." + /* 6 */ "aaa...aaa" + /* 7 */ "mma...amm" + /* 8 */ "mma...amm" + + // Level 2 + /* z\x* 012345678 */ + /* 0 */ "mma...amm" + /* 1 */ "mmb...bmm" + /* 2 */ "aba...aba" + /* 3 */ "........." + /* 4 */ "........." + /* 5 */ "........." + /* 6 */ "aba...aba" + /* 7 */ "mmb...bmm" + /* 8 */ "mma...amm" + + // Level 3 + /* z\x* 012345678 */ + /* 0 */ "mma...amm" + /* 1 */ "mmb...bmm" + /* 2 */ "aba...aba" + /* 3 */ "........." + /* 4 */ "........." + /* 5 */ "........." + /* 6 */ "aba...aba" + /* 7 */ "mmb...bmm" + /* 8 */ "mma...amm" + + // Level 4 + /* z\x* 012345678 */ + /* 0 */ "mma...amm" + /* 1 */ "mmb...bmm" + /* 2 */ "aba...aba" + /* 3 */ "........." + /* 4 */ "........." + /* 5 */ "........." + /* 6 */ "aba...aba" + /* 7 */ "mmb...bmm" + /* 8 */ "mma...amm" + + // Level 5 + /* z\x* 012345678 */ + /* 0 */ "mmcaaadmm" + /* 1 */ "mmcaaadmm" + /* 2 */ "eeeaaaeee" + /* 3 */ "aaaaaaaaa" + /* 4 */ "aaaaaaaaa" + /* 5 */ "aaaaaaaaa" + /* 6 */ "ffcaaadff" + /* 7 */ "mmcaaadmm" + /* 8 */ "mmcaaadmm", + + // Connectors: + "1: 8, 1, 4: 5\n" /* Type 1, direction X+ */ + "1: 4, 1, 0: 2\n" /* Type 1, direction Z- */ + "1: 4, 1, 8: 3\n" /* Type 1, direction Z+ */ + "1: 0, 1, 4: 4\n" /* Type 1, direction X- */ + "-1: 8, 1, 4: 5\n" /* Type -1, direction X+ */ + "-1: 4, 1, 8: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 4: 4\n" /* Type -1, direction X- */ + "-1: 4, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, - }, // CorridorCorner5Chest + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + -50, + }, // CorridorCrossing + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CorridorStairs: - // The data has been exported from gallery Nether, area index 12, ID 42 + // The data has been exported from the gallery Nether, area index 12, ID 42, created by xoft { // Size: 9, 13, 5, // SizeX = 9, SizeY = 13, SizeZ = 5 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 8, 12, 4, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -1342,611 +2950,1118 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "c:113: 0\n" /* netherbrickfence */ "d:114: 2\n" /* netherbrickstairs */ "e:114: 3\n" /* netherbrickstairs */ - "f: 19: 0\n" /* sponge */, + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 012345678 */ + /* 0 */ "aaaaaaaaa" + /* 1 */ "aaaaaaaaa" + /* 2 */ "aaaaaaaaa" + /* 3 */ "aaaaaaaaa" + /* 4 */ "aaaaaaaaa" + // Level 1 - "aaaaaaaaa" - "aaaaaaaaa" - "aaaaaaaaa" - "aaaaaaaaa" - "aaaaaaaaa" + /* z\x* 012345678 */ + /* 0 */ "aaaaaaaaa" + /* 1 */ ".baaaaaaa" + /* 2 */ ".baaaaaaa" + /* 3 */ ".baaaaaaa" + /* 4 */ "aaaaaaaaa" // Level 2 - "aaaaaaaaa" - ".baaaaaaa" - ".baaaaaaa" - ".baaaaaaa" - "aaaaaaaaa" + /* z\x* 012345678 */ + /* 0 */ "acaaaaaaa" + /* 1 */ "..baaaaaa" + /* 2 */ "..baaaaaa" + /* 3 */ "..baaaaaa" + /* 4 */ "acaaaaaaa" // Level 3 - "acaaaaaaa" - "..baaaaaa" - "..baaaaaa" - "..baaaaaa" - "acaaaaaaa" + /* z\x* 012345678 */ + /* 0 */ "acaaaaaaa" + /* 1 */ "...baaaaa" + /* 2 */ "...baaaaa" + /* 3 */ "...baaaaa" + /* 4 */ "acaaaaaaa" // Level 4 - "acaaaaaaa" - "...baaaaa" - "...baaaaa" - "...baaaaa" - "acaaaaaaa" + /* z\x* 012345678 */ + /* 0 */ "acacaaaaa" + /* 1 */ "....baaaa" + /* 2 */ "....baaaa" + /* 3 */ "....baaaa" + /* 4 */ "acacaaaaa" // Level 5 - "acacaaaaa" - "....baaaa" - "....baaaa" - "....baaaa" - "acacaaaaa" + /* z\x* 012345678 */ + /* 0 */ "aaacaaaaa" + /* 1 */ ".....baaa" + /* 2 */ ".....baaa" + /* 3 */ ".....baaa" + /* 4 */ "aaacaaaaa" // Level 6 - "aaacaaaaa" - ".....baaa" - ".....baaa" - ".....baaa" - "aaacaaaaa" + /* z\x* 012345678 */ + /* 0 */ "daacacaaa" + /* 1 */ "a.....baa" + /* 2 */ "a.....baa" + /* 3 */ "a.....baa" + /* 4 */ "eaacacaaa" // Level 7 - "daacacaaa" - "a.....baa" - "a.....baa" - "a.....baa" - "eaacacaaa" + /* z\x* 012345678 */ + /* 0 */ "mdaaacaaa" + /* 1 */ "ma.....ba" + /* 2 */ "ma.....ba" + /* 3 */ "ma.....ba" + /* 4 */ "meaaacaaa" // Level 8 - "fdaaacaaa" - "fa.....ba" - "fa.....ba" - "fa.....ba" - "feaaacaaa" + /* z\x* 012345678 */ + /* 0 */ "mmdaacaca" + /* 1 */ "mma......" + /* 2 */ "mma......" + /* 3 */ "mma......" + /* 4 */ "mmeaacaca" // Level 9 - "ffdaacaca" - "ffa......" - "ffa......" - "ffa......" - "ffeaacaca" + /* z\x* 012345678 */ + /* 0 */ "mmmdaaaca" + /* 1 */ "mmma....." + /* 2 */ "mmma....." + /* 3 */ "mmma....." + /* 4 */ "mmmeaaaca" // Level 10 - "fffdaaaca" - "fffa....." - "fffa....." - "fffa....." - "fffeaaaca" + /* z\x* 012345678 */ + /* 0 */ "mmmmdaaca" + /* 1 */ "mmmma...." + /* 2 */ "mmmma...." + /* 3 */ "mmmma...." + /* 4 */ "mmmmeaaca" // Level 11 - "ffffdaaca" - "ffffa...." - "ffffa...." - "ffffa...." - "ffffeaaca" + /* z\x* 012345678 */ + /* 0 */ "mmmmmdaaa" + /* 1 */ "mmmmma..." + /* 2 */ "mmmmma..." + /* 3 */ "mmmmma..." + /* 4 */ "mmmmmeaaa" // Level 12 - "fffffdaaa" - "fffffa..." - "fffffa..." - "fffffa..." - "fffffeaaa" + /* z\x* 012345678 */ + /* 0 */ "mmmmmmddd" + /* 1 */ "mmmmmmaaa" + /* 2 */ "mmmmmmaaa" + /* 3 */ "mmmmmmaaa" + /* 4 */ "mmmmmmeee", + + // Connectors: + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "1: 8, 8, 2: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 8, 8, 2: 5\n" /* Type -1, direction X+ */, - // Level 13 - "ffffffddd" - "ffffffaaa" - "ffffffaaa" - "ffffffaaa" - "ffffffeee", - - // Connections: - "1: 0, 1, 2: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 8, 8, 2: 5\n" /* Type 1, BLOCK_FACE_XP */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 1000, + + // DepthWeight: + "0:0|2:0|4:0|6:0|8:0|10:0|12:0|14:0|16:0|18:0", + + // AddWeightIfSame: + 0, }, // CorridorStairs + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // DarkCorridor: + // The data has been exported from the gallery Nether, area index 3, ID 30, created by STR_Warrior + { + // Size: + 14, 6, 5, // SizeX = 14, SizeY = 6, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 13, 5, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 3\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "aaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaa" + + // Level 1 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "aaaaaaaaaaaaaa" + /* 1 */ ".............." + /* 2 */ ".............." + /* 3 */ ".............." + /* 4 */ "aaaaaaaaaaaaaa" + + // Level 2 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "aabaaaaaaaabaa" + /* 1 */ ".............." + /* 2 */ ".............." + /* 3 */ ".............." + /* 4 */ "aabaaaaaaaabaa" + + // Level 3 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "aabaaaaaaaabaa" + /* 1 */ ".............." + /* 2 */ ".............." + /* 3 */ ".............." + /* 4 */ "aabaaaaaaaabaa" + + // Level 4 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "aabaaaaaaaabaa" + /* 1 */ ".............." + /* 2 */ ".............." + /* 3 */ ".............." + /* 4 */ "aabaaaaaaaabaa" + + // Level 5 + /* z\x* 1111 */ + /* * 01234567890123 */ + /* 0 */ "cccccccccccccc" + /* 1 */ "aaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaa" + /* 4 */ "dddddddddddddd", + + // Connectors: + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "1: 13, 1, 2: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 13, 1, 2: 5\n" /* Type -1, direction X+ */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // DarkCorridor + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LavaStaircase: - // The data has been exported from gallery Nether, area index 28, ID 278 + // The data has been exported from the gallery Nether, area index 28, ID 278, created by Aloe_vera { // Size: 15, 11, 15, // SizeX = 15, SizeY = 11, SizeZ = 15 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 14, 10, 14, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b:113: 0\n" /* netherbrickfence */ - "c: 11: 0\n" /* lava */, + "c: 10: 0\n" /* lava */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaa...aaaa" + /* 1 */ "aaaaa.........a" + /* 2 */ "aaaaa.........a" + /* 3 */ "aaaaab........a" + /* 4 */ "accca...aaaa..a" + /* 5 */ "accca...acca..a" + /* 6 */ "acccaaaaacca..a" + /* 7 */ "acccccccccca..a" + /* 8 */ "acccaaaaacca..a" + /* 9 */ "accca...acca..a" + /* 10 */ "accca...aaaa..a" + /* 11 */ "aaaaab........a" + /* 12 */ "aaaaa.........a" + /* 13 */ "aaaaa.........a" + /* 14 */ "aaaaaaaa...aaaa" // Level 2 - "aaaaaaaa...aaaa" - "aaaaa.........a" - "aaaaa.........a" - "aaaaab........a" - "accca...aaaa..a" - "accca...acca..a" - "acccaaaaacca..a" - "acccccccccca..a" - "acccaaaaacca..a" - "accca...acca..a" - "accca...aaaa..a" - "aaaaab........a" - "aaaaa.........a" - "aaaaa.........a" - "aaaaaaaa...aaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaa...aaaa" + /* 1 */ "aaaa..........a" + /* 2 */ "aaaa..........a" + /* 3 */ "aaaabb........a" + /* 4 */ "aaaa..........a" + /* 5 */ "a.............a" + /* 6 */ "a.............a" + /* 7 */ "a.............a" + /* 8 */ "a.............a" + /* 9 */ "a.............a" + /* 10 */ "aaaa..........a" + /* 11 */ "aaaabb........a" + /* 12 */ "aaaa..........a" + /* 13 */ "aaaa..........a" + /* 14 */ "aaaaaaaa...aaaa" // Level 3 - "aaaaaaaa...aaaa" - "aaaa..........a" - "aaaa..........a" - "aaaabb........a" - "aaaa..........a" - "a.............a" - "a.............a" - "a.............a" - "a.............a" - "a.............a" - "aaaa..........a" - "aaaabb........a" - "aaaa..........a" - "aaaa..........a" - "aaaaaaaa...aaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaa...aaaa" + /* 1 */ "a.............a" + /* 2 */ "a.............a" + /* 3 */ "a..bb.........a" + /* 4 */ "aaaa..........a" + /* 5 */ "aaaa..........a" + /* 6 */ "a.............a" + /* 7 */ "a.............a" + /* 8 */ "a.............a" + /* 9 */ "aaaa..........a" + /* 10 */ "aaaa..........a" + /* 11 */ "a..bb.........a" + /* 12 */ "a.............a" + /* 13 */ "a.............a" + /* 14 */ "aaaaaaaa...aaaa" // Level 4 - "aaaaaaaa...aaaa" - "a.............a" - "a.............a" - "a..bb.........a" - "aaaa..........a" - "aaaa..........a" - "a.............a" - "a.............a" - "a.............a" - "aaaa..........a" - "aaaa..........a" - "a..bb.........a" - "a.............a" - "a.............a" - "aaaaaaaa...aaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaa...aaaa" + /* 1 */ "a.............a" + /* 2 */ "a.............a" + /* 3 */ "a..b..........a" + /* 4 */ "a..b..........a" + /* 5 */ "aaaa..........a" + /* 6 */ "aaaa..........a" + /* 7 */ "a.............a" + /* 8 */ "aaaa..........a" + /* 9 */ "aaaa..........a" + /* 10 */ "a..b..........a" + /* 11 */ "a..b..........a" + /* 12 */ "a.............a" + /* 13 */ "a.............a" + /* 14 */ "aaaaaaaa...aaaa" // Level 5 - "aaaaaaaabbbaaaa" - "a.............a" - "a.............a" - "a..b..........a" - "a..b..........a" - "aaaa..........a" - "aaaa..........a" - "a.............a" - "aaaa..........a" - "aaaa..........a" - "a..b..........a" - "a..b..........a" - "a.............a" - "a.............a" - "aaaaaaaabbbaaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "a.............a" + /* 2 */ "a.............a" + /* 3 */ "a.............a" + /* 4 */ "a..b..........a" + /* 5 */ "a..b..........a" + /* 6 */ "aaaa..........a" + /* 7 */ "aaaa..........a" + /* 8 */ "aaaa..........a" + /* 9 */ "a..b..........a" + /* 10 */ "a..b..........a" + /* 11 */ "a.............a" + /* 12 */ "a.............a" + /* 13 */ "a.............a" + /* 14 */ "aaaaaaaaaaaaaaa" // Level 6 - "aaaaaaaaaaaaaaa" - "a.............a" - "a.............a" - "a.............a" - "a..b..........a" - "a..b..........a" - "aaaa..........a" - "aaaa..........a" - "aaaa..........a" - "a..b..........a" - "a..b..........a" - "a.............a" - "a.............a" - "a.............a" - "aaaaaaaaaaaaaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "a.............a" + /* 2 */ "a.............a" + /* 3 */ "a.............a" + /* 4 */ "a.............a" + /* 5 */ "a..b..........a" + /* 6 */ "...b..........a" + /* 7 */ "...b..........a" + /* 8 */ "...b..........a" + /* 9 */ "a..b..........a" + /* 10 */ "a.............a" + /* 11 */ "a.............a" + /* 12 */ "a.............a" + /* 13 */ "a.............a" + /* 14 */ "aaaaaaaaaaaaaaa" // Level 7 - "aaaaaaaaaaaaaaa" - "a.............a" - "a.............a" - "a.............a" - "a.............a" - "a..b..........a" - "...b..........a" - "...b..........a" - "...b..........a" - "a..b..........a" - "a.............a" - "a.............a" - "a.............a" - "a.............a" - "aaaaaaaaaaaaaaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aababababababaa" + /* 1 */ "a.............a" + /* 2 */ "b.............b" + /* 3 */ "a.............a" + /* 4 */ "b.............b" + /* 5 */ "a.............a" + /* 6 */ "..............b" + /* 7 */ "..............a" + /* 8 */ "..............b" + /* 9 */ "a.............a" + /* 10 */ "b.............b" + /* 11 */ "a.............a" + /* 12 */ "b.............b" + /* 13 */ "a.............a" + /* 14 */ "aababababababaa" // Level 8 - "aababababababaa" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "..............b" - "..............a" - "..............b" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "aababababababaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aababababababaa" + /* 1 */ "a.............a" + /* 2 */ "b.............b" + /* 3 */ "a.............a" + /* 4 */ "b.............b" + /* 5 */ "a.............a" + /* 6 */ "..............b" + /* 7 */ "..............a" + /* 8 */ "..............b" + /* 9 */ "a.............a" + /* 10 */ "b.............b" + /* 11 */ "a.............a" + /* 12 */ "b.............b" + /* 13 */ "a.............a" + /* 14 */ "aababababababaa" // Level 9 - "aababababababaa" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "..............b" - "..............a" - "..............b" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "aababababababaa" + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aababababababaa" + /* 1 */ "a.............a" + /* 2 */ "b.............b" + /* 3 */ "a.............a" + /* 4 */ "b.............b" + /* 5 */ "a.............a" + /* 6 */ "..............b" + /* 7 */ "..............a" + /* 8 */ "..............b" + /* 9 */ "a.............a" + /* 10 */ "b.............b" + /* 11 */ "a.............a" + /* 12 */ "b.............b" + /* 13 */ "a.............a" + /* 14 */ "aababababababaa" // Level 10 - "aababababababaa" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "..............b" - "..............a" - "..............b" - "a.............a" - "b.............b" - "a.............a" - "b.............b" - "a.............a" - "aababababababaa" - - // Level 11 - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaa", - - // Connections: - "1: 0, 6, 7: 4\n" /* Type 1, BLOCK_FACE_XM */ - "0: 9, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "0: 9, 1, 14: 3\n" /* Type 0, BLOCK_FACE_ZP */, + /* z\x* 11111 */ + /* * 012345678901234 */ + /* 0 */ "aaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaaaaa", + + // Connectors: + "1: 0, 6, 7: 4\n" /* Type 1, direction X- */ + "1: 9, 1, 14: 3\n" /* Type 1, direction Z+ */ + "1: 9, 1, 0: 2\n" /* Type 1, direction Z- */ + "-1: 0, 6, 7: 4\n" /* Type -1, direction X- */ + "-1: 9, 1, 14: 3\n" /* Type -1, direction Z+ */ + "-1: 9, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // LavaStaircase + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LavaStaircaseBig: - // The data has been exported from gallery Nether, area index 31, ID 282 + // The data has been exported from the gallery Nether, area index 31, ID 282, created by STR_Warrior { // Size: 12, 15, 15, // SizeX = 12, SizeY = 15, SizeZ = 15 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 11, 14, 14, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ "b: 10: 0\n" /* lava */ - "c:113: 0\n" /* netherbrickfence */, + "c:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaa" + /* 4 */ "abbbbbaaaaaa" + /* 5 */ "abbbbbbaaaaa" + /* 6 */ "abbbbbba...." + /* 7 */ "abbbbbba...." + /* 8 */ "abbbbbba...." + /* 9 */ "abbbbbbaaaaa" + /* 10 */ "abbbbb.aaaaa" + /* 11 */ "aaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaa" // Level 2 - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "abbbbbaaaaaa" - "abbbbbbaaaaa" - "abbbbbba...." - "abbbbbba...." - "abbbbbba...." - "abbbbbbaaaaa" - "abbbbb.aaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaa" + /* 4 */ "abbbbbaaaaaa" + /* 5 */ "abbbbbba...a" + /* 6 */ "abbbbbba...." + /* 7 */ "abbbbbba...." + /* 8 */ "abbbbbba...." + /* 9 */ "abbbbbba...a" + /* 10 */ "abbbbb.aaaaa" + /* 11 */ "aaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaa" // Level 3 - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "abbbbbaaaaaa" - "abbbbbba...a" - "abbbbbba...." - "abbbbbba...." - "abbbbbba...." - "abbbbbba...a" - "abbbbb.aaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaa" + /* 4 */ "abbbbbaa...a" + /* 5 */ "abbbbbba...a" + /* 6 */ "abbbbbba...." + /* 7 */ "abbbbbba...." + /* 8 */ "abbbbbba...." + /* 9 */ "abbbbbba...a" + /* 10 */ "abbbbbaa...a" + /* 11 */ "aaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaa" // Level 4 - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "abbbbbaa...a" - "abbbbbba...a" - "abbbbbba...." - "abbbbbba...." - "abbbbbba...." - "abbbbbba...a" - "abbbbbaa...a" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaa......a" + /* 2 */ "aaaaa......a" + /* 3 */ "aaaaacc....a" + /* 4 */ "a.....cc...a" + /* 5 */ "a......c...a" + /* 6 */ "a......c...a" + /* 7 */ "a......c...a" + /* 8 */ "a......c...a" + /* 9 */ "a......c...a" + /* 10 */ "a.....cc...a" + /* 11 */ "aaaaacc....a" + /* 12 */ "aaaaa......a" + /* 13 */ "aaaaa......a" + /* 14 */ "aaaaaaaaaaaa" // Level 5 - "aaaaaaaaaaaa" - "aaaaa......a" - "aaaaa......a" - "aaaaacc....a" - "a.....cc...a" - "a......c...a" - "a......c...." - "a......c...." - "a......c...." - "a......c...a" - "a.....cc...a" - "aaaaacc....a" - "aaaaa......a" - "aaaaa......a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaa.......a" + /* 2 */ "aaaa.......a" + /* 3 */ "aaaacc.....a" + /* 4 */ "aaaa.......a" + /* 5 */ "a..........a" + /* 6 */ "a..........a" + /* 7 */ "a..........a" + /* 8 */ "a..........a" + /* 9 */ "a..........a" + /* 10 */ "aaaa.......a" + /* 11 */ "aaaacc.....a" + /* 12 */ "aaaa.......a" + /* 13 */ "aaaa.......a" + /* 14 */ "aaaaaaaaaaaa" // Level 6 - "aaaaaaaaaaaa" - "aaaa.......a" - "aaaa.......a" - "aaaacc.....a" - "aaaa.......a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "aaaa.......a" - "aaaacc.....a" - "aaaa.......a" - "aaaa.......a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..cc......a" + /* 4 */ "aaaa.......a" + /* 5 */ "aaaa.......a" + /* 6 */ "a..........a" + /* 7 */ "a..........a" + /* 8 */ "a..........a" + /* 9 */ "aaaa.......a" + /* 10 */ "aaaa.......a" + /* 11 */ "a..cc......a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 7 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..cc......a" - "aaaa.......a" - "aaaa.......a" - "a..........a" - "a..........a" - "a..........a" - "aaaa.......a" - "aaaa.......a" - "a..cc......a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..c.......a" + /* 4 */ "a..c.......a" + /* 5 */ "aaaa.......a" + /* 6 */ "aaaa.......a" + /* 7 */ "a..........a" + /* 8 */ "aaaa.......a" + /* 9 */ "aaaa.......a" + /* 10 */ "a..c.......a" + /* 11 */ "a..c.......a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 8 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..c.......a" - "a..c.......a" - "aaaa.......a" - "aaaa.......a" - "a..........a" - "aaaa.......a" - "aaaa.......a" - "a..c.......a" - "a..c.......a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..........a" + /* 4 */ "a..c.......a" + /* 5 */ "a..c.......a" + /* 6 */ "aaaa.......a" + /* 7 */ "aaaa.......a" + /* 8 */ "aaaa.......a" + /* 9 */ "a..c.......a" + /* 10 */ "a..c.......a" + /* 11 */ "a..........a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 9 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..........a" - "a..c.......a" - "a..c.......a" - "aaaa.......a" - "aaaa.......a" - "aaaa.......a" - "a..c.......a" - "a..c.......a" - "a..........a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..........a" + /* 4 */ "a..........a" + /* 5 */ "a..c.......a" + /* 6 */ "...c.......a" + /* 7 */ "...c.......a" + /* 8 */ "...c.......a" + /* 9 */ "a..c.......a" + /* 10 */ "a..........a" + /* 11 */ "a..........a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 10 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..c.......a" - "...c.......a" - "...c.......a" - "...c.......a" - "a..c.......a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..........a" + /* 4 */ "a..........a" + /* 5 */ "a..........a" + /* 6 */ "...........a" + /* 7 */ "...........a" + /* 8 */ "...........a" + /* 9 */ "a..........a" + /* 10 */ "a..........a" + /* 11 */ "a..........a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 11 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "...........a" - "...........a" - "...........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..........a" + /* 4 */ "a..........a" + /* 5 */ "a..........a" + /* 6 */ "...........a" + /* 7 */ "...........a" + /* 8 */ "...........a" + /* 9 */ "a..........a" + /* 10 */ "a..........a" + /* 11 */ "a..........a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 12 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "...........a" - "...........a" - "...........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "a..........a" + /* 2 */ "a..........a" + /* 3 */ "a..........a" + /* 4 */ "a..........a" + /* 5 */ "a..........a" + /* 6 */ "a..........a" + /* 7 */ "a..........a" + /* 8 */ "a..........a" + /* 9 */ "a..........a" + /* 10 */ "a..........a" + /* 11 */ "a..........a" + /* 12 */ "a..........a" + /* 13 */ "a..........a" + /* 14 */ "aaaaaaaaaaaa" // Level 13 - "aaaaaaaaaaaa" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "...........a" - "...........a" - "...........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "a..........a" - "aaaaaaaaaaaa" + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaa" // Level 14 - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - "aaaaaaaaaaaa" - - // Level 15 - "aaaaaaaaaaaa" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "abbbbbbbbbba" - "aaaaaaaaaaaa", - - // Connections: - "1: 0, 9, 7: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 11, 1, 7: 5\n" /* Type 1, BLOCK_FACE_XP */, + /* z\x* 11 */ + /* * 012345678901 */ + /* 0 */ "aaaaaaaaaaaa" + /* 1 */ "abbbbbbbbbba" + /* 2 */ "abbbbbbbbbba" + /* 3 */ "abbbbbbbbbba" + /* 4 */ "abbbbbbbbbba" + /* 5 */ "abbbbbbbbbba" + /* 6 */ "abbbbbbbbbba" + /* 7 */ "abbbbbbbbbba" + /* 8 */ "abbbbbbbbbba" + /* 9 */ "abbbbbbbbbba" + /* 10 */ "abbbbbbbbbba" + /* 11 */ "abbbbbbbbbba" + /* 12 */ "abbbbbbbbbba" + /* 13 */ "abbbbbbbbbba" + /* 14 */ "aaaaaaaaaaaa", + + // Connectors: + "1: 11, 1, 7: 5\n" /* Type 1, direction X+ */ + "1: 0, 9, 7: 4\n" /* Type 1, direction X- */ + "-1: 11, 1, 7: 5\n" /* Type -1, direction X+ */ + "-1: 0, 9, 7: 4\n" /* Type -1, direction X- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "", + + // AddWeightIfSame: + -1000, }, // LavaStaircaseBig + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // LavaStairsBridge: + // The data has been exported from the gallery Nether, area index 30, ID 281, created by STR_Warrior + { + // Size: + 16, 12, 15, // SizeX = 16, SizeY = 12, SizeZ = 15 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 15, 11, 14, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c: 10: 0\n" /* lava */ + "d:114: 2\n" /* netherbrickstairs */ + "e:114: 3\n" /* netherbrickstairs */ + "f:114: 7\n" /* netherbrickstairs */ + "g: 44:14\n" /* step */ + "h:114: 6\n" /* netherbrickstairs */ + "i: 44: 6\n" /* step */ + "j:114: 0\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 1 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaa...aaaaa" + /* 1 */ "aaaaa..........a" + /* 2 */ "aaaaa..........a" + /* 3 */ "aaaaab.........a" + /* 4 */ "accca...ddd.aaaa" + /* 5 */ "accca...aaa.acca" + /* 6 */ "acccaaaaaaaaacca" + /* 7 */ "acccccccccccccca" + /* 8 */ "acccaaaaaaaaacca" + /* 9 */ "accca...aaa.acca" + /* 10 */ "accca...eee.aaaa" + /* 11 */ "aaaaab.........a" + /* 12 */ "aaaaa..........a" + /* 13 */ "aaaaa..........a" + /* 14 */ "aaaaaaaa...aaaaa" + + // Level 2 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaa...aaaaa" + /* 1 */ "aaaa...........a" + /* 2 */ "aaaa...........a" + /* 3 */ "aaaabb.........a" + /* 4 */ "aaaa........b..a" + /* 5 */ "a.......ddd....a" + /* 6 */ "a.......fff....a" + /* 7 */ "a.......ggg....a" + /* 8 */ "a.......hhh....a" + /* 9 */ "a.......eee....a" + /* 10 */ "aaaa........b..a" + /* 11 */ "aaaabb.........a" + /* 12 */ "aaaa...........a" + /* 13 */ "aaaa...........a" + /* 14 */ "aaaaaaaa...aaaaa" + + // Level 3 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaa...aaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a..bb..........a" + /* 4 */ "aaaa........b..a" + /* 5 */ "aaaa...........a" + /* 6 */ "a..............a" + /* 7 */ "a..............a" + /* 8 */ "a..............a" + /* 9 */ "aaaa...........a" + /* 10 */ "aaaa........b..a" + /* 11 */ "a..bb..........a" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaa...aaaaa" + + // Level 4 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaabbbaaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a..b...........a" + /* 4 */ "a..b........b..a" + /* 5 */ "aaaa...........a" + /* 6 */ "aaaa...........a" + /* 7 */ "a..............a" + /* 8 */ "aaaa...........a" + /* 9 */ "aaaa...........a" + /* 10 */ "a..b........b..a" + /* 11 */ "a..b...........a" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaabbbaaaaa" + + // Level 5 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a...........ggga" + /* 4 */ "a..b........iija" + /* 5 */ "a..b........iija" + /* 6 */ "aaaa........iija" + /* 7 */ "aaaa........iija" + /* 8 */ "aaaa........iija" + /* 9 */ "a..b........iija" + /* 10 */ "a..b........iija" + /* 11 */ "a...........ggga" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 6 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "a.............ga" + /* 2 */ "a............iia" + /* 3 */ "a..............a" + /* 4 */ "a..............a" + /* 5 */ "a..b...........a" + /* 6 */ "...b...........a" + /* 7 */ "...b...........a" + /* 8 */ "...b...........a" + /* 9 */ "a..b...........a" + /* 10 */ "a..............a" + /* 11 */ "a..............a" + /* 12 */ "a............iia" + /* 13 */ "a.............ga" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 7 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a..............a" + /* 4 */ "a..............a" + /* 5 */ "a..............a" + /* 6 */ "...............a" + /* 7 */ "...............a" + /* 8 */ "...............a" + /* 9 */ "a..............a" + /* 10 */ "a..............a" + /* 11 */ "a..............a" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 8 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a..............a" + /* 4 */ "a..............a" + /* 5 */ "a..............a" + /* 6 */ "...............a" + /* 7 */ "...............a" + /* 8 */ "...............a" + /* 9 */ "a..............a" + /* 10 */ "a..............a" + /* 11 */ "a..............a" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 9 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "a..............a" + /* 2 */ "a..............a" + /* 3 */ "a..............a" + /* 4 */ "a..............a" + /* 5 */ "a..............a" + /* 6 */ "a..............a" + /* 7 */ "a..............a" + /* 8 */ "a..............a" + /* 9 */ "a..............a" + /* 10 */ "a..............a" + /* 11 */ "a..............a" + /* 12 */ "a..............a" + /* 13 */ "a..............a" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 10 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "aaaaaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaaaaa" + /* 13 */ "aaaaaaaaaaaaaaaa" + /* 14 */ "aaaaaaaaaaaaaaaa" + + // Level 11 + /* z\x* 111111 */ + /* * 0123456789012345 */ + /* 0 */ "abbaabbaabbaabba" + /* 1 */ "b..............b" + /* 2 */ "a..............a" + /* 3 */ "b..............b" + /* 4 */ "a..............a" + /* 5 */ "b..............b" + /* 6 */ "a..............a" + /* 7 */ "b..............b" + /* 8 */ "a..............a" + /* 9 */ "b..............b" + /* 10 */ "a..............a" + /* 11 */ "b..............b" + /* 12 */ "a..............a" + /* 13 */ "b..............b" + /* 14 */ "abbaabbaabbaabba", + + // Connectors: + "", + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 10, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // LavaStairsBridge + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // MidStaircase: - // The data has been exported from gallery Nether, area index 23, ID 165 + // The data has been exported from the gallery Nether, area index 23, ID 165, created by Aloe_vera { // Size: 13, 8, 13, // SizeX = 13, SizeY = 8, SizeZ = 13 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 7, 12, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -1957,148 +4072,184 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "f:114: 1\n" /* netherbrickstairs */ "g:114: 2\n" /* netherbrickstairs */ "h: 10: 0\n" /* lava */ - "i:113: 0\n" /* netherbrickfence */, + "i:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaabbbbbaaaa" + /* 4 */ "aaaabbbbbaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "aaaabbbbbaaaa" + /* 9 */ "aaaabbbbbaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaabbbbbaaaa" - "aaaabbbbbaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaabbbbbaaaa" - "aaaabbbbbaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaacccccaaaa" + /* 4 */ "addecccccfdda" + /* 5 */ "...eaaaaad..." + /* 6 */ "...eaaaaa...." + /* 7 */ "...eaaaaag..." + /* 8 */ "agggcccccfgga" + /* 9 */ "aaaacccccaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" // Level 2 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaacccccaaaa" - "addecccccfdda" - "...eaaaaad..." - "...eaaaaa...." - "...eaaaaag..." - "agggcccccfgga" - "aaaacccccaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aha.......aha" + /* 2 */ "aaa.......aaa" + /* 3 */ "a...........a" + /* 4 */ "a...........a" + /* 5 */ "....eaaaa...." + /* 6 */ "....eaaaa...." + /* 7 */ "....eaaaa...." + /* 8 */ "a...........a" + /* 9 */ "a...........a" + /* 10 */ "aaa.......aaa" + /* 11 */ "aha.......aha" + /* 12 */ "aaaaaaaaaaaaa" // Level 3 - "aaaaaaaaaaaaa" - "aha.......aha" - "aaa.......aaa" - "a...........a" - "a...........a" - "....eaaaa...." - "....eaaaa...." - "....eaaaa...." - "a...........a" - "a...........a" - "aaa.......aaa" - "aha.......aha" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaiiaaaiiaaa" + /* 1 */ "a...........a" + /* 2 */ "a...........a" + /* 3 */ "a...........a" + /* 4 */ "a...........a" + /* 5 */ ".....eaaa...." + /* 6 */ ".....eaaa...." + /* 7 */ ".....eaaa...." + /* 8 */ "a...........a" + /* 9 */ "a...........a" + /* 10 */ "a...........a" + /* 11 */ "a...........a" + /* 12 */ "aaaiiaaaiiaaa" // Level 4 - "aaaiiaaaiiaaa" - "a...........a" - "a...........a" - "a...........a" - "a...........a" - ".....eaaa...." - ".....eaaa...." - ".....eaaa...." - "a...........a" - "a...........a" - "a...........a" - "a...........a" - "aaaiiaaaiiaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaiiaaaiiaaa" + /* 1 */ "a...........a" + /* 2 */ "a...........a" + /* 3 */ "a...........a" + /* 4 */ "a...........a" + /* 5 */ "......eaa...." + /* 6 */ "......eaa...." + /* 7 */ "......eaa...." + /* 8 */ "a...........a" + /* 9 */ "a...........a" + /* 10 */ "a...........a" + /* 11 */ "a...........a" + /* 12 */ "aaaiiaaaiiaaa" // Level 5 - "aaaiiaaaiiaaa" - "a...........a" - "a...........a" - "a...........a" - "a...........a" - "......eaa...." - "......eaa...." - "......eaa...." - "a...........a" - "a...........a" - "a...........a" - "a...........a" - "aaaiiaaaiiaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "a...........a" + /* 2 */ "a...........a" + /* 3 */ "a...........a" + /* 4 */ "a...........a" + /* 5 */ "a......ea...a" + /* 6 */ "a......ea...a" + /* 7 */ "a......ea...a" + /* 8 */ "a...........a" + /* 9 */ "a...........a" + /* 10 */ "a...........a" + /* 11 */ "a...........a" + /* 12 */ "aaaaaaaaaaaaa" // Level 6 - "aaaaaaaaaaaaa" - "a...........a" - "a...........a" - "a...........a" - "a...........a" - "a......ea...a" - "a......ea...a" - "a......ea...a" - "a...........a" - "a...........a" - "a...........a" - "a...........a" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaa....eaaaa" + /* 6 */ "aaaa....eaaaa" + /* 7 */ "aaaa....eaaaa" + /* 8 */ "aaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" // Level 7 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaa....eaaaa" - "aaaa....eaaaa" - "aaaa....eaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - - // Level 8 - "iaiaiaiaiaiai" - "a...........a" - "i...........i" - "a...........a" - "i...........i" - "a............" - "i............" - "a............" - "i...........i" - "a...........a" - "i...........i" - "a...........a" - "iaiaiaiaiaiai", - - // Connections: - "1: 0, 1, 6: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 12, 1, 6: 5\n" /* Type 1, BLOCK_FACE_XP */ - "1: 12, 7, 6: 5\n" /* Type 1, BLOCK_FACE_XP */, + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "iaiaiaiaiaiai" + /* 1 */ "a...........a" + /* 2 */ "i...........i" + /* 3 */ "a...........a" + /* 4 */ "i...........i" + /* 5 */ "a...........a" + /* 6 */ "i...........i" + /* 7 */ "a...........a" + /* 8 */ "i...........i" + /* 9 */ "a...........a" + /* 10 */ "i...........i" + /* 11 */ "a...........a" + /* 12 */ "iaiaiaiaiaiai", + + // Connectors: + "1: 12, 1, 6: 5\n" /* Type 1, direction X+ */ + "1: 0, 1, 6: 4\n" /* Type 1, direction X- */ + "-1: 12, 1, 6: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 6: 4\n" /* Type -1, direction X- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + -1000, }, // MidStaircase + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // StairsToOpen1: - // The data has been exported from gallery Nether, area index 27, ID 277 + // The data has been exported from the gallery Nether, area index 27, ID 277, created by Aloe_vera { // Size: 7, 10, 7, // SizeX = 7, SizeY = 10, SizeZ = 7 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 6, 19, 6, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -2106,114 +4257,142 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "aaaaaaa" + /* 2 */ "aaaaaaa" + /* 3 */ "aaaaaaa" + /* 4 */ "aaaaaaa" + /* 5 */ "aaaaaaa" + /* 6 */ "aaaaaaa" + // Level 1 - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "a.....a" + /* 3 */ "a.....a" + /* 4 */ "a.....a" + /* 5 */ "aaaaaaa" + /* 6 */ "aaaaaaa" // Level 2 - "aa...aa" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "aaaaaaa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a.aaaaa" + /* 6 */ "aabaaba" // Level 3 - "aa...aa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a.aaaaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a..aaaa" + /* 6 */ "aabaaba" // Level 4 - "aa...aa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a..aaaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aabbbaa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a...aaa" + /* 6 */ "aabaaba" // Level 5 - "aabbbaa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a...aaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "a.....a" + /* 2 */ "a.....a" + /* 3 */ "a.....a" + /* 4 */ "a.....a" + /* 5 */ "a....aa" + /* 6 */ "aaaaaaa" // Level 6 - "aaaaaaa" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "a....aa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "aaaaaaa" + /* 2 */ "aaaaaaa" + /* 3 */ "aaaaaaa" + /* 4 */ "aaaaaaa" + /* 5 */ "a.....a" + /* 6 */ "aaaaaaa" // Level 7 - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "a.....a" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "a.....a" + /* 2 */ "a......" + /* 3 */ "a......" + /* 4 */ "a......" + /* 5 */ "a.....a" + /* 6 */ "aaaaaaa" // Level 8 - "aaaaaaa" - "a.....a" - "a......" - "a......" - "a......" - "a.....a" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "mmmmmmm" + /* 1 */ "m.....m" + /* 2 */ "m......" + /* 3 */ "m......" + /* 4 */ "m......" + /* 5 */ "m.....m" + /* 6 */ "mmmmmmm" // Level 9 - "mmmmmmm" - "m.....m" - "m......" - "m......" - "m......" - "m.....m" - "mmmmmmm" - - // Level 10 - "mmmmmmm" - "m.....m" - "m......" - "m......" - "m......" - "m.....m" - "mmmmmmm", - - // Connections: - "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "0: 6, 7, 3: 5\n" /* Type 0, BLOCK_FACE_XP */, + /* z\x* 0123456 */ + /* 0 */ "mmmmmmm" + /* 1 */ "m.....m" + /* 2 */ "m......" + /* 3 */ "m......" + /* 4 */ "m......" + /* 5 */ "m.....m" + /* 6 */ "mmmmmmm", + + // Connectors: + "0: 6, 7, 3: 5\n" /* Type 0, direction X+ */ + "0: 3, 1, 0: 2\n" /* Type 0, direction Z- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|3:0|5:0|7:0|9:0|11:0|13:0|15:0", + + // AddWeightIfSame: + 0, }, // StairsToOpen1 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // StairsToOpen2: - // The data has been exported from gallery Nether, area index 8, ID 35 + // The data has been exported from the gallery Nether, area index 8, ID 35, created by xoft { // Size: 7, 10, 7, // SizeX = 7, SizeY = 10, SizeZ = 7 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 6, 19, 6, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -2221,114 +4400,142 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "aaaaaaa" + /* 2 */ "aaaaaaa" + /* 3 */ "aaaaaaa" + /* 4 */ "aaaaaaa" + /* 5 */ "aaaaaaa" + /* 6 */ "aaaaaaa" + // Level 1 - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "a.....a" + /* 3 */ "a.....a" + /* 4 */ "a.....a" + /* 5 */ "aaaaaaa" + /* 6 */ "aaaaaaa" // Level 2 - "aa...aa" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "aaaaaaa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a.aaaaa" + /* 6 */ "aabaaba" // Level 3 - "aa...aa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a.aaaaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a..aaaa" + /* 6 */ "aabaaba" // Level 4 - "aa...aa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a..aaaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aabbbaa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "a.....a" + /* 4 */ "b.....b" + /* 5 */ "a...aaa" + /* 6 */ "aabaaba" // Level 5 - "aabbbaa" - "a.....a" - "b.....b" - "a.....a" - "b.....b" - "a...aaa" - "aabaaba" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "a.....a" + /* 2 */ "a.....a" + /* 3 */ "a.....a" + /* 4 */ "a.....a" + /* 5 */ "a....aa" + /* 6 */ "aaaaaaa" // Level 6 - "aaaaaaa" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "a....aa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "aaaaaaa" + /* 2 */ "aaaaaaa" + /* 3 */ "aaaaaaa" + /* 4 */ "aaaaaaa" + /* 5 */ "a.....a" + /* 6 */ "aaaaaaa" // Level 7 - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "a.....a" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "a.....a" + /* 2 */ "......a" + /* 3 */ "......a" + /* 4 */ "......a" + /* 5 */ "a.....a" + /* 6 */ "aaaaaaa" // Level 8 - "aaaaaaa" - "a.....a" - "......a" - "......a" - "......a" - "a.....a" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "mmmmmmm" + /* 1 */ "m.....m" + /* 2 */ "......m" + /* 3 */ "......m" + /* 4 */ "......m" + /* 5 */ "m.....m" + /* 6 */ "mmmmmmm" // Level 9 - "mmmmmmm" - "m.....m" - "......m" - "......m" - "......m" - "m.....m" - "mmmmmmm" - - // Level 10 - "mmmmmmm" - "m.....m" - "......m" - "......m" - "......m" - "m.....m" - "mmmmmmm", - - // Connections: - "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "0: 0, 7, 3: 4\n" /* Type 0, BLOCK_FACE_XM */, + /* z\x* 0123456 */ + /* 0 */ "mmmmmmm" + /* 1 */ "m.....m" + /* 2 */ "......m" + /* 3 */ "......m" + /* 4 */ "......m" + /* 5 */ "m.....m" + /* 6 */ "mmmmmmm", + + // Connectors: + "0: 0, 7, 3: 4\n" /* Type 0, direction X- */ + "0: 3, 1, 0: 2\n" /* Type 0, direction Z- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:0|3:0|5:0|7:0|9:0|11:0|13:0|15:0", + + // AddWeightIfSame: + 0, }, // StairsToOpen2 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Tee2x4: - // The data has been exported from gallery Nether, area index 40, ID 291 + // The data has been exported from the gallery Nether, area index 40, ID 291, created by Aloe_vera { // Size: 13, 6, 7, // SizeX = 13, SizeY = 6, SizeZ = 7 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 5, 6, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -2340,79 +4547,112 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmaaaaammmm" + /* 1 */ "mmmmaaaaammmm" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + // Level 1 - "mmmmaaaaammmm" - "mmmmaaaaammmm" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmma...ammmm" + /* 2 */ "aaaaa...aaaaa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "aaaaaaaaaaaaa" // Level 2 - "mmmma...ammmm" - "mmmma...ammmm" - "aaaaa...aaaaa" - "............." - "............." - "............." - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "ababa...ababa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "ababababababa" // Level 3 - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "ababa...ababa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "ababababababa" // Level 4 - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "ababa...ababa" + /* 3 */ "............." + /* 4 */ "............." + /* 5 */ "............." + /* 6 */ "ababababababa" // Level 5 - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" - - // Level 6 - "mmmmcaaadmmmm" - "mmmmcaaadmmmm" - "eeeecaaadeeee" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "fffffffffffff", - - // Connections: - "1: 0, 1, 4: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 6, 1, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */ - "1: 12, 1, 4: 5\n" /* Type 1, BLOCK_FACE_XP */, + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmcaaadmmmm" + /* 1 */ "mmmmcaaadmmmm" + /* 2 */ "eeeecaaadeeee" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "fffffffffffff", + + // Connectors: + "1: 0, 1, 4: 4\n" /* Type 1, direction X- */ + "1: 6, 1, 0: 2\n" /* Type 1, direction Z- */ + "1: 12, 1, 4: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 4: 4\n" /* Type -1, direction X- */ + "-1: 12, 1, 4: 5\n" /* Type -1, direction X+ */ + "-1: 6, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // Tee2x4 + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Tee4x4: - // The data has been exported from gallery Nether, area index 41, ID 292 + // The data has been exported from the gallery Nether, area index 41, ID 292, created by Aloe_vera { // Size: 13, 6, 9, // SizeX = 13, SizeY = 6, SizeZ = 9 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 5, 8, // MaxX, MaxY, MaxZ + // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ @@ -2424,335 +4664,730 @@ const cPrefab::sDef g_NetherFortPrefabs1[] = "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmaaaaammmm" + /* 1 */ "mmmmaaaaammmm" + /* 2 */ "mmmmaaaaammmm" + /* 3 */ "mmmmaaaaammmm" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaa" + // Level 1 - "mmmmaaaaammmm" - "mmmmaaaaammmm" - "mmmmaaaaammmm" - "mmmmaaaaammmm" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmma...ammmm" + /* 2 */ "mmmma...ammmm" + /* 3 */ "mmmma...ammmm" + /* 4 */ "aaaaa...aaaaa" + /* 5 */ "............." + /* 6 */ "............." + /* 7 */ "............." + /* 8 */ "aaaaaaaaaaaaa" // Level 2 - "mmmma...ammmm" - "mmmma...ammmm" - "mmmma...ammmm" - "mmmma...ammmm" - "aaaaa...aaaaa" - "............." - "............." - "............." - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "mmmma...ammmm" + /* 3 */ "mmmmb...bmmmm" + /* 4 */ "ababa...ababa" + /* 5 */ "............." + /* 6 */ "............." + /* 7 */ "............." + /* 8 */ "ababababababa" // Level 3 - "mmmma...ammmm" - "mmmmb...bmmmm" - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "mmmma...ammmm" + /* 3 */ "mmmmb...bmmmm" + /* 4 */ "ababa...ababa" + /* 5 */ "............." + /* 6 */ "............." + /* 7 */ "............." + /* 8 */ "ababababababa" // Level 4 - "mmmma...ammmm" - "mmmmb...bmmmm" - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmma...ammmm" + /* 1 */ "mmmmb...bmmmm" + /* 2 */ "mmmma...ammmm" + /* 3 */ "mmmmb...bmmmm" + /* 4 */ "ababa...ababa" + /* 5 */ "............." + /* 6 */ "............." + /* 7 */ "............." + /* 8 */ "ababababababa" // Level 5 - "mmmma...ammmm" - "mmmmb...bmmmm" - "mmmma...ammmm" - "mmmmb...bmmmm" - "ababa...ababa" - "............." - "............." - "............." - "ababababababa" - - // Level 6 - "mmmmcaaadmmmm" - "mmmmcaaadmmmm" - "mmmmcaaadmmmm" - "mmmmcaaadmmmm" - "eeeecaaadeeee" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "fffffffffffff", - - // Connections: - "1: 0, 1, 6: 4\n" /* Type 1, BLOCK_FACE_XM */ - "1: 12, 1, 6: 5\n" /* Type 1, BLOCK_FACE_XP */ - "1: 6, 1, 0: 2\n" /* Type 1, BLOCK_FACE_ZM */, + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "mmmmcaaadmmmm" + /* 1 */ "mmmmcaaadmmmm" + /* 2 */ "mmmmcaaadmmmm" + /* 3 */ "mmmmcaaadmmmm" + /* 4 */ "eeeecaaadeeee" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "fffffffffffff", + + // Connectors: + "1: 0, 1, 6: 4\n" /* Type 1, direction X- */ + "1: 6, 1, 0: 2\n" /* Type 1, direction Z- */ + "1: 12, 1, 6: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 6: 4\n" /* Type -1, direction X- */ + "-1: 6, 1, 0: 2\n" /* Type -1, direction Z- */ + "-1: 12, 1, 6: 5\n" /* Type -1, direction X+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, }, // Tee4x4 + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TinyCorridorCorner: + // The data has been exported from the gallery Nether, area index 66, ID 331, created by xoft + { + // Size: + 5, 6, 5, // SizeX = 5, SizeY = 6, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 4, 5, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:113: 0\n" /* netherbrickfence */ + "c:114: 2\n" /* netherbrickstairs */ + "d:114: 1\n" /* netherbrickstairs */ + "e:114: 0\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "aaaaa" + + // Level 1 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "....a" + /* 2 */ "....a" + /* 3 */ "....a" + /* 4 */ "a...a" + + // Level 2 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....b" + /* 2 */ "....a" + /* 3 */ "....b" + /* 4 */ "a...a" + + // Level 3 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....b" + /* 2 */ "....a" + /* 3 */ "....b" + /* 4 */ "a...a" + + // Level 4 + /* z\x* 01234 */ + /* 0 */ "ababa" + /* 1 */ "....b" + /* 2 */ "....a" + /* 3 */ "....b" + /* 4 */ "a...a" + + // Level 5 + /* z\x* 01234 */ + /* 0 */ "ccccc" + /* 1 */ "aaaad" + /* 2 */ "aaaad" + /* 3 */ "aaaad" + /* 4 */ "eaaad", + + // Connectors: + "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + -50, + }, // TinyCorridorCorner + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TinyCorridorCornerChest: + // The data has been exported from the gallery Nether, area index 67, ID 332, created by Aloe_vera + { + // Size: + 5, 6, 5, // SizeX = 5, SizeY = 6, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 4, 5, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b: 54: 4\n" /* chest */ + "c:113: 0\n" /* netherbrickfence */ + "d:114: 2\n" /* netherbrickstairs */ + "e:114: 1\n" /* netherbrickstairs */ + "f:114: 0\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "aaaaa" + + // Level 1 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "....a" + /* 2 */ "...ba" + /* 3 */ "....a" + /* 4 */ "a...a" + + // Level 2 + /* z\x* 01234 */ + /* 0 */ "acaca" + /* 1 */ "....c" + /* 2 */ "....a" + /* 3 */ "....c" + /* 4 */ "a...a" + + // Level 3 + /* z\x* 01234 */ + /* 0 */ "acaca" + /* 1 */ "....c" + /* 2 */ "....a" + /* 3 */ "....c" + /* 4 */ "a...a" + + // Level 4 + /* z\x* 01234 */ + /* 0 */ "acaca" + /* 1 */ "....c" + /* 2 */ "....a" + /* 3 */ "....c" + /* 4 */ "a...a" + + // Level 5 + /* z\x* 01234 */ + /* 0 */ "ddddd" + /* 1 */ "aaaae" + /* 2 */ "aaaae" + /* 3 */ "aaaae" + /* 4 */ "faaae", + + // Connectors: + "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // TinyCorridorCornerChest + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // TinyCorridorCrossing: + // The data has been exported from the gallery Nether, area index 64, ID 329, created by xoft + { + // Size: + 5, 6, 5, // SizeX = 5, SizeY = 6, SizeZ = 5 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 4, 5, 4, // MaxX, MaxY, MaxZ + + // Block definitions: + ".: 0: 0\n" /* air */ + "a:112: 0\n" /* netherbrick */ + "b:114: 2\n" /* netherbrickstairs */ + "c:114: 0\n" /* netherbrickstairs */ + "d:114: 1\n" /* netherbrickstairs */ + "m: 19: 0\n" /* sponge */, + + // Block data: + // Level 0 + /* z\x* 01234 */ + /* 0 */ "aaaaa" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "aaaaa" + + // Level 1 + /* z\x* 01234 */ + /* 0 */ "a...a" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "a...a" + + // Level 2 + /* z\x* 01234 */ + /* 0 */ "a...a" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "a...a" + + // Level 3 + /* z\x* 01234 */ + /* 0 */ "a...a" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "a...a" + + // Level 4 + /* z\x* 01234 */ + /* 0 */ "a...a" + /* 1 */ "....." + /* 2 */ "....." + /* 3 */ "....." + /* 4 */ "a...a" + + // Level 5 + /* z\x* 01234 */ + /* 0 */ "baaab" + /* 1 */ "aaaaa" + /* 2 */ "aaaaa" + /* 3 */ "aaaaa" + /* 4 */ "caaad", + + // Connectors: + "1: 4, 1, 2: 5\n" /* Type 1, direction X+ */ + "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "1: 2, 1, 0: 2\n" /* Type 1, direction Z- */ + "-1: 4, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 2, 1, 0: 2\n" /* Type -1, direction Z- */, + + // AllowedRotations: + 7, /* 1, 2, 3 CCW rotation allowed */ + + // Merge strategy: + cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "1:200|2:400|3:0|4:500", + + // AddWeightIfSame: + -50, + }, // TinyCorridorCrossing + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Turret: - // The data has been exported from gallery Nether, area index 7, ID 34 + // The data has been exported from the gallery Nether, area index 7, ID 34, created by xoft { // Size: - 7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7 + 7, 7, 7, // SizeX = 7, SizeY = 7, SizeZ = 7 + + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 6, 16, 6, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ - "b:113: 0\n" /* netherbrickfence */, + "b:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "aaaaaaa" + /* 2 */ "aaaaaaa" + /* 3 */ "aaaaaaa" + /* 4 */ "aaaaaaa" + /* 5 */ "aaaaaaa" + /* 6 */ "aaaaaaa" + // Level 1 - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" - "aaaaaaa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "......." + /* 3 */ "......." + /* 4 */ "......." + /* 5 */ "a.....a" + /* 6 */ "aa...aa" // Level 2 - "aa...aa" - "a.....a" - "......." - "......." - "......." - "a.....a" - "aa...aa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "......." + /* 3 */ "......." + /* 4 */ "......." + /* 5 */ "a.....a" + /* 6 */ "aa...aa" // Level 3 - "aa...aa" - "a.....a" - "......." - "......." - "......." - "a.....a" - "aa...aa" + /* z\x* 0123456 */ + /* 0 */ "aa...aa" + /* 1 */ "a.....a" + /* 2 */ "......." + /* 3 */ "......." + /* 4 */ "......." + /* 5 */ "a.....a" + /* 6 */ "aa...aa" // Level 4 - "aa...aa" - "a.....a" - "......." - "......." - "......." - "a.....a" - "aa...aa" + /* z\x* 0123456 */ + /* 0 */ "aabbbaa" + /* 1 */ "a.....a" + /* 2 */ "b.....b" + /* 3 */ "b.....b" + /* 4 */ "b.....b" + /* 5 */ "a.....a" + /* 6 */ "aabbbaa" // Level 5 - "aabbbaa" - "a.....a" - "b.....b" - "b.....b" - "b.....b" - "a.....a" - "aabbbaa" + /* z\x* 0123456 */ + /* 0 */ "aaaaaaa" + /* 1 */ "a.....a" + /* 2 */ "a.....a" + /* 3 */ "a.....a" + /* 4 */ "a.....a" + /* 5 */ "a.....a" + /* 6 */ "aaaaaaa" // Level 6 - "aaaaaaa" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "a.....a" - "aaaaaaa", - - // Connections: - "0: 0, 1, 3: 4\n" /* Type 0, BLOCK_FACE_XM */ - "0: 3, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "0: 6, 1, 3: 5\n" /* Type 0, BLOCK_FACE_XP */ - "0: 3, 1, 6: 3\n" /* Type 0, BLOCK_FACE_ZP */, + /* z\x* 0123456 */ + /* 0 */ "......." + /* 1 */ "......." + /* 2 */ "......." + /* 3 */ "......." + /* 4 */ "......." + /* 5 */ "......." + /* 6 */ ".......", + + // Connectors: + "0: 0, 1, 3: 4\n" /* Type 0, direction X- */ + "0: 3, 1, 0: 2\n" /* Type 0, direction Z- */ + "0: 6, 1, 3: 5\n" /* Type 0, direction X+ */ + "0: 3, 1, 6: 3\n" /* Type 0, direction Z+ */, // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, + + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + -99, }, // Turret +}; // g_NetherFortPrefabs -} ; // g_NetherFortPrefabs1 -const cPrefab::sDef g_NetherFortStartingPrefabs1[] = +const cPrefab::sDef g_NetherFortStartingPrefabs[] = { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CentralRoom: - // The data has been exported from gallery Nether, area index 22, ID 164 + // The data has been exported from the gallery Nether, area index 22, ID 164, created by Aloe_vera { // Size: 13, 9, 13, // SizeX = 13, SizeY = 9, SizeZ = 13 + // Hitbox (relative to bounding box): + 0, 0, 0, // MinX, MinY, MinZ + 12, 8, 12, // MaxX, MaxY, MaxZ + // Block definitions: + ".: 0: 0\n" /* air */ "a:112: 0\n" /* netherbrick */ - "b: 0: 0\n" /* air */ - "c: 10: 0\n" /* lava */ - "d:113: 0\n" /* netherbrickfence */, + "b: 10: 0\n" /* lava */ + "c:113: 0\n" /* netherbrickfence */ + "m: 19: 0\n" /* sponge */, // Block data: + // Level 0 + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" + // Level 1 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaa...aaaaa" + /* 1 */ "aaaaa...aaaaa" + /* 2 */ "aa.........aa" + /* 3 */ "aa.........aa" + /* 4 */ "aa.........aa" + /* 5 */ "aa...aaa...aa" + /* 6 */ "aa...aba...aa" + /* 7 */ "aa...aaa...aa" + /* 8 */ "aa.........aa" + /* 9 */ "aa.........aa" + /* 10 */ "aa.........aa" + /* 11 */ "aaaaa...aaaaa" + /* 12 */ "aaaaa...aaaaa" // Level 2 - "aaaaabbbaaaaa" - "aaaaabbbaaaaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbaaabbbaa" - "aabbbacabbbaa" - "aabbbaaabbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aabbbbbbbbbaa" - "aaaaabbbaaaaa" - "aaaaabbbaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaa...aaaaa" + /* 1 */ "aaaca...acaaa" + /* 2 */ "aa.........aa" + /* 3 */ "ac.........ca" + /* 4 */ "aa.........aa" + /* 5 */ "ac.........ca" + /* 6 */ "aa.........aa" + /* 7 */ "ac.........ca" + /* 8 */ "aa.........aa" + /* 9 */ "ac.........ca" + /* 10 */ "aa.........aa" + /* 11 */ "aaaca...acaaa" + /* 12 */ "aaaaa...aaaaa" // Level 3 - "aaaaabbbaaaaa" - "aaadabbbadaaa" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "aaadabbbadaaa" - "aaaaabbbaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaa...aaaaa" + /* 1 */ "aaaca...acaaa" + /* 2 */ "aa.........aa" + /* 3 */ "ac.........ca" + /* 4 */ "aa.........aa" + /* 5 */ "ac.........ca" + /* 6 */ "aa.........aa" + /* 7 */ "ac.........ca" + /* 8 */ "aa.........aa" + /* 9 */ "ac.........ca" + /* 10 */ "aa.........aa" + /* 11 */ "aaaca...acaaa" + /* 12 */ "aaaaa...aaaaa" // Level 4 - "aaaaabbbaaaaa" - "aaadabbbadaaa" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "adbbbbbbbbbda" - "aabbbbbbbbbaa" - "aaadabbbadaaa" - "aaaaabbbaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "acacacccacaca" + /* 1 */ "caaaa...aaaac" + /* 2 */ "aa.........aa" + /* 3 */ "ca.........ac" + /* 4 */ "aa.........aa" + /* 5 */ "ca.........ac" + /* 6 */ "aa.........aa" + /* 7 */ "ca.........ac" + /* 8 */ "aa.........aa" + /* 9 */ "ca.........ac" + /* 10 */ "aa.........aa" + /* 11 */ "caaaa...aaaac" + /* 12 */ "acaca...acaca" // Level 5 - "adadadddadada" - "daaaabbbaaaad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "daaaabbbaaaad" - "adadabbbadada" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "acacaaaaacaca" + /* 1 */ "caaaaaaaaaaac" + /* 2 */ "aa.........aa" + /* 3 */ "ca.........ac" + /* 4 */ "aa.........aa" + /* 5 */ "ca.........ac" + /* 6 */ "aa.........aa" + /* 7 */ "ca.........ac" + /* 8 */ "aa.........aa" + /* 9 */ "ca.........ac" + /* 10 */ "aa.........aa" + /* 11 */ "caaaaaaaaaaac" + /* 12 */ "acacaaaaacaca" // Level 6 - "adadaaaaadada" - "daaaaaaaaaaad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "dabbbbbbbbbad" - "aabbbbbbbbbaa" - "daaaaaaaaaaad" - "adadaaaaadada" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" // Level 7 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "aaaaaaaaaaaaa" + /* 1 */ "aaaaaaaaaaaaa" + /* 2 */ "aaaaaaaaaaaaa" + /* 3 */ "aaaaaaaaaaaaa" + /* 4 */ "aaaaaaaaaaaaa" + /* 5 */ "aaaaaaaaaaaaa" + /* 6 */ "aaaaaaaaaaaaa" + /* 7 */ "aaaaaaaaaaaaa" + /* 8 */ "aaaaaaaaaaaaa" + /* 9 */ "aaaaaaaaaaaaa" + /* 10 */ "aaaaaaaaaaaaa" + /* 11 */ "aaaaaaaaaaaaa" + /* 12 */ "aaaaaaaaaaaaa" // Level 8 - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" - "aaaaaaaaaaaaa" + /* z\x* 111 */ + /* * 0123456789012 */ + /* 0 */ "cacacacacacac" + /* 1 */ "a...........a" + /* 2 */ "c...........c" + /* 3 */ "a...........a" + /* 4 */ "c...........c" + /* 5 */ "a...........a" + /* 6 */ "c...........c" + /* 7 */ "a...........a" + /* 8 */ "c...........c" + /* 9 */ "a...........a" + /* 10 */ "c...........c" + /* 11 */ "a...........a" + /* 12 */ "cacacacacacac", + + // Connectors: + "0: 6, 1, 0: 2\n" /* Type 0, direction Z- */ + "1: 6, 1, 12: 3\n" /* Type 1, direction Z+ */ + "-1: 6, 1, 12: 3\n" /* Type -1, direction Z+ */, - // Level 9 - "dadadadadadad" - "abbbbbbbbbbba" - "dbbbbbbbbbbbd" - "abbbbbbbbbbba" - "dbbbbbbbbbbbd" - "abbbbbbbbbbba" - "dbbbbbbbbbbbd" - "abbbbbbbbbbba" - "dbbbbbbbbbbbd" - "abbbbbbbbbbba" - "dbbbbbbbbbbbd" - "abbbbbbbbbbba" - "dadadadadadad", - - // Connections: - "0: 6, 1, 0: 2\n" /* Type 0, BLOCK_FACE_ZM */ - "1: 6, 1, 12: 3\n" /* Type 1, BLOCK_FACE_ZP */, - // AllowedRotations: - 7, /* 1, 2, 3 CCW rotations */ - + 7, /* 1, 2, 3 CCW rotation allowed */ + // Merge strategy: cBlockArea::msSpongePrint, - }, -} ; // g_NetherFortStartingPrefabs1 -const size_t g_NetherFortPrefabs1Count = ARRAYCOUNT(g_NetherFortPrefabs1); -const size_t g_NetherFortStartingPrefabs1Count = ARRAYCOUNT(g_NetherFortStartingPrefabs1); + // ShouldExtendFloor: + true, + + // DefaultWeight: + 100, + + // DepthWeight: + "", + + // AddWeightIfSame: + 0, + }, // CentralRoom +}; + + + + +// The prefab counts: +const size_t g_NetherFortPrefabsCount = ARRAYCOUNT(g_NetherFortPrefabs); +const size_t g_NetherFortStartingPrefabsCount = ARRAYCOUNT(g_NetherFortStartingPrefabs); diff --git a/src/Generating/Prefabs/NetherFortPrefabs.h b/src/Generating/Prefabs/NetherFortPrefabs.h index 37a91689d..04edc2953 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.h +++ b/src/Generating/Prefabs/NetherFortPrefabs.h @@ -1,7 +1,7 @@ // NetherFortPrefabs.h -// Declares the data used for nether fortress prefabs +// Declares the prefabs in the group NetherFort #include "../Prefab.h" @@ -9,7 +9,7 @@ -extern const cPrefab::sDef g_NetherFortPrefabs1[]; -extern const cPrefab::sDef g_NetherFortStartingPrefabs1[]; -extern const size_t g_NetherFortPrefabs1Count; -extern const size_t g_NetherFortStartingPrefabs1Count; +extern const cPrefab::sDef g_NetherFortPrefabs[]; +extern const cPrefab::sDef g_NetherFortStartingPrefabs[]; +extern const size_t g_NetherFortPrefabsCount; +extern const size_t g_NetherFortStartingPrefabsCount; diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index e64f55214..267dcbbf9 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -269,7 +269,7 @@ void cStructGenRavines::cRavine::GenerateBaseDefPoints(int a_BlockX, int a_Block int CenterZ = a_BlockZ + OffsetZ; // Get the base angle in which the ravine "axis" goes: - float Angle = (float)(((float)((a_Noise.IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * 3.141592653); + float Angle = (float)(((float)((a_Noise.IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * M_PI); float xc = sin(Angle); float zc = cos(Angle); @@ -311,12 +311,13 @@ void cStructGenRavines::cRavine::RefineDefPoints(const cRavDefPoints & a_Src, cR a_Dst.clear(); a_Dst.reserve(Num * 2 + 2); cRavDefPoints::const_iterator itr = a_Src.begin() + 1; - a_Dst.push_back(a_Src.front()); - int PrevX = a_Src.front().m_BlockX; - int PrevZ = a_Src.front().m_BlockZ; - int PrevR = a_Src.front().m_Radius; - int PrevT = a_Src.front().m_Top; - int PrevB = a_Src.front().m_Bottom; + const cRavDefPoint & Source = a_Src.front(); + a_Dst.push_back(Source); + int PrevX = Source.m_BlockX; + int PrevZ = Source.m_BlockZ; + int PrevR = Source.m_Radius; + int PrevT = Source.m_Top; + int PrevB = Source.m_Bottom; for (int i = 0; i <= Num; ++i, ++itr) { int dx = itr->m_BlockX - PrevX; diff --git a/src/Globals.h b/src/Globals.h index 26a0d87a9..71e9191e4 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -264,7 +264,21 @@ template class SizeChecker<UInt16, 2>; // Same as assert but in all Self test builds #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) + #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) +#endif + +// Allow both Older versions of MSVC and newer versions of everything use a shared_ptr: +// Note that we cannot typedef, because C++ doesn't allow (partial) templates to be typedeffed. +#if (defined(_MSC_VER) && (_MSC_VER < 1600)) + // MSVC before 2010 doesn't have std::shared_ptr, but has std::tr1::shared_ptr, defined in <memory> included earlier + #define SharedPtr std::tr1::shared_ptr +#elif (defined(_MSC_VER) || (__cplusplus >= 201103L)) + // C++11 has std::shared_ptr in <memory>, included earlier + #define SharedPtr std::shared_ptr +#else + // C++03 has std::tr1::shared_ptr in <tr1/memory> + #include <tr1/memory> + #define SharedPtr std::tr1::shared_ptr #endif @@ -296,7 +310,7 @@ T Clamp(T a_Value, T a_Min, T a_Max) #ifndef TOLUA_TEMPLATE_BIND -#define TOLUA_TEMPLATE_BIND(x) + #define TOLUA_TEMPLATE_BIND(x) #endif diff --git a/src/Group.cpp b/src/Group.cpp index 9c2467144..725740905 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -7,7 +7,7 @@ -void cGroup::AddCommand( AString a_Command ) +void cGroup::AddCommand( const AString & a_Command ) { m_Commands[ a_Command ] = true; } @@ -16,7 +16,7 @@ void cGroup::AddCommand( AString a_Command ) -void cGroup::AddPermission( AString a_Permission ) +void cGroup::AddPermission( const AString & a_Permission ) { m_Permissions[ a_Permission ] = true; } diff --git a/src/Group.h b/src/Group.h index 8bee6f7ed..47088d50d 100644 --- a/src/Group.h +++ b/src/Group.h @@ -11,11 +11,11 @@ public: // tolua_export cGroup() {} ~cGroup() {} - void SetName( AString a_Name ) { m_Name = a_Name; } // tolua_export + void SetName( const AString & a_Name ) { m_Name = a_Name; } // tolua_export const AString & GetName() const { return m_Name; } // tolua_export - void SetColor( AString a_Color ) { m_Color = a_Color; } // tolua_export - void AddCommand( AString a_Command ); // tolua_export - void AddPermission( AString a_Permission ); // tolua_export + void SetColor( const AString & a_Color ) { m_Color = a_Color; } // tolua_export + void AddCommand( const AString & a_Command ); // tolua_export + void AddPermission( const AString & a_Permission ); // tolua_export void InheritFrom( cGroup* a_Group ); // tolua_export typedef std::map< AString, bool > PermissionMap; 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/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 44a3d3f88..da4df0e34 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -70,7 +70,7 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response) void cHTTPConnection::Send(const void * a_Data, size_t a_Size) { ASSERT(m_State == wcsSendingResp); - AppendPrintf(m_OutgoingData, SIZE_T_FMT "\r\n", a_Size); + AppendPrintf(m_OutgoingData, SIZE_T_FMT_HEX "\r\n", a_Size); m_OutgoingData.append((const char *)a_Data, a_Size); m_OutgoingData.append("\r\n"); m_HTTPServer.NotifyConnectionWrite(*this); diff --git a/src/Item.cpp b/src/Item.cpp index 856b68be6..7e472f6d8 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -5,6 +5,8 @@ #include "json/json.h" #include "Items/ItemHandler.h" +#include "FastRandom.h" + @@ -196,9 +198,6 @@ bool cItem::IsEnchantable(short item) return true; if ((item >= 298) && (item <= 317)) return true; - if ((item >= 290) && (item <= 294)) - return true; - if ((item == 346) || (item == 359) || (item == 261)) return true; @@ -209,6 +208,157 @@ bool cItem::IsEnchantable(short item) +int cItem::GetEnchantability() +{ + int Enchantability = 0; + + switch (m_ItemType) + { + case E_ITEM_WOODEN_SWORD: Enchantability = 15; break; + case E_ITEM_WOODEN_PICKAXE: Enchantability = 15; break; + case E_ITEM_WOODEN_SHOVEL: Enchantability = 15; break; + case E_ITEM_WOODEN_AXE: Enchantability = 15; break; + case E_ITEM_WOODEN_HOE: Enchantability = 15; break; + + case E_ITEM_LEATHER_CAP: Enchantability = 15; break; + case E_ITEM_LEATHER_TUNIC: Enchantability = 15; break; + case E_ITEM_LEATHER_PANTS: Enchantability = 15; break; + case E_ITEM_LEATHER_BOOTS: Enchantability = 15; break; + + case E_ITEM_STONE_SWORD: Enchantability = 5; break; + case E_ITEM_STONE_PICKAXE: Enchantability = 5; break; + case E_ITEM_STONE_SHOVEL: Enchantability = 5; break; + case E_ITEM_STONE_AXE: Enchantability = 5; break; + case E_ITEM_STONE_HOE: Enchantability = 5; break; + + case E_ITEM_IRON_HELMET: Enchantability = 9; break; + case E_ITEM_IRON_CHESTPLATE: Enchantability = 9; break; + case E_ITEM_IRON_LEGGINGS: Enchantability = 9; break; + case E_ITEM_IRON_BOOTS: Enchantability = 9; break; + + case E_ITEM_IRON_SWORD: Enchantability = 14; break; + case E_ITEM_IRON_PICKAXE: Enchantability = 14; break; + case E_ITEM_IRON_SHOVEL: Enchantability = 14; break; + case E_ITEM_IRON_AXE: Enchantability = 14; break; + case E_ITEM_IRON_HOE: Enchantability = 14; break; + + case E_ITEM_CHAIN_HELMET: Enchantability = 12; break; + case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12; break; + case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12; break; + case E_ITEM_CHAIN_BOOTS: Enchantability = 12; break; + + case E_ITEM_DIAMOND_HELMET: Enchantability = 10; break; + case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10; break; + case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10; break; + case E_ITEM_DIAMOND_BOOTS: Enchantability = 10; break; + + case E_ITEM_DIAMOND_SWORD: Enchantability = 10; break; + case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10; break; + case E_ITEM_DIAMOND_AXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_HOE: Enchantability = 10; break; + + case E_ITEM_GOLD_HELMET: Enchantability = 25; break; + case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25; break; + case E_ITEM_GOLD_LEGGINGS: Enchantability = 25; break; + case E_ITEM_GOLD_BOOTS: Enchantability = 25; break; + + case E_ITEM_GOLD_SWORD: Enchantability = 22; break; + case E_ITEM_GOLD_PICKAXE: Enchantability = 22; break; + case E_ITEM_GOLD_SHOVEL: Enchantability = 22; break; + case E_ITEM_GOLD_AXE: Enchantability = 22; break; + case E_ITEM_GOLD_HOE: Enchantability = 22; break; + + case E_ITEM_FISHING_ROD: Enchantability = 1; break; + case E_ITEM_BOW: Enchantability = 1; break; + case E_ITEM_BOOK: Enchantability = 1; break; + } + + return Enchantability; +} + + + + + +bool cItem::EnchantByXPLevels(int a_NumXPLevels) +{ + if (!cItem::IsEnchantable(m_ItemType) && (m_ItemType != E_ITEM_BOOK)) + { + return false; + } + + int Enchantability = GetEnchantability(); + + cFastRandom Random; + int ModifiedEnchantmentLevel = a_NumXPLevels + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1; + float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F; + int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F); + + cWeightedEnchantments enchantments; + cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel); + + if (m_ItemType == E_ITEM_BOOK) + { + m_ItemType = E_ITEM_ENCHANTED_BOOK; + } + + cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment1.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment1); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); + + float NewEnchantmentLevel = (float)a_NumXPLevels; + + // Next Enchantment (Second) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance)) + { + return true; + } + + cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment2.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); + + // Next Enchantment (Third) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance)) + { + return true; + } + + cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment3.ToString()); + cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3); + + // Checking for conflicting enchantments + cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); + + // Next Enchantment (Fourth) + NewEnchantmentLevel = NewEnchantmentLevel / 2; + float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; + if (enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance)) + { + return true; + } + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment4.ToString()); + + return true; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cItems: diff --git a/src/Item.h b/src/Item.h index 910ecb382..8eb0a1f4e 100644 --- a/src/Item.h +++ b/src/Item.h @@ -64,7 +64,7 @@ public: { if (!IsValidItem(m_ItemType)) { - if (m_ItemType != E_BLOCK_AIR) + if ((m_ItemType != E_BLOCK_AIR) && (m_ItemType != E_ITEM_EMPTY)) { LOGWARNING("%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType); } @@ -73,6 +73,10 @@ public: } + // The constructor is disabled in code, because the compiler generates it anyway, + // but it needs to stay because ToLua needs to generate the binding for it + #if 0 + /** Creates an exact copy of the item */ cItem(const cItem & a_CopyFrom) : m_ItemType (a_CopyFrom.m_ItemType), @@ -85,6 +89,8 @@ public: { } + #endif + void Empty(void) { @@ -175,6 +181,13 @@ public: /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */ static bool IsEnchantable(short a_ItemType); // tolua_export + /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */ + int GetEnchantability(); // tolua_export + + /** Enchants the item using the specified number of XP levels. + Returns true if item enchanted, false if not. */ + bool EnchantByXPLevels(int a_NumXPLevels); // tolua_export + // tolua_begin short m_ItemType; 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}) diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h new file mode 100644 index 000000000..2436df5bd --- /dev/null +++ b/src/Items/ItemArmor.h @@ -0,0 +1,110 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemArmorHandler : + public cItemHandler +{ +public: + cItemArmorHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + /** 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; + 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; + } + else + { + LOGWARNING("Used unknown armor: %i", a_Item.m_ItemType); + return false; + } + + if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty()) + { + return false; + } + + a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne()); + + 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; + } + + virtual bool CanRepairWithRawMaterial(short a_ItemType) override + { + switch (m_ItemType) + { + case E_ITEM_CHAIN_BOOTS: + case E_ITEM_CHAIN_CHESTPLATE: + case E_ITEM_CHAIN_HELMET: + case E_ITEM_CHAIN_LEGGINGS: + { + return (a_ItemType == E_ITEM_IRON); + } + case E_ITEM_DIAMOND_BOOTS: + case E_ITEM_DIAMOND_CHESTPLATE: + case E_ITEM_DIAMOND_HELMET: + case E_ITEM_DIAMOND_LEGGINGS: + { + return (a_ItemType == E_ITEM_DIAMOND); + } + case E_ITEM_IRON_BOOTS: + case E_ITEM_IRON_CHESTPLATE: + case E_ITEM_IRON_HELMET: + case E_ITEM_IRON_LEGGINGS: + { + return (a_ItemType == E_ITEM_IRON); + } + case E_ITEM_GOLD_BOOTS: + case E_ITEM_GOLD_CHESTPLATE: + case E_ITEM_GOLD_HELMET: + case E_ITEM_GOLD_LEGGINGS: + { + return (a_ItemType == E_ITEM_GOLD); + } + case E_ITEM_LEATHER_BOOTS: + case E_ITEM_LEATHER_CAP: + case E_ITEM_LEATHER_PANTS: + case E_ITEM_LEATHER_TUNIC: + { + return (a_ItemType == E_ITEM_LEATHER); + } + } + return false; + } + +} ; + + + + diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 410c5f512..8c0b3a0a3 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -9,7 +9,7 @@ #pragma once -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ArrowEntity.h" diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 1e77717e3..5cc5b66a0 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" @@ -222,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); + } } } @@ -431,7 +457,6 @@ bool cItemHandler::IsTool() || (m_ItemType >= 267 && m_ItemType <= 279) || (m_ItemType >= 283 && m_ItemType <= 286) || (m_ItemType >= 290 && m_ItemType <= 294) - || (m_ItemType >= 256 && m_ItemType <= 259) || (m_ItemType == 325) || (m_ItemType == 346); } @@ -486,6 +511,25 @@ bool cItemHandler::IsPlaceable(void) + +bool cItemHandler::CanRepairWithRawMaterial(short a_ItemType) +{ + return false; +} + + + + + +int cItemHandler::GetRepairCost(void) +{ + return 0; +} + + + + + bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType) { UNUSED(a_BlockType); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 5b6c239cc..ca090eb29 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,48 +44,54 @@ 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 { - int FoodLevel; double Saturation; + int FoodLevel; int PoisonChance; // 0 - 100, in percent. 0 = no chance of poisoning, 100 = sure poisoning FoodInfo(int a_FoodLevel, double a_Saturation, int a_PoisonChance = 0) : - FoodLevel(a_FoodLevel), Saturation(a_Saturation), + FoodLevel(a_FoodLevel), PoisonChance(a_PoisonChance) { } } ; - /// 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. + /** Can the anvil repair this item, when a_Item is the second input? */ + virtual bool CanRepairWithRawMaterial(short a_ItemType); + + /** Get the repair cost from the item, or 0 if the item hasn't repair cost. */ + virtual int GetRepairCost(void); + + /** 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 +102,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/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 8fc1d8543..bc650cdbd 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -47,9 +47,9 @@ public: public cBlockTracer::cCallbacks { public: - cCallbacks(cWorld * a_CBWorld) : - m_HasHitFluid(false), - m_World(a_CBWorld) + + cCallbacks(void) : + m_HasHitFluid(false) { } @@ -62,10 +62,9 @@ public: return false; } AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, BLOCK_FACE_YP); // Always place pad at top of water block - BLOCKTYPE Block = m_World->GetBlock(a_CBBlockX, a_CBBlockY, a_CBBlockZ); if ( - !IsBlockWater(Block) && - cBlockInfo::FullyOccupiesVoxel(Block) + !IsBlockWater(a_CBBlockType) && + cBlockInfo::FullyOccupiesVoxel(a_CBBlockType) ) { // Can't place lilypad on air/in another block! @@ -80,11 +79,10 @@ public: Vector3i m_Pos; bool m_HasHitFluid; - cWorld * m_World; }; - cCallbacks Callbacks(a_World); + cCallbacks Callbacks; cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index 4f8ef4eb1..82bec52d4 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -86,6 +86,19 @@ public: } return false; } + + virtual bool CanRepairWithRawMaterial(short a_ItemType) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_PICKAXE: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_PICKAXE: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_PICKAXE: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_PICKAXE: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_PICKAXE: return (a_ItemType == E_ITEM_DIAMOND); + } + return false; + } } ; diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index 873d5ae25..333ba46e8 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -41,4 +41,18 @@ public: { return (a_BlockType == E_BLOCK_SNOW); } + + virtual bool CanRepairWithRawMaterial(short a_ItemType) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_SHOVEL: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SHOVEL: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SHOVEL: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SHOVEL: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SHOVEL: return (a_ItemType == E_ITEM_DIAMOND); + } + return false; + } + }; diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h index 0d6019398..bba97afa1 100644 --- a/src/Items/ItemSpawnEgg.h +++ b/src/Items/ItemSpawnEgg.h @@ -33,7 +33,10 @@ public: a_BlockY--; } - if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, (cMonster::eType)(a_Item.m_ItemDamage)) >= 0) + cMonster::eType MonsterType = ItemDamageToMonsterType(a_Item.m_ItemDamage); + if ( + (MonsterType != cMonster::mtInvalidType) && // Valid monster type + (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType) >= 0)) // Spawning succeeded { if (!a_Player->IsGameModeCreative()) { @@ -45,6 +48,41 @@ public: return false; } + + + /** Converts the Spawn egg item damage to the monster type to spawn. + Returns mtInvalidType for invalid damage values. */ + static cMonster::eType ItemDamageToMonsterType(short a_ItemDamage) + { + switch (a_ItemDamage) + { + case E_META_SPAWN_EGG_BAT: return cMonster::mtBat; + case E_META_SPAWN_EGG_BLAZE: return cMonster::mtBlaze; + case E_META_SPAWN_EGG_CAVE_SPIDER: return cMonster::mtCaveSpider; + case E_META_SPAWN_EGG_CHICKEN: return cMonster::mtChicken; + case E_META_SPAWN_EGG_COW: return cMonster::mtCow; + case E_META_SPAWN_EGG_CREEPER: return cMonster::mtCreeper; + case E_META_SPAWN_EGG_ENDERMAN: return cMonster::mtEnderman; + case E_META_SPAWN_EGG_GHAST: return cMonster::mtGhast; + case E_META_SPAWN_EGG_HORSE: return cMonster::mtHorse; + case E_META_SPAWN_EGG_MAGMA_CUBE: return cMonster::mtMagmaCube; + case E_META_SPAWN_EGG_MOOSHROOM: return cMonster::mtMooshroom; + case E_META_SPAWN_EGG_OCELOT: return cMonster::mtOcelot; + case E_META_SPAWN_EGG_PIG: return cMonster::mtPig; + case E_META_SPAWN_EGG_SHEEP: return cMonster::mtSheep; + case E_META_SPAWN_EGG_SILVERFISH: return cMonster::mtSilverfish; + case E_META_SPAWN_EGG_SKELETON: return cMonster::mtSkeleton; + case E_META_SPAWN_EGG_SLIME: return cMonster::mtSlime; + case E_META_SPAWN_EGG_SPIDER: return cMonster::mtSpider; + case E_META_SPAWN_EGG_SQUID: return cMonster::mtSquid; + case E_META_SPAWN_EGG_VILLAGER: return cMonster::mtVillager; + case E_META_SPAWN_EGG_WITCH: return cMonster::mtWitch; + case E_META_SPAWN_EGG_WOLF: return cMonster::mtWolf; + case E_META_SPAWN_EGG_ZOMBIE: return cMonster::mtZombie; + case E_META_SPAWN_EGG_ZOMBIE_PIGMAN: return cMonster::mtZombiePigman; + } + return cMonster::mtInvalidType; + } } ; diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index a7c1d2432..44feb2d83 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,6 +23,19 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } + + virtual bool CanRepairWithRawMaterial(short a_ItemType) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_SWORD: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SWORD: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SWORD: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SWORD: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SWORD: return (a_ItemType == E_ITEM_DIAMOND); + } + return false; + } } ; diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index c6a4e714e..35c2b8731 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -28,15 +28,19 @@ 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 { + Vector3d Pos = a_Player->GetThrowStartPos(); + Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; + + if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed) < 0) + { + return false; + } + if (!a_Player->IsGameModeCreative()) { 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; } @@ -127,7 +131,10 @@ public: return false; } - a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()); + if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()) < 0) + { + return false; + } if (!a_Player->IsGameModeCreative()) { diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 302473d71..5ba2940d2 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -286,6 +286,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item) { a_Item.m_CallbackAfter->Call(a_Item.m_ChunkX, a_Item.m_ChunkZ); } + a_Item.Disable(); delete &a_Item; } 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/MCLogger.cpp b/src/MCLogger.cpp index 80fa7b173..583438d65 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 <io.h> // Needed for _isatty(), not available on Linux @@ -33,7 +32,8 @@ cMCLogger * cMCLogger::GetInstance(void) -cMCLogger::cMCLogger(void) +cMCLogger::cMCLogger(void): + 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; } #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 c0150c124..114210f63 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 m_ShouldColorOutput; /// Sets the specified color scheme in the terminal (TODO: if coloring available) diff --git a/src/MobProximityCounter.cpp b/src/MobProximityCounter.cpp index 6c44ea458..519757c2c 100644 --- a/src/MobProximityCounter.cpp +++ b/src/MobProximityCounter.cpp @@ -34,7 +34,7 @@ void cMobProximityCounter::CollectMob(cEntity& a_Monster, cChunk& a_Chunk, doubl void cMobProximityCounter::convertMaps() { - for(tMonsterToDistance::const_iterator itr = m_MonsterToDistance.begin(); itr != m_MonsterToDistance.end(); itr++) + for(tMonsterToDistance::const_iterator itr = m_MonsterToDistance.begin(); itr != m_MonsterToDistance.end(); ++itr) { m_DistanceToMonster.insert(tDistanceToMonster::value_type(itr->second.m_Distance,sMonsterAndChunk(*itr->first,itr->second.m_Chunk))); } @@ -55,7 +55,7 @@ cMobProximityCounter::sIterablePair cMobProximityCounter::getMobWithinThosesDist convertMaps(); } - for(tDistanceToMonster::const_iterator itr = m_DistanceToMonster.begin(); itr != m_DistanceToMonster.end(); itr++) + for(tDistanceToMonster::const_iterator itr = m_DistanceToMonster.begin(); itr != m_DistanceToMonster.end(); ++itr) { if (toReturn.m_Begin == m_DistanceToMonster.end()) { diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 05da5d01c..ce8e06777 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -13,7 +13,7 @@ cMobSpawner::cMobSpawner(cMonster::eFamily a_MonsterFamily,const std::set<cMonst m_NewPack(true), m_MobType(cMonster::mtInvalidType) { - for (std::set<cMonster::eType>::const_iterator itr = a_AllowedTypes.begin(); itr != a_AllowedTypes.end(); itr++) + for (std::set<cMonster::eType>::const_iterator itr = a_AllowedTypes.begin(); itr != a_AllowedTypes.end(); ++itr) { if (cMonster::FamilyFromType(*itr) == a_MonsterFamily) { @@ -112,7 +112,7 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) for(int i = 0; i < iRandom; i++) { - itr++; + ++itr; } return *itr; diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 0901f85a9..85b122034 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,17 @@ void cAggressiveMonster::Attack(float a_Dt) +bool cAggressiveMonster::IsMovingToTargetPosition() +{ + // Difference between destination x and target x is negligible (to 10^-12 precision) + if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < std::numeric_limits<float>::epsilon()) + { + return false; + } + // Difference between destination z and target z is negligible (to 10^-12 precision) + else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > std::numeric_limits<float>::epsilon()) + { + return false; + } + return true; +} diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 152260f95..d70ff04a3 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(); + } ; diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 84ff8929b..326b42f07 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -3,6 +3,7 @@ #include "Blaze.h" #include "../World.h" +#include "../Entities/FireChargeEntity.h" 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/Mobs/Cavespider.cpp b/src/Mobs/CaveSpider.cpp index 94e93283d..56ecd2d28 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -1,15 +1,14 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "Cavespider.h" +#include "CaveSpider.h" #include "../World.h" -cCavespider::cCavespider(void) : - super("Cavespider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) +cCaveSpider::cCaveSpider(void) : + super("CaveSpider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5) { } @@ -17,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); @@ -29,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 10ea03f7b..be9f174f9 100644 --- a/src/Mobs/Cavespider.h +++ b/src/Mobs/CaveSpider.h @@ -1,4 +1,3 @@ - #pragma once #include "AggressiveMonster.h" @@ -7,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/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/Ghast.cpp b/src/Mobs/Ghast.cpp index fe18f5e76..d8a7663f8 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -3,6 +3,7 @@ #include "Ghast.h" #include "../World.h" +#include "../Entities/GhastFireballEntity.h" 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 05405f082..3e9abc108 100644 --- a/src/Mobs/Magmacube.cpp +++ b/src/Mobs/MagmaCube.cpp @@ -1,7 +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/Magmacube.h b/src/Mobs/MagmaCube.h index 130952970..43065cae5 100644 --- a/src/Mobs/Magmacube.h +++ b/src/Mobs/MagmaCube.h @@ -1,4 +1,3 @@ - #pragma once #include "AggressiveMonster.h" diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index aa6071515..62670907f 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -111,9 +111,9 @@ void cMonster::SpawnOn(cClientHandle & a_Client) void cMonster::TickPathFinding() { - const int PosX = (int)floor(GetPosX()); - const int PosY = (int)floor(GetPosY()); - const int PosZ = (int)floor(GetPosZ()); + const int PosX = POSX_TOINT; + const int PosY = POSY_TOINT; + const int PosZ = POSZ_TOINT; m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z); @@ -148,13 +148,27 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtY = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 1, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); - BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); - - if ((!cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + int LowestY = FindFirstNonAirBlockPosition(gCrossCoords[i].x + PosX, gCrossCoords[i].z + PosZ); + BLOCKTYPE BlockAtLowestY = m_World->GetBlock(gCrossCoords[i].x + PosX, LowestY, gCrossCoords[i].z + PosZ); + + if ( + (!cBlockInfo::IsSolid(BlockAtY)) && + (!cBlockInfo::IsSolid(BlockAtYP)) && + (!IsBlockLava(BlockAtLowestY)) && + (BlockAtLowestY != E_BLOCK_CACTUS) && + (PosY - LowestY < FALL_DAMAGE_HEIGHT) + ) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); } - else if ((cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!cBlockInfo::IsSolid(BlockAtYPP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + else if ( + (cBlockInfo::IsSolid(BlockAtY)) && + (BlockAtY != E_BLOCK_CACTUS) && + (!cBlockInfo::IsSolid(BlockAtYP)) && + (!cBlockInfo::IsSolid(BlockAtYPP)) && + (BlockAtY != E_BLOCK_FENCE) && + (BlockAtY != E_BLOCK_FENCE_GATE) + ) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); } @@ -402,7 +416,7 @@ void cMonster::HandleFalling() GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); } - m_LastGroundHeight = (int)floor(GetPosY()); + m_LastGroundHeight = POSY_TOINT; } } @@ -411,7 +425,7 @@ void cMonster::HandleFalling() int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) { - int PosY = (int)floor(GetPosY()); + int PosY = POSY_TOINT; if (PosY < 0) PosY = 0; @@ -443,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); @@ -454,6 +471,7 @@ void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) { m_Target = a_TDI.Attacker; } + return true; } @@ -526,7 +544,10 @@ void cMonster::KilledBy(cEntity * a_Killer) break; } } - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward); + if ((a_Killer != NULL) && (!IsBaby())) + { + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward); + } m_DestroyTimer = 0; } @@ -744,8 +765,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 mfNoSpawn; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -756,17 +779,20 @@ 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; - } ; + + case mtInvalidType: break; + } ASSERT(!"Unhandled mob type"); - return mfMaxplusone; + return mfUnhandled; } @@ -777,10 +803,12 @@ 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 mfNoSpawn: return -1; + case mfUnhandled: break; } ASSERT(!"Unhandled mob family"); return -1; @@ -799,6 +827,10 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) switch (a_MobType) { case mtMagmaCube: + { + toReturn = new cMagmaCube(Random.NextInt(2) + 1); + break; + } case mtSlime: { toReturn = new cSlime(Random.NextInt(2) + 1); @@ -842,13 +874,14 @@ 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; 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; @@ -966,15 +999,15 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk) return; } - int RelY = (int)floor(GetPosY()); + int RelY = POSY_TOINT; if ((RelY < 0) || (RelY >= cChunkDef::Height)) { // Outside the world return; } - int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width; - int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width; + int RelX = POSX_TOINT - GetChunkX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - GetChunkZ() * cChunkDef::Width; if (!a_Chunk.IsLightValid()) { @@ -986,7 +1019,8 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk) (a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight (a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand (GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime - !IsOnFire() // Not already burning + !IsOnFire() && // Not already burning + (GetWorld()->GetWeather() != eWeather_Rain) // Not raining ) { // Burn for 100 ticks, then decide again diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 776426a0d..7d7e90eb2 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,7 +66,8 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid - mfMaxplusone, // Nothing. Be sure this is the last and the others are in order + mfNoSpawn, + mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; // tolua_end @@ -87,7 +88,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; @@ -185,14 +186,14 @@ protected: inline bool IsNextYPosReachable(int a_PosY) { return ( - (a_PosY <= (int)floor(GetPosY())) || + (a_PosY <= POSY_TOINT) || DoesPosYRequireJump(a_PosY) ); } /** Returns if a monster can reach a given height by jumping */ inline bool DoesPosYRequireJump(int a_PosY) { - return ((a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1)); + return ((a_PosY > POSY_TOINT) && (a_PosY == POSY_TOINT + 1)); } /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */ 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/Sheep.cpp b/src/Mobs/Sheep.cpp index c64360153..5a6b760af 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -36,7 +36,8 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSheep::OnRightClicked(cPlayer & a_Player) { - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) + const cItem & EquippedItem = a_Player.GetEquippedItem(); + if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) { m_IsSheared = true; m_World->BroadcastEntityMetadata(*this); @@ -51,9 +52,9 @@ void cSheep::OnRightClicked(cPlayer & a_Player) Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); } - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - a_Player.GetEquippedItem().m_ItemDamage)) + else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage)) { - m_WoolColor = 15 - a_Player.GetEquippedItem().m_ItemDamage; + m_WoolColor = 15 - EquippedItem.m_ItemDamage; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); @@ -101,7 +102,7 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) { if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_SHEEP_EATING); + m_World->BroadcastEntityStatus(*this, esSheepEating); m_TimeToStopEating = 40; } } diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 1685f40c5..1e62d7987 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -3,6 +3,7 @@ #include "Skeleton.h" #include "../World.h" +#include "../Entities/ArrowEntity.h" diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index bbd8d6aaa..41283acf4 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -23,16 +23,21 @@ 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) { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_VILLAGER_ANGRY); + 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..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); } @@ -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) + if (m_WitherInvulnerableTicks > 0) { - return; + return false; } if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) { - return; + return false; } - super::DoTakeDamage(a_TDI); + return super::DoTakeDamage(a_TDI); } @@ -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 bc78bfaad..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; @@ -27,13 +27,13 @@ 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: /** 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/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 0d3619166..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; } @@ -75,12 +80,12 @@ void cWolf::OnRightClicked(cPlayer & a_Player) SetMaxHealth(20); SetIsTame(true); SetOwner(a_Player.GetName()); - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED); + m_World->BroadcastEntityStatus(*this, esWolfTamed); m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } else { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMING); + m_World->BroadcastEntityStatus(*this, esWolfTaming); m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } } diff --git a/src/Mobs/Wolf.h b/src/Mobs/Wolf.h index 9e5ad03c7..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(); @@ -37,7 +37,7 @@ public: void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; } void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; } void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; } - void SetOwner (AString a_NewOwner) { m_OwnerName = a_NewOwner; } + void SetOwner (const AString & a_NewOwner) { m_OwnerName = a_NewOwner; } void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; } protected: diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/ZombiePigman.cpp index a0142b566..c9d94face 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/ZombiePigman.cpp @@ -1,7 +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/Mobs/Zombiepigman.h b/src/Mobs/ZombiePigman.h index 67991d56a..ab3cebf6d 100644 --- a/src/Mobs/Zombiepigman.h +++ b/src/Mobs/ZombiePigman.h @@ -1,4 +1,3 @@ - #pragma once #include "PassiveAggressiveMonster.h" diff --git a/src/MonsterConfig.cpp b/src/MonsterConfig.cpp index c06bd6b6f..72a3a3245 100644 --- a/src/MonsterConfig.cpp +++ b/src/MonsterConfig.cpp @@ -17,6 +17,7 @@ struct cMonsterConfig::sAttributesStruct int m_AttackRange; double m_AttackRate; int m_MaxHealth; + bool m_IsFireproof; }; @@ -72,6 +73,7 @@ void cMonsterConfig::Initialize() Attributes.m_SightDistance = MonstersIniFile.GetValueI(Name, "SightDistance", 0); Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0); Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1); + Attributes.m_IsFireproof = MonstersIniFile.GetValueB(Name, "IsFireproof", false); m_pState->AttributesList.push_front(Attributes); } // for i - SplitList[] } @@ -92,6 +94,7 @@ void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Na a_Monster->SetSightDistance(itr->m_SightDistance); a_Monster->SetAttackRate ((float)itr->m_AttackRate); a_Monster->SetMaxHealth (itr->m_MaxHealth); + a_Monster->SetIsFireproof (itr->m_IsFireproof); return; } } // for itr - m_pState->AttributesList[] diff --git a/src/Noise.cpp b/src/Noise.cpp index 32922c8f3..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); @@ -744,6 +746,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++) @@ -840,12 +844,14 @@ void cPerlinNoise::Generate2D( } // Generate the first octave directly into array: - m_Octaves.front().m_Noise.Generate2D( + const cOctave & FirstOctave = m_Octaves.front(); + + FirstOctave.m_Noise.Generate2D( a_Workspace, a_SizeX, a_SizeY, - a_StartX * m_Octaves.front().m_Frequency, a_EndX * m_Octaves.front().m_Frequency, - a_StartY * m_Octaves.front().m_Frequency, a_EndY * m_Octaves.front().m_Frequency + a_StartX * FirstOctave.m_Frequency, a_EndX * FirstOctave.m_Frequency, + a_StartY * FirstOctave.m_Frequency, a_EndY * FirstOctave.m_Frequency ); - NOISE_DATATYPE Amplitude = m_Octaves.front().m_Amplitude; + NOISE_DATATYPE Amplitude = FirstOctave.m_Amplitude; for (int i = 0; i < ArrayCount; i++) { a_Array[i] *= Amplitude; @@ -902,13 +908,15 @@ void cPerlinNoise::Generate3D( } // Generate the first octave directly into array: - m_Octaves.front().m_Noise.Generate3D( + const cOctave & FirstOctave = m_Octaves.front(); + + FirstOctave.m_Noise.Generate3D( a_Workspace, a_SizeX, a_SizeY, a_SizeZ, - a_StartX * m_Octaves.front().m_Frequency, a_EndX * m_Octaves.front().m_Frequency, - a_StartY * m_Octaves.front().m_Frequency, a_EndY * m_Octaves.front().m_Frequency, - a_StartZ * m_Octaves.front().m_Frequency, a_EndZ * m_Octaves.front().m_Frequency + a_StartX * FirstOctave.m_Frequency, a_EndX * FirstOctave.m_Frequency, + a_StartY * FirstOctave.m_Frequency, a_EndY * FirstOctave.m_Frequency, + a_StartZ * FirstOctave.m_Frequency, a_EndZ * FirstOctave.m_Frequency ); - NOISE_DATATYPE Amplitude = m_Octaves.front().m_Amplitude; + NOISE_DATATYPE Amplitude = FirstOctave.m_Amplitude; for (int i = 0; i < ArrayCount; i++) { a_Array[i] = a_Workspace[i] * Amplitude; diff --git a/src/Noise.h b/src/Noise.h index 62004503f..e605051b5 100644 --- a/src/Noise.h +++ b/src/Noise.h @@ -280,7 +280,7 @@ NOISE_DATATYPE cNoise::CubicInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE cNoise::CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct) { const NOISE_DATATYPE ft = a_Pct * (NOISE_DATATYPE)3.1415927; - const NOISE_DATATYPE f = (1 - cos(ft)) * (NOISE_DATATYPE)0.5; + const NOISE_DATATYPE f = (NOISE_DATATYPE)((NOISE_DATATYPE)(1 - cos(ft)) * (NOISE_DATATYPE)0.5); return a_A * (1 - f) + a_B * f; } diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp deleted file mode 100644 index 07f48b955..000000000 --- a/src/OSSupport/BlockingTCPLink.cpp +++ /dev/null @@ -1,142 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "BlockingTCPLink.h" -#include "Errors.h" - - - - -cBlockingTCPLink::cBlockingTCPLink(void) -{ -} - - - - - -cBlockingTCPLink::~cBlockingTCPLink() -{ - CloseSocket(); -} - - - - - -void cBlockingTCPLink::CloseSocket() -{ - if (!m_Socket.IsValid()) - { - m_Socket.CloseSocket(); - } -} - - - - - -bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort) -{ - ASSERT(!m_Socket.IsValid()); - if (m_Socket.IsValid()) - { - LOGWARN("WARNING: cTCPLink Connect() called while still connected."); - m_Socket.CloseSocket(); - } - - struct hostent *hp; - unsigned int addr; - struct sockaddr_in server; - - m_Socket = socket(AF_INET, SOCK_STREAM, 0); - if (!m_Socket.IsValid()) - { - LOGERROR("cTCPLink: Cannot create a socket"); - return false; - } - - addr = inet_addr(iAddress); - hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET); - if (hp == NULL) - { - //LOGWARN("cTCPLink: gethostbyaddr returned NULL"); - hp = gethostbyname(iAddress); - if (hp == NULL) - { - LOGWARN("cTCPLink: Could not resolve %s", iAddress); - CloseSocket(); - return false; - } - } - - memcpy(&server.sin_addr.s_addr,hp->h_addr, hp->h_length); - server.sin_family = AF_INET; - server.sin_port = htons( (unsigned short)iPort); - if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server))) - { - LOGWARN("cTCPLink: Connection to \"%s:%d\" failed (%s)", iAddress, iPort,GetOSErrorString( cSocket::GetLastError() ).c_str() ); - CloseSocket(); - return false; - } - - return true; -} - - - - - -int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* = 0 */ ) -{ - UNUSED(a_Flags); - - ASSERT(m_Socket.IsValid()); - if (!m_Socket.IsValid()) - { - LOGERROR("cBlockingTCPLink: Trying to send data without a valid connection!"); - return -1; - } - return m_Socket.Send(a_Data, a_Size); -} - - - - - -int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */ ) -{ - UNUSED(a_Flags); - - ASSERT(m_Socket.IsValid()); - if (!m_Socket.IsValid()) - { - LOGWARN("cBlockingTCPLink: Trying to send message without a valid connection!"); - return -1; - } - return m_Socket.Send(a_Message, strlen(a_Message)); -} - - - - - -void cBlockingTCPLink::ReceiveData(AString & oData) -{ - ASSERT(m_Socket.IsValid()); - if (!m_Socket.IsValid()) - { - return; - } - - int Received = 0; - char Buffer[256]; - while ((Received = recv(m_Socket, Buffer, sizeof(Buffer), 0)) > 0) - { - oData.append(Buffer, Received); - } -} - - - - diff --git a/src/OSSupport/BlockingTCPLink.h b/src/OSSupport/BlockingTCPLink.h deleted file mode 100644 index cb5f9e3f4..000000000 --- a/src/OSSupport/BlockingTCPLink.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once - -#include "Socket.h" - - - - - -class cBlockingTCPLink // tolua_export -{ // tolua_export -public: // tolua_export - cBlockingTCPLink(void); // tolua_export - ~cBlockingTCPLink(); // tolua_export - - bool Connect( const char* a_Address, unsigned int a_Port ); // tolua_export - int Send( char* a_Data, unsigned int a_Size, int a_Flags = 0 ); // tolua_export - int SendMessage( const char* a_Message, int a_Flags = 0 ); // tolua_export - void CloseSocket(); // tolua_export - void ReceiveData(AString & oData); // tolua_export -protected: - - cSocket m_Socket; -}; // tolua_export - - - - 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/OSSupport/File.cpp b/src/OSSupport/File.cpp index 7f0f0ad2f..8c24fa541 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -67,15 +67,15 @@ 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 - fopen_s(&m_File, (FILE_IO_PREFIX + iFileName).c_str(), Mode); + m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), Mode, _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), Mode); #endif // _WIN32 @@ -88,7 +88,7 @@ bool cFile::Open(const AString & iFileName, eMode iMode) // Simply re-open for read-writing, erasing existing contents: #ifdef _WIN32 - fopen_s(&m_File, (FILE_IO_PREFIX + iFileName).c_str(), "wb+"); + m_File = _fsopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+", _SH_DENYWR); #else m_File = fopen((FILE_IO_PREFIX + iFileName).c_str(), "wb+"); #endif // _WIN32 @@ -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); 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) { } diff --git a/src/OSSupport/IsThread.cpp b/src/OSSupport/IsThread.cpp index 36205bcf1..04fc818e4 100644 --- a/src/OSSupport/IsThread.cpp +++ b/src/OSSupport/IsThread.cpp @@ -18,26 +18,33 @@ // Usage: SetThreadName (-1, "MainThread"); // -static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName) +// Code adapted from MSDN: http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx + +const DWORD MS_VC_EXCEPTION = 0x406D1388; + +#pragma pack(push, 8) +typedef struct tagTHREADNAME_INFO { - struct - { - DWORD dwType; // must be 0x1000 - LPCSTR szName; // pointer to name (in user addr space) - DWORD dwThreadID; // thread ID (-1=caller thread) - DWORD dwFlags; // reserved for future use, must be zero - } info; - + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwThreadID; // Thread ID (-1 = caller thread). + DWORD dwFlags; // Reserved for future use, must be zero. +} THREADNAME_INFO; +#pragma pack(pop) + +static void SetThreadName(DWORD dwThreadID, const char * threadName) +{ + THREADNAME_INFO info; info.dwType = 0x1000; - info.szName = szThreadName; + info.szName = threadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { - RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (DWORD *)&info); + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info); } - __except(EXCEPTION_CONTINUE_EXECUTION) + __except (EXCEPTION_EXECUTE_HANDLER) { } } diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index 42b8bfdda..57651a490 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -62,7 +62,7 @@ protected: HANDLE m_Handle; - static DWORD_PTR __stdcall thrExecute(LPVOID a_Param) + static DWORD __stdcall thrExecute(LPVOID a_Param) { // Create a window so that the thread can be identified by 3rd party tools: HWND IdentificationWnd = CreateWindow("STATIC", ((cIsThread *)a_Param)->m_ThreadName.c_str(), 0, 0, 0, 0, WS_OVERLAPPED, NULL, NULL, NULL, NULL); diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index c29e495c3..98f694a79 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -295,7 +295,7 @@ bool cSocket::ConnectToLocalhostIPv4(unsigned short a_Port) bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port) { - // First try IP Address string to hostent conversion, because it's faster + // First try IP Address string to hostent conversion, because it's faster and local: unsigned long addr = inet_addr(a_HostNameOrAddr.c_str()); if (addr == INADDR_NONE) { @@ -307,10 +307,16 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por CloseSocket(); return false; } - // Should be optimised to a single word copy memcpy(&addr, hp->h_addr, hp->h_length); } + // If the socket is not created yet, create one: + if (!IsValid()) + { + m_Socket = socket((int)IPv4, SOCK_STREAM, 0); + } + + // Connect the socket: sockaddr_in server; server.sin_addr.s_addr = addr; server.sin_family = AF_INET; diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp index 3df75f0e7..7a10ef8d2 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -10,27 +10,34 @@ // // Usage: SetThreadName (-1, "MainThread"); // + +// Code adapted from MSDN: http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx + +const DWORD MS_VC_EXCEPTION = 0x406D1388; + +#pragma pack(push, 8) typedef struct tagTHREADNAME_INFO { - DWORD dwType; // must be 0x1000 - LPCSTR szName; // pointer to name (in user addr space) - DWORD dwThreadID; // thread ID (-1=caller thread) - DWORD dwFlags; // reserved for future use, must be zero + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwThreadID; // Thread ID (-1 = caller thread). + DWORD dwFlags; // Reserved for future use, must be zero. } THREADNAME_INFO; +#pragma pack(pop) -void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName) +static void SetThreadName(DWORD dwThreadID, const char * threadName) { THREADNAME_INFO info; info.dwType = 0x1000; - info.szName = szThreadName; + info.szName = threadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { - RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info ); + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info); } - __except(EXCEPTION_CONTINUE_EXECUTION) + __except (EXCEPTION_EXECUTE_HANDLER) { } } diff --git a/src/PolarSSL++/AesCfb128Decryptor.cpp b/src/PolarSSL++/AesCfb128Decryptor.cpp new file mode 100644 index 000000000..af0d5106e --- /dev/null +++ b/src/PolarSSL++/AesCfb128Decryptor.cpp @@ -0,0 +1,67 @@ + +// AesCfb128Decryptor.cpp + +// Implements the cAesCfb128Decryptor class decrypting data using AES CFB-128 + +#include "Globals.h" +#include "AesCfb128Decryptor.h" + + + + + +cAesCfb128Decryptor::cAesCfb128Decryptor(void) : + m_IVOffset(0), + m_IsValid(false) +{ +} + + + + + +cAesCfb128Decryptor::~cAesCfb128Decryptor() +{ + // Clear the leftover in-memory data, so that they can't be accessed by a backdoor + memset(&m_Aes, 0, sizeof(m_Aes)); +} + + + + + +void cAesCfb128Decryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) +{ + ASSERT(!IsValid()); // Cannot Init twice + + memcpy(m_IV, a_IV, 16); + aes_setkey_enc(&m_Aes, a_Key, 128); + m_IsValid = true; +} + + + + + +void cAesCfb128Decryptor::ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length) +{ + ASSERT(IsValid()); // Must Init() first + + // PolarSSL doesn't support AES-CFB8, need to implement it manually: + for (size_t i = 0; i < a_Length; i++) + { + Byte Buffer[sizeof(m_IV)]; + aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); + for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) + { + m_IV[idx] = m_IV[idx + 1]; + } + m_IV[sizeof(m_IV) - 1] = a_EncryptedIn[i]; + a_DecryptedOut[i] = a_EncryptedIn[i] ^ Buffer[0]; + } +} + + + + + diff --git a/src/PolarSSL++/AesCfb128Decryptor.h b/src/PolarSSL++/AesCfb128Decryptor.h new file mode 100644 index 000000000..68c203d70 --- /dev/null +++ b/src/PolarSSL++/AesCfb128Decryptor.h @@ -0,0 +1,52 @@ + +// AesCfb128Decryptor.h + +// Declares the cAesCfb128Decryptor class decrypting data using AES CFB-128 + + + + + +#pragma once + +#include "polarssl/aes.h" + + + + + +/** Decrypts data using the AES / CFB 128 algorithm */ +class cAesCfb128Decryptor +{ +public: + Byte test; + + cAesCfb128Decryptor(void); + ~cAesCfb128Decryptor(); + + /** Initializes the decryptor with the specified Key / IV */ + void Init(const Byte a_Key[16], const Byte a_IV[16]); + + /** Decrypts a_Length bytes of the encrypted data; produces a_Length output bytes */ + void ProcessData(Byte * a_DecryptedOut, const Byte * a_EncryptedIn, size_t a_Length); + + /** Returns true if the object has been initialized with the Key / IV */ + bool IsValid(void) const { return m_IsValid; } + +protected: + aes_context m_Aes; + + /** The InitialVector, used by the CFB mode decryption */ + Byte m_IV[16]; + + /** Current offset in the m_IV, used by the CFB mode decryption */ + size_t m_IVOffset; + + /** Indicates whether the object has been initialized with the Key / IV */ + bool m_IsValid; +} ; + + + + + diff --git a/src/PolarSSL++/AesCfb128Encryptor.cpp b/src/PolarSSL++/AesCfb128Encryptor.cpp new file mode 100644 index 000000000..a641ad48e --- /dev/null +++ b/src/PolarSSL++/AesCfb128Encryptor.cpp @@ -0,0 +1,68 @@ + +// AesCfb128Encryptor.cpp + +// Implements the cAesCfb128Encryptor class encrypting data using AES CFB-128 + +#include "Globals.h" +#include "AesCfb128Encryptor.h" + + + + + +cAesCfb128Encryptor::cAesCfb128Encryptor(void) : + m_IVOffset(0), + m_IsValid(false) +{ +} + + + + + +cAesCfb128Encryptor::~cAesCfb128Encryptor() +{ + // Clear the leftover in-memory data, so that they can't be accessed by a backdoor + memset(&m_Aes, 0, sizeof(m_Aes)); +} + + + + + +void cAesCfb128Encryptor::Init(const Byte a_Key[16], const Byte a_IV[16]) +{ + ASSERT(!IsValid()); // Cannot Init twice + ASSERT(m_IVOffset == 0); + + memcpy(m_IV, a_IV, 16); + aes_setkey_enc(&m_Aes, a_Key, 128); + m_IsValid = true; +} + + + + + +void cAesCfb128Encryptor::ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length) +{ + ASSERT(IsValid()); // Must Init() first + + // PolarSSL doesn't do AES-CFB8, so we need to implement it ourselves: + for (size_t i = 0; i < a_Length; i++) + { + Byte Buffer[sizeof(m_IV)]; + aes_crypt_ecb(&m_Aes, AES_ENCRYPT, m_IV, Buffer); + for (size_t idx = 0; idx < sizeof(m_IV) - 1; idx++) + { + m_IV[idx] = m_IV[idx + 1]; + } + a_EncryptedOut[i] = a_PlainIn[i] ^ Buffer[0]; + m_IV[sizeof(m_IV) - 1] = a_EncryptedOut[i]; + } +} + + + + + diff --git a/src/PolarSSL++/AesCfb128Encryptor.h b/src/PolarSSL++/AesCfb128Encryptor.h new file mode 100644 index 000000000..9dbb5d2c3 --- /dev/null +++ b/src/PolarSSL++/AesCfb128Encryptor.h @@ -0,0 +1,50 @@ + +// AesCfb128Encryptor.h + +// Declares the cAesCfb128Encryptor class encrypting data using AES CFB-128 + + + + + +#pragma once + +#include "polarssl/aes.h" + + + + + +/** Encrypts data using the AES / CFB (128) algorithm */ +class cAesCfb128Encryptor +{ +public: + cAesCfb128Encryptor(void); + ~cAesCfb128Encryptor(); + + /** Initializes the decryptor with the specified Key / IV */ + void Init(const Byte a_Key[16], const Byte a_IV[16]); + + /** Encrypts a_Length bytes of the plain data; produces a_Length output bytes */ + void ProcessData(Byte * a_EncryptedOut, const Byte * a_PlainIn, size_t a_Length); + + /** Returns true if the object has been initialized with the Key / IV */ + bool IsValid(void) const { return m_IsValid; } + +protected: + aes_context m_Aes; + + /** The InitialVector, used by the CFB mode encryption */ + Byte m_IV[16]; + + /** Current offset in the m_IV, used by the CFB mode encryption */ + size_t m_IVOffset; + + /** Indicates whether the object has been initialized with the Key / IV */ + bool m_IsValid; +} ; + + + + + diff --git a/src/PolarSSL++/BlockingSslClientSocket.cpp b/src/PolarSSL++/BlockingSslClientSocket.cpp new file mode 100644 index 000000000..699bc57ee --- /dev/null +++ b/src/PolarSSL++/BlockingSslClientSocket.cpp @@ -0,0 +1,195 @@ + +// BlockingSslClientSocket.cpp + +// Implements the cBlockingSslClientSocket class representing a blocking TCP socket with client SSL encryption over it + +#include "Globals.h" +#include "BlockingSslClientSocket.h" + + + + + +cBlockingSslClientSocket::cBlockingSslClientSocket(void) : + m_Ssl(*this), + m_IsConnected(false) +{ + // Nothing needed yet +} + + + + + +bool cBlockingSslClientSocket::Connect(const AString & a_ServerName, UInt16 a_Port) +{ + // If already connected, report an error: + if (m_IsConnected) + { + // TODO: Handle this better - if connected to the same server and port, and the socket is alive, return success + m_LastErrorText = "Already connected"; + return false; + } + + // Connect the underlying socket: + m_Socket.CreateSocket(cSocket::IPv4); + if (!m_Socket.ConnectIPv4(a_ServerName.c_str(), a_Port)) + { + Printf(m_LastErrorText, "Socket connect failed: %s", m_Socket.GetLastErrorString().c_str()); + return false; + } + + // Initialize the SSL: + int ret = m_Ssl.Initialize(true); + if (ret != 0) + { + Printf(m_LastErrorText, "SSL initialization failed: -0x%x", -ret); + return false; + } + + // If we have been assigned a trusted CA root cert store, push it into the SSL context: + if (m_CACerts.get() != NULL) + { + m_Ssl.SetCACerts(m_CACerts, m_ExpectedPeerName); + } + + ret = m_Ssl.Handshake(); + if (ret != 0) + { + Printf(m_LastErrorText, "SSL handshake failed: -0x%x", -ret); + return false; + } + + m_IsConnected = true; + return true; +} + + + + + + +bool cBlockingSslClientSocket::SetTrustedRootCertsFromString(const AString & a_CACerts, const AString & a_ExpectedPeerName) +{ + // Warn if used multiple times, but don't signal an error: + if (m_CACerts.get() != NULL) + { + LOGWARNING( + "SSL: Trying to set multiple trusted CA root cert stores, only the last one will be used. Name: %s", + a_ExpectedPeerName.c_str() + ); + } + + // Parse the cert: + m_CACerts.reset(new cX509Cert); + int ret = m_CACerts->Parse(a_CACerts.data(), a_CACerts.size()); + if (ret < 0) + { + Printf(m_LastErrorText, "CA cert parsing failed: -0x%x", -ret); + return false; + } + m_ExpectedPeerName = a_ExpectedPeerName; + + return true; +} + + + + + +bool cBlockingSslClientSocket::Send(const void * a_Data, size_t a_NumBytes) +{ + ASSERT(m_IsConnected); + + // Keep sending the data until all of it is sent: + const char * Data = (const char *)a_Data; + size_t NumBytes = a_NumBytes; + for (;;) + { + int res = m_Ssl.WritePlain(a_Data, a_NumBytes); + if (res < 0) + { + ASSERT(res != POLARSSL_ERR_NET_WANT_READ); // This should never happen with callback-based SSL + ASSERT(res != POLARSSL_ERR_NET_WANT_WRITE); // This should never happen with callback-based SSL + Printf(m_LastErrorText, "Data cannot be written to SSL context: -0x%x", -res); + return false; + } + else + { + Data += res; + NumBytes -= res; + if (NumBytes == 0) + { + return true; + } + } + } +} + + + + + + +int cBlockingSslClientSocket::Receive(void * a_Data, size_t a_MaxBytes) +{ + ASSERT(m_IsConnected); + + int res = m_Ssl.ReadPlain(a_Data, a_MaxBytes); + if (res < 0) + { + Printf(m_LastErrorText, "Data cannot be read form SSL context: -0x%x", -res); + } + return res; +} + + + + + +void cBlockingSslClientSocket::Disconnect(void) +{ + // Ignore if not connected + if (!m_IsConnected) + { + return; + } + + m_Ssl.NotifyClose(); + m_Socket.CloseSocket(); + m_IsConnected = false; +} + + + + + +int cBlockingSslClientSocket::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) +{ + int res = m_Socket.Receive((char *)a_Buffer, a_NumBytes, 0); + if (res < 0) + { + // PolarSSL's net routines distinguish between connection reset and general failure, we don't need to + return POLARSSL_ERR_NET_RECV_FAILED; + } + return res; +} + + + + + +int cBlockingSslClientSocket::SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) +{ + int res = m_Socket.Send((const char *)a_Buffer, a_NumBytes); + if (res < 0) + { + // PolarSSL's net routines distinguish between connection reset and general failure, we don't need to + return POLARSSL_ERR_NET_SEND_FAILED; + } + return res; +} + + + + diff --git a/src/PolarSSL++/BlockingSslClientSocket.h b/src/PolarSSL++/BlockingSslClientSocket.h new file mode 100644 index 000000000..7af897582 --- /dev/null +++ b/src/PolarSSL++/BlockingSslClientSocket.h @@ -0,0 +1,80 @@ + +// BlockingSslClientSocket.h + +// Declares the cBlockingSslClientSocket class representing a blocking TCP socket with client SSL encryption over it + + + + + +#pragma once + +#include "CallbackSslContext.h" +#include "../OSSupport/Socket.h" + + + + + +class cBlockingSslClientSocket : + protected cCallbackSslContext::cDataCallbacks +{ +public: + cBlockingSslClientSocket(void); + + /** Connects to the specified server and performs SSL handshake. + Returns true if successful, false on failure. Sets internal error text on failure. */ + bool Connect(const AString & a_ServerName, UInt16 a_Port); + + /** Sends the specified data over the connection. + Returns true if successful, false on failure. Sets the internal error text on failure. */ + bool Send(const void * a_Data, size_t a_NumBytes); + + /** Receives data from the connection. + Blocks until there is any data available, then returns as much as possible. + Returns the number of bytes actually received, negative number on failure. + Sets the internal error text on failure. */ + int Receive(void * a_Data, size_t a_MaxBytes); + + /** Disconnects the connection gracefully, if possible. + Note that this also frees the internal SSL context, so all the certificates etc. are lost. */ + void Disconnect(void); + + /** Sets the root certificates that are to be trusted. Forces the connection to use strict cert + verification. Needs to be used before calling Connect(). + a_ExpectedPeerName is the name that we expect to receive in the SSL peer's cert; verification will fail if + the presented name is different (possible MITM). + Returns true on success, false on failure. Sets internal error text on failure. */ + bool SetTrustedRootCertsFromString(const AString & a_CACerts, const AString & a_ExpectedPeerName); + + /** Returns the text of the last error that has occurred in this instance. */ + const AString & GetLastErrorText(void) const { return m_LastErrorText; } + +protected: + /** The SSL context used for the socket */ + cCallbackSslContext m_Ssl; + + /** The underlying socket to the SSL server */ + cSocket m_Socket; + + /** The trusted CA root cert store, if we are to verify the cert strictly. Set by SetTrustedRootCertsFromString(). */ + cX509CertPtr m_CACerts; + + /** The expected SSL peer's name, if we are to verify the cert strictly. Set by SetTrustedRootCertsFromString(). */ + AString m_ExpectedPeerName; + + /** Text of the last error that has occurred. */ + AString m_LastErrorText; + + /** Set to true if the connection established successfully. */ + bool m_IsConnected; + + + // cCallbackSslContext::cDataCallbacks overrides: + virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) override; + virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) override; +} ; + + + + diff --git a/src/PolarSSL++/BufferedSslContext.cpp b/src/PolarSSL++/BufferedSslContext.cpp new file mode 100644 index 000000000..885b30c68 --- /dev/null +++ b/src/PolarSSL++/BufferedSslContext.cpp @@ -0,0 +1,62 @@ + +// BufferedSslContext.cpp + +// Implements the cBufferedSslContext class representing a SSL context with the SSL peer data backed by a cByteBuffer + +#include "Globals.h" +#include "BufferedSslContext.h" + + + + + +cBufferedSslContext::cBufferedSslContext(size_t a_BufferSize): + m_OutgoingData(a_BufferSize), + m_IncomingData(a_BufferSize) +{ +} + + + + + +int cBufferedSslContext::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) +{ + // Called when PolarSSL wants to read encrypted data from the SSL peer + // Read the data from the buffer inside this object, where the owner has stored them using WriteIncoming(): + size_t NumBytes = std::min(a_NumBytes, m_IncomingData.GetReadableSpace()); + if (NumBytes == 0) + { + return POLARSSL_ERR_NET_WANT_READ; + } + if (!m_IncomingData.ReadBuf(a_Buffer, NumBytes)) + { + m_IncomingData.ResetRead(); + return POLARSSL_ERR_NET_RECV_FAILED; + } + m_IncomingData.CommitRead(); + return (int)NumBytes; +} + + + + + +int cBufferedSslContext::SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) +{ + // Called when PolarSSL wants to write encrypted data to the SSL peer + // Write the data into the buffer inside this object, where the owner can later read them using ReadOutgoing(): + if (!m_OutgoingData.CanWriteBytes(a_NumBytes)) + { + return POLARSSL_ERR_NET_WANT_WRITE; + } + if (!m_OutgoingData.Write((const char *)a_Buffer, a_NumBytes)) + { + return POLARSSL_ERR_NET_SEND_FAILED; + } + return (int)a_NumBytes; +} + + + + diff --git a/src/PolarSSL++/BufferedSslContext.h b/src/PolarSSL++/BufferedSslContext.h new file mode 100644 index 000000000..1b7e1af46 --- /dev/null +++ b/src/PolarSSL++/BufferedSslContext.h @@ -0,0 +1,52 @@ + +// BufferedSslContext.h + +// Declares the cBufferedSslContext class representing a SSL context with the SSL peer data backed by a cByteBuffer + + + + + +#pragma once + +#include "SslContext.h" + + + + + +class cBufferedSslContext : + public cSslContext +{ + typedef cSslContext super; + +public: + /** Creates a new context with the buffers of specified size for the encrypted / decrypted data. */ + cBufferedSslContext(size_t a_BufferSize = 64000); + + /** Stores the specified data in the "incoming" buffer, to be process by the SSL decryptor. + This is the data received from the SSL peer. + Returns the number of bytes actually stored. If 0 is returned, owner should check the error state. */ + size_t WriteIncoming(const void * a_Data, size_t a_NumBytes); + + /** Retrieves data from the "outgoing" buffer, after being processed by the SSL encryptor. + This is the data to be sent to the SSL peer. + Returns the number of bytes actually retrieved. */ + size_t ReadOutgoing(void * a_Data, size_t a_DataMaxSize); + +protected: + /** Buffer for the data that has been encrypted into the SSL stream and should be sent out. */ + cByteBuffer m_OutgoingData; + + /** Buffer for the data that has come in and needs to be decrypted from the SSL stream. */ + cByteBuffer m_IncomingData; + + + // cSslContext overrides: + virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) override; + virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) override; +} ; + + + + diff --git a/src/PolarSSL++/CMakeLists.txt b/src/PolarSSL++/CMakeLists.txt new file mode 100644 index 000000000..b0a592760 --- /dev/null +++ b/src/PolarSSL++/CMakeLists.txt @@ -0,0 +1,41 @@ + +cmake_minimum_required (VERSION 2.6) +project (MCServer) + +include_directories ("${PROJECT_SOURCE_DIR}/../") + +set(SOURCES + AesCfb128Decryptor.cpp + AesCfb128Encryptor.cpp + BlockingSslClientSocket.cpp + BufferedSslContext.cpp + CallbackSslContext.cpp + CtrDrbgContext.cpp + EntropyContext.cpp + PublicKey.cpp + RsaPrivateKey.cpp + Sha1Checksum.cpp + SslContext.cpp + X509Cert.cpp +) + +set(HEADERS + AesCfb128Decryptor.h + AesCfb128Encryptor.h + BlockingSslClientSocket.h + BufferedSslContext.h + CallbackSslContext.h + CtrDrbgContext.h + EntropyContext.h + PublicKey.h + RsaPrivateKey.h + SslContext.h + Sha1Checksum.h + X509Cert.h +) + +add_library(PolarSSL++ ${SOURCES} ${HEADERS}) + +if (UNIX) + target_link_libraries(PolarSSL++ polarssl) +endif() diff --git a/src/PolarSSL++/CallbackSslContext.cpp b/src/PolarSSL++/CallbackSslContext.cpp new file mode 100644 index 000000000..0cc88a14a --- /dev/null +++ b/src/PolarSSL++/CallbackSslContext.cpp @@ -0,0 +1,59 @@ + +// CallbackSslContext.cpp + +// Declares the cCallbackSslContext class representing a SSL context wrapper that uses callbacks to read and write SSL peer data + +#include "Globals.h" +#include "CallbackSslContext.h" + + + + + + +cCallbackSslContext::cCallbackSslContext(void) +{ + // Nothing needed, but the constructor needs to exist so +} + + + + + +cCallbackSslContext::cCallbackSslContext(cCallbackSslContext::cDataCallbacks & a_Callbacks) : + m_Callbacks(&a_Callbacks) +{ +} + + + + + +int cCallbackSslContext::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) +{ + if (m_Callbacks == NULL) + { + LOGWARNING("SSL: Trying to receive data with no callbacks, aborting."); + return POLARSSL_ERR_NET_RECV_FAILED; + } + return m_Callbacks->ReceiveEncrypted(a_Buffer, a_NumBytes); +} + + + + + +int cCallbackSslContext::SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) +{ + if (m_Callbacks == NULL) + { + LOGWARNING("SSL: Trying to send data with no callbacks, aborting."); + return POLARSSL_ERR_NET_SEND_FAILED; + } + return m_Callbacks->SendEncrypted(a_Buffer, a_NumBytes); +} + + + + + diff --git a/src/PolarSSL++/CallbackSslContext.h b/src/PolarSSL++/CallbackSslContext.h new file mode 100644 index 000000000..3e6edc5f4 --- /dev/null +++ b/src/PolarSSL++/CallbackSslContext.h @@ -0,0 +1,64 @@ + +// CallbackSslContext.h + +// Declares the cCallbackSslContext class representing a SSL context wrapper that uses callbacks to read and write SSL peer data + + + + + +#pragma once + +#include "SslContext.h" + + + + + +class cCallbackSslContext : + public cSslContext +{ +public: + /** Interface used as a data sink for the SSL peer data. */ + class cDataCallbacks + { + public: + // Force a virtual destructor in descendants: + virtual ~cDataCallbacks() {} + + /** Called when PolarSSL wants to read encrypted data from the SSL peer. + The returned value is the number of bytes received, or a PolarSSL error on failure. + The implementation can return POLARSSL_ERR_NET_WANT_READ or POLARSSL_ERR_NET_WANT_WRITE to indicate + that there's currently no more data and that there might be more data in the future. In such cases the + SSL operation that invoked this call will terminate with the same return value, so that the owner is + notified of this condition and can potentially restart the operation later on. */ + virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) = 0; + + /** Called when PolarSSL wants to write encrypted data to the SSL peer. + The returned value is the number of bytes sent, or a PolarSSL error on failure. + The implementation can return POLARSSL_ERR_NET_WANT_READ or POLARSSL_ERR_NET_WANT_WRITE to indicate + that there's currently no more data and that there might be more data in the future. In such cases the + SSL operation that invoked this call will terminate with the same return value, so that the owner is + notified of this condition and can potentially restart the operation later on. */ + virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) = 0; + } ; + + + /** Creates a new SSL context with no callbacks assigned */ + cCallbackSslContext(void); + + /** Creates a new SSL context with the specified callbacks */ + cCallbackSslContext(cDataCallbacks & a_Callbacks); + +protected: + /** The callbacks to use to send and receive SSL peer data */ + cDataCallbacks * m_Callbacks; + + // cSslContext overrides: + virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) override; + virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) override; +}; + + + + diff --git a/src/PolarSSL++/CtrDrbgContext.cpp b/src/PolarSSL++/CtrDrbgContext.cpp new file mode 100644 index 000000000..86e6d1ca5 --- /dev/null +++ b/src/PolarSSL++/CtrDrbgContext.cpp @@ -0,0 +1,49 @@ + +// CtrDrbgContext.cpp + +// Implements the cCtrDrbgContext class representing a wrapper over CTR-DRBG implementation in PolarSSL + +#include "Globals.h" +#include "CtrDrbgContext.h" +#include "EntropyContext.h" + + + + + +cCtrDrbgContext::cCtrDrbgContext(void) : + m_EntropyContext(new cEntropyContext), + m_IsValid(false) +{ +} + + + + + +cCtrDrbgContext::cCtrDrbgContext(const SharedPtr<cEntropyContext> & a_EntropyContext) : + m_EntropyContext(a_EntropyContext), + m_IsValid(false) +{ +} + + + + + +int cCtrDrbgContext::Initialize(const void * a_Custom, size_t a_CustomSize) +{ + if (m_IsValid) + { + // Already initialized + return 0; + } + + int res = ctr_drbg_init(&m_CtrDrbg, entropy_func, &(m_EntropyContext->m_Entropy), (const unsigned char *)a_Custom, a_CustomSize); + m_IsValid = (res == 0); + return res; +} + + + + diff --git a/src/PolarSSL++/CtrDrbgContext.h b/src/PolarSSL++/CtrDrbgContext.h new file mode 100644 index 000000000..65e9a2374 --- /dev/null +++ b/src/PolarSSL++/CtrDrbgContext.h @@ -0,0 +1,63 @@ + +// CtrDrbgContext.h + +// Declares the cCtrDrbgContext class representing a wrapper over CTR-DRBG implementation in PolarSSL + + + + + +#pragma once + +#include "polarssl/ctr_drbg.h" + + + + + +// fwd: EntropyContext.h +class cEntropyContext; + + + + + +class cCtrDrbgContext +{ + friend class cSslContext; + friend class cRsaPrivateKey; + friend class cPublicKey; + +public: + /** Constructs the context with a new entropy context. */ + cCtrDrbgContext(void); + + /** Constructs the context with the specified entropy context. */ + cCtrDrbgContext(const SharedPtr<cEntropyContext> & a_EntropyContext); + + /** Initializes the context. + a_Custom is optional additional data to use for entropy, nullptr is accepted. + Returns 0 if successful, PolarSSL error code on failure. */ + int Initialize(const void * a_Custom, size_t a_CustomSize); + + /** Returns true if the object is valid (has been initialized properly) */ + bool IsValid(void) const { return m_IsValid; } + +protected: + /** The entropy source used for generating the random */ + SharedPtr<cEntropyContext> m_EntropyContext; + + /** The random generator context */ + ctr_drbg_context m_CtrDrbg; + + /** Set to true if the object is valid (has been initialized properly) */ + bool m_IsValid; + + + /** Returns the internal context ptr. Only use in PolarSSL API calls. */ + ctr_drbg_context * GetInternal(void) { return &m_CtrDrbg; } +} ; + + + + diff --git a/src/PolarSSL++/EntropyContext.cpp b/src/PolarSSL++/EntropyContext.cpp new file mode 100644 index 000000000..9c59b3f11 --- /dev/null +++ b/src/PolarSSL++/EntropyContext.cpp @@ -0,0 +1,29 @@ + +// EntropyContext.cpp + +// Implements the cEntropyContext class representing a wrapper over entropy contexts in PolarSSL + +#include "Globals.h" +#include "EntropyContext.h" + + + + + +cEntropyContext::cEntropyContext(void) +{ + entropy_init(&m_Entropy); +} + + + + + +cEntropyContext::~cEntropyContext() +{ + entropy_free(&m_Entropy); +} + + + + diff --git a/src/PolarSSL++/EntropyContext.h b/src/PolarSSL++/EntropyContext.h new file mode 100644 index 000000000..bc7fff066 --- /dev/null +++ b/src/PolarSSL++/EntropyContext.h @@ -0,0 +1,31 @@ + +// EntropyContext.h + +// Declares the cEntropyContext class representing a wrapper over entropy contexts in PolarSSL + + + + + +#pragma once + +#include "polarssl/entropy.h" + + + + + +class cEntropyContext +{ + friend class cCtrDrbgContext; +public: + cEntropyContext(void); + ~cEntropyContext(); + +protected: + entropy_context m_Entropy; +} ; + + + + diff --git a/src/PolarSSL++/PublicKey.cpp b/src/PolarSSL++/PublicKey.cpp new file mode 100644 index 000000000..49794a0c8 --- /dev/null +++ b/src/PolarSSL++/PublicKey.cpp @@ -0,0 +1,73 @@ + +// PublicKey.cpp + +// Implements the cPublicKey class representing a RSA public key in PolarSSL + +#include "Globals.h" +#include "PublicKey.h" + + + + + +cPublicKey::cPublicKey(const AString & a_PublicKeyDER) +{ + pk_init(&m_Pk); + if (pk_parse_public_key(&m_Pk, (const Byte *)a_PublicKeyDER.data(), a_PublicKeyDER.size()) != 0) + { + ASSERT(!"Cannot parse PubKey"); + return; + } + m_CtrDrbg.Initialize("rsa_pubkey", 10); +} + + + + + +cPublicKey::~cPublicKey() +{ + pk_free(&m_Pk); +} + + + + + +int cPublicKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) +{ + size_t DecryptedLen = a_DecryptedMaxLength; + int res = pk_decrypt(&m_Pk, + a_EncryptedData, a_EncryptedLength, + a_DecryptedData, &DecryptedLen, a_DecryptedMaxLength, + ctr_drbg_random, m_CtrDrbg.GetInternal() + ); + if (res != 0) + { + return res; + } + return (int)DecryptedLen; +} + + + + + +int cPublicKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) +{ + size_t EncryptedLength = a_EncryptedMaxLength; + int res = pk_encrypt(&m_Pk, + a_PlainData, a_PlainLength, a_EncryptedData, &EncryptedLength, a_EncryptedMaxLength, + ctr_drbg_random, m_CtrDrbg.GetInternal() + ); + if (res != 0) + { + return res; + } + return (int)EncryptedLength; +} + + + + + diff --git a/src/PolarSSL++/PublicKey.h b/src/PolarSSL++/PublicKey.h new file mode 100644 index 000000000..5a0a57147 --- /dev/null +++ b/src/PolarSSL++/PublicKey.h @@ -0,0 +1,48 @@ + +// PublicKey.h + +// Declares the cPublicKey class representing a RSA public key in PolarSSL + + + + + +#pragma once + +#include "CtrDrbgContext.h" +#include "polarssl/pk.h" + + + + + +class cPublicKey +{ +public: + /** Constructs the public key out of the DER-encoded pubkey data */ + cPublicKey(const AString & a_PublicKeyDER); + + ~cPublicKey(); + + /** Decrypts the data using the stored public key + Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); + + /** Encrypts the data using the stored public key + Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); + +protected: + /** The public key PolarSSL representation */ + pk_context m_Pk; + + /** The random generator used in encryption and decryption */ + cCtrDrbgContext m_CtrDrbg; +} ; + + + + + diff --git a/src/PolarSSL++/RsaPrivateKey.cpp b/src/PolarSSL++/RsaPrivateKey.cpp new file mode 100644 index 000000000..2d5a2a4b1 --- /dev/null +++ b/src/PolarSSL++/RsaPrivateKey.cpp @@ -0,0 +1,176 @@ + +// RsaPrivateKey.cpp + +#include "Globals.h" +#include "RsaPrivateKey.h" +#include "CtrDrbgContext.h" +#include "polarssl/pk.h" + + + + + + +cRsaPrivateKey::cRsaPrivateKey(void) +{ + rsa_init(&m_Rsa, RSA_PKCS_V15, 0); + m_CtrDrbg.Initialize("RSA", 3); +} + + + + + +cRsaPrivateKey::cRsaPrivateKey(const cRsaPrivateKey & a_Other) +{ + rsa_init(&m_Rsa, RSA_PKCS_V15, 0); + rsa_copy(&m_Rsa, &a_Other.m_Rsa); + m_CtrDrbg.Initialize("RSA", 3); +} + + + + + +cRsaPrivateKey::~cRsaPrivateKey() +{ + rsa_free(&m_Rsa); +} + + + + + +bool cRsaPrivateKey::Generate(unsigned a_KeySizeBits) +{ + int res = rsa_gen_key(&m_Rsa, ctr_drbg_random, m_CtrDrbg.GetInternal(), a_KeySizeBits, 65537); + if (res != 0) + { + LOG("RSA key generation failed: -0x%x", -res); + return false; + } + + return true; +} + + + + + +AString cRsaPrivateKey::GetPubKeyDER(void) +{ + class cPubKey + { + public: + cPubKey(rsa_context * a_Rsa) : + m_IsValid(false) + { + pk_init(&m_Key); + if (pk_init_ctx(&m_Key, pk_info_from_type(POLARSSL_PK_RSA)) != 0) + { + ASSERT(!"Cannot init PrivKey context"); + return; + } + if (rsa_copy(pk_rsa(m_Key), a_Rsa) != 0) + { + ASSERT(!"Cannot copy PrivKey to PK context"); + return; + } + m_IsValid = true; + } + + ~cPubKey() + { + if (m_IsValid) + { + pk_free(&m_Key); + } + } + + operator pk_context * (void) { return &m_Key; } + + protected: + bool m_IsValid; + pk_context m_Key; + } PkCtx(&m_Rsa); + + unsigned char buf[3000]; + int res = pk_write_pubkey_der(PkCtx, buf, sizeof(buf)); + if (res < 0) + { + return AString(); + } + return AString((const char *)(buf + sizeof(buf) - res), (size_t)res); +} + + + + + +int cRsaPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) +{ + if (a_EncryptedLength < m_Rsa.len) + { + LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + if (a_DecryptedMaxLength < m_Rsa.len) + { + LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + size_t DecryptedLength; + int res = rsa_pkcs1_decrypt( + &m_Rsa, ctr_drbg_random, m_CtrDrbg.GetInternal(), RSA_PRIVATE, &DecryptedLength, + a_EncryptedData, a_DecryptedData, a_DecryptedMaxLength + ); + if (res != 0) + { + return -1; + } + return (int)DecryptedLength; +} + + + + + +int cRsaPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) +{ + if (a_EncryptedMaxLength < m_Rsa.len) + { + LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + if (a_PlainLength < m_Rsa.len) + { + LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_PlainLength!"); + return -1; + } + int res = rsa_pkcs1_encrypt( + &m_Rsa, ctr_drbg_random, m_CtrDrbg.GetInternal(), RSA_PRIVATE, + a_PlainLength, a_PlainData, a_EncryptedData + ); + if (res != 0) + { + return -1; + } + return (int)m_Rsa.len; +} + + + + + diff --git a/src/PolarSSL++/RsaPrivateKey.h b/src/PolarSSL++/RsaPrivateKey.h new file mode 100644 index 000000000..ffacde11b --- /dev/null +++ b/src/PolarSSL++/RsaPrivateKey.h @@ -0,0 +1,59 @@ + +// RsaPrivateKey.h + +// Declares the cRsaPrivateKey class representing a private key for RSA operations. + + + + + +#pragma once + +#include "CtrDrbgContext.h" +#include "polarssl/rsa.h" + + + + + +/** Encapsulates an RSA private key used in PKI cryptography */ +class cRsaPrivateKey +{ +public: + /** Creates a new empty object, the key is not assigned */ + cRsaPrivateKey(void); + + /** Deep-copies the key from a_Other */ + cRsaPrivateKey(const cRsaPrivateKey & a_Other); + + ~cRsaPrivateKey(); + + /** Generates a new key within this object, with the specified size in bits. + Returns true on success, false on failure. */ + bool Generate(unsigned a_KeySizeBits = 1024); + + /** Returns the public key part encoded in ASN1 DER encoding */ + AString GetPubKeyDER(void); + + /** Decrypts the data using RSAES-PKCS#1 algorithm. + Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength); + + /** Encrypts the data using RSAES-PKCS#1 algorithm. + Both a_EncryptedData and a_DecryptedData must be at least <KeySizeBytes> bytes large. + Returns the number of bytes decrypted, or negative number for error. */ + int Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength); + +protected: + /** The PolarSSL key context */ + rsa_context m_Rsa; + + /** The random generator used for generating the key and encryption / decryption */ + cCtrDrbgContext m_CtrDrbg; +} ; + + + + + diff --git a/src/PolarSSL++/Sha1Checksum.cpp b/src/PolarSSL++/Sha1Checksum.cpp new file mode 100644 index 000000000..a1ee9d7b9 --- /dev/null +++ b/src/PolarSSL++/Sha1Checksum.cpp @@ -0,0 +1,138 @@ + +// Sha1Checksum.cpp + +// Declares the cSha1Checksum class representing the SHA-1 checksum calculator + +#include "Globals.h" +#include "Sha1Checksum.h" + + + + + +/* +// Self-test the hash formatting for known values: +// sha1(Notch) : 4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48 +// sha1(jeb_) : -7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1 +// sha1(simon) : 88e16a1019277b15d58faf0541e11910eb756f6 + +static class Test +{ +public: + Test(void) + { + AString DigestNotch, DigestJeb, DigestSimon; + Byte Digest[20]; + cSha1Checksum Checksum; + Checksum.Update((const Byte *)"Notch", 5); + Checksum.Finalize(Digest); + cSha1Checksum::DigestToJava(Digest, DigestNotch); + Checksum.Restart(); + Checksum.Update((const Byte *)"jeb_", 4); + Checksum.Finalize(Digest); + cSha1Checksum::DigestToJava(Digest, DigestJeb); + Checksum.Restart(); + Checksum.Update((const Byte *)"simon", 5); + Checksum.Finalize(Digest); + cSha1Checksum::DigestToJava(Digest, DigestSimon); + printf("Notch: \"%s\"\n", DigestNotch.c_str()); + printf("jeb_: \"%s\"\n", DigestJeb.c_str()); + printf("simon: \"%s\"\n", DigestSimon.c_str()); + assert(DigestNotch == "4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48"); + assert(DigestJeb == "-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1"); + assert(DigestSimon == "88e16a1019277b15d58faf0541e11910eb756f6"); + } +} test; +*/ + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSha1Checksum: + +cSha1Checksum::cSha1Checksum(void) : + m_DoesAcceptInput(true) +{ + sha1_starts(&m_Sha1); +} + + + + + +void cSha1Checksum::Update(const Byte * a_Data, size_t a_Length) +{ + ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed + + sha1_update(&m_Sha1, a_Data, a_Length); +} + + + + + +void cSha1Checksum::Finalize(cSha1Checksum::Checksum & a_Output) +{ + ASSERT(m_DoesAcceptInput); // Not Finalize()-d yet, or Restart()-ed + + sha1_finish(&m_Sha1, a_Output); + m_DoesAcceptInput = false; +} + + + + + +void cSha1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out) +{ + Checksum Digest; + memcpy(Digest, a_Digest, sizeof(Digest)); + + bool IsNegative = (Digest[0] >= 0x80); + if (IsNegative) + { + // Two's complement: + bool carry = true; // Add one to the whole number + for (int i = 19; i >= 0; i--) + { + Digest[i] = ~Digest[i]; + if (carry) + { + carry = (Digest[i] == 0xff); + Digest[i]++; + } + } + } + a_Out.clear(); + a_Out.reserve(40); + for (int i = 0; i < 20; i++) + { + AppendPrintf(a_Out, "%02x", Digest[i]); + } + while ((a_Out.length() > 0) && (a_Out[0] == '0')) + { + a_Out.erase(0, 1); + } + if (IsNegative) + { + a_Out.insert(0, "-"); + } +} + + + + + + +void cSha1Checksum::Restart(void) +{ + sha1_starts(&m_Sha1); + m_DoesAcceptInput = true; +} + + + + diff --git a/src/PolarSSL++/Sha1Checksum.h b/src/PolarSSL++/Sha1Checksum.h new file mode 100644 index 000000000..68fdbcf1b --- /dev/null +++ b/src/PolarSSL++/Sha1Checksum.h @@ -0,0 +1,52 @@ + +// Sha1Checksum.h + +// Declares the cSha1Checksum class representing the SHA-1 checksum calculator + + + + + +#pragma once + +#include "polarssl/sha1.h" + + + + + +/** Calculates a SHA1 checksum for data stream */ +class cSha1Checksum +{ +public: + typedef Byte Checksum[20]; // The type used for storing the checksum + + cSha1Checksum(void); + + /** Adds the specified data to the checksum */ + void Update(const Byte * a_Data, size_t a_Length); + + /** Calculates and returns the final checksum */ + void Finalize(Checksum & a_Output); + + /** Returns true if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool DoesAcceptInput(void) const { return m_DoesAcceptInput; } + + /** Converts a raw 160-bit SHA1 digest into a Java Hex representation + According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802 + */ + static void DigestToJava(const Checksum & a_Digest, AString & a_JavaOut); + + /** Clears the current context and start a new checksum calculation */ + void Restart(void); + +protected: + /** True if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool m_DoesAcceptInput; + + sha1_context m_Sha1; +} ; + + + + diff --git a/src/PolarSSL++/SslContext.cpp b/src/PolarSSL++/SslContext.cpp new file mode 100644 index 000000000..1994cf844 --- /dev/null +++ b/src/PolarSSL++/SslContext.cpp @@ -0,0 +1,243 @@ + +// SslContext.cpp + +// Implements the cSslContext class that holds everything a single SSL context needs to function + +#include "Globals.h" +#include "SslContext.h" +#include "EntropyContext.h" +#include "CtrDrbgContext.h" + + + + + +cSslContext::cSslContext(void) : + m_IsValid(false), + m_HasHandshaken(false) +{ +} + + + + + +cSslContext::~cSslContext() +{ + if (m_IsValid) + { + ssl_free(&m_Ssl); + } +} + + + + + +int cSslContext::Initialize(bool a_IsClient, const SharedPtr<cCtrDrbgContext> & a_CtrDrbg) +{ + // Check double-initialization: + if (m_IsValid) + { + LOGWARNING("SSL: Double initialization is not supported."); + return POLARSSL_ERR_SSL_MALLOC_FAILED; // There is no return value well-suited for this, reuse this one. + } + + // Set the CtrDrbg context, create a new one if needed: + m_CtrDrbg = a_CtrDrbg; + if (m_CtrDrbg.get() == NULL) + { + m_CtrDrbg.reset(new cCtrDrbgContext); + m_CtrDrbg->Initialize("MCServer", 8); + } + + // Initialize PolarSSL's structures: + memset(&m_Ssl, 0, sizeof(m_Ssl)); + int res = ssl_init(&m_Ssl); + if (res != 0) + { + return res; + } + ssl_set_endpoint(&m_Ssl, a_IsClient ? SSL_IS_CLIENT : SSL_IS_SERVER); + ssl_set_authmode(&m_Ssl, SSL_VERIFY_OPTIONAL); + ssl_set_rng(&m_Ssl, ctr_drbg_random, &m_CtrDrbg->m_CtrDrbg); + ssl_set_bio(&m_Ssl, ReceiveEncrypted, this, SendEncrypted, this); + + #ifdef _DEBUG + /* + // These functions allow us to debug SSL and certificate problems, but produce way too much output, + // so they're disabled until someone needs them + ssl_set_dbg(&m_Ssl, &SSLDebugMessage, this); + ssl_set_verify(&m_Ssl, &SSLVerifyCert, this); + */ + #endif + + m_IsValid = true; + return 0; +} + + + + + +void cSslContext::SetCACerts(const cX509CertPtr & a_CACert, const AString & a_ExpectedPeerName) +{ + // Store the data in our internal buffers, to avoid losing the pointers later on + // PolarSSL will need these after this call returns, and the caller may move / delete the data before that: + m_ExpectedPeerName = a_ExpectedPeerName; + m_CACerts = a_CACert; + + // Set the trusted CA root cert store: + ssl_set_authmode(&m_Ssl, SSL_VERIFY_REQUIRED); + ssl_set_ca_chain(&m_Ssl, m_CACerts->GetInternal(), NULL, m_ExpectedPeerName.empty() ? NULL : m_ExpectedPeerName.c_str()); +} + + + + + +int cSslContext::WritePlain(const void * a_Data, size_t a_NumBytes) +{ + ASSERT(m_IsValid); // Need to call Initialize() first + if (!m_HasHandshaken) + { + int res = Handshake(); + if (res != 0) + { + return res; + } + } + + return ssl_write(&m_Ssl, (const unsigned char *)a_Data, a_NumBytes); +} + + + + + +int cSslContext::ReadPlain(void * a_Data, size_t a_MaxBytes) +{ + ASSERT(m_IsValid); // Need to call Initialize() first + if (!m_HasHandshaken) + { + int res = Handshake(); + if (res != 0) + { + return res; + } + } + + return ssl_read(&m_Ssl, (unsigned char *)a_Data, a_MaxBytes); +} + + + + + +int cSslContext::Handshake(void) +{ + ASSERT(m_IsValid); // Need to call Initialize() first + ASSERT(!m_HasHandshaken); // Must not call twice + + int res = ssl_handshake(&m_Ssl); + if (res == 0) + { + m_HasHandshaken = true; + } + return res; +} + + + + + +int cSslContext::NotifyClose(void) +{ + return ssl_close_notify(&m_Ssl); +} + + + + + +#ifdef _DEBUG + void cSslContext::SSLDebugMessage(void * a_UserParam, int a_Level, const char * a_Text) + { + if (a_Level > 3) + { + // Don't want the trace messages + return; + } + + // Remove the terminating LF: + size_t len = strlen(a_Text) - 1; + while ((len > 0) && (a_Text[len] <= 32)) + { + len--; + } + AString Text(a_Text, len + 1); + + LOGD("SSL (%d): %s", a_Level, Text.c_str()); + } + + + + + + int cSslContext::SSLVerifyCert(void * a_This, x509_crt * a_Crt, int a_Depth, int * a_Flags) + { + char buf[1024]; + UNUSED(a_This); + + LOG("Verify requested for (Depth %d):", a_Depth); + x509_crt_info(buf, sizeof(buf) - 1, "", a_Crt); + LOG("%s", buf); + + int Flags = *a_Flags; + if ((Flags & BADCERT_EXPIRED) != 0) + { + LOG(" ! server certificate has expired"); + } + + if ((Flags & BADCERT_REVOKED) != 0) + { + LOG(" ! server certificate has been revoked"); + } + + if ((Flags & BADCERT_CN_MISMATCH) != 0) + { + LOG(" ! CN mismatch"); + } + + if ((Flags & BADCERT_NOT_TRUSTED) != 0) + { + LOG(" ! self-signed or not signed by a trusted CA"); + } + + if ((Flags & BADCRL_NOT_TRUSTED) != 0) + { + LOG(" ! CRL not trusted"); + } + + if ((Flags & BADCRL_EXPIRED) != 0) + { + LOG(" ! CRL expired"); + } + + if ((Flags & BADCERT_OTHER) != 0) + { + LOG(" ! other (unknown) flag"); + } + + if (Flags == 0) + { + LOG(" This certificate has no flags"); + } + + return 0; + } +#endif // _DEBUG + + + + diff --git a/src/PolarSSL++/SslContext.h b/src/PolarSSL++/SslContext.h new file mode 100644 index 000000000..85add5f8b --- /dev/null +++ b/src/PolarSSL++/SslContext.h @@ -0,0 +1,137 @@ + +// SslContext.h + +// Declares the cSslContext class that holds everything a single SSL context needs to function + + + + + +#pragma once + +#include "polarssl/ssl.h" +#include "../ByteBuffer.h" +#include "X509Cert.h" + + + + + +// fwd: +class cCtrDrbgContext; + + + + + +/** +Acts as a generic SSL encryptor / decryptor between the two endpoints. The "owner" of this class is expected +to create it, initialize it and then provide the means of reading and writing data through the SSL link. +This is an abstract base class, there are descendants that handle the specific aspects of how the SSL peer +data comes into the system: + - cBufferedSslContext uses a cByteBuffer to read and write the data + - cCallbackSslContext uses callbacks to provide the data +*/ +class cSslContext abstract +{ +public: + /** Creates a new uninitialized context */ + cSslContext(void); + + ~cSslContext(); + + /** Initializes the context for use as a server or client. + Returns 0 on success, PolarSSL error on failure. */ + int Initialize(bool a_IsClient, const SharedPtr<cCtrDrbgContext> & a_CtrDrbg = SharedPtr<cCtrDrbgContext>()); + + /** Returns true if the object has been initialized properly. */ + bool IsValid(void) const { return m_IsValid; } + + /** Sets a cert chain as the trusted cert store for this context. + Calling this will switch the context into strict cert verification mode. + a_ExpectedPeerName is the CommonName that we expect the SSL peer to have in its cert, + if it is different, the verification will fail. An empty string will disable the CN check. */ + void SetCACerts(const cX509CertPtr & a_CACert, const AString & a_ExpectedPeerName); + + /** Writes data to be encrypted and sent to the SSL peer. Will perform SSL handshake, if needed. + Returns the number of bytes actually written, or PolarSSL error code. + If the return value is POLARSSL_ERR_NET_WANT_READ or POLARSSL_ERR_NET_WANT_WRITE, the owner should send any + cached outgoing data to the SSL peer and write any incoming data received from the SSL peer and then call + this function again with the same parameters. Note that this may repeat a few times before the data is + actually written, mainly due to initial handshake. */ + int WritePlain(const void * a_Data, size_t a_NumBytes); + + /** Reads data decrypted from the SSL stream. Will perform SSL handshake, if needed. + Returns the number of bytes actually read, or PolarSSL error code. + If the return value is POLARSSL_ERR_NET_WANT_READ or POLARSSL_ERR_NET_WANT_WRITE, the owner should send any + cached outgoing data to the SSL peer and write any incoming data received from the SSL peer and then call + this function again with the same parameters. Note that this may repeat a few times before the data is + actually read, mainly due to initial handshake. */ + int ReadPlain(void * a_Data, size_t a_MaxBytes); + + /** Performs the SSL handshake. + Returns zero on success, PoladSSL error code on failure. + If the return value is POLARSSL_ERR_NET_WANT_READ or POLARSSL_ERR_NET_WANT_WRITE, the owner should send any + cached outgoing data to the SSL peer and write any incoming data received from the SSL peer and then call + this function again. Note that this may repeat a few times before the handshake is completed. */ + int Handshake(void); + + /** Returns true if the SSL handshake has been completed. */ + bool HasHandshaken(void) const { return m_HasHandshaken; } + + /** Notifies the SSL peer that the connection is being closed. + Returns 0 on success, PolarSSL error code on failure. */ + int NotifyClose(void); + +protected: + /** True if the object has been initialized properly. */ + bool m_IsValid; + + /** The random generator to use */ + SharedPtr<cCtrDrbgContext> m_CtrDrbg; + + /** The SSL context that PolarSSL uses. */ + ssl_context m_Ssl; + + /** True if the SSL handshake has been completed. */ + bool m_HasHandshaken; + + /** A copy of the trusted CA root cert store that is passed to us in SetCACerts(), so that the pointer + stays valid even after the call, when PolarSSL finally uses it. */ + cX509CertPtr m_CACerts; + + /** Buffer for the expected peer name. We need to buffer it because the caller may free the string they + give us before PolarSSL consumes the raw pointer it gets to the CN. */ + AString m_ExpectedPeerName; + + + /** The callback used by PolarSSL when it wants to read encrypted data. */ + static int ReceiveEncrypted(void * a_This, unsigned char * a_Buffer, size_t a_NumBytes) + { + return ((cSslContext *)a_This)->ReceiveEncrypted(a_Buffer, a_NumBytes); + } + + /** The callback used by PolarSSL when it wants to write encrypted data. */ + static int SendEncrypted(void * a_This, const unsigned char * a_Buffer, size_t a_NumBytes) + { + return ((cSslContext *)a_This)->SendEncrypted(a_Buffer, a_NumBytes); + } + + #ifdef _DEBUG + /** The callback used by PolarSSL to output debug messages */ + static void SSLDebugMessage(void * a_UserParam, int a_Level, const char * a_Text); + + /** The callback used by PolarSSL to log information on the cert chain */ + static int SSLVerifyCert(void * a_This, x509_crt * a_Crt, int a_Depth, int * a_Flags); + #endif // _DEBUG + + /** Called when PolarSSL wants to read encrypted data. */ + virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) = 0; + + /** Called when PolarSSL wants to write encrypted data. */ + virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) = 0; +} ; + + + + diff --git a/src/PolarSSL++/X509Cert.cpp b/src/PolarSSL++/X509Cert.cpp new file mode 100644 index 000000000..ecf664855 --- /dev/null +++ b/src/PolarSSL++/X509Cert.cpp @@ -0,0 +1,38 @@ + +// X509Cert.cpp + +// Implements the cX509Cert class representing a wrapper over X509 certs in PolarSSL + +#include "Globals.h" +#include "X509Cert.h" + + + + + +cX509Cert::cX509Cert(void) +{ + x509_crt_init(&m_Cert); +} + + + + + +cX509Cert::~cX509Cert() +{ + x509_crt_free(&m_Cert); +} + + + + + +int cX509Cert::Parse(const void * a_CertContents, size_t a_Size) +{ + return x509_crt_parse(&m_Cert, (const unsigned char *)a_CertContents, a_Size); +} + + + + diff --git a/src/PolarSSL++/X509Cert.h b/src/PolarSSL++/X509Cert.h new file mode 100644 index 000000000..991617d24 --- /dev/null +++ b/src/PolarSSL++/X509Cert.h @@ -0,0 +1,41 @@ + +// X509Cert.h + +// Declares the cX509Cert class representing a wrapper over X509 certs in PolarSSL + + + + + +#pragma once + +#include "polarssl/x509_crt.h" + + + + + +class cX509Cert +{ + friend class cSslContext; + +public: + cX509Cert(void); + ~cX509Cert(void); + + /** Parses the certificate chain data into the context. + Returns 0 on succes, or PolarSSL error code on failure. */ + int Parse(const void * a_CertContents, size_t a_Size); + +protected: + x509_crt m_Cert; + + /** Returns the internal cert ptr. Only use in PolarSSL API calls. */ + x509_crt * GetInternal(void) { return &m_Cert; } +} ; + +typedef SharedPtr<cX509Cert> cX509CertPtr; + + + + diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp new file mode 100644 index 000000000..2050393c2 --- /dev/null +++ b/src/Protocol/Authenticator.cpp @@ -0,0 +1,309 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Authenticator.h" +#include "../Root.h" +#include "../Server.h" +#include "../ClientHandle.h" + +#include "inifile/iniFile.h" +#include "json/json.h" + +#include "PolarSSL++/BlockingSslClientSocket.h" + +#include <sstream> +#include <iomanip> + + + + + +#define DEFAULT_AUTH_SERVER "sessionserver.mojang.com" +#define DEFAULT_AUTH_ADDRESS "/session/minecraft/hasJoined?username=%USERNAME%&serverId=%SERVERID%" + + + + + +cAuthenticator::cAuthenticator(void) : + super("cAuthenticator"), + m_Server(DEFAULT_AUTH_SERVER), + m_Address(DEFAULT_AUTH_ADDRESS), + m_ShouldAuthenticate(true) +{ +} + + + + + +cAuthenticator::~cAuthenticator() +{ + Stop(); +} + + + + + +void cAuthenticator::ReadINI(cIniFile & IniFile) +{ + m_Server = IniFile.GetValueSet("Authentication", "Server", DEFAULT_AUTH_SERVER); + m_Address = IniFile.GetValueSet("Authentication", "Address", DEFAULT_AUTH_ADDRESS); + m_ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true); +} + + + + + +void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash) +{ + if (!m_ShouldAuthenticate) + { + cRoot::Get()->AuthenticateUser(a_ClientID, a_UserName, cClientHandle::GenerateOfflineUUID(a_UserName)); + return; + } + + cCSLock LOCK(m_CS); + m_Queue.push_back(cUser(a_ClientID, a_UserName, a_ServerHash)); + m_QueueNonempty.Set(); +} + + + + + +void cAuthenticator::Start(cIniFile & IniFile) +{ + ReadINI(IniFile); + m_ShouldTerminate = false; + super::Start(); +} + + + + + +void cAuthenticator::Stop(void) +{ + m_ShouldTerminate = true; + m_QueueNonempty.Set(); + Wait(); +} + + + + + +void cAuthenticator::Execute(void) +{ + for (;;) + { + cCSLock Lock(m_CS); + while (!m_ShouldTerminate && (m_Queue.size() == 0)) + { + cCSUnlock Unlock(Lock); + m_QueueNonempty.Wait(); + } + if (m_ShouldTerminate) + { + return; + } + ASSERT(!m_Queue.empty()); + + cAuthenticator::cUser & User = m_Queue.front(); + int ClientID = User.m_ClientID; + AString UserName = User.m_Name; + AString ServerID = User.m_ServerID; + m_Queue.pop_front(); + Lock.Unlock(); + + AString NewUserName = UserName; + AString UUID; + if (AuthWithYggdrasil(NewUserName, ServerID, UUID)) + { + LOGINFO("User %s authenticated with UUID '%s'", NewUserName.c_str(), UUID.c_str()); + cRoot::Get()->AuthenticateUser(ClientID, NewUserName, UUID); + } + else + { + cRoot::Get()->KickUser(ClientID, "Failed to authenticate account!"); + } + } // for (-ever) +} + + + + + +bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID) +{ + LOGD("Trying to auth user %s", a_UserName.c_str()); + + int ret; + unsigned char buf[1024]; + + /* Initialize certificates */ + // This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: + // Downloaded from http://certs.starfieldtech.com/repository/ + static const AString StarfieldCACert( + // G2 cert + "-----BEGIN CERTIFICATE-----\n" + "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" + "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" + "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n" + "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n" + "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n" + "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n" + "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n" + "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" + "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n" + "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n" + "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n" + "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n" + "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n" + "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n" + "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n" + "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n" + "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n" + "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n" + "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n" + "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n" + "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n" + "-----END CERTIFICATE-----\n\n" + // Original (G1) cert: + "-----BEGIN CERTIFICATE-----\n" + "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n" + "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n" + "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n" + "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n" + "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n" + "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n" + "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n" + "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n" + "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n" + "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n" + "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n" + "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n" + "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n" + "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n" + "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n" + "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n" + "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n" + "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n" + "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n" + "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n" + "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n" + "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n" + "-----END CERTIFICATE-----\n" + ); + + // Connect the socket: + cBlockingSslClientSocket Socket; + Socket.SetTrustedRootCertsFromString(StarfieldCACert, m_Server); + if (!Socket.Connect(m_Server, 443)) + { + LOGWARNING("cAuthenticator: Can't connect to %s: %s", m_Server.c_str(), Socket.GetLastErrorText().c_str()); + return false; + } + + // Create the GET request: + AString ActualAddress = m_Address; + ReplaceString(ActualAddress, "%USERNAME%", a_UserName); + ReplaceString(ActualAddress, "%SERVERID%", a_ServerId); + + AString Request; + Request += "GET " + ActualAddress + " HTTP/1.0\r\n"; + Request += "Host: " + m_Server + "\r\n"; + Request += "User-Agent: MCServer\r\n"; + Request += "Connection: close\r\n"; + Request += "\r\n"; + + if (!Socket.Send(Request.c_str(), Request.size())) + { + LOGWARNING("cAuthenticator: Writing SSL data failed: %s", Socket.GetLastErrorText().c_str()); + return false; + } + + // Read the HTTP response: + std::string Response; + for (;;) + { + ret = Socket.Receive(buf, sizeof(buf)); + + if ((ret == POLARSSL_ERR_NET_WANT_READ) || (ret == POLARSSL_ERR_NET_WANT_WRITE)) + { + // This value should never be returned, it is handled internally by cBlockingSslClientSocket + LOGWARNING("cAuthenticator: SSL reading failed internally."); + return false; + } + if (ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) + { + break; + } + if (ret < 0) + { + LOGWARNING("cAuthenticator: SSL reading failed: -0x%x", -ret); + return false; + } + if (ret == 0) + { + break; + } + + Response.append((const char *)buf, (size_t)ret); + } + + Socket.Disconnect(); + + // Check the HTTP status line: + AString prefix("HTTP/1.1 200 OK"); + AString HexDump; + if (Response.compare(0, prefix.size(), prefix)) + { + LOGINFO("User \"%s\" failed to auth, bad http status line received", a_UserName.c_str()); + LOG("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); + return false; + } + + // Erase the HTTP headers from the response: + size_t idxHeadersEnd = Response.find("\r\n\r\n"); + if (idxHeadersEnd == AString::npos) + { + LOGINFO("User \"%s\" failed to authenticate, bad http response header received", a_UserName.c_str()); + LOG("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); + return false; + } + Response.erase(0, idxHeadersEnd + 4); + + // Parse the Json response: + if (Response.empty()) + { + return false; + } + Json::Value root; + Json::Reader reader; + if (!reader.parse(Response, root, false)) + { + LOGWARNING("cAuthenticator: Cannot parse Received Data to json!"); + return false; + } + a_UserName = root.get("name", "Unknown").asString(); + a_UUID = root.get("id", "").asString(); + + // If the UUID doesn't contain the hashes, insert them at the proper places: + if (a_UUID.size() == 32) + { + a_UUID.insert(8, "-"); + a_UUID.insert(13, "-"); + a_UUID.insert(18, "-"); + a_UUID.insert(23, "-"); + } + return true; +} + + + + + diff --git a/src/Authenticator.h b/src/Protocol/Authenticator.h index 02cd6f4c5..211f51394 100644 --- a/src/Authenticator.h +++ b/src/Protocol/Authenticator.h @@ -14,7 +14,7 @@ #ifndef CAUTHENTICATOR_H_INCLUDED #define CAUTHENTICATOR_H_INCLUDED -#include "OSSupport/IsThread.h" +#include "../OSSupport/IsThread.h" @@ -31,23 +31,23 @@ class cAuthenticator : public cIsThread { typedef cIsThread super; - + public: cAuthenticator(void); ~cAuthenticator(); - /// (Re-)read server and address from INI: + /** (Re-)read server and address from INI: */ void ReadINI(cIniFile & IniFile); - /// Queues a request for authenticating a user. If the auth fails, the user is kicked + /** Queues a request for authenticating a user. If the auth fails, the user will be kicked */ void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash); - /// Starts the authenticator thread. The thread may be started and stopped repeatedly + /** Starts the authenticator thread. The thread may be started and stopped repeatedly */ void Start(cIniFile & IniFile); - - /// Stops the authenticator thread. The thread may be started and stopped repeatedly + + /** Stops the authenticator thread. The thread may be started and stopped repeatedly */ void Stop(void); - + private: class cUser @@ -56,30 +56,30 @@ private: int m_ClientID; AString m_Name; AString m_ServerID; - + cUser(int a_ClientID, const AString & a_Name, const AString & a_ServerID) : m_ClientID(a_ClientID), m_Name(a_Name), m_ServerID(a_ServerID) { } - } ; - + }; + typedef std::deque<cUser> cUserList; - + cCriticalSection m_CS; cUserList m_Queue; cEvent m_QueueNonempty; - + AString m_Server; AString m_Address; bool m_ShouldAuthenticate; - - // cIsThread override: + + /** cIsThread override: */ virtual void Execute(void) override; - - // Returns true if the user authenticated okay, false on error; iLevel is the recursion deptht (bails out if too deep) - bool AuthFromAddress(const AString & a_Server, const AString & a_Address, const AString & a_UserName, int a_Level = 1); + + /** Returns true if the user authenticated okay, false on error; iLevel is the recursion deptht (bails out if too deep) */ + bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID); }; 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/Protocol/Protocol.h b/src/Protocol/Protocol.h index ae06f2f9e..8f152ad37 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -83,6 +83,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; + virtual void SendLoginSuccess (void) = 0; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) = 0; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) = 0; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0; @@ -122,7 +123,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowOpen (const cWindow & a_Window) = 0; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) = 0; /// Returns the ServerID used for authentication through session.minecraft.net virtual AString GetAuthServerID(void) = 0; @@ -177,7 +178,7 @@ protected: void WriteInt64 (Int64 a_Value) { UInt64 Value = HostToNetwork8(&a_Value); - SendData((const char *)Value, 8); + SendData((const char *)&Value, 8); } void WriteFloat (float a_Value) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index bf946ef19..e7873cf7a 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/ArrowEntity.h" #include "../Entities/Minecart.h" #include "../Entities/FallingBlock.h" @@ -96,6 +96,7 @@ enum PACKET_INVENTORY_WHOLE = 0x68, PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, + PACKET_ENCHANT_ITEM = 0x6C, PACKET_UPDATE_SIGN = 0x82, PACKET_ITEM_DATA = 0x83, PACKET_PLAYER_LIST_ITEM = 0xC9, @@ -537,9 +538,10 @@ void cProtocol125::SendHealth(void) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); - WriteShort((short)m_Client->GetPlayer()->GetHealth()); - WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); - WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + WriteShort((short)Player->GetHealth()); + WriteShort((short)Player->GetFoodLevel()); + WriteFloat((float)Player->GetFoodSaturationLevel()); Flush(); } @@ -594,6 +596,15 @@ void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol125::SendLoginSuccess(void) +{ + // Not supported in this protocol version +} + + + + + void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { cCSLock Lock(m_CSPacket); @@ -642,18 +653,30 @@ void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor +void cProtocol125::SendMapInfo(int a_ID, unsigned int a_Scale) +{ + // This protocol doesn't support such message + UNUSED(a_ID); + UNUSED(a_Scale); +} + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_PICKUP_SPAWN); WriteInt (a_Pickup.GetUniqueID()); - WriteShort (a_Pickup.GetItem().m_ItemType); - WriteChar (a_Pickup.GetItem().m_ItemCount); - WriteShort (a_Pickup.GetItem().m_ItemDamage); + const cItem & Item = a_Pickup.GetItem(); + WriteShort (Item.m_ItemType); + WriteChar (Item.m_ItemCount); + WriteShort (Item.m_ItemDamage); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().y * 8)); - WriteByte ((char)(a_Pickup.GetSpeed().z * 8)); + WriteByte ((char)(a_Pickup.GetSpeedX() * 8)); + WriteByte ((char)(a_Pickup.GetSpeedY() * 8)); + WriteByte ((char)(a_Pickup.GetSpeedZ() * 8)); Flush(); } @@ -683,6 +706,16 @@ void cProtocol125::SendParticleEffect(const AString & a_ParticleName, float a_Sr +void cProtocol125::SendPaintingSpawn(const cPainting & a_Painting) +{ + // Not implemented in this protocol version + UNUSED(a_Painting); +} + + + + + void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { cCSLock Lock(m_CSPacket); @@ -800,10 +833,11 @@ void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect void cProtocol125::SendRespawn(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte (PACKET_RESPAWN); - WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension())); + WriteInt ((int)(Player->GetWorld()->GetDimension())); WriteByte (2); // TODO: Difficulty; 2 = Normal - WriteChar ((char)m_Client->GetPlayer()->GetGameMode()); + WriteChar ((char)Player->GetGameMode()); WriteShort (256); // Current world height WriteString("default"); } @@ -815,10 +849,11 @@ void cProtocol125::SendRespawn(void) void cProtocol125::SendExperience(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte (PACKET_EXPERIENCE); - WriteFloat (m_Client->GetPlayer()->GetXpPercentage()); - WriteShort (m_Client->GetPlayer()->GetXpLevel()); - WriteShort (m_Client->GetPlayer()->GetCurrentXp()); + WriteFloat (Player->GetXpPercentage()); + WriteShort (Player->GetXpLevel()); + WriteShort (Player->GetCurrentXp()); Flush(); } @@ -842,6 +877,18 @@ void cProtocol125::SendExperienceOrb(const cExpOrb & a_ExpOrb) +void cProtocol125::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) +{ + // This protocol version doesn't support such message + UNUSED(a_Name); + UNUSED(a_DisplayName); + UNUSED(a_Mode); +} + + + + + void cProtocol125::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { // Not needed in this protocol version @@ -1128,7 +1175,7 @@ void cProtocol125::SendWindowOpen(const cWindow & a_Window) -void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocol125::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_PROPERTY); @@ -1236,6 +1283,7 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) case PACKET_SLOT_SELECTED: return ParseSlotSelected(); case PACKET_UPDATE_SIGN: return ParseUpdateSign(); case PACKET_USE_ENTITY: return ParseUseEntity(); + case PACKET_ENCHANT_ITEM: return ParseEnchantItem(); case PACKET_WINDOW_CLICK: return ParseWindowClick(); case PACKET_WINDOW_CLOSE: return ParseWindowClose(); } @@ -1597,6 +1645,20 @@ int cProtocol125::ParseUseEntity(void) +int cProtocol125::ParseEnchantItem(void) +{ + HANDLE_PACKET_READ(ReadByte, Byte, WindowID); + HANDLE_PACKET_READ(ReadByte, Byte, Enchantment); + + m_Client->HandleEnchantItem(WindowID, Enchantment); + + return PARSE_OK; +} + + + + + int cProtocol125::ParseWindowClick(void) { HANDLE_PACKET_READ(ReadChar, char, WindowID); @@ -1951,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/Protocol125.h b/src/Protocol/Protocol125.h index 08d3ebbe9..423e58d67 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -56,19 +56,12 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override - { - // This protocol doesn't support such message - UNUSED(a_ID); - UNUSED(a_Scale); - } + virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override; - virtual void SendPaintingSpawn (const cPainting & a_Painting) override - { - UNUSED(a_Painting); - }; + virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; @@ -82,12 +75,7 @@ public: virtual void SendRespawn (void) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; - virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override - { - UNUSED(a_Name); - UNUSED(a_DisplayName); - UNUSED(a_Mode); - } // This protocol doesn't support such message + virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 @@ -108,7 +96,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override; @@ -155,6 +143,7 @@ protected: virtual int ParseSlotSelected (void); virtual int ParseUpdateSign (void); virtual int ParseUseEntity (void); + virtual int ParseEnchantItem (void); virtual int ParseWindowClick (void); virtual int ParseWindowClose (void); diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index ce5942a5c..f4717f592 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -18,19 +18,7 @@ #include "../WorldStorage/FastNBT.h" #include "../WorldStorage/EnchantmentSerializer.h" #include "../StringCompression.h" - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable:4127) - #pragma warning(disable:4244) - #pragma warning(disable:4231) - #pragma warning(disable:4189) - #pragma warning(disable:4702) -#endif - -#ifdef _MSC_VER - #pragma warning(pop) -#endif +#include "PolarSSL++/Sha1Checksum.h" @@ -408,7 +396,8 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window) super::SendWholeInventory(a_Window); // Send the player inventory and hotbar: - const cInventory & Inventory = m_Client->GetPlayer()->GetInventory(); + cPlayer * Player = m_Client->GetPlayer(); + const cInventory & Inventory = Player->GetInventory(); int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots char WindowID = a_Window.GetWindowID(); for (short i = 0; i < cInventory::invInventoryCount; i++) @@ -422,7 +411,7 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window) } // for i - Hotbar[] // Send even the item being dragged: - SendInventorySlot(-1, -1, m_Client->GetPlayer()->GetDraggingItem()); + SendInventorySlot(-1, -1, Player->GetDraggingItem()); } @@ -800,10 +789,12 @@ void cProtocol132::SendCompass(const cWorld & a_World) void cProtocol132::SendEncryptionKeyRequest(void) { cCSLock Lock(m_CSPacket); + cServer * Server = cRoot::Get()->GetServer(); WriteByte(0xfd); - WriteString(cRoot::Get()->GetServer()->GetServerID()); - WriteShort((short)(cRoot::Get()->GetServer()->GetPublicKeyDER().size())); - SendData(cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + WriteString(Server->GetServerID()); + const AString & PublicKeyDER = Server->GetPublicKeyDER(); + WriteShort((short)(PublicKeyDER.size())); + SendData(PublicKeyDER.data(), PublicKeyDER.size()); WriteShort(4); WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) Flush(); @@ -816,7 +807,7 @@ void cProtocol132::SendEncryptionKeyRequest(void) void cProtocol132::HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce) { // Decrypt EncNonce using privkey - cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; int res = rsaDecryptor.Decrypt((const Byte *)a_EncNonce.data(), a_EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); @@ -873,14 +864,15 @@ void cProtocol132::StartEncryption(const Byte * a_Key) m_IsEncrypted = true; // Prepare the m_AuthServerID: - cSHA1Checksum Checksum; - AString ServerID = cRoot::Get()->GetServer()->GetServerID(); + cSha1Checksum Checksum; + cServer * Server = cRoot::Get()->GetServer(); + AString ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); + cSha1Checksum::DigestToJava(Digest, m_AuthServerID); } diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index b280c8a41..32bc7d581 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -24,7 +24,8 @@ #pragma warning(pop) #endif -#include "../Crypto.h" +#include "PolarSSL++/AesCfb128Decryptor.h" +#include "PolarSSL++/AesCfb128Encryptor.h" @@ -79,8 +80,8 @@ public: protected: bool m_IsEncrypted; - cAESCFBDecryptor m_Decryptor; - cAESCFBEncryptor m_Encryptor; + cAesCfb128Decryptor m_Decryptor; + cAesCfb128Encryptor m_Encryptor; AString m_DataToSend; diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp index f694af1eb..f60e756fd 100644 --- a/src/Protocol/Protocol14x.cpp +++ b/src/Protocol/Protocol14x.cpp @@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup) WriteInt (a_Pickup.GetUniqueID()); WriteItem (a_Pickup.GetItem()); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); - WriteChar ((char)(a_Pickup.GetSpeed().x * 8)); - WriteChar ((char)(a_Pickup.GetSpeed().y * 8)); - WriteChar ((char)(a_Pickup.GetSpeed().z * 8)); + WriteChar((char)(a_Pickup.GetSpeedX() * 8)); + WriteChar((char)(a_Pickup.GetSpeedY() * 8)); + WriteChar((char)(a_Pickup.GetSpeedZ() * 8)); Flush(); } @@ -170,9 +170,9 @@ void cProtocol146::SendPickupSpawn(const cPickup & a_Pickup) WriteInt ((int)(a_Pickup.GetPosY() * 32)); WriteInt ((int)(a_Pickup.GetPosZ() * 32)); WriteInt (1); - WriteShort((short)(a_Pickup.GetSpeed().x * 32)); - WriteShort((short)(a_Pickup.GetSpeed().y * 32)); - WriteShort((short)(a_Pickup.GetSpeed().z * 32)); + WriteShort((short)(a_Pickup.GetSpeedX() * 32)); + WriteShort((short)(a_Pickup.GetSpeedY() * 32)); + WriteShort((short)(a_Pickup.GetSpeedZ() * 32)); WriteByte(0); WriteByte(0); diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index bf7d9a0b1..714bf5e46 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -18,6 +18,7 @@ Implements the 1.6.x protocol classes: #include "../Entities/Entity.h" #include "../Entities/Player.h" #include "../UI/Window.h" +#include "../CompositeChat.h" @@ -89,6 +90,18 @@ void cProtocol161::SendChat(const AString & a_Message) +void cProtocol161::SendChat(const cCompositeChat & a_Message) +{ + // This protocol version doesn't support composite messages to the full + // Just extract each part's text and use it: + + super::SendChat(Printf("{\"text\":\"%s\"}", EscapeString(a_Message.ExtractText()).c_str())); +} + + + + + void cProtocol161::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { cCSLock Lock(m_CSPacket); @@ -118,9 +131,10 @@ void cProtocol161::SendHealth(void) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); - WriteFloat((float)m_Client->GetPlayer()->GetHealth()); - WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); - WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + WriteFloat((float)Player->GetHealth()); + WriteShort((short)Player->GetFoodLevel()); + WriteFloat((float)Player->GetFoodSaturationLevel()); Flush(); } @@ -131,11 +145,12 @@ void cProtocol161::SendHealth(void) void cProtocol161::SendPlayerMaxSpeed(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte(PACKET_ENTITY_PROPERTIES); - WriteInt(m_Client->GetPlayer()->GetUniqueID()); + WriteInt(Player->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * Player->GetMaxSpeed()); Flush(); } @@ -201,6 +216,25 @@ int cProtocol161::ParseEntityAction(void) +int cProtocol161::ParseLogin(void) +{ + // The login packet is sent by Forge clients only + // Only parse the packet, do no extra processing + // Note that the types and the names have been only guessed and are not verified at all! + HANDLE_PACKET_READ(ReadBEInt, int, Int1); + HANDLE_PACKET_READ(ReadBEUTF16String16, AString, String1); + HANDLE_PACKET_READ(ReadChar, char, Char1); + HANDLE_PACKET_READ(ReadChar, char, Char2); + HANDLE_PACKET_READ(ReadChar, char, Char3); + HANDLE_PACKET_READ(ReadByte, Byte, Byte1); + HANDLE_PACKET_READ(ReadByte, Byte, Byte2); + return PARSE_OK; +} + + + + + int cProtocol161::ParsePlayerAbilities(void) { HANDLE_PACKET_READ(ReadByte, Byte, Flags); @@ -263,11 +297,12 @@ cProtocol162::cProtocol162(cClientHandle * a_Client) : void cProtocol162::SendPlayerMaxSpeed(void) { cCSLock Lock(m_CSPacket); + cPlayer * Player = m_Client->GetPlayer(); WriteByte(PACKET_ENTITY_PROPERTIES); - WriteInt(m_Client->GetPlayer()->GetUniqueID()); + WriteInt(Player->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); - WriteDouble(0.1 * m_Client->GetPlayer()->GetMaxSpeed()); + WriteDouble(0.1 * Player->GetMaxSpeed()); WriteShort(0); Flush(); } diff --git a/src/Protocol/Protocol16x.h b/src/Protocol/Protocol16x.h index 325e41c5a..8eedce8d5 100644 --- a/src/Protocol/Protocol16x.h +++ b/src/Protocol/Protocol16x.h @@ -37,6 +37,7 @@ protected: // cProtocol150 overrides: virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; virtual void SendChat (const AString & a_Message) override; + virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; @@ -45,6 +46,7 @@ protected: virtual void SendWindowOpen (const cWindow & a_Window) override; virtual int ParseEntityAction (void) override; + virtual int ParseLogin (void) override; virtual int ParsePlayerAbilities(void) override; // New packets: diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index a4319df37..bc9aff0c0 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -31,6 +31,9 @@ Implements the 1.7.x protocol classes: #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../CompositeChat.h" +#include "../Entities/ArrowEntity.h" +#include "../Entities/FireworkEntity.h" +#include "PolarSSL++/Sha1Checksum.h" @@ -88,8 +91,9 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd // Create the comm log file, if so requested: if (g_ShouldLogCommIn || g_ShouldLogCommOut) { + static int sCounter = 0; cFile::CreateFolder("CommLogs"); - AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str()); + AString FileName = Printf("CommLogs/%x_%d__%s.log", (unsigned)time(NULL), sCounter++, a_Client->GetIPString().c_str()); m_CommLogFile.Open(FileName, cFile::fmWrite); } } @@ -124,6 +128,8 @@ void cProtocol172::DataReceived(const char * a_Data, size_t a_Size) void cProtocol172::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1b); // Attach Entity packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteInt((a_Vehicle != NULL) ? a_Vehicle->GetUniqueID() : 0); @@ -136,6 +142,8 @@ void cProtocol172::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x24); // Block Action packet Pkt.WriteInt(a_BlockX); Pkt.WriteShort(a_BlockY); @@ -151,6 +159,8 @@ void cProtocol172::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x25); // Block Break Animation packet Pkt.WriteVarInt(a_EntityID); Pkt.WriteInt(a_BlockX); @@ -165,6 +175,8 @@ void cProtocol172::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY void cProtocol172::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x23); // Block Change packet Pkt.WriteInt(a_BlockX); Pkt.WriteByte(a_BlockY); @@ -179,6 +191,8 @@ void cProtocol172::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLO void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x22); // Multi Block Change packet Pkt.WriteInt(a_ChunkX); Pkt.WriteInt(a_ChunkZ); @@ -198,6 +212,8 @@ void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV void cProtocol172::SendChat(const AString & a_Message) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x02); // Chat Message packet Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str())); } @@ -208,6 +224,8 @@ void cProtocol172::SendChat(const AString & a_Message) void cProtocol172::SendChat(const cCompositeChat & a_Message) { + ASSERT(m_State == 3); // In game mode? + // Compose the complete Json string to send: Json::Value msg; msg["text"] = ""; // The client crashes without this @@ -280,6 +298,8 @@ void cProtocol172::SendChat(const cCompositeChat & a_Message) void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { + ASSERT(m_State == 3); // In game mode? + // Serialize first, before creating the Packetizer (the packetizer locks a CS) // This contains the flags and bitmasks, too const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2); @@ -296,6 +316,8 @@ void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize void cProtocol172::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0d); // Collect Item packet Pkt.WriteInt(a_Pickup.GetUniqueID()); Pkt.WriteInt(a_Player.GetUniqueID()); @@ -307,6 +329,8 @@ void cProtocol172::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a void cProtocol172::SendDestroyEntity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x13); // Destroy Entities packet Pkt.WriteByte(1); Pkt.WriteInt(a_Entity.GetUniqueID()); @@ -343,6 +367,8 @@ void cProtocol172::SendDisconnect(const AString & a_Reason) void cProtocol172::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x36); // Sign Editor Open packet Pkt.WriteInt(a_BlockX); Pkt.WriteInt(a_BlockY); @@ -355,6 +381,8 @@ void cProtocol172::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol172::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1D); // Entity Effect packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_EffectID); @@ -368,6 +396,8 @@ void cProtocol172::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, in void cProtocol172::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x04); // Entity Equipment packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteShort(a_SlotNum); @@ -380,6 +410,8 @@ void cProtocol172::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum void cProtocol172::SendEntityHeadLook(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x19); // Entity Head Look packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); @@ -391,6 +423,8 @@ void cProtocol172::SendEntityHeadLook(const cEntity & a_Entity) void cProtocol172::SendEntityLook(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x16); // Entity Look packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByteAngle(a_Entity.GetYaw()); @@ -403,6 +437,8 @@ void cProtocol172::SendEntityLook(const cEntity & a_Entity) void cProtocol172::SendEntityMetadata(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteEntityMetadata(a_Entity); @@ -415,6 +451,8 @@ void cProtocol172::SendEntityMetadata(const cEntity & a_Entity) void cProtocol172::SendEntityProperties(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x20); // Entity Properties packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteEntityProperties(a_Entity); @@ -426,6 +464,8 @@ void cProtocol172::SendEntityProperties(const cEntity & a_Entity) void cProtocol172::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_RelX); @@ -439,6 +479,8 @@ void cProtocol172::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char void cProtocol172::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_RelX); @@ -454,6 +496,8 @@ void cProtocol172::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, void cProtocol172::SendEntityStatus(const cEntity & a_Entity, char a_Status) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x1a); // Entity Status packet Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteChar(a_Status); @@ -465,6 +509,8 @@ void cProtocol172::SendEntityStatus(const cEntity & a_Entity, char a_Status) void cProtocol172::SendEntityVelocity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x12); // Entity Velocity packet Pkt.WriteInt(a_Entity.GetUniqueID()); // 400 = 8000 / 20 ... Conversion from our speed in m/s to 8000 m/tick @@ -479,6 +525,8 @@ void cProtocol172::SendEntityVelocity(const cEntity & a_Entity) void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x27); // Explosion packet Pkt.WriteFloat((float)a_BlockX); Pkt.WriteFloat((float)a_BlockY); @@ -502,6 +550,8 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc void cProtocol172::SendGameMode(eGameMode a_GameMode) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2b); // Change Game State packet Pkt.WriteByte(3); // Reason: Change game mode Pkt.WriteFloat((float)a_GameMode); @@ -513,10 +563,13 @@ void cProtocol172::SendGameMode(eGameMode a_GameMode) void cProtocol172::SendHealth(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x06); // Update Health packet - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetHealth()); - Pkt.WriteShort(m_Client->GetPlayer()->GetFoodLevel()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteFloat((float)Player->GetHealth()); + Pkt.WriteShort(Player->GetFoodLevel()); + Pkt.WriteFloat((float)Player->GetFoodSaturationLevel()); } @@ -525,6 +578,8 @@ void cProtocol172::SendHealth(void) void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2f); // Set Slot packet Pkt.WriteChar(a_WindowID); Pkt.WriteShort(a_SlotNum); @@ -537,6 +592,13 @@ void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt void cProtocol172::SendKeepAlive(int a_PingID) { + // Drop the packet if the protocol is not in the Game state yet (caused a client crash): + if (m_State != 3) + { + LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State); + return; + } + cPacketizer Pkt(*this, 0x00); // Keep Alive packet Pkt.WriteInt(a_PingID); } @@ -549,12 +611,13 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) { // Send the Join Game packet: { + cServer * Server = cRoot::Get()->GetServer(); cPacketizer Pkt(*this, 0x01); // Join Game packet Pkt.WriteInt(a_Player.GetUniqueID()); - Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (cRoot::Get()->GetServer()->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 + Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 Pkt.WriteChar((char)a_World.GetDimension()); Pkt.WriteByte(2); // TODO: Difficulty (set to Normal) - Pkt.WriteByte(std::min(cRoot::Get()->GetServer()->GetMaxPlayers(), 60)); + Pkt.WriteByte(std::min(Server->GetMaxPlayers(), 60)); Pkt.WriteString("default"); // Level type - wtf? } @@ -573,8 +636,27 @@ void cProtocol172::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +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()); + } + + m_State = 3; // State = Game +} + + + + + void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x10); // Spawn Painting packet Pkt.WriteVarInt(a_Painting.GetUniqueID()); Pkt.WriteString(a_Painting.GetName().c_str()); @@ -590,6 +672,8 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (3 + a_Length); @@ -610,6 +694,8 @@ void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (1 + (3 * a_Decorators.size())); @@ -630,6 +716,8 @@ void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt(a_ID); Pkt.WriteShort (2); @@ -645,6 +733,8 @@ void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale) void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) { + ASSERT(m_State == 3); // In game mode? + { cPacketizer Pkt(*this, 0x0e); // Spawn Object packet Pkt.WriteVarInt(a_Pickup.GetUniqueID()); @@ -671,24 +761,27 @@ void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup) void cProtocol172::SendPlayerAbilities(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x39); // Player Abilities packet Byte Flags = 0; - if (m_Client->GetPlayer()->IsGameModeCreative()) + cPlayer * Player = m_Client->GetPlayer(); + if (Player->IsGameModeCreative()) { Flags |= 0x01; Flags |= 0x08; // Godmode, used for creative } - if (m_Client->GetPlayer()->IsFlying()) + if (Player->IsFlying()) { Flags |= 0x02; } - if (m_Client->GetPlayer()->CanFly()) + if (Player->CanFly()) { Flags |= 0x04; } Pkt.WriteByte(Flags); - Pkt.WriteFloat((float)(0.05 * m_Client->GetPlayer()->GetFlyingMaxSpeed())); - Pkt.WriteFloat((float)(0.1 * m_Client->GetPlayer()->GetMaxSpeed())); + Pkt.WriteFloat((float)(0.05 * Player->GetFlyingMaxSpeed())); + Pkt.WriteFloat((float)(0.1 * Player->GetMaxSpeed())); } @@ -697,6 +790,8 @@ void cProtocol172::SendPlayerAbilities(void) void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0b); // Animation packet Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteChar(a_Animation); @@ -708,6 +803,8 @@ void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2A); Pkt.WriteString(a_ParticleName); Pkt.WriteFloat(a_SrcX); @@ -726,6 +823,8 @@ void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_Sr void cProtocol172::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x38); // Playerlist Item packet Pkt.WriteString(a_Player.GetName()); Pkt.WriteBool(a_IsOnline); @@ -738,18 +837,21 @@ void cProtocol172::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) void cProtocol172::SendPlayerMaxSpeed(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x20); // Entity Properties - Pkt.WriteInt(m_Client->GetPlayer()->GetUniqueID()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteInt(Player->GetUniqueID()); Pkt.WriteInt(1); // Count Pkt.WriteString("generic.movementSpeed"); // The default game speed is 0.1, multiply that value by the relative speed: - Pkt.WriteDouble(0.1 * m_Client->GetPlayer()->GetNormalMaxSpeed()); - if (m_Client->GetPlayer()->IsSprinting()) + Pkt.WriteDouble(0.1 * Player->GetNormalMaxSpeed()); + if (Player->IsSprinting()) { Pkt.WriteShort(1); // Modifier count Pkt.WriteInt64(0x662a6b8dda3e4c1c); Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteDouble(m_Client->GetPlayer()->GetSprintingMaxSpeed() - m_Client->GetPlayer()->GetNormalMaxSpeed()); + Pkt.WriteDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed()); Pkt.WriteByte(2); } else @@ -764,17 +866,20 @@ void cProtocol172::SendPlayerMaxSpeed(void) void cProtocol172::SendPlayerMoveLook(void) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x08); // Player Position And Look packet - Pkt.WriteDouble(m_Client->GetPlayer()->GetPosX()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteDouble(Player->GetPosX()); // Protocol docs say this is PosY, but #323 says this is eye-pos // Moreover, the "+ 0.001" is there because otherwise the player falls through the block they were standing on. - Pkt.WriteDouble(m_Client->GetPlayer()->GetStance() + 0.001); + Pkt.WriteDouble(Player->GetStance() + 0.001); - Pkt.WriteDouble(m_Client->GetPlayer()->GetPosZ()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetYaw()); - Pkt.WriteFloat((float)m_Client->GetPlayer()->GetPitch()); - Pkt.WriteBool(m_Client->GetPlayer()->IsOnGround()); + Pkt.WriteDouble(Player->GetPosZ()); + Pkt.WriteFloat((float)Player->GetYaw()); + Pkt.WriteFloat((float)Player->GetPitch()); + Pkt.WriteBool(Player->IsOnGround()); } @@ -793,10 +898,12 @@ void cProtocol172::SendPlayerPosition(void) void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) { + ASSERT(m_State == 3); // In game mode? + // Called to spawn another player for the client cPacketizer Pkt(*this, 0x0c); // Spawn Player packet Pkt.WriteVarInt(a_Player.GetUniqueID()); - Pkt.WriteString(Printf("%d", a_Player.GetUniqueID())); // TODO: Proper UUID + Pkt.WriteString(a_Player.GetClientHandle()->GetUUID()); Pkt.WriteString(a_Player.GetName()); Pkt.WriteFPInt(a_Player.GetPosX()); Pkt.WriteFPInt(a_Player.GetPosY()); @@ -816,6 +923,8 @@ void cProtocol172::SendPlayerSpawn(const cPlayer & a_Player) void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & a_Message) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x3f); Pkt.WriteString(a_Channel); Pkt.WriteShort((short)a_Message.size()); @@ -828,7 +937,9 @@ void cProtocol172::SendPluginMessage(const AString & a_Channel, const AString & void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { - cPacketizer Pkt(*this, 0x1E); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x1e); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_EffectID); } @@ -840,9 +951,10 @@ void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect void cProtocol172::SendRespawn(void) { cPacketizer Pkt(*this, 0x07); // Respawn packet - Pkt.WriteInt(m_Client->GetPlayer()->GetWorld()->GetDimension()); + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteInt(Player->GetWorld()->GetDimension()); Pkt.WriteByte(2); // TODO: Difficulty (set to Normal) - Pkt.WriteByte((Byte)m_Client->GetPlayer()->GetEffectiveGameMode()); + Pkt.WriteByte((Byte)Player->GetEffectiveGameMode()); Pkt.WriteString("default"); } @@ -852,10 +964,13 @@ void cProtocol172::SendRespawn(void) void cProtocol172::SendExperience (void) { - cPacketizer Pkt(*this, 0x1F); //Experience Packet - Pkt.WriteFloat(m_Client->GetPlayer()->GetXpPercentage()); - Pkt.WriteShort(m_Client->GetPlayer()->GetXpLevel()); - Pkt.WriteShort(m_Client->GetPlayer()->GetCurrentXp()); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x1f); // Experience Packet + cPlayer * Player = m_Client->GetPlayer(); + Pkt.WriteFloat(Player->GetXpPercentage()); + Pkt.WriteShort(Player->GetXpLevel()); + Pkt.WriteShort(Player->GetCurrentXp()); } @@ -864,6 +979,8 @@ void cProtocol172::SendExperience (void) void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x11); Pkt.WriteVarInt(a_ExpOrb.GetUniqueID()); Pkt.WriteInt((int) a_ExpOrb.GetPosX()); @@ -878,7 +995,9 @@ void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb) void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3B); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3b); Pkt.WriteString(a_Name); Pkt.WriteString(a_DisplayName); Pkt.WriteByte(a_Mode); @@ -890,7 +1009,9 @@ void cProtocol172::SendScoreboardObjective(const AString & a_Name, const AString void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) { - cPacketizer Pkt(*this, 0x3C); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3c); Pkt.WriteString(a_Player); Pkt.WriteByte(a_Mode); @@ -907,7 +1028,9 @@ void cProtocol172::SendScoreUpdate(const AString & a_Objective, const AString & void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) { - cPacketizer Pkt(*this, 0x3D); + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x3d); Pkt.WriteByte((int) a_Display); Pkt.WriteString(a_Objective); } @@ -918,6 +1041,8 @@ void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8 { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x29); // Sound Effect packet Pkt.WriteString(a_SoundName); Pkt.WriteInt(a_SrcX); @@ -933,6 +1058,8 @@ void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x28); // Effect packet Pkt.WriteInt(a_EffectID); Pkt.WriteInt(a_SrcX); @@ -948,6 +1075,8 @@ void cProtocol172::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0e); // Spawn Object packet Pkt.WriteVarInt(a_FallingBlock.GetUniqueID()); Pkt.WriteByte(70); // Falling block @@ -968,6 +1097,8 @@ void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) void cProtocol172::SendSpawnMob(const cMonster & a_Mob) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet Pkt.WriteVarInt(a_Mob.GetUniqueID()); Pkt.WriteByte((Byte)a_Mob.GetMobType()); @@ -990,6 +1121,8 @@ void cProtocol172::SendSpawnMob(const cMonster & a_Mob) void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0xe); // Spawn Object packet Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteByte(a_ObjectType); @@ -1013,6 +1146,8 @@ void cProtocol172::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0xe); // Spawn Object packet Pkt.WriteVarInt(a_Vehicle.GetUniqueID()); Pkt.WriteByte(a_VehicleType); @@ -1036,6 +1171,8 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet Pkt.WriteVarInt(a_Results.size()); @@ -1051,6 +1188,8 @@ void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x18); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteFPInt(a_Entity.GetPosX()); @@ -1066,6 +1205,8 @@ void cProtocol172::SendTeleportEntity(const cEntity & a_Entity) void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2c); // Spawn Global Entity packet Pkt.WriteVarInt(0); // EntityID = 0, always Pkt.WriteByte(1); // Type = Thunderbolt @@ -1080,6 +1221,8 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x03); Pkt.WriteInt64(a_WorldAge); Pkt.WriteInt64(a_TimeOfDay); @@ -1091,6 +1234,8 @@ void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay) void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x21); // Chunk Data packet Pkt.WriteInt(a_ChunkX); Pkt.WriteInt(a_ChunkZ); @@ -1105,6 +1250,8 @@ void cProtocol172::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x35); // Update tile entity packet Pkt.WriteInt(a_BlockEntity.GetPosX()); Pkt.WriteShort(a_BlockEntity.GetPosY()); @@ -1130,6 +1277,8 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x33); Pkt.WriteInt(a_BlockX); Pkt.WriteShort((short)a_BlockY); @@ -1147,6 +1296,8 @@ void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x0a); Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteInt(a_BlockX); @@ -1160,6 +1311,8 @@ void cProtocol172::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc void cProtocol172::SendWeather(eWeather a_Weather) { + ASSERT(m_State == 3); // In game mode? + { cPacketizer Pkt(*this, 0x2b); // Change Game State packet Pkt.WriteByte((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain @@ -1175,6 +1328,8 @@ void cProtocol172::SendWeather(eWeather a_Weather) void cProtocol172::SendWholeInventory(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x30); // Window Items packet Pkt.WriteChar(a_Window.GetWindowID()); Pkt.WriteShort(a_Window.GetNumSlots()); @@ -1192,6 +1347,8 @@ void cProtocol172::SendWholeInventory(const cWindow & a_Window) void cProtocol172::SendWindowClose(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x2e); Pkt.WriteChar(a_Window.GetWindowID()); } @@ -1202,6 +1359,8 @@ void cProtocol172::SendWindowClose(const cWindow & a_Window) void cProtocol172::SendWindowOpen(const cWindow & a_Window) { + ASSERT(m_State == 3); // In game mode? + if (a_Window.GetWindowType() < 0) { // Do not send this packet for player inventory windows @@ -1224,8 +1383,10 @@ void cProtocol172::SendWindowOpen(const cWindow & a_Window) -void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocol172::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { + ASSERT(m_State == 3); // In game mode? + cPacketizer Pkt(*this, 0x31); // Window Property packet Pkt.WriteChar(a_Window.GetWindowID()); Pkt.WriteShort(a_Property); @@ -1431,6 +1592,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true; case 0x0f: // Confirm transaction - not used in MCS case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; + case 0x11: HandlePacketEnchantItem (a_ByteBuffer); return true; case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true; case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true; case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true; @@ -1485,15 +1647,16 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) { // Send the response: AString Response = "{\"version\":{\"name\":\"1.7.2\",\"protocol\":4},\"players\":{"; + cServer * Server = cRoot::Get()->GetServer(); AppendPrintf(Response, "\"max\":%u,\"online\":%u,\"sample\":[]},", - cRoot::Get()->GetServer()->GetMaxPlayers(), - cRoot::Get()->GetServer()->GetNumPlayers() + Server->GetMaxPlayers(), + Server->GetNumPlayers() ); AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", - cRoot::Get()->GetServer()->GetDescription().c_str() + Server->GetDescription().c_str() ); AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", - cRoot::Get()->GetServer()->GetFaviconData().c_str() + Server->GetFaviconData().c_str() ); Response.append("}"); @@ -1528,7 +1691,7 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe } // Decrypt EncNonce using privkey - cRSAPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); + cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey(); Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)]; int res = rsaDecryptor.Decrypt((const Byte *)EncNonce.data(), EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce)); if (res != 4) @@ -1555,15 +1718,6 @@ void cProtocol172::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffe } StartEncryption(DecryptedKey); - - // Send login success: - { - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(Printf("%d", m_Client->GetUniqueID())); // TODO: proper UUID - Pkt.WriteString(m_Client->GetUsername()); - } - - m_State = 3; // State = Game m_Client->HandleLogin(4, m_Client->GetUsername()); } @@ -1582,12 +1736,13 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) return; } + cServer * Server = cRoot::Get()->GetServer(); // If auth is required, then send the encryption request: - if (cRoot::Get()->GetServer()->ShouldAuthenticate()) + if (Server->ShouldAuthenticate()) { cPacketizer Pkt(*this, 0x01); - Pkt.WriteString(cRoot::Get()->GetServer()->GetServerID()); - const AString & PubKeyDer = cRoot::Get()->GetServer()->GetPublicKeyDER(); + Pkt.WriteString(Server->GetServerID()); + const AString & PubKeyDer = Server->GetPublicKeyDER(); Pkt.WriteShort(PubKeyDer.size()); Pkt.WriteBuf(PubKeyDer.data(), PubKeyDer.size()); Pkt.WriteShort(4); @@ -1596,14 +1751,6 @@ void cProtocol172::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer) return; } - // Send login success: - { - cPacketizer Pkt(*this, 0x02); // Login success packet - Pkt.WriteString(Printf("%d", m_Client->GetUniqueID())); // TODO: proper UUID - Pkt.WriteString(Username); - } - - m_State = 3; // State = Game m_Client->HandleLogin(4, Username); } @@ -1912,6 +2059,18 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer) +void cProtocol172::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer) +{ + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID); + HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment); + + m_Client->HandleEnchantItem(WindowID, Enchantment); +} + + + + + void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID); @@ -2135,14 +2294,15 @@ void cProtocol172::StartEncryption(const Byte * a_Key) m_IsEncrypted = true; // Prepare the m_AuthServerID: - cSHA1Checksum Checksum; - const AString & ServerID = cRoot::Get()->GetServer()->GetServerID(); + cSha1Checksum Checksum; + cServer * Server = cRoot::Get()->GetServer(); + const AString & ServerID = Server->GetServerID(); Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length()); Checksum.Update(a_Key, 16); - Checksum.Update((const Byte *)cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); + Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size()); Byte Digest[20]; Checksum.Finalize(Digest); - cSHA1Checksum::DigestToJava(Digest, m_AuthServerID); + cSha1Checksum::DigestToJava(Digest, m_AuthServerID); } @@ -2481,11 +2641,12 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone) { cRideableMinecart & RideableMinecart = ((cRideableMinecart &)a_Entity); - if (!RideableMinecart.GetContent().IsEmpty()) + const cItem & MinecartContent = RideableMinecart.GetContent(); + if (!MinecartContent.IsEmpty()) { WriteByte(0x54); - int Content = RideableMinecart.GetContent().m_ItemType; - Content |= RideableMinecart.GetContent().m_ItemDamage << 8; + int Content = MinecartContent.m_ItemType; + Content |= MinecartContent.m_ItemDamage << 8; WriteInt(Content); WriteByte(0x55); WriteInt(RideableMinecart.GetBlockHeight()); @@ -2664,7 +2825,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; @@ -2755,3 +2916,64 @@ void cProtocol172::cPacketizer::WriteEntityProperties(const cEntity & a_Entity) + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cProtocol176: + +cProtocol176::cProtocol176(cClientHandle * a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) : + super(a_Client, a_ServerAddress, a_ServerPort, a_State) +{ +} + + + + + +void cProtocol176::SendPlayerSpawn(const cPlayer & a_Player) +{ + // Called to spawn another player for the client + cPacketizer Pkt(*this, 0x0c); // Spawn Player packet + Pkt.WriteVarInt(a_Player.GetUniqueID()); + Pkt.WriteString(a_Player.GetClientHandle()->GetUUID()); + Pkt.WriteString(a_Player.GetName()); + Pkt.WriteVarInt(0); // We have no data to send here + Pkt.WriteFPInt(a_Player.GetPosX()); + Pkt.WriteFPInt(a_Player.GetPosY()); + Pkt.WriteFPInt(a_Player.GetPosZ()); + Pkt.WriteByteAngle(a_Player.GetYaw()); + Pkt.WriteByteAngle(a_Player.GetPitch()); + short ItemType = a_Player.GetEquippedItem().IsEmpty() ? 0 : a_Player.GetEquippedItem().m_ItemType; + Pkt.WriteShort(ItemType); + Pkt.WriteByte((3 << 5) | 6); // Metadata: float + index 6 + Pkt.WriteFloat((float)a_Player.GetHealth()); + Pkt.WriteByte(0x7f); // Metadata: end +} + + + + + +void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) +{ + // Send the response: + AString Response = "{\"version\":{\"name\":\"1.7.6\",\"protocol\":5},\"players\":{"; + AppendPrintf(Response, "\"max\":%u,\"online\":%u,\"sample\":[]},", + cRoot::Get()->GetServer()->GetMaxPlayers(), + cRoot::Get()->GetServer()->GetNumPlayers() + ); + AppendPrintf(Response, "\"description\":{\"text\":\"%s\"},", + cRoot::Get()->GetServer()->GetDescription().c_str() + ); + AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", + cRoot::Get()->GetServer()->GetFaviconData().c_str() + ); + Response.append("}"); + + cPacketizer Pkt(*this, 0x00); // Response packet + Pkt.WriteString(Response); +} + + + + + diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 91186b270..dc111e737 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -30,7 +30,8 @@ Declares the 1.7.x protocol classes: #pragma warning(pop) #endif -#include "../Crypto.h" +#include "PolarSSL++/AesCfb128Decryptor.h" +#include "PolarSSL++/AesCfb128Encryptor.h" @@ -87,6 +88,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; @@ -126,7 +128,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override { return m_AuthServerID; } @@ -235,8 +237,8 @@ protected: bool m_IsEncrypted; - cAESCFBDecryptor m_Decryptor; - cAESCFBEncryptor m_Encryptor; + cAesCfb128Decryptor m_Decryptor; + cAesCfb128Encryptor m_Encryptor; /** The logfile where the comm is logged, when g_ShouldLogComm is true */ cFile m_CommLogFile; @@ -252,7 +254,7 @@ protected: // Packet handlers while in the Status state (m_State == 1): void HandlePacketStatusPing (cByteBuffer & a_ByteBuffer); - void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer); + virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer); // Packet handlers while in the Login state (m_State == 2): void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer); @@ -279,6 +281,7 @@ protected: void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer); void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer); void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer); + void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer); void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer); @@ -306,3 +309,22 @@ protected: + +/** The version 5 lengthed protocol, used by 1.7.6 through 1.7.9. */ +class cProtocol176 : + public cProtocol172 +{ + typedef cProtocol172 super; + +public: + cProtocol176(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State); + + // cProtocol172 overrides: + virtual void SendPlayerSpawn(const cPlayer & a_Player) override; + virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; + +} ; + + + + diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 3f7d7b254..22dfe7c88 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -59,6 +59,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion) case PROTO_VERSION_1_6_3: return "1.6.3"; case PROTO_VERSION_1_6_4: return "1.6.4"; case PROTO_VERSION_1_7_2: return "1.7.2"; + case PROTO_VERSION_1_7_6: return "1.7.6"; } ASSERT(!"Unknown protocol version"); return Printf("Unknown protocol (%d)", a_ProtocolVersion); @@ -356,7 +357,7 @@ void cProtocolRecognizer::SendHealth(void) -void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) { ASSERT(m_Protocol != NULL); m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); @@ -396,6 +397,16 @@ void cProtocolRecognizer::SendLogin(const cPlayer & a_Player, const cWorld & a_W +void cProtocolRecognizer::SendLoginSuccess(void) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendLoginSuccess(); +} + + + + + void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) { ASSERT(m_Protocol != NULL); @@ -965,6 +976,18 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema m_Protocol = new cProtocol172(m_Client, ServerAddress, (UInt16)ServerPort, NextState); return true; } + case PROTO_VERSION_1_7_6: + { + AString ServerAddress; + short ServerPort; + UInt32 NextState; + m_Buffer.ReadVarUTF8String(ServerAddress); + m_Buffer.ReadBEShort(ServerPort); + m_Buffer.ReadVarInt(NextState); + m_Buffer.CommitRead(); + m_Protocol = new cProtocol176(m_Client, ServerAddress, (UInt16)ServerPort, NextState); + return true; + } } LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u)", m_Client->GetIPString().c_str(), ProtocolVersion @@ -980,6 +1003,7 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema void cProtocolRecognizer::SendLengthlessServerPing(void) { AString Reply; + cServer * Server = cRoot::Get()->GetServer(); switch (cRoot::Get()->GetPrimaryServerVersion()) { case PROTO_VERSION_1_2_5: @@ -987,11 +1011,11 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) { // http://wiki.vg/wiki/index.php?title=Protocol&oldid=3099#Server_List_Ping_.280xFE.29 Printf(Reply, "%s%s%i%s%i", - cRoot::Get()->GetServer()->GetDescription().c_str(), + Server->GetDescription().c_str(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetNumPlayers(), + Server->GetNumPlayers(), cChatColor::Delimiter.c_str(), - cRoot::Get()->GetServer()->GetMaxPlayers() + Server->GetMaxPlayers() ); break; } @@ -1021,9 +1045,9 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) // http://wiki.vg/wiki/index.php?title=Server_List_Ping&oldid=3100 AString NumPlayers; - Printf(NumPlayers, "%d", cRoot::Get()->GetServer()->GetNumPlayers()); + Printf(NumPlayers, "%d", Server->GetNumPlayers()); AString MaxPlayers; - Printf(MaxPlayers, "%d", cRoot::Get()->GetServer()->GetMaxPlayers()); + Printf(MaxPlayers, "%d", Server->GetMaxPlayers()); AString ProtocolVersionNum; Printf(ProtocolVersionNum, "%d", cRoot::Get()->GetPrimaryServerVersion()); @@ -1037,7 +1061,7 @@ void cProtocolRecognizer::SendLengthlessServerPing(void) Reply.push_back(0); Reply.append(ProtocolVersionTxt); Reply.push_back(0); - Reply.append(cRoot::Get()->GetServer()->GetDescription()); + Reply.append(Server->GetDescription()); Reply.push_back(0); Reply.append(NumPlayers); Reply.push_back(0); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 072d7c2d2..37f47379d 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -18,8 +18,8 @@ // Adjust these if a new protocol is added or an old one is removed: -#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4" -#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4" +#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9" +#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4, 5" @@ -50,6 +50,7 @@ public: // These will be kept "under" the next / latest, because the next and latest are only needed for previous protocols PROTO_VERSION_1_7_2 = 4, + PROTO_VERSION_1_7_6 = 5, } ; cProtocolRecognizer(cClientHandle * a_Client); @@ -90,6 +91,7 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; + virtual void SendLoginSuccess (void) override; virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override; virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override; virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; @@ -129,7 +131,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override; - virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; + virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/src/Root.cpp b/src/Root.cpp index ba4398b35..5d32bdd87 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -499,9 +499,9 @@ void cRoot::KickUser(int a_ClientID, const AString & a_Reason) -void cRoot::AuthenticateUser(int a_ClientID) +void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID) { - m_Server->AuthenticateUser(a_ClientID); + m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID); } diff --git a/src/Root.h b/src/Root.h index 4bbd7586f..d2a4d1eed 100644 --- a/src/Root.h +++ b/src/Root.h @@ -1,7 +1,7 @@ #pragma once -#include "Authenticator.h" +#include "Protocol/Authenticator.h" #include "HTTPServer/HTTPServer.h" #include "Defines.h" @@ -89,7 +89,7 @@ public: void KickUser(int a_ClientID, const AString & a_Reason); /// Called by cAuthenticator to auth the specified user - void AuthenticateUser(int a_ClientID); + void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID); /// Executes commands queued in the command queue void TickCommands(void); diff --git a/src/Server.cpp b/src/Server.cpp index d1e53bfff..bfb1b1cbb 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -190,7 +190,7 @@ void cServer::PlayerDestroying(const cPlayer * a_Player) bool cServer::InitServer(cIniFile & a_SettingsIni) { - m_Description = a_SettingsIni.GetValueSet("Server", "Description", "MCServer - in C++!").c_str(); + m_Description = a_SettingsIni.GetValueSet("Server", "Description", "MCServer - in C++!"); m_MaxPlayers = a_SettingsIni.GetValueSetI("Server", "MaxPlayers", 100); m_bIsHardcore = a_SettingsIni.GetValueSetB("Server", "HardcoreEnabled", false); m_PlayerCount = 0; @@ -275,7 +275,7 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) -int cServer::GetNumPlayers(void) +int cServer::GetNumPlayers(void) const { cCSLock Lock(m_CSPlayerCount); return m_PlayerCount; @@ -615,14 +615,14 @@ void cServer::KickUser(int a_ClientID, const AString & a_Reason) -void cServer::AuthenticateUser(int a_ClientID) +void cServer::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID) { cCSLock Lock(m_CSClients); for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) { if ((*itr)->GetUniqueID() == a_ClientID) { - (*itr)->Authenticate(); + (*itr)->Authenticate(a_Name, a_UUID); return; } } // for itr - m_Clients[] diff --git a/src/Server.h b/src/Server.h index b5280c59d..3d76c8ccf 100644 --- a/src/Server.h +++ b/src/Server.h @@ -23,7 +23,7 @@ #pragma warning(disable:4702) #endif -#include "Crypto.h" +#include "PolarSSL++/RsaPrivateKey.h" #ifdef _MSC_VER #pragma warning(pop) @@ -59,7 +59,7 @@ public: // tolua_export // Player counts: int GetMaxPlayers(void) const {return m_MaxPlayers; } - int GetNumPlayers(void); + int GetNumPlayers(void) const; void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } // Hardcore mode or not: @@ -83,7 +83,7 @@ public: // tolua_export void Shutdown(void); void KickUser(int a_ClientID, const AString & a_Reason); - void AuthenticateUser(int a_ClientID); // Called by cAuthenticator to auth the specified user + void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator to auth the specified user const AString & GetServerID(void) const { return m_ServerID; } // tolua_export @@ -109,7 +109,7 @@ public: // tolua_export /** Returns base64 encoded favicon data (obtained from favicon.png) */ const AString & GetFaviconData(void) const { return m_FaviconData; } - cRSAPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } + cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; } const AString & GetPublicKeyDER(void) const { return m_PublicKeyDER; } bool ShouldAuthenticate(void) const { return m_ShouldAuthenticate; } @@ -168,7 +168,7 @@ private: cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld cClientHandleList m_ClientsToRemove; ///< Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick() - cCriticalSection m_CSPlayerCount; ///< Locks the m_PlayerCount + mutable cCriticalSection m_CSPlayerCount; ///< Locks the m_PlayerCount int m_PlayerCount; ///< Number of players currently playing in the server cCriticalSection m_CSPlayerCountDiff; ///< Locks the m_PlayerCountDiff int m_PlayerCountDiff; ///< Adjustment to m_PlayerCount to be applied in the Tick thread @@ -182,7 +182,7 @@ private: bool m_bRestarting; /** The private key used for the assymetric encryption start in the protocols */ - cRSAPrivateKey m_PrivateKey; + cRsaPrivateKey m_PrivateKey; /** Public key for m_PrivateKey, ASN1-DER-encoded */ AString m_PublicKeyDER; 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/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 470dfc791..4fbfffd43 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -350,7 +350,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel { continue; } - BlockType = Neighbour->GetBlock(X, a_RelY + gCrossCoords[i].y, Z); + BlockType = Neighbour->GetBlock(X, a_RelY + gNeighborCoords[i].y, Z); if (!IsFuel(BlockType)) { diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index 03e94e791..e95af3a1c 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -119,7 +119,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re if (SpreadFurther && (NewMeta < 8)) { // Spread to the neighbors: - Spread(a_Chunk, a_RelX, a_RelY, a_RelZ, NewMeta); + SpreadXZ(a_Chunk, a_RelX, a_RelY, a_RelZ, NewMeta); } // Mark as processed: @@ -130,7 +130,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re -void cFloodyFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) +void cFloodyFluidSimulator::SpreadXZ(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) { SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, a_NewMeta); SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta); diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h index 632de3bb2..8e1be5e6b 100644 --- a/src/Simulator/FloodyFluidSimulator.h +++ b/src/Simulator/FloodyFluidSimulator.h @@ -48,16 +48,13 @@ protected: bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ); /** Checks if the specified block should harden (Water/Lava interaction) and if so, converts it to a suitable block. - * - * Returns whether the block was changed or not. - */ + Returns whether the block was changed or not. */ bool HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta); - /** Spread water to neighbors. - * - * May be overridden to provide more sophisticated algorithms. - */ - virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta); + /** Spread fluid to XZ neighbors. + The coords are of the block currently being processed; a_NewMeta is the new meta for the new fluid block. + Descendants may overridde to provide more sophisticated algorithms. */ + virtual void SpreadXZ(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta); } ; diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 7779573d7..4a84084d2 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -155,7 +155,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a Points.push_back(new Vector3i(a_X, a_Y, a_Z + 1)); Points.push_back(new Vector3i(a_X, a_Y, a_Z - 1)); - for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); it++) + for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); ++it) { Vector3i *Pos = (*it); char BlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z); diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 92659fab7..074063add 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -9,11 +9,13 @@ #include "../Entities/Pickup.h" #include "../Blocks/BlockTorch.h" #include "../Blocks/BlockDoor.h" +#include "../Blocks/BlockButton.h" +#include "../Blocks/BlockLever.h" #include "../Piston.h" - + cIncrementalRedstoneSimulator::cIncrementalRedstoneSimulator(cWorld & a_World) : super(a_World) @@ -69,18 +71,19 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, // Checking only when a block is changed, as opposed to every tick, also improves performance PoweredBlocksList * PoweredBlocks = a_Chunk->GetRedstoneSimulatorPoweredBlocksList(); - for (PoweredBlocksList::iterator itr = PoweredBlocks->begin(); itr != PoweredBlocks->end(); ++itr) + for (PoweredBlocksList::iterator itr = PoweredBlocks->begin(); itr != PoweredBlocks->end();) { if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { + ++itr; continue; } if (!IsPotentialSource(Block)) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list as it no longer connected to a source", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - PoweredBlocks->erase(itr); - break; + itr = PoweredBlocks->erase(itr); + continue; } else if ( // Changeable sources @@ -93,29 +96,10 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); - PoweredBlocks->erase(itr); - break; - } - else if (Block == E_BLOCK_DAYLIGHT_SENSOR) - { - if (!a_Chunk->IsLightValid()) - { - m_World.QueueLightChunk(a_Chunk->GetPosX(), a_Chunk->GetPosZ()); - break; - } - else - { - NIBBLETYPE SkyLight; - a_Chunk->UnboundedRelGetBlockSkyLight(RelX, itr->a_SourcePos.y + 1, RelZ, SkyLight); - - if (a_Chunk->GetTimeAlteredLight(SkyLight) <= 8) // Could use SkyLight - m_World.GetSkyDarkness(); - { - LOGD("cIncrementalRedstoneSimulator: Erased daylight sensor from powered blocks list due to insufficient light level"); - PoweredBlocks->erase(itr); - break; - } - } + itr = PoweredBlocks->erase(itr); + continue; } + ++itr; } LinkedBlocksList * LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); @@ -134,7 +118,9 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, // Things that can send power through a block but which depends on meta ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || - (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) + (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || + (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) || + (((Block == E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE) || (Block == E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE)) && (Meta == 0)) ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from linked powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); @@ -157,14 +143,14 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, SimulatedPlayerToggleableList * SimulatedPlayerToggleableBlocks = a_Chunk->GetRedstoneSimulatorSimulatedPlayerToggleableList(); for (SimulatedPlayerToggleableList::iterator itr = SimulatedPlayerToggleableBlocks->begin(); itr != SimulatedPlayerToggleableBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_RelBlockPos.Equals(Vector3i(RelX, a_BlockY, RelZ))) { continue; } if (!IsAllowedBlock(Block)) { - LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); + LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from toggleable simulated list as it is no longer redstone", itr->a_RelBlockPos.x, itr->a_RelBlockPos.y, itr->a_RelBlockPos.z); SimulatedPlayerToggleableBlocks->erase(itr); break; } @@ -173,7 +159,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, RepeatersDelayList * RepeatersDelayList = a_Chunk->GetRedstoneSimulatorRepeatersDelayList(); for (RepeatersDelayList::iterator itr = RepeatersDelayList->begin(); itr != RepeatersDelayList->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_RelBlockPos.Equals(Vector3i(RelX, a_BlockY, RelZ))) { continue; } @@ -239,9 +225,6 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int m_LinkedPoweredBlocks = a_Chunk->GetRedstoneSimulatorLinkedBlocksList(); m_Chunk = a_Chunk; - int BaseX = a_Chunk->GetPosX() * cChunkDef::Width; - int BaseZ = a_Chunk->GetPosZ() * cChunkDef::Width; - for (cRedstoneSimulatorChunkData::iterator dataitr = m_RedstoneSimulatorChunkData->begin(); dataitr != m_RedstoneSimulatorChunkData->end();) { if (dataitr->DataTwo) @@ -250,67 +233,65 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int continue; } - int a_X = BaseX + dataitr->x; - int a_Z = BaseZ + dataitr->z; switch (dataitr->Data) { - case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; - case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; - case E_BLOCK_FENCE_GATE: HandleFenceGate(a_X, dataitr->y, a_Z); break; - case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; - case E_BLOCK_TRAPDOOR: HandleTrapdoor(a_X, dataitr->y, a_Z); break; - case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; - case E_BLOCK_NOTE_BLOCK: HandleNoteBlock(a_X, dataitr->y, a_Z); break; - case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(a_X, dataitr->y, a_Z); break; - case E_BLOCK_COMMAND_BLOCK: HandleCommandBlock(a_X, dataitr->y, a_Z); break; + case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_LEVER: HandleRedstoneLever(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_FENCE_GATE: HandleFenceGate(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_TNT: HandleTNT(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_TRAPDOOR: HandleTrapdoor(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_NOTE_BLOCK: HandleNoteBlock(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_COMMAND_BLOCK: HandleCommandBlock(dataitr->x, dataitr->y, dataitr->z); break; case E_BLOCK_REDSTONE_TORCH_OFF: case E_BLOCK_REDSTONE_TORCH_ON: { - HandleRedstoneTorch(a_X, dataitr->y, a_Z, dataitr->Data); + HandleRedstoneTorch(dataitr->x, dataitr->y, dataitr->z, dataitr->Data); break; } case E_BLOCK_STONE_BUTTON: case E_BLOCK_WOODEN_BUTTON: { - HandleRedstoneButton(a_X, dataitr->y, a_Z, dataitr->Data); + HandleRedstoneButton(dataitr->x, dataitr->y, dataitr->z); break; } case E_BLOCK_REDSTONE_REPEATER_OFF: case E_BLOCK_REDSTONE_REPEATER_ON: { - HandleRedstoneRepeater(a_X, dataitr->y, a_Z, dataitr->Data); + HandleRedstoneRepeater(dataitr->x, dataitr->y, dataitr->z, dataitr->Data); break; } case E_BLOCK_PISTON: case E_BLOCK_STICKY_PISTON: { - HandlePiston(a_X, dataitr->y, a_Z); + HandlePiston(dataitr->x, dataitr->y, dataitr->z); break; } case E_BLOCK_REDSTONE_LAMP_OFF: case E_BLOCK_REDSTONE_LAMP_ON: { - HandleRedstoneLamp(a_X, dataitr->y, a_Z, dataitr->Data); + HandleRedstoneLamp(dataitr->x, dataitr->y, dataitr->z, dataitr->Data); break; } case E_BLOCK_DISPENSER: case E_BLOCK_DROPPER: { - HandleDropSpenser(a_X, dataitr->y, a_Z); + HandleDropSpenser(dataitr->x, dataitr->y, dataitr->z); break; } case E_BLOCK_WOODEN_DOOR: case E_BLOCK_IRON_DOOR: { - HandleDoor(a_X, dataitr->y, a_Z); + HandleDoor(dataitr->x, dataitr->y, dataitr->z); break; } case E_BLOCK_ACTIVATOR_RAIL: case E_BLOCK_DETECTOR_RAIL: case E_BLOCK_POWERED_RAIL: { - HandleRail(a_X, dataitr->y, a_Z, dataitr->Data); + HandleRail(dataitr->x, dataitr->y, dataitr->z, dataitr->Data); break; } case E_BLOCK_WOODEN_PRESSURE_PLATE: @@ -318,7 +299,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: { - HandlePressurePlate(a_X, dataitr->y, a_Z, dataitr->Data); + HandlePressurePlate(dataitr->x, dataitr->y, dataitr->z, dataitr->Data); break; } default: LOGD("Unhandled block (!) or unimplemented redstone block: %s", ItemToString(dataitr->Data).c_str()); break; @@ -360,7 +341,7 @@ void cIncrementalRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_Blo -void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState) { static const struct // Define which directions the torch can power { @@ -377,54 +358,58 @@ void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_Bloc if (a_MyState == E_BLOCK_REDSTONE_TORCH_ON) { // Check if the block the torch is on is powered - int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; - AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on + int X = a_RelBlockX; int Y = a_RelBlockY; int Z = a_RelBlockZ; + AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ)), true); // Inverse true to get the block torch is on if (AreCoordsDirectlyPowered(X, Y, Z)) { // There was a match, torch goes off - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ)); return; } // Torch still on, make all 4(X, Z) + 1(Y) sides powered for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - BLOCKTYPE Type = m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z); + BLOCKTYPE Type = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, Type)) + { + continue; + } if (i + 1 < ARRAYCOUNT(gCrossCoords)) // Sides of torch, not top (top is last) { if ( ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) && // Is it a mechanism or wire? Not block/other torch etc. - (!Vector3i(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z).Equals(Vector3i(X, Y, Z))) // CAN'T power block is that it is on + (!Vector3i(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z).Equals(Vector3i(X, Y, Z))) // CAN'T power block is that it is on ) { - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + SetBlockPowered(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, a_RelBlockX, a_RelBlockY, a_RelBlockZ); } } else { // Top side, power whatever is there, including blocks - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + SetBlockPowered(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, a_RelBlockX, a_RelBlockY, a_RelBlockZ); // Power all blocks surrounding block above torch - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_REDSTONE_TORCH_ON); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YP); } } - if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0x5) // Is torch standing on ground? If NOT (i.e. on wall), power block beneath + if (m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) != 0x5) // Is torch standing on ground? If NOT (i.e. on wall), power block beneath { - BLOCKTYPE Type = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + BLOCKTYPE Type = m_Chunk->GetBlock(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ); if ((IsMechanism(Type)) || (Type == E_BLOCK_REDSTONE_WIRE)) // Still can't make a normal block powered though! { - SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON); + SetBlockPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ); } } } else { // Check if the block the torch is on is powered - int X = a_BlockX; int Y = a_BlockY; int Z = a_BlockZ; - AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)), true); // Inverse true to get the block torch is on + int X = a_RelBlockX; int Y = a_RelBlockY; int Z = a_RelBlockZ; + AddFaceDirection(X, Y, Z, cBlockTorchHandler::MetaDataToDirection(m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ)), true); // Inverse true to get the block torch is on // See if off state torch can be turned on again if (AreCoordsDirectlyPowered(X, Y, Z)) @@ -433,7 +418,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_Bloc } // Block torch on not powered, can be turned on again! - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ)); } } @@ -441,28 +426,47 @@ void cIncrementalRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_Bloc -void cIncrementalRedstoneSimulator::HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleRedstoneBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); // Set self as powered + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ); // Set self as powered } -void cIncrementalRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleRedstoneLever(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - if (IsLeverOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) + NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + if (IsLeverOn(Meta)) { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_LEVER); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_LEVER); + NIBBLETYPE Dir = cBlockLeverHandler::BlockMetaDataToBlockFace(Meta); + switch (Dir) // Now, flip the direction into the type used by SetBlockLinkedPowered() + { + case BLOCK_FACE_YP: + case BLOCK_FACE_XP: + case BLOCK_FACE_ZP: + { + Dir--; + break; + } + case BLOCK_FACE_XM: + case BLOCK_FACE_ZM: + case BLOCK_FACE_YM: + { + Dir++; + break; + } + default: + { + ASSERT(!"Unhandled lever metadata!"); + return; + } + } + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Dir); } } @@ -470,27 +474,29 @@ void cIncrementalRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_Bloc -void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleFenceGate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; cChunkInterface ChunkInterface(m_World.GetChunkMap()); - NIBBLETYPE MetaData = ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE MetaData = ChunkInterface.GetBlockMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData | 0x4); - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData | 0x4); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true); } } else { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaData & 0xFFFFFFFB); - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData & 0xFFFFFFFB); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false); } } } @@ -499,18 +505,35 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_BlockX, int a_BlockY, -void cIncrementalRedstoneSimulator::HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) +void cIncrementalRedstoneSimulator::HandleRedstoneButton(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - if (IsButtonOn(m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ))) + NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + if (IsButtonOn(Meta)) { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockType); - - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YP, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, a_BlockType); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, a_BlockType); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + + NIBBLETYPE Dir = cBlockButtonHandler::BlockMetaDataToBlockFace(Meta); + switch (Dir) // Now, flip the direction into the type used by SetBlockLinkedPowered() + { + case BLOCK_FACE_XP: + case BLOCK_FACE_ZP: + { + Dir--; + break; + } + case BLOCK_FACE_XM: + case BLOCK_FACE_ZM: + { + Dir++; + break; + } + default: + { + ASSERT(!"Unhandled button metadata!"); + return; + } + } + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Dir); } } @@ -518,7 +541,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneButton(int a_BlockX, int a_Blo -void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { static const struct // Define which directions the wire can receive power from { @@ -552,128 +575,122 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block }; // Check to see if directly beside a power source - if (IsWirePowered(a_BlockX, a_BlockY, a_BlockZ)) + unsigned char MyPower; + if (!IsWirePowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 15); // Maximum power + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0); + m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + return; } - else + + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + + if (MyPower < 1) { - NIBBLETYPE MetaToSet = 0; - NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - int TimesMetaSmaller = 0, TimesFoundAWire = 0; + return; + } - for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through all directions to transfer or receive power + MyPower--; + + for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through all directions to transfer or receive power + { + if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... { - if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... + BLOCKTYPE Type = 0; + if (a_RelBlockY + 1 >= cChunkDef::Height) { - if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) // If there is something solid above us (wire cut off)... - { - continue; // We don't receive power from that wire - } + continue; } - else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, Type)) { - if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z))) - { - continue; - } + continue; } - - BLOCKTYPE SurroundType; - NIBBLETYPE SurroundMeta; - m_World.GetBlockTypeMeta(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, SurroundType, SurroundMeta); - - if (SurroundType == E_BLOCK_REDSTONE_WIRE) + if (cBlockInfo::IsSolid(Type)) // If there is something solid above us (wire cut off)... { - TimesFoundAWire++; - - if (SurroundMeta > 1) // Wires of power 1 or 0 cannot transfer power TO ME, don't bother checking - { - // Does surrounding wire have a higher power level than self? - // >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list - if (SurroundMeta >= MyMeta) - { - MetaToSet = SurroundMeta - 1; // To improve performance - } - } - - if (SurroundMeta < MyMeta) // Go through all surroundings to see if self power is larger than everyone else's - { - TimesMetaSmaller++; - } - } + continue; // We don't receive power from that wire + } + } + else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us + { + BLOCKTYPE Type = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY, a_RelBlockZ + gCrossCoords[i].z, Type)) + { + continue; + } + if (cBlockInfo::IsSolid(Type)) + { + continue; + } } - if ((TimesMetaSmaller == TimesFoundAWire) && (MyMeta != 0)) + BLOCKTYPE Type = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, Type)) { - // All surrounding metas were smaller - self must have been a wire that was - // transferring power to other wires around. - // However, self not directly powered anymore, so source must have been removed, - // therefore, self must be set to meta zero - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE, 0); // SetMeta & WakeUpSims doesn't seem to work here, so SetBlock - return; // No need to process block power sets because self not powered + continue; } - else if (MyMeta != MetaToSet) + if (Type == E_BLOCK_REDSTONE_WIRE) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); + SetBlockPowered(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); } } - if (m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) != 0) // A powered wire + for (size_t i = 0; i < ARRAYCOUNT(gSideCoords); i++) // Look for repeaters immediately surrounding self and try to power them { - for (size_t i = 0; i < ARRAYCOUNT(gSideCoords); i++) // Look for repeaters immediately surrounding self and try to power them + BLOCKTYPE Type = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + gSideCoords[i].x, a_RelBlockY + gSideCoords[i].y, a_RelBlockZ + gSideCoords[i].z, Type)) { - if (m_World.GetBlock(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z) == E_BLOCK_REDSTONE_REPEATER_OFF) - { - SetBlockPowered(a_BlockX + gSideCoords[i].x, a_BlockY + gSideCoords[i].y, a_BlockZ + gSideCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - } + continue; + } + if (Type == E_BLOCK_REDSTONE_REPEATER_OFF) + { + SetBlockPowered(a_RelBlockX + gSideCoords[i].x, a_RelBlockY + gSideCoords[i].y, a_RelBlockZ + gSideCoords[i].z, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); } + } - // Wire still powered, power blocks beneath - SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); + // Wire still powered, power blocks beneath + SetBlockPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YM, MyPower); - switch (GetWireDirection(a_BlockX, a_BlockY, a_BlockZ)) + switch (GetWireDirection(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) + { + case REDSTONE_NONE: { - case REDSTONE_NONE: - { - SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); + SetBlockPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetBlockPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_YM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_X_POS: - { - SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_X_NEG: - { - SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_Z_POS: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_WIRE); - break; - } - case REDSTONE_Z_NEG: - { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_WIRE); - break; - } + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XM, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XP, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZM, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZP, MyPower); + break; + } + case REDSTONE_X_POS: + { + SetBlockPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XP, MyPower); + break; + } + case REDSTONE_X_NEG: + { + SetBlockPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XM, MyPower); + break; + } + case REDSTONE_Z_POS: + { + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZP, MyPower); + break; + } + case REDSTONE_Z_NEG: + { + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MyPower); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZM, MyPower); + break; } } } @@ -682,25 +699,49 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block -void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState) { - NIBBLETYPE a_Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + /* Repeater Orientation Mini Guide: + =================================== - bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on - bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered + | + | Z Axis + V - if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on - { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); - } - else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on + X Axis ----> + + Repeater directions, values from a cWorld::GetBlockMeta(a_RelBlockX , a_RelBlockY, a_RelBlockZ) lookup: + + East (Right) (X+): 0x1 + West (Left) (X-): 0x3 + North (Up) (Z-): 0x2 + South (Down) (Z+): 0x0 + // TODO: Add E_META_XXX enum entries for all meta values and update project with them + + Sun rises from East (X+) + + */ + + // Create a variable holding my meta to avoid multiple lookups. + NIBBLETYPE a_Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + bool IsOn = (a_MyState == E_BLOCK_REDSTONE_REPEATER_ON); + + if (!IsRepeaterLocked(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_Meta)) // If we're locked, change nothing. Otherwise: { - QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); + bool IsSelfPowered = IsRepeaterPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_Meta); + if (IsSelfPowered && !IsOn) // Queue a power change if powered, but not on and not locked. + { + QueueRepeaterPowerChange(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_Meta, true); + } + else if (!IsSelfPowered && IsOn) // Queue a power change if unpowered, on, and not locked. + { + QueueRepeaterPowerChange(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_Meta, false); + } } for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_RelBlockPos.Equals(Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ))) { continue; } @@ -711,33 +752,33 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B { if (!IsOn) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // For performance + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // For performance } switch (a_Meta & 0x3) // We only want the direction (bottom) bits { case 0x0: { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_REDSTONE_REPEATER_ON); + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZM); break; } case 0x1: { - SetBlockPowered(a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XP, E_BLOCK_REDSTONE_REPEATER_ON); + SetBlockPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XP); break; } case 0x2: { - SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_REDSTONE_REPEATER_ON); + SetBlockPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_ZP); break; } case 0x3: { - SetBlockPowered(a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON); - SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_XM, E_BLOCK_REDSTONE_REPEATER_ON); + SetBlockPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_XM); break; } } @@ -750,7 +791,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B { if (IsOn) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); } m_RepeatersDelayList->erase(itr); // We can remove off repeaters which don't need further updating return; @@ -761,7 +802,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B // Apparently, incrementing ticks only works reliably here, and not in SimChunk; // With a world with lots of redstone, the repeaters simply do not delay // I am confounded to say why. Perhaps optimisation failure. - LOGD("Incremented a repeater @ {%i %i %i} | Elapsed ticks: %i | Target delay: %i", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z, itr->a_ElapsedTicks, itr->a_DelayTicks); + LOGD("Incremented a repeater @ {%i %i %i} | Elapsed ticks: %i | Target delay: %i", itr->a_RelBlockPos.x, itr->a_RelBlockPos.y, itr->a_RelBlockPos.z, itr->a_ElapsedTicks, itr->a_DelayTicks); itr->a_ElapsedTicks++; } } @@ -771,16 +812,19 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B -void cIncrementalRedstoneSimulator::HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandlePiston(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { cPiston Piston(&m_World); - if (IsPistonPowered(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x7)) // We only want the bottom three bits (4th controls extended-ness) + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + + if (IsPistonPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x7)) // We only want the bottom three bits (4th controls extended-ness) { - Piston.ExtendPiston(a_BlockX, a_BlockY, a_BlockZ); + Piston.ExtendPiston(BlockX, a_RelBlockY, BlockZ); } else { - Piston.RetractPiston(a_BlockX, a_BlockY, a_BlockZ); + Piston.RetractPiston(BlockX, a_RelBlockY, BlockZ); } } @@ -788,7 +832,7 @@ void cIncrementalRedstoneSimulator::HandlePiston(int a_BlockX, int a_BlockY, int -void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { class cSetPowerToDropSpenser : public cDropSpenserCallback @@ -802,29 +846,31 @@ void cIncrementalRedstoneSimulator::HandleDropSpenser(int a_BlockX, int a_BlockY a_DropSpenser->SetRedstonePower(m_IsPowered); return false; } - } DrSpSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); + } DrSpSP (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)); - m_World.DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, DrSpSP); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + m_Chunk->DoWithDropSpenserAt(BlockX, a_RelBlockY, BlockZ, DrSpSP); } -void cIncrementalRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState) +void cIncrementalRedstoneSimulator::HandleRedstoneLamp(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState) { if (a_MyState == E_BLOCK_REDSTONE_LAMP_OFF) { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); } } else { - if (!AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + if (!AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); } } } @@ -833,13 +879,16 @@ void cIncrementalRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_Block -void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleTNT(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom + m_Chunk->BroadcastSoundEffect("game.tnt.primed", BlockX * 8, a_RelBlockY * 8, BlockZ * 8, 0.5f, 0.6f); + m_Chunk->SetBlock(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_BLOCK_AIR, 0); + m_World.SpawnPrimedTNT(BlockX + 0.5, a_RelBlockY + 0.5, BlockZ + 0.5); // 80 ticks to boom } } @@ -847,26 +896,29 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_ -void cIncrementalRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleDoor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true)) { cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true); } } else { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false)) { cChunkInterface ChunkInterface(m_World.GetChunkMap()); - cBlockDoorHandler::ChangeDoor(ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); - m_World.BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + cBlockDoorHandler::ChangeDoor(ChunkInterface, a_RelBlockX, a_RelBlockY, a_RelBlockZ); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false); } } } @@ -875,7 +927,7 @@ void cIncrementalRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a -void cIncrementalRedstoneSimulator::HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleCommandBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { class cSetPowerToCommandBlock : public cCommandBlockCallback @@ -889,37 +941,39 @@ void cIncrementalRedstoneSimulator::HandleCommandBlock(int a_BlockX, int a_Block a_CommandBlock->SetRedstonePower(m_IsPowered); return false; } - } CmdBlockSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); + } CmdBlockSP (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)); - m_World.DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, CmdBlockSP); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + m_Chunk->DoWithCommandBlockAt(BlockX, a_RelBlockY, BlockZ, CmdBlockSP); } -void cIncrementalRedstoneSimulator::HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) +void cIncrementalRedstoneSimulator::HandleRail(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType) { switch (a_MyType) { case E_BLOCK_DETECTOR_RAIL: { - if ((m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x08) == 0x08) + if ((m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x08) == 0x08) { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_MyType); } break; } case E_BLOCK_ACTIVATOR_RAIL: case E_BLOCK_POWERED_RAIL: { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) | 0x08); } else { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x07); } break; } @@ -931,22 +985,25 @@ void cIncrementalRedstoneSimulator::HandleRail(int a_BlockX, int a_BlockY, int a -void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + + if (AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ)) { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true)) { - m_World.SetTrapdoorOpen(a_BlockX, a_BlockY, a_BlockZ, true); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + m_World.SetTrapdoorOpen(BlockX, a_RelBlockY, BlockZ, true); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true); } } else { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false)) { - m_World.SetTrapdoorOpen(a_BlockX, a_BlockY, a_BlockZ, false); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + m_World.SetTrapdoorOpen(BlockX, a_RelBlockY, BlockZ, false); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false); } } } @@ -955,13 +1012,13 @@ void cIncrementalRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, i -void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - bool m_bAreCoordsPowered = AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ); + bool m_bAreCoordsPowered = AreCoordsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); if (m_bAreCoordsPowered) { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true)) { class cSetPowerToNoteBlock : public cNoteBlockCallback @@ -980,15 +1037,17 @@ void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, } } NoteBlockSP(m_bAreCoordsPowered); - m_World.DoWithNoteBlockAt(a_BlockX, a_BlockY, a_BlockZ, NoteBlockSP); - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + m_Chunk->DoWithNoteBlockAt(BlockX, a_RelBlockY, BlockZ, NoteBlockSP); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true); } } else { - if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false)) { - SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false); } } } @@ -997,10 +1056,10 @@ void cIncrementalRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, -void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ) +void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { int a_ChunkX, a_ChunkZ; - cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, a_ChunkX, a_ChunkZ); + cChunkDef::BlockToChunk(a_RelBlockX, a_RelBlockZ, a_ChunkX, a_ChunkZ); if (!m_World.IsChunkLighted(a_ChunkX, a_ChunkZ)) { @@ -1008,10 +1067,12 @@ void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_Blo } else { - NIBBLETYPE SkyLight = m_World.GetBlockSkyLight(a_BlockX, a_BlockY + 1, a_BlockZ) - m_World.GetSkyDarkness(); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + NIBBLETYPE SkyLight = m_Chunk->GetTimeAlteredLight(m_World.GetBlockSkyLight(BlockX, a_RelBlockY + 1, BlockZ)); if (SkyLight > 8) { - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DAYLIGHT_SENSOR); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } } } @@ -1020,38 +1081,175 @@ void cIncrementalRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_Blo -void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType) +void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType) { + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + switch (a_MyType) { case E_BLOCK_STONE_PRESSURE_PLATE: { // MCS feature - stone pressure plates can only be triggered by players :D - cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(a_BlockX + 0.5f, (float)a_BlockY, a_BlockZ + 0.5f), 0.5f, false); + cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(BlockX + 0.5f, (float)a_RelBlockY, BlockZ + 0.5f), 0.7f, false); if (a_Player != NULL) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_STONE_PRESSURE_PLATE); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0x1); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YM, a_MyType); } else { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); - m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0x0); + m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); } break; } case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + { + class cPressurePlateCallback : + public cEntityCallback + { + public: + cPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ) : + m_NumberOfEntities(0), + m_X(a_BlockX), + m_Y(a_BlockY), + m_Z(a_BlockZ) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + Vector3f EntityPos = a_Entity->GetPosition(); + Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); + double Distance = (EntityPos - BlockPos).Length(); + + if (Distance <= 0.7) + { + m_NumberOfEntities++; + } + return false; + } + + bool GetPowerLevel(unsigned char & a_PowerLevel) const + { + a_PowerLevel = std::min(m_NumberOfEntities, MAX_POWER_LEVEL); + return (a_PowerLevel > 0); + } + + protected: + int m_NumberOfEntities; + + int m_X; + int m_Y; + int m_Z; + }; + + cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); + m_World.ForEachEntity(PressurePlateCallback); + + unsigned char Power; + NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + if (PressurePlateCallback.GetPowerLevel(Power)) + { + if (Meta == E_META_PRESSURE_PLATE_RAISED) + { + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.5F); + } + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_DEPRESSED); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Power); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YM, a_MyType); + } + else + { + if (Meta == E_META_PRESSURE_PLATE_DEPRESSED) + { + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); + } + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); + m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + } + + break; + } case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: + { + class cPressurePlateCallback : + public cEntityCallback + { + public: + cPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ) : + m_NumberOfEntities(0), + m_X(a_BlockX), + m_Y(a_BlockY), + m_Z(a_BlockZ) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + Vector3f EntityPos = a_Entity->GetPosition(); + Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); + double Distance = (EntityPos - BlockPos).Length(); + + if (Distance <= 0.7) + { + m_NumberOfEntities++; + } + return false; + } + + bool GetPowerLevel(unsigned char & a_PowerLevel) const + { + a_PowerLevel = std::min((int)ceil(m_NumberOfEntities / (float)10), MAX_POWER_LEVEL); + return (a_PowerLevel > 0); + } + + protected: + int m_NumberOfEntities; + + int m_X; + int m_Y; + int m_Z; + }; + + cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); + m_World.ForEachEntity(PressurePlateCallback); + + unsigned char Power; + NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + if (PressurePlateCallback.GetPowerLevel(Power)) + { + if (Meta == E_META_PRESSURE_PLATE_RAISED) + { + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.5F); + } + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_DEPRESSED); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Power); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YM, a_MyType); + } + else + { + if (Meta == E_META_PRESSURE_PLATE_DEPRESSED) + { + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); + } + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); + m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + } + + break; + } case E_BLOCK_WOODEN_PRESSURE_PLATE: { class cPressurePlateCallback : public cEntityCallback { public: - cPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - m_Entity(NULL), - m_World(a_World), + cPressurePlateCallback(int a_BlockX, int a_BlockY, int a_BlockZ) : + m_FoundEntity(false), m_X(a_BlockX), m_Y(a_BlockY), m_Z(a_BlockZ) @@ -1066,7 +1264,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc if (Distance <= 0.7) { - m_Entity = a_Entity; + m_FoundEntity = true; return true; // Break out, we only need to know for plates that at least one entity is on top } return false; @@ -1074,45 +1272,47 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc bool FoundEntity(void) const { - return m_Entity != NULL; + return m_FoundEntity; } protected: - cEntity * m_Entity; - cWorld * m_World; + bool m_FoundEntity; int m_X; int m_Y; int m_Z; } ; - cPressurePlateCallback PressurePlateCallback(a_BlockX, a_BlockY, a_BlockZ, &m_World); + cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); m_World.ForEachEntity(PressurePlateCallback); - NIBBLETYPE Meta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); if (PressurePlateCallback.FoundEntity()) { - if (Meta == 0x0) + if (Meta == E_META_PRESSURE_PLATE_RAISED) { - m_World.BroadcastSoundEffect("random.click", (int) ((a_BlockX + 0.5) * 8.0), (int) ((a_BlockY + 0.1) * 8.0), (int) ((a_BlockZ + 0.5) * 8.0), 0.3F, 0.5F); + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.5F); } - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x1); - SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, a_MyType); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_DEPRESSED); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + SetDirectionLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, BLOCK_FACE_YM, a_MyType); } else { - if (Meta == 0x1) + if (Meta == E_META_PRESSURE_PLATE_DEPRESSED) { - m_World.BroadcastSoundEffect("random.click", (int) ((a_BlockX + 0.5) * 8.0), (int) ((a_BlockY + 0.1) * 8.0), (int) ((a_BlockZ + 0.5) * 8.0), 0.3F, 0.6F); + m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); } - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); - m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); + m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); } break; } default: + { LOGD("Unimplemented pressure plate type %s in cRedstoneSimulator", ItemToFullString(a_MyType).c_str()); break; + } } } @@ -1120,11 +1320,15 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_Bloc -bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ) +bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) // Check powered list + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + + PoweredBlocksList * Powered = m_Chunk->GetNeighborChunk(BlockX, BlockZ)->GetRedstoneSimulatorPoweredBlocksList(); // Torches want to access neighbour's data when on a wall + for (PoweredBlocksList::const_iterator itr = Powered->begin(); itr != Powered->end(); ++itr) // Check powered list { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { return true; } @@ -1136,11 +1340,14 @@ bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a -bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ) +bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) // Check linked powered list { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { return true; } @@ -1151,36 +1358,39 @@ bool cIncrementalRedstoneSimulator::AreCoordsLinkedPowered(int a_BlockX, int a_B - -bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) +// IsRepeaterPowered tests if a repeater should be powered by testing for power sources behind the repeater. +// It takes the coordinates of the repeater the the meta value. +bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta) { // Repeaters cannot be powered by any face except their back; verify that this is true for a source + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { continue; } - switch (a_Meta) + switch (a_Meta & 0x3) { case 0x0: { // Flip the coords to check the back of the repeater - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ + 1))) { return true; } break; } case 0x1: { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(BlockX - 1, a_RelBlockY, BlockZ))) { return true; } break; } case 0x2: { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ - 1))) { return true; } break; } case 0x3: { - if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(BlockX + 1, a_RelBlockY, BlockZ))) { return true; } break; } } @@ -1188,28 +1398,28 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { continue; } - switch (a_Meta) + switch (a_Meta & 0x3) { case 0x0: { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ + 1))) { return true; } break; } case 0x1: { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(BlockX - 1, a_RelBlockY, BlockZ))) { return true; } break; } case 0x2: { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ - 1))) { return true; } break; } case 0x3: { - if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(BlockX + 1, a_RelBlockY, BlockZ))) { return true; } break; } } @@ -1220,43 +1430,101 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY -bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) + +bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta) +{ + switch (a_Meta & 0x3) // We only want the 'direction' part of our metadata + { + // If the repeater is looking up or down (If parallel to the Z axis) + case 0x0: + case 0x2: + { + // Check if eastern(right) neighbor is a powered on repeater who is facing us. + BLOCKTYPE Block = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, Block) && (Block == E_BLOCK_REDSTONE_REPEATER_ON)) // Is right neighbor a powered repeater? + { + NIBBLETYPE OtherRepeaterDir = m_Chunk->GetMeta(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ) & 0x3; + if (OtherRepeaterDir == 0x3) { return true; } // If so, I am latched/locked. + } + + // Check if western(left) neighbor is a powered on repeater who is facing us. + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, Block) && (Block == E_BLOCK_REDSTONE_REPEATER_ON)) + { + NIBBLETYPE OtherRepeaterDir = m_Chunk->GetMeta(a_RelBlockX -1, a_RelBlockY, a_RelBlockZ) & 0x3; + if (OtherRepeaterDir == 0x1) { return true; } // If so, I am latched/locked. + } + + break; + } + + // If the repeater is looking left or right (If parallel to the x axis) + case 0x1: + case 0x3: + { + // Check if southern(down) neighbor is a powered on repeater who is facing us. + BLOCKTYPE Block = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, Block) && (Block == E_BLOCK_REDSTONE_REPEATER_ON)) + { + NIBBLETYPE OtherRepeaterDir = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1) & 0x3; + if (OtherRepeaterDir == 0x0) { return true; } // If so, am latched/locked. + } + + // Check if northern(up) neighbor is a powered on repeater who is facing us. + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, Block) && (Block == E_BLOCK_REDSTONE_REPEATER_ON)) + { + NIBBLETYPE OtherRepeaterDir = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1) & 0x3; + if (OtherRepeaterDir == 0x2) { return true; } // If so, I am latched/locked. + } + + break; + } + } + + return false; // None of the checks succeeded, I am not a locked repeater. +} + + + + +bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta) { // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement - int OldX = a_BlockX, OldY = a_BlockY, OldZ = a_BlockZ; + int OldX = a_RelBlockX, OldY = a_RelBlockY, OldZ = a_RelBlockZ; eBlockFace Face = cPiston::MetaDataToDirection(a_Meta); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { continue; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); + AddFaceDirection(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Face); - if (!itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_SourcePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { return true; } - a_BlockX = OldX; - a_BlockY = OldY; - a_BlockZ = OldZ; + a_RelBlockX = OldX; + a_RelBlockY = OldY; + a_RelBlockZ = OldZ; } for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { continue; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, Face); + AddFaceDirection(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Face); - if (!itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_MiddlePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { return true; } - a_BlockX = OldX; - a_BlockY = OldY; - a_BlockZ = OldZ; + a_RelBlockX = OldX; + a_RelBlockY = OldY; + a_RelBlockZ = OldZ; } return false; // Source was in front of the piston's front face } @@ -1264,39 +1532,42 @@ bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, -bool cIncrementalRedstoneSimulator::IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ) +bool cIncrementalRedstoneSimulator::IsWirePowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char & a_PowerLevel) { - for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) - { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + a_PowerLevel = 0; + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; - if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) // Check powered list + { + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { - return true; + continue; } + a_PowerLevel = std::max(a_PowerLevel, itr->a_PowerLevel); } - for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) // Check linked powered list { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } - - if (m_World.GetBlock(itr->a_SourcePos) != E_BLOCK_REDSTONE_WIRE) + if (!itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ))) { - return true; + continue; } + a_PowerLevel = std::max(a_PowerLevel, itr->a_PowerLevel); } - return false; // Source was in front of the piston's front face + + return (a_PowerLevel != 0); // Source was in front of the piston's front face } -bool cIncrementalRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered) +bool cIncrementalRedstoneSimulator::AreCoordsSimulated(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, bool IsCurrentStatePowered) { for (SimulatedPlayerToggleableList::const_iterator itr = m_SimulatedPlayerToggleableBlocks->begin(); itr != m_SimulatedPlayerToggleableBlocks->end(); ++itr) { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (itr->a_RelBlockPos.Equals(Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ))) { if (itr->WasLastStatePowered != IsCurrentStatePowered) // Was the last power state different to the current? { @@ -1315,79 +1586,98 @@ bool cIncrementalRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_Block -void cIncrementalRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceType) +void cIncrementalRedstoneSimulator::SetDirectionLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, char a_Direction, unsigned char a_PowerLevel) { + BLOCKTYPE MiddleBlock = 0; switch (a_Direction) { case BLOCK_FACE_XM: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX - 2, a_BlockY, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX - 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX - 2, a_RelBlockY, a_RelBlockZ, a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } case BLOCK_FACE_XP: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX + 2, a_BlockY, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX + 1, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX + 2, a_RelBlockY, a_RelBlockZ, a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } case BLOCK_FACE_YM: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX, a_BlockY - 2, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY - 2, a_RelBlockZ, a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } case BLOCK_FACE_YP: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX, a_BlockY + 2, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY + 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY + 2, a_RelBlockZ, a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } case BLOCK_FACE_ZM: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ - 2, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ - 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 2, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } case BLOCK_FACE_ZP: { - BLOCKTYPE MiddleBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, MiddleBlock)) + { + return; + } - SetBlockLinkedPowered(a_BlockX, a_BlockY, a_BlockZ + 2, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX + 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX - 1, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY + 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); - SetBlockLinkedPowered(a_BlockX, a_BlockY - 1, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ + 1, a_BlockX, a_BlockY, a_BlockZ, a_SourceType, MiddleBlock); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 2, a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY + 1, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); + SetBlockLinkedPowered(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, a_RelBlockX, a_RelBlockY, a_RelBlockZ, MiddleBlock, a_PowerLevel); break; } @@ -1403,7 +1693,7 @@ void cIncrementalRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int -void cIncrementalRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock) +void cIncrementalRedstoneSimulator::SetAllDirsAsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char a_PowerLevel) { static const struct { @@ -1411,16 +1701,16 @@ void cIncrementalRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_Bloc } gCrossCoords[] = { { 1, 0, 0 }, - {-1, 0, 0 }, + { -1, 0, 0 }, { 0, 0, 1 }, - { 0, 0,-1 }, + { 0, 0, -1 }, { 0, 1, 0 }, - { 0,-1, 0 } + { 0, -1, 0 } }; for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) // Loop through struct to power all directions { - SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, a_SourceBlock); + SetBlockPowered(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY + gCrossCoords[i].y, a_RelBlockZ + gCrossCoords[i].z, a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_PowerLevel); } } @@ -1428,32 +1718,55 @@ void cIncrementalRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_Bloc -void cIncrementalRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock) +void cIncrementalRedstoneSimulator::SetBlockPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, unsigned char a_PowerLevel) { - BLOCKTYPE Block = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + int SourceX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelSourceX; + int SourceZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelSourceZ; + + BLOCKTYPE Block = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ, Block)) + { + return; + } if (Block == E_BLOCK_AIR) { // Don't set air, fixes some bugs (wires powering themselves) return; } - PoweredBlocksList * Powered = m_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ)->GetRedstoneSimulatorPoweredBlocksList(); + PoweredBlocksList * Powered = m_Chunk->GetNeighborChunk(BlockX, BlockZ)->GetRedstoneSimulatorPoweredBlocksList(); + for (PoweredBlocksList::iterator itr = Powered->begin(); itr != Powered->end(); ++itr) // Check powered list + { + if ( + itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ)) && + itr->a_SourcePos.Equals(Vector3i(SourceX, a_RelSourceY, SourceZ)) + ) + { + // Check for duplicates, update power level, don't add a new listing + itr->a_PowerLevel = a_PowerLevel; + return; + } + } - for (PoweredBlocksList::const_iterator itr = Powered->begin(); itr != Powered->end(); ++itr) // Check powered list + PoweredBlocksList * OtherPowered = m_Chunk->GetNeighborChunk(SourceX, SourceZ)->GetRedstoneSimulatorPoweredBlocksList(); + for (PoweredBlocksList::const_iterator itr = OtherPowered->begin(); itr != OtherPowered->end(); ++itr) // Check powered list { if ( - itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && - itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) + itr->a_BlockPos.Equals(Vector3i(SourceX, a_RelSourceY, SourceZ)) && + itr->a_SourcePos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ)) ) { - // Check for duplicates + // Powered wires try to power their source - don't let them! return; } } sPoweredBlocks RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); + RC.a_BlockPos = Vector3i(BlockX, a_RelBlockY, BlockZ); + RC.a_SourcePos = Vector3i(SourceX, a_RelSourceY, SourceZ); + RC.a_PowerLevel = a_PowerLevel; Powered->push_back(RC); } @@ -1462,42 +1775,58 @@ void cIncrementalRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( - int a_BlockX, int a_BlockY, int a_BlockZ, - int a_MiddleX, int a_MiddleY, int a_MiddleZ, - int a_SourceX, int a_SourceY, int a_SourceZ, - BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddleBlock -) + int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, + int a_RelMiddleX, int a_RelMiddleY, int a_RelMiddleZ, + int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, + BLOCKTYPE a_MiddleBlock, unsigned char a_PowerLevel + ) { - BLOCKTYPE DestBlock = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); + int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; + int BlockZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelBlockZ; + int MiddleX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelMiddleX; + int MiddleZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelMiddleZ; + int SourceX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelSourceX; + int SourceZ = (m_Chunk->GetPosZ() * cChunkDef::Width) + a_RelSourceZ; + + BLOCKTYPE DestBlock = 0; + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ, DestBlock)) + { + return; + } if (DestBlock == E_BLOCK_AIR) { // Don't set air, fixes some bugs (wires powering themselves) return; } + if ((DestBlock == E_BLOCK_REDSTONE_WIRE) && (m_Chunk->GetBlock(a_RelSourceX, a_RelSourceY, a_RelSourceZ) == E_BLOCK_REDSTONE_WIRE)) + { + return; + } if (!IsViableMiddleBlock(a_MiddleBlock)) { return; } - LinkedBlocksList * Linked = m_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ)->GetRedstoneSimulatorLinkedBlocksList(); - - for (LinkedBlocksList::const_iterator itr = Linked->begin(); itr != Linked->end(); ++itr) // Check linked powered list + LinkedBlocksList * Linked = m_Chunk->GetNeighborChunk(BlockX, BlockZ)->GetRedstoneSimulatorLinkedBlocksList(); + for (LinkedBlocksList::iterator itr = Linked->begin(); itr != Linked->end(); ++itr) // Check linked powered list { if ( - itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && - itr->a_MiddlePos.Equals(Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ)) && - itr->a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) - ) + itr->a_BlockPos.Equals(Vector3i(BlockX, a_RelBlockY, BlockZ)) && + itr->a_MiddlePos.Equals(Vector3i(MiddleX, a_RelMiddleY, MiddleZ)) && + itr->a_SourcePos.Equals(Vector3i(SourceX, a_RelSourceY, SourceZ)) + ) { - // Check for duplicates + // Check for duplicates, update power level, don't add a new listing + itr->a_PowerLevel = a_PowerLevel; return; } } sLinkedPoweredBlocks RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_MiddlePos = Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ); - RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); + RC.a_BlockPos = Vector3i(BlockX, a_RelBlockY, BlockZ); + RC.a_MiddlePos = Vector3i(MiddleX, a_RelMiddleY, MiddleZ); + RC.a_SourcePos = Vector3i(SourceX, a_RelSourceY, SourceZ); + RC.a_PowerLevel = a_PowerLevel; Linked->push_back(RC); } @@ -1505,11 +1834,11 @@ void cIncrementalRedstoneSimulator::SetBlockLinkedPowered( -void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered) +void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, bool WasLastStatePowered) { for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks->begin(); itr != m_SimulatedPlayerToggleableBlocks->end(); ++itr) { - if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (!itr->a_RelBlockPos.Equals(Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ))) { continue; } @@ -1529,7 +1858,7 @@ void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_Bl // We have arrive here; no block must be in list - add one sSimulatedPlayerToggleableList RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_RelBlockPos = Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ); RC.WasLastStatePowered = WasLastStatePowered; m_SimulatedPlayerToggleableBlocks->push_back(RC); } @@ -1538,11 +1867,11 @@ void cIncrementalRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_Bl -void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn) +void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn) { for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); ++itr) { - if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (itr->a_RelBlockPos.Equals(Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ))) { if (ShouldPowerOn == itr->ShouldPowerOn) // We are queued already for the same thing, don't replace entry { @@ -1559,10 +1888,10 @@ void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a // Self not in list, add self to list sRepeatersDelayList RC; - RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_RelBlockPos = Vector3i(a_RelBlockX, a_RelBlockY, a_RelBlockZ); // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) - // * 2 because apparently, MCS ticks are way faster than vanilla ticks, so repeater aren't noticeably delayed + // * 2 because in MCS, 1 redstone tick = 1 world tick, but in Vanilla, 1 redstone tick = 2 world ticks, and we need to maintain compatibility RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + 1) * 2; RC.a_ElapsedTicks = 0; @@ -1575,52 +1904,64 @@ void cIncrementalRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a -cIncrementalRedstoneSimulator::eRedstoneDirection cIncrementalRedstoneSimulator::GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ) +cIncrementalRedstoneSimulator::eRedstoneDirection cIncrementalRedstoneSimulator::GetWireDirection(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { int Dir = REDSTONE_NONE; - BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); - if (IsPotentialSource(NegX)) + BLOCKTYPE NegX = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX - 1, a_RelBlockY, a_RelBlockZ, NegX)) { - Dir |= (REDSTONE_X_POS); + if (IsPotentialSource(NegX)) + { + Dir |= (REDSTONE_X_POS); + } } - BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); - if (IsPotentialSource(PosX)) + BLOCKTYPE PosX = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + 1, a_RelBlockY, a_RelBlockZ, PosX)) { - Dir |= (REDSTONE_X_NEG); + if (IsPotentialSource(PosX)) + { + Dir |= (REDSTONE_X_NEG); + } } - BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); - if (IsPotentialSource(NegZ)) + BLOCKTYPE NegZ = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ - 1, NegZ)) { - if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner - { - Dir ^= REDSTONE_X_POS; - Dir |= REDSTONE_X_NEG; - } - if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner + if (IsPotentialSource(NegZ)) { - Dir ^= REDSTONE_X_NEG; - Dir |= REDSTONE_X_POS; + if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner + { + Dir ^= REDSTONE_X_POS; + Dir |= REDSTONE_X_NEG; + } + if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner + { + Dir ^= REDSTONE_X_NEG; + Dir |= REDSTONE_X_POS; + } + Dir |= REDSTONE_Z_POS; } - Dir |= REDSTONE_Z_POS; } - BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); - if (IsPotentialSource(PosZ)) + BLOCKTYPE PosZ = 0; + if (m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY, a_RelBlockZ + 1, PosZ)) { - if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner + if (IsPotentialSource(PosZ)) { - Dir ^= REDSTONE_X_POS; - Dir |= REDSTONE_X_NEG; - } - if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner - { - Dir ^= REDSTONE_X_NEG; - Dir |= REDSTONE_X_POS; + if ((Dir & REDSTONE_X_POS) && !(Dir & REDSTONE_X_NEG)) // corner + { + Dir ^= REDSTONE_X_POS; + Dir |= REDSTONE_X_NEG; + } + if ((Dir & REDSTONE_X_NEG) && !(Dir & REDSTONE_X_POS)) // corner + { + Dir ^= REDSTONE_X_NEG; + Dir |= REDSTONE_X_POS; + } + Dir |= REDSTONE_Z_NEG; } - Dir |= REDSTONE_Z_NEG; } return (eRedstoneDirection)Dir; } @@ -1638,12 +1979,3 @@ bool cIncrementalRedstoneSimulator::IsLeverOn(NIBBLETYPE a_BlockMeta) - -bool cIncrementalRedstoneSimulator::IsButtonOn(NIBBLETYPE a_BlockMeta) -{ - return IsLeverOn(a_BlockMeta); -} - - - - diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 8b7363366..233a3d408 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -36,31 +36,35 @@ public: private: + #define MAX_POWER_LEVEL 15 + struct sPoweredBlocks // Define structure of the directly powered blocks list { Vector3i a_BlockPos; // Position of powered block Vector3i a_SourcePos; // Position of source powering the block at a_BlockPos + unsigned char a_PowerLevel; }; struct sLinkedPoweredBlocks // Define structure of the indirectly powered blocks list (i.e. repeaters powering through a block to the block at the other side) { Vector3i a_BlockPos; - Vector3i a_MiddlePos; + Vector3i a_MiddlePos; // Position of block that is betwixt a source and the destination Vector3i a_SourcePos; + unsigned char a_PowerLevel; }; - struct sSimulatedPlayerToggleableList + struct sSimulatedPlayerToggleableList // Define structure of the list containing simulate-on-update blocks (such as trapdoors that respond once to a block update, and can be toggled by a player) { - Vector3i a_BlockPos; - bool WasLastStatePowered; + Vector3i a_RelBlockPos; + bool WasLastStatePowered; // Was the last state powered or not? Determines whether a source update has happened and if I should resimulate }; - struct sRepeatersDelayList + struct sRepeatersDelayList // Define structure of list containing repeaters' delay states { - Vector3i a_BlockPos; - unsigned char a_DelayTicks; - unsigned char a_ElapsedTicks; - bool ShouldPowerOn; + Vector3i a_RelBlockPos; + unsigned char a_DelayTicks; // For how many ticks should the repeater delay + unsigned char a_ElapsedTicks; // How much of the previous has been elapsed? + bool ShouldPowerOn; // What happens when the delay time is fulfilled? }; public: @@ -87,85 +91,86 @@ private: /* ====== SOURCES ====== */ /** Handles the redstone torch */ - void HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + void HandleRedstoneTorch(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState); /** Handles the redstone block */ - void HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleRedstoneBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles levers */ - void HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleRedstoneLever(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles buttons */ - void HandleRedstoneButton(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType); + void HandleRedstoneButton(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles daylight sensors */ - void HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleDaylightSensor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles pressure plates */ - void HandlePressurePlate(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); + void HandlePressurePlate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType); /* ==================== */ /* ====== CARRIERS ====== */ /** Handles redstone wire */ - void HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleRedstoneWire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles repeaters */ - void HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + void HandleRedstoneRepeater(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState); /* ====================== */ /* ====== DEVICES ====== */ /** Handles pistons */ - void HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandlePiston(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles dispensers and droppers */ - void HandleDropSpenser(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleDropSpenser(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles TNT (exploding) */ - void HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleTNT(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles redstone lamps */ - void HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyState); + void HandleRedstoneLamp(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyState); /** Handles doords */ - void HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleDoor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles command blocks */ - void HandleCommandBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleCommandBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles activator, detector, and powered rails */ - void HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_MyType); + void HandleRail(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType); /** Handles trapdoors */ - void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleTrapdoor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles fence gates */ - void HandleFenceGate(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleFenceGate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles noteblocks */ - void HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + void HandleNoteBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ===================== */ /* ====== Helper functions ====== */ /** Marks a block as powered */ - void SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock); + void SetBlockPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Marks a block as being powered through another block */ - void SetBlockLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MiddleX, int a_MiddleY, int a_MiddleZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddeBlock); + void SetBlockLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, int a_RelMiddleX, int a_RelMiddleY, int a_RelMiddleZ, int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, BLOCKTYPE a_MiddeBlock, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Marks a block as simulated, who should not be simulated further unless their power state changes, to accomodate a player manually toggling the block without triggering the simulator toggling it back */ - void SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered); + void SetPlayerToggleableBlockAsSimulated(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, bool WasLastStatePowered); /** Marks the second block in a direction as linked powered */ - void SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceBlock); + void SetDirectionLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, char a_Direction, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Marks all blocks immediately surrounding a coordinate as powered */ - void SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_SourceBlock); + void SetAllDirsAsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char a_PowerLevel = MAX_POWER_LEVEL); /** Queues a repeater to be powered or unpowered */ - void QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); + void QueueRepeaterPowerChange(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta, bool ShouldPowerOn); /** Returns if a coordinate is powered or linked powered */ - bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { return AreCoordsDirectlyPowered(a_BlockX, a_BlockY, a_BlockZ) || AreCoordsLinkedPowered(a_BlockX, a_BlockY, a_BlockZ); } + bool AreCoordsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { return AreCoordsDirectlyPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ) || AreCoordsLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); } /** Returns if a coordinate is in the directly powered blocks list */ - bool AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + bool AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Returns if a coordinate is in the indirectly powered blocks list */ - bool AreCoordsLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + bool AreCoordsLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Returns if a coordinate was marked as simulated (for blocks toggleable by players) */ - bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); + bool AreCoordsSimulated(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, bool IsCurrentStatePowered); /** Returns if a repeater is powered */ - bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + bool IsRepeaterPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta); + /** Returns if a repeater is locked */ + bool IsRepeaterLocked(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta); /** Returns if a piston is powered */ - bool IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); + bool IsPistonPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, NIBBLETYPE a_Meta); /** Returns if a wire is powered - The only diffence between this and a normal AreCoordsPowered is that this function checks for a wire powering another wire - */ - bool IsWirePowered(int a_BlockX, int a_BlockY, int a_BlockZ); + The only diffence between this and a normal AreCoordsPowered is that this function checks for a wire powering another wire */ + bool IsWirePowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, unsigned char & a_PowerLevel); /** Returns if lever metadata marks it as emitting power */ bool IsLeverOn(NIBBLETYPE a_BlockMeta); /** Returns if button metadata marks it as emitting power */ - bool IsButtonOn(NIBBLETYPE a_BlockMeta); + bool IsButtonOn(NIBBLETYPE a_BlockMeta) { return IsLeverOn(a_BlockMeta); } /* ============================== */ /* ====== Misc Functions ====== */ diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index f305ba61a..c4f57c86a 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -254,6 +254,10 @@ void cSandSimulator::FinishFalling( { // Rematerialize the material here: a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_FallingBlockType, a_FallingBlockMeta); + if (a_FallingBlockType == E_BLOCK_ANVIL) + { + a_World->BroadcastSoundParticleEffect(1022, a_BlockX, a_BlockY, a_BlockZ, 0); + } return; } diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp index 78aff9d68..18d9b07e1 100644 --- a/src/Simulator/VanillaFluidSimulator.cpp +++ b/src/Simulator/VanillaFluidSimulator.cpp @@ -35,14 +35,16 @@ cVanillaFluidSimulator::cVanillaFluidSimulator( -void cVanillaFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) +void cVanillaFluidSimulator::SpreadXZ(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) { + // Calculate the distance to the nearest "hole" in each direction: int Cost[4]; Cost[0] = CalculateFlowCost(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, X_PLUS); Cost[1] = CalculateFlowCost(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, X_MINUS); Cost[2] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, Z_PLUS); Cost[3] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, Z_MINUS); + // Find the minimum distance: int MinCost = InfiniteCost; for (unsigned int i = 0; i < ARRAYCOUNT(Cost); ++i) { @@ -52,6 +54,7 @@ void cVanillaFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, in } } + // Spread in all directions where the distance matches the minimum: if (Cost[0] == MinCost) { SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta); @@ -86,7 +89,10 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int { return Cost; } - if (!IsPassableForFluid(BlockType) && !IsBlockLiquid(BlockType)) + if ( + !IsPassableForFluid(BlockType) || // The block cannot be passed by the liquid ... + (IsAllowedBlock(BlockType) && (BlockMeta == 0)) // ... or if it is liquid, it is a source block + ) { return Cost; } diff --git a/src/Simulator/VanillaFluidSimulator.h b/src/Simulator/VanillaFluidSimulator.h index a9ea98b5a..89a56ca14 100644 --- a/src/Simulator/VanillaFluidSimulator.h +++ b/src/Simulator/VanillaFluidSimulator.h @@ -30,7 +30,7 @@ public: protected: // cFloodyFluidSimulator overrides: - virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) override; + virtual void SpreadXZ(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) override; /** Recursively calculates the minimum number of blocks needed to descend a level. */ int CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, Direction a_Dir, unsigned a_Iteration = 0); diff --git a/src/StackWalker.cpp b/src/StackWalker.cpp index b4f8ed8c7..b608d69e6 100644 --- a/src/StackWalker.cpp +++ b/src/StackWalker.cpp @@ -935,7 +935,8 @@ BOOL StackWalker::LoadModules() break; } } // for (search for path separator...) - if (strlen(szTemp) > 0) + + if (szTemp[0] != '\0') // If szTemp is not empty (Note: This is more efficient than using strlen) { strcat_s(szSymPath, nSymPathLen, szTemp); strcat_s(szSymPath, nSymPathLen, ";"); diff --git a/src/Statistics.cpp b/src/Statistics.cpp new file mode 100644 index 000000000..2c980d98e --- /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] = { + // The order must match the order of enum eStatistic + + // 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..540df38cc --- /dev/null +++ b/src/Statistics.h @@ -0,0 +1,116 @@ + +// Statistics.h + + + + +#pragma once + + + + +enum eStatistic +{ + // The order must match the order of cStatInfo::ms_Info + + 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]; +}; + + + diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 6da6b2ad7..be42430a5 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -219,6 +219,10 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int return false; } + if ((pos.y < 0) || (pos.y >= cChunkDef::Height)) + { + return false; + } BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // Block is counted as a collision if we are not doing a line of sight and it is solid, // or if the block is not air and not water. That way mobs can still see underwater. @@ -226,7 +230,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); - if(Normal > 0) + if (Normal > 0) { HitNormal = m_NormalTable[Normal-1]; } 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/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 88977e005..fcf5f6f6b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -13,6 +13,8 @@ #include "Window.h" #include "../CraftingRecipes.h" #include "../Root.h" +#include "../FastRandom.h" +#include "../BlockArea.h" @@ -145,6 +147,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA FreeSlots = 0; } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; + Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -167,7 +170,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA { m_ParentWindow.BroadcastWholeWindow(); } - } @@ -242,7 +244,7 @@ void cSlotArea::OnPlayerRemoved(cPlayer & a_Player) -void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) { for (int i = 0; i < m_NumSlots; i++) { @@ -262,7 +264,7 @@ void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ { NumFit = a_ItemStack.m_ItemCount; } - if (a_Apply) + if (a_ShouldApply) { cItem NewSlot(a_ItemStack); NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; @@ -483,6 +485,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) // Get the current recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); + const cItem & Result = Recipe.GetResult(); cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); @@ -490,16 +493,16 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) // If possible, craft: if (DraggingItem.IsEmpty()) { - DraggingItem = Recipe.GetResult(); + DraggingItem = Result; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } - else if (DraggingItem.IsEqual(Recipe.GetResult())) + else if (DraggingItem.IsEqual(Result)) { - cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType); - if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize()) + cItemHandler * Handler = ItemHandler(Result.m_ItemType); + if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Handler->GetMaxStackSize()) { - DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount; + DraggingItem.m_ItemCount += Result.m_ItemCount; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } @@ -593,6 +596,704 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaAnvil: + +cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : + cSlotAreaTemporary(3, a_ParentWindow), + m_MaximumCost(0) +{ +} + + + + + +void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + if (a_SlotNum != 2) + { + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + UpdateResult(a_Player); + return; + } + + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + if (a_ClickAction == caDblClick) + { + return; + } + + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + 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 (Slot.IsEmpty()) + { + return; + } + if (!DraggingItem.IsEmpty()) + { + if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize()))) + { + return; + } + } + + if (!CanTakeResultItem(a_Player)) + { + return; + } + + cItem NewItem = cItem(Slot); + NewItem.m_ItemCount += DraggingItem.m_ItemCount; + + Slot.Empty(); + DraggingItem.Empty(); + SetSlot(a_SlotNum, a_Player, Slot); + + DraggingItem = NewItem; + OnTakeResult(a_Player); + + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } +} + + + + + +void cSlotAreaAnvil::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) +{ + if (a_SlotNum != 2) + { + super::ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + UpdateResult(a_Player); + return; + } + + // Make a copy of the slot, distribute it among the other areas, then update the slot to contain the leftover: + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + + if (Slot.IsEmpty() || !CanTakeResultItem(a_Player)) + { + return; + } + + m_ParentWindow.DistributeStack(Slot, a_Player, this, true); + if (Slot.IsEmpty()) + { + Slot.Empty(); + OnTakeResult(a_Player); + } + SetSlot(a_SlotNum, a_Player, Slot); + + // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: + m_ParentWindow.BroadcastWholeWindow(); +} + + + + + +void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) +{ + for (int i = 0; i < 2; i++) + { + const cItem * Slot = GetSlot(i, a_Player); + if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots)) + { + // Different items + continue; + } + int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + if (NumFit <= 0) + { + // Full stack already + continue; + } + if (NumFit > a_ItemStack.m_ItemCount) + { + NumFit = a_ItemStack.m_ItemCount; + } + if (a_ShouldApply) + { + cItem NewSlot(a_ItemStack); + NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; + SetSlot(i, a_Player, NewSlot); + } + a_ItemStack.m_ItemCount -= NumFit; + if (a_ItemStack.IsEmpty()) + { + UpdateResult(a_Player); + return; + } + } // for i - Slots + UpdateResult(a_Player); +} + + + + + +void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) +{ + if (!a_Player.IsGameModeCreative()) + { + a_Player.DeltaExperience(cPlayer::XpForLevel(m_MaximumCost)); + } + SetSlot(0, a_Player, cItem()); + + if (m_StackSizeToBeUsedInRepair > 0) + { + const cItem * Item = GetSlot(1, a_Player); + if (!Item->IsEmpty() && (Item->m_ItemCount > m_StackSizeToBeUsedInRepair)) + { + cItem NewSecondItem(*Item); + NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair; + SetSlot(1, a_Player, NewSecondItem); + } + else + { + SetSlot(1, a_Player, cItem()); + } + } + else + { + SetSlot(1, a_Player, cItem()); + } + m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); + + m_MaximumCost = 0; + ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", NULL); + + int PosX, PosY, PosZ; + ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + + BLOCKTYPE Block; + NIBBLETYPE BlockMeta; + a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta); + + cFastRandom Random; + if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F)) + { + NIBBLETYPE Orientation = BlockMeta & 0x3; + NIBBLETYPE AnvilDamage = BlockMeta >> 2; + ++AnvilDamage; + + if (AnvilDamage > 2) + { + // Anvil will break + a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, (NIBBLETYPE)0); + a_Player.GetWorld()->BroadcastSoundParticleEffect(1020, PosX, PosY, PosZ, 0); + a_Player.CloseWindow(false); + } + else + { + a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, Orientation | (AnvilDamage << 2)); + a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); + } + } + else + { + a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); + } +} + + + + + +bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player) +{ + return ( + ( + a_Player.IsGameModeCreative() || // Is the player in gamemode? + (a_Player.GetXpLevel() >= m_MaximumCost) // or the player have enough exp? + ) && + (!GetSlot(2, a_Player)->IsEmpty()) && // Is a item in the result slot? + (m_MaximumCost > 0) // When no maximum cost is set, the item isn't set from the UpdateResult() method and can't be a valid enchanting result. + ); +} + + + + + +void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player) +{ + TossItems(a_Player, 0, 2); + super::OnPlayerRemoved(a_Player); +} + + + + + +void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) +{ + cItem Input(*GetSlot(0, a_Player)); + cItem SecondInput(*GetSlot(1, a_Player)); + cItem Output(*GetSlot(2, a_Player)); + + if (Input.IsEmpty() && !Output.IsEmpty()) + { + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + m_MaximumCost = 0; + m_StackSizeToBeUsedInRepair = 0; + int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost(); + int NeedExp = 0; + if (!SecondInput.IsEmpty()) + { + RepairCost += cItemHandler::GetItemHandler(SecondInput)->GetRepairCost(); + if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithRawMaterial(SecondInput.m_ItemType)) + { + // Tool and armor repair with special item (iron / gold / diamond / ...) + int DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); + if (DamageDiff < 0) + { + // No enchantment + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + int x = 0; + while ((DamageDiff > 0) && (x < SecondInput.m_ItemCount)) + { + Input.m_ItemDamage -= DamageDiff; + NeedExp += std::max(1, DamageDiff / 100) + Input.m_Enchantments.Count(); + DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); + + ++x; + } + m_StackSizeToBeUsedInRepair = x; + } + else + { + // Tool and armor repair with two tools / armors + if (!Input.IsSameType(SecondInput) || !Input.IsDamageable()) + { + // No enchantment + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + int FirstDamageDiff = Input.GetMaxDamage() - Input.m_ItemDamage; + int SecondDamageDiff = SecondInput.GetMaxDamage() - SecondInput.m_ItemDamage; + int Damage = SecondDamageDiff + Input.GetMaxDamage() * 12 / 100; + + int NewItemDamage = Input.GetMaxDamage() - (FirstDamageDiff + Damage); + if (NewItemDamage > 0) + { + NewItemDamage = 0; + } + + if (NewItemDamage < Input.m_ItemDamage) + { + Input.m_ItemDamage = NewItemDamage; + NeedExp += std::max(1, Damage / 100); + } + + // TODO: Add enchantments. + } + } + + int NameChangeExp = 0; + const AString & RepairedItemName = ((cAnvilWindow*)&m_ParentWindow)->GetRepairedItemName(); + if (RepairedItemName.empty()) + { + // Remove custom name + if (!Input.m_CustomName.empty()) + { + NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5); + NeedExp += NameChangeExp; + Input.m_CustomName = ""; + } + } + else if (RepairedItemName != Input.m_CustomName) + { + // Change custom name + NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5); + NeedExp += NameChangeExp; + + if (!Input.m_CustomName.empty()) + { + RepairCost += NameChangeExp / 2; + } + + Input.m_CustomName = RepairedItemName; + } + + // TODO: Add enchantment exp cost. + + m_MaximumCost = RepairCost + NeedExp; + + if (NeedExp < 0) + { + Input.Empty(); + } + + if (NameChangeExp == NeedExp && NameChangeExp > 0 && m_MaximumCost >= 40) + { + m_MaximumCost = 39; + } + if (m_MaximumCost >= 40 && !a_Player.IsGameModeCreative()) + { + Input.Empty(); + } + + /* TODO: Add repair cost to cItem and not ItemHandler. This is required for this function! + if (!Input.IsEmpty()) + { + RepairCost = max(cItemHandler::GetItemHandler(Input)->GetRepairCost(), cItemHandler::GetItemHandler(SecondInput)->GetRepairCost()); + if (!Input.m_CustomName.empty()) + { + RepairCost -= 9; + } + RepairCost = max(RepairCost, 0); + RepairCost += 2; + }*/ + + SetSlot(2, a_Player, Input); + m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); +} + + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnchanting: + +cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) : + cSlotAreaTemporary(1, a_ParentWindow) +{ + a_ParentWindow.m_SlotArea = this; +} + + + + + +void cSlotAreaEnchanting::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; + } + + switch (a_ClickAction) + { + case caShiftLeftClick: + case caShiftRightClick: + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + + case caDblClick: + { + DblClicked(a_Player, a_SlotNum); + return; + } + default: + { + break; + } + } + + 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(); + switch (a_ClickAction) + { + case caRightClick: + { + // Right-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (Slot.IsEmpty()) + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1)) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + break; + } + + case caLeftClick: + { + // Left-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (DraggingItem.IsEqual(Slot)) + { + // Do nothing + break; + } + + if (!Slot.IsEmpty()) + { + if (DraggingItem.m_ItemCount == 1) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + } + else + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + break; + } + default: + { + LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); + m_ParentWindow.BroadcastWholeWindow(); + return; + } + } // switch (a_ClickAction + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } + UpdateResult(a_Player); +} + + + + + +void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum) +{ + cItem & Dragging = a_Player.GetDraggingItem(); + if ((!Dragging.IsEmpty()) || (a_SlotNum != 0)) + { + return; + } + + cItem Item = *GetSlot(0, a_Player); + if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false)) + { + m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true); + } +} + + + + + +void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +{ + const cItem * Slot = GetSlot(0, a_Player); + if (!Slot->IsEmpty()) + { + return; + } + + if (a_Apply) + { + SetSlot(0, a_Player, a_ItemStack.CopyOne()); + } + a_ItemStack.m_ItemCount -= 1; + if (a_ItemStack.m_ItemCount <= 0) + { + a_ItemStack.Empty(); + } + + UpdateResult(a_Player); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + + super::OnPlayerRemoved(a_Player); +} + + + + + +void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) +{ + cItem Item = *GetSlot(0, a_Player); + + if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty()) + { + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); + } + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) + { + int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); + + cFastRandom Random; + int base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); + int topSlot = std::max(base / 3, 1); + int middleSlot = (base * 2) / 3 + 1; + int bottomSlot = std::max(base, Bookshelves * 2); + + m_ParentWindow.SetProperty(0, topSlot, a_Player); + m_ParentWindow.SetProperty(1, middleSlot, a_Player); + m_ParentWindow.SetProperty(2, bottomSlot, a_Player); + } + else + { + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); + } +} + + + + + +int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) +{ + int PosX, PosY, PosZ; + ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + + int Bookshelves = 0; + cBlockArea Area; + Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); + + static const struct + { + int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won't be counted + } CheckCoords[] = + { + { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} + { 0, 0, 1, 1, 0, 1 }, // Bookcase at {0, 0, 1}, air at {1, 0, 1} + { 0, 0, 2, 1, 0, 2 }, // Bookcase at {0, 0, 2}, air at {1, 0, 2} + { 0, 0, 3, 1, 0, 3 }, // Bookcase at {0, 0, 3}, air at {1, 0, 3} + { 0, 0, 4, 1, 0, 3 }, // Bookcase at {0, 0, 4}, air at {1, 0, 3} + { 1, 0, 4, 1, 0, 3 }, // Bookcase at {1, 0, 4}, air at {1, 0, 3} + { 2, 0, 4, 2, 0, 3 }, // Bookcase at {2, 0, 4}, air at {2, 0, 3} + { 3, 0, 4, 3, 0, 3 }, // Bookcase at {3, 0, 4}, air at {3, 0, 3} + { 4, 0, 4, 3, 0, 3 }, // Bookcase at {4, 0, 4}, air at {3, 0, 3} + { 4, 0, 3, 3, 0, 3 }, // Bookcase at {4, 0, 3}, air at {3, 0, 3} + { 4, 0, 2, 3, 0, 2 }, // Bookcase at {4, 0, 2}, air at {3, 0, 2} + { 4, 0, 1, 3, 0, 1 }, // Bookcase at {4, 0, 1}, air at {3, 0, 1} + { 4, 0, 0, 3, 0, 1 }, // Bookcase at {4, 0, 0}, air at {3, 0, 1} + { 3, 0, 0, 3, 0, 1 }, // Bookcase at {3, 0, 0}, air at {3, 0, 1} + { 2, 0, 0, 2, 0, 1 }, // Bookcase at {2, 0, 0}, air at {2, 0, 1} + { 1, 0, 0, 1, 0, 1 }, // Bookcase at {1, 0, 0}, air at {1, 0, 1} + + { 0, 1, 0, 1, 1, 1 }, // Bookcase at {0, 1, 0}, air at {1, 1, 1} + { 0, 1, 1, 1, 1, 1 }, // Bookcase at {0, 1, 1}, air at {1, 1, 1} + { 0, 1, 2, 1, 1, 2 }, // Bookcase at {0, 1, 2}, air at {1, 1, 2} + { 0, 1, 3, 1, 1, 3 }, // Bookcase at {0, 1, 3}, air at {1, 1, 3} + { 0, 1, 4, 1, 1, 3 }, // Bookcase at {0, 1, 4}, air at {1, 1, 3} + { 1, 1, 4, 1, 1, 3 }, // Bookcase at {1, 1, 4}, air at {1, 1, 3} + { 2, 1, 4, 2, 1, 3 }, // Bookcase at {2, 1, 4}, air at {2, 1, 3} + { 3, 1, 4, 3, 1, 3 }, // Bookcase at {3, 1, 4}, air at {3, 1, 3} + { 4, 1, 4, 3, 1, 3 }, // Bookcase at {4, 1, 4}, air at {3, 1, 3} + { 4, 1, 3, 3, 1, 3 }, // Bookcase at {4, 1, 3}, air at {3, 1, 3} + { 4, 1, 2, 3, 1, 2 }, // Bookcase at {4, 1, 2}, air at {3, 1, 2} + { 4, 1, 1, 3, 1, 1 }, // Bookcase at {4, 1, 1}, air at {3, 1, 1} + { 4, 1, 0, 3, 1, 1 }, // Bookcase at {4, 1, 0}, air at {3, 1, 1} + { 3, 1, 0, 3, 1, 1 }, // Bookcase at {3, 1, 0}, air at {3, 1, 1} + { 2, 1, 0, 2, 1, 1 }, // Bookcase at {2, 1, 0}, air at {2, 1, 1} + { 1, 1, 0, 1, 1, 1 }, // Bookcase at {1, 1, 0}, air at {1, 1, 1} + }; + + for (size_t i = 0; i < ARRAYCOUNT(CheckCoords); i++) + { + if ( + (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot + (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place + ) + { + Bookshelves++; + } + } // for i - CheckCoords + + return Bookshelves; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow) : @@ -787,6 +1488,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 25b367cff..4da6a672f 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -9,6 +9,7 @@ #pragma once #include "../Inventory.h" +#include "Window.h" @@ -19,6 +20,8 @@ class cDropSpenserEntity; class cEnderChestEntity; class cFurnaceEntity; class cCraftingRecipe; +class cEnchantingWindow; +class cWorld; @@ -66,7 +69,7 @@ public: /// If a_CollectFullStacks is false, slots with full stacks are skipped while collecting. /// Returns true if full stack has been collected in a_Dragging, false if there's space remaining to fill. virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks); - + protected: int m_NumSlots; cWindow & m_ParentWindow; @@ -143,8 +146,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); } ; @@ -252,6 +260,71 @@ protected: +class cSlotAreaAnvil : + public cSlotAreaTemporary +{ + typedef cSlotAreaTemporary super; + +public: + cSlotAreaAnvil(cAnvilWindow & a_ParentWindow); + + // cSlotArea overrides: + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) override; + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + + // cSlotAreaTemporary overrides: + virtual void OnPlayerRemoved(cPlayer & a_Player) override; + + /** Can the player take the item from the slot? */ + bool CanTakeResultItem(cPlayer & a_Player); + + /** This function will call, when the player take the item from the slot. */ + void OnTakeResult(cPlayer & a_Player); + + /** Handles a click in the item slot. */ + void UpdateResult(cPlayer & a_Player); + +protected: + /** The maximum cost of repairing/renaming in the anvil. */ + int m_MaximumCost; + + /** The stack size of the second item where was used for repair */ + char m_StackSizeToBeUsedInRepair; +} ; + + + + + +class cSlotAreaEnchanting : + public cSlotAreaTemporary +{ + typedef cSlotAreaTemporary super; + +public: + cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow); + + // cSlotArea overrides: + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void DblClicked(cPlayer & a_Player, int a_SlotNum) override; + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + + // cSlotAreaTemporary overrides: + virtual void OnPlayerRemoved(cPlayer & a_Player) override; + + /* Get the count of bookshelves who stand in the near of the enchanting table */ + int GetBookshelvesCount(cWorld * a_World); + +protected: + /** Handles a click in the item slot. */ + void UpdateResult(cPlayer & a_Player); +}; + + + + + class cSlotAreaChest : public cSlotArea { diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index aae7b99a3..4991f0147 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -805,6 +805,111 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cAnvilWindow: + +cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : + cWindow(wtAnvil, "Repair"), + m_RepairedItemName(""), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) +{ + m_AnvilSlotArea = new cSlotAreaAnvil(*this); + m_SlotAreas.push_back(m_AnvilSlotArea); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); +} + + + + + +void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player) +{ + m_RepairedItemName = a_Name; + + if (a_Player != NULL) + { + m_AnvilSlotArea->UpdateResult(*a_Player); + } +} + + + + + +void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) +{ + a_PosX = m_BlockX; + a_PosY = m_BlockY; + a_PosZ = m_BlockZ; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEnchantingWindow: + +cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : + cWindow(wtEnchantment, "Enchant"), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) +{ + m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); +} + + + + + +void cEnchantingWindow::SetProperty(int a_Property, int a_Value) +{ + m_PropertyValue[a_Property] = a_Value; + + super::SetProperty(a_Property, a_Value); +} + + + + + +void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +{ + m_PropertyValue[a_Property] = a_Value; + + super::SetProperty(a_Property, a_Value, a_Player); +} + + + + + +int cEnchantingWindow::GetPropertyValue(int a_Property) +{ + return m_PropertyValue[a_Property]; +} + + + + + +void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) +{ + a_PosX = m_BlockX; + a_PosY = m_BlockY; + a_PosZ = m_BlockZ; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cChestWindow: cChestWindow::cChestWindow(cChestEntity * a_Chest) : diff --git a/src/UI/Window.h b/src/UI/Window.h index 030182888..542dccb88 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -24,6 +24,7 @@ class cEnderChestEntity; class cFurnaceEntity; class cHopperEntity; class cSlotArea; +class cSlotAreaAnvil; class cWorld; typedef std::list<cPlayer *> cPlayerList; @@ -136,11 +137,11 @@ public: void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; } /// Sends the UpdateWindowProperty (0x69) packet to all clients of the window - void SetProperty(int a_Property, int a_Value); + virtual void SetProperty(int a_Property, int a_Value); /// Sends the UpdateWindowPropert(0x69) packet to the specified player - void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); - + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); + // tolua_end void OwnerDestroyed(void); @@ -165,7 +166,7 @@ public: /// Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative to a_SlotArea void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum); - + protected: cSlotAreas m_SlotAreas; @@ -231,6 +232,58 @@ public: +class cAnvilWindow : + public cWindow +{ + typedef cWindow super; +public: + cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ); + + /** Gets the repaired item name. */ + AString GetRepairedItemName(void) const { return m_RepairedItemName; } + + /** Set the repaired item name. */ + void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player); + + /** Gets the Position from the Anvil */ + void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + +protected: + cSlotAreaAnvil * m_AnvilSlotArea; + AString m_RepairedItemName; + int m_BlockX, m_BlockY, m_BlockZ; +} ; + + + + + +class cEnchantingWindow : + public cWindow +{ + typedef cWindow super; +public: + cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player) override; + virtual void SetProperty(int a_Property, int a_Value) override; + + /** Return the Value of a Property */ + int GetPropertyValue(int a_Property); + + /** Get the Position from the Enchantment Table */ + void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + + cSlotArea * m_SlotArea; + +protected: + int m_PropertyValue[3]; + int m_BlockX, m_BlockY, m_BlockZ; +}; + + + + + class cFurnaceWindow : public cWindow { diff --git a/src/Vector3.h b/src/Vector3.h index a00e14508..fed776018 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -40,7 +40,6 @@ public: Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {} // tolua_begin - inline void Set(T a_x, T a_y, T a_z) { x = a_x; @@ -105,13 +104,18 @@ public: inline bool Equals(const Vector3<T> & a_Rhs) const { - return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z; + // Perform a bitwise comparison of the contents - we want to know whether this object is exactly equal + // To perform EPS-based comparison, use the EqualsEps() function + return ( + (memcmp(&x, &a_Rhs.x, sizeof(x)) == 0) && + (memcmp(&y, &a_Rhs.y, sizeof(y)) == 0) && + (memcmp(&z, &a_Rhs.z, sizeof(z)) == 0) + ); } - - inline bool operator < (const Vector3<T> & a_Rhs) + + inline bool EqualsEps(const Vector3<T> & a_Rhs, T a_Eps) const { - // return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ? - return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z); + return (Abs(x - a_Rhs.x) < a_Eps) && (Abs(y - a_Rhs.y) < a_Eps) && (Abs(z - a_Rhs.z) < a_Eps); } inline void Move(T a_X, T a_Y, T a_Z) @@ -130,6 +134,16 @@ public: // tolua_end + inline bool operator != (const Vector3<T> & a_Rhs) const + { + return !Equals(a_Rhs); + } + + inline bool operator == (const Vector3<T> & a_Rhs) const + { + return Equals(a_Rhs); + } + inline void operator += (const Vector3<T> & a_Rhs) { x += a_Rhs.x; @@ -158,8 +172,16 @@ public: z *= a_v; } - // tolua_begin + inline Vector3<T> & operator = (const Vector3<T> & a_Rhs) + { + x = a_Rhs.x; + y = a_Rhs.y; + z = a_Rhs.z; + return *this; + } + // tolua_begin + inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const { return Vector3<T>( @@ -212,7 +234,7 @@ public: */ inline double LineCoeffToXYPlane(const Vector3<T> & a_OtherEnd, T a_Z) const { - if (abs(z - a_OtherEnd.z) < EPS) + if (Abs(z - a_OtherEnd.z) < EPS) { return NO_INTERSECTION; } @@ -227,7 +249,7 @@ public: */ inline double LineCoeffToXZPlane(const Vector3<T> & a_OtherEnd, T a_Y) const { - if (abs(y - a_OtherEnd.y) < EPS) + if (Abs(y - a_OtherEnd.y) < EPS) { return NO_INTERSECTION; } @@ -242,7 +264,7 @@ public: */ inline double LineCoeffToYZPlane(const Vector3<T> & a_OtherEnd, T a_X) const { - if (abs(x - a_OtherEnd.x) < EPS) + if (Abs(x - a_OtherEnd.x) < EPS) { return NO_INTERSECTION; } @@ -255,7 +277,15 @@ public: /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */ static const double NO_INTERSECTION; + +protected: + /** Returns the absolute value of the given argument. + Templatized because the standard library differentiates between abs() and fabs(). */ + static T Abs(T a_Value) + { + return (a_Value < 0) ? -a_Value : a_Value; + } }; // tolua_end diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index cd141f7eb..08e164d78 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -89,6 +89,7 @@ bool cWebAdmin::Init(void) m_IniFile.AddHeaderComment(" Password format: Password=*password*; for example:"); m_IniFile.AddHeaderComment(" [User:admin]"); m_IniFile.AddHeaderComment(" Password=admin"); + m_IniFile.WriteFile("webadmin.ini"); } if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true)) @@ -229,10 +230,11 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque } // for itr - Data->m_Form[] // Parse the URL into individual params: - size_t idxQM = a_Request.GetURL().find('?'); + const AString & URL = a_Request.GetURL(); + size_t idxQM = URL.find('?'); if (idxQM != AString::npos) { - cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, a_Request.GetURL().c_str() + idxQM + 1, a_Request.GetURL().length() - idxQM - 1, *Data); + cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, URL.c_str() + idxQM + 1, URL.length() - idxQM - 1, *Data); URLParams.Finish(); for (cHTTPFormParser::const_iterator itr = URLParams.begin(), end = URLParams.end(); itr != end; ++itr) { @@ -284,11 +286,6 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque Content = GetDefaultPage(); } - if (ShouldWrapInTemplate && (URL.size() > 1)) - { - Content += "\n<p><a href='" + BaseURL + "'>Go back</a></p>"; - } - int MemUsageKiB = cRoot::GetPhysicalRAMUsage(); if (MemUsageKiB > 0) { @@ -388,7 +385,6 @@ AString cWebAdmin::GetDefaultPage(void) { continue; } - AString VersionNum; AppendPrintf(Content, "<li>%s V.%i</li>", itr->second->GetName().c_str(), itr->second->GetVersion()); } Content += "</ul>"; diff --git a/src/World.cpp b/src/World.cpp index c188fd522..5ac8e0a6e 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; } @@ -521,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"); @@ -574,7 +556,7 @@ void cWorld::Start(void) m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true); m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); - int TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", (int)slNone); + int TNTShrapnelLevel = IniFile.GetValueSetI("Physics", "TNTShrapnelLevel", (int)slAll); m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); @@ -592,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); @@ -687,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: @@ -786,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) { @@ -860,7 +838,7 @@ void cWorld::TickMobs(float a_Dt) { m_ChunkMap->SpawnMobs(Spawner); // do the spawn - for (cMobSpawner::tSpawnedContainer::const_iterator itr2 = Spawner.getSpawned().begin(); itr2 != Spawner.getSpawned().end(); itr2++) + for (cMobSpawner::tSpawnedContainer::const_iterator itr2 = Spawner.getSpawned().begin(); itr2 != Spawner.getSpawned().end(); ++itr2) { SpawnMobFinalize(*itr2); } @@ -870,14 +848,14 @@ void cWorld::TickMobs(float a_Dt) // move close mobs cMobProximityCounter::sIterablePair allCloseEnoughToMoveMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(-1, 64 * 16);// MG TODO : deal with this magic number (the 16 is the size of a block) - for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allCloseEnoughToMoveMobs.m_Begin; itr != allCloseEnoughToMoveMobs.m_End; itr++) + for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allCloseEnoughToMoveMobs.m_Begin; itr != allCloseEnoughToMoveMobs.m_End; ++itr) { itr->second.m_Monster.Tick(a_Dt, itr->second.m_Chunk); } // remove too far mobs cMobProximityCounter::sIterablePair allTooFarMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(128 * 16, -1);// MG TODO : deal with this magic number (the 16 is the size of a block) - for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allTooFarMobs.m_Begin; itr != allTooFarMobs.m_End; itr++) + for(cMobProximityCounter::tDistanceToMonster::const_iterator itr = allTooFarMobs.m_Begin; itr != allTooFarMobs.m_End; ++itr) { itr->second.m_Monster.Destroy(true); } @@ -1632,7 +1610,6 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated) { - MTRand r1; a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { @@ -1642,9 +1619,9 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double continue; } - float SpeedX = (float)(a_FlyAwaySpeed * (r1.randInt(10) - 5)); - float SpeedY = (float)(a_FlyAwaySpeed * r1.randInt(50)); - float SpeedZ = (float)(a_FlyAwaySpeed * (r1.randInt(10) - 5)); + float SpeedX = (float)(a_FlyAwaySpeed * (GetTickRandomNumber(10) - 5)); + float SpeedY = (float)(a_FlyAwaySpeed * GetTickRandomNumber(50)); + float SpeedZ = (float)(a_FlyAwaySpeed * (GetTickRandomNumber(10) - 5)); cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, @@ -1692,6 +1669,11 @@ int cWorld::SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NI int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) { + if (a_Reward < 1) + { + return -1; + } + cExpOrb * ExpOrb = new cExpOrb(a_X, a_Y, a_Z, a_Reward); ExpOrb->Initialize(this); return ExpOrb->GetUniqueID(); @@ -2890,7 +2872,7 @@ void cWorld::TickQueuedBlocks(void) m_BlockTickQueueCopy.clear(); m_BlockTickQueue.swap(m_BlockTickQueueCopy); - for (std::vector<BlockTickQueueItem *>::iterator itr = m_BlockTickQueueCopy.begin(); itr != m_BlockTickQueueCopy.end(); itr++) + for (std::vector<BlockTickQueueItem *>::iterator itr = m_BlockTickQueueCopy.begin(); itr != m_BlockTickQueueCopy.end(); ++itr) { BlockTickQueueItem * Block = (*itr); Block->TicksToWait -= 1; @@ -2981,7 +2963,7 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster) -int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed) +int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem & a_Item, const Vector3d * a_Speed) { cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Item, a_Speed); if (Projectile == NULL) diff --git a/src/World.h b/src/World.h index b3ee94a27..86cbb3e7e 100644 --- a/src/World.h +++ b/src/World.h @@ -126,15 +126,15 @@ public: int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; } - virtual Int64 GetWorldAge (void) const { return m_WorldAge; } // override, cannot specify due to tolua - virtual Int64 GetTimeOfDay(void) const { return m_TimeOfDay; } // override, cannot specify due to tolua + virtual Int64 GetWorldAge (void) const override { return m_WorldAge; } + virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; } void SetTicksUntilWeatherChange(int a_WeatherInterval) { m_WeatherInterval = a_WeatherInterval; } - virtual void SetTimeOfDay(Int64 a_TimeOfDay) // override, cannot specify due to tolua + virtual void SetTimeOfDay(Int64 a_TimeOfDay) override { m_TimeOfDay = a_TimeOfDay; m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0; @@ -351,7 +351,7 @@ public: /** Is the trapdoor open? Returns false if there is no trapdoor at the specified coords. */ bool IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export - /** Set the state of a trapdoor. Returns true if the trapdoor was update, false if there was no trapdoor at those coords. */ + /** Set the state of a trapdoor. Returns true if the trapdoor was updated, false if there was no trapdoor at those coords. */ bool SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open); // tolua_export /** Regenerate the given chunk: */ @@ -430,10 +430,10 @@ public: // tolua_begin /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) override; /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ - virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); // override; cannot specify it here due to tolua + virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) override; /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */ int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); @@ -457,7 +457,7 @@ public: // tolua_begin bool DigBlock (int a_X, int a_Y, int a_Z); - virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player); // override, cannot specify due to tolua + virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) override; double GetSpawnX(void) const { return m_SpawnX; } double GetSpawnY(void) const { return m_SpawnY; } @@ -508,7 +508,7 @@ public: | esWitherBirth | cMonster * | | esPlugin | void * | */ - virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export // override, cannot specify due to tolua + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override; // tolua_export /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -707,11 +707,13 @@ public: bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ - virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export // override, cannot specify due to tolua + virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) override; // tolua_export int SpawnMobFinalize(cMonster* a_Monster); - /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ - int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed = NULL); // tolua_export + /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise + Item parameter used currently for Fireworks to correctly set entity metadata based on item metadata + */ + int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem & a_Item, const Vector3d * a_Speed = NULL); // tolua_export /** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */ int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); } @@ -938,7 +940,10 @@ private: /** <summary>Generates a random spawnpoint on solid land by walking chunks and finding their biomes</summary> */ 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); 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}) diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index be25fd1a4..ac9a21205 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -345,7 +345,7 @@ cFastNBTWriter::cFastNBTWriter(const AString & a_RootTagName) : void cFastNBTWriter::BeginCompound(const AString & a_Name) { - if (m_CurrentStack >= MAX_STACK) + if (m_CurrentStack >= MAX_STACK - 1) { ASSERT(!"Stack overflow"); return; @@ -376,7 +376,7 @@ void cFastNBTWriter::EndCompound(void) void cFastNBTWriter::BeginList(const AString & a_Name, eTagType a_ChildrenType) { - if (m_CurrentStack >= MAX_STACK) + if (m_CurrentStack >= MAX_STACK - 1) { ASSERT(!"Stack overflow"); return; diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 5e5af3ca3..bcf93228f 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -237,7 +237,7 @@ public: { ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_String); AString res; - res.assign(m_Data + m_Tags[(size_t)a_Tag].m_DataStart, m_Tags[(size_t)a_Tag].m_DataLength); + res.assign(m_Data + m_Tags[(size_t)a_Tag].m_DataStart, (size_t)m_Tags[(size_t)a_Tag].m_DataLength); return res; } @@ -245,7 +245,7 @@ public: inline AString GetName(int a_Tag) const { AString res; - res.assign(m_Data + m_Tags[(size_t)a_Tag].m_NameStart, m_Tags[(size_t)a_Tag].m_NameLength); + res.assign(m_Data + m_Tags[(size_t)a_Tag].m_NameStart, (size_t)m_Tags[(size_t)a_Tag].m_NameLength); return res; } diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 744fc731f..e0cd69634 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -231,7 +231,7 @@ void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkIte -int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta) +int cFireworkItem::GetVanillaColourCodeFromDye(NIBBLETYPE a_DyeMeta) { /* Colours are supposed to be calculated via: R << 16 + G << 8 + B diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h index cbc544a14..59f1b09b0 100644 --- a/src/WorldStorage/FireworksSerializer.h +++ b/src/WorldStorage/FireworksSerializer.h @@ -81,7 +81,7 @@ public: static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem); /** Returns a colour code for fireworks used by the network code */ - static int GetVanillaColourCodeFromDye(short a_DyeMeta); + static int GetVanillaColourCodeFromDye(NIBBLETYPE a_DyeMeta); bool m_HasFlicker; bool m_HasTrail; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 415693ae2..fd356c7de 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/ArrowEntity.h" #include "../Entities/TNTEntity.h" #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" @@ -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" @@ -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: @@ -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; } } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 48934d074..f33178173 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" @@ -36,7 +35,12 @@ #include "../Entities/FallingBlock.h" #include "../Entities/Minecart.h" #include "../Entities/Pickup.h" -#include "../Entities/ProjectileEntity.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" @@ -1757,7 +1761,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<cCavespider> Monster(new cCavespider()); + std::auto_ptr<cCaveSpider> Monster(new cCaveSpider()); if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) { return; @@ -2272,7 +2276,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()); @@ -2668,6 +2672,11 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri return false; } + // Add padding to 4K boundary: + size_t BytesWritten = a_Data.size() + MCA_CHUNK_HEADER_LENGTH; + static const char Padding[4095] = {0}; + m_File.Write(Padding, 4096 - (BytesWritten % 4096)); + // Store the header: ChunkSize = (a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size *up* to nearest 4KB sector, make it a sector number ASSERT(ChunkSize < 256); diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index bb9d4b9e6..359bac4a8 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 @@ -797,7 +805,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() ++index2; } InChunkOffset += index2 / 2; - index2 = 0; AString Converted(ConvertedData, ExpectedSize); @@ -839,7 +846,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() -bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWorld * a_World) +bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int a_UncompressedSize, const AString & a_Data, cWorld * a_World) { // Crude data integrity check: if (a_UncompressedSize < cChunkDef::BlockDataSize) diff --git a/src/WorldStorage/WSSCompact.h b/src/WorldStorage/WSSCompact.h index 4df146ec3..97e3b82f9 100644 --- a/src/WorldStorage/WSSCompact.h +++ b/src/WorldStorage/WSSCompact.h @@ -135,7 +135,7 @@ protected: bool EraseChunkData(const cChunkCoords & a_Chunk); /// Loads the chunk from the data (no locking needed) - bool LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWorld * a_World); + bool LoadChunkFromData(const cChunkCoords & a_Chunk, int a_UncompressedSize, const AString & a_Data, cWorld * a_World); void LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World); diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 711c8612f..54eaaca5c 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -150,7 +150,7 @@ size_t cWorldStorage::GetSaveQueueLength(void) void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) { - m_LoadQueue.EnqueueItemIfNotPresent(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); + m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); m_Event.Set(); } |