void init_world(void) { int x, y; cform * f; world.zones = malloc(sizeof(zone *)); load_iforms(); load_cforms(); *world.zones = zone_new(500, 300); f = cform_new('@' | A_BOLD); f->weight = TILE_MAX_WEIGHT / 2; f->max_health = 10; crtr_init(&world.plyr, f); world.plyr.nofree = 1; world.plyr.inv = inv_new(500); world.plyr.attack = 5; do { x = random() % get_dispw(); y = random() % get_disph(); } while (!crtr_tele(&world.plyr, x, y, *world.zones)); zone_update(world.plyr.z, x, y); }
int crtr_move(creature * crtr, int dx, int dy) { int ox = crtr->x; int oy = crtr->y; int nx = ox + dx; int ny = oy + dy; return crtr_tele(crtr, nx, ny, crtr->z); }
void plyr_act_enter(int argc, char ** argv) { int ox, oy; zone * oz; tile * t = tileof(&PLYR); if (t->linked) { // TODO generalize if (t->link_z == NULL) { ox = PLYR.x; oy = PLYR.y; oz = PLYR.z; // generate new zone vector_append(&world.zones, zone_new(150, 50)); // TODO why 150,50? t->link_z = world.zones.arr[world.zones.cnt - 1]; // place player randomly crtr_spawn(&PLYR, t->link_z); t->link_x = PLYR.x; t->link_y = PLYR.y; // link back t = tileof(&PLYR); t->linked = 1; t->link_x = ox; t->link_y = oy; t->link_z = oz; t->ch = '@'; t->show_ch = '@'; } else { if (!crtr_tele(&PLYR, t->link_x, t->link_y, t->link_z)) { memo("Your way appears to be blocked?"); } } update_vis(); zone_draw(PLYR.z); } else { memo("I see no visible method of doing that."); } }
// this function is really ugly static void generate(zone * z) { static int first = 1; int i, x, y, max; int rc; int ** walls; room * rv; item * it; creature * cr; if (first) { fill_walls(); first = 0; } // generate rooms rc = random() % ((z->width * z->height) / ROOM_INFREQ) + ROOM_MIN; rv = malloc(sizeof(room) * rc); for (i = 0; i < rc; i++) { rv[i].w = random() % 12 + 5; rv[i].h = random() % 8 + 3; rv[i].x = random() % (z->width - rv[i].w - 1) + 1; rv[i].y = random() % (z->height - rv[i].h - 1) + 1; } // cut out rooms walls = malloc(sizeof(int *) * z->width); for (x = 0; x < z->width; x++) { walls[x] = malloc(sizeof(int) * z->height); for (y = 0; y < z->height; y++) { for (i = 0; i < rc; i++) { if (in_room(rv + i, x, y)) break; } z->tiles[x][y].ch = '.'; walls[x][y] = (i == rc); } } // draw walls for (x = 0; x < z->width; x++) { for (y = 0; y < z->height; y++) { if (walls[x][y]) { z->tiles[x][y].impassible = 1; set_wall_char(walls,z,x,y); } } } // place some random junk if (world.iform_cnt != 0) { max = random() % (z->width * z->height / ITEM_INFREQ) + ITEM_MIN; for (i = max; i >= 0; i--) { it = item_new(world.iforms[random() % world.iform_cnt]); do { x = random() % z->width; y = random() % z->height; } while (z->tiles[x][y].impassible || !inv_try(z->tiles[x][y].inv, it)); item_tele(it, x, y, z); zone_update(z, x, y); } } // place some more random junk if (world.cform_cnt != 0) { max = random() % (z->width * z->height / CRTR_INFREQ) + CRTR_MIN; for (i = max; i >= 0; i--) { cr = crtr_new(world.cforms[random() % world.cform_cnt]); do { x = random() % z->width; y = random() % z->height; } while (z->tiles[x][y].impassible || z->tiles[x][y].crtr != NULL); crtr_tele(cr, x, y, z); zone_update(z, x, y); } } }