Beispiel #1
0
 public Terrain(IMultiplayerSession multiplayerSession, IPacketSender packetSender, VisibleCells visibleCells, PacketReceiver packetReceiver)
 {
     this.multiplayerSession = multiplayerSession;
     this.packetSender       = packetSender;
     this.visibleCells       = visibleCells;
     this.packetReceiver     = packetReceiver;
 }
 public void SetEditing(bool editing, bool animated)
 {
     foreach (var cell in VisibleCells.Where(x => x is IEditable).Cast <IEditable>())
     {
         cell.SetEditing(editing, animated);
     }
     _isEditing = editing;
 }
 public MultiplayerClient(string playerId)
 {
     Log.SetLevel(Log.LogLevel.ConsoleInfo | Log.LogLevel.ConsoleDebug);
     visibleCells   = new VisibleCells();
     packetReceiver = new DeferringPacketReceiver(visibleCells);
     client         = new TcpClient(packetReceiver);
     PacketSender   = new PacketSender(client, playerId);
     Logic          = new Logic(PacketSender, visibleCells, packetReceiver);
 }
 public MultiplayerClient(string playerId)
 {
     Log.SetLevel(Log.LogLevel.ConsoleInfo | Log.LogLevel.ConsoleDebug);
     playerName     = playerId;
     visibleCells   = new VisibleCells();
     packetReceiver = new DeferringPacketReceiver(visibleCells);
     client         = new TcpClient(packetReceiver);
     ClientBridge   = new ClientBridge(client);
     PacketSender   = ClientBridge;
     Logic          = new Logic(ClientBridge, visibleCells, packetReceiver);
 }
Beispiel #5
0
        IEnumerable <CellPos> GetCells(CGRect cellFrame)
        {
            int    nexpands      = 0;
            double requiredSize  = 0;
            double availableSize = cellFrame.Width;

            var visibleCells = VisibleCells.ToArray();
            var sizes        = new double [visibleCells.Length];

            // Get the natural size of each child
            for (int i = 0; i < visibleCells.Length; i++)
            {
                var v = visibleCells[i] as NSView;
                var s = v.FittingSize;
                if (s.IsEmpty && SizeToFit(v))
                {
                    s = v.Frame.Size;
                }
                sizes [i]     = s.Width;
                requiredSize += s.Width;
                if (visibleCells [i].Backend.Frontend.Expands)
                {
                    nexpands++;
                }
            }

            double remaining = availableSize - requiredSize;

            if (remaining > 0)
            {
                var expandRemaining = new SizeSplitter(remaining, nexpands);
                for (int i = 0; i < visibleCells.Length; i++)
                {
                    if (visibleCells [i].Backend.Frontend.Expands)
                    {
                        sizes [i] += (nfloat)expandRemaining.NextSizePart();
                    }
                }
            }

            double x = cellFrame.X;

            for (int i = 0; i < visibleCells.Length; i++)
            {
                var cell   = (NSView)visibleCells [i];
                var height = cell.FittingSize.Height;
                var y      = (cellFrame.Height - height) / 2;
                yield return(new CellPos {
                    Cell = cell, Frame = new CGRect(x, y, sizes [i], height)
                });

                x += sizes [i];
            }
        }
