Skip to content

Commit

Permalink
Use named magic constant instead of hardcoding 51/64 everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 21, 2017
1 parent 8541f96 commit 29cf24e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions fCraft/Commands/ModerationCommands.cs
Expand Up @@ -1413,7 +1413,7 @@ static void UnfreezeHandler(Player player, CommandReader cmd)


Vector3I P = player.World.map.HighestFreeSpace(zone.Bounds.XCentre, Vector3I P = player.World.map.HighestFreeSpace(zone.Bounds.XCentre,
zone.Bounds.YCentre, zone.Bounds.ZCentre); zone.Bounds.YCentre, zone.Bounds.ZCentre);
Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + (51 + 1)); Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + Player.CharacterHeight);
if (player.World != null) { if (player.World != null) {
player.LastWorld = player.World; player.LastWorld = player.World;
player.LastPosition = player.Position; player.LastPosition = player.Position;
Expand All @@ -1427,7 +1427,7 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
Random rand = new Random(); Random rand = new Random();
int x = rand.Next(0, player.WorldMap.Width); int x = rand.Next(0, player.WorldMap.Width);
int y = rand.Next(0, player.WorldMap.Length); int y = rand.Next(0, player.WorldMap.Length);
int z = (player.Position.Z - 51) / 32; int z = (player.Position.Z - Player.CharacterHeight) / 32;
Vector3I P = player.WorldMap.HighestFreeSpace(x, y, z); Vector3I P = player.WorldMap.HighestFreeSpace(x, y, z);


if (player.World != null) { if (player.World != null) {
Expand All @@ -1437,7 +1437,7 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
player.TeleportTo(new Position { player.TeleportTo(new Position {
X = (P.X * 32 + 16), X = (P.X * 32 + 16),
Y = (P.Y * 32 + 16), Y = (P.Y * 32 + 16),
Z = (P.Z * 32 + (51 + 1)), Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R, R = player.Position.R,
L = player.Position.L L = player.Position.L
}); });
Expand Down Expand Up @@ -1672,13 +1672,13 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
static void TopHandler(Player player, CommandReader cmd) { static void TopHandler(Player player, CommandReader cmd) {
int x = player.Position.BlockX; int x = player.Position.BlockX;
int y = player.Position.BlockY; int y = player.Position.BlockY;
int z = (player.Position.Z - 51) / 32; int z = (player.Position.Z - Player.CharacterHeight) / 32;
Vector3I P = player.World.map.HighestFreeSpace(x, y, z); Vector3I P = player.World.map.HighestFreeSpace(x, y, z);


player.TeleportTo(new Position { player.TeleportTo(new Position {
X = (P.X * 32 + 16), X = (P.X * 32 + 16),
Y = (P.Y * 32 + 16), Y = (P.Y * 32 + 16),
Z = (P.Z * 32 + (51 + 1)), Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R, R = player.Position.R,
L = player.Position.L L = player.Position.L
}); });
Expand Down
5 changes: 4 additions & 1 deletion fCraft/Player/Player.cs
Expand Up @@ -41,6 +41,9 @@ public sealed partial class Player : IClassy {
/// Note that Player.Console.World is always null, /// Note that Player.Console.World is always null,
/// and that prevents console from calling certain commands (like /TP). </summary> /// and that prevents console from calling certain commands (like /TP). </summary>
public static Player Console, AutoRank; public static Player Console, AutoRank;

/// <summary> Height of in-game player model, necessary as Position works in head position. </summary>
public const byte CharacterHeight = 51;




#region Properties #region Properties
Expand Down Expand Up @@ -267,7 +270,7 @@ public FontFamily LoadFontFamily(string fileName)
bb = new BoundingBox(Vector3I.Zero, Vector3I.Zero); bb = new BoundingBox(Vector3I.Zero, Vector3I.Zero);
bb.XMin = Position.X - 6; bb.XMax = Position.X + 6; bb.XMin = Position.X - 6; bb.XMax = Position.X + 6;
bb.YMin = Position.Y - 6; bb.YMax = Position.Y + 6; bb.YMin = Position.Y - 6; bb.YMax = Position.Y + 6;
bb.ZMin = Position.Z - 51; bb.ZMax = Position.Z; bb.ZMin = Position.Z - CharacterHeight; bb.ZMax = Position.Z;
return bb; return bb;
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion fCraft/Portals/Portal.cs
Expand Up @@ -50,7 +50,7 @@ public class Portal {
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ, TeleportPosR, TeleportPosL); return new Position(TeleportPosX, TeleportPosY, TeleportPosZ, TeleportPosR, TeleportPosL);
} }
public Position tpPosition() { public Position tpPosition() {
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + 64, TeleportPosR, TeleportPosL); return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + Player.CharacterHeight, TeleportPosR, TeleportPosL);
} }


public bool IsInRange(Player player) { public bool IsInRange(Player player) {
Expand Down
2 changes: 1 addition & 1 deletion fCraft/Zone/SpecialZone.Move.cs
Expand Up @@ -66,7 +66,7 @@ public static partial class SpecialZone {
} }


static bool HandleCheckpoint(Player p, Zone zone, ref bool deniedZone, Position newPos) { static bool HandleCheckpoint(Player p, Zone zone, ref bool deniedZone, Position newPos) {
Position centre = new Position(zone.Bounds.XCentre * 32 + 16, zone.Bounds.YCentre * 32 + 16, zone.Bounds.ZCentre * 32 + 64); Position centre = new Position(zone.Bounds.XCentre * 32 + 16, zone.Bounds.YCentre * 32 + 16, zone.Bounds.ZCentre * 32 + Player.CharacterHeight);
if (p.CheckPoint == centre) return false; if (p.CheckPoint == centre) return false;
if (zone.Bounds.Contains(newPos.BlockX, newPos.BlockY, (newPos.Z - 32) / 32)) { if (zone.Bounds.Contains(newPos.BlockX, newPos.BlockY, (newPos.Z - 32) / 32)) {
SendZoneMessage(p, "&aCheckPoint &Sreached! This is now your respawn point."); SendZoneMessage(p, "&aCheckPoint &Sreached! This is now your respawn point.");
Expand Down

0 comments on commit 29cf24e

Please sign in to comment.