Calculates kills and deaths. You get frags by killing yourself \o/
authorsaiam
Mon, 08 Dec 2008 20:57:16 +0000
changeset 308 60f4b55d5713
parent 307 5b4806c61342
child 309 05a39422c81e
Calculates kills and deaths. You get frags by killing yourself \o/
src/Network/Client.cc
src/Network/Server.cc
src/Player.cc
src/Player.hh
src/Projectile.cc
src/Projectile.hh
--- a/src/Network/Client.cc	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Network/Client.cc	Mon Dec 08 20:57:16 2008 +0000
@@ -370,6 +370,6 @@
     Engine::log(INFO, "client_projectile.hit_player") << this << ": player=" << player << ", damage=" << damage;
     
     // pass on to super
-    Projectile::onHitPlayer(player, damage);
+    Projectile::onHitPlayer(player);
 }
 
--- a/src/Network/Server.cc	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Network/Server.cc	Mon Dec 08 20:57:16 2008 +0000
@@ -314,6 +314,6 @@
     send_all(NETMSG_PROJECTILE_HIT_PLAYER, pkt, true);
 
     // super
-    Projectile::onHitPlayer(player_ptr, damage);
+    Projectile::onHitPlayer(player_ptr);
 }
 
--- a/src/Player.cc	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Player.cc	Mon Dec 08 20:57:16 2008 +0000
@@ -291,13 +291,20 @@
     }
 }
 
-void Player::takeDamage (Health damage) {
-    health -= damage;
+void Player::takeDamage (Projectile *source) {
+    health -= source->getDamage();
 
-    if (health <= 0)
+    if (health <= 0) {
+        source->addKillToOwner();
         die();
+    }
 
-    Engine::log(DEBUG, "player.take_damage") << this << ": damage=" << damage << ", health=" << health;
+    Engine::log(DEBUG, "player.take_damage") << this << ": damage=" << source->getDamage() << ", health=" << health;
+    Engine::log(DEBUG, "player.take_damage") << this << ": kills=" << kills << ", deaths=" << deaths;
+}
+
+void Player::addKill () {
+    kills++;
 }
 
 void Player::draw (Graphics *g, PixelCoordinate camera) {
--- a/src/Player.hh	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Player.hh	Mon Dec 08 20:57:16 2008 +0000
@@ -6,6 +6,7 @@
 class RemotePlayer;
 
 #include "Weapon.hh"
+#include "Projectile.hh"
 #include "GameState.hh"
 #include "PhysicsObject.hh"
 #include "Input.hh"
@@ -132,7 +133,12 @@
      *
      * XXX: should this take the Projectile instead or somesuch?
      */
-    void takeDamage (Health damage);
+    void takeDamage (Projectile *source);
+
+    /**
+     * Increment player killcounter by one.
+     */
+    void addKill ();
 
     /*
      * Drawing requires the skin texture, which is loaded on-demand when draw is called
--- a/src/Projectile.cc	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Projectile.cc	Mon Dec 08 20:57:16 2008 +0000
@@ -36,9 +36,17 @@
 
     destroy();
 }
-    
-void Projectile::onHitPlayer (Player *player, Health damage) {
-    player->takeDamage(damage);
+
+Health Projectile::getDamage () {
+    return weapon->getDamage();
+}
+
+void Projectile::addKillToOwner () {
+    player->addKill();
+} 
+   
+void Projectile::onHitPlayer (Player *player) {
+    player->takeDamage(this);
 }
 
 void Projectile::onCollision (Vector collisionPoint, PhysicsObject *other) {
@@ -47,7 +55,7 @@
         Player* player = dynamic_cast<Player*>(other);
 
         // XXX: check that player really is !NULL
-        onHitPlayer(player, weapon->getDamage());
+        onHitPlayer(player);
     }
 
     if (collision_elasticity == 0)
--- a/src/Projectile.hh	Mon Dec 08 20:33:40 2008 +0000
+++ b/src/Projectile.hh	Mon Dec 08 20:57:16 2008 +0000
@@ -51,6 +51,18 @@
      */
     virtual void draw (Graphics *g, PixelCoordinate camera) const;
 
+    /**
+     * Get damage inflicted by this projectile.
+     *
+     * @return Damage inflicted by projectile.
+     */
+    Health getDamage ();
+
+    /**
+     * Adds one kill to projectile owner.
+     */
+    void addKillToOwner ();
+
 protected:
     /**
      * Removes ground at given position if applicable, and destroys this PhysicsObject.
@@ -65,7 +77,7 @@
      * This Projectile inflicts a certain amount of damage on the player. We are not destroyed, this can be called
      * multiple times...
      */
-    virtual void onHitPlayer (Player *player, Health damage);
+    virtual void onHitPlayer (Player *player);
     
     /**
      * Call onDestroy, removingGround