Skip to content

Commit

Permalink
Make payload blocks run onDestroyed() of the block payload it carri…
Browse files Browse the repository at this point in the history
…es when destroyed. (#8253)

* Payloads go boom.

* When a payload unit dies too

* Keep the functionality, but limit it to a rule
  • Loading branch information
MEEPofFaith authored Mar 29, 2024
1 parent 520c423 commit d8c1ea1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ rules.unitdamagemultiplier = Unit Damage Multiplier
rules.unitcrashdamagemultiplier = Unit Crash Damage Multiplier
rules.solarmultiplier = Solar Power Multiplier
rules.unitcapvariable = Cores Contribute To Unit Cap
rules.unitpayloadsexplode = Carried Payloads Explode With The Unit
rules.unitcap = Base Unit Cap
rules.limitarea = Limit Map Area
rules.enemycorebuildradius = Enemy Core No-Build Radius:[lightgray] (tiles)
Expand Down
5 changes: 5 additions & 0 deletions core/src/mindustry/entities/comp/PayloadComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public void update(){
}
}

@Override
public void destroy(){
if(Vars.state.rules.unitPayloadsExplode) payloads.each(Payload::destroyed);
}

float payloadUsed(){
return payloads.sumf(p -> p.size() * p.size());
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/mindustry/game/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class Rules{
public boolean unitAmmo = false;
/** EXPERIMENTAL! If true, blocks will update in units and share power. */
public boolean unitPayloadUpdate = false;
/** If true, units' payloads are destroy()ed when the unit is destroyed. */
public boolean unitPayloadsExplode = false;
/** Whether cores add to unit limit */
public boolean unitCapVariable = true;
/** If true, unit spawn points are shown. */
Expand Down
1 change: 1 addition & 0 deletions core/src/mindustry/ui/dialogs/CustomRulesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void setup(){

title("@rules.title.unit");
check("@rules.unitcapvariable", b -> rules.unitCapVariable = b, () -> rules.unitCapVariable);
check("@rules.unitpayloadsexplode", b -> rules.unitPayloadsExplode = b, () -> rules.unitPayloadsExplode);
numberi("@rules.unitcap", f -> rules.unitCap = f, () -> rules.unitCap, -999, 999);
number("@rules.unitdamagemultiplier", f -> rules.unitDamageMultiplier = f, () -> rules.unitDamageMultiplier);
number("@rules.unitcrashdamagemultiplier", f -> rules.unitCrashDamageMultiplier = f, () -> rules.unitCrashDamageMultiplier);
Expand Down
5 changes: 5 additions & 0 deletions core/src/mindustry/world/blocks/payloads/BuildPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void update(@Nullable Unit unitHolder, @Nullable Building buildingHolder)
build.updatePayload(unitHolder, buildingHolder);
}

@Override
public void destroyed(){
build.onDestroyed();
}

@Override
public ItemStack[] requirements(){
return build.block.requirements;
Expand Down
2 changes: 2 additions & 0 deletions core/src/mindustry/world/blocks/payloads/Payload.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ default float rotation(){
return 0f;
}

default void destroyed(){};

/** writes the payload for saving. */
void write(Writes write);

Expand Down
6 changes: 6 additions & 0 deletions core/src/mindustry/world/blocks/payloads/PayloadBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public void updateTile(){
}
}

@Override
public void onDestroyed(){
if(payload != null) payload.destroyed();
super.onDestroyed();
}

public boolean blends(int direction){
return PayloadBlock.blends(this, direction);
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/mindustry/world/blocks/payloads/PayloadConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public void drawBottom(){
super.draw();
}

@Override
public void onDestroyed(){
if(item != null) item.destroyed();
super.onDestroyed();
}

@Override
public void draw(){
super.draw();
Expand Down

0 comments on commit d8c1ea1

Please sign in to comment.