public void adjacentMoveTo(Unit u, Location loc)
 {
     foreach (Unit u2 in loc.units)
     {
         if (u2.isMilitary)
         {
             if (u != u2 && u.hostileTo(u2))
             {
                 combatAction(u, u2, loc);
                 return;
             }
         }
     }
     //Check agent combat after military unit combat
     foreach (Unit u2 in loc.units)
     {
         if (!u2.isMilitary)
         {
             if (u != u2 && u.hostileTo(u2))
             {
                 combatAction(u, u2, loc);
                 return;
             }
         }
     }
     u.location.units.Remove(u);
     loc.units.Add(u);
     u.location = loc;
 }
Example #2
0
        public void checkData()
        {
            if (unit.person != null && unit.person.state == Person.personState.enthralledAgent)
            {
                borderLayer1.color = Color.black;
                borderLayer2.color = Color.black;
            }
            else if (unit.society == null || unit.dontDisplayBorder)
            {
                borderLayer1.color = Color.clear;
                borderLayer2.color = Color.clear;
            }
            else
            {
                borderLayer1.color = unit.society.color;
                borderLayer2.color = unit.society.color2;
            }

            hpText.text = unit.hp + "/" + unit.maxHp;

            /*
             * hpBar.SetActive(unit.isMilitary);
             * if (unit.isMilitary)
             * {
             *  hpText.text = "" + (int)(unit.getStrength());
             * }
             * unitLayer.sprite = unit.getSprite();
             */

            this.hostilityBorder.enabled = false;
            if (GraphicalMap.selectedSelectable != null && GraphicalMap.selectedSelectable is Unit)
            {
                Unit other = (Unit)GraphicalMap.selectedSelectable;
                if (unit.hostileTo(other))
                {
                    this.hostilityBorder.enabled = true;
                    this.hostilityBorder.color   = Color.red;
                }
                else if (unit.person != null && other.person != null && unit.person.getRelation(other.person).suspicion > 0)
                {
                    this.hostilityBorder.enabled = true;
                    this.hostilityBorder.color   = Color.yellow;
                }
            }
        }
Example #3
0
 public virtual bool hostileTo(Unit other, bool allowRecursion = true)
 {
     if (this == other)
     {
         return(false);
     }
     if (this.society.hostileTo(other))
     {
         return(true);
     }
     if (this.isEnthralled() && other.flaggedAsEnthralledHostile)
     {
         return(true);
     }
     if (allowRecursion && other.hostileTo(this, false))
     {
         return(true);
     }
     return(hostility.Contains(other));
 }
