Skip to content
Snippets Groups Projects
Commit 1a83d97e authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Various engine fixes/updates

- Set default values for world.dat so it can be created with new()
- Add `r0 to start of the default more string
- Create the world file if it doesn't exist (for globals)
- Fix stupid error in @do trim
- Support all the different @clear commands
- Support the different @key commands properly
- Support @name command
- Only @say is still required for the NPC "stuff" that nothing uses
- Fix blank line skip looking for @begin after @if...then do
  Was looking for comments starting with ; only
- Add try/catch around maint call in case it doesn't exist
- Don't load rules.ref if there's a REF passed on command-line
parent f2ec12aa
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -297,7 +297,7 @@ var World_Def = [ ...@@ -297,7 +297,7 @@ var World_Def = [
{ {
prop:'mapdatindex', prop:'mapdatindex',
type:'Array:1600:SignedInteger16', type:'Array:1600:SignedInteger16',
def:new Array(1600) def:eval('var aret = []; while(aret.length < 1600) aret.push(0); aret;')
}, },
{ {
prop:'v', prop:'v',
...@@ -307,7 +307,7 @@ var World_Def = [ ...@@ -307,7 +307,7 @@ var World_Def = [
{ {
prop:'s', prop:'s',
type:'Array:10:PString:80', type:'Array:10:PString:80',
def:new Array(10) def:eval('var aret = []; while(aret.length < 10) aret.push(""); aret;')
}, },
{ {
prop:'time', prop:'time',
...@@ -317,7 +317,7 @@ var World_Def = [ ...@@ -317,7 +317,7 @@ var World_Def = [
{ {
prop:'hideonmap', prop:'hideonmap',
type:'Array:1600:Integer8', type:'Array:1600:Integer8',
def:new Array(1600) def:eval('var aret = []; while(aret.length < 1600) aret.push(0); aret;')
}, },
{ {
prop:'extra', prop:'extra',
...@@ -537,7 +537,7 @@ function getkeyw() ...@@ -537,7 +537,7 @@ function getkeyw()
var curlinenum = 1; var curlinenum = 1;
var curcolnum = 1; var curcolnum = 1;
var morechk = true; var morechk = true;
var morestr = '`2<`0MORE`2>'; var morestr = '`r0`2<`0MORE`2>';
// Reads a key // Reads a key
function getkey() function getkey()
{ {
...@@ -1648,6 +1648,10 @@ if (!file_isdir(maildir)) { ...@@ -1648,6 +1648,10 @@ if (!file_isdir(maildir)) {
} }
maildir = backslash(maildir).replace(js.exec_dir, ''); maildir = backslash(maildir).replace(js.exec_dir, '');
world = wfile.get(0); world = wfile.get(0);
if (world === null) {
wfile.new();
world = wfile.get(0);
}
load_players(); load_players();
load_items(); load_items();
load_game(); load_game();
...@@ -630,7 +630,7 @@ function insane_run_ref(sec, fname, refret) ...@@ -630,7 +630,7 @@ function insane_run_ref(sec, fname, refret)
if (!f.open('r+b')) if (!f.open('r+b'))
throw new Error('Unable to open '+f.name+' at '+fname+':'+line); throw new Error('Unable to open '+f.name+' at '+fname+':'+line);
al = f.readAll(); al = f.readAll();
while (al.length > len); while (al.length > len)
al.shift(); al.shift();
f.position = 0; f.position = 0;
al.forEach(function(l) { al.forEach(function(l) {
...@@ -876,9 +876,45 @@ function insane_run_ref(sec, fname, refret) ...@@ -876,9 +876,45 @@ function insane_run_ref(sec, fname, refret)
setvar(args[0], pl + 1); setvar(args[0], pl + 1);
}, },
'clear':function(args) { 'clear':function(args) {
if (args[0].toLowerCase() === 'screen') { var i;
sclrscr(); var str;
return;
if (args.length < 1)
throw new Error('@clear requires a parameter');
switch (args[0].toLowerCase()) {
case 'screen':
sclrscr();
return;
case 'name':
dk.console.gotoxy(54, 14);
sw(spaces(21));
return;
case 'picture':
str = spaces(22);
for (i = 2; i < 13; i++) {
dk.console.gotoxy(54, i);
sw(str);
}
return;
case 'text':
str = spaces(21);
for (i = 2; i < 13; i++) {
dk.console.gotoxy(32, i);
sw(str);
}
return;
case 'all':
dk.console.clear(dk.console.attr.value);
curlinenum = 1;
return;
case 'userscreen':
for (i = 15; i < 24; i++) {
dk.console.gotoxy(0, i);
dk.console.cleareol();
}
dk.console.gotoxy(77, 23);
return;
} }
throw new Error('Unknown clear type at '+fname+':'+line); throw new Error('Unknown clear type at '+fname+':'+line);
}, },
...@@ -1062,7 +1098,7 @@ function insane_run_ref(sec, fname, refret) ...@@ -1062,7 +1098,7 @@ function insane_run_ref(sec, fname, refret)
//if (files[fname].lines[line + 1].search(/^\s*@begin/i) === -1) //if (files[fname].lines[line + 1].search(/^\s*@begin/i) === -1)
// throw new Error('trailing do at '+fname+':'+line); // throw new Error('trailing do at '+fname+':'+line);
tmp = line; tmp = line;
while (files[fname].lines[++tmp].search(/^\s*;/) != -1) { while (files[fname].lines[++tmp].search(/^\s*@/) === -1) {
if (tmp >= files[fname].lines.length) if (tmp >= files[fname].lines.length)
break; break;
} }
...@@ -1374,16 +1410,23 @@ function insane_run_ref(sec, fname, refret) ...@@ -1374,16 +1410,23 @@ function insane_run_ref(sec, fname, refret)
} }
}, },
'key':function(args) { 'key':function(args) {
var orig_attr = dk.console.attr.value;
var mlen = 8;
if (args.length > 0) { if (args.length > 0) {
switch(args[0].toLowerCase()) { switch(args[0].toLowerCase()) {
case 'nodisplay': case 'nodisplay':
getkey(); getkey();
return; return;
case 'top': case 'top':
dk.console.gotoxy(0,0); dk.console.gotoxy(39, 14);
lw(' `0MORE ');
mlen = 6;
break; break;
case 'bottom': case 'bottom':
dk.console.gotoxy(0,23); dk.console.gotoxy(35,23);
lw(' `0MORE ');
mlen = 6;
break; break;
// Any other argument is the same as no argument... CNW reset.ref uses '@key noshow' // Any other argument is the same as no argument... CNW reset.ref uses '@key noshow'
default: default:
...@@ -1396,14 +1439,14 @@ function insane_run_ref(sec, fname, refret) ...@@ -1396,14 +1439,14 @@ function insane_run_ref(sec, fname, refret)
else { else {
// No, this would be the sane thing to do... don't do it. // No, this would be the sane thing to do... don't do it.
//lw('\r'); //lw('\r');
lw('`r0 `2<`0MORE`2>');
} }
dk.console.cleareol();
// NOTE: This doesn't actually use the "More" prompt that you can override... and it's not centred like the docs claim. // NOTE: This doesn't actually use the "More" prompt that you can override... and it's not centred like the docs claim.
//lw(spaces(40-(displen(morestr)/2))+morestr); //lw(spaces(40-(displen(morestr)/2))+morestr);
lw(' `2<`0MORE`2>');
getkey(); getkey();
lw('\r'); lw(repeat_chars('\b', mlen));
dk.console.cleareol(); lw(repeat_chars(' ', mlen));
dk.console.attr.value = orig_attr;
}, },
'label':function(args) {}, 'label':function(args) {},
'loadcursor':function(args) { 'loadcursor':function(args) {
...@@ -1443,6 +1486,25 @@ function insane_run_ref(sec, fname, refret) ...@@ -1443,6 +1486,25 @@ function insane_run_ref(sec, fname, refret)
cl = files[fname].lines[line]; cl = files[fname].lines[line];
morestr = replace_vars(cl); morestr = replace_vars(cl);
}, },
'name':function(args) {
var str;
var len;
if (args.length < 1)
throw new Error('@name requires an argument');
str = getvar(args[0]);
dk.console.gotoxy(53, 14);
// Truncate to 20 characters, center in 20 charaters, put space a start/end
var len = displen(getvar(args[0]));
if (len > 20) { // Truncate
while (displen(str) > 20)
str = str.slice(0, -1);
len = displen(str);
}
// Center in 22 spaces...
str = spaces(Math.floor((23 - len) / 2)) + str + spaces(Math.ceil((23 - len) / 2));
lw(str);
},
'nocheck':function(args) { 'nocheck':function(args) {
// We don't really support this because there's no need for it. // We don't really support this because there's no need for it.
}, },
...@@ -1560,6 +1622,9 @@ function insane_run_ref(sec, fname, refret) ...@@ -1560,6 +1622,9 @@ function insane_run_ref(sec, fname, refret)
'saveglobals':function(args) { 'saveglobals':function(args) {
world.put(); world.put();
}, },
'say':function(args) {
throw new Error('@say not implemented');
},
'saveworld':function(args) { 'saveworld':function(args) {
world.put(); world.put();
}, },
...@@ -1946,12 +2011,14 @@ function load_player() ...@@ -1946,12 +2011,14 @@ function load_player()
var p; var p;
function post_load() { function post_load() {
map = load_map(player.map); if (world !== null) {
// Force move to home on invalid map (can be triggered by a crash in the glen which no longer happens. :) map = load_map(player.map);
if (map === null) { // Force move to home on invalid map (can be triggered by a crash in the glen which no longer happens. :)
player.map = 1; if (map === null) {
player.x = 1; player.map = 1;
player.y = 1; player.x = 1;
player.y = 1;
}
} }
player.lastx = player.x; player.lastx = player.x;
player.lasty = player.y; player.lasty = player.y;
...@@ -4289,7 +4356,12 @@ function load_time() ...@@ -4289,7 +4356,12 @@ function load_time()
f.write(state.time+'\r\n'); f.write(state.time+'\r\n');
f.close; f.close;
// TODO: Delete inactive players after 15 days. // TODO: Delete inactive players after 15 days.
run_ref('maint', 'maint.ref'); try {
run_ref('maint', 'maint.ref');
}
catch(e) {
log(LOG_ERROR, (new Date()).toString() + ", Node "+dk.connection.node+": REF Error "+e.message+" at maint");
}
} }
} }
...@@ -4343,11 +4415,6 @@ if (file_exists(getfname('fonts/lord2.fnt'))) { ...@@ -4343,11 +4415,6 @@ if (file_exists(getfname('fonts/lord2.fnt'))) {
load_player(); load_player();
load_time(); load_time();
run_ref('rules', 'rules.ref');
hail_cleanup();
setup_time_warnings();
var done = false; var done = false;
for (arg in argv) { for (arg in argv) {
var m = argv[arg].match(/^(.*)\+(.*)$/); var m = argv[arg].match(/^(.*)\+(.*)$/);
...@@ -4359,6 +4426,11 @@ for (arg in argv) { ...@@ -4359,6 +4426,11 @@ for (arg in argv) {
if (done) if (done)
exit(0); exit(0);
run_ref('rules', 'rules.ref');
hail_cleanup();
setup_time_warnings();
js.on_exit('killfiles.forEach(function(f) { if (f.is_open) { f.close(); } file_remove(f.name); });'); js.on_exit('killfiles.forEach(function(f) { if (f.is_open) { f.close(); } file_remove(f.name); });');
var tfile = new File(getfname(maildir + 'talk'+(player.Record + 1)+'.tmp')); var tfile = new File(getfname(maildir + 'talk'+(player.Record + 1)+'.tmp'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment