Exemple #1
0
    void HireProspect(Prole prospect)
    {
        if (immigration.Requests.Count == 0)
        {
            return;                 //if there's no house looking for a resident, don't keep looking
        }
        //get start node, an adjacent road tile
        Node start = new Node(this);

        //get closest requester from immigration controller
        //	we know we'll get at least one result bc we already checked that there's more than zero houses in line
        SimplePriorityQueue <Structure> houses = immigration.FindClosestHouses(start);

        if (houses.Count == 0)
        {
            return;
        }
        Structure requester = houses.Dequeue();

        prospect.waitCountdown = 0;

        //send immigrant from here to that house
        immigration.SpawnImmigrant(start, requester, prospect);
        immigration.Requests.Remove(requester);         //don't forget to remove requester from list

        //remove prospect from array
        RemoveProspectFromArray(prospect);

        return;
    }
Exemple #2
0
    public void NextImmigrant()
    {
        //only proceed if there's a map entrance
        Structure mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance").GetComponent <Structure>();

        if (mapEntrance == null)
        {
            Debug.LogError("Missing map entrance");
        }

        //we're going to pass this data into SpawnImmigrant(,,)
        //	also, it may be later that we'll KNOW what immigrant is moving it, so it's good to have it separate and not call GetRandomImmigrant() as an argument itself
        Structure requester = GetRandomRequester();
        Prole     immigrant = GetRandomImmigrant();

        //if requester still exists, send an immigrant to it from the map entrance
        if (requester != null)
        {
            SpawnImmigrant(requester, immigrant);
            immigrantsWaiting--;
        }

        //whether null or not, remove from list so it's not there anymore
        Requests.Remove(requester);
    }
Exemple #3
0
    public override void DoEveryDay()
    {
        base.DoEveryDay();

        if (!ActiveSmartWalker && !immigration.Contains(this) && Residents.Count < residentsMax && DiseasedResidents == 0)
        {
            RequestImmigrant();
        }

        //proles who move out receive a fraction of the house's total savings to take with them
        if (Residents.Count > residentsMax)
        {
            Prole mover = Residents[Residents.Count - 1];

            mover.personalSavings += Savings / Residents.Count;
            Savings -= mover.personalSavings;

            immigration.TryEmigrant(mover);
            population.RemoveProle(mover);
        }

        if (CanEvolve())
        {
            ChangeHouse(evolvesTo);
        }

        CheckBiggerSize();
        UpdateResidentsAge();
        cholera.SetActive(DiseasedResidents > 0);
    }
Exemple #4
0
    void GetAnotherProspect()
    {
        if (!Active)
        {
            return;
        }

        //if there's any space for prospects left and if there's any empty houses
        if (Prospects.Count + ProspectsExpecting < maxProspects /* && immigration.Requests.Count > 0 */)
        {
            Prole prospect = immigration.GetRandomImmigrant();

            LaborType prospectPref = prospect.HighestValue();
            if (prospectPref == LaborType.Physical && !HireHighPhy)
            {
                return;
            }
            if (prospectPref == LaborType.Intellectual && !HireHighInt)
            {
                return;
            }
            if (prospectPref == LaborType.Emotional && !HireHighEmo)
            {
                return;
            }

            //get immigrant to this building from outside
            immigration.SpawnImmigrant(this, prospect);

            //add prospect to queue
            ProspectsExpecting++;
        }
    }
Exemple #5
0
    public void SpawnImmigrant(Node start, Structure requester, Prole immigrant)
    {
        //by the way: it's way easier to deal with the starting point as a node than a structure, especially because we don't need to know where the immigrant came from
        //	no matter how weird that we instantiate 'end' here but not 'start'

        Queue <Node> path = new Pathfinder(worldController.Map).FindPath(start, new Node(requester), "Immigrant");

        if (path.Count == 0)
        {
            return;
        }

        GameObject go = worldController.SpawnObject("Walkers", "Immigrant", start);

        Walker w = go.GetComponent <Walker>();

        w.world       = worldController;
        w.Destination = requester;
        w.SetPath(path);
        w.SetPersonData(immigrant);               //data for immigrant moving into house
        w.Activate();

        immigrant.EvictHouse(false);          //quit current house if they have one, but don't quit work because they're still here
        if (immigrant.Employed)
        {
            immigrant.QuitWork();
        }
    }
