public static List <Pawn> GenerateFighter(float points, Lord lord, List <PawnKindDef> kindDefs, Map map, Faction faction, IntVec3 vec3, bool toList = false) { Pawn fighter = new Pawn(); List <Pawn> pawns = new List <Pawn>(); PawnKindDef def = new PawnKindDef(); while (points > 0) { PawnGenerationRequest generationRequest = new PawnGenerationRequest(kindDefs.Where(x => x.RaceProps.Humanlike).TryRandomElementByWeight(x => x.combatPower, out def) ? def : null, faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true); fighter = PawnGenerator.GeneratePawn(generationRequest); fighter.mindState.canFleeIndividual = false; if (fighter.equipment != null && fighter.equipment.Primary != null && fighter.equipment.Primary.def.thingSetMakerTags != null && fighter.equipment.Primary.def.thingSetMakerTags.Contains("SingleUseWeapon"))//.Where(x=> x.def.IsWeaponUsingProjectiles && x.def.thingSetMakerTags.Contains("SingleUseWeapon")).Any()) { fighter.equipment.Primary.Destroy(); fighter.equipment.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Gun_Revolver"))); } points -= fighter.kindDef.combatPower; if (!toList) { lord.AddPawn(fighter); GenSpawn.Spawn(fighter, vec3, map); vec3 = fighter.RandomAdjacentCell8Way(); vec3.ClampInsideMap(map); map.mapPawns.UpdateRegistryForPawn(fighter); } else { pawns.Add(fighter); } } return(pawns); }
protected virtual void FireTurret(VehicleTurret turret) { float horizontalOffset = turret.turretDef.projectileShifting.NotNullAndAny() ? turret.turretDef.projectileShifting[turret.CurrentTurretFiring] : 0; Vector3 launchPos = TurretLocation(turret) + new Vector3(horizontalOffset, 1f, turret.turretDef.projectileOffset); Vector3 targetPos = Target(turret); float range = Vector3.Distance(TurretLocation(turret), targetPos); IntVec3 target = targetPos.ToIntVec3() + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(turret.CurrentFireMode.spreadRadius * (range / turret.turretDef.maxRange)))]; if (turret.CurrentTurretFiring >= turret.turretDef.projectileShifting.Count) { turret.CurrentTurretFiring = 0; } ThingDef projectile; if (turret.turretDef.ammunition != null && !turret.turretDef.genericAmmo) { projectile = turret.loadedAmmo?.projectileWhenLoaded; } else { projectile = turret.turretDef.projectile; } try { float speedTicksPerTile = projectile.projectile.SpeedTilesPerTick; if (turret.turretDef.projectileSpeed > 0) { speedTicksPerTile = turret.turretDef.projectileSpeed; } ProjectileSkyfaller projectile2 = ProjectileSkyfallerMaker.WrapProjectile(ProjectileSkyfallerDefOf.ProjectileSkyfaller, projectile, this, launchPos, target.ToVector3Shifted(), speedTicksPerTile); //REDO - RANDOMIZE TARGETED CELLS GenSpawn.Spawn(projectile2, target.ClampInsideMap(Map), Map); if (turret.turretDef.ammunition != null) { turret.ConsumeShellChambered(); } if (turret.turretDef.cannonSound != null) { turret.turretDef.cannonSound.PlayOneShot(new TargetInfo(Position, Map, false)); } turret.PostTurretFire(); } catch (Exception ex) { Log.Error($"Exception when firing Cannon: {turret.turretDef.LabelCap} on Pawn: {vehicle.LabelCap}. Exception: {ex.Message}"); } }
public Stencil ClampInsideMap() { return(new Stencil(map, pos.ClampInsideMap(map), rot, bounds)); }