Beispiel #1
0
        private void RepositionItems(List <Location> ItemLocs, string lvl)
        {
            if (IsDevelopmentModeOn)
            {
                PlaceAllItems(ItemLocs);
                return;
            }

            if (ItemLocs.Count > 0)
            {
                //We are currently looking guns + ammo
                List <TR2Entities> targetents = TR2EntityUtilities.GetListOfGunTypes();
                targetents.AddRange(TR2EntityUtilities.GetListOfAmmoTypes());

                //And also key items...
                if (IncludeKeyItems)
                {
                    targetents.AddRange(TR2EntityUtilities.GetListOfKeyItemTypes());
                }

                //It's important to now start zoning key items as softlocks must be avoided.
                ZonedLocationCollection ZonedLocations = new ZonedLocationCollection();
                ZonedLocations.PopulateZones(lvl, ItemLocs, ZonePopulationMethod.KeyPuzzleQuestOnly);

                for (int i = 0; i < _levelInstance.Entities.Count(); i++)
                {
                    if (targetents.Contains((TR2Entities)_levelInstance.Entities[i].TypeID) && (i != _unarmedLevelPistolIndex))
                    {
                        Location RandomLocation        = new Location();
                        bool     FoundPossibleLocation = false;

                        if (TR2EntityUtilities.IsKeyItemType((TR2Entities)_levelInstance.Entities[i].TypeID))
                        {
                            TR2Entities type = (TR2Entities)_levelInstance.Entities[i].TypeID;

                            // Apply zoning for key items
                            switch (type)
                            {
                            case TR2Entities.Puzzle1_S_P:
                                if (ZonedLocations.Puzzle1Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Puzzle2_S_P:
                                if (ZonedLocations.Puzzle2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle2Zone[_generator.Next(0, ZonedLocations.Puzzle2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Puzzle3_S_P:
                                if (ZonedLocations.Puzzle3Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle3Zone[_generator.Next(0, ZonedLocations.Puzzle3Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Puzzle4_S_P:
                                if (ZonedLocations.Puzzle4Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle4Zone[_generator.Next(0, ZonedLocations.Puzzle4Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key1_S_P:
                                if (ZonedLocations.Key1Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key1Zone[_generator.Next(0, ZonedLocations.Key1Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key2_S_P:
                                if (ZonedLocations.Key2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key2Zone[_generator.Next(0, ZonedLocations.Key2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key3_S_P:
                                if (ZonedLocations.Key3Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key3Zone[_generator.Next(0, ZonedLocations.Key3Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key4_S_P:
                                if (ZonedLocations.Key4Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key4Zone[_generator.Next(0, ZonedLocations.Key4Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Quest1_S_P:
                                if (ZonedLocations.Quest1Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Quest1Zone[_generator.Next(0, ZonedLocations.Quest1Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Quest2_S_P:
                                if (ZonedLocations.Quest2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Quest2Zone[_generator.Next(0, ZonedLocations.Quest2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            //Place standard items as normal for now
                            RandomLocation        = ItemLocs[_generator.Next(0, ItemLocs.Count)];
                            FoundPossibleLocation = true;
                        }

                        if (FoundPossibleLocation)
                        {
                            Location GlobalizedRandomLocation = SpatialConverters.TransformToLevelSpace(RandomLocation, _levelInstance.Rooms[RandomLocation.Room].Info);

                            _levelInstance.Entities[i].Room       = Convert.ToInt16(GlobalizedRandomLocation.Room);
                            _levelInstance.Entities[i].X          = GlobalizedRandomLocation.X;
                            _levelInstance.Entities[i].Y          = GlobalizedRandomLocation.Y;
                            _levelInstance.Entities[i].Z          = GlobalizedRandomLocation.Z;
                            _levelInstance.Entities[i].Intensity1 = -1;
                            _levelInstance.Entities[i].Intensity2 = -1;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void PlaceAllSecrets(TR23ScriptedLevel lvl, List <Location> LevelLocations)
        {
            ZonedLocationCollection ZonedLocations = new ZonedLocationCollection();

            ZonedLocations.PopulateZones(lvl.LevelFileBaseName.ToUpper(), LevelLocations, ZonePopulationMethod.SecretsOnly);

            List <TR2Entity> ents = _levelInstance.Entities.ToList();

            bool SecretsRemain = true;

            while (SecretsRemain)
            {
                int i;

                //Remove any existing secrets
                for (i = 0; i < ents.Count; i++)
                {
                    if (ents[i].TypeID == (int)TR2Entities.StoneSecret_S_P ||
                        ents[i].TypeID == (int)TR2Entities.JadeSecret_S_P ||
                        ents[i].TypeID == (int)TR2Entities.GoldSecret_S_P)
                    {
                        ents.RemoveAt(i);
                        i--;
                        break;
                    }
                }
                ;

                //We have exhausted the list and found nothing, if we exited early try again
                if (i == ents.Count)
                {
                    SecretsRemain = false;
                }
            }

            //Add new entities
            foreach (Location loc in ZonedLocations.StoneZone)
            {
                Location copy = SpatialConverters.TransformToLevelSpace(loc, _levelInstance.Rooms[loc.Room].Info);

                ents.Add(new TR2Entity
                {
                    TypeID     = (int)TR2Entities.StoneSecret_S_P,
                    Room       = Convert.ToInt16(copy.Room),
                    X          = copy.X,
                    Y          = copy.Y,
                    Z          = copy.Z,
                    Angle      = 0,
                    Intensity1 = -1,
                    Intensity2 = -1,
                    Flags      = 0
                });
            }

            foreach (Location loc in ZonedLocations.JadeZone)
            {
                Location copy = SpatialConverters.TransformToLevelSpace(loc, _levelInstance.Rooms[loc.Room].Info);

                ents.Add(new TR2Entity
                {
                    TypeID     = (int)TR2Entities.JadeSecret_S_P,
                    Room       = Convert.ToInt16(copy.Room),
                    X          = copy.X,
                    Y          = copy.Y,
                    Z          = copy.Z,
                    Angle      = 0,
                    Intensity1 = -1,
                    Intensity2 = -1,
                    Flags      = 0
                });
            }

            foreach (Location loc in ZonedLocations.GoldZone)
            {
                Location copy = SpatialConverters.TransformToLevelSpace(loc, _levelInstance.Rooms[loc.Room].Info);

                ents.Add(new TR2Entity
                {
                    TypeID     = (int)TR2Entities.GoldSecret_S_P,
                    Room       = Convert.ToInt16(copy.Room),
                    X          = copy.X,
                    Y          = copy.Y,
                    Z          = copy.Z,
                    Angle      = 0,
                    Intensity1 = -1,
                    Intensity2 = -1,
                    Flags      = 0
                });
            }

            _levelInstance.NumEntities = (uint)ents.Count;
            _levelInstance.Entities    = ents.ToArray();
        }
Beispiel #3
0
        private void RandomizeSecrets(List <Location> LevelLocations, TR23ScriptedLevel lvl)
        {
            if (LevelLocations.Count > 2)
            {
                if (IsDevelopmentModeOn)
                {
                    PlaceAllSecrets(lvl, LevelLocations);
                    return;
                }

                //Apply zoning to the locations to ensure they are spread out.
                ZonedLocationCollection ZonedLocations = new ZonedLocationCollection();

                ZonedLocations.PopulateZones(lvl.LevelFileBaseName.ToUpper(), LevelLocations, ZonePopulationMethod.SecretsOnly);

                Location GoldSecret;
                Location JadeSecret;
                Location StoneSecret;

                //Find suitable locations, ensuring they are zoned, do not share a room and difficulty.
                //Location = ZoneLocations[ZoneGroup][LocationInZoneGroup]
                do
                {
                    GoldSecret = ZonedLocations.GoldZone[_generator.Next(0, ZonedLocations.GoldZone.Count)];
                } while (GoldSecret.Difficulty == Difficulty.Hard && AllowHard == false);


                do
                {
                    JadeSecret = ZonedLocations.JadeZone[_generator.Next(0, ZonedLocations.JadeZone.Count)];
                } while ((JadeSecret.Room == GoldSecret.Room) ||
                         (JadeSecret.Difficulty == Difficulty.Hard && AllowHard == false));

                do
                {
                    StoneSecret = ZonedLocations.StoneZone[_generator.Next(0, ZonedLocations.StoneZone.Count)];
                } while ((StoneSecret.Room == GoldSecret.Room) ||
                         (StoneSecret.Room == JadeSecret.Room) ||
                         (StoneSecret.Difficulty == Difficulty.Hard && AllowHard == false));

                //Due to TRMod only accepting room space coords entities are actually stored in level space. So include some
                //calls to support a transformation of any locations that are specified in room space to maintain backwards compatbility
                //with older locations and support locations that are specified in both level or room space.
                GoldSecret  = SpatialConverters.TransformToLevelSpace(GoldSecret, _levelInstance.Rooms[GoldSecret.Room].Info);
                JadeSecret  = SpatialConverters.TransformToLevelSpace(JadeSecret, _levelInstance.Rooms[JadeSecret.Room].Info);
                StoneSecret = SpatialConverters.TransformToLevelSpace(StoneSecret, _levelInstance.Rooms[StoneSecret.Room].Info);

                //Does the level contain the entities?
                int GoldIndex  = Array.FindIndex(_levelInstance.Entities, ent => (ent.TypeID == (short)TR2Entities.GoldSecret_S_P));
                int JadeIndex  = Array.FindIndex(_levelInstance.Entities, ent => (ent.TypeID == (short)TR2Entities.JadeSecret_S_P));
                int StoneIndex = Array.FindIndex(_levelInstance.Entities, ent => (ent.TypeID == (short)TR2Entities.StoneSecret_S_P));

                //Check if we could find instances of the secret entities, if not, we need to add not edit.
                if (GoldIndex != -1)
                {
                    _levelInstance.Entities[GoldIndex].Room = Convert.ToInt16(GoldSecret.Room);
                    _levelInstance.Entities[GoldIndex].X    = GoldSecret.X;
                    _levelInstance.Entities[GoldIndex].Y    = GoldSecret.Y;
                    _levelInstance.Entities[GoldIndex].Z    = GoldSecret.Z;
                }
                else
                {
                    TR2Entity GoldEntity = new TR2Entity
                    {
                        TypeID     = (int)TR2Entities.GoldSecret_S_P,
                        Room       = Convert.ToInt16(GoldSecret.Room),
                        X          = GoldSecret.X,
                        Y          = GoldSecret.Y,
                        Z          = GoldSecret.Z,
                        Angle      = 0,
                        Intensity1 = -1,
                        Intensity2 = -1,
                        Flags      = 0
                    };

                    List <TR2Entity> ents = _levelInstance.Entities.ToList();
                    ents.Add(GoldEntity);
                    _levelInstance.Entities = ents.ToArray();
                    _levelInstance.NumEntities++;
                }

                if (JadeIndex != -1)
                {
                    _levelInstance.Entities[JadeIndex].Room = Convert.ToInt16(JadeSecret.Room);
                    _levelInstance.Entities[JadeIndex].X    = JadeSecret.X;
                    _levelInstance.Entities[JadeIndex].Y    = JadeSecret.Y;
                    _levelInstance.Entities[JadeIndex].Z    = JadeSecret.Z;
                }
                else
                {
                    TR2Entity JadeEntity = new TR2Entity
                    {
                        TypeID     = (int)TR2Entities.JadeSecret_S_P,
                        Room       = Convert.ToInt16(JadeSecret.Room),
                        X          = JadeSecret.X,
                        Y          = JadeSecret.Y,
                        Z          = JadeSecret.Z,
                        Angle      = 0,
                        Intensity1 = -1,
                        Intensity2 = -1,
                        Flags      = 0
                    };

                    List <TR2Entity> ents = _levelInstance.Entities.ToList();
                    ents.Add(JadeEntity);
                    _levelInstance.Entities = ents.ToArray();
                    _levelInstance.NumEntities++;
                }

                if (StoneIndex != -1)
                {
                    _levelInstance.Entities[StoneIndex].Room = Convert.ToInt16(StoneSecret.Room);
                    _levelInstance.Entities[StoneIndex].X    = StoneSecret.X;
                    _levelInstance.Entities[StoneIndex].Y    = StoneSecret.Y;
                    _levelInstance.Entities[StoneIndex].Z    = StoneSecret.Z;
                }
                else
                {
                    TR2Entity StoneEntity = new TR2Entity
                    {
                        TypeID     = (int)TR2Entities.StoneSecret_S_P,
                        Room       = Convert.ToInt16(StoneSecret.Room),
                        X          = StoneSecret.X,
                        Y          = StoneSecret.Y,
                        Z          = StoneSecret.Z,
                        Angle      = 0,
                        Intensity1 = -1,
                        Intensity2 = -1,
                        Flags      = 0
                    };

                    List <TR2Entity> ents = _levelInstance.Entities.ToList();
                    ents.Add(StoneEntity);
                    _levelInstance.Entities = ents.ToArray();
                    _levelInstance.NumEntities++;
                }
            }
        }
Beispiel #4
0
        private void RepositionItems(List <Location> ItemLocs)
        {
            if (IsDevelopmentModeOn)
            {
                PlaceAllItems(ItemLocs);
                return;
            }

            if (ItemLocs.Count > 0)
            {
                //We are currently looking guns + ammo
                List <TR2Entities> targetents = TR2EntityUtilities.GetListOfGunTypes();
                targetents.AddRange(TR2EntityUtilities.GetListOfAmmoTypes());

                //And also key items...
                if (IncludeKeyItems)
                {
                    targetents.AddRange(TR2EntityUtilities.GetListOfKeyItemTypes());
                }

                //It's important to now start zoning key items as softlocks must be avoided.
                ZonedLocationCollection ZonedLocations = new ZonedLocationCollection();
                ZonedLocations.PopulateZones(_levelInstance.Name, ItemLocs, ZonePopulationMethod.KeyPuzzleQuestOnly);

                for (int i = 0; i < _levelInstance.Data.Entities.Count(); i++)
                {
                    if (targetents.Contains((TR2Entities)_levelInstance.Data.Entities[i].TypeID) && (i != _unarmedLevelPistolIndex))
                    {
                        Location RandomLocation        = new Location();
                        bool     FoundPossibleLocation = false;

                        if (TR2EntityUtilities.IsKeyItemType((TR2Entities)_levelInstance.Data.Entities[i].TypeID))
                        {
                            TR2Entities type = (TR2Entities)_levelInstance.Data.Entities[i].TypeID;

                            // Apply zoning for key items
                            switch (type)
                            {
                            case TR2Entities.Puzzle1_S_P:
                                if (ZonedLocations.Puzzle1Zone.Count > 0)
                                {
                                    if (_levelInstance.Name == LevelNames.DA)
                                    {
                                        int burnerChipID  = 120;
                                        int consoleChipID = 7;

                                        RandomLocation = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];

                                        //Special case - multiple chips
                                        if (i == burnerChipID)
                                        {
                                            //Burner Chip
                                            List <int> AllowedBurnerRooms = new List <int>()
                                            {
                                                13, 14, 15, 16, 21, 22, 23, 24, 25, 26, 29, 30, 32, 34, 75, 80, 83, 84, 85, 86, 87, 88, 89
                                            };

                                            while (!AllowedBurnerRooms.Contains(RandomLocation.Room))
                                            {
                                                RandomLocation = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];
                                            }

                                            FoundPossibleLocation = true;
                                        }
                                        else if (i == consoleChipID)
                                        {
                                            //Center Console Chip
                                            List <int> AllowedConsoleRooms = new List <int>()
                                            {
                                                2, 12, 13, 14, 15, 16, 17, 21, 22, 23, 24, 25, 26, 29, 30, 32, 34, 35, 64, 65, 66, 68, 69, 70, 75, 80, 82, 83, 84, 85, 86, 87, 88, 89
                                            };

                                            while (!AllowedConsoleRooms.Contains(RandomLocation.Room))
                                            {
                                                RandomLocation = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];
                                            }

                                            FoundPossibleLocation = true;
                                        }
                                        else
                                        {
                                            RandomLocation        = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];
                                            FoundPossibleLocation = true;
                                        }
                                    }
                                    else
                                    {
                                        RandomLocation        = ZonedLocations.Puzzle1Zone[_generator.Next(0, ZonedLocations.Puzzle1Zone.Count)];
                                        FoundPossibleLocation = true;
                                    }
                                }
                                break;

                            case TR2Entities.Puzzle2_S_P:
                                if (ZonedLocations.Puzzle2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle2Zone[_generator.Next(0, ZonedLocations.Puzzle2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Puzzle3_S_P:
                                if (ZonedLocations.Puzzle3Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle3Zone[_generator.Next(0, ZonedLocations.Puzzle3Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Puzzle4_S_P:
                                if (ZonedLocations.Puzzle4Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Puzzle4Zone[_generator.Next(0, ZonedLocations.Puzzle4Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key1_S_P:
                                if (ZonedLocations.Key1Zone.Count > 0)
                                {
                                    if (_levelInstance.Name == LevelNames.OPERA)
                                    {
                                        int startKeyID = 172;
                                        int fanKeyID   = 118;

                                        //Special case - multiple keys
                                        if (i == startKeyID)
                                        {
                                            //Start key
                                            List <int> AllowedStartRooms = new List <int>()
                                            {
                                                10, 23, 25, 27, 29, 30, 31, 32, 33, 35, 127, 162, 163
                                            };

                                            while (!AllowedStartRooms.Contains(RandomLocation.Room))
                                            {
                                                RandomLocation = ZonedLocations.Key1Zone[_generator.Next(0, ZonedLocations.Key1Zone.Count)];
                                            }

                                            FoundPossibleLocation = true;
                                        }
                                        else if (i == fanKeyID)
                                        {
                                            //Fan area key
                                            List <int> AllowedFanRooms = new List <int>()
                                            {
                                                1, 5, 8, 16, 37, 38, 44, 46, 47, 48, 49, 50, 52, 53, 55, 57, 59, 60, 63, 65, 66, 67, 68, 69, 70, 71, 72, 75, 76, 77, 78, 82, 83, 86, 87, 88, 89, 90, 93, 95, 96, 100, 102, 103, 105, 107, 109, 111, 120, 132, 139, 141, 143, 144, 151, 153, 154, 155, 156, 158, 159, 161, 174, 176, 177, 178, 179, 183, 185, 187, 188, 189
                                            };

                                            while (!AllowedFanRooms.Contains(RandomLocation.Room))
                                            {
                                                RandomLocation = ZonedLocations.Key1Zone[_generator.Next(0, ZonedLocations.Key1Zone.Count)];
                                            }

                                            FoundPossibleLocation = true;
                                        }
                                        else
                                        {
                                            RandomLocation        = ZonedLocations.Key1Zone[_generator.Next(0, ZonedLocations.Key1Zone.Count)];
                                            FoundPossibleLocation = true;
                                        }
                                    }
                                    else
                                    {
                                        RandomLocation        = ZonedLocations.Key1Zone[_generator.Next(0, ZonedLocations.Key1Zone.Count)];
                                        FoundPossibleLocation = true;
                                    }
                                }
                                break;

                            case TR2Entities.Key2_S_P:
                                if (ZonedLocations.Key2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key2Zone[_generator.Next(0, ZonedLocations.Key2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key3_S_P:
                                if (ZonedLocations.Key3Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key3Zone[_generator.Next(0, ZonedLocations.Key3Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Key4_S_P:
                                if (ZonedLocations.Key4Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Key4Zone[_generator.Next(0, ZonedLocations.Key4Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Quest1_S_P:
                                if (ZonedLocations.Quest1Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Quest1Zone[_generator.Next(0, ZonedLocations.Quest1Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            case TR2Entities.Quest2_S_P:
                                if (ZonedLocations.Quest2Zone.Count > 0)
                                {
                                    RandomLocation        = ZonedLocations.Quest2Zone[_generator.Next(0, ZonedLocations.Quest2Zone.Count)];
                                    FoundPossibleLocation = true;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            //Place standard items as normal for now
                            RandomLocation        = ItemLocs[_generator.Next(0, ItemLocs.Count)];
                            FoundPossibleLocation = true;
                        }

                        if (FoundPossibleLocation)
                        {
                            Location GlobalizedRandomLocation = SpatialConverters.TransformToLevelSpace(RandomLocation, _levelInstance.Data.Rooms[RandomLocation.Room].Info);

                            _levelInstance.Data.Entities[i].Room       = Convert.ToInt16(GlobalizedRandomLocation.Room);
                            _levelInstance.Data.Entities[i].X          = GlobalizedRandomLocation.X;
                            _levelInstance.Data.Entities[i].Y          = GlobalizedRandomLocation.Y;
                            _levelInstance.Data.Entities[i].Z          = GlobalizedRandomLocation.Z;
                            _levelInstance.Data.Entities[i].Intensity1 = -1;
                            _levelInstance.Data.Entities[i].Intensity2 = -1;
                        }
                    }
                }
            }
        }