コード例 #1
0
ファイル: Clock.cs プロジェクト: OldAmnis/daggerfall-unity
        int GetTravelTimeInSeconds()
        {
            // First Place resource should be main location of quest
            // This seems to hold true in all quests looked at in detail so far
            QuestResource[] placeResources = ParentQuest.GetAllResources(typeof(Place));
            if (placeResources == null || placeResources.Length == 0)
            {
                Debug.LogError("Clock wants a travel time but quest has no Place resources.");
                return(0);
            }

            // Get location from place resource
            DFLocation location;
            Place      place = (Place)placeResources[0];

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(place.SiteDetails.regionName, place.SiteDetails.locationName, out location))
            {
                Debug.LogErrorFormat("Could not find Quest Place {0}/{1}", place.SiteDetails.regionName, place.SiteDetails.locationName);
                return(0);
            }

            // Get end position in map pixel coordinates
            DFPosition endPos = MapsFile.WorldCoordToMapPixel(location.Exterior.RecordElement.Header.X, location.Exterior.RecordElement.Header.Y);

            // Create a path to location
            // Use the most cautious time possible allowing for player to camp out or stop at inns along the way
            TravelTimeCalculator travelTimeCalculator = new TravelTimeCalculator();

            travelTimeCalculator.GeneratePath(endPos);
            travelTimeCalculator.CalculateTravelTimeTotal(true, false, false, true, false);

            // Get travel time in total days across land and water
            // Allow for return trip travel time plus some fudge for side goals and quest process itself
            // How Daggerfall actually calcutes travel time is currently unknown
            // This should be fair and realistic in most circumstances while still creating time pressures
            // Modify "returnTripMultiplier" to make calcualted quest time harder/easier
            int travelTimeDaysLand  = 0;
            int travelTimeDaysWater = 0;
            int travelTimeDaysTotal = 0;

            if (travelTimeCalculator.TravelTimeTotalLand > 0)
            {
                travelTimeDaysLand = (int)((travelTimeCalculator.TravelTimeTotalLand / 60 / 24) + 0.5);
            }
            if (travelTimeCalculator.TravelTimeTotalWater > 0)
            {
                travelTimeDaysWater = (int)((travelTimeCalculator.TravelTimeTotalWater / 60 / 24) + 0.5);
            }
            travelTimeDaysTotal = (int)((travelTimeDaysLand + travelTimeDaysWater) * returnTripMultiplier);

            return(GetTimeInSeconds(travelTimeDaysTotal, 0, 0));
        }
コード例 #2
0
        public TravelInfo CalculateTravelInfo(ContentReader.MapSummary locationSummary, DFPosition destination)
        {
            // travel time calculator (unfortunately) has side-effects. You must calculate the
            // travel time and then calculate the costs using the same instance.
            TravelTimeCalculator travelTimeCalculator = new TravelTimeCalculator();
            var travelTimeMinutes = travelTimeCalculator.CalculateTravelTime(destination,
                                                                             false, useInns, true, PlayerOwnsHorse(), PlayerHasCart());

            bool playerOwnsShip = DaggerfallWorkshop.Game.Banking.DaggerfallBankManager.OwnsShip;

            travelTimeCalculator.CalculateTripCost(travelTimeMinutes, useInns, playerOwnsShip, true);
            var tripCost = travelTimeCalculator.TotalCost;

            return(new TravelInfo(travelTimeMinutes, tripCost));
        }
コード例 #3
0
        /// <summary>
        /// Gets travel time based on overworld map logic.
        /// </summary>
        /// <param name="place">Target place resource. If null will use first place defined in quest.</param>
        /// <param name="returnTrip">Use return trip multiplier.</param>
        /// <returns>Travel time in seconds.</returns>
        int GetTravelTimeInSeconds(Place place, bool returnTrip = true)
        {
            if (place == null)
            {
                // Get first place resource from quest
                QuestResource[] placeResources = ParentQuest.GetAllResources(typeof(Place));
                if (placeResources == null || placeResources.Length == 0)
                {
                    Debug.LogError("Clock wants a travel time but quest has no Place resources.");
                    return(0);
                }
                place = (Place)placeResources[0];
            }

            // Get target location from place resource
            DFLocation location;

            if (!DaggerfallUnity.Instance.ContentReader.GetLocation(place.SiteDetails.regionName, place.SiteDetails.locationName, out location))
            {
                Debug.LogErrorFormat("Could not find Quest Place {0}/{1}", place.SiteDetails.regionName, place.SiteDetails.locationName);
                return(0);
            }

            // Get end position in map pixel coordinates
            DFPosition endPos = MapsFile.WorldCoordToMapPixel(location.Exterior.RecordElement.Header.X, location.Exterior.RecordElement.Header.Y);

            // Create a path to location
            // Use the most cautious time possible allowing for player to camp out or stop at inns along the way
            TravelTimeCalculator travelTimeCalculator = new TravelTimeCalculator();
            int travelTimeMinutes = travelTimeCalculator.CalculateTravelTime(endPos, true, false, false, false, true);

            // Apply return trip multiplier
            if (returnTrip)
            {
                travelTimeMinutes = (int)(travelTimeMinutes * returnTripMultiplier);
            }

            // Always allow at least 1 day for travel time
            if (travelTimeMinutes < 1440)
            {
                travelTimeMinutes = 1440;
            }

            return(GetTimeInSeconds(0, 0, travelTimeMinutes));
        }