Example #1
0
        protected override bool GetSuitableData(SearchAroundContext ctx, VoxelData unitData, int row, int col, out int altitude)
        {
            altitude = int.MinValue;
            MapCell cell = m_taskEngine.MatchEngine.Map.Get(row, col, ctx.m_weight);

            if (cell.Last == null)
            {
                return(false);
            }

            if (cell.Last == unitData)
            {
                altitude = cell.Last.Prev.Altitude;
            }
            else
            {
                altitude = cell.Last.Altitude;
            }

            Coordinate    coordinate = new Coordinate(row, col, altitude, ctx.m_weight);
            CmdResultCode result     = m_dataController.CanSplit4(
                m_dataController.ControlledData.Type,
                m_dataController.ControlledData.Health,
                coordinate);

            return(result == CmdResultCode.Success);
        }
Example #2
0
        protected virtual bool NextIteration(object context)
        {
            SearchAroundContext ctx = (SearchAroundContext)context;

            ctx.m_deltaCol++;

            if (ctx.m_deltaRow == ctx.m_radius && ctx.m_deltaCol == ctx.m_radius + 1)
            {
                ctx.m_radius++;
                if (ctx.m_radius > ctx.m_maxRadius)
                {
                    return(false);
                }

                ctx.m_deltaRow = -ctx.m_radius;
                ctx.m_deltaCol = -ctx.m_radius;
            }

            else if (ctx.m_deltaCol == ctx.m_radius + 1)
            {
                ctx.m_deltaRow++;
                ctx.m_deltaCol = -ctx.m_radius;
            }

            return(true);
        }
Example #3
0
        protected override void OnConstruct()
        {
            SearchAroundContext ctx = ReadInput <SearchAroundContext>(m_taskInfo.Inputs[0]);
            long unitIndex          = ReadInput <long>(m_taskInfo.Inputs[1]);

            m_unit = m_taskEngine.MatchEngine.GetPlayerView(m_taskInfo.PlayerIndex).GetUnit(unitIndex);
            if (m_unit == null)
            {
                m_taskInfo.StatusCode = TaskInfo.TaskFailed;
                m_taskInfo.State      = TaskState.Completed;
            }
            else
            {
                m_dataController = m_unit.DataController.Clone();
                int mapSize = m_dataController.Map.GetMapSizeWith(m_unit.Data.Weight);
                if (ctx == null)
                {
                    ctx = new SearchAroundContext(m_unit.Position, mapSize, m_unit.Data.Weight, StartRadius, GetMaxRadius(m_unit));
                }
                m_taskEngine.TaskRunner.Run(unitIndex, -1, ctx, FindSuitableData, FindSuitableDataCompleted, (id, context) =>
                {
                    if (m_taskInfo.State == TaskState.Active)
                    {
                        Debug.Assert(false, "Task Runner should not be interrupted when task is in active state");
                        m_taskInfo.StatusCode = TaskInfo.TaskFailed;
                        m_taskInfo.State      = TaskState.Completed;
                    }
                });
            }
        }
Example #4
0
        protected override bool GetSuitableData(SearchAroundContext ctx, VoxelData unitData, int row, int col, out int altitude)
        {
            MapCell   cell    = m_taskEngine.MatchEngine.Map.Get(row, col, ctx.m_weight);
            VoxelData eatable = cell.GetDescendantsWithVoxelData(data => IsEatable(data, unitData));

            if (eatable != null)
            {
                altitude = eatable.Altitude;
                return(true);
            }
            altitude = int.MinValue;
            return(false);
        }
Example #5
0
        private object FindSuitableData(long unitIndex, object context)
        {
            if (!NextIteration(context))
            {
                return(false);
            }

            SearchAroundContext ctx = (SearchAroundContext)context;

            if (!GetSuitableData(ctx))
            {
                return(null);
            }
            return(true);
        }
Example #6
0
        private void FindSuitableDataCompleted(long unitIndex, object context, object result)
        {
            SearchAroundContext ctx = (SearchAroundContext)context;
            bool found = (bool)result;

            if (found)
            {
                HandleSuitableDataFound();
                WriteOutput(0, ctx);
            }
            else
            {
                HandleLastIteration();
                WriteOutput(0, null);
            }
        }
Example #7
0
        protected override bool GetSuitableData(SearchAroundContext ctx)
        {
            VoxelData unitData = m_unit.Data;

            int row = ctx.m_position.Row + ctx.m_deltaRow;
            int col = ctx.m_position.Col + ctx.m_deltaCol;

            if (row < 0 || col < 0 || row >= ctx.m_mapSize || col >= ctx.m_mapSize)
            {
                return(false);
            }

            int altitude;

            if (GetSuitableData(ctx, unitData, row, col, out altitude))
            {
                WriteOutput(1, new[] { m_unit.DataController.Coordinate, new Coordinate(row, col, altitude, ctx.m_weight) });
                return(true);
            }

            return(false);
        }
Example #8
0
        protected override bool GetSuitableData(SearchAroundContext ctx, VoxelData unitData, int row, int col, out int altitude)
        {
            altitude = int.MinValue;
            MapCell cell = m_taskEngine.MatchEngine.Map.Get(row, col, ctx.m_weight);

            if (cell.Last == null)
            {
                return(false);
            }

            if (cell.Last.Owner != unitData.Owner)
            {
                return(false);
            }

            if (cell.Last.Type != (int)KnownVoxelTypes.Ground)
            {
                return(false);
            }

            altitude = cell.Last.Altitude + cell.Last.Height;
            return(true);
        }
Example #9
0
 protected virtual bool GetSuitableData(SearchAroundContext ctx, VoxelData unitData, int row, int col, out int altitude)
 {
     altitude = int.MinValue;
     return(false);
 }
Example #10
0
 protected abstract bool GetSuitableData(SearchAroundContext ctx);