and the rats work

This commit is contained in:
darkrose 2014-09-27 05:03:28 +10:00
parent ab27c517f5
commit 6bbd7fe21c
9 changed files with 52 additions and 37 deletions

View File

@ -246,6 +246,7 @@ void MobCAO::addToScene(scene::ISceneManager *smgr)
if (m_node != NULL)
return;
video::IVideoDriver* driver = smgr->getVideoDriver();
MobFeatures m = content_mob_features(m_content);
if (m.model != "") {
scene::IAnimatedMesh* mesh = createModelMesh(smgr,m.model.c_str(),true);
@ -266,7 +267,7 @@ void MobCAO::addToScene(scene::ISceneManager *smgr)
bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
// Set material flags and texture
m_node->setMaterialTexture( 0, m.texture);
m_node->setMaterialTexture( 0, driver->getTexture(getTexturePath(m.texture).c_str()));
video::SMaterial& material = m_node->getMaterial(0);
material.setFlag(video::EMF_LIGHTING, false);
material.setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
@ -274,7 +275,6 @@ void MobCAO::addToScene(scene::ISceneManager *smgr)
material.setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
m_node->setPosition(m.model_offset);
m_node->setVisible(true);
}
#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
@ -287,7 +287,6 @@ void MobCAO::addToScene(scene::ISceneManager *smgr)
void MobCAO::removeFromScene()
{
if (m_node != NULL) {
m_node->drop();
m_node->remove();
m_node = NULL;
}
@ -302,8 +301,8 @@ void MobCAO::updateLight(u8 light_at_pos)
m_last_light = light_at_pos;
if (m_damage_visual_timer > 0)
return;
//if (m_damage_visual_timer > 0)
//return;
u8 li = decode_light(light_at_pos);
video::SColor color(255,li,li,li);
@ -315,14 +314,18 @@ void MobCAO::updateLight(u8 light_at_pos)
}
v3s16 MobCAO::getLightPosition()
{
return v3s16(0,0,0);
return floatToInt(m_position, BS);
}
void MobCAO::updateNodePos()
{
if (m_node == NULL)
return;
m_node->setPosition(pos_translator.vect_show-intToFloat(m_camera_offset, BS));
v3f offset = content_mob_features(m_content).model_offset+v3f(0,-0.5,0);
offset.X *= (float)BS;
offset.Y *= (float)BS;
offset.Z *= (float)BS;
offset += pos_translator.vect_show;
m_node->setPosition(offset-intToFloat(m_camera_offset, BS));
v3f rot = m_node->getRotation();
rot.Y = 90-m_yaw;
@ -361,9 +364,9 @@ void MobCAO::step(float dtime, ClientEnvironment *env)
/* Run timers */
m_player_hit_timer -= dtime;
if(m_damage_visual_timer >= 0){
if (m_damage_visual_timer >= 0) {
m_damage_visual_timer -= dtime;
if(m_damage_visual_timer <= 0){
if (m_damage_visual_timer <= 0) {
infostream<<"id="<<m_id<<" damage visual ended"<<std::endl;
}
}

View File

@ -179,7 +179,7 @@ public:
{
m_camera_offset = camera_offset;
}
bool doShowSelectionBox(){return false;}
//bool doShowSelectionBox(){return false;}
// If returns true, punch will not be sent to the server
bool directReportPunch(const std::string &toolname, v3f dir);

View File

@ -41,11 +41,6 @@ MobFeatures & content_mob_features(content_t i)
}
#ifndef SERVER
void MobFeatures::setTexture(std::string name)
{
if (g_texturesource)
texture = g_texturesource->getTextureRaw(name);
}
void MobFeatures::setBoxTexture(u16 i, std::string name, u8 alpha)
{
if (g_texturesource)
@ -171,6 +166,7 @@ bool content_mob_spawn(ServerEnvironment *env, v3s16 pos)
void content_mob_init()
{
g_content_mob_features.clear();
printf("initialising mobs\n\n");
content_t i;
MobFeatures *f = NULL;
@ -183,6 +179,7 @@ void content_mob_init()
f->setTexture("mob_rat.png");
f->setAnimationFrames(MA_STAND,0,79);
f->punch_action = MPA_PICKUP;
f->dropped_item = std::string("CraftItem2 ")+itos(CONTENT_CRAFTITEM_RAT)+" 1";
f->motion = MM_WANDER;
f->spawn_on = CONTENT_GRASS;
f->spawn_in = CONTENT_AIR;
@ -194,6 +191,7 @@ void content_mob_init()
f->level = MOB_PASSIVE;
f->setTexture("mob_firefly.png");
f->punch_action = MPA_PICKUP;
f->dropped_item = std::string("CraftItem2 ")+itos(CONTENT_CRAFTITEM_FIREFLY)+" 1";
f->motion = MM_WANDER;
f->glow_light = LIGHT_MAX-1;
f->spawn_on = CONTENT_JUNGLETREE;

View File

@ -86,8 +86,8 @@ struct MobFeatures {
u8 level;
#ifndef SERVER
TileSpec tiles[6];
video::ITexture *texture;
#endif
std::string texture;
std::string model;
std::map<MobAnimationKey,int> animations;
v3f model_scale;
@ -144,6 +144,8 @@ struct MobFeatures {
void setCollisionBox(aabb3f cb)
{
cb.MinEdge.Y -= 0.5*BS;
cb.MaxEdge.Y -= 0.5*BS;
collisionbox = cb;
}
@ -152,17 +154,15 @@ struct MobFeatures {
if (collisionbox.MinEdge != collisionbox.MaxEdge)
return collisionbox;
if (!nodeboxes.size())
return aabb3f(-0.5,-0.5,-0.5,0.5,0.5,0.5);
return aabb3f(-0.5*BS,0.,-0.5*BS,0.5*BS,BS,0.5*BS);
aabb3f b = nodeboxes[0];
b.MinEdge /= BS;
b.MaxEdge /= BS;
return b;
}
v3f getSize()
{
aabb3f c = getCollisionBox();
return v3f(c.MaxEdge.X-c.MinEdge.X,c.MaxEdge.Y-c.MinEdge.Y,c.MaxEdge.Z-c.MinEdge.Z);
return v3f((c.MaxEdge.X-c.MinEdge.X)/BS,(c.MaxEdge.Y-c.MinEdge.Y)/BS,(c.MaxEdge.Z-c.MinEdge.Z)/BS);
}
v3s16 getSizeBlocks()
@ -173,16 +173,14 @@ struct MobFeatures {
void getAnimationFrames(MobAnimation type, int *start, int *end);
void setAnimationFrames(MobAnimation type, int start, int end);
void setTexture(std::string name) {texture = name;}
#ifdef SERVER
void setTexture(std::string name)
{}
void setBoxTexture(u16 i, std::string name, u8 alpha=255)
{}
void setAllBoxTextures(std::string name, u8 alpha=255)
{}
#else
void setTexture(std::string name);
void setBoxTexture(u16 i, std::string name, u8 alpha=255);
void setAllBoxTextures(std::string name, u8 alpha=255)
@ -196,8 +194,9 @@ struct MobFeatures {
void reset()
{
content = CONTENT_IGNORE;
texture = "";
model = "";
model_scale = v3f(0,0,0);
model_scale = v3f(1.0,1.0,1.0);
model_offset = v3f(0,0,0);
nodeboxes.clear();
punch_action = MPA_DIE;

View File

@ -280,11 +280,20 @@ MobSAO::~MobSAO()
ServerActiveObject* MobSAO::create(ServerEnvironment *env, u16 id, v3f pos, const std::string &data)
{
std::istringstream is(data, std::ios::binary);
char buf[1];
// read version
is.read(buf, 1);
u8 version = buf[0];
// check if version is supported
if (version != 0)
return NULL;
v3f p = readV3F1000(is);
content_t c = readU16(is);
c = content_mob_features(c).content;
if (c == CONTENT_IGNORE)
return NULL;
MobSAO *o = new MobSAO(env,id,pos,c);
o->m_base_position = p;
o->m_yaw = readF1000(is);
o->m_speed = readV3F1000(is);
o->m_age = readF1000(is);
@ -327,7 +336,7 @@ void MobSAO::step(float dtime, bool send_recommended)
m_age += dtime;
if (m.lifetime >= 0.0 && m_age >= m.lifetime) {
if (m.lifetime > 0.0 && m_age >= m.lifetime) {
m_removed = true;
return;
}
@ -433,11 +442,12 @@ void MobSAO::step(float dtime, bool send_recommended)
m_walk_around_timer -= dtime;
if (m_walk_around_timer <= 0.0) {
m_walk_around = !m_walk_around;
if (m_walk_around) {
m_walk_around_timer = 0.1*myrand_range(10,50);
}else{
m_walk_around_timer = 0.1*myrand_range(30,70);
}
m_walk_around_timer = 1.0;
//if (m_walk_around) {
//m_walk_around_timer = 0.1*myrand_range(10,50);
//}else{
//m_walk_around_timer = 0.1*myrand_range(30,70);
//}
}
if (m_next_pos_exists) {
v3f pos_f = m_base_position;
@ -493,6 +503,7 @@ void MobSAO::stepMotionWander(float dtime)
MobFeatures m = content_mob_features(m_content);
v3s16 pos_i = floatToInt(m_base_position, BS);
v3s16 pos_size_off(0,0,0);
v3f s = m.getSize();
if (m.getSize().X >= 2.5) {
pos_size_off.X = -1;
pos_size_off.Y = -1;
@ -1036,6 +1047,8 @@ InventoryItem* MobSAO::createPickedUpItem()
return NULL;
std::istringstream is(m.dropped_item, std::ios_base::binary);
InventoryItem *item = InventoryItem::deSerialize(is);
if (!m_removed)
m_removed = true;
return item;
}
u16 MobSAO::punch(const std::string &toolname, v3f dir, const std::string &playername)

View File

@ -52,7 +52,8 @@ public:
MobSAO(ServerEnvironment *env, u16 id, v3f pos, content_t type);
MobSAO(ServerEnvironment *env, u16 id, v3f pos, v3f speed, content_t type);
virtual ~MobSAO();
u8 getType() const {return ACTIVEOBJECT_TYPE_MOB;}
u8 getType() const
{return ACTIVEOBJECT_TYPE_MOB;}
static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos,
const std::string &data);
std::string getStaticData();

View File

@ -184,10 +184,10 @@ void Player::deSerialize(std::istream &is)
}catch(SettingNotFoundException &e){
hunger = 20;
}
try{
if (args.exists("home")) {
m_home = args.getV3F("home");
m_hashome = true;
}catch(SettingNotFoundException &e){}
}
/*try{
std::string sprivs = args.get("privs");
if(sprivs == "all")

View File

@ -1402,6 +1402,8 @@ void Server::AsyncRunStep()
type = obj->getType();
}
printf("type == %u\n",type);
// Add to data buffer for sending
writeU16((u8*)buf, id);
data_buffer.append(buf, 2);
@ -1413,7 +1415,7 @@ void Server::AsyncRunStep()
}else{
data_buffer.append(serializeLongString(""));
}
printf("data_buffer.size() == %u\n",(u32)data_buffer.size());
// Add to known objects
client->m_known_objects.insert(i.getNode()->getKey(), false);

View File

@ -44,8 +44,7 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
// Find factory function
core::map<u16, Factory>::Node *n;
n = m_types.find(type);
if(n == NULL)
{
if (n == NULL) {
// If factory is not found, just return.
dstream<<"WARNING: ServerActiveObject: No factory for type="
<<type<<std::endl;