Пример #1
0
    // Update is called once per frame
    public void UpdateInfo()
    {
        provincegen pr = intendant.selected_province.GetComponent <provincegen>();

        max_cost = (int)(pr.population * pr.separatism / 100f);
        AssimilateSlider.value = 0;
        CostText.text          = "0MP";
    }
Пример #2
0
    public void UpdateMenuText()
    {
        provincegen current_provincegen = intendant.selected_province.GetComponent <provincegen>();

        GameObject.Find("FarmBuild/Text").GetComponent <TMPro.TextMeshProUGUI>().text     = String.Format("Build farm for {0}", current_provincegen.Farms * 100 + 100);
        GameObject.Find("FactoryBuild/Text").GetComponent <TMPro.TextMeshProUGUI>().text  = String.Format("Build factory for {0}", current_provincegen.Factories * 100 + 100);
        GameObject.Find("LibraryBuild/Text").GetComponent <TMPro.TextMeshProUGUI>().text  = String.Format("Build library for {0}", current_provincegen.Libraries * 100 + 100);
        GameObject.Find("FortressBuild/Text").GetComponent <TMPro.TextMeshProUGUI>().text = String.Format("Build fortress for {0}", current_provincegen.Fortresses * 100 + 100);
    }
Пример #3
0
 public void OnPressAssimilateButton()
 {
     if (intendant.GetBalance() >= cost && intendant.action_points >= 1)
     {
         provincegen pr = intendant.selected_province.GetComponent <provincegen>();
         pr.separatism = (int)(pr.separatism * (1 - AssimilateSlider.value));
         intendant.SpendMoney(cost); intendant.SpendActionPoints(1);
         intendant.UpdateMode(); UpdateInfo();
     }
 }
Пример #4
0
    public int GetCurrentTechLevel()
    {
        foreach (GameObject province in list_of_provinces)
        {
            provincegen current_provincegen = province.GetComponent <provincegen>();
            technology += current_provincegen.education;
        }

        technology = (int)((float)technology / (float)list_of_provinces.Count);
        // Debug.Log(string.Format("GetCurrentTechLeve;() state{0}, redult {1}", GetId(), technology));
        return(technology);
    }
Пример #5
0
 public void CalculateCharacteristics()
 {
     population = 0; productions = 0;
     technology = 0;
     foreach (GameObject province in list_of_provinces)
     {
         provincegen current_provincegen = province.GetComponent <provincegen>();
         population  += current_provincegen.population;
         productions += current_provincegen.productions;
         technology  += current_provincegen.education;
     }
 }
Пример #6
0
    public void AddProvince(int province_id) // manager
    {
        string     province_object_name = "province_" + Convert.ToString(province_id);
        GameObject province             = GameObject.Find(province_object_name);

        list_of_provinces.Add(province);
        provincegen current_provincegen = province.GetComponent <provincegen>();

        // Debug.Log(String.Format("stategen {0}, {1}, {2}", state_color.r, state_color.g, state_color.b));
        current_provincegen.ChangeColor(state_color);
        current_provincegen.SetState(gameObject);
    }
Пример #7
0
    void ArmyDeterminate(int action_points)
    {
        List <provincegen> border_provinces = new List <provincegen>();

        foreach (GameObject province in state.list_of_provinces)
        {
            provincegen pr = province.GetComponent <provincegen>();
            foreach (int connection in pr.connections)
            {
                if (state.Enemyes.Contains(provincegen.GetProvinceById(connection).GetComponent <provincegen>().state))
                {
                    border_provinces.Add(pr);
                }
            }
        }
        while (true)
        {
            if (action_points < 0)
            {
                break;
            }
            int action = Random.Range(0, 2);
            if (action == 0)
            {
                int province_id = Random.Range(0, border_provinces.Count);
                int quantity    = Random.Range(0, border_provinces[province_id].population / 2);
                border_provinces[province_id].population -= quantity;
                border_provinces[province_id].army       += quantity;
                action_points -= 4;
            }
            if (action == 1)
            {
                int province_id = Random.Range(0, border_provinces.Count);
                List <provincegen> enemy_provinces = new List <provincegen>();
                foreach (int conenction in border_provinces[province_id].connections)
                {
                    provincegen pr = provincegen.GetProvinceById(conenction).GetComponent <provincegen>();
                    if (state.Enemyes.Contains(pr.state))
                    {
                        enemy_provinces.Add(pr);
                    }
                }
                int province_subject_id = Random.Range(0, enemy_provinces.Count);
                int quantity            = Random.Range(0, border_provinces[province_id].army + 1);
                Consequentor.MoveSoldiers(border_provinces[province_id].gameObject, enemy_provinces[province_subject_id].gameObject, quantity);
                border_provinces[province_id].army -= quantity;
            }
        }
    }
