예제 #1
0
        public override void CompTick()
        {
            base.CompTick();

            //Tools.Warn(" >>>TICK begin<<< ", prcDebug);
            Tools.Warn(" >>>TICK begin tp:" + Registry.Count + "<<< ");
            if (HasSpot)
            {
                if (Tools.TwoTicksOneTrue())
                {
                    //foreach(Building cur in Registry)
                    for (int i = Registry.Count - 1; i >= 0; i--)
                    {
                        Building cur = Registry[i];
                        if ((!ToolsBuilding.CheckBuilding(cur)) || (!ToolsBuilding.CheckPower(cur)) || !InRangeSpot(cur))
                        {
                            Comp_LTF_TpSpot comp_LTF_TpSpot = cur?.TryGetComp <Comp_LTF_TpSpot>();
                            if (comp_LTF_TpSpot != null)
                            {
                                comp_LTF_TpSpot.ResetFacility();
                            }
                            RemoveSpot(cur);
                        }
                    }
                }
                IndexCorrecter();
            }


            // Tools.Warn(" >>>TICK end<<< ", prcDebug);
            Tools.Warn(" >>>TICK end " + Registry.Count + "<<< ");
        }
예제 #2
0
        private float Bench2SpotDistance(Building spot)
        {
            float Answer = 999f;

            if (!ToolsBuilding.CheckBuilding(spot))
            {
                return(Answer);
            }

            Answer = building.Position.DistanceTo(spot.Position);
            return(Answer);
        }
예제 #3
0
        //Facility required

        /*
         * public static Building GetPoweredFacility(Building building, Building facility, CompAffectedByFacilities buildingFacilityComp= null, CompPowerTrader facilityPowerComp = null, bool debug = false)
         * {
         *  Building Answer = null;
         *
         *  //Building - needed to find other things
         *  if (!ToolsBuilding.CheckBuilding(building))
         *  {
         *      Tools.Warn("bad building, wont check facility", debug);
         *      return null;
         *  }
         *
         *  if(buildingFacilityComp == null)
         *      buildingFacilityComp = ToolsBuilding.GetAffectedComp(building, debug);
         *
         *  if (facility == null)
         *      ToolsBuilding.GetFacility(buildingFacilityComp, debug);
         *
         *  if (!ToolsBuilding.CheckBuilding((facility))
         *  {
         *      Tools.Warn(" give facility is not ok, getting one", debug);
         *
         *      Building newFacility = thing as Building;
         *      return null;
         *  }
         *
         *
         *
         *  if (facilityPowerComp != null)
         *  {
         *
         *  }
         *  else
         *  {
         *      if (!CheckPower(facility))
         *      {
         *          if (debug)
         *              Log.Warning("facility has no power");
         *      }
         *  }
         *
         *
         *  Answer = facility;
         *  return Answer;
         * }
         */
        public static bool TickCheckFacilityPower(Building facility, CompPowerTrader powerComp = null, bool debug = false)
        {
            bool Answer = true;

            //ToolsBuilding.CheckBuildingBelongsFacility(buildingFacilityComp, facility, debug);
            Tools.Warn("tick check facility", debug);

            //Valid
            Answer &= ToolsBuilding.CheckBuilding(facility);

            //power
            Answer &= ((powerComp == null) ? (ToolsBuilding.CheckPower(facility)):(ToolsBuilding.CheckPower(powerComp)));

            Tools.WarnRare("no powered facility", 300, debug);

            return(Answer);
        }
