Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Water changes including #618 #619

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MCGalaxy/Blocks/Physics/AirPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public static void DoFlood(Level lvl, ref PhysInfo C, AirFlood mode, BlockID blo

static void FloodAir(Level lvl, ushort x, ushort y, ushort z, BlockID block) {
int index;
BlockID curBlock = Block.Convert(lvl.GetBlock(x, y, z, out index));
if (curBlock == Block.Water || curBlock == Block.Lava) {
BlockID curBlock = lvl.GetBlock(x, y, z, out index);
if (curBlock == Block.WaterDown || curBlock == Block.FiniteWater ||
curBlock == Block.LavaDown || curBlock == Block.FiniteLava ) {
lvl.AddUpdate(index, block);
}
}
Expand Down
4 changes: 4 additions & 0 deletions MCGalaxy/Blocks/Physics/ExtLiquidPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static void DoWaterfall(Level lvl, ref PhysInfo C) {
case Block.Air_FloodDown:
case Block.StillLava:
case Block.StillWater:
case Block.Lava:
case Block.Water:
case Block.WaterDown:
break;

Expand Down Expand Up @@ -144,6 +146,8 @@ public static void DoLavafall(Level lvl, ref PhysInfo C) {
case Block.Air_FloodDown:
case Block.StillLava:
case Block.StillWater:
case Block.Lava:
case Block.Water:
case Block.LavaDown:
break;
default:
Expand Down
26 changes: 24 additions & 2 deletions MCGalaxy/Blocks/Physics/FinitePhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public unsafe static void DoWaterOrLava(Level lvl, ref PhysInfo C) {
if (below == Block.Air) {
lvl.AddUpdate(index, C.Block, C.Data);
lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));
CheckAround(lvl, x, y, z, index);
C.Data.ResetTypes();
} else if (below == Block.StillWater || below == Block.StillLava) {
lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));
CheckAround(lvl, x, y, z, index);
C.Data.ResetTypes();
} else {
const int count = 25;
Expand Down Expand Up @@ -69,14 +71,34 @@ public unsafe static void DoWaterOrLava(Level lvl, ref PhysInfo C) {

if (lvl.IsAirAt(posX, y, posZ, out index) && lvl.AddUpdate(index, C.Block, C.Data)) {
lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));
CheckAround(lvl, x, y, z, index);
C.Data.ResetTypes();
return;
}
}
}

// Not moving - don't retry.
C.Data.Data = PhysicsArgs.RemoveFromChecks;
}
}


static void CheckAround(Level lvl, ushort x, ushort y, ushort z, int newind) {
int index, dx, dy, dz;
for (dx = -2; dx<3; dx++)
for (dy = -2; dy<3; dy++)
for (dz = -2; dz<3; dz++)
{
if (dx==0 && dy==0 && dz==0) continue;

BlockID block = lvl.GetBlock((ushort)(x+dx), (ushort)(y+dy), (ushort)(z+dz), out index);
if (index == newind) continue;

if (block == Block.FiniteWater || block == Block.FiniteLava)
lvl.AddCheck(index);
}
}

