/// <summary>
 /// Initializes a new instance of the <see cref="BaseCreatorEditorSettings" /> struct
 /// when the unit composition is NOT preset.
 /// </summary>
 /// <param name="unitName">Name of the unit.</param>
 /// <param name="isOwnerUser">if set to <c>true</c> [is owner user].</param>
 /// <param name="elementQty">The element qty.</param>
 /// <param name="userRelations">The user relations.</param>
 /// <param name="cmsPerCmd">The CMS per command.</param>
 /// <param name="activeCMs">The active c ms.</param>
 /// <param name="deployDate">The deploy date.</param>
 /// <param name="losTurrets">The LOS turrets.</param>
 /// <param name="missileLaunchers">The missile launchers.</param>
 /// <param name="passiveCMs">The passive c ms.</param>
 /// <param name="shieldGens">The shield gens.</param>
 /// <param name="sensors">The sensors.</param>
 /// <param name="formation">The formation.</param>
 public BaseCreatorEditorSettings(string unitName, bool isOwnerUser, int elementQty, DebugDiploUserRelations userRelations, int cmsPerCmd, int activeCMs,
     GameDate deployDate, DebugLosWeaponLoadout losTurrets, DebugWeaponLoadout missileLaunchers, int passiveCMs, int shieldGens, int sensors,
     DebugBaseFormation formation)
     : base(unitName, isOwnerUser, elementQty, userRelations, cmsPerCmd, activeCMs, deployDate, losTurrets, missileLaunchers, passiveCMs,
         shieldGens, sensors) {
     Formation = formation;
 }
 public UnitCreatorConfiguration(string unitName, Player owner, GameDate deployDate, string cmdDesignName, IEnumerable<string> elementDesignNames) {
     UnitName = unitName;
     Owner = owner;
     DeployDate = deployDate;
     CmdDesignName = cmdDesignName;
     ElementDesignNames = elementDesignNames;
     ValidateDeployDate();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseCreatorEditorSettings" /> struct
 /// when the unit composition is preset.
 /// </summary>
 /// <param name="unitName">Name of the unit.</param>
 /// <param name="isOwnerUser">if set to <c>true</c> [is owner user].</param>
 /// <param name="userRelations">The user relations.</param>
 /// <param name="cmsPerCmd">The CMS per command.</param>
 /// <param name="activeCMs">The active c ms.</param>
 /// <param name="deployDate">The deploy date.</param>
 /// <param name="losTurrets">The LOS turrets.</param>
 /// <param name="missileLaunchers">The missile launchers.</param>
 /// <param name="passiveCMs">The passive c ms.</param>
 /// <param name="shieldGens">The shield gens.</param>
 /// <param name="sensors">The sensors.</param>
 /// <param name="formation">The formation.</param>
 /// <param name="presetHullCats">The preset hull cats.</param>
 public BaseCreatorEditorSettings(string unitName, bool isOwnerUser, DebugDiploUserRelations userRelations, int cmsPerCmd, int activeCMs,
     GameDate deployDate, DebugLosWeaponLoadout losTurrets, DebugWeaponLoadout missileLaunchers, int passiveCMs, int shieldGens, int sensors,
     DebugBaseFormation formation, IList<FacilityHullCategory> presetHullCats)
     : base(unitName, isOwnerUser, userRelations, cmsPerCmd, activeCMs, deployDate, losTurrets, missileLaunchers, passiveCMs, shieldGens,
           sensors) {
     Formation = formation;
     PresetElementHullCategories = presetHullCats;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FleetCreatorEditorSettings" /> struct
 /// when the unit composition is NOT preset.
 /// </summary>
 /// <param name="unitName">Name of the unit.</param>
 /// <param name="isOwnerUser">if set to <c>true</c> [is owner user].</param>
 /// <param name="elementQty">The element qty.</param>
 /// <param name="userRelations">The user relations.</param>
 /// <param name="cmsPerCmd">The CMS per command.</param>
 /// <param name="activeCMs">The active c ms.</param>
 /// <param name="deployDate">The deploy date.</param>
 /// <param name="losTurrets">The LOS turrets.</param>
 /// <param name="missileLaunchers">The missile launchers.</param>
 /// <param name="passiveCMs">The passive c ms.</param>
 /// <param name="shieldGens">The shield gens.</param>
 /// <param name="sensors">The sensors.</param>
 /// <param name="formation">The formation.</param>
 /// <param name="toMove">if set to <c>true</c> [to move].</param>
 /// <param name="findFarthest">if set to <c>true</c> [find farthest].</param>
 /// <param name="toAttack">if set to <c>true</c> [to attack].</param>
 /// <param name="stanceExclusions">The stance exclusions.</param>
 public FleetCreatorEditorSettings(string unitName, bool isOwnerUser, int elementQty, DebugDiploUserRelations userRelations, int cmsPerCmd, int activeCMs,
     GameDate deployDate, DebugLosWeaponLoadout losTurrets, DebugWeaponLoadout missileLaunchers, int passiveCMs, int shieldGens, int sensors,
     DebugFleetFormation formation, bool toMove, bool findFarthest, bool toAttack, DebugShipCombatStanceExclusions stanceExclusions)
     : base(unitName, isOwnerUser, elementQty, userRelations, cmsPerCmd, activeCMs, deployDate, losTurrets, missileLaunchers, passiveCMs,
         shieldGens, sensors) {
     Formation = formation;
     Move = toMove;
     FindFarthest = findFarthest;
     Attack = toAttack;
     StanceExclusions = stanceExclusions;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes the change to a new level of coverage BEFORE the new level of coverage
        /// is applied.
        /// </summary>
        /// <param name="newCoverage">The new coverage.</param>
        protected override void PreProcessChange(IntelCoverage newCoverage) {
            if (newCoverage < CurrentCoverage) {
                // we have less data than before so record the level we had and stamp the date
                DatedCoverage = CurrentCoverage;
                DateStamp = GameTime.Instance.CurrentDate;
            }
            if (newCoverage > CurrentCoverage && newCoverage >= DatedCoverage) {
                // we have more data than before and it is the same or more than our previous record, so erase the previous record
                DatedCoverage = default(IntelCoverage);
                DateStamp = default(GameDate);
            }
            // if newCoverage is same as currentCoverage than they are both None and this is a new instance - nothing to change
            // if we have more data than before, but we still haven't reached our record, then nothing to change

            // CurrentCoverage is set to newCoverage after PreProcessChange(newCoverage) finishes
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AUnitCreatorEditorSettings" /> struct
 /// when the unit composition is NOT preset.
 /// </summary>
 /// <param name="unitName">Name of the unit.</param>
 /// <param name="isOwnerUser">if set to <c>true</c> [is owner user].</param>
 /// <param name="elementQty">The element qty.</param>
 /// <param name="userRelations">The user relations.</param>
 /// <param name="cmsPerCmd">The CMS per command.</param>
 /// <param name="activeCMs">The active c ms.</param>
 /// <param name="deployDate">The deploy date.</param>
 /// <param name="losTurrets">The LOS turrets.</param>
 /// <param name="missileLaunchers">The missile launchers.</param>
 /// <param name="passiveCMs">The passive c ms.</param>
 /// <param name="shieldGens">The shield gens.</param>
 /// <param name="sensors">The sensors.</param>
 public AUnitCreatorEditorSettings(string unitName, bool isOwnerUser, int elementQty, DebugDiploUserRelations userRelations, int cmsPerCmd,
     int activeCMs, GameDate deployDate, DebugLosWeaponLoadout losTurrets, DebugWeaponLoadout missileLaunchers, int passiveCMs, int shieldGens,
     int sensors) {
     UnitName = unitName;
     IsOwnerUser = isOwnerUser;
     IsCompositionPreset = false;
     NonPresetElementQty = elementQty;
     DesiredRelationshipWithUser = userRelations;
     CMsPerCommand = cmsPerCmd;
     ActiveCMsPerElement = activeCMs;
     DateToDeploy = deployDate;
     LosTurretsPerElement = losTurrets;
     MissileLaunchersPerElement = missileLaunchers;
     PassiveCMsPerElement = passiveCMs;
     ShieldGeneratorsPerElement = shieldGens;
     SensorsPerElement = sensors;
 }
    /// <summary>
    /// Generates a random fleet creator, places it at location and deploys it on the provided date.
    /// </summary>
    /// <param name="owner">The owner.</param>
    /// <param name="location">The location.</param>
    /// <param name="deployDate">The deploy date.</param>
    /// <returns></returns>
    public FleetCreator GenerateRandomAutoFleetCreator(Player owner, Vector3 location, GameDate deployDate) {
        string unitName = GetUniqueUnitName("AutoFleet");
        int cmsPerCmd = RandomExtended.Range(0, 3);
        Formation formation = Formation.Diamond; // = Enums<Formation>.GetRandom(excludeDefault: true);
        string cmdDesignName = MakeAndRecordFleetCmdDesign(owner, unitName, cmsPerCmd, formation);

        int elementQty = RandomExtended.Range(1, TempGameValues.MaxShipsPerFleet);
        var hullStats = CreateShipHullStats(elementQty);
        var turretLoadout = DebugLosWeaponLoadout.Random;
        var missileLoadout = DebugWeaponLoadout.Random;
        int elementPassiveCMs = RandomExtended.Range(0, 3);
        int elementActiveCMs = RandomExtended.Range(0, 3);
        int elementSensors = RandomExtended.Range(1, 5);
        int elementShieldGens = RandomExtended.Range(0, 3);
        var combatStances = Enums<ShipCombatStance>.GetValues(excludeDefault: true);
        var elementDesignNames = MakeAndRecordShipDesigns(owner, hullStats, turretLoadout, missileLoadout, elementPassiveCMs,
            elementActiveCMs, elementSensors, elementShieldGens, combatStances);

        UnitCreatorConfiguration config = new UnitCreatorConfiguration(unitName, owner, deployDate, cmdDesignName, elementDesignNames);
        //D.Log(ShowDebugLog, "{0} has generated/placed a random {1} for {2}.", DebugName, typeof(FleetCreator).Name, owner);
        return UnitFactory.Instance.MakeFleetCreatorInstance(location, config);
    }
    /// <summary>
    /// Assigns a configuration to the provided existing DebugFleetCreator, using the DeployDate provided.
    /// <remarks>The DebugCreator's EditorSettings specifying the DeployDate will be ignored.</remarks>
    /// </summary>
    /// <param name="creator">The creator.</param>
    /// <param name="owner">The owner.</param>
    /// <param name="location">The location.</param>
    /// <param name="deployDate">The deploy date.</param>
    public void AssignConfigurationToExistingCreator(DebugFleetCreator creator, Player owner, Vector3 location, GameDate deployDate) {
        var editorSettings = creator.EditorSettings as FleetCreatorEditorSettings;

        ValidateOwner(owner, editorSettings);

        string unitName = editorSettings.UnitName;
        string cmdDesignName = MakeAndRecordFleetCmdDesign(owner, editorSettings.UnitName, editorSettings.CMsPerCommand, editorSettings.Formation.Convert());
        var hullStats = CreateShipHullStats(editorSettings);
        IEnumerable<ShipCombatStance> stances = SelectCombatStances(editorSettings.StanceExclusions);
        IList<string> elementDesignNames = MakeAndRecordShipDesigns(owner, hullStats, editorSettings.LosTurretsPerElement,
            editorSettings.MissileLaunchersPerElement, editorSettings.PassiveCMsPerElement, editorSettings.ActiveCMsPerElement,
            editorSettings.SensorsPerElement, editorSettings.ShieldGeneratorsPerElement, stances);
        UnitCreatorConfiguration config = new UnitCreatorConfiguration(unitName, owner, deployDate, cmdDesignName, elementDesignNames);
        creator.Configuration = config;
        creator.transform.position = location;
        //D.Log(ShowDebugLog, "{0} has placed a {1} for {2}.", DebugName, typeof(DebugFleetCreator).Name, owner);
    }
    /// <summary>
    /// Assigns a configuration to the provided existing DebugSettlementCreator, using the DeployDate provided.
    /// <remarks>The DebugCreator's EditorSettings specifying the DeployDate will be ignored.</remarks>
    /// </summary>
    /// <param name="creator">The creator.</param>
    /// <param name="owner">The owner.</param>
    /// <param name="system">The system to assign the settlement creator to.</param>
    /// <param name="deployDate">The deploy date.</param>
    public void AssignConfigurationToExistingCreator(DebugSettlementCreator creator, Player owner, SystemItem system, GameDate deployDate) {
        var editorSettings = creator.EditorSettings as BaseCreatorEditorSettings;

        ValidateOwner(owner, editorSettings);

        string unitName = editorSettings.UnitName;
        string cmdDesignName = MakeAndRecordSettlementCmdDesign(owner, editorSettings.UnitName, editorSettings.CMsPerCommand, editorSettings.Formation.Convert());
        var hullStats = CreateFacilityHullStats(editorSettings, isSettlement: true);
        IList<string> elementDesignNames = MakeAndRecordFacilityDesigns(owner, hullStats, editorSettings.LosTurretsPerElement,
            editorSettings.MissileLaunchersPerElement, editorSettings.PassiveCMsPerElement, editorSettings.ActiveCMsPerElement,
            editorSettings.SensorsPerElement, editorSettings.ShieldGeneratorsPerElement);
        UnitCreatorConfiguration config = new UnitCreatorConfiguration(unitName, owner, deployDate, cmdDesignName, elementDesignNames);
        creator.Configuration = config;
        SystemFactory.Instance.InstallCelestialItemInOrbit(creator.gameObject, system.SettlementOrbitData);
        D.Log(ShowDebugLog, "{0} has installed a {1} for {2} in System {3}.", DebugName, typeof(DebugSettlementCreator).Name, owner, system.DebugName);
    }
Ejemplo n.º 10
0
    IEnumerator ExecuteMoveOrder_EnterState() {
        LogEvent();

        TryBreakOrbit();

        var currentShipMoveOrder = CurrentOrder as ShipMoveOrder;
        _apMoveSpeed = currentShipMoveOrder.Speed;

        //D.Log(ShowDebugLog, "{0} calling {1}.{2}. Target: {3}, Speed: {4}, Fleetwide: {5}.", DebugName, typeof(ShipState).Name,
        //ShipState.Moving.GetValueName(), _fsmTgt.DebugName, _apMoveSpeed.GetValueName(), currentShipMoveOrder.IsFleetwide);

        Call(ShipState.Moving);
        yield return null;  // required so Return()s here

        if (_orderFailureCause != UnitItemOrderFailureCause.None) {
            switch (_orderFailureCause) {
                case UnitItemOrderFailureCause.TgtUncatchable:
                case UnitItemOrderFailureCause.TgtDeath:
                    IssueAssumeStationOrderFromCaptain();
                    break;
                case UnitItemOrderFailureCause.UnitItemNeedsRepair:
                    InitiateRepair(retainSuperiorsOrderOnRepairCompletion: false);
                    break;
                case UnitItemOrderFailureCause.UnitItemDeath:
                    // No Cmd notification reqd in this state. Dead state will follow
                    break;
                case UnitItemOrderFailureCause.TgtRelationship:
                case UnitItemOrderFailureCause.TgtUnreachable:
                default:
                    throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(_orderFailureCause));
            }
            yield return null;
        }

        // If there was a failure generated by Moving, resulting new Orders or Dead state should keep this point from being reached
        D.AssertDefault((int)_orderFailureCause, _orderFailureCause.GetValueName());

        IShipOrbitable highOrbitTgt;
        if (__TryValidateRightToAssumeHighOrbit(_fsmTgt, out highOrbitTgt)) {
            GameDate errorDate = new GameDate(new GameTimeDuration(3F));    // HACK
            GameDate currentDate;
            while (!AttemptHighOrbitAround(highOrbitTgt)) {
                // wait here until high orbit is assumed
                if ((currentDate = _gameTime.CurrentDate) > errorDate) {
                    D.Warn("{0}: CurrentDate {1} > ErrorDate {2} while assuming high orbit.", DebugName, currentDate, errorDate);
                }
                yield return null;
            }
        }

        D.Log(ShowDebugLog, "{0}.ExecuteMoveOrder_EnterState is about to set State to {1}.", DebugName, ShipState.Idling.GetValueName());
        CurrentState = ShipState.Idling;
    }
Ejemplo n.º 11
0
 private IEnumerator OperateCollisionAvoidancePropulsionIn(Vector3 worldSpaceDirectionToAvoidCollision, GameDate errorDate) {
     worldSpaceDirectionToAvoidCollision.ValidateNormalized();
     GameDate currentDate;
     while (true) {
         ApplyCollisionAvoidancePropulsionIn(worldSpaceDirectionToAvoidCollision);
         currentDate = _gameTime.CurrentDate;
         if (currentDate > errorDate) {
             D.Warn("{0}: CurrentDate {1} > ErrorDate {2} while avoiding collision.", DebugName, currentDate, errorDate);
         }
         yield return Yielders.WaitForFixedUpdate;
     }
 }
Ejemplo n.º 12
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        /// <remarks>Tree growth algorithm reverse engineered from <see cref="FruitTree.dayUpdate"/>.</remarks>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            FruitTree tree = this.Target;

            // get basic info
            bool isMature            = tree.daysUntilMature <= 0;
            bool isDead              = tree.stump;
            bool isStruckByLightning = tree.struckByLightningCountdown > 0;

            // show next fruit
            if (isMature && !isDead)
            {
                string label = this.Translate(L10n.FruitTree.NextFruit);
                if (isStruckByLightning)
                {
                    yield return(new GenericField(label, this.Translate(L10n.FruitTree.NextFruitStruckByLightning, new { count = tree.struckByLightningCountdown })));
                }
                else if (Game1.currentSeason != tree.fruitSeason && !tree.greenHouseTree)
                {
                    yield return(new GenericField(label, this.Translate(L10n.FruitTree.NextFruitOutOfSeason)));
                }
                else if (tree.fruitsOnTree == FruitTree.maxFruitsOnTrees)
                {
                    yield return(new GenericField(label, this.Translate(L10n.FruitTree.NextFruitMaxFruit)));
                }
                else
                {
                    yield return(new GenericField(label, this.Translate(L10n.Generic.Tomorrow)));
                }
            }

            // show growth data
            if (!isMature)
            {
                GameDate dayOfMaturity      = GameHelper.GetDate(metadata.Constants.DaysInSeason).GetDayOffset(tree.daysUntilMature);
                string   grownOnDateText    = this.Translate(L10n.FruitTree.GrowthSummary, new { date = this.Stringify(dayOfMaturity) });
                string   daysUntilGrownText = this.Text.GetPlural(tree.daysUntilMature, L10n.Generic.Tomorrow, L10n.Generic.InXDays).Tokens(new { count = tree.daysUntilMature });
                string   growthText         = $"{grownOnDateText} ({daysUntilGrownText})";

                yield return(new GenericField(this.Translate(L10n.FruitTree.NextFruit), this.Translate(L10n.FruitTree.NextFruitTooYoung)));

                yield return(new GenericField(this.Translate(L10n.FruitTree.Growth), growthText));

                if (this.HasAdjacentObjects(this.Tile))
                {
                    yield return(new GenericField(this.Translate(L10n.FruitTree.Complaints), this.Translate(L10n.FruitTree.ComplaintsAdjacentObjects)));
                }
            }
            else
            {
                // get quality schedule
                ItemQuality currentQuality = this.GetCurrentQuality(tree, metadata.Constants.FruitTreeQualityGrowthTime);
                if (currentQuality == ItemQuality.Iridium)
                {
                    yield return(new GenericField(this.Translate(L10n.FruitTree.Quality), this.Translate(L10n.FruitTree.QualityNow, new { quality = this.Translate(L10n.For(currentQuality)) })));
                }
                else
                {
                    string[] summary = this
                                       .GetQualitySchedule(tree, currentQuality, metadata.Constants.FruitTreeQualityGrowthTime)
                                       .Select(entry =>
                    {
                        // read schedule
                        ItemQuality quality = entry.Key;
                        int daysLeft        = entry.Value;
                        GameDate date       = GameHelper.GetDate(metadata.Constants.DaysInSeason).GetDayOffset(daysLeft);
                        int yearOffset      = date.Year - Game1.year;

                        // generate summary line
                        string qualityName = this.Translate(L10n.For(quality));

                        if (daysLeft <= 0)
                        {
                            return("-" + this.Translate(L10n.FruitTree.QualityNow, new { quality = qualityName }));
                        }

                        string line;
                        if (yearOffset == 0)
                        {
                            line = $"-{this.Translate(L10n.FruitTree.QualityOnDate, new { quality = qualityName, date = this.Stringify(date) })}";
                        }
                        else if (yearOffset == 1)
                        {
                            line = $"-{this.Translate(L10n.FruitTree.QualityOnDateNextYear, new { quality = qualityName, date = this.Stringify(date) })}";
                        }
                        else
                        {
                            line = $"-{this.Translate(L10n.FruitTree.QualityOnDate, new { quality = qualityName, date = this.Text.Stringify(date, withYear: true), year = date.Year })}";
                        }

                        line += $" ({this.Text.GetPlural(daysLeft, L10n.Generic.Tomorrow, L10n.Generic.InXDays).Tokens(new { count = daysLeft })})";

                        return(line);
                    })
                                       .ToArray();

                    yield return(new GenericField(this.Translate(L10n.FruitTree.Quality), string.Join(Environment.NewLine, summary)));
                }
            }

            // show season
            yield return(new GenericField(this.Translate(L10n.FruitTree.Season), this.Translate(L10n.FruitTree.SeasonSummary, new { season = this.Text.GetSeasonName(tree.fruitSeason) })));
        }
Ejemplo n.º 13
0
        ///// <summary>
        ///// Updates the period to a value reflective of the supplied date. Useful
        ///// when the period was created using GameDates. Does nothing except issuing
        ///// a warning if the period was created using days and years.
        ///// </summary>
        ///// <param name="currentDate">The current date.</param>
        //public void UpdatePeriod(GameDate currentDate) {
        //    if (_startDate != null) {
        //        SetPeriodValues(_startDate, currentDate);
        //    }
        //}

        private void SetPeriodValues(GameDate startDate, GameDate endDate) {
            _startDate = startDate;
            _endDate = endDate;
            int years = endDate.Year - startDate.Year;
            int days = endDate.DayOfYear - startDate.DayOfYear;
            if (days < 0) {
                years--;
                days = GameDate.DaysPerYear + days;
            }
            int hours = endDate.HourOfDay - startDate.HourOfDay;
            if (hours < 0) {
                days--;
                hours = GameDate.HoursPerDay + hours;
                if (days < 0) {
                    years--;
                    days = GameDate.DaysPerYear + days;
                }
            }
            Years = years;
            Days = days;
            Hours = hours;
            //PeriodInDays = years * GameDate.DaysPerYear + days;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaitForHours"/> class.
 /// </summary>
 /// <param name="duration">The duration.</param>
 public WaitForHours(GameTimeDuration duration) {
     _gameTime = GameTime.Instance;
     _targetDate = new GameDate(duration);
     _duration = duration;
 }
Ejemplo n.º 15
0
    /// <summary>
    /// Generates a random settlement creator, places it in orbit around <c>system</c> and deploys it on the provided date.
    /// </summary>
    /// <param name="owner">The owner.</param>
    /// <param name="system">The system.</param>
    /// <param name="deployDate">The deploy date.</param>
    /// <returns></returns>
    public SettlementCreator GenerateRandomAutoSettlementCreator(Player owner, SystemItem system, GameDate deployDate) {
        string unitName = GetUniqueUnitName("AutoSettlement");
        int cmsPerCmd = RandomExtended.Range(0, 3);
        Formation formation = Enums<Formation>.GetRandomExcept(Formation.Wedge, default(Formation));
        string cmdDesignName = MakeAndRecordSettlementCmdDesign(owner, unitName, cmsPerCmd, formation);

        int elementQty = RandomExtended.Range(1, TempGameValues.MaxFacilitiesPerBase);
        var hullStats = CreateFacilityHullStats(elementQty, isSettlement: true);
        var turretLoadout = DebugLosWeaponLoadout.Random;
        var missileLoadout = DebugWeaponLoadout.Random;
        int elementPassiveCMs = RandomExtended.Range(0, 3);
        int elementActiveCMs = RandomExtended.Range(0, 3);
        int elementSensors = RandomExtended.Range(1, 5);
        int elementShieldGens = RandomExtended.Range(0, 3);
        var elementDesignNames = MakeAndRecordFacilityDesigns(owner, hullStats, turretLoadout, missileLoadout, elementPassiveCMs, elementActiveCMs, elementSensors, elementShieldGens);

        UnitCreatorConfiguration config = new UnitCreatorConfiguration(unitName, owner, deployDate, cmdDesignName, elementDesignNames);
        D.Log(ShowDebugLog, "{0} has placed a random {1} for {2} in orbit in System {3}.", DebugName, typeof(SettlementCreator).Name, owner, system.DebugName);
        return UnitFactory.Instance.MakeSettlementCreatorInstance(config, system);
    }
Ejemplo n.º 16
0
 private void RefreshValues() {
     _startDate = _gameTime.CurrentDate;
     var targetDate = new GameDate(_startDate, _duration);
     //D.Log("{0} is refreshing target date to {1}.", DebugName, targetDate);
     _targetDate = targetDate;
 }
Ejemplo n.º 17
0
 public WaitForDate(GameDate date) {
     _gameTime = GameTime.Instance;
     _targetDate = date;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Copy constructor. Initializes a new instance of the <see cref="Intel"/> class,
 /// a copy of <c>intelToCopy</c>.
 /// </summary>
 /// <param name="intelToCopy">The intel to copy.</param>
 public Intel(Intel intelToCopy)
     : base(intelToCopy) {
     DatedCoverage = intelToCopy.DatedCoverage;
     DateStamp = intelToCopy.DateStamp;
 }
Ejemplo n.º 19
0
 /// <summary>
 ///     コピーコンストラクタ
 /// </summary>
 /// <param name="original">複製元の任務</param>
 public Mission(Mission original)
 {
     Type = original.Type;
     Target = original.Target;
     MissionScope = original.MissionScope;
     Percentage = original.Percentage;
     Night = original.Night;
     Day = original.Day;
     TargetZone = original.TargetZone;
     AttackConvoy = original.AttackConvoy;
     OrgLimit = original.OrgLimit;
     if (original.StartDate != null)
     {
         StartDate = new GameDate(original.StartDate);
     }
     if (original.EndDate != null)
     {
         EndDate = new GameDate(original.EndDate);
     }
     Task = original.Task;
     Location = original.Location;
 }
Ejemplo n.º 20
0
 private void HandleAnyDurationChange() {
     if (_durationRef == null) {
         return;
     }
     if (_durationRef.Value != _duration) {
         // duration has changed
         //D.Log("{0}.ReferenceValue is changing from {1} to {2}.", DebugName, _duration, _durationRef.Value);
         _duration = _durationRef.Value;
         _targetDate = new GameDate(_startDate, _duration);
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Changes the heading.
 /// OPTIMIZE use Quaternions like ShipNav?
 /// </summary>
 /// <param name="requestedHeading">The requested heading.</param>
 /// <param name="allowedTime">The allowed time in seconds before an error is thrown.
 /// <returns></returns>
 private IEnumerator ChangeHeading(Vector3 requestedHeading, GameDate errorDate) {
     //Vector3 startingHeading = CurrentHeading;
     while (!CurrentHeading.IsSameDirection(requestedHeading, SteeringInaccuracy)) {
         float maxTurnRateInRadiansPerSecond = Mathf.Deg2Rad * TurnRate * _gameTime.GameSpeedAdjustedHoursPerSecond;
         float allowedTurn = maxTurnRateInRadiansPerSecond * _gameTime.DeltaTime;
         Vector3 newHeading = Vector3.RotateTowards(CurrentHeading, requestedHeading, allowedTurn, maxMagnitudeDelta: 1F);
         // maxMagnitudeDelta > 0F appears to be important. Otherwise RotateTowards can stop rotating when it gets very close
         transform.rotation = Quaternion.LookRotation(newHeading); // UNCLEAR turn kinematic on and off while rotating?
         //D.Log("{0} actual heading after turn step: {1}.", Name, Heading);
         GameDate currentDate;
         D.Warn((currentDate = _gameTime.CurrentDate) > errorDate, "{0}: CurrentDate {1} > ErrorDate {2} while changing heading.", Name, currentDate, errorDate);
         yield return null;
     }
     //D.Log("{0} has completed heading change of {1:0.#} degrees.", Name, Vector3.Angle(startingHeading, CurrentHeading));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaitForHours"/> class.
 /// </summary>
 /// <param name="durationRef">The duration reference.</param>
 public WaitForHours(Reference<GameTimeDuration> durationRef) : this(durationRef.Value) {
     _durationRef = durationRef;
     _startDate = _gameTime.CurrentDate;
 }
Ejemplo n.º 23
0
 public void PrepareToBeginNewGame() {
     D.Log("GameTime.PrepareToBeginNewGame() called.");
     EnableClock(false);
     _cumTimeInPriorSessions = Constants.ZeroF;
     _timeGameBeganInCurrentSession = Constants.ZeroF;
     _cumTimePaused = Constants.ZeroF;
     _timeCurrentPauseBegan = Constants.ZeroF;
     _gameRealTimeAtLastSync = Constants.ZeroF;
     _currentDateTime = Constants.ZeroF;
     _savedCurrentDateTime = Constants.ZeroF;
     // don't wait for the Gui to set GameSpeed. Use the backing field as the Property calls OnGameSpeedChanged()
     _gameSpeed = _playerPrefsMgr.GameSpeedOnLoad;
     _gameSpeedMultiplier = _gameSpeed.SpeedMultiplier();
     _date = new GameDate(GameDate.PresetDateSelector.Start);
 }
Ejemplo n.º 24
0
    IEnumerator AssumingCloseOrbit_EnterState() {
        LogEvent();

        IShipCloseOrbitable closeOrbitTgt = _fsmTgt as IShipCloseOrbitable;
        // use autopilot to move into close orbit whether inside or outside slot
        IShipNavigable closeOrbitApTgt = closeOrbitTgt.CloseOrbitSimulator as IShipNavigable;

        Vector3 apTgtOffset = Vector3.zero;
        float apTgtStandoffDistance = CollisionDetectionZoneRadius;
        AutoPilotDestinationProxy closeOrbitApTgtProxy = closeOrbitApTgt.GetApMoveTgtProxy(apTgtOffset, apTgtStandoffDistance, Position);
        _helm.EngagePilotToMoveTo(closeOrbitApTgtProxy, Speed.Slow, isFleetwideMove: false);
        yield return null;

        // Wait here until we arrive. When we arrive, AssumingCloseOrbit_UponApTargetReached() will disengage APilot
        while (_helm.IsPilotEngaged) {
            yield return null;
        }

        // Assume Orbit
        GameDate errorDate = new GameDate(new GameTimeDuration(3F));    // HACK
        GameDate currentDate;
        while (!AttemptCloseOrbitAround(closeOrbitTgt)) {
            // wait here until close orbit is assumed
            if ((currentDate = _gameTime.CurrentDate) > errorDate) {
                D.Warn("{0}: CurrentDate {1} > ErrorDate {2} while assuming close orbit.", DebugName, currentDate, errorDate);
            }
            yield return null;
        }
        Return();
    }
Ejemplo n.º 25
0
        ///// <summary>
        ///// Initializes a new instance of the <see cref="GameTimePeriod"/> class of the
        ///// duration provided. Creates an artificial start date said duration before the current
        ///// date.
        ///// </summary>
        ///// <param name="days">The days.</param>
        ///// <param name="years">The years.</param>
        //public GameTimePeriod(int days, int years) : this(Constants.Zero, days, years) { }

        ///// <summary>
        ///// Initializes a new instance of the <see cref="GameTimePeriod" /> class of the
        ///// duration provided.
        ///// </summary>
        ///// <param name="hours">The hours.</param>
        ///// <param name="days">The days.</param>
        ///// <param name="years">The years.</param>
        //public GameTimePeriod(int hours, int days, int years) {
        //    Arguments.ValidateForRange(hours, Constants.Zero, GameDate.HoursPerDay - 1);
        //    Arguments.ValidateForRange(days, Constants.Zero, GameDate.DaysPerYear - 1);
        //    Arguments.ValidateNotNegative(years);
        //    Hours = hours;
        //    Days = days;
        //    Years = years;
        //    PeriodInDays = years * GameDate.DaysPerYear + days;
        //}

        /// <summary>
        /// Initializes a new instance of the <see cref="GameTimePeriod"/> class.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        public GameTimePeriod(GameDate startDate, GameDate endDate) {
            GameUtility.ValidateForRange(startDate, GameDate.GameStartDate, GameDate.GameEndDate);
            GameUtility.ValidateForRange(endDate, GameDate.GameStartDate, GameDate.GameEndDate);
            D.Assert(startDate != endDate);
            //_startDate = startDate;
            SetPeriodValues(startDate, endDate);
        }
Ejemplo n.º 26
0
 private void __ReportTurnTimeWarning(GameDate errorDate, GameDate currentDate, float desiredTurn, float resultingTurn, IList<float> allowedTurns, IList<float> actualTurns, ref bool isInformedOfDateError) {
     if (!isInformedOfDateError) {
         D.Warn("{0}.ChangeHeading of {1:0.##} degrees. CurrentDate {2} > ErrorDate {3}. Turn accomplished: {4:0.##} degrees.",
             DebugName, desiredTurn, currentDate, errorDate, resultingTurn);
         isInformedOfDateError = true;
     }
     if (ShowDebugLog) {
         if (__allowedAndActualTurnSteps == null) {
             __allowedAndActualTurnSteps = new List<string>();
         }
         __allowedAndActualTurnSteps.Clear();
         for (int i = 0; i < allowedTurns.Count; i++) {
             string line = __TurnTimeLineFormat.Inject(allowedTurns[i], actualTurns[i]);
             __allowedAndActualTurnSteps.Add(line);
         }
         D.Log("Allowed vs Actual TurnSteps:\n {0}", __allowedAndActualTurnSteps.Concatenate());
     }
 }
Ejemplo n.º 27
0
            private void EngageCollisionAvoidancePropulsionFor(IObstacle obstacle) {
                D.Assert(!_caPropulsionJobs.ContainsKey(obstacle));
                Vector3 worldSpaceDirectionToAvoidCollision = (_shipData.Position - obstacle.Position).normalized;

                GameDate errorDate = new GameDate(new GameTimeDuration(5F));    // HACK
                string jobName = "{0}.CollisionAvoidanceJob".Inject(DebugName);
                Job caJob = _jobMgr.StartGameplayJob(OperateCollisionAvoidancePropulsionIn(worldSpaceDirectionToAvoidCollision, errorDate), jobName, isPausable: true, jobCompleted: (jobWasKilled) => {
                    D.Assert(jobWasKilled); // CA Jobs never complete naturally
                });
                _caPropulsionJobs.Add(obstacle, caJob);
            }
Ejemplo n.º 28
0
        public Test(VirtualResolution virtualResolution, DrawMap drawMap, Movement movement, Camera camera, IRenderer renderer, IAssetLoader assetLoader, SpriteBatch spriteBatch, GameDate gameDate)
        {
            _camera      = camera;
            _spriteBatch = spriteBatch;
            RegisterSystem(drawMap.UpdateWindTrailTime);
            RegisterSystem(drawMap.DrawMapBuffers);
            RegisterSystem(drawMap.SetSubRenderer);
            RegisterSystem(drawMap.DrawMaskBuffer);
            RegisterSystem(drawMap.DrawMaskEntities);
            RegisterSystem(drawMap.DrawFringeBuffer);
            RegisterSystem(drawMap.DrawFringeEntities);
            RegisterSystem(drawMap.FinaliseRender);

            //RegisterSystem(drawMap.DebugDrawCollidableEntities, 999);

            //RegisterSystem(camera.DebugDraw, 999);
            //RegisterSystem(DebugDrawHtml, 1000);

            RegisterSystem(movement.ProcessMovement, 0);

            test = new WebView(renderer, assetLoader, spriteBatch,
                               virtualResolution.MaxWidth, virtualResolution.MaxHeight,
                               "file://content/ui/html/test.html");

            gameDate.DisableTimeFlow();
        }