Beispiel #1
0
    private void Start()
    {
        itemLabel.text = Regex.Replace(ItemName, "([a-z])([A-Z])", "$1 $2");

        Sprite spr = ResourcesDatabase.GetSprite(ItemName);

        if (spr != null)
        {
            itemSprite.sprite = spr;
        }

        foreach (string s in ResourcesDatabase.GetIngredients(ItemName))
        {
            GameObject go = Instantiate(ingredient);
            go.transform.SetParent(ingredientGrid.transform);

            string[] d = s.Split(' ');

            IngredientInfo ing = go.GetComponent <IngredientInfo>();
            ing.Info = s;
            ing.LoadSprite(d[1]);

            //set sprite of go's image to whatever the ingredient is
        }
    }
        private static void Main(string[] args)
        {
            var resourcesDatabase = new ResourcesDatabase();
            var engine            = new Engine(resourcesDatabase);

            engine.Run();
        }
Beispiel #3
0
    public void CreateWorld()
    {
        Node size = SaveLoadMap.newWorldSize;
        int  szx  = size.x;
        int  szy  = size.y;

        Map           = new World(size);
        Map.terrain   = mapGenerator.GetRandomTerrain(size);
        Map.elevation = mapGenerator.GetRandomElevation(size);
        //Map.elevation = new float[szx, szy];

        //until we've successfully placed the map entrance/exit, keep trying
        bool success = false;

        do
        {
            success = CreateMapEntrance(szx, szy);
        } while (!success);

        money.Money = 10000;

        actionSelecter.FreshActions();

        if (notifications != null)
        {
            notifications.FreshEvents();
        }
        ProductivityController.CreateProductivities();
        ResourcesDatabase.CreateWhitelist();
        money.FreshStartingQuarter((int)timeController.CurrentSeason, timeController.CurrentYear);
        timeController.finances.LoadFinancialReports();
    }
Beispiel #4
0
    void LoadMachinery()
    {
        if (machineryType == MachineType.END)
        {
            MachineData       = null;
            MachineryResource = ResourceType.END;
            Fuel             = ResourceType.END;
            BaseProductivity = 1;
        }
        else
        {
            MachineData = MachineDatabase.GetMachineData(machineryType);

            //CHANGE TO USE DEFINED HOURS CONTRIBUTED BY MACHINE
            if (MachineData == null)
            {
                Debug.LogError("Data does not exist for " + machineryType + " machinery");
            }


            MachineryResource = MachineData.material;
            Fuel = MachineData.fuel;
            //BaseProductivity = MachineData.improvement;
            int baseDays = ResourcesDatabase.GetBaseDays(product);
            //BaseProductivity = (float)(baseDays + MachineData.socialDays) / baseDays;
            BaseProductivity = (float)baseDays / MachineData.socialDays;
        }
    }
Beispiel #5
0
    public override void Activate()
    {
        base.Activate();

        BaseDaysToGrow = ResourcesDatabase.GetBaseDays(cropType);

        JoinProductivityList(cropType);
    }
Beispiel #6
0
    public void LoadSprite(string s)
    {
        Sprite spr = ResourcesDatabase.GetSprite(s);

        if (spr != null)
        {
            GetComponent <Image>().sprite = spr;
        }
    }
Beispiel #7
0
    //sums up total inventory
    public int TotalAmountStored()
    {
        int sum = 0;

        for (int item = 0; item < Inventory.Length; item++)
        {
            sum += Inventory[item] * ResourcesDatabase.GetWeight(Enums.GetItemName(item, typeStored));
        }
        return(sum);
    }
Beispiel #8
0
    //sums up total queue
    public int AmountQueued()
    {
        int sum = 0;

        for (int item = 0; item < Queue.Length; item++)
        {
            sum += Queue[item] * ResourcesDatabase.GetWeight(Enums.GetItemName(item, typeStored));
        }
        return(sum);
    }
Beispiel #9
0
    public override void Load(ObjSave o)
    {
        base.Load(o);

        BaseDaysToGrow = ResourcesDatabase.GetBaseDays(cropType);

        CropSave c = (CropSave)o;

        GrowTimer = c.GrowTimer;
        JoinProductivityList(cropType);
    }
    private static void LoadResourceToViewLayer(string viewPath, UIViewLayer viewLayer, Action <GameObject> callback)
    {
        ResourcesDatabase.Load(viewPath, _object =>
        {
            GameObject viewGo       = GameObject.Instantiate(_object) as GameObject;
            RectTransform rectTrans = viewGo.GetComponent <RectTransform>();

            rectTrans.SetParent(canvasGo.transform.Find(viewLayer.ToString()), false);

            callback(viewGo);
        });
    }