static bool Expand(Level lvl, ushort x, ushort y, ushort z) {
int index;
return lvl.IsAirAt(x, y, z, out index) && lvl.AddUpdate(index, Block.FiniteWater, default(PhysicsArgs));
Expand Down Expand Up @@ -123,4 +145,4 @@ public unsafe static void DoFaucet(Level lvl, ref PhysInfo C) {
}
}
}
}
}
14 changes: 12 additions & 2 deletions MCGalaxy/Blocks/Physics/SimpleLiquidPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ public static class SimpleLiquidPhysics {

public static void DoWater(Level lvl, ref PhysInfo C) {
if (lvl.Config.FiniteLiquids) {
FinitePhysics.DoWaterOrLava(lvl, ref C);
} else if (lvl.Config.RandomFlow) {
if (lvl.Config.FiniteHighWater) {
ushort y = C.Y;
if (y >= lvl.Config.EdgeLevel) {
FinitePhysics.DoWaterOrLava(lvl, ref C);
return;
}
} else {
FinitePhysics.DoWaterOrLava(lvl, ref C);
return;
}
}
if (lvl.Config.RandomFlow) {
DoWaterRandowFlow(lvl, ref C);
} else {
DoWaterUniformFlow(lvl, ref C);
Expand Down
2 changes: 2 additions & 0 deletions MCGalaxy/Commands/World/CmdMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ static void PrintMapInfo(Player p, LevelConfig cfg) {
p.Message("&TPhysics settings:");
p.Message(" Finite mode: {0}&S, Random flow: {1}",
GetBool(cfg.FiniteLiquids), GetBool(cfg.RandomFlow));
p.Message(" Finite high water {0}&S",
GetBool(cfg.FiniteHighWater));
p.Message(" Animal hunt AI: {0}&S, Edge water: {1}",
GetBool(cfg.AnimalHuntAI), GetBool(cfg.EdgeWater));
p.Message(" Grass growing: {0}&S, {1} tree growing: {2}",
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/Levels/LevelConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public sealed class LevelConfig : AreaConfig {
public bool LeafDecay;
[ConfigBool("Finite mode", "Physics", false)]
public bool FiniteLiquids;
[ConfigBool("FiniteHighWater", "Physics", false)]
public bool FiniteHighWater;
[ConfigBool("GrowTrees", "Physics", false)]
public bool GrowTrees;
[ConfigBool("Animal AI", "Physics", true)]
Expand Down Expand Up @@ -307,4 +309,4 @@ public void Save(string path, string map) {
}
}
}
}
}
3 changes: 3 additions & 0 deletions MCGalaxy/Levels/LevelOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class LevelOptions {
public const string Goto = "LoadOnGoto", Decay = "LeafDecay", Flow = "RandomFlow", Trees = "GrowTrees";
public const string Chat = "Chat", Guns = "Guns", Buildable = "Buildable", Deletable = "Deletable";
public const string LoadDelay = "LoadDelay", Drawing = "Drawing", Authors = "Authors";
public const string FiniteHighWater = "FiniteHighWater";

public static List<LevelOption> Options = new List<LevelOption>() {
new LevelOption(MOTD, SetMotd, "&HSets the motd for this map. (leave blank to use default motd)"),
Expand All @@ -51,6 +52,7 @@ public static class LevelOptions {
new LevelOption(Fall, SetFall, "&HSets how many blocks you can fall before dying."),
new LevelOption(Drown, SetDrown, "&HSets how long you can stay underwater (in tenths of a second) before drowning."),
new LevelOption(Finite, SetFinite, "&HWhether all liquids are finite."),
new LevelOption(FiniteHighWater, SetFiniteHighWater, "&HWhether Only active water above edge level is finite."),
new LevelOption(AI, SetAI, "&HAI will make animals hunt or flee."),
new LevelOption(Edge, SetEdge, "&HWhether water flows from the map edges."),
new LevelOption(Grass, SetGrass, "&HWhether grass auto grows or not."),
Expand Down Expand Up @@ -126,6 +128,7 @@ static void SetTree(Player p, Level lvl, string value) {
}

static void SetFinite(Player p, Level l, string v) { Toggle(p, l, ref l.Config.FiniteLiquids, "Finite mode"); }
static void SetFiniteHighWater(Player p, Level l, string v) { Toggle(p, l, ref l.Config.FiniteHighWater, "FiniteHighWater"); }
static void SetAI(Player p, Level l, string v) { Toggle(p, l, ref l.Config.AnimalHuntAI, "Animal AI"); }
static void SetEdge(Player p, Level l, string v) { Toggle(p, l, ref l.Config.EdgeWater, "Edge water"); }
static void SetGrass(Player p, Level l, string v) { Toggle(p, l, ref l.Config.GrassGrow, "Growing grass"); }
Expand Down