Missions

Overview

As part of each game turn, NPCs can optionally be assigned to missions. Missions are the method by which you as the player interact with the world and cause the world to change. For instance, perhaps you are tasked with a mission to defeat some bandits. If you fail to defeat the bandits they murder an NPC. As a result a chain of missions is never unlocked. Or perhaps the bandit group takes over a town and enslaves the townspeople. If you, as the mercenary manager, talk to the companion you send on the mission beforehand and tell them to force information out of the bandits - why are the bandits doing what they’re doing - then when your companion goes on the mission they might learn that the bandits have been brainwashed by some evil magic.

My intent is to design the game so that communicating with your companions and NPCs is significant. The knowledge you acquire from talking with NPCs has the power to change the results of the mission. If you learn that the bandits harassing people are evil your companion is more likely to kill the bandits while on the mission. If you learn that the bandits’ family have been kidnapped and they’re being forced to do bad deeds, maybe your companion will leave the bandits be for now and come back with said information as well as a new mission to save their families and/or kill their captors. I re-iterate here that this new mission is not generatively created on the fly. This is a mission that has been expertly created by the game designer that unlocks based on which mission outcome results. However, the mission outcome that result is impacted by the long term memory and knowledge of the companion sent on the mission.

So how do missions work? Missions are expertly created - this means that they are put together by the game designer in the react frontend. A mission is comprised of the following components.

  • Name - this is simply for identification and not really important.

  • Briefing - This describes the mission to the player. For instance it could be something as simple as “bandits have been causing trouble at the local tavern, deal with them”.

  • Associated tags - This is the list of entities/knowledge-tags that are important to the mission. For instance, this could include “TumTum”, “TumTum’s Tavern”, and “Bandits”. This makes it so that the state of these entities/tags can be updated based on the mission results.

  • Outcomes - A list of potential outcomes where an outcome is comprised of a name and mission summary. The mission outcome can be as generic or specific as the game designer wants. It’s essentially the backbone of the outcome and then genAI is used to generate the full narrative. The reason why we feed the LLM a list of possible outcomes as opposed to giving it free reign is so that we can constrain the system and make sure that we stick to the structure of the story that we have.

  • Availability Logic - depending on the state of the game, the mission may or may not be available to the player. For instance, maybe you need to complete a certain NPC objective in order to unlock the mission. Or maybe the mission unlocks based upon the outcome of some other mission.

So what is a mission from the perspective of the player and how do they work? When the player receives a mission, they simply see a mission briefing. They then have the option of sending a companion on the mission, or they can just ignore the mission. After sending a companion on the mission, a narrative of the mission is generated. This includes the outcome of the mission in narrative form. It’s essentially just like a 3 paragraph short story of what happened on the mission.

Okay, so this potentially sounds sort of boring and trivial. What else goes on under the hood? So there are a few things that I want to bring up here.

First, the companion you send on the mission matters. If you send an NPC with a violent personality on a diplomacy mission, then that mission could potentially end catastrophically. Perhaps the companion murders the diplomat and a war erupts. If you send your bard on a solo mission to stop some bandits, mayhaps your companion is legitimately just killed. This changes the game state as well as the future direction of your game. For example, if your companion kills the diplomat, maybe one mission unlocks, whereas if you recruit a skilled diplomat as a companion and send him/her on the mission you forge an alliance with a great nation. This is essentially the system that allows the game to move forward and branch in different directions.

How does the mission updated the world state? So the world state is essentially tracked as a set of knowledge. Each important entity has its own state which is represented as knowledge (e.g. its just a txt doc). When a mission is completed, information relevant to each entity/knowledge-tag in ‘associated tags’ is generated and the knowledge docs are updated appropriately. So if the diplomat is murdered, that entity’s knowledge doc would be updated such that the diplomat is dead. If any NPCs have access to that knowledge tag, then they would be aware that said diplomat has been murdered.

Prompt Pipeline

