Esempio n. 1
0
//t is for type
bool TavernExpansion::makeExpansion(String tileMat, int t)
{
    int rowChange = row / 2;
    int colChange = col / 2;
    
    String tMat = "GridMaterial";
    
    getBorders();
    
    if (this->viableExpansion() == true)
    {
        TavernResources::getInstance()->removeGold(row * col * TavernResources::getInstance()->getTilePrice());
        TavernResources::getInstance()->incrementTilePrice();
        TavernResources::getInstance()->addBuildRep(row * col * 20);
       TavernResources::getInstance()->calcRep();
       
        for (int dRow = -rowChange; dRow <= rowChange; dRow++)
        {
            for (int dCol = -colChange; dCol <= colChange; dCol++)
            {
                if (centerPos.x + dRow > 0 && centerPos.x + dRow < DIM - 1 && centerPos.y + dCol > 0 && centerPos.y + dCol < DIM - 1)
                {
                    setTile(dRow, dCol, tMat, TILE, true);
                    setTE(dRow, dCol, true);
                }
            }
        }
        
        configureTiles(tMat);
        //redoBotWalls();
       return true;
    }
   return false;
}
Esempio n. 2
0
// Builds an array with only the indexed vertices and calls getBorders
void getIndexedBorders (float* vertexArray, unsigned int* indicesArray, unsigned int isize, Vec3f& small, Vec3f& big) {
	float* indexedVertexArray = new float[isize*3];
	for (unsigned int i=0; i<isize; ++i) {
		indexedVertexArray[0 + 3*i] = vertexArray[0 + 3*indicesArray[i]];
		indexedVertexArray[1 + 3*i] = vertexArray[1 + 3*indicesArray[i]];
		indexedVertexArray[2 + 3*i] = vertexArray[2 + 3*indicesArray[i]];
	}
	getBorders (indexedVertexArray, isize*3, small, big);
	delete indexedVertexArray;
}
QList< QImage> DwarfClipboardPng::regenerateImages(DwarfClipboardCopyObj & obj)
{
    QList<QImage> retImages;
    QVector<QVector<QVector<QString > > > dig = obj.getDig();
    QVector<QVector<QVector<QString > > > build = obj.getBuild();
    DFHack::t_screen temp;
    temp.background = 0;
    temp.foreground = 7;
    temp.bright = 1;
    cursorIdx current;
    for(current.z=dig.size()-1;current.z>=0;current.z--){
        QImage currentImg(dig[current.z][0].size()*tileWidth,dig[current.z].size()*tileHeight,QImage::Format_ARGB32);
        QPainter painter(&currentImg);
        painter.setCompositionMode(QPainter::CompositionMode_Source);
        QVector<QVector<QString> > rawNumbers(dig[current.z][0].size(),QVector<QString>(dig[current.z].size()));
        for(current.y = 0;current.y<dig[current.z].size();current.y++){
            for(current.x =0;current.x<dig[current.z][current.y].size();current.x++){
                QList< int > borders = getBorders(dig,current);
                temp.symbol = 0;
                if(dig[current.z][current.y][current.x] == " " && borders.size() >= 1 ){
                    temp.symbol = 176;
                }
                if(dig[current.z][current.y][current.x] == "i"){
                    temp.symbol = 88;
                }
                QImage tile = getTileFromScreen(temp);
                QString test = stringFromScreen(temp);
                rawNumbers[current.x][current.y] = test;
                painter.drawImage(current.x * tileWidth, current.y * tileHeight, tile);
            }
        }
        painter.end();
        QString rawComplete;
        for(int yitr = 0;yitr < rawNumbers[0].size();yitr++){
            for(int xitr = 0;xitr < rawNumbers.size();xitr++){
                rawComplete.append(rawNumbers[xitr][yitr]);
            }
            rawComplete.append(':');
        }
        currentImg.setText("rawNumbers",rawComplete);
        retImages.append(currentImg);
    }
    return(retImages);
}
void c_sprite::set_by_xml(TiXmlElement *elemSprite)
{
	const char* sheetIndexStr;
	sheetIndexStr = elemSprite->Attribute("sheetIndex");
	if (sheetIndexStr != NULL && sheetIndexStr[0] != 0)
	{
		sheetindex=atoi(sheetIndexStr);
	}
	const char* spriteStr;
	spriteStr = elemSprite->Attribute("sprite");
	if (spriteStr != NULL && spriteStr[0] != 0)
	{
		sheetindex=atoi(spriteStr);
	}
	const char* indexStr;
	indexStr = elemSprite->Attribute("index");
	if (indexStr != NULL && indexStr[0] != 0)
	{
		sheetindex=atoi(indexStr);
	}
	const char* animoffStr;
	animoffStr = elemSprite->Attribute("random_anim_offset");
	if (animoffStr != NULL && animoffStr[0] != 0)
	{
		randomanimation=atoi(animoffStr);
	}
	const char* scaleStr;
	scaleStr = elemSprite->Attribute("zoom");
	if (scaleStr != NULL && scaleStr[0] != 0)
	{
		int scalev=atoi(scaleStr);
		spritescale=std::pow(2.0f,(float)scalev);
	}
	//load files, if any
	const char* filename = elemSprite->Attribute("file");
	if (filename != NULL && filename[0] != 0)
	{
		fileindex = loadConfigImgFile((char*)filename,elemSprite);
		if(fileindex == -1) return;
	}

	animframes = getAnimFrames(elemSprite->Attribute("frames"));
	if (animframes == 0)
		animframes = ALL_FRAMES;

	openborders = getBorders(elemSprite->Attribute("border_open_OR"));

	floorborders = getBorders(elemSprite->Attribute("border_floor_OR"));

	wallborders = getBorders(elemSprite->Attribute("border_wall_OR"));

	rampborders = getBorders(elemSprite->Attribute("border_ramp_OR"));

	upstairborders = getBorders(elemSprite->Attribute("border_upstair_OR"));

	downstairborders = getBorders(elemSprite->Attribute("border_downstair_OR"));

	darkborders = getUnBorders(elemSprite->Attribute("border_dark_OR"));

	lightborders = getBorders(elemSprite->Attribute("border_light_OR"));

	notopenborders = getUnBorders(elemSprite->Attribute("border_open_NOR"));

	notfloorborders = getUnBorders(elemSprite->Attribute("border_floor_NOR"));

	notwallborders = getUnBorders(elemSprite->Attribute("border_wall_NOR"));

	notrampborders = getUnBorders(elemSprite->Attribute("border_ramp_NOR"));

	notupstairborders = getUnBorders(elemSprite->Attribute("border_upstair_NOR"));

	notdownstairborders = getUnBorders(elemSprite->Attribute("border_downstair_NOR"));

	//check for randomised tiles
	const char* spriteVariationsStr = elemSprite->Attribute("variations");
	if (spriteVariationsStr == NULL || spriteVariationsStr[0] == 0)
	{
		variations = 0;
	}
	else 
	{
		variations=atoi(spriteVariationsStr);
	}


	const char* waterDirStr = elemSprite->Attribute("water_direction");
	if (waterDirStr == NULL || waterDirStr[0] == 0)
	{
		water_direction = -1;
	}
	else 
	{
		water_direction=atoi(waterDirStr);
	}

	//decide what the sprite should be shaded by.
	const char* spriteVarColorStr = elemSprite->Attribute("color");
	if (spriteVarColorStr == NULL || spriteVarColorStr[0] == 0)
	{
		shadeBy = ShadeNone;
	}
	else
	{
		shadeBy = getShadeType(spriteVarColorStr);
	}

	//some sprites should only be drawn when the tile is chopped in half
	const char* spriteChopStr = elemSprite->Attribute("halftile");
	if (spriteChopStr == NULL || spriteChopStr[0] == 0)
	{
		halftile = HALFTILECHOP;
	}
	else if( strcmp(spriteChopStr, "chop") == 0)
	{
		halftile = HALFTILECHOP;
	}
	else if( strcmp(spriteChopStr, "yes") == 0)
	{
		halftile = HALFTILEYES;
	}
	else if( strcmp(spriteChopStr, "no") == 0)
	{
		halftile = HALFTILENO;
	}
	else if( strcmp(spriteChopStr, "both") == 0)
	{
		halftile = HALFTILEBOTH;
	}

	//hidden in the shadows
	const char* spriteShadowStr = elemSprite->Attribute("dark");
	if (spriteShadowStr == NULL || spriteShadowStr[0] == 0)
	{
		light = LIGHTANY;
	}
	else if( strcmp(spriteShadowStr, "yes") == 0)
	{
		light = LIGHTNO;
	}
	else if( strcmp(spriteShadowStr, "no") == 0)
	{
		light = LIGHTYES;
	}
	else if( strcmp(spriteShadowStr, "both") == 0)
	{
		light = LIGHTANY;
	}

	//some sprites are actually tile borders.
	const char* spriteBorderStr = elemSprite->Attribute("tileborder");
	if (spriteBorderStr == NULL || spriteBorderStr[0] == 0)
	{
		isoutline = OUTLINENONE;
	}
	else if( strcmp(spriteBorderStr, "none") == 0)
	{
		isoutline = OUTLINENONE;
	}
	else if( strcmp(spriteBorderStr, "left") == 0)
	{
		isoutline = OUTLINELEFT;
	}
	else if( strcmp(spriteBorderStr, "right") == 0)
	{
		isoutline = OUTLINERIGHT;
	}
	else if( strcmp(spriteBorderStr, "bottom") == 0)
	{
		isoutline = OUTLINEBOTTOM;
	}

	//Grass states
	const char* grass_growth_string = elemSprite->Attribute("grass_state");
	if (grass_growth_string == NULL || grass_growth_string[0] == 0)
	{
		grass_growth = GRASS_GROWTH_ANY;
	}
	else if( strcmp(grass_growth_string, "any") == 0)
	{
		grass_growth = GRASS_GROWTH_ANY;
	}
	else if( strcmp(grass_growth_string, "green") == 0)
	{
		grass_growth = GRASS_GROWTH_NORMAL;
	}
	else if( strcmp(grass_growth_string, "dry") == 0)
	{
		grass_growth = GRASS_GROWTH_DRY;
	}
	else if( strcmp(grass_growth_string, "dead") == 0)
	{
		grass_growth = GRASS_GROWTH_DEAD;
	}

	//do bodyparts
	const char* bodyPartStr = elemSprite->Attribute("bodypart");
	//clear old bodypart string
	memset(bodypart, 0, sizeof(bodypart));
	//copy new, if found
	if (bodyPartStr != NULL && bodyPartStr[0] != 0)
	{
		strcpy(bodypart, bodyPartStr);
	}

	uint8_t red, green, blue, alpha;
	//do custom colors
	const char* spriteRedStr = elemSprite->Attribute("red");
	if (spriteRedStr == NULL || spriteRedStr[0] == 0)
	{
		red = 255;
	}
	else red=atoi(spriteRedStr);
	const char* spriteGreenStr = elemSprite->Attribute("green");
	if (spriteGreenStr == NULL || spriteGreenStr[0] == 0)
	{
		green = 255;
	}
	else green=atoi(spriteGreenStr);
	const char* spriteBlueStr = elemSprite->Attribute("blue");
	if (spriteBlueStr == NULL || spriteBlueStr[0] == 0)
	{
		blue = 255;
	}
	else blue=atoi(spriteBlueStr);
	const char* spriteAlphaStr = elemSprite->Attribute("alpha");
	if (spriteAlphaStr == NULL || spriteAlphaStr[0] == 0)
	{
		alpha = 255;
	}
	else alpha=atoi(spriteAlphaStr);
	shadecolor = al_map_rgba(red, green, blue, alpha);

	//Should the sprite be shown only when there is snow?
	const char* spriteSnowMinStr = elemSprite->Attribute("snow_min");
	if (spriteSnowMinStr == NULL || spriteSnowMinStr[0] == 0)
	{
		snowmin = 0;
	}
	else snowmin=atoi(spriteSnowMinStr);
	const char* spriteSnowMaxStr = elemSprite->Attribute("snow_max");
	if (spriteSnowMaxStr == NULL || spriteSnowMaxStr[0] == 0)
	{
		snowmax = -1;
	}
	else snowmax=atoi(spriteSnowMaxStr);

	//Should the sprite be shown only when there is grass?
	const char* spriteGrassMinStr = elemSprite->Attribute("grass_min");
	if (spriteGrassMinStr == NULL || spriteGrassMinStr[0] == 0)
	{
		grassmin = 0;
	}
	else grassmin=atoi(spriteGrassMinStr);
	const char* spriteGrassMaxStr = elemSprite->Attribute("grass_max");
	if (spriteGrassMaxStr == NULL || spriteGrassMaxStr[0] == 0)
	{
		grassmax = -1;
	}
	else grassmax=atoi(spriteGrassMaxStr);

	//does the sprite match a particular grass type?
	const char* idstr = elemSprite->Attribute("grass_type");
	if (idstr == NULL || idstr[0] == 0)
	{
		grasstype = INVALID_INDEX;
	}
	else grasstype = lookupIndexedType(idstr,contentLoader->organic);

	//Should the sprite be shown only when there is blood?
	const char* spritebloodMinStr = elemSprite->Attribute("blood_min");
	if (spritebloodMinStr == NULL || spritebloodMinStr[0] == 0)
	{
		bloodmin = 0;
	}
	else bloodmin=atoi(spritebloodMinStr);
	const char* spritebloodMaxStr = elemSprite->Attribute("blood_max");
	if (spritebloodMaxStr == NULL || spritebloodMaxStr[0] == 0)
	{
		bloodmax = -1;
	}
	else bloodmax=atoi(spritebloodMaxStr);

	//Should the sprite be shown only when there is mud?
	const char* spritemudMinStr = elemSprite->Attribute("mud_min");
	if (spritemudMinStr == NULL || spritemudMinStr[0] == 0)
	{
		mudmin = 0;
	}
	else mudmin=atoi(spritemudMinStr);
	const char* spritemudMaxStr = elemSprite->Attribute("mud_max");
	if (spritemudMaxStr == NULL || spritemudMaxStr[0] == 0)
	{
		mudmax = -1;
	}
	else mudmax=atoi(spritemudMaxStr);

	//Add user settable sprite offsets
	const char* strOffsetX = elemSprite->Attribute("offsetx");
	if (strOffsetX == NULL || strOffsetX[0] == 0)
	{
		offset_user_x = 0;
	}
	else offset_user_x=atoi(strOffsetX);
	const char* strOffsetY = elemSprite->Attribute("offsety");
	if (strOffsetY == NULL || strOffsetY[0] == 0)
	{
		offset_user_y = 0;
	}
	else offset_user_y=atoi(strOffsetY);

	//not all tiles work well with an outline
	const char* spriteOutlineStr = elemSprite->Attribute("outline");
	if (spriteOutlineStr != NULL && spriteOutlineStr[0] != 0)
		needoutline=(atoi(spriteOutlineStr) == 1);

	//get the possible offset for blood bools
	const char* spriteBloodStr = elemSprite->Attribute("blood_sprite");
	if (spriteBloodStr != NULL && spriteBloodStr[0] != 0)
		bloodsprite=(atoi(spriteBloodStr) == 1);

	subsprites.clear();
	//add subsprites, if any.
	TiXmlElement* elemSubSprite = elemSprite->FirstChildElement("subsprite");
	for(TiXmlElement* elemSubType = elemSprite->FirstChildElement("subsprite");
		elemSubType;
		elemSubType = elemSubType->NextSiblingElement("subsprite"))
	{
		c_sprite subsprite;
		subsprite.set_size(spritewidth, spriteheight);
		subsprite.set_by_xml(elemSubType, fileindex);
		subsprite.set_offset(offset_x, offset_y);
		subsprites.push_back(subsprite);
	}
}