Inheritance: ConcreteObject, ILivingObject
Exemple #1
0
 public ManualControlAI(LivingObject worker, int playerID)
 {
     this.Worker  = worker;
     m_playerID   = playerID;
     m_actions    = new ObservableCollection <GameAction>();
     this.Actions = new ReadOnlyObservableCollection <GameAction>(m_actions);
 }
Exemple #2
0
 public ManualControlAI(LivingObject worker, int playerID)
 {
     this.Worker = worker;
     m_playerID = playerID;
     m_actions = new ObservableCollection<GameAction>();
     this.Actions = new ReadOnlyObservableCollection<GameAction>(m_actions);
 }
 public ManualControlAI(LivingObject worker, byte aiID)
 {
     this.Worker = worker;
     m_id = aiID;
     m_actions = new ObservableCollection<GameAction>();
     this.Actions = new ReadOnlyObservableCollection<GameAction>(m_actions);
 }
Exemple #4
0
 public void RequestAction(GameAction action)
 {
     if (LivingObject.LivingRequestsAction != null)
     {
         LivingObject.LivingRequestsAction(this, action);
     }
 }
        void OnLivingRequestsAction(LivingObject living, GameAction action)
        {
            turnTrace.TraceVerbose("SignalLivingHasAction({0}, {1}", living, action);

            if (m_world.IsOurTurn == false)
            {
                turnTrace.TraceWarning("SignalLivingHasAction when not our turn");
                return;
            }

            m_actionMap[living] = action;

            SendProceedTurn();
        }
        public static void SendSetLivingTraceLevel(LivingObject living, System.Diagnostics.TraceLevel traceLevel)
        {
            var args = new Dictionary <string, object>()
            {
                { "livingID", living.ObjectID },
                { "traceLevel", traceLevel.ToString() },
            };

            var script =
                @"l = world.GetObject(livingID)
t = l.Trace
tl = t.TraceLevel.Parse(t.TraceLevel.GetType(), traceLevel)
t.TraceLevel = tl
";

            var msg = new Dwarrowdelf.Messages.IPScriptMessage(script, args);

            GameData.Data.User.Send(msg);
        }
        public void SendProceedTurn()
        {
            turnTrace.TraceVerbose("SendProceedTurn");

            if (m_world.IsOurTurn == false)
            {
                turnTrace.TraceWarning("SendProceedTurn when not our turn");
                return;
            }

            if (m_proceedTurnSent)
            {
                turnTrace.TraceWarning("SendProceedTurn when proceed turn already sent");
                return;
            }

            var list = new List <KeyValuePair <ObjectID, GameAction> >();

            IEnumerable <LivingObject> livings;

            if (m_world.CurrentLivingID == ObjectID.AnyObjectID)
            {
                // livings which the user can control (ie. server not doing high priority action)
                livings = m_world.Controllables.Where(l => l.UserActionPossible());
            }
            else
            {
                var living = m_world.GetObject <LivingObject>(m_world.CurrentLivingID);
                if (living.UserActionPossible() == false)
                {
                    throw new NotImplementedException();
                }
                livings = new LivingObject[] { living };
            }

            var focusedObject = this.FocusedObject;

            foreach (var living in livings)
            {
                GameAction action;

                if (m_actionMap.TryGetValue(living, out action) == false)
                {
                    // skip AI if we're directly controlling the living
                    if (focusedObject != living)
                    {
                        action = living.DecideAction();
                    }
                    else
                    {
                        action = living.CurrentAction;
                    }
                }

                Debug.Assert(action == null || action.GUID.IsNull == false);

                if (action != living.CurrentAction)
                {
                    turnTrace.TraceVerbose("{0}: selecting new action {1}", living, action);
                    list.Add(new KeyValuePair <ObjectID, GameAction>(living.ObjectID, action));
                }
            }

            m_user.Send(new Dwarrowdelf.Messages.ProceedTurnReplyMessage()
            {
                Actions = list.ToArray()
            });

            m_proceedTurnSent = true;
            m_actionMap.Clear();
        }
Exemple #8
0
		public void SendProceedTurn()
		{
			turnTrace.TraceVerbose("SendProceedTurn");

			if (m_world.IsOurTurn == false)
			{
				turnTrace.TraceWarning("SendProceedTurn when not our turn");
				return;
			}

			if (m_proceedTurnSent)
			{
				turnTrace.TraceWarning("SendProceedTurn when proceed turn already sent");
				return;
			}

			var list = new List<Tuple<ObjectID, GameAction>>();

			IEnumerable<LivingObject> livings;

			if (m_world.CurrentLivingID == ObjectID.AnyObjectID)
			{
				// livings which the user can control (ie. server not doing high priority action)
				livings = m_world.Controllables.Where(l => l.UserActionPossible());
			}
			else
			{
				var living = m_world.GetObject<LivingObject>(m_world.CurrentLivingID);
				if (living.UserActionPossible() == false)
					throw new NotImplementedException();
				livings = new LivingObject[] { living };
			}

			var focusedObject = App.MainWindow.FocusedObject;

			foreach (var living in livings)
			{
				GameAction action;

				if (m_actionMap.TryGetValue(living, out action) == false)
				{
					// skip AI if we're directly controlling the living
					if (focusedObject != living)
						action = living.DecideAction();
					else
						action = living.CurrentAction;
				}

				Debug.Assert(action == null || action.MagicNumber != 0);

				if (action != living.CurrentAction)
				{
					turnTrace.TraceVerbose("{0}: selecting new action {1}", living, action);
					list.Add(new Tuple<ObjectID, GameAction>(living.ObjectID, action));
				}
			}

			Send(new ProceedTurnReplyMessage() { Actions = list.ToArray() });

			m_proceedTurnSent = true;
			m_actionMap.Clear();
		}
Exemple #9
0
		void OnLivingRequestsAction(LivingObject living, GameAction action)
		{
			turnTrace.TraceVerbose("SignalLivingHasAction({0}, {1}", living, action);

			if (m_world.IsOurTurn == false)
			{
				turnTrace.TraceWarning("SignalLivingHasAction when not our turn");
				return;
			}

			m_actionMap[living] = action;

			SendProceedTurn();
		}
        public static void SendSetLivingTraceLevel(LivingObject living, System.Diagnostics.TraceLevel traceLevel)
        {
            var args = new Dictionary<string, object>()
            {
                { "livingID", living.ObjectID },
                { "traceLevel", traceLevel.ToString() },
            };

            var script =
            @"l = world.GetObject(livingID)
            t = l.Trace
            tl = t.TraceLevel.Parse(t.TraceLevel.GetType(), traceLevel)
            t.TraceLevel = tl
            ";

            var msg = new Dwarrowdelf.Messages.IPScriptMessage(script, args);

            GameData.Data.User.Send(msg);
        }