Esempio n. 1
0
int ARegion::CanBeStartingCity( ARegionArray *pRA )
{
	if(type == R_OCEAN) return 0;
    if (!IsCoastal()) return 0;
    if (town && town->pop == 5000) return 0;

    int regs = 0;
    AList inlist;
    AList donelist;

    ARegionPtr * temp = new ARegionPtr;
    temp->ptr = this;
    inlist.Add(temp);

    while(inlist.Num()) {
        ARegionPtr * reg = (ARegionPtr *) inlist.First();
        for (int i=0; i<NDIRS; i++) {
            ARegion * r2 = reg->ptr->neighbors[i];
            if (!r2) continue;
            if (r2->type == R_OCEAN) continue;
            if (GetRegion(&inlist,r2->num)) continue;
            if (GetRegion(&donelist,r2->num)) continue;
            regs++;
            if (regs>20) return 1;
            ARegionPtr * temp = new ARegionPtr;
            temp->ptr = r2;
            inlist.Add(temp);
        }
        inlist.Remove(reg);
        donelist.Add(reg);
    }
    return 0;
}
Esempio n. 2
0
void ADVBConfig::ListUsers(AList& list) const
{
	AHash 	 users(10);
	AList 	 userpatterns;
	AString  filepattern 	   = GetUserPatternsPattern();
	AString  filepattern_parsed = ParseRegex(filepattern);
	AString  _users             = GetConfigItem("users");
	AStdFile fp;
	uint_t   i, n = _users.CountColumns();

	//debug("Reading users from config %s\n", config.GetFilename().str());

	for (i = 0; i < n; i++) {
		AString user = _users.Column(i).Words(0);

		if (!users.Exists(user)) {
			users.Insert(user, 0);
			list.Add(new AString(user));
		}
	}

	if (fp.open(GetPatternsFile())) {
		AString line;

		while (line.ReadLn(fp) >= 0) {
			AString user;
			int p;

			if		((p = line.PosNoCase(" user:="******"user:=") == 0)        user = line.Mid(6).Word(0).DeQuotify();

			if (user.Valid() && !users.Exists(user)) {
				users.Insert(user, 0);
				list.Add(new AString(user));
			}
		}

		fp.close();
	}

	::CollectFiles(filepattern.PathPart(), filepattern.FilePart(), 0, userpatterns);

	const AString *file = AString::Cast(userpatterns.First());
	while (file) {
		AString   user;
		ADataList regions;

		if (MatchRegex(*file, filepattern_parsed, regions)) {
			const REGEXREGION *region = (const REGEXREGION *)regions[0];

			if (region) {
				user = file->Mid(region->pos, region->len);
				if (!users.Exists(user)) {
					users.Insert(user, 0);
					list.Add(new AString(user));
				}
			}
		}

		file = file->Next();
	}

	list.Sort(&AString::AlphaCompareCase);
}
Esempio n. 3
0
int AGetName(int town, ARegion *reg)
{
	int unique, rnd, syllables, i, trail, port, similar;
	unsigned int u;
	char temp[80];
	AString *name;

	port = 0;
	if (town) {
		for (i = 0; i < NDIRS; i++)
			if (reg->neighbors[i] &&
					TerrainDefs[reg->neighbors[i]->type].similar_type == R_OCEAN)
				port = 1;
	}

	unique = 0;
	while (!unique) {
		rnd = getrandom(tSyll);
		for (syllables = 0; rnd >= syllprob[syllables]; syllables++)
			rnd -= syllprob[syllables];
		syllables++;
		temp[0] = 0;
		trail = 0;
		while (syllables-- > 0) {
			if (!syllables) {
				// Might replace the last syllable with a
				// terrain specific suffix
				rnd = getrandom(400);
				similar = TerrainDefs[reg->type].similar_type;
				// Use forest names for underforest
				if (similar == R_UFOREST)
					similar = R_FOREST;
				// ocean (water) names for lakes
				if (similar == R_LAKE)
					similar = R_OCEAN;
				// and plains names for cavern
				if (similar == R_CAVERN)
					similar = R_PLAIN;
				for (u = 0; u < sizeof(ts) / sizeof(ts[0]); u++) {
					if (ts[u].terrain == similar ||
							ts[u].terrain == -1 ||
							(ts[u].town && town) ||
							(ts[u].port && port)) {
						if (rnd >= ts[u].prob)
							rnd -= ts[u].prob;
						else {
							if (trail) {
								switch(ts[u].word[0]) {
									case 'a':
									case 'e':
									case 'i':
									case 'o':
									case 'u':
										strcat(temp, "'");
										break;
									default:
										break;
								}
							}
							strcat(temp, ts[u].word);
							break;
						}
					}
				}
				if (u < sizeof(ts) / sizeof(ts[0]))
					break;
			}
			if (getrandom(5) > 0) {
				// 4 out of 5 syllables start with a consonant sequence
				rnd = getrandom(tIC);
				for (i = 0; rnd >= ic[i].prob; i++)
					rnd -= ic[i].prob;
				strcat(temp, ic[i].word);
			} else if (trail) {
				// separate adjacent vowels
				strcat(temp, "'");
			}
			// All syllables have a vowel sequence
			rnd = getrandom(tV);
			for (i = 0; rnd >= v[i].prob; i++)
				rnd -= v[i].prob;
			strcat(temp, v[i].word);
			if (getrandom(5) > 1) {
				// 3 out of 5 syllables end with a consonant sequence
				rnd = getrandom(tFC);
				for (i = 0; rnd >= fc[i].prob; i++)
					rnd -= fc[i].prob;
				strcat(temp, fc[i].word);
				trail = 0;
			} else {
				trail = 1;
			}
		}
		temp[0] = toupper(temp[0]);
		unique = 1;
		forlist(&regionnames) {
			name = (AString *) elem;
			if (*name == temp) {
				unique = 0;
				break;
			}
		}
		if (strlen(temp) > 12)
			unique = 0;
	}

	nnames++;
	if (town)
		ntowns++;
	else
		nregions++;

	name = new AString(temp);
	regionnames.Add(name);

	return regionnames.Num();
}