Beispiel #1
0
        private void ProcessBattle(IUnit currentUnit, IEnumerable<IUnit> targets, IList<IUnit> killedUnits)
        {
            foreach (var target in targets)
            {
                var attack = currentUnit.CombatHandler.GenerateAttack();

                int healthDamage = attack.Damage - target.DefensePoints;
                if (healthDamage > 0)
                {
                    target.HealthPoints -= healthDamage;

                    this.Engine.OutputWriter.Write(string.Format(
                        "{0} cast {1} on {2} for {3} damage",
                        currentUnit.Name,
                        attack.GetType().Name,
                        target.Name,
                        healthDamage));

                    if (target.HealthPoints < 0)
                    {
                        target.HealthPoints = 0;

                        this.Engine.OutputWriter.Write(string.Format(
                            "{0} has killed {1}",
                            currentUnit.Name,
                            target.Name));

                        killedUnits.Add(target);
                    }
                }
            }
        }
 public override IEnumerable<IUnitConversion<double>> GetConversionsTo(IUnit to)
 {
     Contract.Ensures(Contract.Result<IEnumerable<IUnitConversion<double>>>() != null);
     return AreUnitsMatching(_singleUnit, to)
         ? new[] { new UnitUnityConversion(_singleUnit, to) }
         : Enumerable.Empty<IUnitConversion<double>>();
 }
Beispiel #3
0
        public override int Attack(IUnit enemy)
        {
            int r = 0;

            if ((Unit.LifePoints > 0) && (enemy.LifePoints > 0))
            {
                Print("\n" + Unit.Name + " --> попадание", 0);
                if (Hit(enemy) != 0)
                {
                    Print(" --> ранение ", 0);
                    if (Wound(enemy) != 0)
                    {
                        Print(" --> броня ", 0);
                        if (NotAs(Unit) != 0)
                        {
                            if (enemy.Ward != 0)
                            {
                                Print(" --> особая защита ", 0);
                            }
                            if (not_ward(enemy) != 0)
                            {
                                Print(" --> " + enemy.Name + " РАНЕН", 2);
                                r = 1;
                            }
                        }
                    }
                }
                if (r == 0)
                {
                    Print(" --> не получилось", 1);
                }
            }
            return r;
        }
Beispiel #4
0
        public void MoveUnit(int x, int y, IUnit glad)
        {
            if (IsOutOfBounds(x, y))
            {
                Text.WriteLine("");
                Text.ColorWriteLine("Cant move there!", ConsoleColor.DarkRed);
                Thread.Sleep(2000);
                return;
            }

            var unitOnTile = GetTile(x, y);

            if (unitOnTile == null)
            {
                _map[glad.CurrentTile.x, glad.CurrentTile.y] = null;
                glad.CurrentTile.y = y;
                glad.CurrentTile.x = x;
                _map[x, y] = (Tile)glad.CurrentTile;
                return;
            }

            IUnit target = GetTile(x, y).OccupyingUnit;
            (glad as Gladiator).Target = target;
            Program.GameState = GameState.Interacting;
        }
Beispiel #5
0
        protected int Hit(IUnit enemy)
        {
            int r = 0;

            if (Unit.Param.Contains("A"))
            {
                r = 1;
                Print("(автопопадание)", 0);
            }
            else
            {
                if (Unit.WeaponSkill == enemy.WeaponSkill)
                {
                    if (check_k("ws", Unit.Param, 4, 1) != 0) { r = 1; }
                }
                if (Unit.WeaponSkill > enemy.WeaponSkill)
                {
                    if (check_k("ws", Unit.Param, 3, 1) != 0) { r = 1; }
                }
                if (Unit.WeaponSkill < enemy.WeaponSkill)
                {
                    if ((Unit.WeaponSkill * 2) < enemy.WeaponSkill)
                    {
                        if (check_k("ws", Unit.Param, 5, 1) != 0) { r = 1; }
                    }
                    else
                    {
                        if (check_k("ws", Unit.Param, 4, 1) != 0) { r = 1; }
                    }
                }
            }
            return r;
        }
