コード例 #1
0
ファイル: Business.cs プロジェクト: joshf67/Dissertation
    void SortApplicationsBasedOnStats(Job job)
    {
        //arrange based on total stats
        bool more = false;

        do
        {
            more = false;
            //loop through all applications
            for (int a = 0; a < job.applications.Count - 1; a++)
            {
                //store stats
                Stats currentStats = job.applications [a].stats;
                Stats nextStats    = job.applications [a + 1].stats;

                //calculate total score
                float currentStatsTotal = currentStats.dexterity + currentStats.intelligence + currentStats.strength;
                float nextStatsTotal    = nextStats.dexterity + nextStats.intelligence + nextStats.strength;

                //test scores
                if (currentStatsTotal < nextStatsTotal)
                {
                    HumanLife temp = job.applications [a + 1];
                    job.applications [a + 1] = job.applications [a];
                    job.applications [a]     = temp;
                    more = true;
                }
            }
        } while (more);
    }
コード例 #2
0
 public PurchaseOptions(int _index = 0, bool _delivery = false, bool _online = false, HumanLife _buyer = null)
 {
     index    = _index;
     online   = _online;
     delivery = _delivery;
     buyer    = _buyer;
 }
コード例 #3
0
 //function to add worker to list
 public virtual void AddWorker(HumanLife worker)
 {
     //setup worker data
     workers.Add(ScriptableObject.CreateInstance <JobData>());
     worker.stats.jobData = workers [workers.Count - 1];
     workers [workers.Count - 1].worker = worker;
 }
コード例 #4
0
    //function that handles what happens when workers work
    public override bool Work(HumanLife student)
    {
        //increase each statGrowth by delta time and levelup if above 100
        student.stats.intellegenceGrowth += Time.deltaTime * time.timeMult;
        if (student.stats.intellegenceGrowth > 100)
        {
            student.stats.intellegenceGrowth = 0;
            student.stats.intelligence++;
        }

        student.stats.strengthGrowth += Time.deltaTime * time.timeMult;
        if (student.stats.strengthGrowth > 100)
        {
            student.stats.strengthGrowth = 0;
            student.stats.strength++;
        }

        student.stats.dexterityGrowth += Time.deltaTime * time.timeMult;
        if (student.stats.dexterityGrowth > 100)
        {
            student.stats.dexterityGrowth = 0;
            student.stats.dexterity++;
        }

        return(true);
    }
コード例 #5
0
 //function to add worker to list
 public override void AddWorker(HumanLife worker)
 {
     //setup delivery data for worker
     workers.Add(ScriptableObject.CreateInstance <DeliveryDetails>());
     worker.stats.jobData = workers [workers.Count - 1];
     workers [workers.Count - 1].worker = worker;
 }
コード例 #6
0
 protected override bool Compare(Product one, HumanLife person)
 {
     switch (one.type)
     {
     case itemTypes.houses:
         return(((HousingProduct)one).data.rooms.Count >= person.stats.accomodation.requiredRooms);
     }
     return(false);
 }
コード例 #7
0
    public void Reproduce(HumanLife mate1, HumanLife mate2)
    {
        //create new child
        GameObject temp  = GameObject.Instantiate(baseObject, mate1.transform.position, mate1.transform.rotation);
        HumanLife  child = temp.GetComponent <HumanLife> ();

        //reset desire to have kids
        mate1.stats.wantKids = false;
        mate2.stats.wantKids = false;

        //setup accomodation data
        mate1.stats.accomodation.occupants.Add(child);
        mate2.stats.accomodation.occupants.Add(child);
        child.stats.accomodation.occupants.Add(child);
        child.stats.accomodation.occupants.Add(mate1);
        child.stats.accomodation.occupants.Add(mate2);
        child.stats.accomodation.requiredRooms = mate1.stats.accomodation.requiredRooms;

        //setup relationship data
        mate1.stats.relationship.Add(new Relation(child, 2));
        mate2.stats.relationship.Add(new Relation(child, 2));
        child.stats.relationship.Add(new Relation(mate1, 1));
        child.stats.relationship.Add(new Relation(mate2, 1));

        //calculate intellegence
        if (Random.Range(0, 100) <= chanceOfMutation)
        {
            child.stats.intelligence = Random.Range(0, (mate1.stats.intelligence + mate2.stats.intelligence) / 2);
        }
        else
        {
            child.stats.intelligence = (mate1.stats.intelligence + mate2.stats.intelligence) / 2;
        }

        //calculate strength
        if (Random.Range(0, 100) <= chanceOfMutation)
        {
            child.stats.strength = Random.Range(0, (mate1.stats.strength + mate2.stats.strength) / 2);
        }
        else
        {
            child.stats.strength = (mate1.stats.strength + mate2.stats.strength) / 2;
        }

        //calculate dexterity
        if (Random.Range(0, 100) <= chanceOfMutation)
        {
            child.stats.dexterity = Random.Range(0, (mate1.stats.dexterity + mate2.stats.dexterity) / 2);
        }
        else
        {
            child.stats.dexterity = (mate1.stats.dexterity + mate2.stats.dexterity) / 2;
        }
    }
