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); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if (t is Building_ShipTurret) { Building_ShipTurret turret = t as Building_ShipTurret; if (turret.ParentShip != null) { return(pawn.Map.reservationManager.CanReserve(pawn, turret, 1) && turret.ParentShip.weaponsToUninstall.Count > 0 && !turret.ParentShip.weaponsToUninstall.Any(x => x.Value == null)); } } return(false); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Building_ShipTurret turret = t as Building_ShipTurret; if (turret != null && turret.ParentShip != null) { //KeyValuePair<ShipWeaponSlot, Thing> weaponSpecs = turret.ParentShip.weaponsToUninstall.FirstOrDefault(x => x.Value == turret); if (turret.ParentShip.weaponsToUninstall.ContainsValue(turret) && pawn.Map.reservationManager.CanReserve(pawn, turret, 1)) { return(new Job(ShipNamespaceDefOfs.UninstallShipWeapon, turret, turret.ParentShip) { count = 1, ignoreForbidden = false, }); } } return(null); }
private void InitiateInstalledTurrets() { foreach (ShipWeaponSlot current in this.compShip.weaponSlots) { if (current.slotType == WeaponSystemType.LightCaliber) { this.installedTurrets.Add(current, null); } if (current.slotType == WeaponSystemType.Bombing) { this.Payload.Add(current, null); } if (this.assignedTurrets.Count > 0) { Building_ShipTurret turret = this.assignedTurrets.Find(x => x.assignedSlotName == current.SlotName); if (turret != null) { turret.AssignParentShip(this); this.installedTurrets[current] = turret; } } else { } if (this.loadedBombs.Count > 0) { WeaponSystemShipBomb bomb = (WeaponSystemShipBomb)this.loadedBombs.First(x => x.assignedSlotName == current.SlotName); if (bomb != null) { this.Payload[current] = bomb; } } if (this.assignedSystemsToModify.Count > 0) { KeyValuePair <WeaponSystem, bool> entry = this.assignedSystemsToModify.First(x => x.Key.assignedSlotName == current.SlotName); this.TryModifyWeaponSystem(current, entry.Key, entry.Value); } } }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(TargetIndex.A, 10)); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)); Toil toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 500; toil.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); yield return(toil); yield return(new Toil { initAction = delegate { ShipBase ship = (ShipBase)TargetA.Thing; Action action = delegate { Building_ShipTurret turret = (Building_ShipTurret)TargetC.Thing; if (turret != null && ship.installedTurrets.ContainsValue(turret)) { Thing t = ThingMaker.MakeThing(turret.installedByWeaponSystem); GenSpawn.Spawn(t, TargetB.Thing.Position, this.Map); ship.installedTurrets.Remove(turret.Slot); } }; ship.compShip.Notify_PawnEntered(this.pawn); action(); }, defaultCompleteMode = ToilCompleteMode.Instant }); yield break; }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnSomeonePhysicallyInteracting(TargetIndex.A); yield return(Toils_Reserve.Reserve(TargetIndex.A, 1)); //yield return Toils_Reserve.Reserve(TargetIndex.B, 1); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)); Toil toil = new Toil(); toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 500; toil.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); yield return(toil); yield return(new Toil { initAction = delegate { ShipBase ship = (ShipBase)TargetB.Thing; Building_ShipTurret turret = (Building_ShipTurret)TargetA.Thing; if (turret != null && ship.installedTurrets.ContainsValue(turret)) { Thing t = ThingMaker.MakeThing(turret.installedByWeaponSystem); GenSpawn.Spawn(t, TargetA.Thing.Position, this.Map); ship.weaponsToUninstall.RemoveAll(x => x.Value == turret); ship.installedTurrets[turret.Slot] = null; ship.assignedTurrets.Remove(turret); turret.Destroy(); } }, defaultCompleteMode = ToilCompleteMode.Instant }); yield break; }