Exemple #6
0
 public Child(bool randomAge, Prole parent) : base(randomAge)
 {
     //if parent already has children, we want to be younger than the most recent child; otherwise we can be anywhere from 0 to 15 years old
     yearsOld  = randomAge ? Random.Range(0, (parent.children.Count > 0 ? parent.children[parent.children.Count - 1].yearsOld : comingOfAge)) : 0;
     surname   = parent.surname;
     skinColor = parent.skinColor;
     ID        = surname + name + Random.Range(0, 100);
 }
Exemple #7
0
    void SendAwayProspect(Prole prospect)
    {
        //send emigrant from here
        immigration.SpawnEmigrant(new Node(this), prospect);

        //remove prospect from array
        RemoveProspectFromArray(prospect);
    }
Exemple #8
0
    void UpdateResidentsAge()
    {
        //iterate backwards to not have any problems with removing residents or children
        for (int i = Residents.Count - 1; i >= 0; i--)
        {
            Prole p        = Residents[i];
            bool  diseased = p.diseased;
            p.UpdateAge();
            if (!p.diseased && diseased)
            {
                RemoveDiseasedResident();                   //if resident was diseased and is no longer bc time ran out, remove one from the diseased count
            }
            //the reason we age children here and not in Prole.UpdateAge() is so we can detect death and coming of age
            for (int j = p.children.Count - 1; j >= 0; j--)
            {
                Child c         = p.children[j];
                bool  diseasedC = c.diseased;
                c.UpdateAge();
                if (!c.diseased && diseasedC)
                {
                    RemoveDiseasedResident();                       //if the child was diseased and is no longer bc time ran out, remove one from the diseased count
                }
                //do if c is dead
                if (c.markedForDeath)
                {
                    //if c was diseased upon death, remove one from diseased count
                    if (c.diseased)
                    {
                        RemoveDiseasedResident();
                    }
                    p.children.Remove(c);
                    c.Kill();
                    Corpses++;
                }

                //do if c is grown up
                else if (c.GrownUp)
                {
                    ReceiveImmigrant(p.GrowUpChild(c));
                    p.children.Remove(c);
                }
            }

            //do if p is about to die
            if (p.markedForDeath)
            {
                //if c was diseased upon death, remove one from diseased count
                if (p.diseased)
                {
                    RemoveDiseasedResident();
                }

                p.Kill();
                population.RemoveProle(p);
                Corpses++;
            }
        }
    }
Exemple #9
0
    public void SpawnImmigrant(Structure requester, Prole immigrant)
    {
        //only proceed if there's a map entrance
        Structure mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance").GetComponent <Structure>();

        if (mapEntrance == null)
        {
            Debug.LogError("Missing map entrance");
        }

        SpawnImmigrant(new Node(mapEntrance), requester, immigrant);
    }
Exemple #10
0
    public override void ReceiveImmigrant(Prole prospect)
    {
        prospect.StartWaitCountdown();
        Prospects.Add(prospect);
        ProspectsExpecting--;

        //if we traverse the whole array without there being an empty space
        if (Prospects.Count > maxProspects)
        {
            Debug.LogError(name + " received an immigrant when it didn't need one");
        }
    }
Exemple #11
0
    public bool RemoveWorker(Prole p)
    {
        if (!WorkerList.Contains(p))
        {
            Debug.LogError("Removing " + p + " who doesn't work at " + this);
        }

        WorkerList.Remove(p);
        CalculateWorkerEffectiveness();

        return(true);
    }
Exemple #12
0
 public override void ReceiveImmigrant(Prole p)
 {
     p.MoveIntoHouse(this);
     Residents.Add(p);
     //Debug.Log(p + " moved into " + this);
     if (Residents.Count > residentsMax)
     {
         Debug.Log("Not enough room in " + name + " for " + p);
     }
     Savings          += p.personalSavings;
     p.personalSavings = 0;
     population.AddProle(p);             //add to prole list of town
 }
