Author Topic: doors in interactive.c, help please  (Read 3234 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« on: October 18, 2006, 02:53:20 PM »
Ok, Im trying to set it up so that the room displays like this:





code:
/realms/capo/area/room/sample_room
Sample Room
This is a room you can use as a template.
     
     Steel door heading north is closed
     Obvious Exits: north, east, west

     a simple table
     A fighter
   
and when open:

/realms/capo/area/room/sample_room
Sample Room
This is a room you can use as a template.
     
     Steel door heading north is open
     Obvious Exits: north, east, west

     a simple table
     A fighter




These are the errors that I get and the code that I have... how should I go about fixing the problem?





quote:


/lib/interactive.c line 227: Undefined variable 'door'

   

/lib/interactive.c line 422: Too many local variables

   

/lib/interactive.c line 424: Too many local variables

   








code:
/*
        if(door->GetClosed())
            desc += "The " + door + " is closed.";
           else
            desc += "The " + door + " is open.";
*/

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« Reply #1 on: October 18, 2006, 03:02:57 PM »
I switched to this:



code:
        if( (tmp =(string)env->GetDoor() && env->GetClosed()))
            desc += "\nThe " + tmp + " is closed.";
           else
            desc += "\nThe " + tmp + " is open.";




And this is what it looks like from my test character's standpoint:





l
quote:


Sample Room

This is a room you can use as a template.

The 0 is open.



     Obvious Exits: north, east, west



     a test character Visitor's Pass

     a steel door leading south

     a simple table

     Capo the creator

     A fighter

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« Reply #2 on: October 18, 2006, 03:22:59 PM »
I also wanted to point out that the "0" is actually closed, no matter what the game says!

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« Reply #3 on: October 18, 2006, 05:58:51 PM »
Current code from interactive.c

code:

        if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM )
            desc += (string)env->GetLong();

        if( (tmp =(string)env->GetDoor() && env->GetClosed()))
            desc += "\n\nThe " + tmp + " is closed.";
           else
            desc += "\n\n%^CYAN%^The " + tmp + " is open.%^RESET%^";

        if( (tmp = (string)env->GetObviousExits()) && tmp != "" )
            desc += "\n\n%^RESET%^%^BOLD%^%^WHITE%^     Obvious Exits: " + tmp + "%^RESET%^";
        else desc += "";

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
doors in interactive.c, help please
« Reply #4 on: October 18, 2006, 06:01:15 PM »

It looks like you're asking the wrong thing for the right info.



What is env?



Could you post the entire file?



Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« Reply #5 on: October 18, 2006, 06:10:08 PM »
For those following along at home the function this is being pasted from is eventDescribeEnvironment() in interactive.c

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
doors in interactive.c, help please
« Reply #6 on: October 18, 2006, 06:13:09 PM »
This is the func, as requested... long:



code:


void eventDescribeEnvironment(int brief) {
    object env;
    mixed tmp;
    string *shorts;
    string desc, smell, sound, touch;
    int i, maxi;

    if(!(env = environment(this_object()))) {
        eventPrint("You are nowhere.", MSG_ROOMDESC);
        return;
    }
    switch( i = GetEffectiveVision() ) {
    case VISION_BLIND:
        eventPrint("You are blind and can see nothing.");
        break;
    case VISION_TOO_DARK:
        eventPrint("It is much too dark to see.");
        break;
    case VISION_DARK:
        eventPrint("It is too dark to see.");
        break;
    case VISION_TOO_BRIGHT:
        eventPrint("It is much too %^YELLOW%^bright%^RESET%^ to see.");
        break;
    case VISION_BRIGHT:
        eventPrint("It is too %^YELLOW%^bright%^RESET%^ to see.");
        break;
    }
    if( !brief ) {
        if( i == VISION_CLEAR ){
            desc = (string)env->GetObviousExits() || "";
            if(desc && desc != "")
                desc = capitalize((string)env->GetShort() || "") + "\n";
            else desc = capitalize((string)env->GetShort()+"\n" || "\n");
        }
        else desc = "\n";
        if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM )
            desc += (string)env->GetLong();

        if( (tmp =(string)env->GetDoor() && env->GetClosed()))
            desc += "\n\nThe " + tmp + " is closed.";
           else
            desc += "\n\n%^CYAN%^The " + tmp + " is open.%^RESET%^";

        if( (tmp = (string)env->GetObviousExits()) && tmp != "" )
            desc += "\n\n%^RESET%^%^BOLD%^%^WHITE%^     Obvious Exits: " + tmp + "%^RESET%^";
        else desc += "";

        if(functionp(tmp = (mixed)env->GetSmell("default")))
            tmp = (string)(*tmp)("default");
        smell = tmp;
        if(functionp(tmp = (mixed)env->GetListen("default")))
            tmp = (string)(*tmp)("default");
        sound = tmp;
        if( functionp(tmp = (mixed)env->GetTouch("default")) )
            tmp = evaluate(tmp, "default");
        touch = tmp;
    }
    else {
        if(i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM){
            desc = (string)env->GetShort();
            if( (tmp = (string)env->GetObviousExits()) && tmp != "" )
                desc += "" + "";
            else desc += "";
        }
        else desc = "";
    }

  if( i == VISION_CLEAR ) {
        mapping lying = ([]);

        shorts = map(filter(all_inventory(env),
            function(object ob) {
                if( ob->GetProperty("furniture")) return 1;
                return 0;
              }), (: (string)$1->GetShort() :));

          foreach(string s in shorts)
          {
              if(!desc) desc = "";
              desc += "\n%^RESET%^     " + s +"%^RESET%";
          }
          if( desc ) eventPrint(desc, MSG_ROOMDESC);
          desc = "";

          shorts = map(filter(all_inventory(env),
              function(object ob)
              {
                  if(ob->GetProperty("furniture")) return 0;
                  if( living(ob) ) return 0;
                  if(ob->GetShort() == 0) return 0;
                  if((int)ob->GetInvis(this_object()) && !ob->GetDoor() ) return 0;
                  if(ob->GetDoor() && load_object(ob->GetDoor())->GetHiddenDoor()) return 0;
                  return 1;
                }), (: (string)$1->GetShort() :));

          foreach(string s in shorts)

            {
                if(!desc) desc = "";
                desc += "\n%^RESET%^     " + s + "%^RESET%^";
            }
            if( desc ) eventPrint(desc, MSG_ROOMDESC);
            desc = "";
        }
          i = GetEffectiveVision();
          if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM ) {
              mapping lying = ([]), sitting = ([]), standing = ([]), flying = ([]);
              mapping furniture = ([]);
              object *obs;
              string key;
              int val;

              obs = filter(all_inventory(env), function(object ob) {
                    if( (int)ob->GetInvis(this_object()) ) return 0;
                    if( living(ob) ) return 1;

/*
if( (int)ob->isFreshCorpse())
                        return 1;
*/
                  }) - ({ this_object() });
                maxi = sizeof(shorts = map(obs, (: (string)$1->GetHealthShort() :)));
                foreach(object liv in obs) {
                    string s = (string)liv->GetHealthShort();
                    int pos = (int)liv->GetPosition();
                    if( !s ) continue;
                    if(liv->GetProperty("furniture")) {
                        s += "BEGIN"+random(999999)+"END";
                    }
                    if(liv->GetProperty("furniture")){
                        furniture = liv->GetProperty("furniture");
                    }
                    else if(!furniture) furniture = 0;

                    if( pos == POSITION_STANDING) standing++;
                    else if( pos == POSITION_LYING ) lying++;
                    else if( pos == POSITION_SITTING ) sitting++;
                    else if( pos == POSITION_FLYING ) flying++;
                    else lying++;

                }
                if( !desc )
                {
                    tmp = "";
                }
                else
                {
                    tmp = desc;
                }
                desc = "    ";
/*
                foreach(key, val in lying) {
                    globaltmp = key;
                    if(grepp(key,"BEGIN")) {
                        sscanf(key,"%sBEGIN%*s",key);
                    }

                    if(lying[globaltmp]>1 && !furniture[globaltmp]){
                        desc += capitalize(consolidate(val, globaltmp)) +
                        "%^RESET%^ are lying down.";
                    }
                    else if(lying[globaltmp]<2 && !furniture[globaltmp]){
                        desc += capitalize(key) + "%^RESET%^ is lying down.";
                    }
                    else if(furniture[globaltmp]) {
                        desc += capitalize(key) + "%^RESET%^ is lying down"+
                        ((furniture[globaltmp]) ? furniture[globaltmp] : "") +".";
                    }
                    else if(furniture[key]) {
                        desc += capitalize(key) + "%^RESET%^ is lying down"+
                        ((furniture[key]) ? furniture[key] : "") +".";
                    }

                    desc += "    ";
                }
                foreach(key, val in sitting) {
                    globaltmp = key;
                    if(grepp(key,"BEGIN")) {
                        sscanf(key,"%sBEGIN%*s",key);
                    }

                    if(sitting[globaltmp]>1 && !furniture[globaltmp]){
                        desc += capitalize(consolidate(val, globaltmp)) +
                        "%^RESET%^ are sitting down.";
                    }
                    else if(sitting[globaltmp]<2 && !furniture[globaltmp]){
                        desc += capitalize(key) + "%^RESET%^ is sitting down.";
                    }
                    else if(furniture[globaltmp]) {
                        desc += capitalize(key) + "%^RESET%^ is sitting down"+
                        ((furniture[globaltmp]) ? furniture[globaltmp] : "") +".";
                    }
                    else if(furniture[key]) {
                        desc += capitalize(key) + "%^RESET%^ is sitting down"+
                        ((furniture[key]) ? furniture[key] : "") +".";
                    }


                    else {
                        desc += "wtf. i am "+key+", furniture["+globaltmp+"] is: "+furniture[globaltmp]+"\n"+
                        "  furniture["+key+"] is: "+furniture[key]+", and val is: "+val;
                    }
                    desc += "     ";
                }


                foreach(key, val in standing)
                {
                    if(grepp(key,"BEGIN"))
                    {
                        sscanf(key,"%sBEGIN%*s",key);
                    }
                    if( val<2 )
                        desc += capitalize(key) + "%^RESET%^ is standing here.";
                    else desc += capitalize(consolidate(val, key)) + "%^RESET%^ are standing here.";
                    desc += "\n    ";
                }


*/

                foreach(string s in shorts)
                 {
                 desc += " %^RESET%^" + capitalize(s) +"%^RESET%^\n";
                 desc += "    ";
                 }

/*
                foreach(key, val in flying)
                   {
                    if( val<2 )
                        desc += capitalize(key) + "%^RESET%^ is hovering here.";
                    else desc += capitalize(consolidate(val, key)) + "%^RESET%^ are hovering here.";
                    desc += "\n";
                }

*/
            }
              if( tmp )
              {
                  desc = tmp + desc;
              }
              if( sizeof(desc) ) {
                  eventPrint(desc + "", MSG_ROOMDESC);
              }
          }


Offline Aransus

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
doors in interactive.c, help please
« Reply #7 on: October 18, 2006, 06:23:28 PM »
Capo,



Have a peek at this code. I'm just posting the 'if( !brief )' block that starts on line 217 in my /lib/interactive.c. I also had to define 'string doorexit' as a global variable, because I was running into 'too many local variable' errors defining it within this block. If this does what you want, you may want to figure out how to consolidate variables so you don't have to define doorexit globally. In any case, hope this helps somewhat.



LPC code:
    if( !brief ) {
        if( i == VISION_CLEAR ){
            desc = (string)env->GetObviousExits() || "";
            if(desc && desc != "")
                desc = capitalize((string)env->GetShort() || "")
                + " [" + desc + "]\n";
            else desc = capitalize((string)env->GetShort()+"\n" || "\n");
        }
        else desc = "\n";
        if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM )
            desc += (string)env->GetLong();

        if(functionp(tmp = (mixed)env->GetSmell("default")))
            tmp = (string)(*tmp)("default");
        smell = tmp;
        if(functionp(tmp = (mixed)env->GetListen("default")))
            tmp = (string)(*tmp)("default");
        sound = tmp;
        if( functionp(tmp = (mixed)env->GetTouch("default")) )
            tmp = evaluate(tmp, "default");
        touch = tmp;

        desc += "\n\n";
        foreach( doorexit in env->GetDoors() ) {

            desc += capitalize( env->GetDoor(doorexit)->GetShort() );
            if( env->GetDoor(doorexit)->GetClosed() )
                desc += " is closed.\n";
            else
                desc += " is open.\n";
        }

    }




-- Aransus

Offline shadyman

  • Friend
  • **
  • Posts: 50
    • View Profile
doors in interactive.c, help please
« Reply #8 on: October 18, 2006, 07:24:11 PM »
Here's how I did mine. It's a little different, but then again, display design styles are different :)



I added "GenerateVerboseExits()" to my room.c, incase I ever wanted to get this string from somewhere else (ie, interactive.c, etc)



Code: room.c

