Author Topic: Object matching and entry messages  (Read 2535 times)

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Object matching and entry messages
« on: November 12, 2007, 12:47:51 am »
We've got a small bug^H^H^H old optimization here. It conflicts with OBJECT_MATCHING.

Code: [Select]
> goto /domains/campus/room/basement
The basement
You are in the basement of the LPC University administrative building. It is very dark here, and rather damp. The fluorescent
lighting seems to be on the verge of total failure, with only one or two flickering on and off enough to see anything. The air
here is damp, thick and musty. There is a small crawlspace you can enter under the stairs here, and the basement continues east
into darkness.
Obvious exits: east, up, enter crawlspace
A rat is standing here.
>
Now, to load the room and allow rat to wander:
Code: [Select]
> enter crawlspace
/domains/campus/room/crawlspace
A tiny crawlspace
You are in a cramped little space beneath the stairs in the basement. It is dark, tight, and dirty in here.
Obvious exit: out
A small, plastic flashlight and thirty-one dollars are here.
> out
/domains/campus/room/basement
The basement
You are in the basement of the LPC University administrative building. It is very dark here, and rather damp. The fluorescent
lighting seems to be on the verge of total failure, with only one or two flickering on and off enough to see anything. The air
here is damp, thick and musty. There is a small crawlspace you can enter under the stairs here, and the basement continues east
into darkness.
Obvious exits: east, up, enter crawlspace
>
(wait a moment...)
Code: [Select]
A mangy little rat scurries in.
A mangy little rat enters into the cr.
A mangy little rat scurries in.
A mangy little rat enters into the crawl.
A mangy little rat scurries in.
A mangy little rat enters into the crawlsp.
A mangy little rat scurries in.
A mangy little rat enters into the craw.
A mangy little rat scurries in.
A mangy little rat enters into the crawlspac.
A mangy little rat scurries in.
A mangy little rat enters into the crawlspace.
A mangy little rat scurries in.
A mangy little rat enters into the crawlspa.
A mangy little rat scurries in.
A mangy little rat enters into the crawlspace.

After half a minute (thanks again for findfun command), I've found this:
Code: [Select]
/lib/sentient.c:
293: foreach(tmp in (string *)environment()->GetEnters()) {
And, of course:
Code: [Select]
> call here->GetEnters()
OBJ(/domains/campus/room/basement) -> GetEnters() = ({ "crawlspace", "crawlspac", "crawlspa", "crawlsp", "crawls", "crawl",
"craw", "cra", "cr", "/lib/std/dummy#27", "crawlspace", "crawlspace", "crawlspac", "crawlspa", "crawlsp", "crawls", "crawl",
"craw", "cra", "cr" })
>
Why?
Code: [Select]
/lib/exits.c:
177: varargs string array GetEnters(int i) {
(snip...)
190:     foreach(object ob in obs) {
191:         if( ob->GetEnter() ) {
192:             if(i) ids += ({ ob->GetId()[0] });
193:             else ids += ob->GetId();
193:         }
195:     }
Code: [Select]
/lib/props/id.c:
57: string array GetId() {
58:     string tmp;
59:     //if(!inherits(LIB_GERM,this_object())) tmp = GetKeyName();
60:     tmp = GetKeyName();
61:
62:     if( tmp ) {
63:         if(!OBJECT_MATCHING || !Matching) return distinct_array(({ CanonicalId..., tmp }));
64:         else return Id + ({ file_name(this_object()) }) + atomize_string(tmp) - ExcludedIds;
65:     }
66:     else return Id;
67: }

Ok, so if I change line 293 in /lib/sentient.c from GetEnters() to GetEnters(1) wandering monsters will not
use truncated names. (This is good because the wandering code picks an entrance randomly, and now it is
imbalanced - crawlspace with truncations has 20 entries in array, while for example 'hut' will have... er...
(@#%$ duplicates)... 3? 6? Not the same amount, that is. With GetEnters(1) every entrance has one array entry.)

But what if player types 'enter crawlsp' instead of 'enter crawlspace'?
Code: [Select]
Raudhrskal enters into the crawlsp.Oops.

Let's see... verb just call eventEnter...
Code: [Select]
/lib/enter.c:
95:  varargs mixed eventEnter(object who, string what, string verb) {
(snip)//string what is the word as typed by player^^^ - it worked in the old days where the full name was required
114:     if(verb == "crawl") who->eventMoveLiving(Enter["room"],"into the " + what );
115:     else who->eventMoveLiving(Enter["room"], "$N enters into the " + what + ".");
Aha!

My current fix (in addition to the sentient.c:293) is:
Code: [Select]
--- lib/enter.c~        2007-10-27 21:45:03.000000000 +0200
+++ lib/enter.c 2007-11-11 18:42:51.769447000 +0100
@@ -111,8 +111,8 @@
     if( Enter["pre"] && !evaluate(Enter["pre"], what) ) {
         return 1;
     }
-    if(verb == "crawl") who->eventMoveLiving(Enter["room"],"into the " + what );
-    else who->eventMoveLiving(Enter["room"], "$N enters into the " + what + ".");
+    if(verb == "crawl") who->eventMoveLiving(Enter["room"],"into the " + this_object()->GetKeyName() );
+    else who->eventMoveLiving(Enter["room"], "$N enters into the " + this_object()->GetKeyName() + ".");
+    //this_object() refers to the dummy entrance item                          ^^^
     if( Enter["post"] ) {
         evaluate(Enter["post"], what);
     }
This is a Kludge(tm). /lib/enter is inherited by the dummy entrance, but it may be inherited by somthing else.
'grep -R LIB_ENTER /*' reveals /lib/vehicle.c - this is OK, it has GetKeyName(). But there must be a better way to fix this.
Any ideas?

'Skal

PS. Exits are unaffected by the matching system - they are not dummy objects.
Code: [Select]
OBJ(/domains/campus/room/basement) -> GetExits() = ({ "east", "up" })PPS. I use the basement as an example - tested also with the dry well.
PPPS. This is DS 2.5a21 - if it has been fixed last week, sorry.
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Object matching and entry messages
« Reply #1 on: November 12, 2007, 05:08:00 pm »
Very nice...thank you.

-Crat

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Object matching and entry messages
« Reply #2 on: December 20, 2007, 04:09:05 am »
Hello,
sorry for digging topic after such amount of time, but I am just back from hospital,
and found that I didn't send this data before.

All diffs for stock 2.6

After the sentient patch, I grepped through the lib, and found that it's used
in a few more places...

* /lib/include/exits.h - shouldn't the prototype be updated?
string array GetEnters();  ==> varargs string array GetEnters(int i);
Everything works without it...

* lib/command.c - Well, the "official" commands are tried before matching enters,
so there's no conflict, but I personally think that BARE_EXITS should match
only the full names. What's your opinion?
Code: [Select]
    if(BARE_EXITS){
<snip>
            if(member_array(verb,environment(this_player())->GetEnters()) != -1) verb = "enter "+verb;
        }

* Wimpy function preferred the enters with longer names - just like
the sentient wandering code ;)
Code: [Select]
--- lib/combat.c~       2007-12-05 21:38:42.000000000 +0100
+++ lib/combat.c        2007-12-07 16:21:55.000000000 +0100
@@ -1084,7 +1084,7 @@
             tmp = filter((string *)environment()->GetExits(),
               (: !((string)environment()->GetDoor($1)) :));
             if( !sizeof(tmp) ) {
-                tmp = filter((string *)environment()->GetEnters(),
+                tmp = filter((string *)environment()->GetEnters(1),
                   (: !((string)environment()->GetDoor($1)) :));
                 if( !sizeof(tmp) ) {
                     this_object()->eventPrint("You need to escape, but you have nowhere to go!");

* And this one is just extremely funny:
When you yell, you should be heard in adjacent rooms, right?
Code: [Select]
/realms/raudhrskal/area/room/entrz
GetEnters() bug room
Obvious exits: south, enter crawlspace
Khawar the Test Character is standing here.

Khawar enters into the crawlspace.
You yell in Common, "Test!"
(I am again using "crawlspace" as example - long name, many expansions)

And what Khawar sees?
Code: [Select]
Bug Space
This is room behind the crawlspace.
Obvious exits: out

You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"
You hear a male human yell in Common from a distance, "Test!"

Nice reverb ;)

Code: [Select]
--- lib/std/room.c~     2007-10-27 21:45:03.000000000 +0200
+++ lib/std/room.c      2007-12-07 16:00:37.133664312 +0100
@@ -848,7 +848,7 @@
             if( (door = GetDoor(exit)) && (int)door->GetClosed() ) continue;
             tmp->eventHearTalk(who, target, TALK_LOCAL, verb, msg, lang);
         }
-        foreach(exit in GetEnters()) {
+        foreach(exit in GetEnters(1)) {
             string tmp;

             tmp = GetEnter(exit);

* This one just for convenience - "exits" gives unique exits & enters,
"exits all" show the truncations.
Code: [Select]
--- /tmp/exits.c        2007-10-27 21:45:01.000000000 +0200
+++ cmds/creators/exits.c       2007-12-07 16:28:30.000000000 +0100
@@ -8,7 +8,7 @@

 inherit LIB_DAEMON;

-mixed cmd()
+mixed cmd(string str)
 {
     string *asExits, sDir, sExit;
     string *asEnters;
@@ -18,7 +18,7 @@
         return "You do not have a valid environment.";

     asExits = oEnv->GetExits();
-    asEnters = oEnv->GetEnters();
+    asEnters = oEnv->GetEnters(str != "all");

     message( "Nmy_action", sprintf("\t *** %s ***\n\n", identify( oEnv ) ),
       this_player() );

* And now the hard stuff: GetEnters() is also used in a few other places:
lib/exits.c -> pretty sure it should be this way.
lib/interactive.c -> If I understand the code, this appends plural "s"
to some string if there is more than one exit/enter. But it counts expansions,
so even with single entrance...
secure/modules/room.c && verbs/creators/delete.c -> these are part of QCS.
I'm unable to understand that code.

Could you check these out?

Wesolych Swiat / Merry Christmas,
'Skal
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...

Offline lobster

  • Acquaintance
  • *
  • Posts: 6
    • View Profile
Re: Object matching and entry messages
« Reply #3 on: March 16, 2008, 08:00:49 pm »
I had the same problem but got round it by adding the following code in /lib/std/room.c

Add after the vars, around line 67
private string* ToldTalk = ({});

Then in eventHearTalk    case TALK_AREA  after the first 'continue'
    if(member_array((string)tmp,ToldTalk) != -1) continue;

on the line after the tmp->eventHearTalk(.......   add
    ToldTalk +=({(string)tmp});

Do this for the enters as well and the echo will be lost.

Hope this helps.