Example #1
0
    // Refactor this to not use an Enum to control group size?
    private void CreateCreature(GameObject prefabAgent)
    {
        int             size;
        AgentController agentController = prefabAgent.GetComponent <AgentController>();
        Agent           prefabProto     = agentController.agent;

        if (prefabProto.SocialLevel == SocialLevel.SOLO)
        {
            size = 1;
        }
        else if (prefabProto.SocialLevel == SocialLevel.SMALL_GROUPS)
        {
            size = 5;
        }
        else // if (prefabProto.SocialLevel == SocialLevel.BIG_GROUPS)
        {
            size = 1;
        }

        GameObject parentObject = new GameObject(prefabProto.race);
        GameObject newCreature;
        Vector3    spawnPos = GameObject.Find(prefabProto.spawnName).transform.position;
        AgentGroup group    = new AgentGroup();

        for (int i = 0; i < size; i++)
        {
            spawnPos    = new Vector3(spawnPos.x + Random.Range(-0.2f, 0.2f), prefabAgent.transform.position.y, spawnPos.z + Random.Range(-0.2f, 0.2f));
            newCreature = Instantiate(prefabAgent, spawnPos, Quaternion.identity);
            newCreature.transform.parent = parentObject.transform;
            group.AddAgent(prefabProto);
        }

        group.SelectLeader();
        allComunities.Add(group);
    }
    public override void Initialize(AgentDefinition agentDefinition, AgentGroup parentGroup)
    {
        base.Initialize(agentDefinition, parentGroup);
        AIPlayer_MajorEmpire aiPlayer = base.ContextObject as AIPlayer_MajorEmpire;

        if (aiPlayer == null)
        {
            Diagnostics.LogError("The agent context object is not an ai player.");
            return;
        }
        this.empire = aiPlayer.MajorEmpire;
        if (this.empire == null)
        {
            Diagnostics.LogError("Can't retrieve the empire.");
            return;
        }
        Diagnostics.Assert(this.empire != null);
        this.departmentOfTheInterior = this.empire.GetAgency <DepartmentOfTheInterior>();
        Diagnostics.Assert(this.departmentOfTheInterior != null);
        this.departmentOfTheTreasury = this.empire.GetAgency <DepartmentOfTheTreasury>();
        Diagnostics.Assert(this.departmentOfTheTreasury != null);
        DepartmentOfIndustry agency = this.empire.GetAgency <DepartmentOfIndustry>();

        Diagnostics.Assert(agency != null);
        DepartmentOfIndustry.ConstructibleElement[] availableConstructibleElements = ((IConstructibleElementDatabase)agency).GetAvailableConstructibleElements(new StaticString[]
        {
            DistrictImprovementDefinition.ReadOnlyCategory
        });
        Diagnostics.Assert(availableConstructibleElements != null);
        this.districtImprovement = Array.Find <DepartmentOfIndustry.ConstructibleElement>(availableConstructibleElements, (DepartmentOfIndustry.ConstructibleElement element) => element.Name == aiPlayer.AIData_Faction.DistrictImprovement);
        Diagnostics.Assert(this.districtImprovement != null && this.districtImprovement.Costs != null);
        InfluencedByPersonalityAttribute.LoadFieldAndPropertyValues(this.empire, this);
    }
Example #3
0
        /// <summary>
        /// Updates the AgentGroupMembers of the specified AgentGroup id
        /// </summary>
        /// <param name="agentGroupId"></param>
        /// <param name="agentId"></param>
        /// <returns></returns>
        public IEnumerable <AgentGroupMember> UpdateGroupMembers(string agentGroupId, IEnumerable <AgentGroupMember> groupMembers)
        {
            var agentGroupGuid = Guid.Parse(agentGroupId);

            AgentGroup agentGroup = _agentGroupRepository.GetOne(agentGroupGuid);

            if (agentGroup == null)
            {
                throw new EntityDoesNotExistException("No agent group was found with the specified id");
            }

            List <AgentGroupMember> memberList = new List <AgentGroupMember>();

            DeleteGroupMembers(agentGroupId);//delete existing members

            foreach (var member in groupMembers ?? Enumerable.Empty <AgentGroupMember>())
            {
                member.AgentGroupId = agentGroupGuid;
                member.CreatedBy    = _caller.Identity.Name;
                member.CreatedOn    = DateTime.UtcNow;

                _agentGroupMemberRepository.Add(member);
                memberList.Add(member);
            }

            _webhookPublisher.PublishAsync("AgentGroups.AgentGroupMemberUpdated", agentGroupId, agentGroup.Name).ConfigureAwait(false);
            return(memberList.AsEnumerable());
        }
