Esempio n. 1
0
        private static void LoadCargo(IMyCubeGrid deliveryShip, CargoType cargo)
        {
            var slimBlocks = new List <IMySlimBlock>();

            deliveryShip.GetBlocks(slimBlocks, b => b.FatBlock is IMyCargoContainer);
//            MyLog.Default.WriteLine("LoadCargo: " + deliveryShip.CustomName);
//            MyLog.Default.Flush();
            foreach (var slim in slimBlocks)
            {
                var cargoContainer = (IMyCargoContainer)slim.FatBlock;
//                MyLog.Default.WriteLine("LoadCargo: " + cargoContainer.CustomName);
//                MyLog.Default.Flush();
                var entity = cargoContainer as MyEntity;
                if (entity.HasInventory)
                {
                    var inventory = entity.GetInventoryBase() as MyInventory;
                    if (inventory == null)
                    {
                        continue;
                    }

                    // for V15: Added check  since SE V1.189 removed cargo container multiplier
                    int  amount    = cargo.AmountPerCargoContainer;
                    var  cargoitem = cargo.GetObjectBuilder();
                    bool bPlaced   = false;
                    do
                    {
                        bPlaced = inventory.AddItems(amount, cargoitem);
                        if (!bPlaced)
                        {
                            //                            MyLog.Default.WriteLine("LoadCargo: Does not fit-" + amount.ToString() + " "+cargo.GetDisplayName());
                            amount /= 2; // reduce size until it fits
                        }
                        if (amount < 3)
                        {
                            bPlaced = true;           // force to true if it gets too small
                        }
                    } while (!bPlaced);
                }
            }
        }
Esempio n. 2
0
        protected override void InitCommon(IModSystemRegistry modSystemRegistry)
        {
            var    stringIdInit = MyStringId.TryGet("Init");
            string sInit        = VRage.MyTexts.Get(stringIdInit).ToString() + " " + CurrentModVersion;

            var    TranslationByID = MyStringId.TryGet("TranslationBy");
            string sTranslationBy  = VRage.MyTexts.Get(TranslationByID).ToString();

            if (!string.IsNullOrWhiteSpace(sTranslationBy))
            {
                sInit += "\n  " + sTranslationBy;
            }

            var    AudioByID = MyStringId.TryGet("AudioBy");
            string sAudioBy  = VRage.MyTexts.Get(AudioByID).ToString();

            if (!string.IsNullOrWhiteSpace(sAudioBy))
            {
                sInit += "\n  " + sAudioBy;
            }
            //            string sInit = "Initialising Escape From Mars build " + CurrentModVersion;

            MyAPIGateway.Utilities.ShowNotification(sInit, 5000, MyFontEnum.DarkBlue);
            ModLog.Info(sInit);
            MyLog.Default.Info("EFM Init" + sInit);

//            var gamelanguage = MySpaceTexts.ToolTipOptionsGame_Language;
            var gamelanguage = MyAPIGateway.Session.Config.Language;

            ModLog.Info("Game Language=" + gamelanguage.ToString());

            /*
             * var idString1=MyStringId.TryGet("String1");
             * var String1=VRage.MyTexts.Get(idString1);
             * ModLog.Info("idString1=" + idString1);
             * ModLog.Info("String1=" + String1);
             */

            if (MyAPIGateway.Session.IsServer)
            {
                MyVisualScriptLogicProvider.SendChatMessage(sInit, "Wicorel", 0, MyFontEnum.DarkBlue);
            }

            gameVersion = MyAPIGateway.Session.Version;
            ModLog.Info("SE Version=" + gameVersion.ToString());

            /*
             * ModLog.Info(" Major=" + gameVersion.Major.ToString());
             * ModLog.Info(" MajorRevision=" + gameVersion.MajorRevision.ToString());
             * ModLog.Info(" Minor=" + gameVersion.Minor.ToString());
             * ModLog.Info(" MinorRevision=" + gameVersion.MinorRevision.ToString());
             * ModLog.Info(" Build=" + gameVersion.Build.ToString());
             */
            /*
             * // TESTING: (they seem to be the same)
             * if (MyAPIGateway.Session.IsServer)
             *  ModLog.Info("MyAPIGateway.Session.IsServer.IsServer");
             * else
             *  ModLog.Info("MyAPIGateway.Session.NOT Server");
             * if (MyAPIGateway.Multiplayer.IsServer)
             *  ModLog.Info("MyAPIGateway.Multiplayer.IsServer");
             * else
             *  ModLog.Info("MyAPIGateway.Multiplayer.NOT Server");
             */
            bool bResearch = Session.SessionSettings.EnableResearch;

            // This works to change the setting.
            Session.SessionSettings.EnableResearch = true;

            Session.SessionSettings.EnableBountyContracts = false; // SE V1.192

            if ((gameVersion.Major == 1 && gameVersion.Minor >= 192) || gameVersion.Major > 1)
            {
                ModLog.Info("Economy items enabled");
                CargoType.AllowEconomyItems();
            }
            if ((gameVersion.Major == 1 && gameVersion.Minor >= 198) || gameVersion.Major > 1)
            {
                ModLog.Info("Warefare1 items enabled");
                CargoType.AllowWarefare1Items();
            }
            if ((gameVersion.Major == 1 && gameVersion.Minor >= 200) || gameVersion.Major > 1)
            {
                ModLog.Info("Warefare2 items enabled");
                CargoType.AllowWarefare2Items();
            }

            if (!bResearch)
            {
//                MyAPIGateway.Utilities.ShowNotification("Save, then Exit. Edit world /Advanced settings and Enable progression", 50000, MyFontEnum.Red);
                ModLog.Info("Research was not turned on");
            }
            TextAPI = new HudAPIv2();
//            if (modBuildWhenGameStarted > 4) V37
            {
                DuckUtils.PutPlayerIntoFaction("CRASH");
            }
            researchControl = new ResearchControl(audioSystem);
            researchControl.InitResearchRestrictions();
            researchHacking = new ResearchHacking(researchControl, TextAPI, networkComms);
            networkComms.Init(audioSystem, researchControl, researchHacking);
            modSystemRegistry.AddCloseableModSystem(networkComms);
            modSystemRegistry.AddUpatableModSystem(audioSystem);

            MyAPIGateway.Utilities.MessageEntered += MessageEntered;
        }
