/// <summary>
        /// Initialize this Component
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // Initialize TCPIP
            if (Simulate == eSimulate.SimulateDontAsk)
            {
                throw new ForceSimulateException("Always Simulate");
            }

            try
            {
                BuildErrorList();
                _oECUtils = new ECUtils();
                _iSession = new Session();
                Attach();
                Simulate = eSimulate.None;
            }
            catch (ForceSimulateException fsex)
            {
                throw fsex;
            }
            catch (Exception ex)
            {
                throw new ForceSimulateException(ex);
            }
        }
Beispiel #2
0
 public virtual void init()
 {
     foreach (mEntity e in filter)
     {
         mEntity ent = ECUtils.getMatchingEntity(e, owner.entities);
         cachedFilter.Add(ent);
     }
 }
Beispiel #3
0
    public void init()
    {
        //populate lists from profile. Profile has archetypes.
        //DO NOT USE ARCHETYPES. I will hurt you!
        //Make copies for use

        Debug.Log("Initializing agent");

        List <Inventory> inventories = profile.getComponents <Inventory>();

        List <MAction> acts = profile.getComponent <ActionListComponent>().list;
        List <MGoal>   gls  = profile.getComponent <GoalListComponent>().list;
        List <MNorm>   nrms = profile.getComponent <NormListComponent>().list;

        List <mEntity> ents = new List <mEntity>();

        foreach (Inventory inv in inventories)
        {
            if (inv.name.Contains("Entities"))
            {
                ents = inv.list;
            }
        }

        entities.Clear();

        Debug.Log("Populating entities");

        foreach (mEntity entity in ents)
        {
            Debug.Log("Copying " + entity.entityName);
            mEntity e = ECUtils.DeepCopyEntity(entity);//entity.copy();
            entities.Add(e);
        }

        actions.Clear();
        Debug.Log("Populating actions");
        foreach (MAction action in actions)
        {
            //  MAction act = ECUtils.DeepCopy<MAction>(action);
            //   actions.Add(act);
        }

        goals.Clear();
        Debug.Log("Populating goals");
        foreach (MGoal goal in gls)
        {
            //goals.Add(ECUtils.DeepCopy<MGoal>(goal));
        }

        norms.Clear();
        Debug.Log("Populating norms");
        foreach (MNorm norm in nrms)
        {
            // norms.Add(ECUtils.DeepCopy<MNorm>(norm));
        }
    }
Beispiel #4
0
    // Start is called before the first frame update
    void Start()
    {
        initResource();
        initCommunities();


        othertest = ECUtils.DeepCopyEntity(test);
        othertest.components.Add(new ColorComponent());

        Debug.Log(test.components.Count);
        Debug.Log(othertest.components.Count);
    }
Beispiel #5
0
    void initAgents(mEntity agentProfile, GameObject comGO, mEntity comProfile, mEntity vesselProfile)
    {
        GameObject agentGO = Instantiate(ECUtils.GetComponent <Prefab>(agentProfile).prefab);

        agentGO.GetComponent <AgentBehavior>().profile          = agentProfile;
        agentGO.GetComponent <AgentBehavior>().communityProfile = comProfile;

        agentGO.GetComponent <AgentBehavior>().init();
        agentGO.transform.parent = comGO.transform;
        agents.Add(agentGO);

        initVessels(vesselProfile, agentGO);
    }
Beispiel #6
0
    public mEntity copy()
    {
        mEntity copy = CreateInstance <mEntity>();

        copy.name       = this.name + "*";
        copy.entityName = this.entityName + "*";

        // copy.components = new List<IComponent>(this.components);//this.components.ToList();
        foreach (IComponent c in components)
        {
            copy.components.Add(ECUtils.DeepCopyComponent(c));
        }
        return(copy);
    }
Beispiel #7
0
    public void init()
    {
        cachedInFilter.Clear();
        cachedOutFilter.Clear();

        foreach (mEntity e in inFilter)
        {
            cachedInFilter.Add(ECUtils.getMatchingEntity(e, owner.entities));
        }

        foreach (mEntity e in outFilter)
        {
            cachedOutFilter.Add(ECUtils.getMatchingEntity(e, owner.entities));
        }
    }
