Exemple #1
0
    public CellController ReplaceCell(MapPoint point, CellController prefab)
    {
        if (point.X < 0 || point.Y < 0 || point.X > 0xffff || point.Y > 0xffff)
        {
            return(null);
        }


        CellController newCell = CellController.InstantiateMe(prefab, transform, point);


        MapRect rect = prefab.GetCellIndexes(point, selectedRotation);

        rect.Foreach((MapPoint p) => {
            int key = p.toInt();
            if (cells.ContainsKey(key))
            {
                GameObject.Destroy(cells[key].gameObject);
                cells.Remove(key);
                cells[key] = newCell;
            }
        });

        newCell.SetRotation(selectedRotation);

        return(newCell);
    }
Exemple #2
0
    public void PlaceIndicators(Dictionary <int, CellController> cells,
                                Dictionary <int, WallController> walls,
                                WallController wallPrefab)
    {
        bool isDoor = wallPrefab.PrefabIsDoor();

        foreach (CellController c in cells.Values)
        {
            if (c.IsMultiCell)
            {
                MapRect rect = c.GetCurCellIndexes();
                rect.Foreach((MapPoint p) => {
                    WallPoint wp = new WallPoint(p.X, p.Y);
                    if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                    {
                        InstantiateIndicator(wp, isDoor);
                    }
                });
            }
            else
            {
                WallPoint wp = new WallPoint(c.Position.X, c.Position.Y);
                if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                {
                    InstantiateIndicator(wp, isDoor);
                }
            }
        }
    }
	//returns true if this phantom already has been placed
	public bool PlacePhantom(MapPoint pos,MapRect rect)
	{
		LastPhantomPosition = pos;
		if(lastRect.Equals(rect))
			return true;

		RemovePhantom();

		rect.Foreach((MapPoint p) => {
			InstantiatePhantom(p,true);
		});

	
		lastRect = new MapRect(rect);
		return false;
	}
Exemple #4
0
    //returns true if this phantom already has been placed
    public bool PlacePhantom(MapPoint pos, MapRect rect)
    {
        LastPhantomPosition = pos;
        if (lastRect.Equals(rect))
        {
            return(true);
        }

        RemovePhantom();

        rect.Foreach((MapPoint p) => {
            InstantiatePhantom(p, true);
        });


        lastRect = new MapRect(rect);
        return(false);
    }
Exemple #5
0
    public bool IsRectFree(MapRect rect, bool usePhantom)
    {
        bool res = true;

        rect.Foreach((MapPoint p) => {
            CellController c = M.House.GetCell(p);
            if (c == null || c.CellObject != null)
            {
                res = false;
                if (usePhantom)
                {
                    M.House.Phantom.SetRedPhantom(p);
                }
            }

            if (p.X > rect.MinX && p.Y > rect.MinY)
            {
                WallController w = M.House.GetWall(new WallPoint(p.X, p.Y));
                if (w != null)
                {
                    res = false;
                }
            }
        });

        for (int x = rect.MinX + 1; x <= rect.MaxX; x++)
        {
            WallController w = M.House.GetWall(new WallPoint(x, rect.MinY));
            if (w != null && w.wallSprite.Top == true)
            {
                res = false;
            }
        }

        for (int y = rect.MinY + 1; y <= rect.MaxY; y++)
        {
            WallController w = M.House.GetWall(new WallPoint(rect.MinX, y));
            if (w != null && w.wallSprite.Right == true)
            {
                res = false;
            }
        }
        return(res);
    }
Exemple #6
0
    public bool IsRectFree(MapRect rect)
    {
        bool res = true;

        rect.Foreach((MapPoint p) => {
            LogicCell c = null;
            if (res && !LogicCells.TryGetValue(p.toInt(), out c))
            {
                res = false;
            }

            if (res && p.X > rect.MinX && p.Y > rect.MinY)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(p.X, p.Y).toInt(), out w))
                {
                    res = false;
                }
            }
        });
        if (res)
        {
            for (int x = rect.MinX + 1; x <= rect.MaxX; x++)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(x, rect.MinY).toInt(), out w) && w.Top)
                {
                    res = false;
                }
            }

            for (int y = rect.MinY + 1; y <= rect.MaxY; y++)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(rect.MinX, y).toInt(), out w) && w.Right)
                {
                    res = false;
                }
            }
        }
        return(res);
    }
