intfiction.org

The Interactive Fiction Community Forum
It is currently Tue May 21, 2013 10:25 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: AgendaItem Question
PostPosted: Fri Jun 03, 2011 11:08 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
AgendaItems have two parameters that seem redundant to me -- initiallyActive and isReady. Is there some reason why AgendaItems should be made active during game initialization? If not (and indeed, the default is nil), does it make any difference whether I delay the activity of the AgendaItem by setting initiallyActive = true and isReady = nil or vice-versa?

Or is this distinction only of value for an NPC who needs to do something on the very first turn (hence initiallyActive)?


Top
 Profile Send private message  
 
 Post subject: Re: AgendaItem Question
PostPosted: Sat Jun 04, 2011 1:07 am 
Offline

Joined: Tue Apr 27, 2010 1:02 pm
Posts: 797
initiallyActive is purely for convenience - a way to add an AgendaItem to an NPC's agenda at startup without having to roll your own InitObject / PreInitObject for that purpose. You have to add them somewhere; the NPC's executeAgenda routine only knows about the AgendaItems in their list. It checks them all, picks the first one where isReady returns true, and then runs it.

You might have a guard NPC with a lot of behaviors - patrolling a route, calling for help if attacked, running away if wounded, heading toward suspicious noises - all of which are always active and ordered by priority, but which are only ready under the right conditions. It would make sense for those AgendaItems to be initiallyActive so your guard starts the game able to react without having to call addToAgenda() in the action handling for any input that might trigger a response.

You could also have an NPC that only does a few, more heavily scripted things - like disarming a bomb - only one of which will be active at a time, and which will always be ready when active. Here you can set initiallyActive to nil, isReady to true, and call addToAgenda() in the code that starts the scene.

Or you could have a hybrid approach - a guard that does the normal stuff and then tries to disarm the bomb once the player tells him about it.


Top
 Profile Send private message  
 
 Post subject: Re: AgendaItem Question
PostPosted: Sat Jun 04, 2011 2:00 am 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
Thanks -- addToAgenda() is the piece of the puzzle that I didn't know about.

But unless I'm misunderstanding something, there doesn't seem to be a reason not to always make initiallyActive true for every AgendaItem. There seems to be no penalty for doing this.

It seems to be purely a matter of taste whether to use the defaults for the class (initiallyActive = nil, isReady = true) and call addToAgenda; or whether to make initiallyActive true for an AgendaItem and then either (a) write a method for isReady that will return true when certain conditions are met, or (b) just leave isReady = nil and add a line like

Code:
juliaTrekToRidge.isReady = true;


...when it's time for that AgendaItem to start running.


Top
 Profile Send private message  
 
 Post subject: Re: AgendaItem Question
PostPosted: Sat Jun 04, 2011 12:15 pm 
Offline

Joined: Tue Apr 27, 2010 1:02 pm
Posts: 797
Right, you can definitely do that. I like your a & b approaches.

If you had a lot of AgendaItems with very complex isReady conditions - ones that iterated through the object tree, or tested whether some very big number modulo the turn count was relatively prime - you might see a performance hit, especially if most of the conditions returned nil. The penalty in this case is that you do a lot of calculation every turn and the NPC winds up not doing anything at all.

On modern hardware this is not something I would lose sleep over, but I suspect it's half the reason behind the current defaults. The other half could be that addToAgenda(x) is better from an object-oriented perspective than x.isReady = true, since you aren't breaking the object metaphor by reaching inside a nominally black box and setting a property directly.


Top
 Profile Send private message  
 
 Post subject: Re: AgendaItem Question
PostPosted: Sat Jun 04, 2011 7:12 pm 
Offline
User avatar

Joined: Sat Dec 22, 2007 6:00 pm
Posts: 355
Location: Western Australia
bcressey wrote:
The other half could be that addToAgenda(x) is better from an object-oriented perspective than x.isReady = true, since you aren't breaking the object metaphor by reaching inside a nominally black box and setting a property directly.

From my point of view, setting isReady seems better than using addToAgenda, because it encapsulates all the AgendaItem's logic within the item. I can just look at a particular AgendaItem and say, "Right, that's activated when the NPC learns this piece of information," which saves time writing comments and/or being confused about what I was trying to achieve.

For what it's worth, all the AgendaItems in my WIP are initiallyActive, and use isReady to check whether they're available or not. I haven't had any problems with that approach, but I don't have that many AgendaItems and the way they interact is tightly controlled. If I had more AgendaItems, or if I was going for a less scripted, more AI-ish approach to NPC actions, addToAgenda might be a more attractive choice.

_________________
Emily Boegheim


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group