Example #1
0
        private static ReadOnlyMemory <byte> DR(ReadOnlyMemory <byte> key, ReadOnlyMemory <byte> constant, int keySize, int blockSize)
        {
            var keyBytes = new Memory <byte>(new byte[keySize]);

            ReadOnlyMemory <byte> Ki;

            if (constant.Length != blockSize)
            {
                Ki = NFold(constant.Span, blockSize);
            }
            else
            {
                Ki = constant;
            }

            var n = 0;

            do
            {
                Ki = AESCTS.Encrypt(Ki, key, AllZerosInitVector);

                if (n + blockSize >= keySize)
                {
                    Ki.CopyTo(keyBytes.Slice(n, keySize - n));
                    break;
                }

                Ki.CopyTo(keyBytes.Slice(n, blockSize));

                n += blockSize;
            }while (n < keySize);

            return(keyBytes);
        }
        /// <summary>
        /// Is called every frame.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="hud"></param>
        /// <param name="otherSpaceShips"></param>
        public virtual void Update(GameTime gameTime)
        {
            Debug.Assert(Status != Conditions.Undefined);

            if (DeleteFlag)
            {
                return;
            }

            if (IsAirborne)
            {
                CalcTrack();
                Ki.Owner = this;
                if (UpdateKi)
                {
                    Ki.Update(gameTime);
                }
                CalcMovement(gameTime);
                if (Weapon != null)
                {
                    Weapon.Update(gameTime);
                }
            }

            CalcCarrierBehaviour(gameTime);
        }
Example #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (IntegratorEnable != false)
            {
                hash ^= IntegratorEnable.GetHashCode();
            }
            if (IntegratorSaturationLevel != 0D)
            {
                hash ^= IntegratorSaturationLevel.GetHashCode();
            }
            if (Kp != 0D)
            {
                hash ^= Kp.GetHashCode();
            }
            if (Ki != 0D)
            {
                hash ^= Ki.GetHashCode();
            }
            if (Kd != 0D)
            {
                hash ^= Kd.GetHashCode();
            }
            if (Kaw != 0D)
            {
                hash ^= Kaw.GetHashCode();
            }
            if (OutputSaturationLevel != 0D)
            {
                hash ^= OutputSaturationLevel.GetHashCode();
            }
            return(hash);
        }
Example #4
0
 private void sliderKi_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     Ki = sliderKi.Value;
     if (boxKi != null)
     {
         boxKi.Text = Ki.ToString(FORMAT);
     }
 }
 /// <summary>
 /// Is called for some ships per frame (round-robin), but at least once per second for every ship. Use for expensive calculations.
 /// </summary>
 /// <param name="elapsedTime"></param>
 /// <param name="hud"></param>
 /// <param name="otherSpaceShips"></param>
 public virtual void LongUpdate(TimeSpan elapsedTime)
 {
     Ki.LongUpdate(elapsedTime);
     if (Weapon != null)
     {
         Weapon.LongUpdate(elapsedTime);
     }
 }
Example #6
0
        private int VerifySlope(Ki chess, int x, int y, bool?toNegative = null)
        {
            if (x < 0 || y < 0 || x >= ROW_COUNT || y >= COLUMN_COUNT)
            {
                return(0);
            }

            if (this[x, y] == chess)
            {
                if (toNegative == null)
                {
                    return(VerifySlope(chess, x - 1, y - 1, true) + 1 + VerifySlope(chess, x + 1, y + 1, false));
                }
                if (toNegative == true)
                {
                    return(VerifySlope(chess, x - 1, y - 1, true) + 1);
                }
                return(1 + VerifySlope(chess, x + 1, y + 1, false));
            }
            return(0);
        }
Example #7
0
 void UpdateConfig()
 {
     try
     {
         if (this.TxtBoxKp.InvokeRequired)
         {
             this.Invoke(new UpdateConfigCallback(UpdateConfig));
         }
         else
         {
             TxtBoxKp.Text        = Kp.ToString();
             TxtBoxKi.Text        = Ki.ToString();
             TxtBoxKd.Text        = Kd.ToString();
             TxtBoxErrorMax.Text  = ErrorMax.ToString();
             TxtBoxPWMPeriod.Text = PWMPeriod.ToString();
             TxtBoxIntMax.Text    = IntMax.ToString();
         }
     }
     catch (Exception ex)
     {
         return;
     }
 }
Example #8
0
        private int VerifyHorizontal(Ki chess, int x, int y, bool?toNegative = null)
        {
            if (x < 0 || y < 0 || x >= ROW_COUNT || y >= COLUMN_COUNT)
            {
                return(0);
            }

            if (this[x, y] == chess)
            {
                if (toNegative == null)
                {
                    return(VerifyHorizontal(chess, x - 1, y, true) + 1 + VerifyHorizontal(chess, x + 1, y, false));
                }
                else if (toNegative == true)
                {
                    return(VerifyHorizontal(chess, x - 1, y, true) + 1);
                }
                else
                {
                    return(1 + VerifyHorizontal(chess, x + 1, y, false));
                }
            }
            return(0);
        }
