void JoinRaceInProgress(string settingsStr) { //When joining a game in progress the racesetup wont be there already, so create a new one IsInLobby = false; RaceSetup rs = (RaceSetup)Instantiate(raceSetupObject); rs.settings = RaceSettings.ParseFromString(settingsStr); rs.JoinGameInProgress(); //Make the racesetup run on level load }
public RaceSettings(RaceSettings original) //Copy from other settings { laps = original.laps; stage = original.stage; allowSuperSanic = original.allowSuperSanic; aiBallCount = original.aiBallCount; aiStupidness = original.aiStupidness; aiCharacters = new List <int>(original.aiCharacters); }
public StartMenuController( GameSettings settings, InputController input, OutputController output, RaceSettings races, CheatController cheats = null ) { _settings = settings; _input = input; _output = output; _races = races; _cheats = cheats; }
private static RaceSettingsDto BuildRaceSettings(string raceId, RaceSettings model) { return(new RaceSettingsDto { RaceId = raceId, Name = model.Name, Start = model.Start, End = model.End }); }
private RaceIndexEntry BuildIndexEntry(string raceId, RaceSettings raceSettings) { return(new RaceIndexEntry { RaceId = raceId, Name = raceSettings.Name, Start = raceSettings.Start, End = raceSettings.End, SearchTokens = tokenizer.GetTokens(raceSettings.Name) }); }
void LoadRace(string settings) { IsInLobby = false; RaceSetup rs = GameObject.FindObjectOfType <RaceSetup>(); //Get the race setup object if (rs != null) { //ensure that the clientside settings are correct rs.settings = RaceSettings.ParseFromString(settings); rs.StartRace(false); } else { Debug.LogError("Tried to load race but no RaceSetup is present"); } }
void UpdateRaceSettings(string settingsStr) { if (Network.isServer) { return; } RaceSetup rs = GameObject.FindObjectOfType <RaceSetup>(); if (rs != null) { rs.settings = RaceSettings.ParseFromString(settingsStr); } else { Debug.LogError("Couldn't update race settings: RaceSetup not found."); } }
public override bool Equals(object other) //Checks racesettings against each other { RaceSettings rs = other as RaceSettings; //Cast to racesettings if (rs != null) { if (laps == rs.laps && stage == rs.stage && allowSuperSanic == rs.allowSuperSanic && aiBallCount == rs.aiBallCount && aiStupidness == rs.aiStupidness && aiCharacters.SequenceEqual <int>(rs.aiCharacters)) { return(true); } } return(false); }
/// <summary> /// Parses from string returned by GetString. /// </summary> /// <returns>The from string.</returns> /// <param name="str">String.</param> public static RaceSettings ParseFromString(string str) { try { RaceSettings output = new RaceSettings(); string[] args = str.Split(';'); output.laps = int.Parse(args[0]); output.stage = int.Parse(args[1]); output.allowSuperSanic = bool.Parse(args[2]); output.aiBallCount = int.Parse(args[3]); output.aiStupidness = int.Parse(args[4]); output.aiCharacters = ParseAICharactersFromString(args[5]); return(output); } catch (System.Exception ex) { Debug.LogError("Failed to parse race settings: " + ex); } return(null); }
void Start() { if (Network.isServer) { raceSettingsVisible = true; } client = FindObjectOfType <Client>(); if (GameSettings.music) { audio.Play(); } if (client == null) { Destroy(this.gameObject); } raceSetup = FindObjectOfType <RaceSetup>(); //Load race settings from playerprefs string settingsString = PlayerPrefs.GetString("RaceSettings", raceSetup.settings.ToString()); raceSetup.settings = RaceSettings.ParseFromString(settingsString); //Set some things from the race settings totalCharacters = Global.characters.Length; tempSettings = new RaceSettings(raceSetup.settings); tempLapsF = tempSettings.laps; tempAIBallsF = tempSettings.aiBallCount; tempAIStupidnessF = tempSettings.aiStupidness; tempLapsStr = tempSettings.laps.ToString(); tempAIBallsStr = tempSettings.aiBallCount.ToString(); character = client.FindServerPlayer(Network.player).character; //Set stage records stageRecords = new float[Global.stages.Length]; for (int i = 0; i < stageRecords.Length; i++) { Stage s = Global.stages[i]; stageRecords[i] = PlayerPrefs.GetFloat(s.sceneName + "_lap", -1); } GameSettings.Apply(false); }
static void Main(string[] args) { var mapSettings = new MapSettings(6, 6) .WithChance(LocationType.Sea, y => y * 0.8) .WithChance(LocationType.Lands, y => Math.Max(Math.Sin((y - 0.3) * Math.PI * 2), 0.0)) .WithChance(LocationType.Woods, y => Math.Max(Math.Sin((y - 0.1) * Math.PI * 2), 0.0)) .WithChance(LocationType.Mountains, y => (0.75 - y)) .WithChance(LocationType.Barrens, y => y * 0.75); var raceSettings = new RaceSettings() // population, growthRate, power, speed, taxRate, soldierPrice, loc .With(new Race(RaceId.Human, 100, 0.020, 1.10, 1.00, 0.25, 5, LocationType.Lands)) .With(new Race(RaceId.Dwarf, 50, 0.015, 1.85, 0.50, 0.75, 10, LocationType.Mountains)) .With(new Race(RaceId.Elf, 50, 0.019, 1.60, 1.25, 0.50, 7, LocationType.Woods)) .With(new Race(RaceId.Goblin, 200, 0.025, 0.33, 2.00, 0.10, 3, LocationType.Barrens)) .With(new Race(RaceId.Halfling, 100, 0.024, 0.43, 0.75, 0.50, 4, LocationType.Lands)) .With(new Race(RaceId.Orc, 150, 0.023, 0.76, 1.50, 0.15, 4, LocationType.Barrens)); var provider = Configure(mapSettings, raceSettings).PreRun().Generate().Init(); provider.Run(); }
static ServiceProvider Configure(MapSettings mapSettings, RaceSettings raceSettings) { var services = new ServiceCollection() .AddSingleton(mapSettings) .AddSingleton(raceSettings) .AddSingleton <CountryGenerator>() .AddSingleton <MapGenerator>() .AddGameLogics() .AddSingleton <CheatController>() .AddSingleton <InputController>() .AddSingleton <OutputController>() .AddSingleton <ContextController>() .AddSingleton <TimeController>() .AddSingleton <CountryController>() .AddSingleton <MapController>() .AddSingleton <MoneyController>() .AddSingleton <PopulationController>() .AddSingleton <ArmyController>() .AddSingleton <ConquestController>() .AddSingleton <DiscoveryController>() .AddSingleton <MoveController>() .AddSingleton <BotController>() .AddSingleton <IDayStarter, ArmyUpdater>() .AddSingleton <IDayStarter, PopulationUpdater>() .AddSingleton <IDayStarter, BotController>() .AddSingleton <IStartHandler, MapInterface>() .AddSingleton <IStartHandler, MoneyInteface>() .AddArmyInterface() .AddSingleton <IStartHandler, SleepInterface>() .AddSingleton <IStartHandler, FreeModeInterface>() .AddConquestInterface() .AddSingleton <GameSettings>() .AddSingleton <StartMenuController>() .AddGameController(); return(services.BuildServiceProvider()); }
void OnGUI() { GUI.skin = skin; GUIStyle smallButton = GUI.skin.GetStyle("SmallButton"); GUIStyle smallText = new GUIStyle(GUI.skin.label); smallText.fontSize = 14; if (!stageSelect) { #region Character selection int charSelectWidth = Mathf.Min(400, Screen.width - 280 * 2); Rect charSelectRect = new Rect(Screen.width / 2 - charSelectWidth / 2, Screen.height - 92, charSelectWidth, 92); GUI.Box(charSelectRect, ""); GUILayout.BeginArea(charSelectRect); GUILayout.BeginHorizontal(); if (GUILayout.Button("", GUI.skin.GetStyle("BigArrowLeft")) && !ready) { character--; if (character < 0) { character += totalCharacters; } if (!raceSetup.settings.allowSuperSanic && Global.characters[character].attributes.Contains("2fast")) { character -= 1; } client.networkView.RPC("SetCharacter", RPCMode.All, Network.player, character); } GUILayout.BeginVertical(); GUIStyle centeredLabel = GUI.skin.GetStyle("CenteredLabel"); GUIStyle nameStyle = new GUIStyle(centeredLabel); if (Screen.width - 280 * 2 < 400) { nameStyle.fontSize = 24; nameStyle.fontStyle = FontStyle.Bold; } else { nameStyle.fontSize = 46; } GUILayout.FlexibleSpace(); GUILayout.Label(GetCharacterName(character), nameStyle); GUILayout.Label(Global.characters[character].author, new GUIStyle(centeredLabel) { fontSize = 18 }); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); if (GUILayout.Button("", GUI.skin.GetStyle("BigArrowRight")) && !ready) { character++; if (character >= totalCharacters) { character -= totalCharacters; } client.networkView.RPC("SetCharacter", RPCMode.All, Network.player, character); } GUILayout.EndHorizontal(); GUILayout.EndArea(); #endregion #region Race settings //Main settings panel Rect settingsRect = new Rect(Screen.width - raceSettingsPos, 33, 400, Screen.height - 260 - 33); GUI.Box(settingsRect, ""); //Placing the Box inside the GUILayout gives strange results GUILayout.BeginArea(settingsRect); raceSettingsScroll = GUILayout.BeginScrollView(raceSettingsScroll); //Server panel if (Network.isServer) { if (!showAISettings) { if (unlockFields) //Unlocked fields { GUILayout.Label("Laps: " + tempSettings.laps); tempLapsStr = GUILayout.TextField(tempLapsStr); GUILayout.Label("AI Balls: " + tempSettings.aiBallCount); tempAIBallsStr = GUILayout.TextField(tempAIBallsStr); GUILayout.Label("Note that high amounts of AI balls can cause crazy lagspikes and sometimes cause Sanicball to stop responding.", smallText); //apply settings int lapsInt; if (!int.TryParse(tempLapsStr, out lapsInt)) { GUILayout.Label("- Laps has to be a number"); } else { if (lapsInt < 1) { GUILayout.Label("- Laps has to be above 0"); } else { tempSettings.laps = lapsInt; } } int aiBallsInt; if (!int.TryParse(tempAIBallsStr, out aiBallsInt)) { GUILayout.Label("- AI Balls has to be a number"); } else //Locked fields { if (aiBallsInt < 0) { GUILayout.Label("- AI Balls has to be 0 or above"); } else { tempSettings.aiBallCount = aiBallsInt; } if (aiBallsInt >= 1000) { GUILayout.Label("- Prepare your anus."); } } } else { GUILayout.Label("Number of laps: " + tempSettings.laps); tempLapsF = GUILayout.HorizontalSlider(tempLapsF, 1, 6); GUILayout.Label("AI Balls: " + tempSettings.aiBallCount); tempAIBallsF = GUILayout.HorizontalSlider(tempAIBallsF, 0, 30); //apply settings tempSettings.laps = (int)tempLapsF; tempSettings.aiBallCount = (int)tempAIBallsF; } unlockFields = GUILayout.Toggle(unlockFields, "Unlock fields"); if (GUILayout.Button("Go to AI settings", smallButton)) { showAISettings = true; } tempSettings.allowSuperSanic = GUILayout.Toggle(tempSettings.allowSuperSanic, "Allow Super Sanic"); } else { //AI settings if (GUILayout.Button("Back", smallButton)) { showAISettings = false; } string AIStupidnessname = tempSettings.aiStupidness.ToString(); switch (tempSettings.aiStupidness) { case 0: AIStupidnessname = "Clones"; break; case 30: AIStupidnessname = "Default"; break; case 100: AIStupidnessname = "Retarded"; break; } GUILayout.Label("AI Stupidness: " + AIStupidnessname); tempAIStupidnessF = GUILayout.HorizontalSlider(tempAIStupidnessF, 0, 100); tempSettings.aiStupidness = (int)tempAIStupidnessF; if (tempSettings.aiBallCount > tempSettings.aiCharacters.Count) { //Build an array of knackles to add to the list of AI characters int[] newBalls = new int[tempSettings.aiBallCount - tempSettings.aiCharacters.Count]; for (int i = 0; i < newBalls.Length; i++) { newBalls[i] = 1; } tempSettings.aiCharacters.AddRange(newBalls); } for (int i = 0; i < Mathf.Min(tempSettings.aiBallCount, 64); i++) //AI Ball list { GUIStyle labelStyle = GUI.skin.label; GUIStyle buttonStyle = smallButton; if (i % 2 == 0) { labelStyle = GUI.skin.GetStyle("LabelOdd"); buttonStyle = GUI.skin.GetStyle("SmallButtonOdd"); } int aiChar = 1; //Default to Knackles (just to be sure) if (i < tempSettings.aiCharacters.Count) //If inside the AI character array { aiChar = (int)tempSettings.aiCharacters[i]; } GUILayout.BeginHorizontal(); GUILayout.Label("AI " + (i + 1) + ": ", labelStyle, GUILayout.Width(85)); if (GUILayout.Button("<", buttonStyle, GUILayout.Width(40))) { int c = 1; if (i < tempSettings.aiCharacters.Count) { c = tempSettings.aiCharacters[i]; } c--; if (c < 0) { c = totalCharacters - 1; } tempSettings.aiCharacters[i] = c; } GUILayout.Label(GetCharacterName(aiChar), labelStyle); if (GUILayout.Button(">", buttonStyle, GUILayout.Width(40))) { int c = 1; if (i < tempSettings.aiCharacters.Count) { c = tempSettings.aiCharacters[i]; } c++; if (c >= totalCharacters) { c = 0; } tempSettings.aiCharacters[i] = c; } GUILayout.EndHorizontal(); } if (tempSettings.aiBallCount > 64) { string str = "AI 65"; if (tempSettings.aiBallCount > 65) { str = "AI 65-" + (tempSettings.aiBallCount + 1); } GUILayout.Label(str + ": " + GetCharacterName(tempSettings.aiCharacters[63])); } if (GUILayout.Button("Set to random characters", smallButton)) { for (int i = 0; i < tempSettings.aiCharacters.Count; i++) { tempSettings.aiCharacters[i] = Random.Range(0, Global.characters.Length); } } if (GUILayout.Button("Set to default characters", smallButton)) { tempSettings.aiCharacters = new List <int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }); } GUILayout.Label("Set all:"); for (int i = 0; i < totalCharacters; i++) { if (GUILayout.Button(GetCharacterName(i), smallButton)) { SetAllAICharacters(i); } } } } else //Client panel { RaceSettings rs = raceSetup.settings; if (!showAISettings) { GUILayout.Label("Number of laps: " + rs.laps); GUILayout.Label("AI Balls: " + rs.aiBallCount); GUILayout.Label("Super sanic is " + (rs.allowSuperSanic ? "ALLOWED" : "BANNED")); if (GUILayout.Button("Show AI settings", smallButton)) { showAISettings = true; } } else { if (GUILayout.Button("Back", smallButton)) { showAISettings = false; } GUILayout.Label("AI stupidness: " + rs.aiStupidness); GUILayout.Label("AI characters:"); for (int i = 0; i < Mathf.Min(rs.aiBallCount, 64); i++) //AI Ball list { GUIStyle labelStyle = GUI.skin.label; if (i % 2 == 0) { labelStyle = GUI.skin.GetStyle("LabelOdd"); } int aiChar = 1; //Default to Knackles (just to be sure) if (i < rs.aiCharacters.Count) //If inside the AI character array { aiChar = (int)rs.aiCharacters[i]; } GUILayout.BeginHorizontal(); GUILayout.Label("AI " + (i + 1) + ": ", labelStyle, GUILayout.Width(85)); GUILayout.Label(GetCharacterName(aiChar), labelStyle); GUILayout.EndHorizontal(); } if (rs.aiBallCount > 64) { string str = "AI 65"; if (rs.aiBallCount > 65) { str = "AI 65-" + (rs.aiBallCount + 1); } GUILayout.Label(str + ": " + GetCharacterName(rs.aiCharacters[63])); } } } GUILayout.EndScrollView(); GUILayout.FlexibleSpace(); if (!settingsEqual && Network.isServer) { GUILayout.Label("Settings haven't been saved! Remember to save before you start the game.", smallText); GUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { raceSetup.settings = new RaceSettings(tempSettings); client.networkView.RPC("UpdateRaceSettings", RPCMode.Others, tempSettings.ToString()); FindObjectOfType <Server>().SendPublicMsg("The race settings have been updated."); PlayerPrefs.SetString("RaceSettings", raceSetup.settings.ToString()); PlayerPrefs.Save(); } if (GUILayout.Button("Revert")) { tempSettings = new RaceSettings(raceSetup.settings); tempAIBallsF = tempSettings.aiBallCount; tempLapsF = tempSettings.laps; tempAIStupidnessF = tempSettings.aiStupidness; } GUILayout.EndHorizontal(); } GUILayout.EndArea(); //Show/hide button Rect showHideRect = new Rect(Screen.width - 400, 0, 400, 33); GUILayout.BeginArea(showHideRect); if (!raceSettingsVisible) { string showRaceSettingsText = "Show race settings"; if (Network.isServer) { if (settingsEqual) { showRaceSettingsText = "Change race settings"; } else { showRaceSettingsText = "Settings not saved!"; } } if (GUILayout.Button(showRaceSettingsText, smallButton)) { raceSettingsVisible = true; } } else { if (GUILayout.Button("Hide race settings", smallButton)) { raceSettingsVisible = false; } } GUILayout.EndArea(); #endregion #region Ready/Start race Rect cornerRect = new Rect(Screen.width - 280, Screen.height - 92, 280, 92); GUI.Box(cornerRect, ""); List <ServerPlayer> players = client.GetPlayerList(); if (Network.isServer && players.Count > 1) { if (forceStartTimer <= 0) { if (GUI.Button(new Rect(Screen.width - 280, Screen.height - 92 - 34, 280, 34), "Force start", smallButton)) { forceStartTimer = 5; } } else { if (GUI.Button(new Rect(Screen.width - 280, Screen.height - 92 - 34, 280, 34), "Are you sure?", smallButton)) { client.networkView.RPC("GotoStageSelect", RPCMode.All); } } } GUILayout.BeginArea(cornerRect); if (players.Count > 1) { if (!ready) { if (GUILayout.Button("Ready!")) { ready = true; client.networkView.RPC("SetReady", RPCMode.All, Network.player, true); } } else { if (GUILayout.Button("Cancel")) { ready = false; client.networkView.RPC("SetReady", RPCMode.All, Network.player, false); } } //Get amount of players ready int playersReady = 0; foreach (ServerPlayer sp in players) { if (sp.ready) { playersReady++; } } if (playersReady < players.Count) { if (gameStart) { StopCountdown(); } GUILayout.Label(playersReady + "/" + players.Count + " players ready"); } else { if (!gameStart) { StartCountdown(); } if (gameStartTimer > 0) { GUILayout.Label("Game starts in " + Mathf.Ceil(gameStartTimer) + " seconds"); } else { GUILayout.Label("Just a moment..."); } } } else { if (GUILayout.Button("Continue")) { client.networkView.RPC("GotoStageSelect", RPCMode.All); } GUILayout.Label("To stage select"); } GUILayout.EndArea(); #endregion } else { #region Stage Select GUIStyle titleStyle = new GUIStyle(GUI.skin.label); titleStyle.fontSize = GUI.skin.button.fontSize; titleStyle.alignment = TextAnchor.UpperCenter; if (Network.isServer) { int width = Mathf.Min(740, Screen.width); int height = Screen.height - 92 * 2; Rect stageSelectRect = new Rect(Screen.width / 2 - width / 2, Screen.height / 2 - height / 2, width, height); GUIStyle recordStyle = new GUIStyle(GUI.skin.label); recordStyle.alignment = TextAnchor.UpperCenter; GUI.Box(stageSelectRect, ""); GUILayout.BeginArea(stageSelectRect); GUILayout.Label("Stage select", titleStyle); stageSelectScroll = GUILayout.BeginScrollView(stageSelectScroll); //GUILayout.BeginHorizontal(GUILayout.Width(350)); foreach (Stage s in Global.stages) { GUILayout.BeginHorizontal(); GUILayout.Box(s.picture, GUILayout.Width(350), GUILayout.Height(233)); GUILayout.BeginVertical(); if (GUILayout.Button(s.name)) { raceSetup.settings.stage = s.id; raceSetup.LoadRace(); } ; GUILayout.Label("Made by " + s.author); if (stageRecords[s.id] != -1) { GUILayout.Label("Lap record: " + Timing.GetTimeString(stageRecords[s.id])); } else { GUILayout.Label("No records yet"); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndArea(); } else { if (!ready) { ready = true; client.networkView.RPC("SetReady", RPCMode.All, Network.player, true); } GUI.Label(new Rect(0, 100, Screen.width, 100), "Host is selecting stage...", titleStyle); } #endregion } Rect backToMenuRect = new Rect(0, Screen.height - 92, 280, 92); GUI.Box(backToMenuRect, ""); GUILayout.BeginArea(backToMenuRect); if (Network.isServer && stageSelect) { if (GUILayout.Button("Cancel")) { client.networkView.RPC("CancelStageSelect", RPCMode.All); client.networkView.RPC("SetAllReady", RPCMode.All, false); } GUILayout.Label("Back to settings"); } else { if (GUILayout.Button("Disconnect")) { BackToMenu(); } if (Network.isServer) { GUILayout.Label("Server will close"); } else { GUILayout.Label("Back to menu"); } } GUILayout.EndArea(); }
public CountryGenerator(GameSettings gameSettings, RaceSettings raceSettings) { _gameSettings = gameSettings; _raceSettings = raceSettings; }