Example #1
0
void MapMakeRoom(Map *map, int xOrigin, int yOrigin, int width, int height)
{
	int x, y;
	// Set the perimeter walls and interior
	// If the tile is a room interior already, do not turn it into a wall
	// This is due to overlapping rooms
	for (y = yOrigin; y < yOrigin + height; y++)
	{
		for (x = xOrigin; x < xOrigin + width; x++)
		{
			if (y == yOrigin || y == yOrigin + height - 1 ||
				x == xOrigin || x == xOrigin + width - 1)
			{
				if (IMapGet(map, Vec2iNew(x, y)) == MAP_FLOOR)
				{
					IMapSet(map, Vec2iNew(x, y), MAP_WALL);
				}
			}
			else
			{
				IMapSet(map, Vec2iNew(x, y), MAP_ROOM);
			}
		}
	}
	// Check perimeter again; if there are walls where both sides contain
	// rooms, remove the wall as the rooms have merged
	for (y = yOrigin; y < yOrigin + height; y++)
	{
		for (x = xOrigin; x < xOrigin + width; x++)
		{
			if (y == yOrigin || y == yOrigin + height - 1 ||
				x == xOrigin || x == xOrigin + width - 1)
			{
				if (((IMapGet(map, Vec2iNew(x + 1, y)) & MAP_MASKACCESS) == MAP_ROOM &&
					(IMapGet(map, Vec2iNew(x - 1, y)) & MAP_MASKACCESS) == MAP_ROOM) ||
					((IMapGet(map, Vec2iNew(x, y + 1)) & MAP_MASKACCESS) == MAP_ROOM &&
					(IMapGet(map, Vec2iNew(x, y - 1)) & MAP_MASKACCESS) == MAP_ROOM))
				{
					IMapSet(map, Vec2iNew(x, y), MAP_ROOM);
				}
			}
		}
	}
}
Example #2
0
void MapMakePillar(Map *map, Vec2i pos, Vec2i size)
{
	Vec2i v;
	for (v.y = pos.y; v.y < pos.y + size.y; v.y++)
	{
		for (v.x = pos.x; v.x < pos.x + size.x; v.x++)
		{
			IMapSet(map, v, MAP_WALL);
		}
	}
}
Example #3
0
void MapMakeSquare(Map *map, Vec2i pos, Vec2i size)
{
	Vec2i v;
	for (v.y = pos.y; v.y < pos.y + size.y; v.y++)
	{
		for (v.x = pos.x; v.x < pos.x + size.x; v.x++)
		{
			IMapSet(map, v, MAP_SQUARE);
		}
	}
}
Example #4
0
void MapSetTile(Map *map, Vec2i pos, unsigned short tileType, Mission *m)
{
	IMapSet(map, pos, tileType);
	// Update the tile as well, plus neighbours as they may be affected
	// by shadows etc. especially walls
	MapSetupTile(map, pos, m);
	MapSetupTile(map, Vec2iNew(pos.x - 1, pos.y), m);
	MapSetupTile(map, Vec2iNew(pos.x + 1, pos.y), m);
	MapSetupTile(map, Vec2iNew(pos.x, pos.y - 1), m);
	MapSetupTile(map, Vec2iNew(pos.x, pos.y + 1), m);
}
Example #5
0
static void MapSetupPerimeter(Map *map)
{
	Vec2i v;
	for (v.y = 0; v.y < map->Size.y; v.y++)
	{
		for (v.x = 0; v.x < map->Size.x; v.x++)
		{
			if (v.y == 0 || v.y == map->Size.y - 1 ||
				v.x == 0 || v.x == map->Size.x - 1)
			{
				IMapSet(map, v, MAP_WALL);
			}
		}
	}
}
Example #6
0
void MapMakeWall(Map *map, Vec2i pos)
{
	IMapSet(map, pos, MAP_WALL);
}
Example #7
0
void MapPlaceDoors(
	Map *map, Vec2i pos, Vec2i size,
	int hasDoors, int doors[4], int doorMin, int doorMax,
	unsigned short accessMask)
{
	int x, y;
	int i;
	unsigned short doorTile = hasDoors ? MAP_DOOR : MAP_ROOM;
	Vec2i v;

	// Set access mask
	for (y = pos.y + 1; y < pos.y + size.y - 1; y++)
	{
		for (x = pos.x + 1; x < pos.x + size.x - 1; x++)
		{
			if ((IMapGet(map, Vec2iNew(x, y)) & MAP_MASKACCESS) == MAP_ROOM)
			{
				IMapSet(map, Vec2iNew(x, y), MAP_ROOM | accessMask);
			}
		}
	}

	// Set the doors
	if (doors[0])
	{
		int doorSize = MIN(
			(doorMax > doorMin ? (rand() % (doorMax - doorMin + 1)) : 0) + doorMin,
			size.y - 4);
		for (i = -doorSize / 2; i < (doorSize + 1) / 2; i++)
		{
			v = Vec2iNew(pos.x, pos.y + size.y / 2 + i);
			if (IMapGet(map, Vec2iNew(v.x + 1, v.y)) != MAP_WALL &&
				IMapGet(map, Vec2iNew(v.x - 1, v.y)) != MAP_WALL)
			{
				IMapSet(map, v, doorTile);
			}
		}
	}
	if (doors[1])
	{
		int doorSize = MIN(
			(doorMax > doorMin ? (rand() % (doorMax - doorMin + 1)) : 0) + doorMin,
			size.y - 4);
		for (i = -doorSize / 2; i < (doorSize + 1) / 2; i++)
		{
			v = Vec2iNew(pos.x + size.x - 1, pos.y + size.y / 2 + i);
			if (IMapGet(map, Vec2iNew(v.x + 1, v.y)) != MAP_WALL &&
				IMapGet(map, Vec2iNew(v.x - 1, v.y)) != MAP_WALL)
			{
				IMapSet(map, v, doorTile);
			}
		}
	}
	if (doors[2])
	{
		int doorSize = MIN(
			(doorMax > doorMin ? (rand() % (doorMax - doorMin + 1)) : 0) + doorMin,
			size.x - 4);
		for (i = -doorSize / 2; i < (doorSize + 1) / 2; i++)
		{
			v = Vec2iNew(pos.x + size.x / 2 + i, pos.y);
			if (IMapGet(map, Vec2iNew(v.x, v.y + 1)) != MAP_WALL &&
				IMapGet(map, Vec2iNew(v.x, v.y - 1)) != MAP_WALL)
			{
				IMapSet(map, v, doorTile);
			}
		}
	}
	if (doors[3])
	{
		int doorSize = MIN(
			(doorMax > doorMin ? (rand() % (doorMax - doorMin + 1)) : 0) + doorMin,
			size.x - 4);
		for (i = -doorSize / 2; i < (doorSize + 1) / 2; i++)
		{
			v = Vec2iNew(pos.x + size.x / 2 + i, pos.y + size.y - 1);
			if (IMapGet(map, Vec2iNew(v.x, v.y + 1)) != MAP_WALL &&
				IMapGet(map, Vec2iNew(v.x, v.y - 1)) != MAP_WALL)
			{
				IMapSet(map, v, doorTile);
			}
		}
	}
}