Example #9
0
 public void Save(ConfigNode node)
 {
     node.SetValue("Kp", Kp.ToString());
     node.SetValue("Ki", Ki.ToString());
     node.SetValue("Kd", Kd.ToString());
 }
Example #10
0
        // ~FGPID();

        public override bool Run()
        {
            double I_out_delta = 0.0;
            double Dval        = 0;

            input = inputNodes[0].GetDoubleValue();

            if (ProcessVariableDot != null)
            {
                Dval = ProcessVariableDot.GetValue();
            }
            else
            {
                Dval = (input - Input_prev) / dt;
            }

            // Do not continue to integrate the input to the integrator if a wind-up
            // condition is sensed - that is, if the property pointed to by the trigger
            // element is non-zero. Reset the integrator to 0.0 if the Trigger value
            // is negative.

            double test = 0.0;

            if (Trigger != null)
            {
                test = Trigger.GetValue();
            }

            if (Math.Abs(test) < 0.000001)
            {
                switch (IntType)
                {
                case eIntegrateType.eRectEuler:
                    I_out_delta = input;                             // Normal rectangular integrator
                    break;

                case eIntegrateType.eTrapezoidal:
                    I_out_delta = 0.5 * (input + Input_prev);        // Trapezoidal integrator
                    break;

                case eIntegrateType.eAdamsBashforth2:
                    I_out_delta = 1.5 * input - 0.5 * Input_prev;      // 2nd order Adams Bashforth integrator
                    break;

                case eIntegrateType.eAdamsBashforth3:                                       // 3rd order Adams Bashforth integrator
                    I_out_delta = (23.0 * input - 16.0 * Input_prev + 5.0 * Input_prev2) / 12.0;
                    break;

                case eIntegrateType.eNone:
                    // No integrator is defined or used.
                    I_out_delta = 0.0;
                    break;
                }
            }

            if (test < 0.0)
            {
                I_out_total = 0.0;              // Reset integrator to 0.0
            }
            I_out_total += Ki.GetValue() * dt * I_out_delta;

            if (IsStandard)
            {
                output = Kp.GetValue() * (input + I_out_total + Kd.GetValue() * Dval);
            }
            else
            {
                output = Kp.GetValue() * input + I_out_total + Kd.GetValue() * Dval;
            }

            Input_prev2 = test < 0.0 ? 0.0 : Input_prev;
            Input_prev  = input;

            Clip();
            SetOutput();

            return(true);
        }
 private void trackBar1_Scroll(object sender, EventArgs e)
 {
     Ki          = (float)integralSlider.Value / 20.0f;
     iLabel.Text = Ki.ToString();
 }
