Beispiel #1
0
        private void PerformEngineInitOnBot(MappedBot mo)
        {
            SetBotInitialValues(mo);

            b.Verbose.Log("Lanching engine init UI messages, engine informing UI of position etc");

            BotEnterWorldContext bewC = new BotEnterWorldContext();

            bewC.BotName    = mo.Bot.Name;
            bewC.ObjectId   = mo.EngineId;
            bewC.BotVersion = mo.Bot.Version;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.BotEnterWorld)
            {
                RequestContext = bewC,
            });

            MapObjectPositionChangeContext mopcc = new MapObjectPositionChangeContext();

            mopcc.Destination    = mo.Position;
            mopcc.ObjectIdentity = mo.EngineId;
            hub.Launch <Message_Game>(new Message_Game(MainMessageKind.MapObjectMovementChange, KnownSubkinds.BotPositionChange)
            {
                RequestContext = mopcc
            });

#if DEBUG
            b.Info.Log("Extended diagnostics, checking to see whether one bot sits on another one");
            if (!activeWorld.IsFreeWorldSpace(mo.Position))
            {
                b.Info.Log("Object " + mo.EngineId.ToString() + " on top of boundary at " + mo.Position.ToString());
                throw new BdBaseException("Mapped object on top of world boundary (" + mo.Position.ToString() + "), fault.");
            }

            foreach (var v in mappedObjects)
            {
                if (v.EngineId == mo.EngineId)
                {
                    continue;
                }

                if (v.Position == mo.Position)
                {
                    throw new BdBaseException("Cant add a bot on top of an existing mapped object");
                }
            }
#endif
        }
Beispiel #2
0
        private void PerformMovementForTick()
        {
            List <MappedObjectPotentialMove> potentialMoves = new List <MappedObjectPotentialMove>();

            EachActiveBot(bt => {
                MappedObjectPotentialMove res;
                if (SpeedTriggersMoveForTick(Tick, bt.Speed))
                {
                    res = MoveMappableObject(bt);
                }
                else
                {
                    res = new MappedObjectPotentialMove(bt);
                    res.DesiredPosition = bt.Position;
                }
                potentialMoves.Add(res);
            });

            List <string> collisionsAlreadyRecorded = new List <string>();

            b.Verbose.Log("All potential moves are recorded, resolving collisions");
            foreach (var v in potentialMoves)
            {
                if (v.HasBoundaryCollision)
                {
                    ApplyCollision(v);
                }
                else
                {
                    foreach (var p in potentialMoves)
                    {
                        if (v.Underlying.EngineId == p.Underlying.EngineId)
                        {
                            continue;
                        }

                        b.Assert.True(v.Underlying.Position != p.Underlying.Position, "Two objects sat on top of each other problem.  [" + v.Underlying.Position.ToString() + "][" + v.Underlying.Position.ToString() + "]");

                        if ((v.DesiredPosition == p.DesiredPosition) || (v.Underlying.Position == p.DesiredPosition) || (v.DesiredPosition == p.Underlying.Position))
                        {
                            string key = CreateKeyForCollision(v, p);

                            if (!collisionsAlreadyRecorded.Contains(key))
                            {
                                collisionsAlreadyRecorded.Add(key);
                                ApplyCollision(v, p);
                            }
                        }
                    }
                }
            }

            b.Verbose.Log("Move potentials done, finalising");
            foreach (var move in potentialMoves)
            {
                if (move.Underlying.Position != move.DesiredPosition)
                {
                    move.Underlying.Position = move.DesiredPosition;
                    MapObjectPositionChangeContext ctxt = new MapObjectPositionChangeContext();
                    ctxt.ObjectIdentity = move.Underlying.EngineId;
                    ctxt.Destination    = move.DesiredPosition;

                    bd2TickAction act = new bd2TickAction();
                    act.ActionType = LastTickEventType.Moved;
                    CreateNextTurnNotificationMessage(move.Underlying.EngineId, act);

                    hub.Launch <Message_Game>(new Message_Game(MainMessageKind.MapObjectMovementChange, KnownSubkinds.BotPositionChange)
                    {
                        RequestContext = ctxt
                    });
                }
            }
        }