Пример #1
0
// ------------------------------------------------------
// StartWork
// ------------------------------------------------------
bool UpgradeWork::start(Island* island, const TextLine& line) {
	int x = line.get_int(1);
	int y = line.get_int(2);
	Tiles* tiles = island->getTiles();
	int idx = x + y * tiles->width;
	if ( tiles->getBuildingID(idx) == -1 ) {
		gContext->messages.report_error("There is no building at %d %d",x,y);
		return false;
	}
	// FIXME: check if there is only a regular work item
	if ( tiles->isActive(idx)) {
		gContext->messages.report_error("The building is active - upgrade is not available");
		return false;
	}
	if (island->checkRequirements(tiles->getBuildingID(idx), tiles->getLevel(idx) + 1)) {
		tiles->set_state(x,y,TS_ACTIVE);
		island->createWork(PT_UPGRADE,x,y,tiles->getBuildingID(idx),tiles->getLevel(idx)+1);
		return true;
	}
	return false;
}
Пример #2
0
	void print_map(Island* island, int centerX, int centerY, int size) {
		Tiles* tiles = island->getTiles();
		int xmin = centerX - size;
		int xmax = centerX + size;
		int ymin = centerY - size;
		int ymax = centerY + size;
		if (xmin < 0) {
			xmin = 0;
			xmax = 2 * size;
		}
		if (xmax >= tiles->width) {
			xmin = tiles->width - 2 * size;
			xmax = tiles->width;
		}
		if (ymin < 0) {
			ymin = 0;
			ymax = 2 * size;
		}
		if (ymax >= tiles->height) {
			ymin = tiles->height - 2 * size;
			ymax = tiles->height;
		}
		for ( int y = ymax - 1; y >= ymin; --y ) {
			printf("%2d | ", y);
			for ( int x = xmin; x < xmax; ++x ) {
				int idx = x + y * tiles->width;
				if ( tiles->has_state(x,y,TS_LOCKED)) {
					printf("??  ");
				}
				else if ( tiles->has_state(x,y,TS_UNDEFINED)) {
					printf("    ");
				}
				else {
					if ( tiles->getBuildingID(idx) != -1 ) {
						printf("%s", gContext->building_definitions.getSign(tiles->getBuildingID(idx)));
						if ( tiles->isActive(idx)) {			
							printf("# ");
						}
						else if ( tiles->has_state(x,y,TS_COLLECTABLE)) {
							printf("* ");
						}
						else {
							printf("  ");
						}
					}
					else if ( tiles->_tiles[idx].ref_id != -1 ) {
						printf("xx  ");
					}
					else {
						printf("-   ");
					}
				}
			}
			printf("\n");
		}
		printf("   -----------------------------------------------------------------\n");
		printf("     ");
		for (int i = xmin; i < xmax; ++i) {
			printf("%2d  ", i);
		}
		printf("\n");
	}