Exemple #1
0
        private void RandomizeFloorTracks(TR2Level level, FDControl floorData)
        {
            // Try to keep triggers that are beside each other and setup for the same
            // thing using the same track, otherwise the result is just a bit too random.
            // This relies on tr2audio.json having PrimaryCategory properly defined for
            // each track.
            foreach (TR2Room room in level.Rooms)
            {
                Dictionary <TRAudioCategory, TRAudioTrack> roomTracks = new Dictionary <TRAudioCategory, TRAudioTrack>();

                List <FDActionListItem> triggerItems = new List <FDActionListItem>();
                foreach (TRRoomSector sector in room.SectorList)
                {
                    if (sector.FDIndex > 0)
                    {
                        triggerItems.AddRange(FDUtilities.GetActionListItems(floorData, FDTrigAction.PlaySoundtrack, sector.FDIndex));
                    }
                }

                // Generate a random track for the first in each category for this room, then others
                // in the same category will follow suit.
                foreach (FDActionListItem item in triggerItems)
                {
                    TRAudioCategory category = FindTrackCategory(item.Parameter);
                    if (!roomTracks.ContainsKey(category))
                    {
                        List <TRAudioTrack> tracks = _tracks[category];
                        roomTracks[category] = tracks[_generator.Next(0, tracks.Count)];
                    }

                    item.Parameter = roomTracks[category].ID;
                }
            }
        }
        public void FloorData_InsertFDEntryWriteReadTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Add a music trigger to index 9
            fdataReader.Entries[9].Add(new FDTriggerEntry
            {
                Setup          = new FDSetup(FDFunctions.Trigger),
                TrigSetup      = new FDTrigSetup(),
                TrigActionList = new List <FDActionListItem>
                {
                    new FDActionListItem
                    {
                        TrigAction = FDTrigAction.PlaySoundtrack,
                        Parameter  = 40
                    }
                }
            });

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            TR2LevelWriter writer = new TR2LevelWriter();

            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            //Verify index 9 has two entries, that its first entry
            //does not have EndData set, but that its second does
            Assert.AreEqual(fdataReader.Entries[9].Count, 2);
            Assert.IsFalse(fdataReader.Entries[9][0].Setup.EndData);
            Assert.IsTrue(fdataReader.Entries[9][1].Setup.EndData);

            //Verify the trigger we added matches what we expect
            FDEntry entry = fdataReader.Entries[9][1];

            Assert.IsTrue(entry is FDTriggerEntry);

            FDTriggerEntry triggerEntry = entry as FDTriggerEntry;

            Assert.IsTrue(triggerEntry.Setup.Function == (byte)FDFunctions.Trigger);
            Assert.IsTrue(triggerEntry.TrigActionList.Count == 1);
            Assert.IsTrue(triggerEntry.TrigActionList[0].TrigAction == FDTrigAction.PlaySoundtrack);
            Assert.IsTrue(triggerEntry.TrigActionList[0].Parameter == 40);
        }
        public void FloorData_RemoveFDTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Find a sector that currently has floor data
            int room, roomSector = -1;

            for (room = 0; room < lvl.NumRooms; room++)
            {
                roomSector = lvl.Rooms[room].SectorList.ToList().FindIndex(s => s.FDIndex > 0);
                if (roomSector != -1)
                {
                    break;
                }
            }

            if (roomSector == -1)
            {
                Assert.Fail("Could not locate a Room Sector that has floor data associated with it.");
            }

            TRRoomSector sector = lvl.Rooms[room].SectorList[roomSector];

            // Remove the FD for this sector
            fdataReader.RemoveFloorData(sector);
            Assert.AreEqual(sector.FDIndex, 0, "Sector still has FD allocated.");

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            TR2LevelWriter writer = new TR2LevelWriter();

            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            //Reassign the sector
            sector = lvl.Rooms[room].SectorList[roomSector];

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            //Ensure the sector still has FD associated with it
            Assert.AreEqual(sector.FDIndex, 0, "Sector still has FD after write/read.");
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public static void SetEntityTriggers(TR2Level level, TR2Entity entity)
        {
            if (_oneShotEnemies.Contains((TR2Entities)entity.TypeID))
            {
                int entityID = level.Entities.ToList().IndexOf(entity);

                FDControl fdControl = new FDControl();
                fdControl.ParseFromLevel(level);

                List <FDTriggerEntry> triggers = FDUtilities.GetEntityTriggers(fdControl, entityID);
                foreach (FDTriggerEntry trigger in triggers)
                {
                    trigger.TrigSetup.SetOneShot();
                }

                fdControl.WriteToLevel(level);
            }
        }
        public void FloorData_AppendFDActionListItemTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Add a music action to the trigger at index 13
            FDTriggerEntry trigger = fdataReader.Entries[13][0] as FDTriggerEntry;

            Assert.AreEqual(trigger.TrigActionList.Count, 2);
            trigger.TrigActionList.Add(new FDActionListItem
            {
                TrigAction = FDTrigAction.PlaySoundtrack,
                Parameter  = 40
            });

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            TR2LevelWriter writer = new TR2LevelWriter();

            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            trigger = fdataReader.Entries[13][0] as FDTriggerEntry;
            // Verifying that the trigger has 3 items implicitly verifies that the Continue
            // flag was correctly changed on the previous last item and on the new item,
            // otherwise the parsing would have stopped at the second
            Assert.AreEqual(trigger.TrigActionList.Count, 3);

            Assert.IsTrue(trigger.TrigActionList[2].TrigAction == FDTrigAction.PlaySoundtrack);
            Assert.IsTrue(trigger.TrigActionList[2].Parameter == 40);
        }
        public void FloorData_AppendFDActionListItemCamTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Add a music action to the trigger at index 6010
            //This has a CamAction in its TrigList so this tests
            //that the Continue flag is correctly set
            FDTriggerEntry trigger = fdataReader.Entries[6010][1] as FDTriggerEntry;

            Assert.AreEqual(trigger.TrigActionList.Count, 2);
            Assert.IsNotNull(trigger.TrigActionList[1].CamAction);
            Assert.IsFalse(trigger.TrigActionList[1].CamAction.Continue);

            trigger.TrigActionList.Add(new FDActionListItem
            {
                TrigAction = FDTrigAction.PlaySoundtrack,
                Parameter  = 40
            });

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Check the CamAction has been updated
            Assert.AreEqual(trigger.TrigActionList.Count, 3);
            Assert.IsNotNull(trigger.TrigActionList[1].CamAction);
            Assert.IsTrue(trigger.TrigActionList[1].CamAction.Continue);

            //Check the music trigger has Continue set to false
            Assert.IsFalse(trigger.TrigActionList[2].Continue);
        }
        public void FloorData_InsertRemoveFDEntryTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Store the original floordata from the level
            ushort[] originalFData = new ushort[lvl.NumFloorData];
            Array.Copy(lvl.FloorData, originalFData, lvl.NumFloorData);

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Verify index 9 has one entry and that it's currently
            //set as EndData for this index
            Assert.AreEqual(fdataReader.Entries[9].Count, 1);
            Assert.IsTrue(fdataReader.Entries[9][0].Setup.EndData);

            //Verify the next index is currently 9 + the entry's length
            List <int> indices   = fdataReader.Entries.Keys.ToList();
            int        nextIndex = 9 + fdataReader.Entries[9][0].Flatten().Length;

            Assert.AreEqual(nextIndex, indices[indices.IndexOf(9) + 1]);

            //Add a music trigger to index 9
            fdataReader.Entries[9].Add(new FDTriggerEntry
            {
                Setup          = new FDSetup(FDFunctions.Trigger),
                TrigSetup      = new FDTrigSetup(),
                TrigActionList = new List <FDActionListItem>
                {
                    new FDActionListItem
                    {
                        TrigAction = FDTrigAction.PlaySoundtrack,
                        Parameter  = 40
                    }
                }
            });

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Verify index 9 has two entries, that its first entry
            //does not have EndData set, but that its second does
            Assert.AreEqual(fdataReader.Entries[9].Count, 2);
            Assert.IsFalse(fdataReader.Entries[9][0].Setup.EndData);
            Assert.IsTrue(fdataReader.Entries[9][1].Setup.EndData);

            //Verify the next index is now 9 + both the entry's lengths
            //Bear in mind the underlying dictionary's keys have changed
            indices   = fdataReader.Entries.Keys.ToList();
            nextIndex = 9 + fdataReader.Entries[9][0].Flatten().Length + fdataReader.Entries[9][1].Flatten().Length;
            Assert.AreEqual(nextIndex, indices[indices.IndexOf(9) + 1]);

            //Remove the new entry
            fdataReader.Entries[9].RemoveAt(1);

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Verify index 9 again has one entry and that it's again
            //set as EndData for this index
            Assert.AreEqual(fdataReader.Entries[9].Count, 1);
            Assert.IsTrue(fdataReader.Entries[9][0].Setup.EndData);

            //Verify the next index is again 9 + the entry's length
            indices   = fdataReader.Entries.Keys.ToList();
            nextIndex = 9 + fdataReader.Entries[9][0].Flatten().Length;
            Assert.AreEqual(nextIndex, indices[indices.IndexOf(9) + 1]);

            //Finally compare to make sure the original fdata was written back.
            CollectionAssert.AreEqual(originalFData, lvl.FloorData, "Floordata does not match");
            Assert.AreEqual((uint)lvl.FloorData.Length, lvl.NumFloorData);
        }
        public void FloorData_InsertFDTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Find a sector that currently has no floor data
            int room, roomSector = -1;

            for (room = 0; room < lvl.NumRooms; room++)
            {
                roomSector = lvl.Rooms[room].SectorList.ToList().FindIndex(s => s.FDIndex == 0);
                if (roomSector != -1)
                {
                    break;
                }
            }

            if (roomSector == -1)
            {
                Assert.Fail("Could not locate a Room Sector that does not have floor data associated with it.");
            }

            TRRoomSector sector = lvl.Rooms[room].SectorList[roomSector];

            // Create a slot in the FD for this sector
            fdataReader.CreateFloorData(sector);
            Assert.AreNotEqual(sector.FDIndex, 0, "Sector does not have FD allocated.");

            // Add a music trigger
            fdataReader.Entries[sector.FDIndex].Add(new FDTriggerEntry
            {
                Setup          = new FDSetup(FDFunctions.Trigger),
                TrigSetup      = new FDTrigSetup(),
                TrigActionList = new List <FDActionListItem>
                {
                    new FDActionListItem
                    {
                        TrigAction = FDTrigAction.PlaySoundtrack,
                        Parameter  = 40
                    }
                }
            });

            //Write the data back
            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            TR2LevelWriter writer = new TR2LevelWriter();

            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            //Reassign the sector
            sector = lvl.Rooms[room].SectorList[roomSector];

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            //Ensure the sector still has FD associated with it
            Assert.AreNotEqual(sector.FDIndex, 0, "Sector no longer has FD after write/read.");

            //Verify there is one entry for this sector
            Assert.AreEqual(fdataReader.Entries[sector.FDIndex].Count, 1);

            //Verify the trigger we added matches what we expect
            FDEntry entry = fdataReader.Entries[sector.FDIndex][0];

            Assert.IsTrue(entry is FDTriggerEntry);

            FDTriggerEntry triggerEntry = entry as FDTriggerEntry;

            Assert.IsTrue(triggerEntry.Setup.Function == (byte)FDFunctions.Trigger);
            Assert.IsTrue(triggerEntry.TrigActionList.Count == 1);
            Assert.IsTrue(triggerEntry.TrigActionList[0].TrigAction == FDTrigAction.PlaySoundtrack);
            Assert.IsTrue(triggerEntry.TrigActionList[0].Parameter == 40);
        }
        public void FloorData_ReadWriteOneShotTest()
        {
            //Read GW data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("wall.tr2");

            //Parse the floordata using FDControl
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);

            //Get all triggers for entity ID 18
            List <FDTriggerEntry> triggers = FDUtilities.GetEntityTriggers(fdataReader, 18);

            //There should be 3
            Assert.AreEqual(triggers.Count, 3);

            //Verify none of the triggers has OneShot set
            foreach (FDTriggerEntry trigger in triggers)
            {
                Assert.IsFalse(trigger.TrigSetup.OneShot);
            }

            //Set OneShot on each trigger
            foreach (FDTriggerEntry trigger in triggers)
            {
                trigger.TrigSetup.SetOneShot();
            }

            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            TR2LevelWriter writer = new TR2LevelWriter();

            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            //Get the triggers again afresh
            triggers = FDUtilities.GetEntityTriggers(fdataReader, 18);

            //Verify that they now have OneShot set
            foreach (FDTriggerEntry trigger in triggers)
            {
                Assert.IsTrue(trigger.TrigSetup.OneShot);
            }

            //Switch it off again
            foreach (FDTriggerEntry trigger in triggers)
            {
                trigger.TrigSetup.ClearOneShot();
            }

            fdataReader.WriteToLevel(lvl);

            //Save it and read it back in
            writer.WriteLevelToFile(lvl, "TEST.tr2");
            lvl = reader.ReadLevel("TEST.tr2");

            fdataReader = new FDControl();
            fdataReader.ParseFromLevel(lvl);

            //Get the triggers again afresh
            triggers = FDUtilities.GetEntityTriggers(fdataReader, 18);

            //Verify that they now once again do not have OneShot set
            foreach (FDTriggerEntry trigger in triggers)
            {
                Assert.IsFalse(trigger.TrigSetup.OneShot);
            }
        }
        public void FloorData_ReadWriteTest()
        {
            //Read Dragons Lair data
            TR2LevelReader reader = new TR2LevelReader();
            TR2Level       lvl    = reader.ReadLevel("xian.tr2");

            //Store the original floordata from the level
            ushort[] originalFData = new ushort[lvl.NumFloorData];
            Array.Copy(lvl.FloorData, originalFData, lvl.NumFloorData);

            //Parse the floordata using FDControl and re-write the parsed data back
            FDControl fdataReader = new FDControl();

            fdataReader.ParseFromLevel(lvl);
            fdataReader.WriteToLevel(lvl);

            //Store the new floordata written back by FDControl
            ushort[] newFData = lvl.FloorData;

            //Compare to make sure the original fdata was written back.
            CollectionAssert.AreEqual(originalFData, newFData, "Floordata does not match");
            Assert.AreEqual((uint)newFData.Length, lvl.NumFloorData);

            //Now modify an entry, and ensure it is different to the original data.
            FDPortalEntry portal = fdataReader.Entries[3][0] as FDPortalEntry;

            portal.Room = 42;
            fdataReader.WriteToLevel(lvl);

            //Test. FDIndex 3 of Dragon's Lair is a portal to room 3, which is being modified to Room 42.
            //Data should be:
            //New - [3] = 0x8001 and [4] = 0x002A

            //Get ref to new data
            newFData = lvl.FloorData;

            Assert.AreEqual(newFData[3], (ushort)0x8001);
            Assert.AreEqual(newFData[4], (ushort)0x002A);

            //Compare to make sure the modified fdata was written back.
            CollectionAssert.AreNotEqual(originalFData, newFData, "Floordata matches, change unsuccessful");
            Assert.AreEqual((uint)newFData.Length, lvl.NumFloorData);

            //Test pattern/type matching example for fdata.
            bool isPortal = false;

            foreach (KeyValuePair <int, List <FDEntry> > sector in fdataReader.Entries)
            {
                foreach (FDEntry entry in sector.Value)
                {
                    switch (entry)
                    {
                    case FDClimbEntry climbEntry:
                        break;

                    case FDKillLaraEntry killEntry:
                        break;

                    case FDPortalEntry portalEntry:
                        isPortal = true;
                        break;

                    case FDSlantEntry slantEntry:
                        break;

                    case FDTriggerEntry triggerEntry:
                        break;
                    }
                }
            }

            Assert.IsTrue(isPortal);
        }
