public void SetDiplomaticContractState(DiplomaticContract diplomaticContract, DiplomaticContractState destinationState) { DiplomaticContractState state = diplomaticContract.State; if (diplomaticContract.Terms.Count > 0 && !diplomaticContract.IsTransitionPossible(destinationState)) { Diagnostics.LogError("Transition between state {0} and {1} is not possible.", new object[] { state, destinationState }); } int num = 0; if (diplomaticContract.TurnAtTheBeginningOfTheState >= 0) { num = base.Game.Turn - diplomaticContract.TurnAtTheBeginningOfTheState; } ((IDiplomaticContractManagement)diplomaticContract).SetDiplomaticState(destinationState); if (num > 1) { return; } IEventService service = Services.GetService <IEventService>(); service.Notify(new EventDiplomaticContractStateChange(diplomaticContract, state)); }
public bool IsTransitionPossible(DiplomaticContractState destinationState) { bool result = false; switch (this.State) { case DiplomaticContractState.Negotiation: { DiplomaticTerm.PropositionMethod propositionMethod = this.GetPropositionMethod(); if (destinationState == DiplomaticContractState.Proposed && propositionMethod == DiplomaticTerm.PropositionMethod.Negotiation) { result = this.IsValid(); } if (destinationState == DiplomaticContractState.Signed && propositionMethod == DiplomaticTerm.PropositionMethod.Declaration) { result = this.IsValid(); } if ((destinationState == DiplomaticContractState.Refused || destinationState == DiplomaticContractState.Ignored) && propositionMethod == DiplomaticTerm.PropositionMethod.Negotiation) { result = true; } break; } case DiplomaticContractState.Proposed: if (destinationState == DiplomaticContractState.Signed) { result = this.IsValid(); } if (destinationState == DiplomaticContractState.Refused) { result = true; } if (destinationState == DiplomaticContractState.Negotiation) { result = true; } if (destinationState == DiplomaticContractState.Ignored) { for (int i = 0; i < this.terms.Count; i++) { DiplomaticTerm diplomaticTerm = this.terms[i]; Diagnostics.Assert(diplomaticTerm != null); if (diplomaticTerm.EmpireWhichProvides.Index == this.EmpireWhichProposes.Index && !diplomaticTerm.CanApply(this, new string[0])) { result = true; } } } break; } return(result); }
void IDiplomaticContractManagement.SetDiplomaticState(DiplomaticContractState destinationState) { DiplomaticContractState state = this.State; IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; Diagnostics.Assert(game != null); this.TurnAtTheBeginningOfTheState = game.Turn; if (destinationState == DiplomaticContractState.Proposed && this.EmpireWhichProposes.IsControlledByAI && !this.EmpireWhichReceives.IsControlledByAI) { for (int i = this.terms.Count - 1; i >= 0; i--) { DiplomaticTermResourceExchange diplomaticTermResourceExchange = this.terms[i] as DiplomaticTermResourceExchange; if (diplomaticTermResourceExchange != null && diplomaticTermResourceExchange.EmpireWhichProvides.Index == this.EmpireWhichProposes.Index) { DepartmentOfTheTreasury agency = diplomaticTermResourceExchange.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>(); if (agency.TryTransferResources(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, -diplomaticTermResourceExchange.Amount)) { float num; agency.TryGetResourceStockValue(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, out num, false); Diagnostics.Log("ELCP {0} with {1} Buffering Resource {2} {3}, providerstock2: {4}", new object[] { diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.EmpireWhichReceives, diplomaticTermResourceExchange.ResourceName, diplomaticTermResourceExchange.Amount, num }); diplomaticTermResourceExchange.BufferedAmount = diplomaticTermResourceExchange.Amount; } } } } if (destinationState == DiplomaticContractState.Negotiation || destinationState == DiplomaticContractState.Refused || destinationState == DiplomaticContractState.Ignored) { for (int j = this.terms.Count - 1; j >= 0; j--) { DiplomaticTermResourceExchange diplomaticTermResourceExchange2 = this.terms[j] as DiplomaticTermResourceExchange; if (diplomaticTermResourceExchange2 != null && diplomaticTermResourceExchange2.BufferedAmount > 0f) { DepartmentOfTheTreasury agency2 = diplomaticTermResourceExchange2.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>(); agency2.TryTransferResources(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, diplomaticTermResourceExchange2.BufferedAmount); float num2; agency2.TryGetResourceStockValue(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, out num2, false); Diagnostics.Log("ELCP {0} with {1} UnBuffering Resource {2} {3} {4}, providerstock2: {5}", new object[] { diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.EmpireWhichReceives, diplomaticTermResourceExchange2.ResourceName, diplomaticTermResourceExchange2.BufferedAmount, diplomaticTermResourceExchange2.Amount, num2 }); diplomaticTermResourceExchange2.BufferedAmount = 0f; } } } if (state == DiplomaticContractState.Proposed && destinationState == DiplomaticContractState.Negotiation) { global::Empire empireWhichProposes = this.EmpireWhichProposes; this.EmpireWhichProposes = this.EmpireWhichReceives; this.EmpireWhichReceives = empireWhichProposes; float empireWhichProposesEmpirePointInvestment = this.EmpireWhichProposesEmpirePointInvestment; this.EmpireWhichProposesEmpirePointInvestment = this.EmpireWhichReceivesEmpirePointInvestment; this.EmpireWhichReceivesEmpirePointInvestment = empireWhichProposesEmpirePointInvestment; for (int k = this.terms.Count - 1; k >= 0; k--) { DiplomaticTerm diplomaticTerm = this.terms[k]; Diagnostics.Assert(diplomaticTerm != null); if (!diplomaticTerm.CanApply(this, new string[0])) { this.terms.RemoveAt(k); } } int contractRevisionNumber = this.ContractRevisionNumber; this.ContractRevisionNumber = contractRevisionNumber + 1; } if (destinationState == DiplomaticContractState.Signed) { this.ApplyTerms(); } Diagnostics.Log("Contract {0} pass from state {1} to state {2}.", new object[] { this.GUID, this.State, destinationState }); this.State = destinationState; this.OnDiplomaticContractChange(); }
void IDiplomacyControl.OnServerBeginTurn() { this.firstBeginTurnDone = true; if (this.majorEmpires == null) { return; } while (this.visibilityControllerRefreshedArgs.Count > 0) { KeyValuePair <object, VisibilityRefreshedEventArgs> keyValuePair = this.visibilityControllerRefreshedArgs.Dequeue(); this.OnVisibityRefreshed(keyValuePair.Key, keyValuePair.Value); } int turn = base.Game.Turn; for (int i = 0; i < this.majorEmpires.Length; i++) { MajorEmpire majorEmpire = this.majorEmpires[i] as MajorEmpire; DepartmentOfForeignAffairs agency = majorEmpire.GetAgency <DepartmentOfForeignAffairs>(); Diagnostics.Assert(agency != null); for (int j = i + 1; j < this.majorEmpires.Length; j++) { MajorEmpire majorEmpire2 = this.majorEmpires[j] as MajorEmpire; DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(majorEmpire2); Diagnostics.Assert(diplomaticRelation != null && diplomaticRelation.State != null); if (majorEmpire.IsSpectator || majorEmpire.ELCPIsEliminated || majorEmpire2.IsSpectator || majorEmpire2.ELCPIsEliminated) { if (diplomaticRelation.State.Name != DiplomaticRelationState.Names.Dead) { OrderChangeDiplomaticRelationState order = new OrderChangeDiplomaticRelationState(this.majorEmpires[i].Index, majorEmpire2.Index, DiplomaticRelationState.Names.Dead); this.PlayerController.PostOrder(order); } } else { DiplomaticRelationState.Transition automaticTransition = diplomaticRelation.State.AutomaticTransition; if (automaticTransition != null && automaticTransition.GetRemainingTurns(diplomaticRelation) <= 0) { OrderChangeDiplomaticRelationState order2 = new OrderChangeDiplomaticRelationState(i, j, automaticTransition.DestinationState); this.PlayerController.PostOrder(order2); } } } } bool[][] array = new bool[this.majorEmpires.Length][]; for (int k = 0; k < this.majorEmpires.Length; k++) { array[k] = new bool[this.majorEmpires.Length]; } Diagnostics.Assert(this.diplomaticContracts != null); for (int l = 0; l < this.diplomaticContracts.Count; l++) { DiplomaticContract diplomaticContract = this.diplomaticContracts[l]; Diagnostics.Assert(diplomaticContract != null); if (diplomaticContract.EmpireWhichInitiated.Index >= array.Length || diplomaticContract.EmpireWhichReceives.Index >= array[diplomaticContract.EmpireWhichInitiated.Index].Length) { Diagnostics.Assert(false, "ELCP: Unexpected EmpireIndex {0}", new object[] { diplomaticContract.ToString() }); } else { if (diplomaticContract.State == DiplomaticContractState.Proposed && turn > diplomaticContract.TurnAtTheBeginningOfTheState) { OrderChangeDiplomaticContractState order3 = new OrderChangeDiplomaticContractState(diplomaticContract, DiplomaticContractState.Refused); this.PlayerController.PostOrder(order3); } if (diplomaticContract.State == DiplomaticContractState.Negotiation && turn > diplomaticContract.TurnAtTheBeginningOfTheState) { if (diplomaticContract.EmpireWhichInitiated != diplomaticContract.EmpireWhichProposes || diplomaticContract.ContractRevisionNumber > 0 || array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index]) { DiplomaticContractState newState = DiplomaticContractState.Refused; OrderChangeDiplomaticContractState order4 = new OrderChangeDiplomaticContractState(diplomaticContract, newState); this.PlayerController.PostOrder(order4); } else { array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index] = true; } } } } }