void LoadMap(string path)
        {
            IMapFileFormat mapFile = null;

            if (path.EndsWith(".dat"))
            {
                mapFile = new MapDat();
            }
            else if (path.EndsWith(".fcm"))
            {
                mapFile = new MapFcm3();
            }
            else if (path.EndsWith(".cw"))
            {
                mapFile = new MapCw();
            }

            try {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    int width, height, length;
                    game.Map.Reset();

                    byte[] blocks = mapFile.Load(fs, game, out width, out height, out length);
                    game.Map.SetData(blocks, width, height, length);
                    game.MapEvents.RaiseOnNewMapLoaded();

                    LocalPlayer    p      = game.LocalPlayer;
                    LocationUpdate update = LocationUpdate.MakePos(p.SpawnPoint, false);
                    p.SetLocation(update, false);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("loading map", ex);
                game.Chat.Add("&e/client loadmap: Failed to load map \"" + path + "\"");
            }
        }
Example #2
0
        static bool PushbackPlace(Game game, AABB blockBB)
        {
            LocalPlayer p = game.LocalPlayer;
            Vector3     curPos = p.Position, adjPos = p.Position;


            // Offset position by the closest face
            PickedPos selected = game.SelectedPos;

            if (selected.Face == BlockFace.XMax)
            {
                adjPos.X = blockBB.Max.X + 0.5f;
            }
            else if (selected.Face == BlockFace.ZMax)
            {
                adjPos.Z = blockBB.Max.Z + 0.5f;
            }
            else if (selected.Face == BlockFace.XMin)
            {
                adjPos.X = blockBB.Min.X - 0.5f;
            }
            else if (selected.Face == BlockFace.ZMin)
            {
                adjPos.Z = blockBB.Min.Z - 0.5f;
            }
            else if (selected.Face == BlockFace.YMax)
            {
                adjPos.Y = blockBB.Min.Y + 1 + Entity.Adjustment;
            }
            else if (selected.Face == BlockFace.YMin)
            {
                adjPos.Y = blockBB.Min.Y - p.Size.Y - Entity.Adjustment;
            }

            // exclude exact map boundaries, otherwise player can get stuck outside map
            bool validPos =
                adjPos.X > 0 && adjPos.Y >= 0 && adjPos.Z > 0 &&
                adjPos.X < game.World.Width && adjPos.Z < game.World.Length;

            if (!validPos)
            {
                return(false);
            }

            p.Position = adjPos;
            if (!p.Hacks.Noclip && p.TouchesAny(p.Bounds, touchesAnySolid))
            {
                p.Position = curPos;
                return(false);
            }

            p.Position = curPos;
            LocationUpdate update = LocationUpdate.MakePos(adjPos, false);

            p.SetLocation(update, false);
            return(true);
        }