コード例 #8
0
 //function to remove applicant from list
 public void RemoveApplication(HumanLife person)
 {
     //loop until applicant is found then remove it
     for (int a = 0; a < applications.Count; a++)
     {
         if (applications [a] == person)
         {
             applications.RemoveAt(a);
             return;
         }
     }
 }
コード例 #9
0
    //function to check if products effects are below persons needs
    protected override bool Compare(Product one, HumanLife person)
    {
        switch (((ItemProduct)one).data.itemType)
        {
        case itemTypes.food:
            return(((ItemProduct)one).data.effect < (person.maxFood - person.food));

        case itemTypes.energy:
            return(((ItemProduct)one).data.effect < (person.maxEnergy - person.energy));

        case itemTypes.happiness:
            return(((ItemProduct)one).data.effect < (person.maxHappiness - person.happiness));
        }
        return(false);
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        //test if left click is being activated
        if (Input.GetMouseButton(0))
        {
            //raycast from mouse pointer to world space
            RaycastHit hit;
            if (Physics.Raycast(GetComponent <Camera> ().ScreenPointToRay(Input.mousePosition), out hit))
            {
                //reset variables
                currentActor = null;
                bus          = null;
                housing      = null;

                //grab any connected script
                bus          = hit.collider.GetComponent <Business> ();
                housing      = hit.collider.GetComponent <Housing> ();
                currentActor = hit.collider.GetComponent <HumanLife> ();

                //if house exists ignore business script
                if (housing != null)
                {
                    bus = null;
                }

                //check if object has a script
                if (bus != null || housing != null || currentActor != null)
                {
                    //check if object has changed
                    if (bus != lastBusiness || housing != lastHousing || currentActor != lastActor)
                    {
                        offset      = 0;
                        offset2     = 0;
                        currentJob  = null;
                        currentHome = null;
                    }
                }
            }

            //update last selected object
            lastBusiness = bus;
            lastHousing  = housing;
            lastActor    = currentActor;
        }
    }
コード例 #11
0
    //test if the person can afford the product
    protected override bool CompareCost(Product one, HumanLife person)
    {
        float allCash      = 0;
        float allCashMonth = 0;

        //add up all buyers income per month
        for (int a = 0; a < person.stats.accomodation.occupants.Count; a++)
        {
            allCashMonth += person.stats.accomodation.occupants [a].incomePerMonth;
            allCash      += person.stats.accomodation.occupants [a].cash;
        }

        //half the potential cost so the buyers can afford other items
        allCashMonth /= 2;
        allCash      /= 2;

        return(one.cost <= allCashMonth && ((HousingProduct)one).data.initialCost <= allCash);
    }
コード例 #12
0
ファイル: Functions.cs プロジェクト: joshf67/Dissertation
 //function to check distance to a business
 public static bool checkDistanceBusiness(HumanLife actor, NavMeshAgent agent, Business business, Vector3 destination, float distance)
 {
     //check if distance to destination is larger than distance
     if (Vector3.Distance(agent.transform.position, destination) > distance)
     {
         //check if the business is not online or the actor doesn't have internet
         if (!(business.online && actor.accessToInternet))
         {
             //enable the navmesh agent
             agent.enabled = true;
             //sets the navmesh agent's destination
             agent.SetDestination(destination);
             return(false);
         }
     }
     //if actor is within range disable navmesh agent
     agent.enabled = false;
     return(true);
 }
