Пример #1
0
DoorBrush* Item::getDoorBrush() const
{
	ItemType& it = item_db[id];
	if(!it.isWall || !it.isBrushDoor) {
		return nullptr;
	}
	WallBrush* wb = dynamic_cast<WallBrush*>(it.brush);
	DoorBrush* db = nullptr;
	// Quite a horrible dependency on a global here, meh.
	switch(wb->getDoorTypeFromID(id)) {
		case WALL_DOOR_NORMAL: {
			db = gui.normal_door_brush;
			break;
		}
		case WALL_DOOR_LOCKED: {
			db = gui.locked_door_brush;
			break;
		}
		case WALL_DOOR_QUEST: {
			db = gui.quest_door_brush;
			break;
		}
		case WALL_DOOR_MAGIC: {
			db = gui.magic_door_brush;
			break;
		}
		case WALL_WINDOW: {
			db = gui.window_door_brush;
			break;
		}
		case WALL_HATCH_WINDOW: {
			db = gui.hatch_door_brush;
			break;
		}
		default: {
			break;
		}
	}
	return db;
}
Пример #2
0
void WallDecorationBrush::draw(BaseMap* map, Tile* tile, void* parameter) {
	ASSERT(tile);

	ItemVector::iterator iter = tile->items.begin();

	tile->cleanWalls(this);
	while(iter != tile->items.end()) {
		Item* item = *iter;
		if(item->isBorder()) {
			++iter;
			continue;
		}

		if(item->isWall()) {
			// Now we found something interesting.

			// Is it just a decoration, like what we're trying to add?
			WallBrush* wb = item->getWallBrush();
			if(dynamic_cast<WallDecorationBrush*>(wb)) {
				// It is, discard and advance!
				++iter;
				continue;
			}

			// We first need to figure out the alignment of this item (wall)
			BorderType wall_alignment = item->getWallAlignment();

			// Now we need to figure out if we got an item that mights suffice to place on this tile..

			int id = 0;
			if(item->isBrushDoor()) {
				// If it's a door
				::DoorType doortype = wb->getDoorTypeFromID(item->getID());
				uint16_t discarded_id = 0;
				bool close_match = false;
				bool open = item->isOpen();

				for(std::vector<WallBrush::DoorType>::iterator door_iter = door_items[wall_alignment].begin();
						door_iter!= door_items[wall_alignment].end();
						++door_iter)
				{
					WallBrush::DoorType& dt = *door_iter;
					if(dt.type == doortype) {
						ASSERT(dt.id);
						ItemType& it = item_db[dt.id];
						ASSERT(it.id != 0);

						if(it.isOpen == open) {
							id = dt.id;
							break;
						} else {
							discarded_id = dt.id;
							close_match = true;
						}
						if(!close_match && discarded_id == 0) {
							discarded_id = dt.id;
						}
					}
				}
				if(id == 0) {
					id = discarded_id;
					if(id == 0) {
						++iter;
						continue;
					}
				}
			} else {
				// If it's a normal wall...
				if(wall_items[wall_alignment].total_chance <= 0) {
					// No fitting item, exit
					++iter;
					continue;
				}
				int chance = random(1, wall_items[wall_alignment].total_chance);
				for(std::vector<WallBrush::WallType>::const_iterator witer = wall_items[wall_alignment].items.begin();
					witer != wall_items[wall_alignment].items.end();
					++witer)
				{
					if(chance <= witer->chance) {
						id = witer->id;
						break;
					}
				}
			}
			// If we found an invalid id we should've already exited the loop
			ASSERT(id);

			// Add a matching item above this item.
			Item* item = Item::Create(id);
			++iter;
			iter = tile->items.insert(iter, item);
		}
		++iter;
	}
}