Esempio n. 3
0
        private void GiveOrdersToUnassignedShips()
        {
            bool bFoundBackup = false;

            while (unitialisedNewGrids.Count > 0)
            {
                var grid = unitialisedNewGrids.Dequeue();
                if (!grid.IsControlledByFaction("GCORP"))
                {
                    continue;
                }

                var roleAndUnitType = PrefabGrid.GetRoleAndUnitType(grid);
                if (roleAndUnitType == null)
                {
                    // V26 debug
                    ModLog.Info("Discarding grid because no role found");
                    continue;
                }

                var unitType = roleAndUnitType.Value.UnitType;

                switch (roleAndUnitType.Value.UnitRole)
                {
                case UnitRole.Delivery:
                    var cargoType = CargoType.GenerateRandomCargo(random);
                    LoadCargo(grid, cargoType);

                    if (cargoType.subtypeName == "SteelPlate")
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.SteelPlateConvoyDispatched, AudioClip.ConvoyDispatched1);
                    }
                    else if (cargoType.subtypeName == "MetalGrid")
                    {
                        audioSystem.PlayAudioRandomChance(1, AudioClip.MetalGridConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Construction")
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConstructionConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "InteriorPlate")
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.InteriorPlateConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Girder")
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.GirderConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "SmallTube")
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.SmallTubeConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "LargeTube")
                    {
                        audioSystem.PlayAudioRandomChance(0.2, AudioClip.LargeTubeConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Motor")
                    {
                        audioSystem.PlayAudioRandomChance(0.75, AudioClip.MotorConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Display")
                    {
                        audioSystem.PlayAudioRandomChance(0.2, AudioClip.DisplayConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "BulletproofGlass")
                    {
                        audioSystem.PlayAudioRandomChance(0.3, AudioClip.BulletproofGlassConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Computer")
                    {
                        audioSystem.PlayAudioRandomChance(0.2, AudioClip.ComputerConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Reactor")
                    {
                        audioSystem.PlayAudioRandomChance(0.75, AudioClip.ReactorConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Medical")
                    {
                        audioSystem.PlayAudioRandomChance(0.7, AudioClip.MedicalConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "RadioCommunication")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.RadioCommunicationConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Explosives")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.ExplosivesConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "SolarCell")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.SolarCellConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "PowerCell")
                    {
                        audioSystem.PlayAudioRandomChance(0.75, AudioClip.PowerCellConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "NATO_5p56x45mm")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO_5p56x45mmConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "NATO_25x184mm")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO25x184mmConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Missile200mm")
                    {
                        audioSystem.PlayAudioRandomChance(0.5, AudioClip.Missile200mmConvoyDispatched);
                    }
                    else if (cargoType.subtypeName == "Uranium")
                    {
                        audioSystem.PlayAudioRandomChance(1, AudioClip.UraniumConvoyDispatched);
                    }
                    else      // we don't know what it is..
                    {
                        audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConvoyDispatched1, AudioClip.ConvoyDispatched2, AudioClip.ConvoyDispatched3);
                    }

                    string sPrefix = "T";
                    if (unitType == UnitType.Air)
                    {
                        sPrefix += "A";
                    }
                    else
                    {
                        sPrefix += "G";
                    }

                    grid.SetAllBeaconNames(sPrefix + random.Next(10000, 99999) + " - " + cargoType.GetDisplayName() + " Shipment",
                                           200f);              // V31 set short until initialize check timeout
                    var destination = unitType == UnitType.Air ? airConvoyDestinationPosition : groundConvoyDestinationPosition;

//                        ModLog.Info("Air Destination=" + airConvoyDestinationPosition.ToString());
//                        ModLog.Info("GND Destination=" + groundConvoyDestinationPosition.ToString());
//                        ModLog.Info("Chosen Dest=" + destination.ToString());
                    SetDestination(grid, destination);
                    RegisterConvoy(grid, NpcGroupState.Travelling, unitType, destination, MyAPIGateway.Session.GameDateTime);

                    var planet = DuckUtils.FindPlanetInGravity(grid.GetPosition());
                    if (planet != null)
                    {
                        convoySpawner.SpawnConvoyEscorts(grid, unitType, planet);
                    }
                    break;

                case UnitRole.Escort:
                    var group = FindNearestJoinableNpcGroup(grid.GetPosition(), unitType);
                    if (group == null)
                    {
                        ModLog.Error("Escort ship spawned but can't find a group to join!");
                        grid.CloseAll();
                    }
                    else
                    {
                        grid.SetAllBeaconNames("E" + random.Next(10000, 99999) + " - " + EscortName, 2500f);                                 // V31 shorten escort beacon range to decrease hud spam
                        var nearestPlanet = DuckUtils.FindPlanetInGravity(grid.GetPosition());
                        if (nearestPlanet != null)
                        {
                            group.JoinAsEscort(grid, unitType, nearestPlanet);
                        }
                    }
                    break;

                case UnitRole.Backup:
                    var gCorpBase = baseManager.FindBaseWantingBackup();
                    // V26
                    bFoundBackup = true;

                    if (gCorpBase == null)
                    {
                        gCorpBase = baseManager.FindBaseNear(grid.GetPosition());
                    }

                    if (gCorpBase == null)
                    {
                        ModLog.Error("Backup ship spawned but can't find the base that asked for it!");
                        grid.CloseAll();
                        break;
                    }
                    var backupPosition = gCorpBase.GetBackupPosition();
                    grid.SendToPosition(backupPosition);
                    // backup debug
                    string sBeacon = "M" + random.Next(10000, 99999) + " Investigating Backup Call";
//                        ModLog.Info("Backup Found:" + sBeacon);
//                        ModLog.Info(" Destination=" + backupPosition.ToString());
                    grid.SetAllBeaconNames(sBeacon, 20000f);
                    var backupGroup = new BackupGroup(NpcGroupState.Travelling, backupPosition, grid,
                                                      heatSystem, audioSystem, MyAPIGateway.Session.GameDateTime);
                    //damageSensor.RegisterDamageObserver(grid.EntityId, backupGroup);
                    npcGroups.Add(backupGroup);
                    break;

                case UnitRole.Bomb:
                    bool hasSensors = false;
                    var  slimBlocks = new List <IMySlimBlock>();
                    grid.GetBlocks(slimBlocks, b => b.FatBlock is IMySensorBlock);
                    if (slimBlocks.Count > 0)
                    {
                        hasSensors = true;
                    }


                    grid.GetBlocks(slimBlocks, b => b.FatBlock is IMyWarhead);
                    foreach (var slim in slimBlocks)
                    {
                        var wh = slim.FatBlock as IMyWarhead;
                        wh.IsArmed = true;
                        if (!hasSensors)    // if no sensors, start the countdown
                        {
                            ModLog.Info("BOMB: no sensors: Starting timer");
                            wh.StartCountdown();
                        }
                    }
                    break;

                default:
                    continue;
                }
            }
            if (bFoundBackup)
            {
                baseManager.ClearBaseBackupRequests();
            }
        }
Esempio n. 4
0
        protected override void InitCommon(IModSystemRegistry modSystemRegistry)
        {
            string sInit = "Initialising Escape From Mars build " + CurrentModVersion;

            MyAPIGateway.Utilities.ShowNotification(sInit, 5000, MyFontEnum.DarkBlue);
            ModLog.Info(sInit);

            if (MyAPIGateway.Session.IsServer)
            {
                MyVisualScriptLogicProvider.SendChatMessage(sInit, "Wicorel", 0, MyFontEnum.DarkBlue);
            }

            gameVersion = MyAPIGateway.Session.Version;
            ModLog.Info("SE Version=" + gameVersion.ToString());

            /*
             * ModLog.Info(" Major=" + gameVersion.Major.ToString());
             * ModLog.Info(" MajorRevision=" + gameVersion.MajorRevision.ToString());
             * ModLog.Info(" Minor=" + gameVersion.Minor.ToString());
             * ModLog.Info(" MinorRevision=" + gameVersion.MinorRevision.ToString());
             * ModLog.Info(" Build=" + gameVersion.Build.ToString());
             */
            /*
             * // TESTING: (they seem to be the same)
             * if (MyAPIGateway.Session.IsServer)
             *  ModLog.Info("MyAPIGateway.Session.IsServer.IsServer");
             * else
             *  ModLog.Info("MyAPIGateway.Session.NOT Server");
             * if (MyAPIGateway.Multiplayer.IsServer)
             *  ModLog.Info("MyAPIGateway.Multiplayer.IsServer");
             * else
             *  ModLog.Info("MyAPIGateway.Multiplayer.NOT Server");
             */
            bool bResearch = Session.SessionSettings.EnableResearch;

            // This works to change the setting.
            Session.SessionSettings.EnableResearch = true;

            Session.SessionSettings.EnableBountyContracts = false; // SE V1.192

            if ((gameVersion.Major == 1 && gameVersion.Minor >= 192) || gameVersion.Major > 1)
            {
                ModLog.Info("Economy items enabled");
                CargoType.AllowEconomyItems();
            }

            if (!bResearch)
            {
//                MyAPIGateway.Utilities.ShowNotification("Save, then Exit. Edit world /Advanced settings and Enable progression", 50000, MyFontEnum.Red);
                ModLog.Info("Research was not turned on");
            }
            TextAPI = new HudAPIv2();
            if (modBuildWhenGameStarted > 4)
            {
                DuckUtils.PutPlayerIntoFaction("CRASH");
            }
            researchControl = new ResearchControl(audioSystem);
            researchControl.InitResearchRestrictions();
            researchHacking = new ResearchHacking(researchControl, TextAPI, networkComms);
            networkComms.Init(audioSystem, researchControl, researchHacking);
            modSystemRegistry.AddCloseableModSystem(networkComms);
            modSystemRegistry.AddUpatableModSystem(audioSystem);

            MyAPIGateway.Utilities.MessageEntered += MessageEntered;
        }