Game::Xomb - a game featuring @ versus the Xarci Bedo
Xomb is a terminal-based roguelike. Assuming that the development tools (C99 support is required), perl(1), App::cpanminus, and optionally local::lib are installed and setup in a suitable terminal install and run the game via:
cpanm Game::Xomb xomb
Use the ? key in game to show the help text. The xomb documentation details other useful game information; it should be available once the module is installed via:
?
perldoc xomb
The remainder of this documentation concerns internal details likely only of interest to someone who wants to modify the source code.
The game is data oriented in design; adding a new floor tile would require a new SPECIES constant, suitable entries in %Thingy, %Descript, and @Level_Features, and then any additional code for passive effects or whatever. Various routines may need adjustment for a new floor type as there is not a good component system to indicate whether a floor tile is solid, dangerous, etc. A new monster would require similar additions, and would need a custom update_* function for when that critter has an action to make.
SPECIES
%Thingy
%Descript
@Level_Features
Only the player can move, so much of the code assumes that. New player actions would need to be added to %Key_Commands and suitable code added to carry out the new action.
%Key_Commands
All entropy comes from the JSF random number generator (see src/jsf.c). The perl built-in rand function MUST NOT be used; instead use irand, roll, or one of the other utility functions that call into the JSF code.
src/jsf.c
rand
There are tests for some of the code, see the t directory in the module's distribution.
t
Called by the movement code to determine whether the run should be aborted, e.g. before the player steps to a pool of acid. $Sticky indicates whether a run is in progress, and runs are caused by the move_player_runner or move_player_snooze functions, see %Key_Commands.
$Sticky
Removes hitpoints from the given animate, with complications to report the damage and to mark the game as over (for the player) or otherwise the monster as dead. Calls over to %Damage_From table entries which return the damage as appropriate for the arguments.
%Damage_From
These routines move the cursor around the terminal. at takes arguments in col,row (x,y) form.
Floor tiles can have passive effects that can vary depending on the duration the player is within the cell, or could be a message to the player. See passive_burn, passive_msg_maker.
Waits for the player to quit usually from a submenu. $RKFN holds the function that read keys; these could either come from STDIN or from a save game file.
$RKFN
STDIN
Indicates whether a terminal exists and is of suitable dimensions.
Called when something goes horribly wrong, usually on fatal signal or internal error.
Like clamp from the Common LISP Alexandria library.
clamp
Calls the callback function with pairs of items from the given list of items.
Returns 0 or 1. Uses the JSF random number generator (see src/jsf.c).
0
1
Returns a string usually shown in the status bar consisting of the VEGGIE (item, if any) and MINERAL (floor tile) of the cell the player is in.
VEGGIE
MINERAL
Returns a string that prints the player's shield points in the status bar.
Returns a string that prints whether and if so what VEGGIE is being used to regenerate the shield.
Pythagorean distance between two cells, with rounding. Will differ in some cases from the Chebyshev distance that the linecb and walkcb line functions use for an iterations count.
Whether or not the given weapon hits at the given distance, and what the cost of that move was. The cost will be higher if the target is out of range so that the animate will not wake up until the player can be in range.
Removes a random element from the given array reference and returns it. Uses the JSF random number generator (see src/jsf.c).
Note that the original order of the array reference will not be preserved. If that order is important, do not use this call. Order preserving extraction can be done with:
... = splice @array, irand(scalar @array), 1;
Shuffles an array reference in place. Uses the JSF random number generator (see src/jsf.c).
Entry point to the game, see bin/xomb for how this gets called and what needs to be setup before that. Loops using a simple integer based energy system over active animates and calls the update function for each on that gets a go, plus some complications to change the level, etc.
bin/xomb
Called when the game needs to exit for various reasons mostly unrelated to gameplay (terminal size too small, fatal signal).
Generates a level map around where the player is. Various knobs can be found in @Level_Features.
Reads a key from the terminal until one in the hash of valid choices is entered. See also $RKFN.
Whether the player is carrying (or has equiped) the Amulet.
Exits game with death screen and score.
Exits game with win screen and score. Should be the only 0 exit status of the game.
In game information on keyboard command available
Sets the seed for the JSF random number generator (see src/jsf.c).
Initial setup of the @LMap. This is in row,col form though points use the col,row form. Each cell (LMC) has WHERE, MINERAL, VEGGIE, and ANIMAL slots that contain a col,row point for the cell, the floor tile, item (if any), and animate (if any).
@LMap
LMC
WHERE
ANIMAL
Integer random value between 0 and max - 1. Uses the JSF random number generator (see src/jsf.c).
max - 1
Bresenham line function with some features to keep it from going off of the map and to skip the first point and to abort should the callback return -1.
-1
Used to bold -> normal -> faint cycle log the most recent message (shown at the top of the screen) depending on the age of the message.
Adds a message to the log and displays it at the top of the screen.
Returns the value of the loot the player is carrying.
Creates the amulet and returns it.
Creates a gem and returns it.
Creates a monster and returns it. Suitable parameters must be supplied.
Creates the player, places them into the HERO slot of the @Animates array, and returns the col,row starting position of the player. generate_map builds the level map around this position.
HERO
@Animates
A far too complicated routine to inspect, drop, or equip items in the inventory list.
Moves the player around the level map, with various game related complications. See %Key_Commands and move_player_maker.
Drops an item from the inventory.
Equips an item from the inventory.
Lets the player move the cursor around the level map to inspect various features.
For when the player climbs down the "stairs".
For when the player tries to climb up the "stairs".
For when the player rests for a turn.
Picks an item (if any) up off of the level map.
Creates a function suitable for moving the player in a particular direction. See %Key_Commands.
Creates a function suitable for running the player in a particular direction.
Creates a function suitable for resting with over multiple turns.
Prompts whether they want to quit the game.
Unequips an item (if any).
Query the player whether they want to carry out some dangerous move.
Returns true if the RNG rolls 0 within max. Uses the JSF random number generator (see src/jsf.c).
Apply acid damage because the player is in a pool of acid.
Returns a subroutine that issues a message when a cell is entered into. The cell should probably be made unique with reify first as otherwise all floor tiles of that type will share the same update routine.
Ensures that a path exists between the given coordinates and the given list of points; used by generate_map to ensure that the player can reach all the gates and gems.
Picks a random item from the given array reference. Uses the JSF random number generator (see src/jsf.c).
Clears the PKC error code from the status bar.
Prints a PKC error code in the status bar.
Used by generate_map to place floor tiles somewhat randomly (brown noise) around the level map, as controlled by @Level_Features counts.
Creates and places a monster onto the level map, and that the monster has not been placed above a hole or in acid.
Displays and applies splash damage from Fungi attacks.
Calculates the FOV for the player and updates various related variables such as what monsters are visible.
Reduces a map cell floor tile to RUBBLE. Some monsters can destroy walls.
RUBBLE
Redraw the level map, status bar, and previous message if any.
Marks a particular level map item (MINERAL, typically) as unique, usually so that a passive_msg_maker can be applied to it.
Handles moving the player from one level map cell to another.
Replays commands from a save game file. See also $RKFN.
Logs a message showing where the player is on the level map.
Logs a message with the game version, seed, and current turn number.
Gets the terminal out of raw mode and more back to normal.
Dice rolling, so 3d6 would be roll(3,6). Uses the JSF random number generator (see src/jsf.c).
3d6
roll(3,6)
Slow the player down when they move in (or into, or out of) rubble.
Update the energy cost of the last move.
Returns a string with the game score in it.
Show all the recent messages in the message log.
Prints the status bar at the bottom of the screen.
Prints the most recent log message at the top of the screen.
UPDATE function for fungi.
UPDATE
Custom UPDATE function for when the player is dead.
UPDATE function for ghast.
UPDATE function for mimics.
UPDATE function for the player. Failed moves (zero-cost things) are looped over until a move that costs energy is made. Input comes from the $RKFN which is usually a function that reads from standard input.
UPDATE function for stalkers.
UPDATE function for trolls.
Uses an item, possibly swapping it with some existing item.
Returns a string with the name and value of a vegetable (a gem, or the amulet).
Like linecb but continues until the edge of the level map or until the callback function returns -1.
Runs the callback function for each cell adjacent to the given coordinates that is within the level map.
HP 100 You plunge into the hole. HP -140314714594444
'tis but a flesh wound.
https://thrig.me/src/Game-Xomb.git
Game::PlatformsOfPeril from which this code evolved.
7DRL 2020 - https://itch.io/jam/7drl-challenge-2020
Vektor - Terminal Redux
Jeremy Mates
Copyright (C) 2020 by Jeremy Mates
This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause
The src directory code appears to be under a "I wrote this PRNG. I place it in the public domain." license:
src
http://burtleburtle.net/bob/rand/smallprng.html
To install Game::Xomb, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::Xomb
CPAN shell
perl -MCPAN -e shell install Game::Xomb
For more information on module installation, please visit the detailed CPAN module installation guide.