#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"
LuaEntitySAO::~LuaEntitySAO()
{
if(m_registered){
- ENV_TO_SA(m_env)->luaentity_Remove(m_id);
+ m_env->getScriptIface()->luaentity_Remove(m_id);
}
}
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);
}
}
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)
os<<serializeString(m_init_name);
// state
if(m_registered){
- std::string state = ENV_TO_SA(m_env)->luaentity_GetStaticdata(m_id);
+ std::string state = m_env->getScriptIface()->
+ luaentity_GetStaticdata(m_id);
os<<serializeLongString(state);
} else {
os<<serializeLongString(m_init_state);
m_removed = true;
}
- ENV_TO_SA(m_env)->luaentity_Punch(m_id, puncher,
+ m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
time_from_last_punch, toolcap, dir);
return result.wear;
// 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)
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),
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);
os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
}
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
- os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity)); // 5
+ os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
+ m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
+ m_physics_override_sneak_glitch)); // 5
}
else
{
if(m_physics_override_sent == false){
m_physics_override_sent = true;
- std::string str = gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity);
+ std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
+ m_physics_override_jump, m_physics_override_gravity,
+ m_physics_override_sneak, m_physics_override_sneak_glitch);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
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;
}
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;
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