示例#1
0
文件: world.c 项目: cmr/iiag
//
// Performs the first initialization of the world
// Will call assure_world if it has yet to be called
//
void init_world(void) {
	zone * z;

	assure_world();

	z = zone_new(150, 50);
	vector_append(&world.zones, z);

	world.plyr.on_death.c_func    = (trigger_cfunc)plyr_ev_death;
	world.plyr.on_lvlup.c_func    = (trigger_cfunc)plyr_ev_lvlup;
	world.plyr.on_act_comp.c_func = (trigger_cfunc)plyr_ev_act_comp;
	world.plyr.on_act_fail.c_func = (trigger_cfunc)plyr_ev_act_fail;
	world.plyr.refs = NOFREE;

	crtr_spawn(&world.plyr, z);
	zone_update(z, world.plyr.x, world.plyr.y);
}
示例#2
0
文件: player.c 项目: cmr/iiag
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.");
	}
}
示例#3
0
文件: zone.c 项目: Grissess/iiag
// this function is really ugly
static void generate(zone * z)
{
	static int first = 1;

	int i, x, y, max, timeout;
	int rc;
	int ** walls;
	room * rv;
	item * it;
	creature * cr;

	if (first) {
		fill_walls();
		first = 0;
	}

	z->name = place_name(world.eth);

	// 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 = '.';
			z->tiles[x][y].show_ch = '.';
			z->tiles[x][y].linked = 0;
			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
	max = random() % (z->width * z->height / ITEM_INFREQ) + ITEM_MIN;
	for (i = max; i >= 0; i--) {
		it = gen_item(world.gitems, 1);

		timeout = 1000;
		do {
			x = random() % z->width;
			y = random() % z->height;
			timeout--;
		} while ((z->tiles[x][y].impassible || !inv_try(z->tiles[x][y].inv, it)) && timeout);

		if (timeout) {
			item_tele(it, x, y, z);
			zone_update(z, x, y);
		} else {
			item_free(it);
		}
	}

	// place some more random junk
	if (!config.all_alone) {
		max = random() % (z->width * z->height / CRTR_INFREQ) + CRTR_MIN;
		for (i = max; i >= 0; i--) {
			cr = gen_crtr(world.gcrtrs, 1);
			crtr_spawn(cr, z);
			zone_update(z, cr->x, cr->y);
		}
	}

	// place random zone jumpers
	for (i = 0; i < 4; i++) {
		do {
			x = random() % z->width;
			y = random() % z->height;
			timeout--;
		} while (z->tiles[x][y].impassible);

		z->tiles[x][y].linked = 1;
		z->tiles[x][y].link_z = NULL;
		z->tiles[x][y].ch = '@';
		z->tiles[x][y].show_ch = '@';
	}

	// cleanup
	for (x = 0; x < z->width; x++) free(walls[x]);
	free(walls);
	free(rv);
}
示例#4
0
文件: zone.c 项目: fshemsing/iiag
// this function is really ugly
static void generate(zone * z)
{
	static int first = 1;

	int i, x, y, max, timeout;
	int wall;
	int x1,x2,y1,y2;
	int rc;
	room ** rooms;
	item * it;
	creature * cr;

	if (first) {
		fill_walls();
		first = 0;
	}

	z->name = place_name(world.eth);

	rc = random() % ((z->width * z->height) / ROOM_INFREQ) + ROOM_MIN;
	rooms = malloc(sizeof(room*) * rc);

	//make everything walls!
	for (x = 0; x < z->width; x++) {
	for (y = 0; y < z->height; y++) {
		z->tiles[x][y].impassible = 1;
	}
	}

	//gen rooms and cut out
	for(i=0; i< rc; i++){
		rooms[i]=gen_room(world.grooms,1);
		build_room(z,rooms[i]);
	}

	//make sure rooms are connected!
	//connect each room to one other room

	for(i=0; i< rc; i++){
		max = random() % rc;
		room_spot(z,rooms[i],&x1,&y1);
		room_spot(z,rooms[max],&x2,&y2);
		wall=0;

		if(x1 == -1 || x2 == -1){
			warning("Room generation timed out!");
			break;
		}

		for(;x1 != x2; x1-= sign(x1-x2)){
			if(z->tiles[x1][y1].impassible) wall=1;
			else if (wall) break;

			zone_empty_tile(z,x1,y1);
		}

		for(;y1 != y2; y1-= sign(y1-y2)){
			if(z->tiles[x1][y1].impassible) wall=1;
			else if (wall) break;

			zone_empty_tile(z,x1,y1);
		}
	}

	//do rendering thing
	for (x = 0; x < z->width; x++) {
	for (y = 0; y < z->height; y++) {
		if (z->tiles[x][y].impassible) {
			set_wall_char(z,x,y);
		}
	}
	}

	for(i=0; i< rc; i++)
		free(rooms[i]);

	free(rooms);

	// place some random junk
	max = random() % (z->width * z->height / ITEM_INFREQ) + ITEM_MIN;
	for (i = max; i >= 0; i--) {
		it = gen_item(world.gitems, 1);

		timeout = 1000;
		do {
			x = random() % z->width;
			y = random() % z->height;
			timeout--;
		} while ((z->tiles[x][y].impassible || !inv_try(z->tiles[x][y].inv, it)) && timeout);

		if (timeout) {
			item_tele(it, x, y, z);
			zone_update(z, x, y);
		} else {
			item_free(it);
		}
	}

	// place some more random junk
	if (!config.all_alone) {
		max = random() % (z->width * z->height / CRTR_INFREQ) + CRTR_MIN;
		for (i = max; i >= 0; i--) {
			cr = gen_crtr(world.gcrtrs, 1);
			crtr_spawn(cr, z);
			zone_update(z, cr->x, cr->y);
		}
	}

	// place random zone jumpers
	for (i = 0; i < 4; i++) {
		do {
			x = random() % z->width;
			y = random() % z->height;
			timeout--;
		} while (z->tiles[x][y].impassible);

		z->tiles[x][y].linked = 1;
		z->tiles[x][y].link_z = NULL;
		z->tiles[x][y].ch = '@';
		z->tiles[x][y].show_ch = '@';
	}

	// cleanup
	//for (x = 0; x < z->width; x++) free(walls[x]);
	//free(walls);
	//free(rv);
}