aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-12-04 14:43:01 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-12-04 14:43:01 +0200
commit4cc117ddf6149b5b488e598a620674c8df208eac (patch)
tree32881a0ac8394cf7bdea5ab8dc26195c711a6ed9 /src
parentceaf8edaded4c9e8f2e6fa285d9765e7095df332 (diff)
downloadminetest-4cc117ddf6149b5b488e598a620674c8df208eac.tar.gz
minetest-4cc117ddf6149b5b488e598a620674c8df208eac.tar.bz2
minetest-4cc117ddf6149b5b488e598a620674c8df208eac.zip
Properly use time_from_last_punch for limiting PvP punch damage
Diffstat (limited to 'src')
-rw-r--r--src/materials.cpp4
-rw-r--r--src/server.cpp3
-rw-r--r--src/serverremoteplayer.cpp14
-rw-r--r--src/serverremoteplayer.h5
-rw-r--r--src/tooldef.h2
5 files changed, 21 insertions, 7 deletions
diff --git a/src/materials.cpp b/src/materials.cpp
index 3f88f9d45..d2d37ebf4 100644
--- a/src/materials.cpp
+++ b/src/materials.cpp
@@ -104,9 +104,9 @@ HittingProperties getHittingProperties(const MaterialProperties *mp,
time_from_last_punch);
// If digging time would be 1 second, 2 hearts go in 1 second.
- s16 hp = 2.0 * 2.0 / digprop.time + 0.5;
+ s16 hp = 2.0 * 2.0 / digprop.time;
// Wear is the same as for digging a single node
- s16 wear = (float)digprop.wear + 0.5;
+ s16 wear = (float)digprop.wear;
return HittingProperties(hp, wear);
}
diff --git a/src/server.cpp b/src/server.cpp
index 8fbc0f793..11c11b259 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2964,7 +2964,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
<<pointed.object_id<<std::endl;
// Do stuff
- pointed_object->punch(srp);
+ pointed_object->punch(srp, srp->m_time_from_last_punch);
+ srp->m_time_from_last_punch = 0;
}
} // action == 0
diff --git a/src/serverremoteplayer.cpp b/src/serverremoteplayer.cpp
index 900cc5432..1681900e0 100644
--- a/src/serverremoteplayer.cpp
+++ b/src/serverremoteplayer.cpp
@@ -31,11 +31,11 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
ServerActiveObject(env, v3f(0,0,0)),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
- m_additional_items(),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_respawn_active(false),
m_is_in_environment(false),
+ m_time_from_last_punch(0),
m_position_not_sent(false)
{
}
@@ -43,9 +43,12 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 pee
const char *name_):
Player(env->getGameDef()),
ServerActiveObject(env, pos_),
+ m_last_good_position(0,0,0),
+ m_last_good_position_age(0),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_is_in_environment(false),
+ m_time_from_last_punch(0),
m_position_not_sent(false)
{
setPosition(pos_);
@@ -93,6 +96,8 @@ bool ServerRemotePlayer::unlimitedTransferDistance() const
void ServerRemotePlayer::step(float dtime, bool send_recommended)
{
+ m_time_from_last_punch += dtime;
+
if(send_recommended == false)
return;
@@ -157,9 +162,14 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
HittingProperties hitprop = getHittingProperties(&mp, &tp,
time_from_last_punch);
+ actionstream<<"Player "<<getName()<<" punched by "
+ <<puncher->getDescription()<<", damage "<<hitprop.hp
+ <<" HP"<<std::endl;
+
setHP(getHP() - hitprop.hp);
puncher->damageWieldedItem(hitprop.wear);
-
+
+ if(hitprop.hp != 0)
{
std::ostringstream os(std::ios::binary);
// command (1 = punched)
diff --git a/src/serverremoteplayer.h b/src/serverremoteplayer.h
index 15a9ebc38..bdc3bba20 100644
--- a/src/serverremoteplayer.h
+++ b/src/serverremoteplayer.h
@@ -74,7 +74,8 @@ public:
void rightClick(ServerActiveObject *clicker);
void setPos(v3f pos);
void moveTo(v3f pos, bool continuous);
- virtual std::string getDescription(){return getName();}
+ virtual std::string getDescription()
+ {return std::string("player ")+getName();}
virtual void getWieldDiggingProperties(ToolDiggingProperties *dst);
virtual void damageWieldedItem(u16 amount);
@@ -93,6 +94,8 @@ public:
bool m_hp_not_sent;
bool m_respawn_active;
bool m_is_in_environment;
+ // Incremented by step(), read and reset by Server
+ float m_time_from_last_punch;
private:
bool m_position_not_sent;
diff --git a/src/tooldef.h b/src/tooldef.h
index c30579cb2..68a894898 100644
--- a/src/tooldef.h
+++ b/src/tooldef.h
@@ -38,7 +38,7 @@ struct ToolDiggingProperties
float dd_crumbliness;
float dd_cuttability;
- ToolDiggingProperties(float full_punch_interval_=1.0,
+ ToolDiggingProperties(float full_punch_interval_=2.0,
float a=0.75, float b=0, float c=0, float d=0, float e=0,
float f=50, float g=0, float h=0, float i=0, float j=0);
};