private RecalculatedPropertyModel GetViewModelFromProperty(PropertyModel property, RoofModel roof = null) { try { List <SectionModel> sections = null; if (roof != null) { sections = roof.Sections; } else { sections = _property.Roofs.SelectMany(x => x.Sections).ToList(); } var overallPitch = RoofUtility.GetPredominantPitchFromSections(sections); var count = RoofUtility.GetPitchCount(sections)?.PitchCount ?? 1; var recalc = new RecalculatedPropertyModel(property) { RecalculatedSections = property.Roofs.SelectMany(x => x.Sections).Where(x => x.PitchRise == overallPitch).ToList(), CurrentPitch = overallPitch, OriginalPitch = overallPitch, PitchCount = count }; recalc.Roofs = recalc.Roofs.Where(x => x.Name == (roof?.Name ?? x.Name)).ToList(); return(recalc); } catch (Exception ex) { _logger.LogError("Failed to get view model from property.", ex, property); return(null); } }
public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { LocalTargetInfo targetB = c; Thing thing = RoofUtility.FirstBlockingThing(c, pawn.Map); if (thing != null) { return(RoofUtility.HandleBlockingThingJob(thing, pawn, forced)); } if (!pawn.CanReach(c, PathEndMode.Touch, pawn.NormalMaxDanger())) { targetB = BuildingToTouchToBeAbleToBuildRoof(c, pawn); } return(new Job(JobDefOf.BuildRoof, c, targetB)); }
private void CalculateCurrentTotals(PropertyModel property) { try { foreach (var roof in property.Roofs) { var response = RoofUtility.CalculateTotals(roof); var rise = RoofUtility.GetPredominantPitchFromSections(roof.Sections); roof.TotalArea = Math.Round(response.TotalArea, 0); roof.TotalSquares = Math.Ceiling(response.TotalSquaresCount); roof.PredominantPitchRise = rise; } } catch (Exception ex) { _logger.LogError("Failed to calculate current totals.", ex); } }
public override bool HasJobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { bool result; if (!pawn.Map.areaManager.BuildRoof[c]) { result = false; } else if (c.Roofed(pawn.Map)) { result = false; } else if (c.IsForbidden(pawn)) { result = false; } else { LocalTargetInfo target = c; ReservationLayerDef ceiling = ReservationLayerDefOf.Ceiling; if (!pawn.CanReserve(target, 1, -1, ceiling, forced)) { result = false; } else if (!pawn.CanReach(c, PathEndMode.Touch, pawn.NormalMaxDanger(), false, TraverseMode.ByPawn) && this.BuildingToTouchToBeAbleToBuildRoof(c, pawn) == null) { result = false; } else if (!RoofCollapseUtility.WithinRangeOfRoofHolder(c, pawn.Map, false)) { result = false; } else if (!RoofCollapseUtility.ConnectedToRoofHolder(c, pawn.Map, true)) { result = false; } else { Thing thing = RoofUtility.FirstBlockingThing(c, pawn.Map); result = (thing == null || RoofUtility.CanHandleBlockingThing(thing, pawn, forced)); } } return(result); }
private void OnPitchValueChanged(int oldValue, int newValue) { try { if (newValue > 35 || newValue < 0) { return; } PredominantPitch = $"{newValue}:12"; _recalculated.CurrentPitch = newValue; foreach (var section in _recalculated.RecalculatedSections) { section.PitchRise = newValue; var totals = SectionUtility.CalculateAreaAndSquares(new CalculateSectionModelRequest() { Length = section.Length, NumberOfSections = section.NumberOfSections, PitchRise = section.PitchRise, PitchRun = section.PitchRun, SecondLength = section.SecondLength, ShapeType = section.ShapeType, Width = section.Width }); section.CalculatedX = totals.CalculatedX; section.Area = totals.Area; section.SquaresCount = totals.SquaresCount; } foreach (var roof in _recalculated.Roofs) { var totals = RoofUtility.CalculateTotals(roof); roof.TotalArea = totals.TotalArea; roof.TotalSquares = totals.TotalSquaresCount; roof.PredominantPitchRise = RoofUtility.GetPredominantPitchFromSections(roof.Sections); } Area = $"{Convert.ToInt64(_recalculated.Roofs.Sum(x => x.TotalArea)).ToString()} sq. ft."; Squares = $"Total Squares: {Math.Ceiling(_recalculated.Roofs.Sum(x => x.TotalSquares)).ToString()} squares"; RefreshTableView(_recalculated.Roofs.Sum(x => x.TotalArea)); } catch (Exception ex) { _logger.LogError("Failed to calculate pitch. " + ex.ToString(), ex); } }
public override bool HasJobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { if (!pawn.Map.areaManager.BuildRoof[c]) { return(false); } if (c.Roofed(pawn.Map)) { return(false); } if (c.IsForbidden(pawn)) { return(false); } LocalTargetInfo target = c; ReservationLayerDef ceiling = ReservationLayerDefOf.Ceiling; bool ignoreOtherReservations = forced; if (!pawn.CanReserve(target, 1, -1, ceiling, ignoreOtherReservations)) { return(false); } if (!pawn.CanReach(c, PathEndMode.Touch, pawn.NormalMaxDanger()) && BuildingToTouchToBeAbleToBuildRoof(c, pawn) == null) { return(false); } if (!RoofCollapseUtility.WithinRangeOfRoofHolder(c, pawn.Map)) { return(false); } if (!RoofCollapseUtility.ConnectedToRoofHolder(c, pawn.Map, assumeRoofAtRoot: true)) { return(false); } Thing thing = RoofUtility.FirstBlockingThing(c, pawn.Map); if (thing != null) { return(RoofUtility.CanHandleBlockingThing(thing, pawn, forced)); } return(true); }
protected override void DoEffect() { JobDriver_BuildRoof.builtRoofs.Clear(); for (int i = 0; i < 9; i++) { IntVec3 intVec = base.Cell + GenAdj.AdjacentCellsAndInside[i]; if (intVec.InBounds(base.Map)) { if (base.Map.areaManager.BuildRoof[intVec] && !intVec.Roofed(base.Map) && RoofCollapseUtility.WithinRangeOfRoofHolder(intVec, base.Map, false) && RoofUtility.FirstBlockingThing(intVec, base.Map) == null) { base.Map.roofGrid.SetRoof(intVec, RoofDefOf.RoofConstructed); MoteMaker.PlaceTempRoof(intVec, base.Map); JobDriver_BuildRoof.builtRoofs.Add(intVec); } } } JobDriver_BuildRoof.builtRoofs.Clear(); }