Beispiel #11
0
    private void Update()
    {
        float baseDays           = ResourcesDatabase.GetBaseDays(ItemName);
        float localProductivity  = ProductivityController.GetAverageProductivityHere(ItemName);
        float globalProductivity = ProductivityController.GetAverageProductivityEverywhere(ItemName);

        daysWorldWide.text = Mathf.RoundToInt(baseDays / globalProductivity) + " days";
        daysLocal.text     = localProductivity > 0 ? "(" + Mathf.RoundToInt(baseDays / localProductivity) + " days here)" : "(??? days here)";

        ItemOrder io = new ItemOrder(100, ItemName);

        valueLabel.text = MoneyController.symbol + io.ExchangeValue().ToString("n2");
    }
Beispiel #12
0
    public override void ReceiveItem(ItemOrder io)
    {
        if (io.type == ItemType.Meal)
        {
            Hunger         -= io.amount;
            FoodQualCurrent = ResourcesDatabase.GetQuality(io.GetItemName());
        }

        else if (io.type == ItemType.Good)
        {
            Goods[io.item] += io.amount;
        }
    }
Beispiel #13
0
    private void Start()
    {
        string itemName = order.GetItemDisplayName();

        desc.text = order.amount + " " + itemName + " for " + MoneyController.symbol + order.ExchangeValue().ToString("n2");
        Sprite spr = ResourcesDatabase.GetSprite(itemName);

        if (spr != null)
        {
            image.sprite = spr;
        }

        UpdateButton(trade.ContainsDeal(order));
    }
Beispiel #14
0
    void Start()
    {
        UpdateLabel();
        UpdateAcceptButton();

        accept.gameObject.SetActive(sb.WillGet[index]);
        fill.gameObject.SetActive(!sb.WillGet[index]);
        Sprite spr = ResourcesDatabase.GetSprite(Enums.GetItemName(index, sb.typeStored));

        if (spr != null)
        {
            itemSprite.sprite = spr;
        }
    }
    public void OpenCity(City c)
    {
        CloseCity();
        CurrentCity = c;

        if (c == null)
        {
            Debug.LogError("Tried to open null city");
        }

        cityName.text = CurrentCity.name;
        cityMenu.OpenMenu(cityPage);
        diploMenu.OpenMenu();

        exports = c.GetPossibleExports();
        foreach (ItemOrder export in exports)
        {
            //don't allow trade if item is not whitelisted
            if (!ResourcesDatabase.ItemAllowed(export.GetItemName()))
            {
                continue;
            }

            GameObject deal = Instantiate(UIObjectDatabase.GetUIElement("TradeDeal"));
            deal.transform.SetParent(exportsGrid.transform);

            TradeDeal td = deal.GetComponent <TradeDeal>();
            td.order = export;
            td.trade = tradeController;
            td.diplo = this;
        }

        imports = c.GetPossibleImports();
        foreach (ItemOrder import in imports)
        {
            //don't allow trade if item is not whitelisted
            if (!ResourcesDatabase.ItemAllowed(import.GetItemName()))
            {
                continue;
            }

            GameObject deal = Instantiate(UIObjectDatabase.GetUIElement("TradeDeal"));
            deal.transform.SetParent(importsGrid.transform);

            TradeDeal td = deal.GetComponent <TradeDeal>();
            td.order = import;
            td.trade = tradeController;
            td.diplo = this;
        }
    }
Beispiel #16
0
    // Use this for initialization
    void Start()
    {
        List <string> items = Enums.GetAllItems();

        foreach (string item in items)
        {
            if (!ResourcesDatabase.ItemAllowed(item))
            {
                continue;
            }

            GameObject go = Instantiate(UIObjectDatabase.GetUIElement("ItemValueUI"));
            go.transform.SetParent(grid.transform);

            ItemValueUI iv = go.GetComponent <ItemValueUI>();
            iv.ItemName = item;
            iv.Tooltip  = tooltip;
        }
    }
Beispiel #17
0
    public ItemOrder WillBuyMeal(int item, int amountStored)
    {
        //if you don't want anything, stop
        if (foodQualWant == Quality.None)
        {
            return(null);
        }

        //if this food is not high enough quality and we're not desperate enough, don't buy

        if (!WillAcceptFoodTypes(ResourcesDatabase.GetQuality(Enums.GetItemName(item, ItemType.Meal))))
        {
            return(null);
        }

        int delta = Hunger;

        //if we don't have that much food, sell as much as we can
        if (amountStored < delta)
        {
            delta = amountStored;
        }

        ItemOrder io = new ItemOrder(delta, item, ItemType.Meal);

        //if house cannot afford, find the largest amount it can buy for the smallest price
        if (io.ExchangeValue() > Savings)
        {
            float priceOfOne              = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Meal));
            int   smallestAmount          = (int)(Savings / priceOfOne);
            int   smallestAmountWantToBuy = (int)(0.25f * delta);

            if (smallestAmount <= smallestAmountWantToBuy)
            {
                return(null);
            }

            io.amount = smallestAmount;
        }

        return(io);
    }
Beispiel #18
0
    //empty space for a particular type, both currently and futurely stored
    public int EmptySpaceFor(int a)
    {
        //weight of item
        int weight = ResourcesDatabase.GetWeight(Enums.GetItemName(a, typeStored));

        //if cannot accept type at all, return 0
        if (WillAccept[a] == 0)
        {
            return(0);
        }

        //actual space left, which is the max it will accept times the total potential space minus the amount stored
        int space = (int)(WillAccept[a] * stockpile / weight) - Inventory[a] - Queue[a];

        //if the total potential space is less than what could be stored individually, return the total potential space
        if (EmptySpace < space)
        {
            return(EmptySpace);
        }

        //otherwise return specifically for this type
        return(space);
    }
Beispiel #19
0
    public void LoadScenario(BasicWorldSave w)
    {
        Map = w.world;
        money.Load(w.money);
        actionSelecter.Load(w.actionSelecter);
        diplomacy.Load(w.diplomacy);
        scenario.Load(w.scenario);

        //GO THROUGH LISTS OF OBJECTS AND ACTIVATE THEM USING THE LOADMAPOBJECT() FUNCTION
        //structures
        foreach (ObjSave save in w.structures)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }

        if (notifications != null)
        {
            notifications.FreshEvents();
        }

        //load whitelist for items
        ResourcesDatabase.LoadWhitelist(w.Whitelist);
    }
Beispiel #20
0
    void LoadIngredients()
    {
        string[] i = ResourcesDatabase.GetIngredients(product);

        //if this generator requires fuel to operate, add +1 to the length of the ingredients list
        int length = Fuel != ResourceType.END ? i.Length + 1 : i.Length;

        IngredientsPer100 = new int[length];
        Ingredients       = new string[length];
        IngredientsStored = new int[length];
        int index = 0;

        foreach (string s in i)
        {
            string[] split = s.Split(' ');
            if (split.Length != 2)
            {
                Debug.LogError("Bad info for " + product + " ingredient(s)");
            }
            IngredientsPer100[index] = int.Parse(split[0]);
            Ingredients[index]       = split[1];

            index++;
        }

        if (Fuel != ResourceType.END)
        {
            int fuelIndex = length - 1;
            Ingredients[fuelIndex] = Fuel + "";
        }

        if (Fuel != ResourceType.END)
        {
            IngredientsPer100[index] = DeteriorationPerCycle;
        }
    }
Beispiel #21
0
    public float ExchangeValue()
    {
        //get initial base value (item worth * amount)
        float baseValue = ResourcesDatabase.GetBasePrice(this);

        if (city != null)
        {
            baseValue += city.distance;
        }

        //if (city == null)
        return(baseValue);

        //float modifier = city.attitude * 10;

        //if this is an import, we want to subtract the price if it's from a friendly city, not add to it
        //if (direction == TradeDirection.Import)
        //    modifier *= -1;
        //return baseValue * (100 + modifier) / 100;

        //if attitude is 2, modifier is 20
        //if an import, final price is 80% of base
        //otherwise it's 120%
    }
Beispiel #22
0
    public ItemOrder WillBuyGood(int item, int amountStored)
    {
        bool wantsToBuy = false;

        //check the wanted good first if there is one
        if (goodWanted != GoodType.END)
        {
            //only proceed if the good considered is the good that this house wants
            if ((int)goodWanted == item)
            {
                wantsToBuy = true;
            }
        }

        //now we're going to check the same for each good that we need if we don't want it to evolve
        //	if we don't need this good, don't proceed
        if (!wantsToBuy)
        {
            foreach (GoodType good in goodsNeeded)
            {
                if ((int)good == item)
                {
                    wantsToBuy = true;
                }
            }
        }

        //if we don't want this good, return null
        if (!wantsToBuy)
        {
            return(null);
        }

        //the smallest amount we want to buy is 1 unit, and the most we can have is 2 * houseSize
        //	if the vendor has less goods than we want, match that
        int delta = GoodsMax - Goods[item];

        if (amountStored < delta)
        {
            delta = amountStored;
        }

        ItemOrder io = new ItemOrder(delta, item, ItemType.Good);

        //if house cannot afford, find the largest amount it can buy for the smallest price
        if (io.ExchangeValue() > Savings)
        {
            float priceOfOne              = ResourcesDatabase.GetBasePrice(new ItemOrder(1, item, ItemType.Good));
            int   smallestAmount          = (int)(Savings / priceOfOne);
            int   smallestAmountWantToBuy = (int)(0.25f * delta);

            if (smallestAmount <= smallestAmountWantToBuy)
            {
                return(null);
            }

            io.amount = smallestAmount;
        }

        return(io);
    }
Beispiel #23
0
 public int GetTotalDeadLabor()
 {
     return(ResourcesDatabase.GetAccumulativeDays(material.ToString()) + deadLabor);
 }
    public override void Open()
    {
        base.Open();

        StorageBuilding sb = (StorageBuilding)obj;

        ItemType type = sb.typeStored;

        string[] items  = new string[0];
        int      length = 0;

        switch (type)
        {
        case ItemType.Food:
            length = (int)FoodType.END;
            items  = new string[length];
            Enums.foodDict.Keys.CopyTo(items, 0);
            break;

        case ItemType.Good:
            length = (int)GoodType.END;
            items  = new string[length];
            Enums.goodDict.Keys.CopyTo(items, 0);
            break;

        case ItemType.Resource:
            length = (int)ResourceType.END;
            items  = new string[length];
            Enums.resourceDict.Keys.CopyTo(items, 0);
            break;
        }
        List <string> sorted = new List <string>(items);

        sorted.Sort();
        foreach (string item in sorted)
        {
            if (!ResourcesDatabase.ItemAllowed(item))
            {
                continue;
            }

            Node n     = Enums.GetItemData(item);
            int  index = n.x;

            ////for simple grid
            //if (sb.Inventory[index] > 0) {

            //	GameObject g1 = Instantiate(storageitem_smpl);
            //	g1.transform.SetParent(simpleInventoryGrid.transform);

            //	StorageItem_smpl s = g1.GetComponent<StorageItem_smpl>();
            //	s.sb = sb;
            //	s.index = index;

            //	noItems.SetActive(false);

            //}

            //entry in advanced grid
            GameObject g2 = Instantiate(UIObjectDatabase.GetUIElement("StorageItem_adv"));
            g2.transform.SetParent(advancedInventoryGrid);

            StorageItem_adv si = g2.GetComponent <StorageItem_adv>();
            si.index = index;
            si.sb    = sb;
        }
    }
Beispiel #25
0
    public void LoadSavedGame(WorldProgressSave w)
    {
        Map = w.world;
        timeController.Load(w.time);
        population.Load(w.population);
        money.Load(w.money);
        cameraController.Load(w.camera);
        actionSelecter.Load(w.actionSelecter);
        immigration.Load(w.immigration);
        trade.Load(w.trade);
        diplomacy.Load(w.diplomacy);
        scenario.Load(w.scenario);
        research.Load(w.research);

        ProductivityController.LoadProductivities(w.productivities, w.automation);
        notifications.LoadEvents(w.Events);

        //load whitelist for items
        ResourcesDatabase.LoadWhitelist(w.Whitelist);

        //GO THROUGH LISTS OF OBJECTS AND ACTIVATE THEM USING THE LOADMAPOBJECT() FUNCTION
        //structures
        foreach (ObjSave save in w.structures)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.jobcentres)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.workplaces)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.storagebuildings)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.generators)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.stables)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.houses)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.wtps)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.canals)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.crops)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }
        foreach (ObjSave save in w.farmhouses)
        {
            LoadMapObject(save).transform.parent = structures.transform;
        }

        //walkers
        foreach (ObjSave save in w.animals)
        {
            LoadMapObject(save).transform.parent = walkers.transform;
        }
        foreach (ObjSave save in w.walkers)
        {
            LoadMapObject(save).transform.parent = walkers.transform;
        }
    }