Skip to content

Commit

Permalink
Merged PR 492: Merge 597_decaying_light_source to master
Browse files Browse the repository at this point in the history
Related work items: #597
  • Loading branch information
Allen B. Cummings committed Apr 25, 2019
1 parent 7e0eb2d commit 2d78ee6
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 7 deletions.
46 changes: 40 additions & 6 deletions environment/environmentalElement.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ protected int displayEntryMessage()
return 0;
}

/////////////////////////////////////////////////////////////////////////////
protected string getDescriptionFromSet()
{
return (member(descriptionData[State], "active light template") ?
descriptionData[State]["active light template"] : "");
}

/////////////////////////////////////////////////////////////////////////////
protected nomask varargs string parseTemplate(string template, mapping data,
int illuminationLevel)
Expand All @@ -184,6 +191,13 @@ protected nomask varargs string parseTemplate(string template, mapping data,
{
ret = parseEntryAction(ret, data);
}

if (sizeof(regexp(({ template }), "##UseDescriptionSet##")))
{
ret = regreplace(ret, "##UseDescriptionSet##",
getDescriptionFromSet(), 1);
}

ret = parseAdjectives(ret, data, illuminationLevel);
return ret;
}
Expand Down Expand Up @@ -227,7 +241,7 @@ public nomask int lightSourceIsActive(string state, object environment)
member(descriptionData, "active light sources") &&
member(descriptionData["active light sources"], environment))
{
ret = descriptionData["active light sources"][environment];
ret = descriptionData["active light sources"][environment]["magnitude"];
}
return ret;
}
Expand Down Expand Up @@ -266,10 +280,19 @@ public nomask nomask int canActivateLightSource(string state)

/////////////////////////////////////////////////////////////////////////////
protected nomask string getSourceOfLightTemplate(string state,
int illuminationLevel)
int illuminationLevel, object environment)
{
string descriptionTemplate =
descriptionData[state][getTemplateKey(illuminationLevel)];

if (member(descriptionData, "active light sources") &&
member(descriptionData["active light sources"], environment))
{
descriptionTemplate =
descriptionData["active light sources"][environment]["template"];
}
return canActivateLightSource(state) ?
parseTemplate(descriptionData[state]["active light template"],
parseTemplate(descriptionTemplate,
descriptionData[state], illuminationLevel) : 0;
}

Expand All @@ -290,8 +313,19 @@ public nomask void activateLightSource(string state, object environment)
{
descriptionData["active light sources"] = ([]);
}
descriptionData["active light sources"][environment] =
if (!member(descriptionData["active light sources"], environment))
{
descriptionData["active light sources"][environment] = ([]);
}
descriptionData["active light sources"][environment]["magnitude"] =
processLightSourceActivation(state, environment);

if (!member(descriptionData["active light sources"][environment],
"template"))
{
descriptionData["active light sources"][environment]["template"] =
descriptionData[state]["active light template"];
}
}
}

