[Pogamut-list] understanding geometry, visible/hidden navpoint filtering

michal.bida pogamut-forum at artemis.ms.mff.cuni.cz
Tue Jul 14 17:22:36 CEST 2009


Re: Re: Re: Re: understanding geometry, visible/hidden navpoint filtering

Author: michal.bida

Hi Jeremy!

First of all - in your example here, you were using getKnownNavPoints method. This method returns all the navpoints that the bot knowns about - these NavPoints are stored in the bot memory and they are obtained when the bot connects to environment. These NavPoints ARE NOT updated during the runtime. The reason they are there is to let the bot to know about them. 

The NavPoints that are currently visible can be got through other method such as memory.getSeeNavPoints() . This method returns a list of NavPoints that are currently around the bot. Test their visibility field to know if they are currently in front of the bot (due to better orientation in the environment, this method will return also NavPoints that are behind the bot - but their visibility field will be set to false).

Or you can register a listener to NAV message completely overring Pogamut method code and handle these information yourself - which is sometimes a better way, cause you have then 100% control of the code. The code below picks the id of NavPoint the bot receives first. Then you can watch in introspection how this navpoint visibility is changing (the bot is programmed to turn around, so the visibility status of the NavPoints will change). Through this listener you will get all the navpoint messages the bot receives also with correct visibility fields.

Hope this helps. 

Best,
Michal

public class Main extends Agent {
    
    @PogProp String navId = "";
    
    @PogProp boolean visibility;

    /** Creates a new instance of agent. */
    public Main() {
        super();
        /**
         * set level of logging - see logging documentation, now you will see only more relevant things
         */
        this.log.setLevel(Level.INFO);
        this.platformLog.setLevel(Level.INFO);
    }
    

    RcvMsgListener myNavListener = new RcvMsgListener() {

        @Override
        public void receiveMessage(RcvMsgEvent e) {

            NavPoint nav;

            nav = (NavPoint) e.getMessage();
            
            if (navId.isEmpty()){
                navId = nav.UnrealID;            
            }
            
            if (navId.equals(nav.UnrealID)){
                visibility = nav.visible;
            }                        
            //getLogger().info("Message: " + gc.string);

        }
    };    
    
    @Override
    protected void postPrepareAgent() {
        this.getBody().addTypedRcvMsgListener(myNavListener, MessageType.NAV_POINT);
    }

    /**
     * Main method of the bot's brain - we're going to do some thinking about
     * the situation we're in (how it's unfair to be the bot in the gloomy world
     * of UT2004 :-).
     * 
     * Check out the javadoc for this class - there you find a basic concept
     * of this bot.
     */
    @Override
    protected void doLogic() {
        body.turnHorizontal(30);


    }
}





More information about the Pogamut-list mailing list