Skip to content

Commit

Permalink
Prepared test convo
Browse files Browse the repository at this point in the history
  • Loading branch information
Blecki committed Jun 19, 2018
1 parent ce56cf8 commit 38cea89
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 10 deletions.
197 changes: 191 additions & 6 deletions DwarfCorp/DwarfCorpContent/World/dwarf.conv
Original file line number Diff line number Diff line change
@@ -1,6 +1,191 @@
Mae: What did you say to her?
-> Nothing.
Mae: Oh, man. Maybe you should have.
-> That she was an idiot.
Mae: Hah! I bet that pissed her off.
Mae: Anyway, I'd better get going.
title: Start
---
Dwarf: I am $envoy-name of $envoy-faction.
[[Main]]
===


title: Main
---
<<if $envoy-demands-tribute>>
<<pick>>
$envoy-name: We have come to collect taxes for the King.
$envoy-name: The Dwarven Kingdom demands tax!
$envoy-name: The King needs revenue for his army.
$envoy-name: You have not paid your corporate income tax - pay me or be auditted!
<<end>>
[[Pay a tribute of $envoy-tribute-demanded|PayTribute]]
[[Refuse to pay. (WAR)|DeclareWar]]
<<elseif $faction-was-at-war>>
We are at war.
[[Make peace.|MakePeace]]
[[Continue the war.|DeclareWar]]
<<else>>
<<pick>>
$envoy-name: Hello!
$envoy-name: Well met.
$envoy-name: Greetings!
$envoy-name: Salutations!
$envoy-name: Good to see you, fellow dwarf!
<<end>>
[[Trade.|Trade]]
[[What is your opinion of us?|Opinion]]
[[What is something you have many of?|Many]]
[[What is something you have few of?|Few]]
[[What is something you hate?|Hate]]
[[What is something you like?|Like]]
[[Declare war!|ConfirmWar]]
[[Goodbye.|Goodbye]]
<<endif>>
===


title: Trade
---
<<trade>> // Pauses conversation until trade is complete.
<<if $trade-result == "cancelled">>
$envoy-name: Not sure what you think I'm here for.
[[Main]]
<<elseif $trade-result == "hated">>
$envoy-name: What is this? The deal is off! This is outrageous!
<<increment $offensive-trades>>
<<political-event "you tried to give us something offensive" -0.25 4>> // Description, change, duration (days)
<<if $offensive-trades == 3>>
[[Goodbye]]
<<endif>>
[[Main]]
<<elseif $trade-result == "unprofitable">>
<<pick>>
$envoy-name: Do you take me for a fool? Where is the profit?
$envoy-name: I should not have come all this way. Not. Profitable.
$envoy-name: I thought we could trust one another. Instead you're wasting my time.
$envoy-name: Do you think I have space to carry such worthless goods?
<<end>>
<<else>>
<<if $trade-result == "liked">>
<<political-event "you gave us something we liked" 0.25 4>>
<<endif>>
<<finalize-trade>> // Applys the trade and creates the events the achievement engine needs.
<<political-event "we had profitable trade" 0.25 2>>
<<pick>>
$envoy-name: Yes, this is profitable.
$envoy-name: We will both be rich at this rate.
$envoy-name: Ha! The baloon can barely stay in the air now!
$envoy-name: Thank Seleprak for inventing mercantilism!
<<end>>
<<endif>>
[[Main]]
===


title: Opinion
---
$envoy-name: So far, our relationship has been $envoy-relationship.
[[Main]]
===


title: Many
---
<<pick>>
$envoy-name: We have a great deal of stone. Transporting more would not be profitable.
$envoy-name: The markets are flooded with metal of all kinds. Do not give us more!
$envoy-name: The mushroom crop has done exceptionally. We have more than we need, honestly.
$envoy-name: Ha, Ale, of course! Don't even try and compete with the local craft breweries!
<<end>>
[[Main]]
===


title: Few
---
<<pick>>
$envoy-name: There never seems to be enough magical items. Is there just not enough mana?
$envoy-name: Trees don't grow well underground. That's a hint.
$envoy-name: Well, you know, you can't go wrong with gems.
$envoy-name: Precious things. Gold. That's usually good, we can always use more gold.
$envoy-name: Trinkets are good for reselling. All kinds.
<<end>>
[[Main]]
===


title: Hate
---
$envoy-name: Anything can be profitable if you know who to sell it to. Don't worry about selling us distasteful items, I guarantee there's a buyer for everything.
[[Main]]
===


title: Like
---
<<pick>>
$envoy-name: Metal. It's just amazing, isn't it?
$envoy-name: Gold - yeah. Gold. Lots of gold.
$envoy-name: Shiny transparent rocks. Rubies. Diamonds. Emeralds. All of them.
$envoy-name: I like things that show true artisinal talent. The kinds of things a craftsdwarf pours his soul into you.
<<end>>
[[Main]]
===