Example #3
0
        static bool PushbackPlace(Game game, AABB blockBB)
        {
            Vector3 newP = game.LocalPlayer.Position;
            Vector3 oldP = game.LocalPlayer.Position;

            // Offset position by the closest face
            PickedPos selected = game.SelectedPos;

            if (selected.Face == BlockFace.XMax)
            {
                newP.X = blockBB.Max.X + 0.5f;
            }
            else if (selected.Face == BlockFace.ZMax)
            {
                newP.Z = blockBB.Max.Z + 0.5f;
            }
            else if (selected.Face == BlockFace.XMin)
            {
                newP.X = blockBB.Min.X - 0.5f;
            }
            else if (selected.Face == BlockFace.ZMin)
            {
                newP.Z = blockBB.Min.Z - 0.5f;
            }
            else if (selected.Face == BlockFace.YMax)
            {
                newP.Y = blockBB.Min.Y + 1 + Entity.Adjustment;
            }
            else if (selected.Face == BlockFace.YMin)
            {
                newP.Y = blockBB.Min.Y - game.LocalPlayer.Size.Y - Entity.Adjustment;
            }

            Vector3I newLoc   = Vector3I.Floor(newP);
            bool     validPos = newLoc.X >= 0 && newLoc.Y >= 0 && newLoc.Z >= 0 &&
                                newLoc.X < game.World.Width && newP.Z < game.World.Length;

            if (!validPos)
            {
                return(false);
            }

            game.LocalPlayer.Position = newP;
            if (!game.LocalPlayer.Hacks.Noclip &&
                game.LocalPlayer.TouchesAny(b => game.BlockInfo.Collide[b] == CollideType.Solid))
            {
                game.LocalPlayer.Position = oldP;
                return(false);
            }

            game.LocalPlayer.Position = oldP;
            LocationUpdate update = LocationUpdate.MakePos(newP, false);

            game.LocalPlayer.SetLocation(update, false);
            return(true);
        }
        void HandleRelPositionUpdate()
        {
            byte  playerId = reader.ReadUInt8();
            float x        = reader.ReadInt8() / 32f;
            float y        = reader.ReadInt8() / 32f;
            float z        = reader.ReadInt8() / 32f;

            LocationUpdate update = LocationUpdate.MakePos(x, y, z, true);

            UpdateLocation(playerId, update, true);
        }
        bool PushbackPlace(PickedPos selected, BoundingBox blockBB)
        {
            Vector3 newP = game.LocalPlayer.Position;
            Vector3 oldP = game.LocalPlayer.Position;

            // Offset position by the closest face
            if (selected.BlockFace == CpeBlockFace.XMax)
            {
                newP.X = blockBB.Max.X + 0.5f;
            }
            else if (selected.BlockFace == CpeBlockFace.ZMax)
            {
                newP.Z = blockBB.Max.Z + 0.5f;
            }
            else if (selected.BlockFace == CpeBlockFace.XMin)
            {
                newP.X = blockBB.Min.X - 0.5f;
            }
            else if (selected.BlockFace == CpeBlockFace.ZMin)
            {
                newP.Z = blockBB.Min.Z - 0.5f;
            }
            else if (selected.BlockFace == CpeBlockFace.YMax)
            {
                newP.Y = blockBB.Min.Y + 1 + Entity.Adjustment;
            }
            else if (selected.BlockFace == CpeBlockFace.YMin)
            {
                newP.Y = blockBB.Min.Y - game.LocalPlayer.CollisionSize.Y - Entity.Adjustment;
            }

            Vector3I newLoc   = Vector3I.Floor(newP);
            bool     validPos = newLoc.X >= 0 && newLoc.Y >= 0 && newLoc.Z >= 0 &&
                                newLoc.X < game.Map.Width && newP.Z < game.Map.Length;

            if (!validPos)
            {
                return(false);
            }

            game.LocalPlayer.Position = newP;
            if (!game.LocalPlayer.noClip && game.LocalPlayer.TouchesAny(CannotPassThrough))
            {
                game.LocalPlayer.Position = oldP;
                return(false);
            }

            game.LocalPlayer.Position = oldP;
            LocationUpdate update = LocationUpdate.MakePos(newP, false);

            game.LocalPlayer.SetLocation(update, false);
            return(true);
        }
        bool CheckIsFree(PickedPos selected, byte block)
        {
            Vector3     pos  = (Vector3)selected.TranslatedPos;
            BlockInfo   info = game.BlockInfo;
            LocalPlayer p    = game.LocalPlayer;

            if (info.Collide[block] != CollideType.Solid)
            {
                return(true);
            }
            if (IntersectsOtherPlayers(pos, block))
            {
                return(false);
            }

            AABB blockBB = new AABB(pos + info.MinBB[block], pos + info.MaxBB[block]);
            // NOTE: We need to also test against nextPos here, because otherwise
            // we can fall through the block as collision is performed against nextPos
            AABB localBB = AABB.Make(p.Position, p.Size);

            localBB.Min.Y = Math.Min(p.nextPos.Y, localBB.Min.Y);

            if (p.Hacks.Noclip || !localBB.Intersects(blockBB))
            {
                return(true);
            }
            if (p.Hacks.CanPushbackBlocks && p.Hacks.PushbackPlacing && p.Hacks.Enabled)
            {
                return(PushbackPlace(selected, blockBB));
            }

            localBB.Min.Y += 0.25f + Entity.Adjustment;
            if (localBB.Intersects(blockBB))
            {
                return(false);
            }

            // Push player up if they are jumping and trying to place a block underneath them.
            Vector3 next = game.LocalPlayer.nextPos;

            next.Y = pos.Y + game.BlockInfo.MaxBB[block].Y + Entity.Adjustment;
            LocationUpdate update = LocationUpdate.MakePos(next, false);

            game.LocalPlayer.SetLocation(update, false);
            return(true);
        }
