Пример #1
0
        protected override IAssignment GetNewOrCurrentAssignment(ActionPriority priority)
        {
            switch (this.State)
            {
                case DwarfState.Working:
                    {
                        Debug.Assert(m_target == null);

                        m_target = AIHelpers.FindNearestEnemy(this.Worker, LivingCategory.Monster);

                        if (m_target == null)
                        {
                            // continue doing work

                            if (this.CurrentAssignment != null)
                                return this.CurrentAssignment;

                            return this.JobManager.FindAssignment(this.Worker);
                        }

                        this.State = DwarfState.Fighting;

                        trace.TraceInformation("Found target: {0}", m_target);

                        if (this.CurrentAssignment == null || (this.CurrentAssignment is AttackAssignment) == false)
                        {
                            trace.TraceInformation("Start attacking: {0}", m_target);

                            var assignment = new AttackAssignment(this, m_target);
                            return assignment;
                        }
                        else
                        {
                            trace.TraceInformation("Continue attacking: {0}", m_target);
                            return this.CurrentAssignment;
                        }
                    }

                case DwarfState.Fighting:
                    if (m_target.IsDestructed)
                        return null;

                    Debug.Assert(this.CurrentAssignment != null);

                    trace.TraceInformation("Continue attacking: {0}", m_target);

                    return this.CurrentAssignment;

                default:
                    throw new Exception();
            }
        }
Пример #2
0
        // return new or current assignment, or null to cancel current assignment, or do nothing is no current assignment
        protected override IAssignment GetNewOrCurrentAssignment(ActionPriority priority)
        {
            if (priority == ActionPriority.Idle)
                return this.CurrentAssignment;

            if (m_target == null)
            {
                m_target = AIHelpers.FindNearestEnemy(this.Worker, LivingCategory.Civilized);

                if (m_target == null)
                {
                    // continue patrolling
                    if (this.CurrentAssignment == null || (this.CurrentAssignment is RandomMoveAssignment) == false)
                    {
                        trace.TraceInformation("Start random move");
                        return new RandomMoveAssignment(null);
                    }
                    else
                    {
                        trace.TraceVerbose("Continue patrolling");
                        return this.CurrentAssignment;
                    }
                }

                trace.TraceInformation("Found target: {0}", m_target);
            }

            Debug.Assert(m_target != null);

            if (this.CurrentAssignment == null || (this.CurrentAssignment is AttackAssignment) == false)
            {
                trace.TraceInformation("Start attacking: {0}", m_target);

                var assignment = new AttackAssignment(this, m_target);
                return assignment;
            }
            else
            {
                trace.TraceInformation("Continue attacking: {0}", m_target);
                return this.CurrentAssignment;
            }
        }