예제 #1
0
        public void TakeCover()
        {
            AIStatic cover = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.Cover);

            if (cover == _cover)
            {
                return;
            }

            if (cover.IsAllowedToEnter(this))
            {
                this.MoveTo(cover.Position);
                _cover = cover;
                if (_isShootAt)
                {
                    UpdateFitness(AIParams.FITNESS_INCREASE_GET_TO_COVER);
                }
            }
            else
            {
                _coversBanned.Add(cover);
                TakeCover(AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned));
            }
            OccupyBy(AIAction.TakeCover);
        }
예제 #2
0
        private void UpdatePickUpStatic()
        {
            if (_pickUpStatic != null)
            {
                if ((_pickUpStatic.Position - this.Position).Length() <= 30f)
                {
                    switch (_pickUpStatic.Type)
                    {
                    case AIStaticType.Bonus:
                        if (_life > 0.5)
                        {
                            BoostOrDecreaseExperience(AIParams.CONFIG_INCREASE_EXP_BONUS);
                        }

                        if (_life > 0.5)
                        {
                            UpdateFitness(AIParams.FITNESS_INCREASE_BONUS);
                        }
                        break;

                    case AIStaticType.FirstAidKit:
                        HealOrHarm(AIParams.CONFIG_INCREASE_MED);
                        if (_life < 0.5)
                        {
                            UpdateFitness(AIParams.FITNESS_INCREASE_MED);
                        }
                        break;

                    default:
                        break;
                    }
                    _pickUpStatic.Position = new Vector3((float)AIGame.random.NextDouble() * AIGame.terrain.TerrainHeightMap.RealSize, 0, (float)AIGame.random.NextDouble() * AIGame.terrain.TerrainHeightMap.RealSize);
                    //_pickUpStatic.IsGone = true;

                    // free rest of the objects picking up this static
                    foreach (AIObject aiobj in _pickUpStatic.AIObjects)
                    {
                        if (!aiobj.Equals(this))
                        {
                            aiobj._pickUpStatic = null;
                            aiobj.SetFree();
                        }
                    }

                    if (_pickUpStatic.AIObjects.Count > 0)
                    {
                        _pickUpStatic.AIObjects.Clear();
                    }

                    _pickUpStatic = null;
                    SetFree();
                }
            }
        }
예제 #3
0
파일: AIContainer.cs 프로젝트: siupa/AIGame
        public AIStatic GetActualCover(AIObject aiobj)
        {
            AIStatic actual = GetNearestStatic(aiobj.Position, AIStaticType.Cover);

            if (actual.IsObjectLocatedInside(aiobj))
            {
                return(actual);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public void PickUpMedKit()
        {
            if (this._life == 1)
            {
                UpdateFitness(AIParams.FITNESS_DECREASE_MED);
                SetFree();
                return;
            }

            AIStatic medKit = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.FirstAidKit);

            _pickUpStatic = medKit;
            this.MoveTo(medKit.Position);
            medKit.AIObjects.Add(this);
            OccupyBy(AIAction.PUMed);
        }
예제 #5
0
        private AIStatic GetNearestAvailableStatic(AIStaticType type)
        {
            AIStatic nearest  = null;
            float    min_dist = float.MaxValue;

            foreach (AIStatic aistatic in AIGame.AIContainer.AIStatics.FindAll(delegate(AIStatic ais) { return(ais.Type == type); }))
            {
                float real_dist = (aistatic.Position - Position).Length();
                if (real_dist < min_dist)
                {
                    nearest  = aistatic;
                    min_dist = real_dist;
                }
            }
            return(nearest);
        }
예제 #6
0
        public void PickUpBonus()
        {
            if (_experience == 100)
            {
                UpdateFitness(AIParams.FITNESS_DECREASE_BONUS);
                SetFree();
                return;
            }

            AIStatic bonus = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.Bonus);

            _pickUpStatic = bonus;
            this.MoveTo(bonus.Position);
            bonus.AIObjects.Add(this);

            OccupyBy(AIAction.PUBonus);
        }
