MCPcopy Create free account
hub / github.com/NetHack/NetHack / shuffle

Function shuffle

src/o_init.c:112–148  ·  view source on GitHub ↗

shuffle descriptions on objects o_low to o_high */

Source from the content-addressed store, hash-verified

110
111/* shuffle descriptions on objects o_low to o_high */
112staticfn void
113shuffle(int o_low, int o_high, boolean domaterial)
114{
115 int i, j, num_to_shuffle;
116 short sw;
117 int color;
118
119 for (num_to_shuffle = 0, j = o_low; j <= o_high; j++)
120 if (!objects[j].oc_name_known)
121 num_to_shuffle++;
122 if (num_to_shuffle < 2)
123 return;
124
125 for (j = o_low; j <= o_high; j++) {
126 if (objects[j].oc_name_known)
127 continue;
128 do
129 i = j + rn2(o_high - j + 1);
130 while (objects[i].oc_name_known);
131 sw = objects[j].oc_descr_idx;
132 objects[j].oc_descr_idx = objects[i].oc_descr_idx;
133 objects[i].oc_descr_idx = sw;
134 sw = objects[j].oc_tough;
135 objects[j].oc_tough = objects[i].oc_tough;
136 objects[i].oc_tough = sw;
137 color = objects[j].oc_color;
138 objects[j].oc_color = objects[i].oc_color;
139 objects[i].oc_color = color;
140
141 /* shuffle material */
142 if (domaterial) {
143 sw = objects[j].oc_material;
144 objects[j].oc_material = objects[i].oc_material;
145 objects[i].oc_material = sw;
146 }
147 }
148}
149
150void
151init_objects(void)

Callers 1

shuffle_allFunction · 0.85

Calls 1

rn2Function · 0.85

Tested by

no test coverage detected