protected override void OnControlledObjectRender(Camera camera) { base.OnControlledObjectRender(camera); if (camera != RendererWorld.Instance.DefaultCamera) { return; } if (EngineDebugSettings.DrawGameSpecificDebugGeometry) { GameCharacter controlledObj = ControlledObject; if (controlledObj != null) { if (taskMove.IsInitialized) { Vec3 pos; if (taskMove.Dynamic != null) { pos = taskMove.Dynamic.Position; } else { pos = taskMove.Position; } bool ignore = false; if (taskAttack != null && taskAttack == taskMove.Dynamic) { ignore = true; } if (!ignore) { camera.DebugGeometry.Color = new ColorValue(0, 1, 0, .5f); camera.DebugGeometry.AddLine(controlledObj.Position, pos); camera.DebugGeometry.AddSphere(new Sphere(pos, 1)); } } if (taskAttack != null) { Vec3 pos = taskAttack.Position; camera.DebugGeometry.Color = new ColorValue(1, 0, 0, .5f); camera.DebugGeometry.AddLine(controlledObj.Position, pos); camera.DebugGeometry.AddSphere(new Sphere(pos, 1)); } } } }
void UpdateInitialWeapons() { GameCharacter controlledObj = ControlledObject; initialWeapons = new List <Weapon>(); foreach (MapObjectAttachedObject attachedObject in controlledObj.AttachedObjects) { MapObjectAttachedMapObject attachedMapObject = attachedObject as MapObjectAttachedMapObject; if (attachedMapObject != null) { Weapon weapon = attachedMapObject.MapObject as Weapon; if (weapon != null) { initialWeapons.Add(weapon); } } } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary> protected override void OnTick() { base.OnTick(); GameCharacter controlledObj = ControlledObject; if (controlledObj != null) { if (initialWeapons == null) { UpdateInitialWeapons(); } if (!forceTaskMove.IsInitialized && forceTaskAttack == null) { updateTaskTimer -= TickDelta; if (updateTaskTimer <= 0) { updateTaskTimer += 1.0f; if (!UpdateTasks()) { updateTaskTimer += .5f; } } } TickTasks(); } if (taskAttack != null) { foreach (Weapon weapon in initialWeapons) { Vec3 pos = taskAttack.Position; Gun gun = weapon as Gun; if (gun != null) { gun.GetAdvanceAttackTargetPosition(false, taskAttack, false, out pos); } weapon.SetForceFireRotationLookTo(pos); } } }
protected void TickTasks() { GameCharacter controlledObj = ControlledObject; float distanceAttack; if (taskAttack != null) { distanceAttack = (taskAttack.Position - controlledObj.Position).LengthFast(); } else { distanceAttack = 0; } if (taskMove.IsInitialized) { Vec3 taskPos; if (taskMove.Dynamic != null) { taskPos = taskMove.Dynamic.Position; } else { taskPos = taskMove.Position; } Vec2 diff = taskPos.ToVec2() - controlledObj.Position.ToVec2(); float len; Vec2 vec = diff; len = vec.NormalizeFast(); if (taskAttack != null && taskAttack == taskMove.Dynamic) { Range optimalAttackDistanceRange = controlledObj.Type.OptimalAttackDistanceRange; if (distanceAttack < optimalAttackDistanceRange.Minimum) { vec *= -1.0f; } else if (distanceAttack <= optimalAttackDistanceRange.Maximum) { vec = Vec2.Zero; } } else { if (len > .3f) { if (len < 1.5f) { vec *= len; //come if (taskAttack == null) { if (taskMove.Dynamic == null) { if (taskMove.dynamic == forceTaskMove.dynamic && taskMove.position == forceTaskMove.position) { ForceTaskMove = new TaskMoveValue(null); } TaskMove = new TaskMoveValue(null); } else { vec = Vec2.Zero; } } } } else { vec = Vec2.Zero; } } if (!controlledObj.ForceAnimationIsEnabled()) { if (vec != Vec2.Zero) { controlledObj.SetForceMoveVector(vec); } } if (taskAttack == null || taskAttack == taskMove.Dynamic) { controlledObj.SetTurnToPosition(taskPos); } } if (taskAttack != null) { foreach (Weapon weapon in initialWeapons) { if (!weapon.Ready) { continue; } //weapon.SetForceFireRotationLookTo( true, taskAttack.Position ); Range range; range = weapon.Type.WeaponNormalMode.UseDistanceRange; if (distanceAttack >= range.Minimum && distanceAttack <= range.Maximum) { weapon.TryFire(false); } range = weapon.Type.WeaponAlternativeMode.UseDistanceRange; if (distanceAttack >= range.Minimum && distanceAttack <= range.Maximum) { weapon.TryFire(true); } } if (taskAttack != taskMove.Dynamic) { controlledObj.SetTurnToPosition(taskAttack.Position); } } }
protected bool UpdateTasks() { GameCharacter controlledObj = ControlledObject; if (controlledObj == null) { return(false); } TaskMoveValue newTaskMove = new TaskMoveValue(null); Dynamic newTaskAttack = null; float moveObjectPriority = 0; float attackObjectPriority = 0; Vec3 controlledObjPos = controlledObj.Position; float radius = controlledObj.ViewRadius; Map.Instance.GetObjects(new Sphere(controlledObjPos, radius), GameFilterGroups.UnitFilterGroup, delegate(MapObject mapObject) { Unit obj = (Unit)mapObject; Vec3 objpos = obj.Position; //check distance Vec3 diff = objpos - controlledObjPos; float objDistance = diff.LengthFast(); if (objDistance > radius) { return; } float priority; //Move task { priority = GetTaskMoveObjectPriority(obj); if (priority != 0 && priority > moveObjectPriority) { moveObjectPriority = priority; newTaskMove = new TaskMoveValue(obj); } } //Attack task { if (initialWeapons.Count != 0) { priority = GetTaskAttackObjectPriority(obj); if (priority != 0 && priority > attackObjectPriority) { attackObjectPriority = priority; newTaskAttack = obj; } } } }); //Move task { if (!newTaskMove.IsInitialized && newTaskAttack != null) { newTaskMove = new TaskMoveValue(newTaskAttack); } if (taskMove.Position != newTaskMove.Position || taskMove.Dynamic != newTaskMove.Dynamic) { TaskMove = newTaskMove; } } //Attack task { if (taskAttack != newTaskAttack) { TaskAttack = newTaskAttack; } } return(taskMove.IsInitialized || taskAttack != null); }