Example #1
0
        public TakesDamageWorker(TakesDamageWorker_Props defaultProps, Tuple<Type, TakesDamageWorker_Props>[] typeModifiers = null)
        {
            _default = defaultProps;

            if (typeModifiers != null && typeModifiers.Length > 0)
            {
                _typeModifiers = typeModifiers;
            }
            else
            {
                _typeModifiers = null;
            }
        }
Example #2
0
        public TakesDamageWorker(TakesDamageWorker_Props defaultProps, Tuple <Type, TakesDamageWorker_Props>[] typeModifiers = null)
        {
            _default = defaultProps;

            if (typeModifiers != null && typeModifiers.Length > 0)
            {
                _typeModifiers = typeModifiers;
            }
            else
            {
                _typeModifiers = null;
            }
        }
Example #3
0
        public double GetDamage_Collision(IMapObject collidedWith, Point3D positionModel, Vector3D velocityModel, double mass1, double mass2)
        {
            const double MAXMASSRATIO = 3;

            TakesDamageWorker_Props props = GetTypeModifier(collidedWith);

            double speed = velocityModel.Length;

            // If the impact velocity is low enough, there won't be damage
            if (speed < props.VelocityThreshold)
            {
                return(0);
            }

            // Restrict mass
            // If the difference in mass is large enough, then the larger could just be considered as a stationary object.  Including more of the larger's
            // mass would make it appear like there is more energy than there actually is (a probe hitting a large asteroid or a planet will feel the
            // same impulse, even though the masses are very different)
            UtilityCore.MinMax(ref mass1, ref mass2);
            if (mass2 > mass1 * MAXMASSRATIO)
            {
                mass2 = mass1 * MAXMASSRATIO;
            }

            // Next check is the collision energy
            // Energy = m/2 * v^2
            double energy = ((mass1 + mass2) / 2d) * speed * speed;

            //May or may not want this check
            // If one of the masses is significantly small relative to the other, then velocity will need to be very large for damage to occur

            // Next is the min energy threshold
            if (energy < props.EnergyTheshold)
            {
                return(0);
            }

            // Final step should just be to convert energy into hitpoint loss
            // HitPointLoss = Energy * c
            double retVal = energy * props.EnergyToHitpointMult;

            // Finally, run it through a randomization
            retVal *= StaticRandom.GetRandomForThread().NextBellPercent(ItemOptions.DAMAGE_RANDOMBELL, props.RandomPercent);

            //LogHit(mass1, mass2, speed, energy);

            return(retVal);
        }