Example #1
0
 public bool TryInstallTurret(CompShipWeapon comp)
 {
     if (comp.SProps.TurretToInstall != null)
     {
         ShipWeaponSlot      slot   = comp.slotToInstall;
         Building_ShipTurret turret = (Building_ShipTurret)ThingMaker.MakeThing(comp.SProps.TurretToInstall, null);
         turret.installedByWeaponSystem = comp.parent.def;
         this.installedTurrets[slot]    = turret;
         turret.AssignParentShip(this);
         turret.assignedSlotName = slot.SlotName;
         turret.SetFactionDirect(this.Faction);
         if (slot.turretMinSize.x != turret.def.size.x)
         {
             //           turret.def.size.x = slot.turretMinSize.x;
         }
         if (slot.turretMinSize.z != turret.def.size.z)
         {
             //            turret.def.size.z = slot.turretMinSize.z;
         }
         IntVec3 drawLoc = this.Position + DropShipUtility.AdjustedIntVecForShip(this, slot.turretPosOffset);
         if (!turret.Spawned)
         {
             GenSpawn.Spawn(turret, drawLoc, this.Map);
         }
         this.assignedTurrets.Add(turret);
         return(true);
     }
     return(false);
 }
Example #2
0
 public ShipWeaponSlot(ShipWeaponSlot existingSlot)
 {
     this.SlotName        = existingSlot.SlotName;
     this.slotType        = existingSlot.slotType;
     this.posOffset       = existingSlot.posOffset;
     this.turretPosOffset = existingSlot.turretPosOffset;
     this.InitiateWeaponSlotID();
 }
Example #3
0
 public bool TryInstallPayload(ShipWeaponSlot slot, CompShipWeapon comp)
 {
     if (comp.SProps.PayloadToInstall != null)
     {
         WeaponSystemShipBomb newBomb = (WeaponSystemShipBomb)ThingMaker.MakeThing(comp.SProps.PayloadToInstall, null);
         this.Payload.Add(slot, newBomb);
         return(true);
     }
     return(false);
 }
Example #4
0
 public bool TryInstallPayload(WeaponSystemShipBomb bomb, CompShipWeapon comp)
 {
     if (comp.SProps.PayloadToInstall != null)
     {
         ShipWeaponSlot slot = comp.slotToInstall;
         this.loadedBombs.Add(bomb);
         this.Payload[slot] = bomb;
         return(true);
     }
     return(false);
 }
Example #5
0
        public static List <WeaponSystem> availableWeaponSystemsForSlot(Map map, ShipWeaponSlot slot)
        {
            List <Thing> list = map.listerThings.AllThings.FindAll(x => x.TryGetComp <CompShipWeapon>() != null);

            List <WeaponSystem> list2 = new List <WeaponSystem>();

            for (int i = 0; i < list.Count; i++)
            {
                CompShipWeapon comp = list[i].TryGetComp <CompShipWeapon>();
                if (comp.SProps.weaponSystemType == slot.slotType)
                {
                    list2.Add((WeaponSystem)list[i]);
                }
            }
            return(list2);
        }
Example #6
0
 public bool TryModifyWeaponSystem(ShipWeaponSlot slot, Thing system, bool AddForInstalling = true)
 {
     if (AddForInstalling)
     {
         if (this.weaponsToInstall.ContainsKey(slot))
         {
             this.weaponsToInstall.Remove(slot);
         }
         this.weaponsToInstall.Add(slot, system);
         return(true);
     }
     else
     {
         if (this.weaponsToUninstall.ContainsKey(slot))
         {
             this.weaponsToUninstall.Remove(slot);
         }
         this.weaponsToUninstall.Add(slot, system);
         return(true);
     }
 }
        // SpaceDorf added LabelLength
        private void DrawWeaponsTurretRow(ref float y, float width, KeyValuePair <ShipWeaponSlot, Building_ShipTurret> currentWeapon, float LabelLength)
        {
            Rect rectslotName = new Rect(10f, y, LabelLength, 30f);

            Widgets.Label(rectslotName, currentWeapon.Key.SlotName);

            Rect rectslotIcon = new Rect(rectslotName.xMax + 5f, y, 30f, 30f);

            if (currentWeapon.Value == null)
            {
                Widgets.DrawWindowBackground(rectslotIcon);
            }
            else
            {
                Widgets.DrawWindowBackground(rectslotIcon);
                Texture2D tex = ContentFinder <Texture2D> .Get(currentWeapon.Value.def.building.turretTopGraphicPath);

                GUI.DrawTexture(rectslotIcon, tex);
            }

            if (Mouse.IsOver(rectslotIcon))
            {
                GUI.color = ITab_ShipCargo.HighlightColor;
                GUI.DrawTexture(rectslotIcon, TexUI.HighlightTex);
            }
            GUI.color = Color.white;
            if (Widgets.ButtonInvisible(rectslotIcon))
            {
                List <FloatMenuOption> opts = new List <FloatMenuOption>();
                if (currentWeapon.Value == null)
                {
                    List <Thing> list = DropShipUtility.availableWeaponsForSlot(this.ship.Map, currentWeapon.Key);
                    list.OrderBy(x => x.Position.DistanceToSquared(this.ship.Position));
                    for (int i = 0; i < list.Count; i++)
                    {
                        Thing  weapon = list[i];
                        Action action = new Action(delegate
                        {
                            ship.TryModifyWeaponSystem(currentWeapon.Key, weapon, true);
                        });

                        FloatMenuOption newOption = new FloatMenuOption("Install".Translate() + weapon.Label, action);
                        opts.Add(newOption);
                    }
                }
                else
                {
                    Action action = new Action(delegate
                    {
                        ship.TryModifyWeaponSystem(currentWeapon.Key, currentWeapon.Value, false);
                    });
                    FloatMenuOption newOption = new FloatMenuOption("Uninstall".Translate() + currentWeapon.Value.Label, action);
                    opts.Add(newOption);
                }
                if (opts.Count < 1)
                {
                    opts.Add(new FloatMenuOption("None", null));
                }
                Find.WindowStack.Add(new FloatMenu(opts));
            }
            Rect rect3 = new Rect(rectslotIcon.xMax + 10f, y, width - rectslotName.width - rectslotIcon.width - 10f, 30f);

            if (currentWeapon.Value == null && !ship.weaponsToInstall.Any(x => x.Key == currentWeapon.Key))
            {
                Widgets.Label(rect3, "NoneInstalled".Translate());
            }
            else
            {
                ShipWeaponSlot installingSlot = ship.weaponsToInstall.FirstOrDefault(x => x.Key == currentWeapon.Key).Key;
                if (installingSlot != null)
                {
                    Widgets.Label(rect3, "InstallingShipWeapon".Translate(new object[]
                    {
                        ship.weaponsToInstall[installingSlot].LabelCap
                    }));
                }
                else
                {
                    Widgets.Label(rect3, currentWeapon.Value.def.LabelCap);
                }
            }
            y += 35f;
        }
Example #8
0
 public static List <Thing> availableWeaponsForSlot(Map map, ShipWeaponSlot slot)
 {
     return(map.listerThings.AllThings.FindAll(x => x.TryGetComp <CompShipWeapon>() != null && x.TryGetComp <CompShipWeapon>().SProps.weaponSystemType == slot.slotType));
 }