예제 #7
0
파일: AIContainer.cs 프로젝트: siupa/AIGame
        public AIStatic GetNearestStatic(Vector3 position, AIStaticType type)
        {
            AIStatic nearest  = null;
            float    min_dist = float.MaxValue;

            foreach (AIStatic aistatic in _aistatics)
            {
                if (aistatic.Type == type)
                {
                    float real_dist = (aistatic.Position - position).Length();
                    if (real_dist < min_dist)
                    {
                        nearest  = aistatic;
                        min_dist = real_dist;
                    }
                }
            }
            return(nearest);
        }
예제 #8
0
        private void UpdateTakeCover()
        {
            if (_cover != null)
            {
                if (_cover.IsObjectLocatedInside(this) && !_inCover)
                {
                    if (!_cover.IsAllowedToEnter(this))
                    {
                        _coversBanned.Add(_cover);
                        _cover = AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned);
                        TakeCover(_cover);
                        return;
                    }

                    _inCover = true;
                    _coversBanned.Clear();
                    if (!_cover.AIObjects.Contains(this))
                    {
                        _cover.AIObjects.CopyTo(_cover.AIObjects_Prev);
                        _cover.AIObjects.Add(this);
                        _cover.TeamInside = this.Team.TeamType;
                        SetFree();
                    }
                }

                if (!_cover.IsObjectLocatedInside(this) && _inCover)
                {
                    _inCover = false;
                    if (_cover.AIObjects.Contains(this))
                    {
                        _cover.AIObjects.CopyTo(_cover.AIObjects_Prev);
                        _cover.AIObjects.Remove(this);
                        if (_cover.AIObjects.Count == 0)
                        {
                            _cover.TeamInside = AITeamType.NULL;
                        }
                        _cover = null;
                    }
                }
            }
        }
예제 #9
0
        public void TakeCover(AIStatic cover)
        {
            if (cover == null)
            {
                SetFree();
                _coversBanned.Clear();
                return;
            }

            if (cover.IsAllowedToEnter(this))
            {
                this.MoveTo(cover.Position);
                _cover = cover;
            }
            else
            {
                _coversBanned.Add(cover);
                TakeCover(AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned));
            }
            OccupyBy(AIAction.TakeCover);
        }
예제 #10
0
파일: AIContainer.cs 프로젝트: siupa/AIGame
        public AIStatic GetOtherNearestStatic(Vector3 position, AIStaticType type, List <AIStatic> not_this_ones)
        {
            AIStatic nearest  = null;
            float    min_dist = float.MaxValue;

            foreach (AIStatic aistatic in _aistatics)
            {
                if (not_this_ones.Contains(aistatic))
                {
                    continue;
                }
                if (aistatic.Type == type)
                {
                    float real_dist = (aistatic.Position - position).Length();
                    if (real_dist < min_dist)
                    {
                        nearest  = aistatic;
                        min_dist = real_dist;
                    }
                }
            }
            return(nearest);
        }
예제 #11
0
파일: AIObject.cs 프로젝트: siupa/AIGame
 /// <summary>
 /// Cancels all the posible actions undertaken before. 
 /// Needs to be updated everytime actions logic is changed or new action added.
 /// </summary>
 public void CancelPreviousActions()
 {
     _pickUpStatic = null;
     SetFree();
 }
예제 #12
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        private void UpdatePickUpStatic()
        {
            if (_pickUpStatic != null)
            {
                if ((_pickUpStatic.Position - this.Position).Length() <= 30f)
                {
                    switch (_pickUpStatic.Type)
                    {
                        case AIStaticType.Bonus:
                            if (_life > 0.5)
                                BoostOrDecreaseExperience(AIParams.CONFIG_INCREASE_EXP_BONUS);

                            if (_life > 0.5)
                                UpdateFitness(AIParams.FITNESS_INCREASE_BONUS);
                            break;
                        case AIStaticType.FirstAidKit:
                            HealOrHarm(AIParams.CONFIG_INCREASE_MED);
                            if (_life < 0.5)
                                UpdateFitness(AIParams.FITNESS_INCREASE_MED);
                            break;
                        default:
                            break;
                    }
                    _pickUpStatic.Position = new Vector3((float)AIGame.random.NextDouble() * AIGame.terrain.TerrainHeightMap.RealSize, 0, (float)AIGame.random.NextDouble() * AIGame.terrain.TerrainHeightMap.RealSize);
                    //_pickUpStatic.IsGone = true;

                    // free rest of the objects picking up this static
                    foreach (AIObject aiobj in _pickUpStatic.AIObjects)
                    {
                        if (!aiobj.Equals(this))
                        {
                            aiobj._pickUpStatic = null;
                            aiobj.SetFree();
                        }
                    }

                    if(_pickUpStatic.AIObjects.Count > 0)
                        _pickUpStatic.AIObjects.Clear();

                    _pickUpStatic = null;
                    SetFree();
                }
            }
        }
