X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fcontent_sao.cpp;h=4ee92f4d34255408e83f1159cfadb73f359fb26b;hb=58e6d25e033c76dc91aaac18fdeda92ac23fe0e1;hp=ed660cf1006139cbc21379083669d3df095adf87;hpb=2ed3067bbed9844b434b53fb9cacb870e6ca97ea;p=oweals%2Fminetest.git diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ed660cf10..4ee92f4d3 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -27,9 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tool.h" // For ToolCapabilities #include "gamedef.h" #include "player.h" -#include "cpp_api/scriptapi.h" +#include "scripting_game.h" #include "genericobject.h" #include "util/serialize.h" +#include "util/mathconstants.h" std::map ServerActiveObject::m_types; @@ -190,7 +191,7 @@ public: } ItemSAO(ServerEnvironment *env, v3f pos, - const std::string itemstring): + const std::string &itemstring): ServerActiveObject(env, pos), m_itemstring(itemstring), m_itemstring_changed(false), @@ -349,7 +350,7 @@ private: ItemSAO proto_ItemSAO(NULL, v3f(0,0,0), ""); ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos, - const std::string itemstring) + const std::string &itemstring) { return new ItemSAO(env, pos, itemstring); } @@ -398,7 +399,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, LuaEntitySAO::~LuaEntitySAO() { if(m_registered){ - ENV_TO_SA(m_env)->luaentity_Remove(m_id); + m_env->getScriptIface()->luaentity_Remove(m_id); } } @@ -407,15 +408,18 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s) ServerActiveObject::addedToEnvironment(dtime_s); // Create entity from name - m_registered = ENV_TO_SA(m_env)->luaentity_Add(m_id, m_init_name.c_str()); + m_registered = m_env->getScriptIface()-> + luaentity_Add(m_id, m_init_name.c_str()); if(m_registered){ // Get properties - ENV_TO_SA(m_env)->luaentity_GetProperties(m_id, &m_prop); + m_env->getScriptIface()-> + luaentity_GetProperties(m_id, &m_prop); // Initialize HP from properties m_hp = m_prop.hp_max; // Activate entity, supplying serialized state - ENV_TO_SA(m_env)->luaentity_Activate(m_id, m_init_state.c_str(), dtime_s); + m_env->getScriptIface()-> + luaentity_Activate(m_id, m_init_state.c_str(), dtime_s); } } @@ -522,10 +526,15 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) * dtime * m_acceleration; m_velocity += dtime * m_acceleration; } + + if((m_prop.automatic_face_movement_dir) && + (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)){ + m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset; + } } if(m_registered){ - ENV_TO_SA(m_env)->luaentity_Step(m_id, dtime); + m_env->getScriptIface()->luaentity_Step(m_id, dtime); } if(send_recommended == false) @@ -635,7 +644,8 @@ std::string LuaEntitySAO::getStaticData() os<luaentity_GetStaticdata(m_id); + std::string state = m_env->getScriptIface()-> + luaentity_GetStaticdata(m_id); os<luaentity_Punch(m_id, puncher, + m_env->getScriptIface()->luaentity_Punch(m_id, puncher, time_from_last_punch, toolcap, dir); return result.wear; @@ -715,7 +725,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker) // It's best that attachments cannot be clicked if(isAttached()) return; - ENV_TO_SA(m_env)->luaentity_Rightclick(m_id, clicker); + m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker); } void LuaEntitySAO::setPos(v3f pos) @@ -933,6 +943,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, m_player(player_), m_peer_id(peer_id_), m_inventory(NULL), + m_damage(0), m_last_good_position(0,0,0), m_time_from_last_punch(0), m_nocheat_dig_pos(32767, 32767, 32767), @@ -958,6 +969,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, m_physics_override_speed(1), m_physics_override_jump(1), m_physics_override_gravity(1), + m_physics_override_sneak(true), + m_physics_override_sneak_glitch(true), m_physics_override_sent(false) { assert(m_player); @@ -1014,6 +1027,8 @@ void PlayerSAO::removingFromEnvironment() { m_player->setPlayerSAO(NULL); m_player->peer_id = 0; + m_env->savePlayer(m_player->getName()); + m_env->removePlayer(m_player->getName()); } } @@ -1049,7 +1064,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) os<hp; } +s16 PlayerSAO::readDamage() +{ + s16 damage = m_damage; + m_damage = 0; + return damage; +} + void PlayerSAO::setHP(s16 hp) { s16 oldhp = m_player->hp; @@ -1326,19 +1344,15 @@ void PlayerSAO::setHP(s16 hp) m_player->hp = hp; - if(hp != oldhp) + if(hp != oldhp) { m_hp_not_sent = true; + if(oldhp > hp) + m_damage += oldhp - hp; + } - // On death or reincarnation send an active object message + // Update properties on death if((hp == 0) != (oldhp == 0)) - { - // Will send new is_visible value based on (getHP()!=0) m_properties_sent = false; - // Send new HP - std::string str = gob_cmd_punched(0, getHP()); - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push_back(aom); - } } u16 PlayerSAO::getBreath() const