Пример #1
0
        List <GunPosition> ProcessGunRotate(ref State state, Unit unit, Player enemyPlayer)
        {
            List <GunPosition> ret       = new List <GunPosition>();
            double             currStage = 0.0;
            double             lastStage = currStage;
            double             lastAngle = unit.CurrAngle;
            double             step      = 1.0 / 10;

            while (Utility.doubleLess(currStage, 1))
            {
                double x = unit.GetCoordinate(currStage).x;
                double y = unit.GetCoordinate(currStage).y;

                double?possibleAngleToEnemy = GetAngleToNearestEnemy(unit, unit.Line, enemyPlayer, currStage);
                if (possibleAngleToEnemy == null)
                {
                    ret.Add(new GunPosition(lastAngle, GunPosition.DirectionType.None));
                    return(ret);
                }
                double angleToEnemy = (double)possibleAngleToEnemy;
                if (angleToEnemy > 0)
                {
                    unit.CurrAngle += Utility.MinAbs(angleToEnemy, unit.RotationRate * (currStage - lastStage));
                }
                else
                {
                    unit.CurrAngle -= Utility.MinAbs(angleToEnemy, unit.RotationRate * (currStage - lastStage));
                }
                if (Utility.doubleGreater(currStage - lastStage, 0.0))
                {
                    unit.AddGunRotate(unit.CurrAngle - lastAngle, currStage - lastStage);
                    GunPosition.DirectionType dir;
                    if (unit.CurrAngle > lastAngle)
                    {
                        dir = GunPosition.DirectionType.Clockwise;
                    }
                    else
                    {
                        dir = GunPosition.DirectionType.AntiClockwise;
                    }
                    ret.Add(new GunPosition(lastAngle, dir));
                }
                //unit.CurrAngle = Utility.LimitAngle(unit.CurrAngle);
                lastAngle  = unit.CurrAngle;
                lastStage  = currStage;
                currStage += step;
            }
            ret.Add(new GunPosition(lastAngle, GunPosition.DirectionType.None));
            return(ret);
        }
Пример #2
0
        void ProcessShots(ref State state, Player player, Player enemyPlayer)
        {
            OwnerType owner = player.Owner;

            for (int i = 0; i < Const.NumberOfLines; i++)
            {
                Unit unit = player.Units[i];
                if (unit == null || !unit.FireEnabled)
                {
                    continue;
                }
                double shotStage;
                if (Utility.doubleEqual(unit.StageOfLastShot, -1))
                {
                    shotStage = 0.0;
                }
                else
                {
                    shotStage = unit.StageOfLastShot + 1.0 / unit.DamageRate;
                    if (Utility.doubleGreaterOrEqual(shotStage, 1.0))
                    {
                        shotStage -= 1.0;
                    }
                }
                double currStage = 0.0;
                double lastStage = currStage;
                double lastAngle = unit.CurrAngle;
                double step      = 1.0 / 10;
                while (Utility.doubleLess(currStage, 1))
                {
                    double x = unit.GetCoordinate(currStage).x;
                    double y = unit.GetCoordinate(currStage).y;
                    if (Utility.doubleGreaterOrEqual(currStage, shotStage))
                    {
                        double angle = unit.CurrAngle;
                        if (player.Owner == OwnerType.Player2)
                        {
                            angle -= 180;
                            angle  = Utility.LimitAngle(angle);
                        }
                        state.shells.Add(new Shell(new Point2(x, y), angle, owner, unit, currStage));
                        unit.StageOfLastShot = currStage;
                        shotStage           += 1.0 / unit.DamageRate;
                    }
                    double?possibleAngleToEnemy = GetAngleToNearestEnemy(unit, i, enemyPlayer, currStage);
                    if (possibleAngleToEnemy == null)
                    {
                        return;
                    }
                    double angleToEnemy = (double)possibleAngleToEnemy;
                    if (angleToEnemy > 0)
                    {
                        unit.CurrAngle += Utility.MinAbs(angleToEnemy, unit.RotationRate * (currStage - lastStage));
                    }
                    else
                    {
                        unit.CurrAngle -= Utility.MinAbs(angleToEnemy, unit.RotationRate * (currStage - lastStage));
                    }
                    if (Utility.doubleGreater(currStage - lastStage, 0.0))
                    {
                        unit.AddGunRotate(unit.CurrAngle - lastAngle, currStage - lastStage);
                    }
                    //unit.CurrAngle = Utility.LimitAngle(unit.CurrAngle);
                    lastAngle  = unit.CurrAngle;
                    lastStage  = currStage;
                    currStage += step;
                }
                if (Utility.doubleGreaterOrEqual(shotStage, 1.0 + 1.0 / unit.DamageRate))
                {
                    unit.StageOfLastShot -= 1.0;
                }
            }
        }