Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commits (1)
  • Deucе's avatar
    Various fixins... · 2bfd6109
    Deucе authored
    - Fix @run command to lower-case section and filename, and add .ref
    - Set battle flag when @busy is called
    - Redraw map after exiting the buy/sell manager
    - Fix Sell confirmation
    - Check the CON file every time mail is checked automatically
    - Turn off the battle flag when returning from a hotspot module
    - Fix box with calculation in draw_box
    - Fix sell manager first draw colour after unsellable item
    - Clear message area when an item is used
    - Run the busy routing in gametxt.ref when battle is set
    - Actually allow doing things with items
    2bfd6109
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// TODO: More optimal horizontal lightbars // TODO: More optimal horizontal lightbars
// TODO: Multiplayer interactions // TODO: Multiplayer interactions
// TODO: Save player after changes in case process crashes // TODO: Save player after changes in case process crashes
// TODO: run NOTIME in HELP.REF on idle timeout
js.yield_interval = 0; js.yield_interval = 0;
js.load_path_list.unshift(js.exec_dir+"dorkit/"); js.load_path_list.unshift(js.exec_dir+"dorkit/");
...@@ -33,7 +34,7 @@ var map; ...@@ -33,7 +34,7 @@ var map;
var world; var world;
var game; var game;
var killfiles = []; var killfiles = [];
var enemy; var enemy = undefined;
var saved_cursor = {x:0, y:0}; var saved_cursor = {x:0, y:0};
var progname = ''; var progname = '';
var time_warnings = []; var time_warnings = [];
...@@ -1013,6 +1014,16 @@ function sclrscr() ...@@ -1013,6 +1014,16 @@ function sclrscr()
curlinenum = 1; curlinenum = 1;
} }
function clearrows(start, end)
{
var row;
for (row = start; row <= end; row++) {
dk.console.gotoxy(0, row);
dk.console.cleareol();
}
}
function foreground(col) function foreground(col)
{ {
if (col > 15) { if (col > 15) {
...@@ -1683,7 +1694,7 @@ function run_ref(sec, fname) ...@@ -1683,7 +1694,7 @@ function run_ref(sec, fname)
setvar(args[0], str); setvar(args[0], str);
}, },
'rename':function(args) { 'rename':function(args) {
file_rename(getfname(getvar(args[0]).toLowerCase()), getfname(getvar(args[1]).toLowerCase())); file_rename(getfname(getvar(args[0])), getfname(getvar(args[1])));
}, },
'addlog':function(args) { 'addlog':function(args) {
var f = new File(getfname('lognow.txt')); var f = new File(getfname('lognow.txt'));
...@@ -1697,13 +1708,13 @@ function run_ref(sec, fname) ...@@ -1697,13 +1708,13 @@ function run_ref(sec, fname)
} }
}, },
'delete':function(args) { 'delete':function(args) {
file_remove(getfname(getvar(args[0]).toLowerCase())); file_remove(getfname(getvar(args[0])));
}, },
'statbar':function(args) { 'statbar':function(args) {
status_bar(); status_bar();
}, },
'trim':function(args) { 'trim':function(args) {
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var len = getvar(args[1]); var len = getvar(args[1]);
var al; var al;
...@@ -1882,7 +1893,7 @@ function run_ref(sec, fname) ...@@ -1882,7 +1893,7 @@ function run_ref(sec, fname)
break; break;
case 'exist': case 'exist':
case 'exists': case 'exists':
if (file_exists(getfname(args[0].toLowerCase())) === (args[2].toLowerCase() === 'true')) if (file_exists(getfname(args[0])) === (args[2].toLowerCase() === 'true'))
handlers.do(args.slice(4)); handlers.do(args.slice(4));
else if (args[4].toLowerCase() === 'begin') else if (args[4].toLowerCase() === 'begin')
handlers.begin(args.slice(5)); handlers.begin(args.slice(5));
...@@ -1929,15 +1940,19 @@ function run_ref(sec, fname) ...@@ -1929,15 +1940,19 @@ function run_ref(sec, fname)
}, },
'run':function(args) { 'run':function(args) {
var f = fname; var f = fname;
var s = replace_vars(args[0]); var s = replace_vars(args[0]).toLowerCase();
if (args.length > 2 && args[1].toLowerCase() === 'in') { if (args.length > 2 && args[1].toLowerCase() === 'in') {
f = getvar(args[2]); f = getvar(args[2]).toLowerCase();
} }
if (f.indexOf('.') === -1)
f += '.ref';
if (files[f] === undefined) if (files[f] === undefined)
load_ref(f); load_ref(f);
if (files[f] === undefined)
throw new Error('Unable to load REF "'+f+'"');
if (files[f].section[s] === undefined) if (files[f].section[s] === undefined)
throw new Error('Unable to find run section '+sec+' in '+f+' at '+fname+':'+line); throw new Error('Unable to find run section '+s+' in '+f+' at '+fname+':'+line);
fname = f; fname = f;
line = files[f].section[s].line; line = files[f].section[s].line;
}, },
...@@ -2011,7 +2026,7 @@ function run_ref(sec, fname) ...@@ -2011,7 +2026,7 @@ function run_ref(sec, fname)
'writefile':function(args) { 'writefile':function(args) {
if (args.length < 1) if (args.length < 1)
throw new Error('No filename for writefile at '+fname+':'+line); throw new Error('No filename for writefile at '+fname+':'+line);
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
if (!f.open('ab')) if (!f.open('ab'))
throw new Error('Unable to open '+f.name+' at '+fname+':'+line); throw new Error('Unable to open '+f.name+' at '+fname+':'+line);
getlines().forEach(function(l) { getlines().forEach(function(l) {
...@@ -2021,7 +2036,7 @@ function run_ref(sec, fname) ...@@ -2021,7 +2036,7 @@ function run_ref(sec, fname)
}, },
'readfile':function(args) { 'readfile':function(args) {
var vs = getlines(); var vs = getlines();
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var l; var l;
if (f.open('r')) { if (f.open('r')) {
...@@ -2047,7 +2062,7 @@ function run_ref(sec, fname) ...@@ -2047,7 +2062,7 @@ function run_ref(sec, fname)
var lines; var lines;
if (args.length < 1) if (args.length < 1)
throw new Error('No filename for displayfile at '+fname+':'+line); throw new Error('No filename for displayfile at '+fname+':'+line);
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
if (!file_exists(f.name)) { if (!file_exists(f.name)) {
lln('`0File '+getvar(args[0])+' missing - please inform sysop'); lln('`0File '+getvar(args[0])+' missing - please inform sysop');
return; return;
...@@ -2177,11 +2192,10 @@ function run_ref(sec, fname) ...@@ -2177,11 +2192,10 @@ function run_ref(sec, fname)
player.put(); player.put();
}, },
'busy':function(args) { 'busy':function(args) {
// Actually, it doesn't seem this touches UPDATE.TMP *or* TRADER.DAT
// TODO: Turn red for other players, and run @#busy if other player interacts // TODO: Turn red for other players, and run @#busy if other player interacts
// this toggles battle... // this toggles battle...
//update_rec.battle = 1; player.battle = 1;
//update_rec.put(); update_update();
}, },
'drawmap':function(args) { 'drawmap':function(args) {
draw_map(); draw_map();
...@@ -2203,10 +2217,7 @@ function run_ref(sec, fname) ...@@ -2203,10 +2217,7 @@ function run_ref(sec, fname)
var sattr = dk.console.attr.value; var sattr = dk.console.attr.value;
dk.console.attr.value = 2; dk.console.attr.value = 2;
for (i = start; i < end; i++) { clearrows(start, end - 1);
dk.console.gotoxy(0, start);
dk.console.cleareol();
}
dk.console.attr.value = sattr; dk.console.attr.value = sattr;
}, },
'loadmap':function(args) { 'loadmap':function(args) {
...@@ -2272,8 +2283,8 @@ function run_ref(sec, fname) ...@@ -2272,8 +2283,8 @@ function run_ref(sec, fname)
lw('`$Q `2to quit, `$ENTER `2to buy item. You have `$&gold `2gold.`r0'); lw('`$Q `2to quit, `$ENTER `2to buy item. You have `$&gold `2gold.`r0');
break; break;
} }
draw_map();
} }
draw_map();
}, },
'saveglobals':function(args) { 'saveglobals':function(args) {
world.put(); world.put();
...@@ -2347,6 +2358,7 @@ function run_ref(sec, fname) ...@@ -2347,6 +2358,7 @@ function run_ref(sec, fname)
var itm; var itm;
var ch; var ch;
var choice; var choice;
var box;
dk.console.gotoxy(0, 6); dk.console.gotoxy(0, 6);
lw('`r5`% Item To Sell Amount Owned `r0'); lw('`r5`% Item To Sell Amount Owned `r0');
...@@ -2386,8 +2398,8 @@ rescan: ...@@ -2386,8 +2398,8 @@ rescan:
continue rescan; continue rescan;
} }
if (player.i[itm.Record] > 1) { if (player.i[itm.Record] > 1) {
draw_box(14, items[itm.Record].name, ['', ' `$Sell how many? ','']) box = draw_box(14, items[itm.Record].name, ['', ' `$Sell how many? ',''])
dk.console.gotoxy(38, 16); dk.console.gotoxy(box.x + 21, box.y + 2);
// TODO: This isn't exactly right... cursor is in wrong position, and selected colour is used. // TODO: This isn't exactly right... cursor is in wrong position, and selected colour is used.
ch = dk.console.getstr({edit:player.i[itm.Record].toString(), integer:true, input_box:true, attr:new Attribute(47), len:11}); ch = dk.console.getstr({edit:player.i[itm.Record].toString(), integer:true, input_box:true, attr:new Attribute(47), len:11});
lw('`r1`0'); lw('`r1`0');
...@@ -2396,8 +2408,8 @@ rescan: ...@@ -2396,8 +2408,8 @@ rescan:
continue rescan; continue rescan;
} }
} }
draw_box(16, itm.name ['', '`$Sell '+amt+' of \'em for '+(amt * price)+' gold?','','`r5`$Yes','`$No']); box = draw_box(16, itm.name, ['', '`$Sell '+amt+' of \'em for '+(amt * price)+' gold?','','`r5`$Yes','`$No']);
dk.console.gotoxy(25,21); dk.console.gotoxy(box.x + 3, box.y + 4);
yn = true; yn = true;
do { do {
ch = getkey().toUpperCase(); ch = getkey().toUpperCase();
...@@ -2411,14 +2423,15 @@ rescan: ...@@ -2411,14 +2423,15 @@ rescan:
case '6': case '6':
case 'KEY_RIGHT': case 'KEY_RIGHT':
yn = !yn; yn = !yn;
dk.console.gotoxy(23,20); dk.console.gotoxy(box.x + 3, box.y + 4);
if (yn) if (yn)
lw('`r5'); lw('`r5');
lw('`$Yes`r1'); lw('`$Yes`r1');
dk.console.gotoxy(23,21); dk.console.gotoxy(box.x + 3, box.y + 5);
if (!yn) if (!yn)
lw('`r5'); lw('`r5');
lw('`$No`r1'); lw('`$No`r1');
dk.console.gotoxy(box.x + 3, box.y + 5 - yn);
break; break;
} }
} while (ch !== '\r'); } while (ch !== '\r');
...@@ -2435,12 +2448,12 @@ rescan: ...@@ -2435,12 +2448,12 @@ rescan:
lw('`r0'); lw('`r0');
continue rescan; continue rescan;
} }
draw_map();
} }
draw_map();
} }
}, },
'dataload':function(args) { 'dataload':function(args) {
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var rec = getvar(args[1]); var rec = getvar(args[1]);
var val; var val;
...@@ -2465,7 +2478,7 @@ rescan: ...@@ -2465,7 +2478,7 @@ rescan:
setvar(args[2], val); setvar(args[2], val);
}, },
'datasave':function(args) { 'datasave':function(args) {
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var rec = getvar(args[1]); var rec = getvar(args[1]);
var val = replace_vars(getvar(args[2])); var val = replace_vars(getvar(args[2]));
...@@ -2488,7 +2501,7 @@ rescan: ...@@ -2488,7 +2501,7 @@ rescan:
f.close(); f.close();
}, },
'datanewday':function(args) { 'datanewday':function(args) {
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var i; var i;
var d; var d;
...@@ -2572,11 +2585,11 @@ rescan: ...@@ -2572,11 +2585,11 @@ rescan:
} }
}, },
'copyfile':function(args) { 'copyfile':function(args) {
file_copy(getfname(getvar(args[0]).toLowerCase()), getfname(getvar(args[1]).toLowerCase())); file_copy(getfname(getvar(args[0])), getfname(getvar(args[1])));
}, },
'convert_file_to_ansi':function(args) { 'convert_file_to_ansi':function(args) {
var inf = new File(getfname(getvar(args[0]).toLowerCase())); var inf = new File(getfname(getvar(args[0])));
var out = new File(getfname(getvar(args[1]).toLowerCase())); var out = new File(getfname(getvar(args[1])));
var l; var l;
if (!inf.open('r')) if (!inf.open('r'))
...@@ -2592,8 +2605,8 @@ rescan: ...@@ -2592,8 +2605,8 @@ rescan:
out.close(); out.close();
}, },
'convert_file_to_ascii':function(args) { 'convert_file_to_ascii':function(args) {
var inf = new File(getfname(getvar(args[0]).toLowerCase())); var inf = new File(getfname(getvar(args[0])));
var out = new File(getfname(getvar(args[1]).toLowerCase())); var out = new File(getfname(getvar(args[1])));
var l; var l;
if (!inf.open('r')) if (!inf.open('r'))
...@@ -2625,7 +2638,7 @@ rescan: ...@@ -2625,7 +2638,7 @@ rescan:
player = op; player = op;
}, },
'lordrank':function(args) { 'lordrank':function(args) {
var f = new File(getfname(getvar(args[0]).toLowerCase())); var f = new File(getfname(getvar(args[0])));
var rp = ranked_players(args[1]); var rp = ranked_players(args[1]);
if (!f.open('ab')) if (!f.open('ab'))
...@@ -2767,7 +2780,6 @@ rescan: ...@@ -2767,7 +2780,6 @@ rescan:
while (1) { while (1) {
line++; line++;
//log(fname+':'+line);
if (line >= files[fname].lines.length) if (line >= files[fname].lines.length)
return; return;
cl = files[fname].lines[line].replace(/^\s*/,''); cl = files[fname].lines[line].replace(/^\s*/,'');
...@@ -2970,6 +2982,7 @@ function mail_check(messenger) ...@@ -2970,6 +2982,7 @@ function mail_check(messenger)
lln(l); lln(l);
} }
} }
con_check();
if (messenger) { if (messenger) {
sln(''); sln('');
more(); more();
...@@ -3192,7 +3205,6 @@ function update(skip) { ...@@ -3192,7 +3205,6 @@ function update(skip) {
timeout_bar(); timeout_bar();
mail_check(true); mail_check(true);
con_check();
} }
dk.console.gotoxy(player.x - 1, player.y - 1); dk.console.gotoxy(player.x - 1, player.y - 1);
foreground(15); foreground(15);
...@@ -3334,6 +3346,8 @@ function move_player(xoff, yoff) { ...@@ -3334,6 +3346,8 @@ function move_player(xoff, yoff) {
} }
else if (s.reffile !== '' && s.refsection !== '') { else if (s.reffile !== '' && s.refsection !== '') {
run_ref(s.refsection, s.reffile); run_ref(s.refsection, s.reffile);
player.battle = 0;
update_update();
} }
} }
}); });
...@@ -3346,8 +3360,10 @@ function move_player(xoff, yoff) { ...@@ -3346,8 +3360,10 @@ function move_player(xoff, yoff) {
} }
} }
if (moved && !special && map.battleodds > 0 && map.reffile !== '' && map.refsection !== '') { if (moved && !special && map.battleodds > 0 && map.reffile !== '' && map.refsection !== '') {
if (random(map.battleodds) === 0) if (random(map.battleodds) === 0) {
run_ref(map.refsection, map.reffile); run_ref(map.refsection, map.reffile);
// TODO: Is this where we clear battle?!?!
}
} }
} }
...@@ -3385,9 +3401,9 @@ function draw_box(y, title, lines, width) ...@@ -3385,9 +3401,9 @@ function draw_box(y, title, lines, width)
if (width === undefined) { if (width === undefined) {
width = displen(title) + 6; width = displen(title) + 6;
lines.forEach(function(l) { lines.forEach(function(l) {
var l = displen(lines) + 6; var len = displen(l) + 6;
if (l > width) if (len > width)
l = width; width = len;
}); });
} }
...@@ -3401,6 +3417,7 @@ function draw_box(y, title, lines, width) ...@@ -3401,6 +3417,7 @@ function draw_box(y, title, lines, width)
}); });
dk.console.gotoxy(x, y + lines.length + 1); dk.console.gotoxy(x, y + lines.length + 1);
lw(box_bottom(width)); lw(box_bottom(width));
return {width:width, y:y, x:x};
} }
// Assume width of 36 // Assume width of 36
...@@ -3435,7 +3452,7 @@ function popup_menu(title, opts) ...@@ -3435,7 +3452,7 @@ function popup_menu(title, opts)
}); });
ch = vbar(otxt, {drawall:false, x:x + 3, y:y + 1, highlight:'`r5`0', norm:'`r1`0'}); ch = vbar(otxt, {drawall:false, x:x + 3, y:y + 1, highlight:'`r5`0', norm:'`r1`0'});
return ch.cur; return opts[ch.cur].ret;
} }
function decorate_item(it) function decorate_item(it)
...@@ -3551,6 +3568,8 @@ newpage: ...@@ -3551,6 +3568,8 @@ newpage:
player.armournumber = 0; player.armournumber = 0;
break; break;
case 'S': case 'S':
dk.console.attr.value = 2;
clearrows(12, 22);
ret = run_ref(items[inv[cur] - 1].refsection, 'items.ref'); ret = run_ref(items[inv[cur] - 1].refsection, 'items.ref');
if (items[inv[cur] - 1].useonce) { if (items[inv[cur] - 1].useonce) {
player.i[inv[cur] - 1]--; player.i[inv[cur] - 1]--;
...@@ -3795,6 +3814,7 @@ function offline_battle() ...@@ -3795,6 +3814,7 @@ function offline_battle()
if (player.p[1] < 1) { if (player.p[1] < 1) {
if (enm.lose_reffile !== '' && enm.lose_refname !== '') if (enm.lose_reffile !== '' && enm.lose_refname !== '')
run_ref(enm.lose_refname, enm.lose_reffile); run_ref(enm.lose_refname, enm.lose_reffile);
break;
} }
} }
} }
...@@ -4016,20 +4036,20 @@ function items_menu(itms, cur, buying, selling, extras, starty, endy) ...@@ -4016,20 +4036,20 @@ function items_menu(itms, cur, buying, selling, extras, starty, endy)
lw('`r0`2'); lw('`r0`2');
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
idx = i + off; idx = i + off;
if (idx >= itms.length) { str = '';
str = ''; if (idx < itms.length) {
}
else {
it = itms[idx] - 1; it = itms[idx] - 1;
desc = items[it].description; desc = items[it].description;
choices.push(((selling && (items[it].sell === false)) ? '`8 ' : '`2 ')+items[it].name); choices.push(((selling && (items[it].sell === false)) ? '`8 ' : '`2 ')+items[it].name);
if (cur === idx) if (cur === idx)
str = '`r1`2'; str += '`r1';
else else
str = '`r0`2'; str += '`r0';
if (selling && items[it].sell === false) if (selling && items[it].sell === false)
str += '`8'; str += '`8';
str = ' '+items[it].name; else
str += '`2';
str += ' '+items[it].name;
if (cur === idx) if (cur === idx)
str += '`r0'; str += '`r0';
str += decorate_item(items[it]); str += decorate_item(items[it]);
...@@ -4253,6 +4273,16 @@ function hail() ...@@ -4253,6 +4273,16 @@ function hail()
op.put(false); op.put(false);
update_bar('You find `0'+op.name+'`2 sleeping like a baby. (hit a key)', true); update_bar('You find `0'+op.name+'`2 sleeping like a baby. (hit a key)', true);
switch(hbar(2, 23, ['Leave', 'Attack', 'Give Item', 'Transfer Gold', 'Write Mail'])) { switch(hbar(2, 23, ['Leave', 'Attack', 'Give Item', 'Transfer Gold', 'Write Mail'])) {
case 0:
break;
case 1: // Attack
break;
case 2: // Give Item
break;
case 3: // Transfer Gold
break;
case 4: // Write Mail
break;
} }
// TODO: Offline battles, giving things, etc... // TODO: Offline battles, giving things, etc...
} }
...@@ -4379,9 +4409,8 @@ function do_map() ...@@ -4379,9 +4409,8 @@ function do_map()
ch = '' ch = ''
while (ch != 'Q') { while (ch != 'Q') {
if (enemy !== undefined) { if (enemy !== undefined)
offline_battle(); offline_battle();
}
while (!dk.console.waitkey(game.delay)) { while (!dk.console.waitkey(game.delay)) {
update(); update();
}; };
...@@ -4638,6 +4667,7 @@ function load_time() ...@@ -4638,6 +4667,7 @@ function load_time()
f.truncate(0); f.truncate(0);
f.write(state.time+'\r\n'); f.write(state.time+'\r\n');
f.close; f.close;
// TODO: Delete inactive players after 15 days.
run_ref('maint', 'maint.ref'); run_ref('maint', 'maint.ref');
} }
} }
...@@ -4770,6 +4800,10 @@ if (!cfile.open('w+b')) ...@@ -4770,6 +4800,10 @@ if (!cfile.open('w+b'))
killfiles.push(cfile); killfiles.push(cfile);
cfile.close(); cfile.close();
if (player.battle) {
run_ref('busy', 'gametxt.ref');
}
run_ref('startgame', 'gametxt.ref'); run_ref('startgame', 'gametxt.ref');
js.on_exit('if (player !== undefined) { update_rec.onnow = 0; update_rec.busy = 0; update_rec.battle = 0; update_rec.map = player.map; update_rec.x = player.x; update_rec.y = player.y; update_rec.put(); ufile.file.close(); player.onnow = 0; player.busy = 0; player.battle = 0; player.lastsaved = savetime(); player.put(); pfile.file.close() }'); js.on_exit('if (player !== undefined) { update_rec.onnow = 0; update_rec.busy = 0; update_rec.battle = 0; update_rec.map = player.map; update_rec.x = player.x; update_rec.y = player.y; update_rec.put(); ufile.file.close(); player.onnow = 0; player.busy = 0; player.battle = 0; player.lastsaved = savetime(); player.put(); pfile.file.close() }');
......