Ejemplo n.º 1
0
void StrategyMemoData::fixInvalidEntries(void) {
	StrategyMemoEntry* bySpecies[0x19b] = { NULL };
	StrategyMemoEntry* entries2[500] = { NULL };

	StrategyMemoEntry* emptyobj = entries[0]->create();

	nbEntries = 0;
	for (size_t i = 0; i < 500; ++i) {
		size_t index = (size_t)entries[i]->species;
		if ((bySpecies[index] != NULL) && (index <= 0x19b) && (getSpeciesData(entries[i]->species).isValid)) {
			bySpecies[index] = entries[i];
			entries2[nbEntries++] = entries[i];
		}
		else {
			delete entries[i];
		}
	}

	for (size_t i = 0; i < 500; ++i) {
		if (entries2[i] == NULL) entries2[i] = emptyobj->clone();
	}

	std::copy(entries2, entries2 + nbEntries, entries);
	delete emptyobj;
}
Ejemplo n.º 2
0
void StrategyMemoData::sortedBySpeciesIndex(StrategyMemoEntry* dst[0x19b]) {
	std::fill(dst, dst + 0x19b, (StrategyMemoEntry*)NULL);
	for (size_t i = 0; i < (size_t)nbEntries; ++i) {
		size_t index = (size_t)entries[i]->species;
		if ((dst[index] != NULL) && (index <= 0x19b) && (getSpeciesData(entries[i]->species).isValid)) dst[index] = entries[i];
	}
}
Ejemplo n.º 3
0
const String NameManager::makeCreatureName(int type, int species) {
	String name;
	NameData* data = getSpeciesData(species);

	// Covers all Imperial Trooper types
	if (type >= NameManagerType::STORMTROOPER && type <= NameManagerType::SWAMPTROOPER) {
		name = makeImperialTrooperName(type);
	} else {
		name = generateRandomName(data);
	}

	return name;
}
Ejemplo n.º 4
0
size_t StrategyMemoData::registerSpecies(PokemonSpeciesIndex index, u32 PID, u16 SID, u16 TID) {
	u16 i = 0;

	if (!getSpeciesData(index).isValid) return 501;
	while (i < nbEntries && index != NoSpecies && index != entries[i++]->species);
	if (i == nbEntries || nbEntries == 500) return 501;

	i = ++nbEntries - 1;
	StrategyMemoEntry* entry = entries[i];

	entry->setInfoCompleteness(true);
	entry->species = index;
	entry->firstSID = SID;
	entry->firstTID = TID;
	entry->firstPID = PID;

	return i;
}
Ejemplo n.º 5
0
size_t StrategyMemoData::recount(void) const {
	size_t i = 0;
	while (i < 500 && getSpeciesData(entries[i]->species).isValid) ++i;
	return i;
}
Ejemplo n.º 6
0
int NameManager::validateName(const String& name, int species) {
	NameData* data = getSpeciesData(species);
	NameRules* firstNameRules = data->getFirstNameRules();
	NameRules* lastNameRules = data->getLastNameRules();

	if (name.isEmpty())
		return NameManagerResult::DECLINED_EMPTY;

	int fullMaxLength = firstNameRules->getMaxChars() + lastNameRules->getMaxChars() + 1;

	if (name.length() > fullMaxLength)
		return NameManagerResult::DECLINED_RACE_INAPP;

	String firstName, lastName;

	//Split the name into first and last
	int spc = name.indexOf(" ");
	if (spc != -1) {
		firstName = name.subString(0, spc);
		lastName = name.subString(spc + 1, name.length());
	} else {
		firstName = name;
		lastName = "";
	}

	if (isProfane(name))
		return NameManagerResult::DECLINED_PROFANE;

	if (isDeveloper(name))
		return NameManagerResult::DECLINED_DEVELOPER;

	if (isFiction(name))
		return NameManagerResult::DECLINED_FICT_RESERVED;

	if (isReserved(name) || isReserved(firstName) )
		return NameManagerResult::DECLINED_RESERVED;

	if (firstName.length() < firstNameRules->getMinChars() || firstName.length() > firstNameRules->getMaxChars())
		return NameManagerResult::DECLINED_RACE_INAPP;

	// This will handle species not allowed surnames (Wookiees) if the rules have min/max set to 0
	if (lastName != "" && (lastName.length() < lastNameRules->getMinChars() || lastName.length() > lastNameRules->getMaxChars()))
		return NameManagerResult::DECLINED_RACE_INAPP;

	// Iterates through the name, looking for non alphabetic characters and comparing it to the allowed
	// special characters in the rules, also counting total characters and comparing to the max
	int specialCount = 0;
	for (int i = 0; i < firstName.length(); i++) {
		String singleChar = firstName.subString(i, i + 1);
		if (isalpha(firstName.charAt(i)) == 0) {
			if (!firstNameRules->getSpecialChars().contains(singleChar))
				return NameManagerResult::DECLINED_RACE_INAPP;
			else
				specialCount++;
		}
	}

	if (specialCount > firstNameRules->getMaxSpecialChars())
		return NameManagerResult::DECLINED_RACE_INAPP;

	if (lastName != "") {
		specialCount = 0;
		for (int i = 0; i < lastName.length(); i++) {
			String singleChar = lastName.subString(i, i + 1);
			if (isalpha(lastName.charAt(i)) == 0) {
				if (!lastNameRules->getSpecialChars().contains(singleChar))
					return NameManagerResult::DECLINED_RACE_INAPP;
				else
					specialCount++;
			}
		}

		if (specialCount > lastNameRules->getMaxSpecialChars())
			return NameManagerResult::DECLINED_RACE_INAPP;
	}

	return NameManagerResult::ACCEPTED;
}