コード例 #1
0
    //Add the powers when buying new units
    public void AddPower(MilitaryUnit unit)
    {
        if (moneyAmount >= unit.cost)
        {
            attackPower    += unit.attackPower;
            defensivePower += unit.defencePower;
            supplyPower    += unit.supplyPower;

            moneyAmount -= unit.cost;

            //Update the powers in database
            PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
            {
                Data = new Dictionary <string, string>()
                {
                    { "AttackPower", attackPower.ToString() },
                    { "DefencePower", defensivePower.ToString() },
                    { "SupportPower", supplyPower.ToString() }
                }
            },
                                            result => Debug.Log("Successfully updated user data"),
                                            error =>
            {
                Debug.Log("Got error setting user data Ancestor to Arthur");
                Debug.Log(error.GenerateErrorReport());
            });
        }
    }
コード例 #2
0
ファイル: MakeUnit.cs プロジェクト: SoPra18-07/Singularity
        protected override void CreateUnit()
        {
            var camera = mDirector.GetStoryManager.Level.Camera;
            var unit   = new MilitaryUnit(mPlatform.Center + mOffset, camera, ref mDirector);

            mDirector.GetStoryManager.Level.GameScreen.AddObject(unit);
        }
コード例 #3
0
 // Add l istener to button so we can click it
 void Start()
 {
     gameManager = FindObjectOfType <GameManager>();
     unit        = transform.parent.GetComponent <CardDisplay>().unit;
     button      = GetComponent <Button>();
     button.onClick.AddListener(delegate { gameManager.AddPower(unit); });
 }
コード例 #4
0
        public static bool FreeFrom(ref MilitaryUnit unit, int amount)
        {
            if (unit.count == amount)
            {
                return(Free(unit));
            }
            else if (unit.count > amount)
            {
                unit.Free();
                var freedPartialUnit = unit.split(amount);
                unit.Deploy();
                if (freedPartialUnit == null)
                {
                    Debug.LogWarning("Couldn't split unit");
                    return(false);
                }

                if (!JoinWithSimilar(freedPartialUnit))
                {
                    instance.armies.Add(freedPartialUnit);
                }
                return(true);
            }
            return(false);
        }
コード例 #5
0
 // Use this for initialization
 void Awake()
 {
     unit  = GetComponent <MilitaryUnit>();
     Agent = unit.GOAP;
     Agent.AvailableActions.Add(this);
     SetupPreconditions();
     SetUpEffects();
     SetupSatisfactions();
 }
コード例 #6
0
    public static void createSymbolFromMilitaryUnit(MilitaryUnit unit)
    {
        string  id        = unit.SymbolID;
        float   lon       = (float)unit.Lon;
        float   lat       = (float)unit.Lat;
        Vector3 converted = MapData.convert(new Vector2(lon, lat));

        createSymbol(new Vector3(converted.x, converted.y, 0), "Test1");
    }
コード例 #7
0
    public static MilitaryUnit[] getUnits(string fileName)
    {
        XmlDocument doc = new XmlDocument();

        doc.PreserveWhitespace = true;
        try{
            TextAsset textXml = (TextAsset)Resources.Load(fileName, typeof(TextAsset));
            doc.LoadXml(textXml.text);
            Console.WriteLine("XML loaded");
        }
        catch (System.IO.FileNotFoundException) {
            Console.WriteLine("No XML found :(");
        }

        XmlNode root = doc.DocumentElement;
        //XmlNodeList units = root.SelectNodes("//root/identifiables/scenario/militaryUnits");
        XmlNodeList units = root.SelectNodes("descendant::militaryUnits");
        //int counter = 1;
        int count = units.Count;

        MilitaryUnit[] unitsList = new MilitaryUnit[count];
        for (int i = 0; i < count; i++)
        {
            //Console.WriteLine(counter);
            //counter++;
            XmlNode    unit           = units[i];
            XmlNode    currentNode    = unit.SelectSingleNode("./present");
            XmlElement currentElement = (XmlElement)currentNode;
            bool       present        = bool.Parse(currentElement["value"].InnerText);
            //Console.WriteLine(present);

            currentNode    = unit.SelectSingleNode("./location/radius");
            currentElement = (XmlElement)currentNode;
            double radius = double.Parse(currentElement["value"].InnerText, NumberStyles.Any, CultureInfo.InvariantCulture);
            //Console.WriteLine(radius);

            currentNode    = unit.SelectSingleNode("./location/center");
            currentElement = (XmlElement)currentNode;
            double lat = double.Parse(currentElement["lat"].InnerText, NumberStyles.Any, CultureInfo.InvariantCulture);
            //Console.WriteLine(lat);
            double lon = double.Parse(currentElement["lon"].InnerText, NumberStyles.Any, CultureInfo.InvariantCulture);
            //Console.WriteLine(lon);

            currentNode    = unit.SelectSingleNode("./symbolIDCode");
            currentElement = (XmlElement)currentNode;
            string symbolID = currentElement["value"].InnerText;
            //Console.WriteLine(symbolID);

            MilitaryUnit newUnit = new MilitaryUnit(present, radius, lon, lat, symbolID);
            unitsList[i] = newUnit;
        }

        return(unitsList);
    }
