Exemple #1
0
    /// <summary>
    /// Generates all empty NPCs, defining only their name, and thier homes
    /// </summary>
    /// <param name="set"></param>
    private List <NPC> GenerateNPCShells(Settlement set)
    {
        if (set.Buildings == null)
        {
            return(null);
        }
        List <NPC> settlementNPCs = new List <NPC>(250);

        List <NPC> inThisHouse = new List <NPC>(10);

        //iterate all building, and check if this is a house
        foreach (Building b in set.Buildings)
        {
            if (b is House)
            {
                inThisHouse.Clear();
                //Define the house and get the possible tiles we can spawn the this houses' NPCs on
                House        h = b as House;
                List <Vec2i> spawnableTiles = h.GetSpawnableTiles();

                for (int i = 0; i < h.capacity; i++)
                {
                    //Attempt to find a valid spawn point
                    Vec2i entitySpawn = MiscUtils.RandomFromArray(spawnableTiles, Random.value);
                    if (entitySpawn == null)
                    {
                        Debug.Log("No valid spawn point found for house " + h.ToString(), Debug.ENTITY_GENERATION);
                        continue;
                    }
                    //Create the empty NPC and add it to the settlement
                    NPC npc = new NPC(isFixed: true);
                    npc.SetPosition(entitySpawn);
                    npc.NPCData.SetHome(h);
                    //First two entities should be male and female (husband and wife)
                    //All others are then randomly assigned
                    if (i == 0)
                    {
                        npc.NPCData.SetGender(NPCGender.male);
                    }
                    else if (i == 1)
                    {
                        npc.NPCData.SetGender(NPCGender.female);
                    }
                    else
                    {
                        npc.NPCData.SetGender((NPCGender)GenerationRan.RandomInt(0, 2));
                    }

                    EntityManager.AddFixedEntity(npc);
                    npc.SetName("NPC " + npc.ID);
                    set.AddNPC(npc);
                    settlementNPCs.Add(npc);
                    inThisHouse.Add(npc);
                }
                //If more than 1 person lives in this house, they are family
                if (inThisHouse.Count > 1)
                {
                    //Iterate all pairs of family members in this house
                    for (int i = 0; i < inThisHouse.Count; i++)
                    {
                        for (int j = 0; j < inThisHouse.Count; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }
                            inThisHouse[i].EntityRelationshipManager.SetRelationshipTag(inThisHouse[j], EntityRelationshipTag.Family);
                            inThisHouse[j].EntityRelationshipManager.SetRelationshipTag(inThisHouse[i], EntityRelationshipTag.Family);
                        }
                    }
                }
            }
        }
        return(settlementNPCs);
    }