Пример #8
0
    // Update is called once per frame
    public void UpdateInfo()
    {
        // Debug.LogError(intendant);
        provincegen current_provincegen = intendant.selected_province.GetComponent <provincegen>();
        stategen    current_stategen    = intendant.ProtagonistState.GetComponent <stategen>();

        MaxPeopleToConscript  = (int)((float)current_provincegen.population / 2);
        MaxPeopleToDemobilize = current_provincegen.army;
        MaxPeopleToMove       = current_provincegen.army;

        PeopleToConscript  = 0;
        PeopleToDemobilize = 0;
        PeopleToMove       = 0;

        ConscriptSlider.value = 0; DemobilizeSlider.value = 0; MoveSlider.value = 0;
    }
Пример #9
0
    public bool CheckEconomicWin()
    {
        int provinces_economic = 0;
        int provinces_prot     = 0;

        foreach (GameObject province in list_of_provinces)
        {
            provincegen pr = province.GetComponent <provincegen>();
            provinces_economic += pr.productions;
            if (pr.state == ProtagonistState)
            {
                provinces_prot += pr.productions;
            }
        }
        return((float)provinces_prot / (float)provinces_economic >= 0.9f);
    }
Пример #10
0
 public void Simulate()
 {
     // Debug.Log(actions);
     foreach (Action action in actions)
     {
         if (action.GetActionType() == Action.move)
         {
             if (action.GetActionSubject().GetComponent <provincegen>().state == action.GetActionObject().GetComponent <provincegen>().state)
             {
                 action.GetActionObject().GetComponent <provincegen>().army += action.GetQuantity();
             }
             else
             {
                 provincegen oc  = action.GetActionSubject().GetComponent <provincegen>();
                 provincegen def = action.GetActionObject().GetComponent <provincegen>();
                 // Debug.LogError(string.Format("equality of "));
                 int ocArm   = action.GetQuantity();
                 int defArm  = def.army;
                 int ocTech  = oc.state.GetComponent <stategen>().GetCurrentTechLevel();
                 int defTech = def.state.GetComponent <stategen>().GetCurrentTechLevel();
                 // Debug.Log(string.Format("defTech = {0}", defTech));
                 int ocLoyality  = (150 - oc.separatism);
                 int defLoyality = (150 - def.separatism);
                 int ocRes       = ocArm * ocTech * ocLoyality;
                 int defRes      = (int)(defArm * defTech * defLoyality * (1 + (float)def.defensive_ability / 100f));
                 if (oc.state == intendant.ProtagonistState)
                 { // Debug.LogError("contact"); Debug.LogError(string.Format("{0}, {1}", ocRes, defRes)); }
                     if (ocRes > defRes)
                     {
                         Debug.Log("captured");
                         // Debug.Log(string.Format("{0}, {1}, {2}, {3}, {4}", defRes, defArm, defTech, defLoyality, (1 + (float)def.defensive_ability / 100f)));
                         // Debug.Log(string.Format("{0}, {1}", def.GetId(), oc.state.GetComponent<stategen>().GetId()));
                         intendant.CaptureProvince(def.gameObject, oc.state);
                         def.army = ocArm - defArm;
                     }
                     else
                     {
                         def.army = defArm - ocArm;
                     }
                 }
             }
         }
     }
 }
Пример #11
0
    public bool CheckSquareWin()
    {
        int provinces_no_seas = 0;
        int provinces_prot    = 0;

        foreach (GameObject province in list_of_provinces)
        {
            provincegen pr = province.GetComponent <provincegen>();
            if (pr.sea == 0)
            {
                provinces_no_seas++;
            }
            if (pr.state == ProtagonistState)
            {
                provinces_prot++;
            }
        }
        return((float)provinces_prot / (float)provinces_no_seas >= 0.9f);
    }