Exemple #13
0
    public void FreshHouse(Prole firstResident)
    {
        Thirst           = 0;
        Hunger           = 0;
        WaterQualCurrent = Quality.None;
        FoodQualCurrent  = Quality.None;
        Goods            = new int[(int)GoodType.END];
        VenueAccess      = new Dictionary <string, int>();
        Residents        = new List <Prole>();

        //CREATE NEW RESIDENT HAPPENS RIGHT HERE
        ReceiveImmigrant(firstResident);
    }
Exemple #14
0
    void TurnIntoHouse(Prole immigrant)
    {
        //demolish this and build new house
        float rot = transform.position.y;

        world.Demolish(X, Y);
        Structure str = world.SpawnStructure(immigration.startingHouse, X, Y, rot);

        Debug.Log(str);

        House newHouse = str.GetComponent <House>();

        newHouse.FreshHouse(immigrant);
    }
Exemple #15
0
    public Prole GrowUpChild(Child c)
    {
        if (!children.Contains(c))
        {
            Debug.LogError(this + " trying to grow up child " + c + " which is not its own");
        }

        //SOMEWHERE HERE DETERMINE RANDOM LABOR PREF FOR

        children.Remove(c);

        Prole grownup = new Prole(c, LaborType.Physical);

        return(grownup);
    }
Exemple #16
0
    public void CreateWorkerListElement(Prole p, Workplace wp)
    {
        if (p == null)
        {
            return;
        }

        GameObject go = Instantiate(UIObjectDatabase.GetUIElement("ProleInfo"));

        go.transform.SetParent(proleGrid);

        ProleInfo pi = go.GetComponent <ProleInfo>();

        pi.Employee = p;
        pi.WP       = wp;
    }
Exemple #17
0
    public override void Load(ObjSave o)
    {
        base.Load(o);

        WalkerSave w = (WalkerSave)o;

        //retrieve origin and destination structures
        if (w.origin != null)
        {
            Origin = GameObject.Find(world.Map.GetBuildingNameAt(w.origin)).GetComponent <Structure>();
        }
        if (w.destination != null)
        {
            Destination = GameObject.Find(world.Map.GetBuildingNameAt(w.destination)).GetComponent <Structure>();
        }

        Stuck           = w.stuck;
        SpawnedFollower = w.SpawnedFollower;
        GoingOnRamp     = w.GoingOnRamp;

        Prevx       = w.prevx;
        Prevy       = w.prevy;
        LaborPoints = w.laborPoints;
        lifeTime    = w.lifeTime;
        yield       = w.yield;

        MovementDistance = w.movementDistance;

        Path         = w.path;
        VisitedSpots = w.visitedSpots;
        Direction    = w.direction;
        Order        = w.order;

        data       = w.data;
        PersonData = w.PersonData;

        Skin = PersonData != null?PersonData.skinColor.GetColor() : GetSkinColor();

        if (meshRenderer != null)
        {
            meshRenderer.material.color = Skin;
        }

        LoadFollower(w.follower);

        world.EnterSquare(this, X, Y);
    }
Exemple #18
0
    public WalkerSave(GameObject go) : base(go)
    {
        Walker w = go.GetComponent <Walker>();

        //save origin and destination as coordinates
        Structure o = w.Origin;

        if (o != null)
        {
            origin = new Node(o.X, o.Y);
        }
        Structure d = w.Destination;

        if (d != null)
        {
            destination = new Node(d.X, d.Y);
        }

        prevx       = w.Prevx;
        prevy       = w.Prevy;
        laborPoints = w.LaborPoints;
        lifeTime    = w.lifeTime;
        yield       = w.yield;

        movementDistance = w.MovementDistance;

        stuck           = w.Stuck;
        SpawnedFollower = w.SpawnedFollower;
        GoingOnRamp     = w.GoingOnRamp;

        direction = w.Direction;
        order     = w.Order;

        path         = w.Path;
        visitedSpots = w.VisitedSpots;
        skin         = new Float3d(w.Skin);

        data       = w.data;
        PersonData = w.PersonData;


        if (w.Follower != null)
        {
            follower = new WalkerSave(w.Follower.gameObject);
        }
    }