Beispiel #6
0
        protected virtual bool LookForFood()
        {
            var eatableCell = VisibleCells.FirstOrDefault(IsCellEatable);

            if (eatableCell != null)
            {
                EnqueueMovingToDestinationObject(eatableCell, Game.Map.GetObjectFromCell(eatableCell));
                _stateQueue.Enqueue(new Eating(this, () => Game.Map.GetObjectFromCell(eatableCell)));

                return(true);
            }

            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// Return the cameras's field of view using the angle
        /// </summary>
        /// <param name="angle"></param>
        /// <returns></returns>
        public override bool[,] GetVision(double angle)
        {
            bool[,] result = new bool[VisibleCells.GetLength(0), VisibleCells.GetLength(1)];
            // Vector representing the direction of the camera
            double[] cameraViewVector =
            {
                Math.Cos(angle),
                Math.Sin(angle)
            };
            // tolerance on the cosinus
            double cosTolerance = Math.Cos(FOV);

            // for each cell
            for (int i = 0; i < result.GetLength(0); i++)
            {
                for (int j = 0; j < result.GetLength(1); j++)
                {
                    if (!VisibleCells[i, j])
                    {
                        result[i, j] = false;
                    }
                    else
                    {
                        // get the vector camera -> cell
                        double dx     = i - X;
                        double dy     = j - Y;
                        double normSq = dx * dx + dy * dy;
                        if (normSq > 0)
                        {
                            // get the cosinus cos = (a.b) / |a||b| (. is the dot product of the vectors)
                            double cos = (dx * cameraViewVector[0] + dy * cameraViewVector[1]) / Math.Sqrt(normSq);
                            // if the cos is above than tolerance, the cell is visible
                            if (cos > cosTolerance)
                            {
                                result[i, j] = true;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #8
0
 public Logic(PacketSender packetSender, VisibleCells visibleCells, DeferringPacketReceiver packetReceiver)
 {
     AI                  = new AI(packetSender);
     Building            = new Building(packetSender);
     Chat                = new Chat(packetSender);
     Entities            = new Entities(packetSender);
     MedkitFabricator    = new MedkitFabricator(packetSender);
     Item                = new Item(packetSender);
     EquipmentSlots      = new EquipmentSlots(packetSender);
     ItemContainers      = new ItemContainers(packetSender);
     Player              = new PlayerLogic(packetSender);
     Power               = new Power(packetSender);
     SimulationOwnership = new SimulationOwnership(packetSender);
     Crafting            = new Crafting(packetSender);
     Cyclops             = new Cyclops(packetSender);
     Interior            = new Interior(packetSender);
     MobileVehicleBay    = new MobileVehicleBay(packetSender);
     Terrain             = new Terrain(packetSender, visibleCells, packetReceiver);
 }
Beispiel #9
0
        private void LookForFoodOrMove()
        {
            _stateQueue.Clear();

            var destination = PositionCell;

            if (LookForFood())
            {
                return;
            }
            var passable = VisibleCells
                           .Where(x => Game.Map.GetObjectFromCell(x)?.IsPassable ?? true)
                           .ToList();

            if (passable.Any())
            {
                destination = passable[Game.Random.Next(passable.Count)];
            }

            EnqueueMovingToDestination(destination);
        }
Beispiel #10
0
        protected override bool LookForFood()
        {
            var destinationObject = VisibleCells.Select(vCell =>
            {
                var t = Game.Map.GetMobileObject(vCell);
                return(t);
            }).OfType <Animal>().FirstOrDefault(mo =>
            {
                return(mo != null && mo.Name == "Hare" && !mo.IsDead);
            });

            if (destinationObject != null)
            {
                _stateQueue.Enqueue(new Pursuing(this, destinationObject as Animal));
                _stateQueue.Enqueue(new Killing(this, () => destinationObject as Animal));

                return(true);
            }

            return(false);
        }
Beispiel #11
0
        public override void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            Bitfield = reader.ReadUInt32();

            reader.BaseStream.Position += 4; // Skip ahead 4 bytes, because this is the CellId. Again. Twice.

            byte   numSurfaces = reader.ReadByte();
            byte   numPortals  = reader.ReadByte();     // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells
            ushort numStabs    = reader.ReadUInt16();   // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw.

            // Read what surfaces are used in this cell
            for (uint i = 0; i < numSurfaces; i++)
            {
                Shadows.Add(0x08000000u | reader.ReadUInt16()); // these are stored in the dat as short values, so we'll make them a full dword
            }
            EnvironmentId = (0x0D000000u | reader.ReadUInt16());

            CellStructure = reader.ReadUInt16();

            Position.Unpack(reader);

            CellPortals.Unpack(reader, numPortals);

            for (uint i = 0; i < numStabs; i++)
            {
                VisibleCells.Add(reader.ReadUInt16());
            }

            if ((Bitfield & 2) != 0)
            {
                StaticObjects.Unpack(reader);
            }

            if ((Bitfield & 8) != 0)
            {
                RestrictionObj = reader.ReadUInt32();
            }
        }
Beispiel #12
0
 public Logic(IClientBridge clientBridge, VisibleCells visibleCells, DeferringPacketReceiver packetReceiver)
 {
     Log.Info("Initializing Multiplayer GameLogic...");
     AI                  = new AI(clientBridge);
     Building            = new Building(clientBridge);
     Chat                = new Chat(clientBridge);
     Entities            = new Entities(clientBridge);
     MedkitFabricator    = new MedkitFabricator(clientBridge);
     Item                = new Item(clientBridge);
     EquipmentSlots      = new EquipmentSlots(clientBridge);
     ItemContainers      = new ItemContainers(clientBridge);
     Player              = new PlayerLogic(clientBridge);
     Power               = new Power(clientBridge);
     SimulationOwnership = new SimulationOwnership(clientBridge);
     Crafting            = new Crafting(clientBridge);
     Cyclops             = new Cyclops(clientBridge);
     Interior            = new Interior(clientBridge);
     MobileVehicleBay    = new MobileVehicleBay(clientBridge);
     Terrain             = new Terrain(clientBridge, visibleCells, packetReceiver);
     PacketSender        = clientBridge;
     ClientBridge        = clientBridge;
     Log.Info("Multiplayer GameLogic Initialized...");
 }
Beispiel #13
0
        protected override bool LookForFood()
        {
            if (!_bundle.IsEmpty)
            {
                _stateQueue.Enqueue(new Eating(this, () => _bundle.GameObjects.FirstOrDefault()));
                return(true);
            }

            if (base.LookForFood())
            {
                return(true);
            }

            var treeCell = VisibleCells.FirstOrDefault(p =>
            {
                var obj = Game.Map.GetObjectFromCell(p);
                if ((obj is Tree && obj.Name == "Apple tree") &&
                    obj.GetBehavior <CollectBehavior <Berry> >()?.CurrentCount > 0)
                {
                    return(true);
                }

                return(false);
            });

            if (treeCell != null)
            {
                EnqueueMovingToDestinationObject(treeCell, Game.Map.GetObjectFromCell(treeCell));

                var appleTree = Game.Map.GetObjectFromCell(treeCell) as Tree;
                _stateQueue.Enqueue(new ShakingTree(this, () => appleTree?.GetBehavior <CollectBehavior <Berry> >()));
                return(true);
            }

            return(false);
        }
Beispiel #14
0
 public Terrain(PacketSender packetSender, VisibleCells visibleCells, DeferringPacketReceiver packetReceiver)
 {
     this.packetSender   = packetSender;
     this.visibleCells   = visibleCells;
     this.packetReceiver = packetReceiver;
 }
Beispiel #15
0
 public override IEnumerable <MobileObject> GetEnemies()
 {
     return(VisibleCells.SelectMany(c => Game.Map.GetMobileObjects().Where(mb => mb.PositionCell == c).Where(mb => mb.Name == "Fox")));
 }
 public DeferringPacketReceiver(VisibleCells visibleCells)
 {
     this.visibleCells = visibleCells;
 }
 public DeferringPacketReceiver(VisibleCells visibleCells)
 {
     this.visibleCells = visibleCells;
     receivedPackets   = new NitroxModel.DataStructures.PriorityQueue <Packet>();
 }