internal override void Update(MySmallShipBot bot) { base.Update(bot); m_targetVisibleTime += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; //No need to have this here, because it runs on main thread //lock (MyEntities.EntityCloseLock) { UpdateTargetVisibility(bot); if (m_targetVisible && m_target != null) { // If target is visible long enough, attack is initiated, this also happens when target is too close or target shoots MySmallShip smallShip = m_target as MySmallShip; if (m_targetVisibleTime > DISCOVER_TIME || (m_target.GetPosition() - bot.GetPosition()).LengthSquared() < IDENTIFY_DISTANCE_SQR || (smallShip != null && smallShip.Weapons != null && smallShip.Weapons.IsShooting())) { bot.AddSeenEnemy(m_target); m_state = CuriousState.FINISHED; return; } } } switch (m_state) { // First stage - goto location case CuriousState.GOTO: m_gotoLocationHelper.Update(bot); if (m_gotoLocationHelper.PathNotFound || Vector3.DistanceSquared(bot.GetPosition(), m_location) < LOCATION_NEAR_DISTANCE_SQR) { TrySwitchExploreSearch(bot); } break; // Second stage - try explore area case CuriousState.EXPLORE: m_explorationTime += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; m_exploreTargetTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; if (m_explorationTime > EXPLORATION_TIME) { m_state = CuriousState.FINISHED; } else if (m_exploreTargetTimer <= 0) { TrySwitchExploreSearch(bot); } else { float factor = MathHelper.Clamp((m_exploreTarget - bot.GetPosition()).Length() / 20, 0.15f, 0.45f); bot.Move(m_exploreTarget, m_exploreTarget, GetUpPlane(bot), false, 1, 5, factor, slowRotation: true); } break; // Paralel searching for new explore location case CuriousState.EXPLORE_SEARCHING: TrySwitchToExplore(bot); if (m_explorationTime > EXPLORATION_TIME) { m_state = CuriousState.FINISHED; } break; // Third stage - nothing interesting was found (IsInvalid is true) case CuriousState.FINISHED: default: break; } }