コード例 #1
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
        private void DisguiseEntity(TR2CombinedLevel level, TR2Entities guiser, TR2Entities targetEntity)
        {
            List <TRModel> models        = level.Data.Models.ToList();
            int            existingIndex = models.FindIndex(m => m.ID == (short)guiser);

            if (existingIndex != -1)
            {
                models.RemoveAt(existingIndex);
            }

            TRModel disguiseAsModel = models[models.FindIndex(m => m.ID == (short)targetEntity)];

            if (targetEntity == TR2Entities.BirdMonster && level.Is(LevelNames.CHICKEN))
            {
                // We have to keep the original model for the boss, so in
                // this instance we just clone the model for the guiser
                models.Add(new TRModel
                {
                    Animation    = disguiseAsModel.Animation,
                    FrameOffset  = disguiseAsModel.FrameOffset,
                    ID           = (uint)guiser,
                    MeshTree     = disguiseAsModel.MeshTree,
                    NumMeshes    = disguiseAsModel.NumMeshes,
                    StartingMesh = disguiseAsModel.StartingMesh
                });
            }
            else
            {
                disguiseAsModel.ID = (uint)guiser;
            }

            level.Data.Models    = models.ToArray();
            level.Data.NumModels = (uint)models.Count;
        }
コード例 #2
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
            private bool Import(TR2CombinedLevel level, EnemyTransportCollection enemies)
            {
                try
                {
                    // The importer will handle any duplication between the entities to import and
                    // remove so just pass the unfiltered lists to it.
                    TRModelImporter importer = new TRModelImporter
                    {
                        ClearUnusedSprites = true,
                        EntitiesToImport   = enemies.EntitiesToImport,
                        EntitiesToRemove   = enemies.EntitiesToRemove,
                        Level                  = level.Data,
                        LevelName              = level.Name,
                        TextureRemapPath       = @"Resources\Textures\Deduplication\" + level.JsonID + "-TextureRemap.json",
                        TexturePositionMonitor = _outer.TextureMonitor.CreateMonitor(level.Name, enemies.EntitiesToImport)
                    };

                    // Try to import the selected models into the level.
                    importer.Import();
                    return(true);
                }
                catch (PackingException /* e*/)
                {
                    //System.Diagnostics.Debug.WriteLine(level.Name + ": " + e.Message);
                    // We need to reload the level to undo anything that may have changed.
                    _outer.ReloadLevelData(level);
                    // Tell the monitor to no longer track what we tried to import
                    _outer.TextureMonitor.ClearMonitor(level.Name, enemies.EntitiesToImport);
                    return(false);
                }
            }
コード例 #3
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
        private void RandomizeEnemiesNatively(TR2CombinedLevel level)
        {
            // For the assault course, nothing will be changed for the time being
            if (level.IsAssault)
            {
                return;
            }

            List <TR2Entities> availableEnemyTypes = TR2EntityUtilities.GetEnemyTypeDictionary()[level.Name];
            List <TR2Entities> droppableEnemies    = TR2EntityUtilities.DroppableEnemyTypes()[level.Name];
            List <TR2Entities> waterEnemies        = TR2EntityUtilities.FilterWaterEnemies(availableEnemyTypes);

            if (DocileBirdMonsters && level.Is(LevelNames.CHICKEN))
            {
                DisguiseEntity(level, TR2Entities.MaskedGoon1, TR2Entities.BirdMonster);
            }

            RandomizeEnemies(level, new EnemyRandomizationCollection
            {
                Available         = availableEnemyTypes,
                Droppable         = droppableEnemies,
                Water             = waterEnemies,
                BirdMonsterGuiser = TR2Entities.MaskedGoon1 // If randomizing natively, this will only apply to Ice Palace
            });
        }
コード例 #4
0
 private void AdjustOutfit(TR2CombinedLevel level, TR2Entities lara)
 {
     if (level.Is(LevelNames.HOME) && lara != TR2Entities.LaraHome)
     {
         // This ensures that Lara's hips match the new outfit for the starting animation and shower cutscene,
         // otherwise the dressing gown hips are rendered, but the mesh is completely different for this, plus
         // its textures will have been removed.
         TRMesh laraMiscMesh = TR2LevelUtilities.GetModelFirstMesh(level.Data, TR2Entities.LaraMiscAnim_H);
         TRMesh laraHipsMesh = TR2LevelUtilities.GetModelFirstMesh(level.Data, TR2Entities.Lara);
         TR2LevelUtilities.DuplicateMesh(level.Data, laraMiscMesh, laraHipsMesh);
     }
 }