Exemple #7
0
    private void OnRemoveObject(Vector3 pz)
    {
        MapPoint       mp           = new MapPoint(Mathf.FloorToInt(pz.x), Mathf.FloorToInt(pz.y));
        CellController cellToRemove = null;

        if (cells.TryGetValue(mp.toInt(), out cellToRemove))
        {
            if (cellToRemove.CellObject != null)
            {
                M.UI.bCostsPanel.Expences.AddValue(-cellToRemove.CellObject.GetCost());
            }

            MapRect rect = cellToRemove.GetCellIndexes(cellToRemove.Position, cellToRemove.Rotation);
            rect.Foreach((MapPoint p) => {
                cells.Remove(p.toInt());
                EditorSetCell(p, CellPrefab);
            });
            Destroy(cellToRemove.gameObject);
        }
    }
	public bool IsRectFree(MapRect rect, bool usePhantom)
	{
		bool res = true;
		rect.Foreach((MapPoint p) => {
			
			CellController c =M.House.GetCell(p);
			if(c==null || c.CellObject!=null)
			{
				res = false;
				if(usePhantom)
					M.House.Phantom.SetRedPhantom(p);
			}
			
			if(p.X>rect.MinX && p.Y>rect.MinY)
			{
				WallController w = M.House.GetWall(new WallPoint(p.X,p.Y));
				if(w!=null)
					res = false;
			}
			
		});
		
		for(int x = rect.MinX+1;x<=rect.MaxX;x++)
		{
			WallController w = M.House.GetWall(new WallPoint(x,rect.MinY));
			if(w!=null && w.wallSprite.Top==true)
				res = false;
		}
		
		for(int y = rect.MinY+1;y<=rect.MaxY;y++)
		{
			WallController w = M.House.GetWall(new WallPoint(rect.MinX,y));
			if(w!=null && w.wallSprite.Right==true)
				res = false;
		}
		return res;
	}
Exemple #9
0
    public void Launch(LevelConditions conditions, Dictionary <int, CellController> cells,
                       Dictionary <int, WallController> walls)
    {
        rooms.Clear();
        processed.Clear();
        Doors.Clear();
        LCache.Clear();
        LogicCells.Clear();
        Conditions = conditions;

        // Filling logic walls
        foreach (WallController w in walls.Values)
        {
            LogicWalls[w.Position.toInt()] = new LogicWall(w.Position, w.wallSprite.Top,
                                                           w.wallSprite.Bottom,
                                                           w.wallSprite.Left,
                                                           w.wallSprite.Right);
        }

        // Filling logic cells
        foreach (CellController cell in cells.Values)
        {
            if (LogicCells.ContainsKey(cell.Position.toInt()))
            {
                continue;
            }
            LogicCells.Add(cell.Position.toInt(), new LogicCell(cell.Position));
            if (cell.SizeX > 1 || cell.SizeY > 1)
            {
                MapRect rect = cell.GetCurCellIndexes();
                rect.Foreach((MapPoint p) => {
                    if (!LogicCells.ContainsKey(p.toInt()))
                    {
                        LogicCells.Add(p.toInt(), new LogicCell(p));
                    }
                });
            }
        }

        // Calculating reaches
        foreach (LogicCell cell in LogicCells.Values)
        {
            WallController w = null;
            LogicCell      c = null;


            //left
            c = GetLogicCell(cell.Position.X - 1, cell.Position.Y);
            w = GetWall(cell.Position.X, cell.Position.Y);
            if (c != null && (w == null || w.wallSprite.Top == false))
            {
                cell.ReachableCells.Add(c);
            }


            //right
            c = GetLogicCell(cell.Position.X + 1, cell.Position.Y);
            w = GetWall(cell.Position.X + 1, cell.Position.Y + 1);
            if (c != null && (w == null || w.wallSprite.Bottom == false))
            {
                cell.ReachableCells.Add(c);
            }

            //top
            c = GetLogicCell(cell.Position.X, cell.Position.Y + 1);
            w = GetWall(cell.Position.X + 1, cell.Position.Y + 1);
            if (c != null && (w == null || w.wallSprite.Left == false))
            {
                cell.ReachableCells.Add(c);
            }

            //bottom
            c = GetLogicCell(cell.Position.X, cell.Position.Y - 1);
            w = GetWall(cell.Position.X, cell.Position.Y);
            if (c != null && (w == null || w.wallSprite.Right == false))
            {
                cell.ReachableCells.Add(c);
            }


            cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y + 1) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y + 1) == null?0:1;
        }
        // Finding Rooms
        curRoom = new Room(this);
        foreach (LogicCell cell in LogicCells.Values)
        {
            if (processed.Contains(cell))
            {
                continue;
            }
            Next(cell);
            if (curRoom.Size > 0)
            {
                rooms.Add(curRoom);
                Debug.Log(string.Format("Found room #{1} with {0} cells", curRoom.Size, curRoom.Number));
                curRoom        = new Room(this);
                curRoom.Number = rooms.Count;
            }
        }


        // STEP 2 - Recognize rooms
        Recognize();

        // STEP 3 - Calculate connections
        Connections();

        foreach (Room r in rooms)
        {
            M.Overlay.DrawRoom(r);
            Debug.Log(string.Format("Room #{0} is {1}, {2} objects", r.Number,
                                    Enum.GetName(typeof(RoomType), r.TypeOfRoom),
                                    r.LogicObjects.Count));
            foreach (Door d in r.Doors)
            {
                if (d.Rooms.Count == 1)
                {
                    Debug.Log(string.Format("  Room #{0} contains door that leads to nothing", r.Number));
                }
                else if (d.Rooms.Count == 2)
                {
                    Debug.Log(string.Format("  Room #{0} contains door that leads to room #{1}",
                                            r.Number, d.GetAnotherRoom(r).Number));
                }
                else
                {
                    Debug.Log(string.Format("  Buggy room #{0}", r.Number));
                }
            }
        }
        evaluator.Launch();
    }