Location, Location, Location

In anticipation of a huge new feature in Vidar, today I’m talking location. Specifically, how NPC locations are handled in the game.

A town of 24 would feel stagnant indeed if everyone just stayed in their homes and never went outside, never visited, never did anything but Move Path: Randomed in their little corner. Just like dialogue frequently changes in Vidar, so does location – in the demo, for example, Etel, the city watchman, can be at the inn drinking, outside on patrol, or guarding Cecilia’s house.

Each npc has an attribute called location, represented as [m,x,y] – where m is the map, and x and y are the coordinates on that map. That’s where the npc should appear, and nowhere else. Unsurprisingly, we set this location the same way we set dialogue trees: with Chat Mapper.

Look familiar? The location trees don't have dialogue, ONLY script calls.

Look familiar? The location trees don’t have dialogue, ONLY script calls.

As mentioned in my previous serious on Chat Mapper, the dialogue tree can also do script calls depending on how we go down the tree. It’s the stuff that appears after \script. At the beginning of every day, we can just “run” every tree to set the location for that day based on, e.g., who is dead.  In the above, if Dorottya is dead but Cecilia is not, Dani’s location will be outside, and the x and y are the location of Dorottya’s grave. She’s visiting and paying respects.

Then we have a function that reads like this:

def place_npcs_on_map(map_id)
  $npc_hash.each do |key, npc|
    next if npc.is_dead?
    next unless npc.location[0] == map_id
    newevent = EventSpawn.spawn_event(33, npc.event_id, npc.location[1], npc.location[2], false, 0)
    npc.spawned_event_id = newevent.id
   end
end

This function (which will get called every time we transfer maps) takes the destination map ID. It then cycles through the 24 NPCs and asks “are they alive? Are they on this destination map? If so, spawn them at their correct x,y, and make sure to save the new event id.”

With these two tools, Vidar is suddenly more dynamic. Not everyone is confined to their homes. People who were outside yesterday are inside today (assuming they’re alive).

What this doesn’t consider is someone changing maps on the same day. We’ll address it in a future post!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s