float32 LandscapeEditorDrawSystem::GetHeightAtTexturePoint(Landscape::eTextureLevel level, const Vector2& point) { if (GetTextureRect(level).PointInside(point)) { return GetHeightAtPoint(TexturePointToHeightmapPoint(level, point)); } return 0.f; }
bool BaseZone::AttemptToPlaceBuildingConnectedToRoad_( BaseBuilding* building, BuildingSize size, uint32 numResidents, uint32 extentsRadius, bool attemptToCenterBuilding, uint32 minDistFromRoad, uint32 maxDistFromRoad ) { // SNOW: do something with attemptToCenterBuilding // Note- there will be a performance increase here if road nodes that are surrounded by buildings are not included in this search Assert( roadNodes_.GetCount() > 0 ); uint32 indexStart = rand() % roadNodes_.GetCount(); bool isFirstIteration = true; int32 i = indexStart; int32 iInc = (rand() % 2) * 2 - 1; while( true ) { if( i < 0 || i == roadNodes_.GetCount() ) { // switch iteration direction and reset to starting point if( isFirstIteration ) { iInc = -iInc; i = indexStart + iInc; isFirstIteration = false; continue; } break; } RoadNode* randomRoadNode = roadNodes_[i]; BaseArea buildingArea; if( roadGenerator_->GetAreaAdjacentToRoadNode( randomRoadNode, buildingArea, extentsRadius * 2, extentsRadius * 2, 1, 5 ) ) { // init entrance. UPoint3D entrance( buildingArea.GetClosestPointInAreaToPoint( *randomRoadNode ) ); //UPoint3D entrance( buildingArea.GetRandBorderPoint( false, false, true, 0.4f ) ); entrance.z = GetHeightAtPoint( entrance.x, entrance.y ); Direction doorSide = buildingArea.GetSideOfArea2DBorderPointIsOn( entrance ); building->SetBounds( entrance, buildingArea.GetMin(), buildingArea.GetMax(), size, doorSide ); if( IsBuildingBoundsPlaceable( buildingArea.GetMin(), buildingArea.GetMax() ) ) { if( building->PlaceRooms( doorSide ) ) { // SNOW: implement this // TODO: add customization options for this Assert( buildings_.GetCount() == connectingRoadNodeForBuildings_.GetCount() ); buildings_.InsertBack( building ); connectingRoadNodeForBuildings_.InsertBack( randomRoadNode ); return true; } return false; // Note- must delete building data after unsuccessful PlaceRooms } } i += iInc; } return false; }