Ejemplo n.º 1
0
void Zone::addSelection(VolumeSelection* Selection)
{
	MapCoordinates Origin = Selection->OriginLocation;
	MapCoordinates Terminal = Selection->TerminalLocation;

	for (int x = Origin.X; x < Terminal.X; x++)
	{
		for (int y = Origin.Y; y < Terminal.Y; y++)
		{
			for (int z = Origin.Z; z < Terminal.Z; z++)
			{
				MapCoordinates ZoneCube = MapCoordinates(x, y, z);
				CellCoordinates ZoneCell = CellCoordinates(ZoneCube);

				std::map< uint64_t, bitset <CUBESPERCELL>* >::iterator it = ZoneMap.find(ZoneCell.Key());
				if (it != ZoneMap.end())
				{
					bitset<CUBESPERCELL>* Bits = it->second;
					Bits->set(ZoneCube.Cube(), true);
				} else {
					bitset<CUBESPERCELL>* Bits = new bitset<CUBESPERCELL>;
					Bits->set(ZoneCube.Cube(), true);
					ZoneMap[ZoneCell.Key()] = Bits;
				}
			}
		}
	}
}
Ejemplo n.º 2
0
inline bool AStar::ExpandNode()
{
    // Get the min-weight element off the fringe.
    std::pop_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
    CurrentNode = FringeNodes.back();
    FringeNodes.pop_back();

    MapCoordinates TestCoordinates = CurrentNode->LocationCoordinates;

    if (VisitedCoordinates.find(TestCoordinates) != VisitedCoordinates.end())
    {
        return false;
    }

    if (TestCoordinates == GoalCoordinates)
    {
        return true; //GenerateBestPath();
    }

    // mark as VisitedCoordinates if not already VisitedCoordinates
    VisitedCoordinates.insert(TestCoordinates);

    MapCoordinates NeiboringCoordinates;
    DirectionFlags TestDirections = SearchGraph->getDirectionFlags(TestCoordinates);

    // Check all Neibors
	for (uint8_t i = 0, DirectionType = Direction::ANGULAR_DIRECTIONS[i]; i < NUM_ANGULAR_DIRECTIONS; ++i, DirectionType = Direction::ANGULAR_DIRECTIONS[i])
    {
        if (TestDirections & (1 << i))  // Connectivity is valid for this direction
        {
            NeiboringCoordinates = TestCoordinates;
            NeiboringCoordinates.TranslateMapCoordinates(DirectionType);

            // If Coordinate is not already on the VisitedCoordinates list
            if (VisitedCoordinates.find(NeiboringCoordinates) == VisitedCoordinates.end())
            {
                float EdgeCost = SearchGraph->getEdgeCost(TestCoordinates, DirectionType);
                GraphReads++;

                AStarNode* NewNode = NodePool->ProvideObject();
                NewNode->Set(NeiboringCoordinates, CurrentNode, DirectionType, CurrentNode->PathLengthFromStart + EdgeCost, MainHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates), TieBreakerHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates));

                // Add the new Node to the Fringe
                FringeNodes.push_back(NewNode);
                std::push_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
            }
        }
    }

    return false; // Goal was not found
}
Ejemplo n.º 3
0
bool Zone::isCoordinateInZone(MapCoordinates TestCoordinates)
{
	std::map< uint64_t, bitset <CUBESPERCELL>* >::iterator it = ZoneMap.find(CellCoordinates(TestCoordinates).Key());
	if (it != ZoneMap.end())
	{
		return it->second->test(TestCoordinates.Cube());
	} else {
		return false;
	}
}
Ejemplo n.º 4
0
bool Map::hasFace(MapCoordinates Coordinates, Direction DirectionType) const
{
    MapCoordinates TargetMapCoordinates = Coordinates;
    Direction TargetFace = DirectionType;

    if (isDirectionPositive(DirectionType)) // East, South and Top Directions get translated to adjacent Cells avoiding a bounce back call
    {
        // Do something for edge of Map cases??
        TargetMapCoordinates.TranslateMapCoordinates(DirectionType);
        TargetFace = OppositeDirection(TargetFace);
    }

    CellCoordinates TargetCellCoordinates = CellCoordinates(TargetMapCoordinates);
    Cell* TargetCell = getCell(TargetCellCoordinates);

    if (TargetCell != NULL)
    {
        return TargetCell->hasFace(CubeCoordinates(TargetMapCoordinates), TargetFace);
    }
    return false;
}
Ejemplo n.º 5
0
void Map::Dig(MapCoordinates Coordinates)
{
    static int16_t FloorID = DATA->getLabelIndex("TILESHAPE_FLOOR");
    static int16_t RoughWallID = DATA->getLabelIndex("SURFACETYPE_ROUGH_WALL");
    static int16_t RoughFloorID = DATA->getLabelIndex("SURFACETYPE_ROUGH_FLOOR_1");

    if (isCubeInited(Coordinates))
    {
        if(isCubeSolid(Coordinates) || isCubeSloped(Coordinates))
        {
            for(Direction DirectionType = AXIAL_DIRECTIONS_START; DirectionType < NUM_AXIAL_DIRECTIONS; ++DirectionType)
            {
                MapCoordinates ModifiedCoordinates = Coordinates;
                ModifiedCoordinates.TranslateMapCoordinates(DirectionType);

                if (DirectionType == DIRECTION_DOWN)
                {
                    if (isCubeSolid(ModifiedCoordinates))
                    {
                        Face* TargetFace = getFace(Coordinates, DirectionType);
                        if (TargetFace == NULL)
                        {
                            TargetFace = addFace(Coordinates, DIRECTION_DOWN);
                        }

                        TargetFace->MaterialTypeID = getCubeMaterial(ModifiedCoordinates);
                        TargetFace->NegativeAxisSurfaceTypeID = RoughFloorID;
                        TargetFace->PositiveAxisSurfaceTypeID = RoughFloorID;
                    }
                    else
                    {
                        removeFace(Coordinates, DirectionType);
                    }
                }
                else
                {
                    if (isCubeSolid(ModifiedCoordinates))
                    {
                        Face* TargetFace = getFace(Coordinates, DirectionType);
                        if (TargetFace == NULL)
                        {
                            TargetFace = addFace(Coordinates, DirectionType);
                        }

                        TargetFace->MaterialTypeID = getCubeMaterial(ModifiedCoordinates);
                        TargetFace->NegativeAxisSurfaceTypeID = getCubeSurfaceType(ModifiedCoordinates);
                        TargetFace->PositiveAxisSurfaceTypeID = getCubeSurfaceType(ModifiedCoordinates);
                    }
                    else
                    {
                        removeFace(Coordinates, DirectionType);
                    }
                }
            }

            setCubeHidden(Coordinates, false);
            setCubeShape(Coordinates, FloorID);

            setCubeMaterial(Coordinates, -1);
        }

        // reveal tiles around
        for(Direction DirectionType = COMPASS_DIRECTIONS_START; DirectionType < NUM_COMPASS_DIRECTIONS; ++DirectionType)
        {
            setCubeHidden(MapCoordinates(Coordinates, DirectionType), false);
        }
    }
}
Ejemplo n.º 6
0
void Cell::BuildFaceData()
{
	Map* ParentMap = GAME->getMap();
    MapCoordinates TargetMapCoordinates;
    bool Debug = true;

    CubeCoordinates TargetCube = 0;
    do
    {
        CubeShape Shape = getCubeShape(TargetCube);
        int16_t CubeMaterial = getCubeMaterial(TargetCube);

        //static int16_t NEHEMaterial = DATA->getLabelIndex("MATERIAL_UNINITIALIZED");
        static int16_t WallSurface = DATA->getLabelIndex("SURFACETYPE_ROUGH_WALL");
        static int16_t FloorSurface = DATA->getLabelIndex("SURFACETYPE_ROUGH_FLOOR_1");

        for (uint8_t i = 0, DirectionType = Direction::AXIAL_DIRECTIONS[i]; i < NUM_AXIAL_DIRECTIONS; ++i, DirectionType = Direction::AXIAL_DIRECTIONS[i])
        {
            FaceCoordinates FaceLocation = FaceCoordinates(TargetCube, DirectionType);
            MapCoordinates ModifiedCoordinates = MapCoordinates(thisCellCoordinates, TargetCube);
            ModifiedCoordinates.TranslateMapCoordinates(DirectionType);

            CubeShape AdjacentShape = ParentMap->getCubeShape(ModifiedCoordinates);

            if (!Shape.isSky())
            {
                if (ParentMap->isCubeInited(ModifiedCoordinates) && AdjacentShape.isSky())
                {
                    if (Shape.hasFace(DirectionType))
                    {
                        Face* NewFace = ParentMap->addFace(MapCoordinates(thisCellCoordinates, TargetCube), DirectionType);

                        NewFace->setFaceMaterialType(CubeMaterial);
                        NewFace->setFaceSurfaceType(WallSurface);
                        NewFace->setFaceShapeType(FaceShape(Shape, DirectionType));
                    }
                }

                if (!AdjacentShape.isEmpty())
                {
                    if (DirectionType == DIRECTION_DOWN && Shape.hasFloor())
                    {
                        Face* NewFace = ParentMap->addFace(MapCoordinates(thisCellCoordinates, TargetCube), DirectionType);

                        NewFace->setFaceMaterialType(ParentMap->getCubeMaterial(ModifiedCoordinates));
                        NewFace->setFaceSurfaceType(FloorSurface);
                        NewFace->setFaceShapeType(FaceShape(Shape, DirectionType));
                    }
                }
            }
        }

        if (!Shape.isEmpty() && !Shape.isSolid())
        {
            Face* NewFace = addFace(FaceCoordinates(TargetCube, DIRECTION_NONE));

            NewFace->setFaceMaterialType(CubeMaterial);
            NewFace->setFaceSurfaceType(FloorSurface);
            NewFace->setFaceShapeType(FaceShape(Shape, DIRECTION_NONE));
        }

        TargetCube++;

    }
    while (TargetCube != 0);  // End Loop when Byte rolls over
	Render->setDirty();
}