예제 #13
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        public void TakeCover(AIStatic cover)
        {
            if (cover == null)
            {
                SetFree();
                _coversBanned.Clear();
                return;
            }

            if (cover.IsAllowedToEnter(this))
            {
                this.MoveTo(cover.Position);
                _cover = cover;
            }
            else
            {
                _coversBanned.Add(cover);
                TakeCover(AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned));
            }
            OccupyBy(AIAction.TakeCover);
        }
예제 #14
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        public void TakeCover()
        {
            AIStatic cover = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.Cover);
            if (cover == _cover)
                return;

            if (cover.IsAllowedToEnter(this))
            {
                this.MoveTo(cover.Position);
                _cover = cover;
                if (_isShootAt)
                    UpdateFitness(AIParams.FITNESS_INCREASE_GET_TO_COVER);
            }
            else
            {
                _coversBanned.Add(cover);
                TakeCover(AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned));
            }
            OccupyBy(AIAction.TakeCover);
        }
예제 #15
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        public void PickUpMedKit()
        {
            if (this._life == 1)
            {
                UpdateFitness(AIParams.FITNESS_DECREASE_MED);
                SetFree();
                return;
            }

            AIStatic medKit = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.FirstAidKit);
            _pickUpStatic = medKit;
            this.MoveTo(medKit.Position);
            medKit.AIObjects.Add(this);
            OccupyBy(AIAction.PUMed);
        }
예제 #16
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        public void PickUpBonus()
        {
            if (_experience == 100)
            {
                UpdateFitness(AIParams.FITNESS_DECREASE_BONUS);
                SetFree();
                return;
            }

            AIStatic bonus = AIGame.AIContainer.GetNearestStatic(this.Position, AIStaticType.Bonus);
            _pickUpStatic = bonus;
            this.MoveTo(bonus.Position);
            bonus.AIObjects.Add(this);

            OccupyBy(AIAction.PUBonus);
        }
예제 #17
0
파일: AIObject.cs 프로젝트: siupa/AIGame
        private void UpdateTakeCover()
        {
            if (_cover != null)
            {
                if (_cover.IsObjectLocatedInside(this) && !_inCover)
                {
                    if (!_cover.IsAllowedToEnter(this))
                    {
                        _coversBanned.Add(_cover);
                        _cover = AIGame.AIContainer.GetOtherNearestStatic(this.Position, AIStaticType.Cover, _coversBanned);
                        TakeCover(_cover);
                        return;
                    }

                    _inCover = true;
                    _coversBanned.Clear();
                    if (!_cover.AIObjects.Contains(this))
                    {
                        _cover.AIObjects.CopyTo(_cover.AIObjects_Prev);
                        _cover.AIObjects.Add(this);
                        _cover.TeamInside = this.Team.TeamType;
                        SetFree();
                    }
                }

                if(!_cover.IsObjectLocatedInside(this) && _inCover)
                {
                    _inCover = false;
                    if (_cover.AIObjects.Contains(this))
                    {
                        _cover.AIObjects.CopyTo(_cover.AIObjects_Prev);
                        _cover.AIObjects.Remove(this);
                        if (_cover.AIObjects.Count == 0)
                            _cover.TeamInside = AITeamType.NULL;
                        _cover = null;
                    }
                }
            }
        }
예제 #18
0
 /// <summary>
 /// Cancels all the posible actions undertaken before.
 /// Needs to be updated everytime actions logic is changed or new action added.
 /// </summary>
 public void CancelPreviousActions()
 {
     _pickUpStatic = null;
     SetFree();
 }