+ int tape_action = map_key_SP_to_RND(demo_action);
+ int tape_repeat = demo_repeat + 1;
+ int tape_entries = 1; // one new tape entry may be added
+
+ if (tape.length + tape_entries >= MAX_TAPE_LEN)
+ {
+ Error(ERR_WARN, "SP demo truncated: size exceeds maximum tape size %d",
+ MAX_TAPE_LEN);
+
+ break;
+ }
+
+ if (tape.pos[tape.length].delay > 0) /* already stored action */
+ {
+ if (tape.pos[tape.length].action[0] != tape_action ||
+ tape.pos[tape.length].delay + tape_repeat >= 256)
+ {
+ tape.length++;
+ tape.pos[tape.length].delay = 0;
+ }
+ else
+ {
+ tape.pos[tape.length].delay += tape_repeat;
+ }
+ }