예제 #1
0
        protected void worsenRelation(DiplomaticEntity sender, DiplomaticEntity target, Relation relation, List <DiplomaticRelation> relations)
        {
            //set new relationship on both entites to the new value:
            //first direction / entity

            /*
             * setDiplomaticEntityState(sender, target, relation);
             *
             * //second direction / entity
             * setDiplomaticEntityState(target, sender, relation);
             *
             * relations.Add(new DiplomaticRelation(sender.GetHashCode(), target.GetHashCode(), (int)relation));
             * relations.Add(new DiplomaticRelation(target.GetHashCode(), sender.GetHashCode(), (int)relation));
             */

            //list of ships moved away
            List <Ship> shipsFighting = new List <Ship>();

            //set  new relationship on both entites-USERS to the new value (in case of alliances):
            //create list of sender-Users
            //if (sender.diplomaticType != 1 || target.diplomaticType != 1  )
            //{

            foreach (var senderUser in sender.GetAllEntities())
            {
                foreach (var targetUser in target.GetAllEntities())
                {
                    setDiplomaticEntityState(senderUser, targetUser, relation);
                    setDiplomaticEntityState(targetUser, senderUser, relation);
                    relations.Add(new DiplomaticRelation(senderUser.GetHashCode(), targetUser.GetHashCode(), (int)relation));
                    relations.Add(new DiplomaticRelation(targetUser.GetHashCode(), senderUser.GetHashCode(), (int)relation));

                    if (relation < Relation.Neutral && senderUser.diplomaticType == 1 && targetUser.diplomaticType == 1)
                    {
                        ((User)senderUser).declaredWar((User)targetUser, shipsFighting, true);
                    }
                    //((User)targetUser).declaredWar((User)senderUser, shipsFighting, false);
                }
            }

            //}

            Core.Instance.dataConnection.saveShips(shipsFighting);
        }
예제 #2
0
        /// <summary>
        /// set the relation between two entities
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="target"></param>
        /// <param name="relation"></param>
        /// <param name="relations">Is needed to write result to DB (and generate XML?) </param>
        /// <remarks>called with input data is already checked</remarks>
        protected void SetRelation(DiplomaticEntity sender, DiplomaticEntity target, Relation relation, List <DiplomaticRelation> relations)
        {
            Relation currentRelation = Relation.Neutral;

            if (DiplomaticEntityState.ContainsKey(sender) &&
                DiplomaticEntityState[sender].ContainsKey(target) &&
                DiplomaticEntityState.ContainsKey(target) &&
                DiplomaticEntityState[target].ContainsKey(sender))
            {
                currentRelation = Min(DiplomaticEntityState[sender][target], DiplomaticEntityState[target][sender]);
            }

            //worsening of the relation
            if (relation < currentRelation)
            {
                //Todo: lock all users, ships and alliances. Use a priority lock (to be implemented), since a lot of objects can be part of the transaction
                worsenRelation(sender, target, relation, relations);

                //always worth a Galactic Event
                GalacticEvents.CreateEventFromDiplomacy(sender, target, relation, currentRelation);

                return;
            }

            //relationion is not worsened:
            //either a proposal is done or
            // a proposal is accepted (and perhaps an additional proposal is done)

            //if targetRelationToSender is the currentRelation
            Relation targetRelationToSender = Relation.Neutral;

            if (DiplomaticEntityState.ContainsKey(target) &&
                DiplomaticEntityState[target].ContainsKey(sender))
            {
                targetRelationToSender = (Relation)DiplomaticEntityState[target][sender];
            }



            Relation newCurrentRelation = (Relation)Math.Min((int)targetRelationToSender, (int)relation);

            if (newCurrentRelation != currentRelation)
            {
                //change of relation: always worth a Galactic Event
                GalacticEvents.CreateEventFromDiplomacy(sender, target, newCurrentRelation, currentRelation);
            }

            //Some Relations can't be changed
            if (target is User)
            {
                if (((User)target).AiId > 0 && ((User)target).AiRelation < (int)Relation.Neutral)
                {
                    newCurrentRelation = UserRelations.Min(newCurrentRelation, ((Relation)((User)target).AiRelation));
                }
            }


            /*
             * //all senderusers should be set to newCurrentRelation
             * //create list of sender-Users
             * List<DiplomaticEntity> senders = sender.getMembers();
             *
             * //create list of target-Users
             * List<DiplomaticEntity> targets = target.getMembers();
             *
             * //update all users that are mebers and have a lower relationship than the new one:
             * foreach(var senderUser in senders)
             * {
             *  foreach(var targetUser in targets)
             *  {
             *      if (UserRelations.IsLower( getRelation(senderUser, targetUser) , newCurrentRelation))
             *      {
             *          setDiplomaticEntityState(senderUser, targetUser, newCurrentRelation);
             *          relations.Add(new DiplomaticRelation(senderUser.GetHashCode(), targetUser.GetHashCode(), (int)newCurrentRelation));
             *      }
             *      if (UserRelations.IsLower(getRelation(targetUser, senderUser) , newCurrentRelation))
             *      {
             *          setDiplomaticEntityState(targetUser, senderUser, newCurrentRelation);
             *          relations.Add(new DiplomaticRelation(targetUser.GetHashCode(), senderUser.GetHashCode(), (int)newCurrentRelation));
             *      }
             *  }
             * }
             *
             *
             * //and senderDiplomaticEntity proposes "his" relation
             * setDiplomaticEntityState(sender, target, relation);
             */

            foreach (var senderUser in sender.GetAllEntities())
            {
                foreach (var targetUser in target.GetAllEntities())
                {
                    setDiplomaticEntityState(senderUser, targetUser, relation);
                    relations.Add(new DiplomaticRelation(senderUser.GetHashCode(), targetUser.GetHashCode(), (int)relation));

                    /*
                     * if (UserRelations.IsLower(getRelation(senderUser, targetUser), newCurrentRelation))
                     * {
                     *  setDiplomaticEntityState(senderUser, targetUser, newCurrentRelation);
                     *  relations.Add(new DiplomaticRelation(senderUser.GetHashCode(), targetUser.GetHashCode(), (int)newCurrentRelation));
                     * }
                     * if (UserRelations.IsLower(getRelation(targetUser, senderUser), newCurrentRelation))
                     * {
                     *  setDiplomaticEntityState(targetUser, senderUser, newCurrentRelation);
                     *  relations.Add(new DiplomaticRelation(targetUser.GetHashCode(), senderUser.GetHashCode(), (int)newCurrentRelation));
                     * }
                     */
                }
            }
        }