/*
     *	A person (or entity) can remove speech after moving onto another state
     *
     */
    public void RemoveMessageImmediate(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID())) {
            SpeechBubble speechBubble = speechBubbles[entity.GetID()];

            if (speechBubble.panel != null)
                speechBubble.panel.RemoveSpeechBubble();

            speechBubbles.Remove(entity.GetID());

        }
    }
    Dictionary<int, SpeechBubble> speechBubbles = new Dictionary<int, SpeechBubble>(); // first int is entity id

    #endregion Fields

    #region Methods

    /*
     *	A person (or entity) can remove speech after completing showing speech bubble
     *	(called from speech bubble panel)
     *
     *	Delay removal (therefore introducing timeout to next continuous speech bubble)
     */
    public void RemoveMessageDelayed(Entity entity)
    {
        if (speechBubbles.ContainsKey(entity.GetID())) {
            // make sure we're not already waiting for removal
            if (!speechBubbles[entity.GetID()].waitingForRemoval) {
                // setup delayed removal
                speechBubbles[entity.GetID()].waitingForRemoval = true;

                int removalTimeInSeconds = TimeController.TimeInSeconds + speechRemovalTimeDelayInSeconds;
                speechBubbles[entity.GetID()].removalTimeInSeconds = removalTimeInSeconds;

                removeQueue.Enqueue(speechBubbles[entity.GetID()]);

            }
        }
    }
Example #3
0
    public CostNode(Cost cost, Entity entity, int time)
    {
        Entity = entity;
        EntityID = Entity.GetID();

        CostPerHour = cost.costPerHour;
        TimeInMinutes = time;
    }
Example #4
0
 public override void HandleCollisionEnd( Entity collider )
 {
     if( null == collider )
     {
         //-- Ignore null targets
         return;
     }
     
     if( IsAffectedTarget( collider ) )
     {
         //-- Check if this entity is one of our targets
         int targetSlotIndex = -1;
         if( m_TargetLookup.TryGetValue( collider.GetID(), out targetSlotIndex ) )
         {
             //-- If so, deactivate it
             
         }
     }
 }
Example #5
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }
        
        if( IsAffectedTarget( collider ) )
        {
            int newTargetSlotIndex = -1;
            if( 0 < m_FreeSlots.Count )
            {
                //-- There's an expired target we can use
                int slotIndex = m_FreeSlots.Dequeue();

                //-- Re-initilize expired target with new data
                HotSpotTarget target = m_TargetPool[slotIndex];
                {
                    target.TargetEntityID = collider.GetID();
                    target.AffectationCount = 0;
                    target.Active = true;
                }

                newTargetSlotIndex = slotIndex;
            }
            else
            {
                //-- There was no more room in the pool, so grow it. Create a new
                //   target and append it to the target pool
                HotSpotTarget newTarget = new HotSpotTarget();
                newTarget.TargetEntityID = collider.GetID();
                newTarget.AffectationCount = 0;
                newTarget.Active = true;

                //-- Add new slot to target pool
                m_TargetPool.Add( newTarget );

                newTargetSlotIndex = m_TargetPool.Count - 1;
            }

            //-- Register the new target to our lookup dictionary
            m_TargetLookup[collider.GetID()] = newTargetSlotIndex;

            //-- Immediately schedule the target to be affected
            ScheduleTarget( newTargetSlotIndex, GameSystem.GetTime() + m_InitialDelay );
        }
    }
Example #6
0
 /// <summary>
 /// Prints the description for an individual entity on its own line.
 /// </summary>
 /// <param name="entity"></param>
 private static void PrintEntity( Entity entity )
 {
     Console.Out.WriteLine( entity.GetID() + " - " + entity.ToString() + " [" + entity.m_Type.ToString() + "]" );
 }
Example #7
0
    /// <summary>
    /// Removes a specified entity from the game. This private function assumes that its parameter
    /// is a valid entity currently present in the game world.
    /// </summary>
    /// <param name="entity"></param>
    private static void RemoveEntity( Entity entity )
    {
        //-- Remove any collision that this entity may be involved with
        RemoveCollision( entity );
        
        //-- Remove the entity from the world
        entity.ExitWorld();
        s_GameEntities.Remove( entity.GetID() );

        //-- Print
        Console.Out.Write( "Removed entity: " );
        PrintEntity( entity );

        Console.Out.WriteLine();
        PrintEntities();
    }
Example #8
0
    /// <summary>
    /// Adds a specified entity to the game world.
    /// </summary>
    private static void AddEntity( Entity entity )
    {
        //-- Print new entity
        Console.Out.Write( "Created entity: " );
        PrintEntity( entity );

        //-- Add the entity to the world
        s_GameEntities.Add( entity.GetID(), entity );
        entity.EnterWorld();

        //-- Print list
        Console.Out.WriteLine();
        PrintEntities();
    }
