Ejemplo n.º 1
0
 public FillInfo GetFillInfo(int id)
 {
     for (int i = 0; i < fillInfos.Count; i++)
     {
         FillInfo fillInfo = fillInfos[i];
         if (fillInfo.id == id)
         {
             return(fillInfo);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
    public void InitFillInfo()
    {
        config_map_item map_item = BattleModel.Instance.crtConfig;

        FillInfo fillInfo = GetFillInfo(map_item.fill);

        if (fillInfo == null)
        {
            fillInfo    = new FillInfo();
            fillInfo.id = map_item.fill;
            string content = GameMgr.resourceMgr.GetTextString("txt/fill.ab", fillInfo.id.ToString());
            fillInfo.FillTxt(content);
            fillInfos.Add(fillInfo);
        }
        crtFillInfo         = fillInfo;
        FillInfo.FILL_COUNT = 0;
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders fill changes
        /// </summary>
        /// <param name="info"> Fill information </param>
        void renderFillInfo(FillInfo info)
        {
            WorldRegion undoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer),
                        redoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer);

            int selectionWidth  = TilesetSelection.Width / TileSize.Width,
                selectionHeight = TilesetSelection.Height / TileSize.Height;

            // <bounds loop>
            for (int boundsX = info.Bounds.X; boundsX < info.Bounds.Right; boundsX += selectionWidth)
            {
                for (int boundsY = info.Bounds.Y; boundsY < info.Bounds.Bottom; boundsY += selectionHeight)
                {
                    // <render loop>
                    for (int renderX = boundsX, sx = 0; renderX < boundsX + selectionWidth; renderX++, sx++)
                    {
                        for (int renderY = boundsY, sy = 0; renderY < boundsY + selectionHeight; renderY++, sy++)
                        {
                            int offsetX = renderX - info.Bounds.X,
                                offsetY = renderY - info.Bounds.Y;

                            // determine if the point from the current selection iteration should be rendered.
                            // must be inside the region bounds and an existing change
                            if (offsetX >= info.Bounds.Width || offsetY >= info.Bounds.Height || !info.Changes[offsetX][offsetY])
                            {
                                continue;
                            }

                            WorldTile tile = TileFromSelectionOffset(sx, sy);

                            World.SetTile(renderX, renderY, tile);
                            redoRegion[offsetX, offsetY] = tile;
                        }
                    }
                    // </render loop>
                }
            }
            // </bounds loop>

            ChangesUndo = new TileChangesRegion(undoRegion, info.Bounds.Location, World.SelectedLayer);
            ChangesRedo = new TileChangesRegion(redoRegion, info.Bounds.Location, World.SelectedLayer);

            History.Add(PackagedHistoryItem());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Preenche apenas as tabelas de dados especificadas.
        /// </summary>
        /// <param name="sources">Os nomes das origens. Formato de cada uma: <c>dataTable:tabela_ou_view</c></param>
        public int FillData(params string[] sources)
        {
            try
            {
                int c = 0;
                using (AdpConnection conn = CreateConnection())
                {
                    foreach (string rawInfo in sources)
                    {
                        FillInfo fi = new FillInfo(rawInfo);
                        using (AdpDataAdapter da = new AdpDataAdapter())
                        {
                            if (fi.Source == fi.DataTable && ds.Tables.Contains(fi.DataTable))
                            {
                                DataTable dt = ds.Tables[fi.DataTable];
                                lock (dt)
                                {
                                    string old = dt.TableName;
                                    dt.TableName = GetPhysicalTableName(dt);
                                    new AdpCommandBuilder(da, conn, dt, AdpCommandOperation.Select);
                                    c           += da.Fill(dt);
                                    dt.TableName = old;
                                }
                            }
                            else
                            {
                                da.SelectCommand = new AdpCommand("SELECT * FROM " + fi.Source, conn);
                                if (!ds.Tables.Contains(fi.DataTable))
                                {
                                    Debug.WriteLine(String.Format("WARN: DataTable {0} doesn't exist.", fi.DataTable));
                                }
                                c += da.Fill(ds, fi.DataTable);
                            }
                        }
                    }
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw new ConnectorException("Erro ao realizar o preenchimento dos dados", ex);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Renders fill changes
        /// </summary>
        /// <param name="info"> Fill information </param>
        void renderFillInfo(FillInfo info)
        {
            WorldRegion undoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer),
                        redoRegion = World.GetLayerRegion(info.Bounds, World.SelectedLayer);

            int selectionWidth = TilesetSelection.Width / TileSize.Width,
                selectionHeight = TilesetSelection.Height / TileSize.Height;

            // <bounds loop>
            for (int boundsX = info.Bounds.X; boundsX < info.Bounds.Right; boundsX += selectionWidth)
            {
                for (int boundsY = info.Bounds.Y; boundsY < info.Bounds.Bottom; boundsY += selectionHeight)
                {
                    // <render loop>
                    for (int renderX = boundsX, sx = 0; renderX < boundsX + selectionWidth; renderX++, sx++)
                    {
                        for (int renderY = boundsY, sy = 0; renderY < boundsY + selectionHeight; renderY++, sy++)
                        {
                            int offsetX = renderX - info.Bounds.X,
                                offsetY = renderY - info.Bounds.Y;

                            // determine if the point from the current selection iteration should be rendered.
                            // must be inside the region bounds and an existing change
                            if (offsetX >= info.Bounds.Width || offsetY >= info.Bounds.Height || !info.Changes[offsetX][offsetY])
                                continue;

                            WorldTile tile = TileFromSelectionOffset(sx, sy);

                            World.SetTile(renderX, renderY, tile);
                            redoRegion[offsetX, offsetY] = tile;
                        }
                    }
                    // </render loop>
                }
            }
            // </bounds loop>

            ChangesUndo = new TileChangesRegion(undoRegion, info.Bounds.Location, World.SelectedLayer);
            ChangesRedo = new TileChangesRegion(redoRegion, info.Bounds.Location, World.SelectedLayer);

            History.Add(PackagedHistoryItem());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Computes a fill region and points contained in it based
        /// on the origin
        /// </summary>
        /// <param name="origin"> Initial fill point </param>
        /// <returns> Fill information generated from origin </returns>
        FillInfo computeFillInfo(Point origin)
        {
            FillInfo fillInfo = new FillInfo();
            
            fillInfo.Bounds = new Rectangle(origin.X, origin.Y, origin.X, origin.Y);

            WorldTile targetTile = World.GetTile(origin);

            //queue containing tiles to check
            List<Point> fillQ = new List<Point>();
            fillQ.Add(origin);

            //list that will be pushed with points valid
            //for change. This is used later to populate
            //our flag array
            List<Point> changedPoints = new List<Point>();

            //cache this condition for later optimization
            bool checkRect = World.SelectionRectangle != Rectangle.Empty;

            //iteration bounds. used for optimization
            int boundLeft, boundRight, boundTop, boundBottom;

            //set the bounds depending on the selection rectangle
            if (checkRect)
            {
                boundLeft = World.SelectionRectangle.X.Clamp(0, WorldSize.Width);
                boundRight = World.SelectionRectangle.Right.Clamp(0, WorldSize.Width);
                boundTop = World.SelectionRectangle.Y.Clamp(0, WorldSize.Height);
                boundBottom = World.SelectionRectangle.Bottom.Clamp(0, WorldSize.Height);
            }
            else
            {
                boundLeft = boundTop = 0;
                boundRight = WorldSize.Width;
                boundBottom = WorldSize.Height;
            }

            //array of flags containing tiles already processed for optimization
            bool[][] processedTiles = new bool[WorldSize.Width][];

            for (int i = 0; i < WorldSize.Width; i++)
                processedTiles[i] = new bool[WorldSize.Height];

            //process fill queue until there's no remaining options
            while (fillQ.Count > 0) {
                //take this point from the queue
                Point currentPoint = fillQ[0];
                fillQ.RemoveAt(0);

                //set the current point as a valid change
                changedPoints.Add(currentPoint);
                processedTiles[currentPoint.X][currentPoint.Y] = true;

                //seek left
                int left = currentPoint.X;
                while (--left >= boundLeft && World.GetTile(left, currentPoint.Y) == targetTile); left++;
                    
                //seek right
                int right = currentPoint.X;
                while (++right < boundRight && World.GetTile(right, currentPoint.Y) == targetTile); right--;

                //adjust fill region bounds
                fillInfo.Bounds.X = Math.Min(left, fillInfo.Bounds.X);
                fillInfo.Bounds.Y = Math.Min(currentPoint.Y, fillInfo.Bounds.Y);
                fillInfo.Bounds.Width = Math.Max(right, fillInfo.Bounds.Width);
                fillInfo.Bounds.Height = Math.Max(currentPoint.Y, fillInfo.Bounds.Height);

                //used for optimizing left-right iterations
                bool lAbove = false;
                bool lBelow = false;

                //iterate through row based on calculation and
                //add other potential rows
                for (int x = left; x <= right; x++) {
                    Point fillPoint = new Point(x, currentPoint.Y);

                    changedPoints.Add(fillPoint);

                    //check tile above
                    if (fillPoint.Y > boundTop) {
                        Point pointAbove = new Point(fillPoint.X, fillPoint.Y - 1);

                        if (!processedTiles[pointAbove.X][pointAbove.Y] && World.GetTile(pointAbove) == targetTile)
                        {
                            if (!lAbove)
                                fillQ.Add(pointAbove);

                            lAbove = true;
                        } 
                        else 
                        {
                            lAbove = false;
                        }

                        //declare this tile as processed
                        processedTiles[pointAbove.X][pointAbove.Y] = true;
                    }

                    //check tile below
                    if (fillPoint.Y + 1 < boundBottom)
                    {
                        Point pointBelow = new Point(fillPoint.X, fillPoint.Y + 1);
                        if (!processedTiles[pointBelow.X][pointBelow.Y] && World.GetTile(pointBelow) == targetTile)
                        {
                            if (!lBelow)
                                fillQ.Add(pointBelow);

                            lBelow = true;
                        }
                        else 
                        { 
                            lBelow = false; 
                        }

                        //declare this tile as processed
                        processedTiles[pointBelow.X][pointBelow.Y] = true;
                    }
                }
            }

            //normalize fill region size
            fillInfo.Bounds.Width = fillInfo.Bounds.Width - fillInfo.Bounds.X + 1;
            fillInfo.Bounds.Height = fillInfo.Bounds.Height - fillInfo.Bounds.Y + 1;

            //if there's a selection in the world, determine if we should
            //use it, or the bounds of the changes
            if (checkRect && !World.SelectionRectangle.Contains(fillInfo.Bounds))
            {
                fillInfo.Bounds = World.SelectionRectangle;
            }

            fillInfo.Changes = new bool[fillInfo.Bounds.Width][];

            for (int i = 0; i < fillInfo.Bounds.Width; i++)
                fillInfo.Changes[i] = new bool[fillInfo.Bounds.Height];

            //convert changed tiles into flags for optimized
            //use in applying changes
            foreach (Point change in changedPoints)
            {
                fillInfo.Changes[change.X - fillInfo.Bounds.X]
                                [change.Y - fillInfo.Bounds.Y] = true;
            }

            return fillInfo;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Preenche a tabela de dados especificada, com os critérios especificados.
        /// </summary>
        /// <param name="source">O nome da origem. Formato: <c>dataTable:tabela_ou_view</c></param>
        /// <param name="cond">O critério de seleção dos registros.</param>
        /// <param name="orderBy">A ordem</param>
        public int FillData(string source, SqlCondition cond, SqlOrder orderBy)
        {
            FillInfo fi = new FillInfo(source);

            return(FillData(fi.DataTable, new SqlQuery(new SqlTableSource(fi.Source), cond, orderBy)));
        }
Ejemplo n.º 8
0
	private FillInfo[,] GenerateRefillTrendMap(Container2D_Rectangular container)
	{
		var ret = new FillInfo[container.Height, container.Width];
		var slots = container.WrapperRect;
		Action<int, int, List<SlotWrapper2D>> picker = (x, y, list)=>{
			if (x < 0 || x >= container.Width) return;
			if (y < 0 || y >= container.Height) return;
			if (null != slots[y, x].slotAttribute && slots[y, x].slotAttribute.category == SlotAttribute.Category.INSULATOR)
			{
				return;
			}
			list.Add(slots[y, x]);
		};
		Action<int, int> exitMarker = (x, y)=>{
			if (null == ret[y, x])
			{
				ret[y, x] = new FillInfo();
				ret[y, x].ancestorPos = new Pos2D(x, y + 1);
			}
		};

		container.ForeachSlot((x, y, slot)=>{
			if (null != ret[y, x]) 
				return;
			if (null != slot.slotAttribute && slot.slotAttribute.category == SlotAttribute.Category.INSULATOR)
				return;
			var ctx = new AStar.Context<SlotWrapper2D>();
			ctx.start = slots[y, x];
			ctx.procTrait = (s)=>{
				return s.Trait;
			};
			ctx.procWeight = (SlotWrapper2D from, SlotWrapper2D to)=>{
				foreach (var t in surroundingOffsets){
					if (to.pos.x == from.pos.x + t.item1 && to.pos.y == from.pos.y + t.item2){
						return t.item3;
					}
				}
				throw new NotImplementedException();
			};
			ctx.procTermination = (SlotWrapper2D s)=>{
				return s.pos.y == container.Height - 1;
			};
			ctx.procDistanceEstimator = (SlotWrapper2D s)=>{
				return (container.Height - 1 - s.pos.y) * 1.0001f;
			};
			ctx.procAdjacencies = (SlotWrapper2D s)=>{
				var list = new List<SlotWrapper2D>();
				foreach (var t in surroundingOffsets){
					picker.Invoke(s.pos.x + t.item1, s.pos.y + t.item2, list);
				}
				return list;
			};

			if (AStar.Evaluate(ctx))
			{
				var result = ctx.path;
				if (result.Count <= 0)
				{
					exitMarker.Invoke(x, y);
				}
				else
				{
					result.Reverse();
					for (int i = 0, len = result.Count - 1; i < len; i++)
					{
						if (null != ret[result[i].pos.y, result[i].pos.x]) continue;
						var t = new FillInfo();
						t.ancestorPos = new Pos2D(result[i + 1].pos.x, result[i + 1].pos.y);
						ret[result[i].pos.y, result[i].pos.x] = t;
					}
					exitMarker(result[result.Count - 1].pos.x, result[result.Count - 1].pos.y);
				}
			}
			else
			{
				ret[y, x] = new FillInfo();
			}
		});

		for (int y = 0; y < container.Height; y++)
		{
			for (int x = 0; x < container.Width; x++)
			{
				var fi = ret[y, x];
				if (null == fi) continue;
				if (fi.IsOnSpot) continue;
				fi.childrenPos = new List<Pos2D>();
				foreach (var t in surroundingOffsets)
				{
					var sx = x + t.item1;
					var sy = y + t.item2;

					if (!container.IsLegalPosition(sx, sy))
					{
						continue;
					}
					var slot = container.GetSlot(sx, sy);
					if (null != slot && null != slot.slotAttribute && slot.slotAttribute.category == SlotAttribute.Category.INSULATOR)
					{
						continue;
					}

					var touch = ret[sy, sx];
					if (null != touch.ancestorPos && touch.ancestorPos.x == x && touch.ancestorPos.y == y)
					{
						fi.childrenPos.Add(new Pos2D(sx, sy));
					}
				}
			}
		}

		return ret;
	}
Ejemplo n.º 9
0
		/// <summary>
		/// Preenche apenas as tabelas de dados especificadas.
		/// </summary>
		/// <param name="sources">Os nomes das origens. Formato de cada uma: <c>dataTable:tabela_ou_view</c></param>
		public int FillData(params string[] sources) 
		{
			try 
			{
				int c = 0;
				using (AdpConnection conn = CreateConnection()) 
				{
					foreach (string rawInfo in sources) 
					{
						FillInfo fi = new FillInfo(rawInfo);
						using (AdpDataAdapter da = new AdpDataAdapter())
						{
							if (fi.Source == fi.DataTable && ds.Tables.Contains(fi.DataTable)) 
							{
								DataTable dt = ds.Tables[fi.DataTable];
								lock (dt) 
								{
									string old = dt.TableName;
									dt.TableName = GetPhysicalTableName(dt);
									new AdpCommandBuilder(da, conn, dt, AdpCommandOperation.Select);
									c += da.Fill(dt);
									dt.TableName = old;
								}
							}
							else
							{
								da.SelectCommand = new AdpCommand("SELECT * FROM " + fi.Source, conn);
								if (!ds.Tables.Contains(fi.DataTable))
									Debug.WriteLine(String.Format("WARN: DataTable {0} doesn't exist.", fi.DataTable));
								c += da.Fill(ds, fi.DataTable);
							}
						}
					}
				}

				return c;
			}
			catch (Exception ex)
			{
				throw new ConnectorException("Erro ao realizar o preenchimento dos dados", ex);
			}
		}
Ejemplo n.º 10
0
	private List<RefillFlowRecord.Path> CollectFillPathList(Container2D_Rectangular container, FillInfo[,] fillInfos)
	{
		var ret = new List<RefillFlowRecord.Path>();
		for (int x = 0; x < container.Width; x++)
		{
			var sub = CollectFromPos(container, fillInfos, x, container.Height - 1);
			if (null == sub) continue;
			sub.Sort((lhr, rhr)=>{
				return (lhr.movements.Count > rhr.movements.Count) ? -1 : 1;
			});
			var len = sub.Count;
			for (int i = 0; i < len; i++)
			{
				var index = i + 1;
				var s = sub[i];
				s.src = new Pos2D(x, container.Height - 1 + index);
				for (int j = 1; j <= index; j++)
				{
					s.movements.Add(new Pos2D(x, container.Height - 1 + j));
				}
				s.movements.Reverse();
			}
			ret.AddRange(sub);
		}
		return ret;
	}
Ejemplo n.º 11
0
	private Tuple<Pos2D, int> DepthFirstSearch(SlotWrapper2D[,] slots,
	                                           FillInfo[,] infos, 
	                                           int fromX, int fromY)
	{
		Tuple<Pos2D, int> ret = null;
		var fi = infos[fromY, fromX];
		foreach (var t in fi.childrenPos)
		{
			if (null == slots[t.y, t.x])
			{
				var branchSearch = DepthFirstSearch(slots, infos, t.x, t.y);
				if (null == ret || branchSearch.item2 > ret.item2)
				{
					ret = branchSearch;
				}
			}
		}
		if (null == ret)
		{
			ret = new Tuple<Pos2D, int>(new Pos2D(fromX, fromY), 0);
		}
		else
		{
			ret.item2 = ret.item2 + 1;
		}
		return ret;
	}
Ejemplo n.º 12
0
	private List<Pos2D> CollectRefillEnds(Container2D_Rectangular container, FillInfo[,] fillInfoMap)
	{
		var slots = container.WrapperRect;
		var ret = new List<Pos2D>();

		container.ForeachSlot((x, y, slot)=>{
			if (null != slot) return;
			if (fillInfoMap[y, x].IsOnSpot) return;
			foreach (var t in surroundingOffsets){
				if (!container.IsLegalPosition(x + t.item1, y + t.item2)) continue;
				if (null != slots[y + t.item2, x + t.item1]) continue;
				var fi = fillInfoMap[y + t.item2, x + t.item1];
				if (!fi.IsOnSpot && fi.ancestorPos.x == x && fi.ancestorPos.y == y)
				{
					return;
				}
			}
			ret.Add(new Pos2D(x, y));
		});
		return ret;
	}
Ejemplo n.º 13
0
	private RefillFlowRecord DoApply(Container2D_Rectangular container, FillInfo[,] fillInfoMap)
	{
		var ret = new RefillFlowRecord();
		var slots = container.WrapperRect;

		container.ForeachSlot((x, y, slot)=>{
			if (null != slot) return;
			var fi = fillInfoMap[y, x];
			if (fi.IsOnSpot){
				ret.OnSpotList.Add(new Pos2D(x, y));
			}
		});
		var ends = CollectRefillEnds(container, fillInfoMap);
		var dir = new Dictionary<int, Tuple<SlotWrapper2D, int>>();
		foreach (var e in ends)
		{
			var pos = fillInfoMap[e.y, e.x].ancestorPos;
			int inverseDepth = 0;
			while (container.IsLegalPosition(pos.x, pos.y))
			{
				var s = slots[pos.y, pos.x];
				if (null != s)
				{
					inverseDepth++;
					if (!dir.ContainsKey(s.Trait))
					{
						dir.Add(s.Trait, new Tuple<SlotWrapper2D, int>(s, inverseDepth));
					}
					else if (dir[s.Trait].item2 < inverseDepth)
					{
						dir[s.Trait].item2 = inverseDepth;
					}
				}
				pos = fillInfoMap[pos.y, pos.x].ancestorPos;
			}
		}
		var list = new List<Tuple<SlotWrapper2D, int>>();
		foreach (var kvp in dir)
		{
			list.Add(kvp.Value);
		}
		list.Sort((lhr, rhr)=>{
			return (lhr.item2 < rhr.item2) ? -1 : 1;
		});

		foreach (var t in list)
		{
			var src = t.item1.pos;
			var moveTo = DepthFirstSearch(slots, fillInfoMap, src.x, src.y);
			var dst = moveTo.item1;

			var path = new RefillFlowRecord.Path();
			path.src = src.Clone();
			path.dst = dst.Clone();

			container.SwapSlot(src.x, src.y, dst.x, dst.y);
			var cur = path.dst;
			do {
				path.movements.Add(cur);
				cur = fillInfoMap[cur.y, cur.x].ancestorPos;
			} while (cur != path.src);

			path.movements.Add(path.src);
			path.movements.Reverse();

			ret.NonFillMovements.Add(path);
		}

		ret.FillMovements = CollectFillPathList(container, fillInfoMap);

		return ret;
	}
Ejemplo n.º 14
0
        /// <summary>
        /// Computes a fill region and points contained in it based
        /// on the origin
        /// </summary>
        /// <param name="origin"> Initial fill point </param>
        /// <returns> Fill information generated from origin </returns>
        FillInfo computeFillInfo(Point origin)
        {
            FillInfo fillInfo = new FillInfo();

            fillInfo.Bounds = new Rectangle(origin.X, origin.Y, origin.X, origin.Y);

            WorldTile targetTile = World.GetTile(origin);

            //queue containing tiles to check
            List <Point> fillQ = new List <Point>();

            fillQ.Add(origin);

            //list that will be pushed with points valid
            //for change. This is used later to populate
            //our flag array
            List <Point> changedPoints = new List <Point>();

            //cache this condition for later optimization
            bool checkRect = World.SelectionRectangle != Rectangle.Empty;

            //iteration bounds. used for optimization
            int boundLeft, boundRight, boundTop, boundBottom;

            //set the bounds depending on the selection rectangle
            if (checkRect)
            {
                boundLeft   = World.SelectionRectangle.X.Clamp(0, WorldSize.Width);
                boundRight  = World.SelectionRectangle.Right.Clamp(0, WorldSize.Width);
                boundTop    = World.SelectionRectangle.Y.Clamp(0, WorldSize.Height);
                boundBottom = World.SelectionRectangle.Bottom.Clamp(0, WorldSize.Height);
            }
            else
            {
                boundLeft   = boundTop = 0;
                boundRight  = WorldSize.Width;
                boundBottom = WorldSize.Height;
            }

            //array of flags containing tiles already processed for optimization
            bool[][] processedTiles = new bool[WorldSize.Width][];

            for (int i = 0; i < WorldSize.Width; i++)
            {
                processedTiles[i] = new bool[WorldSize.Height];
            }

            //process fill queue until there's no remaining options
            while (fillQ.Count > 0)
            {
                //take this point from the queue
                Point currentPoint = fillQ[0];
                fillQ.RemoveAt(0);

                //set the current point as a valid change
                changedPoints.Add(currentPoint);
                processedTiles[currentPoint.X][currentPoint.Y] = true;

                //seek left
                int left = currentPoint.X;
                while (--left >= boundLeft && World.GetTile(left, currentPoint.Y) == targetTile)
                {
                    ;
                }
                left++;

                //seek right
                int right = currentPoint.X;
                while (++right < boundRight && World.GetTile(right, currentPoint.Y) == targetTile)
                {
                    ;
                }
                right--;

                //adjust fill region bounds
                fillInfo.Bounds.X      = Math.Min(left, fillInfo.Bounds.X);
                fillInfo.Bounds.Y      = Math.Min(currentPoint.Y, fillInfo.Bounds.Y);
                fillInfo.Bounds.Width  = Math.Max(right, fillInfo.Bounds.Width);
                fillInfo.Bounds.Height = Math.Max(currentPoint.Y, fillInfo.Bounds.Height);

                //used for optimizing left-right iterations
                bool lAbove = false;
                bool lBelow = false;

                //iterate through row based on calculation and
                //add other potential rows
                for (int x = left; x <= right; x++)
                {
                    Point fillPoint = new Point(x, currentPoint.Y);

                    changedPoints.Add(fillPoint);

                    //check tile above
                    if (fillPoint.Y > boundTop)
                    {
                        Point pointAbove = new Point(fillPoint.X, fillPoint.Y - 1);

                        if (!processedTiles[pointAbove.X][pointAbove.Y] && World.GetTile(pointAbove) == targetTile)
                        {
                            if (!lAbove)
                            {
                                fillQ.Add(pointAbove);
                            }

                            lAbove = true;
                        }
                        else
                        {
                            lAbove = false;
                        }

                        //declare this tile as processed
                        processedTiles[pointAbove.X][pointAbove.Y] = true;
                    }

                    //check tile below
                    if (fillPoint.Y + 1 < boundBottom)
                    {
                        Point pointBelow = new Point(fillPoint.X, fillPoint.Y + 1);
                        if (!processedTiles[pointBelow.X][pointBelow.Y] && World.GetTile(pointBelow) == targetTile)
                        {
                            if (!lBelow)
                            {
                                fillQ.Add(pointBelow);
                            }

                            lBelow = true;
                        }
                        else
                        {
                            lBelow = false;
                        }

                        //declare this tile as processed
                        processedTiles[pointBelow.X][pointBelow.Y] = true;
                    }
                }
            }

            //normalize fill region size
            fillInfo.Bounds.Width  = fillInfo.Bounds.Width - fillInfo.Bounds.X + 1;
            fillInfo.Bounds.Height = fillInfo.Bounds.Height - fillInfo.Bounds.Y + 1;

            //if there's a selection in the world, determine if we should
            //use it, or the bounds of the changes
            if (checkRect && !World.SelectionRectangle.Contains(fillInfo.Bounds))
            {
                fillInfo.Bounds = World.SelectionRectangle;
            }

            fillInfo.Changes = new bool[fillInfo.Bounds.Width][];

            for (int i = 0; i < fillInfo.Bounds.Width; i++)
            {
                fillInfo.Changes[i] = new bool[fillInfo.Bounds.Height];
            }

            //convert changed tiles into flags for optimized
            //use in applying changes
            foreach (Point change in changedPoints)
            {
                fillInfo.Changes[change.X - fillInfo.Bounds.X]
                [change.Y - fillInfo.Bounds.Y] = true;
            }

            return(fillInfo);
        }
Ejemplo n.º 15
0
    private FillInfo[,] GenerateRefillTrendMap(Container2D_Rectangular container)
    {
        var ret   = new FillInfo[container.Height, container.Width];
        var slots = container.WrapperRect;
        Action <int, int, List <SlotWrapper2D> > picker = (x, y, list) => {
            if (x < 0 || x >= container.Width)
            {
                return;
            }
            if (y < 0 || y >= container.Height)
            {
                return;
            }
            if (null != slots[y, x].slotAttribute && slots[y, x].slotAttribute.category == SlotAttribute.Category.INSULATOR)
            {
                return;
            }
            list.Add(slots[y, x]);
        };
        Action <int, int> exitMarker = (x, y) => {
            if (null == ret[y, x])
            {
                ret[y, x]             = new FillInfo();
                ret[y, x].ancestorPos = new Pos2D(x, y + 1);
            }
        };

        container.ForeachSlot((x, y, slot) => {
            if (null != ret[y, x])
            {
                return;
            }
            if (null != slot.slotAttribute && slot.slotAttribute.category == SlotAttribute.Category.INSULATOR)
            {
                return;
            }
            var ctx       = new AStar.Context <SlotWrapper2D>();
            ctx.start     = slots[y, x];
            ctx.procTrait = (s) => {
                return(s.Trait);
            };
            ctx.procWeight = (SlotWrapper2D from, SlotWrapper2D to) => {
                foreach (var t in surroundingOffsets)
                {
                    if (to.pos.x == from.pos.x + t.item1 && to.pos.y == from.pos.y + t.item2)
                    {
                        return(t.item3);
                    }
                }
                throw new NotImplementedException();
            };
            ctx.procTermination = (SlotWrapper2D s) => {
                return(s.pos.y == container.Height - 1);
            };
            ctx.procDistanceEstimator = (SlotWrapper2D s) => {
                return((container.Height - 1 - s.pos.y) * 1.0001f);
            };
            ctx.procAdjacencies = (SlotWrapper2D s) => {
                var list = new List <SlotWrapper2D>();
                foreach (var t in surroundingOffsets)
                {
                    picker.Invoke(s.pos.x + t.item1, s.pos.y + t.item2, list);
                }
                return(list);
            };

            if (AStar.Evaluate(ctx))
            {
                var result = ctx.path;
                if (result.Count <= 0)
                {
                    exitMarker.Invoke(x, y);
                }
                else
                {
                    result.Reverse();
                    for (int i = 0, len = result.Count - 1; i < len; i++)
                    {
                        if (null != ret[result[i].pos.y, result[i].pos.x])
                        {
                            continue;
                        }
                        var t         = new FillInfo();
                        t.ancestorPos = new Pos2D(result[i + 1].pos.x, result[i + 1].pos.y);
                        ret[result[i].pos.y, result[i].pos.x] = t;
                    }
                    exitMarker(result[result.Count - 1].pos.x, result[result.Count - 1].pos.y);
                }
            }
            else
            {
                ret[y, x] = new FillInfo();
            }
        });

        for (int y = 0; y < container.Height; y++)
        {
            for (int x = 0; x < container.Width; x++)
            {
                var fi = ret[y, x];
                if (null == fi)
                {
                    continue;
                }
                if (fi.IsOnSpot)
                {
                    continue;
                }
                fi.childrenPos = new List <Pos2D>();
                foreach (var t in surroundingOffsets)
                {
                    var sx = x + t.item1;
                    var sy = y + t.item2;

                    if (!container.IsLegalPosition(sx, sy))
                    {
                        continue;
                    }
                    var slot = container.GetSlot(sx, sy);
                    if (null != slot && null != slot.slotAttribute && slot.slotAttribute.category == SlotAttribute.Category.INSULATOR)
                    {
                        continue;
                    }

                    var touch = ret[sy, sx];
                    if (null != touch.ancestorPos && touch.ancestorPos.x == x && touch.ancestorPos.y == y)
                    {
                        fi.childrenPos.Add(new Pos2D(sx, sy));
                    }
                }
            }
        }

        return(ret);
    }
Ejemplo n.º 16
0
	private List<RefillFlowRecord.Path> CollectFromPos(Container2D_Rectangular container, FillInfo[,] fillInfos, int fromX, int fromY)
	{
		if (!container.IsLegalPosition(fromX, fromY) || null != container.GetSlot(fromX, fromY)) return null;
		var fi = fillInfos[fromY, fromX];
		var ret = new List<RefillFlowRecord.Path>();

		var selfPos = new Pos2D(fromX, fromY);
		var self = new RefillFlowRecord.Path();
		self.dst = selfPos;
		ret.Add(self);

		foreach (var child in fi.childrenPos)
		{
			var sub = CollectFromPos(container, fillInfos, child.x, child.y);
			if (null == sub) continue;
			ret.AddRange(sub);
		}
		foreach (var r in ret)
		{
			r.src = selfPos;
			r.movements.Add(selfPos);
		}
		return ret;
	}
        private static Fill GetNewFill(FillInfo fillInfo, Boolean ignoreMod = true)
        {
            var fill = new Fill();

            var patternFill = new PatternFill();
            if (fillInfo.Fill.PatternTypeModified || ignoreMod)
                patternFill.PatternType = fillInfo.Fill.PatternType.ToOpenXml();

            if (fillInfo.Fill.PatternColorModified || ignoreMod)
            {
                var foregroundColor = new ForegroundColor();
                if (fillInfo.Fill.PatternColor.ColorType == XLColorType.Color)
                    foregroundColor.Rgb = fillInfo.Fill.PatternColor.Color.ToHex();
                else if (fillInfo.Fill.PatternColor.ColorType == XLColorType.Indexed)
                    foregroundColor.Indexed = (UInt32)fillInfo.Fill.PatternColor.Indexed;
                else
                {
                    foregroundColor.Theme = (UInt32)fillInfo.Fill.PatternColor.ThemeColor;
                    if (fillInfo.Fill.PatternColor.ThemeTint != 1)
                        foregroundColor.Tint = fillInfo.Fill.PatternColor.ThemeTint;
                }
                patternFill.AppendChild(foregroundColor);
            }

            if (fillInfo.Fill.PatternBackgroundColorModified || ignoreMod)
            {
                var backgroundColor = new BackgroundColor();
                if (fillInfo.Fill.PatternBackgroundColor.ColorType == XLColorType.Color)
                    backgroundColor.Rgb = fillInfo.Fill.PatternBackgroundColor.Color.ToHex();
                else if (fillInfo.Fill.PatternBackgroundColor.ColorType == XLColorType.Indexed)
                    backgroundColor.Indexed = (UInt32)fillInfo.Fill.PatternBackgroundColor.Indexed;
                else
                {
                    backgroundColor.Theme = (UInt32)fillInfo.Fill.PatternBackgroundColor.ThemeColor;
                    if (fillInfo.Fill.PatternBackgroundColor.ThemeTint != 1)
                        backgroundColor.Tint = fillInfo.Fill.PatternBackgroundColor.ThemeTint;
                }
                patternFill.AppendChild(backgroundColor);
            }

            fill.AppendChild(patternFill);

            return fill;
        }
Ejemplo n.º 18
0
		/// <summary>
		/// Preenche a tabela de dados especificada, com os critérios especificados.
		/// </summary>
		/// <param name="source">O nome da origem. Formato: <c>dataTable:tabela_ou_view</c></param>
		/// <param name="cond">O critério de seleção dos registros.</param>
		/// <param name="orderBy">A ordem</param>
		public int FillData(string source, SqlCondition cond, SqlOrder orderBy)
		{
			FillInfo fi = new FillInfo(source);
			return FillData(fi.DataTable, new SqlQuery(new SqlTableSource(fi.Source), cond, orderBy));
		}