Skip to content

IConfigurableVehicle

Kye edited this page Sep 19, 2022 · 1 revision

IConfigurableVehicle

The IConfigurableVehicle is an Interface implementation. It allows you to make your Vehicle Settings Overridable to allow either:

  • Other Modders
  • Server Owners

To customize all aspects of your vehicles capabilities such as max weight, inventory slots and more.

The implementation of the IConfigurableVehicle can be used on Any Vehicle, Human Powered or Fuel Powered.

Below is the Implementation of the IConfigurableVehicle:


Implementation


The implementation uses a specific data structure and is setup in a specific way for it to be able to work.

Working with the implementation will be confusing to start with as it is not a normal implementation of the vehicle settings.

public static VehicleModel defaults = new(
    typeof(VehicleObject),
    fuelTagList        :fuelTagList,
    fuelSlots          :2,
    fuelConsumption    :25,
    airPollution       :0.5f,
    maxSpeed           :20,
    efficencyMultiplier:2,
    storageSlots       :36,
    maxWeight          :8000000,
    seats              : 1
);

Here is each component broken down and explained:


typeof(Object)

This is The item you are connecting the Resolver too.


fuelTagList

This is a basic Array of strings using Tags to say what kind of fuel the vehicle uses, if it is human powered just set this too null.

Fuel Tag List is not editable at this time


fuelSlots

This is the total amount of fuel slots the vehicle has, if human powered just set this to 0


fuelConsumption

This is the rate at which your vehicle consumes fuel, if human powered just set this to 0


airPollution

This is how much pollution the vehicle will emit on use, if human powered just set this to 0


maxSpeed

This is the maximum speed at the vehicle can travel


efficencyMultiplier (spelling error i know >.<)

Efficiency Multiplier is affected by the road type the vehicle is travelling on


storageSlots

This is how many storage slots the vehicle has, this does not require the IStorageSlotObject as it is included in this resolver as its own thing

*This Resolver can't be used on a storage object only vehicles


maxWeight

This is the maximum weight the vehicle can hold,

Do not set this to int.MaxValue as it will throw errors


seats

This is the amount of seats the vehicle has

This needs to be used with care as adding more seats then the vehicle has mounting points can cause big issues


Setting It Up


These are the values that are required when using this on the Your Vehicles.

Anything Marked with an Asterixis (//*) is Required (Attributes Not Included)


Using on a Vehicle with Fuel

    public partial class NewTruckObject : PhysicsWorldObject, IRepresentsItem, IConfigurableVehicle
    {
        public override LocString DisplayName => Localizer.DoStr("New Truck");
        public Type RepresentedItemType => typeof(NewTruckItem);

        public static VehicleModel defaults = new(
            typeof(NewTruckObject),
            fuelTagList        :fuelTagList,
            fuelSlots          :2,
            fuelConsumption    :25,
            airPollution       :0.5f,
            maxSpeed           :20,
            efficencyMultiplier:2,
            storageSlots       :36,
            maxWeight          :8000000,
            seats              : 2
        );

        static NewTruckObject()
        {
            WorldObject.AddOccupancy<NewTruckObject>(new List<BlockOccupancy>(0));
            EMVehicleResolver.AddDefaults(defaults);
        }

        private static readonly string[] fuelTagList = new string[]
        {
            "Liquid Fuel"
        };

        private NewTruckObject() { }

        protected override void Initialize()
        {
            base.Initialize();
            
            this.GetComponent<PublicStorageComponent>().Initialize(EMVehicleResolver.Obj.ResolveStorageSlots(this), EMVehicleResolver.Obj.ResolveMaxWeight(this));           
            this.GetComponent<FuelSupplyComponent>().Initialize(EMVehicleResolver.Obj.ResolveFuelSlots(this), EMVehicleResolver.Obj.ResolveFuelTagList(this));           
            this.GetComponent<FuelConsumptionComponent>().Initialize(EMVehicleResolver.Obj.ResolveFuelConsumption(this));    
            this.GetComponent<AirPollutionComponent>().Initialize(EMVehicleResolver.Obj.ResolveAirPollution(this));            
            this.GetComponent<VehicleComponent>().Initialize(EMVehicleResolver.Obj.ResolveMaxSpeed(this), EMVehicleResolver.Obj.ResolveEfficiencyMultiplier(this), EMVehicleResolver.Obj.ResolveSeats(this));
            this.GetComponent<StockpileComponent>().Initialize(new Vector3i(2,2,3));  
        }
    }

Using on a Human Powered Vehicle

public partial class NewWoodCartObject : PhysicsWorldObject, IRepresentsItem, IConfigurableVehicle
    {
        public override LocString DisplayName => Localizer.DoStr("New Wood Cart");
        public Type RepresentedItemType => typeof(NewWoodCartItem);

        public static VehicleModel defaults = new(
            typeof(NewWoodCartObject),
            fuelTagList        : null,
            fuelSlots          : 0,
            fuelConsumption    : 0,
            airPollution       : 0,
            maxSpeed           : 12,
            efficencyMultiplier: 1,
            storageSlots       : 12,
            maxWeight          : 2100000
        );

        static NewWoodCartObject()
        {
            WorldObject.AddOccupancy<NewWoodCartObject>(new List<BlockOccupancy>(0));
            EMVehicleResolver.AddDefaults(defaults);
        }

        private NewWoodCartObject() { }

        protected override void Initialize()
        {
            base.Initialize();

            this.GetComponent<PublicStorageComponent>().Initialize(EMVehicleResolver.Obj.ResolveStorageSlots(this), EMVehicleResolver.Obj.ResolveMaxWeight(this));    
            this.GetComponent<VehicleComponent>().Initialize(EMVehicleResolver.Obj.ResolveMaxSpeed(this), EMVehicleResolver.Obj.ResolveEfficiencyMultiplier(this), EMVehicleResolver.Obj.ResolveSeats(this));
            this.GetComponent<VehicleComponent>().HumanPowered(1);           
            this.GetComponent<StockpileComponent>().Initialize(new Vector3i(2,1,2));        
        }
    }

And thats it! you can now override your Vehicles with other mods and the EM Configure Plugin (Built In)

This doesn't support vehicles being able to drive underwater yet

For a Good Example of this implementation have a look at the EM Version Of The Colored Vehicles Mod

Clone this wiki locally