void PartDb::ScanGenderedParts(std::vector<Part> &output, const int species_idx, const int race_idx, const std::string &path, const char *prefix) { const int prefix_len = strlen(prefix); for (fs::FileEnumerator files(fs::gameDataFiles, path); !files.Finished(); files.Next()) { const std::string &name = files.Current().GetName(); if (starts_with(name, prefix)) { char *end = nullptr; int gender_idx = strtol(name.c_str() + prefix_len, &end, 10); Uint32 sel; // HACK -- attempt to recognise `foo_3.png' style names if (strcmp(end, ".png") == 0) { sel = _make_selector(species_idx, race_idx, -1); } else { if (gender_idx < 0 || gender_idx >= MAX_GENDERS) { Output("Gender out of range: %s\n", files.Current().GetPath().c_str()); continue; } sel = _make_selector(species_idx, race_idx, gender_idx); } SDLSurfacePtr im = LoadSurfaceFromFile(files.Current().GetPath()); if (im) { output.push_back(Part(sel, im)); } else { Output("Failed to load image %s\n", files.Current().GetPath().c_str()); } } } }
void FaceParts::PickFaceParts(FaceDescriptor &inout_face, const Uint32 seed) { Random rand(seed); _pick(rand, inout_face.species, NumSpecies()); _pick(rand, inout_face.race, NumRaces(inout_face.species)); _pick(rand, inout_face.gender, NumGenders(inout_face.species)); const Uint32 selector = _make_selector(inout_face.species, inout_face.race, inout_face.gender); _pick(rand, inout_face.head, _count_parts(s_partdb->heads, selector)); _pick(rand, inout_face.eyes, _count_parts(s_partdb->eyes, selector)); _pick(rand, inout_face.nose, _count_parts(s_partdb->noses, selector)); _pick(rand, inout_face.mouth, _count_parts(s_partdb->mouths, selector)); _pick(rand, inout_face.hairstyle, _count_parts(s_partdb->hairstyles, selector)); const bool has_accessories = (rand.Int32() & 1); _pick(rand, inout_face.accessories, _count_parts(s_partdb->accessories, selector)); if (!has_accessories) { inout_face.accessories = 0; } _pick(rand, inout_face.clothes, _count_parts(s_partdb->clothes, selector)); _pick(rand, inout_face.armour, _count_parts(s_partdb->armour, selector)); }
void PartDb::ScanParts(std::vector<Part> &output, const int species_idx, const int race_idx, const std::string &path, const char *prefix) { const Uint32 selector = _make_selector(species_idx, race_idx, -1); for (fs::FileEnumerator files(fs::gameDataFiles, path); !files.Finished(); files.Next()) { const std::string &name = files.Current().GetName(); if (starts_with(name, prefix)) { SDLSurfacePtr im = LoadSurfaceFromFile(files.Current().GetPath()); if (im) { output.push_back(Part(selector, im)); } else { Output("Failed to load image %s\n", files.Current().GetPath().c_str()); } } } }
void FaceParts::BuildFaceImage(SDL_Surface *faceIm, const FaceDescriptor &face, bool armoured) { const Uint32 selector = _make_selector(face.species, face.race, face.gender); _blit_image(faceIm, s_partdb->background_general.Get(), 0, 0); _blit_image(faceIm, _get_part(s_partdb->heads, selector, face.head), 0, 0); if (!armoured) { _blit_image(faceIm, _get_part(s_partdb->clothes, selector, face.clothes), 0, 135); } _blit_image(faceIm, _get_part(s_partdb->eyes, selector, face.eyes), 0, 41); _blit_image(faceIm, _get_part(s_partdb->noses, selector, face.nose), 1, 89); _blit_image(faceIm, _get_part(s_partdb->mouths, selector, face.mouth), 0, 155); if (!armoured) { _blit_image(faceIm, _get_part(s_partdb->accessories, selector, face.accessories), 0, 0); _blit_image(faceIm, _get_part(s_partdb->hairstyles, selector, face.hairstyle), 0, 0); } else { _blit_image(faceIm, _get_part(s_partdb->armour, selector, face.armour), 0, 0); } }
int FaceParts::NumArmour(const int speciesIdx, const int raceIdx, const int genderIdx) { return _count_parts(s_partdb->armour, _make_selector(speciesIdx, raceIdx, genderIdx)); }
int FaceParts::NumAccessories(const int speciesIdx, const int raceIdx, const int genderIdx) { return _count_parts(s_partdb->accessories, _make_selector(speciesIdx, raceIdx, genderIdx)); }
int FaceParts::NumHairstyles(const int speciesIdx, const int raceIdx, const int genderIdx) { return _count_parts(s_partdb->hairstyles, _make_selector(speciesIdx, raceIdx, genderIdx)); }