Beispiel #1
0
        bool DoPathFind()
        {
            Dynamic targetObj = null;

            {
                RTSUnitAI ai = Intellect as RTSUnitAI;
                if (ai != null)
                {
                    targetObj = ai.CurrentTask.Entity;
                }
            }

            //remove this unit from the pathfinding grid
            GetNavigationSystem().RemoveObjectFromMotionMap(this);

            float radius     = Type.Radius;
            Rect  targetRect = new Rect(
                MovePosition.ToVec2() - new Vec2(radius, radius),
                MovePosition.ToVec2() + new Vec2(radius, radius));

            //remove target unit from the pathfinding grid
            if (targetObj != null && targetObj != this)
            {
                GetNavigationSystem().RemoveObjectFromMotionMap(targetObj);
            }

            //TO DO: really need this call?
            GetNavigationSystem().AddTempClearMotionMap(targetRect);

            const int maxFieldsDistance = 1000;
            const int maxFieldsToCheck  = 100000;
            bool      found             = GetNavigationSystem().FindPath(
                Type.Radius * 2 * 1.1f,
                Position.ToVec2(),
                MovePosition.ToVec2(),
                maxFieldsDistance,
                maxFieldsToCheck,
                true,
                false,
                path);

            GetNavigationSystem().DeleteAllTempClearedMotionMap();

            //add target unit to the pathfinding grid
            if (targetObj != null && targetObj != this)
            {
                GetNavigationSystem().AddObjectToMotionMap(targetObj);
            }

            //add this unit the the pathfinding grid
            GetNavigationSystem().AddObjectToMotionMap(this);

            return(found);
        }
        protected override void DoTaskInternal(RTSUnitAI.Task task)
        {
            if (task.Type != Task.Types.ProductUnit)
                ControlledObject.StopProductUnit();

            base.DoTaskInternal(task);

            if (task.Type == Task.Types.ProductUnit)
            {
                ControlledObject.StartProductUnit((RTSUnitType)task.EntityType);
            }
        }
 private bool IsEnableTaskTypeInTasks(List<RTSUnitAI.UserControlPanelTask> tasks, RTSUnitAI.Task.Types taskType)
 {
     if (tasks == null)
         return false;
     foreach (RTSUnitAI.UserControlPanelTask task in tasks)
         if (task.Task.Type == taskType && task.Enable)
             return true;
     return false;
 }