Expand All @@ -318,7 +352,7 @@ public nomask varargs string description(string state, int illuminationLevel,
if (isSourceOfLight(state, environment) && canActivateLightSource(state) &&
lightSourceIsActive(state, environment))
{
ret = getSourceOfLightTemplate(state, illuminationLevel);
ret = getSourceOfLightTemplate(state, illuminationLevel, environment);
}
else
{
Expand Down Expand Up @@ -373,7 +407,7 @@ public nomask string long(int brief)
raise_error(sprintf("ERROR in baseFeature.c: The item details for "
"the %s state does not exist.\n", state));
}
return ret;
return format(ret, 78);
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
81 changes: 81 additions & 0 deletions environment/items/baseFire.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//*****************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/environment/items/baseItem.c";

private int currentFireState;
private string *fireDescriptions = ({});

/////////////////////////////////////////////////////////////////////////////
protected nomask varargs void addFireDescriptions(string *descriptions)
{
if (pointerp(descriptions) && sizeof(descriptions) &&
stringp(descriptions[0]))
{
fireDescriptions = descriptions + ({});
}
else
{
raise_error("ERROR in baseFire.c: The fire descriptions "
"must be an array of strings.\n");
}
}

/////////////////////////////////////////////////////////////////////////////
public void decayFire(string state, object environment)
{
remove_call_out("decayFire");

if (lightSourceIsActive(state, environment))
{
if (currentFireState <= 1)
{
deactivateLightSource(state, environment);
currentFireState = 0;
}
else
{
currentFireState--;

descriptionData["active light sources"][environment]["template"] =
fireDescriptions[currentFireState];
descriptionData["active light sources"][environment]["magnitude"] =
currentFireState;

call_out("decayFire", 150, state, environment);
}
}
}

/////////////////////////////////////////////////////////////////////////////
protected int processLightSourceActivation(string state, object environment)
{
currentFireState = 0;
if (canActivateLightSource(state) && sizeof(fireDescriptions) > 1)
{
currentFireState = sizeof(fireDescriptions) - 1;

descriptionData["active light sources"][environment]["template"] =
fireDescriptions[currentFireState];

call_out("decayFire", 150, state, environment);
}
return currentFireState;
}


/////////////////////////////////////////////////////////////////////////////
protected string getDescriptionFromSet()
{
object environment = ((member(inherit_list(previous_object()),
"lib/environments/environment.c") > -1) || !this_player()) ?
previous_object() :
environment(this_player());

return capitalize(
(member(descriptionData, "active light sources") &&
member(descriptionData["active light sources"], environment)) ?
descriptionData["active light sources"][environment]["template"] :
getSourceOfLightTemplate(State, currentFireState, environment));
}
42 changes: 42 additions & 0 deletions environment/items/camp-fire.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//*****************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/environment/items/baseFire.c";

/////////////////////////////////////////////////////////////////////////////
public void Setup()
{
Name("camp fire");
addAlias("fire");
addAlias("campfire");
suppressEntryMessage();

addDescriptionTemplate("there are charred cinders and the ashen remains "
"of a small campfire");
addActiveSourceOfLight(8, "flickering tendrils of flame roil out from the "
"newly-added logs of a small camp fire");

addFireDescriptions(({
"there are charred cinders and the ashen remains of a small campfire",
"faint light emanates from the ashen embers of a small camp fire",
"occasional flickers of red flame emanate from the faintly glowing red "
"coals of a small camp fire",
"faint flickers of red flame emanate from the nearly-spent logs of a "
"small camp fire, its red coals feverishly glowing",
"hisses come from the low flames of a small camp fire, its bed of coals "
"hues of red, orange, and blue",
"flames greedily wrap around the charred logs of a "
"small camp fire, its bed of coals brilliant yellow and blue",
"flames greedily ascend from a small camp fire that "
"hisses and pops as water vapor escapes the logs it is consuming",
"flickering tendrils of flame roil out from the slightly-charred logs of a "
"small camp fire",
"flickering tendrils of flame roil out from the newly-added logs of a "
"small camp fire"
}));

addItemTemplate("the area around the campfire has been cleared away to "
"place a barrier between the fire and other combustible objects. "
"##UseDescriptionSet##");
}
67 changes: 67 additions & 0 deletions tests/environment/elementLightTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,70 @@ void ActiveAndInactiveLightSourcesCorrectlyDisplayed()
ExpectEq(0, Element->lightSourceIsActive("default", this_object()));
ExpectEq(5, Element->isSourceOfLight("default", this_object()));
}

/////////////////////////////////////////////////////////////////////////////
void CanSetActiveDecayingLighting()
{
destruct(Element);
Element = clone_object("/lib/environment/items/camp-fire.c");

ExpectEq("there are charred cinders and the ashen remains of a small "
"campfire",
Element->description("default", 1, this_object()));

Element->activateLightSource("default", this_object());

ExpectEq("flickering tendrils of flame roil out from the newly-added "
"logs of a small camp fire",
Element->description("default", 1, this_object()));
ExpectEq(8, Element->lightSourceIsActive("default", this_object()));
ExpectEq(8, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq("flickering tendrils of flame roil out from the slightly-"
"charred logs of a small camp fire",
Element->description("default", 1, this_object()));
ExpectEq(7, Element->lightSourceIsActive("default", this_object()));
ExpectEq(7, Element->isSourceOfLight("default", this_object()));
}

/////////////////////////////////////////////////////////////////////////////
void ActiveDecayingLightingWillResetToNoLight()
{
destruct(Element);
Element = clone_object("/lib/environment/items/camp-fire.c");

ExpectEq("there are charred cinders and the ashen remains of a small "
"campfire",
Element->description("default", 1, this_object()));

Element->activateLightSource("default", this_object());
ExpectEq(8, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(7, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(6, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(5, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(4, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(3, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(2, Element->isSourceOfLight("default", this_object()));
ExpectEq("occasional flickers of red flame emanate from the faintly "
"glowing red coals of a small camp fire",
Element->description("default", 1, this_object()));

Element->decayFire("default", this_object());
ExpectEq(1, Element->isSourceOfLight("default", this_object()));

Element->decayFire("default", this_object());
ExpectEq(0, Element->isSourceOfLight("default", this_object()));
}
Loading

0 comments on commit 2d78ee6

Please sign in to comment.