LuaEquipmentGrid reduce battery energy evenly

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

LuaEquipmentGrid reduce battery energy evenly

Post by sparr »

I would like to consume some of the power in the player's batteries. The built-in equipment all draws evenly from the batteries. I can't find a way to do that. I am loathe to loop through every LuaEquipment in the grid and reduce the energy one at a time, for both speed and unevenness reasons.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Ranakastrasz »

Consuming energy directly? No vanilla equipment does that, it draws from a consumer type equipment.


That said, I think you can get the total power stored from the grid and then loop through all of the modules to remove the proportional fraction



That said, this would be somewhat useful.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by sparr »

Ranakastrasz wrote:Consuming energy directly? No vanilla equipment does that, it draws from a consumer type equipment.
That's the behavior I want to mimic.

Ranakastrasz wrote:That said, I think you can get the total power stored from the grid and then loop through all of the modules to remove the proportional fraction
Yeah, I went with an even lazier option and just removed from the first batteries for now.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Ranakastrasz »

If you want to mimic that behavior, use a dummy consumer and get power from it alone.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by sparr »

Do you have an example of a mod with a dummy consumer? For equipment, not entities.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Ranakastrasz »

Well, not directly, but you could use one of several things.

The main issue is that you probably can't make the tooltip show the power consumption.

Laser turret Equipment. Set range to zero, power consumption to *Lots*, cooldown to *Lots*, etc.
Battery Equipment. Set priority to... Uhm, Primary? I think?. Whatever shields and legs use anyway.
Legs. Set speed boost to 0, power consumption to zero. Otherwise it would use energy if you move, or give you +speed.
Discharge Equipment. Actually, given that that requires an action to activate, it might be the best case. Just don't add a trigger item thinggy.
Night vision, might have unwanted behavior, don't use.

Shields probably have unwanted behavior, but I am unsure. You might be able to set capacity to zero, and then still have it display a power consumption amount. That is probably the best choice.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Nexela »

Nanobots in the scripts/armormods.lua has some examples that might interest you.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by sparr »

I don't understand how I would trigger any of those entity types to use power when I want them to.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Ranakastrasz »

....

OnTick, get the equipment grid. Loop through till you find equipment of matching type. Check for enough power for that tick. (60 ticks/second).
Remove that much power if it is available, do your effect. Else, do nothing.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by sparr »

But then the equipment would hold energy when it's not being used, like a roboport or a battery. I don't want that. I want it to just consume electricity directly from the batteries, like the laser defense does.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: LuaEquipmentGrid reduce battery energy evenly

Post by Ranakastrasz »

The laser defence does not consume energy directly from the batteries, it stores energy until it has enough energy and a target, then discharges it all for a laser blast. It holds enough for like 3 shots, or a single second of firing. As such, just leave the capacity very low.

Even the frikkin Night vision goggles store enough power for like 12 seconds of operation.

Code: Select all

    energy_source =
    {
      type = "electric",
      buffer_capacity = "120kJ",
      input_flow_limit = "240kW",
      usage_priority = "primary-input"
    },
    energy_input = "10kW",
Night vision consumes 10 kW, or 10 kJ/seconds, and stores 120 kJ. It fully charges in half a second as well.

Code: Select all

 energy_source =
    {
      type = "electric",
      usage_priority = "secondary-input",
      buffer_capacity = "220kJ"
    },
    attack_parameters =
    {
      type = "projectile",
      ammo_category = "electric",
      cooldown = 20,
      damage_modifier = 15,
      projectile_center = {0, 0},
      projectile_creation_distance = 0.6,
      range = 15,
      sound = make_laser_sounds(),
      ammo_type =
      {
        type = "projectile",
        category = "electric",
        energy_consumption = "200kJ",
        projectile = "laser",
        speed = 1,
        action =
        {
          {
            type = "direct",
            action_delivery =
            {
              {
                type = "projectile",
                projectile = "laser",
                starting_speed = 0.28
              }
            }
          }
        }
      }
    },
The Laser turret consumes 200 kJ per shot, and holds 220 kJ. It charges at a rate of.... Yes.
Apperently it has no throttle on how fast it charges, presumably to support attack speed upgrades.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

Post Reply

Return to “Modding interface requests”