예제 #1
0
		public void SetTransit(CelestialObject targetBody, int warpSpeed, int startTurn, Config conf)
		{
			var start = GetPosition(startTurn, conf.SecondsPerTurn); // init from locations and time
			if (OrbitsObjectID != null) FromObjectID = OrbitsObjectID;
			else FromObjectID = null;
			StartBattleTurn = startTurn;
			CelestialObjectByToObjectID = targetBody;
			FromX = (float)start.X;
			FromY = (float)start.Y;
			Warp = warpSpeed;

			if (FromObjectID == ToObjectID) throw new ApplicationException("Invalid order - from == to");

			var turn = startTurn + 1;

			var failSafe = 1000;
			Position dest;
			do
			{
				dest = targetBody.GetPosition(turn*conf.SecondsPerTurn, conf.SecondsPerTurn);
				var vector = dest - start;
				var curPos = vector.Normalized()*(conf.WarpDistance*warpSpeed*(turn - startTurn));
				var targetToCur = curPos - dest;
				if (targetToCur.X/vector.X >= 0 && targetToCur.Y/vector.Y >= 0) break; // we are "past" target
				turn++;
			} while (failSafe-- > 0);

			if (failSafe == 0) throw new ApplicationException("Erro in fleet settransit logic");

			EndBattleTurn = turn;
			ToX = (float)dest.X;
			ToY = (float)dest.Y;

		}
예제 #2
0
        public Position GetPosition(int gameTurn, int secondsPerTurn)
        {
            if (OrbitsObjectID != null)
            {
                return(CelestialObject.GetPosition(gameTurn, secondsPerTurn));
            }
            else
            {
                if (gameTurn >= EndBattleTurn)
                {
                    return(new Position(ToX, ToY));
                }
                if (gameTurn <= StartBattleTurn)
                {
                    return(new Position(FromX, FromY));
                }
                if (EndBattleTurn - StartBattleTurn <= 0)
                {
                    throw new ApplicationException("Incorrect transit data");
                }

                var part = (double)(gameTurn - StartBattleTurn) / (EndBattleTurn - StartBattleTurn);
                return(new Position((ToX - FromX) * part + FromX, (ToY - FromY) * part + FromY));
            }
        }
예제 #3
0
        public void SetTransit(CelestialObject targetBody, int warpSpeed, int startTurn, Config conf)
        {
            var start = GetPosition(startTurn, conf.SecondsPerTurn);             // init from locations and time

            if (OrbitsObjectID != null)
            {
                FromObjectID = OrbitsObjectID;
            }
            else
            {
                FromObjectID = null;
            }
            StartBattleTurn             = startTurn;
            CelestialObjectByToObjectID = targetBody;
            FromX = (float)start.X;
            FromY = (float)start.Y;
            Warp  = warpSpeed;

            if (FromObjectID == ToObjectID)
            {
                throw new ApplicationException("Invalid order - from == to");
            }

            var turn = startTurn + 1;

            var      failSafe = 1000;
            Position dest;

            do
            {
                dest = targetBody.GetPosition(turn * conf.SecondsPerTurn, conf.SecondsPerTurn);
                var vector      = dest - start;
                var curPos      = vector.Normalized() * (conf.WarpDistance * warpSpeed * (turn - startTurn));
                var targetToCur = curPos - dest;
                if (targetToCur.X / vector.X >= 0 && targetToCur.Y / vector.Y >= 0)
                {
                    break;                                                                             // we are "past" target
                }
                turn++;
            } while (failSafe-- > 0);

            if (failSafe == 0)
            {
                throw new ApplicationException("Erro in fleet settransit logic");
            }

            EndBattleTurn = turn;
            ToX           = (float)dest.X;
            ToY           = (float)dest.Y;
        }
		public Position GetCurrentPosition(CelestialObject body)
		{
			var conf = GetConfig();
			return body.GetPosition(conf.GameSecond, conf.SecondsPerTurn);
		}
예제 #5
0
        public Position GetCurrentPosition(CelestialObject body)
        {
            var conf = GetConfig();

            return(body.GetPosition(conf.GameSecond, conf.SecondsPerTurn));
        }