Beispiel #6
0
 public void Select(IUnit unit)
 {
     if(SelectedUnit == unit)
         return;
     SelectedUnit = unit;
     FireUnitEvent(unit, SelectedUnitChanged);
 }
 public Intracommunicator localComm(IUnit caller)
 {
     Intracommunicator _localComm;
        //_localComm = (Intracommunicator)Communicator.world.Create(Communicator.world.Group.IncludeOnly(caller.Ranks));
        _localComm = (Intracommunicator)this.WorldComm.Create(this.WorldComm.Group.IncludeOnly(caller.Ranks));
        return _localComm;
 }
Beispiel #8
0
        /// <summary>
        /// Получить пропись числа с согласованной единицей измерения.
        /// </summary>
        /// <param name="decimalDigit"> CDigit должно быть целым, неотрицательным. </param>
        /// <param name="unit"></param>
        /// <param name="result"> Сюда записывается результат. </param>
        /// <returns> <paramref name="result"/> </returns>
        /// <exception cref="ArgumentException">
        /// Если decimalDigit меньше нуля или не целое. 
        /// </exception>
        public static StringBuilder ConvertToString(decimal decimalDigit, IUnit unit, StringBuilder result)
        {
            string error = CheckDigit(decimalDigit);
            if (error != null) throw new ArgumentException(error, "число");

            // Целочисленные версии работают в разы быстрее, чем decimal.
            if (decimalDigit <= uint.MaxValue)
            {
                ConvertToString((uint)decimalDigit, unit, result);
            }
            else if (decimalDigit <= ulong.MaxValue)
            {
                ConvertToString((ulong)decimalDigit, unit, result);
            }
            else
            {
                MyStringBuilder mySb = new MyStringBuilder(result);

                decimal div1000 = Math.Floor(decimalDigit / 1000);
                HightDigitClassesToString(div1000, 0, mySb);
                DigitClassToString((uint)(decimalDigit - div1000 * 1000), unit, mySb);
            }

            return result;
        }
 /// <summary>
 /// Loads a unit into the host
 /// </summary>
 /// <param name="unit">Unit to load</param>
 public void LoadUnit( IUnit unit )
 {
     Arguments.CheckNotNull( unit, "unit" );
     Log.Info( "Loading unit " + unit);
     unit.Initialize( m_Environment );
     m_Units.Add( unit );
 }
Beispiel #10
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The unit to copy</param>
 public Unit(IUnit source)
 {
     Description = source.Description;
     ID = source.ID;
     ConversionFactorToSI = source.ConversionFactorToSI;
     OffSetToSI = source.OffSetToSI;
 }
 /// <summary>
 /// value is on line between units and on the dist form unit1
 /// </summary>
 /// <param name="unit1">first unit</param>
 /// <param name="unit2">second unit</param>
 /// <param name="Dist">distance from unit1</param>
 public RelativeVector(IUnit unit1, IUnit unit2, float Dist)
 {
     relativeUnit1 = unit1;
     relativeUnit2 = unit2;
     dist = Dist;
     mode = Modes.BetweenUnitsNearOne;
 }
        /// <summary>
        /// Converts the distance into area
        /// </summary>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <returns></returns>
        public static IUnit<IArea> Times(this IUnit<IDistance> d1, IUnit<IDistance> d2)
        {
            var f1 = d1.In().Feet;
            var f2 = d2.In().Feet;

            return (f1.Quantity * f2.Quantity).Square().Feet;
        }
 private void ChangeUnitLocation(IPath pathToTheTargetPlanet, IUnit unitToTeleport, ILocation targetLocation)
 {
     pathToTheTargetPlanet.TargetLocation.Planet.Units.Add(unitToTeleport);
     unitToTeleport.CurrentLocation.Planet.Units.Remove(unitToTeleport);
     unitToTeleport.PreviousLocation = unitToTeleport.CurrentLocation;
     unitToTeleport.CurrentLocation = targetLocation;
 }
 public SingleUnityUnitConversionMap(IUnit unit, IEqualityComparer<IUnit> unitEqualityComparer = null)
     : base(unitEqualityComparer)
 {
     if (null == unit) throw new ArgumentNullException("unit");
     Contract.EndContractBlock();
     _singleUnit = unit;
 }