Example #7
0
        internal bool HandleKeyDown(Key key)
        {
            KeyMap keys = game.InputHandler.Keys;

            if (key == keys[KeyBinding.Respawn] && CanRespawn && HacksEnabled)
            {
                Vector3I p = Vector3I.Floor(SpawnPoint);
                if (game.Map.IsValidPos(p))
                {
                    // Spawn player at highest valid position.
                    for (int y = p.Y; y <= game.Map.Height; y++)
                    {
                        byte block1 = GetPhysicsBlockId(p.X, y, p.Z);
                        byte block2 = GetPhysicsBlockId(p.X, y + 1, p.Z);
                        if (info.CollideType[block1] != BlockCollideType.Solid &&
                            info.CollideType[block2] != BlockCollideType.Solid)
                        {
                            p.Y = y;
                            break;
                        }
                    }
                }
                Vector3        spawn  = (Vector3)p + new Vector3(0.5f, 0.01f, 0.5f);
                LocationUpdate update = LocationUpdate.MakePos(spawn, false);
                SetLocation(update, false);
            }
            else if (key == keys[KeyBinding.SetSpawn] && CanRespawn && HacksEnabled)
            {
                SpawnPoint = Position;
            }
            else if (key == keys[KeyBinding.Fly] && CanFly && HacksEnabled)
            {
                flying = !flying;
            }
            else if (key == keys[KeyBinding.NoClip] && CanNoclip && HacksEnabled)
            {
                noClip = !noClip;
            }
            else
            {
                return(false);
            }
            return(true);
        }
        bool CheckIsFree(PickedPos selected, byte newBlock)
        {
            Vector3 pos = (Vector3)selected.TranslatedPos;

            if (!CannotPassThrough(newBlock))
            {
                return(true);
            }
            if (IntersectsOtherPlayers(pos, newBlock))
            {
                return(false);
            }

            AABB blockBB = new AABB(pos + game.BlockInfo.MinBB[newBlock],
                                    pos + game.BlockInfo.MaxBB[newBlock]);
            AABB localBB = game.LocalPlayer.CollisionBounds;

            if (game.LocalPlayer.Hacks.Noclip || !localBB.Intersects(blockBB))
            {
                return(true);
            }
            HacksComponent hacks = game.LocalPlayer.Hacks;

            if (hacks.CanPushbackBlocks && hacks.PushbackPlacing && hacks.Enabled)
            {
                return(PushbackPlace(selected, blockBB));
            }

            localBB.Min.Y += 0.25f + Entity.Adjustment;
            if (localBB.Intersects(blockBB))
            {
                return(false);
            }

            // Push player up if they are jumping and trying to place a block underneath them.
            Vector3 p = game.LocalPlayer.Position;

            p.Y = pos.Y + game.BlockInfo.MaxBB[newBlock].Y + Entity.Adjustment;
            LocationUpdate update = LocationUpdate.MakePos(p, false);

            game.LocalPlayer.SetLocation(update, false);
            return(true);
        }