So how does it all work under the hood? The inputs to the mission system are simple: a mission and NPC(s) assigned to the mission.

  • Assigned NPCs: Currently, only a single NPC can be assigned to a mission but there are plans to make it so that multiple companions can be assigned to the mission. This introduces the concept of team building. Do your companions skills complement each other? Do your companions get along or are they likely to try and murder each other while out on mission?

  • Mission: The mission is comprised of a mission briefing and skeletons of possible mission outcomes. The mission also has availability logic (what game state causes this mission to be available) and effects (e.g. what knowledge is acquired based on the mission outcome).

The outputs are quite simple as well: (1) the mission narrative and (2) updates to the game state. The mission narrative is stored in the NoSQL DB and the player will see the mission results in the form of this narrative when their companions do (or don’t) return from the mission. Updates to the game state are stored in the knowledge base. For instance, if a building is burned down, the entity/knowledge tag associated with said building will be adjusted appropriately. If the companion sent on the mission does something heroic and the companions’ acts are witnessed by others then the companions’ knowledge document will be updated appropriately as well.

Okay, so those are the inputs and outputs of the mission system, but how about the guts? The general workflow for missions, shown in Figure X, is comprised of four stages. These stages are (1) Context Retrieval, (2) Mission Synopsis, (3) Mission Narrative Writing, (4) Context Update. During context retrieval, we pull relevant information from your companions’ knowledge and long term memories. During stage 2, we generate a general overview of what happened on the mission as well as the outcome of the mission. During stage 3, we generate an actual short-story-like written narrative of the mission which is outputted to the game player. During stage 4, we extract updates to each of the entities (knowledge tags) that are effected by the mission. We then update the knowledge documents for these entities; the world needs to update in accordance with the mission outcome after all. Lastly, we progress the game state per the mission outcome. This could mean locking/unlocking npcs, npc objectives, or missions etc. It also allows for various outcome-specific missions effects such as knowledge explicitly added to some knowledge base.

Generic Role / Mission Prompt: We begin by telling the LLM of its role and some details about how to carry it out.

Generate a mission narrative for a game using the following structure: Begin with a 'Brief Recap' that summarizes the mission's objective and lists the chosen NPC(s). Transition into 'Departure', painting a scene of the mission preparations and capturing the emotions and thoughts of the NPCs as they start their journey. Introduce 'Challenges & Encounters', detailing the obstacles or confrontations the NPCs face, adding tension and action. As the narrative unfolds, highlight 'Decision Points', emphasizing critical choices made by NPCs and showing their consequences. Build the story to its 'Climax', narrating the peak and most intense moments of the mission. Follow with the 'Outcome', describing whether the mission was a success or failure and the direct consequences of NPC actions. Detail the 'Aftermath', illustrating post-mission events, the NPCs' return, and any character development. Finally, wrap up with a 'Feedback Loop' that offers reflection on the mission, player choices, and hints for future strategy. Using this structure, craft a dynamic mission narrative based on specific player choices and mission details.

Mission Briefing: We pass the mission prompt to the LLM so that it understands the mission that has been given to the player.

Mission Outcomes: We pass the potential mission outcomes (names and summaries) that are available to the LLM so that it knows the possible directions.

NPC Personality: We pass the personality of the NPC to the mission so that the LLM understands the general tendencies, abilities, and personality characteristics of the NPC that are undertaking the mission.

Long Term Memories: We pass relevant LTMs (long term memories) to the LLM prompt. These memories are extracted from the NPC’s long term memory vector store via multiple steps. First, we sub-query the LLM to generate a list of questions that we should ask the NPC LTM to extract relevant information from the NPC’s memory.

"""Given the following mission brief and potential mission outcomes we need to generate a list of questions

that can be used to query an NPC's long-term memory to pull out core NPC characteristics as well as to gather

relevant information and experiences that might impact the outcome or narrative of the mission:

mission_brief: {mission_brief}

potential mission outcomes: {formatted_mission_outcomes}

''''

You must format your output as a JSON dictionary that adheres to the following JSON schema instance:

'questions': The list of questions

"""

We then take these questions and query the long term memory. We pass these responses to the mission prompt.

Knowledge: Knowledge proceeds in a manner very similar to long term memory. We sub-query the LLM to generate a list of questions to query the NPC-specific knowledge index. We then feed the responses to the mission prompt chain.

Output Format: As with the other prompts, the output of the LLM is a json dictionary with a variety of key value pairs which step by step have the LLM explain what it is doing. The outputs are further explorer in subsection 3.2.2.

