Sign in to follow this  
imontheverge

Updating game world every new day

Recommended Posts

Im looking to create a class that will update things like quests after my character sleeps or a new day has started. I currently have a single class that updates my game clock and current day.
My first idea was to create a class that will run an update quest method every time a new day has started, in other words after the clock hits midnight. I think this may work but I am curious as to how other people have gone about this?

Share this post


Link to post
Share on other sites

I would rather add a vector of listener classes to my main Class that updates clock and day with methods addListener(listener*) and removeListener(listener*)

 

then once that class updates the clock and day, it would call the update methods of the listener classes in the list.

 

So, you dont have to make major code changes whenever you decide you need to do do some other operation depending on time and day, you just create another listener derived class and register it as a listener...

Share this post


Link to post
Share on other sites

the update portion of Caveman 3.0 is split into:

 

do_global_frame  (single updates, or stuff that updates every N updates)

do_global_second  (stuff that updates once per second, or every N seconds)

do_global_minute  (stuff that updates once per minute, or every N minutes)

do_global_hour  (stuff that updates once per hour, or every N hours)

do_global_day  (stuff that updates once per day, or every N days).

do_global_year  (stuff that updates once per year - basically a happy birthday message).

 

everything is updated only as often as necessary.

 

doing it this way, i can update things at rates from every update all the way up to every N game years.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

Use events and abstraction. If you make a single class or method, you will be strongly tying your code together. Every time you add a new quest, you will have to include knowledge of the quest with your master quest update class, slowing production in the long run and cause avoidable headaches.

 

i.e.

class KillGoblinsQuest: public QuestBase, public EventListener;
 
EventListener::Trigger(EventType type)
{
    switch(type)
    {
        case newDay:
        {
           //do stuff
        }
    }
}

or

 

class KillGoblinsQuest: public QuestBase
 
QuestBase::NewDay()
{
    //do things
}
 
int main()
{
    //Update
    KillGoblinsQuest.NewDay();
}

 

that's what I would do

Edited by ExErvus

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this