Exemplo n.º 1
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Frame frame = t as Frame;

            if (frame == null)
            {
                return(null);
            }
            if (frame.MaterialsNeeded().Count > 0)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(frame, pawn, forced));
            }
            if (!GenConstruct.CanConstruct(frame, pawn, forced))
            {
                return(null);
            }
            return(new Job(JobDefOf.FinishFrame, frame));
        }
        public static bool CanConstruct(Thing t, Pawn p, bool checkConstructionSkill = true, bool forced = false)
        {
            if (GenConstruct.FirstBlockingThing(t, p) != null)
            {
                return(false);
            }
            LocalTargetInfo target    = t;
            PathEndMode     peMode    = PathEndMode.Touch;
            Danger          maxDanger = (!forced) ? p.NormalMaxDanger() : Danger.Deadly;

            if (!p.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
            {
                return(false);
            }
            if (t.IsBurning())
            {
                return(false);
            }
            if (checkConstructionSkill && p.skills.GetSkill(SkillDefOf.Construction).Level < t.def.constructionSkillPrerequisite)
            {
                JobFailReason.Is(GenConstruct.ConstructionSkillTooLowTrans, null);
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.Faction != pawn.Faction)
            {
                result = null;
            }
            else
            {
                Frame frame = t as Frame;
                if (frame == null)
                {
                    result = null;
                }
                else if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
                {
                    result = GenConstruct.HandleBlockingThingJob(frame, pawn, forced);
                }
                else
                {
                    bool checkConstructionSkill = this.def.workType == WorkTypeDefOf.Construction;
                    if (!GenConstruct.CanConstruct(frame, pawn, checkConstructionSkill, forced))
                    {
                        result = null;
                    }
                    else
                    {
                        result = base.ResourceDeliverJobFor(pawn, frame, true);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public virtual bool TryReplaceWithSolidThing(Pawn workerPawn, out Thing createdThing, out bool jobEnded)
        {
            jobEnded = false;
            if (GenConstruct.FirstBlockingThing(this, workerPawn) != null)
            {
                workerPawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                jobEnded     = true;
                createdThing = null;
                return(false);
            }
            createdThing = MakeSolidThing();
            Map map = base.Map;

            GenSpawn.WipeExistingThings(base.Position, base.Rotation, createdThing.def, map, DestroyMode.Deconstruct);
            if (!base.Destroyed)
            {
                Destroy();
            }
            if (createdThing.def.CanHaveFaction)
            {
                createdThing.SetFactionDirect(workerPawn.Faction);
            }
            GenSpawn.Spawn(createdThing, base.Position, map, base.Rotation);
            return(true);
        }
        // Token: 0x060000E0 RID: 224 RVA: 0x000070E0 File Offset: 0x000052E0
        public static bool CanConstruct(Thing t, Pawn p, bool forced = false)
        {
            bool flag = GenConstruct.FirstBlockingThing(t, p) != null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                LocalTargetInfo target    = t;
                PathEndMode     peMode    = PathEndMode.Touch;
                Danger          maxDanger = (!forced) ? p.NormalMaxDanger() : Danger.Deadly;
                bool            flag2     = !p.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced);
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    bool flag3 = t.IsBurning();
                    if (flag3)
                    {
                        result = false;
                    }
                    else
                    {
                        bool animal = p.RaceProps.Animal;
                        result = (!animal || true);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);
            Job   result;

            if (thing == null)
            {
                result = null;
            }
            else
            {
                if (thing.def.category == ThingCategory.Plant)
                {
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.ClosestTouch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.CutPlant, thing));
                    }
                }
                else if (thing.def.category == ThingCategory.Item)
                {
                    if (thing.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                    }
                    Log.ErrorOnce(string.Concat(new object[]
                    {
                        "Never haulable ",
                        thing,
                        " blocking ",
                        constructible.ToStringSafe <Thing>(),
                        " at ",
                        constructible.Position
                    }), 6429262, false);
                }
                else if (thing.def.category == ThingCategory.Building)
                {
                    if (worker.story != null && worker.story.WorkTypeIsDisabled(WorkTypeDefOf.Construction))
                    {
                        JobFailReason.Is(GenConstruct.IncapableOfDeconstruction, null);
                        return(null);
                    }
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.Touch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Deconstruct, thing)
                        {
                            ignoreDesignations = true
                        });
                    }
                }
                result = null;
            }
            return(result);
        }
