From 3fbe970f83eabcc7dd223231068a6e25ded2f654 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 27 Feb 2019 22:55:10 -0500 Subject: Some enhancements Variable lines and characters per line. Action lines are surrounded in brackets if they are not already delimited. Sometimes a prior speaker will be reused instead of using the distribution. --- CMakeLists.txt | 2 +- dialogue.cpp | 33 ++++++++++++++++++++++++--------- vendor/rawr-ebooks | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe3ba2..f563ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 3.1) project (rawr-ebooks) -add_subdirectory(vendor/rawr-ebooks) +add_subdirectory(vendor/rawr-ebooks EXCLUDE_FROM_ALL) include_directories(vendor/rawr-ebooks) diff --git a/dialogue.cpp b/dialogue.cpp index dd34ee5..0e0c7bc 100644 --- a/dialogue.cpp +++ b/dialogue.cpp @@ -81,32 +81,47 @@ int main(int, char**) for (;;) { + std::set pastSpeakers; + + speaker_id curSpeaker = allSpeakers.next(); std::ostringstream theEnd; + int maxLines = rand() % 4 + 3; - for (int i = 0; i < 5; i++) + for (int i = 0; i < maxLines; i++) { - speaker_data& curSd = speakerData.at(curSpeaker); + pastSpeakers.insert(curSpeaker); - //std::ostringstream thisLine; + speaker_data& curSd = speakerData.at(curSpeaker); if (curSd.name != "") { theEnd << curSd.name << ": "; } - theEnd << curSd.chain.randomSentence(1); + std::string curLine = curSd.chain.randomSentence(rand() % 30 + 1); - /*if (i > 0 && theEnd.str().length() + thisLine.str().length() > 280) + if (curSd.name == "" && + curLine[0] != '[' && + curLine[0] != '(' && + curLine[0] != '*') { - break; - }*/ + theEnd << "[" << curLine << "]"; + } else { + theEnd << curLine; + } theEnd << std::endl; - //theEnd << thisLine.str(); - curSpeaker = curSd.nextSpeaker.next(); + speaker_id repeatSpeaker = *std::next(std::begin(pastSpeakers), rand() % pastSpeakers.size()); + if (repeatSpeaker != curSpeaker && + rand() % 3 == 0) + { + curSpeaker = repeatSpeaker; + } else { + curSpeaker = curSd.nextSpeaker.next(); + } } std::string output = theEnd.str(); diff --git a/vendor/rawr-ebooks b/vendor/rawr-ebooks index d75685e..1890eb5 160000 --- a/vendor/rawr-ebooks +++ b/vendor/rawr-ebooks @@ -1 +1 @@ -Subproject commit d75685e69f9a5d3cfc255aa921005fc40ae6e585 +Subproject commit 1890eb5d4a496aea5e9114550081ca63bd280f3b -- cgit 1.4.1