public Hex getNeighbourRelative(Hex core, int up, bool right)
        {
            if (up > 1)
            {
                up = 1;
            }
            if (up < -1)
            {
                up = -1;
            }
            int x = core.x; int y = core.y;

            if (up == 0)
            {
                if (!right)
                {
                    if (canGet(x - 1, y))
                    {
                        return(grid[x - 1][y]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (canGet(x + 1, y))
                    {
                        return(grid[x + 1][y]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else if (y % 2 == 0)
            {//Even, add one
                if (right)
                {
                    if (canGet(x + 1, y + up))
                    {
                        return(grid[x + 1][y + up]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (canGet(x, y + up))
                    {
                        return(grid[x][y + up]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {//Odd, remove one
                if (right)
                {
                    if (canGet(x, y + up))
                    {
                        return(grid[x][y + up]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (canGet(x - 1, y + up))
                    {
                        return(grid[x - 1][y + up]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
 public bool isSea(Hex hex)
 {
     return(!landmass[hex.x][hex.y]);
 }
 public double getDist(Hex a, Hex b)
 {
     return(Math.Sqrt(getSqrDist(a, b)));
 }
 public override bool castable(Map map, Hex hex)
 {
     return(false);
 }
Example #5
0
        public override void cast(Map map, Hex hex)
        {
            base.cast(map, hex);


            ThreatItem item = hex.location.person().getGreatestThreat();

            if (item == null)
            {
                return;
            }

            string changes = "";

            foreach (Location loc in hex.location.getNeighbours())
            {
                if (loc.person() != null)
                {
                    Person other = loc.person();
                    foreach (ThreatItem t2 in other.threatEvaluations)
                    {
                        if (t2.isSame(item))
                        {
                            double delta = item.threat - t2.threat;
                            if (delta <= 0)
                            {
                                continue;
                            }
                            double liking = other.getRelation(hex.location.person()).getLiking();
                            if (liking <= 0)
                            {
                                continue;
                            }
                            liking /= 100;

                            double prev = t2.threat;
                            delta *= liking;
                            if (t2.threat + delta > 200)
                            {
                                delta = 200 - t2.threat;
                            }
                            t2.threat         += delta;
                            t2.temporaryDread += delta;

                            changes += other.getFullName() + " " + (int)(prev) + " -> " + (int)(t2.threat) + "; ";
                        }
                    }
                }
            }
            if (changes.Length > 0)
            {
                changes = changes.Substring(0, changes.Length - 2);//Strip the last separator
            }

            string msgs = "You spread " + hex.location.person().getFullName() + "'s fears of " + item.getTitle() + " to any neighbour who will listen. ";

            if (changes.Length > 0)
            {
                msgs += "\n" + changes;
            }
            else
            {
                msgs += "\nBut there are none.";
            }
            map.world.prefabStore.popImgMsg(
                msgs,
                map.world.wordStore.lookup("ABILITY_SPREAD_FEAR"));
        }
Example #6
0
        public override void cast(Map map, Hex hex)
        {
            base.cast(map, hex);
            if (!castable(map, hex))
            {
                return;
            }

            List <Location> targets = new List <Location>();

            targets.Add(hex.location);
            foreach (Location loc in hex.location.getNeighbours())
            {
                targets.Add(loc);
            }

            int prevHab  = (int)(100 * hex.getHabilitability());
            int prevTemp = (int)(100 * hex.getTemperature());

            double scaling = (24d * 32d) / (map.grid.Length * map.grid[0].Length);

            World.log("Scaling " + scaling);
            float delta = (float)(map.param.ability_deathOfTheSunTempChange * scaling);
            int   count = 0;

            int debug = Eleven.random.Next();

            foreach (Location loc in map.locations)
            {
                foreach (Property p in loc.properties)
                {
                    if (p.proto is Pr_RecentHumanBattle)
                    {
                        count += 1;
                    }
                }
            }
            delta *= count;

            foreach (Hex[] row in map.grid)
            {
                foreach (Hex h in row)
                {
                    h.transientTempDelta += delta;
                }
            }

            map.world.prefabStore.popImgMsg("The entire world cools, as the dead sap the life from the sun, leaving every location on the planet colder. " + count + " recent battles have been drawn upon.",
                                            map.world.wordStore.lookup("ABILITY_DEATH_OF_THE_SUN"));

            foreach (Location loc in map.locations)
            {
                Property rem = null;
                foreach (Property p in loc.properties)
                {
                    if (p.proto is Pr_RecentHumanBattle)
                    {
                        rem = p;
                    }
                }
                if (rem != null)
                {
                    loc.properties.Remove(rem);
                }
            }

            hex.map.assignTerrainFromClimate();
        }
 public override void cast(Map map, Hex hex)
 {
 }
Example #8
0
        public void checkData()
        {
            map = hex.map;
            gameObject.transform.localScale = new Vector3(GraphicalMap.scale, GraphicalMap.scale, 1);

            float dark      = 0.2f + (0.5f * hex.purity);
            float floraDark = 0.3f + (+0.7f * hex.purity);
            Color colour    = new Color(dark, dark, dark);

            if (hex.terrain == Hex.terrainType.SEA)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_sea;
            }
            else if (hex.terrain == Hex.terrainType.GRASS)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_grass;
            }
            else if (hex.terrain == Hex.terrainType.PATH)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_path;
            }
            //else if (hex.terrain == Hex.terrainType.FOREST)
            //{
            //    if (map.tempMap[hex.x][ hex.y] < 0.3f)
            //    {
            //        terrainLayer.sprite = world.textureStore.hex_terrain_snowforest;
            //    }
            //    else
            //    {
            //        terrainLayer.sprite = world.textureStore.hex_terrain_forest;
            //    }
            //}
            else if (hex.terrain == Hex.terrainType.SWAMP)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_swamp;
            }
            else if (hex.terrain == Hex.terrainType.MUD)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_path;
            }
            else if (hex.terrain == Hex.terrainType.DESERT)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_desert;
            }
            else if (hex.terrain == Hex.terrainType.DRY)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_dry;
            }
            else if (hex.terrain == Hex.terrainType.WETLAND)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_damp;
            }
            else if (hex.terrain == Hex.terrainType.SNOW)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_snow;
            }
            else if (hex.terrain == Hex.terrainType.TUNDRA)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_tundra;
            }
            else if (hex.terrain == Hex.terrainType.MOUNTAIN)
            {
                terrainLayer.sprite = world.textureStore.hex_terrain_mountain;
            }
            else
            {
                terrainLayer.sprite = world.textureStore.hex_base;
            }
            terrainLayer.color = colour;


            //setTerrainGraphicsSimplified();


            if (hex.location != null)
            {
                locLayer.enabled = true;
                locLayer.sprite  = hex.location.getSprite();
            }
            //else if (hex.terrain == Hex.terrainType.SEA && hex.amphibPoint)
            //{
            //    locLayer.enabled = true;
            //    locLayer.sprite = world.textureStore.hex_loc_lighthouse;
            //}
            else
            {
                locLayer.enabled = false;
            }



            if (hex.location != null)
            {
                if (nameTag == null)
                {
                    nameTag = world.prefabStore.getNameTag(hex.location.locName, Color.white);
                    nameTag.gameObject.transform.SetParent(transform);
                    nameTag.gameObject.transform.localPosition = new Vector3(0, -0.5f, -3.02f);
                    nameTag.gameObject.transform.localScale    = new Vector3(0.015f, 0.015f, 1);//This is apparently their default scale
                }
                else
                {
                    nameTag.gameObject.SetActive(true);
                    nameTag.gameObject.transform.localScale = new Vector3(0.015f, 0.015f, 1);//This is apparently their default scale
                }
                //Name tag now must exist, so can be given a name and color
                if (hex.location.settlement != null)
                {
                    nameTag.words.text = hex.location.settlement.name;
                    if (hex.location.soc == null)
                    {
                        nameTag.words.color = new Color(0.7f, 0.7f, 0.5f);
                    }
                    else
                    {
                        float brightness = hex.location.soc.color[0];
                        brightness += hex.location.soc.color[0];
                        brightness += hex.location.soc.color[0];
                        if (brightness > 0.5f)
                        {
                            nameTag.words.color = new Color(hex.location.soc.color[0], hex.location.soc.color[1], hex.location.soc.color[2]);
                        }
                        else
                        {
                            nameTag.words.color = new Color(0.7f, 0.7f, 0.5f);
                        }
                    }
                }
                else
                {
                    nameTag.words.text  = hex.location.locName;
                    nameTag.words.color = new Color(0.7f, 0.7f, 0.5f);
                }

                if (hex.location.soc != null)
                {
                    if (defenceTag == null)
                    {
                        defenceTag = world.prefabStore.getNameTag(hex.location.locName, Color.white);
                        defenceTag.gameObject.transform.SetParent(transform);
                        defenceTag.gameObject.transform.localPosition = new Vector3(0, -0.75f, -3.02f);
                        defenceTag.gameObject.transform.localScale    = new Vector3(0.015f, 0.015f, 1);//This is apparently their default scale
                    }
                    else
                    {
                        defenceTag.gameObject.SetActive(true);
                        defenceTag.gameObject.transform.localScale = new Vector3(0.015f, 0.015f, 1);//This is apparently their default scale
                    }
                    string strDef = "" + ((int)(hex.location.soc.currentMilitary + 0.5) + "/" + (int)(hex.location.soc.maxMilitary + 0.5));
                    if (hex.location.getMaxMilitaryDefence() > 0)
                    {
                        strDef += " +DEF " + (int)(hex.location.getMilitaryDefence() + 0.5) + "/" + (int)(0.5 + hex.location.getMaxMilitaryDefence());
                    }
                    defenceTag.words.text = strDef;
                }
                else
                {
                    if (defenceTag != null)
                    {
                        defenceTag.gameObject.SetActive(false);
                    }
                }

                /*
                 *
                 * if (hex.location.cloud == null)
                 * {
                 *  cloudLayer.sprite = null;
                 * }
                 * else
                 * {
                 *  cloudLayer.sprite = hex.location.cloud.getSprite(map);
                 * }
                 */
            }

            /*
             * if (hex.territoryOf != null && hex.territoryOf.soc != null && hex.territoryOf.soc.centralHex == hex)
             * {
             *  if (societyNameTag == null)
             *  {
             *      societyNameTag = world.prefabStore.getSocietyName(hex.territoryOf.soc.getName());
             *      societyNameTag.gameObject.transform.SetParent(transform);
             *      societyNameTag.gameObject.transform.localPosition = new Vector3(0, 0, -9.02f);
             *  }
             *  float scale = 1 + hex.territoryOf.soc.centralHexWidth;
             *  societyNameTag.gameObject.transform.localScale = new Vector3(scale, scale, 1);
             * }
             * else if (societyNameTag != null)
             * {
             *  Destroy(societyNameTag.gameObject);
             * }
             */


            if (hex.flora != null)
            {
                floraLayer.enabled = true;
                floraLayer.sprite  = hex.flora.getSprite();
                floraLayer.color   = new Color(floraDark, floraDark, floraDark);
            }
            else
            {
                floraLayer.enabled = false;
            }

            for (int i = 0; i < 6; i++)
            {
                bool shouldHaveDivider = true;
                bool shouldHaveBorder  = true;
                if (hex.owner == null)
                {
                    shouldHaveBorder = false;
                }                                                   //No need for borders at all

                bool right = false;
                int  y     = 0;
                if (i == 0)
                {
                    right = false; y = 0;
                }
                else if (i == 1)
                {
                    right = false; y = -1;
                }
                else if (i == 2)
                {
                    right = true; y = -1;
                }
                else if (i == 3)
                {
                    right = true; y = 0;
                }
                else if (i == 4)
                {
                    right = true; y = 1;
                }
                else if (i == 5)
                {
                    right = false; y = 1;
                }

                Hex neighbour = map.getNeighbourRelative(hex, y, right);
                if (neighbour == null)
                {
                    shouldHaveBorder = false; shouldHaveDivider = false;
                }
                if (neighbour != null && neighbour.owner == hex.owner)
                {
                    shouldHaveBorder = false;
                }
                if (neighbour != null && neighbour.territoryOf == hex.territoryOf)
                {
                    shouldHaveDivider = false;
                }
                if (neighbour != null && neighbour.terrain == Hex.terrainType.SEA)
                {
                    shouldHaveDivider = false;
                }
                if (hex.terrain == Hex.terrainType.SEA)
                {
                    shouldHaveDivider = false;
                }
                if (neighbour != null && neighbour.terrain == Hex.terrainType.SEA)
                {
                    if (neighbour.owner == null)
                    {
                        shouldHaveBorder = false;
                    }
                }


                //Temporarily disabling these altogether, to see how it looks
                shouldHaveDivider = false;

                if (shouldHaveBorder || shouldHaveDivider)
                {
                    if (borders[i] == null)
                    {
                        borders[i] = world.prefabStore.getHexEdgeSprite();
                        borders[i].transform.SetParent(transform);
                        borders[i].transform.localPosition = new Vector3(0, 0, -0.01f);
                        borders[i].transform.Rotate(new Vector3(0, 0, 60 * (i + 3)));
                    }
                    if (shouldHaveBorder && borders2[i] == null)
                    {
                        borders2[i] = world.prefabStore.getHexEdge2Sprite();
                        borders2[i].transform.SetParent(transform);
                        borders2[i].transform.localPosition = new Vector3(0, 0, -0.011f);
                        borders2[i].transform.Rotate(new Vector3(0, 0, 60 * (i + 3)));
                    }
                }

                if (shouldHaveBorder)
                {
                    borders[i].SetActive(true);
                    if (borders[i] != null)
                    {
                        borders[i].GetComponent <SpriteRenderer>().color = new Color(hex.owner.color[0], hex.owner.color[1], hex.owner.color[2]);
                    }

                    borders2[i].SetActive(true);
                    borders2[i].GetComponent <SpriteRenderer>().color = new Color(hex.owner.color2[0], hex.owner.color2[1], hex.owner.color2[2]);
                }
                else if (!shouldHaveBorder && shouldHaveDivider)
                {
                    borders[i].SetActive(true);
                    if (borders[i] != null)
                    {
                        borders[i].GetComponent <SpriteRenderer>().color = pale;
                    }

                    if (borders2[i] != null)
                    {
                        borders2[i].SetActive(false);
                    }
                }
                else
                {
                    if (borders[i] != null)
                    {
                        borders[i].SetActive(false);
                    }
                    if (borders2[i] != null)
                    {
                        borders2[i].SetActive(false);
                    }
                }
            }

            if (map != null && map.masker.applyMask(this.hex))
            {
                mask.color   = map.masker.getColor(hex);
                mask.enabled = true;
            }
            else
            {
                mask.enabled = false;
            }


            //Reset all these, because they can spawn wrong somehow
            for (int i = 0; i < 6; i++)
            {
                if (borders[i] != null)
                {
                    borders[i].gameObject.transform.localScale = new Vector3(1, 1, 1);
                }
                if (borders2[i] != null)
                {
                    borders2[i].gameObject.transform.localScale = new Vector3(1, 1, 1);
                }
            }

            if (hex.location != null)
            {
                foreach (Property p in hex.location.properties)
                {
                    if (p.outer == null)
                    {
                        p.outer = map.world.prefabStore.getGraphicalProperty(map, p);
                    }
                }
            }
        }
Example #9
0
        public override void cast(Map map, Hex hex)
        {
            base.cast(map, hex);

            castInner(map, hex.location.person());
        }
        public Color getColor(Hex hex)
        {
            if (mask == maskType.NONE)
            {
                if (GraphicalMap.selectedSelectable != null && GraphicalMap.selectedSelectable is Unit)
                {
                    if (hex.owner != null && hex.owner.hostileTo((Unit)GraphicalMap.selectedSelectable))
                    {
                        return(new Color(0.5f, 0.0f, 0f, 0.5f));
                    }
                }
                return(Color.clear);
            }
            else if (mask == maskType.NATION)
            {
                if (hex.owner != null)
                {
                    float r     = hex.owner.color.r;
                    float g     = hex.owner.color.g;
                    float b     = hex.owner.color.b;
                    Color color = new Color(r, g, b, 0.8f);
                    return(color);
                }
                else
                {
                    return(new Color(0.5f, 0.5f, 0.5f, 0.5f));
                }
            }
            else if (mask == maskType.PROVINCE)
            {
                return(new Color(hex.province.cr, hex.province.cg, hex.province.cb, 0.5f));
            }
            else if (mask == maskType.INFORMATION)
            {
                if (hex.location != null && GraphicalMap.selectedHex != null && GraphicalMap.selectedHex.location != null && GraphicalMap.selectedHex.location.soc != null)
                {
                    SocialGroup group = GraphicalMap.selectedHex.location.soc;

                    float mult = (float)map.getInformationAvailability(hex.location, group);
                    mult = Mathf.Max(0, mult);
                    mult = Mathf.Min(1, mult);
                    float r = mult;
                    float g = mult;
                    float b = mult;

                    //Color color = new Color(r, g, b, 0.8f);
                    Color color = new Color(0, 0, 0, (1 - mult));
                    return(color);
                }
                else if (hex.location != null)
                {
                    return(new Color(0f, 0f, 0f, 1f));
                }
                else
                {
                    return(new Color(0f, 0f, 0f, 0.75f));
                }
            }
            else if (mask == maskType.VOTE_EFFECT)
            {
                if (GraphicalMap.selectedHex != null && GraphicalMap.selectedHex.location != null && GraphicalMap.selectedHex.location.person() != null && hex.location != null && hex.location.soc != null)
                {
                    if (GraphicalMap.selectedHex == hex)
                    {
                        return(new Color(1f, 1f, 1f, 0.5f));
                    }
                    Person voter = GraphicalMap.selectedHex.location.person();
                    if (hex.location.soc == voter.society)
                    {
                        if (hex.location.person() != null && hex.location.soc is Society)
                        {
                            Society soc = (Society)hex.location.soc;
                            if (soc.voteSession == null)
                            {
                                return(new Color(0f, 0f, 0f, 0.75f));
                            }
                            VoteOption opt = null;
                            foreach (VoteOption o2 in soc.voteSession.issue.options)
                            {
                                if (o2.votesFor.Contains(voter))
                                {
                                    opt = o2;
                                    break;
                                }
                            }
                            if (opt == null)
                            {
                                soc.voteSession.assignVoters();
                            }
                            foreach (VoteOption o2 in soc.voteSession.issue.options)
                            {
                                if (o2.votesFor.Contains(voter))
                                {
                                    opt = o2;
                                    break;
                                }
                            }
                            if (soc.voteSession != null)
                            {
                                float delta = (float)soc.voteSession.issue.getLikingDelta(hex.location.person(), opt, soc.voteSession.issue);
                                delta /= 25;
                                if (delta > 1)
                                {
                                    delta = 1f;
                                }
                                if (delta < -1)
                                {
                                    delta = -1f;
                                }
                                if (delta >= 0)
                                {
                                    return(new Color(0f, delta, 0f, 0.75f));
                                }
                                else
                                {
                                    return(new Color(-delta, 0f, 0f, 0.75f));
                                }
                            }
                        }
                    }
                }
                return(new Color(0f, 0f, 0f, 0.75f));
            }
            else if (mask == maskType.THREAT)
            {
                if (hex.location != null && GraphicalMap.selectedHex != null && GraphicalMap.selectedHex.location != null && GraphicalMap.selectedHex.location.settlement != null && GraphicalMap.selectedHex.location.settlement.title != null && GraphicalMap.selectedHex.location.settlement.title.heldBy != null)
                {
                    SocialGroup group = GraphicalMap.selectedHex.location.soc;

                    Person p             = GraphicalMap.selectedHex.settlement.title.heldBy;
                    double highestThreat = 0;
                    foreach (ThreatItem item in p.threatEvaluations)
                    {
                        if (item.group != null && item.threat > highestThreat)
                        {
                            highestThreat = item.threat;
                        }
                    }
                    if (highestThreat != 0)
                    {
                        if (hex.location.soc == null)
                        {
                            return(Color.black);
                        }
                        double threat = 0;
                        foreach (ThreatItem item in p.threatEvaluations)
                        {
                            if (item.group == hex.location.soc)
                            {
                                threat = item.threat / highestThreat; break;
                            }
                        }
                        float mult = (float)threat;
                        mult = Mathf.Max(0, mult);
                        mult = Mathf.Min(1, mult);
                        float r = mult;
                        float g = mult;
                        float b = mult;

                        //Color color = new Color(r, g, b, 0.8f);
                        Color color = new Color(mult, 0, 0, 0.5f);
                        return(color);
                    }
                    else
                    {
                        return(Color.black);
                    }
                }
                else if (hex.location != null)
                {
                    return(new Color(0f, 0f, 0f, 1f));
                }
                else
                {
                    return(new Color(0f, 0f, 0f, 0.75f));
                }
            }

            else if (mask == maskType.LIKING_THEM)
            {
                Color c = new Color(0, 0, 0, 0.5f);
                try
                {
                    Person me = null;
                    if (GraphicalMap.selectedSelectable is Unit)
                    {
                        if (((Unit)GraphicalMap.selectedSelectable).person != null)
                        {
                            me = ((Unit)GraphicalMap.selectedSelectable).person;
                        }
                    }
                    else
                    {
                        me = GraphicalMap.selectedHex.location.settlement.title.heldBy;
                    }

                    Person them   = hex.location.settlement.title.heldBy;
                    float  liking = (float)them.getRelation(me).getLiking();
                    if (liking > 0)
                    {
                        if (liking > 100)
                        {
                            liking = 100;
                        }
                        liking /= 100;
                        c       = new Color(0, liking, 0, 0.5f);
                    }
                    else
                    {
                        liking *= -1;
                        if (liking > 100)
                        {
                            liking = 100;
                        }
                        liking /= 100;
                        c       = new Color(liking, 0, 0, 0.5f);
                    }
                }
                catch (NullReferenceException e)
                {
                }
                catch (ArgumentNullException e)
                {
                }
                return(c);
            }

            else if (mask == maskType.LIKING_ME)
            {
                Color c = new Color(0, 0, 0, 0.5f);
                try
                {
                    Person me = null;
                    if (GraphicalMap.selectedSelectable is Unit)
                    {
                        if (((Unit)GraphicalMap.selectedSelectable).person != null)
                        {
                            me = ((Unit)GraphicalMap.selectedSelectable).person;
                        }
                    }
                    else
                    {
                        me = GraphicalMap.selectedHex.location.settlement.title.heldBy;
                    }
                    Person them   = hex.location.settlement.title.heldBy;
                    float  liking = (float)me.getRelation(them).getLiking();
                    if (liking > 0)
                    {
                        if (liking > 100)
                        {
                            liking = 100;
                        }
                        liking /= 100;
                        c       = new Color(0, liking, 0, 0.5f);
                    }
                    else
                    {
                        liking *= -1;
                        if (liking > 100)
                        {
                            liking = 100;
                        }
                        liking /= 100;
                        c       = new Color(liking, 0, 0, 0.5f);
                    }
                }
                catch (NullReferenceException e)
                {
                }
                catch (ArgumentNullException e)
                {
                }
                return(c);
            }
            else if (mask == maskType.AWARENESS)
            {
                try
                {
                    Person them = hex.settlement.title.heldBy;

                    return(new Color((float)them.awareness, 0, 0, 0.9f));
                }
                catch (Exception e)
                {
                    return(new Color(0, 0, 0, 0.9f));
                }
            }
            else if (mask == maskType.SUSPICION)
            {
                try
                {
                    Person me   = GraphicalMap.selectedHex.settlement.title.heldBy;
                    Person them = hex.settlement.title.heldBy;
                    RelObj rel  = me.getRelation(them);

                    return(new Color((float)rel.suspicion, 0, 0, 0.5f));
                }catch (Exception e)
                {
                    return(new Color(0, 0, 0, 0.5f));
                }
            }
            else if (mask == maskType.SUSPICION_FROM)
            {
                try
                {
                    Person them = GraphicalMap.selectedHex.settlement.title.heldBy;
                    Person me   = hex.settlement.title.heldBy;
                    RelObj rel  = me.getRelation(them);

                    return(new Color((float)rel.suspicion, 0, 0, 0.5f));
                }
                catch (Exception e)
                {
                    return(new Color(0, 0, 0, 0.5f));
                }
            }
            else if (mask == maskType.TESTING)
            {
                if (hex.location != null)
                {
                    if (hex.location.debugVal == map.turn)
                    {
                        return(new Color(1, 1, 1, 0.5f));
                    }
                    else
                    {
                        return(new Color(0, 0, 0, 0.5f));
                    }
                }

                return(new Color(0f, 0f, 0f, 0.75f));
            }
            else
            {
                return(new Color(0, 0, 0, 0));
            }
        }
        public string getBodyText()
        {
            if (mask == maskType.LIKING_ME)
            {
                try
                {
                    Hex    hex = GraphicalMap.getHexUnderMouse(Input.mousePosition).hex;
                    Person me  = null;
                    if (GraphicalMap.selectedSelectable is Unit)
                    {
                        if (((Unit)GraphicalMap.selectedSelectable).person != null)
                        {
                            me = ((Unit)GraphicalMap.selectedSelectable).person;
                        }
                    }
                    else
                    {
                        me = GraphicalMap.selectedHex.location.settlement.title.heldBy;
                    }
                    Person them = hex.location.settlement.title.heldBy;

                    if (me.state == Person.personState.enthralled)
                    {
                        return(me.getFullName() + " is enthralled, so does not have normal likings.");
                    }
                    string words = me.getFullName() + " liking for " + them.getFullName();
                    RelObj rel   = me.getRelation(them);
                    words += "\nAmount: " + ((int)rel.getLiking());

                    double sus = rel.getDislikingFromSuspicion();
                    if (sus != 0)
                    {
                        words += "\nFROM SUSPICION: " + (int)sus;
                    }

                    List <ReasonMsg> msgs = new List <ReasonMsg>();
                    RelObj.getLikingModifiers(me, them, msgs);
                    foreach (ReasonMsg msg in msgs)
                    {
                        words += "\n\n  -" + msg.msg + " " + ((int)msg.value);
                    }

                    List <RelEvent> sortedEvents = new List <RelEvent>();
                    sortedEvents.AddRange(rel.events);
                    sortedEvents.Sort();
                    int nPrinted = 0;
                    foreach (RelEvent ev in sortedEvents)
                    {
                        words    += "\n\n  -" + ev.reason + " : " + ((int)ev.amount);
                        nPrinted += 1;
                        if (nPrinted > 6)
                        {
                            break;
                        }
                    }
                    return(words);
                }
                catch (Exception e)
                {
                    return("");
                }
            }
            else if (mask == maskType.LIKING_THEM)
            {
                try
                {
                    Hex    hex  = GraphicalMap.getHexUnderMouse(Input.mousePosition).hex;
                    Person them = null;
                    if (GraphicalMap.selectedSelectable is Unit)
                    {
                        if (((Unit)GraphicalMap.selectedSelectable).person != null)
                        {
                            them = ((Unit)GraphicalMap.selectedSelectable).person;
                        }
                    }
                    else
                    {
                        them = GraphicalMap.selectedHex.location.settlement.title.heldBy;
                    }
                    Person me = hex.location.settlement.title.heldBy;

                    if (me.state == Person.personState.enthralled)
                    {
                        return(me.getFullName() + " is enthralled, so does not have normal likings.");
                    }

                    string words = me.getFullName() + " liking for " + them.getFullName();
                    RelObj rel   = me.getRelation(them);
                    words += "\nAmount: " + ((int)rel.getLiking());

                    double sus = rel.getDislikingFromSuspicion();
                    if (sus != 0)
                    {
                        words += "\nFROM SUSPICION: " + (int)sus;
                    }

                    List <ReasonMsg> msgs = new List <ReasonMsg>();
                    RelObj.getLikingModifiers(me, them, msgs);
                    foreach (ReasonMsg msg in msgs)
                    {
                        words += "\n\n  -" + msg.msg + " " + ((int)msg.value);
                    }

                    List <RelEvent> sortedEvents = new List <RelEvent>();
                    sortedEvents.AddRange(rel.events);
                    sortedEvents.Sort();
                    int nPrinted = 0;
                    foreach (RelEvent ev in sortedEvents)
                    {
                        words    += "\n\n  -" + ev.reason + " : " + ((int)ev.amount);
                        nPrinted += 1;
                        if (nPrinted > 6)
                        {
                            break;
                        }
                    }
                    return(words);
                }
                catch (Exception e)
                {
                    return("");
                }
            }
            else if (mask == maskType.VOTE_EFFECT)
            {
                if (GraphicalMap.selectedHex != null && GraphicalMap.selectedHex.location != null && GraphicalMap.selectedHex.location.person() != null)
                {
                    Person  voter = GraphicalMap.selectedHex.location.person();
                    Society soc   = (Society)voter.society;
                    if (soc.voteSession == null)
                    {
                        return("No voting currently happening in " + voter.getFullName() + "'s society");
                    }
                    VoteOption opt = soc.voteSession.issue.options[0];
                    foreach (VoteOption o2 in soc.voteSession.issue.options)
                    {
                        if (o2.votesFor.Contains(voter))
                        {
                            opt = o2;
                            break;
                        }
                    }
                    return("The change in liking towards " + voter.getFullName() + " if they vote for their currently preferred option (" + opt.info(soc.voteSession.issue) + ").");
                }
            }
            return("");
        }
        public override void turnTick(Hex hex)
        {
            //if (Eleven.random.Next(2) == 0) {
            age += 1;
            //}
            if (age > 6)
            {
                hex.cloud = null;
            }
            else
            {
                int c      = 0;
                Hex target = null;
                for (int i = -1; i <= 1; i++)
                {
                    int x = i + hex.x;
                    if (x < 0)
                    {
                        continue;
                    }
                    if (x >= hex.map.sizeX)
                    {
                        continue;
                    }
                    for (int j = -1; j <= 1; j++)
                    {
                        int y = j + hex.y;
                        if (y < 0)
                        {
                            continue;
                        }
                        if (y >= hex.map.sizeY)
                        {
                            continue;
                        }

                        if (hex.map.grid[x][y].cloud == null || hex.map.grid[x][y].cloud is Cloud_Fog)
                        {
                            c += 1;
                            if (Eleven.random.Next(c) == 0)
                            {
                                target = hex.map.grid[x][y];
                            }
                        }
                    }
                }
                if (target != null)
                {
                    if (target.cloud == null)
                    {
                        target.cloud = this;
                        Cloud_Fog child = new Cloud_Fog();
                        child.age = this.age + 1;
                        hex.cloud = child;
                    }
                    else if (this.age < maxAge - 2)
                    {
                        Cloud_Fog recipient = (Cloud_Fog)target.cloud;
                        if (recipient.age >= this.age - 2)
                        {
                            recipient.age -= 2;
                            this.age      += 2;
                        }
                    }
                }
            }
        }
        public void checkData()
        {
            Hex hex = GraphicalMap.selectedHex;

            if (World.staticMap != null)
            {
                bool canUsePower   = master.world.map.overmind.power > 0;
                bool canUseAbility = true;
                bool canVote       = hex != null && hex.location != null && hex.location.soc != null && hex.location.soc is Society && ((Society)hex.location.soc).voteSession != null;

                if (World.staticMap.param.overmind_singleAbilityPerTurn && master.world.map.overmind.hasTakenAction)
                {
                    canUsePower   = false;
                    canUseAbility = false;
                }

                if (master.state == UIMaster.uiState.WORLD)
                {
                    if (GraphicalMap.selectedSelectable == null)
                    {
                        abilityButtonText.text = "Use Ability (" + master.world.map.overmind.countAvailableAbilities(hex) + ")";
                        powerButtonText.text   = "Use Power (" + master.world.map.overmind.countAvailablePowers(hex) + ")";
                    }
                    else if (GraphicalMap.selectedSelectable is Unit)
                    {
                        abilityButtonText.text = "Use Ability (" + master.world.map.overmind.countAvailableAbilities((Unit)GraphicalMap.selectedSelectable) + ")";
                        powerButtonText.text   = "Use Power (" + master.world.map.overmind.countAvailablePowers((Unit)GraphicalMap.selectedSelectable) + ")";
                        canVote = ((Unit)GraphicalMap.selectedSelectable).person != null && ((Unit)GraphicalMap.selectedSelectable).person.state == Person.personState.enthralledAgent;
                    }
                    else
                    {
                        canUseAbility = false;
                        canUsePower   = false;
                        canVote       = false;
                    }
                }
                else if (master.state == UIMaster.uiState.SOCIETY)
                {
                    if (GraphicalSociety.focus == null)
                    {
                        canUseAbility = false;
                        canUsePower   = false;
                    }
                    abilityButtonText.text = "Use Ability (" + master.world.map.overmind.countAvailableAbilities(GraphicalSociety.focus) + ")";
                    powerButtonText.text   = "Use Power (" + master.world.map.overmind.countAvailablePowers(GraphicalSociety.focus) + ")";
                }
                powerButton.gameObject.SetActive(canUsePower);
                abilityButton.gameObject.SetActive(canUseAbility);
                votingButton.gameObject.SetActive(canVote);

                personAwarenessBlock.SetActive(World.staticMap.param.useAwareness == 1);
            }


            if (master.state == UIMaster.uiState.WORLD)
            {
                maskTitle.text = GraphicalMap.map.masker.getTitleText();
            }
            locText.text = "";

            //Disable all, re-enable as per need
            screenSociety.SetActive(false);
            screenPerson.SetActive(false);
            screenLocation.SetActive(false);
            uiUnit.gameObject.SetActive(false);

            if (GraphicalMap.selectedSelectable != null && GraphicalMap.selectedSelectable is Unit)
            {
                uiUnit.setTo((Unit)GraphicalMap.selectedSelectable);
                uiUnit.gameObject.SetActive(true);
            }
            else if (GraphicalMap.selectedSelectable != null && GraphicalMap.selectedSelectable is Property)
            {
                Property sel = (Property)GraphicalMap.selectedSelectable;
                screenSociety.SetActive(true);
                setToEmpty();

                socTitle.text    = sel.proto.name;
                socTypeDesc.text = "Effects remain bound to locations, regardless of societal and political change, until they expire or are dispelled by another means." +
                                   " \n(Rapidly select a location without selecting properties by holding CTRL while clicking on it)";
                if (sel.proto.decaysOverTime)
                {
                    title.text        = sel.proto.name;
                    socTypeTitle.text = "Turns Remaining: " + sel.charge;
                }
                else
                {
                    title.text        = sel.proto.name;
                    socTypeTitle.text = "Indefinite Effect";
                    socTypeDesc.text  = "Effects remain bound to locations, regardless of societal and political change. This one decays over time.";
                }
                string bodyText = sel.proto.getDescription();
                body.text = bodyText;
            }
            else if (state == tabState.PERSON)
            {
                screenPerson.SetActive(true);
                if (master.state == UIMaster.uiState.SOCIETY && GraphicalSociety.focus != null)
                {
                    Person p = GraphicalSociety.focus;
                    showPersonInfo(p);
                }
                else if (hex != null && hex.settlement != null && hex.settlement.title != null && hex.settlement.title.heldBy != null)
                {
                    Person p = hex.settlement.title.heldBy;
                    showPersonInfo(p);
                }
                else
                {
                    setToEmpty();
                }
            }
            else if (state == tabState.LOCATION)
            {
                screenLocation.SetActive(true);
                showLocationInfo();
            }
            else if (state == tabState.SOCIETY)
            {
                screenSociety.SetActive(true);
                flag1.color = Color.clear;
                flag2.color = Color.clear;
                if (hex != null && hex.location != null && hex.location.soc != null)
                {
                    flag1.color  = hex.location.soc.color;
                    flag2.color  = hex.location.soc.color2;
                    title.text   = GraphicalMap.selectedHex.getName();
                    locText.text = "";
                    if (GraphicalMap.selectedHex.location != null && GraphicalMap.selectedHex.location.soc != null)
                    {
                        socTitle.text = GraphicalMap.selectedHex.location.soc.getName();
                    }
                    else
                    {
                        socTitle.text = "";
                    }
                    string bodyText = "";
                    //bodyText += "Body text for hex " + GraphicalMap.selectedHex.getName();
                    //bodyText += "\nAttachedTo " + GraphicalMap.selectedHex.territoryOf.hex.getName();

                    if (hex.location.settlement != null && hex.location.settlement.title != null)
                    {
                        if (hex.location.settlement.title.heldBy != null)
                        {
                            bodyText += "\nTitle held by: " + hex.location.settlement.title.heldBy.getFullName();
                        }
                        else
                        {
                            bodyText += "\nTitle currently unheld";
                        }
                    }
                    bodyText         += "\nSocial group: " + hex.location.soc.getName();
                    socTypeTitle.text = hex.location.soc.getTypeName();
                    socTypeDesc.text  = hex.location.soc.getTypeDesc();
                    if (hex.location.soc is Society)
                    {
                        Society locSoc = (Society)hex.location.soc;

                        if (locSoc.voteSession != null)
                        {
                            bodyText += "\nVoting on: " + locSoc.voteSession.issue.ToString();
                            bodyText += "\nTurns Remaining: " + locSoc.voteSession.timeRemaining;
                        }

                        string econEffects = "";
                        foreach (EconEffect effect in locSoc.econEffects)
                        {
                            econEffects += "Econ from " + effect.from.name + " to " + effect.to.name + "\n";
                        }
                        socEcon.text = econEffects;


                        bodyText += "\nMILITARY POSTURE: " + locSoc.posture;
                        if (locSoc.offensiveTarget != null)
                        {
                            bodyText += "\nOffensive: " + locSoc.offensiveTarget.getName();
                        }
                        else
                        {
                            bodyText += "\nOffensive: None";
                        }
                        if (locSoc.defensiveTarget != null)
                        {
                            bodyText += "\nDefensive: " + locSoc.defensiveTarget.getName();
                        }
                        else
                        {
                            bodyText += "\nDefensive: None";
                        }
                        bodyText += "\nRebel cap " + locSoc.data_rebelLordsCap;
                        bodyText += "\nLoyal cap " + locSoc.data_loyalLordsCap;
                        bodyText += "\nStability: " + (int)(locSoc.data_societalStability * 100) + "%";
                        if (locSoc.instabilityTurns > 0)
                        {
                            bodyText += "\nTURNS TILL CIVIL WAR: " + (locSoc.map.param.society_instablityTillRebellion - locSoc.instabilityTurns);
                        }
                    }
                    body.text = bodyText;

                    string           strThreat = "";
                    List <ReasonMsg> msgs      = new List <ReasonMsg>();
                    double           threat    = hex.location.soc.getThreat(msgs);
                    strThreat += "Threat: " + (int)threat;
                    foreach (ReasonMsg msg in msgs)
                    {
                        strThreat += "\n   " + msg.msg + " " + (int)msg.value;
                    }
                    socThreat.text = strThreat;
                }
                else
                {
                    this.setToEmpty();
                }
            }
        }
        public void showLocationInfo()
        {
            if (GraphicalMap.selectedHex == null || GraphicalMap.selectedHex.location == null)
            {
                locInfoTitle.text   = "No location selected";
                locInfoBody.text    = "No location selected";
                locNumsBody.text    = "";
                locNumsNumbers.text = "";
                locFlavour.text     = "";
            }
            else
            {
                Map      map = World.staticMap;
                Location loc = GraphicalMap.selectedHex.location;
                locInfoTitle.text = loc.getName();
                string bodyText = "";
                double hab      = loc.hex.getHabilitability() - map.param.mapGen_minHabitabilityForHumans;
                hab *= 1d / (1 - map.param.mapGen_minHabitabilityForHumans);


                string valuesBody    = "";
                string valuesNumbers = "";

                Hex hex = loc.hex;
                bodyText += "\nProvince: " + hex.province.name;
                foreach (EconTrait t in hex.province.econTraits)
                {
                    bodyText += "\nIndustry: " + t.name;
                }

                if (hex.location != null)
                {
                    if (hex.location.settlement != null)
                    {
                        if (hex.location.settlement.title != null)
                        {
                            if (hex.location.settlement.title.heldBy != null)
                            {
                                bodyText += "\nTitle held by: " + hex.location.settlement.title.heldBy.getFullName();
                            }
                            else
                            {
                                bodyText += "\nTitle currently unheld";
                            }
                        }
                        valuesBody    += "\nPrestige:";
                        valuesNumbers += "\n" + Eleven.toMaxLen(hex.location.settlement.getPrestige(), 4);
                        valuesBody    += "\nBase Prestige:";
                        valuesNumbers += "\n" + Eleven.toMaxLen(hex.location.settlement.basePrestige, 4);
                        valuesBody    += "\nMilitary Cap Add:";
                        valuesNumbers += "\n" + hex.location.settlement.getMilitaryCap();
                        valuesBody    += "\nMilitary Regen";
                        valuesNumbers += "\n" + hex.location.settlement.militaryRegenAdd;
                    }
                }

                if (loc.settlement != null)
                {
                    locFlavour.text = loc.settlement.getFlavour();
                    if (loc.settlement is Set_City)
                    {
                        valuesBody    += "\n" + ((Set_City)loc.settlement).getStatsDesc();
                        valuesNumbers += "\n" + ((Set_City)loc.settlement).getStatsValues();
                    }
                }

                valuesBody    += "\nTemperature ";
                valuesNumbers += "\n" + (int)(loc.hex.getTemperature() * 100) + "%";
                valuesBody    += "\nHabilitability ";
                valuesNumbers += "\n" + (int)(hab * 100) + "%";

                locNumsBody.text    = valuesBody;
                locNumsNumbers.text = valuesNumbers;
                locInfoBody.text    = bodyText;
            }
        }
Example #15
0
        public void clickOnHex()
        {
            Hex clickedHex = GraphicalMap.getHexUnderMouse(Input.mousePosition).hex;



            if (Input.GetKey(KeyCode.LeftControl))
            {
                GraphicalMap.selectedSelectable = null;
                GraphicalMap.selectedHex        = clickedHex;
                world.audioStore.playClick();
                return;
            }
            world.ui.checkData();


            if (clickedHex.location != null)
            {
                List <object> selectables = new List <object>();
                foreach (object o in clickedHex.location.units)
                {
                    selectables.Add(o);
                }
                foreach (object o in clickedHex.location.properties)
                {
                    selectables.Add(o);
                }
                int index = -1;
                if (GraphicalMap.selectedSelectable != null)
                {
                    index = selectables.IndexOf(GraphicalMap.selectedSelectable);
                }
                if (index == -1)//Nothing from this loc selected yet
                {
                    index = 0;
                }
                else
                {
                    index += 1;
                }
                //See if we're out of selectables (including if there were none)
                if (index >= selectables.Count)
                {
                    GraphicalMap.selectedSelectable = null;
                    GraphicalMap.selectedHex        = clickedHex;
                    world.audioStore.playClick();
                    world.ui.checkData();
                    return;
                }
                else
                {
                    GraphicalMap.selectedSelectable = selectables[index];
                    GraphicalMap.selectedHex        = clickedHex;
                    world.audioStore.playClick();
                    world.ui.checkData();
                    return;
                }
            }

            GraphicalMap.selectedSelectable = null;
            GraphicalMap.selectedHex        = clickedHex;
            world.audioStore.playClick();
            world.ui.checkData();
        }
Example #16
0
 public abstract bool castable(Map map, Hex hex);