Beispiel #15
0
        public IUnit CreateUnit(IUnit unitType)
        {
            var spawnedUnit = unitType.Spawn();
            this.UnitsManufactured += 1;

            return spawnedUnit;
        }
Beispiel #16
0
        /// <summary>
        /// Получить пропись числа с согласованной единицей измерения.
        /// </summary>
        /// <param name="doubleDigit"> 
        /// CDigit должно быть целым, неотрицательным, не большим <see cref="MaxDouble"/>. 
        /// </param>
        /// <param name="unit"></param>
        /// <param name="result"> Сюда записывается результат. </param>
        /// <exception cref="ArgumentException">
        /// Если doubleDigit меньше нуля, не целое или больше <see cref="MaxDouble"/>. 
        /// </exception>
        /// <returns> <paramref name="result"/> </returns>
        /// <remarks>
        /// float по умолчанию преобразуется к double, поэтому нет перегрузки для float.
        /// В результате ошибок округления возможно расхождение цифр прописи и
        /// строки, выдаваемой double.ToString ("R"), начиная с 17 значащей цифры.
        /// </remarks>
        public static StringBuilder ConvertToString(double doubleDigit, IUnit unit, StringBuilder result)
        {
            string error = CheckDigit(doubleDigit);
            if (error != null) throw new ArgumentException(error, "число");

            if (doubleDigit <= uint.MaxValue)
            {
                ConvertToString((uint)doubleDigit, unit, result);
            }
            else if (doubleDigit <= ulong.MaxValue)
            {
                // SumConvertToString с ulong выполняется в среднем в 2 раза быстрее.
                ConvertToString((ulong)doubleDigit, unit, result);
            }
            else
            {
                MyStringBuilder mySb = new MyStringBuilder(result);

                double div1000 = Math.Floor(doubleDigit / 1000);
                HightDigitClassesToString(div1000, 0, mySb);
                DigitClassToString((uint)(doubleDigit - div1000 * 1000), unit, mySb);
            }

            return result;
        }
Beispiel #17
0
 public Spell(IUnit unit, int energyCost, int damage)
 {
     this.Unit = unit;
     this.Targets = targets;
     this.Damage = damage;
     this.EnergyCost = energyCost;
 }
Beispiel #18
0
        protected int Wound(IUnit enemy)
        {
            int r = 0;

            int a_s = Unit.Strength;
            if (Unit.Param.Contains("B")) { a_s += 2; }

            if (a_s == enemy.Resistance)
            {
                if (check_k("s", Unit.Param, 4, 1) != 0) { r = 1; }
            }
            else if (a_s == (enemy.Resistance + 1))
            {
                if (check_k("s", Unit.Param, 3, 1) != 0) { r = 1; }
            }
            else if (a_s > (enemy.Resistance + 1))
            {
                if (check_k("s", Unit.Param, 2, 1) != 0) { r = 1; }
            }
            else if ((a_s + 1) == enemy.Resistance)
            {
                if (check_k("s", Unit.Param, 5, 1) != 0) { r = 1; }
            }
            else if ((a_s + 2) == enemy.Resistance)
            {
                if (check_k("s", Unit.Param, 6, 1) != 0) { r = 1; }
            }
            else if ((a_s + 2) < enemy.Resistance)
            {
                r = 0;
            }

            return r;
        }
 public void TestInit()
 {
     _unit = Unit.Create();
     _unitHolder = UnitHolder.Create();
     _unitChangedEventFired = false;
     _unitHolder.UnitChanged += UnitHolderOnUnitChanged;
 }
