Example #1
0
 public bool Equals(TimedLocation Other)
 {
     if (this.Loc == Other.Loc && this.Time == Other.Time)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        public void Update(GameTime gameTime)
        {
            AllFutureMoves = new Dictionary <TimedLocation, int>();
            //the first enemy can't crash into themselves
            if (mapRef.CurrentEnemies.Count > 0)
            {
                foreach (KeyValuePair <int, Enemy> T in mapRef.CurrentEnemies)
                {
                    int I = T.Key;
                    for (int J = 0; J < Math.Min(mapRef.CurrentEnemies[I].CurrentBS.myPlannedMoves.Count, 16); J++)//only looks 15 moves into the future at most
                    {
                        TimedLocation Move = new TimedLocation(mapRef.CurrentEnemies[I].CurrentBS.myPlannedMoves[J], J);
                        if (!Move.MatchInDict(AllFutureMoves, I) && !Move.OneEarlier.MatchInDict(AllFutureMoves, I) && !Move.OneLater.MatchInDict(AllFutureMoves, I))
                        {
                            AllFutureMoves.Add(Move, I);
                        }
                        else
                        {//collision chance here
                            int     I_Priority = I;
                            int     Other_Priority;
                            Vector2 LocOfColl = Move.Loc;
                            int     Other_Priority_MovesToColl;
                            if (Move.MatchInDict(AllFutureMoves, I))
                            {
                                Other_Priority             = AllFutureMoves[Move.DictPos(AllFutureMoves)];
                                Other_Priority_MovesToColl = Move.Time;
                            }
                            else if (Move.OneEarlier.MatchInDict(AllFutureMoves, I))
                            {
                                Other_Priority             = AllFutureMoves[Move.OneEarlier.DictPos(AllFutureMoves)];
                                Other_Priority_MovesToColl = Move.OneEarlier.Time;
                            }
                            else if (Move.OneLater.MatchInDict(AllFutureMoves, I))
                            {
                                Other_Priority             = AllFutureMoves[Move.OneLater.DictPos(AllFutureMoves)];
                                Other_Priority_MovesToColl = Move.OneLater.Time;
                            }
                            else
                            {
                                throw new Exception("Triggered despite fulfilling none of the categories");
                            }

                            //Check that they're not just near each other and going in the same direction

                            if (!AreTheyJustFollowingEachOther(I_Priority, J, Other_Priority, Other_Priority_MovesToColl))
                            {
                                if (I < Other_Priority)
                                {//The Target of index Other_Priority yields
                                    if (!mapRef.CurrentEnemies[Other_Priority].CurrentBS.WarnOfFriendlyCollision
                                            (I, Other_Priority, LocOfColl, mapRef.CurrentEnemies[I].CurrentBS.myPlannedMoves, mapRef.CurrentEnemies[I].MovingToTilePosition,
                                            Other_Priority_MovesToColl, J))
                                    {//if is found to be impossible for that individual, the other tries
                                        if (!mapRef.CurrentEnemies[I_Priority].CurrentBS.WarnOfFriendlyCollision
                                                (Other_Priority, I, LocOfColl, mapRef.CurrentEnemies[Other_Priority].CurrentBS.myPlannedMoves, mapRef.CurrentEnemies[Other_Priority].MovingToTilePosition,
                                                J, Other_Priority_MovesToColl))
                                        {
                                            //throw new Exception("Collision could not be averted");
                                        }
                                    }
                                }
                                else if (Other_Priority < I)
                                {// Enemy of Index I yields
                                    if (!mapRef.CurrentEnemies[I_Priority].CurrentBS.WarnOfFriendlyCollision
                                            (Other_Priority, I, LocOfColl, mapRef.CurrentEnemies[Other_Priority].CurrentBS.myPlannedMoves, mapRef.CurrentEnemies[Other_Priority].MovingToTilePosition,
                                            J, Other_Priority_MovesToColl))
                                    {
                                        if (!mapRef.CurrentEnemies[Other_Priority].CurrentBS.WarnOfFriendlyCollision
                                                (I, Other_Priority, LocOfColl, mapRef.CurrentEnemies[I].CurrentBS.myPlannedMoves, mapRef.CurrentEnemies[I].MovingToTilePosition,
                                                Other_Priority_MovesToColl, J))
                                        {
                                            //throw new Exception("Collision could not be averted");
                                        }
                                    }
                                }
                                else
                                {
                                    throw new Exception("Somehow called the same enemy against itself");
                                }
                                break;//as the path has been changed somehow, any more of this data is useless anyway.
                            }
                        }
                    }
                }
            }
            //now monitor PassCalls
            for (int I = 0; I < PassCalls.Count; I++)
            {
                if (!mapRef.CurrentEnemies.ContainsKey(PassCalls[I].EnemyWaiting))
                {//the enemy that should be waiting no longer exists - delete the passcall
                    PassCalls.RemoveAt(I);
                    I--;
                    continue;
                }
                else if (!mapRef.CurrentEnemies.ContainsKey(PassCalls[I].EnemyWatching))
                {                                               //the enemy that was being waited for no longer exists - begin broadcast until reception as the way is therefore clear by default
                    PassCalls[I].BroadcastuntilReceived = true; //begin broadcast until reception
                }
                else
                {
                    if (!mapRef.CurrentEnemies[PassCalls[I].EnemyWatching].CurrentBS.myPlannedMoves.Contains(PassCalls[I].TileToPass) &&
                        mapRef.CurrentEnemies[PassCalls[I].EnemyWatching].CurrentBS.myPlannedMoves.Count > 0 &&
                        mapRef.CurrentEnemies[PassCalls[I].EnemyWatching].TilePosition != PassCalls[I].TileToPass &&
                        mapRef.CurrentEnemies[PassCalls[I].EnemyWatching].MovingToTilePosition != PassCalls[I].TileToPass)
                    {
                        PassCalls[I].BroadcastuntilReceived = true;//begin broadcast until reception
                    }
                }
                if (PassCalls[I].BroadcastuntilReceived)
                {
                    //The other has passed; the Enemy may continue

                    if (mapRef.CurrentEnemies[PassCalls[I].EnemyWaiting].CurrentBS.GiveGoAhead())
                    {//if the enemy has successfully been given the go ahead
                        CollisionCheck.Instance.RemoveOverrule(PassCalls[I].LaybyLocation);
                        PassCalls.RemoveAt(I);

                        I--;
                        if (PassCalls.Count == 0)
                        {
                            CollisionCheck.Instance.ClearAllOverridesForGivenNewValue(4);
                        }
                    }
                }
            }
        }