Exemple #12
0
        private void RandomizeSecretTracks(TR2Level level, FDControl floorData)
        {
            // Generate new triggers for secrets to allow different sounds for each one
            List <TRAudioTrack>         secretTracks = _tracks[TRAudioCategory.Secret];
            Dictionary <int, TR2Entity> secrets      = GetSecretItems(level);

            foreach (int entityIndex in secrets.Keys)
            {
                TR2Entity    secret = secrets[entityIndex];
                TRRoomSector sector = FDUtilities.GetRoomSector(secret.X, secret.Y, secret.Z, secret.Room, level, floorData);
                if (sector.FDIndex == 0)
                {
                    // The secret is positioned on a tile that currently has no FD, so create it
                    floorData.CreateFloorData(sector);
                }

                List <FDEntry> entries = floorData.Entries[sector.FDIndex];
                FDTriggerEntry existingTriggerEntry = entries.Find(e => e is FDTriggerEntry) as FDTriggerEntry;
                bool           existingEntityPickup = false;
                if (existingTriggerEntry != null)
                {
                    if (existingTriggerEntry.TrigType == FDTrigType.Pickup && existingTriggerEntry.TrigActionList[0].Parameter == entityIndex)
                    {
                        // GW gold secret (default location) already has a pickup trigger to spawn the
                        // TRex (or whatever enemy) so we'll just append to that item list here
                        existingEntityPickup = true;
                    }
                    else
                    {
                        // There is already a non-pickup trigger for this sector so while nothing is wrong with
                        // adding a pickup trigger, the game ignores it. So in this instance, the sound that
                        // plays will just be whatever is set in the script.
                        continue;
                    }
                }

                // Generate a new music action
                FDActionListItem musicAction = new FDActionListItem
                {
                    TrigAction = FDTrigAction.PlaySoundtrack,
                    Parameter  = secretTracks[_generator.Next(0, secretTracks.Count)].ID
                };

                // For GW default gold, just append it
                if (existingEntityPickup)
                {
                    existingTriggerEntry.TrigActionList.Add(musicAction);
                }
                else
                {
                    entries.Add(new FDTriggerEntry
                    {
                        // The values here are replicated from Trigger#112 (in trview) in GW.
                        // The first action list must be the entity being picked up and so
                        // remaining action list items are actioned on pick up.
                        Setup = new FDSetup {
                            Value = 1028
                        },
                        TrigSetup = new FDTrigSetup {
                            Value = 15872
                        },
                        TrigActionList = new List <FDActionListItem>
                        {
                            new FDActionListItem
                            {
                                TrigAction = FDTrigAction.Object,
                                Parameter  = (ushort)entityIndex
                            },
                            musicAction
                        }
                    });
                }
            }
        }