public MapSelection(IntVector3 start, IntVector3 end) : this() { this.SelectionStart = start; this.SelectionEnd = end; this.IsSelectionValid = true; }
public void MoveTo(ContainerObject dst, IntVector3 dstLoc) { var src = this.Container; var srcLoc = this.Location; if (src != dst) { if (src != null) src.RemoveChild(this); this.Container = dst; } if (srcLoc != dstLoc) { this.Location = dstLoc; if (dst != null && src == dst) dst.MoveChild(this, srcLoc, dstLoc); } if (src != dst) { if (dst != null) dst.AddChild(this); } if (src != dst || srcLoc != dstLoc) if (ObjectMoved != null) ObjectMoved(this, this.Container, this.Location); }
/// <summary> /// Find route from src to dst, using the given positionings /// </summary> public static AStarResult Find(IEnvironmentObject env, IntVector3 src, DirectionSet srcPositioning, IntVector3 dst, DirectionSet dstPositioning, int maxNodeCount = 200000, CancellationToken? cancellationToken = null) { var initLocs = env.GetPositioningLocations(src, srcPositioning); var target = new AStarDefaultTarget(env, dst, dstPositioning); return Find(initLocs, target, maxNodeCount, cancellationToken); }
public static bool isInsideMapData(int[,,]mapData, IntVector3 point) { return (point.x >= 0 && point.y >= 0 && point.z >= 0 && mapData.GetLength (0) > point.x && mapData.GetLength (1) > point.y && mapData.GetLength (2) > point.z); }
public static ArrayList findDetachedVoxels(int [,,] mapData, int stopCode, IntVector3 point) { /* where i,j,k is a recently destroyed block, returns a list of IntVector3s of all blocks that should be detached, as well as the size of the blob that would contain them. */ ArrayList detachedVoxels = new ArrayList (); allVisitedVoxels = new ArrayList (); ArrayList seeds = MDView.getNeighbors (mapData, point); for (int index=0; index<seeds.Count; index++) { IntVector3 seedPoint = (IntVector3)seeds [index]; if (allVisitedVoxels.Contains (seedPoint)) { seeds.Remove (seedPoint); index--; continue; } ArrayList newVoxels = getBlob (mapData, stopCode, seedPoint); if (newVoxels.Count > 0) { detachedVoxels.AddRange (newVoxels); } } return detachedVoxels; }
public override bool Sees(IntVector3 p) { if (!m_environment.Contains(p)) return false; return GetVisible(p); }
/* Parallel */ /// <summary> /// Returns if dst can be reached from src /// </summary> public static bool CanReach(IEnvironmentObject env, IntVector3 src, IntVector3 dst, DirectionSet dstPositioning) { Debug.Assert(env != null); // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked CancellationTokenSource cts = new CancellationTokenSource(); AStarResult resBackward = null; AStarResult resForward = null; var taskForward = new Task(delegate { resForward = Find(env, src, DirectionSet.Exact, dst, dstPositioning, 200000, cts.Token); }); taskForward.Start(); var taskBackward = new Task(delegate { resBackward = Find(env, dst, dstPositioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token); }); taskBackward.Start(); Task.WaitAny(taskBackward, taskForward); cts.Cancel(); Task.WaitAll(taskBackward, taskForward); if (resForward.Status == AStarStatus.Found || resBackward.Status == AStarStatus.Found) return true; else return false; }
public override Voxel GenerateVoxel(IntVector3 pos) { var distance = pos.DistanceTo(IntVector3.Zero); if (distance < half) return new Voxel { Weight = 255 }; /* var polarPos = SphericalPosition.FromCartesian(pos.X, pos.Y, pos.Z); if (polarPos.Radius < half) { //var noiseVal = (float)gen.GetValue(polarPos.Azimuth, polarPos.Inclination, Seed); //var radHere = (float)(noiseVal + 1f / 2f) * Size; //if (radHere < half) return new Voxel(1f); } // the easy way to generate a sphere //if(pos.DistanceTo(IntVector3.Zero) < half) // return new Voxel(1f); */ return Voxel.Empty; }
public void InitializeWorld(World world, IntSize3 size) { CreateTerrain(size); IntVector3? stairs = null; foreach (var p2 in m_terrainData.Size.Plane.Range()) { var p = new IntVector3(p2, m_terrainData.Size.Depth - 1); var td = m_terrainData.GetTileData(p.Down); if (td.ID == TileID.Stairs) { stairs = p; break; } } if (stairs.HasValue == false) throw new Exception(); m_env = EnvironmentObject.Create(world, m_terrainData, VisibilityMode.LivingLOS, stairs.Value); CreateMonsters(); CreateDebugMonsterAtEntry(); }
// I/F public bool Contains(IntVector3 eyePosition, IntVector3 point) { int distanceSquared; IntVector3.DistanceSquared(ref eyePosition, ref point, out distanceSquared); return distanceSquared <= radiusSquared; }
public static TerrainData CreateBallMap(IntSize3 size, int innerSide = 0) { var map = new TerrainData(size); int side = MyMath.Min(size.Width, size.Height, size.Depth); int r = side / 2 - 1; int ir = innerSide / 2 - 1; Parallel.For(0, size.Depth, z => { for (int y = 0; y < size.Height; ++y) for (int x = 0; x < size.Width; ++x) { var pr = Math.Sqrt((x - r) * (x - r) + (y - r) * (y - r) + (z - r) * (z - r)); var p = new IntVector3(x, y, z); if (pr < r && pr >= ir) map.SetTileDataNoHeight(p, TileData.GetNaturalWall(MaterialID.Granite)); else map.SetTileDataNoHeight(p, TileData.EmptyTileData); } }); map.RescanLevelMap(); return map; }
public static void Calculate3(IntVector3 viewerLocation, int visionRange, VisionMap visibilityMap, IntSize3 mapSize, Func<IntVector3, bool> blockerDelegate) { visibilityMap.Clear(); if (blockerDelegate(viewerLocation) == true) return; var g = new IntGrid3(new IntVector3(), mapSize); g = g.Offset(-viewerLocation.X, -viewerLocation.Y, -viewerLocation.Z); var vr = new IntVector3(visionRange, visionRange, visionRange); g = g.Intersect(new IntGrid3(vr, -vr)); int visionRangeSquared = (visionRange + 1) * (visionRange + 1); // +1 to get a bit bigger view area foreach (var dst in g.Range()) { if (dst.LengthSquared > visionRangeSquared) continue; bool vis = FindLos3(viewerLocation, dst, blockerDelegate); visibilityMap[dst] = vis; // XXX Cheat a bit so that the floor will be visible if (vis && dst.Z == 0 && viewerLocation.Z > 1) { visibilityMap[dst.SetZ(dst.Z - 1)] = true; } } }
/// <summary> /// Creates a new Chunk of size chunkSize x chunkSize x chunkSize, filled with null blocks. /// This is for chunks that are part of the map. /// It will assume that its north-west-bottom corner is at pos * chunkSize, /// and (when implemented...) it will save its data to "pos.x,pos.y,pos.z".xml /// </summary> /// <param name="layers"></param> /// <param name="pos"></param> public Chunk(IntVector3 pos, GraphicsDevice graphics) { size = Sizes.ChunkSize; blocks = new Block[Sizes.ChunkSize, Sizes.ChunkSize, Sizes.ChunkSize]; structures = new List<MapStructure>(); position = pos; filename = MainGame.WorldFolder + position.X + "," + position.Y + "," + position.Z; try { vBuff = new DynamicVertexBuffer(graphics, typeof(VertexPositionColorNormal), maxVerts, BufferUsage.WriteOnly); //vBuff.ContentLost += new EventHandler<EventArgs>(verticesLostHandler); iBuff = new DynamicIndexBuffer(graphics, IndexElementSize.SixteenBits, maxInds, BufferUsage.WriteOnly); //iBuff.ContentLost += new EventHandler<EventArgs>(indicesLostHandler); //so do I need to add a custom test for content lost before drawing? } catch(OpenTK.Graphics.GraphicsContextException e) { Logger.Log(e.ToString()); } vertices = new VertexPositionColorNormal[0]; indices = new short[0]; }
public MineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType) : base(parent) { m_environment = environment; m_location = location; m_mineActionType = mineActionType; }
List<TexturedVertex> GenerateVertsFor(VoxelContainer data, IntVector3 start, IntVector3 end) { var verts = new List<TexturedVertex>(); var here = new IntVector3(data.Start); //Voxel currentVoxel; Vector3[] currentVerts; Vector2[] currentUVs; for (here.X = start.X; here.X <= end.X; here.X++) for (here.Z = start.Z; here.Z <= end.Z; here.Z++) for (here.Y = start.Y; here.Y <= end.Y; here.Y++) { //currentVoxel = data.GetVoxel(here); foreach (var face in VoxelHelper.VisibleFacesFor(data, here)) { currentVerts = VoxelHelper.FaceVerts(here, face).ToArray(); currentUVs = VoxelHelper.UVCoords(data.GetVoxel(here).Type, face, Atlas).ToArray(); verts.AddRange(new []{ new TexturedVertex(currentVerts[0], currentUVs[0]), new TexturedVertex(currentVerts[1], currentUVs[1]), new TexturedVertex(currentVerts[2], currentUVs[2]), new TexturedVertex(currentVerts[3], currentUVs[3]) }); } } return verts; }
public void applyActions(BlobManager blobManager) { /* when a blob is in the process of moving its voxels to another blob, it keeps track of actions made to it like setCorrupt and setBroken, so it can apply them to the new blob as well once it finishes building. */ IntVector3 blobPosition = blobManager.getRealPosition (); IntVector3 offset = new IntVector3 (blobPosition.x - getRealPosition ().x, blobPosition.y - getRealPosition ().y, blobPosition.z - getRealPosition ().z); /* Debug.Log ("applyActions blobPosition: "+ZTools.toString(blobPosition)); Debug.Log ("applyActions position: "+ZTools.toString(position)); Debug.Log ("applyActions getRealPosition: "+ZTools.toString(getRealPosition())); */ foreach (BlobAction action in blobManager.blobActions) { IntVector3 point = new IntVector3 (action.point.x + offset.x, action.point.y + offset.y, action.point.z + offset.z); if (action.action == "setBroken") { //Debug.Log("zz setBroken "+iOffset+" joff "+jOffset+" koff "+kOffset); setBroken (point); continue; } if (action.action == "setCorrupt") { //Debug.Log("ioff "+iOffset+" joff "+jOffset+" koff "+kOffset); setCorrupt (point); continue; } } blobManager.blobActions = new ArrayList (); }
public static int[,,] gen(VoxelTheme voxelTheme, IntVector3 size) { int [,,] mapData = new int[size.x, size.y, size.z]; int maxPercent = 30; int engineCount = 0; int percent = Random.Range (0, maxPercent); int iSquare = size.x * percent / 100; int kSquare = size.z * (maxPercent - percent - 1) / 100; Square baseSquare = new Square (iSquare, kSquare, size.x - 2 * iSquare, size.z - 2 * kSquare); mapData = MDController.combine (mapData, genPlatformBase (voxelTheme, size.x, size.z, baseSquare), 0, 0, 0); mapData = MDController.combine (mapData, genPlatformPlate (voxelTheme, baseSquare.width, baseSquare.height), baseSquare.x, 1, baseSquare.y); int minFractalSpacing = 1; foreach (Square square in ZTools.getFractalSquares(new Square( 0,0,baseSquare.width ,baseSquare.height),minFractalSpacing)) { int i = square.x + baseSquare.x; int k = square.y + baseSquare.y; int j = 1 + MDView.getMapHeight (mapData, i + square.width / 2, k + square.height / 2); mapData = MDController.combine (mapData, GreebleGenerator.gen (voxelTheme, square.width, size.y - j, square.height), i, j, k); if (Random.Range (0, engineCount / 3 + 1) == 0) { if (mapData.GetLength (1) > j) mapData [i + square.width / 2, j, k + square.height / 2] = voxelTheme.getCode ("engine"); engineCount++; } } return mapData; }
protected MoveBaseAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location) : base(parent) { this.Environment = environment; this.Location = location; m_state = 0; }
public static int[,,] genFootballPosts(VoxelTheme voxelTheme, IntVector3 destination, int width, int addedHeight) { int cageHeight=5; int[,,] newData = genMapDataFromPoint (destination, width,addedHeight+cageHeight); int iSize = newData.GetLength (0); int jSize = newData.GetLength (1); if (iSize < 3 || width<3 || jSize/iSize>1) return genBasic (voxelTheme, destination, width); IntVector3 lastHopPoint = new IntVector3 (0, 0, -1); int stepSpacing=5; foreach (IntVector3 hopPoint in getHopArray(iSize,jSize-addedHeight,stepSpacing)) { IntVector3 offset = new IntVector3 (hopPoint.x, hopPoint.y+addedHeight-1, 0); int[,,] cageData=new int[1,cageHeight-1,width]; cageData=MDController.combine(cageData,GreebleGenerator.genCage(voxelTheme,1,cageHeight,width)); newData = MDController.combine (newData, cageData, offset); if (lastHopPoint.z != -1) { offset = new IntVector3 (lastHopPoint.x,0,width/2); int underhangAddedHeight=Mathf.Min (hopPoint.y,lastHopPoint.y)+addedHeight; int[,,] underhangData=ShapeGenerator.genUnderhang(voxelTheme, hopPoint,lastHopPoint,underhangAddedHeight); newData = MDController.combine (newData, underhangData, offset); } lastHopPoint = hopPoint; } return rotateMapData (newData, destination); }
public static int[,] getCollisionArray(int[,,]mapData, IntVector3 direction) { /* where direction is a unit vector, pointing in the direction mapData is travelling the direction vector decides what the collision plane will be. for example the collision plane of a moving car is vertical, like the surface of a brick wall, in front of the car. the returned collisionArray is the heights of the nearest voxel lining up to each (x,y) of that plane. */ //Debug.Log ("getCollisionArray " + direction.i + " " + direction.j + " " + direction.k); if (! direction.isOrthogonalUnitVector ()) Debug.Log ("warning: getCollisionArray didn't get a unit vector."); IntVector2 arraySize = getCollisionArraySize (mapData, direction); int [,] collisionArray = new int [arraySize.x, arraySize.y]; for (int xOffset=0; xOffset<arraySize.x; xOffset++) { for (int yOffset=0; yOffset<arraySize.y; yOffset++) { int dist = getClosestVoxelDistance (mapData, xOffset, yOffset, direction); collisionArray [xOffset, yOffset] = dist; if (dist != -1) { //Debug.Log ("xoffset: " + xOffset + " yoffset: " + yOffset + " dist: " + dist); } } } return collisionArray; }
public void AdjustRiver() { int minZ = m_riverPath.Min(p => m_terrain.GetSurfaceLevel(p)); var pos = DirectionSet.Cardinal | DirectionSet.Exact; var coreLocs = new HashSet<IntVector2>(m_riverPath.SelectMany(p => pos.ToSurroundingPoints(p))); foreach (var pp in coreLocs) { if (m_terrain.Size.Plane.Contains(pp) == false) continue; for (int z = m_terrain.Depth - 1; z >= minZ - 1; --z) { var p = new IntVector3(pp.X, pp.Y, z); var td = TileData.EmptyTileData; if (z == minZ - 1) td.WaterLevel = TileData.MaxWaterLevel; m_terrain.SetTileData(p, td); } } }
protected override void AssignValues(AItemData data) { var sData = data as SystemData; var accessCntlr = sData.InfoAccessCntlr; if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Name)) { Name = sData.Name; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Position)) { Position = sData.Position; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.SectorID)) { SectorID = sData.SectorID; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Owner)) { // true if any member has access Owner = sData.Owner; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Capacity)) { // true if all members have access Capacity = sData.Capacity; } else { Capacity = CalcPartialCapacity(sData.StarData, sData.AllPlanetoidData, sData.SettlementData); } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Resources)) { // true if all members have access Resources = sData.Resources; } else { Resources = CalcPartialResources(sData.StarData, sData.AllPlanetoidData, sData.SettlementData); } }
/// <summary> /// Returns <c>true</c> if the sector indicated by sectorID contains one or more ISectorViewHighlightables, <c>false</c> otherwise. /// </summary> /// <param name="sectorID">ID of the sector.</param> /// <param name="highlightablesInSector">The highlightables in sector.</param> /// <returns></returns> public bool TryGetSectorViewHighlightables(IntVector3 sectorID, out IEnumerable<ISectorViewHighlightable> highlightablesInSector) { D.AssertNotDefault(sectorID); List<ISectorViewHighlightable> sectorHighlightables = new List<ISectorViewHighlightable>(); ISystem_Ltd system; if (TryGetSystem(sectorID, out system)) { ISectorViewHighlightable sys = system as ISectorViewHighlightable; D.AssertNotNull(sys); sectorHighlightables.Add(sys); } IEnumerable<IStarbaseCmd_Ltd> starbases; if (TryGetStarbases(sectorID, out starbases)) { IEnumerable<ISectorViewHighlightable> highlightableStarbases = starbases.Cast<ISectorViewHighlightable>(); D.Assert(!highlightableStarbases.IsNullOrEmpty()); sectorHighlightables.AddRange(highlightableStarbases); } IEnumerable<IFleetCmd_Ltd> fleets; if (TryGetFleets(sectorID, out fleets)) { IEnumerable<ISectorViewHighlightable> highlightableFleets = fleets.Cast<ISectorViewHighlightable>(); D.Assert(!highlightableFleets.IsNullOrEmpty()); sectorHighlightables.AddRange(highlightableFleets); } if (sectorHighlightables.Any()) { highlightablesInSector = sectorHighlightables; return true; } highlightablesInSector = null; return false; }
protected override void AssignValues(AItemData data) { var sData = data as StarData; var accessCntlr = sData.InfoAccessCntlr; if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Name)) { Name = sData.Name; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Position)) { Position = sData.Position; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Owner)) { Owner = sData.Owner; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.ParentName)) { ParentName = sData.ParentName; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Category)) { Category = sData.Category; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Capacity)) { Capacity = sData.Capacity; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.Resources)) { Resources = sData.Resources; } if (accessCntlr.HasAccessToInfo(Player, ItemInfoID.SectorID)) { SectorID = sData.SectorID; } }
/// <summary> /// インスタンスを生成します。 /// </summary> /// <param name="settings">チャンク設定。</param> /// <param name="graphicsDevice">グラフィックス デバイス。</param> /// <param name="regionManager">リージョン マネージャ。</param> /// <param name="sceneManager">シーン マネージャ。</param> public ChunkManager( ChunkSettings settings, GraphicsDevice graphicsDevice, RegionManager regionManager, SceneManager sceneManager) : base(settings.PartitionManager) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); if (regionManager == null) throw new ArgumentNullException("regionManager"); ChunkSize = settings.ChunkSize; this.graphicsDevice = graphicsDevice; this.regionManager = regionManager; SceneManager = sceneManager; switch (settings.ChunkStoreType) { case ChunkStoreType.Storage: ChunkStore = StorageChunkStore.Instance; break; default: ChunkStore = NullChunkStore.Instance; break; } EmptyData = new ChunkData(this); BaseNode = sceneManager.CreateSceneNode("ChunkRoot"); sceneManager.RootNode.Children.Add(BaseNode); meshManager = new ChunkMeshManager(this, settings.VertexBuildConcurrencyLevel, settings.UpdateBufferCountPerFrame); }
EnvironmentObject(Dwarrowdelf.TerrainGen.TerrainData terrain, VisibilityMode visMode, IntVector3 startLocation) : base(ObjectType.Environment) { this.Version = 1; this.VisibilityMode = visMode; terrain.GetData(out m_tileGrid, out m_levelMap); this.Size = terrain.Size; this.StartLocation = startLocation; InitFlags(); VerifyLevelMap(); m_contentArray = new KeyedObjectCollection[this.Depth]; for (int i = 0; i < this.Depth; ++i) m_contentArray[i] = new KeyedObjectCollection(); m_originalNumTrees = ParallelEnumerable.Range(0, this.Size.Depth).Sum(z => { int sum = 0; for (int y = 0; y < this.Size.Height; ++y) for (int x = 0; x < this.Size.Width; ++x) if (GetTileData(x, y, z).HasTree) sum++; return sum; }); }
public static bool isVoxelOccupied(int [,,] mapData, IntVector3 point) { if (!isInsideMapData (mapData, point)) return false; return mapData [point.x, point.y, point.z] > 0; }
public ChunkBlock(Chunk chunk, IntVector3 position) { if (chunk == null) throw new ArgumentNullException("chunk"); if (!chunk.Contains(position)) throw new ArgumentOutOfRangeException("position"); this.chunk = chunk; this.position = position; }
public void Initialise(IntVector3 position) { base.Initialise(GameManager.Instance.ChunkPrefab); Position = position; GameObject.name = "ChunkEntity " + Position; GameObject.transform.position = position.ToVector3(); MeshFilter = GameObject.GetComponent<MeshFilter>(); }
public MoveConstructAssignment(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntVector3 location) : base(parent, environment, items[0].Location) { m_mode = mode; m_items = items; m_environment = environment; m_location = location; }
void MapChanged(IntVector3 l, TileData tileData) { this.World.AddChange(new MapChange(this, l, tileData)); }
public TileID GetTileID(IntVector3 p) { return(GetTileData(p).ID); }
public bool Contains(IntVector3 p) { return(p.X >= 0 && p.Y >= 0 && p.Z >= 0 && p.X < this.Width && p.Y < this.Height && p.Z < this.Depth); }
void Update() { if (_voxels == null && b45Building != null) { _voxels = b45Building.DataSource; } RaycastHit raycastHit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out raycastHit, 100.0f) //&& Physics.Raycast(ray, out raycastHitUnused, 100.0f, uiLayerMask) == false ) { if (cursorCubeGo != null) { cursorCubeGo.GetComponent <MeshRenderer>().enabled = true; Vector3 snapVec = raycastHit.point; //snapVec += raycastHit.normal/2.0f; snapVec *= Block45Constants._scaleInverted; // round to the nearest constants._scale snapVec.x = Mathf.FloorToInt(snapVec.x); snapVec.y = Mathf.FloorToInt(snapVec.y); snapVec.z = Mathf.FloorToInt(snapVec.z); snapVec.x += Block45Constants._scale / 2.0f; snapVec.y += Block45Constants._scale / 2.0f; snapVec.z += Block45Constants._scale / 2.0f; buildCursorPos = new IntVector3(snapVec); snapVec /= Block45Constants._scaleInverted; cursorCubeGo.transform.position = snapVec; if (snapVec.x >= 0 && snapVec.y >= 0 && snapVec.z >= 0) { buildCursorPos.x = Mathf.FloorToInt(buildCursorPos.x); buildCursorPos.y = Mathf.FloorToInt(buildCursorPos.y); buildCursorPos.z = Mathf.FloorToInt(buildCursorPos.z); } else { cursorCubeGo.GetComponent <MeshRenderer>().enabled = false; buildCursorPos = null; } } } else { // if(Physics.Raycast(ray, out raycastHitUnused, 100.0f, uiLayerMask)) // { // print (raycastHitUnused.collider.name); // } // cursorCubeGo.GetComponent<MeshRenderer>().enabled = false; // buildCursorPos = null; } if (Input.GetMouseButtonUp(0) && Input.GetKey(KeyCode.LeftAlt) && buildCursorPos != null) { B45Block block; block.blockType = B45Block.MakeBlockType(currentShape, currentRotation); block.materialType = (byte)currentMat; // _voxels.Write(buildCursorPos.x, buildCursorPos.y, buildCursorPos.z, block, 0); b45Building.AlterBlockInBuild(buildCursorPos.x, buildCursorPos.y, buildCursorPos.z, block); } // if(Input.GetKey(KeyCode.P)) // { // float lv = refPlaneMan.getXYRefPlaneLevel(); // refPlaneMan.setXYRefPlane(lv + 1); // } // if(Input.GetKey(KeyCode.O)) // { // float lv = refPlaneMan.getXYRefPlaneLevel(); // refPlaneMan.setXYRefPlane(lv - 1); // } testRoutine(); }
public MaterialID GetMaterialID(IntVector3 p) { return(GetTileData(p).MaterialID); }
public MapChange(EnvironmentObject map, IntVector3 l, TileData tileData) : base(map) { this.Location = l; this.TileData = tileData; }
public MoveConstructAssignment(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntVector3 location) : base(parent, environment, items[0].Location) { m_mode = mode; m_items = items; m_environment = environment; m_location = location; }
IEnumerable <IMovableObject> IEnvironmentObject.GetContents(IntVector3 l) { var list = m_contentArray[l.Z]; return(list.Where(o => o.Location == l)); }
/// <summary> /// Note: this does not change tile flags! /// </summary> public void SetTileData(IntVector3 p, TileData data) { Debug.Assert(this.IsInitialized); Debug.Assert(this.World.IsWritable); this.Version += 1; var oldData = GetTileData(p); // retain the old flags Debug.Assert(data.Flags == oldData.Flags || data.Flags == 0); data.Flags = oldData.Flags; m_tileGrid[p.Z, p.Y, p.X] = data; var p2d = p.ToIntVector2(); int oldSurfaceLevel = GetSurfaceLevel(p2d); int newSurfaceLevel = oldSurfaceLevel; if (data.IsWall && oldSurfaceLevel <= p.Z) { // Surface level has risen Debug.Assert(p.Z >= 0 && p.Z < 256); newSurfaceLevel = p.Z + 1; } else if (data.IsWall == false && oldSurfaceLevel == p.Z + 1) { // Surface level has possibly lowered if (p.Z == 0) { throw new Exception(); } for (int z = p.Z - 1; z >= 0; --z) { if (GetTileData(p.X, p.Y, z).IsWall) { Debug.Assert(z >= 0 && z < 256); newSurfaceLevel = z + 1; break; } } } if (newSurfaceLevel != oldSurfaceLevel) { SetSurfaceLevel(p2d, (byte)newSurfaceLevel); } MapChanged(p, data); if (this.TerrainOrInteriorChanged != null) { this.TerrainOrInteriorChanged(p, oldData, data); } if (data.WaterLevel > 0) { m_waterHandler.AddWater(p); } else { m_waterHandler.RemoveWater(p); } if (newSurfaceLevel > oldSurfaceLevel) { for (int z = oldSurfaceLevel; z < newSurfaceLevel; ++z) { SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, true); } } else if (newSurfaceLevel < oldSurfaceLevel) { for (int z = oldSurfaceLevel - 1; z >= newSurfaceLevel; --z) { SetTileFlags(new IntVector3(p2d, z), TileFlags.Subterranean, false); } } // ZZZ notify up if (Contains(p.Up)) { // ZZZ if this tile was the only support for the tile above, it should crash down var pu = p.Up; // if support is removed, clear greenery above if (oldData.IsSupporting && data.IsSupporting == false) { if (m_tileGrid[pu.Z, pu.Y, pu.X].IsGreen) { m_tileGrid[pu.Z, pu.Y, pu.X].ID = TileID.Empty; m_tileGrid[pu.Z, pu.Y, pu.X].MaterialID = MaterialID.Undefined; } } if (data.IsSupporting) { m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasSupport; } else { m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasSupport; } if (data.IsWall) { m_tileGrid[pu.Z, pu.Y, pu.X].Flags |= TileFlags.HasWallBelow; } else { m_tileGrid[pu.Z, pu.Y, pu.X].Flags &= ~TileFlags.HasWallBelow; } MapChanged(pu, GetTileData(pu)); //if (this.TerrainOrInteriorChanged != null) // this.TerrainOrInteriorChanged(p, oldData, data); } }
public bool HasContents(IntVector3 l) { var list = m_contentArray[l.Z]; return(list.Any(o => o.Location == l)); }
public IEnumerable <MovableObject> GetContents(IntVector3 l) { var list = m_contentArray[l.Z]; return(list.Where(o => o.Location == l)); }
public override bool OkToMoveChild(MovableObject ob, Direction dir, IntVector3 dstLoc) { return(EnvironmentExtensions.CanMoveFromTo(this, ob.Location, dir)); }
EnvironmentObject(Dwarrowdelf.TerrainGen.TerrainData terrain, VisibilityMode visMode, IntVector3 startLocation) : base(ObjectType.Environment) { this.Version = 1; this.VisibilityMode = visMode; terrain.GetData(out m_tileGrid, out m_levelMap); this.Size = terrain.Size; this.StartLocation = startLocation; InitFlags(); VerifyLevelMap(); m_contentArray = new KeyedObjectCollection[this.Depth]; for (int i = 0; i < this.Depth; ++i) { m_contentArray[i] = new KeyedObjectCollection(); } m_originalNumTrees = ParallelEnumerable.Range(0, this.Size.Depth).Sum(z => { int sum = 0; for (int y = 0; y < this.Size.Height; ++y) { for (int x = 0; x < this.Size.Width; ++x) { if (GetTileData(x, y, z).HasTree) { sum++; } } } return(sum); }); }
/* * public void SetAdditiveVoxelPoint(IntVector3 relativePosition, int material) * { * int old * _editSpace [relativePosition.x, relativePosition.y, relativePosition.z] = material; * }*/ public int GetVoxelPoint(IntVector3 relativePosition) { return(_editSpace [relativePosition.x, relativePosition.y, relativePosition.z]); }
private void UpdateLaser() { Camera camera = CameraExtensions.FindCameraUnderMouse(); if (camera == null) { return; } Vector3 mousePosition = Input.mousePosition; mousePosition.z = 50; Vector3 target = camera.ScreenToWorldPoint(mousePosition); Vector3 delta = target - laser.transform.position; if (delta.magnitude > 30) { delta = delta.normalized * 30.0f; target = laser.transform.position + delta; } // First check if the mouse pointer is over a mesh Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; bool hit = false; VoxelRenderer voxelRenderer = null; if (Physics.Raycast(ray, out hitInfo, 50.0f)) { target = hitInfo.point; voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>(); // Protect a second ray to see if the point we are aiming at would collide first ray = new Ray(laser.transform.position, target - laser.transform.position); if (Physics.Raycast(ray, out hitInfo, 50.0f)) { target = hitInfo.point; voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>(); } hit = true; } if (!hit) { // If not protect a ray from the origin to the target ray = new Ray(laser.transform.position, delta); if (Physics.Raycast(ray, out hitInfo, delta.magnitude)) { target = hitInfo.point; voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>(); hit = true; } } if (hit && voxelRenderer != null) { VoxelMap voxelMap = voxelRenderer.VoxelMap; Vector3 localPosition = target - voxelRenderer.gameObject.transform.position; Vector3 point; point.x = localPosition.x / voxelMap.Scale - voxelMap.Offset.x; point.y = localPosition.y / voxelMap.Scale - voxelMap.Offset.y; point.z = localPosition.z / voxelMap.Scale - voxelMap.Offset.z; // Clamp to the bounds of the map int x = Mathf.Clamp(Mathf.RoundToInt(point.x), 0, voxelMap.Columns); int y = Mathf.Clamp(Mathf.RoundToInt(point.y), 0, voxelMap.Rows); int z = Mathf.Clamp(Mathf.RoundToInt(point.z), 0, voxelMap.Pages); IntVector3 nearestVoxel; if (voxelMap.FindNearestVoxel(localPosition, out nearestVoxel)) { if (!lastVoxel.Equals(nearestVoxel)) { lastVoxel = nearestVoxel; lastVoxelTimer = 0; } else { lastVoxelTimer += Time.deltaTime; if (lastVoxelTimer > 0.1) { Vector3 position = nearestVoxel; position *= voxelMap.Scale; position += voxelMap.Offset; position += voxelRenderer.gameObject.transform.position; DebugUI.DrawCubeCentred(position, new Vector3(voxelMap.Scale, voxelMap.Scale, voxelMap.Scale), voxelRenderer.gameObject.transform.rotation, Color.red); voxelRenderer.RemoveVoxel(nearestVoxel); lastVoxel = IntVector3.UNDEFINED; } } } else { lastVoxel = IntVector3.UNDEFINED; } } else { lastVoxel = IntVector3.UNDEFINED; } delta = target - laser.transform.position; Vector3 scale = laser.transform.localScale; scale.z = delta.magnitude; laser.transform.localScale = scale; laser.transform.LookAt(target); delta = delta.normalized * (delta.magnitude - 0.1f); collision.transform.position = laser.transform.position + delta; ParticleSystem[] particles = collision.GetComponentsInChildren <ParticleSystem>(); foreach (var ps in particles) { var emission = ps.emission; emission.enabled = hit; } }
public FlatArray3D(IntVector3 size) { this._size = size; storage = new T[size.Area]; }
public ObjectMoveLocationChange(MovableObject mover, IntVector3 sourceLocation, IntVector3 destinationLocation) : base(mover) { this.SourceLocation = sourceLocation; this.DestinationLocation = destinationLocation; }
bool EventIsNear(IntVector3 p) { return(m_livings.Any(l => (l.Location - p).ManhattanLength <= l.VisionRange)); }
public bool GetTileFlags(IntVector3 p, TileFlags flags) { return((GetTileData(p).Flags & flags) != 0); }
public MoveMineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType) : base(parent, environment, location) { m_mineActionType = mineActionType; }
public override bool Sees(IntVector3 p) { return(m_livings.Any(l => l.Sees(m_environment, p))); }
public byte GetWaterLevel(IntVector3 p) { return(GetTileData(p).WaterLevel); }
public MaterialInfo GetMaterial(IntVector3 p) { return(Materials.GetMaterial(GetMaterialID(p))); }
public void SetTileData(IntVector3 p, TileData data) { m_grid[p.Z, p.Y, p.X] = data; }
public TileData GetTileData(IntVector3 p) { return(m_grid[p.Z, p.Y, p.X]); }
private void Update() { if (Input.GetKeyDown(KeyCode.Keypad0)) { toolsVisible = !toolsVisible; } if (!toolsVisible) { selectingColor = false; } if (Input.GetMouseButtonDown(0) || Input.GetKey(key)) { try { var block = Singleton.Manager <ManPointer> .inst.targetVisible.block; IntVector3 blockPosition = block.cachedLocalPosition; var mod = block.GetComponent <ModuleColor>(); if (selectingColor) { color = mod.Color; selectingColor = false; } else if (toolsVisible) { if (axis[selection] == "X") { IntVector3 start = blockPosition - new IntVector3(0, radius - 2, radius - 2); IntVector3 end = blockPosition + new IntVector3(0, radius - 1, radius - 1); for (int y = start.y; y < end.y; y++) { for (int z = start.z; z < end.z; z++) { var current = block.tank.blockman.GetBlockAtPosition(new IntVector3(blockPosition.x, y, z)); var modc = current?.GetComponent <ModuleColor>(); if (modc) { modc.Color = color; } } } } else if (axis[selection] == "Y") { IntVector3 start = blockPosition - new IntVector3(radius - 2, 0, radius - 2); IntVector3 end = blockPosition + new IntVector3(radius - 1, 0, radius - 1); for (int x = start.x; x < end.x; x++) { for (int z = start.z; z < end.z; z++) { var current = block.tank.blockman.GetBlockAtPosition(new IntVector3(x, blockPosition.y, z)); var modc = current?.GetComponent <ModuleColor>(); if (modc) { modc.Color = color; } } } } else if (axis[selection] == "Z") { IntVector3 start = blockPosition - new IntVector3(radius - 2, radius - 2, 0); IntVector3 end = blockPosition + new IntVector3(radius - 1, radius - 1, 0); for (int x = start.x; x < end.x; x++) { for (int y = start.y; y < end.y; y++) { var current = block.tank.blockman.GetBlockAtPosition(new IntVector3(x, y, blockPosition.z)); var modc = current?.GetComponent <ModuleColor>(); if (modc) { modc.Color = color; } } } } } } catch (Exception e) { } } if (!Singleton.Manager <ManPointer> .inst.DraggingItem) { if (Input.GetMouseButtonDown(1)) { win = new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y - 200f, 200f, 200f); try { module = Singleton.Manager <ManPointer> .inst.targetVisible.block.GetComponent <ModuleColor>(); blockColor = module.Color; } catch (Exception e) { //Console.WriteLine(e); module = null; } } } }
public void SetVoxel(IntVector3 p, Voxel voxel) { this.Grid[p.Z, p.Y, p.X] = voxel; }
public MaterialID GetMaterialID(IntVector3 p) { return(m_grid[p.Z, p.Y, p.X].MaterialID); }
public TileID GetTileID(IntVector3 p) { return(m_grid[p.Z, p.Y, p.X].ID); }
public Voxel GetVoxel(IntVector3 p) { return(this.Grid[p.Z, p.Y, p.X]); }