Beispiel #20
0
 /// <summary>
 /// Constructs a prime meridian.
 /// </summary>
 /// <param name="name">The name of the prime meridian.</param>
 /// <param name="longitude">The longitude location of the meridian.</param>
 /// <param name="angularUnit">The angular unit of the longitude value.</param>
 /// <param name="authority">The authority.</param>
 public OgcPrimeMeridian(string name, double longitude, IUnit angularUnit, IAuthorityTag authority = null)
     : base(name, authority)
 {
     Contract.Requires(name != null);
     Longitude = longitude;
     Unit = angularUnit ?? OgcAngularUnit.DefaultDegrees;
 }
        public void Init()
        {
            motionSimulation = new ThreadSimulationProxy(new Simulation());

            //var npc = new NPC() { ID = "Villain" };
            //motionSimulation.Insert(npc);
            //unit1 = new ThreadUnitProxy(new Unit { ID = "Unit1" }, motionSimulation);
            var us = new Simulation().CreateUnit();
            ((Unit)us).ID = "Unit1";

            unit1 = motionSimulation.CreateUnit(us);
            unit1.IntersectsUnit += new EventHandler<IObjectArgs<IUnit>>(unit1_IntersectsUnit);
            //unit1.IntersectsUnit -= new EventHandler<IObjectArgs<IUnit>>(unit1_IntersectsUnit);
            //unit1.IntersectsUnit += (sender, unit) =>
            //{
            //    DebugOutput("UNITS INTERSECTED");
            //};
            //unit1.IntersectsUnit -= (sender, unit) =>
            //{
            //    DebugOutput("UNITS INTERSECTED");
            //};
            motionSimulation.Insert(unit1);

            //var projectile = new Projectile();
            //projectile.HitsObject += new Action<Object>((o) =>
            //{
            //    DebugOutput("Projectile hit " + ((Unit)o).ID);
            //});
            //motionSimulation.Insert(projectile);
        }
Beispiel #22
0
        public override LanguageDigit ConvertToString(decimal number, IUnit unit)
        {
            CheckNumber(number);
            

            if (number <= uint.MaxValue)
            {
                return ConvertToString((uint)number, unit);
            }
            
            if (number <= ulong.MaxValue)
            {
                return ConvertToString((ulong)number, unit);
            }
            


            decimal div1000 = Math.Floor(number / 1000);

            HightDigitClassesToString(div1000, 0, convertedNumber);

            DigitClassToString((uint)(number - div1000 * 1000), unit, convertedNumber);


            return this;
        }
Beispiel #23
0
 public override void ApplyBehavior(IUnit unit)
 {
     if (!CanApplyBehaviorTo(unit)) return;
     AppliedUnit = unit;
     if (IsActivated) return;
     Thread trd = new Thread(ThreadMethod);
     trd.Start();
 }
 public void AddUnit(IUnit unit)
 {
     if (unit == null)
     {
         throw new ArgumentNullException(nameof(unit));
     }
     this.units.Add(unit);
 }
 /// <summary>
 /// value is relative to unit's position
 /// </summary>
 /// <param name="RelativeUnit">unit to be used as a pivot</param>
 /// <param name="Angle">angle between pivot.forward and direction from pivot to this vector</param>
 /// <param name="Dist">dist from pivot to this vector</param>
 public RelativeVector(IUnit RelativeUnit, float Angle, float Dist)
 {
     relativeUnit1 = RelativeUnit;
     dist = Dist;
     angle = Angle;
     rotationOnAngle = Matrix.CreateRotation(angle);
     mode = Modes.UnitsSideAndDist;
 }
Beispiel #26
0
 public void Attack(IUnit target)
 {
     target.TakeHit(unitAttackPower);
     if (target.unitDamageSuffered >= target.unitHealth)
     {
         target = null;
     }
 }
