Sunday, March 5, 2017

Ploxel engine working

After some debugging difficulties, I think I have a workable ploxel engine constructed.  It currently has three ploxels, one with only a plug, one with only a socket, and one with a plug and a socket that match the sockets and plugs of the other two.

The engine successfully finds and connects them into a chain.  For instance, if I start with these three ploxels in the "open" list:

{
id = "Cthulhu",
name = "Cthulhu",
ilk = "enemy",
description = "Cthulhu lies dreaming, and must be defeated.",
describe = function(self)
 print( "Connection = " .. self.plugs[1].connection )
 return self.description .. "  He sleeps in " ..
  mystery:ploxel( self.plugs[1].connection ):describe()
end,
plugs = { "lair" }
}

{
id = "R'Lyeh",
name = "R'Lyeh",
ilk = "middle",
description = "the sunken city of R'Lyeh",
describe = function(self)
 return self.description .. ", which can only be reached by means of " ..
  mystery:ploxel( self.plugs[1].connection ):describe()
end,
plugs = { "gate" },
sockets = { "lair" }
}

{
id = "Passage",
name = "Passage",
ilk = "trivial",
map = "maps/manor.lua",
description = "a passage to another world",
describe = function(self)
 return self.description .. ""
end,
plugs = {},
sockets = { "gate" }
}

Then, when the mystery is generated and describe() called on the topmost enemy ploxel, it will spit out Cthulhu lies dreaming, and must be defeated.  He sleeps in the sunken city of R'Lyeh, which can only be reached by means of a passage to another world.

So the engine is successfully starting with a "big bad" and connecting ploxels to it to flesh out the mystery, based on the character of plugs and sockets.  A "plug" is an "aspect of this thing that I will need to generate something for."  A "socket" is an "aspect of this thing that can fulfill a requirement for another ploxel".  In the above example, Cthulhu has a "lair" plug, because it needs to find a "lair" socket on some other ploxel to connect to.  R'Lyeh has a lair socket, because it can act as a lair to a big bad.  Thus, they can be connected, giving Cthulhu a lair.  But the lair itself has requirements of its own; a gate to that mysterious location is needed, so a gate plug is created for it.  Eventually, the plug finds the matching socket in the passage, and the gate to R'Lyeh is established.

It took a bit of doing to allow the ploxels to "play nice" with things like functions in the ploxel objects.  I wanted to be able to serialize the mystery structure without having to save all the ploxel data in the save file (especially difficult-to-serialize things like functions).

My goal for tomorrow is to get maps generating in a way that is informed by the ploxel representing the map in the mystery.

No comments:

Post a Comment