Exemplo n.º 7
0
        public virtual bool TryReplaceWithSolidThing(Pawn workerPawn, out Thing createdThing, out bool jobEnded)
        {
            jobEnded = false;
            bool result;

            if (GenConstruct.FirstBlockingThing(this, workerPawn) != null)
            {
                workerPawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                jobEnded     = true;
                createdThing = null;
                result       = false;
            }
            else
            {
                createdThing = this.MakeSolidThing();
                Map      map      = base.Map;
                CellRect cellRect = this.OccupiedRect();
                GenSpawn.WipeExistingThings(base.Position, base.Rotation, createdThing.def, map, DestroyMode.Deconstruct);
                if (!base.Destroyed)
                {
                    this.Destroy(DestroyMode.Vanish);
                }
                createdThing.SetFactionDirect(workerPawn.Faction);
                GenSpawn.Spawn(createdThing, base.Position, map, base.Rotation, WipeMode.Vanish, false);
                Blueprint.tmpCrashedShipParts.Clear();
                CellRect.CellRectIterator iterator = cellRect.ExpandedBy(3).GetIterator();
                while (!iterator.Done())
                {
                    if (iterator.Current.InBounds(map))
                    {
                        List <Thing> thingList = iterator.Current.GetThingList(map);
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            CompSpawnerMechanoidsOnDamaged compSpawnerMechanoidsOnDamaged = thingList[i].TryGetComp <CompSpawnerMechanoidsOnDamaged>();
                            if (compSpawnerMechanoidsOnDamaged != null)
                            {
                                Blueprint.tmpCrashedShipParts.Add(compSpawnerMechanoidsOnDamaged);
                            }
                        }
                    }
                    iterator.MoveNext();
                }
                Blueprint.tmpCrashedShipParts.RemoveDuplicates <CompSpawnerMechanoidsOnDamaged>();
                for (int j = 0; j < Blueprint.tmpCrashedShipParts.Count; j++)
                {
                    Blueprint.tmpCrashedShipParts[j].Notify_BlueprintReplacedWithSolidThingNearby(workerPawn);
                }
                Blueprint.tmpCrashedShipParts.Clear();
                result = true;
            }
            return(result);
        }
Exemplo n.º 8
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Blueprint blueprint = t as Blueprint;

            if (blueprint == null)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced));
            }
            bool flag = def.workType == WorkTypeDefOf.Construction;

            if (!GenConstruct.CanConstruct(blueprint, pawn, flag, forced))
            {
                return(null);
            }
            if (!flag && WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint))
            {
                return(null);
            }
            Job job = RemoveExistingFloorJob(pawn, blueprint);

            if (job != null)
            {
                return(job);
            }
            Job job2 = ResourceDeliverJobFor(pawn, blueprint);

            if (job2 != null)
            {
                return(job2);
            }
            if (def.workType != WorkTypeDefOf.Hauling)
            {
                Job job3 = NoCostFrameMakeJobFor(pawn, blueprint);
                if (job3 != null)
                {
                    return(job3);
                }
            }
            return(null);
        }
Exemplo n.º 9
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Blueprint blueprint = t as Blueprint;

            if (blueprint == null)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced));
            }
            if (!GenConstruct.CanConstruct(blueprint, pawn, forced))
            {
                return(null);
            }
            Job job = base.RemoveExistingFloorJob(pawn, blueprint);

            if (job != null)
            {
                return(job);
            }
            Job job2 = base.ResourceDeliverJobFor(pawn, blueprint, true);

            if (job2 != null)
            {
                return(job2);
            }
            Job job3 = this.NoCostFrameMakeJobFor(pawn, blueprint);

            if (job3 != null)
            {
                return(job3);
            }
            return(null);
        }
