X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fcontent_sao.cpp;h=85ab8d307abe4bb4e36682eea48f92ffe6a6c8bc;hb=68bbdf1b2c1bc70f48d52694411cd7859d09c728;hp=f3ccd6db0fe45de38374b61d77fd71ec78e1253b;hpb=fc571ad46df8f3dcc04745bc55d9ca6e1e82ed87;p=minetest.git diff --git a/src/content_sao.cpp b/src/content_sao.cpp index f3ccd6db0..85ab8d307 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -27,7 +27,7 @@ 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" @@ -399,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); } } @@ -408,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); } } @@ -524,13 +527,14 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) m_velocity += dtime * m_acceleration; } - if(m_prop.automatic_face_movement_dir){ - m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI; + 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) @@ -640,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; @@ -720,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) @@ -938,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), @@ -1294,14 +1300,6 @@ int PlayerSAO::punch(v3f dir, setHP(getHP() - hitparams.hp); - if(hitparams.hp != 0) - { - std::string str = gob_cmd_punched(hitparams.hp, getHP()); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push_back(aom); - } - return hitparams.wear; } @@ -1314,6 +1312,13 @@ s16 PlayerSAO::getHP() const return m_player->hp; } +s16 PlayerSAO::readDamage() +{ + s16 damage = m_damage; + m_damage = 0; + return damage; +} + void PlayerSAO::setHP(s16 hp) { s16 oldhp = m_player->hp; @@ -1331,19 +1336,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