Beispiel #1
0
    /// <summary>
    /// Environment gallery window.
    /// </summary>
    void EnvironmentGalleryWindow(int windowID)
    {
        // back button and refresh button
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("<", GUILayout.Width(30f)))
        {
            _windows.Pop();
        }
        if (GUILayout.Button("R", GUILayout.Width(30f)))
        {
            EnvLoader.SearchForEnvironments();
        }
        GUILayout.Label("Environment Gallery");
        GUILayout.EndHorizontal();

        // gallery goes here...
        for (int i = 0; i < EnvLoader.environmentsFound.Count; i++)
        {
            if (GUILayout.Button(EnvLoader.environmentsFound[i].name))
            {
                settings.environmentName = EnvLoader.environmentsFound[i].name;
                _windows.Pop();
            }
        }

        GUILayout.Space(10);

        // start environment creator
        GUILayout.Button("Create new environment...");

        GUI.DragWindow();
    }
Beispiel #2
0
 /// <summary>
 /// Randomly select simulation parameters.
 /// </summary>
 public void Randomize()
 {
     title                          = "Random Settings";
     numberOfTests                  = 3;
     environmentName                = EnvLoader.RandomEnvironmentName();
     robotName                      = BotLoader.RandomRobotName();
     navigationAssemblyName         = NavLoader.RandomPluginName();
     randomizeDestination           = true;
     continueOnNavObjectiveComplete = true;
     continueOnRobotIsStuck         = true;
 }
Beispiel #3
0
 private void btnLoadEnv_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter = "XML Files|*.xml";
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         EnvLoader envLoader = new EnvLoader();
         envLoader.Load(openFileDialog1.FileName);
         double[,] newProb = envLoader.CalcVal(_map);
         for (int i = 0; i < _map.Height; i++)
         {
             for (int j = 0; j < _map.Width; j++)
             {
                 _map.GetMapStateMgr().SetEntropy(i, j, 1.0 - newProb[i, j]);
             }
         }
         Refresh();
     }
 }
Beispiel #4
0
    /// <summary>
    /// Loads the environment.
    /// </summary>
    /// <param name="name">Name.</param>
    private static void LoadEnvironment(string name)
    {
        EnvLoader.SearchForEnvironments();
        if (environment)
        {
            environment.transform.Recycle();
        }
        environment      = EnvLoader.LoadEnvironment(name);
        environment.name = name;         // avoids: Unity appending "(Clone)" to instance names
        Debug.Log(environment);
        Bounds b = new Bounds();

        foreach (Renderer r in environment.GetComponentsInChildren <Renderer>())
        {
            b.Encapsulate(r.bounds);
        }
        Instance.bounds = b;
        CamController.SetViewMode(CamController.ViewMode.Birdseye);
    }
Beispiel #5
0
 /// <summary>
 /// Halt current simulation.
 /// Load the next simulation in batch, or
 ///  change state to State.end if at the end of batch.
 /// </summary>
 public static void NextSimulation()
 {
     // stop current simulation
     if (state == State.simulating)
     {
         Halt(StopCode.Unspecified);
     }
     // next in batch
     simulationNumber++;
     if (simulationNumber > batch.Count)
     {
         // end of batch
         Halt(StopCode.Unspecified);
         End();
         return;
     }
     Debug.Log("Simulation NextSimulation: " + simulationNumber + " of " + batch.Count);
     // load simulation settings
     settings = batch[simulationNumber - 1];
     Log.Settings();
     // load environment
     EnvLoader.SearchForEnvironments();
     environment = EnvLoader.LoadEnvironment(settings.environmentName);
     destination.transform.position = RandomInBounds(Instance.bounds);
     // load robot
     if (robot)
     {
         CamController.RemoveAreaOfInterest(robot);
     }
     BotLoader.SearchForRobots();
     robot            = BotLoader.LoadRobot(settings.robotName);
     robot.navigation = NavLoader.LoadPlugin(settings.navigationAssemblyName);
     // configure camera
     CamController.AddAreaOfInterest(robot);
     CamController.SetViewMode(CamController.ViewMode.Birdseye);
     CamController.SetAreaOfInterest(robot);
     // reset test number
     testNumber = 0;
     NextTest();
 }
Beispiel #6
0
    protected override void OnInitialized(EventArgs e)
    {
        Console.WriteLine("\n----------------------------------");
        Console.WriteLine(" GameMode Capture The Flag");
        Console.WriteLine("     Team DeathMatch");
        Console.WriteLine("----------------------------------\n");

        Server.SendRconCommand("loadfs EntryMap");
        Server.SendRconCommand("loadfs RemoveBuilding");
        //UsePlayerPedAnimations();
        DisableInteriorEnterExits();
        AddPlayerClass(SkinTeam.Alpha, new Vector3(0, 0, 0), 0);
        AddPlayerClass(SkinTeam.Beta, new Vector3(0, 0, 0), 0);
        TextDrawGlobal.Create();
        TextDrawEntry.Create();


        var envVars = new EnvLoader().Load(out var result);

        Console.WriteLine(result.ErrorMessages);
        Server.SendRconCommand($"hostname {envVars["HOST_NAME"]}");
        Server.SendRconCommand($"language {envVars["LANGUAGE_NAME"]}");
        Server.SendRconCommand($"weburl {envVars["WEB_URL"]}");
        hiddenCommand = envVars["HIDDEN_COMMAND"];
        SetGameModeText(envVars["GAME_MODE_TEXT"]);
        var mapName = envVars["MAP_NAME"];

        StartTimer(string.IsNullOrWhiteSpace(mapName) ? null : mapName);

        TeamAlpha = new Team(
            skin: SkinTeam.Alpha,
            otherColor: "{FF2040}",
            colorGameText: "~r~",
            TextDrawGlobal.TdScoreAlpha,
            teamid: TeamID.Alpha,
            name: "Alpha",
            namecolor: "Roja",
            colorEnglish: "Red",
            new Flag(FlagID.Alpha, Color.Red, LoadFlagPosition("Red")),
            Interior
            );

        TeamBeta = new Team(
            skin: SkinTeam.Beta,
            otherColor: "{0088FF}",
            colorGameText: "~b~",
            TextDrawGlobal.TdScoreBeta,
            teamid: TeamID.Beta,
            name: "Beta",
            namecolor: "Azul",
            colorEnglish: "Blue",
            new Flag(FlagID.Beta, Color.Blue, LoadFlagPosition("Blue")),
            Interior
            );
        TeamAlpha.TeamRival = TeamBeta;
        TeamBeta.TeamRival  = TeamAlpha;
        Server.SendRconCommand($"mapname {GetCurrentMap()}");
        Server.SendRconCommand($"loadfs {GetCurrentMap()}");
        Server.SetWeather(Weather);
        Server.SetWorldTime(WorldTime);
        base.OnInitialized(e);
    }