コード例 #13
0
 //function to remove worker from list
 public void RemoveWorker(HumanLife worker, bool addToRequiredWorkers)
 {
     //loop until worker is found then remove it
     for (int a = 0; a < workers.Count; a++)
     {
         if (workers [a].worker == worker)
         {
             workers [a].worker.stats.job     = null;
             workers [a].worker.stats.jobData = null;
             workers.RemoveAt(a);
             break;
         }
     }
     //add to required workers if needed
     if (addToRequiredWorkers)
     {
         requiredWorkers++;
         jobSearchTime = jobSearchResetTime;
     }
 }
コード例 #14
0
 //virtual function for workers to work
 public virtual bool Work(HumanLife worker)
 {
     return(true);
 }
コード例 #15
0
 public ShopTest(itemTypes type = 0, string name = "", HumanLife life = null)
 {
     productType = type;
     productName = name;
     person      = life;
 }
コード例 #16
0
 public Relation(HumanLife _other, int type)
 {
     other        = _other;
     relationType = type;
 }
コード例 #17
0
 public DeliveryDetails(HumanLife actor) : base(actor)
 {
 }
コード例 #18
0
    //function that handles what happens when workers work
    public override bool Work(HumanLife worker)
    {
        //cast workers stats to delivery info
        DeliveryDetails workerStats = (DeliveryDetails)worker.stats.jobData;

        //check if worker has a current delivery
        if (workerStats.deliveryToBeMade)
        {
            //check if worker has delivery items
            if (workerStats.deliveryItems.Count != 0)
            {
                //check if worker is able to move
                if (workerStats.startDeliveryTime <= 0)
                {
                    //check if recipient still exists
                    if (workerStats.recipient)
                    {
                        //travel to recipent
                        if (Functions.checkDistance(worker.agent, workerStats.destination, worker.minDist))
                        {
                            //add all delivery items to recipient
                            foreach (Item item in workerStats.deliveryItems)
                            {
                                workerStats.recipient.inventory.Add(item);
                            }

                            //reset delivery details
                            workerStats.deliveryItems.Clear();
                            workerStats.recipient.waitingForDelivery--;
                            workerStats.recipient = null;
                        }
                    }
                    else
                    {
                        //clear current delivery data
                        workerStats.deliveryItems.Clear();
                        workerStats.recipient = null;
                    }
                }
                else
                {
                    workerStats.startDeliveryTime -= Time.deltaTime;
                }
            }
            else
            {
                //travel to business location
                if (Functions.checkDistance(worker.agent, worker.stats.company.buildingPosition.transform.position, worker.minDist))
                {
                    //reset delivery data when worker back at work
                    workerStats.deliveryToBeMade = false;
                    workerStats.ignoreDistance   = false;
                }
            }
        }
        else
        {
            //check if delivery jobs are available
            if (deliveryJobs.Count > 0)
            {
                //check if first delivery job has a recipient
                if (deliveryJobs [0].recipient)
                {
                    //setup delivery information
                    workerStats.deliveryItems     = deliveryJobs [0].items;
                    workerStats.recipient         = deliveryJobs [0].recipient;
                    workerStats.destination       = deliveryJobs [0].recipient.transform.position;
                    workerStats.deliveryToBeMade  = true;
                    workerStats.ignoreDistance    = true;
                    workerStats.startDeliveryTime = 0;
                }
                deliveryJobs.RemoveAt(0);
            }
        }
        return(true);
    }
コード例 #19
0
ファイル: Business.cs プロジェクト: joshf67/Dissertation
 public virtual bool CompareProduct(Product one, HumanLife person)
 {
     return(Compare(one, person));
 }
コード例 #20
0
ファイル: Services.cs プロジェクト: joshf67/Dissertation
 //function that handles what happens when workers work
 public override bool Work(HumanLife worker)
 {
     //add value above to business cash
     GetComponent <Business>().cash += 1 * Time.deltaTime;
     return(true);
 }
コード例 #21
0
ファイル: Business.cs プロジェクト: joshf67/Dissertation
 protected abstract bool Compare(Product one, HumanLife person);
コード例 #22
0
 protected override bool CompareCost(Product one, HumanLife person)
 {
     return(false);
 }
コード例 #23
0
 //test if the person can afford the product
 protected override bool CompareCost(Product one, HumanLife person)
 {
     return(((ItemProduct)one).cost <= person.cash);
 }
コード例 #24
0
 public JobData(HumanLife actor)
 {
     worker = actor;
 }