コード例 #5
0
        private void SetNightMode(TR2CombinedLevel level)
        {
            foreach (TR2Room room in level.Data.Rooms)
            {
                room.Darken();
            }

            // Replace any entities that don't "make sense" at night
            List <TR2Entity> entities = level.Data.Entities.ToList();

            // A list of item locations to choose from
            List <TR2Entity> items = entities.Where
                                     (
                e =>
                TR2EntityUtilities.IsAmmoType((TR2Entities)e.TypeID) ||
                TR2EntityUtilities.IsGunType((TR2Entities)e.TypeID) ||
                TR2EntityUtilities.IsUtilityType((TR2Entities)e.TypeID)
                                     ).ToList();

            foreach (TR2Entities entityToReplace in _entitiesToReplace.Keys)
            {
                IEnumerable <TR2Entity> ents = entities.Where(e => e.TypeID == (short)entityToReplace);
                foreach (TR2Entity entity in ents)
                {
                    TR2Entity item = items[_generator.Next(0, items.Count)];
                    entity.TypeID     = (short)_entitiesToReplace[entityToReplace];
                    entity.Room       = item.Room;
                    entity.X          = item.X;
                    entity.Y          = item.Y;
                    entity.Z          = item.Z;
                    entity.Intensity1 = item.Intensity1;
                    entity.Intensity2 = item.Intensity2;
                }
            }

            // Hide any static meshes
            if (_staticMeshesToHide.ContainsKey(level.Name))
            {
                List <TRStaticMesh> staticMeshes = level.Data.StaticMeshes.ToList();
                foreach (uint meshID in _staticMeshesToHide[level.Name])
                {
                    TRStaticMesh mesh = staticMeshes.Find(m => m.ID == meshID);
                    if (mesh != null)
                    {
                        mesh.NonCollidable = true;
                        mesh.Visible       = false;
                    }
                }
            }
        }
コード例 #6
0
ファイル: AudioRandomizer.cs プロジェクト: lahm86/TR2-Rando
        private void RandomizeMusicTriggers(TR2CombinedLevel level)
        {
            FDControl floorData = new FDControl();

            floorData.ParseFromLevel(level.Data);

            if (ChangeTriggerTracks)
            {
                RandomizeFloorTracks(level.Data, floorData);
            }
            RandomizeSecretTracks(level.Data, floorData);

            floorData.WriteToLevel(level.Data);
        }
コード例 #7
0
ファイル: TextureRandomizer.cs プロジェクト: lahm86/TR2-Rando
 private TextureLevelMapping GetMapping(TR2CombinedLevel level)
 {
     lock (_drawLock)
     {
         return(TextureLevelMapping.Get
                (
                    level.Data,
                    level.JsonID,
                    _textureDatabase,
                    TextureMonitor.GetLevelMapping(level.Name),
                    TextureMonitor.GetIgnoredEntities(level.Name)
                ));
     }
 }