code:
string GenerateVerboseExits(){
    string *normals;
    int exitCount = 0;
    string *roomexits;
    string *entersArray;
    string dir_string, enters;
    string temp,temp2;
    roomexits = GetExits();

   foreach( string ex in roomexits )
   {
      if( LIB_EXITS->GetExitObv( ex ) ) {
          roomexits -= ({ex});
       }
   }

    enters = "";
    normals = ({ "north", "south", "east", "west", "up", "down" });
    normals += ({ "northeast", "southeast", "northwest", "southwest" });
    normals += ({ "out" });
    dir_string = "";

    if( sizeof(GetEnters(1)-({0})))
    {
        entersArray = this_object()->GetEnters(1);
        foreach( string en in entersArray )
        {
           entersArray[exitCount++] = "enter "+entersArray[exitCount];
        }
        roomexits += entersArray;
    }

    exitCount = 0;
    if( sizeof( roomexits ) == 0 )
       dir_string += "%^BOLD%^WHITE%^There are no obvious exits%^RESET%^. ";
   else if( sizeof(roomexits) == 1 )
        dir_string += "%^BOLD%^WHITE%^There is "+ cardinal((int)sizeof(roomexits)) +" obvious exit%^RESET%^: ";
    else
       dir_string += "%^BOLD%^WHITE%^There are "+ cardinal((int)sizeof(roomexits)) +" obvious exits: ";

   //Generate Brief list
   //Brief = implode(roomexits,", ");

    foreach( string ex in roomexits )
    {
       //Generate Verbose list
       if (GetDoor(ex)) {
          temp = find_object(GetDoor(ex))->GetClosed();
          temp2 = find_object(GetDoor(ex))->GetShort();
         if (temp) {
            dir_string += "a closed "+temp2+" to the %^RED%^"+roomexits[exitCount]+"%^RESET%^";
         } else {
             dir_string += "an open "+temp2+" to the %^BOLD%^GREEN%^"+roomexits[exitCount]+"%^RESET%^";
          }
       } else {
           dir_string += "%^BOLD%^GREEN%^"+roomexits[exitCount]+"%^RESET%^";
        }

        if( ++exitCount == (sizeof( roomexits )-1) ) dir_string += ", and ";
        else dir_string += ", ";
    }

    if(last(dir_string,2) == ", ") dir_string = truncate(dir_string,2);
    dir_string = replace_string(dir_string,", , ",", ") + ".";
    return dir_string;
}






My Interactive.c, starting at like 2somethingsomething.. (If (!brief))

code:
    if( !brief ) {
      if( i == VISION_CLEAR ) {
          desc = capitalize("%^BOLD%^WHITE%^" + (string)env->GetShort() + "%^RESET%^\n" || "");
          //+ " [" + desc + "]\n";
      } else desc = "";

      if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM )
          desc += (string)env->GetLong()+"\n";

      desc += (string)env->GenerateVerboseExits() || "";

      if(functionp(tmp = (mixed)env->GetSmell("default")))
          tmp = (string)(*tmp)("default");
      smell = tmp;
      if(functionp(tmp = (mixed)env->GetListen("default")))
          tmp = (string)(*tmp)("default");
      sound = tmp;
      if( functionp(tmp = (mixed)env->GetTouch("default")) )
          tmp = evaluate(tmp, "default");
      touch = tmp;
    }




As you can see, I nerfed the [n,s,e,w] from up top by the title because we get a nice, verbose message instead. If folks want it brief, they can see [n,s,e,w].



I think that's all the code that it needs, but maybe not.  (devil)





Edit:

Disclaimer: Doors must have a short like "metal door" or "iron gate", etc to display correctly.

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
doors in interactive.c, help please
« Reply #9 on: October 19, 2006, 09:13:00 PM »

I like the GenerateVerboseExits() that you did; however, I noticed a couple problems that you may want to work around.



The first problem is that SetNoObviousExits(1) does not change the exits with your function.  It still shows the standard exits.



The second problem I found is that SetObviousExits("...") also does not change the obvious exits.



Perhaps you've already thought of this or already come upon this situation and have corrected it.  If not, I hope this helps you in some way.



Daelas/Amun-Ra


Offline shadyman

  • Friend
  • **
  • Posts: 50
    • View Profile
doors in interactive.c, help please
« Reply #10 on: October 19, 2006, 09:19:49 PM »

Oooh. Good point.



I had to hack it in from the previous (read: old) version of DS, when doors/exits were really rather different. I was sure I didn't catch everything, and that would be it. Good eye (nod)



I'll post a new version here when it's done.


Offline shadyman

  • Friend
  • **
  • Posts: 50
    • View Profile
doors in interactive.c, help please
« Reply #11 on: October 20, 2006, 09:18:02 PM »
This guy has to go in your /lib/exits.c  :>



code:

int GetExitObv( string str ) {
    if( !Exits[str] ) return 0;
    else return Exits[str]["obv"];
}