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); }
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(); } } }
public AIStatic GetActualCover(AIObject aiobj) { AIStatic actual = GetNearestStatic(aiobj.Position, AIStaticType.Cover); if (actual.IsObjectLocatedInside(aiobj)) { return(actual); } else { return(null); } }
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); }
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); }
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); }
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); }
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; } } } }
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); }
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); }
/// <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(); }
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(); } } }
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); }
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; } } } }