Skip to content

Commit

Permalink
Computing score
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafsson committed May 19, 2012
1 parent 7189019 commit 3f7baf8
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions server/world.cpp
Expand Up @@ -6,6 +6,9 @@
#include <boost/foreach.hpp>
#include <cmath>

#define WARNING_DISTANCE (400ll*100ll)
#define SHAFE_DISTANCE (800ll*100ll)


World::World()
{
Expand Down Expand Up @@ -119,6 +122,7 @@ void World::
else
{
p.timeSinceVisible = 0;
p.newTargetVisibleTime();
// Start growing trail
if (!p.currentPatch)
newPatch = true;
Expand Down Expand Up @@ -170,6 +174,17 @@ void World::
{
p.alive = false;
sender->sendPlayerData(p.id(), "({serverMessage:'Press space to restart',deathByWall:true})");

BOOST_FOREACH(Players::value_type& v2, players)
{
Player& p2 = *v2.second;
if (!p2.alive)
continue;

Position::T d = dist2(p.pos, p2.pos);
if (d<SHAFE_DISTANCE*SHAFE_DISTANCE)
p2.score++;
}
}
}

Expand All @@ -188,15 +203,12 @@ void World::
p.alive = true;
Position::T d = dist2(p.pos, n->pos);

Position::T warning = 400*100;
Position::T kill = 800*100;

if (d>kill*kill)
if (d>SHAFE_DISTANCE*SHAFE_DISTANCE)
{
p.alive = false;
sender->sendPlayerData(p.id(), "({serverMessage:'Press space to restart',deathBySheep:true})");
}
else if (d>warning*warning)
else if (d>WARNING_DISTANCE*WARNING_DISTANCE)
{
sender->sendPlayerData(p.id(), "({serverMessage:'Press space to restart'})");
}
Expand All @@ -209,12 +221,13 @@ void World::
if (!playerPosData.isEmpty())
playerPosData += ",";

playerPosData += QString("{id:%1,pos:[%2,%3],alive:%5,color:'%4'}")
playerPosData += QString("{id:%1,pos:[%2,%3],alive:%5,color:'%4,score:%6'}")
.arg(p.first)
.arg(p.second->pos.x*0.01f)
.arg(p.second->pos.y*0.01f)
.arg(QColor(p.second->rgba).name())
.arg(p.second->alive?"true":"false");
.arg(p.second->alive?"true":"false")
.arg(p.second->score);
}

BOOST_FOREACH(Players::value_type& p, players)
Expand Down

0 comments on commit 3f7baf8

Please sign in to comment.