Example #4
0
    public override void Initialize(AgentDefinition agentDefinition, AgentGroup parentGroup)
    {
        base.Initialize(agentDefinition, parentGroup);
        AIPlayer_MajorEmpire aiplayer_MajorEmpire = base.ContextObject as AIPlayer_MajorEmpire;

        if (aiplayer_MajorEmpire == null)
        {
            Diagnostics.LogError("The agent context object is not an ai player.");
            return;
        }
        this.empire = aiplayer_MajorEmpire.MajorEmpire;
        if (this.empire == null)
        {
            Diagnostics.LogError("Can't retrieve the empire.");
            return;
        }
        Diagnostics.Assert(base.ParentGroup != null);
        this.netEmpireMoneyAgent = (base.ParentGroup.GetAgent("NetEmpireMoney") as SimulationNormalizedAgent);
        Diagnostics.Assert(this.netEmpireMoneyAgent != null);
        this.departmentOfScience = this.empire.GetAgency <DepartmentOfScience>();
        IGameService service = Services.GetService <IGameService>();

        this.game = (service.Game as global::Game);
        InfluencedByPersonalityAttribute.LoadFieldAndPropertyValues(this.empire, this);
    }
Example #5
0
    public override void Initialize(AgentDefinition agentDefinition, AgentGroup parentGroup)
    {
        base.Initialize(agentDefinition, parentGroup);
        City city = base.ContextObject as City;

        if (city == null)
        {
            Diagnostics.LogError("The agent context object is not a city");
            return;
        }
        Diagnostics.Assert(city.Empire != null);
        this.departmentOfTheTreasury = city.Empire.GetAgency <DepartmentOfTheTreasury>();
        Diagnostics.Assert(this.departmentOfTheTreasury != null);
        DepartmentOfIndustry agency = city.Empire.GetAgency <DepartmentOfIndustry>();

        Diagnostics.Assert(agency != null);
        this.aiPlayer = (base.ParentGroup.Parent.ContextObject as AIPlayer_MajorEmpire);
        if (this.aiPlayer == null)
        {
            Diagnostics.LogError("The agent context object is not an ai player.");
            return;
        }
        this.constructionQueue = agency.GetConstructionQueue(city);
        Diagnostics.Assert(this.constructionQueue != null);
        InfluencedByPersonalityAttribute.LoadFieldAndPropertyValues(city.Empire, this);
    }
Example #6
0
    // Percepts
    private void Spotting()
    {
        foreach (Agent a in LevelManager.Instance.Agents)
        {
            OtherAgent oa = new OtherAgent(a.name, a.Team, a.transform.position, a.visionDirection, a.direction);
            if (InFieldOfVision(a.name))
            {
                // Update position & looking direction
                if (seenOtherAgents.ContainsKey(oa.Name))
                {
                    seenOtherAgents[oa.Name].Position        = oa.Position;
                    seenOtherAgents[oa.Name].VisionDirection = oa.VisionDirection;
                }
                else
                {
                    seenOtherAgents.Add(oa.Name, oa);
                    AgentGroup.SeenAgent(oa);
                }

                if (TargetAgent != null && TargetAgent.Enemy.Equals(oa))
                {
                    TargetAgent.Enemy.Position = oa.Position;
                }
            }
            else
            {
                AgentGroup.UnseenAgent(oa);

                // Remove unseen agents
                seenOtherAgents.Remove(oa.Name);
            }
        }
    }
