From 8d9090c4e10586a7b2edb95ab6689388af7cec42 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Wed, 25 Sep 2019 02:58:57 +0000
Subject: [PATCH] Fix fixes from Complete New World Random offset can be a
 variable. Now that `* is the node number use `r4`^ If game.dat doesn't exist
 or is zero bytes, create it. In local mode, load FONTS/LORD2.FNT which just
 happens to be the same format conio supports.  SyncTERM users should get this
 font for free.

lord2.js can now bootstrap Complete New World.
---
 xtrn/lord2/lord2.js | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/xtrn/lord2/lord2.js b/xtrn/lord2/lord2.js
index 7fe1bcf6ad..6e8a1e6245 100644
--- a/xtrn/lord2/lord2.js
+++ b/xtrn/lord2/lord2.js
@@ -1700,7 +1700,7 @@ function run_ref(sec, fname)
 				return;
 			}
 			if (args.length > 3 && args[1].toLowerCase() === 'random') {
-				setvar(args[0], random(clamp_integer(getvar(args[2]), 's32')) + clamp_integer(args[3], 's32'));
+				setvar(args[0], random(clamp_integer(getvar(args[2]), 's32')) + clamp_integer(getvar(args[3]), 's32'));
 				return;
 			}
 			if (args.length === 3 && args[1].toLowerCase() === 'random') {
@@ -2213,11 +2213,12 @@ function run_ref(sec, fname)
 							player.i[itm.Record]++;
 							player.money -= itm.value;
 							dk.console.gotoxy(1, 23);
-							lw('`* ITEM BOUGHT! `%You now have ' + player.i[itm.Record] + ' of \'em.  `2(`0press a key to continue`2)`r0');
+							// TODO: `* is node number... sometimes!
+							lw('`r4`^* ITEM BOUGHT! `%You now have ' + player.i[itm.Record] + ' of \'em.  `2(`0press a key to continue`2)`r0');
 						}
 						else {
 							dk.console.gotoxy(1, 23);
-							lw('`* ITEM NOT BOUGHT! `%You don\'t have enough gold.  `2(`0press a key to continue`2)`r0');
+							lw('`r4`^ ITEM NOT BOUGHT! `%You don\'t have enough gold.  `2(`0press a key to continue`2)`r0');
 						}
 						getkey();
 						dk.console.gotoxy(0, 23);
@@ -3902,7 +3903,12 @@ function load_time()
 
 function load_game()
 {
-	game = gfile.get(0);
+	if (gfile.length > 0)
+		game = gfile.get(0);
+	else {
+		game = gfile.new();
+		game.put();
+	}
 }
 
 function pick_deleted()
@@ -3940,6 +3946,12 @@ var ufile = new RecordFile(getfname('update.tmp'), Update_Def);
 var gfile = new RecordFile(getfname('game.dat'), Game_Def);
 var maildir = getfname('mail');
 
+// TODO: Actually send this font to SyncTERM too.
+if (file_exists(getfname('FONTS/LORD2.FNT'))) {
+	if (dk.system.mode === 'local')
+		conio.loadfont(getfname('FONTS/LORD2.FNT'));
+}
+
 if (!file_isdir(maildir)) {
 	mkdir(maildir);
 	if (!file_isdir(maildir))
-- 
GitLab