Beispiel #8
0
    void initWorkPlace(mEntity workProfile, GameObject comGO, mEntity comProfile)
    {
        GameObject workGO = Instantiate(ECUtils.GetComponent <Prefab>(workProfile).prefab);

        workGO.transform.position = ECUtils.GetComponent <Position>(workProfile).position;
        workGO.GetComponent <SpriteRenderer>().color = ECUtils.GetComponent <ColorComponent>(comProfile).color;
        ECUtils.GetComponent <SceneObject>(workProfile).gameObject = workGO;

        ECUtils.GetComponent <CommunityProfile>(workProfile).profile  = comProfile;
        ECUtils.GetComponent <CommunityObject>(workProfile).community = comGO;

        workGO.transform.parent = comGO.transform;

        workGO.GetComponent <WorkPlaceScript>().profile = workProfile;
    }
Beispiel #9
0
    void initHarbor(mEntity harborProfile, GameObject comGO, mEntity comProfile)
    {
        GameObject harborGO = Instantiate(ECUtils.GetComponent <Prefab>(harborProfile).prefab);

        harborGO.transform.position = ECUtils.GetComponent <Position>(harborProfile).position;
        harborGO.GetComponent <SpriteRenderer>().color = ECUtils.GetComponent <ColorComponent>(comProfile).color;
        ECUtils.GetComponent <SceneObject>(harborProfile).gameObject = harborGO;

        ECUtils.GetComponent <CommunityProfile>(harborProfile).profile  = comProfile;
        ECUtils.GetComponent <CommunityObject>(harborProfile).community = comGO;

        harborGO.transform.parent = comGO.transform;

        //add this profile to the harbor behavior script
        harborGO.GetComponent <HarborScript>().profile = harborProfile;
    }
Beispiel #10
0
    public virtual void init(BaseAgentBehavior owner)
    {
        this.owner = owner;

        cachedContext.Clear();
        foreach (mEntity ent in context)
        {
            cachedContext.Add(ECUtils.getMatchingEntity(ent, owner.entities));
        }

        if (targetAction != null)
        {
            cachedTargetAction = owner.actions.getAction(targetAction);
        }

        if (targetGoal != null)
        {
            cachedTargetGoal = owner.goals.getGoal(targetGoal);
        }
    }
Beispiel #11
0
    public void initReferences()
    {
        List <mEntity> infilterMirror  = new List <mEntity>();
        List <mEntity> outfilterMirror = new List <mEntity>();

        foreach (mEntity ent in inFilter)
        {
            if (owner.entities.Any(item => ECUtils.entitiesMatch(item, ent)))
            {
                infilterMirror.Add(ECUtils.getMatchingEntity(ent, owner.entities));
            }
        }
        inFilter = infilterMirror;

        foreach (mEntity ent in outFilter)
        {
            if (owner.entities.Any(item => ECUtils.entitiesMatch(item, ent)))
            {
                outfilterMirror.Add(ECUtils.getMatchingEntity(ent, owner.entities));
            }
        }
        outFilter = outfilterMirror;
    }
Beispiel #12
0
    void initVessels(mEntity vesselProfile, GameObject agent)
    {
        GameObject vesselGO = Instantiate(ECUtils.GetComponent <Prefab>(vesselProfile).prefab);
        Color      color    = agent.GetComponent <AgentBehavior>().communityProfile.getComponent <ColorComponent>().color;

        vesselGO.GetComponent <SpriteRenderer>().color         = color;
        vesselGO.GetComponent <VesselBehavior>().vesselProfile = vesselProfile;

        Transform comGO = agent.transform.parent;


        foreach (Transform child in comGO)
        {
            // Debug.Log(child.gameObject.tag);

            if (child.gameObject.tag.Contains("Harbor"))
            {
                //  Debug.Log(child.transform.position.ToString());
                vesselGO.transform.position = child.position;
            }
        }

        vesselGO.transform.parent = agent.transform;
    }