Beispiel #27
0
 /// <summary>
 /// creates new radar instance. 
 /// Radar is created automatically for each UnitPilot class instance, has radius a little more than his ShootingRadius
 /// </summary>
 /// <param name="Radius">radar range</param>
 /// <param name="HolderUnit">unit that holds this radar</param>
 /// <param name="AI">AI that HolderUnit belongs to</param>
 internal Radar(float Radius, IUnit HolderUnit, AI AI)
 {
     holderUnit = HolderUnit;
     ai = AI;
     this.Radius = Radius;
     NearUnits = ai.Game.GetNearUnits(holderUnit.Position, Radius);
     Scan();
 }
 public void ValidateEnergyPoints(IUnit unit, ISpell spell)
 {
     if (unit.EnergyPoints < spell.EnergyCost)
     {
         throw new NotEnoughEnergyException(
             string.Format("{0} does not have enough energy to cast {1}", unit.Name, spell.GetType().Name));
     }
 }
Beispiel #29
0
 public static Unit FromUnit(IUnit unit)
 {
     Unit u = new Unit
      {
     Name = unit.Name,
      };
      return u;
 }
Beispiel #30
0
        public void RemoveUnit(IUnit unit)
        {
            if (unit == null)
            {
                throw new ArgumentNullException("Unit cannot be null");
            }

            this.units.Remove(unit);
        }
Beispiel #31
0
 /// <summary>
 /// Gets a new unit specific measure based on this measure but in the <paramref name="unit">specified unit</paramref>
 /// </summary>
 /// <param name="unit">Unit in which the new measure should be specified</param>
 IMeasure <Number> IMeasure <Number> .this[IUnit <Number> unit]
 {
     get { return(this[unit]); }
 }
Beispiel #32
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Number New(float amount, IUnit <Number> unit)
 {
     return(new Number(amount, unit));
 }
Beispiel #33
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Number New(double amount, IUnit <Number> unit)
 {
     return(new Number(amount, unit));
 }
Beispiel #34
0
 /// <summary>
 /// Allocates an object that associates contracts, such as preconditions and postconditions, with methods, types and loops.
 /// If the object is already associated with a contract, that association will be lost as a result of this call.
 /// </summary>
 /// <param name="contractMethods">A collection of methods that can be called in a way that provides tools with information about contracts.</param>
 /// <param name="unit">The unit that this is a contract provider for.</param>
 public ContractProvider(IContractMethods contractMethods, IUnit unit)
 {
     this.contractMethods = contractMethods;
     this.unit            = unit;
 }
Beispiel #35
0
 /// <summary>
 /// Creates a new measure from the specified <paramref name="amount"/> and <paramref name="unit"/>.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Measure from the specified <paramref name="amount"/> and <paramref name="unit"/>.</returns>
 public IMeasure <Activity> NewPreserveUnit(decimal amount, IUnit <Activity> unit)
 {
     return(new Measure <Activity>(amount, unit));
 }
Beispiel #36
0
 /// <summary>
 /// Creates a new measure from the specified <paramref name="amount"/> and <paramref name="unit"/>.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Measure from the specified <paramref name="amount"/> and <paramref name="unit"/>.</returns>
 public IMeasure <Number> NewPreserveUnit(decimal amount, IUnit <Number> unit)
 {
     return(new Measure <Number>(amount, unit));
 }
Beispiel #37
0
        public void ShouldNotCreate()
        {
            IUnit createdUnit = _unitFactory.CreateUnit(UnitType.Skeleton);

            Assert.Null(createdUnit);
        }
