Ejemplo n.º 1
0
        /// <summary>
        /// Gets the text that your advisor will tell the player when they believe the response
        /// to the trade proposal will be that which is passed in.
        /// </summary>
        /// <param name="response">The response to get the advisor text for.</param>
        /// <returns>The text for the advisors' phrase telling you of the probable response from
        /// the foreign country to the proposed trade.</returns>
        public static string GetProbableTradeResponseString(TradeResponse response)
        {
            string text = string.Empty;

            switch (response)
            {
            case TradeResponse.Accept:
                text = ClientResources.GetString(StringKey.AdviseOfDealAcceptance);
                break;

            case TradeResponse.NeutralDecline:
                text = ClientResources.GetString(StringKey.AdviseOfDealRejectionNeutral);
                break;

            case TradeResponse.StrongDecline:
                text = ClientResources.GetString(StringKey.AdviseOfDealRejectionStrong);
                break;

            case TradeResponse.TotalDecline:
                text = ClientResources.GetString(StringKey.AdviseOfDealRejectTotal);
                break;

            case TradeResponse.WeakDecline:
                text = ClientResources.GetString(StringKey.AdviseOfDealRejectionWeak);
                break;
            }

            return(text);
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication          ca     = ClientApplication.Instance;
            IDiplomaticTiePicker       picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));
            Collection <DiplomaticTie> ties   = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            this.City          = this.DiplomaticTie.ForeignCountry.CapitalCity;
            string          text   = string.Empty;
            EspionageResult result = this.DiplomaticTie.StealWorldMap();

            switch (result)
            {
            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("stealworldmap_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("stealworldmap_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                break;

            case EspionageResult.Failure:
                text = ClientResources.GetString("stealworldmap_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("stealworldmap_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            OnInvoked();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;

            Unit     unit     = client.ServerInstance.ActiveUnit;
            GridCell unitCell = client.ServerInstance.Grid.GetCell(unit.Coordinates);

            if (unit == null)
            {
                throw new InvalidOperationException(ClientResources.GetString("Unit_Null"));
            }

            if (unitCell.City == null)
            {
                throw new InvalidOperationException(ClientResources.GetString("Unit_MergeNoCity"));
            }

            if (!unit.CanMergeWithCity)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, ClientResources.GetString("Unit_CannotMerge"), unit.Name));
            }

            unit.MergeWithCity();
            OnInvoked();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            Settler settler;
            string  newCityName;

            OnInvoking();

            ClientApplication client = ClientApplication.Instance;
            GameRoot          root   = client.ServerInstance;

            if (root.ActiveUnit == null)
            {
                throw new InvalidOperationException(ClientResources.GetExceptionString("Unit_Null"));
            }

            if (!root.ActiveUnit.CanSettle)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, ClientResources.GetExceptionString("Unit_CannotSettle"), root.ActiveUnit.Name));
            }

            INewCityControl newCityWindow = (INewCityControl)client.GetControl(typeof(INewCityControl));

            settler = (Settler)root.ActiveUnit;
            newCityWindow.ShowSimilizationControl();

            newCityName = newCityWindow.CityName;
            _city       = settler.Settle(newCityName);

            OnInvoked();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the <see cref="McKnight.Similization.Server.City"/>, and if necessary,
        /// the <see cref="McKnight.Similization.Server.DiplomaticTie"/> from the user.
        /// </summary>
        protected virtual void SelectCity(string cityPickerTitle)
        {
            ClientApplication ca = ClientApplication.Instance;

            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("espionageTiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.tie = picker.DiplomaticTie;

            ICityPicker cityPicker = (ICityPicker)ca.GetControl(typeof(ICityPicker));

            cityPicker.PickerTitle = cityPickerTitle;
            cityPicker.InitializePicker(this.DiplomaticTie.ForeignCountry);
            cityPicker.ShowSimilizationControl();
            this.city = cityPicker.City;
        }
        private static string GetAdvisorText()
        {
            string            text   = string.Empty;
            ClientApplication client = ClientApplication.Instance;
            Country           player = client.Player;

            if (player.Government.Fallback)
            {
                text = ClientResources.GetString("domesticAdvisor_anarchy");
            }
            else
            {
                if (RandomNumber.GetRandomNumber(10) > 5)
                {
                    //tell them we need more cities.
                    text = ClientResources.GetString("domesticAdvisor_needCities");
                }
                else
                {
                    //say something about a city.
                    int    count  = player.Cities.Count;
                    int    idx    = RandomNumber.GetRandomNumber(count - 1);
                    City   city   = client.Player.Cities[idx];
                    string format = ClientResources.GetString("domesticAdvisor_cityHappiness");
                    text = string.Format(CultureInfo.CurrentCulture, format, player.Government.LeaderTitle, city.Name, "");
                }
            }

            return(text);
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication    client = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)client.GetControl(typeof(IDiplomaticTiePicker));

            picker.ShowSimilizationControl();
            DiplomaticTie tie = picker.DiplomaticTie;

            if (tie == null)
            {
                return;
            }

            //get an instance of the diplomacy control
            DiplomacyControl = (IDiplomacyControl)client.GetControl(typeof(IDiplomacyControl));
            IDiplomacyTaskLinkFactory factory = DiplomacyControl.GetTaskLinkFactory();

            //initialize the properties of the control
            DiplomacyControl.DiplomaticTie = tie;

            DiplomacyControl.ForeignLeaderHeaderText = string.Format(
                CultureInfo.InvariantCulture,
                ClientResources.GetString(StringKey.DiplomacyCountryHeader),
                tie.ForeignCountry.Name,
                ClientApplication.GetAttitudeString(tie.Attitude));

            DiplomacyControl.ForeignLeaderPhrase   = AIDiplomacyPhraseHelper.GetForeignLeaderGreeting(tie);
            DiplomacyControl.AdvisorHelpRequested += new EventHandler(HandleAdvisorHelpRequested);
            _advice = DiplomacyAdvice.GetAdvice(tie);
            DiplomacyControl.AdvisorPhrase = _advice[_adviceIndex];

            //get the tasks
            DiplomacyTask[] tasks = DiplomacyHelper.GetDiplomacyTasks(tie, null, null);

            string             taskText;
            DiplomacyCommand   command;
            IDiplomacyTaskLink taskLink;

            //add the tasks to the diplomacy control.
            foreach (DiplomacyTask task in tasks)
            {
                taskText = DiplomacyHelper.GetTaskString(task, tie);
                command  = DiplomacyHelper.GetTaskCommand(task, DiplomacyControl);
                taskLink = factory.CreateTaskLink(taskText, command);
                DiplomacyControl.TaskLinks.Add(taskLink);
            }

            DiplomacyControl.ShowSimilizationControl();
            OnInvoked();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;
            Unit unit = client.ServerInstance.ActiveUnit;

            if (unit == null)
            {
                throw new InvalidOperationException(ClientResources.GetExceptionString("Unit_Null"));
            }

            unit.Fortified = true;
            OnInvoked();
        }
 private static string GetAdvisorText(Country parent, Country foreign)
 {
     if (foreign == null)
     {
         //there's no foreign country, so the advisor will have to offer
         //other advice.
         return(ClientResources.GetString("militaryAdvisor_needUnits"));
     }
     else
     {
         //we can talk about anything.
         return(GetMilitaryComparisonString(parent, foreign));
     }
 }
        private static string GetCountryHeaderText(Country country)
        {
            if (country == null)
            {
                return(string.Empty);
            }

            string s         = ClientResources.GetString(StringKey.MilitaryAdvisorCountryHeader);
            string adjective = country.Civilization.Adjective;
            string gov       = country.Government.Name;
            string text      = string.Format(CultureInfo.InvariantCulture, s, adjective, gov);

            return(text);
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication    ca     = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.ShowSimilizationControl();
            DiplomaticTie tie = picker.DiplomaticTie;

            if (tie == null)
            {
                OnCanceled();
                return;
            }
            ICityPicker cityPicker = (ICityPicker)ca.GetControl(typeof(ICityPicker));

            cityPicker.PickerTitle = ClientResources.GetString("investigateCity_cityPickerTitle");
            cityPicker.ShowSimilizationControl();
            City city = cityPicker.City;

            if (city == null)
            {
                OnCanceled();
                return;
            }
            bool   success = tie.InvestigateCity(city);
            string text    = string.Empty;

            if (success)
            {
                text = ClientResources.GetString("investigateCity_success");
                text = string.Format(CultureInfo.CurrentCulture, text, city.Name);
                ca.GameWindow.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
                ICityControl cityControl = (ICityControl)ca.GetControl(typeof(ICityControl));
                cityControl.Editable = false;
                cityControl.City     = city;
                cityControl.ShowSimilizationControl();
            }
            else
            {
                text = ClientResources.GetString("investigateCity_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    tie.ForeignCountry.Civilization.Adjective);
                ca.GameWindow.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            }
            OnInvoked();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;
            ILoadGameWindow   window = (ILoadGameWindow)client.GetControl(typeof(ILoadGameWindow));

            window.ShowSimilizationControl();
            if (window.LoadedGameFile == null || window.LoadedGameFile.Length == 0)
            {
                OnCanceled();
                return;
            }
            client.Console.WriteLine(string.Format(CultureInfo.InvariantCulture, ClientResources.GetString("item_loading"), window.LoadedGameFile));
            client.ServerInstance.LoadGame(window.LoadedGameFile);
            client.Console.WriteLine(ClientResources.GetString("game_loaded"));
            OnInvoked();
        }
        /// <summary>
        /// Invokes the Command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            string cityPickerTitle = ClientResources.GetString("propaganda_cityPickerTitle");

            SelectCity(cityPickerTitle);
            if (this.City == null)
            {
                OnCanceled();
                return;
            }
            EspionageResult result = this.DiplomaticTie.SpreadPropaganda(this.City);
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                text = ClientResources.GetString("propaganda_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("propaganda_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("propaganda_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;
            string            message, title;

            message = ClientResources.GetString(StringKey.DisbandConfirmation);
            title   = ClientResources.GetString(StringKey.GameTitle);

            bool confirmed = client.GameWindow.GetUserConfirmation(message, title);

            if (confirmed)
            {
                Country player = client.Player;
                Unit    unit   = client.ServerInstance.ActiveUnit;
                player.DisbandUnit(unit);
            }
            OnInvoked();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Invokes the <c>BuildRoadCommand</c>.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;
            Unit unit = client.ServerInstance.ActiveUnit;

            if (unit == null)
            {
                throw new InvalidOperationException(ClientResources.GetExceptionString("Unit_Null"));
            }

            if (!unit.CanWork)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, ClientResources.GetExceptionString("Unit_CannotWork"), unit.Name));
            }

            ((Worker)unit).BuildRoad();
            OnInvoked();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication    ca     = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("establishEmbassy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (!t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            if (ties.Count == 0)
            {
                string msg = ClientResources.GetString("establishEmbassy_noTies");
                ca.GameWindow.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.tie            = picker.DiplomaticTie;
            this.tie.HasEmbassy = true;
            string text = ClientResources.GetString("establishEmbassy_success");

            text = string.Format(
                CultureInfo.CurrentCulture,
                text,
                ca.Player.Government.LeaderTitle,
                this.tie.ForeignCountry.Civilization.Adjective,
                ClientResources.GetCitySizeString(this.tie.ForeignCountry.CapitalCity.SizeClass),
                this.tie.ForeignCountry.CapitalCity.Name
                );


            ca.GameWindow.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
        private static string GetMilitaryComparisonString(Country parent, Country foreign)
        {
            int powerThem = 0;
            int powerUs   = 0;

            foreach (Unit unit in foreign.Units)
            {
                powerThem += unit.OffensivePower;
            }
            foreach (Unit unit in parent.Units)
            {
                powerUs += unit.OffensivePower;
            }

            double n, d;

            n = Convert.ToDouble(powerUs);
            d = Convert.ToDouble(powerThem + powerUs);
            if (d == 0 && n > 0)
            {
                return(ClientResources.GetString("militaryAdvisor_strongMilitary"));
            }
            else if (d == 0 && n == 0)
            {
                return(ClientResources.GetString("militaryAdvisor_averageMilitary"));
            }
            double div = n / d;

            if (div >= .4 && div <= .6)
            {
                return(ClientResources.GetString("militaryAdvisor_averageMilitary"));
            }
            else if (div <= .4)
            {
                return(ClientResources.GetString("militaryAdvisor_weakMilitary"));
            }
            else if (div >= .6)
            {
                return(ClientResources.GetString("militaryAdvisor_strongMilitary"));
            }
            return(string.Empty);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication client = ClientApplication.Instance;
            GameRoot          root   = client.ServerInstance;

            //load the ruleset
            string loadingMessage = ClientResources.GetString("item_loading");
            string message        = string.Format(CultureInfo.CurrentCulture, loadingMessage, this.rulesetPath);

            client.Console.WriteLine(message);
            root.LoadRuleset(this.rulesetPath);

            //load the tileset
            message = string.Format(CultureInfo.CurrentCulture, loadingMessage, this.tilesetPath);
            client.Console.WriteLine(message);
            client.LoadTileset(this.tilesetPath);

            INewGameControl ctl = (INewGameControl)client.GetControl(typeof(INewGameControl));

            ctl.ResultChosen += new EventHandler(HandleResultChosen);
            ctl.ShowSimilizationControl();
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication          ca     = ClientApplication.Instance;
            IDiplomaticTiePicker       picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));
            Collection <DiplomaticTie> ties   = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            IGameWindow gw       = ClientApplication.Instance.GameWindow;
            bool        canSteal = CheckForStealableTechnologies();

            if (!canSteal)
            {
                string msg = ClientResources.GetString("stealtechnology_noneavailable");
                msg = string.Format(
                    CultureInfo.CurrentCulture,
                    ClientApplication.Instance.Player.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                gw.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
            }
            this.City = this.DiplomaticTie.ForeignCountry.CapitalCity;
            EspionageResult result = this.DiplomaticTie.StealTechnology();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                text = ClientResources.GetString("stealtechnology_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name);
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("stealtechnology_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("stealtechnology_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("stealtechnology_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Noun);
                break;
            }

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication ca        = ClientApplication.Instance;
            bool hasValidTies           = false;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("plantSpy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    hasValidTies = true;
                    if (!t.HasSpy)
                    {
                        ties.Add(t);
                    }
                }
            }
            if (ties.Count == 0 && hasValidTies)
            {
                //all the valid civs already have spys.
                string msg = ClientResources.GetString("plantSpy_spysExists");
                ca.GameWindow.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
                return;
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.tie = picker.DiplomaticTie;
            EspionageResult result = this.DiplomaticTie.PlantSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Success:
                text = ClientResources.GetString("plantspy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name);
                break;

            case EspionageResult.Failure:
                text = ClientResources.GetString("plantspy_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();

            string cityPickerTitle = ClientResources.GetString("sabotage_cityPickerTitle");

            SelectCity(cityPickerTitle);
            if (this.City == null)
            {
                OnCanceled();
                return;
            }
            BuildableItem   improvement = this.City.NextImprovement;
            EspionageResult result      = this.DiplomaticTie.Sabotage(this.City);
            string          text        = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("sabotage_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("sabotage_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("sabotage_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("sabotage_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            ClientApplication    ca     = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("exposespy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            this.City = this.DiplomaticTie.ForeignCountry.CapitalCity;
            EspionageResult result = this.DiplomaticTie.ExposeSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("exposespy_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("exposespy_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("exposespy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text, this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("exposespy_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CityTile"/> class.
        /// </summary>
        /// <param name="tileRow"></param>
        public CityTile(DataRow tileRow)
        {
            //City tile names contain information regarding the civilization
            //the image belongs to, the size class,  and also the era the tile belongs to.
            //we parse this apart with underscore characters "_".  So, for
            //example, a city tile for America in industrial times for a metropolis-sized
            //city would look like "america_industrial_metropolis".  Note that these
            //are case-insensitive.

            if (tileRow == null)
            {
                throw new ArgumentNullException("tileRow");
            }

            //here is the full, unsplit version of the tilename.
            string unsplit = Convert.ToString(tileRow["CityTileName"], CultureInfo.InvariantCulture);

            string[] split = unsplit.Split("_".ToCharArray());

            if (split.Length != 3)
            {
                string error = ClientResources.GetExceptionString("error_invalidCityTileName");
                error = string.Format(CultureInfo.CurrentCulture, error, unsplit);
                throw new ArgumentException(error, "tileRow");
            }

            string civ           = split[0];
            string eraName       = split[1];
            string sizeClassName = split[2];

            Ruleset rs = ClientApplication.Instance.ServerInstance.Ruleset;

            foreach (Civilization c in rs.Civilizations)
            {
                if (string.Compare(c.Name, civ, true, CultureInfo.InvariantCulture) == 0)
                {
                    this.civilization = c;
                    break;
                }
            }

            if (this.civilization == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, ClientResources.GetExceptionString("error_invalidCivilization"), civ), "tileRow");
            }


            foreach (Era e in rs.Eras)
            {
                if (string.Compare(e.Name, eraName, true, CultureInfo.InvariantCulture) == 0)
                {
                    this.era = e;
                    break;
                }
            }

            if (this.era == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, ClientResources.GetExceptionString("error_invalidEra"), eraName), "tileRow");
            }

            try
            {
                this.sizeClass = (CitySizeClass)Enum.Parse(typeof(CitySizeClass), sizeClassName, true);
            }
            catch (System.Exception ex)
            {
                throw new ArgumentException(sizeClassName + string.Format(CultureInfo.InvariantCulture, ClientResources.GetExceptionString("error_invalidCitySize"), sizeClassName), "tileRow", ex);
            }

            string path = string.Empty;

            path       = Convert.ToString(tileRow["TilePath"], CultureInfo.InvariantCulture);
            this.image = Image.FromFile(path);
        }