Skip to content

Commit

Permalink
Feat add config for cores to set preferred respawn point
Browse files Browse the repository at this point in the history
  • Loading branch information
zxtej committed Jan 3, 2025
1 parent 4a6d199 commit f896154
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ client.attemwarn = [scarlet]Attem placed by {0}[scarlet] at ({1}, {2})
client.nojava = It seems that you don't have java installed, please click the button below then click the "latest LTS release" button on the website.\nClosing this dialog will close the game.
client.installjava = Install Java
client.autotransfer = Auto Transfer
client.preferredcore = Set preferred respawn core to {0}

# CLaJ related
client.claj.join = Join via CLaJ
Expand Down
9 changes: 8 additions & 1 deletion core/src/mindustry/entities/comp/PlayerComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ public boolean isBuilder(){
/** @return largest/closest core, with largest cores getting priority */
@Nullable
public CoreBuild bestCore(){
return team.cores().min(Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y))));
if(self() != Vars.player){
return team.cores().min(Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y))));
} else {
return team.cores().min(Structs.comps(
Structs.comparingBool(c -> (CoreBlock)c.block != ((CoreBlock)c.block).preferredCoreType),
Structs.comps(Structs.comparingInt(c -> -c.block.size), Structs.comparingFloat(c -> c.dst(x, y)))
));
}
}

public TextureRegion icon(){
Expand Down
16 changes: 15 additions & 1 deletion core/src/mindustry/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,21 @@ else if (selectPlans.isEmpty()){ // SHIFT + Z to view lastSentPos, double tap to
if(Core.input.keyTap(Binding.respawn) && !scene.hasDialog()){
controlledType = null;
recentRespawnTimer = 1f;
Call.unitClear(player);
var u = player.unit();
var closest = player.bestCore();
if(CoreBlock.preferredCoreType == null ||
(!u.spawnedByCore &&
((u.dockedType != null && u.dockedType.coreUnitDock) ||
(closest != null && ((CoreBlock)closest.block).unitType != null &&
((CoreBlock)closest.block).unitType.coreUnitDock))
)
){
// Use original spawning mechanism for docking units
Call.unitClear(player);
} else {
// Send a packet that supports respawning at a specific block
Call.buildingControlSelect(player, closest);
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions core/src/mindustry/world/blocks/storage/CoreBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import static mindustry.Vars.*;
import static mindustry.client.ClientVars.coreItemsDisplay;

import org.jetbrains.annotations.Nullable;

public class CoreBlock extends StorageBlock{
//hacky way to pass item modules between methods
private static ItemModule nextItems;
Expand All @@ -46,6 +48,8 @@ public class CoreBlock extends StorageBlock{

public float captureInvicibility = 60f * 15f;

public static @Nullable CoreBlock preferredCoreType = null;

public CoreBlock(String name){
super(name);

Expand Down Expand Up @@ -654,13 +658,23 @@ public void handleItem(Building source, Item item){
if(team == player.team() && items.get(item) < storageCapacity) coreItemsDisplay.addItem(item, 1);
}

@Override
public boolean onConfigureBuildTapped(Building other){
deselect();
return false;
}

@Override
public void buildConfiguration(Table table){
if(!state.isCampaign() || net.client()){
// Client: Always have configuration to set preferred core
table.button(Icon.commandRally, Styles.clearTogglei, () -> {
preferredCoreType = preferredCoreType == this.block ? null : (CoreBlock)this.block;
deselect();
return;
}
}).size(40f)
.checked(b -> this.block == preferredCoreType)
.tooltip(Core.bundle.format("client.preferredcore", this.block.localizedName));

if(state.isCampaign() && !net.client()){
table.button(Icon.downOpen, Styles.cleari, () -> {
ui.planet.showSelect(state.rules.sector, other -> {
if(state.isCampaign()){
Expand All @@ -669,6 +683,7 @@ public void buildConfiguration(Table table){
});
deselect();
}).size(40f);
} // Else deselect
}
}
}

0 comments on commit f896154

Please sign in to comment.