title: ConfirmWar
---
$envoy-name: Seleprak! Must we make war?
[[Yes!|DeclareWar]]
[[No.|Main]]
===


title: DeclareWar
---
<<pick>>
$envoy-name: This is a dark day for the dwarven empire.
$envoy-name: In the name of the king, we shall strike you down!
$envoy-name: Your rebellious corporation ends now.
<<end>>
<<political-event "you declared war on us" -2.0 4>>
<<declare-war>> // This is what actually turns them hostile. Also generates the events for the achievement system.
[[Be gone.|End]]
===


title: MakePeace
---
$envoy-name: War of this kind is not profitable.
<<political-event "you made peace with us" 0.4 4>>
[[Main]]
===


title: PayTribute
---
<<if $player-money < $envoy-tribute-demanded>>
$envoy-name: Ha! You can't even afford this paltry amount? We'll come back when you get your finances in order.
[[Fine.|End]]
<<else>>
<<pay-tribute>>
<<political-event "you paid us tribute" 0.5 4>>
$envoy-name: A wonderfully straightforward transaction.
[[Main]]
<<endif>>
===


title: Goodbye
---
<<pick>>
$envoy-name: Seleprak be with you!
$envoy-name: May your mines be deep and profitable.
$envoy-name: Remember the motherland.
<<end>>
[[So long!|End]]
===


title: End
---
<<recall-envoy>>
<<end-conversation>>
===

73 changes: 71 additions & 2 deletions YarnSpinner/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,79 @@ void GenerateCode(Node node, Parser.Statement parseNode, string line) {
// Does this line have a "#line:LINENUM" tag? Use it
string lineID = GetLineIDFromNodeTags(parseNode);

var num = program.RegisterString (line, node.name, lineID, parseNode.lineNumber, true);
var parts = new List<String>();
var currentPart = "";
foreach (var c in line)
{
if (c == '$')
{
if (currentPart.Length > 0) parts.Add(currentPart);
currentPart = "$";
}
else
{
if (currentPart.Length > 0 && currentPart[0] == '$' && ",.?!: ".Contains(new string(c,1)))
{
parts.Add(currentPart);
currentPart = new string(c, 1);
}
else
{
currentPart += c;
}
}
}
if (currentPart.Length > 0) parts.Add(currentPart);

Emit (node, ByteCode.RunLine, num);
if (parts.Count == 1)
{
var num = program.RegisterString(line, node.name, lineID, parseNode.lineNumber, true);
Emit(node, ByteCode.RunLine, num);
}
else
{
EmitLinePart(node, parseNode, parts[0], lineID);
for (var i = 1; i < parts.Count; ++i)
{
EmitLinePart(node, parseNode, parts[i], lineID);
node.instructions.Add(new Instruction
{
operation = ByteCode.Concat,
operandA = null,
operandB = null
});
}

node.instructions.Add(new Instruction
{
operation = ByteCode.RunLineFromStack,
operandA = null,
operandB = null
});
}
}

private void EmitLinePart(Node node, Parser.Statement parseNode, String part, String lineID)
{
if (part[0] == '$')
{
node.instructions.Add(new Instruction
{
operation = ByteCode.PushVariable,
operandA = part,
operandB = null
});
}
else
{
var num = program.RegisterString(part, node.name, lineID, parseNode.lineNumber, true);
node.instructions.Add(new Instruction
{
operation = ByteCode.PushString,
operandA = num,
operandB = null
});
}
}

void GenerateCode(Node node, Parser.ShortcutOptionGroup statement) {
Expand Down
6 changes: 5 additions & 1 deletion YarnSpinner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ internal enum ByteCode
/// stops execution
Stop,
/// run the node whose name is at the top of the stack
RunNode
RunNode,
/// Pop two strings, concat them, and push back to the stack
Concat,
/// Run a line, but get the text from the stack instead of the table.
RunLineFromStack,

}
}
19 changes: 18 additions & 1 deletion YarnSpinner/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,24 @@ internal void RunInstruction(Instruction i) {
}));

break;
default:
case ByteCode.Concat:
/// = Concat
/** Pop two items off the stack, concat them, and push the result onto the stack.
*/
{
var second = state.PopValue();
var first = state.PopValue();
state.PushValue(first.AsString + second.AsString);
}
break;
case ByteCode.RunLineFromStack:
/// - RunLineFromStack
/** Pop a string from the stack and pass to client as a line.
*/
lineHandler(new Dialogue.LineResult(state.PopValue().AsString));

break;
default:
/// - default
/** Whoa, no idea what bytecode this is. Stop the program
* and throw an exception.
Expand Down

0 comments on commit 38cea89

Please sign in to comment.