I've spent hours trying to re-code the inventory being unimpressed by how it simply listed all the items a player was carrying without it stating what was wielded, what was worn and what the player was actually carrying so I put togther this.
//Written by Shigs - 03-05-2008
//Lists items in your inventory
//:PLAYERCOMMAND
//USAGE: i
// inventory
//
//Shows you what you have in your inventory.
#include <flags.h>
inherit CMD;
private void main()
{
string wielded = "";
string worn = "";
string carrying = "";
string ex;
object ob;
int a = 0;
int b = 0;
int c = 0;
//Constrcut Wielded string
//Construct Worn String
//Construct Carrying String
object * items = all_inventory(this_body());
foreach(ob in items)
if (duplicatep(ob))
{
out "there is more than one of" + ob;
}
if(ob->test_flag(F_WIELDED)){
if(!a){
wielded += " Wielded : " + capitalize(ob->the_short());
a = 1;
}else{
wielded += "\n\t " + capitalize(ob->the_short());
}
}else if(ob->test_flag(F_WORN)){
if(!b){
worn += "\n Worn : " + capitalize(ob->the_short());
b = 1;
}else{
worn += "\n\t " + capitalize(ob->the_short());
}
}else{
if(!c){
carrying += "\nCarrying : " + capitalize(ob->the_short());
c = 1;
}else{
carrying += "\n\t " + capitalize(ob->the_short());
}
}
}
ex = wielded + worn + carrying;
out("%^RED%^===============================%^RESET%^\n");
out("\tINVENTORY\n");
out(" You are carrying " + sizeof(items) + " items.\n");
out("%^RED%^===============================%^RESET%^\n");
if (ex)
out(ex);
else
out("You are empty handed.\n");
out("\n%^RED%^===============================%^RESET%^\n");
return;
}
Now forgive my slightly hacked toghther code I'm still getting used to things.. this displays as.
===============================
INVENTORY
You are carrying 9 items.
===============================
Wielded : The Fencing Saber
Worn : The Alliance Vest
Carrying : The dull sword
The dull sword
The dull sword
The map
The small leaflet
The LIMA Guide Book
The full armor eight
===============================
vs
You are carrying:
3 dull swords
a map
a Fencing Saber (damaged) (wielded in right hand)
a small leaflet
the LIMA Guide Book titled '0'
a Alliance Vest worn over torso and arms
a full armor eight
The problem is, as you can see, it dosen't group up duplicate items.
I've trudged through the code and found how the inital inventory code does it by calling inv_list,
varargs string inv_list(object array obs, int flag, int depth) {
string res;
int j;
depth++;
res = "";
foreach (object ob in obs) {
if (!ob) continue;
if (!ob->is_visible()) continue;
if (!ob->short()) continue;
if (flag && !ob->test_flag(TOUCHED) && ob->untouched_long()) continue;
if (ob->is_attached()) {
if (ob->inventory_visible() && !ob->query_hide_contents())
res += ob->inventory_recurse(depth);
continue;
}
if (!duplicatep(ob))
{
for (j=0; j<depth; j++) res+=" ";
if ((j=count(ob))>1) {
if (j > 4) res += "many " + ob->plural_short();
else res += j + " " + ob->plural_short();
} else {
if (ob->is_living()) {
res += ob->in_room_desc();
} else {
res += ob->a_short() + ob->get_attributes();
}
}
res += "\n";
if( ob->inventory_visible() && !ob->query_hide_contents())
res += ob->inventory_recurse(depth);
}
}
return res == "" ? 0 : res;
}
which uses duplicatep to check if the item is a duplicate.
varargs int duplicatep( object o ) {
int i;
object *obs;
if (!o)
o = previous_object();
obs = all_inventory(environment(o));
for (i=0; i<sizeof(obs); i++) {
if (obs[i]==o) return 0;
if (compare_objects(obs[i], o)) return 1;
}
}
I sort of understand the code, but it might as well be in German for all my 'sort of understanding 'it goes.. because I can't for the slightest figure out how to implement anything passed checking for duplicate objects.
any suggestions, Gents?