Skip to content

Instantly share code, notes, and snippets.

@nelsnelson
Created February 2, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsnelson/6c7507228a9ccd04b60d to your computer and use it in GitHub Desktop.
Save nelsnelson/6c7507228a9ccd04b60d to your computer and use it in GitHub Desktop.
# ----------------------------------------------------------------------------
# The WriteListFrom routine, a flexible object-lister taking care of
# plurals, inventory information, various formats and so on. This is used
# by everything in the library which ever wants to list anything.
#
# If there were no objects to list, it prints nothing and returns false;
# otherwise it returns true.
#
# o is the object, and style is a bitmap, whose bits are given by:
# ----------------------------------------------------------------------------
Constant NEWLINE_BIT 1; # New-line after each entry
Constant INDENT_BIT 2; # Indent each entry by depth
Constant FULLINV_BIT 4; # Full inventory information after entry
Constant ENGLISH_BIT 8; # English sentence style, with commas and and
Constant RECURSE_BIT 16; # Recurse downwards with usual rules
Constant ALWAYS_BIT 32; # Always recurse downwards
Constant TERSE_BIT 64; # More terse English style
Constant PARTINV_BIT 128; # Only brief inventory information after entry
Constant DEFART_BIT 256; # Use the definite article in list
Constant WORKFLAG_BIT 512; # At top level (only), only list objects
# which have the "workflag" attribute
Constant ISARE_BIT 1024; # Print " is" or " are" before list
Constant CONCEAL_BIT 2048; # Omit objects with "concealed" or "scenery":
# if WORKFLAG_BIT also set, then does _not_
# apply at top level, but does lower down
Constant NOARTICLE_BIT 4096; # Print no articles, definite or not
#ifdef NI_BUILD_COUNT;
Constant EXTRAINDENT_BIT 8192; # Used only by I7: extra indentation of 1 level
Constant EXTRA_WORKFLAG_BIT 16384; # Ditto: like WORKFLAG_BIT but at level 1
#endif;
[ NextEntry o odepth;
for (::) {
o = sibling(o);
if (o == 0) return 0;
if (lt_value ~= 0 && o.list_together ~= lt_value) continue;
if (c_style & WORKFLAG_BIT ~= 0 && odepth==0 && o hasnt workflag) continue;
#ifdef NI_BUILD_COUNT;
if (c_style & EXTRA_WORKFLAG_BIT ~= 0 && odepth<=1 && o hasnt workflag) continue;
#endif;
if (c_style & CONCEAL_BIT ~= 0 && (o has concealed || o has scenery)) continue;
return o;
}
];
[ WillRecurs o;
if (c_style & ALWAYS_BIT ~= 0) rtrue;
if (c_style & RECURSE_BIT == 0) rfalse;
if (o has transparent || o has supporter || (o has container && o has open)) rtrue;
rfalse;
];
[ ListEqual o1 o2;
if (child(o1) ~= 0 && WillRecurs(o1) ~= 0) rfalse;
if (child(o2) ~= 0 && WillRecurs(o2) ~= 0) rfalse;
if (c_style & (FULLINV_BIT + PARTINV_BIT) ~= 0) {
if ((o1 hasnt worn && o2 has worn) || (o2 hasnt worn && o1 has worn)) rfalse;
if ((o1 hasnt light && o2 has light) || (o2 hasnt light && o1 has light)) rfalse;
if (o1 has container) {
if (o2 hasnt container) rfalse;
if ((o1 has open && o2 hasnt open) || (o2 has open && o1 hasnt open))
rfalse;
}
else if (o2 has container)
rfalse;
}
return Identical(o1, o2);
];
[ SortTogether obj value;
# print "Sorting together possessions of ", (object) obj, " by value ", value, "^";
# for (x=child(obj) : x~=0 : x=sibling(x))
# print (the) x, " no: ", x, " lt: ", x.list_together, "^";
while (child(obj) ~= 0) {
if (child(obj).list_together ~= value) move child(obj) to out_obj;
else move child(obj) to in_obj;
}
while (child(in_obj) ~= 0) move child(in_obj) to obj;
while (child(out_obj) ~= 0) move child(out_obj) to obj;
];
[ SortOutList obj i k l;
# print "^^Sorting out list from ", (name) obj, "^ ";
# for (i=child(location) : i~=0 : i=sibling(i))
# print (name) i, " --> ";
# new_line;
.AP_SOL;
for (i=obj : i~=0 : i=sibling(i)) {
k = i.list_together;
if (k ~= 0) {
# print "Scanning ", (name) i, " with lt=", k, "^";
for (i=sibling(i) : i~=0 && i.list_together == k :) i = sibling(i);
if (i == 0) rfalse;
# print "First not in block is ", (name) i, " with lt=", i.list_together, "^";
for (l=sibling(i) : l~=0 : l=sibling(l))
if (l.list_together == k) {
SortTogether(parent(obj), k);
# print "^^After ST:^ ";
# for (i=child(location) : i~=0 : i=sibling(i))
# print (name) i, " --> ";
# new_line;
obj = child(parent(obj));
jump AP_SOL;
}
}
}
];
#Ifdef TARGET_ZCODE;
[ Print__Spaces n; # To avoid a bug occurring in Inform 6.01 to 6.10
if (n == 0) return;
spaces n;
];
#Ifnot; # TARGET_GLULX;
[ Print__Spaces n;
while (n > 0) {
@streamchar ' ';
n = n - 1;
}
];
#Endif; # TARGET_
#ifdef NI_BUILD_COUNT;
Global c_depth;
Global I7_wlf_sp;
[ WriteListFrom o style depth a ol;
if ((o == 0) || (parent(o) == 0)) {
print (string) NOTHING__TX;
if (style & NEWLINE_BIT ~= 0) new_line;
return;
}
#ifdef TARGET_ZCODE;
@push c_style; @push c_depth;
#ifnot; # TARGET_GLULX
@copy c_style sp; @copy c_depth sp;
#endif; # TARGET_
c_style = style; c_depth = depth;
if (o ~= child(parent(o))) { I7_WLF(o, depth); return; }
objectloop (ol provides list_together)
ol.list_together = 0;
CarryOutActivity(LISTCONTS_ACT, parent(o));
#ifdef TARGET_ZCODE;
@pull c_depth; @pull c_style;
#ifnot; # TARGET_GLULX
@copy sp c_depth; @copy sp c_style;
#endif; # TARGET_
];
[ I7_WLF o depth swi;
if (o == child(parent(o))) {
SortOutList(o);
o = child(parent(o));
}
swi = wlf_indent;
wlf_indent = 0; WriteListR(o, c_depth, I7_wlf_sp); say__p = 1;
wlf_indent = swi;
rtrue;
];
[ WriteListR o depth stack_pointer classes_p sizes_p i j k k2 l m n q senc mr;
# I7 version
if ((o == 0) || (parent(o) == 0)) return;
if (depth > 0 && o == child(parent(o))) {
SortOutList(o);
o = child(parent(o));
}
for (::) {
if (o == 0) rfalse;
if (c_style & WORKFLAG_BIT ~= 0 && depth==0 && o hasnt workflag) {
o = sibling(o);
continue;
}
if (c_style & EXTRA_WORKFLAG_BIT ~= 0 && depth<=1 && o hasnt workflag) {
o = sibling(o);
continue;
}
if (c_style & CONCEAL_BIT ~= 0 && (o has concealed || o has scenery)) {
o = sibling(o);
continue;
}
break;
}
classes_p = match_classes + stack_pointer;
sizes_p = match_list + stack_pointer;
for (i=o,j=0 : i~=0 && (j+stack_pointer)<128 : i=NextEntry(i,depth),j++) {
classes_p->j = 0;
if (i.plural ~= 0) k++;
}
if (c_style & ISARE_BIT ~= 0) {
if (j == 1 && o hasnt pluralname) print (string) IS__TX;
else print (string) ARE__TX;
if (c_style & NEWLINE_BIT ~= 0) print ":^";
else print (char) ' ';
c_style = c_style - ISARE_BIT;
}
stack_pointer = stack_pointer+j+1;
#ifdef TARGET_ZCODE; @push I7_wlf_sp; #endif;
#ifdef TARGET_GLULX; @copy I7_wlf_sp sp; #endif;
I7_wlf_sp = stack_pointer;
if (k < 2) jump EconomyVersion; # It takes two to plural
n = 1;
for (i=o,k=0 : k<j : i=NextEntry(i,depth),k++)
if (classes_p->k == 0) {
classes_p->k = n; sizes_p->n = 1;
for (l=NextEntry(i,depth),m=k+1 : l~=0 && m<j : l=NextEntry(l,depth),m++)
if (classes_p->m == 0 && i.plural ~= 0 && l.plural ~= 0) {
if (ListEqual(i, l) == 1) {
sizes_p->n = sizes_p->n + 1;
classes_p->m = n;
}
}
n++;
}
n--;
for (i=1,j=o,k=0 : i<=n : i++,senc++) {
while (((classes_p->k) ~= i) && ((classes_p->k) ~= -i)) {
k++; j=NextEntry(j, depth);
}
m = sizes_p->i;
if (j == 0) mr = 0;
else {
if (j.list_together ~= 0 or lt_value && ZRegion(j.list_together) == 2 or 3 &&
j.list_together == mr) senc--;
mr = j.list_together;
}
}
senc--;
for (i=1,j=o,k=0,mr=0 : senc>=0 : i++,senc--) {
while (((classes_p->k) ~= i) && ((classes_p->k) ~= -i)) {
k++; j=NextEntry(j, depth);
}
if (j.list_together ~= 0 or lt_value) {
if (j.list_together == mr) {
senc++;
jump Omit_FL2a;
}
k2 = NextEntry(j, depth);
if (k2 == 0 || k2.list_together ~= j.list_together) jump Omit_WL2;
k2 = ZRegion(j.list_together);
if (k2 == 2 or 3) {
q = j; listing_size = 1; l = k; m = i;
while (m < n && q.list_together == j.list_together) {
m++;
while (((classes_p->l) ~= m) && ((classes_p->l) ~= -m)) {
l++; q = NextEntry(q, depth);
}
if (q.list_together == j.list_together) listing_size++;
}
# print " [", listing_size, "] ";
if (listing_size == 1) jump Omit_WL2;
q = c_style;
if (c_style & INDENT_BIT ~= 0) Print__Spaces(2*(depth+wlf_indent));
BeginActivity(GROUP_ACT, j);
if (ForActivity(GROUP_ACT, j)) {
c_style = c_style &~ NEWLINE_BIT; jump RuleOmitted2;
}
if (k2 == 3) {
#ifdef TARGET_ZCODE; @push q; #endif;
#ifdef TARGET_GLULX; @copy q sp; #endif;
q = 0;
for (l=0 : l<listing_size : l++) q = q+sizes_p->(l+i);
EnglishNumber(q); print " ";
print (string) j.list_together;
if (c_style & ENGLISH_BIT ~= 0) print " (";
if (c_style & INDENT_BIT ~= 0) print ":^";
#ifdef TARGET_ZCODE; @pull q; #endif;
#ifdef TARGET_GLULX; @copy sp q; #endif;
}
if (k2 ~= 3) {
inventory_stage = 1;
parser_one = j; parser_two = depth+wlf_indent;
if (RunRoutines(j, list_together) == 1) jump Omit__Sublist2;
}
#Ifdef TARGET_ZCODE;
@push lt_value; @push listing_together; @push listing_size;
#Ifnot; # TARGET_GLULX;
@copy lt_value sp; @copy listing_together sp; @copy listing_size sp;
#Endif; # TARGET_;
lt_value = j.list_together; listing_together = j; wlf_indent++;
WriteListR(j, depth, stack_pointer); wlf_indent--;
#Ifdef TARGET_ZCODE;
@pull listing_size; @pull listing_together; @pull lt_value;
#Ifnot; # TARGET_GLULX;
@copy sp listing_size;
@copy sp listing_together;
@copy sp lt_value;
#Endif; # TARGET_;
if (k2 == 3) {
if (q & ENGLISH_BIT ~= 0) print ")";
}
else {
inventory_stage = 2;
parser_one = j; parser_two = depth+wlf_indent;
RunRoutines(j, list_together);
}
.RuleOmitted2;
EndActivity(GROUP_ACT, j);
.Omit__Sublist2;
if (q & NEWLINE_BIT ~= 0 && c_style & NEWLINE_BIT == 0) new_line;
c_style = q;
mr = j.list_together;
#ifdef TARGET_ZCODE; @push c_style; #endif;
#ifdef TARGET_GLULX; @copy c_style sp; #endif;
jump Omit_EL2;
}
}
.Omit_WL2;
#ifdef TARGET_ZCODE; @push c_style; #endif;
#ifdef TARGET_GLULX; @copy c_style sp; #endif;
if (WriteBeforeEntry(j, depth, -senc) == 1) jump Omit_FL2;
if (sizes_p->i == 1) {
if (c_style & NOARTICLE_BIT ~= 0) print (name) j;
else {
if (c_style & DEFART_BIT ~= 0) print (the) j; else print (a) j;
}
}
else {
if (c_style & DEFART_BIT ~= 0) PrefaceByArticle(j, 1, sizes_p->i);
print (number) sizes_p->i, " ";
BeginActivity(PLURALNAME_ACT, j);
if (ForActivity(PLURALNAME_ACT, j) == false) PrintOrRun(j, plural, 1);
EndActivity(PLURALNAME_ACT, j);
}
if (sizes_p->i > 1 && j hasnt pluralname) {
give j pluralname;
WriteAfterEntry(j, depth, stack_pointer);
give j ~pluralname;
}
else WriteAfterEntry(j,depth,stack_pointer);
.Omit_EL2;
if (c_style & ENGLISH_BIT ~= 0) {
if (senc == 1) {
if (i == 1) print (string) LISTAND2__TX;
else print (string) LISTAND__TX;
}
if (senc > 1) print (string) COMMA__TX;
}
.Omit_FL2;
#ifdef TARGET_ZCODE; @pull c_style; #endif;
#ifdef TARGET_GLULX; @copy sp c_style; #endif;
.Omit_FL2a;
}
#ifdef TARGET_ZCODE; @pull I7_wlf_sp; #endif;
#ifdef TARGET_GLULX; @copy sp I7_wlf_sp; #endif;
rtrue;
.EconomyVersion;
n = j;
for (i=1,j=o : i<=n : j=NextEntry(j,depth),i++,senc++) {
if (j.list_together ~= 0 or lt_value && ZRegion(j.list_together) == 2 or 3 &&
j.list_together==mr) senc--;
mr = j.list_together;
}
for (i=1,j=o,mr=0 : i<=senc : j=NextEntry(j,depth),i++) {
if (j.list_together ~= 0 or lt_value) {
if (j.list_together == mr) {
i--;
jump Omit_FLa;
}
k = NextEntry(j, depth);
if (k == 0 || k.list_together ~= j.list_together) jump Omit_WL;
k = ZRegion(j.list_together);
if (k == 2 or 3) {
if (c_style & INDENT_BIT ~= 0) Print__Spaces(2*(depth+wlf_indent));
q = c_style;
BeginActivity(GROUP_ACT, j);
if (ForActivity(GROUP_ACT, j)) {
c_style = c_style &~ NEWLINE_BIT;
jump RuleOmitted;
}
if (k == 3) {
#ifdef TARGET_ZCODE; @push q; #endif;
#ifdef TARGET_GLULX; @copy q sp; #endif;
q = j; l = 0;
do {
q = NextEntry(q, depth); l++;
} until (q == 0 || q.list_together ~= j.list_together);
#ifdef TARGET_ZCODE; @pull q; #endif;
#ifdef TARGET_GLULX; @copy sp q; #endif;
EnglishNumber(l); print " ";
print (string) j.list_together;
if (c_style & ENGLISH_BIT ~= 0) print " (";
if (c_style & INDENT_BIT ~= 0) print ":^";
}
if (k ~= 3) {
inventory_stage = 1;
parser_one = j; parser_two = depth+wlf_indent;
if (RunRoutines(j, list_together) == 1) jump Omit__Sublist;
}
#Ifdef TARGET_ZCODE;
@push lt_value; @push listing_together; @push listing_size;
#Ifnot; # TARGET_GLULX;
@copy lt_value sp; @copy listing_together sp; @copy listing_size sp;
#Endif; # TARGET_;
lt_value = j.list_together; listing_together = j; wlf_indent++;
WriteListR(j, depth, stack_pointer); wlf_indent--;
#Ifdef TARGET_ZCODE;
@pull listing_size; @pull listing_together; @pull lt_value;
#Ifnot; # TARGET_GLULX;
@copy sp listing_size; @copy sp listing_together; @copy sp lt_value;
#Endif; # TARGET_;
if (k == 3) {
if (c_style & ENGLISH_BIT ~= 0) print ")";
}
else {
inventory_stage = 2;
parser_one = j; parser_two = depth+wlf_indent;
RunRoutines(j, list_together);
}
.RuleOmitted;
EndActivity(GROUP_ACT, j);
.Omit__Sublist;
if (q & NEWLINE_BIT ~= 0 && c_style & NEWLINE_BIT == 0) new_line;
c_style = q;
mr = j.list_together;
#ifdef TARGET_ZCODE; @push c_style; #endif;
#ifdef TARGET_GLULX; @copy c_style sp; #endif;
jump Omit_EL;
}
}
.Omit_WL;
#ifdef TARGET_ZCODE; @push c_style; #endif;
#ifdef TARGET_GLULX; @copy c_style sp; #endif;
if (WriteBeforeEntry(j, depth, i-senc) == 1) jump Omit_FL;
if (c_style & NOARTICLE_BIT ~= 0) print (name) j;
else {
if (c_style & DEFART_BIT ~= 0) print (the) j; else print (a) j;
}
WriteAfterEntry(j, depth, stack_pointer);
.Omit_EL;
if (c_style & ENGLISH_BIT ~= 0) {
if (i == senc-1) {
if (i == 1) print (string) LISTAND2__TX;
else print (string) LISTAND__TX;
}
if (i < senc-1) print (string) COMMA__TX;
}
.Omit_FL;
#ifdef TARGET_ZCODE; @pull c_style; #endif;
#ifdef TARGET_GLULX; @copy sp c_style; #endif;
.Omit_FLa;
}
#ifdef TARGET_ZCODE; @pull I7_wlf_sp; #endif;
#ifdef TARGET_GLULX; @copy sp I7_wlf_sp; #endif;
]; # end of WriteListR
#ifnot; # NI_BUILD_COUNT
[ WriteListFrom o style depth;
#Ifdef TARGET_ZCODE;
@push c_style; @push lt_value; @push listing_together;
@push listing_size; @push wlf_indent; @push inventory_stage;
#Ifnot; # TARGET_GLULX
@copy c_style sp; @copy lt_value sp; @copy listing_together sp;
@copy listing_size sp; @copy wlf_indent sp; @copy inventory_stage sp;
#Endif;
if (o == child(parent(o))) {
SortOutList(o);
o = child(parent(o));
}
c_style = style;
wlf_indent = 0;
WriteListR(o, depth);
#Ifdef TARGET_ZCODE;
@pull inventory_stage; @pull wlf_indent; @pull listing_size;
@pull listing_together; @pull lt_value; @pull c_style;
#Ifnot; # TARGET_GLULX
@copy sp inventory_stage; @copy sp wlf_indent; @copy sp listing_size;
@copy sp listing_together; @copy sp lt_value; @copy sp c_style;
#Endif;
rtrue;
];
[ WriteListR o depth stack_pointer classes_p sizes_p i j k k2 l m n q senc mr;
# I6 version
if ((o == 0) || (parent(o) == 0)) return;
if (depth > 0 && o == child(parent(o))) {
SortOutList(o);
o = child(parent(o));
}
for (::) {
if (o == 0) rfalse;
if (c_style & WORKFLAG_BIT ~= 0 && depth==0 && o hasnt workflag) {
o = sibling(o);
continue;
}
if (c_style & CONCEAL_BIT ~= 0 && (o has concealed || o has scenery)) {
o = sibling(o);
continue;
}
break;
}
classes_p = match_classes + stack_pointer;
sizes_p = match_list + stack_pointer;
for (i=o,j=0 : i~=0 && (j+stack_pointer)<128 : i=NextEntry(i,depth),j++) {
classes_p->j = 0;
if (i.plural ~= 0) k++;
}
if (c_style & ISARE_BIT ~= 0) {
if (j == 1 && o hasnt pluralname) print (string) IS__TX;
else print (string) ARE__TX;
if (c_style & NEWLINE_BIT ~= 0) print ":^";
else print (char) ' ';
c_style = c_style - ISARE_BIT;
}
stack_pointer = stack_pointer+j+1;
if (k < 2) jump EconomyVersion; # It takes two to plural
n = 1;
for (i=o,k=0 : k<j : i=NextEntry(i,depth),k++)
if (classes_p->k == 0) {
classes_p->k = n; sizes_p->n = 1;
for (l=NextEntry(i,depth),m=k+1 : l~=0 && m<j : l=NextEntry(l,depth),m++)
if (classes_p->m == 0 && i.plural ~= 0 && l.plural ~= 0) {
if (ListEqual(i, l) == 1) {
sizes_p->n = sizes_p->n + 1;
classes_p->m = n;
}
}
n++;
}
n--;
for (i=1,j=o,k=0 : i<=n : i++,senc++) {
while (((classes_p->k) ~= i) && ((classes_p->k) ~= -i)) {
k++; j=NextEntry(j, depth);
}
m = sizes_p->i;
if (j == 0) mr = 0;
else {
if (j.list_together ~= 0 or lt_value && ZRegion(j.list_together) == 2 or 3 &&
j.list_together == mr) senc--;
mr = j.list_together;
}
}
senc--;
for (i=1,j=o,k=0,mr=0 : senc>=0 : i++,senc--) {
while (((classes_p->k) ~= i) && ((classes_p->k) ~= -i)) {
k++; j=NextEntry(j, depth);
}
if (j.list_together ~= 0 or lt_value) {
if (j.list_together == mr) {
senc++;
jump Omit_FL2;
}
k2 = NextEntry(j, depth);
if (k2 == 0 || k2.list_together ~= j.list_together) jump Omit_WL2;
k2 = ZRegion(j.list_together);
if (k2 == 2 or 3) {
q = j; listing_size = 1; l = k; m = i;
while (m < n && q.list_together == j.list_together) {
m++;
while (((classes_p->l) ~= m) && ((classes_p->l) ~= -m)) {
l++; q = NextEntry(q, depth);
}
if (q.list_together == j.list_together) listing_size++;
}
# print " [", listing_size, "] ";
if (listing_size == 1) jump Omit_WL2;
if (c_style & INDENT_BIT ~= 0) Print__Spaces(2*(depth+wlf_indent));
if (k2 == 3) {
q = 0;
for (l=0 : l<listing_size : l++) q = q+sizes_p->(l+i);
EnglishNumber(q); print " ";
print (string) j.list_together;
if (c_style & ENGLISH_BIT ~= 0) print " (";
if (c_style & INDENT_BIT ~= 0) print ":^";
}
q = c_style;
if (k2 ~= 3) {
inventory_stage = 1;
parser_one = j; parser_two = depth+wlf_indent;
if (RunRoutines(j, list_together) == 1) jump Omit__Sublist2;
}
#Ifdef TARGET_ZCODE;
@push lt_value; @push listing_together; @push listing_size;
#Ifnot; # TARGET_GLULX;
@copy lt_value sp; @copy listing_together sp; @copy listing_size sp;
#Endif; # TARGET_;
lt_value = j.list_together; listing_together = j; wlf_indent++;
WriteListR(j, depth, stack_pointer); wlf_indent--;
#Ifdef TARGET_ZCODE;
@pull listing_size; @pull listing_together; @pull lt_value;
#Ifnot; # TARGET_GLULX;
@copy sp listing_size;
@copy sp listing_together;
@copy sp lt_value;
#Endif; # TARGET_;
if (k2 == 3) {
if (q & ENGLISH_BIT ~= 0) print ")";
}
else {
inventory_stage = 2;
parser_one = j; parser_two = depth+wlf_indent;
RunRoutines(j, list_together);
}
.Omit__Sublist2;
if (q & NEWLINE_BIT ~= 0 && c_style & NEWLINE_BIT == 0) new_line;
c_style = q;
mr = j.list_together;
jump Omit_EL2;
}
}
.Omit_WL2;
if (WriteBeforeEntry(j, depth, -senc) == 1) jump Omit_FL2;
if (sizes_p->i == 1) {
if (c_style & NOARTICLE_BIT ~= 0) print (name) j;
else {
if (c_style & DEFART_BIT ~= 0) print (the) j; else print (a) j;
}
}
else {
if (c_style & DEFART_BIT ~= 0) PrefaceByArticle(j, 1, sizes_p->i);
print (number) sizes_p->i, " ";
PrintOrRun(j, plural, 1);
}
if (sizes_p->i > 1 && j hasnt pluralname) {
give j pluralname;
WriteAfterEntry(j, depth, stack_pointer);
give j ~pluralname;
}
else WriteAfterEntry(j,depth,stack_pointer);
.Omit_EL2;
if (c_style & ENGLISH_BIT ~= 0) {
if (senc == 1) print (string) AND__TX;
if (senc > 1) print (string) COMMA__TX;
}
.Omit_FL2;
}
rtrue;
.EconomyVersion;
n = j;
for (i=1,j=o : i<=n : j=NextEntry(j,depth),i++,senc++) {
if (j.list_together ~= 0 or lt_value && ZRegion(j.list_together) == 2 or 3 &&
j.list_together==mr) senc--;
mr = j.list_together;
}
for (i=1,j=o,mr=0 : i<=senc : j=NextEntry(j,depth),i++) {
if (j.list_together ~= 0 or lt_value) {
if (j.list_together == mr) {
i--;
jump Omit_FL;
}
k = NextEntry(j, depth);
if (k == 0 || k.list_together ~= j.list_together) jump Omit_WL;
k = ZRegion(j.list_together);
if (k == 2 or 3) {
if (c_style & INDENT_BIT ~= 0) Print__Spaces(2*(depth+wlf_indent));
if (k == 3) {
q = j; l = 0;
do {
q = NextEntry(q, depth); l++;
} until (q == 0 || q.list_together ~= j.list_together);
EnglishNumber(l); print " ";
print (string) j.list_together;
if (c_style & ENGLISH_BIT ~= 0) print " (";
if (c_style & INDENT_BIT ~= 0) print ":^";
}
q = c_style;
if (k ~= 3) {
inventory_stage = 1;
parser_one = j; parser_two = depth+wlf_indent;
if (RunRoutines(j, list_together) == 1) jump Omit__Sublist;
}
#Ifdef TARGET_ZCODE;
@push lt_value; @push listing_together; @push listing_size;
#Ifnot; # TARGET_GLULX;
@copy lt_value sp; @copy listing_together sp; @copy listing_size sp;
#Endif; # TARGET_;
lt_value = j.list_together; listing_together = j; wlf_indent++;
WriteListR(j, depth, stack_pointer); wlf_indent--;
#Ifdef TARGET_ZCODE;
@pull listing_size; @pull listing_together; @pull lt_value;
#Ifnot; # TARGET_GLULX;
@copy sp listing_size; @copy sp listing_together; @copy sp lt_value;
#Endif; # TARGET_;
if (k == 3) {
if (q & ENGLISH_BIT ~= 0) print ")";
}
else {
inventory_stage = 2;
parser_one = j; parser_two = depth+wlf_indent;
RunRoutines(j, list_together);
}
.Omit__Sublist;
if (q & NEWLINE_BIT ~= 0 && c_style & NEWLINE_BIT == 0) new_line;
c_style = q;
mr = j.list_together;
jump Omit_EL;
}
}
.Omit_WL;
if (WriteBeforeEntry(j, depth, i-senc) == 1) jump Omit_FL;
if (c_style & NOARTICLE_BIT ~= 0) print (name) j;
else {
if (c_style & DEFART_BIT ~= 0) print (the) j; else print (a) j;
}
WriteAfterEntry(j, depth, stack_pointer);
.Omit_EL;
if (c_style & ENGLISH_BIT ~= 0) {
if (i == senc-1) print (string) AND__TX;
if (i < senc-1) print (string) COMMA__TX;
}
.Omit_FL;
}
]; # end of WriteListR
#endif; # NI_BUILD_COUNT
[ WriteBeforeEntry o depth sentencepos
flag invent_bits;
inventory_stage = 1;
if (c_style & INDENT_BIT) Print__Spaces(2*(depth+wlf_indent));
#ifdef NI_BUILD_COUNT;
# JM: don't use the 'invent' property for room listings in I7
invent_bits = FULLINV_BIT;
#ifnot;
invent_bits = PARTINV_BIT|FULLINV_BIT;
#endif; # NI_BUILD_COUNT
if (o.invent && (c_style & invent_bits)) { # This line changed
flag = PrintOrRun(o, invent, 1);
if (flag) {
if (c_style & ENGLISH_BIT) {
#ifdef NI_BUILD_COUNT;
if (sentencepos == -1) print (string) LISTAND__TX;
#ifnot;
if (sentencepos == -1) print (string) AND__TX;
#endif; # NI_BUILD_COUNT
if (sentencepos < -1) print (string) COMMA__TX;
}
if (c_style & NEWLINE_BIT) new_line;
}
}
return flag;
];
[ WriteAfterEntry o depth stack_p
p recurse_flag parenth_flag eldest_child child_count combo;
inventory_stage = 2;
if (c_style & PARTINV_BIT) {
#ifdef NI_BUILD_COUNT;
BeginActivity(DETAILS_ACT);
if (ForActivity(DETAILS_ACT) == false) {
#ifnot;
# JM: don't use the 'invent' property for room listings in I7
if (o.invent && RunRoutines(o, invent)) {
if (c_style & NEWLINE_BIT) new_line;
rtrue;
}
#endif; # NI_BUILD_COUNT
combo = 0;
if (o has light && location hasnt light) combo=combo+1;
if (o has container && o hasnt open) combo=combo+2;
if ((o has container && (o has open || o has transparent))
&& (child(o)==0)) combo=combo+4;
if (combo) L__M(##ListMiscellany, combo, o);
#ifdef NI_BUILD_COUNT;
}
EndActivity(DETAILS_ACT);
#endif; # NI_BUILD_COUNT
} # end of PARTINV_BIT processing
if (c_style & FULLINV_BIT) {
if (o.invent && RunRoutines(o, invent))
if (c_style & NEWLINE_BIT) ""; else rtrue;
if (o has light && o has worn) { L__M(##ListMiscellany, 8); parenth_flag = true; }
else {
if (o has light) { L__M(##ListMiscellany, 9, o); parenth_flag = true; }
if (o has worn) { L__M(##ListMiscellany, 10, o); parenth_flag = true; }
}
if (o has container)
if (o has openable) {
if (parenth_flag) print (string) AND__TX;
else L__M(##ListMiscellany, 11, o);
if (o has open)
if (child(o)) L__M(##ListMiscellany, 12, o);
else L__M(##ListMiscellany, 13, o);
else
if (o has lockable && o has locked) L__M(##ListMiscellany, 15, o);
else L__M(##ListMiscellany, 14, o);
parenth_flag = true;
}
else
if (child(o)==0 && o has transparent)
if (parenth_flag) L__M(##ListMiscellany, 16, o);
else L__M(##ListMiscellany, 17, o);
if (parenth_flag) print ")";
} # end of FULLINV_BIT processing
if (c_style & CONCEAL_BIT) {
child_count = 0;
objectloop (p in o)
if (p hasnt concealed && p hasnt scenery) { child_count++; eldest_child = p; }
}
else { child_count = children(o); eldest_child = child(o); }
if (child_count && (c_style & ALWAYS_BIT)) {
if (c_style & ENGLISH_BIT) L__M(##ListMiscellany, 18, o);
recurse_flag = true;
}
if (child_count && (c_style & RECURSE_BIT)) {
if (o has supporter) {
if (c_style & ENGLISH_BIT) {
if (c_style & TERSE_BIT) L__M(##ListMiscellany, 19, o);
else L__M(##ListMiscellany, 20, o);
if (o has animate) print (string) WHOM__TX;
else print (string) WHICH__TX;
}
recurse_flag = true;
}
if (o has container && (o has open || o has transparent)) {
if (c_style & ENGLISH_BIT) {
if (c_style & TERSE_BIT) L__M(##ListMiscellany, 21, o);
else L__M(##ListMiscellany, 22, o);
if (o has animate) print (string) WHOM__TX;
else print (string) WHICH__TX;
}
recurse_flag = true;
}
}
if (recurse_flag && (c_style & ENGLISH_BIT))
if (child_count > 1 || eldest_child has pluralname) print (string) ARE2__TX;
else print (string) IS2__TX;
if (c_style & NEWLINE_BIT) new_line;
if (recurse_flag) {
o = child(o);
#Ifdef TARGET_ZCODE;
@push lt_value; @push listing_together; @push listing_size;
#Ifnot; # TARGET_GLULX;
@copy lt_value sp; @copy listing_together sp; @copy listing_size sp;
#Endif;
lt_value = 0; listing_together = 0; listing_size = 0;
WriteListR(o, depth+1, stack_p);
#Ifdef TARGET_ZCODE;
@pull listing_size; @pull listing_together; @pull lt_value;
#Ifnot; # TARGET_GLULX;
@copy sp listing_size; @copy sp listing_together; @copy sp lt_value;
#Endif;
if (c_style & TERSE_BIT) print ")";
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment