private async Task <IActionResult> ShowGroupFormAsync(GroupSelection groupSelection)
    {
        // Pass slots
        ViewData["Slots"] = await _slotService.GetSlotsAsync().ToListAsync();

        return(await RenderAsync(ViewType.GroupSelection, groupSelection));
    }
    public void Command_RemoveFromGroup(List <string> Params)
    {
        string         gName = Params[0];
        GroupSelection g     = GetComponent <GroupSelection>();

        if (gName != "" && g.GroupNames.Count > 0)
        {
            if (g.GroupNames.Contains(gName))
            {
                int ID = g.GroupNames.IndexOf(gName);
                for (int x = 0; x < R.selectedVertex.Count; x++)
                {
                    if (g.Groups[ID].Contains(R.selectedVertex[x].transform.GetSiblingIndex()))
                    {
                        g.Groups[ID].Remove(R.selectedVertex[x].transform.GetSiblingIndex());
                    }
                }
                R.ConsoleMessage("\n<color=cyan>Removed vertices from group " + "\"" + gName + "\".</color>");
            }
            else
            {
                R.ConsoleMessage("\nThe group doesn't exist.");
            }
        }
        else
        {
            R.ConsoleMessage("\nInsert a name.");
        }
    }
Example #3
0
        protected override void Awake()
        {
            base.Awake();

            selection = Instantiate(selection);
            selection.transform.localScale = new Vector3(GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH, GridManager.PIECE_WIDTH);

            _nextBombSpawnScore = _bombInterval;

            inputReceiver.ClickEvent += OnClick;
            inputReceiver.SwipeEvent += OnSwipe;
        }
Example #4
0
 private string GetGroupInfo(int id)
 {
     if (_selections != null)
     {
         GroupSelection info = _selections.FirstOrDefault(g => g.id == id);
         if (info != null)
         {
             return(info.ToString());
         }
     }
     return(string.Empty);
 }
        public void SelectGroup(GroupSelection group)
        {
            if (_myMethod.Equals(AutomationMethods.SendMessage))
            {
                Interop.SendMessage(_myHandle, (uint)Interop.WMessages.Keydown, (IntPtr)group, IntPtr.Zero);
                Interop.SendMessage(_myHandle, (uint)Interop.WMessages.Keyup, (IntPtr)group, IntPtr.Zero);
            }

            else if (_myMethod.Equals(AutomationMethods.PostMessage))
            {
                Interop.PostMessage(_myHandle, (uint)Interop.WMessages.Keydown, (IntPtr)group, IntPtr.Zero);
                Interop.PostMessage(_myHandle, (uint)Interop.WMessages.Keyup, (IntPtr)group, IntPtr.Zero);
            }
        }
        public void SelectGroup(GroupSelection group)
        {
            if (_myMethod.Equals(AutomationMethods.SendMessage))
            {
                Interop.SendMessage(_myHandle, (uint)Interop.WMessages.Keydown, (IntPtr)group, IntPtr.Zero);
                Interop.SendMessage(_myHandle, (uint)Interop.WMessages.Keyup, (IntPtr)group, IntPtr.Zero);
            }

            else if (_myMethod.Equals(AutomationMethods.PostMessage))
            {
                Interop.PostMessage(_myHandle, (uint)Interop.WMessages.Keydown, (IntPtr)group, IntPtr.Zero);
                Interop.PostMessage(_myHandle, (uint)Interop.WMessages.Keyup, (IntPtr)group, IntPtr.Zero);
            }
        }
