Esempio n. 1
0
    public void FireWeapon(Action _action)
    {
        new Effect(_muzzleFlash, GunTrans.position, GunTrans.rotation);
        CombatState _target = _action.Combat;

        if (_target != null)
        {
            float _coverAmount;
            if (_target.CoverAmount(GunTrans.position, out _coverAmount))
            {
                float _weaponAccuracy = _inventory.SelectedWeapon.Accuracy - _inventory.SelectedWeapon.AccuracyLoss(Vector3.Distance(transform.position, _target.transform.position));
                float _dc             = Math.Max(5f, _accuracy + _weaponAccuracy - _coverAmount - _target.Dodge);
                if (SRand.Roll(ref _rollI) <= _dc)
                {
                    _target.SetAction(new WeaponAction(ActionType.ShotBy, _inventory.SelectedWeapon, true), true);
                }
                else
                {
                }
            }
            else
            {
            }
        }
    }
Esempio n. 2
0
        public override bool Test()
        {
            base.Test();
            if (Settings.randomEvents)
            {
                if (SRand.Range(0, 100) < Settings.droughtChance)
                {
                    timeRemaining  = Settings.droughtLength;
                    droughtRunning = true;
                    return(true);
                }

                if (timeRemaining > 0)
                {
                    timeRemaining -= 1;
                    if (timeRemaining == 0)
                    {
                        onDroughtEnd();
                        droughtRunning = false;
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        // Slider value for local height noise
        static void Postfix()
        {
            try
            {
                int   NewX         = Main.Grid.current;
                int   NewY         = Main.Grid.current;
                float NoiseIntense = 0.03f;  //original 0.01f


                int num  = NewX * 2 + 1;
                int num2 = NewY * 2 + 1;
                for (int i = 0; i < num; i++)
                {
                    for (int j = 0; j < num2; j++)
                    {
                        TerrainGen.inst.SetVert(i, j, TerrainGen.inst.GetVertY(i, j)
                                                + SRand.Range(-NoiseIntense, NoiseIntense));
                    }
                }
            }
            catch (ChunkException ex)
            {
                // This is going to cause a lot of trouble.
                Debug.LogError(ex.ToString()); // this.HandleException(ex);
            }
        }
Esempio n. 4
0
        private void SetBias()
        {
            if (this.GenType == GeneratorType.Official)
            {
                switch (this.WorldBias)
                {
                case World.MapBias.Island:
                    this.NewBias = GeneratorBias.Island;
                    break;

                case World.MapBias.Land:
                    this.NewBias = GeneratorBias.Land;
                    break;

                case World.MapBias.Random:
                    if (SRand.CoinFlip())
                    {
                        this.NewBias = GeneratorBias.Land;
                    }
                    else
                    {
                        this.NewBias = GeneratorBias.Island;
                    }
                    break;
                }
            }
            else
            {
                SetGenType(UserInterface.GeneratorDropValue);
            }
        }
Esempio n. 5
0
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.M))
            {
                ModSettingsUI._base.SetActive(!ModSettingsUI._base.activeSelf);
            }

            #region Debug

            if (Settings.debug)
            {
                if (Input.GetKeyDown(KeyCode.T))
                {
                    Events.EventManager.TriggerEvent(typeof(Events.EarthquakeEvent));
                }
                if (Input.GetKeyDown(KeyCode.F))
                {
                    KingdomLog.TryLog("eat" + SRand.Range(1f, 100f).ToString(), "eat rate " + Player.inst.SecondsPerEat.ToString(), KingdomLog.LogStatus.Important);
                }
                if (Input.GetKeyDown(KeyCode.R))
                {
                    Events.EventManager.TriggerEvent(typeof(Events.RiotEvent));
                }
                if (Input.GetKeyDown(KeyCode.E))
                {
                    Events.EventManager.TriggerEvent(typeof(Events.DroughtEvent));
                }
            }

            #endregion
        }
Esempio n. 6
0
        static void CalcCrimeForHome(IResidence residence)
        {
            int happiness = residence.GetHappiness();
            int severity  = (crimeHappinessThreshold - happiness);

            if (severity > 0)
            {
                float severityNormalized = (float)severity / (float)crimeHappinessThreshold;
                Mod.helper.Log("found home with potential crime: " + severityNormalized.ToString());
                foreach (Villager resident in residence.GetResidents())
                {
                    bool flaggedCriminal = SRand.Range(0f, 1f) < severityNormalized;

                    if (flaggedCriminal)
                    {
                        Mod.helper.Log("trying create criminal");
                        Criminal bestCriminal = GetBestCriminalForSeverity(severityNormalized);

                        if (bestCriminal)
                        {
                            CreateCriminal(bestCriminal, resident);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public static void Generate()
        {
            Mod.Log("--- Generating ---");

            SRand.SetSeed(World.inst.seed);

            generatorSeededState = SRand.value;
            try
            {
                GenerateBase();
                if (doSmoothing)
                {
                    ApplySmoothing();
                }
                Apply();

                ElevationManager.RefreshTerrain();

                BlockedTilePruner.DoRegionSearch(ElevationManager.GetAll());
            }
            catch (Exception ex)
            {
                DebugExt.HandleException(ex);
            }

            Mod.Log("--- Generation Complete ---");
        }
Esempio n. 8
0
        /// <summary>
        /// Possibly broken, hasn't been tested, don't consider reliable. Creates a linear weight pick emitted from a weight value, for example, a weight of 4 between 1 and 10 would mean you are most likely to get 4, and the chances lowering going in either direction of the number line.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="weight">The weight emitter</param>
        /// <returns></returns>
        public static int WeightedRandom(int min, int max, int weight = 0)
        {
            List <int> options = new List <int>();

            bool valid = max > min;

            if (valid)
            {
                for (int i = min; i < max; i++)
                {
                    for (int k = 0; k < Math.Abs(i - weight); k++)
                    {
                        options.Add(i);
                    }
                }

                DebugExt.Log(options.ToString(), true);

                return(SRand.Range(0, options.Count));
            }
            else
            {
                return(min);
            }
        }
Esempio n. 9
0
 // Use this for initialization
 void Start()
 {
     GameManager.RegisterCharacter(this);
     RegisterWibblyWobbly();
     SetAction(new BasicAction(ActionType.Null));
     _rollI = SRand.GetStartingIndex();
     SetAction(new AnimAction(ActionType.AnimEnded, 0, 0));
 }
Esempio n. 10
0
        private void AddNoise(Mesh m)
        {
            float range = 1f;

            for (int i = 0; i < m.vertices.Length; i++)
            {
                m.vertices[i].y += SRand.Range(-range, range);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Broken do not use
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="weight"></param>
        /// <param name="increment"></param>
        /// <returns></returns>
        public static float WeightedRandom(float min, float max, float weight = 0f, float increment = 1f)
        {
            List <float> options = new List <float>();

            bool valid = max > min;


            if (valid)
            {
                DebugExt.Log("1", true);

                float total  = Util.RoundToFactor(max - min, increment);
                int   _break = (int)total + 1;


                for (float i = min; i < max; i += increment)
                {
                    float num = Util.RoundToFactor(-Math.Abs(weight - i) + total, increment);

                    DebugExt.Log("1-2: " + total, true);
                    DebugExt.Log("1-2: " + i, true);
                    DebugExt.Log("1-2: " + -Math.Abs(weight - i), true);

                    int counter = 0;

                    if (num != 0 && num != increment)
                    {
                        for (float k = 0; k < num; k += increment)
                        {
                            options.Add(Util.RoundToFactor(i, increment));
                            counter++;
                            if (counter > _break)
                            {
                                options.Add(Util.RoundToFactor(i, increment));
                                break;
                            }
                        }
                    }
                    else
                    {
                        options.Add(Util.RoundToFactor(i, increment));
                    }

                    DebugExt.Log("1-3: " + num, true);
                }

                DebugExt.Log(options.ToString(), true);

                return(SRand.Range(0, options.Count));
            }
            else
            {
                DebugExt.Log("Invalid arguments: " + min.ToString() + ", " + max.ToString() + ", " + weight.ToString() + ", " + increment.ToString());
                return(min);
            }
        }
Esempio n. 12
0
        public override void Run()
        {
            base.Run();
            try
            {
                RiotSpawn riot = null;

                if (riots.Count > 0)
                {
                    foreach (RiotSpawn riotSpawn in riots)
                    {
                        if (riotSpawn.rioters.Count < Settings.riotMaxSize)
                        {
                            riot = riotSpawn;
                        }
                    }
                }
                if (riot == null)
                {
                    riot = new RiotSpawn(GetRallyPoint(Util.GetPlayerStartLandmass()));
                }

                ArrayExt <Villager> villagers = World.inst.GetVillagersForLandMass(Util.GetPlayerStartLandmass());

                int numRioters = Settings.riotStartSize;
                int num        = (int)((float)numRioters / Settings.riotMaxSize);
                for (int k = 0; k < num + 1; k++)
                {
                    while (riot.rioters.Count < Settings.riotMaxSize && numRioters > 0)
                    {
                        Villager  vil       = Player.inst.Workers.data[SRand.Range(0, Player.inst.Workers.Count - 1)];
                        RioterJob newRioter = new RioterJob(riot);
                        newRioter.AssignEmployee(vil);
                        newRioter.employer = riot;
                        JobSystem.inst.AddNewJob(newRioter, JobCategory.Homemakers);
                        numRioters -= 1;
                    }
                    if (numRioters > 0)
                    {
                        riots.Add(riot);
                        riot = new RiotSpawn(GetRallyPoint(Util.GetPlayerStartLandmass()));
                    }
                    else
                    {
                        break;
                    }
                }


                KingdomLog.TryLog("riotAssembling", "My Lord, a riot has begun to assemble!", KingdomLog.LogStatus.Important, 20, riot.GetRallyPoint().Center);
            }catch (Exception ex)
            {
                KingdomLog.TryLog("Exception-" + SRand.Range(0, 100), ex.Message + "\n" + ex.StackTrace, KingdomLog.LogStatus.Neutral);
            }
        }
Esempio n. 13
0
 void Awake()
 {
     if (t != null)
     {
         Destroy(t);
     }
     t         = this;
     _obCam    = ob;
     _collMask = collMask;
     SRand.Awake();
 }
Esempio n. 14
0
        public override void Run()
        {
            base.Run();

            if (!tornadoRunning)
            {
                tornadoRunning = true;
                DebugExt.Log("creating tornado");
                int     landmass = SRand.Range(0, World.inst.NumLandMasses);
                Vector3 pos      = World.inst.cellsToLandmass[landmass].RandomElement().Center;

                tornado = SpawnFreeRoamTornado(pos);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// A linear weighted random detremination starting at a min value and ending on a max value, with a given increment to define the step of the randomness, useful when defining chances of pickups or events.
        /// </summary>
        /// <param name="min">The minimum value of the weighted random, must be less than the max</param>
        /// <param name="max">The maximum value of the weighted random, must be greater than the min</param>
        /// <param name="increment">The step of the weighted random</param>
        /// <returns></returns>
        public static float LinearWeightedRandom(float min, float max, float increment = 1f)
        {
            List <float> options = new List <float>();

            for (float i = max; i > min; i -= increment)
            {
                float num = max - i;

                for (float k = 0; k < num; k += increment)
                {
                    options.Add(i);
                }
            }

            return(options[SRand.Range(0, options.Count - 1)]);
        }
Esempio n. 16
0
        public static Criminal GetBestCriminalForSeverity(float severity)
        {
            Criminal best = null;

            foreach (Criminal criminalType in CriminalTypes)
            {
                Mod.helper.Log(criminalType.c_name + ", " + criminalType.c_severity.ToString());
                Debug.LogError("asdf");
                if (criminalType.c_severity < severity)
                {
                    bool flagSelected = SRand.Range(0f, 1f) < (1f + criminalPickBuffer) - criminalType.c_severity;

                    if (flagSelected)
                    {
                        if (best == null)
                        {
                            best = criminalType;
                        }
                        else
                        {
                            if (
                                Settings.criminalAssignmentPriority == Settings.CriminalAssignmentPriority.PrioritizeDangerousCriminals &&
                                criminalType.c_severity > best.c_severity
                                )
                            {
                                best = criminalType;
                            }
                            if (
                                Settings.criminalAssignmentPriority == Settings.CriminalAssignmentPriority.PrioritizeHarmlessCriminals &&
                                criminalType.c_severity < best.c_severity
                                )
                            {
                                best = criminalType;
                            }
                        }
                    }
                }
            }

            return(best);
        }
Esempio n. 17
0
        Cell[] getCraggyLine(Cell a, Cell b, int segments)
        {
            MinMax variance = new MinMax(-2f, 2f);

            Cell[] result = new Cell[segments + 1];
            result[0] = a;
            Vector3 vec1 = a.Center;
            Vector3 vec2 = b.Center;

            for (int i = 1; i < segments; i++)
            {
                Vector3 vec = Vector3.Lerp(vec1, vec2, 1 / (float)segments * i);
                vec.x    += SRand.Range(variance.Min, variance.Max);
                vec.z    += SRand.Range(variance.Min, variance.Max);;
                result[i] = World.inst.GetCellData((int)vec.x, (int)vec.z);
            }


            result[segments] = b;

            return(result);
        }
Esempio n. 18
0
        public static void TryPlaceTerrainFeatures()
        {
            foreach (TerrainFeature terrainFeature in TerrainFeatures)
            {
                for (int landmass = 0; landmass < World.inst.NumLandMasses; landmass++)
                {
                    for (int place = 0; place < featurePlaceTriesPerLandmass; place++)
                    {
                        Cell rand = World.inst.cellsToLandmass[landmass].data[SRand.Range(0, World.inst.cellsToLandmass[landmass].Count)];

                        if (!ElevationManager.ValidTileForElevation(rand))
                        {
                            return;
                        }

                        if (terrainFeature.TestPlacement(rand))
                        {
                            placedFeatures.Add(terrainFeature.Create(rand));
                        }
                    }
                }
            }
        }
Esempio n. 19
0
 void Start()
 {
     _rollI = SRand.GetStartingIndex();
     GameManager.RegisterTargetable(this);
 }
Esempio n. 20
0
 public static void Log(string message, bool repeatable = false, KingdomLog.LogStatus type = KingdomLog.LogStatus.Neutral, object GameObjectOrVector3 = null)
 {
     if (ModUtilsMain.debug)
     {
         KingdomLog.TryLog(ModUtilsMain.ModID + "_debugmsg-" + IDs.Count + (repeatable ? SRand.Range(0, 1).ToString() : ""), message, type, (repeatable ? 1 : 20), GameObjectOrVector3);
         IDs.Add(1);
     }
 }
Esempio n. 21
0
 public void ReverseFire(Action _action)
 {
     SRand.ReverseRoll(ref _rollI);
     _inventory.SelectedWeapon.ReverseFireWeapon();
 }
Esempio n. 22
0
 /// <summary>
 /// Returns a random number between 0 and 1. (Obsolete, I thought this was impossible with SRand.Range(0f,1f) lol)
 /// </summary>
 /// <returns></returns>
 public static float Randi()
 {
     return(SRand.Range(0f, 10f) / 10f);
 }
Esempio n. 23
0
        public override void Run()
        {
            base.Run();

            float magnitude   = Util.LinearWeightedRandom(Settings.earthquakeStrength.Min, Settings.earthquakeStrength.Max) + Settings.earthquakeVariance.Rand();
            float m_weightage = magnitude / 10f;

            float burnLine_terrafromChance = 0.8f;
            float burnLine_terraformLikelinessWeightage = 0.2f;

            float AOE_terraformChance = 0.5f * m_weightage;
            float AOE_terraformLikelinessWeightage = 0.6f;
            float AOE_fireChance     = 0.9f;
            float AOE_rockChance     = 0.05f;
            float AOE_ironChance     = 0.05f;
            float AOE_stoneChance    = 0.1f;
            float AOE_treeKillChance = 0.3f;

            float radius = 1f;

            int peopleKilled       = 0;
            int buildingsDestroyed = 0;

            int landmass = (int)SRand.Range(0, World.inst.NumLandMasses);

            float lineBreak      = 1.5f;
            float lineResolution = 1f;

            Cell rand1 = World.inst.cellsToLandmass[landmass].RandomElement();
            Cell rand2 = World.inst.cellsToLandmass[landmass].RandomElement();

            Cell[] line = getCraggyLine(rand1, rand2, 10);
            Cell   last = null;

            Cam.inst.Shake(new Vector3(magnitude * 2, 0f, magnitude * 2));

            float i = line.Length;

            Vector3 midpoint = line[line.Length / 2].Center;

            KingdomLog.TryLog("earthquakeStruck", "My lord, " + GetAdjectiveForMagnitude(magnitude) + " earthquake of magnitude " + Util.RoundToFactor(magnitude, 0.1f).ToString() + " has struck the land! ", KingdomLog.LogStatus.Warning, 1, midpoint);

            foreach (Cell point in line)
            {
                radius = (line.Length - Math.Abs(i - (line.Length / 2))) * m_weightage;

                if (last != null)
                {
                    Vector3 difference  = -(last.Center - point.Center);
                    Vector3 currentPos  = last.Center;
                    float   currentDiff = Math.Abs(Vector3.Distance(point.Center, last.Center));

                    while (currentDiff > lineBreak)
                    {
                        currentPos += Vector3.ClampMagnitude(difference, lineResolution);
                        Cell currentCell = World.inst.GetCellData(currentPos);

                        #region Burn Line

                        int m_radius = (int)(magnitude * radius);
                        if (m_radius <= 0)
                        {
                            m_radius = 1;
                        }

                        bool terraform = Util.Randi() <= burnLine_terrafromChance;

                        #region Terraform

                        if (terraform)
                        {
                            // weighted random in favor of terraforming tiles into similar type of the original tile
                            bool likeType = Util.Randi() < burnLine_terraformLikelinessWeightage;

                            if (currentCell.Type != ResourceType.Water)
                            {
                                float height = Settings.earthquakeLandElevation.Rand();

                                if (likeType)
                                {
                                    Util.AnnhiliateCell(currentCell, false, true);
                                    Util.SetLandTile(currentCell, 0, height);
                                    Util.SetCellLandmass(currentCell, landmass);
                                }
                                else
                                {
                                    height = Settings.earthquakeWaterElevation.Rand();
                                    Util.AnnhiliateCell(currentCell);
                                    Util.SetWaterTile(currentCell, height);
                                    Util.SetCellLandmass(currentCell, landmass);
                                }
                            }
                            else
                            {
                                float height = Settings.earthquakeWaterElevation.Rand();

                                if (likeType)
                                {
                                    Util.AnnhiliateCell(currentCell, false, true);
                                    Util.SetWaterTile(currentCell, height);
                                    Util.SetCellLandmass(currentCell, landmass);
                                }
                                else
                                {
                                    height = Settings.earthquakeLandElevation.Rand();
                                    Util.AnnhiliateCell(currentCell);
                                    Util.SetLandTile(currentCell, 0, height);
                                    Util.SetCellLandmass(currentCell, landmass);
                                }
                            }
                        }

                        #endregion

                        #endregion

                        #region AOE

                        World.inst.ForEachTileInRadius((int)currentCell.Center.x, (int)currentCell.Center.z, m_radius, delegate(int x, int z, Cell _cell)
                        {
                            float burnLineDist = Vector3.Distance(currentCell.Center, _cell.Center);

                            // bias all chance events to be less likely further from the source line
                            float weightage = 1f - (burnLineDist / m_radius);

                            bool c_terraform = Util.Randi() < weightage * AOE_terraformChance;
                            bool c_fire      = Util.Randi() < weightage * AOE_fireChance;
                            bool c_rock      = Util.Randi() < weightage * AOE_rockChance && _cell.Type != ResourceType.Water;
                            bool c_treeKill  = Util.Randi() < weightage * AOE_treeKillChance;


                            if (c_terraform)
                            {
                                // weighted random in favor of terraforming tiles into similar type of the original tile
                                bool likeType = Util.Randi() < AOE_terraformLikelinessWeightage * 10;

                                if (_cell.Type != ResourceType.Water)
                                {
                                    float height = Settings.earthquakeLandElevation.Rand();

                                    if (likeType)
                                    {
                                        Util.AnnhiliateCell(_cell, false, true);
                                        Util.SetLandTile(_cell, 0, height);
                                        Util.SetCellLandmass(_cell, landmass);
                                    }
                                    else
                                    {
                                        height = Settings.earthquakeWaterElevation.Rand();
                                        Util.AnnhiliateCell(_cell);
                                        Util.SetWaterTile(_cell, height);
                                        Util.SetCellLandmass(_cell, landmass);
                                    }
                                }
                                else
                                {
                                    float height = Settings.earthquakeWaterElevation.Rand();

                                    if (likeType)
                                    {
                                        Util.AnnhiliateCell(_cell, false, true);
                                        Util.SetWaterTile(_cell, height);
                                        Util.SetCellLandmass(_cell, landmass);
                                    }
                                    else
                                    {
                                        height = Settings.earthquakeLandElevation.Rand();
                                        Util.AnnhiliateCell(_cell);
                                        Util.SetLandTile(_cell, 0, height);
                                        Util.SetCellLandmass(_cell, landmass);
                                    }
                                }
                            }

                            if (c_fire)
                            {
                                Assets.Code.FireManager.inst.StartFireAt(_cell);
                            }

                            if (c_rock)
                            {
                                ResourceType type = ResourceType.UnusableStone;
                                if (Util.Randi() < weightage * AOE_stoneChance)
                                {
                                    type = ResourceType.Stone;
                                }
                                if (Util.Randi() < weightage * AOE_ironChance)
                                {
                                    type = ResourceType.IronDeposit;
                                }
                                Util.SetCellType(_cell, type);
                            }

                            if (c_treeKill)
                            {
                                TreeSystem.inst.DeleteTreesAt(_cell);
                            }
                        });

                        #endregion

                        TerrainGen.inst.FinalizeChanges();



                        currentDiff = Math.Abs(Vector3.Distance(point.Center, currentPos));
                    }
                }
                last = point;
                i   -= 1f;
            }
        }