[Pogamut-list] Receive Kill Message
jakub.gemrot
pogamut-forum at artemis.ms.mff.cuni.cz
Mon Dec 14 07:33:27 CET 2009
Re: Receive Kill Message
Author: jakub.gemrot
Hi gotzl!
Where have you written this code?
I hope you did not written this method directly to the your bot? I mean to the subclass of Agent class?
It's stupid design-choice made by us that Agent is directly receiving messages - you can't override this method
like this because you will forbid OUR receiveMessage() to receive messages (at least you should call super.receiveMessage(e);).
But the preferred way to deal with messages is create anonymous classes (listeners) like this:
RcvMsgListener playerKilledListener = new RcvMsgListener() {
@Override
public void receiveMessage(RcvMsgEvent e)
{
switch(e.getMessage().type)
{
case PLAYER_KILLED:
PlayerKilled? pk = (PlayerKilled)e.getMessage();
break;
}
}
};
and inside prePrepareAgent method register the listener like this:
body.addRcvMsgListener(playerKilledListener, EnumSet.of(MessageType.PLAYER_KILLER));
...
Back to your question - you're getting this many messages because Agent class is registering general
listener at the body ... this.body.addRcvMsgListener(this); ... therefore every message goes
through your overriden method.
Hopefully I guessed correctly ;) or did I not?
Cheers!
Jakub
More information about the Pogamut-list
mailing list