コード例 #1
0
ファイル: Person.cs プロジェクト: connellyj/HousingCrisis
    // Sets the next action based on the person's state
    private bool SetAction()
    {
        int personLoc = PersonLocFromPosition();

        switch (state)
        {
        case PersonState.TARGET_SET:
            goto case PersonState.WANDER_SET;

        // Finds a path to the goal
        case PersonState.WANDER_SET:
            path = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            return(true);

        // Finds a path to a random goal if there are houses and available space, otherwise changes to wander
        case PersonState.TARGET_RANDOM:
            if (HouseManager.houses.Count == 0 || !HouseManager.AnyStallSpaceAnywhere())
            {
                state = PersonState.WANDER;
                goto default;
            }
            else
            {
                goalIndex = HouseManager.GetRandomHouse();
                path      = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            }
            return(true);

        // Finds a path to a random not burning house if there are houses that aren't burning, otherwise changes to wander
        case PersonState.TARGET_RANDOM_NOTBURNING:
            if (HouseManager.houses.Count == 0 || !HouseManager.AnyHousesNotBurning())
            {
                state = PersonState.WANDER;
                goto default;
            }
            else
            {
                goalIndex = HouseManager.GetRandomNotBurningHouse();
                path      = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            }
            return(true);

        // Stalls
        case PersonState.STALL:
            StopAllCoroutines();
            StartCoroutine(Stall());
            return(false);

        // Attacks
        case PersonState.ATTACK:
            StopAllCoroutines();
            Attack();
            return(false);

        // Finds a path to an exit
        default:
            path = Pathfinder.FindPath(state, personLoc);
            return(true);
        }
    }
コード例 #2
0
    private IEnumerator SpawnPeople()
    {
        while (true)
        {
            yield return(new WaitForSeconds(1));

            if (spawnChance > Random.value)
            {
                float rand = Random.value;
                if (rand < robberChance)
                {
                    if (HouseManager.houses.Count > 0 && HouseManager.AnyHousesNotBurning())
                    {
                        Instantiate(robberPrefab, transform.position + Person.positionOffset, Quaternion.identity);
                        continue;
                    }
                }
                else if (rand < policeChance + robberChance)
                {
                    if (HouseManager.houses.Count > 0)
                    {
                        Instantiate(policePrefab, transform.position + Person.positionOffset, Quaternion.identity);
                        continue;
                    }
                }
                else if (rand < soldierChance + policeChance + robberChance)
                {
                    if (HouseManager.houses.Count > 0)
                    {
                        Instantiate(soldierPrefab, transform.position + Person.positionOffset, Quaternion.identity);
                        continue;
                    }
                }
                else if (rand < bankerChance + soldierChance + policeChance + robberChance)
                {
                    Instantiate(bankerPrefab, transform.position + Person.positionOffset, Quaternion.identity);
                    continue;
                }
                SpawnPedestrian();
            }
        }
    }