-struct Map init_map () {
-// Initialize map with some experimental start values.
- struct Map map;
- map.width = 64;
- map.height = 64;
- map.offset_x = 0;
- map.offset_y = 0;
- uint32_t size = map.width * map.height;
- map.cells = malloc(size);
- uint16_t y, x;
- for (y = 0; y < map.height; y++)
- for (x = 0; x < map.width; x++)
- map.cells[(y * map.width) + x] = '~';
- map.cells[size / 2 + (map.width / 2)] = '.';
- uint32_t repeats, root, curpos;
- for (root = 0; root * root * root < size; root++);
- for (repeats = 0; repeats < size * root; repeats++) {
- y = rrand(0, 0) % map.height;
- x = rrand(0, 0) % map.width;
- curpos = y * map.width + x;
- if ('~' == map.cells[curpos] &&
- ( (curpos >= map.width && '.' == map.cells[curpos - map.width])
- || (curpos < map.width * (map.height-1) && '.' == map.cells[curpos + map.width])
- || (curpos > 0 && curpos % map.width != 0 && '.' == map.cells[curpos-1])
- || (curpos < (map.width * map.height) && (curpos+1) % map.width != 0 && '.' == map.cells[curpos+1])))
- map.cells[y * map.width + x] = '.'; }
- return map; }
-
-void save_game(struct World * world) {
-// Save game data to game file.
- FILE * file = fopen("savefile", "w");
- write_uint32_bigendian(world->seed, file);
- write_uint32_bigendian(world->turn, file);
- write_uint16_bigendian(world->player->pos.y, file);
- write_uint16_bigendian(world->player->pos.x, file);
- write_uint16_bigendian(world->monster->pos.y, file);
- write_uint16_bigendian(world->monster->pos.x, file);
- write_uint16_bigendian(world->monster->next->pos.y, file);
- write_uint16_bigendian(world->monster->next->pos.x, file);
- write_uint16_bigendian(world->monster->next->next->pos.y, file);
- write_uint16_bigendian(world->monster->next->next->pos.x, file);
- fclose(file); }
-
-void record_action (char action) {
-// Append action to game record file.
- FILE * file = fopen("record", "a");
- fputc(action, file);
- fclose(file); }
-
-struct yx_uint16 mv_yx_in_dir (char d, struct yx_uint16 yx) {
-// Return yx coordinates one step to the direction d of yx.
- if (d == NORTH) yx.y--;
- else if (d == EAST) yx.x++;
- else if (d == SOUTH) yx.y++;
- else if (d == WEST) yx.x--;
- return yx; }
-
-void next_turn (struct World * world) {
-// Increment turn and move enemy.
- world->turn++;
- rrand(1, world->seed * world->turn);
- char d;
- struct Monster * monster;
- for (monster = world->monster; monster != 0; monster = monster->next) {
- d = rrand(0, 0) % 5;
- struct yx_uint16 t = mv_yx_in_dir (d, monster->pos);
- if (yx_uint16_cmp(t, world->player->pos))
- update_log(world, "\nThe monster hits you.");
- else if (is_passable(world->map, t.y, t.x))
- monster->pos = t; } }
-