Пример #12
0
    public void CaptureProvince(GameObject province, GameObject state) // Manager
    {
        try
        {
            provincegen pr = province.GetComponent <provincegen>();
            pr.state.GetComponent <stategen>().list_of_provinces.Remove(province);
            Debug.Log(String.Format("current state{0} ", pr.state));

            state.GetComponent <stategen>().AddProvince(pr.GetId());
            pr.separatism = 100;
            Debug.LogError(String.Format("setting state{0} except state{1}", state, pr.state));
            pr.SetState(state);
            pr.ChangeColor(pr.state_color);
        }
        catch (Exception)
        {
            Debug.LogError("Can`t find the state or province");
        }
        UpdateMode();
    }
Пример #13
0
    public void UpdateMode() // Manager
    {
        if (mode == CHOISE_MODE)
        {
            AlertDefault();
            GameObject[] provinces = GameObject.FindGameObjectsWithTag("Province");
            foreach (GameObject province in provinces)
            {
                provincegen province_manager = province.GetComponent <provincegen>();
                try
                {
                    String state_name = province_manager.state.GetComponent <stategen>().state_name;
                    province_manager.SetTextFieldValue(state_name);
                }
                catch (Exception)
                {
                    String state_name = province_manager.province_name;
                    province_manager.SetTextFieldValue(state_name);
                }
            }
        }
        else if (mode == POLITICAL_MODE)
        {
            AlertDefault();
            GameObject[] provinces = GameObject.FindGameObjectsWithTag("Province");
            foreach (GameObject province in provinces)
            {
                province.GetComponent <provincegen>().SetStateColor();
                province.GetComponent <provincegen>().SetTextFieldValue(String.Format("{0}", province.GetComponent <provincegen>().population));
            }
        }
        else if (mode == ECONOMICAL_MODE)
        {
            GameObject[] provinces = GameObject.FindGameObjectsWithTag("Province");
            float        minimum_value = 100000000, maximum_value = 0;
            foreach (GameObject province in provinces)
            {
                float       GDP;
                provincegen current_provincegen = province.GetComponent <provincegen>();
                if (current_provincegen.population != 0)
                {
                    GDP = current_provincegen.productions / current_provincegen.population;
                }
                else
                {
                    GDP = 0;
                }
                if (GDP < minimum_value)
                {
                    minimum_value = GDP;
                }
                if (GDP > maximum_value)
                {
                    maximum_value = GDP;
                }
            }
            foreach (GameObject province in provinces)
            {
                provincegen current_provincegen = province.GetComponent <provincegen>();
                if (current_provincegen.state != ProtagonistState)
                {
                    current_provincegen.SetStrictColor(Color.white);
                    current_provincegen.SetTextFieldValue("");
                }
                else
                {
                    float GPD        = (float)current_provincegen.productions / (float)current_provincegen.population;
                    float percentage = (GPD - minimum_value) / (maximum_value - minimum_value);
                    current_provincegen.ChangeColor(EconomicModeMinColor + (EconomicModeMaxColor - EconomicModeMinColor) * percentage);
                    string sgpd = Convert.ToString(GPD);
                    Debug.LogError(sgpd);
                    current_provincegen.SetTextFieldValue(sgpd.Substring(0, sgpd.IndexOf(',') + 2));
                }
            }
        }
        else if (mode == ARMY_MODE)
        {
            int army_min = 0; int army_max = 0;
            for (int i = 0; i < list_of_provinces.Count; i++)
            {
                provincegen current_provincegen = list_of_provinces[i].GetComponent <provincegen>();
                int         current_army        = current_provincegen.army;
                if (i == 0)
                {
                    army_min = current_army; army_max = current_army;
                }
                if (current_army < army_min)
                {
                    army_min = current_army;
                }
                if (current_army > army_max)
                {
                    army_max = current_army;
                }
            }
            foreach (GameObject province in list_of_provinces)
            {
                provincegen current_provincegen = province.GetComponent <provincegen>();
                int         current_army        = current_provincegen.army;
                if (current_provincegen.state != ProtagonistState)
                {
                    if (ProtagonistState.GetComponent <stategen>().Enemyes.Contains(current_provincegen.state))
                    {
                        current_provincegen.SetStrictColor(DiplomacyModeEnemyColor);
                    }
                    if (ProtagonistState.GetComponent <stategen>().Allies.Contains(current_provincegen.state))
                    {
                        current_provincegen.SetStrictColor(DiplomacyModeAllyColor);
                    }
                    else
                    {
                        current_provincegen.SetStrictColor(Color.white);
                    }
                    current_provincegen.SetTextFieldValue("");
                }
                else
                {
                    float percentage = (float)(current_army - army_min) / (float)(army_max - army_min);
                    current_provincegen.ChangeColor(ArmyModeMinColor + (ArmyModeMaxColor - ArmyModeMinColor) * percentage);
                    current_provincegen.SetTextFieldValue(Convert.ToString(current_army));
                }
            }
        }
        else if (mode == CONSTRUCION_MODE)
        {
            int construction_min = 0, construction_max = 0;
            for (int i = 0; i < list_of_provinces.Count; i++)
            {
                GameObject  province                       = list_of_provinces[i];
                provincegen current_provincegen            = province.GetComponent <provincegen>();
                int         current_constructions_quantity = current_provincegen.GetConstructionsQuantity();
                if (i == 0)
                {
                    construction_min = current_constructions_quantity; construction_max = current_constructions_quantity;
                }
                if (current_constructions_quantity < construction_min)
                {
                    construction_min = current_constructions_quantity;
                }
                if (current_constructions_quantity > construction_max)
                {
                    construction_max = current_constructions_quantity;
                }
            }
            foreach (GameObject province in list_of_provinces)
            {
                provincegen current_provincegen = province.GetComponent <provincegen>();
                if (current_provincegen.state != ProtagonistState)
                {
                    current_provincegen.SetStrictColor(Color.white); current_provincegen.SetTextFieldValue("");
                }
                else
                {
                    float percentage;
                    int   current_constructions_quantity = current_provincegen.GetConstructionsQuantity();
                    if (construction_max - construction_min == 0)
                    {
                        percentage = 0;
                    }
                    else
                    {
                        percentage = (float)(current_constructions_quantity - construction_min) / (float)(construction_max - construction_min);
                    }
                    // Debug.Log(ConstructionModeMinColor + (ConstructionModeMaxColor - ConstructionModeMinColor) * percentage);
                    current_provincegen.ChangeColor(ConstructionModeMinColor + (ConstructionModeMaxColor - ConstructionModeMinColor) * percentage);
                    current_provincegen.SetTextFieldValue(String.Format("Farms-{0}\nFactory-{1}\nLibrary-{2}\nCastle-{3}", current_provincegen.Farms, current_provincegen.Factories, current_provincegen.Libraries, current_provincegen.Fortresses));
                }
            }
        }
        else if (mode == DIPLOMACY_MODE)
        {
            float DiplomacyDistanceMin = 0f;
            float DiplomacyDistanceMax = (float)Math.Pow(200f, 0.5f);
            foreach (GameObject province in list_of_provinces)
            {
                provincegen current_provincegen = province.GetComponent <provincegen>();
                // Debug.Log(current_provincegen);
                if (current_provincegen.state == ProtagonistState)
                {
                    current_provincegen.ChangeColor(DiplomacyModeProtagonistColor);
                    current_provincegen.SetTextFieldValue("");
                }
                else if (ProtagonistState.GetComponent <stategen>().Enemyes.Contains(current_provincegen.state))
                {
                    current_provincegen.ChangeColor(DiplomacyModeEnemyColor);
                    current_provincegen.SetTextFieldValue("In war");
                }
                else if (ProtagonistState.GetComponent <stategen>().Allies.Contains(current_provincegen.state))
                {
                    current_provincegen.ChangeColor(DiplomacyModeAllyColor);
                    current_provincegen.SetTextFieldValue("In alliance");
                }
                else
                {
                    try
                    {
                        float diplomacyDistance = stategen.GetDiplomacyDistance(ProtagonistState, current_provincegen.state);
                        float percentage        = diplomacyDistance / DiplomacyDistanceMax;
                        current_provincegen.ChangeColor(DiplomacyModeBestColor + (DiplomacyModeWorstColor - DiplomacyModeBestColor) * percentage);
                        current_provincegen.SetTextFieldValue(String.Format("{0}", diplomacyDistance));
                    }
                    catch (Exception)
                    {
                        current_provincegen.ChangeColor(Color.white);
                    }
                }
            }
        }
        else if (mode == SEPARATISM_MODE)
        {
            int separatism_min = 0, separatism_max = 0;
            for (int i = 0; i < list_of_provinces.Count; i++)
            {
                GameObject  province                       = list_of_provinces[i];
                provincegen current_provincegen            = province.GetComponent <provincegen>();
                int         current_constructions_quantity = current_provincegen.separatism;
                if (i == 0)
                {
                    separatism_min = current_constructions_quantity; separatism_max = current_constructions_quantity;
                }
                if (current_constructions_quantity < separatism_min)
                {
                    separatism_min = current_constructions_quantity;
                }
                if (current_constructions_quantity > separatism_max)
                {
                    separatism_max = current_constructions_quantity;
                }
            }
            foreach (GameObject province in list_of_provinces)
            {
                provincegen current_provincegen = province.GetComponent <provincegen>();
                if (current_provincegen.state != ProtagonistState)
                {
                    current_provincegen.SetStrictColor(Color.white); current_provincegen.SetTextFieldValue("");
                }
                else
                {
                    float percentage;
                    int   current_separatism = current_provincegen.separatism;
                    if (separatism_max - separatism_min == 0)
                    {
                        percentage = 0;
                    }
                    else
                    {
                        percentage = (float)(current_separatism - separatism_min) / (float)(separatism_max - separatism_min);
                    }
                    // Debug.Log(ConstructionModeMinColor + (ConstructionModeMaxColor - ConstructionModeMinColor) * percentage);

                    current_provincegen.ChangeColor(SeparatismModeMinColor + (SeparatismModeMaxColor - SeparatismModeMinColor) * percentage);
                    current_provincegen.SetTextFieldValue(String.Format("{0}", current_separatism));
                }
            }
        }
        else if (mode == NATURALRESOURCES_MODE || mode == EDUCATION_MODE || mode == CLIMATE_MODE)
        {
            int min_value = 0, max_value = 0;
            for (int i = 0; i < list_of_provinces.Count; i++)
            {
                provincegen pr = list_of_provinces[i].GetComponent <provincegen>();
                if (i == 0)
                {
                    if (mode == NATURALRESOURCES_MODE)
                    {
                        min_value = pr.natural_resources; max_value = pr.natural_resources;
                    }
                    if (mode == EDUCATION_MODE)
                    {
                        min_value = pr.education; max_value = pr.education;
                    }
                    if (mode == CLIMATE_MODE)
                    {
                        min_value = pr.climate; max_value = pr.climate;
                    }
                }
                else
                {
                    int current_value = 0;
                    if (mode == NATURALRESOURCES_MODE)
                    {
                        current_value = pr.natural_resources;
                    }
                    if (mode == EDUCATION_MODE)
                    {
                        current_value = pr.education;
                    }
                    if (mode == CLIMATE_MODE)
                    {
                        current_value = pr.climate;
                    }

                    if (current_value < min_value)
                    {
                        min_value = current_value;
                    }
                    if (current_value > max_value)
                    {
                        max_value = current_value;
                    }
                }
            }
            foreach (GameObject province in list_of_provinces)
            {
                provincegen pr            = province.GetComponent <provincegen>();
                int         current_value = 0;
                if (mode == NATURALRESOURCES_MODE)
                {
                    current_value = pr.natural_resources;
                }
                if (mode == EDUCATION_MODE)
                {
                    current_value = pr.education;
                }
                if (mode == CLIMATE_MODE)
                {
                    current_value = pr.climate;
                }

                float percentage = 0;
                if (max_value - min_value != 0)
                {
                    percentage = (float)(current_value - min_value) / (float)(max_value - min_value);
                }
                else
                {
                    percentage = 0;
                }

                Color color_min = Color.white, color_max = Color.white;
                if (mode == NATURALRESOURCES_MODE)
                {
                    color_min = NatresModeMinColor;
                }
                color_max = NatresModeMaxColor;
                if (mode == EDUCATION_MODE)
                {
                    color_min = EduModeMinColor;
                }
                color_max = EduModeMaxColor;
                if (mode == CLIMATE_MODE)
                {
                    color_min = ClimateModeMinColor;
                }
                color_max = ClimateModeMaxColor;

                pr.ChangeColor(color_min + (color_max - color_min) * percentage);
                pr.SetTextFieldValue(String.Format("{0}", current_value));
            }
        }
    }