Ejemplo n.º 1
0
    public void MagicallyTransport(VillageCtrl destination)
    {
        Vector3 pos       = destination.gameObject.transform.position;
        Vector3 destScale = destination.gameObject.transform.localScale;

        pos.x += Random.Range(-destScale.x / 4f, destScale.x / 4f);
        pos.z += Random.Range(-destScale.z / 4f, destScale.z / 4f);
        pos.y  = 1f;
        gameObject.transform.position = pos;
    }
Ejemplo n.º 2
0
 public void StartPings(VillageCtrl sourceVillage)
 {
     foreach (VillageCtrl neighbor in sourceVillage.neighbors)
     {
         GameObject pingClone = Instantiate(PingPrefab);
         PingCtrl   ctrl      = pingClone.GetComponent <PingCtrl>();
         ctrl.ptA = sourceVillage.gameObject.transform.position;
         ctrl.ptB = neighbor.gameObject.transform.position;
         pingClone.transform.position = ctrl.ptA;
         pings.Add(ctrl);
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// We're just checking to make sure that a given village doesn't
    /// sit right on top of another one.
    /// </summary>
    public bool NoOverlaps(VillageCtrl village)
    {
        List <VillageCtrl> neighbors = worldMap.GetNeighbors(village.GetPosition());

        foreach (VillageCtrl neighbor in neighbors)
        {
            if (village.GetRect().Overlaps(neighbor.GetRect()))
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Place the camera so that you can clearly see one of the villages and
    /// not some random empty spot with no sense of scale or position.
    /// </summary>
    protected void PlaceCamera()
    {
        if (worldMap.villageList.Count == 0)
        {
            Invoke("PlaceCamera", 10f);
            return;
        }
        VillageCtrl rndVillage = worldMap.villageList[Random.Range(0, worldMap.villageList.Count)];
        Vector3     pos        = rndVillage.gameObject.transform.position;

        pos.y  = 250;
        pos.z -= 100f;
        Camera.main.transform.position = pos;
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Calculates the difference in two dialects. Also, seattle and portland
    /// just seemed like they'd be better names than villageA and villageB.
    /// </summary>
    public float CalcDiff(VillageCtrl seattle, VillageCtrl portland)
    {
        float diffSq = 0f;

        foreach (Phoneme phone in phonemeOrder)
        {
            float s = seattle.AvgPronunciation(phone) * 100f;
            float p = portland.AvgPronunciation(phone) * 100f;
            s = Mathf.Round(s);
            p = Mathf.Round(p);
            float diff = s - p;
            diffSq += (diff * diff) / 100f;
        }
        return(Mathf.Sqrt(diffSq));
    }
Ejemplo n.º 6
0
    public void DisplayVillageLanguage(VillageCtrl villageCtrl)
    {
        AgentCtrl agent = villageCtrl.agents[0];
        string    s     = "";
        bool      odd   = true;

        foreach (Phoneme phone in agent.idiolect.Keys)
        {
            float f = villageCtrl.AvgPronunciation(phone);

            s += string.Format("{0} : {1:0.00}\t\t", phone.glyph, f);

            odd = !odd;
            if (odd)
            {
                s += "\n";
            }
        }

        langTxt.text = s;
    }
Ejemplo n.º 7
0
    protected VillageCtrl MakeVillage()
    {
        VillageCtrl clone = Instantiate(villagePrefab).GetComponent <VillageCtrl>();

        clone.population = avgPopulation + Random.Range(-popRange, popRange);
        clone.gameObject.transform.localScale = new Vector3(villageWidth, 1f, villageWidth);

        for (int i = 0; i < MAX_PLACEMENT_TRIES; i++)
        {
            clone.worldPos = RndCoord();
            if (NoOverlaps(clone))
            {
                break;
            }
        }

        // Book-keeping.
        clone.villageNumber = worldMap.villageList.Count;
        worldMap.villageList.Add(clone);

        return(clone);
    }
Ejemplo n.º 8
0
    void Update()
    {
        // If our mouse is over a village, display information
        // about that village in the HUD.
        Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(r, out hit, Mathf.Infinity))
        {
            // Check what village is under the mouse right now.
            VillageCtrl villageCtrl = hit.collider.gameObject.GetComponent <VillageCtrl>();
            if (villageCtrl == null || villageCtrl == lastVillage)   // don't update if the village hasn't changed
            {
                return;
            }
            lastVillage = villageCtrl;

            // Display basic village stats.
            uitxt.text = string.Format(
                "Village Number {0}\nPopulation: {1}\nx: {2:0.##}\ty: {3:0.##}",
                villageCtrl.villageNumber,
                villageCtrl.population,
                villageCtrl.worldPos.x,
                villageCtrl.worldPos.y);

            // Display the current language for the group.
            if (Input.GetKeyDown(KeyCode.Space))
            {
                DisplayVillageLanguage(villageCtrl);
            }

            // Make some visual lines the go from the current
            // village to each of its official neighbors.
            KillPings();
            StartPings(villageCtrl);
        }
    }
Ejemplo n.º 9
0
    public void RandomlyTransport()
    {
        gameObject.GetComponent <Renderer>().material = visitingMaterial;

        // We're randomly chosing a neighbor, but weighted by how close it is.
        float rnd = Random.Range(0.0f, 1.0f);
        float sum = TotalNeighborDistance();
        int   idx = 0;

        foreach (float runningSum in IntermediateDistances())
        {
            // sum - runningSum is required so that closer places are more
            // liekly to be chosen, instead of the other way around.
            if ((sum - runningSum) / sum <= rnd)
            {
                break;
            }
            idx++;
        }
        VillageCtrl destination = home.neighbors[idx];

        MagicallyTransport(destination);
        Invoke("GoHome", visitDuration * Random.Range(0.5f, 1.5f));
    }
Ejemplo n.º 10
0
 public void SetHome(VillageCtrl home)
 {
     this.home = home;
 }