Beispiel #1
0
        public static VehiclePawn GenerateVehicle(VehicleGenerationRequest request)
        {
            VehiclePawn result = null;

            try
            {
                result = GenerateVehicleInternal(request);
            }
            catch (Exception ex)
            {
                Log.Error($"Error thrown while generating VehiclePawn {request.VehicleDef.LabelCap} Exception: {ex.Message}");
            }
            return(result);
        }
Beispiel #2
0
        private static VehiclePawn GenerateVehicleInternal(VehicleGenerationRequest request)
        {
            VehiclePawn result = (VehiclePawn)ThingMaker.MakeThing(request.VehicleDef);

            PawnComponentsUtility.CreateInitialComponents(result);

            result.kindDef = request.VehicleDef.VehicleKindDef;
            result.SetFactionDirect(request.Faction);

            string     defaultMask = VehicleMod.settings.vehicles.defaultMasks.TryGetValue(result.VehicleDef.defName, "Default");
            PatternDef pattern     = DefDatabase <PatternDef> .GetNamed(defaultMask);

            if (pattern is null)
            {
                Log.Error($"Unable to retrieve saved default pattern {defaultMask}. Defaulting to original Default mask.");
                pattern = PatternDefOf.Default;
            }

            result.pattern = request.RandomizeMask ? result.VehicleGraphic.maskMatPatterns.RandomElement().Key : pattern;
            if (result.VehicleGraphic.MatSingle.shader.SupportsRGBMaskTex())
            {
                result.DrawColor      = request.ColorOne;
                result.DrawColorTwo   = request.ColorTwo;
                result.DrawColorThree = request.ColorThree;
            }

            result.PostGenerationSetup();
            foreach (VehicleComp comp in result.AllComps.Where(c => c is VehicleComp))
            {
                comp.PostGenerationSetup();
            }

            //REDO - Allow other modders to add setup for non clean-slate items
            if (!request.CleanSlate)
            {
                UpgradeAtRandom(result, request.Upgrades);
                DistributeAmmunition(result);
            }

            float num = Rand.ByCurve(DefaultAgeGenerationCurve);

            result.ageTracker.AgeBiologicalTicks = (long)(num * BiologicalAgeTicksMultiplier) + Rand.Range(0, 3600000);
            result.needs.SetInitialLevels();
            if (Find.Scenario != null)
            {
                Find.Scenario.Notify_NewPawnGenerating(result, PawnGenerationContext.NonPlayer);
            }
            return(result);
        }