コード例 #1
0
ファイル: WS_Tile.cs プロジェクト: rodrigodpl/WorldSimulator
    public void ClearPopulation()
    {
        population     = 0.0f;
        farmers        = builders = traders = soldiers = scholars = 0;
        foodUnits      = 0.0f;
        foodEfficiency = 1.2f;
        sanitation     = 30;
        healthcare     = -0.2f;
        unrestDecay    = 0.8f;
        lastPopGrowth  = 0.0f;
        storedFood     = 0.0f;
        unrest         = unrestCultural = unrestReligious = 0.0f;

        culture      = null;
        cultureBonus = 0.0f;

        disaster         = null;
        disasterDuration = 0;

        religion      = null;
        religionBonus = 0.0f;

        infrastructurePoints = 0.0f;

        for (int i = 0; i < infrastructureLevels.Length; i++)
        {
            infrastructureLevels[i] = 1;
        }

        plannedInfrastructure = null;
        constructionBonus     = 0.0f;

        government = null;

        prosperity = 0.0f;

        foreach (WS_ResourceStack stack in resStacks)
        {
            stack.amount = 0;
        }

        caravan = null;

        qualityBonus      = 1.0f;
        exploitationBonus = 1.0f;

        armyBonus    = 0.5f;
        defenseBonus = 1.0f;

        currentTech      = null;
        storedTechPoints = 0.0f;
        availableTech.Clear();
        researchedTech.Clear();
    }
コード例 #2
0
    protected override void Success()
    {
        WS_CommerceCaravan caravan = tile.caravan;

        if (caravan == null)
        {
            int traders = 2 + tile.baseCitizens;
            WS_CommerceCaravan newCaravan = new WS_CommerceCaravan();

            WS_ResourceStack resStack = new WS_ResourceStack(tile.resource.type);
            resStack.quality = tile.resource.quality * tile.qualityBonus;
            resStack.amount  = (int)(50.0f * traders * tile.resource.abundance * tile.exploitationBonus);

            newCaravan.travelTime  = traders;
            newCaravan.currentTile = tile;
            newCaravan.resStack    = resStack;

            tile.caravan = newCaravan;
            return;
        }
        else
        {
            WS_Tile dest = caravan.currentTile;

            int currentAmount = caravan.currentTile.resStacks[(int)caravan.resStack.type].amount;

            bool trading = false;
            bool embargo = false;

            foreach (WS_Treaty treaty in tile.government.treaties)
            {
                if (treaty.target == dest.government)
                {
                    if (treaty.type == TreatyType.TRADE_AGREEMENT || treaty.type == TreatyType.ALLIANCE)
                    {
                        trading = true;
                    }
                    else if (treaty.type == TreatyType.TRADE_EMBARGO || treaty.type == TreatyType.WAR)
                    {
                        embargo = true;
                    }
                }
            }

            float bestPrice = 1.0f - (currentAmount / (caravan.currentTile.population / 10.0f)) * caravan.resStack.Price();

            if (trading)
            {
                bestPrice *= 1.15f;
            }
            else if (embargo)
            {
                bestPrice = 0;
            }

            foreach (WS_Tile neighbor in caravan.currentTile.Neighbors())
            {
                trading = false;
                embargo = false;

                foreach (WS_Treaty treaty in tile.government.treaties)
                {
                    if (treaty.target == neighbor.government)
                    {
                        if (treaty.type == TreatyType.TRADE_AGREEMENT || treaty.type == TreatyType.ALLIANCE)
                        {
                            trading = true;
                        }
                        else if (treaty.type == TreatyType.TRADE_EMBARGO || treaty.type == TreatyType.WAR)
                        {
                            embargo = true;
                        }
                    }
                }

                int   neighborAmount = neighbor.resStacks[(int)caravan.resStack.type].amount;
                float expectedPrice  = (1.0f - (neighborAmount / (neighbor.population / 10.0f))) * caravan.resStack.Price();

                if (trading)
                {
                    expectedPrice *= 1.15f;
                }
                else if (embargo)
                {
                    expectedPrice = 0;
                }

                if (expectedPrice > bestPrice)
                {
                    bestPrice = expectedPrice;
                    dest      = neighbor;
                }
            }

            caravan.currentTile = dest;

            if (bestPrice > 0)
            {
                int unitsSold = caravan.resStack.amount / caravan.travelTime;

                WS_ResourceStack destStack = caravan.currentTile.resStacks[(int)caravan.resStack.type];

                destStack.quality = (caravan.resStack.quality * unitsSold + destStack.quality * destStack.amount) / (destStack.amount + unitsSold);
                destStack.amount += unitsSold;

                caravan.money   += unitsSold * (int)bestPrice;
                dest.prosperity += unitsSold * (int)bestPrice * 0.1f * dest.tradingbonus;

                if (tile.culture != dest.culture)
                {
                    tile.culture.syncretism += 1.0f;
                    dest.culture.syncretism += 1.0f;
                }
                if (tile.religion != dest.religion)
                {
                    tile.religion.syncretism += 1.0f;
                    dest.religion.syncretism += 1.0f;
                }
            }

            caravan.currentTime++;

            if (caravan.currentTime >= caravan.travelTime)
            {
                float prosperityGain = caravan.money * tile.resProsperityBonus;
                tile.religion.influenceMul += prosperityGain * tile.religion.corruption * 0.001f;
                prosperityGain             *= (1.0f / tile.religion.corruption);

                tile.prosperity += prosperityGain;
                tile.caravan     = null;
            }
        }
    }