df::tiletype findRandomVariant (const df::tiletype tile) { if (tileVariant(tile) == tiletype_variant::NONE) return tile; std::vector<df::tiletype> matches; FOR_ENUM_ITEMS(tiletype, tt) { if (tileShape(tt) == tileShape(tile) && tileMaterial(tt) == tileMaterial(tile) && tileSpecial(tt) == tileSpecial(tile)) matches.push_back(tt); } return matches[rand() % matches.size()]; }
void Tile::DrawGrowth(c_sprite * spriteobject, bool top=true) { //Draw Growths that appear over branches if (tileMaterial() == RemoteFortressReader::ROOT || tileMaterial() == RemoteFortressReader::TREE_MATERIAL || tileMaterial() == RemoteFortressReader::MUSHROOM) { df::plant_raw* plantRaw = df::global::world->raws.plants.all[tree.index]; for (int i = 0; i < plantRaw->growths.size(); i++) { df::plant_growth * growth = plantRaw->growths[i]; if (!growth->locations.whole) continue; //we need at least one location. int32_t time = *df::global::cur_year_tick; if (growth->timing_1 >= 0 && growth->timing_1 > time) continue; if (growth->timing_2 >= 0 && growth->timing_2 < time) continue; growth_locations loca = LOCATION_NONE; if (growth->locations.bits.cap && tileMaterial() == RemoteFortressReader::MUSHROOM) loca = LOCATION_CAP; if (growth->locations.bits.heavy_branches && (tileSpecial() == RemoteFortressReader::BRANCH && tileType != df::tiletype::TreeBranches)) loca = LOCATION_HEAVY_BRANCHES; if (growth->locations.bits.roots && tileMaterial() == RemoteFortressReader::ROOT) loca = LOCATION_ROOTS; if (growth->locations.bits.light_branches && tileType == df::tiletype::TreeBranches) loca = LOCATION_LIGHT_BRANCHES; if (growth->locations.bits.sapling && tileMaterial() == RemoteFortressReader::SAPLING) loca = LOCATION_SAPLING; if (growth->locations.bits.trunk && tileShape() == RemoteFortressReader::WALL) loca = LOCATION_TRUNK; if (growth->locations.bits.twigs && tileShape() == RemoteFortressReader::TWIG) loca = LOCATION_TWIGS; if (loca == LOCATION_NONE) continue; DFHack::t_matglossPair fakeMat; fakeMat.index = tree.index; fakeMat.type = i * 10 + loca; if (top) spriteobject = contentLoader->growthTopConfigs.get(fakeMat); else spriteobject = contentLoader->growthBottomConfigs.get(fakeMat); if (spriteobject) { DFHack::t_matglossPair growthMat; growthMat.index = growth->mat_index; growthMat.type = growth->mat_type; ALLEGRO_COLOR growCol = lookupMaterialColor(growthMat); if (growth->prints.size() > 1) { df::plant_growth_print * basePrint = growth->prints[0]; df::plant_growth_print * currentPrint = basePrint; for (int k = 0; k < growth->prints.size(); k++) { if (growth->prints[k]->timing_start >= 0 && growth->prints[k]->timing_start > time) continue; if (growth->prints[k]->timing_end >= 0 && growth->prints[k]->timing_end < time) continue; currentPrint = growth->prints[k]; } growCol = morph_color(growCol, ssConfig.colors.getDfColor(basePrint->color[0], basePrint->color[2], ssConfig.useDfColors), ssConfig.colors.getDfColor(currentPrint->color[0], currentPrint->color[2], ssConfig.useDfColors)); } spriteobject->set_growthColor(growCol); spriteobject->assemble_world(x, y, z, this); } } } }