Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v7' into v7
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Nov 4, 2024
2 parents 5742491 + 1d17735 commit 10e91e2
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 26 deletions.
1 change: 1 addition & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ client.stopsendbuildplans = [accent][[{0}][] to stop dispatching build plans
client.sendbuildplans = [accent][[{0}][] to start dispatching build plans
client.freezequeueing = [scarlet][SHIFT + {0}][] to toggle freeze queueing
client.configured = configured
client.configurednodelink = link added
client.built = built
client.broke = broke
client.destroyed = destroyed
Expand Down
1 change: 1 addition & 0 deletions core/assets/bundles/bundle_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ client.stopsendbuildplans = 建設計画の送信を停止 [accent][[{0}][]
client.sendbuildplans = 建設計画の送信を開始 [accent][[{0}][]
client.freezequeueing = [scarlet][SHIFT + {0}][] で凍結キューイングを切り替える
client.configured = 設定済み
client.configurednodelink = リンクを追加
client.built = 建設済み
client.broke = 破壊済み
client.destroyed = 破壊されました
Expand Down
3 changes: 3 additions & 0 deletions core/assets/bundles/bundle_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ client.stopsendbuildplans = [accent][[{0}][]停止派遣建筑规划
client.sendbuildplans = [accent][[{0}][]开始派遣建筑规划
client.freezequeueing = [scarlet][SHIFT + {0}][]切换冻结队列
client.configured = 配置/更改了
client.configurednodelink = 链接增添了
client.built = 建造了
client.broke = 拆除了
client.destroyed = 被摧毁
Expand Down Expand Up @@ -102,6 +103,8 @@ client.claj.portnotfound = CLaJ链接缺失端口
client.claj.colonnotfound = CLaJ链接缺失冒号
client.claj.wrongkeylength = CLaJ链接长度错误
client.claj.missingprefix = CLaJ链接缺失前缀
client.claj.ping.error = 连接服务器时出错.
client.claj.ping.pending = 尚未连接.

# Editor
client.editor.autosaved = 自动保存完成!
Expand Down
9 changes: 8 additions & 1 deletion core/src/mindustry/ai/BaseRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import arc.util.pooling.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.game.Schematic.*;
Expand Down Expand Up @@ -81,7 +82,13 @@ public void load(){
drills ++;
}
}
schem.tiles.removeAll(s -> s.block.buildVisibility == BuildVisibility.sandboxOnly);
schem.tiles.removeAll(s -> {
if(s.block.buildVisibility == BuildVisibility.sandboxOnly){
Pools.free(s);
return true;
}
return false;
});

part.tier = schem.tiles.sumf(s -> Mathf.pow(s.block.buildCost / s.block.buildCostMultiplier, 1.4f));

Expand Down
29 changes: 23 additions & 6 deletions core/src/mindustry/client/antigrief/Interactor.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package mindustry.client.antigrief

import arc.*
import mindustry.ai.types.*
import mindustry.entities.units.*
import mindustry.gen.*
import mindustry.gen.Unit
import mindustry.ui.*

interface Interactor {
val name: String
Expand All @@ -13,30 +16,44 @@ interface Interactor {
}

open class UnitInteractor(unit: Unit?) : Interactor {
override val name = when {
override val name = when { // FINISHME: bundle
unit?.isPlayer == true -> "${unit.type.localizedName} controlled by ${unit.player.coloredName()}"
// (unit?.controller() as? FormationAI)?.leader?.isPlayer == true -> "${unit.type.localizedName} controlled by ${(unit.controller() as FormationAI).leader.playerNonNull().coloredName()}" FINISHME: commanding exists
unit?.controller() is CommandAI -> "${unit.type.localizedName} commanded by ${unit.lastCommanded ?: "unknown"} " +
"to ${(unit.controller() as CommandAI).currentCommand()?.name ?: "unknown"}"
unit?.controller() is LogicAI -> {
val lcontrol = (unit.controller() as? LogicAI)?.controller
"${unit.type.localizedName} logic-controlled by ${lcontrol?.block()?.localizedName} (${lcontrol?.tileX()}, ${lcontrol?.tileY()}) accessed by ${lcontrol?.lastAccessed}"
}
unit?.controller() is AIController -> {
val controllerName = when (unit.controller()) {
is MinerAI -> Core.bundle.get("command.mine")
is FlyingAI -> "fly"
is GroundAI -> "walk"
is BuilderAI -> Core.bundle.get("command.${if ((unit.controller() as BuilderAI).onlyAssist) "rebuild" else "assist"}")
is RepairAI -> Core.bundle.get("command.repair")
else -> "control"
}
"AI-${controllerName} ${unit.type.localizedName}"
}
else -> unit?.type?.localizedName ?: "null unit"
}

override val shortName: String = when {
unit?.isPlayer == true -> unit.player.coloredName()
// (unit?.controller() as? FormationAI)?.leader?.isPlayer == true -> (unit.controller() as FormationAI).leader.playerNonNull().name FINISHME: Commanding exists
unit?.controller() is LogicAI -> "logic-controlled ${unit.type.localizedName}"
unit?.controller() is CommandAI -> if (Core.settings.getBool("useiconslogs")) Iconc.codes.get("units").toChar().toString() + Fonts.getUnicodeStr(unit.type.name)
else "player-commanded ${unit.type.localizedName}"
unit?.controller() is LogicAI -> if (Core.settings.getBool("useiconslogs")) Iconc.codes.get("logic").toChar().toString() + Fonts.getUnicodeStr(unit.type.name)
else "logic-controlled ${unit.type.localizedName}"
else -> unit?.type?.localizedName ?: "null unit"
}

override val playerID: Int = if (unit?.isPlayer == true) unit.player.id else -1
}

object NullUnitInteractor : UnitInteractor(Nulls.unit) {
override val name = "null unit" // FINISHME: Dont use this when nodes are automatically configured
override val name = "null unit"

override val shortName = "null unit" // FINISHME: Dont use this when nodes are automatically configured
override val shortName = "null unit"
}

class NoInteractor : Interactor {
Expand Down
26 changes: 16 additions & 10 deletions core/src/mindustry/client/antigrief/TileLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ abstract class AbstractTileLog(tile: Tile, cause: Interactor, val block: Block)
protected val eventTarget: String = if (Core.settings.getBool("useiconslogs")) Fonts.getUnicodeStr(block.name) else block.localizedName
}

class ConfigureTileLog(tile: Tile, cause: Interactor, block: Block, val rotation: Int, var configuration: Any?) : AbstractTileLog(tile, cause, block) {
open class ConfigureTileLog(tile: Tile, cause: Interactor, block: Block, val rotation: Int, var configuration: Any?) : AbstractTileLog(tile, cause, block) {
override fun apply(previous: TileState) {
previous.rotation = rotation
previous.configuration = configuration
Expand All @@ -204,11 +204,17 @@ class ConfigureTileLog(tile: Tile, cause: Interactor, block: Block, val rotation
}
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[accent]${Core.bundle.get("client.configured")}[]" else Core.bundle.get("client.configured")
private val eventName: String = Core.bundle.get("client.configured").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}

class NodeLinkAddedTileLog(tile: Tile, cause: Interactor, block: Block, rotation: Int, configuration: Any?) : ConfigureTileLog(tile, cause, block, rotation, configuration) {
override fun toString() = "$eventTarget ${Core.bundle.get("client.configurednodelink")}"
private val eventName: String = Core.bundle.get("client.configurednodelink").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }
override fun toShortString() = "$eventTarget $eventName"
}

open class TilePlacedLog(tile: Tile, cause: Interactor, block: Block, var rotation: Int = tile.build?.rotation ?: 0, var configuration: Any?, val isRootTile: Boolean) : AbstractTileLog(tile, cause, block) {
override fun apply(previous: TileState) {
previous.block = block
Expand All @@ -226,7 +232,7 @@ open class TilePlacedLog(tile: Tile, cause: Interactor, block: Block, var rotati
return "${cause.name.stripColors()} ${Core.bundle.get("client.built")} ${block.localizedName}"
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[green]${Core.bundle.get("client.built")}[]" else Core.bundle.get("client.built")
private val eventName: String = Core.bundle.get("client.built").let { if(Core.settings.getBool("colorizelogs")) "[green]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}
Expand All @@ -236,7 +242,7 @@ class BlockPayloadDropLog(tile: Tile, cause: Interactor, block: Block, rotation:
return "${cause.name.stripColors()} ${Core.bundle.get("client.putdown")} ${block.localizedName}"
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[accent]${Core.bundle.get("client.putdown")}[]" else Core.bundle.get("client.putdown")
private val eventName: String = Core.bundle.get("client.putdown").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}
Expand All @@ -253,7 +259,7 @@ open class TileBreakLog(tile: Tile, cause: Interactor, block: Block) : AbstractT
return "${cause.name.stripColors()} ${Core.bundle.get("client.broke")} ${block.localizedName}"
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[red]${Core.bundle.get("client.broke")}[]" else Core.bundle.get("client.broke")
private val eventName: String = Core.bundle.get("client.broke").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}
Expand All @@ -263,7 +269,7 @@ class BlockPayloadPickupLog(tile: Tile, cause: Interactor, block: Block) : TileB
return "${cause.name.stripColors()} ${Core.bundle.get("client.pickedup")} ${block.localizedName}"
}

private val eventName: String = if (Core.settings.getBool("colorizelogs")) "[accent]${Core.bundle.get("client.pickedup")}[]" else Core.bundle.get("client.pickedup")
private val eventName: String = Core.bundle.get("client.pickedup").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}
Expand All @@ -272,7 +278,7 @@ class TileDestroyedLog(tile: Tile, block: Block) : TileBreakLog(tile, NoInteract
return "${block.localizedName} ${Core.bundle.get("client.destroyed")}"
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[red]${Core.bundle.get("client.destroyed")}[]" else Core.bundle.get("client.destroyed")
private val eventName: String = Core.bundle.get("client.destroyed").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }

override fun toShortString() = "$eventTarget $eventName"
}
Expand All @@ -287,8 +293,8 @@ class UnitDestroyedLog(val tile: Tile, cause: Interactor, val unit: Unit, val is
}

private val eventController: String = "${cause.shortName.stripColors().take(16)}${if (cause.shortName.stripColors().length > 16) "..." else ""}"
private val eventNamePlayer: String = if(Core.settings.getBool("colorizelogs")) "[red]${Core.bundle.get("client.playerunitdeath")}[]" else Core.bundle.get("client.playerunitdeath")
private val eventNameLogic: String = if(Core.settings.getBool("colorizelogs")) "[red]${Core.bundle.get("client.unitdeath")}[]" else Core.bundle.get("client.unitdeath")
private val eventNamePlayer: String = Core.bundle.get("client.playerunitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private val eventNameLogic: String = Core.bundle.get("client.unitdeath").let { if(Core.settings.getBool("colorizelogs")) "[red]$it[]" else it }
private val eventUnit: String = if(Core.settings.getBool("useiconslogs") && unit.type.name.isNotEmpty()) Fonts.getUnicodeStr(unit.type.name) else unit.type?.localizedName ?: "null unit"

override fun toShortString(): String {
Expand All @@ -305,7 +311,7 @@ class RotateTileLog(tile: Tile, cause: Interactor, block: Block, val rotation: I
return "${cause.name.stripColors()} ${Core.bundle.get("client.rotated")} ${block.localizedName} ${Core.bundle.get(if (direction) "client.counterclockwise" else "client.clockwise")}"
}

private val eventName: String = if(Core.settings.getBool("colorizelogs")) "[accent]${Core.bundle.get("client.rotated")}[]" else Core.bundle.get("client.rotated")
private val eventName: String = Core.bundle.get("client.rotated").let { if(Core.settings.getBool("colorizelogs")) "[accent]$it[]" else it }

override fun toShortString() = "$eventPlayer $eventName $eventTarget"
}
10 changes: 6 additions & 4 deletions core/src/mindustry/client/antigrief/TileRecords.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import mindustry.game.*
import mindustry.gen.*
import mindustry.world.*
import mindustry.world.blocks.*
import mindustry.world.blocks.power.*
import java.time.*
import kotlin.math.*

Expand Down Expand Up @@ -61,8 +62,9 @@ object TileRecords {

Events.on(EventType.ConfigEventBefore::class.java) {
if (it.player != null) Seer.blockConfig(it.player, it.tile.tile, it.value)
val constructor = if ((it.player == null) && it.tile.tile.block() is PowerNode) ::NodeLinkAddedTileLog else ::ConfigureTileLog
it.tile.tile.getLinkedTiles { tile ->
addLog(tile, ConfigureTileLog(tile, it.player.toInteractor(), tile.block(), it.tile.rotation, it.value))
addLog(tile, constructor(tile, it.player.toInteractor(), tile.block(), it.tile.rotation, it.value))
}
}

Expand Down Expand Up @@ -90,14 +92,14 @@ object TileRecords {

Events.on(EventType.UnitDeadEvent::class.java) {
if(it.unit == null || it.unit.team() != Vars.player.team() || it.unit.tileOn() == null) return@on
val controller = it.unit.controller()
if(controller !is LogicAI && controller !is Player) return@on

if(it.unit.controller() is MissileAI) return@on

val threshold = it.unit.type.hitSize * it.unit.type.hitSize + 0.01f
for (point in TileLog.linkedArea(it.unit.tileOn(), Mathf.ceil(it.unit.type.hitSize / Vars.tilesize))) {
if (point in Vars.world && it.unit.within(Vars.world[point], threshold)) {
val tile = Vars.world[point]
addLog(tile, UnitDestroyedLog(tile, it.unit.toInteractor(), it.unit, controller is Player))
addLog(tile, UnitDestroyedLog(tile, it.unit.toInteractor(), it.unit, it.unit.controller() is Player))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ class CommandTransmission : Transmission {
STOP_PATH(false, {
val cert = Main.keyStorage.findTrusted(BigInteger(it.certSN))!!
if (Navigation.currentlyFollowing != null) {
lastStopTime = Time.millis()
val oldPath = Navigation.currentlyFollowing
if (Main.keyStorage.builtInCerts.contains(cert)) {
val dialog = BaseDialog("@client.stoppath.stopped")
dialog.cont.add(Core.bundle.format("client.stoppath.bydev", cert.readableName))
dialog.buttons.button("@close", Icon.menu) { dialog.hide() }
.size(210f, 64f)
} else if (Time.timeSinceMillis(lastStopTime) > Time.toMinutes * (1 + numStopIgnores)) {
dialog.show()
} else if (Time.timeSinceMillis(lastStopTime) > Time.toMinutes.toLong() * (1 + numStopIgnores)) {
numStopIgnores -= Math.min(numStopIgnores, (Time.timeSinceMillis(lastStopTime) / Time.toMinutes.toLong()).toInt() - numStopIgnores - 1)
Vars.ui.showCustomConfirm("@client.stoppath.stopped",
Core.bundle.format("client.stoppath.by", Main.keyStorage.aliasOrName(cert)),
Core.bundle.get("client.stoppath.continue"), Core.bundle.get("client.stoppath.stop"),
{ Navigation.follow(oldPath); numStopIgnores ++; }, {}
)
}
lastStopTime = Time.millis()
Navigation.stopFollowing()
}
}),
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/client/utils/AutoShoot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun autoShoot() {

if (target == null || Client.timer.get(2, 6f)) { // Acquire target FINISHME: Heal allied units?
if (type.canAttack) {
val ignoreDisarmed = Server.io()
val ignoreDisarmed = Server.io() && !CustomMode.defense();
target = Units.closestEnemy(unit.team, unit.x, unit.y, unit.range()) { u -> !(ignoreDisarmed && u.disarmed) && u.checkTarget(type.targetAir, unit.type.targetGround) }
}
if (type.canHeal && target == null) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/mindustry/entities/comp/PlayerComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void unit(Unit unit){
if(this.unit != Nulls.unit){
//un-control the old unit
this.unit.resetController();
if(!headless && isLocal()) { // Plan persistence is client side only FINISHME: Move this to some other class
if(!headless && isLocal() && (justSwitchFrom == null || this.unit == justSwitchFrom)) { // Plan persistence is client side only FINISHME: Move this to some other class
if(Navigation.currentlyFollowing instanceof BuildPath bp) bp.clearQueues();
persistPlans.clear(); // Don't want to stack multiple sets of plans...
persistPlans.ensureCapacity(this.unit.plans.size);
Expand All @@ -262,6 +262,8 @@ public void unit(Unit unit){

if(!headless && isLocal() && !persistPlans.isEmpty()){ // Persist plans through unit swaps
if(!ClientVars.syncing && Time.timeSinceMillis(ClientVars.lastJoinTime) < 3000) persistPlans.clear(); // I can't find a more reliable way to not persist through map changes
control.input.playerPlanTree.clear();
player.unit().plans.each(control.input.playerPlanTree::insert);
persistPlans.each(unit::addBuild);
persistPlans.clear();
persistPlans.shrink(); // Don't want an array hanging around in memory, replace it with a 0 element array
Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/game/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import arc.files.*;
import arc.struct.*;
import arc.util.*;
import arc.util.pooling.*;
import mindustry.content.*;
import mindustry.mod.Mods.*;
import mindustry.type.*;
Expand Down Expand Up @@ -154,7 +155,7 @@ public Stile set(Stile other){
}

public Stile copy(){
return new Stile(block, x, y, config, rotation);
return Pools.obtain(Stile.class, Stile::new).set(this);
}
}
}
1 change: 1 addition & 0 deletions core/src/mindustry/game/Schematics.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void overwrite(Schematic target, Schematic newSchematic){
previews.remove(target);
}

Pools.freeAll(target.tiles, true);
target.tiles.clear();
target.tiles.addAll(newSchematic.tiles);
target.width = newSchematic.width;
Expand Down
Loading

0 comments on commit 10e91e2

Please sign in to comment.