Example #9
0
    /// <summary>
    /// Returns an active collision involving two specified entities or null if
    /// no such collision exists.
    /// </summary>
    private static Tuple<InstanceID, InstanceID> GetCollision( Entity entity1, Entity entity2 )
    {
        foreach( Tuple<InstanceID, InstanceID> collision in s_Collisions )
        {
            bool colliding = false;
            colliding = colliding || ((collision.Item1 == entity1.GetID()) && (collision.Item2 == entity2.GetID()));
            colliding = colliding || ((collision.Item2 == entity1.GetID()) && (collision.Item1 == entity2.GetID()));

            if( colliding )
            {
                //-- Both members of the collision match the specified entities
                return collision;
            }
        }

        return null;
    }
Example #10
0
    /// <summary>
    /// Removes all active collisions involving a specified entity or does nothing
    /// if no such collisions exist.
    /// </summary>
    private static void RemoveCollision( Entity entity )
    {
        LinkedListNode<Tuple<InstanceID, InstanceID>> collisionIter = s_Collisions.First;
        while( null != collisionIter )
        {
            //-- Cache next collision
            LinkedListNode<Tuple<InstanceID, InstanceID>> nextCollisionIter = collisionIter.Next;

            //-- Remove this collision if one of its colliders is the entity
            Tuple<InstanceID, InstanceID> collision = collisionIter.Value;
            if( (collision.Item1 == entity.GetID()) || (collision.Item2 == entity.GetID()) )
            {
                //-- Send collision end events
                Entity collider1 = GetEntity( collision.Item1 );
                Entity collider2 = GetEntity( collision.Item2 );

                if( null != collider1 )
                {
                    collider1.HandleCollisionEnd( collider2 );
                }

                if( null != collider2 )
                {
                    collider2.HandleCollisionEnd( collider1 );
                }

                //-- Remove the collision
                s_Collisions.Remove( collisionIter );
            }

            //-- Next collision
            collisionIter = nextCollisionIter;
        }
    }
Example #11
0
    /// <summary>
    /// Adds a collision between two specified entities
    /// </summary>
    private static void AddCollision( Entity entity1, Entity entity2 )
    {
        //-- Only add a collision if the pair aren't already colliding
        if( GetCollision( entity1, entity2 ) == null )
        {
            //-- Send collision events
            entity1.HandleCollision( entity2 );
            entity2.HandleCollision( entity1 );

            //-- Add new collision
            s_Collisions.AddLast( new Tuple<InstanceID, InstanceID>( entity1.GetID(), entity2.GetID() ) );
        }
    }
Example #12
0
    public override void HandleCollisionEnd( Entity collider )
    {
        if( null == collider )
        {
            //-- Ignore null targets
            return;
        }

        //-- Track colliding entity
        m_CollidingEntities.Remove( collider.GetID() );
        
        if( IsAffectedTarget( collider ) )
        {
            //-- Remove the target from any jobs it might be in
            RemoveTargetFromJobs( collider.GetID() );
        }
    }
Example #13
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }

        //-- Track the colliding entity
        m_CollidingEntities.Add( collider.GetID() );

        if( IsAffectedTarget( collider ) )
        {
            //-- Create a new target to schedule to be affected
            HotSpotTarget newTarget = new HotSpotTarget();
            newTarget.TargetEntityID = collider.GetID();
            newTarget.AffectationCount = 0;

            //-- Schedule the new target
            ScheduleTarget( newTarget, GameSystem.GetTime() + m_InitialDelay );
        }
    }
    /*
     *	Create a new speech bubble and add to list
     */
    public void SendMessage(string[] messages, Entity sendingEntity, int messageType)
    {
        // choose what message to use
        int randomMessageIndex = Random.Range(0, messages.Length);
        string message = messages[randomMessageIndex];

        // create speech bubble, set parameters
        SpeechBubble speechBubble = new SpeechBubble(message, messageType, sendingEntity);
        speechBubbles.Add(sendingEntity.GetID(), speechBubble);

        // THIS IS TEMPORARY - this should be managed by looking at the list
        // for now, send to panel to create new speech bubble panel
        if (ShouldCreateSpeechBubble(messageType, sendingEntity.transform.position) &&
                                     !speechBubbles[sendingEntity.GetID()].bubbleCreated) {
            //print("creating speech bubble! size = " + speechBubbles.Count + " entity ID = " + sendingEntity.GetID());

            speechBubbles[sendingEntity.GetID()].panel = speechBubblePanel.CreateNewSpeechBubblePanel(sendingEntity.transform,
                                                                              message,
                                                                              sendingEntity,
                                                                              this);
        } else
            RemoveMessageDelayed(sendingEntity);
    }
 public void SendMessageContinuous(string[] messages, Entity sendingEntity, int messageType)
 {
     if (speechBubbles.ContainsKey(sendingEntity.GetID()))
         return;
     else
         SendMessage(messages, sendingEntity, messageType);
 }