private void AIUpdate(GameTime gameTime) { // AI only works if NPC aboard if (shipInterior.interiorObjects.OfType <Npc>().Any()) { // AI ship direction and movement if (timeSinceLastTurn > millisecondsPerTurn) { if (!roaming) { if (regionKey.Equals("GustoMap")) // TEMP see pathFind comment below { regionKey = "Usopp"; } randomRoamTile = BoundingBoxLocations.RegionMap[regionKey].RegionOceanTiles[RandomEvents.rand.Next(BoundingBoxLocations.RegionMap[regionKey].RegionOceanTiles.Count)]; roaming = true; TilePiece rtp = (TilePiece)randomRoamTile; Point? gridPointTo = rtp.mapCordPoint; currentPath = AIUtility.Pathfind(mapCordPoint.Value, gridPointTo.Value, PathType.Ocean); // NOTE: This freezes the game when hitting GustoMap region (because it is almost all the tiles at the moment) } else { // move to attack/follow target when in range int shotRange = mountedOnShip == null ? 0 : mountedOnShip.shotRange; if (shotRange > 0) { Tuple <Point?, float> targetInfo = AIUtility.ChooseTargetPoint(teamType, shotRange, GetBoundingBox(), inInteriorId, PathType.Ocean); if (targetInfo != null) { // stop distance var distanceToTarget = targetInfo.Item2; if (distanceToTarget <= stopRange) { moving = false; shipSail.moving = false; } else { moving = true; shipSail.moving = true; } Point?targetMapCords = targetInfo.Item1; // compute follow path if (!following) { currentPath = AIUtility.Pathfind(mapCordPoint.Value, targetMapCords.Value, PathType.Ocean); following = true; } } else { following = false; } } // we have found the next tile in path if (currentPath[0].GetBoundingBox().Intersects(GetBoundingBox())) { currentPath.RemoveAt(0); if (currentPath.Count == 0) { roaming = false; following = false; } } if (roaming) { currRowFrame = AIUtility.SetAIShipDirection(currentPath[0].GetBoundingBox().Center.ToVector2(), location); } } shipSail.currRowFrame = currRowFrame; timeSinceLastTurn -= millisecondsPerTurn; } // AI shooting if (mountedOnShip != null) { Vector2?shotDirection = AIUtility.ChooseTargetVector(teamType, mountedOnShip.shotRange, GetBoundingBox(), inInteriorId); mountedOnShip.UpdateAIMountShot(gameTime, shotDirection); // temp setting AI to use weapon slot 0 Vector2 weaponPosOffset = new Vector2(ShipMountTextureCoordinates.WeaponMountCords[bbKey][currRowFrame][0].Item1, ShipMountTextureCoordinates.WeaponMountCords[bbKey][currRowFrame][0].Item2); mountedOnShip.location = GetBoundingBox().Center.ToVector2() + weaponPosOffset; } } }