Skip to content

Commit

Permalink
TestNode/MapPoint #2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusSt committed Jul 29, 2015
1 parent 5fec986 commit 395e4da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/TerritoryRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ bool TerritoryRegion::IsPointValid(GameWorldBase* gwb, std::vector< MapPoint > &
IsPointInPolygon(gwb, polygon, pt4));
}


void TerritoryRegion::TestNode( int x, int y, const unsigned char player, const unsigned char radius, const bool check_barriers)
void TerritoryRegion::TestNode(MapPoint pt, const unsigned char player, const unsigned char radius, const bool check_barriers)
{
int x = static_cast<int>(pt.x), y = static_cast<int>(pt.y);

// Gucken, ob der Punkt �berhaupt mit in diese Region geh�rt
if(x + gwb->GetWidth() >= int(x1) && x + gwb->GetWidth() < int(x2))
x += gwb->GetWidth();
Expand All @@ -106,13 +107,14 @@ void TerritoryRegion::TestNode( int x, int y, const unsigned char player, const
return;

// check whether his node is within the area we may have territory in
if (check_barriers && !IsPointValid(gwb, gwb->GetPlayer(player)->GetRestrictedArea(), MapPoint(x, y)))
if (check_barriers && !IsPointValid(gwb, gwb->GetPlayer(player)->GetRestrictedArea(), pt))
return;

/// Wenn das Militargeb�ude jetzt n�her dran ist, dann geht dieser Punkt in den Besitz vom jeweiligen Spieler
/// oder wenn es halt gar nicht besetzt ist
unsigned idx = (y - y1) * (x2 - x1) + (x - x1);
if(radius < nodes[idx].radius || !nodes[(y - y1) * (x2 - x1) + (x - x1)].owner)

if(radius < nodes[idx].radius || !nodes[idx].owner)
{
nodes[idx].owner = player + 1;
nodes[idx].radius = radius;
Expand All @@ -137,7 +139,7 @@ void TerritoryRegion::CalcTerritoryOfBuilding(const noBaseBuilding* const buildi

// Punkt, auf dem das Milit�rgeb�ude steht
MapPoint pt = building->GetPos();
TestNode(pt.x, pt.y, building->GetPlayer(), 0, false); // no need to check barriers here. this point is on our territory.
TestNode(pt, building->GetPlayer(), 0, false); // no need to check barriers here. this point is on our territory.

for(unsigned r = 1; r <= radius; ++r)
{
Expand All @@ -148,14 +150,10 @@ void TerritoryRegion::CalcTerritoryOfBuilding(const noBaseBuilding* const buildi
{
for(unsigned short i = 0; i < r; ++i)
{
TestNode(pt.x, pt.y, building->GetPlayer(), r, check_barriers);
TestNode(pt, building->GetPlayer(), r, check_barriers);
// Nach rechts oben anfangen
pt = gwb->GetNeighbour(pt, (2 + dir) % 6);
}
}
}
}


//for(unsigned short x = fx;x < building->GetX()-radius+(y+(building->GetY()&1))/2+radius*2+1-y;++x)
// TestNode(x,building->GetY()+y,building->GetPlayer(),y);
3 changes: 2 additions & 1 deletion src/TerritoryRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class TerritoryRegion
static bool IsPointInPolygon(GameWorldBase* gwb, std::vector< MapPoint > &polygon, const MapPoint pt);

/// Testet einen Punkt, ob der neue Spieler ihn übernehmen kann und übernimmt ihn ggf.
void TestNode( int x, int y, const unsigned char player, const unsigned char radius, const bool check_barriers);
void TestNode(MapPoint pt, const unsigned char player, const unsigned char radius, const bool check_barriers);

/// Unterfunktionen von AdjustBorders, vergleicht 2 Punkte, ob sie von unterschiedlichen Spielern sind und setzt
/// Punkt ggf. zu gar keinem Spieler, 2. Funktion wird für Punkte im 2er Abstand verwendet, da es dort ein bisschen anders läuft!
void AdjustNodes(const unsigned short x1, const unsigned short y1, const unsigned short x2, const unsigned short y2);
Expand Down

0 comments on commit 395e4da

Please sign in to comment.