Beispiel #13
0
    void initCommunities()
    {
        Debug.Log("building communities");
        List <Inventory> inventories = ECUtils.GetComponents <Inventory>(scenarioProfile);
        List <mEntity>   comms       = new List <mEntity>();

        foreach (Inventory inv in inventories)
        {
            if (inv.name.Contains("Communities"))
            {
                foreach (mEntity com in inv.list)
                {
                    comms.Add(com);
                    GameObject comGO = Instantiate(ECUtils.GetComponent <Prefab>(com).prefab);
                    ECUtils.GetComponent <SceneObject>(com).gameObject = comGO;
                    // sceneObject = comGO;
                    communities.Add(comGO);
                    comGO.transform.position = ECUtils.GetComponent <Position>(com).position;
                    comGO.GetComponent <SpriteRenderer>().color = ECUtils.GetComponent <ColorComponent>(com).color;
                    Inventory        vessels = new Inventory();
                    List <Inventory> comInv  = ECUtils.GetComponents <Inventory>(com);

                    foreach (Inventory cinv in comInv)
                    {
                        if (cinv.name.Contains("Vessels"))
                        {
                            vessels = cinv;
                        }
                    }

                    foreach (Inventory cinv in comInv)
                    {
                        if (cinv.name.Contains("Harbors"))
                        {
                            foreach (mEntity harborProfile in cinv.list)
                            {
                                initHarbor(harborProfile, comGO, com);
                            }
                        }

                        if (cinv.name.Contains("Workplaces"))
                        {
                            foreach (mEntity workProfile in cinv.list)
                            {
                                initWorkPlace(workProfile, comGO, com);
                            }
                        }

                        if (cinv.name.Contains("Agents"))
                        {
                            mEntity vesselProfile = vessels.list[0];

                            foreach (mEntity agentProfile in cinv.list)
                            {
                                initAgents(agentProfile, comGO, com, vesselProfile);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #14
0
    public void OnEndDay()
    {
        if (entities.getEntity <Catch>().getComponent <isAvailable>() == null)
        {
            entities.getEntity <Catch>().components.Add(new isAvailable());
        }

        if (entities.getEntity <Catch>().getComponent <isAvailable>() != null)
        {
            gameObject.transform.parent.GetComponent <AgentBehavior>().OnVesselReturns(ECUtils.DeepCopyEntity(entities.getEntity <Catch>()));
            // test = ECUtils.DeepCopyEntity(entities.getEntity<Catch>());

            entities.getEntity <Profit>().getComponent <Profit>().profit += entities.getEntity <Catch>().getComponent <Catch>().size;
            entities.getEntity <Catch>().getComponent <Catch>().size      = 0;
            entities.getEntity <Catch>().getComponent <ByCatch>().size    = 0;
        }

        Debug.Log("... and it's done.");
        //  StartCoroutine("goHome");
        // OnVesselReturns();
    }
    public virtual void loadProfile(mEntity profile)
    {
        //populate lists from profile. Profile has archetypes.
        //DO NOT USE ARCHETYPES. I will hurt you!
        //Make copies for use

        Debug.Log("Initializing agent");

        List <Inventory> inventories = profile.getComponents <Inventory>();

        List <MAction> acts = profile.getComponent <ActionListComponent>().list;
        List <MGoal>   gls  = profile.getComponent <GoalListComponent>().list;
        List <MNorm>   nrms = profile.getComponent <NormListComponent>().list;

        List <mEntity> ents = new List <mEntity>();

        foreach (Inventory inv in inventories)
        {
            if (inv.name.Contains("Entities"))
            {
                ents = inv.list;
            }
        }

        entities.Clear();

        //  Debug.Log("Populating entities");

        foreach (mEntity entity in ents)
        {
            // Debug.Log("Copying " + entity.entityName);
            mEntity e = ECUtils.DeepCopyEntity(entity);//entity.copy();
            entities.Add(e);
        }

        actions.Clear();
        //  Debug.Log("Populating actions");
        ActionListComponent actionlist = profile.components.First(item => item is ActionListComponent) as ActionListComponent;

        foreach (MAction action in actionlist.list)
        {
            // Debug.Log("Now adding action " + action.GetType());
            Type type = action.GetType();
            var  act  = ECUtils.DeepCopyAction(action);
            act.owner = this;
            act.init();
            //  act.initReferences();
            act.initCached(act.owner);
            // act = Convert.ChangeType(act, type);
            actions.Add(act);

            // Debug.Log("Action list now contains: " + actions.getAction(act));
        }



        goals.Clear();
        // Debug.Log("Populating goals");
        foreach (MGoal goal in gls)
        {
            //    Debug.Log("Now adding goal " + goal.GetType());
            var g = ECUtils.DeepCopyGoal(goal);
            g.owner = this;
            g.init();
            goals.Add(g);
        }

        norms.Clear();
        //  Debug.Log("Populating norms");
        foreach (MNorm norm in nrms)
        {
            var n = ECUtils.DeepCopyNorm(norm);
            n.owner = this;
            n.init(this);
            norms.Add(n);
        }

        initReasoner(reasonerTemplate);
    }