コード例 #8
0
ファイル: EnemyUtilities.cs プロジェクト: lahm86/TR2-Rando
 public static bool IsWaterEnemyRequired(TR2CombinedLevel level)
 {
     foreach (TR2Entity entityInstance in level.Data.Entities)
     {
         TR2Entities entity = (TR2Entities)entityInstance.TypeID;
         if (TR2EntityUtilities.IsWaterCreature(entity))
         {
             if (!level.CanPerformDraining(entityInstance.Room))
             {
                 // Draining cannot be performed so we need to ensure we get at least one water enemy
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #9
0
        private void RotateLara(TR2Entity lara, TR2CombinedLevel level)
        {
            short currentAngle = lara.Angle;

            while (lara.Angle == currentAngle)
            {
                int degrees = 45 * _generator.Next(0, 8);
                lara.Angle = (short)(degrees * 16384 / -90);
            }

            // Spin the boat around too
            if (level.Is(LevelNames.BARTOLI))
            {
                TR2Entity boat = level.Data.Entities.ToList().Find(e => e.TypeID == (short)TR2Entities.Boat);
                boat.Angle = lara.Angle;
            }
        }
コード例 #10
0
            private bool Import(TR2CombinedLevel level, TR2Entities lara)
            {
                List <TR2Entities> laraImport = new List <TR2Entities> {
                    lara
                };
                TRModelImporter importer = new TRModelImporter
                {
                    Level                  = level.Data,
                    LevelName              = level.Name,
                    ClearUnusedSprites     = false,
                    EntitiesToImport       = laraImport,
                    EntitiesToRemove       = _laraRemovals,
                    TexturePositionMonitor = _outer.TextureMonitor.CreateMonitor(level.Name, laraImport)
                };

                string remapPath = @"Resources\Textures\Deduplication\" + level.JsonID + "-TextureRemap.json";

                if (File.Exists(remapPath))
                {
                    importer.TextureRemapPath = remapPath;
                }

                try
                {
                    // Try to import the selected models into the level.
                    importer.Import();
                    return(true);
                }
                catch (PackingException)
                {
                    // We need to reload the level to undo anything that may have changed.
                    _outer.ReloadLevelData(level);
                    // Tell the monitor to no longer track what we tried to import
                    _outer.TextureMonitor.ClearMonitor(level.Name, laraImport);
                    return(false);
                }
            }
コード例 #11
0
ファイル: EnemyUtilities.cs プロジェクト: lahm86/TR2-Rando
        public static bool IsDroppableEnemyRequired(TR2CombinedLevel level)
        {
            foreach (TR2Entity entityInstance in level.Data.Entities)
            {
                List <TR2Entity> sharedItems = new List <TR2Entity>(Array.FindAll
                                                                    (
                                                                        level.Data.Entities,
                                                                        e =>
                                                                        (
                                                                            e.X == entityInstance.X &&
                                                                            e.Y == entityInstance.Y &&
                                                                            e.Z == entityInstance.Z
                                                                        )
                                                                    ));
                if (sharedItems.Count > 1)
                {
                    // Are any entities that are sharing a location a droppable pickup?
                    foreach (TR2Entity ent in sharedItems)
                    {
                        TR2Entities EntType = (TR2Entities)ent.TypeID;

                        if
                        (
                            TR2EntityUtilities.IsUtilityType(EntType) ||
                            TR2EntityUtilities.IsGunType(EntType) ||
                            TR2EntityUtilities.IsKeyItemType(EntType)
                        )
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #12
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
 internal void AddLevel(TR2CombinedLevel level)
 {
     _enemyMapping.Add(level, new List <EnemyTransportCollection>(_outer.MaxPackingAttempts));
 }
コード例 #13
0
        private void RandomizeStartPosition(TR2CombinedLevel level)
        {
            if (level.Script.HasStartAnimation)
            {
                // Don't change either the position or angle in Rig or HSH as the start cutscene looks odd and
                // for HSH Lara doesn't end up on the trigger for the enemies.
                return;
            }

            List <TR2Entity> entities = level.Data.Entities.ToList();
            TR2Entity        lara     = entities.Find(e => e.TypeID == (short)TR2Entities.Lara);

            if (!RotateOnly)
            {
                // We only change position if there is not a secret in the same room as Lara, This is just in case it ends up
                // where she starts on a slope (GW or Opera House for example), as its X,Y,Z values may not be identical to Lara's.
                if (entities.Find(e => e.Room == lara.Room && TR2EntityUtilities.IsSecretType((TR2Entities)e.TypeID)) == null)
                {
                    // If we haven't defined anything for a level, Lara will just be rotated. This is most likely where there are
                    // triggers just after Lara's starting spot, so we just skip them here.
                    if (_startLocations.ContainsKey(level.Name))
                    {
                        List <Location> locations = _startLocations[level.Name];
                        if (DevelopmentMode)
                        {
                            foreach (Location loc in locations)
                            {
                                entities.Add(new TR2Entity
                                {
                                    TypeID     = (short)TR2Entities.Lara,
                                    Room       = Convert.ToInt16(loc.Room),
                                    X          = loc.X,
                                    Y          = loc.Y,
                                    Z          = loc.Z,
                                    Angle      = 0,
                                    Intensity1 = -1,
                                    Intensity2 = -1,
                                    Flags      = 0
                                });
                            }
                        }
                        else
                        {
                            Location location = locations[_generator.Next(0, locations.Count)];
                            lara.Room  = (short)location.Room;
                            lara.X     = location.X;
                            lara.Y     = location.Y;
                            lara.Z     = location.Z;
                            lara.Angle = location.Angle;
                        }
                    }
                }
            }

            RotateLara(lara, level);

            if (DevelopmentMode)
            {
                level.Data.Entities    = entities.ToArray();
                level.Data.NumEntities = (uint)entities.Count;
            }
        }
コード例 #14
0
            private void CutHair(TR2CombinedLevel level)
            {
                // Every level has a 64x64 transparent gunflare texture so rather than
                // importing something else, we'll just try to find that texture and
                // point Lara's braid to it, so making it invisible.
                TRMesh[] gunflareMeshes = TR2LevelUtilities.GetModelMeshes(level.Data, TR2Entities.Gunflare_H);
                if (gunflareMeshes == null)
                {
                    return;
                }

                ISet <int> textureIndices = new HashSet <int>();

                foreach (TRMesh mesh in gunflareMeshes)
                {
                    foreach (TRFace4 r in mesh.TexturedRectangles)
                    {
                        textureIndices.Add(r.Texture);
                    }
                    foreach (TRFace3 t in mesh.TexturedTriangles)
                    {
                        textureIndices.Add(t.Texture);
                    }
                }

                IndexedTRObjectTexture transparentTexture = null;

                foreach (int index in textureIndices)
                {
                    transparentTexture = new IndexedTRObjectTexture
                    {
                        Index   = index,
                        Texture = level.Data.ObjectTextures[index]
                    };

                    Rectangle rect = transparentTexture.Bounds;
                    if (rect.Width == 64 && rect.Height == 64)
                    {
                        break;
                    }
                    else
                    {
                        transparentTexture = null;
                    }
                }

                // Did we find it?
                if (transparentTexture == null)
                {
                    return;
                }

                // Erase the braid
                foreach (TRMesh mesh in TR2LevelUtilities.GetModelMeshes(level.Data, TR2Entities.LaraPonytail_H))
                {
                    foreach (TRFace4 r in mesh.TexturedRectangles)
                    {
                        r.Texture = (ushort)transparentTexture.Index;
                    }
                    foreach (TRFace3 t in mesh.TexturedTriangles)
                    {
                        t.Texture = (ushort)transparentTexture.Index;
                    }
                }
            }
コード例 #15
0
 internal void AddLevel(TR2CombinedLevel level)
 {
     _outfitAllocations.Add(level, new List <TR2Entities>());
 }
コード例 #16
0
 internal void AddLevel(TR2CombinedLevel level)
 {
     _levels.Add(level);
 }
コード例 #17
0
ファイル: TextureRandomizer.cs プロジェクト: lahm86/TR2-Rando
 internal void AddLevel(TR2CombinedLevel level)
 {
     _holders.Add(level, null);
 }
コード例 #18
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
        private void RandomizeEnemies(TR2CombinedLevel level, EnemyRandomizationCollection enemies)
        {
            bool shotgunGoonSeen = level.Is(LevelNames.HOME); // 1 ShotgunGoon in HSH only
            bool dragonSeen      = level.Is(LevelNames.LAIR); // 1 Marco in DL only

            // Get a list of current enemy entities
            List <TR2Entity> enemyEntities = level.GetEnemyEntities();

            // Keep track of any new entities added (e.g. Skidoo)
            List <TR2Entity> newEntities = new List <TR2Entity>();

            // #148 If it's HSH and we have been able to import cross-level, we will add 15
            // dogs outside the gate to ensure the kill counter works. Dogs, Goon1 and
            // StickGoons will have been excluded from the cross-level pool for simplicity
            // Their textures will have been removed but they won't spawn anyway as we aren't
            // defining triggers - the game only needs them to be present in the entity list.
            if (level.Is(LevelNames.HOME) && !enemies.Available.Contains(TR2Entities.Doberman))
            {
                for (int i = 0; i < 15; i++)
                {
                    newEntities.Add(new TR2Entity
                    {
                        TypeID     = (short)TR2Entities.Doberman,
                        Room       = 85,
                        X          = 61919,
                        Y          = 2560,
                        Z          = 74222,
                        Angle      = 16384,
                        Flags      = 0,
                        Intensity1 = -1,
                        Intensity2 = -1
                    });
                }
            }

            // First iterate through any enemies that are restricted by room
            Dictionary <TR2Entities, List <int> > enemyRooms = EnemyUtilities.GetRestrictedEnemyRooms(level.Name);

            if (enemyRooms != null)
            {
                foreach (TR2Entities entity in enemyRooms.Keys)
                {
                    if (!enemies.Available.Contains(entity))
                    {
                        continue;
                    }

                    List <int> rooms          = enemyRooms[entity];
                    int        maxEntityCount = EnemyUtilities.GetRestrictedEnemyLevelCount(entity);
                    if (maxEntityCount == -1)
                    {
                        // We are allowed any number, but this can't be more than the number of unique rooms,
                        // so we will assume 1 per room as these restricted enemies are likely to be tanky.
                        maxEntityCount = rooms.Count;
                    }
                    else
                    {
                        maxEntityCount = Math.Min(maxEntityCount, rooms.Count);
                    }

                    // Pick an actual count
                    int enemyCount = _generator.Next(1, maxEntityCount + 1);
                    for (int i = 0; i < enemyCount; i++)
                    {
                        // Find an entity in one of the rooms that the new enemy is restricted to
                        TR2Entity targetEntity = null;
                        do
                        {
                            int room = enemyRooms[entity][_generator.Next(0, enemyRooms[entity].Count)];
                            targetEntity = enemyEntities.Find(e => e.Room == room);
                        }while (targetEntity == null);

                        targetEntity.TypeID = (short)TR2EntityUtilities.TranslateEntityAlias(entity);

                        // #146 Ensure OneShot triggers are set for this enemy if needed
                        EnemyUtilities.SetEntityTriggers(level.Data, targetEntity);

                        // Remove the target entity so it doesn't get replaced
                        enemyEntities.Remove(targetEntity);
                    }

                    // Remove this entity type from the available rando pool
                    enemies.Available.Remove(entity);
                }
            }

            foreach (TR2Entity currentEntity in enemyEntities)
            {
                TR2Entities currentEntityType = (TR2Entities)currentEntity.TypeID;
                TR2Entities newEntityType     = currentEntityType;

                // If it's an existing enemy that has to remain in the same spot, skip it
                if (EnemyUtilities.IsEnemyRequired(level.Name, currentEntityType))
                {
                    continue;
                }

                //#45 - Check to see if any items are at the same location as the enemy.
                //If there are we need to ensure that the new random enemy type is one that can drop items.
                List <TR2Entity> sharedItems = new List <TR2Entity>(Array.FindAll
                                                                    (
                                                                        level.Data.Entities,
                                                                        e =>
                                                                        (
                                                                            e.X == currentEntity.X &&
                                                                            e.Y == currentEntity.Y &&
                                                                            e.Z == currentEntity.Z
                                                                        )
                                                                    ));

                //Do multiple entities share one location?
                bool isPickupItem = false;
                if (sharedItems.Count > 1 && enemies.Droppable.Count != 0)
                {
                    //Are any entities sharing a location a droppable pickup?

                    foreach (TR2Entity ent in sharedItems)
                    {
                        TR2Entities entType = (TR2Entities)ent.TypeID;

                        isPickupItem = TR2EntityUtilities.IsUtilityType(entType) ||
                                       TR2EntityUtilities.IsGunType(entType) ||
                                       TR2EntityUtilities.IsKeyItemType(entType);

                        if (isPickupItem)
                        {
                            break;
                        }
                    }

                    //Generate a new type
                    newEntityType = enemies.Available[_generator.Next(0, enemies.Available.Count)];

                    //Do we need to ensure the enemy can drop the item on the same tile?
                    if (!TR2EntityUtilities.CanDropPickups(newEntityType, !ProtectMonks) && isPickupItem)
                    {
                        //Ensure the new random entity can drop pickups
                        newEntityType = enemies.Droppable[_generator.Next(0, enemies.Droppable.Count)];
                    }
                }
                else
                {
                    //Generate a new type
                    newEntityType = enemies.Available[_generator.Next(0, enemies.Available.Count)];
                }

                short   roomIndex = currentEntity.Room;
                TR2Room room      = level.Data.Rooms[roomIndex];

                if (level.Is(LevelNames.DA) && roomIndex == 77)
                {
                    // Make sure the end level trigger isn't blocked by an unkillable enemy
                    while (TR2EntityUtilities.IsHazardCreature(newEntityType) || (ProtectMonks && TR2EntityUtilities.IsMonk(newEntityType)))
                    {
                        newEntityType = enemies.Available[_generator.Next(0, enemies.Available.Count)];
                    }
                }

                if (TR2EntityUtilities.IsWaterCreature(currentEntityType) && !TR2EntityUtilities.IsWaterCreature(newEntityType))
                {
                    // Check alternate rooms too - e.g. rooms 74/48 in 40 Fathoms
                    short roomDrainIndex = -1;
                    if (room.ContainsWater)
                    {
                        roomDrainIndex = roomIndex;
                    }
                    else if (room.AlternateRoom != -1 && level.Data.Rooms[room.AlternateRoom].ContainsWater)
                    {
                        roomDrainIndex = room.AlternateRoom;
                    }

                    if (roomDrainIndex != -1 && !level.PerformDraining(roomDrainIndex))
                    {
                        // Draining cannot be performed so make the entity a water creature.
                        // The list of provided water creatures will either be those native
                        // to this level, or if randomizing cross-level, a pre-check will
                        // have already been performed on draining so if it's not possible,
                        // at least one water creature will be available.
                        newEntityType = enemies.Water[_generator.Next(0, enemies.Water.Count)];
                    }
                }

                // Ensure that if we have to pick a different enemy at this point that we still
                // honour any pickups in the same spot.
                List <TR2Entities> enemyPool = isPickupItem ? enemies.Droppable : enemies.Available;

                if (newEntityType == TR2Entities.ShotgunGoon && shotgunGoonSeen) // HSH only
                {
                    while (newEntityType == TR2Entities.ShotgunGoon)
                    {
                        newEntityType = enemyPool[_generator.Next(0, enemyPool.Count)];
                    }
                }

                if (newEntityType == TR2Entities.MarcoBartoli && dragonSeen) // DL only, other levels use quasi-zoning for the dragon
                {
                    while (newEntityType == TR2Entities.MarcoBartoli)
                    {
                        newEntityType = enemyPool[_generator.Next(0, enemyPool.Count)];
                    }
                }

                // If we are restricting count per level for this enemy and have reached that count, pick
                // someting else. This applies when we are restricting by in-level count, but not by room
                // (e.g. Winston).
                int maxEntityCount = EnemyUtilities.GetRestrictedEnemyLevelCount(newEntityType);
                if (maxEntityCount != -1)
                {
                    if (level.Data.Entities.ToList().FindAll(e => e.TypeID == (short)newEntityType).Count == maxEntityCount)
                    {
                        TR2Entities tmp = newEntityType;
                        while (newEntityType == tmp)
                        {
                            newEntityType = enemyPool[_generator.Next(0, enemyPool.Count)];
                        }
                    }
                }

                // #158 Several entity freezing issues have been found with various enemy
                // combinations in Barkhang, so for now all Mercenary1 and MonkWithLongStick
                // entities must remain in place, and no additional ones should be added.
                if (level.Is(LevelNames.MONASTERY))
                {
                    while (EnemyUtilities.IsEnemyRequired(level.Name, newEntityType))
                    {
                        newEntityType = enemyPool[_generator.Next(0, enemyPool.Count)];
                    }
                }

                // #144 Disguise something as the Chicken. Pre-checks will have been done to ensure
                // the guiser is suitable for the level.
                if (DocileBirdMonsters && newEntityType == TR2Entities.BirdMonster)
                {
                    newEntityType = enemies.BirdMonsterGuiser;
                }

                // Make sure to convert BengalTiger, StickWieldingGoonBandana etc back to their actual types
                currentEntity.TypeID = (short)TR2EntityUtilities.TranslateEntityAlias(newEntityType);

                // #146 Ensure OneShot triggers are set for this enemy if needed. This currently only applies
                // to the dragon, which will be handled above in defined rooms, but the check should be made
                // here in case this needs to be extended later.
                EnemyUtilities.SetEntityTriggers(level.Data, currentEntity);
            }

            // MercSnowMobDriver relies on RedSnowmobile so it will be available in the model list
            if (!level.Is(LevelNames.TIBET))
            {
                TR2Entity mercDriver = level.Data.Entities.ToList().Find(e => e.TypeID == (short)TR2Entities.MercSnowmobDriver);
                if (mercDriver != null)
                {
                    short room, angle;
                    int   x, y, z;

                    // we will only spawn one skidoo, so only need one random location
                    Location randomLocation = VehicleUtilities.GetRandomLocation(level.Name, TR2Entities.RedSnowmobile, _generator);
                    if (randomLocation != null)
                    {
                        room  = (short)randomLocation.Room;
                        x     = randomLocation.X;
                        y     = randomLocation.Y;
                        z     = randomLocation.Z;
                        angle = randomLocation.Angle;
                    }
                    else
                    {
                        // if the level does not have skidoo locations for some reason, just spawn it on the MercSnowMobDriver
                        room  = mercDriver.Room;
                        x     = mercDriver.X;
                        y     = mercDriver.Y;
                        z     = mercDriver.Z;
                        angle = mercDriver.Angle;
                    }

                    newEntities.Add(new TR2Entity
                    {
                        TypeID     = (short)TR2Entities.RedSnowmobile,
                        Room       = room,
                        X          = x,
                        Y          = y,
                        Z          = z,
                        Angle      = angle,
                        Flags      = 0,
                        Intensity1 = -1,
                        Intensity2 = -1
                    });
                }
            }

            // Did we add any new entities?
            if (newEntities.Count > 0)
            {
                List <TR2Entity> levelEntities = level.Data.Entities.ToList();
                levelEntities.AddRange(newEntities);
                level.Data.Entities    = levelEntities.ToArray();
                level.Data.NumEntities = (uint)levelEntities.Count;
            }
        }
コード例 #19
0
ファイル: EnemyRandomizer.cs プロジェクト: lahm86/TR2-Rando
        private EnemyTransportCollection SelectCrossLevelEnemies(TR2CombinedLevel level, int reduceEnemyCountBy = 0)
        {
            // For the assault course, nothing will be imported for the time being
            if (level.IsAssault)
            {
                return(null);
            }

            // Get the list of enemy types currently in the level
            List <TR2Entities> oldEntities = TR2EntityUtilities.GetEnemyTypeDictionary()[level.Name];

            // Work out how many we can support
            int enemyCount = oldEntities.Count - reduceEnemyCountBy + EnemyUtilities.GetEnemyAdjustmentCount(level.Name);
            List <TR2Entities> newEntities = new List <TR2Entities>(enemyCount);

            List <TR2Entities> chickenGuisers = EnemyUtilities.GetEnemyGuisers(TR2Entities.BirdMonster);
            TR2Entities        chickenGuiser  = TR2Entities.BirdMonster;

            // #148 For HSH, we lock the enemies that are required for the kill counter to work outside
            // the gate, which means the game still has the correct target kill count, while allowing
            // us to randomize the ones inside the gate (except the final shotgun goon).
            // If however, we are on the final packing attempt, we will just change the stick goon
            // alias and add docile bird monsters (if selected) as this is known to be supported.
            if (level.Is(LevelNames.HOME) && reduceEnemyCountBy > 0)
            {
                TR2Entities        newGoon = TR2Entities.StickWieldingGoon1BlackJacket;
                List <TR2Entities> goonies = TR2EntityUtilities.GetEntityFamily(newGoon);
                do
                {
                    newGoon = goonies[_generator.Next(0, goonies.Count)];
                }while (newGoon == TR2Entities.StickWieldingGoon1BlackJacket);

                newEntities.AddRange(oldEntities);
                newEntities.Remove(TR2Entities.StickWieldingGoon1);
                newEntities.Add(newGoon);

                if (DocileBirdMonsters)
                {
                    newEntities.Remove(TR2Entities.MaskedGoon1);
                    newEntities.Add(TR2Entities.BirdMonster);
                    chickenGuiser = TR2Entities.MaskedGoon1;
                }
            }
            else
            {
                // Do we need at least one water creature?
                bool waterEnemyRequired = EnemyUtilities.IsWaterEnemyRequired(level);
                // Do we need at least one enemy that can drop?
                bool droppableEnemyRequired = EnemyUtilities.IsDroppableEnemyRequired(level);

                // Let's try to populate the list. Start by adding one water enemy
                // and one droppable enemy if they are needed.
                if (waterEnemyRequired)
                {
                    List <TR2Entities> waterEnemies = TR2EntityUtilities.KillableWaterCreatures();
                    TR2Entities        entity;
                    do
                    {
                        entity = waterEnemies[_generator.Next(0, waterEnemies.Count)];
                    }while (!EnemyUtilities.IsEnemySupported(level.Name, entity));
                    newEntities.Add(entity);
                }

                if (droppableEnemyRequired)
                {
                    List <TR2Entities> droppableEnemies = TR2EntityUtilities.GetCrossLevelDroppableEnemies(!ProtectMonks);
                    TR2Entities        entity;
                    do
                    {
                        entity = droppableEnemies[_generator.Next(0, droppableEnemies.Count)];
                    }while (!EnemyUtilities.IsEnemySupported(level.Name, entity));
                    newEntities.Add(entity);
                }

                // Are there any other types we need to retain?
                foreach (TR2Entities entity in EnemyUtilities.GetRequiredEnemies(level.Name))
                {
                    if (!newEntities.Contains(entity))
                    {
                        newEntities.Add(entity);
                    }
                }

                // Get all other candidate enemies and fill the list
                List <TR2Entities> allEnemies = TR2EntityUtilities.GetCandidateCrossLevelEnemies();

                while (newEntities.Count < newEntities.Capacity)
                {
                    TR2Entities entity = allEnemies[_generator.Next(0, allEnemies.Count)];

                    // Make sure this isn't known to be unsupported in the level
                    if (!EnemyUtilities.IsEnemySupported(level.Name, entity))
                    {
                        continue;
                    }

                    // If it's the chicken in HSH but we're not using docile, we don't want it ending the level
                    if (!DocileBirdMonsters && entity == TR2Entities.BirdMonster && level.Is(LevelNames.HOME))
                    {
                        continue;
                    }

                    // If it's a docile chicken in Barkhang, it won't work because we can't disguise monks in this level.
                    if (DocileBirdMonsters && entity == TR2Entities.BirdMonster && level.Is(LevelNames.MONASTERY))
                    {
                        continue;
                    }

                    // If this is a tracked enemy throughout the game, we only allow it if the number
                    // of unique levels is within the limit. Bear in mind we are collecting more than
                    // one group of enemies per level.
                    if (_gameEnemyTracker.ContainsKey(entity) && !_gameEnemyTracker[entity].Contains(level.Name))
                    {
                        if (_gameEnemyTracker[entity].Count < _gameEnemyTracker[entity].Capacity)
                        {
                            // The entity is allowed, so store the fact that this level will have it
                            _gameEnemyTracker[entity].Add(level.Name);
                        }
                        else
                        {
                            // Otherwise, pick something else
                            continue;
                        }
                    }

                    // GetEntityFamily returns all aliases for the likes of the tigers, but if an entity
                    // doesn't have any, the returned list just contains the entity itself. This means
                    // we can avoid duplicating standard enemies as well as avoiding alias-clashing.
                    List <TR2Entities> family = TR2EntityUtilities.GetEntityFamily(entity);
                    if (!newEntities.Any(e1 => family.Any(e2 => e1 == e2)))
                    {
                        // #144 We can include docile chickens provided we aren't including everything
                        // that can be disguised as a chicken.
                        if (DocileBirdMonsters)
                        {
                            bool guisersAvailable = !chickenGuisers.All(g => newEntities.Contains(g));
                            // If the selected entity is the chicken, it can be added provided there are
                            // available guisers.
                            if (!guisersAvailable && entity == TR2Entities.BirdMonster)
                            {
                                continue;
                            }

                            // If the selected entity is a potential guiser, it can only be added if it's not
                            // the last available guiser. Otherwise, it will become the guiser.
                            if (chickenGuisers.Contains(entity) && newEntities.Contains(TR2Entities.BirdMonster))
                            {
                                if (newEntities.FindAll(e => chickenGuisers.Contains(e)).Count == chickenGuisers.Count - 1)
                                {
                                    continue;
                                }
                            }
                        }

                        newEntities.Add(entity);
                    }
                }
            }

            // #144 Decide at this point who will be guising unless it has already been decided above (e.g. HSH)
            if (DocileBirdMonsters && newEntities.Contains(TR2Entities.BirdMonster) && chickenGuiser == TR2Entities.BirdMonster)
            {
                int guiserIndex = chickenGuisers.FindIndex(g => !newEntities.Contains(g));
                if (guiserIndex != -1)
                {
                    chickenGuiser = chickenGuisers[guiserIndex];
                }
            }

            return(new EnemyTransportCollection
            {
                EntitiesToImport = newEntities,
                EntitiesToRemove = oldEntities,
                BirdMonsterGuiser = chickenGuiser
            });
        }