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); }
public PurchaseOptions(int _index = 0, bool _delivery = false, bool _online = false, HumanLife _buyer = null) { index = _index; online = _online; delivery = _delivery; buyer = _buyer; }
//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; }
//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); }
//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; }
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); }
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; } }
//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; } } }
//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); }
// 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; } }
//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); }
//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); }
//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; } }
//virtual function for workers to work public virtual bool Work(HumanLife worker) { return(true); }
public ShopTest(itemTypes type = 0, string name = "", HumanLife life = null) { productType = type; productName = name; person = life; }
public Relation(HumanLife _other, int type) { other = _other; relationType = type; }
public DeliveryDetails(HumanLife actor) : base(actor) { }
//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); }
public virtual bool CompareProduct(Product one, HumanLife person) { return(Compare(one, person)); }
//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); }
protected abstract bool Compare(Product one, HumanLife person);
protected override bool CompareCost(Product one, HumanLife person) { return(false); }
//test if the person can afford the product protected override bool CompareCost(Product one, HumanLife person) { return(((ItemProduct)one).cost <= person.cash); }
public JobData(HumanLife actor) { worker = actor; }