Author Topic: Checking the season  (Read 2906 times)

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Checking the season
« on: August 07, 2012, 09:46:59 am »
I want to change part of a room description based on the season. Ardneh and Crat have been helping me on <ds> (thanks!), but I'm not quite there yet. Anyone have any idea how to make this work?

Code: [Select]
#include <lib.h>
#include <daemons.h>
#include ROOMS_H

inherit LIB_ROOM;

string checkSeason(string inc);

string checkSeason(string inc){
string tmp;

tmp = "The Forest's Edge Road passes east and west between a fenced yard on the north and a large brick building on the south.";

if( "/daemon/seasons"->GetCurrentSeason() == "winter" ){
tmp += " The yard to the north is filled with vibrant plants in full bloom, despite the season. Outside of the fence, all but the evergreen trees are barren and the plants are withered and brown.";}
if( "/daemon/seasons"->GetCurrentSeason() == "spring" ){
tmp += " The yard to the north is filled with tiny plants in little pots, and more little plants are sprouting from the ground.";}
if( "/daemon/seasons"->GetCurrentSeason() == "summer" ){
tmp += " The yard to the north is a verdant jungle that almost hurts to look at in the bright summer sunlight.";}
if( "/daemon/seasons"->GetCurrentSeason() == "autumn" ){
tmp += " The yard to the north is filled with planting beds that appear to have been recently turned. The smell indicates that they have also been recently fertilized.";}

return tmp;
}
void create() {
    room::create();
    SetAmbientLight(30);
    SetShort("Forest's Edge Road");
    SetNightLong("The Forest's Edge Road passes east and west between a fenced yard on the north and a large brick building on the south. Street lamps holding enchanted balls of light illuminate the area with a soft, cyan-tinted glow.");
    SetDayLong( (: checkSeason :) );
    SetItems(([
        ({ "building", "brick building", "large brick building", "brick" }) : "The large building is made of plain brown bricks and has several windows that face the road. You don't see a door on this side of the building.",
        ({ "fence", "fenced yard", "yard", "north" }) : "A well-kept whitewashed fence surrounds a tidy garden planted behind a small cottage.",
        ({ "cobble", "cobbles", "cobblestones", "road", "street", "cobbled", "cobbled street", "cobbled road", "cobblestone road", "cobblestone street" }) : "The smoothly worn street is paved with irregular, rounded stones that are tightly fitted together.",
      ]));
    SetExits( ([
        "west" : "/domains/medienne/room/main_celm",
        "east" : "/domains/medienne/room/med_forstrd2.c",
      ]) );

    SetClimate("temperate");

}
void init(){
    ::init();
}

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: Checking the season
« Reply #1 on: August 07, 2012, 08:18:55 pm »
You could try doing this:

Code: [Select]
string GetDayLong() {
  string tmp = "The first line. ";

  switch("/daemon/seasons"->GetCurrentSeason()) {
    case "winter":
      tmp += "winter line. ";
    break;

    case "spring":
      tmp += "spring line. ";
    break;

    case "summer":
      tmp += "summer line. ";
    break;

    case "autumn":
      tmp += "autumn line. ";
    break;
  }

  return tmp;
}

I checked and couldn't find any place where GetDayLong()'s value was checked for being a function, only GetLong()'s value. Doing it this way overrides the existing function and hopefully works. Also, switch() is faster for this kind of thing.

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Re: Checking the season
« Reply #2 on: August 08, 2012, 01:57:07 am »
Thanks for the suggestion. Oh yeah, switches! (I haven't written code in a "couple" of years.)

Unfortunately, I couldn't get this to work. I'm not sure how I should go about overriding SetDayLong or GetDayLong. I tried just adding the GetDayLong as written, and I got errors. Getting this to work would help me understand other similar things, so please keep the suggestions coming. Do I have to do something besides adding this to the room file?

Also, please keep in mind that while I took a C++ class in college and I've played around with PHP a fair bit, it's been a while since I actually wrote code. You really can't talk down to me. ;) I am a technical writer, so I will gladly write up anything I learn as task-oriented help files.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: Checking the season
« Reply #3 on: August 08, 2012, 10:46:00 am »
Without seeing the errors, there's not much more I can think of. I tried searching the DS lib to see how it checks this but the very modularity of the code makes it hard to find, and I don't run DS myself. Post some errors (inside code tags: [ code ]   here  [ /code ]) and maybe someone can figure this out.

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: Checking the season
« Reply #4 on: August 09, 2012, 07:17:18 pm »
Ok, here's a quickie set of two basic rooms with a door connecting them which have dynamic descriptions indicating the time of day, season, and open-state of the door.

Paths where they can be put is indicated in the header.

Code itself is hereby declared public domain.

Code: [Select]
/* /domains/examples/room/dynamic_roomA.c
 * 2012-Aug-09 T. Cook
 */
#include <lib.h>
#include <daemons.h>

inherit LIB_ROOM;

string LongDesc();

static void create(){
room::create();
SetShort( "Dynamic-description room A" );
SetLong( (: LongDesc :) );
SetAmbientLight( 30 );
SetExits( ([
"south" : "/domains/examples/room/dynamic_roomB"
]) );
SetDoor( "south", "/domains/examples/doors/example_door" );
}

void init(){
::init();
}

string LongDesc(){
return "This is a room with a dynamically-generated description.  It's a %^YELLOW%^" + SEASONS_D->GetTimeOfDay() +
"%^RESET%^ in %^GREEN%^" + SEASONS_D->GetCurrentSeason() + "%^RESET%^, and has a door which is " +
( find_object( "/domains/examples/doors/example_door" )->GetOpen() == 1 ? "open" : "closed" ) + ".";
}
/* EOF */

Code: [Select]
/* /domains/examples/room/dynamic_roomB.c
 * 2012-Aug-09 T. Cook
 */
#include <lib.h>
#include <daemons.h>

inherit LIB_ROOM;

string LongDesc();

static void create(){
room::create();
SetShort( "Dynamic-description room B" );
SetLong( (: LongDesc :) );
SetAmbientLight( 30 );
SetExits( ([
"north" : "/domains/examples/room/dynamic_roomA"
]) );
SetDoor( "north", "/domains/examples/doors/example_door" );
}

void init(){
::init();
}

string LongDesc(){
return "This is a room with a dynamically-generated description.  It's a %^YELLOW%^" + SEASONS_D->GetTimeOfDay() +
"%^RESET%^ in %^GREEN%^" + SEASONS_D->GetCurrentSeason() + "%^RESET%^, and has a door which is " +
( find_object( "/domains/examples/doors/example_door" )->GetOpen() == 1 ? "open" : "closed" ) + ".";
}
/* EOF */

Code: [Select]
/* /domains/examples/doors/example_door.c
 * 2012-Aug-09 T. Cook
 */
#include <lib.h>

inherit LIB_DOOR;

static void create(){
door::create();
SetSide( "north", ([
"id" : ({ "example door", "door", "north door" }),
"short" : "a door leading into another room",
"long" : "This is a plain door.",
"lockable" : 1
]) );
SetKeys( "north", ({ "master key" }) );
//-----
SetSide( "south", ([
"id" : ({ "example door", "door", "south door" }),
"short" : "a door leading into another room",
"long" : "This is a plain door.",
"lockable" : 1
]) );
SetKeys( "south", ({ "master key" }) );
SetClosed( 1 );
SetLocked( 0 );
}
void init(){ ::init(); }
/* EOF */

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Re: Checking the season
« Reply #5 on: August 09, 2012, 09:18:58 pm »
That works beautifully! Thanks!