From 2147296a8a4b08ab14fe3142c52045982118bfdf Mon Sep 17 00:00:00 2001
From: Reid <reidyaro@gmail.com>
Date: Sun, 13 Mar 2016 07:03:33 +0100
Subject: Extend the openbook feature and add different dialogue if the book
 was used from a shelf or from the inventory.

---
 npc/001-2-6/books.txt      | 81 +++++++++++++++++++++++++++++++++++++++-------
 npc/functions/openbook.txt | 22 ++++++++++++-
 2 files changed, 90 insertions(+), 13 deletions(-)

diff --git a/npc/001-2-6/books.txt b/npc/001-2-6/books.txt
index ad3f7ca3..54be3a5d 100644
--- a/npc/001-2-6/books.txt
+++ b/npc/001-2-6/books.txt
@@ -6,10 +6,7 @@
 
 001-2-6,39,41,0	script	#001-2-6-Book1	NPC_NO_SPRITE,{
 
-    @book_name$ = "\"" + l("The Piou and The Fluffy") + "\"";
-
-    if (openbook ())
-    {
+    function read_book {
         mes "";
         mes col("Master Piou sat on a tree,", 9);
         mes col("Holding a cheese in his beak.", 9);
@@ -38,9 +35,20 @@
         mes col("-- " + l("Aesop"), 9);
     }
 
+OnShelfUse:
+    @book_name$ = .bookname$;
+    if (openbookshelf ())
+        read_book;
+    close;
+
+OnUse:
+    @book_name$ = .bookname$;
+    if (openbook ())
+        read_book;
     close;
 
 OnInit:
+    .bookname$ = "The Piou and The Fluffy";
     .sex = G_OTHER;
     .distance = 1;
     end;
@@ -48,10 +56,7 @@ OnInit:
 
 001-2-6,48,41,0	script	#001-2-6-Book2	NPC_NO_SPRITE,{
 
-    @book_name$ = "\"" + l("Poem about Poems") + "\"";
-
-    if (openbook ())
-    {
+    function read_book {
         mes "";
         mes col("Poem is making the words dance", 9);
         mes col("Words become music and glance", 9);
@@ -85,9 +90,20 @@ OnInit:
         mes col("-- " + l("Nard"), 9);
     }
 
+OnShelfUse:
+    @book_name$ = .bookname$;
+    if (openbookshelf ())
+        read_book;
+    close;
+
+OnUse:
+    @book_name$ = .bookname$;
+    if (openbook ())
+        read_book;
     close;
 
 OnInit:
+    .bookname$ = "Poem about Poems";
     .sex = G_OTHER;
     .distance = 1;
     end;
@@ -95,10 +111,7 @@ OnInit:
 
 001-2-6,43,39,0	script	#001-2-6-Book3	NPC_NO_SPRITE,{
 
-    @book_name$ = "\"" + l("Chorus of the Woods") + "\"";
-
-    if (openbook ())
-    {
+    function read_book {
         mes "";
         mes col("Hush now and hear the chorus of the woods", 9);
         mes col("Bent trees whistling with the beat of the drum", 9);
@@ -110,6 +123,50 @@ OnInit:
         mes col("-- " + l("Princess Slayer"), 9);
     }
 
+OnShelfUse:
+    @book_name$ = .bookname$;
+    if (openbookshelf ())
+        read_book;
+    close;
+
+OnUse:
+    @book_name$ = .bookname$;
+    if (openbook ())
+        read_book;
+    close;
+
+OnInit:
+    .bookname$ = "Chorus of the Woods";
+    .sex = G_OTHER;
+    .distance = 1;
+    end;
+}
+
+001-2-6,54,28,0	script	#001-2-6-Book4	NPC_NO_SPRITE,{
+
+    function read_book {
+        narrator 1,
+            l("Aemil is a magnificent world unknown to us all."),
+            l("Its inhabitants did not know any kind of horror and in peace they lived as the earth gave them everything they needed to live."),
+            l("However, drought came with summers while winters became colder than ever."),
+            l("Therefore, starvation stalked the people of Aemil."),
+            l("Authorities began to control in order to have a peaceful society. This did not work well for long."),
+            l("People started to steal from each other to survive. As cities grew, needs did too. Wars for fertile lands then rose."),
+            l("New technologies assisted the slaughter instead of establishing peace. At some point, two different rivals were formed."),
+            l("Their leaders then came to the conclusion that an alliance was the only way they could survive."),
+            l("The great people of Aemil split up into three groups when they reached the coast."),
+            l("Each of the groups was ordered to sail in a different direction to find a new, suitable land where to live."),
+            l("As they sailed on Oceania, great waters of Aemil, one of the alliances found a land."),
+            ("Even though they did not hear anything about the other groups, they decided to start a new life on this land, full of harmful animals."),
+            l("This new continent, in fact an archipelago, was called Andorra."),
+            l("A great city, now the capital of these islands, called Esperia, rose on the single island, Aurora, where everyone lived."),
+            l("However..."),
+            l("The end of the story got erased, probably because of the sea water. Some pages are still missing. Thus much is left obscure, including even the author's name.");
+    }
+
+OnUse:
+    if (openoldbook ())
+        read_book;
     close;
 
 OnInit:
diff --git a/npc/functions/openbook.txt b/npc/functions/openbook.txt
index 6a9535ec..29074bf1 100644
--- a/npc/functions/openbook.txt
+++ b/npc/functions/openbook.txt
@@ -7,10 +7,30 @@
 //    @book_name$ = The name of the book to read.
 
 function	script	openbook	{
+    .@book_name$ = "\"" + l(@book_name$) + "\"";
+
+    narrator 4,
+        l("You open a book named @@.", .@book_name$),
+        l("Do you want to read it?");
+
+    return (select ("Yes.", "No.") == 1); 
+}
+
+function	script	openbookshelf	{
+    .@book_name$ = "\"" + l(@book_name$) + "\"";
+
     narrator 4,
         l("You see a dust covered book on the shelf..."),
-        l("The name of the book is @@.", @book_name$),
+        l("The name of the book is @@.", .@book_name$),
         l("Do you want to read it?");
 
     return (select ("Yes.", "No.") == 1); 
 }
+
+function	script	openoldbook	{
+    narrator 4,
+        l("You open the book, but it looks like the sea water and time damaged it severely. Some pages are not readable anymore. Some others are simply missing."),
+        l("The old book seems to tell about the legend of Aemil. Would you like to read it?");
+
+    return (select ("Yes.", "No.") == 1); 
+}
-- 
cgit v1.2.3-70-g09d2