Esempio n. 1
0
    private NewOwnerUserRelationshipChoices? _priorNewOwnerUserRelationsChoice = null;  // can't use None without showing it as a choice

    private void CheckNewOwnerUserRelations() {
        if (_newOwnerUserRelationsChoice != _priorNewOwnerUserRelationsChoice) {
            // a new desired owner relationship has been selected

            Player newOwner;
            if (_newOwnerUserRelationsChoice == NewOwnerUserRelationshipChoices.BecomeUser) {
                newOwner = _gameMgr.UserPlayer;
            }
            else {
                DiplomaticRelationship newOwnerUserRelationshipChoice = Convert(_newOwnerUserRelationsChoice);

                IEnumerable<Player> newOwnerCandidates = _gameMgr.UserPlayer.OtherKnownPlayers.Where(aiPlayer => aiPlayer.IsRelationshipWith(_gameMgr.UserPlayer, newOwnerUserRelationshipChoice));
                if (newOwnerCandidates.Any()) {
                    newOwner = newOwnerCandidates.Shuffle().First();
                    // newOwner has already been met and has the desired relationship
                }
                else {
                    newOwnerCandidates = _gameMgr.UniverseCreator.__GetUnmetAiPlayersWithInitialUserRelationsOf(newOwnerUserRelationshipChoice);
                    if (newOwnerCandidates.Any()) {
                        // newOwner is an unmet, unassigned player
                        newOwner = newOwnerCandidates.Shuffle().First();
                    }
                    else {
                        D.Warn("{0} has found no players who have or will have the desired user relationship {1}.", DebugName, newOwnerUserRelationshipChoice.GetValueName());
                        SyncUserRelationsFieldsTo(_currentOwnerUserRelations);
                        return;
                    }
                }
            }

            var tempNewOwnerUserRelationsChoice = _newOwnerUserRelationsChoice; // choice can be changed by owner change event
            D.LogBold("{0} has selected {1} as its new owner.", DebugName, newOwner);
            _unitCmd.Owner = newOwner;  // generates an ownerChange event which will sync to current user relationship

            if (_currentOwnerUserRelations == DiplomaticRelationship.None) {
                // correct _newOwnerUserRelationsChoice to what was chosen
                _allowNewOwnerUserRelationsCheck = false;
                _newOwnerUserRelationsChoice = tempNewOwnerUserRelationsChoice;
                _allowNewOwnerUserRelationsCheck = true;
            }
            _priorNewOwnerUserRelationsChoice = _newOwnerUserRelationsChoice;
        }
    }
Esempio n. 2
0
 private static DiplomaticRelationship Convert(NewOwnerUserRelationshipChoices newOwnerUserRelationship) {
     switch (newOwnerUserRelationship) {
         case NewOwnerUserRelationshipChoices.BecomeUser:
             return DiplomaticRelationship.Self;
         case NewOwnerUserRelationshipChoices.Alliance:
             return DiplomaticRelationship.Alliance;
         case NewOwnerUserRelationshipChoices.Friendly:
             return DiplomaticRelationship.Friendly;
         case NewOwnerUserRelationshipChoices.Neutral:
             return DiplomaticRelationship.Neutral;
         case NewOwnerUserRelationshipChoices.ColdWar:
             return DiplomaticRelationship.ColdWar;
         case NewOwnerUserRelationshipChoices.War:
             return DiplomaticRelationship.War;
         default:
             throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(newOwnerUserRelationship));
     }
 }
Esempio n. 3
0
 private void SyncUserRelationsFieldsTo(DiplomaticRelationship ownerUserRelationship) {
     _allowNewOwnerUserRelationsCheck = false;
     _currentOwnerUserRelations = ownerUserRelationship;
     _newOwnerUserRelationsChoice = Convert(ownerUserRelationship);
     _allowNewOwnerUserRelationsCheck = true;
 }