Beispiel #38
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Activity New(double amount, IUnit <Activity> unit)
 {
     return(new Activity(amount, unit));
 }
    public Queue <IUnit> GetIntersectionsRelativeTo(IUnit firstUnit)
    {
        var possibleIntersections = new List <IUnit>();
        var firstStartCheckPoint  = firstUnit.Transform.position;

        foreach (var unit in _units)
        {
            if (unit == firstUnit ||
                unit == null ||
                !BoundaryHelper.OnScreen(unit.Transform.position) ||
                unit.Transform.gameObject.activeInHierarchy == false ||
                unit.KillHandler.KillPoint.HasValue ||
                unit.AngleDefinition.IntersectionPoint != Vector2.zero && BoundaryHelper.ContainedInObstacleCollider(unit.AngleDefinition.IntersectionPoint))
            {
                continue;
            }

            var firstRearCheckPoint = firstUnit.AngleDefinition.RearPointRelative;

            var rearPoint    = unit.AngleDefinition.RearPointRelative;
            var forwardPoint = unit.AngleDefinition.ForwardPointRelative;

            if (IntersectionMaths.IsIntersecting(firstStartCheckPoint, firstRearCheckPoint, rearPoint, forwardPoint))
            {
                var intersect = IntersectionMaths.FindIntersection(firstStartCheckPoint, firstRearCheckPoint,
                                                                   rearPoint, forwardPoint);

                if (intersect != null)
                {
                    var directionThroughKillPoint =
                        (unit.KillHandler.GetFauxKillPoint() - (Vector2)unit.Transform.position).normalized;
                    if (possibleIntersections.Any(t => Vector2.Distance(intersect.Value, t.AngleDefinition.IntersectionPoint) < 1f))
                    {
                        continue;
                    }
                    if (!NodeGrid.Instance.NodeFromWorldPosition(intersect.Value).IsWalkable ||
                        !BoundaryHelper.OnScreen(intersect.Value) ||
                        BoundaryHelper.ContainedInObstacleCollider(intersect.Value))
                    {
                        continue;
                    }

                    if (Vector2.Distance(unit.Transform.position, intersect.Value) < 2f ||
                        Vector2.Distance(unit.Transform.position, firstStartCheckPoint) < 1f ||
                        Vector2.Distance(firstUnit.Transform.position, intersect.Value) < 1f)
                    {
                        continue;
                    }

                    unit.AngleDefinition.SetIntersectionPoint(intersect.Value);
                    possibleIntersections.Add(unit);
                }
            }
        }

        if (possibleIntersections.Count <= 0)
        {
            return(null);
        }

        var orderedIntersections = possibleIntersections.OrderBy(t =>
                                                                 Vector2.Distance(firstStartCheckPoint, t.AngleDefinition.IntersectionPoint));

        var intersectOrder = new Queue <IUnit>();

        for (var i = 0; i < orderedIntersections.Count(); i++)
        {
            intersectOrder.Enqueue(orderedIntersections.ElementAt(i));
        }
        return(intersectOrder.Count > 0 ? intersectOrder : null);
    }
Beispiel #40
0
 void ISliceInit.Init(IUnit unit)
 {
     m_Sender = unit;
 }
 public void AddUnit(IUnit unit)
 {
     _units.Add(unit);
 }
Beispiel #42
0
 void ISliceInit.Done(IUnit unit)
 {
     m_Sender = null;
 }
Beispiel #43
0
 void ISliceUpdate.Update(IUnit target, float deltaTime)
 {
 }
Beispiel #44
0
 /// <summary>
 /// Creates a new vertex with the specified unit.
 /// </summary>
 /// <param name="unit">The unit will be associated with vertex.</param>
 /// <returns>
 /// A new instance of vertex.
 /// </returns>
 public Vertex NewVertex(IUnit unit)
 {
     return(new Vertex(unit));
 }
Beispiel #45
0
 /// <summary>
 /// Gets a new unit specific measure based on this measure but in the <paramref name="unit">specified unit</paramref>
 /// </summary>
 /// <param name="unit">Unit in which the new measure should be specified</param>
 /// <exception cref="ArgumentNullException">if specified unit is null or if specified unit is not of the Number quantity.</exception>
 IMeasure IMeasure.this[IUnit unit]
 {
     get { return(this[unit as IUnit <Number> ]); }
 }
Beispiel #46
0
        public void ShouldCreateMonster()
        {
            IUnit createdUnit = _unitFactory.CreateUnit(UnitType.Monster);

            Assert.True(createdUnit is Monster);
        }
