Decoded: Rogue (1980) by Toy, Arnold, Wichman
DOS version (1983) by Mel Sibony and Jon Lane
Source file: SLIME.C
Beginner friendly, line-by-line code walkthrough by MaiZure

SLIME.C provides special abilities for the slime monster

Original code:
https://britzl.github.io/roguearchive/

Original code with line numbers
http://www.maizure.org/projects/decoded-rogue/SLIME_linenum.txt



1     COMMENT
2     COMMENT
3     COMMENT
4     COMMENT
5     COMMENT
6     BLANK
7     Include game header
8     Include console management header
9     BLANK
10    COMMENT
11    COMMENT
12    COMMENT
13    COMMENT
14    BLANK
15    Declare global coordinates for slime splitting
16    BLANK

SLIMES CAN SPLIT

17    Declares slime_split with one argument
18    Argument 1 is the pointer to the parent slime
19    BLOCK START - split_slime, attempts to split a slime
20    Declare a pointer to the new slime
21    BLANK
22    If the slime fails to split or the new slime can't be allocated...
23    Return failure
24    Otherwise...send a success message to the status bar
25    Initialize the new slime
26    If the player can see the slime...
27    The new slime needs to buffer it's floor location
28    Add the slime's symbol to the map
29    End check for slime visiblity
30    Bring the new slime to life!
31    BLOCK END - split_slime
32    BLANK

CREATE A NEW SLIME FROM PARENT

33    Define new_slime with one argument
34    Argument one is the pointer to the slime
35    BLOCK START - new_slime, creates a new slime from the parent
36    Declare temporary position variables and a return value
37    Declare a pointer to the new slime
38    Declare a coordinate pair
39    BLANK
40    Assume return failure for now
41    Set the parent to flying
42    If we are unable to place the new slime next to the parent...
43    COMMENT
44    COMMENT
45    COMMENT
46    COMMENT
47    Loop through the rows around the parent
48    Loop through the columns around the parenty
49    If there is a slime at the searched coordinates, grab it
50    If it's already flying then we've attempted this already
51    Skip this slime
52    Otherwise, this slime hasn't attempted to split, do it (Recursive!)
53    Set the outer loop to die
54    Set the inner loop to die
55    End check slime split
56    End check for slime search
57    Otherwise, we were able to place the new slime successfully...
58    Set return success
59    Save the new coordinates to the global for now
60    End check for placing new slime
61    Remove the flying flag from the parent
62    Return success or failure
63    BLOCK END - new_slime
64    BLANK

PLACE THE NEW SLIME

65    Declare plot_monster with three arguments
66    Arguments 1 and 2 are position variables for row and column
67    Argument 3 is a pointer to coordinates
68    BLOCK START - plop_monster, places the newly created slime
69    Declare position iterators for the upcoming loop
70    Declare a return value for success
71    Declare a character
72    BLANK
73    Loop around the input area by rows
74    Loop around the input area by columns
75    COMMENT
76    COMMENT
77    COMMENT
78    If the player happens to be here or the position off the map...
79    Skip this iteration
80    COMMENT
81    COMMENT
82    COMMENT
83    If the position is passable...
84    But if there is a scroll of scare monsters..
85    Skip the location
86    Count the success and...
87    Save the new slime's y coordinate
88    Save the new slime's x coordinate
89    End return slime
90    End check for valid position
91    End column inner loop
92    End row outer loop
93    BLOCK END - plop_monster
94    EOF