public bool TryFindChairNear(CompMusicSpot spot, Pawn sitter, out Thing chair) { IntVec3 center = spot.parent.Position; CompMusicalInstrument comp = spot.parent.TryGetComp <CompMusicalInstrument>(); for (int i = 0; i < RadialPatternMiddleOutward.Count; i++) { IntVec3 c = center + RadialPatternMiddleOutward[i]; if (comp != null && comp.Props.isBuilding && c == comp.parent.InteractionCell) { continue; } Building edifice = c.GetEdifice(map); if (edifice != null && edifice.def.building.isSittable && sitter.CanReserveAndReach(edifice, PathEndMode.OnCell, Danger.None) && !edifice.IsForbidden(sitter) && GenSight.LineOfSight(center, edifice.Position, map, skipFirstCell: true)) { chair = edifice; return(true); } } chair = null; return(false); }
public bool TryFindStandingSpotOrChair(CompMusicSpot musicSpot, Pawn musician, Thing instrument, out LocalTargetInfo target) { IntVec3 standingSpot; Thing chair; target = null; PerformanceManager pm = musician.Map.GetComponent <PerformanceManager>(); CompMusicalInstrument comp = instrument.TryGetComp <CompMusicalInstrument>(); if (comp.Props.isBuilding) { if (pm.TryFindChairAt(comp, musician, out chair)) { target = chair; return(true); } else if (pm.TryFindSpotAt(comp, musician, out standingSpot)) { target = standingSpot; return(true); } } else { if (pm.TryFindSitSpotOnGroundNear(musicSpot, musician, out standingSpot)) { target = standingSpot; return(true); } } return(false); }
public bool TryFindChairNear(CompMusicSpot spot, Pawn sitter, out Thing chair) { var center = spot.parent.Position; var comp = spot.parent.TryGetComp <CompMusicalInstrument>(); foreach (var intVec3 in RadialPatternMiddleOutward) { var c = center + intVec3; if (comp != null && comp.Props.isBuilding && c == comp.parent.InteractionCell) { continue; } var edifice = c.GetEdifice(map); if (edifice == null || !edifice.def.building.isSittable || !sitter.CanReserveAndReach(edifice, PathEndMode.OnCell, Danger.None) || edifice.IsForbidden(sitter) || !GenSight.LineOfSight(center, edifice.Position, map, true)) { continue; } chair = edifice; return(true); } chair = null; return(false); }
public void RegisterDeactivatedMusicSpot(CompMusicSpot spot) { if (ActiveMusicSpots.Contains(spot)) { ActiveMusicSpots.Remove(spot); } //Verse.Log.Message(String.Format("{0} deactivated, count={1}", spot.parent.Label, ActiveMusicSpots.Count)); }
public bool TryFindSitSpotOnGroundNear(CompMusicSpot spot, Pawn sitter, out IntVec3 result) { IntVec3 center = spot.parent.Position; for (int i = 0; i < 30; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[Rand.Range(1, NumRadiusCells)]; if (sitter.CanReserveAndReach(intVec, PathEndMode.OnCell, Danger.None, 1, -1, null, false) && intVec.GetEdifice(map) == null && GenSight.LineOfSight(center, intVec, map, true, null, 0, 0)) { result = intVec; return(true); } } result = IntVec3.Invalid; return(false); }
public bool TryFindSitSpotOnGroundNear(CompMusicSpot spot, Pawn sitter, out IntVec3 result) { var center = spot.parent.Position; for (var i = 0; i < 30; i++) { var intVec = center + GenRadial.RadialPattern[Rand.Range(1, NumRadiusCells)]; if (!sitter.CanReserveAndReach(intVec, PathEndMode.OnCell, Danger.None) || intVec.GetEdifice(map) != null || !GenSight.LineOfSight(center, intVec, map, true)) { continue; } result = intVec; return(true); } result = IntVec3.Invalid; return(false); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) || !pawn.Awake() || pawn.WorkTagIsDisabled(WorkTags.Artistic)) { return(false); } PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>(); if (!pm.CanPlayForWorkNow(pawn)) { return(false); } CompMusicSpot compMusicSpot = t.TryGetComp <CompMusicSpot>(); CompMusicalInstrument instrumentComp = t.TryGetComp <CompMusicalInstrument>(); CompPowerTrader powerComp = t.TryGetComp <CompPowerTrader>(); if (compMusicSpot == null) { return(false); } if (!compMusicSpot.Active || instrumentComp == null) { return(false); } IntVec3 standingSpot; if (!pm.TryFindSitSpotOnGroundNear(compMusicSpot, pawn, out standingSpot)) { return(false); } Thing instrument; LocalTargetInfo chairOrSpot = null; if (forced && instrumentComp != null && instrumentComp.Props.isBuilding && pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.None) && (powerComp == null || powerComp.PowerOn)) { if (!pm.TryFindStandingSpotOrChair(compMusicSpot, pawn, t, out chairOrSpot)) { return(false); } } else if (pm.TryFindInstrumentToPlay(compMusicSpot.parent, pawn, out instrument, true)) { #if DEBUG Verse.Log.Message(String.Format("{0} chose to play {1}", pawn.LabelShort, instrument.LabelShort)); #endif if (!pm.TryFindStandingSpotOrChair(compMusicSpot, pawn, instrument, out chairOrSpot)) { return(false); } } else { return(false); } return(true); }
public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { //Verse.Log.Message(String.Format("Trying to play at {0}", thing.Label)); if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Hearing) || !pawn.Awake() || pawn.WorkTagIsDisabled(WorkTags.Artistic)) { return(null); } PerformanceManager pm = pawn.Map.GetComponent <PerformanceManager>(); if (!pm.CanPlayForWorkNow(pawn)) { return(null); } CompMusicSpot compMusicSpot = thing.TryGetComp <CompMusicSpot>(); if (compMusicSpot == null) { return(null); } if (!compMusicSpot.Active) { return(null); } Job job; IntVec3 standingSpot; if (!pm.TryFindSitSpotOnGroundNear(compMusicSpot, pawn, out standingSpot)) { return(null); } job = new Job(JobDefOf_MusicPlayWork.MusicPlayWork, compMusicSpot.parent); //, standingSpot); Thing instrument; CompMusicSpot musicSpotComp = thing.TryGetComp <CompMusicSpot>(); CompMusicalInstrument instrumentComp = thing.TryGetComp <CompMusicalInstrument>(); CompPowerTrader powerComp = thing.TryGetComp <CompPowerTrader>(); LocalTargetInfo chairOrSpot = null; if (forced && instrumentComp != null && instrumentComp.Props.isBuilding && pawn.CanReserveAndReach(thing, PathEndMode.Touch, Danger.None) && (powerComp == null || powerComp.PowerOn)) { if (!pm.TryFindStandingSpotOrChair(musicSpotComp, pawn, thing, out chairOrSpot)) { return(null); } job.targetB = chairOrSpot; job.targetC = thing; } else if (pm.TryFindInstrumentToPlay(compMusicSpot.parent, pawn, out instrument, true)) { #if DEBUG Verse.Log.Message(String.Format("{0} chose to play {1}", pawn.LabelShort, instrument.LabelShort)); #endif if (!pm.TryFindStandingSpotOrChair(musicSpotComp, pawn, instrument, out chairOrSpot)) { return(null); } job.targetB = chairOrSpot; job.targetC = instrument; } else { #if DEBUG Verse.Log.Message(String.Format("{0} couldn't find an instrument", pawn.LabelShort)); #endif return(null); } job.count = 1; return(job); }