Skip to content

Commit

Permalink
pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
SoLegendary committed Dec 2, 2024
1 parent 90613eb commit 3a1b6d9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 53 deletions.
20 changes: 6 additions & 14 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Wave Survival 0.4
[🟡] Enemy units no longer try to attack bridges or pile up near them
[🟡] Provide 50% refund for deleting a completed building (scaled to how damaged it is)

[❌] Deserts added back to worldgen
[❌] In wave survival, teams randomly switch
[🟡] Ranged units no longer pile up inside buildings

Expand All @@ -28,7 +27,7 @@ Portal fixes
[🟡] Portals can no longer spawn over water (but they can still spawn on land across water)
[🟡] Portals can no longer spawn too close to another portal
[🟡] Piglin waves now have a population cap for units spawned from portals (2x of other waves)

[🟡] Enemy ghasts no longer friendly fire their own portals

Features
--------
Expand All @@ -48,20 +47,14 @@ Bugfixes
[🟡] Can no longer enter enemy garrisons
- You can still enter allied garrisons
[🟡] Tall grass and barrier blocks are now ignored by the cursor
[🟡] Only save resource data if the unit was actively gathering
[🟡] Fix weird pathing over magma
- To fix this, there is a new block identical in texture and function to magma called "Walkable Magma"
- To fix this, there is now a new block identical in texture and function to magma called "Walkable Magma"
- @Mapmakers should replace any regular magma blocks in their maps with this block to improve pathfinding
[❌] Fix #localisation channel problems

[🟡] Only save resource data if the unit was actively gathering
[❌] Wipe all saved data on /rts-reset



[❌] Logical side error in town centre?



Quality of Life
---------------

Expand All @@ -85,17 +78,16 @@ Quality of Life
[❌] /gamerule groundYLevel for mapmakers
- Maybe separate for ghasts and bridges?

[❌] Right click to autocast repair on workers

Balancing
---------
[❌] De-RNG farm growth, and properly measure their output for balancing

[✔] Spiders & Poison Spiders: +1 dmg

[🟡] Capitols after the one at the start of the game take twice as long to build
[❌] All Capitols: +50 wood, +100 ore (starting resources adjusted accordingly)

[❌] Warden HP reduced to 120
[🟡] Capitols after the first take twice as long to build
[🟡] All Capitols: +50 wood, +100 ore (starting resources adjusted accordingly)