Example #4
0
 public void adjacentMoveTo(Unit u, Location loc)
 {
     foreach (Unit u2 in loc.units)
     {
         if (u.hostileTo(u2))
         {
             world.prefabStore.particleCombat(u.location.hex, u2.location.hex);
             u2.hp -= 1;
             if (u2.isEnthralled())
             {
                 world.prefabStore.popMsg(u.getName() + " attacks " + u2.getName() + ", inflicting 1HP damage!");
             }
             if (u2.hp <= 0)
             {
                 u2.die(this, "Attacked by " + u.getName());
             }
             return;
         }
     }
     u.location.units.Remove(u);
     loc.units.Add(u);
     u.location = loc;
 }
        public void combatAction(Unit u, Unit u2, Location loc)
        {
            if (u is Unit_Merchant && (u.isEnthralled() == false))
            {
                return;
            }
            if (u.isMilitary == false && u2.isMilitary == false && u.isEnthralled() && u2.society == loc.soc)
            {
                //Enthralled attacking an agent in their homeland
                //Can be defended by military units locally stationned
                Unit defender = null;
                if (loc.settlement != null && loc.settlement.embeddedUnit != null)
                {
                    defender = loc.settlement.embeddedUnit;
                }
                foreach (Unit u3 in loc.units)
                {
                    if (u3.isMilitary && u3.society == u2.society)
                    {
                        defender = u3;
                    }
                }
                if (defender != null)
                {
                    loc.map.world.prefabStore.popMsg("You agent cannot attack " + u2.getName() + " as they are defended the military unit present (" + defender.getName() + ")");
                    u.movesTaken -= 1;
                    return;
                }
            }

            double lethality    = loc.map.param.combat_lethality;
            double lethalityDef = loc.map.param.combat_lethalityDefensive;

            bool hadAttackBonus = false;

            foreach (Unit bonusU in u.location.units)
            {
                if (bonusU.society == u.society && bonusU is Unit_Investigator && bonusU.task is Task_SupportMilitary)
                {
                    if (((Unit_Investigator)bonusU).state == Unit_Investigator.unitState.knight)
                    {
                        lethality     *= param.unit_knightCombatBonus;
                        hadAttackBonus = true;
                        break;
                    }
                    if (((Unit_Investigator)bonusU).state == Unit_Investigator.unitState.basic)
                    {
                        lethality     *= param.unit_agentCombatBonus;
                        hadAttackBonus = true;
                        break;
                    }
                }
            }
            foreach (Unit bonusU in u2.location.units)
            {
                if (bonusU.society == u2.society && bonusU is Unit_Investigator && bonusU.task is Task_SupportMilitary)
                {
                    if (((Unit_Investigator)bonusU).state == Unit_Investigator.unitState.knight)
                    {
                        lethalityDef  *= param.unit_knightCombatBonus;
                        hadAttackBonus = true;
                        break;
                    }
                    if (((Unit_Investigator)bonusU).state == Unit_Investigator.unitState.basic)
                    {
                        lethalityDef  *= param.unit_agentCombatBonus;
                        hadAttackBonus = true;
                        break;
                    }
                }
            }

            if (burnInComplete)
            {
                world.prefabStore.particleCombat(u.location.hex, u2.location.hex);
            }
            int dmgDone = (int)(u.hp * (lethality + (Eleven.random.NextDouble() * lethality)));

            if (u2.isMilitary)
            {
                if (loc.settlement != null && loc.settlement.defensiveStrengthCurrent > 0 && u2.society == loc.soc)
                {
                    double ablated = Math.Min(loc.settlement.defensiveStrengthCurrent, dmgDone / 2d);
                    dmgDone -= (int)ablated;
                    loc.settlement.defensiveStrengthCurrent -= ablated;
                }

                int dmgReplied = (int)(u2.hp * (lethalityDef + (Eleven.random.NextDouble() * lethalityDef)));
                if (dmgReplied >= u.hp)
                {
                    dmgReplied = u.hp - 1;
                    if (dmgReplied < 0)
                    {
                        dmgReplied = 0;
                    }
                }
                u.hp -= dmgReplied;
            }


            if (dmgDone < 1)
            {
                dmgDone = 1;
            }

            bool kicked = false;

            if (dmgDone > 1 && (u2.isMilitary == false))
            {
                dmgDone = 1; kicked = true;
            }


            u2.hp -= dmgDone;
            if (u2.isEnthralled())
            {
                world.prefabStore.popMsgAgent(u, u2, u.getName() + " attacks " + u2.getName() + ", inflicting " + dmgDone + " HP damage!");
                //world.prefabStore.popMsg(u.getName() + " attacks " + u2.getName() + ", inflicting " + dmgDone + " HP damage!");
            }
            if (u.isEnthralled() && u2 is Unit_Investigator && u.person != null && u2.person != null)
            {
                u2.person.getRelation(u.person).suspicion = 1;
            }
            if (u.hp <= 0)
            {
                u.die(this, "Took damage attacking " + u2.getName());
            }

            if (u2.hp <= 0)
            {
                u2.die(this, "Attacked by " + u.getName());
            }
            else if (kicked)
            {
                int      c        = 0;
                Location kickedTo = null;
                foreach (Location l2 in u2.location.getNeighbours())
                {
                    bool bad = false;
                    foreach (Unit u3 in l2.units)
                    {
                        if (u3.hostileTo(u2) || u2.hostileTo(u3))
                        {
                            bad = true; break;
                        }
                    }
                    if (!bad)
                    {
                        c += 1;
                        if (Eleven.random.Next(c) == 0)
                        {
                            kickedTo = l2;
                        }
                    }
                }
                if (kickedTo != null)
                {
                    u2.task = null;
                    adjacentMoveTo(u2, kickedTo);
                    if (u2.isEnthralled())
                    {
                        world.prefabStore.popMsgAgent(u, u2, u2.getName() + " is forced to retreat, and is now in " + u2.location.getName());
                        //world.prefabStore.popMsg(u2.getName() + " is forced to retreat, and is now in " + u2.location.getName());
                    }
                }
            }

            if (u.isMilitary && loc.settlement != null)
            {
                //if (loc.settlement is Set_City)
                //{
                //    Set_City city = (Set_City)loc.settlement;
                //    //city.infrastructure *= (int)((Eleven.random.NextDouble() * 0.25) + 0.7);//0.05 to 0.3 dmg
                //    city.population *= (int)((Eleven.random.NextDouble() * 0.25) + 0.7);//0.05 to 0.3 dmg
                //    //if (city.infrastructure < 1) { city.infrastructure = 1; }
                //    if (city.population < 1) { city.population = 1; }
                //}
                loc.settlement.takeAssault(u.society, loc.soc, dmgDone);
            }

            if (u.isMilitary && u2.isMilitary && u.society is Society && u2.society is Society)
            {
                Property.addProperty(this, loc, "Recent Human Battle");
            }
        }
        public override void turnTick(Unit unit)
        {
            HashSet <Location> closed = new HashSet <Location>();
            HashSet <Location> open   = new HashSet <Location>();
            HashSet <Location> open2  = new HashSet <Location>();

            closed.Add(unit.location);
            open.Add(unit.location);

            int      c      = 0;
            Location target = null;

            for (int tries = 0; tries < 128; tries++)
            {
                open2.Clear();
                foreach (Location loc in open)
                {
                    foreach (Location l2 in loc.getNeighbours())
                    {
                        if (!closed.Contains(l2))
                        {
                            closed.Add(l2);
                            open2.Add(l2);
                        }
                        if (l2.soc != null && l2.soc.getRel(unit.society).state == DipRel.dipState.war)
                        {
                            c += 1;
                            if (Eleven.random.Next(c) == 0)
                            {
                                target = loc;
                            }
                        }
                        foreach (Unit u2 in l2.units)
                        {
                            if (unit.hostileTo(u2))
                            {
                                c += 1;
                                if (Eleven.random.Next(c) == 0)
                                {
                                    target = loc;
                                }
                            }
                        }
                    }
                }
                if (target != null)
                {
                    break;
                }                             //Now found the closest unit set
                open  = open2;
                open2 = new HashSet <Location>();
            }

            if (unit.society == null || (unit.society.isAtWar() == false))
            {
                unit.task = null;
            }
            else if (target != null && target != unit.location)
            {
                Location[] locations = unit.location.map.getPathTo(unit.location, target);
                if (locations == null || locations.Length < 2)
                {
                    unit.task = null; return;
                }
                unit.location.map.adjacentMoveTo(unit, locations[1]);
            }
        }