Example #12
0
        public override void PostDraw(SpriteBatch spriteBatch, Player player)
        {
            try
            {
                if (PlayerCharacter.Permanence < 1)
                {
                    PermanenceCrown = false;
                }
                if (PlayerCharacter.Transcendence < 1)
                {
                    TranscendenceCrown = false;
                }

                spriteBatch.Draw(GFX.GFX.anvil, new Vector2(GuiPosition.X - 150f * Scale, GuiPosition.Y - 100f * Scale), Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Upgrading an item increases its power, but does not always succeed", new Vector2(GuiPosition.X - 176f * Scale, GuiPosition.Y - 148f * Scale), Color.White, Scale);
                if (PermanenceCrown)
                {
                    spriteBatch.DrawStringWithShadow(Main.fontMouseText, "If the upgrade fails, the item will be downgraded.", new Vector2(GuiPosition.X - 176f * Scale, GuiPosition.Y - 124 * Scale), Color.Lime, Scale);
                }
                else
                {
                    spriteBatch.DrawStringWithShadow(Main.fontMouseText, "If the upgrade fails, the item will be destroyed.", new Vector2(GuiPosition.X - 176f * Scale, GuiPosition.Y - 124 * Scale), Color.Red, Scale);
                }

                spriteBatch.Draw(GuardianCrown ? GFX.GFX.ButtonCrownPressed : GFX.GFX.ButtonCrown, BtnExperiencePos, Color.White, Scale);
                spriteBatch.Draw(GFX.GFX.GuardianCrown, BtnExperiencePos + new Vector2(9f, 10f) * Scale, GuardianCrown ? Color.Gray : Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Increases success chance of upgrades by 10%", BtnExperiencePos + new Vector2(64f, 4f) * Scale, Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "at the cost of a much higher price in currency", BtnExperiencePos + new Vector2(64f, 28f) * Scale, Color.White, Scale);
                spriteBatch.Draw(PermanenceCrown ? GFX.GFX.ButtonCrownPressed : GFX.GFX.ButtonCrown, BtnPermanencePos, Color.White, Scale);
                spriteBatch.Draw(Main.itemTexture[ModContent.ItemType <PermanenceCrown>()], BtnPermanencePos + new Vector2(9f, 10f) * Scale, PermanenceCrown ? Color.Gray : Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontItemStack, PlayerCharacter.Permanence.ToString(), BtnPermanencePos + new Vector2(8f, 24f) * Scale, Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "When an upgrade fails, items are downgraded", BtnPermanencePos + new Vector2(64f, 4f) * Scale, Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "instead of being destroyed. " + (PlayerCharacter.Permanence == 1 ? "1 crown left." : PlayerCharacter.Permanence + " crowns left."),
                                                 BtnPermanencePos + new Vector2(64f, 28f) * Scale, Color.White, Scale);
                spriteBatch.Draw(TranscendenceCrown ? GFX.GFX.ButtonCrownPressed : GFX.GFX.ButtonCrown, BtnTranscendencePos, Color.White, Scale);
                spriteBatch.Draw(Main.itemTexture[ModContent.ItemType <BlacksmithCrown>()], BtnTranscendencePos + new Vector2(9f, 10f) * Scale, TranscendenceCrown ? Color.Gray : Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontItemStack, PlayerCharacter.Transcendence.ToString(), BtnTranscendencePos + new Vector2(8f, 24f) * Scale, Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Allows you to upgrade an item to +8", BtnTranscendencePos + new Vector2(64f, 4f) * Scale, Color.White, Scale);
                spriteBatch.DrawStringWithShadow(Main.fontMouseText, PlayerCharacter.Transcendence == 1 ? "1 crown left." : PlayerCharacter.Transcendence + " crowns left.", BtnTranscendencePos + new Vector2(64f, 28f) * Scale, Color.White, Scale);
                spriteBatch.Draw(GFX.GFX.ButtonClose, BtnCancelPos, Color.White, Scale);

                if (!Selected)
                {
                    spriteBatch.DrawStringWithShadow(Main.fontMouseText, "<Right-click a weapon to select it for upgrading>", new Vector2(GuiPosition.X - 176f * Scale, GuiPosition.Y + 128f * Scale), Color.White, Scale);
                }

                else
                {
                    if (Ki.UpgradeLevel >= PlayerCharacter.DefaultMaxUpgradeLevel && !TranscendenceCrown)
                    {
                        Ki       = null;
                        Item     = null;
                        Selected = false;
                    }

                    spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Selected item: " + (Item != null ? Item.HoverName : ""), new Vector2(GuiPosition.X - 192f * Scale, GuiPosition.Y + 128f * Scale), Color.White, Scale);
                    int modifier = GuardianCrown ? 4 : 1;
                    if (player.Wealth() >= UpgradeCost * modifier)
                    {
                        int bonusChance = GuardianCrown ? 10 : 0;

                        spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Upgrade Cost: " + Coins.MoneyToString(UpgradeCost * modifier), new Vector2(GuiPosition.X - 192f * Scale, GuiPosition.Y + 152f * Scale), Color.White, Scale);
                        spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Chance to succeed: " + (UpgradeSuccess + bonusChance) + "%", new Vector2(GuiPosition.X - 192f * Scale, GuiPosition.Y + 176f * Scale),
                                                         bonusChance > 0 ? Color.Lime : Color.White, Scale);
                        spriteBatch.Draw(GFX.GFX.ButtonUpgrade, BtnUpgradePos, Color.White, Scale);
                        if (new Rectangle((int)BtnUpgradePos.X, (int)BtnUpgradePos.Y, (int)(GFX.GFX.BTN_WIDTH * Scale), (int)(GFX.GFX.BTN_HEIGHT * Scale)).Contains(Main.mouseX, Main.mouseY) && Main.mouseLeft && Main.mouseLeftRelease)
                        {
                            Main.PlaySound(SoundID.MenuTick);
                            if (Ki == null)
                            {
                                throw new Exception("Sanity Check, Ki is null.");
                            }
                            if (Ki.UpgradeLevel >= PlayerCharacter.DefaultMaxUpgradeLevel)
                            {
                                PlayerCharacter.Transcendence -= 1;
                            }

                            if (Main.rand.Next(100) < UpgradeSuccess + bonusChance)
                            {
                                Ki.Upgrade(Item);
                            }
                            else
                            {
                                if (PermanenceCrown)
                                {
                                    Ki.Downgrade(Item);
                                }
                                else
                                {
                                    Ki.Destroy(Item);
                                }
                            }

                            if (PermanenceCrown && bonusChance + UpgradeSuccess < 100)
                            {
                                PlayerCharacter.Permanence -= 1;
                            }

                            player.RemoveCoins(UpgradeCost * modifier);
                            if (!AttemptSelectItem(Ki, Item))
                            {
                                CloseGui();
                            }
                        }
                    }

                    else
                    {
                        spriteBatch.DrawStringWithShadow(Main.fontMouseText, "Upgrade Cost: " + Coins.MoneyToString(UpgradeCost * modifier), new Vector2(GuiPosition.X - 192f * Scale, GuiPosition.Y + 152f * Scale), Color.Red, Scale);
                    }
                }

                //if (playerPosition != null)
                if (Vector2.Distance(player.Center, PlayerPosition) > 128)
                {
                    CloseGui();
                }
            }
            catch (Exception e)
            {
                kRPG.LogMessage("AnvilGui PostDraw Error: " + e);
            }
        }