Exemple #1
0
    public void Migrate(int playerId)
    {
        Tile migrationTarget = GetMigrationTarget(playerId);

        if (!HasNeighbour(migrationTarget) || migrationTarget == null)
        {
            throw new System.ArgumentException(string.Format("Destination {0} is not a neighbour for player {1}", migrationTarget, playerId));
        }

        for (int pId = 0, l = playerPopulations.Count; pId < l; pId++)
        {
            if (pId != playerId)
            {
                continue;
            }
            PlayerPopulation sourcePop = GetPlayerPopulation(pId);
            PlayerPopulation targetPop = migrationTarget.GetPlayerPopulation(pId);
            int migration = (sourcePop.Size - targetPop.Size) / migrationFraction;
            if (migration > 0)
            {
                int realizedSample;
                var subPop = sourcePop.GetDataSample(migration, out realizedSample);

                sourcePop.RemoveMigrants(subPop);
                targetPop.AddMigrants(subPop);
                targetPop.SetSize(targetPop.Size);

                //Debug.Log("Migrated " + subPop.populationSize + " (" + migration + "/" + realizedSample + ") units for Player " + pId + " from " + name + " to " + migrationTarget.name);
            }
        }
    }
Exemple #2
0
    public void SetPopulationSizeAndEnergy(int playerId, int size, int energy)
    {
        PlayerPopulation pop = GetPlayerPopulation(playerId);

        if (pop == null)
        {
            pop = gameObject.AddComponent <PlayerPopulation>();
            playerPopulations.Add(pop);
        }

        pop.SetSize(size);
        pop.SetEnergy(energy);
    }