Example #7
0
        public override void Load()
        {
            #region Chargement de la musique
            sndMusic = AssetManager.mscVictory;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Image de background
            _backgroundColor = Color.Transparent;
            _background      = AssetManager.Victory;
            #endregion

            #region Création des éléments la GUI
            SpriteFont font         = AssetManager.MenuFont;
            int        screenWidth  = MainGame.Screen.Width;
            int        screenHeight = MainGame.Screen.Height;

            _groupMenu = new GroupSelection();

            string text = "MENU";
            _menu = new Textbox(new Vector2(-200, (screenHeight - font.MeasureString(text).Y) / 2 - 40), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_menu);

            text  = "QUITTER";
            _exit = new Textbox(new Vector2(-2200, (screenHeight - font.MeasureString(text).Y) / 2 + 40), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_exit);

            text    = "L'" + MainGame.Winner + " gagne !";
            _winner = new Textbox(new Vector2(-3000, 50), font, text);
            _winner.ApplyColor(Color.Green, Color.Black);

            _groupMenu.RefreshColors();
            _groupMenu.CurrentSelection = 0;

            foreach (Textbox txt in _groupMenu.Elements)
            {
                txt.OnHover += Textbox_OnHover;
                txt.OnClick += Textbox_OnClick;
            }
            #endregion

            #region Création du tweening
            _tweeningMenu   = new Tweening(Tweening.Tween.InSine, (int)_menu.Position.X, (int)(screenWidth - _menu.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningExit   = new Tweening(Tweening.Tween.InSine, (int)_exit.Position.X, (int)(screenWidth - _exit.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningWinner = new Tweening(Tweening.Tween.InSine, (int)_winner.Position.X, (int)(screenWidth - _winner.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            #endregion

            base.Load();
        }
    public void Command_Groups()
    {
        GroupSelection g = GetComponent <GroupSelection>();

        R.ConsoleMessage("\n<color=yellow>Groups: </color>");
        for (int x = 0; x < g.Groups.Count; x++)
        {
            R.ConsoleMessage("\"" + g.GroupNames[x] + "\" ");
        }
        if (g.Groups.Count == 0)
        {
            R.ConsoleMessage("None");
        }
    }
Example #9
0
        public static string AnimalDataFileLocation(GroupSelection group)
        {
            switch (group)
            {
            case GroupSelection.Birds:
                return(@"../../DataFiles/Birds.txt");

            case GroupSelection.Reptiles:
                return(@"../../DataFiles/Reptiles.txt");

            case GroupSelection.Mammals:
                return(@"../../DataFiles/Mammals.txt");

            case GroupSelection.Others:
                return(@"../../DataFiles/Others.txt");
            }

            return("");
        }
Example #10
0
        // Rotate the selected hexagon pieces on the grid around the center point by degrees
        public IEnumerator RotateSelection(GroupSelection selection, float degrees)
        {
            Quaternion currentAngles   = Quaternion.Euler(selection.transform.localEulerAngles);
            Vector3    initialRotation = new Vector3();
            Vector3    targetRotation  = new Vector3(0f, 0f, degrees);

            HexagonPiece p1 = selection.Group.Piece1;
            HexagonPiece p2 = selection.Group.Piece2;
            HexagonPiece p3 = selection.Group.Piece3;

            // Rotation happens by rotation the direction vectors
            Vector3 selectionCenter = selection.transform.localPosition;
            Vector3 dir1            = p1.transform.localPosition - selectionCenter;
            Vector3 dir2            = p2.transform.localPosition - selectionCenter;
            Vector3 dir3            = p3.transform.localPosition - selectionCenter;

            float t           = 0f;
            float tMultiplier = _selectionRotateSpeed / Mathf.Abs(degrees);

            while ((t = t + Time.deltaTime * tMultiplier) < 1f)
            {
                // Using Quaternion.LerpUnclamped applies no rotation for degrees=360, this is actually smart but not desirable in this case
                Quaternion rotation = Quaternion.Euler(Vector3.LerpUnclamped(initialRotation, targetRotation, t));

                selection.transform.localRotation = currentAngles * rotation;
                p1.transform.localPosition        = selectionCenter + rotation * dir1;
                p2.transform.localPosition        = selectionCenter + rotation * dir2;
                p3.transform.localPosition        = selectionCenter + rotation * dir3;

                yield return(null);
            }

            // Can't rely on floating point precision, rotated pieces may deviate from their intended positions after a number of turns,
            // put the rotated pieces at their exact position after the rotation is complete
            selection.transform.localRotation = currentAngles * Quaternion.Euler(targetRotation);
            p1.transform.localPosition        = GridManager.Instance[p1.GridPos.x].CalculatePositionAt(p1.GridPos.y);
            p2.transform.localPosition        = GridManager.Instance[p2.GridPos.x].CalculatePositionAt(p2.GridPos.y);
            p3.transform.localPosition        = GridManager.Instance[p3.GridPos.x].CalculatePositionAt(p3.GridPos.y);
        }
    public void Command_CreateGroup(List <string> Params)
    {
        string         gName = Params[0];
        GroupSelection g     = GetComponent <GroupSelection>();

        if (gName != "")
        {
            if (g.GroupNames.Contains(gName) == false)
            {
                g.GroupNames.Add(gName);
                g.Groups.Add(new List <int>());
                R.ConsoleMessage("\n<color=cyan>Group \"" + gName + "\" has been created. Select vertices and add them to the group with /addtogroup NAME.</color>");
            }
            else
            {
                R.ConsoleMessage("\nA group with this name already exists.");
            }
        }
        else
        {
            R.ConsoleMessage("\nInsert a name.");
        }
    }
    public void Command_UnselectGroup(List <string> Params)
    {
        string         gName = Params[0];
        GroupSelection g     = GetComponent <GroupSelection>();

        if (gName != "" && g.GroupNames.Count > 0)
        {
            if (g.GroupNames.Contains(gName) == true)
            {
                int ID = g.GroupNames.IndexOf(gName);
                GetComponent <GroupSelection>().UnselectGroupByID(ID);
                R.ConsoleMessage("\nUnselected group.");
            }
            else
            {
                R.ConsoleMessage("\nThe group doesn't exist.");
            }
        }
        else
        {
            R.ConsoleMessage("\nInsert a name.");
        }
    }
    public void Command_DeleteGroup(List <string> Params)
    {
        string         gName = Params[0];
        GroupSelection g     = GetComponent <GroupSelection>();

        if (gName != "" && g.GroupNames.Count > 0)
        {
            if (g.GroupNames.Contains(gName) == true)
            {
                int ID = g.GroupNames.IndexOf(gName);
                g.GroupNames.Remove(gName);
                g.Groups.RemoveAt(ID);
                R.ConsoleMessage("\n<color=orange>Group \"" + gName + "\" has been deleted.</color>");
            }
            else
            {
                R.ConsoleMessage("\nThe group doesn't exist.");
            }
        }
        else
        {
            R.ConsoleMessage("\nInsert a name.");
        }
    }
Example #14
0
    private void Load()
    {
        if (File.Exists(Path))
        {
#if USING_XML
            XmlSerializer ser = new XmlSerializer(typeof(ZConfig));
            using (Stream stream = File.OpenRead(Path))
            {
                ZConfig config = ser.Deserialize(stream) as ZConfig;
                _groups     = config.groups;
                _selections = config.selections;
            }
#else
            string json      = File.ReadAllText(Path);
            string groupJson = File.ReadAllText(GroupInfoPath);
            _groups     = JsonMapper.ToObject <List <GroupConfig> >(json);
            _selections = JsonMapper.ToObject <List <GroupSelection> >(groupJson);
#endif
        }

        if (_groups == null)
        {
            _groups = new List <GroupConfig>();
            GroupConfig group = new GroupConfig();
            group.Initialize();
            _groups.Add(group);
        }
        if (_selections == null)
        {
            _selections = new List <GroupSelection>();
            GroupSelection sel = new GroupSelection {
                name = "Default", desc = "Default group"
            };
            _selections.Add(sel);
        }
    }
Example #15
0
    private void DrawGroup()
    {
        EditorGUILayout.BeginVertical();
        {
            _groupFoldout = EditorGUILayout.Foldout(_groupFoldout, "GROUP");
            {
                if (_groupFoldout)
                {
                    for (int i = 0; i < _selections.Count; i++)
                    {
                        GroupSelection selection = _selections[i];
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(i.ToString());
                            selection.id   = i;
                            selection.name = EditorGUILayout.TextField(selection.name);
                            selection.desc = EditorGUILayout.TextField(selection.desc);

                            if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(25)))                             //add resource
                            {
                                _selections.Insert(i + 1, new GroupSelection());
                                return;
                            }
                            if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(25)))                             //remove resource
                            {
                                _selections.RemoveAt(i);
                                return;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }
        EditorGUILayout.EndVertical();
    }
    public async Task <IActionResult> HandleGroupSelectionAsync(GroupSelection groupSelection)
    {
        // Some input validation
        if (!ModelState.IsValid)
        {
            AddStatusMessage(_localizer["HandleGroupSelectionAsync:InvalidInput"], StatusMessageTypes.Error);
            return(await ShowGroupFormAsync(groupSelection));
        }

        // Does the user already have a group?
        var currentUser = await GetCurrentUserAsync();

        if (currentUser.Group != null)
        {
            return(await ShowRedirectAsync(null));
        }

        // Try to create group
        try
        {
            // Filter group codes
            var groupSizeMin = await _configurationService.GetGroupSizeMinAsync(HttpContext.RequestAborted);

            var groupSizeMax = await _configurationService.GetGroupSizeMaxAsync(HttpContext.RequestAborted);

            var codes = groupSelection.OtherUserCodes
                        .Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
                        .Where(c => !string.IsNullOrWhiteSpace(c))
                        .Append(currentUser.GroupFindingCode)
                        .Select(c => c.Trim())
                        .Distinct()
                        .ToList();
            if (codes.Count < groupSizeMin)
            {
                AddStatusMessage(_localizer["HandleGroupSelectionAsync:TooFewCodes", groupSizeMin], StatusMessageTypes.Error);
                return(await ShowGroupFormAsync(groupSelection));
            }

            if (codes.Count > groupSizeMax)
            {
                AddStatusMessage(_localizer["HandleGroupSelectionAsync:TooManyCodes", groupSizeMax], StatusMessageTypes.Error);
                return(await ShowGroupFormAsync(groupSelection));
            }

            // Create group
            // The service method will do further error checking (i.e., validity of codes, whether users are already in a group, ...)
            var group = new Group
            {
                DisplayName      = groupSelection.DisplayName,
                SlotId           = groupSelection.SlotId,
                ShowInScoreboard = groupSelection.ShowInScoreboard
            };
            await _userService.CreateGroupAsync(group, codes, HttpContext.RequestAborted);
        }
        catch (ArgumentException)
        {
            AddStatusMessage(_localizer["HandleGroupSelectionAsync:InvalidInput"], StatusMessageTypes.Error);
            return(await ShowGroupFormAsync(groupSelection));
        }
        catch (InvalidOperationException)
        {
            AddStatusMessage(_localizer["HandleGroupSelectionAsync:CodeAlreadyAssigned"], StatusMessageTypes.Error);
            return(await ShowGroupFormAsync(groupSelection));
        }
        catch (Exception ex)
        {
            // Should only happen on larger database failures or when users mess around with the input model
            _logger.LogError(ex, "Create group");
            AddStatusMessage(_localizer["HandleGroupSelectionAsync:UnknownError"], StatusMessageTypes.Error);
            return(await ShowGroupFormAsync(groupSelection));
        }

        // Success
        AddStatusMessage(_localizer["HandleGroupSelectionAsync:Success"], StatusMessageTypes.Success);
        return(await ShowRedirectAsync(null));
    }
 private void BtnOthers_Click(object sender, EventArgs e)
 {
     selectedGroup = GroupSelection.Others;
     GroupSelectedClickHandler();
 }
Example #18
0
        public override void Load()
        {
            #region Chargement de la musique
            sndMusic = AssetManager.mscMenu;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Image de background
            _backgroundColor = Color.Transparent;
            _background      = AssetManager.Menu;
            #endregion

            #region Création des éléments la GUI
            SpriteFont font         = AssetManager.MenuFont;
            int        screenWidth  = MainGame.Screen.Width;
            int        screenHeight = MainGame.Screen.Height;

            #region Menu
            _groupMenu = new GroupSelection();

            string text = "JOUER";
            _play = new Textbox(new Vector2(-200, (screenHeight - font.MeasureString(text).Y) / 2 - 80), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_play);

            text       = "COMMENT JOUER";
            _howToPlay = new Textbox(new Vector2(-1200, (screenHeight - font.MeasureString(text).Y) / 2), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_howToPlay);

            text  = "QUITTER";
            _exit = new Textbox(new Vector2(-2200, (screenHeight - font.MeasureString(text).Y) / 2 + 80), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_exit);

            text          = "ENTRAINER L'IA";
            _trainingMode = new Textbox(new Vector2(-3200, (screenHeight - font.MeasureString(text).Y) / 2 + 160), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_trainingMode);

            _groupMenu.RefreshColors();
            _groupMenu.CurrentSelection = 0;

            foreach (Textbox txt in _groupMenu.Elements)
            {
                txt.OnHover += MenuTextbox_OnHover;
                txt.OnClick += MenuTextbox_OnClick;
            }
            #endregion

            #region Nombre d'équipes
            _numberOfTeamDescription = new Textbox(new Vector2(-1000, 10), font, "Nombre d'équipes : ");

            _groupNbOfTeam = new GroupSelection();
            _numberOfTeam  = new Textbox[3];
            for (int i = 0; i < _numberOfTeam.Length; i++)
            {
                _numberOfTeam[i] = new Textbox(new Vector2(-1610 + 80 * i, 10), font, (i + 2).ToString());
                _groupNbOfTeam.AddElement((IIntegrableMenu)_numberOfTeam[i]);

                _numberOfTeam[i].OnClick += NbOfTeamTextbox_OnClick;
            }
            _groupNbOfTeam.CurrentSelection = 0;
            SelectNbOfTeam();
            #endregion

            #region Nombre de tanks
            _numberOfTankDescription = new Textbox(new Vector2(-1000, 80), font, "Nombre de tanks : ");

            _groupNbOfTank = new GroupSelection();
            _numberOfTank  = new Textbox[5];
            for (int i = 0; i < _numberOfTank.Length; i++)
            {
                _numberOfTank[i] = new Textbox(new Vector2(-1610 + 80 * i, 80), font, (i + 1).ToString());
                _groupNbOfTank.AddElement((IIntegrableMenu)_numberOfTank[i]);

                _numberOfTank[i].OnClick += NbOfTankTextbox_OnClick;
            }
            _groupNbOfTank.CurrentSelection = 0;
            SelectNbOfTank();
            #endregion

            #endregion

            #region Création du tweening
            _tweeningPlay         = new Tweening(Tweening.Tween.InSine, (int)_play.Position.X, (int)(screenWidth - _play.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeninghowToPlay    = new Tweening(Tweening.Tween.InSine, (int)_howToPlay.Position.X, (int)(screenWidth - _howToPlay.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningExit         = new Tweening(Tweening.Tween.InSine, (int)_exit.Position.X, (int)(screenWidth - _exit.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningTrainingMode = new Tweening(Tweening.Tween.InSine, (int)_trainingMode.Position.X, (int)(screenWidth - _trainingMode.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));

            _tweeningNbOfTeamDescription = new Tweening(Tweening.Tween.InSine, (int)_numberOfTeamDescription.Position.X, 10, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningNbOfTankDescription = new Tweening(Tweening.Tween.InSine, (int)_numberOfTankDescription.Position.X, 10, new TimeSpan(0, 0, 0, TIMER_INTRO));

            _tweeningNbOfTeam = new Tweening[_numberOfTeam.Length];
            for (int i = 0; i < _tweeningNbOfTeam.Length; i++)
            {
                _tweeningNbOfTeam[i] = new Tweening(Tweening.Tween.InSine, (int)_numberOfTeam[i].Position.X, 610 + 80 * i, new TimeSpan(0, 0, 0, TIMER_INTRO));
            }

            _tweeningNbOfTank = new Tweening[_numberOfTank.Length];
            for (int i = 0; i < _tweeningNbOfTank.Length; i++)
            {
                _tweeningNbOfTank[i] = new Tweening(Tweening.Tween.InSine, (int)_numberOfTank[i].Position.X, 610 + 80 * i, new TimeSpan(0, 0, 0, TIMER_INTRO));
            }
            #endregion

            base.Load();
        }
 private void BtnMammals_Click(object sender, EventArgs e)
 {
     selectedGroup = GroupSelection.Mammals;
     GroupSelectedClickHandler();
 }
Example #20
0
        protected virtual void Awake()
        {
            Time.timeScale = 1.0f; //unfreeze game if it was frozen from a previous game.

            Initialized = false;   //faction stats are not ready, yet

            //Get components:
            CamMgr           = FindObjectOfType(typeof(CameraController)) as CameraController; //Find the camera movement script.
            ResourceMgr      = FindObjectOfType(typeof(ResourceManager)) as ResourceManager;   //Find the resource manager script.
            BuildingMgr      = FindObjectOfType(typeof(BuildingManager)) as BuildingManager;
            TaskMgr          = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            UnitMgr          = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr     = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            GroupSelection   = FindObjectOfType(typeof(UnitGroupSelection)) as UnitGroupSelection;
            PlacementMgr     = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr       = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr           = FindObjectOfType(typeof(MovementManager)) as MovementManager;
            UIMgr            = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            ErrorMessageMgr  = FindObjectOfType(typeof(ErrorMessageHandler)) as ErrorMessageHandler;
            MinimapIconMgr   = FindObjectOfType(typeof(MinimapIconManager)) as MinimapIconManager;
            AttackWarningMgr = FindObjectOfType(typeof(AttackWarningManager)) as AttackWarningManager;
            AttackMgr        = FindObjectOfType(typeof(AttackManager)) as AttackManager;
            EffectPool       = FindObjectOfType(typeof(EffectObjPool)) as EffectObjPool;
            UpgradeMgr       = FindObjectOfType(typeof(UpgradeManager)) as UpgradeManager;
            InputMgr         = FindObjectOfType(typeof(InputManager)) as InputManager;
#if RTSENGINE_FOW
            FoWMgr = FindObjectOfType(typeof(FogOfWarRTSManager)) as FogOfWarRTSManager;
#endif

#if RTSENGINE_FOW
            if (FoWMgr) //only if there's a fog of war manager in the scene
            {
                FoWMgr.Init(this);
            }
#endif

            CamMgr.Init(this);
            MinimapIconMgr?.Init(this);
            MvtMgr.Init(this);
            TaskMgr.Init(this);
            SelectionMgr.Init(this);
            GroupSelection.Init(this);
            PlacementMgr.Init(this);
            TerrainMgr.Init(this);
            UIMgr.Init(this); //initialize the UI manager.
            ErrorMessageMgr.Init(this);
            AttackWarningMgr?.Init(this);
            AttackMgr.Init(this);
            EffectPool.Init(this);
            UpgradeMgr.Init(this);
            ResourceMgr.Init(this);
            BuildingMgr.Init(this);
            UnitMgr.Init(this);
            InputMgr.Init(this);

            MultiplayerGame = false;                               //We start by assuming it's a single player game.

            if (!InitMultiplayerGame() && !InitSinglePlayerGame()) //if it's not neither a multiplayer nor a single player game
            {
                InitFactions();                                    //we're starting the game directly from the editor in the map scene, init factions directly
            }

            ResourceMgr.InitFactionResources();       //init resources for factions.

            InitCampaignGame();                       //initialise a game where the player is coming from the campaign menu to play a mission
            SetPlayerFaction();                       //pick the player faction ID.
            InitDefaultEntities();                    //initialise the pre-spawned faction units and factions

            ResourceMgr.InitResources();              //init the pre-spawned resources.

            UnitMgr.OnFactionSlotsInitialized();      //init free units
            BuildingMgr.OnFactionSlotsInitialized();  //init free buildings
            if (MultiplayerGame)                      //if this is a multiplayer game
            {
                InputMgr.OnFactionSlotsInitialized(); //init spawnable prefabs and default entities in a multiplayer game
            }
            //In order to avoid having buildings that are being placed by AI players and units collide, we will ignore physics between their two layers:
            Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Hidden"), LayerMask.NameToLayer("Unit"));

            //Set the amount of the active factions:
            activefactionsAmount = factions.Count;

            SetGameState(GameState.running);          //the game state is now set to running

            UIMgr.PeaceTime.Toggle(peaceTime > 0.0f); //enable the peace time panel if there's actual peace time assigned

            //reaching this point means that all faction info/stats in the game manager are ready:
            Initialized = true;
        }
Example #21
0
    public void SaveGroupsToXfbin(int groupNum, string path__)
    {
        try
        {
            Transform ModelDataTransform;
            ModelDataTransform = GameObject.Find("Model Data").GetComponent <Transform>();

            List <byte> triangleFileNew = new List <byte>();
            List <byte> vertexFileNew   = new List <byte>();
            List <byte> textureFileNew  = new List <byte>();

            //DialogResult dial = MessageBox.Show("Fix vertex count and face count? This fix is only useful if you have used /importobj. However, /impobjpos does not need it.", "Warning", MessageBoxButtons.YesNo);

            rf.meshNormals   = rf.mf.mesh.normals.ToList();
            rf.meshTriangles = rf.mf.mesh.triangles.ToList();
            rf.meshVertices  = rf.mf.mesh.vertices.ToList();

            List <Vector3> meshVertices       = rf.meshVertices;
            List <int>     meshTriangles_full = rf.meshTriangles;
            List <int>     meshTriangles      = new List <int>();
            List <Vector3> meshNormals        = rf.meshNormals;
            List <Vector2> meshUVs            = rf.mf.mesh.uv.ToList();
            List <Vector4> vertexWeight       = rf.vertexWeight.ToList();
            List <Vector4> vertexBone         = rf.vertexBone.ToList();

            int            VertexCount = 0;
            GroupSelection gp          = GetComponent <GroupSelection>();

            for (int x = 0; x < meshTriangles_full.Count; x = x + 3)
            {
                if (gp.Groups[groupNum].Contains(meshTriangles_full[x + 0]) && gp.Groups[groupNum].Contains(meshTriangles_full[x + 1]) && gp.Groups[groupNum].Contains(meshTriangles_full[x + 2]))
                {
                    meshTriangles.Add(meshTriangles_full[x + 0]);
                    meshTriangles.Add(meshTriangles_full[x + 1]);
                    meshTriangles.Add(meshTriangles_full[x + 2]);
                }
            }

            VertexCount = meshVertices.Count;

            for (int x = 0; x < VertexCount; x++)
            {
                for (int z = 0; z < rf.byteLength; z++)
                {
                    vertexFileNew.Add(0x00);
                }
            }

            for (int x = 0; x < VertexCount; x++)
            {
                byte[] posx = BitConverter.GetBytes(meshVertices[x].x).ToArray();
                if (rf.stageMode == true)
                {
                    posx = BitConverter.GetBytes(meshVertices[x].x * 20).ToArray();
                }
                Array.Reverse(posx);
                vertexFileNew[0x0 + (rf.byteLength * x)] = posx[0];
                vertexFileNew[0x1 + (rf.byteLength * x)] = posx[1];
                vertexFileNew[0x2 + (rf.byteLength * x)] = posx[2];
                vertexFileNew[0x3 + (rf.byteLength * x)] = posx[3];

                byte[] posz = BitConverter.GetBytes(meshVertices[x].z).ToArray();
                if (rf.stageMode == true)
                {
                    posz = BitConverter.GetBytes(meshVertices[x].z * 20).ToArray();
                }
                Array.Reverse(posz);
                vertexFileNew[0x4 + (rf.byteLength * x)] = posz[0];
                vertexFileNew[0x5 + (rf.byteLength * x)] = posz[1];
                vertexFileNew[0x6 + (rf.byteLength * x)] = posz[2];
                vertexFileNew[0x7 + (rf.byteLength * x)] = posz[3];

                byte[] posy = BitConverter.GetBytes(meshVertices[x].y).ToArray();
                if (rf.stageMode == true)
                {
                    posy = BitConverter.GetBytes(meshVertices[x].y * 20).ToArray();
                }
                Array.Reverse(posy);
                vertexFileNew[0x8 + (rf.byteLength * x)] = posy[0];
                vertexFileNew[0x9 + (rf.byteLength * x)] = posy[1];
                vertexFileNew[0xA + (rf.byteLength * x)] = posy[2];
                vertexFileNew[0xB + (rf.byteLength * x)] = posy[3];

                if (rf.byteLength == 0x1C)
                {
                    byte[] NXA = RenderFile.ToInt(meshNormals[x].x);
                    Array.Reverse(NXA);

                    byte[] NYA = RenderFile.ToInt(meshNormals[x].y);
                    Array.Reverse(NYA);

                    byte[] NZA = RenderFile.ToInt(meshNormals[x].z);
                    Array.Reverse(NZA);

                    vertexFileNew[0xC + (rf.byteLength * x)] = NXA[0];
                    vertexFileNew[0xD + (rf.byteLength * x)] = NXA[1];

                    vertexFileNew[0xE + (rf.byteLength * x)] = NYA[0];
                    vertexFileNew[0xF + (rf.byteLength * x)] = NYA[1];

                    vertexFileNew[0x10 + (rf.byteLength * x)] = NZA[0];
                    vertexFileNew[0x11 + (rf.byteLength * x)] = NZA[1];
                }
                else if (rf.byteLength == 0x40)
                {
                    // BONE DATA
                    vertexFileNew[0x23 + (rf.byteLength * x)] = (byte)vertexBone[x].x;
                    vertexFileNew[0x27 + (rf.byteLength * x)] = (byte)vertexBone[x].y;
                    vertexFileNew[0x2B + (rf.byteLength * x)] = (byte)vertexBone[x].z;
                    vertexFileNew[0x2F + (rf.byteLength * x)] = (byte)vertexBone[x].w;

                    // WEIGHT DATA
                    byte[] weightx = BitConverter.GetBytes(vertexWeight[x].x).ToArray();
                    Array.Reverse(weightx);

                    vertexFileNew[0x30 + (rf.byteLength * x)] = weightx[0];
                    vertexFileNew[0x31 + (rf.byteLength * x)] = weightx[1];
                    vertexFileNew[0x32 + (rf.byteLength * x)] = weightx[2];
                    vertexFileNew[0x33 + (rf.byteLength * x)] = weightx[3];

                    byte[] weighty = BitConverter.GetBytes(vertexWeight[x].y).ToArray();
                    Array.Reverse(weighty);

                    vertexFileNew[0x34 + (rf.byteLength * x)] = weighty[0];
                    vertexFileNew[0x35 + (rf.byteLength * x)] = weighty[1];
                    vertexFileNew[0x36 + (rf.byteLength * x)] = weighty[2];
                    vertexFileNew[0x37 + (rf.byteLength * x)] = weighty[3];

                    byte[] weightz = BitConverter.GetBytes(vertexWeight[x].z).ToArray();
                    Array.Reverse(weightz);

                    vertexFileNew[0x38 + (rf.byteLength * x)] = weightz[0];
                    vertexFileNew[0x39 + (rf.byteLength * x)] = weightz[1];
                    vertexFileNew[0x3A + (rf.byteLength * x)] = weightz[2];
                    vertexFileNew[0x3B + (rf.byteLength * x)] = weightz[3];

                    byte[] weightw = BitConverter.GetBytes(vertexWeight[x].w).ToArray();
                    Array.Reverse(weightw);

                    vertexFileNew[0x3C + (rf.byteLength * x)] = weightw[0];
                    vertexFileNew[0x3D + (rf.byteLength * x)] = weightw[1];
                    vertexFileNew[0x3E + (rf.byteLength * x)] = weightw[2];
                    vertexFileNew[0x3F + (rf.byteLength * x)] = weightw[3];

                    // NORMALS
                    byte[] normalx = BitConverter.GetBytes(meshNormals[x].x).ToArray();
                    Array.Reverse(normalx);

                    vertexFileNew[0x10 + (rf.byteLength * x)] = normalx[0];
                    vertexFileNew[0x11 + (rf.byteLength * x)] = normalx[1];
                    vertexFileNew[0x12 + (rf.byteLength * x)] = normalx[2];
                    vertexFileNew[0x13 + (rf.byteLength * x)] = normalx[3];

                    byte[] normaly = BitConverter.GetBytes(meshNormals[x].y).ToArray();
                    Array.Reverse(normaly);

                    vertexFileNew[0x14 + (rf.byteLength * x)] = normaly[0];
                    vertexFileNew[0x15 + (rf.byteLength * x)] = normaly[1];
                    vertexFileNew[0x16 + (rf.byteLength * x)] = normaly[2];
                    vertexFileNew[0x17 + (rf.byteLength * x)] = normaly[3];

                    byte[] normalz = BitConverter.GetBytes(meshNormals[x].z).ToArray();
                    Array.Reverse(normalz);

                    vertexFileNew[0x18 + (rf.byteLength * x)] = normalz[0];
                    vertexFileNew[0x19 + (rf.byteLength * x)] = normalz[1];
                    vertexFileNew[0x1A + (rf.byteLength * x)] = normalz[2];
                    vertexFileNew[0x1B + (rf.byteLength * x)] = normalz[3];
                }
                else if (rf.byteLength == 0x20)
                {
                    // NORMALS
                    byte[] normalx = BitConverter.GetBytes(meshNormals[x].x).ToArray();
                    Array.Reverse(normalx);

                    vertexFileNew[0xC + (rf.byteLength * x)] = normalx[0];
                    vertexFileNew[0xD + (rf.byteLength * x)] = normalx[1];
                    vertexFileNew[0xE + (rf.byteLength * x)] = normalx[2];
                    vertexFileNew[0xF + (rf.byteLength * x)] = normalx[3];

                    byte[] normaly = BitConverter.GetBytes(meshNormals[x].y).ToArray();
                    Array.Reverse(normaly);

                    vertexFileNew[0x10 + (rf.byteLength * x)] = normaly[0];
                    vertexFileNew[0x11 + (rf.byteLength * x)] = normaly[1];
                    vertexFileNew[0x12 + (rf.byteLength * x)] = normaly[2];
                    vertexFileNew[0x13 + (rf.byteLength * x)] = normaly[3];

                    byte[] normalz = BitConverter.GetBytes(meshNormals[x].z).ToArray();
                    Array.Reverse(normalz);

                    vertexFileNew[0x14 + (rf.byteLength * x)] = normalz[0];
                    vertexFileNew[0x15 + (rf.byteLength * x)] = normalz[1];
                    vertexFileNew[0x16 + (rf.byteLength * x)] = normalz[2];
                    vertexFileNew[0x17 + (rf.byteLength * x)] = normalz[3];
                }
            }
            for (int x = 0; x < meshUVs.Count; x++)
            {
                if (rf.byteLength == 0x1C)
                {
                    byte[] UVXA = RenderFile.ToInt(meshUVs[x].x);
                    Array.Reverse(UVXA);

                    byte[] UVYA = RenderFile.ToInt(meshUVs[x].y);
                    Array.Reverse(UVYA);

                    vertexFileNew[0x18 + (rf.byteLength * x)] = UVXA[0];
                    vertexFileNew[0x19 + (rf.byteLength * x)] = UVXA[1];

                    vertexFileNew[0x1A + (rf.byteLength * x)] = UVYA[0];
                    vertexFileNew[0x1B + (rf.byteLength * x)] = UVYA[1];
                }
                else if (rf.byteLength == 0x20)
                {
                    byte[] UVXA = RenderFile.ToInt(meshUVs[x].x);
                    Array.Reverse(UVXA);

                    byte[] UVYA = RenderFile.ToInt(meshUVs[x].y);
                    Array.Reverse(UVYA);

                    vertexFileNew[0x18 + (rf.byteLength * x)] = UVXA[0];
                    vertexFileNew[0x19 + (rf.byteLength * x)] = UVXA[1];
                    vertexFileNew[0x1A + (rf.byteLength * x)] = UVYA[0];
                    vertexFileNew[0x1B + (rf.byteLength * x)] = UVYA[1];

                    vertexFileNew[0x1C + (rf.byteLength * x)] = 0;
                    vertexFileNew[0x1D + (rf.byteLength * x)] = 0;
                    vertexFileNew[0x1E + (rf.byteLength * x)] = 0;
                    vertexFileNew[0x1F + (rf.byteLength * x)] = 0;
                }
                else if (rf.byteLength == 0x40)
                {
                    if (rf.textureType == 0)
                    {
                        byte[] UVXA = RenderFile.ToInt(meshUVs[x].x);
                        Array.Reverse(UVXA);

                        byte[] UVYA = RenderFile.ToInt(meshUVs[x].y);
                        Array.Reverse(UVYA);

                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);

                        textureFileNew.Add(UVXA[0]);
                        textureFileNew.Add(UVXA[1]);
                        textureFileNew.Add(UVYA[0]);
                        textureFileNew.Add(UVYA[1]);
                    }
                    else if (rf.textureType == 1)
                    {
                        byte[] UVXA = RenderFile.ToInt(meshUVs[x].x);
                        Array.Reverse(UVXA);

                        byte[] UVYA = RenderFile.ToInt(meshUVs[x].y);
                        Array.Reverse(UVYA);

                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);
                        textureFileNew.Add(0xFF);

                        textureFileNew.Add(UVXA[0]);
                        textureFileNew.Add(UVXA[1]);
                        textureFileNew.Add(UVYA[0]);
                        textureFileNew.Add(UVYA[1]);

                        textureFileNew.Add(UVXA[0]);
                        textureFileNew.Add(UVXA[1]);
                        textureFileNew.Add(UVYA[0]);
                        textureFileNew.Add(UVYA[1]);
                    }
                }
            }

            for (int q = 0; q <= meshTriangles.Count - 3; q += 3)
            {
                byte[] tri1 = BitConverter.GetBytes(meshTriangles[q + 0]).ToArray();
                byte[] tri2 = BitConverter.GetBytes(meshTriangles[q + 1]).ToArray();
                byte[] tri3 = BitConverter.GetBytes(meshTriangles[q + 2]).ToArray();

                triangleFileNew.Add(tri3[1]);
                triangleFileNew.Add(tri3[0]);
                triangleFileNew.Add(tri2[1]);
                triangleFileNew.Add(tri2[0]);
                triangleFileNew.Add(tri1[1]);
                triangleFileNew.Add(tri1[0]);

                triangleFileNew.Add(0xFF);
                triangleFileNew.Add(0xFF);
            }

            int OriginalNDP3Size =
                rf.OriginalNDP3[0x4] * 0x1000000 +
                rf.OriginalNDP3[0x5] * 0x10000 +
                rf.OriginalNDP3[0x6] * 0x100 +
                rf.OriginalNDP3[0x7];

            int SizeBeforeNDP3Index = 0;
            int sizeMode            = 0;

            int x_ = 0;
            while (rf.OriginalXfbin[rf.NDP3Index - 4 + x_] * 0x1000000 + rf.OriginalXfbin[rf.NDP3Index - 3 + x_] * 0x10000 + rf.OriginalXfbin[rf.NDP3Index - 2 + x_] * 0x100 + rf.OriginalXfbin[rf.NDP3Index - 1 + x_] != OriginalNDP3Size)
            {
                x_--;
            }

            SizeBeforeNDP3Index = x_ - 4;

            List <byte> newNDP3File = new List <byte>();
            for (int x = 0; x < 0x10; x++)
            {
                newNDP3File.Add(rf.OriginalNDP3[x]);
            }

            //Add first section size
            for (int x = 0; x < 4; x++)
            {
                newNDP3File.Add(rf.OriginalNDP3[0x10 + x]);
            }
            int firstSectionSize_ = newNDP3File[16] * 0x1000000 + newNDP3File[17] * 0x10000 + newNDP3File[18] * 0x100 + newNDP3File[19];

            //Add triangle section size
            int TriangleSectionSize = triangleFileNew.Count;

            if (TriangleSectionSize < 0x100)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(TriangleSectionSize);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(arrayOfSize[0]);
            }
            else if (TriangleSectionSize >= 0x100 && TriangleSectionSize < 0x10000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(TriangleSectionSize);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(arrayOfSize[1]);
                newNDP3File.Add(arrayOfSize[0]);
            }
            else if (TriangleSectionSize >= 0x10000 && TriangleSectionSize < 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(TriangleSectionSize);
                newNDP3File.Add(0);
                newNDP3File.Add(arrayOfSize[2]);
                newNDP3File.Add(arrayOfSize[1]);
                newNDP3File.Add(arrayOfSize[0]);
            }
            else if (TriangleSectionSize >= 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(TriangleSectionSize);
                newNDP3File.Add(arrayOfSize[3]);
                newNDP3File.Add(arrayOfSize[2]);
                newNDP3File.Add(arrayOfSize[1]);
                newNDP3File.Add(arrayOfSize[0]);
            }

            //Check vertex length
            if (rf.byteLength == 0x40)
            {
                //Add texture section size
                int TextureSectionSize = textureFileNew.Count;

                if (TextureSectionSize < 0x100)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(TextureSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (TextureSectionSize >= 0x100 && TextureSectionSize < 0x10000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(TextureSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (TextureSectionSize >= 0x10000 && TextureSectionSize < 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(TextureSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (TextureSectionSize >= 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(TextureSectionSize);
                    newNDP3File.Add(arrayOfSize[3]);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }

                //Add vertex section size
                int VertexSectionSize = vertexFileNew.Count;

                if (VertexSectionSize < 0x100)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x100 && VertexSectionSize < 0x10000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x10000 && VertexSectionSize < 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(arrayOfSize[3]);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
            }
            else if (rf.byteLength == 0x1C)
            {
                //Add vertex section size
                int VertexSectionSize = vertexFileNew.Count;

                if (VertexSectionSize < 0x100)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x100 && VertexSectionSize < 0x10000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x10000 && VertexSectionSize < 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(arrayOfSize[3]);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
            }
            else if (rf.byteLength == 0x20)
            {
                //Add vertex section size
                int VertexSectionSize = vertexFileNew.Count;

                if (VertexSectionSize < 0x100)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x100 && VertexSectionSize < 0x10000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x10000 && VertexSectionSize < 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(0);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                else if (VertexSectionSize >= 0x1000000)
                {
                    byte[] arrayOfSize = BitConverter.GetBytes(VertexSectionSize);
                    newNDP3File.Add(arrayOfSize[3]);
                    newNDP3File.Add(arrayOfSize[2]);
                    newNDP3File.Add(arrayOfSize[1]);
                    newNDP3File.Add(arrayOfSize[0]);
                }
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
                newNDP3File.Add(0);
            }

            // Add rest of header
            for (int x = 0x20; x < 0x30; x++)
            {
                newNDP3File.Add(rf.OriginalNDP3[x]);
            }

            // Add first section
            for (int x = 0; x < firstSectionSize_; x++)
            {
                newNDP3File.Add(rf.OriginalNDP3[0x30 + x]);
            }

            // Add triangle section
            for (int x = 0; x < triangleFileNew.Count; x++)
            {
                newNDP3File.Add(triangleFileNew[x]);
            }

            if (rf.byteLength == 0x40)
            {
                // Add texture section
                for (int x = 0; x < textureFileNew.Count; x++)
                {
                    newNDP3File.Add(textureFileNew[x]);
                }
                // Add vertex section
                for (int x = 0; x < vertexFileNew.Count; x++)
                {
                    newNDP3File.Add(vertexFileNew[x]);
                }
            }
            else if (rf.byteLength == 0x1C || rf.byteLength == 0x20)
            {
                // Add vertex section
                for (int x = 0; x < vertexFileNew.Count; x++)
                {
                    newNDP3File.Add(vertexFileNew[x]);
                }
            }

            int newNDP3Size = newNDP3File.Count + OriginalNDP3Size - 48 - firstSectionSize_ - rf.triangleFile.Length - rf.textureMapFile.Length - rf.fileBytes.Length;

            List <byte> newXfbinFile = new List <byte>();

            // Copy old .xfbin file until ndp3
            for (int x = 0; x < rf.NDP3Index; x++)
            {
                newXfbinFile.Add(rf.OriginalXfbin[x]);
            }

            // Add new size before NDP3
            if (newNDP3Size < 0x100)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);

                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index]     = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 1] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 2] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 3] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x100 && newNDP3Size < 0x10000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);

                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index]     = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 1] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 2] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 3] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x10000 && newNDP3Size < 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);

                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index]     = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 1] = arrayOfSize[2];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 2] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 3] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);

                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index]     = arrayOfSize[3];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 1] = arrayOfSize[2];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 2] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index + 3] = arrayOfSize[0];
            }

            // Copy new NDP3
            for (int x = 0; x < newNDP3File.Count; x++)
            {
                newXfbinFile.Add(newNDP3File[x]);
            }

            // Fix new NDP3 size
            if (newNDP3Size < 0x100)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 4] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 5] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 6] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 7] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x100 && newNDP3Size < 0x10000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 4] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 5] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 6] = arrayOfSize[1];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 7] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x10000 && newNDP3Size < 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 4] = 0;
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 5] = arrayOfSize[2];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 6] = arrayOfSize[1];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 7] = arrayOfSize[0];
            }
            else if (newNDP3Size >= 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size);
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 4] = arrayOfSize[3];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 5] = arrayOfSize[2];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 6] = arrayOfSize[1];
                newXfbinFile[newXfbinFile.Count - newNDP3File.Count + 7] = arrayOfSize[0];
            }

            // Copy original name and rest of xfbin
            for (int x = rf.NDP3Index + (0x30 + firstSectionSize_ + rf.triangleFile.Length + rf.textureMapFile.Length + rf.fileBytes.Length); x < rf.OriginalXfbin.Length; x++)
            {
                newXfbinFile.Add(rf.OriginalXfbin[x]);
            }

            // Fix new NDP3 size 36
            int DifferenceBetweenSizes =
                (rf.OriginalXfbin[rf.NDP3Index + SizeBeforeNDP3Index - 0x24] * 0x1000000 +
                 rf.OriginalXfbin[rf.NDP3Index + SizeBeforeNDP3Index - 0x23] * 0x10000 +
                 rf.OriginalXfbin[rf.NDP3Index + SizeBeforeNDP3Index - 0x22] * 0x100 +
                 rf.OriginalXfbin[rf.NDP3Index + SizeBeforeNDP3Index - 0x21]) - OriginalNDP3Size;

            if (newNDP3Size + DifferenceBetweenSizes < 0x100)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size + DifferenceBetweenSizes);
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x24] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x23] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x22] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x21] = arrayOfSize[0];
            }
            else if (newNDP3Size + DifferenceBetweenSizes >= 0x100 && newNDP3Size + DifferenceBetweenSizes < 0x10000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size + DifferenceBetweenSizes);
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x24] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x23] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x22] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x21] = arrayOfSize[0];
            }
            else if (newNDP3Size + DifferenceBetweenSizes >= 0x10000 && newNDP3Size + DifferenceBetweenSizes < 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size + DifferenceBetweenSizes);
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x24] = 0;
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x23] = arrayOfSize[2];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x22] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x21] = arrayOfSize[0];
            }
            else if (newNDP3Size + DifferenceBetweenSizes >= 0x1000000)
            {
                byte[] arrayOfSize = BitConverter.GetBytes(newNDP3Size + DifferenceBetweenSizes);
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x24] = arrayOfSize[3];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x23] = arrayOfSize[2];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x22] = arrayOfSize[1];
                newXfbinFile[rf.NDP3Index + SizeBeforeNDP3Index - 0x21] = arrayOfSize[0];
            }

            // FIX 6C AND 80
            if (dial == DialogResult.Yes)
            {
                if (rf.groupCount == 1)
                {
                    //Fix 6C
                    Int32 vertexCountTemp = VertexCount;

                    if (vertexCountTemp <= 0x100)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(vertexCountTemp);
                        newXfbinFile[rf.NDP3Index + 0x6A] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6B] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6C] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6D] = arrayOfSize[0];
                    }
                    else if (vertexCountTemp > 0x100 && vertexCountTemp <= 0x10000)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(vertexCountTemp);
                        newXfbinFile[rf.NDP3Index + 0x6A] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6B] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6C] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x6D] = arrayOfSize[0];
                    }
                    else if (vertexCountTemp > 0x10000 && vertexCountTemp <= 0x1000000)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(vertexCountTemp);
                        newXfbinFile[rf.NDP3Index + 0x6A] = 0;
                        newXfbinFile[rf.NDP3Index + 0x6B] = arrayOfSize[2];
                        newXfbinFile[rf.NDP3Index + 0x6C] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x6D] = arrayOfSize[0];
                    }
                    else if (vertexCountTemp > 0x1000000)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(vertexCountTemp);
                        newXfbinFile[rf.NDP3Index + 0x6A] = arrayOfSize[3];
                        newXfbinFile[rf.NDP3Index + 0x6B] = arrayOfSize[2];
                        newXfbinFile[rf.NDP3Index + 0x6C] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x6D] = arrayOfSize[0];
                    }

                    //Fix 80
                    if (triangleFileNew.ToArray().Length / 2 <= 0x100)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(triangleFileNew.ToArray().Length / 2);
                        newXfbinFile[rf.NDP3Index + 0x7E] = 0;
                        newXfbinFile[rf.NDP3Index + 0x7F] = 0;
                        newXfbinFile[rf.NDP3Index + 0x80] = 0;
                        newXfbinFile[rf.NDP3Index + 0x81] = arrayOfSize[0];
                    }
                    else if (triangleFileNew.ToArray().Length / 2 > 0x100 && triangleFileNew.ToArray().Length / 2 <= 0x10000)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(triangleFileNew.ToArray().Length / 2);
                        newXfbinFile[rf.NDP3Index + 0x7E] = 0;
                        newXfbinFile[rf.NDP3Index + 0x7F] = 0;
                        newXfbinFile[rf.NDP3Index + 0x80] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x81] = arrayOfSize[0];
                    }
                    else if (triangleFileNew.ToArray().Length / 2 > 0x10000 && triangleFileNew.ToArray().Length / 2 <= 0x1000000)
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(triangleFileNew.ToArray().Length / 2);
                        newXfbinFile[rf.NDP3Index + 0x7E] = 0;
                        newXfbinFile[rf.NDP3Index + 0x7F] = arrayOfSize[2];
                        newXfbinFile[rf.NDP3Index + 0x80] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x81] = arrayOfSize[0];
                    }
                    else
                    {
                        byte[] arrayOfSize = BitConverter.GetBytes(triangleFileNew.ToArray().Length / 2);
                        newXfbinFile[rf.NDP3Index + 0x7E] = arrayOfSize[3];
                        newXfbinFile[rf.NDP3Index + 0x7F] = arrayOfSize[2];
                        newXfbinFile[rf.NDP3Index + 0x80] = arrayOfSize[1];
                        newXfbinFile[rf.NDP3Index + 0x81] = arrayOfSize[0];
                    }
                }
            }

            File.WriteAllBytes(path__, newXfbinFile.ToArray());
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.ToString());
        }
    }
