From 79695086c622a9171f738ee7d4f9d5502f948d70 Mon Sep 17 00:00:00 2001 From: NiChrosia Date: Sun, 6 Jun 2021 18:37:20 -0500 Subject: [PATCH] Add powerDynamic to Consumers (#5205) * Add DynamicConsumePower, and powerDynamic to Consumers * Add period to description of DynamicConsumePower Co-authored-by: Patrick 'Quezler' Mounier * Remove redundant Boolf Co-authored-by: Patrick 'Quezler' Mounier --- .../blocks/power/DynamicConsumePower.java | 20 +++++++++++++++++++ .../mindustry/world/consumers/Consumers.java | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 core/src/mindustry/world/blocks/power/DynamicConsumePower.java diff --git a/core/src/mindustry/world/blocks/power/DynamicConsumePower.java b/core/src/mindustry/world/blocks/power/DynamicConsumePower.java new file mode 100644 index 0000000000..c020f80d19 --- /dev/null +++ b/core/src/mindustry/world/blocks/power/DynamicConsumePower.java @@ -0,0 +1,20 @@ +package mindustry.world.blocks.power; + +import arc.func.*; +import mindustry.gen.*; +import mindustry.world.consumers.*; + +/** A power consumer that uses a dynamic amount of power. */ +public class DynamicConsumePower extends ConsumePower{ + private final Floatf usage; + + public DynamicConsumePower(Floatf usage){ + super(0, 0, false); + this.usage = usage; + } + + @Override + public float requestedPower(Building entity){ + return usage.get(entity); + } +} diff --git a/core/src/mindustry/world/consumers/Consumers.java b/core/src/mindustry/world/consumers/Consumers.java index 73ad0b0b96..0b64e3d78f 100644 --- a/core/src/mindustry/world/consumers/Consumers.java +++ b/core/src/mindustry/world/consumers/Consumers.java @@ -68,6 +68,11 @@ public class Consumers{ return add(new ConditionalConsumePower(usage, (Boolf)cons)); } + /** Creates a consumer that consumes a dynamic amount of power. */ + public ConsumePower powerDynamic(Floatf usage){ + return add(new DynamicConsumePower((Floatf)usage)); + } + /** * Creates a consumer which stores power. * @param powerCapacity The maximum capacity in power units.