Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
wallabra committed Jan 15, 2025
2 parents b2821ef + 790fa96 commit 0e0b7b9
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/Built/
.vscode
/run

.DS_Store
59 changes: 41 additions & 18 deletions ZScript.zs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ class ZTBotController : Actor {
void Subroutine_Flee() {
if (DodgeAndUse()) {
if (currNode)
navDest = currNode.RandomNeighbor();
navDest = currNode.RandomNeighborRoughlyToward(vel.xy, 0.5);

else
navDest = null;
Expand Down Expand Up @@ -2668,7 +2668,15 @@ class ZTBotController : Actor {
return true;
}

bool Commands(Actor another) {
bool Commands(Actor another, int depth = 0) {
if (!another) {
return false;
}

if (another == possessed) {
return true;
}

ZetaBotPawn zbp = ZetaBotPawn(another);

if (zbp == null || zbp.cont == null) {
Expand Down Expand Up @@ -2798,15 +2806,19 @@ class ZTBotController : Actor {
navDest = null;
}
}

void Subroutine_Wander() {
void ForgetEnemies() {
if (lastEnemyPos != null) {
lastEnemyPos.Destroy();
lastEnemyPos = null;
}

enemy = null;
BotChat("IDLE", 2.25 / 100);
}

void Subroutine_Wander() {
ForgetEnemies();
PickCommander();

if (bstate != BS_FOLLOWING && ShouldFollow(commander)) {
ConsiderSetBotState(BS_FOLLOWING);
Expand All @@ -2816,27 +2828,25 @@ class ZTBotController : Actor {
return;
}
}

PickCommander();

BotChat("IDLE", 2.25 / 100);
DodgeAndUse();

if (currNode == null) {
SetCurrentNode(ClosestVisibleNode(possessed));
}

DodgeAndUse();

if (currNode && possessed.Distance2D(currNode) < 200 && navDest && navDest != currNode) {
MoveToward(navDest, 5); // wander to this random neighbouring node

if (!currNode) {
return;
}

else {
if (navDest == currNode) {
navDest = null;
RandomMove();
}

if (!navDest) {
SetWanderNavdest();
}
DebugLog(LT_VERBOSE, "picking destination");
navDest = currNode.RandomNeighborRoughlyToward(vel.xy, 4);
}

ZTPathNode LastVisited[LAST_VISITED_LENGTH];
Expand All @@ -2855,8 +2865,21 @@ class ZTBotController : Actor {
if (alist.Get(listIdx) == LastVisited[checkIdx]) {
aList.Remove(listIdx);
}
}
}

if (navDest) {
//DebugLog(LT_VERBOSE, "picked destination");
}

else {
//DebugLog(LT_VERBOSE, "failed to pick destination");
}
}

if (navDest) {
//DebugLog(LT_VERBOSE, "moving to destination");
MoveToward(navDest, 5); // wander to this random neighbouring node
}

if (aList.IsEmpty()) {
return;
Expand Down
54 changes: 54 additions & 0 deletions ZetaCode/Pathing.zs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,60 @@ class ZTPathNode : ZTPositionMarker

return res;
}

ZTPathNode RandomNeighborRoughlyToward(Vector2 direction, double preference = 1.0)
{
ActorList nb = NeighborsOutward();
ZTPathNode res;

if (direction.Length() == 0) {
return RandomNeighbor();
}

direction = direction.Unit();
preference /= 2.0; // due to how dot products work

A_Log(""..direction);

if ( nb.Length() < 1 )
return self;

Array<double> weights;
double total = 0.0;

A_Log(""..direction);

ZTPathnode neigh;
for (nb.iReset(), neigh = ZTPathNode(nb.iNext()); neigh; neigh = ZTPathNode(nb.iNext())) {
if (neigh == self) {
continue;
}
A_Log("--");
A_Log(""..direction);
Vector2 offs = neigh.pos.xy - pos.xy;
offs = offs.Unit();
double directionality = 1 + (1 + offs dot direction) * preference;
A_Log(offs.." "..direction);
weights.push(directionality);
total += directionality;
}

// weighted random
double choice = FRandom(0, total);

for (int i = 0; i < weights.Size(); i++) {
if (choice < weights[i]) {
res = ZTPathNode(nb.Get(i));
break;
}

choice -= weights[i];
}

nb.Destroy(); // clean actorlists after use

return res;
}

void ShowPath(ZTPathNode otherNode) {
uint segRes = 24; // constant
Expand Down
15 changes: 13 additions & 2 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ LZMA=0
PLATFORM=$(uname -s | head -c 5)
RUN=0

REALPATH_CMD="realpath"
# check if we are on macos
if [ "$PLATFORM" == "Darwi" ]; then
REALPATH_CMD="grealpath"
# check if grealpath exists
if ! command -v grealpath &> /dev/null; then
echo "grealpath not found, please install coreutils using 'brew install coreutils' and try again."
exit 1
fi
fi

while [[ $# -gt 0 ]]; do
key="$1"

Expand Down Expand Up @@ -103,10 +114,10 @@ BUILDDIR=""
function ADDFILE {
if [ $# -eq 1 ]; then
if [ -n "$BUILDDIR" ]; then
f="$(realpath --relative-to="./$BUILDDIR" "./${BUILDDIR}/${1}")"
f="$($REALPATH_CMD --relative-to="./$BUILDDIR" "./${BUILDDIR}/${1}")"

else
f="$(realpath --relative-to="." "./${1}")"
f="$($REALPATH_CMD --relative-to="." "./${1}")"

fi

Expand Down

0 comments on commit 0e0b7b9

Please sign in to comment.