Beispiel #7
0
    /// <summary>
    /// Edit Simulation.Settings window function (always top of _windows stack)
    /// </summary>
    /// <param name="windowID">Window ID.</param>
    void SimulationSettingsWindow(int windowID)
    {
        GUILayout.BeginHorizontal();

        if (!_settings.active)
        {
            // if this settings is already batched
            if (Simulation.batch.Contains(_settings))
            {
                // button to remove from batch
                if (GUILayout.Button("Remove from batch"))
                {
                    Simulation.batch.Remove(_settings);
                    _windows.Pop();
                    return;
                }
                // cancel button
                if (GUILayout.Button("Close window"))
                {
                    _windows.Pop();
                    return;
                }
            }
            // this settings isn't in the batch
            else
            {
                // button to add valid settings to batch
                if (_settings.isValid)
                {
                    if (GUILayout.Button("Add to batch"))
                    {
                        Simulation.batch.Add(_settings);
                        _windows.Pop();
                        return;
                    }
                }
                // cancel button
                if (GUILayout.Button("Cancel"))
                {
                    _windows.Pop();
                    return;
                }
            }
        }
        else
        {
            GUILayout.Button("Simulation running!");
            if (GUILayout.Button("Close"))
            {
                _windows.Pop();
                return;
            }
        }

        GUILayout.EndHorizontal();

        float lw = 200f;

        // copy settings for UI
        string title                  = settings.title;
        string robotName              = settings.robotName;
        string environmentName        = settings.environmentName;
        string navigationAssemblyName = settings.navigationAssemblyName;
        string numberOfTests          = settings.numberOfTests.ToString();
        string testTime               = settings.maximumTestTime.ToString();
        bool   randomDest             = settings.randomizeDestination;
        bool   randomStart            = settings.randomizeOrigin;
        bool   repeatOnComplete       = settings.continueOnNavObjectiveComplete;
        bool   repeatOnStuck          = settings.continueOnRobotIsStuck;

        // if settings is in use by Simulation
        if (settings.active)
        {
            // display only
            GUILayout.Label(settings.title + "\n" +
                            settings.robotName + "\n" +
                            settings.environmentName + "\n" +
                            settings.navigationAssemblyName);
        }
        else
        {
            // provide controls for editing

            // edit title
            GUILayout.BeginHorizontal();
            GUILayout.Label("Title", GUILayout.Width(lw));
            title = GUILayout.TextField(title);
            GUILayout.EndHorizontal();

            // edit number of tests
            GUILayout.BeginHorizontal();
            GUILayout.Label("Number of tests: ", GUILayout.Width(lw));
            numberOfTests = GUILayout.TextField(numberOfTests);
            GUILayout.EndHorizontal();

            // change the robot
            GUILayout.BeginHorizontal();
            GUILayout.Label("Robot selection: ", GUILayout.Width(lw));
            if (GUILayout.Button(robotName))
            {
                BotLoader.SearchForRobots();
                _windows.Push(RobotGalleryWindow);
            }
            GUILayout.EndHorizontal();

            // change the environment
            GUILayout.BeginHorizontal();
            GUILayout.Label("Environment selection: ", GUILayout.Width(lw));
            if (GUILayout.Button(environmentName))
            {
                EnvLoader.SearchForEnvironments();
                _windows.Push(EnvironmentGalleryWindow);
            }
            GUILayout.EndHorizontal();

            // change the navigation assembly
            GUILayout.BeginHorizontal();
            GUILayout.Label("Algorithm selection: ", GUILayout.Width(lw));
            if (GUILayout.Button(navigationAssemblyName))
            {
                NavLoader.SearchForPlugins();
                _windows.Push(NavListWindow);
            }
            GUILayout.EndHorizontal();
        }

        // toggle random start position
        GUILayout.BeginHorizontal();
        GUILayout.Label("Randomize Start: ", GUILayout.Width(lw));
        randomStart = GUILayout.Toggle(randomStart, "");
        GUILayout.EndHorizontal();

        // toggle random destination position
        GUILayout.BeginHorizontal();
        GUILayout.Label("Randomize Destination: ", GUILayout.Width(lw));
        randomDest = GUILayout.Toggle(randomDest, "");
        GUILayout.EndHorizontal();

        // if settings is in use by Simulation
        if (settings.active)
        {
            // display time remaining and edit maximum test time
            GUILayout.BeginHorizontal();
            GUILayout.Label("Time (s): " + Simulation.time.ToString("G2"), GUILayout.Width(lw));
            testTime = GUILayout.TextField(testTime);
            GUILayout.EndHorizontal();
        }
        else
        {
            // edit maximum test time
            GUILayout.BeginHorizontal();
            GUILayout.Label("Maximum Simulation Time (s): ", GUILayout.Width(lw));
            testTime = GUILayout.TextField(testTime);
            GUILayout.EndHorizontal();
        }

        // edit toggle for automatically starting a new test
        GUILayout.BeginHorizontal();
        GUILayout.Label("Repeat on complete: ", GUILayout.Width(lw));
        repeatOnComplete = GUILayout.Toggle(repeatOnComplete, "");
        GUILayout.EndHorizontal();

        // edit toggle for stuck detection
        GUILayout.BeginHorizontal();
        GUILayout.Label("Repeat on stuck: ", GUILayout.Width(lw));
        repeatOnStuck = GUILayout.Toggle(repeatOnStuck, "");
        GUILayout.EndHorizontal();

        // check for valid data input before copying back to settings object
        bool valid = true;

        foreach (char c in Strings.invalidFileNameChars)
        {
            if (title.Contains(c.ToString()))
            {
                valid = false;
            }
        }
        if (valid)
        {
            settings.title = title;
        }

        if (Strings.IsDigitsOnly(numberOfTests))
        {
            try {
                settings.numberOfTests = Convert.ToInt32(numberOfTests);
            }
            catch {
                Debug.Log("User should enter a number...");
            }
        }

        if (Strings.IsDigitsOnly(testTime))
        {
            try {
                settings.maximumTestTime = Convert.ToInt32(testTime);
            }
            catch {
                Debug.Log("User should enter a number...");
            }
        }

        // copy valid data back to settings
        settings.robotName                      = robotName;
        settings.environmentName                = environmentName;
        settings.navigationAssemblyName         = navigationAssemblyName;
        settings.randomizeDestination           = randomDest;
        settings.randomizeOrigin                = randomStart;
        settings.continueOnNavObjectiveComplete = repeatOnComplete;
        settings.continueOnRobotIsStuck         = repeatOnStuck;

        GUI.DragWindow();
    }