mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 11:33:44 +01:00
new-style rats are now generated in the map
This commit is contained in:
parent
1a32e5585f
commit
7aa2d4d109
@ -429,7 +429,7 @@ void ServerEnvironment::step(float dtime)
|
|||||||
|
|
||||||
bool send_recommended = false;
|
bool send_recommended = false;
|
||||||
m_send_recommended_timer += dtime;
|
m_send_recommended_timer += dtime;
|
||||||
if(m_send_recommended_timer > 0.2)
|
if(m_send_recommended_timer > 0.1)
|
||||||
{
|
{
|
||||||
m_send_recommended_timer = 0;
|
m_send_recommended_timer = 0;
|
||||||
send_recommended = true;
|
send_recommended = true;
|
||||||
@ -1111,7 +1111,7 @@ void ClientEnvironment::step(float dtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Step active objects
|
Step active objects and update lighting of them
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
for(core::map<u16, ClientActiveObject*>::Iterator
|
||||||
@ -1121,6 +1121,17 @@ void ClientEnvironment::step(float dtime)
|
|||||||
ClientActiveObject* obj = i.getNode()->getValue();
|
ClientActiveObject* obj = i.getNode()->getValue();
|
||||||
// Step object
|
// Step object
|
||||||
obj->step(dtime, this);
|
obj->step(dtime, this);
|
||||||
|
// Update lighting
|
||||||
|
//u8 light = LIGHT_MAX;
|
||||||
|
u8 light = 0;
|
||||||
|
try{
|
||||||
|
// Get node at head
|
||||||
|
v3s16 p = obj->getLightPosition();
|
||||||
|
MapNode n = m_map->getNode(p);
|
||||||
|
light = n.getLightBlend(m_daynight_ratio);
|
||||||
|
}
|
||||||
|
catch(InvalidPositionException &e) {}
|
||||||
|
obj->updateLight(light);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
74
src/map.cpp
74
src/map.cpp
@ -2109,6 +2109,61 @@ double base_rock_level_2d(u64 seed, v2s16 p)
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Adds random objects to block, depending on the content of the block
|
||||||
|
*/
|
||||||
|
void addRandomObjects(MapBlock *block)
|
||||||
|
{
|
||||||
|
for(s16 z0=0; z0<MAP_BLOCKSIZE; z0++)
|
||||||
|
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
|
||||||
|
{
|
||||||
|
bool last_node_walkable = false;
|
||||||
|
for(s16 y0=0; y0<MAP_BLOCKSIZE; y0++)
|
||||||
|
{
|
||||||
|
v3s16 p(x0,y0,z0);
|
||||||
|
MapNode n = block->getNodeNoEx(p);
|
||||||
|
if(n.d == CONTENT_IGNORE)
|
||||||
|
continue;
|
||||||
|
if(content_features(n.d).liquid_type != LIQUID_NONE)
|
||||||
|
continue;
|
||||||
|
if(content_features(n.d).walkable)
|
||||||
|
{
|
||||||
|
last_node_walkable = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(last_node_walkable)
|
||||||
|
{
|
||||||
|
// If block contains light information
|
||||||
|
if(content_features(n.d).param_type == CPT_LIGHT)
|
||||||
|
{
|
||||||
|
if(n.getLight(LIGHTBANK_DAY) <= 3)
|
||||||
|
{
|
||||||
|
if(myrand() % 300 == 0)
|
||||||
|
{
|
||||||
|
v3f pos_f = intToFloat(p+block->getPosRelative(), BS);
|
||||||
|
pos_f.Y -= BS*0.4;
|
||||||
|
ServerActiveObject *obj = new RatSAO(NULL, 0, pos_f);
|
||||||
|
std::string data = obj->getStaticData();
|
||||||
|
StaticObject s_obj(obj->getType(),
|
||||||
|
obj->getBasePosition(), data);
|
||||||
|
// Add some
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
block->m_static_objects.insert(0, s_obj);
|
||||||
|
delete obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_node_walkable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
block->setChangedFlag();
|
||||||
|
}
|
||||||
|
|
||||||
#define VMANIP_FLAG_DUNGEON VOXELFLAG_CHECKED1
|
#define VMANIP_FLAG_DUNGEON VOXELFLAG_CHECKED1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3660,6 +3715,25 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Add random objects to blocks
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
for(s16 x=0; x<sectorpos_base_size; x++)
|
||||||
|
for(s16 z=0; z<sectorpos_base_size; z++)
|
||||||
|
{
|
||||||
|
v2s16 sectorpos = sectorpos_base + v2s16(x,z);
|
||||||
|
ServerMapSector *sector = createSector(sectorpos);
|
||||||
|
assert(sector);
|
||||||
|
|
||||||
|
for(s16 y=y_blocks_min; y<=y_blocks_max; y++)
|
||||||
|
{
|
||||||
|
v3s16 blockpos(sectorpos.X, y, sectorpos.Y);
|
||||||
|
MapBlock *block = createBlock(blockpos);
|
||||||
|
addRandomObjects(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Create chunk metadata
|
Create chunk metadata
|
||||||
|
@ -169,6 +169,7 @@ ServerActiveObject* ItemSAO::create(ServerEnvironment *env, u16 id, v3f pos,
|
|||||||
void ItemSAO::step(float dtime, Queue<ActiveObjectMessage> &messages,
|
void ItemSAO::step(float dtime, Queue<ActiveObjectMessage> &messages,
|
||||||
bool send_recommended)
|
bool send_recommended)
|
||||||
{
|
{
|
||||||
|
assert(m_env);
|
||||||
core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
|
core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
|
||||||
collisionMoveResult moveresult;
|
collisionMoveResult moveresult;
|
||||||
// Apply gravity
|
// Apply gravity
|
||||||
@ -300,17 +301,19 @@ ServerActiveObject* RatSAO::create(ServerEnvironment *env, u16 id, v3f pos,
|
|||||||
void RatSAO::step(float dtime, Queue<ActiveObjectMessage> &messages,
|
void RatSAO::step(float dtime, Queue<ActiveObjectMessage> &messages,
|
||||||
bool send_recommended)
|
bool send_recommended)
|
||||||
{
|
{
|
||||||
|
assert(m_env);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The AI
|
The AI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
m_age += dtime;
|
/*m_age += dtime;
|
||||||
if(m_age > 60)
|
if(m_age > 60)
|
||||||
{
|
{
|
||||||
// Die
|
// Die
|
||||||
m_removed = true;
|
m_removed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Apply gravity
|
// Apply gravity
|
||||||
m_speed_f.Y -= dtime*9.81*BS;
|
m_speed_f.Y -= dtime*9.81*BS;
|
||||||
|
@ -78,6 +78,10 @@ class InventoryItem;
|
|||||||
class ServerActiveObject : public ActiveObject
|
class ServerActiveObject : public ActiveObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
|
NOTE: m_env can be NULL, but step() isn't called if it is.
|
||||||
|
Prototypes are used that way.
|
||||||
|
*/
|
||||||
ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos);
|
ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos);
|
||||||
virtual ~ServerActiveObject();
|
virtual ~ServerActiveObject();
|
||||||
|
|
||||||
@ -101,7 +105,7 @@ public:
|
|||||||
Messages added to messages are sent to client over network.
|
Messages added to messages are sent to client over network.
|
||||||
|
|
||||||
send_recommended:
|
send_recommended:
|
||||||
True at around 5 times a second, same for all objects.
|
True at around 5-10 times a second, same for all objects.
|
||||||
This is used to let objects send most of the data at the
|
This is used to let objects send most of the data at the
|
||||||
same time so that the data can be combined in a single
|
same time so that the data can be combined in a single
|
||||||
packet.
|
packet.
|
||||||
|
Loading…
Reference in New Issue
Block a user