コード例 #8
0
    // Spawns new unit on spawnPoint
    private void SpawnUnit(int unitIndex, Transform parent)
    {
        // Positioning on an interval
        Vector3 spawnPosition = _spawnPoint.position;

        spawnPosition.x += Random.Range(-.5f, .5f);
        spawnPosition.y += Random.Range(-.5f, .5f);

        // Creating the unit
        MilitaryUnit unit = Instantiate(_manager.GameConfig.MilitaryUnit, spawnPosition, Quaternion.identity, parent);

        unit.InitMilitaryUnit(_buildingData.ProductionUnits[unitIndex], _manager);
    }
コード例 #9
0
        public static void AllocateInto(ref MilitaryUnit targetUnit, Participant participant, Tile region, MilitaryUnitType unitType, int quantity)
        {
            var additions = Allocate(participant, region, unitType, quantity);

            if (additions != null)
            {
                Debug.Log("Got addition of " + additions.count + " to add to the current " + targetUnit);
                additions.Free();
                targetUnit.Free();
                additions.join(targetUnit);
                targetUnit.Deploy();
                instance.armies.Remove(additions);
            }
            else
            {
                Debug.Log("Couldn't allocate into as no unit got allocated");
            }
        }
コード例 #10
0
        public MilitaryUnitService(MilitaryBranch branch, MilitaryUnit units)
        {
            var unit = units.Sub.ToList().FirstOrDefault(x => x.Nick == branch.ToString());

            this.Unit     = units.Clone();
            this.Unit.Sub = null;

            if (unit != null)
            {
                var currentUnit = unit.Clone();
                var list        = new List <MilitaryUnit.Unit>();

                while (currentUnit != null)
                {
                    if (currentUnit.Sub == null)
                    {
                        break;
                    }

                    currentUnit = GetUnit(currentUnit);
                    list.Add(currentUnit);
                }

                list.Reverse();
                List <MilitaryUnit.Unit> previous = null;
                foreach (var item in list)
                {
                    if (previous == null)
                    {
                        previous = new List <MilitaryUnit.Unit>();
                    }

                    previous = SetUnit(previous, new List <MilitaryUnit.Unit> {
                        item
                    });
                }

                this.Unit.Sub = previous;
            }

            this.Unit.Country = units.Country;
        }
コード例 #11
0
        static bool JoinWithSimilar(MilitaryUnit unit)
        {
            var similarUnits = AllUnits(Game.Map.GetProvince(unit.location), unit.commander, unit.type);

            while (similarUnits.Count > 0)
            {
                var otherUnit = similarUnits.Dequeue();
                if (otherUnit != unit && otherUnit.available)
                {
                    Debug.Log("Will join " + unit + " with " + otherUnit);
                    unit.join(otherUnit);
                    if (!instance.armies.Remove(unit))
                    {
                        Debug.Log("I don't recognize " + unit + " among the enlisted, this is OK when freeing partial units");
                    }
                    return(true);
                }
            }

            return(false);
        }
コード例 #12
0
        public MilitaryUnitAddressService(MilitaryUnit militaryUnit)
        {
            MilUnit = militaryUnit;

            var currentUnit = militaryUnit.Sub.First();

            while (currentUnit != null)
            {
                if (currentUnit.Sub == null)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(currentUnit.HQ))
                {
                    MilUnit.Address      = new AddressProfiles.AddressProfile();
                    MilUnit.Address.Name = currentUnit.HQ;
                }

                currentUnit = GetUnit(currentUnit);
            }
        }