Mission Outcome Outputs

You must format your output as a JSON value that adheres to the following JSON schema instance:

"Summarize the mission's objective": "Provide a concise recap of what the mission seeks to achieve.",

"List the chosen NPC(s) for the mission": "Identify and provide brief information on the non-player characters selected for the task.",

"Set the immediate context for the story": "Offer a backdrop or situation that sets the stage for the upcoming mission.",

"Describe mission preparations": "Narrate the steps, arrangements, or strategies decided upon before embarking on the mission.",

"Convey NPC emotions/thoughts as the mission starts": "Capture the feelings, mindset, or expectations of the NPCs as they begin their task.",

"Set the initial tone": "Establish the atmosphere, mood, or general sentiment at the onset of the mission.",

"Detail obstacles or confrontations faced": "Elaborate on challenges, enemies, or dilemmas the NPCs encountered during their journey.",

"Create tension and action sequences based on the mission's challenges": "Construct thrilling and suspenseful moments deriving from the mission's hurdles.",

"Emphasize critical choices made by NPCs": "Highlight decisions or crossroads that had significant impact on the mission's direction.",

"Relate choices to NPC attributes or prior player decisions": "Connect decisions to the character traits of NPCs or actions taken by the player in previous scenarios.",

"Show the consequence of these decisions on the mission": "Illustrate the outcomes, results, or repercussions of the choices made during the mission.",

"Narrate the peak of the mission": "Provide a detailed account of the climax or pinnacle moment of the mission.",

"Describe the most intense or revealing moment": "Delve into the highlight or major twist of the mission, capturing its intensity.",

"State mission results (success/failure)": "Clearly announce the outcome of the mission, indicating whether objectives were met or not.",

"Outline direct consequences of NPC actions": "List the immediate effects, results, or changes brought about by the actions of the NPCs during the mission.",

"Highlight tangible rewards or setbacks": "Spotlight any physical rewards, information gained, alliances formed, or setbacks faced as a result of the mission's outcome.",

"Narrate the post-mission events": "Detail events or situations that arise after the main mission concludes.",

"Describe the NPCs' return and any character development": "Narrate the condition, mindset, or any growth of the NPCs as they return from the mission.",

"Highlight potential long-term consequences or future hints": "Provide clues, foreshadowing, or implications of the mission's impact on future events or missions."

"outcome" : "the name of the outcome that the NPC chose."

So why do we utilize each of the various components of this json dict?

Outcome: The name of the outcome that the mission resulted in. This is used for game state progression. For instance, one outcome might result in unlocking a new NPC whereas another might unlock a new mission or NPC objective; just depends on what the game designer wants.

List the Chosen NPC(s) for the mission: This is essentially just making the LLM re-iterate (for debugging purposes) the NPCs that are on the mission.

Set the immediate context of the story: This is making sure that the LLM can re-iterate what is currently going on as part of the story. The LLM needs to prove that it is aware of the mission as well as potentially any relevant knowledge that is relevant to the mission.

Describe Mission Preparations: This is mostly just used to set the scene to a certain extent. How is the NPC preparing for the mission?

Convey NPC emotions/thoughts: Similar to above, what are the NPC’s thoughts on the mission? This is likely extracted from the NPC LTM & Knowledge.

Set the initial tone: There are a lot of different types of stories that can be written. E.g. is the mission dramatic, comedic etc.

Detail obstacles of confrontations:

Create tension and action sequences

Emphasize critical choices made by the NPCs

Relate choices to NPC attributes

Show the consequences of these decisions on the mission outcome

Narrate the peak of the mission

Describe the most intense or revealing moment

State mission results

Outline direct consequences of the NPC actions

Highlight tangible rewards or setbacks

Describe character development

Highlight potential long term consequences

Sample Output:

The village of Mier and its surroundings were enveloped in an air of unease. Ruffians, a group of miscreants notorious for their thievery and pranks, had been causing havoc, stealing goods, and tormenting the villagers. The once peaceful community now lived in constant fear. It was in the midst of this turmoil that Brian, a rugged mercenary member, emerged as the chosen one for the mission. As he prepared for the task ahead, the clinking of his armor and the sharpening of his sword echoed through the quiet streets. Brian's heart raced with a mix of excitement and nervousness as he set out on his journey, eager to prove himself but also aware of the challenges that lay ahead. The villagers, their eyes filled with both hope and doubt, watched him leave, whispering prayers for his success. The path ahead was shrouded in mystery, and Brian couldn't help but wonder what awaited him in the shadows of the surrounding woods and plains. Little did he know, his bravery and skills would soon be put to the ultimate test, as the ruffians he sought to confront were more skilled and formidable than he could have ever imagined.

Brian meticulously prepares for the mission, carefully inspecting his equipment and tightening the straps on his worn leather armor. The morning sun casts long shadows as he steps out onto the cobblestone streets of Mier, a mix of excitement and nervousness knotting in his stomach. The villagers watch from their doorways, their eyes filled with a mixture of hope and skepticism. 'Brian, be careful out there!' an elderly woman calls out, her voice laced with concern. 'I'll do my best, ma'am,' Brian replies with a determined smile. As he approaches the outskirts of Mier, the familiar sounds of chirping birds and rustling leaves are replaced by an eerie silence. The dense woods loom ahead, their branches reaching out like gnarled fingers. Brian's heart races as he senses the presence of the ruffians lurking in the shadows. With a firm grip on his sword, he steps forward, ready to face whatever challenges await him. The air crackles with tension as he confronts the group of ruffians, their eyes gleaming with menace. 'You think you can take us on, little mercenary?' their leader sneers. Brian's voice quivers slightly as he responds, 'I may be young, but I won't back down.' The battle erupts in a flurry of steel and sweat, each clash of swords echoing through the woods. Brian's muscles strain with effort as he tries to hold his ground, but the ruffians' superior skills soon become evident. Each blow sends shockwaves of pain through his body, the taste of defeat bitter on his tongue. Despite the odds stacked against him, Brian fights with an unwavering determination, unwilling to surrender. But as the battle reaches its peak, he realizes the harsh reality of his limitations. The ruffians overpower him, their ruthless blows raining down on him like a storm. Brian's vision blurs, his body battered and bruised, as he falls to the ground in defeat. The rising action reaches its climax, leaving Brian at a crossroads, questioning his abilities and the path he has chosen.

Brian's heart pounded in his chest as he faced the group of ruffians, their menacing grins etched with cruelty. The air crackled with tension, each second stretching out like an eternity. With a surge of adrenaline, Brian charged forward, his sword clashing against the ruffians' blades. The clash of steel filled the air, echoing through the surrounding woods. Sweat dripped down his brow as Brian fought with all his might, but the ruffians moved with an uncanny grace, their attacks precise and deadly. As the battle raged on, Brian's muscles screamed in protest, his breath coming in ragged gasps. He could feel the weight of defeat pressing down on him, the realization of his own limitations. In a desperate attempt to turn the tide, Brian gathered every ounce of strength, his sword swinging in a frenzied flurry. But it was all in vain. The ruffians, with a cruel smile, launched a devastating counterattack, overpowering Brian with their superior skills. The world spun as Brian hit the ground, pain searing through his body. Through blurred vision, he saw the ruffians loom over him, victorious. The mission had ended in failure, and the ruffians continued to terrorize the villagers.

As Brian limps back to the guild, his body battered and bruised, he can't help but feel a sense of defeat weighing heavily on his shoulders. The once eager and confident mercenary is now filled with self-doubt and frustration. The villagers who had placed their hopes in him look on with disappointment, their trust shattered. Brian's injuries serve as a painful reminder of his limitations, both in skill and experience. However, amidst the physical pain and emotional setbacks, a spark of determination ignites within him. He vows to recover and become a more capable fighter, seeking out further training to improve his skills. With a newfound sense of purpose, Brian reflects on his performance and the mistakes he made during the mission. He knows that he can't change the past, but he can shape his future. The defeat and continued presence of the ruffians foreshadow the challenges that lie ahead, hinting at the need for stronger and more skilled mercenaries to overcome them. The falling action serves as a turning point in Brian's journey, marking the beginning of his transformation from a naive and inexperienced mercenary to a seasoned and resilient warrior.

Last updated