private void NotifyOfCollision(MappedObjectPotentialMove v) { hub.Launch <Message_GameCombat>(new Message_GameCombat(MainMessageKind.CombatMessage, KnownSubkinds.CollisionOccured)); hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.CollisionOccured)); bd2TickAction act = new bd2TickAction(); act.ActionType = LastTickEventType.Collision; CreateNextTurnNotificationMessage(v.Underlying.EngineId, act); }
private string CreateKeyForCollision(MappedObjectPotentialMove moveOne, MappedObjectPotentialMove moveTwo) { if (moveTwo.Underlying.EngineId < moveOne.Underlying.EngineId) { return(moveTwo.Underlying.EngineId.ToString() + moveOne.Underlying.EngineId.ToString()); } else { return(moveOne.Underlying.EngineId.ToString() + moveTwo.Underlying.EngineId.ToString()); } }
private MappedObjectPotentialMove MoveMappableObject(MappedObject v) { b.Assert.True(activeWorld.IsFreeWorldSpace(v.Position), "The bot should not be in a non free space"); MappedObjectPotentialMove result = new MappedObjectPotentialMove(v); result.DesiredPosition = activeWorld.CalculateNextPositionForObject(v.Position, v.Heading); if (!activeWorld.IsFreeWorldSpace(result.DesiredPosition)) { result.HasBoundaryCollision = true; } return(result); }
private void ApplyCollision(MappedObjectPotentialMove v, bool isBoundary = true) { v.HasBoundaryCollision = isBoundary; v.HasCollided = true; NotifyOfCollision(v); v.Underlying.Speed = 0; v.DesiredPosition = v.Underlying.Position; // TODO : Unit test, confirm that on a collision the object does not move on (into the boundary wall); ApplyDamageToObject(v.Underlying.EngineId, BdConstants.CollisionDamageBaseValue, DamageType.Collision); }
private void ApplyCollision(MappedObjectPotentialMove moveOne, MappedObjectPotentialMove moveTwo) { if ((moveOne.DesiredPosition == moveTwo.DesiredPosition) && (moveOne.Underlying.Speed > 0) && (moveTwo.Underlying.Speed > 0)) { b.Verbose.Log("Two bots moving into same space collision - checking speeds @ " + moveOne.DesiredPosition.ToString()); if (moveOne.Underlying.Speed > moveTwo.Underlying.Speed) { moveTwo.DesiredPosition = moveTwo.Underlying.Position; } else { moveOne.DesiredPosition = moveOne.Underlying.Position; } } else { b.Verbose.Log("Passthrough collision (one passes through others current loc) - no one moves @ " + moveOne.DesiredPosition.ToString()); moveOne.DesiredPosition = moveOne.Underlying.Position; moveTwo.DesiredPosition = moveTwo.Underlying.Position; } ApplyCollision(moveOne, false); ApplyCollision(moveTwo, false); }
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 }); } } }