Weekly Update – January 30, 2021

I think at least 90% of the time I don’t end up doing what I say I’m going to do the previous week. That was the case again this week.

I added a bunch of content – new room types (treasure room, potion room, barrel room, shrine room, fountain room), new objects (fountains, shrines, barrels, cave decor), and a few new items (gold ring, gold crown, silver – all for the treasure room).

I created a couple of new classes to handle object placement, because object placement code was all over the place – placing objects along a room perimeter, a particular side, corners, center, etc. One of the new classes gets a list of cells corresponding to some location specification (like all room corners). The other new class does the actual object placement and applies rules to ensure that objects are not placed in problematic locations.

Finally, I created a weighted randomizer class. This is super handy for random lookup tables, which were becoming a pain to maintain because I originally implemented them using a series of if-then-else if statements. For example, if a random weapon is going to be dropped, before I had something like:


if (r >= 1 && r < 4) item = shortSword
else if (r >= 4 && r < 7) item = longSword
else if (r >= 7 && r < 8) item = battleAxe

There are a few problems with this approach. First, it’s hard to read. Second, it’s easy to make mistakes. Third, it’s a pain to add a new outcome because the entire distribution has to be changed. 

The weighted randomizer works like this:

weightedRandomizer.Add(shortSword, 4)
weightedRandomizer.Add(longSword, 3)
weightedRandomizer.Add(battleAxe, 2)
item = weightedRandomizer.GetValue()

This is much easier to read, and it’s much easier to add new outcomes.

I still need to get the [2021 in RoguelikeDev] post out in the next couple of days. After that, I’ll try to make a dent in the bug list, which I’ve been neglecting for a while.





Leave a Reply

Your email address will not be published. Required fields are marked *