2012-02-08 07:36:54 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2012-02-13 16:47:03 -05:00
|
|
|
#include "BlockID.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
#else
|
2012-02-13 16:47:03 -05:00
|
|
|
enum ENUM_ITEM_ID;
|
2011-10-03 14:41:19 -04:00
|
|
|
#endif
|
|
|
|
|
2011-12-23 18:58:54 -05:00
|
|
|
#define MAX_PLAYERS 65535
|
|
|
|
|
2011-12-26 15:57:12 -05:00
|
|
|
#include "cSimulatorManager.h"
|
2012-02-08 07:36:54 -05:00
|
|
|
#include "MersenneTwister.h"
|
2012-02-13 16:47:03 -05:00
|
|
|
#include "cChunkMap.h"
|
|
|
|
#include "WorldStorage.h"
|
|
|
|
#include "cChunkGenerator.h"
|
2011-12-26 15:57:12 -05:00
|
|
|
|
2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-07 21:02:13 -05:00
|
|
|
class cPacket;
|
2011-11-08 20:31:19 -05:00
|
|
|
class cRedstone;
|
2011-12-28 16:00:35 -05:00
|
|
|
class cFireSimulator;
|
2011-10-03 14:41:19 -04:00
|
|
|
class cWaterSimulator;
|
2011-11-06 04:23:20 -05:00
|
|
|
class cLavaSimulator;
|
2011-12-26 15:57:12 -05:00
|
|
|
class cSandSimulator;
|
2011-10-03 14:41:19 -04:00
|
|
|
class cItem;
|
|
|
|
class cPlayer;
|
|
|
|
class cClientHandle;
|
|
|
|
class cEntity;
|
|
|
|
class cBlockEntity;
|
2012-02-13 16:47:03 -05:00
|
|
|
class cWorldGenerator; // The generator that actually generates the chunks for a single world
|
|
|
|
class cChunkGenerator; // The thread responsible for generating chunks
|
|
|
|
typedef std::list< cPlayer * > cPlayerList;
|
|
|
|
typedef cListCallback<cPlayer> cPlayerListCallback;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-26 15:57:12 -05:00
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cWorld //tolua_export
|
|
|
|
{ //tolua_export
|
|
|
|
public:
|
2011-11-08 20:31:19 -05:00
|
|
|
|
2011-11-01 17:57:08 -04:00
|
|
|
static cWorld* GetWorld(); //tolua_export
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
// Return time in seconds
|
|
|
|
inline static float GetTime() //tolua_export
|
|
|
|
{
|
|
|
|
return m_Time;
|
|
|
|
}
|
2012-02-13 16:47:03 -05:00
|
|
|
long long GetWorldTime(void) const { return m_WorldTime; } //tolua_export
|
2011-10-26 16:52:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
int GetGameMode(void) const { return m_GameMode; } //return gamemode for world
|
2011-10-26 16:52:19 -04:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void SetWorldTime(long long a_WorldTime) { m_WorldTime = a_WorldTime; } //tolua_export
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cChunkPtr GetChunk ( int a_ChunkX, int a_ChunkY, int a_ChunkZ ) {return m_ChunkMap->GetChunk (a_ChunkX, a_ChunkY, a_ChunkZ); }
|
|
|
|
cChunkPtr GetChunkNoGen ( int a_ChunkX, int a_ChunkY, int a_ChunkZ ) {return m_ChunkMap->GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ); }
|
|
|
|
cChunkPtr GetChunkOfBlock( int a_X, int a_Y, int a_Z );
|
2011-10-03 14:41:19 -04:00
|
|
|
char GetHeight( int a_X, int a_Z ); //tolua_export
|
|
|
|
|
2011-11-01 17:57:08 -04:00
|
|
|
//void AddClient( cClientHandle* a_Client );
|
|
|
|
//void RemoveClient( cClientHandle* a_Client );
|
|
|
|
//ClientList & GetClients();
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2011-11-07 21:02:13 -05:00
|
|
|
void Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude = 0 );
|
2011-12-23 18:58:54 -05:00
|
|
|
|
|
|
|
// MOTD
|
2012-02-13 16:47:03 -05:00
|
|
|
const AString & GetDescription(void) const {return m_Description; }
|
2011-12-23 18:58:54 -05:00
|
|
|
|
|
|
|
// Max Players
|
2012-02-13 16:47:03 -05:00
|
|
|
unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; }
|
2011-12-23 18:58:54 -05:00
|
|
|
void SetMaxPlayers(int iMax);
|
2011-11-07 21:02:13 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void AddPlayer( cPlayer* a_Player );
|
|
|
|
void RemovePlayer( cPlayer* a_Player );
|
2012-02-13 16:47:03 -05:00
|
|
|
bool ForEachPlayer(cPlayerListCallback * a_Callback); // Calls the callback for each player in the list
|
|
|
|
|
|
|
|
// TODO: This interface is dangerous!
|
|
|
|
cPlayerList & GetAllPlayers() {return m_Players; }
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
typedef struct lua_State lua_State;
|
|
|
|
void GetAllPlayers( lua_State* L ); // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
unsigned int GetNumPlayers(); //tolua_export
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
// TODO: This interface is dangerous
|
|
|
|
cPlayer * GetPlayer( const char * a_PlayerName ); //tolua_export
|
|
|
|
|
|
|
|
cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit);
|
|
|
|
|
|
|
|
void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void AddEntity( cEntity* a_Entity );
|
2012-02-13 16:47:03 -05:00
|
|
|
void RemoveEntityFromChunk( cEntity * a_Entity);
|
|
|
|
|
|
|
|
// TODO: This interface is dangerous!
|
|
|
|
cEntityList & GetEntities(void) {return m_AllEntities; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
// TODO: This interface is dangerous!
|
|
|
|
cEntity * GetEntity( int a_UniqueID ); //tolua_export
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
|
|
|
|
void FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ); //tolua_export
|
|
|
|
char GetBlock( int a_X, int a_Y, int a_Z ); //tolua_export
|
|
|
|
char GetBlockMeta( int a_X, int a_Y, int a_Z ); //tolua_export
|
|
|
|
void SetBlockMeta( int a_X, int a_Y, int a_Z, char a_MetaData ); //tolua_export
|
|
|
|
bool DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ); //tolua_export
|
|
|
|
void SendBlockTo( int a_X, int a_Y, int a_Z, cPlayer* a_Player ); //tolua_export
|
|
|
|
|
|
|
|
const double & GetSpawnX() { return m_SpawnX; } //tolua_export
|
|
|
|
const double & GetSpawnY(); //tolua_export
|
|
|
|
const double & GetSpawnZ() { return m_SpawnZ; } //tolua_export
|
|
|
|
|
2011-12-26 15:57:12 -05:00
|
|
|
inline cSimulatorManager *GetSimulatorManager() { return m_SimulatorManager; }
|
|
|
|
inline cWaterSimulator *GetWaterSimulator() { return m_WaterSimulator; }
|
|
|
|
inline cLavaSimulator *GetLavaSimulator() { return m_LavaSimulator; }
|
2011-12-22 16:36:24 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
// TODO: This interface is dangerous!
|
|
|
|
cBlockEntity * GetBlockEntity( int a_X, int a_Y, int a_Z ); //tolua_export
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
unsigned int GetWorldSeed(void) const { return m_WorldSeed; } //tolua_export
|
|
|
|
const AString & GetName(void) const {return m_WorldName; } //tolua_export
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
|
|
|
|
{
|
|
|
|
(void)a_Y; // not unused anymore
|
|
|
|
a_ChunkX = a_X/16;
|
|
|
|
if(a_X < 0 && a_X % 16 != 0) a_ChunkX--;
|
|
|
|
a_ChunkY = 0;
|
|
|
|
a_ChunkZ = a_Z/16;
|
|
|
|
if(a_Z < 0 && a_Z % 16 != 0) a_ChunkZ--;
|
|
|
|
|
|
|
|
a_X = a_X - a_ChunkX*16;
|
|
|
|
//a_Y = a_Y - a_ChunkY*16;
|
|
|
|
a_Z = a_Z - a_ChunkZ*16;
|
|
|
|
}
|
2012-02-13 16:47:03 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
inline static void BlockToChunk( int a_X, int a_Y, int a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
|
|
|
|
{
|
|
|
|
(void)a_Y; // not unused anymore
|
|
|
|
a_ChunkX = a_X/16;
|
|
|
|
if(a_X < 0 && a_X % 16 != 0) a_ChunkX--;
|
|
|
|
a_ChunkY = 0;
|
|
|
|
a_ChunkZ = a_Z/16;
|
|
|
|
if(a_Z < 0 && a_Z % 16 != 0) a_ChunkZ--;
|
|
|
|
}
|
|
|
|
|
2012-01-01 11:20:52 -05:00
|
|
|
void SaveAllChunks(); //tolua_export
|
2012-02-13 16:47:03 -05:00
|
|
|
int GetNumChunks() const; //tolua_export
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void Tick(float a_Dt);
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
void ReSpreadLighting(const cChunkPtr & a_Chunk );
|
|
|
|
void RemoveSpread(const cChunkPtr & a_Chunk );
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void InitializeSpawn();
|
2011-11-08 20:31:19 -05:00
|
|
|
|
2012-01-19 13:12:39 -05:00
|
|
|
void CastThunderbolt ( int, int, int ); //tolua_export
|
2011-11-09 18:24:51 -05:00
|
|
|
void SetWeather ( int ); //tolua_export
|
2012-01-19 13:12:39 -05:00
|
|
|
int GetWeather() { return m_Weather; }; //tolua_export
|
2011-11-09 18:24:51 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cChunkGenerator & GetGenerator(void) { return m_Generator; }
|
|
|
|
cWorldStorage & GetStorage (void) { return m_Storage; }
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
private:
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
friend class cRoot;
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
struct sSetBlockData
|
|
|
|
{
|
|
|
|
sSetBlockData( int a_X, int a_Y, int a_Z, char a_BlockID, char a_BlockMeta )
|
|
|
|
: x( a_X )
|
|
|
|
, y( a_Y )
|
|
|
|
, z( a_Z )
|
|
|
|
, BlockID( a_BlockID )
|
|
|
|
, BlockMeta( a_BlockMeta )
|
|
|
|
{}
|
|
|
|
int x, y, z;
|
|
|
|
char BlockID, BlockMeta;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::list< sSetBlockData > FastSetBlockList;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-08 07:36:54 -05:00
|
|
|
// This random generator is to be used only in the Tick() method, and thus only in the World-Tick-thread (MTRand is not exactly thread-safe)
|
|
|
|
MTRand m_TickRand;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
double m_SpawnX;
|
|
|
|
double m_SpawnY;
|
|
|
|
double m_SpawnZ;
|
|
|
|
|
|
|
|
float m_LastUnload;
|
|
|
|
float m_LastSave;
|
|
|
|
static float m_Time; // Time in seconds
|
|
|
|
long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped)
|
2011-11-06 04:23:20 -05:00
|
|
|
unsigned long long CurrentTick;
|
2011-10-26 16:52:19 -04:00
|
|
|
int m_GameMode;
|
2011-10-03 14:41:19 -04:00
|
|
|
float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
// The cRedstone class simulates redstone and needs access to m_RSList
|
|
|
|
friend class cRedstone;
|
|
|
|
std::vector<int> m_RSList;
|
|
|
|
|
|
|
|
cSimulatorManager * m_SimulatorManager;
|
|
|
|
cSandSimulator * m_SandSimulator;
|
|
|
|
cWaterSimulator * m_WaterSimulator;
|
|
|
|
cLavaSimulator * m_LavaSimulator;
|
|
|
|
cFireSimulator * m_FireSimulator;
|
2011-12-26 15:57:12 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cCriticalSection m_CSClients;
|
|
|
|
cCriticalSection m_CSEntities;
|
|
|
|
cCriticalSection m_CSPlayers;
|
2011-12-26 18:23:05 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cWorldStorage m_Storage;
|
|
|
|
|
|
|
|
AString m_Description;
|
2011-12-23 18:58:54 -05:00
|
|
|
|
|
|
|
unsigned int m_MaxPlayers;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cChunkMap * m_ChunkMap;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
bool m_bAnimals;
|
|
|
|
float m_SpawnMonsterTime;
|
|
|
|
float m_SpawnMonsterRate;
|
|
|
|
|
|
|
|
unsigned int m_WorldSeed;
|
2012-02-13 16:47:03 -05:00
|
|
|
|
2011-11-09 18:24:51 -05:00
|
|
|
int m_Weather;
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cEntityList m_RemoveEntityQueue;
|
|
|
|
cEntityList m_AllEntities;
|
|
|
|
cClientHandleList m_Clients;
|
|
|
|
cPlayerList m_Players;
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cCriticalSection m_CSLighting;
|
|
|
|
cChunkPtrList m_SpreadQueue;
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cCriticalSection m_CSFastSetBlock;
|
|
|
|
FastSetBlockList m_FastSetBlockQueue;
|
|
|
|
|
|
|
|
cChunkGenerator m_Generator;
|
|
|
|
|
|
|
|
AString m_WorldName;
|
|
|
|
|
|
|
|
cWorld(const AString & a_WorldName);
|
|
|
|
~cWorld();
|
|
|
|
|
|
|
|
void TickWeather(float a_Dt); // Handles weather each tick
|
|
|
|
void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick
|
|
|
|
|
|
|
|
void RemoveEntity( cEntity * a_Entity );
|
|
|
|
void UnloadUnusedChunks();
|
2011-10-03 14:41:19 -04:00
|
|
|
}; //tolua_export
|
2012-02-08 07:36:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|