コード例 #13
0
 public new void Initialise(BaseUnit Unit)
 {
     unit = (MilitaryUnit)Unit;
 }
コード例 #14
0
 static bool IsMatchingAndAvailable(MilitaryUnit unit, Participant participant, Tile region, MilitaryUnitType unitType)
 {
     return(unit.commander == participant.ID && unit.type == unitType && unit.location == region.name && unit.available);
 }
コード例 #15
0
 static bool IsMatchingAndAvailable(MilitaryUnit unit, Participant participant, Tile region, MilitaryUnitType unitType, int count)
 {
     return(IsMatchingAndAvailable(unit, participant, region, unitType) && unit.count >= count);
 }
コード例 #16
0
 public static bool Free(MilitaryUnit unit)
 {
     unit.Free();
     JoinWithSimilar(unit);
     return(true);
 }
コード例 #17
0
        public void Shooting(MilitaryUnit sender, ICollider shootingAt, GameTime gametime)
        {
            if (shootingAt == null)
            {
                return;
            }

            // make sure to active the AI if it wasn't already because something is shooting
            // (either getting shot at or shooting at smth)
            if (!mActive)
            {
                mActive = true;
            }

            // now check whether your units fired or you get attacked by the enemy, we don't really need to do anything if
            // we're not the ones shooting

            var asEnemy = sender as EnemyUnit;

            if (asEnemy == null)
            {
                return;
            }

            var senderAsFast  = sender as EnemyFast;
            var senderAsHeavy = sender as EnemyHeavy;

            var targetAsPlatform = shootingAt as PlatformBlank;

            if (senderAsFast != null)
            {
                // the one who shot was a scouting unit, make sure to retreat ASAP
                Retreat(senderAsFast, EEnemyType.Scout, gametime);

                // at this point we know that our scout attacked an enemy platform
                if (targetAsPlatform != null)
                {
                    // make sure to not attack the center, since then the unit wouldn't even move there since there's collision.
                    // this basically sets the position to attack for the AI if it decides to attack.
                    SetAttackTarget(targetAsPlatform);
                }

                return;
            }

            if (senderAsHeavy != null)
            {
                // a defending unit shot, thus move (currently all) defending units to where this happened
                var allDefendings = GetPrioritiyQueueByEnemyType(EEnemyType.Defend).ToList();

                // make a temporary flocking group to reduce stress
                foreach (var defending in allDefendings)
                {
                    if (mIsCurrentlyMoving[defending.GetObject()])
                    {
                        continue;
                    }

                    if (!mUnitToFlockingGroup.ContainsKey(defending.GetObject()))
                    {
                        mUnitToFlockingGroup[defending.GetObject()] = mDirector.GetMilitaryManager.GetNewFlock();
                        mUnitToFlockingGroup[defending.GetObject()].AssignUnit(defending.GetObject());
                    }

                    mUnitToFlockingGroup[defending.GetObject()].FindPath(shootingAt.Center);
                }
                SetAttackTarget(shootingAt);
                return;
            }

            // now the unit is defintely an attacking one, make sure to retreat once the target is destroyed.

            if (shootingAt.Health > 0)
            {
                SetAttackTarget(shootingAt);

                return;
            }

            mShouldAttack = false;
            Retreat(asEnemy, EEnemyType.Attack, gametime);
        }
コード例 #18
0
ファイル: BasicAi.cs プロジェクト: SoPra18-07/Singularity
 public void Shooting(MilitaryUnit sender, ICollider shootingAt, GameTime gametime)
 {
     mBehavior.Shooting(sender, shootingAt, gametime);
 }
コード例 #19
0
 public override void Initialise(BaseUnit Unit)
 {
     unit = (MilitaryUnit)Unit;
 }
コード例 #20
0
ファイル: GameBoard.cs プロジェクト: trasa/cabal
 private void AddUnits(Nationality nationality, MilitaryUnit unitType, params Placement[] placements)
 {
     foreach (Placement p in placements)
     {
         TerritoryState t = Game.GetTerritory(p.Territory);
         t.ControlledBy = nationality;
         t.AddUnits(nationality, unitType, p.UnitCount);
     }
 }
コード例 #21
0
 public void Shooting(MilitaryUnit sender, ICollider shootingAt, GameTime gametime)
 {
     throw new NotImplementedException();
 }