Example #7
0
        /// <summary>
        /// Retrieve ExchangeRate information from the database
        /// </summary>
        /// <param name="recordID">record ID according to which the touple is to be retrieved</param>
        /// <returns></returns>
        public AgentGroup GetAgentGroupRecord(int recordID, string UserID)
        {
            try
            {
                AgentGroup     agent      = new AgentGroup();
                SqlParameter[] Parameters = { new SqlParameter("@SNo", Convert.ToInt32(recordID)) };
                SqlDataReader  dr         = SqlHelper.ExecuteReader(ReadConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetRecordAgentGroup", Parameters);
                if (dr.Read())
                {
                    agent.SNo             = Convert.ToInt32(dr["SNo"]);
                    agent.AgentGroupName  = Convert.ToString(dr["AgentGroupName"]).ToUpper();
                    agent.GroupLevel      = Convert.ToInt32(dr["GroupLevel"]);
                    agent.Text_GroupLevel = Convert.ToString(dr["Text_GroupLevel"]).ToUpper();
                    agent.CountrySNo      = Convert.ToInt32(dr["CountrySNo"]);
                    agent.Text_CountrySNo = Convert.ToString(dr["Text_CountrySNo"]).ToUpper();
                    agent.CitySNo         = Convert.ToInt32(dr["CitySNo"]);
                    agent.Text_CitySNo    = Convert.ToString(dr["Text_CitySNo"]).ToUpper();
                    agent.AccountSNo      = Convert.ToString(dr["AccountSNo"]);
                    agent.Text_AccountSNo = Convert.ToString(dr["Text_AccountSNo"]).ToUpper();
                    agent.IsActive        = Convert.ToBoolean(dr["IsActive"]);
                    agent.Text_IsActive   = Convert.ToBoolean(dr["IsActive"]) == true ? "YES" : "NO";
                    agent.UpdatedBy       = dr["UpdatedUser"].ToString();
                    agent.CreatedBy       = dr["CreatedUser"].ToString();
                }

                dr.Close();
                return(agent);
            }
            catch (Exception ex)//
            {
                throw ex;
            }
        }
    public override void Initialize(AgentDefinition agentDefinition, AgentGroup parentGroup)
    {
        base.Initialize(agentDefinition, parentGroup);
        Diagnostics.Assert(base.ParentGroup != null && base.ParentGroup.Parent != null);
        AIPlayer_MajorEmpire aiplayer_MajorEmpire = base.ParentGroup.Parent.ContextObject as AIPlayer_MajorEmpire;

        Diagnostics.Assert(aiplayer_MajorEmpire != null);
        this.Empire = aiplayer_MajorEmpire.MajorEmpire;
        if (this.Empire == null)
        {
            Diagnostics.LogError("The agent's parent context object is not an empire");
            return;
        }
        this.EmpireWhichReceives = (base.ParentGroup.ContextObject as global::Empire);
        if (this.EmpireWhichReceives == null)
        {
            Diagnostics.LogError("The agent context object is not an empire");
            return;
        }
        this.aiEntityEmpire = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
        if (this.aiEntityEmpire == null)
        {
            Diagnostics.LogError("The AIPlayer has no ai entity empire.");
            return;
        }
        InfluencedByPersonalityAttribute.LoadFieldAndPropertyValues(this.aiEntityEmpire.Empire, this);
    }
    private void FillDecisionMakerVariables()
    {
        if (this.decisionMaker.Context == null)
        {
            return;
        }
        this.decisionMaker.Context.Register("GlobalWarNeed", this.aiLayerDiplomacy.GetGlobalWarNeed());
        this.decisionMaker.Context.Register("IndustryReferenceTurnCount", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.IndustryReferenceTurnCount));
        this.decisionMaker.Context.Register("TechnologyReferenceTurnCount", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.TechnologyReferenceTurnCount));
        this.decisionMaker.Context.Register("MoneyReferenceRatio", this.aiLayerResourceAmas.Amas.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.MoneyReferenceRatio));
        int num  = this.departmentOfScience.CurrentTechnologyEraNumber - 1;
        int num2 = 0;
        int num3 = 0;

        foreach (DepartmentOfScience.ConstructibleElement constructibleElement in this.departmentOfScience.TechnologyDatabase)
        {
            TechnologyDefinition technologyDefinition = constructibleElement as TechnologyDefinition;
            if (technologyDefinition != null)
            {
                int technologyEraNumber = DepartmentOfScience.GetTechnologyEraNumber(technologyDefinition);
                DepartmentOfScience.ConstructibleElement.State technologyState = this.departmentOfScience.GetTechnologyState(constructibleElement);
                if (technologyState == DepartmentOfScience.ConstructibleElement.State.Available)
                {
                    num3++;
                    if (technologyEraNumber < num)
                    {
                        num2++;
                    }
                }
            }
        }
        float num4 = 0f;

        if (num3 > 0)
        {
            num4 = (float)num2 / (float)num3;
        }
        this.decisionMaker.Context.Register("OldTechnologyRatio", num4);
        AILayer_Strategy layer      = base.AIEntity.GetLayer <AILayer_Strategy>();
        float            agentValue = layer.StrategicNetwork.GetAgentValue("Expansion");

        this.decisionMaker.Context.Register("ColonizationPriority", agentValue);
        DepartmentOfTheInterior agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheInterior>();
        float num5 = 0f;

        if (agency.Cities.Count > 0)
        {
            for (int i = 0; i < agency.Cities.Count; i++)
            {
                AgentGroup cityAgentGroup = this.aiLayerResourceAmas.GetCityAgentGroup(agency.Cities[i]);
                if (cityAgentGroup != null)
                {
                    num5 += cityAgentGroup.GetAgentCriticityMaxIntensity(AILayer_ResourceAmas.AgentNames.PopulationReferenceTurnCount);
                }
            }
            num5 /= (float)agency.Cities.Count;
        }
        this.decisionMaker.Context.Register("PopulationReferenceTurnCount", num5);
    }