Exemplo n.º 10
0
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);

            if (thing == null)
            {
                return(null);
            }
            if (thing.def.category == ThingCategory.Plant)
            {
                LocalTargetInfo target    = thing;
                PathEndMode     peMode    = PathEndMode.ClosestTouch;
                Danger          maxDanger = worker.NormalMaxDanger();
                if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                {
                    return(new Job(JobDefOf.CutPlant, thing));
                }
            }
            else if (thing.def.category == ThingCategory.Item)
            {
                if (thing.def.EverHaulable)
                {
                    return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                }
                Log.ErrorOnce("Never haulable " + thing + " blocking " + constructible.ToStringSafe() + " at " + constructible.Position, 6429262);
            }
            else if (thing.def.category == ThingCategory.Building)
            {
                LocalTargetInfo target    = thing;
                PathEndMode     peMode    = PathEndMode.Touch;
                Danger          maxDanger = worker.NormalMaxDanger();
                if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                {
                    Job job = new Job(JobDefOf.Deconstruct, thing);
                    job.ignoreDesignations = true;
                    return(job);
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Frame frame = t as Frame;

            if (frame == null)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(frame, pawn, forced));
            }
            if (!GenConstruct.CanConstruct(frame, pawn, forced))
            {
                return(null);
            }
            return(base.ResourceDeliverJobFor(pawn, frame, true));
        }
		public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
		{
			if (t.Faction != pawn.Faction)
			{
				return null;
			}
			Frame frame = t as Frame;
			if (frame == null)
			{
				return null;
			}
			if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
			{
				return GenConstruct.HandleBlockingThingJob(frame, pawn, forced);
			}
			bool checkConstructionSkill = def.workType == WorkTypeDefOf.Construction;
			if (!GenConstruct.CanConstruct(frame, pawn, checkConstructionSkill, forced))
			{
				return null;
			}
			return ResourceDeliverJobFor(pawn, frame);
		}
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.Faction != pawn.Faction)
            {
                result = null;
            }
            else
            {
                Frame frame = t as Frame;
                if (frame == null)
                {
                    result = null;
                }
                else if (frame.MaterialsNeeded().Count > 0)
                {
                    result = null;
                }
                else if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
                {
                    result = GenConstruct.HandleBlockingThingJob(frame, pawn, forced);
                }
                else
                {
                    Frame t2 = frame;
                    if (!GenConstruct.CanConstruct(t2, pawn, true, forced))
                    {
                        result = null;
                    }
                    else
                    {
                        result = new Job(JobDefOf.FinishFrame, frame);
                    }
                }
            }
            return(result);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.Faction != pawn.Faction)
            {
                result = null;
            }
            else
            {
                Blueprint blueprint = t as Blueprint;
                if (blueprint == null)
                {
                    result = null;
                }
                else if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null)
                {
                    result = GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced);
                }
                else
                {
                    bool flag = this.def.workType == WorkTypeDefOf.Construction;
                    if (!GenConstruct.CanConstruct(blueprint, pawn, flag, forced))
                    {
                        result = null;
                    }
                    else if (!flag && WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint))
                    {
                        result = null;
                    }
                    else
                    {
                        Job job = base.RemoveExistingFloorJob(pawn, blueprint);
                        if (job != null)
                        {
                            result = job;
                        }
                        else
                        {
                            Job job2 = base.ResourceDeliverJobFor(pawn, blueprint, true);
                            if (job2 != null)
                            {
                                result = job2;
                            }
                            else
                            {
                                Job job3 = this.NoCostFrameMakeJobFor(pawn, blueprint);
                                if (job3 != null)
                                {
                                    result = job3;
                                }
                                else
                                {
                                    result = null;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }