Build cost/speed rules
This commit is contained in:
@@ -234,9 +234,9 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
||||
if(!Net.client()){
|
||||
//deconstructing is 2x as fast
|
||||
if(current.breaking){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile));
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}else{
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile));
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}
|
||||
|
||||
current.progress = entity.progress();
|
||||
|
||||
@@ -25,6 +25,8 @@ public enum RulePreset{
|
||||
pvp = true;
|
||||
enemyCoreBuildRadius = 600f;
|
||||
respawnTime = 60 * 10;
|
||||
buildCostMultiplier = 0.5f;
|
||||
buildSpeedMultiplier = 2f;
|
||||
}});
|
||||
|
||||
private final Supplier<Rules> rules;
|
||||
|
||||
@@ -19,6 +19,10 @@ public class Rules{
|
||||
public boolean pvp;
|
||||
/**Whether enemy units drop random items on death.*/
|
||||
public boolean unitDrops;
|
||||
/**Multiplier for buildings for the player.*/
|
||||
public float buildCostMultiplier = 1f;
|
||||
/**Multiplier for building speed.*/
|
||||
public float buildSpeedMultiplier = 1f;
|
||||
/**No-build zone around enemy core radius.*/
|
||||
public float enemyCoreBuildRadius = 400f;
|
||||
/**Player respawn time in ticks.*/
|
||||
|
||||
@@ -15,6 +15,10 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
|
||||
public CustomRulesDialog(){
|
||||
super("$mode.custom");
|
||||
|
||||
rules.waves = true;
|
||||
rules.waveTimer = true;
|
||||
|
||||
setFillParent(true);
|
||||
shown(this::setup);
|
||||
addCloseButton();
|
||||
@@ -31,12 +35,14 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
main.row();
|
||||
main.addCheck("$rules.wavetimer", b -> rules.waveTimer = b).checked(b -> rules.waveTimer);
|
||||
main.row();
|
||||
main.addCheck("$rules.waves", b -> rules.waves = b).checked(b -> rules.waves);
|
||||
main.addCheck("$rules.waves", b -> rules.waves = b).checked(b -> rules.waves).disabled(b -> rules.pvp);
|
||||
main.row();
|
||||
main.addCheck("$rules.pvp", b -> rules.pvp = b).checked(b -> rules.pvp);
|
||||
main.addCheck("$rules.pvp", b -> rules.pvp = b).checked(b -> rules.pvp).disabled(b -> rules.waves);
|
||||
main.row();
|
||||
main.addCheck("$rules.unitdrops", b -> rules.unitDrops = b).checked(b -> rules.unitDrops);
|
||||
main.row();
|
||||
number("$rules.buildcostmultiplier", f -> rules.buildCostMultiplier = f, () -> rules.buildCostMultiplier);
|
||||
number("$rules.buildspeedmultiplier", f -> rules.buildSpeedMultiplier = f, () -> rules.buildSpeedMultiplier);
|
||||
number("$rules.enemycorebuildradius", f -> rules.enemyCoreBuildRadius = f*tilesize, () -> Math.min(rules.enemyCoreBuildRadius/tilesize, 200));
|
||||
number("$rules.respawntime", f -> rules.respawnTime = f*60f, () -> rules.respawnTime/60f);
|
||||
number("$rules.wavespacing", f -> rules.waveSpacing = f*60f, () -> rules.waveSpacing/60f);
|
||||
@@ -46,7 +52,7 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
main.table(t -> {
|
||||
t.left();
|
||||
t.add(text).left().padRight(5);
|
||||
Platform.instance.addDialog(t.addField((int)prov.get() + "", s -> cons.accept(Strings.parseFloat(s)))
|
||||
Platform.instance.addDialog(t.addField(prov.get() + "", s -> cons.accept(Strings.parseFloat(s)))
|
||||
.valid(Strings::canParsePositiveFloat).width(120f).left().get());
|
||||
});
|
||||
|
||||
|
||||
@@ -215,9 +215,10 @@ public class PlacementFragment extends Fragment{
|
||||
if(core == null || state.rules.infiniteResources) return "*/*";
|
||||
|
||||
int amount = core.items.get(stack.item);
|
||||
String color = (amount < stack.amount / 2f ? "[red]" : amount < stack.amount ? "[accent]" : "[white]");
|
||||
int stackamount = Math.round(stack.amount * state.rules.buildCostMultiplier);
|
||||
String color = (amount < stackamount / 2f ? "[red]" : amount < stackamount ? "[accent]" : "[white]");
|
||||
|
||||
return color + ui.formatAmount(amount) + "[white]/" + stack.amount;
|
||||
return color + ui.formatAmount(amount) + "[white]/" + stackamount;
|
||||
}).padLeft(5);
|
||||
}).left();
|
||||
req.row();
|
||||
|
||||
@@ -197,8 +197,9 @@ public class BuildBlock extends Block{
|
||||
float maxProgress = checkRequired(core.items, amount, false);
|
||||
|
||||
for(int i = 0; i < block.buildRequirements.length; i++){
|
||||
accumulator[i] += Math.min(block.buildRequirements[i].amount * maxProgress, block.buildRequirements[i].amount - totalAccumulator[i] + 0.00001f); //add min amount progressed to the accumulator
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + block.buildRequirements[i].amount * maxProgress, block.buildRequirements[i].amount);
|
||||
int reqamount = Math.round(state.rules.buildCostMultiplier * block.buildRequirements[i].amount);
|
||||
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001f); //add min amount progressed to the accumulator
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
|
||||
}
|
||||
|
||||
maxProgress = checkRequired(core.items, maxProgress, true);
|
||||
@@ -215,6 +216,7 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
public void deconstruct(Unit builder, TileEntity core, float amount){
|
||||
float deconstructMultiplier = 0.5f;
|
||||
|
||||
if(block != null){
|
||||
ItemStack[] requirements = block.buildRequirements;
|
||||
@@ -223,8 +225,9 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
for(int i = 0; i < requirements.length; i++){
|
||||
accumulator[i] += Math.min(requirements[i].amount * amount / 2f, requirements[i].amount / 2f - totalAccumulator[i]); //add scaled amount progressed to the accumulator
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + requirements[i].amount * amount / 2f, requirements[i].amount);
|
||||
int reqamount = Math.round(state.rules.buildCostMultiplier * requirements[i].amount);
|
||||
accumulator[i] += Math.min(amount * deconstructMultiplier * reqamount, deconstructMultiplier * reqamount - totalAccumulator[i]); //add scaled amount progressed to the accumulator
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * amount * deconstructMultiplier, reqamount);
|
||||
|
||||
int accumulated = (int)(accumulator[i]); //get amount
|
||||
|
||||
@@ -248,9 +251,10 @@ public class BuildBlock extends Block{
|
||||
float maxProgress = amount;
|
||||
|
||||
for(int i = 0; i < block.buildRequirements.length; i++){
|
||||
int sclamount = Math.round(state.rules.buildCostMultiplier * block.buildRequirements[i].amount);
|
||||
int required = (int) (accumulator[i]); //calculate items that are required now
|
||||
|
||||
if(inventory.get(block.buildRequirements[i].item) == 0){
|
||||
if(inventory.get(block.buildRequirements[i].item) == 0 && sclamount != 0){
|
||||
maxProgress = 0f;
|
||||
}else if(required > 0){ //if this amount is positive...
|
||||
//calculate how many items it can actually use
|
||||
|
||||
Reference in New Issue
Block a user