mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Fix fly animal AI with custom blocks.
This commit is contained in:
parent
8273253828
commit
d8954e5c38
@ -24,49 +24,52 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
Random rand = lvl.physRandom;
|
Random rand = lvl.physRandom;
|
||||||
ushort x, y, z;
|
ushort x, y, z;
|
||||||
lvl.IntToPos(C.b, out x, out y, out z);
|
lvl.IntToPos(C.b, out x, out y, out z);
|
||||||
|
ExtBlock block = lvl.GetBlock(x, y, z);
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
switch (rand.Next(1, 15)) {
|
switch (rand.Next(1, 15)) {
|
||||||
case 1:
|
case 1:
|
||||||
if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index))
|
if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index)) {
|
||||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
lvl.AddUpdate(index, block);
|
||||||
|
}
|
||||||
else goto case 3;
|
else goto case 3;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index))
|
if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index)) {
|
||||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
lvl.AddUpdate(index, block);
|
||||||
|
}
|
||||||
else goto case 6;
|
else goto case 6;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
FlyTo(lvl, ref C, x - 1, y, z);
|
FlyTo(lvl, ref C, (ushort)(x - 1), y, z, block);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
case 7:
|
case 7:
|
||||||
case 8:
|
case 8:
|
||||||
FlyTo(lvl, ref C, x + 1, y, z);
|
FlyTo(lvl, ref C, (ushort)(x + 1), y, z, block);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11:
|
||||||
FlyTo(lvl, ref C, x, y, z - 1);
|
FlyTo(lvl, ref C, x, y, (ushort)(z - 1), block);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FlyTo(lvl, ref C, x, y, z + 1);
|
FlyTo(lvl, ref C, x, y, (ushort)(z + 1), block);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lvl.AddUpdate(C.b, Block.Air);
|
lvl.AddUpdate(C.b, Block.Air);
|
||||||
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FlyTo(Level lvl, ref Check C, int x, int y, int z) {
|
static void FlyTo(Level lvl, ref Check C, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||||
int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z);
|
int index = lvl.PosToInt(x, y, z);
|
||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
|
|
||||||
switch (lvl.blocks[index]) {
|
switch (lvl.blocks[index]) {
|
||||||
case Block.Air:
|
case Block.Air:
|
||||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
lvl.AddUpdate(index, block);
|
||||||
break;
|
break;
|
||||||
case Block.Op_Air:
|
case Block.Op_Air:
|
||||||
break;
|
break;
|
||||||
|
@ -59,9 +59,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
block = ExtBlock.FromIndex(lvl.BlockProps[block.Index].oDoorIndex);
|
block = ExtBlock.FromIndex(lvl.BlockProps[block.Index].oDoorIndex);
|
||||||
|
|
||||||
if (index >= 0 && oDoor == block) {
|
if (index >= 0 && oDoor == block) {
|
||||||
PhysicsArgs args = default(PhysicsArgs);
|
lvl.AddUpdate(index, oDoor, true);
|
||||||
args.ExtBlock = oDoor.BlockID == Block.custom_block;
|
|
||||||
lvl.AddUpdate(index, oDoor.RawID, true, args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 3:
|
case 3:
|
||||||
if (closest.Pos.BlockX != x) {
|
if (closest.Pos.BlockX != x) {
|
||||||
index = lvl.PosToInt((ushort)(x + Math.Sign(closest.Pos.BlockX - x)), y, z);
|
index = lvl.PosToInt((ushort)(x + Math.Sign(closest.Pos.BlockX - x)), y, z);
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -47,7 +47,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 6:
|
case 6:
|
||||||
if (closest.Pos.BlockY != y) {
|
if (closest.Pos.BlockY != y) {
|
||||||
index = lvl.PosToInt(x, (ushort)(y + Math.Sign(closest.Pos.BlockY - y)), z);
|
index = lvl.PosToInt(x, (ushort)(y + Math.Sign(closest.Pos.BlockY - y)), z);
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -58,7 +58,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 9:
|
case 9:
|
||||||
if (closest.Pos.BlockZ != z) {
|
if (closest.Pos.BlockZ != z) {
|
||||||
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign(closest.Pos.BlockZ - z)));
|
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign(closest.Pos.BlockZ - z)));
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -84,7 +84,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 3:
|
case 3:
|
||||||
if (closest.Pos.BlockX != x) {
|
if (closest.Pos.BlockX != x) {
|
||||||
index = lvl.PosToInt((ushort)(x - Math.Sign(closest.Pos.BlockX - x)), y, z);
|
index = lvl.PosToInt((ushort)(x - Math.Sign(closest.Pos.BlockX - x)), y, z);
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -95,7 +95,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 6:
|
case 6:
|
||||||
if (closest.Pos.BlockY != y) {
|
if (closest.Pos.BlockY != y) {
|
||||||
index = lvl.PosToInt(x, (ushort)(y - Math.Sign(closest.Pos.BlockY - y)), z);
|
index = lvl.PosToInt(x, (ushort)(y - Math.Sign(closest.Pos.BlockY - y)), z);
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -106,7 +106,7 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
case 9:
|
case 9:
|
||||||
if (closest.Pos.BlockZ != z) {
|
if (closest.Pos.BlockZ != z) {
|
||||||
index = lvl.PosToInt(x, y, (ushort)(z - Math.Sign(closest.Pos.BlockZ - z)));
|
index = lvl.PosToInt(x, y, (ushort)(z - Math.Sign(closest.Pos.BlockZ - z)));
|
||||||
if (MoveFish(lvl, C.b, index, target)) return;
|
if (MoveTo(lvl, C.b, index, target)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirsVisited++;
|
dirsVisited++;
|
||||||
@ -117,9 +117,8 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
RandomlyMove(lvl, ref C, rand, x, y, z, target);
|
RandomlyMove(lvl, ref C, rand, x, y, z, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool MoveFish(Level lvl, int baseIndex, int index, byte target) {
|
static bool MoveTo(Level lvl, int baseIndex, int index, byte target) {
|
||||||
if (index >= 0 && lvl.blocks[index] == target
|
if (index >= 0 && lvl.blocks[index] == target && lvl.AddUpdate(index, lvl.blocks[baseIndex])) {
|
||||||
&& lvl.AddUpdate(index, lvl.blocks[baseIndex])) {
|
|
||||||
lvl.AddUpdate(baseIndex, target);
|
lvl.AddUpdate(baseIndex, target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -129,30 +128,30 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
static void RandomlyMove(Level lvl, ref Check C, Random rand, ushort x, ushort y, ushort z, byte target ) {
|
static void RandomlyMove(Level lvl, ref Check C, Random rand, ushort x, ushort y, ushort z, byte target ) {
|
||||||
switch (rand.Next(1, 15)) {
|
switch (rand.Next(1, 15)) {
|
||||||
case 1:
|
case 1:
|
||||||
if (MoveFish(lvl, C.b, lvl.PosToInt(x, (ushort)(y - 1), z), target)) return;
|
if (MoveTo(lvl, C.b, lvl.PosToInt(x, (ushort)(y - 1), z), target)) return;
|
||||||
goto case 3;
|
goto case 3;
|
||||||
case 2:
|
case 2:
|
||||||
if (MoveFish(lvl, C.b, lvl.PosToInt(x, (ushort)(y + 1), z), target)) return;
|
if (MoveTo(lvl, C.b, lvl.PosToInt(x, (ushort)(y + 1), z), target)) return;
|
||||||
goto case 6;
|
goto case 6;
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
if (MoveFish(lvl, C.b, lvl.PosToInt((ushort)(x - 1), y, z), target)) return;
|
if (MoveTo(lvl, C.b, lvl.PosToInt((ushort)(x - 1), y, z), target)) return;
|
||||||
goto case 9;
|
goto case 9;
|
||||||
case 6:
|
case 6:
|
||||||
case 7:
|
case 7:
|
||||||
case 8:
|
case 8:
|
||||||
if (MoveFish(lvl, C.b, lvl.PosToInt((ushort)(x + 1), y, z), target)) return;
|
if (MoveTo(lvl, C.b, lvl.PosToInt((ushort)(x + 1), y, z), target)) return;
|
||||||
goto case 12;
|
goto case 12;
|
||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11:
|
||||||
MoveFish(lvl, C.b, lvl.PosToInt(x, y, (ushort)(z - 1)), target);
|
MoveTo(lvl, C.b, lvl.PosToInt(x, y, (ushort)(z - 1)), target);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
case 13:
|
case 13:
|
||||||
case 14:
|
case 14:
|
||||||
MoveFish(lvl, C.b, lvl.PosToInt(x, y, (ushort)(z + 1)), target);
|
MoveTo(lvl, C.b, lvl.PosToInt(x, y, (ushort)(z + 1)), target);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,6 +228,12 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool AddUpdate(int b, ExtBlock block, bool overRide = false) {
|
||||||
|
PhysicsArgs args = default(PhysicsArgs);
|
||||||
|
args.ExtBlock = block.BlockID == Block.custom_block;
|
||||||
|
return AddUpdate(b, block.RawID, overRide, args);
|
||||||
|
}
|
||||||
|
|
||||||
internal bool AddUpdate(int b, byte type, bool overRide = false) {
|
internal bool AddUpdate(int b, byte type, bool overRide = false) {
|
||||||
return AddUpdate(b, type, overRide, default(PhysicsArgs));
|
return AddUpdate(b, type, overRide, default(PhysicsArgs));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user