mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -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;
|
||||
ushort x, y, z;
|
||||
lvl.IntToPos(C.b, out x, out y, out z);
|
||||
ExtBlock block = lvl.GetBlock(x, y, z);
|
||||
int index;
|
||||
|
||||
switch (rand.Next(1, 15)) {
|
||||
case 1:
|
||||
if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index))
|
||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
||||
if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index)) {
|
||||
lvl.AddUpdate(index, block);
|
||||
}
|
||||
else goto case 3;
|
||||
break;
|
||||
case 2:
|
||||
if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index))
|
||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
||||
if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index)) {
|
||||
lvl.AddUpdate(index, block);
|
||||
}
|
||||
else goto case 6;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
FlyTo(lvl, ref C, x - 1, y, z);
|
||||
FlyTo(lvl, ref C, (ushort)(x - 1), y, z, block);
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
FlyTo(lvl, ref C, x + 1, y, z);
|
||||
FlyTo(lvl, ref C, (ushort)(x + 1), y, z, block);
|
||||
break;
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
FlyTo(lvl, ref C, x, y, z - 1);
|
||||
FlyTo(lvl, ref C, x, y, (ushort)(z - 1), block);
|
||||
break;
|
||||
default:
|
||||
FlyTo(lvl, ref C, x, y, z + 1);
|
||||
FlyTo(lvl, ref C, x, y, (ushort)(z + 1), block);
|
||||
break;
|
||||
}
|
||||
lvl.AddUpdate(C.b, Block.Air);
|
||||
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
||||
}
|
||||
|
||||
static void FlyTo(Level lvl, ref Check C, int x, int y, int z) {
|
||||
int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z);
|
||||
static void FlyTo(Level lvl, ref Check C, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
int index = lvl.PosToInt(x, y, z);
|
||||
if (index < 0) return;
|
||||
|
||||
switch (lvl.blocks[index]) {
|
||||
case Block.Air:
|
||||
lvl.AddUpdate(index, lvl.blocks[C.b]);
|
||||
lvl.AddUpdate(index, block);
|
||||
break;
|
||||
case Block.Op_Air:
|
||||
break;
|
||||
|
@ -59,9 +59,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
block = ExtBlock.FromIndex(lvl.BlockProps[block.Index].oDoorIndex);
|
||||
|
||||
if (index >= 0 && oDoor == block) {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.ExtBlock = oDoor.BlockID == Block.custom_block;
|
||||
lvl.AddUpdate(index, oDoor.RawID, true, args);
|
||||
lvl.AddUpdate(index, oDoor, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 3:
|
||||
if (closest.Pos.BlockX != x) {
|
||||
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++;
|
||||
@ -47,7 +47,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 6:
|
||||
if (closest.Pos.BlockY != y) {
|
||||
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++;
|
||||
@ -58,7 +58,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 9:
|
||||
if (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++;
|
||||
@ -84,7 +84,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 3:
|
||||
if (closest.Pos.BlockX != x) {
|
||||
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++;
|
||||
@ -95,7 +95,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 6:
|
||||
if (closest.Pos.BlockY != y) {
|
||||
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++;
|
||||
@ -106,7 +106,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
case 9:
|
||||
if (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++;
|
||||
@ -117,9 +117,8 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
RandomlyMove(lvl, ref C, rand, x, y, z, target);
|
||||
}
|
||||
|
||||
static bool MoveFish(Level lvl, int baseIndex, int index, byte target) {
|
||||
if (index >= 0 && lvl.blocks[index] == target
|
||||
&& lvl.AddUpdate(index, lvl.blocks[baseIndex])) {
|
||||
static bool MoveTo(Level lvl, int baseIndex, int index, byte target) {
|
||||
if (index >= 0 && lvl.blocks[index] == target && lvl.AddUpdate(index, lvl.blocks[baseIndex])) {
|
||||
lvl.AddUpdate(baseIndex, target);
|
||||
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 ) {
|
||||
switch (rand.Next(1, 15)) {
|
||||
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;
|
||||
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;
|
||||
case 3:
|
||||
case 4:
|
||||
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;
|
||||
case 6:
|
||||
case 7:
|
||||
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;
|
||||
case 9:
|
||||
case 10:
|
||||
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;
|
||||
case 12:
|
||||
case 13:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -227,6 +227,12 @@ namespace MCGalaxy {
|
||||
//ListCheck.Add(new Check(b)); //Lousy back up plan
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
return AddUpdate(b, type, overRide, default(PhysicsArgs));
|
||||
|
Loading…
x
Reference in New Issue
Block a user