Beispiel #47
0
 /// <summary>
 /// Gets the amount of this measure in the requested unit
 /// </summary>
 /// <param name="unit">Unit to which the measured amount should be converted</param>
 /// <returns>Measured amount converted into <paramref name="unit">specified unit</paramref></returns>
 AmountType IMeasure.GetAmount(IUnit unit)
 {
     return(this.GetAmount(unit as IUnit <Number>));
 }
Beispiel #48
0
 /// <summary>
 /// Gets a new unit specific measure based on this measure but in the <paramref name="unit">specified unit</paramref>
 /// </summary>
 /// <param name="unit">Unit in which the new measure should be specified</param>
 /// <exception cref="ArgumentNullException">if specified unit is null or if specified unit is not of the Activity quantity.</exception>
 IMeasure IMeasure.this[IUnit unit]
 {
     get { return(this[unit as IUnit <Activity> ]); }
 }
Beispiel #49
0
 /// <summary>
 /// Gets a new unit specific measure based on this measure but in the <paramref name="unit">specified unit</paramref>
 /// </summary>
 /// <param name="unit">Unit in which the new measure should be specified</param>
 IMeasure <Activity> IMeasure <Activity> .this[IUnit <Activity> unit]
 {
     get { return(this[unit]); }
 }
Beispiel #50
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Mass New(float amount, IUnit <Mass> unit)
 {
     return(new Mass(amount, unit));
 }
Beispiel #51
0
        public void ShouldCreatePlayer()
        {
            IUnit createdUnit = _unitFactory.CreateUnit(UnitType.Player);

            Assert.True(createdUnit is Player);
        }
Beispiel #52
0
 public Variable(string name, IUnit unit)
     : this(name, unit, -1)
 {
 }
Beispiel #53
0
        /// <summary>
        /// Returns a unit namespace definition, nested in the given unitNamespace if possible,
        /// otherwise nested in the given unit if possible, otherwise nested in the given host if possible, otherwise it returns Dummy.UnitNamespace.
        /// If unitNamespaceReference is a root namespace, the result is equal to the given unitNamespace if not null,
        /// otherwise the result is the root namespace of the given unit if not null,
        /// otherwise the result is root namespace of unitNamespaceReference.Unit, if that can be resolved via the given host,
        /// otherwise the result is Dummy.UnitNamespace.
        /// </summary>
        public static IUnitNamespace Resolve(IUnitNamespaceReference unitNamespaceReference, IMetadataHost host, IUnit unit = null, IUnitNamespace unitNamespace = null)
        {
            Contract.Requires(unitNamespaceReference != null);
            Contract.Requires(host != null);
            Contract.Requires(unit != null || unitNamespace == null);
            Contract.Ensures(Contract.Result <IUnitNamespace>() != null);

            var rootNsRef = unitNamespaceReference as IRootUnitNamespaceReference;

            if (rootNsRef != null)
            {
                if (unitNamespace != null)
                {
                    return(unitNamespace);
                }
                if (unit != null)
                {
                    return(unit.UnitNamespaceRoot);
                }
                unit = UnitHelper.Resolve(unitNamespaceReference.Unit, host);
                if (unit is Dummy)
                {
                    return(Dummy.UnitNamespace);
                }
                return(unit.UnitNamespaceRoot);
            }
            var nestedNsRef = unitNamespaceReference as INestedUnitNamespaceReference;

            if (nestedNsRef == null)
            {
                return(Dummy.UnitNamespace);
            }
            var containingNsDef = UnitHelper.Resolve(nestedNsRef.ContainingUnitNamespace, host, unit, unitNamespace);

            if (containingNsDef is Dummy)
            {
                return(Dummy.UnitNamespace);
            }
            foreach (var nsMem in containingNsDef.GetMembersNamed(nestedNsRef.Name, ignoreCase: false))
            {
                var neNsDef = nsMem as INestedUnitNamespace;
                if (neNsDef != null)
                {
                    return(neNsDef);
                }
            }
            return(Dummy.UnitNamespace);
        }
