"""Defines generic class Message used for both commands and reports."""

class Message:
    """A class for generic timed message. 
    
    Only two parameters are present explicitely: type and delay.    
    Type is the type of the message, e.g. 'start','I am attacked' etc. 
    Delay sets how many update cycles the message stays in the queue. 
    Each update cycle delay is decreased by 1. When it reaches 0, the message 
    is porcessed and removed from the queue. 
    Context-specific parameters of the message are stored in the dictionary 
    paramsDict. 
    
    The class declaration is mostly hidden from the rest of the code. That  
    allows to distinguish reports from commands via functions sendReport and 
    sendCommand defined in class Agent."""

    def __init__(self, type, delay=0, paramsDict=None):
        self.type = type
        self.delay = delay
        self.dict = paramsDict

    def paramByName(self,name):
        """Retrieves message parameter by its name. The function first
        checks if the key is present in the parameters dictionary. 
        If the key is not present then the function returns None."""

        if (self.dict.has_key(name)):
            return self.dict[name]
        else:
            return None