Example #10
0
 // Placeholder for dying
 private void Die()
 {
     foreach (OtherAgent oa in seenOtherAgents.Values)
     {
         AgentGroup.UnseenAgent(oa);
     }
     AgentGroup.DeleteMember(this);
     LevelManager.Instance.DeleteAgent(this);
 }
Example #11
0
        /// <summary>
        /// Takes an AgentGroup and returns it for addition
        /// </summary>
        /// <param name="agentGroup"></param>
        /// <returns>The AgentGroup to be added</returns>
        public AgentGroup AddAgentGroup(AgentGroup agentGroup)
        {
            var namedAgentGroup = _agentGroupRepository.Find(null, d => d.Name.ToLower() == agentGroup.Name.ToLower())?.Items?.FirstOrDefault();

            if (namedAgentGroup != null)
            {
                throw new EntityAlreadyExistsException("Agent group name already exists");
            }
            return(agentGroup);
        }
Example #12
0
        private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e)
        {
            label_AgentGroupID.Text = comboBox_AgentGroupID.SelectedValue.ToString();

            if (Convert.ToInt32(label_AgentGroupID.Text) > 0)
            {
                anAgentGroup.ID = Convert.ToInt32(label_AgentGroupID.Text);
                anAgentGroup    = agentGroupH.Show(anAgentGroup.ID);
            }
        }
