Ejemplo n.º 1
0
    /// <summary>
    /// Only goods sent to market
    /// Based  on last turn data
    /// </summary>
    internal float getSupply(Product pro, bool takeThisTurnData)
    {
        float result = 0f;

        if (takeThisTurnData)
        {
            foreach (Country country in Country.allCountries)
            {
                foreach (Province province in country.ownedProvinces)
                {
                    foreach (Producer producer in province)
                    {
                        if (producer.sentToMarket.getProduct() == pro) //sup.getProduct()
                        {
                            result += producer.sentToMarket.get();
                        }
                    }
                }
            }
            return(result);
        }
        if (dateOfgetSupply != Game.date)
        {
            //recalculate supplybuffer
            foreach (Storage sup in marketPrice)
            {
                result = 0;
                foreach (Country country in Country.allCountries)
                {
                    foreach (Province province in country.ownedProvinces)
                    {
                        foreach (Producer producer in province)
                        {
                            if (producer.sentToMarket.getProduct() == sup.getProduct()) //sup.getProduct()
                            {
                                result += producer.sentToMarket.get();
                            }
                        }
                    }
                }

                getSupplyBuffer.Set(new Storage(sup.getProduct(), result));
            }
            dateOfgetSupply = Game.date;
        }
        Storage tmp = getSupplyBuffer.findStorage(pro);

        if (tmp == null)
        {
            return(0);
        }
        else
        {
            return(getSupplyBuffer.findStorage(pro).get());
        }
        //return result;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// returns new copy
    /// </summary>
    internal PrimitiveStorageSet Divide(float v)
    {
        PrimitiveStorageSet result = new PrimitiveStorageSet();

        foreach (Storage stor in container)
        {
            result.Set(new Storage(stor.getProduct(), stor.get() / v));
        }
        return(result);
    }
Ejemplo n.º 3
0
    internal PrimitiveStorageSet getBuildNeeds()
    {
        //return new Storage(Product.Food, 40f);
        PrimitiveStorageSet result = new PrimitiveStorageSet();

        result.Set(new Storage(Product.Food, 40f));
        //TODO!has connection in pop.invest!!
        //if (whoCanProduce(Product.Gold) == this)
        //        result.Set(new Storage(Product.Wood, 40f));
        return(result);
    }
Ejemplo n.º 4
0
 internal FactoryType(string iname, Storage ibasicProduction, PrimitiveStorageSet iresourceInput, bool shaft)
 {
     name = iname;
     if (iname == "Gold pit")
     {
         GoldMine = this;
     }
     if (iname == "Furniture factory")
     {
         Furniture = this;
     }
     if (iname == "Metal pit")
     {
         MetalDigging = this;
     }
     if (iname == "Metal smelter")
     {
         MetalSmelter = this;
     }
     allTypes.Add(this);
     basicProduction = ibasicProduction;
     if (iresourceInput == null)
     {
         resourceInput = new PrimitiveStorageSet();
     }
     else
     {
         resourceInput = iresourceInput;
     }
     //upgradeResource.Set(new Storage(Product.Wood, 10f));
     upgradeResource.Set(new Storage(Product.Stone, 10f));
     //internal ConditionsList conditionsBuild;
     enoughMoneyOrResourcesToBuild = new Condition(
         (delegate(Country forWhom)
     {
         if (Economy.isMarket.checkIftrue(forWhom))
         {
             return(forWhom.wallet.canPay(getBuildCost()));
         }
         else
         {
             return(forWhom.storageSet.has(getBuildNeeds()));
         }
     }), "Have enough money or resources to build", true
         );
     conditionsBuild = new ConditionsList(new List <AbstractCondition>()
     {
         Economy.isNotLF, enoughMoneyOrResourcesToBuild
     });                                               // can build
     this.shaft = shaft;
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Result > 1 mean demand is hier, price should go up   Result feuwer 1 mean supply is hier, price should go down
    /// based on last turn data
    internal float getDemandSupplyBalance(Product pro)
    {
        float balance;

        if (dateOfDSB != Game.date)
        // recalculate DSBbuffer
        {
            foreach (Storage stor in marketPrice)
            {
                getProductionTotal(pro, false);  // for pre-turn initialization
                getTotalConsumption(pro, false); // for pre-turn initialization
                float supply = getSupply(stor.getProduct(), false);
                float demand = getBouth(stor.getProduct(), false);
                //if (demand == 0) getTotalConsumption(stor.getProduct());
                //else
                ////if (demand == 0) balance = 1f;
                ////else
                //if (supply == 0) balance = 2f;
                //else

                balance = demand / supply;

                //if (balance > 1f) balance = 1f;
                //&& supply == 0
                if (demand == 0)
                {
                    balance = 0f;              // overwise - furniture bag
                }
                // else
                if (supply == 0)
                {
                    balance = float.MaxValue;
                }
                //if (float.IsInfinity(balance)) // if divided by zero, s = zero
                //    balance = float.NaN;
                DSBbuffer.Set(new Storage(stor.getProduct(), balance));
            }
            dateOfDSB = Game.date;
        }
        Storage tmp = DSBbuffer.findStorage(pro);

        if (tmp == null)
        {
            return(float.NaN);
        }
        else
        {
            return(tmp.get());
        }
    }
Ejemplo n.º 6
0
    public Game()
    {
        Application.runInBackground = true;
        //LoadImages();
        generateMapImage();
        new Product("Food", false, 0.4f);
        new Product("Wood", true, 2.7f);
        new Product("Lumber", false, 8f);
        new Product("Gold", true, 4f);
        new Product("Metall ore", true, 3f);
        new Product("Metall", false, 6f);
        new Product("Wool", true, 1);
        new Product("Clothes", false, 3);
        new Product("Furniture", false, 7);
        new Product("Stone", true, 1);
        new Product("Cement", false, 2);
        new Product("Fruit", true, 1);
        new Product("Wine", false, 3);
        market.initialize();
        makeMap();
        roundMesh();
        var mapWidth  = mapImage.width * cellMuliplier;
        var mapHeight = mapImage.height * cellMuliplier;

        //MainCamera.cameraMy.transform.position = GameObject.FindWithTag("mapObject").transform.position;
        MainCamera.cameraMy.transform.position = new Vector3(mapWidth / 2f, mapHeight / 2f, MainCamera.cameraMy.transform.position.z);

        FindProvinceCenters();
        r3dTextPrefab = (GameObject)Resources.Load("prefabs/3dTextPrefab", typeof(GameObject));
        foreach (Province pro in Province.allProvinces)
        {
            pro.SetLabel();
        }

        Province.allProvinces[0].setResource(Product.Gold);
        //Province.allProvinces[0].setResource(Product.Wood;
        Province.allProvinces[1].setResource(Product.Wood);
        Province.allProvinces[2].setResource(Product.Fruit);
        Province.allProvinces[3].setResource(Product.Wool);
        Province.allProvinces[4].setResource(Product.Stone);
        Province.allProvinces[5].setResource(Product.MetallOre);



        new FactoryType("Forestry", new Storage(Product.Wood, 2f), null, false);
        new FactoryType("Gold pit", new Storage(Product.Gold, 2f), null, true);
        new FactoryType("Metal pit", new Storage(Product.MetallOre, 2f), null, true);
        new FactoryType("Sheepfold", new Storage(Product.Wool, 2f), null, false);
        new FactoryType("Quarry", new Storage(Product.Stone, 2f), null, true);
        new FactoryType("Orchard", new Storage(Product.Fruit, 2f), null, false);

        PrimitiveStorageSet resourceInput = new PrimitiveStorageSet();

        resourceInput.Set(new Storage(Product.Lumber, 1f));
        new FactoryType("Furniture factory", new Storage(Product.Furniture, 4f), resourceInput, false);

        resourceInput = new PrimitiveStorageSet();
        resourceInput.Set(new Storage(Product.Wood, 1f));
        new FactoryType("Sawmill", new Storage(Product.Lumber, 2f), resourceInput, false);

        resourceInput = new PrimitiveStorageSet();
        resourceInput.Set(new Storage(Product.Wood, 0.5f));
        resourceInput.Set(new Storage(Product.MetallOre, 2f));
        new FactoryType("Metal smelter", new Storage(Product.Metal, 3f), resourceInput, false);

        resourceInput = new PrimitiveStorageSet();
        resourceInput.Set(new Storage(Product.Wool, 1f));
        new FactoryType("Weaver factory", new Storage(Product.Clothes, 2f), resourceInput, false);

        resourceInput = new PrimitiveStorageSet();
        resourceInput.Set(new Storage(Product.Wood, 0.5f));
        resourceInput.Set(new Storage(Product.Stone, 1f));
        new FactoryType("Cement factory", new Storage(Product.Cement, 3f), resourceInput, false);

        resourceInput = new PrimitiveStorageSet();
        resourceInput.Set(new Storage(Product.Fruit, 0.3333f));
        new FactoryType("Winery", new Storage(Product.Wine, 2f), resourceInput, false);

        //new Product("Grain");

        //new PopType(PopType.PopTypes.TribeMen, new Storage(Product.findByName("Food"), 1.5f), "Tribemen");
        new PopType(PopType.PopTypes.Tribemen, new Storage(Product.findByName("Food"), 1.0f), "Tribemen");
        new PopType(PopType.PopTypes.Aristocrats, null, "Aristocrats");
        new PopType(PopType.PopTypes.Capitalists, null, "Capitalists");
        new PopType(PopType.PopTypes.Farmers, new Storage(Product.findByName("Food"), 2.0f), "Farmers");
        //new PopType(PopType.PopTypes.Artisans, null, "Artisans");
        //new PopType(PopType.PopTypes.Soldiers, null, "Soldiers");
        new PopType(PopType.PopTypes.Workers, null, "Workers");

        Culture cul = new Culture("Kocopetji");

        player = new Country("Kocopia", cul, new CountryWallet(0f));
        player.storageSet.add(new Storage(Product.Food, 200f));
        player.wallet.haveMoney.add(100f);

        CreateRandomPopulation();
        Province.allProvinces[0].allPopUnits[0].education.set(1f);

        MainCamera.topPanel.refresh();
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Meaning demander actyally can pay for item in current prices
    /// Basing on current prices and needs
    /// Not encounting ConsumedInMarket
    /// </summary>
    internal float getBouth(Product pro, bool takeThisTurnData)
    {
        float result = 0f;

        if (takeThisTurnData)
        {
            foreach (Country country in Country.allCountries)
            {
                foreach (Province province in country.ownedProvinces)
                {
                    foreach (Producer producer in province)
                    {
                        //if (any.c.getProduct() == sup.getProduct()) //sup.getProduct()
                        {
                            Storage re = producer.consumedInMarket.findStorage(pro);
                            if (re != null)
                            {
                                result += re.get();
                            }
                        }
                    }
                }
            }
            return(result);
        }
        if (dateOfgetBouth != Game.date)
        {
            //recalculate supplybuffer
            foreach (Storage sup in marketPrice)
            {
                result = 0;
                foreach (Country country in Country.allCountries)
                {
                    foreach (Province province in country.ownedProvinces)
                    {
                        foreach (Producer producer in province)
                        {
                            //if (any.c.getProduct() == sup.getProduct()) //sup.getProduct()
                            {
                                Storage re = producer.consumedInMarket.findStorage(sup.getProduct());
                                if (re != null)
                                {
                                    result += re.get();
                                }
                            }
                        }
                    }
                }
                getBouthBuffer.Set(new Storage(sup.getProduct(), result));
            }
            dateOfgetBouth = Game.date;
        }
        Storage tmp = getBouthBuffer.findStorage(pro);

        if (tmp == null)
        {
            return(0);
        }
        else
        {
            return(getBouthBuffer.findStorage(pro).get());
        }
        //float result = 0f;
        //foreach (Country country in Country.allCountries)
        //    foreach (Province province in country.ownedProvinces)
        //    {
        //        foreach (Producer shownFactory in province)
        //            //result += shownFactory.getLocalEffectiveDemand(pro);
        //            if (shownFactory.consumedInMarket.findStorage(pro) != null)
        //                result += shownFactory.consumedInMarket.findStorage(pro).get();


        //        //foreach (PopUnit pop in province.allPopUnits)
        //        //    //result += pop.getLocalEffectiveDemand(pro);
        //        //    if (pop.consumedInMarket.findStorage(pro) != null)
        //        //        result += pop.consumedInMarket.findStorage(pro).get();
        //        // todo add same for country and any demander
        //    }
        //return result;
    }
Ejemplo n.º 8
0
 /// <summary>
 /// per 1 unit
 /// </summary>
 //Value defaultPrice = new Value(2f);
 public void SetDefaultPrice(Product pro, float inprice)
 {
     marketPrice.Set(new Storage(pro, inprice));
 }/// <summary>
Ejemplo n.º 9
0
    public PopType(PopTypes itype, Storage iproduces, string iname)
    {
        type            = itype;
        name            = iname;
        basicProduction = iproduces;
        allPopTypes.Add(this);
        switch (itype)
        {
        case PopTypes.Tribemen:
            tribeMen = this;
            lifeNeeds.Set(new Storage(Product.Food, 1));
            everyDayNeeds.Set(new Storage(Product.Food, 2));
            luxuryNeeds.Set(new Storage(Product.Food, 3));
            break;

        case PopTypes.Aristocrats:
            aristocrats = this;
            lifeNeeds.Set(new Storage(Product.Food, 1));

            everyDayNeeds.Set(new Storage(Product.Fruit, 1));


            luxuryNeeds.Set(new Storage(Product.Clothes, 1));
            luxuryNeeds.Set(new Storage(Product.Furniture, 1));

            luxuryNeeds.Set(new Storage(Product.Wine, 2));
            luxuryNeeds.Set(new Storage(Product.Metal, 1));
            luxuryNeeds.Set(new Storage(Product.Cement, 0.5f));
            break;

        case PopTypes.Capitalists:
            capitalists = this;
            lifeNeeds.Set(new Storage(Product.Food, 1));

            luxuryNeeds.Set(new Storage(Product.Fruit, 1));

            everyDayNeeds.Set(new Storage(Product.Clothes, 1));
            everyDayNeeds.Set(new Storage(Product.Furniture, 1));

            everyDayNeeds.Set(new Storage(Product.Wine, 2));
            everyDayNeeds.Set(new Storage(Product.Metal, 1));
            everyDayNeeds.Set(new Storage(Product.Cement, 0.5f));
            break;

        case PopTypes.Farmers:
            farmers = this;
            lifeNeeds.Set(new Storage(Product.Food, 1f));

            //everyDayNeeds.Set(new Storage(Product.Fruit, 1));
            everyDayNeeds.Set(new Storage(Product.Stone, 1));
            everyDayNeeds.Set(new Storage(Product.Wood, 1));
            everyDayNeeds.Set(new Storage(Product.Wool, 1));
            everyDayNeeds.Set(new Storage(Product.Lumber, 1));
            everyDayNeeds.Set(new Storage(Product.MetallOre, 1));

            luxuryNeeds.Set(new Storage(Product.Clothes, 1));
            luxuryNeeds.Set(new Storage(Product.Furniture, 1));

            luxuryNeeds.Set(new Storage(Product.Wine, 2));
            luxuryNeeds.Set(new Storage(Product.Metal, 1));
            luxuryNeeds.Set(new Storage(Product.Cement, 0.5f));

            break;

        case PopTypes.Artisans:
            artisans = this;
            break;

        case PopTypes.Soldiers:
            soldiers = this;
            break;

        case PopTypes.Workers:
            workers = this;
            lifeNeeds.Set(new Storage(Product.Food, 1));

            everyDayNeeds.Set(new Storage(Product.Fruit, 1));

            everyDayNeeds.Set(new Storage(Product.Clothes, 1));
            everyDayNeeds.Set(new Storage(Product.Furniture, 1));

            luxuryNeeds.Set(new Storage(Product.Wine, 2));
            everyDayNeeds.Set(new Storage(Product.Metal, 1));


            break;

        default:
            Debug.Log("Unnown PopType");
            break;
        }
    }