Exemple #19
0
    public void TryEmigrant(Prole emigrant)
    {
        //if there are other houses to move into, go to the closest one
        if (Requests.Count > 0)
        {
            SimplePriorityQueue <Structure> houses = FindClosestHouses(emigrant.homeNode);
            if (houses.Count == 0)
            {
                return;
            }
            Structure str = houses.Dequeue();
            SpawnImmigrant(emigrant.homeNode, str, emigrant);
            Requests.Remove(str);
            return;
        }

        //otherwise leave the map
        SpawnEmigrant(emigrant);
    }
Exemple #20
0
    void SendOutProspects()
    {
        //iterate backwards to avoid problems from removing prospects
        for (int i = Prospects.Count - 1; i >= 0; i--)
        {
            Prole prospect = Prospects[i];

            if (prospect.rejected)              //send prospect out of it is rejected or now too old to work or has waited for too long (regardless of hire status)
            {
                SendAwayProspect(prospect);
            }
            else if (prospect.accepted)
            {
                HireProspect(prospect);
            }

            prospect.UpdateAge();               //here we can have the prospect age and also countdown to leaving if they waited for too long
        }
    }
Exemple #21
0
    public bool AddWorker(Prole p)
    {
        if (WorkerList.Count >= workersMax)
        {
            return(false);
        }

        population.EmployProle(p);
        WorkerList.Add(p);
        p.JoinWork(this);

        CalculateWorkerEffectiveness();

        //update UI if possible
        Action <Prole, Workplace> act = ProleEmploymentAction;

        if (act != null)
        {
            act.Invoke(p, this);
        }

        return(true);
    }
Exemple #22
0
    public void SpawnEmigrant(Node start, Prole emigrant)
    {
        GameObject mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance");

        if (mapEntrance == null)
        {
            return;
        }

        Node end = new Node(mapEntrance.GetComponent <Structure>());

        Queue <Node> path = new Pathfinder(worldController.Map).FindPath(start, end, "Emigrant");

        if (path.Count == 0)
        {
            return;
        }

        GameObject go = worldController.SpawnObject("Walkers", "Emigrant", start);
        //GameObject go = Instantiate(Resources.Load<GameObject>("Walkers/Emigrant"));
        //go.transform.position = mapExit.transform.position;
        //go.name = "Emigrant";

        Walker w = go.GetComponent <Walker>();

        w.world       = worldController;
        w.Destination = mapEntrance.GetComponent <Structure>();
        w.SetPersonData(emigrant);
        w.SetPath(path);
        w.Activate();

        //evict house at the very end to remove homeNode and remove prole data from house
        //quit job too because they're leaving the city
        emigrant.EvictHouse(false);
        emigrant.QuitWork();
        //RemoveResidents(ExcessResidents);
    }
 public void RemoveProle(Prole p)
 {
     Proles.Remove(p);
 }
Exemple #24
0
 public void SpawnEmigrant(Prole emigrant)
 {
     SpawnEmigrant(emigrant.homeNode, emigrant);
 }
Exemple #25
0
    public Prole GetRandomImmigrant()
    {
        Prole prospect = new Prole(true, true, GetRandomLaborPref());

        return(prospect);
    }
Exemple #26
0
    public override bool Equals(object obj)
    {
        Prole pr = (Prole)obj;

        return(ID == pr.ID);
    }
Exemple #27
0
 public override void ReceiveImmigrant(Prole p)
 {
     TurnIntoHouse(p);
 }
 public void UnemployProle(Prole p)
 {
     Working--;
 }
Exemple #29
0
 public virtual void ReceiveImmigrant(Prole p)
 {
     Debug.LogError(name + " received prole " + p + " and can't do anything with it");
 }
 public void EmployProle(Prole p)
 {
     Working++;
 }