Example #13
0
 public int agentGroupValidate(int agentId, string groupName)
 {
     try
     {
         return(AgentGroup.Find("idAgentGroups IN (SELECT iGroupID FROM  dbo.[_rtblAgentGroupMembers] WHERE iAgentID = " + Convert.ToString(agentId) + ") AND cGroupName='" + groupName + "'"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public BindingList <AgentGroupDetail> Show(AgentGroup anAgentGroup)
 {
     try
     {
         var myList      = new AgentGroupDetailDataHelper().SelectByGroupID(anAgentGroup.ID);
         var bindingList = new BindingList <AgentGroupDetail>(myList);
         return(bindingList);
     }
     catch (ArgumentNullException)
     {
         throw new DataExistence("No Data Found! No Members are avialable in selected Agent group.");
     }
 }
        public Job GetAgentGroupJob(Guid agentGuid)
        {
            List <Job> agentGroupJobs     = new List <Job>();
            var        agentGroupsMembers = GetAllMembersInGroup(agentGuid.ToString()).Items;

            foreach (var member in agentGroupsMembers)
            {
                AgentGroup agentGroup = _agentGroupRepository.Find(null, g => g.Id == member.AgentGroupId).Items?.FirstOrDefault();
                //if agent group is disabled, then do not retreive jobs from that group
                if (agentGroup.IsEnabled == false)
                {
                    continue;
                }

                var memberGroupJobs = _jobRepo.Find(null, j => j.AgentGroupId == member.AgentGroupId && j.JobStatus == JobStatusType.New).Items;
                agentGroupJobs = agentGroupJobs.Concat(memberGroupJobs).ToList();
            }

            var agentJobs    = _jobRepo.Find(null, j => j.AgentId == agentGuid && j.JobStatus == JobStatusType.New).Items;
            var allAgentJobs = agentGroupJobs.Concat(agentJobs).ToList();
            Job job          = allAgentJobs.OrderBy(j => j.CreatedOn).FirstOrDefault();

            //update job
            if (job != null)
            {
                job.JobStatus   = JobStatusType.Assigned;
                job.DequeueTime = DateTime.UtcNow;
                job.AgentId     = agentGuid;
                try
                {
                    job = _jobRepo.Update(job);
                }
                catch (EntityConcurrencyException ex)
                {
                    job = null;
                }
            }
            return(job);
        }
    public override void Initialize(AgentDefinition agentDefinition, AgentGroup parentGroup)
    {
        base.Initialize(agentDefinition, parentGroup);
        AIPlayer_MajorEmpire aiplayer_MajorEmpire = base.ContextObject as AIPlayer_MajorEmpire;

        if (aiplayer_MajorEmpire == null)
        {
            Diagnostics.LogError("The agent context object is not an ai player.");
            return;
        }
        this.empire = aiplayer_MajorEmpire.MajorEmpire;
        if (this.empire == null)
        {
            Diagnostics.LogError("Can't retrieve the empire.");
            return;
        }
        this.aiEntityEmpire = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
        Diagnostics.Assert(this.aiEntityEmpire != null);
        Diagnostics.Assert(base.ParentGroup != null);
        this.netEmpireMoneyAgent = (base.ParentGroup.GetAgent("NetEmpireMoney") as SimulationNormalizedAgent);
        Diagnostics.Assert(this.netEmpireMoneyAgent != null);
        InfluencedByPersonalityAttribute.LoadFieldAndPropertyValues(this.aiEntityEmpire.Empire, this);
    }
Example #17
0
        /// <summary>
        /// Updates an AgentGroup entity
        /// </summary>
        /// <param name="id"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public AgentGroup UpdateAgentGroup(string id, AgentGroup request)
        {
            Guid entityId = new Guid(id);

            var existingAgentGroup = _agentGroupRepository.GetOne(entityId);

            if (existingAgentGroup == null)
            {
                throw new EntityDoesNotExistException("No agent group exists for the specified agent group id");
            }

            var namedAgentGroup = _agentGroupRepository.Find(null, d => d.Name.ToLower() == request.Name.ToLower() && d.Id != entityId)?.Items?.FirstOrDefault();

            if (namedAgentGroup != null && namedAgentGroup.Id != entityId)
            {
                throw new EntityAlreadyExistsException("Agent group name already exists");
            }

            existingAgentGroup.Name        = request.Name;
            existingAgentGroup.IsEnabled   = request.IsEnabled;
            existingAgentGroup.Description = request.Description;

            return(existingAgentGroup);
        }
Example #18
0
 protected void sosAgent_ManageGroups(object sender, UcControlArgs e)
 {
     AgentGroup.AgentId = e.Id;
     AgentGroup.UcDataBind();
     mvAgent.ActiveViewIndex = 1;
 }