Exemple #1
0
        public override void UpdateAfterSimulation100()
        {
            var current = sink.SuppliedRatioByType(Gasses.Flesh);

            bloodStored += sink.RequiredInputByType(Gasses.Flesh) * current * SecsPerUpdate;
            block.RefreshCustomInfo();
            sink.Update();
            RespawnAllowed = CanSpawnPlayer();
        }
 void AppendCustomInfo(IMyTerminalBlock block, StringBuilder info)
 {
     if (!m_initialized)
     {
         return;
     }
     info.Clear();
     info.AppendLine($"Cooling mode: {(!CubeBlock.IsFunctional ? "Disabled (Needs Repair)" : m_functionalBlock.Enabled && m_powerAvailable ? "Active (60°/sec)" : "Passive (6°/sec)")}");
     info.AppendLine($"Input power: {m_resourceSink.RequiredInputByType(m_electricityDefinition).ToString("0.00")}/{m_powerConsumption.ToString("0.00")} MW");
     info.AppendLine($"Temp/Max: {Heat}°/{MaxHeat}°");
     info.AppendLine($"Integrity: {((IMySlimBlock)CubeBlock.SlimBlock).Integrity/MaxHeat * 100}%");
 }
        void Recharge()
        {
            int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds[damageUpgrades]);

            if (chargesInInventory < attractorWeaponInfo.keepAtCharge)
            {
                if (resourceSink.RequiredInputByType(electricityDefinition) != (attractorWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, (attractorWeaponInfo.powerUsage / efficiencyUpgrades));

                    setPowerConsumption = (attractorWeaponInfo.powerUsage / efficiencyUpgrades);
                    powerConsumption    = (attractorWeaponInfo.powerUsage / efficiencyUpgrades);
                }
                else
                {
                    if (!functionalBlock.Enabled)
                    {
                        powerConsumption = 0.0001f;
                    }
                }

                if (resourceSink.CurrentInputByType(electricityDefinition) == (attractorWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    if (!overheated)
                    {
                        m_inventory.AddItems((MyFixedPoint)(attractorWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]);
                    }
                }
            }
            else if (chargesInInventory > attractorWeaponInfo.keepAtCharge)
            {
                m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - attractorWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]);
            }
            else
            {
                if (setPowerConsumption != 0.0001f)
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);

                    setPowerConsumption = 0.0001f;
                    powerConsumption    = 0.0001f;
                }
            }

//            terminalBlock.RefreshCustomInfo ();
        }
        // Context: All
        private void CustomInfo(IMyTerminalBlock block, StringBuilder sb)
        {
            sb.Append("Current Input: ");
            MyValueFormatter.AppendWorkInBestUnit(sink.RequiredInputByType(MyResourceDistributorComponent.ElectricityId), sb);
            sb.AppendLine();

            if (BuildState == State.Building)
            {
                sb.Append("Building ship...").AppendLine();
            }
            else if (BuildState == State.Waiting)
            {
                sb.Append("Ship will be built in ");
                AppendTime(sb, Timer);
                sb.AppendLine();
            }
        }
        public override void UpdateBeforeSimulation()
        {
            int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds [damageUpgrades]);

            IMyCubeBlock cube = Entity as IMyCubeBlock;

            long currentShootTime = ((MyObjectBuilder_InteriorTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime;


            if (currentHeat > 0f)
            {
                if ((ticks - lastShootTimeTicks) > beamWeaponInfo.heatDissipationDelay)
                {
                    currentHeat -= beamWeaponInfo.heatDissipationPerTick;

                    if (currentHeat <= 0f)
                    {
                        currentHeat = 0f;

                        overheated = false;
                    }
                }
            }

            //MyAPIGateway.Utilities.ShowNotification("TIME: " + currentShootTime + " :: " + lastShootTime, 17, MyFontEnum.Red);


            if (currentShootTime != lastShootTime)
            {
                // test

                hitBool = false;

                MyEntitySubpart subpart1 = cubeBlock.GetSubpart("InteriorTurretBase1");
                MyEntitySubpart subpart2 = subpart1.GetSubpart("InteriorTurretBase2");;
                //MyAPIGateway.Utilities.ShowNotification("Dif: " + (currentShootTime - lastShootTime), 17, MyFontEnum.Blue);

                from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 1.25d;
                to   = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 3000d;

                LineD testRay = new LineD(from, to);

                List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >();

                MyGamePruningStructure.GetAllEntitiesInRay(ref testRay, result);


                foreach (var resultItem in result)
                {
                    IMyCubeGrid grid = resultItem.Element as IMyCubeGrid;

                    IMyDestroyableObject destroyableEntity = resultItem.Element as IMyDestroyableObject;

                    if (grid != null)
                    {
                        IMySlimBlock slimblock;

                        double hitd;

                        Vector3D?resultVec = grid.GetLineIntersectionExactAll(ref testRay, out hitd, out slimblock);

                        if (resultVec != null)
                        {
                            hitBool = true;

                            toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                            if (!MyAPIGateway.Session.CreativeMode)
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            else
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            //MyAPIGateway.Utilities.ShowNotification("" + s.BlockDefinition.Id.SubtypeId + " ::: " + resultItem.Distance, 17);
                        }
                    }
                    if (destroyableEntity != null)
                    {
                        IMyEntity ent  = (IMyEntity)destroyableEntity;
                        double    hitd = (from - ent.WorldMatrix.Translation).Length();

                        toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                        hitBool = true;

                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                        else
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                    }
                }


                // test

                lastShootTime      = currentShootTime;
                lastShootTimeTicks = ticks;

                currentHeat += beamWeaponInfo.heatPerTick;

                if (currentHeat > beamWeaponInfo.maxHeat)
                {
                    currentHeat = beamWeaponInfo.maxHeat;

                    overheated = true;
                }
            }

            if (ticks - lastShootTimeTicks < 3)
            {
                var beamcolor     = Color.DodgerBlue;
                var beamcolor_aux = Color.LightSkyBlue;
                var maincolor     = new Vector4(beamcolor.X / 30, beamcolor.Y / 30, beamcolor.Z / 30, 1f);
                var auxcolor      = new Vector4(beamcolor_aux.X / 30, beamcolor_aux.Y / 30, beamcolor_aux.Z / 30, 1f);
                var material      = MyStringId.GetOrCompute("WeaponLaser");
                if (hitBool == false)
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
                else
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
            }

            if (chargesInInventory < beamWeaponInfo.keepAtCharge)
            {
                if (resourceSink.RequiredInputByType(electricityDefinition) != (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, (beamWeaponInfo.powerUsage / efficiencyUpgrades));

                    setPowerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                    powerConsumption    = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                }
                else
                {
                    if (!functionalBlock.Enabled)
                    {
                        powerConsumption = 0.0001f;
                    }
                }

                if (resourceSink.CurrentInputByType(electricityDefinition) == (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    if (!overheated)
                    {
                        m_inventory.AddItems((MyFixedPoint)(beamWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]);
                    }
                }
            }
            else if (chargesInInventory > beamWeaponInfo.keepAtCharge)
            {
                m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - beamWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]);
            }
            else
            {
                if (setPowerConsumption != 0.0001f)
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);

                    setPowerConsumption = 0.0001f;
                    powerConsumption    = 0.0001f;
                }
            }

            terminalBlock.RefreshCustomInfo();

            ticks++;
        }