Beispiel #54
0
 /// <summary>
 /// Gets the amount of this measure in the requested unit
 /// </summary>
 /// <param name="unit">Unit to which the measured amount should be converted</param>
 /// <returns>Measured amount converted into <paramref name="unit">specified unit</paramref></returns>
 AmountType IMeasure.GetAmount(IUnit unit)
 {
     return(this.GetAmount(unit as IUnit <Activity>));
 }
Beispiel #55
0
 public GatherCommand(IUnit unit)
 {
     this.unit = unit;
 }
Beispiel #56
0
 /// <summary>begins a prerecorded camera animation synchronized to unit relative to cutscene flag.</summary>
 public void camera_set_animation_relative(AnimationGraphTag animationTag, string trackName, IUnit unit, ILocationFlag locationFlag)
 {
     this.cameraSystem.PerformCameraMove(animationTag, trackName, unit, locationFlag);
 }
Beispiel #57
0
        public void ShouldCreateRandomUnit()
        {
            IUnit randomUnit = _unitFactory.CreateRandomUnit();

            Assert.NotNull(randomUnit);
        }
Beispiel #58
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Number New(decimal amount, IUnit <Number> unit)
 {
     return(new Number(amount, unit));
 }
Beispiel #59
0
 /// <summary>
 /// Creates a new standard unit measure.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="unit">Unit.</param>
 /// <returns>Standard unit measure.</returns>
 public Activity New(float amount, IUnit <Activity> unit)
 {
     return(new Activity(amount, unit));
 }
Beispiel #60
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (_update || ProductionInvalid)
            {
                _shieldsPerLine = 10;
                _shieldPrice    = (int)_city.CurrentProduction.Price * 10;
                _totalShields   = _shieldPrice;
                if (_city.Shields > _totalShields)
                {
                    _totalShields = _city.Shields;
                }

                _shieldWidth = 8;
                if (_totalShields > 100)
                {
                    _shieldsPerLine = (int)Math.Ceiling((double)_totalShields / 10);
                    _shieldWidth    = ((double)80 / _shieldsPerLine);
                }

                int width  = (int)(_shieldWidth * (_shieldsPerLine - 1)) + 11;
                int height = SHIELD_HEIGHT * ((_shieldPrice - (_shieldPrice % _shieldsPerLine)) / _shieldsPerLine);
                if (height < SHIELD_HEIGHT)
                {
                    height = SHIELD_HEIGHT;
                }

                this.Tile(Pattern.PanelBlue)
                .DrawRectangle(0, 0, width, 19 + height, 1)
                .FillRectangle(1, 1, (width - 2), 16, 1);
                if (width < 88)
                {
                    this.FillRectangle(width, 0, 88 - width, 99, 5);
                }
                if (height < 80)
                {
                    this.FillRectangle(0, 19 + height, width, 80 - height, 5);
                }
                bool blink = ProductionInvalid && (gameTick % 4 > 1);
                if (!(Common.TopScreen is CityManager))
                {
                    blink = ProductionInvalid;
                }
                if (!_viewCity)
                {
                    DrawButton("Change", (byte)(blink ? 14 : 9), 1, 1, 7, 33);
                    DrawButton("Buy", 9, 1, 64, 7, 18);
                }

                DrawShields();

                if (_city.CurrentProduction is IUnit)
                {
                    IUnit unit = (_city.CurrentProduction as IUnit);
                    this.AddLayer(unit.ToBitmap(_city.Owner), 33, 0);
                }
                else
                {
                    string name = (_city.CurrentProduction as ICivilopedia).Name;
                    while (Resources.GetTextSize(1, name).Width > 86)
                    {
                        name = $"{name.Substring(0, name.Length - 2)}.";
                    }
                    this.DrawText(name, 1, 15, 44, 1, TextAlign.Center);
                }

                _update = false;
            }
            return(true);
        }