void Triangle::SetPosition(const Vector2D& position) { double deltaX = position.GetX() - GetX(); double deltaY = position.GetY() - GetY(); double aX = GetPointA().GetX() + deltaX; double bX = GetPointB().GetX() + deltaX; double cX = GetPointC().GetX() + deltaX; double aY = GetPointA().GetY() + deltaY; double bY = GetPointB().GetY() + deltaY; double cY = GetPointC().GetY() + deltaY; SetPoints(aX, aY, bX, bY, cX, cY); _position = Vector2D((aX + bX + cX) / 3.0, (aY + bY + cY) / 3.0); }
/// Baut eine (bisher noch visuell gebaute) Straße wieder zurück void GameWorldBase::RemoveVisualRoad(unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route) { // Wieder zurückbauen for(unsigned z = 0;z<route.size();++z) { if (!GetPointRoad(start_x,start_y, route[z], false)) { SetPointVirtualRoad(start_x,start_y, route[z],0); CalcRoad(start_x,start_y,GAMECLIENT.GetPlayerID()); } GetPointA(start_x,start_y,route[z]); } }
bool Triangle::Intersects(const a2de::Vector2D& position) const { Vector3D A(GetPointA().GetX(), GetPointA().GetY()); Vector3D B(GetPointB().GetX(), GetPointB().GetY()); Vector3D C(GetPointC().GetX(), GetPointC().GetY()); Vector3D AB(A - B); Vector3D BC(B - C); Vector3D CA(C - A); Vector3D AP(A - position); Vector3D BP(B - position); Vector3D CP(C - position); Vector3D resultABAP(Vector3D::CrossProduct(AB, AP)); Vector3D resultBCBP(Vector3D::CrossProduct(BC, BP)); Vector3D resultCACP(Vector3D::CrossProduct(CA, CP)); bool resultPos = (resultABAP.GetZ() > 0.0) && (resultBCBP.GetZ() > 0.0) && (resultCACP.GetZ() > 0.0); bool resultZero = (Math::IsEqual(resultABAP.GetZ(), 0.0) && Math::IsEqual(resultBCBP.GetZ(), 0.0) && Math::IsEqual(resultCACP.GetZ(), 0.0)); bool resultNeg = (resultABAP.GetZ() < 0.0) && (resultBCBP.GetZ() < 0.0) && (resultCACP.GetZ() < 0.0); //bool isOn = point.IsOnLine(GetLineAB()) || point.IsOnLine(GetLineBC()) || point.IsOnLine(GetLineCA()); return (/*isOn ||*/ resultPos || resultZero || resultNeg); }
/// Ist es an dieser Stelle für einen Spieler möglich einen Hafen zu bauen bool GameWorldBase::IsHarborPointFree(const unsigned harbor_id, const unsigned char player, const unsigned short sea_id) const { Point<MapCoord> coords(GetHarborPoint(harbor_id)); // Befindet sich der Hafenpunkt auch an dem erforderlichen Meer? bool at_sea = false; for(unsigned i = 0;i<6;++i) { if(harbor_pos[harbor_id].cps[i].sea_id == sea_id) { at_sea = true; break; } } if(!at_sea) return false; // Überprüfen, ob das Gebiet in einem bestimmten Radius entweder vom Spieler oder gar nicht besetzt ist for(MapCoord tx=GetXA(coords.x,coords.y,0), r=1;r<=4;tx=GetXA(tx,coords.y,0),++r) { MapCoord tx2 = tx, ty2 = coords.y; for(unsigned i = 2;i<8;++i) { for(MapCoord r2=0;r2<r;GetPointA(tx2,ty2,i%6),++r2) { unsigned char owner = GetNode(tx2,ty2).owner; if(owner != 0 && owner != player+1) return false; } } } return (CalcBQ(coords.x,coords.y,0,false,false,true) == BQ_HARBOR); }
void Triangle::SetPointC(const Point& C) { SetPoints(GetPointA(), GetPointB(), C); }
void Triangle::SetPointB(const Point& B) { SetPoints(GetPointA(), B, GetPointC()); }
void Triangle::SetPointC(const Vector2D& position) { SetPoints(GetPointA(), GetPointB(), Point(position)); }
bool Triangle::IsRightTriangle() const { double AC = Point::GetDistanceSquared(GetPointA(), GetPointC()); double CB = Point::GetDistanceSquared(GetPointC(), GetPointB()); double AB = Point::GetDistanceSquared(GetPointA(), GetPointB()); return (Math::IsEqual(AC + CB, AB)); }