@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
28
28
#include " server.h"
29
29
#include " scripting_server.h"
30
30
#include " genericobject.h"
31
+ #include < algorithm>
31
32
32
33
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
33
34
@@ -919,9 +920,9 @@ void PlayerSAO::getStaticData(std::string * result) const
919
920
920
921
void PlayerSAO::step (float dtime, bool send_recommended)
921
922
{
922
- if (m_drowning_interval.step (dtime, 2.0 )) {
923
- // get head position
924
- v3s16 p = floatToInt (m_base_position + v3f ( 0 , BS * 1.6 , 0 ), BS);
923
+ if (m_drowning_interval.step (dtime, 2 .0f )) {
924
+ // Get nose/mouth position, approximate with eye position
925
+ v3s16 p = floatToInt (getEyePosition ( ), BS);
925
926
MapNode n = m_env->getMap ().getNodeNoEx (p);
926
927
const ContentFeatures &c = m_env->getGameDef ()->ndef ()->get (n);
927
928
// If node generates drown
@@ -937,32 +938,37 @@ void PlayerSAO::step(float dtime, bool send_recommended)
937
938
}
938
939
}
939
940
940
- if (m_breathing_interval.step (dtime, 0.5 )) {
941
- // get head position
942
- v3s16 p = floatToInt (m_base_position + v3f ( 0 , BS * 1.6 , 0 ), BS);
941
+ if (m_breathing_interval.step (dtime, 0 .5f )) {
942
+ // Get nose/mouth position, approximate with eye position
943
+ v3s16 p = floatToInt (getEyePosition ( ), BS);
943
944
MapNode n = m_env->getMap ().getNodeNoEx (p);
944
945
const ContentFeatures &c = m_env->getGameDef ()->ndef ()->get (n);
945
- // If player is alive & no drowning, breath
946
+ // If player is alive & no drowning, breathe
946
947
if (m_hp > 0 && m_breath < m_prop.breath_max && c.drowning == 0 )
947
948
setBreath (m_breath + 1 );
948
949
}
949
950
950
- if (m_node_hurt_interval.step (dtime, 1.0 )) {
951
- // Feet, middle and head
952
- v3s16 p1 = floatToInt (m_base_position + v3f (0 , BS*0.1 , 0 ), BS);
953
- MapNode n1 = m_env->getMap ().getNodeNoEx (p1);
954
- v3s16 p2 = floatToInt (m_base_position + v3f (0 , BS*0.8 , 0 ), BS);
955
- MapNode n2 = m_env->getMap ().getNodeNoEx (p2);
956
- v3s16 p3 = floatToInt (m_base_position + v3f (0 , BS*1.6 , 0 ), BS);
957
- MapNode n3 = m_env->getMap ().getNodeNoEx (p3);
958
-
951
+ if (m_node_hurt_interval.step (dtime, 1 .0f )) {
959
952
u32 damage_per_second = 0 ;
960
- damage_per_second = MYMAX (damage_per_second,
961
- m_env->getGameDef ()->ndef ()->get (n1).damage_per_second );
962
- damage_per_second = MYMAX (damage_per_second,
963
- m_env->getGameDef ()->ndef ()->get (n2).damage_per_second );
964
- damage_per_second = MYMAX (damage_per_second,
965
- m_env->getGameDef ()->ndef ()->get (n3).damage_per_second );
953
+ // Lowest and highest damage points are 0.1 within collisionbox
954
+ float dam_top = m_prop.collisionbox .MaxEdge .Y - 0 .1f ;
955
+
956
+ // Sequence of damage points, starting 0.1 above feet and progressing
957
+ // upwards in 1 node intervals, stopping below top damage point.
958
+ for (float dam_height = 0 .1f ; dam_height < dam_top; dam_height++) {
959
+ v3s16 p = floatToInt (m_base_position +
960
+ v3f (0 .0f , dam_height * BS, 0 .0f ), BS);
961
+ MapNode n = m_env->getMap ().getNodeNoEx (p);
962
+ damage_per_second = std::max (damage_per_second,
963
+ m_env->getGameDef ()->ndef ()->get (n).damage_per_second );
964
+ }
965
+
966
+ // Top damage point
967
+ v3s16 ptop = floatToInt (m_base_position +
968
+ v3f (0 .0f , dam_top * BS, 0 .0f ), BS);
969
+ MapNode ntop = m_env->getMap ().getNodeNoEx (ptop);
970
+ damage_per_second = std::max (damage_per_second,
971
+ m_env->getGameDef ()->ndef ()->get (ntop).damage_per_second );
966
972
967
973
if (damage_per_second != 0 && m_hp > 0 ) {
968
974
s16 newhp = ((s32) damage_per_second > m_hp ? 0 : m_hp - damage_per_second);
@@ -980,21 +986,20 @@ void PlayerSAO::step(float dtime, bool send_recommended)
980
986
}
981
987
982
988
// If attached, check that our parent is still there. If it isn't, detach.
983
- if (m_attachment_parent_id && !isAttached ())
984
- {
989
+ if (m_attachment_parent_id && !isAttached ()) {
985
990
m_attachment_parent_id = 0 ;
986
991
m_attachment_bone = " " ;
987
- m_attachment_position = v3f (0 , 0 , 0 );
988
- m_attachment_rotation = v3f (0 , 0 , 0 );
992
+ m_attachment_position = v3f (0 . 0f , 0 . 0f , 0 . 0f );
993
+ m_attachment_rotation = v3f (0 . 0f , 0 . 0f , 0 . 0f );
989
994
setBasePosition (m_last_good_position);
990
995
m_env->getGameDef ()->SendMovePlayer (m_peer_id);
991
996
}
992
997
993
998
// dstream<<"PlayerSAO::step: dtime: "<<dtime<<std::endl;
994
999
995
1000
// Set lag pool maximums based on estimated lag
996
- const float LAG_POOL_MIN = 5.0 ;
997
- float lag_pool_max = m_env->getMaxLagEstimate () * 2.0 ;
1001
+ const float LAG_POOL_MIN = 5 .0f ;
1002
+ float lag_pool_max = m_env->getMaxLagEstimate () * 2 .0f ;
998
1003
if (lag_pool_max < LAG_POOL_MIN)
999
1004
lag_pool_max = LAG_POOL_MIN;
1000
1005
m_dig_pool.setMax (lag_pool_max);
@@ -1007,8 +1012,10 @@ void PlayerSAO::step(float dtime, bool send_recommended)
1007
1012
m_time_from_last_punch += dtime;
1008
1013
m_nocheat_dig_time += dtime;
1009
1014
1010
- // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
1011
- // If the object gets detached this comes into effect automatically from the last known origin
1015
+ // Each frame, parent position is copied if the object is attached,
1016
+ // otherwise it's calculated normally.
1017
+ // If the object gets detached this comes into effect automatically from
1018
+ // the last known origin.
1012
1019
if (isAttached ()) {
1013
1020
v3f pos = m_env->getActiveObject (m_attachment_parent_id)->getBasePosition ();
1014
1021
m_last_good_position = pos;
@@ -1018,20 +1025,21 @@ void PlayerSAO::step(float dtime, bool send_recommended)
1018
1025
if (!send_recommended)
1019
1026
return ;
1020
1027
1021
- // If the object is attached client-side, don't waste bandwidth sending its position to clients
1022
- if (m_position_not_sent && ! isAttached ())
1023
- {
1028
+ // If the object is attached client-side, don't waste bandwidth sending its
1029
+ // position to clients.
1030
+ if (m_position_not_sent && ! isAttached ()) {
1024
1031
m_position_not_sent = false ;
1025
1032
float update_interval = m_env->getSendRecommendedInterval ();
1026
1033
v3f pos;
1027
- if (isAttached ()) // Just in case we ever do send attachment position too
1034
+ if (isAttached ()) // Just in case we ever do send attachment position too
1028
1035
pos = m_env->getActiveObject (m_attachment_parent_id)->getBasePosition ();
1029
1036
else
1030
1037
pos = m_base_position;
1038
+
1031
1039
std::string str = gob_cmd_update_position (
1032
1040
pos,
1033
- v3f (0 , 0 , 0 ),
1034
- v3f (0 , 0 , 0 ),
1041
+ v3f (0 . 0f , 0 . 0f , 0 . 0f ),
1042
+ v3f (0 . 0f , 0 . 0f , 0 . 0f ),
1035
1043
m_yaw,
1036
1044
true ,
1037
1045
false ,
@@ -1083,7 +1091,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
1083
1091
}
1084
1092
}
1085
1093
1086
- if (!m_attachment_sent){
1094
+ if (!m_attachment_sent) {
1087
1095
m_attachment_sent = true ;
1088
1096
std::string str = gob_cmd_update_attachment (m_attachment_parent_id,
1089
1097
m_attachment_bone, m_attachment_position, m_attachment_rotation);
0 commit comments