#Fight_Story.connect(One, {}, Two) #Fight_Story.connect(Two, {}, Three) #Fight_Story.connect(Three, {}, Four) # #Fight_Rule = RewriteRule(None, Fight, Fight_Story, None, "Fight") #---------------------------------------------------- # MurderBlackmailer Skeleton #---------------------------------------------------- #---------------------------------- # Social Condition #---------------------------------- A = SocialNode("Invoker", {"type" : "NPC", "alive" : True}) B = SocialNode("Recipient", {"type" : "NPC", "alive" : True}) MurderBlackmailer = Graph("MurderBlackmailer", [A, B]) MurderBlackmailer.connect(A, {"Blackmail" : "N/A"}, B) #---------------------------------- # Social Outcomes #---------------------------------- # Player Movement mod_a = {"Method" : {"name" : SocialNode.move_player_to_node, "self" : {"ref" : "Player"}, "args" : [{"ref" : "Invoker"}]}} Move_1 = [mod_a] mod_a = {"Method" : {"name" : SocialNode.move_player_to_node, "self" : {"ref" : "Player"}, "args" : [{"ref" : "Recipient"}]}} Move_2 = [mod_a] # Kill Victim mod_1 = {"Method" : {"name" : SocialNode.murder, "self" : {"ref" : "Recipient"}, "args" : [{"ref" : "Player"}]}}
#Spare = StoryNode("Spare", {"Node_Type" : "Sympathy", "Additional" : "Branched_Node"}, Target) #Ambush.set_modification(Ambush_Modification) #Ambush_Story_Outcome = StoryGraph("Ambush_By_Hater_Story_Outcome", [Murder, Ambush, Spare]) #Ambush_Story_Outcome.connect(Murder, {}, Ambush) #Ambush_Rule = RewriteRule(Ambush_Story_Condition, Ambush_Social_Condition, Ambush_Story_Outcome, None, "Ambush_By_Hater", True) #---------------------------------------------------- # Ambush Skeleton #---------------------------------------------------- #---------------------------------- # Social Condition #---------------------------------- Monster = SocialNode("Monster", {"alive": True}) Recipient = SocialNode("Recipient", {"alive" : True}) Ambush_Social_Condition = Graph("Stolen_Gift_Social_Condition", [Monster, Recipient]) Ambush_Social_Condition.connect(Monster, {"Hates" : "N/A"}, Recipient) #---------------------------------- # Social Modification #---------------------------------- #---------------------------------- # Story Condition #---------------------------------- Murder = StoryNode("Give_Gift", {"Node_Type" : "Give_Item"}, Recipient) Ambush_Story_Condition = StoryGraph("Stolen_Gift_Condition", [Murder]) #---------------------------------- # Story Outcome #---------------------------------- Spare = StoryNode("Stolen_Gift", {"Node_Type" : "Robbery", "Additional" : "Branched_Node"}, Monster) Foigh = StoryNode("Fight_For_Gift", {"Node_Type" : "Fight", "Additional" : "Branched_Node"}, Monster)
def applyRule(self, chosen_results, social_results, narrative): #Get the rule from our chosen results chosen_rule = chosen_results[1] #Get the new story nodes from our results resulting_story_nodes = choice(chosen_results[0]) #Get the resulting story nodes for our rewrite result = choice(social_results) #Get the social condition from our rule social_condition = chosen_rule.get_social_condition() #Add any new cast members necessary for i in range(len(result)): if not social_condition.get_nodes()[i].get_name() in narrative.get_cast(): narrative.add_cast(social_condition.get_nodes()[i].get_name(), result[i]) story_modification = chosen_rule.get_story_modification() #Make our new graph nodes = [] for node in story_modification.get_nodes(): target = narrative.get_cast()[node.get_target().get_name()] new_node = node.Copy_Story_Node() new_node.set_linked_to_node(target) new_node.add_attribute("Target", target.get_name()) nodes.append(new_node) new_graph = Graph("Temp", nodes) adj = story_modification.get_adjacency() for row in range(len(adj)): for col in range(len(adj)): if adj[row][col] == 1: adj[col][row] = 0 new_graph.connect(nodes[row], {}, nodes[col]) backup_narrative = narrative.Copy() narrative.replace_node_with_new(narrative.get_node_from_name(resulting_story_nodes[0].get_name()), new_graph) narrative.fix_graph() self._social_graph.make_node_postconditions(narrative) narrative.initialize_conditions() narrative.refine_lost_conditions() print "Validating Final Story\n" if self._verbose: print self._divider for node in narrative.get_nodes(): print "Preconditions for " + node.get_name() for con in node.get_preconditions(): print con print "\nPostconditions for " + node.get_name() for con in node.get_postconditions(): print con print "\nLost Conditions for " + node.get_name() for con in node.get_lostconditions(): print con print "\n" + self._divider valid = narrative.validate_story() if not valid: print "INVALID STORY" self._invalids += 1 print "VALIDS = " + str(self._valids) print "INVALIDS = " + str(self._invalids) return backup_narrative else: print "VALID STORY" self._valids += 1 print "VALIDS = " + str(self._valids) print "INVALIDS = " + str(self._invalids) return narrative
def applyRule(self, chosen_results, social_results, narrative): #Get the rule from our chosen results chosen_rule = chosen_results[1] #Get the new story nodes from our results resulting_story_nodes = choice(chosen_results[0]) #Get the resulting story nodes for our rewrite result = choice(social_results) #Get the social condition from our rule social_condition = chosen_rule.get_social_condition() #Add any new cast members necessary for i in range(len(result)): if not social_condition.get_nodes()[i].get_name( ) in narrative.get_cast(): narrative.add_cast(social_condition.get_nodes()[i].get_name(), result[i]) story_modification = chosen_rule.get_story_modification() #Make our new graph nodes = [] for node in story_modification.get_nodes(): target = narrative.get_cast()[node.get_target().get_name()] new_node = node.Copy_Story_Node() new_node.set_linked_to_node(target) new_node.add_attribute("Target", target.get_name()) nodes.append(new_node) new_graph = Graph("Temp", nodes) adj = story_modification.get_adjacency() for row in range(len(adj)): for col in range(len(adj)): if adj[row][col] == 1: adj[col][row] = 0 new_graph.connect(nodes[row], {}, nodes[col]) backup_narrative = narrative.Copy() narrative.replace_node_with_new( narrative.get_node_from_name(resulting_story_nodes[0].get_name()), new_graph) narrative.fix_graph() self._social_graph.make_node_postconditions(narrative) narrative.initialize_conditions() narrative.refine_lost_conditions() print "Validating Final Story\n" if self._verbose: print self._divider for node in narrative.get_nodes(): print "Preconditions for " + node.get_name() for con in node.get_preconditions(): print con print "\nPostconditions for " + node.get_name() for con in node.get_postconditions(): print con print "\nLost Conditions for " + node.get_name() for con in node.get_lostconditions(): print con print "\n" + self._divider valid = narrative.validate_story() if not valid: print "INVALID STORY" self._invalids += 1 print "VALIDS = " + str(self._valids) print "INVALIDS = " + str(self._invalids) return backup_narrative else: print "VALID STORY" self._valids += 1 print "VALIDS = " + str(self._valids) print "INVALIDS = " + str(self._invalids) return narrative