예제 #4
0
        public static bool CheckBuildingBelongsFacility(CompAffectedByFacilities buildingFacilityComp, Building facility, bool debug = false)
        {
            if (!ToolsBuilding.CheckBuilding(facility))
            {
                Tools.Warn("null facility", debug);
                return(false);
            }
            if (buildingFacilityComp == null)
            {
                Tools.Warn("null facility comp", debug);
                return(false);
            }

            //Building.CompFacility legit
            if (buildingFacilityComp.LinkedFacilitiesListForReading.NullOrEmpty())
            {
                Tools.Warn("no linked facility found", debug);
                return(false);
            }
            Tools.Warn("Found: " + buildingFacilityComp.LinkedFacilitiesListForReading.Count + " facilities", debug);

            Thing thing = null;

            thing = buildingFacilityComp.LinkedFacilitiesListForReading.RandomElement();
            if (thing == null)
            {
                // will happen on load
                Tools.Warn("no facility found; ok on load", debug);
                return(false);
            }

            Building maybeFacility = thing as Building;

            if (maybeFacility != facility)
            {
                Tools.Warn("Found " + maybeFacility.ThingID + ", but it's not " + facility.ThingID, debug);
                return(false);
            }

            return(true);
        }
        public override void DoEffectOn(Pawn user, Thing target)
        {
            //Tools.Warn(">>> DoEffectOn  <<<", true);

            Building tpSpot1 = (Building)target;
            Building tpSpot2 = user.CurJob.targetA.Thing as Building;

            // check building
            if (!ToolsBuilding.CheckBuilding(tpSpot1) || !ToolsBuilding.CheckBuilding(tpSpot2))
            {
                Tools.Warn("//Null spot", true);
                return;
            }

            // comp validity
            string Spot1Valid = Comp_LTF_TpSpot.ValidTpSpot(tpSpot1);

            if (!Spot1Valid.NullOrEmpty())
            {
                Messages.Message(Spot1Valid, this.parent, MessageTypeDefOf.TaskCompletion);
                return;
            }
            string Spot2Valid = Comp_LTF_TpSpot.ValidTpSpot(tpSpot2);

            if (!Spot2Valid.NullOrEmpty())
            {
                Messages.Message(Spot2Valid, this.parent, MessageTypeDefOf.TaskCompletion);
                return;
            }

            // both catchers
            //if (tpSpot1.def.defName == "LTF_TpCatcher" && tpSpot2.def.defName == "LTF_TpCatcher")
            // At least 1 tpspot
            if (!Comp_LTF_TpSpot.AtLeastOneTpSpot(tpSpot1, tpSpot2))
            {
                Messages.Message("At least one of the two spots must be powered.", this.parent, MessageTypeDefOf.TaskCompletion);
                return;
            }
            // targeting itself
            if (tpSpot1 == tpSpot2)
            {
                Messages.Message(tpSpot1.Label + " can not target itself", this.parent, MessageTypeDefOf.TaskCompletion);
                return;
            }

            // comp !null
            Comp_LTF_TpSpot spot1Comp = tpSpot1.TryGetComp <Comp_LTF_TpSpot>();
            Comp_LTF_TpSpot spot2Comp = tpSpot2.TryGetComp <Comp_LTF_TpSpot>();

            if ((spot1Comp == null) || (spot2Comp == null))
            {
                Tools.Warn("// Not comp", true);
                return;
            }
            Tools.Warn("Trying to register: " + tpSpot2.Label + " in " + tpSpot1.Label, spot1Comp.prcDebug);

            // tp spot without powered facility
            //if ((spot1Comp.requiresPower) && (!spot1Comp.HasPoweredFacility))

            /*
             * if ((spot1Comp.requiresPower) && (!spot1Comp.HasPoweredFacility))
             * {
             *  Messages.Message(tpSpot1.Label + " requires a powered facility to be linked", this.parent, MessageTypeDefOf.TaskCompletion);
             *  return;
             * }
             */

            float distance  = tpSpot1.Position.DistanceTo(tpSpot2.Position);
            float bestRange = ToolsBuilding.TheoricBestRange(spot1Comp, spot2Comp);

            Tools.Warn("dist:" + distance + " ; range:" + bestRange, spot1Comp.prcDebug);
            if (distance > bestRange)
            {
                Messages.Message(tpSpot2.Label + " is out of range (distance : " + distance + ", max : " + bestRange + ")", this.parent, MessageTypeDefOf.TaskCompletion);
                return;
            }

            bool didSomething = spot1Comp.CreateLink(tpSpot2, spot2Comp);

            Messages.Message(
                Tools.OkStr(didSomething) + ' ' +
                tpSpot1.Label + spot1Comp.MyCoordinates +
                " was " + ((didSomething) ? ("") : ("not ")) + "linked to " +
                tpSpot2.Label + spot2Comp.MyCoordinates
                , this.parent, MessageTypeDefOf.TaskCompletion);

            Tools.Warn(Tools.OkStr(didSomething) + "registered: " + tpSpot2.Label + " in " + tpSpot1.Label, spot1Comp.prcDebug);
        }