Example #22
0
        public override void Load()
        {
            #region Initialisation de la population (en cas de mode entrainement IA)
            IATrainingMode = MainGame.IATrainingMode;
            if (IATrainingMode)
            {
                if (File.Exists("Population.json"))
                {
                    Population = Population.OpenFromFile("Population");
                }
                else
                {
                    Population = new Population();
                    Population.MutationRate = 0.05f;
                }
                Population.OnGenomesDeletion += Population_OnGenomesDeletion;
                Population.OnGenomesChanged  += Population_OnGenomesChanged;
            }
            #endregion

            #region Démarrage des musiques
            sndMusic = AssetManager.mscGameplay;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.Volume      = 0.5f;
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Ajout des bruitages
            _sndexplosion = AssetManager.sndExplosion;
            #endregion

            #region Création du ciel
            _skyTexture = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, _skyHeight);
            Color[] skyData = new Color[_skyTexture.Width * _skyTexture.Height];
            int     skyH    = _skyTexture.Height;
            int     skyW    = _skyTexture.Width;
            for (int y = 0; y < skyH; y++)
            {
                Color skyColor = Color.Lerp(Color.Black, new Color(119, 181, 254), (float)y / skyH);
                for (int x = 0; x < skyW; x++)
                {
                    skyData[x + y * skyW] = skyColor;
                }
            }
            _skyTexture.SetData(skyData);
            #endregion

            #region Création de la map et relevé des points d'eau pour le réseau de neurone
            WaterPosition = new List <Rectangle>();
            bool beginWater         = false;
            int  beginWaterPosition = 0;
            _perlinNoise = PerlinNoise.Generate1DMap((int)MapSize.X, 550f);
            _mapTexture  = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, (int)MapSize.Y);
            MapData      = new byte[(int)(MapSize.X * MapSize.Y)];
            MapColors    = new Color[MapData.Length];

            Color[] colors = new Color[5];
            colors[0] = Color.White;
            colors[1] = Color.Green;
            colors[2] = Color.DarkGreen;
            colors[4] = new Color(132, 73, 44);
            colors[3] = new Color(62, 28, 0);

            for (ushort i = 0; i < _perlinNoise.Length; i++)
            {
                float  noiseVal = _perlinNoise[i];
                ushort x        = (ushort)(i % MapSize.X);
                ushort h        = (ushort)Math.Floor((noiseVal + 1) * MapSize.Y * 0.5f);
                h = (ushort)MathHelper.Clamp(h, 0, WaterLevel + 1);
                int min = (int)Math.Floor((_perlinNoise.Min() + 1) * MapSize.Y * 0.5f);
                int dif = (int)MapSize.Y - min;
                for (ushort y = h; y < MapSize.Y; y++)
                {
                    uint index = (uint)(x + y * MapSize.X);
                    if (y <= WaterLevel)
                    {
                        float pourcent = (float)(y - min) / dif;
                        float p1       = 0.25f;
                        float p2       = 0.5f;
                        float p3       = 0.75f;
                        float p4       = 1f;
                        if (pourcent < p1)
                        {
                            MapColors[index] = Color.Lerp(colors[0], colors[1], pourcent / p1);
                        }
                        else if (pourcent < p2)
                        {
                            MapColors[index] = Color.Lerp(colors[1], colors[2], (pourcent - p1) / (p2 - p1));
                        }
                        else if (pourcent < p3)
                        {
                            MapColors[index] = Color.Lerp(colors[2], colors[3], (pourcent - p2) / (p3 - p2));
                        }
                        else if (pourcent < p4)
                        {
                            MapColors[index] = Color.Lerp(colors[3], colors[4], (pourcent - p3) / (p4 - p3));
                        }
                        MapData[index] = 1;
                    }
                    else
                    {
                        MapColors[index] = Color.Brown;
                    }
                }
                if (!IsSolid(new Vector2(x, WaterLevel - 1)))
                {
                    if (!beginWater)
                    {
                        beginWater         = true;
                        beginWaterPosition = x;
                    }
                }
                else
                {
                    if (beginWater)
                    {
                        beginWater = false;
                        WaterPosition.Add(new Rectangle(beginWaterPosition, WaterLevel, x - beginWaterPosition, (int)MapSize.Y - WaterLevel));
                    }
                }
            }
            _mapTexture.SetData(MapColors);
            #endregion

            #region Création de l'eau
            Vector2 p = new Vector2(0, WaterLevel);
            WaterHeight = (int)(MapSize - p).Y;
            Vector2 s = new Vector2(MapSize.X, WaterHeight);
            _water = new Water(this, p, s);
            #endregion

            #region Paramétrage de la Caméra
            Camera c = MainGame.Camera;
            c.CameraSize   = new Vector3(MapSize.X, MapSize.Y, 0);
            c.CameraOffset = new Vector3(0, MapSize.Y - MainGame.Screen.Height, 0);
            c.Enable       = true;
            c.Speed        = 10;
            #endregion

            #region Création d'un timer de tours
            _timerSecond           = new Timer(1000);
            _timerSecond.Elapsed  += OnTimerElapsed;
            _timerSecond.AutoReset = true;
            _timerSecond.Enabled   = true;
            _counter = TIME_BETWEEN_TOUR;
            #endregion

            #region Création des éléments de GUI
            GUIGroup = new Group();
            Texture2D texture = AssetManager.GameBottomBar;
            _gameBarImage        = new Image(texture, new Vector2(MainGame.Screen.Width / 2, MainGame.Screen.Height - texture.Height / 2));
            _gameBarImage.Layer -= 0.1f;
            _gameBarImage.SetOriginToCenter();
            GUIGroup.AddElement(_gameBarImage);

            texture      = AssetManager.Cursor;
            _cursorImage = new Image(texture, new Vector2(_gameBarImage.Position.X - _gameBarImage.Origin.X + (_gameBarImage.Position.X / MapSize.X), _gameBarImage.Position.Y - texture.Height * 0.75f));
            _cursorImage.SetOriginToCenter();
            GUIGroup.AddElement(_cursorImage);

            Viewport   screen = MainGame.Screen;
            SpriteFont font   = AssetManager.MenuFont;
            _bigTimerTextBox = new Textbox(new Vector2((screen.Width - font.MeasureString("3").X) / 2, (screen.Height - font.MeasureString("3").Y) / 2), font, "3");
            _bigTimerTextBox.ApplyColor(Color.White, Color.Black);
            _bigTimerTextBox.Visible = false;
            _bigTimerTextBox.Layer  += 0.2f;
            GUIGroup.AddElement(_bigTimerTextBox);

            font          = AssetManager.MainFont;
            _timerTextBox = new Textbox(new Vector2(382, 725), font, TIME_BETWEEN_TOUR.ToString() + "sec");
            _timerTextBox.ApplyColor(Color.Red, Color.Black);
            GUIGroup.AddElement(_timerTextBox);

            _currentTeamTextBox = new Textbox(new Vector2(25, 725), font, "Equipe des rouges");
            GUIGroup.AddElement(_currentTeamTextBox);

            _currentTankTextBox = new Textbox(new Vector2(196, 725), font, ".");
            _currentTankTextBox.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_currentTankTextBox);

            _infoBulle = new Textbox(new Vector2(925, 725), font, "InfoBulle :");
            _infoBulle.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_infoBulle);

            if (IATrainingMode)
            {
                _fittingScoreTextBox = new Textbox(Vector2.One, font, "Fitness Score : 0 Generation : " + Population.Generation);
                _fittingScoreTextBox.ApplyColor(Color.Yellow, Color.Black);
                GUIGroup.AddElement(_fittingScoreTextBox);
            }

            GUIGroupButtons = new GroupSelection();
            for (int i = 0; i < Enum.GetValues(typeof(Action.eActions)).Length; i++)
            {
                ButtonAction btn;
                if (i == 0)
                {
                    btn = new ButtonAction(this, (Action.eActions)i, Vector2.Zero, Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                else
                {
                    btn = new ButtonAction(this, (Action.eActions)i, new Vector2(442 + 37 * (i - 1), 725), Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                GUIGroupButtons.AddElement((IIntegrableMenu)btn);
                btn.OnHover += OnButtonHover;
                btn.OnClick += OnButtonClicked;
            }
            c.OnPositionChange += OnCameraPositionChange;
            #endregion

            #region Remplissage du sac à loot
            _lootBag = new List <Action.eActions>();
            FillLootBag();
            #endregion

            #region Création des équipes
            Teams = new List <Team>();
            Texture2D img = AssetManager.TanksSpriteSheet;
            Team      t;
            int       numberOfTeam        = MainGame.NumberOfTeam;
            int       numberOfTankPerTeam = MainGame.NumberOfTank;
            Random    rnd = new Random();

            for (byte i = 0; i < numberOfTeam; i++)
            {
                eControlType controlType;
                if (IATrainingMode)
                {
                    controlType = eControlType.NeuralNetwork;
                }
                else
                {
                    //if (i < 1)
                    controlType = eControlType.Player;     // MainGame.ControlTypes[i];
                    //else
                    //controlType = eControlType.NeuralNetwork;
                }
                t = new Team(this, img, numberOfTankPerTeam, i, rnd, controlType);
                Teams.Add(t);
                if (IATrainingMode)
                {
                    NeuralNetworkControl nn = (NeuralNetworkControl)t.Control;
                    if (Population.Genomes.Count > i)
                    {
                        nn.Genome = Population.Genomes[i % Population.Genomes.Count];
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                    else
                    {
                        Population.Genomes.Add(nn.Genome);
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                }
                t.OnTankSelectionChange += OnTankSelectionChange;
            }
            t = Teams[IndexTeam];
            t.RefreshCameraOnSelection();
            _currentTeamTextBox.ApplyColor(t.TeamColor, Color.Black);
            _currentTankTextBox.Text = t.Tanks[t.IndexTank].Name;
            RefreshActionButtonInventory();
            #endregion

            base.Load();
        }
Example #23
0
 public AddForm(GroupSelection group)
 {
     InitializeComponent();
     selectedGroup = group;
 }
 private void BtnReptiles_Click(object sender, EventArgs e)
 {
     selectedGroup = GroupSelection.Reptiles;
     GroupSelectedClickHandler();
 }