Languages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public Building(

// re-hide players if they were revealed
if (this.isCapitol && !this.level.isClientSide()) {
if (BuildingUtils.getTotalCompletedBuildingsOwned(false, this.ownerName) == 1
&& !TutorialServerEvents.isEnabled()) {
sendMessageToAllPlayers(I18n.get("hud.reignofnether.placed_capitol", this.ownerName));
if (BuildingUtils.getTotalCompletedBuildingsOwned(false, this.ownerName) == 1 &&
!TutorialServerEvents.isEnabled() && FogOfWarServerEvents.isEnabled()) {
sendMessageToAllPlayers("hud.reignofnether.placed_capitol", false, this.ownerName);
}
FogOfWarClientboundPacket.revealOrHidePlayer(false, this.ownerName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,13 @@ else if (evt.getExplosion().getSourceMob() instanceof PillagerUnit pUnit) {
Set<Building> affectedBuildings = new HashSet<>();
for (BlockPos bp : evt.getAffectedBlocks()) {
Building building = BuildingUtils.findBuilding(false, bp);

if (building != null) {
affectedBuildings.add(building);
// prevent enemy ghasts friendly firing their own buildings
if (!(SurvivalServerEvents.isEnabled() && ghastUnit != null &&
SurvivalServerEvents.ENEMY_OWNER_NAMES.contains(ghastUnit.getOwnerName()) &&
SurvivalServerEvents.ENEMY_OWNER_NAMES.contains(building.ownerName)))
affectedBuildings.add(building);
}
}
for (Building building : affectedBuildings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ else if ((newBuildingAuthActions.contains(this.action) &&
success.set(false);
return;
}

ReignOfNether.LOGGER.warn("Processing packet from: " + player.getName() + " for " + ownerName);

switch (this.action) {
case PLACE -> {
BuildingServerEvents.placeBuilding(this.itemName, this.buildingPos, this.rotation, this.ownerName, this.builderUnitIds, false, isDiagonalBridge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,6 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
// ------------------------------
if (!PlayerClientEvents.isRTSPlayer && !PlayerClientEvents.rtsLocked) {

/*
Button gamemodeButton = ClientGameModeHelper.getButton();
if (gamemodeButton != null && !gamemodeButton.isHidden.get() && !TutorialClientEvents.isEnabled()) {
gamemodeButton.render(evt.getPoseStack(),
Expand All @@ -1114,7 +1113,6 @@ else if (hudSelectedEntity != null && portraitRendererUnit.model != null
);
renderedButtons.add(gamemodeButton);
}
*/

if (!StartButtons.villagerStartButton.isHidden.get()) {
StartButtons.villagerStartButton.render(evt.getPoseStack(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level;

import java.util.ArrayList;
Expand Down Expand Up @@ -97,13 +98,21 @@ public void action(Level level) {
for (Unit unit : actionableUnits) {

// recalculating pathfinding can be expensive, so check if we actually need to first
/*
if (action == UnitAction.MOVE) {
MoveToTargetBlockGoal goal = unit.getMoveGoal();
if (goal != null && goal.willReachTargetWithoutRepathing())
continue;

if (goal != null) {
BlockPos bp = goal.getMoveTarget();
if (bp != null) {
double distToTarget = bp.distSqr(((Mob) unit).getOnPos());
if (distToTarget > 400) {
double ignoreDist = Math.min(5, Math.sqrt(distToTarget) / 10);
if (bp.distSqr(preselectedBlockPos) < ignoreDist * ignoreDist)
return;
}
}
}
}
*/

// have to do this before resetBehaviours so we can assign the correct resourceName first
if (action == UnitAction.TOGGLE_GATHER_TARGET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,38 +302,27 @@ else if (!Keybindings.altMod.isDown() && selectedUnits.size() > 0 && MC.level !=
MC.level, selectedUnits, getPreselectedBlockPos()
);

int skips = 0;

for (Pair<Integer, BlockPos> pair : formationPairs) {
int entityId = pair.getFirst();
BlockPos targetPos = pair.getSecond();
Entity entity = MC.level.getEntity(entityId);
if (entity instanceof Unit unit &&
unit.getMoveGoal() != null) {

BlockPos pbp = getPreselectedBlockPos();

if (unit.getMoveGoal().getMoveTarget() != null &&
unit.getMoveGoal().lastSelectedMoveTarget != null &&
unit.getMoveGoal().lastSelectedMoveTarget.distToCenterSqr(pbp.getX(), pbp.getY(), pbp.getZ()) <= 9 &&
entity.getOnPos().distToCenterSqr(pbp.getX(), pbp.getY(), pbp.getZ()) >= 100)
continue;

BlockPos oldFinalPos = unit.getMoveGoal().getFinalNodePos();
sendUnitCommandManual(UnitAction.MOVE, -1, new int[]{entityId}, targetPos, true, false);
BlockPos newFinalPos = unit.getMoveGoal().getFinalNodePos();

// if the client didn't calculate a new enough finalNodePos, then don't bother sending the server command
if (oldFinalPos != null && newFinalPos != null &&
oldFinalPos.distToCenterSqr(newFinalPos.getX(), newFinalPos.getY(), newFinalPos.getZ()) <= 9) {
skips += 1;
continue;
}
sendUnitCommandManual(UnitAction.MOVE, -1, new int[]{entityId}, targetPos, false, true);
/**
* BlockPos oldFinalPos = unit.getMoveGoal().getFinalNodePos();
* sendUnitCommandManual(UnitAction.MOVE, -1, new int[]{entityId}, targetPos, true, false);
* BlockPos newFinalPos = unit.getMoveGoal().getFinalNodePos();
*
* // if the client didn't calculate a new enough finalNodePos, then don't bother sending the server command
* if (oldFinalPos != null && newFinalPos != null &&
* oldFinalPos.distToCenterSqr(newFinalPos.getX(), newFinalPos.getY(), newFinalPos.getZ()) <= 9) {
* skips += 1;
* continue;
* }
*/
sendUnitCommandManual(UnitAction.MOVE, -1, new int[]{entityId}, targetPos);
}
}
//System.out.println(skips);

for (LivingEntity le : selectedUnits)
if (le instanceof Unit unit && unit.getMoveGoal() != null)
unit.getMoveGoal().lastSelectedMoveTarget = getPreselectedBlockPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public boolean canUse() {

public boolean canContinueToUse() {
// PathNavigation seems to have a max length so restart it if we haven't actually reached the target yet
// TODO: this repeats every tick if the mob is stuck, eg. targeting over water
if (this.mob.getNavigation().isDone() && moveTarget != null &&
this.mob.getOnPos().distSqr(moveTarget) > 1) {
this.start();
Expand All @@ -63,12 +64,17 @@ public void start() {
}

public void setMoveTarget(@Nullable BlockPos bp) {



if (bp != null) {
MiscUtil.addUnitCheckpoint((Unit) mob, bp);
((Unit) mob).setIsCheckpointGreen(true);
}
this.moveTarget = bp;
this.start();

if (!this.mob.level.isClientSide())
this.start();
}

public BlockPos getMoveTarget() {
Expand All @@ -85,7 +91,6 @@ public BlockPos getMoveTarget() {
public void stopMoving() {
this.moveTarget = null;
this.mob.getNavigation().stop();

if (this.mob.isVehicle() && this.mob.getPassengers().get(0) instanceof Unit unit)
unit.getMoveGoal().stopMoving();
}
Expand Down

0 comments on commit 3a1b6d9

Please sign in to comment.