Esempio n. 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;
}
Esempio n. 2
0
File: vis.cpp Progetto: amecky/space
	// ------------------------------------------------------
	// describe building
	// ------------------------------------------------------
	bool describe_building(Island* island,int x, int y) {
		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;
		}
		const Tile& t = tiles->get(x, y);
		printf("Building: %s\n", gContext->building_definitions.getName(t.building_id));
		printf("   Level: %d\n", t.level);
		Resources tmp;
		if (gContext->price_registry.get(PT_REGULAR, 2, t.building_id, t.level, &tmp)) {
			printf("Regular income:\n");
			printf("Duration: %d\n", gContext->price_registry.getDuration(PT_REGULAR, t.building_id, t.level));
			res::show_resources(gContext->resource_registry, tmp, false);
		}
		printf("Available work:\n");
		for (int i = 1; i <= t.level; ++i) {
			if (gContext->price_registry.get(PT_WORK, 0, t.building_id, i, &tmp)) {
				printf(" Level %d\n", i);
				printf("Duration: %d\n", gContext->price_registry.getDuration(PT_WORK, t.building_id, i));
				printf("Costs:\n");
				res::show_resources(gContext->resource_registry, tmp, false);
			}
			if (gContext->price_registry.get(PT_WORK, 1, t.building_id, i, &tmp)) {
				printf("Income:\n");
				Resources collect;
				if (gContext->price_registry.get(PT_WORK, 2, t.building_id, i, &collect)) {
					tmp.add(collect);

				}
				res::show_resources(gContext->resource_registry, tmp, false);
			}
		}
		// FIXME: list start options
		return true;
	}
Esempio n. 3
0
File: vis.cpp Progetto: amecky/space
	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");
	}