File diff r4608:cbac9c94e467 → r4609:43908f0c2b9c
players.c
Show inline comments
 
@@ -323,49 +323,49 @@ static void GenerateCompanyName(Player *
 
	Town *t;
 
	StringID str;
 
	Player *pp;
 
	uint32 strp;
 
	char buffer[100];
 

	
 
	if (p->name_1 != STR_SV_UNNAMED) return;
 

	
 
	tile = p->last_build_coordinate;
 
	if (tile == 0) return;
 

	
 
	t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
	if (IS_INT_INSIDE(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST+1)) {
 
		str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START;
 
		strp = t->townnameparts;
 

	
 
verify_name:;
 
		// No player must have this name already
 
		FOR_ALL_PLAYERS(pp) {
 
			if (pp->name_1 == str && pp->name_2 == strp) goto bad_town_name;
 
		}
 

	
 
		GetString(buffer, str);
 
		if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 150)
 
		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 150)
 
			goto bad_town_name;
 

	
 
set_name:;
 
		p->name_1 = str;
 
		p->name_2 = strp;
 

	
 
		MarkWholeScreenDirty();
 

	
 
		if (!IS_HUMAN_PLAYER(p->index)) {
 
			SetDParam(0, t->index);
 
			AddNewsItem(p->index + (4 << 4), NEWS_FLAGS(NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY), p->last_build_coordinate, 0);
 
		}
 
		return;
 
	}
 
bad_town_name:;
 

	
 
	if (p->president_name_1 == SPECSTR_PRESIDENT_NAME) {
 
		str = SPECSTR_ANDCO_NAME;
 
		strp = p->president_name_2;
 
		goto set_name;
 
	} else {
 
		str = SPECSTR_ANDCO_NAME;
 
		strp = Random();
 
		goto verify_name;
 
@@ -430,49 +430,49 @@ static byte GeneratePlayerColor(void)
 
			}
 
			break;
 
		}
 
	}
 

	
 
	// Return the first available color
 
	for (i = 0;; i++) {
 
		if (colors[i] != 0xFF) return colors[i];
 
	}
 
}
 

	
 
static void GeneratePresidentName(Player *p)
 
{
 
	Player *pp;
 
	char buffer[100], buffer2[40];
 

	
 
	for (;;) {
 
restart:;
 

	
 
		p->president_name_2 = Random();
 
		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
 

	
 
		SetDParam(0, p->president_name_2);
 
		GetString(buffer, p->president_name_1);
 
		if (strlen(buffer) >= 32 || GetStringWidth(buffer) >= 94)
 
		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
 
			continue;
 

	
 
		FOR_ALL_PLAYERS(pp) {
 
			if (pp->is_active && p != pp) {
 
				SetDParam(0, pp->president_name_2);
 
				GetString(buffer2, pp->president_name_1);
 
				if (strcmp(buffer2, buffer) == 0)
 
					goto restart;
 
			}
 
		}
 
		return;
 
	}
 
}
 

	
 
static Player *AllocatePlayer(void)
 
{
 
	Player *p;
 
	// Find a free slot
 
	FOR_ALL_PLAYERS(p) {
 
		if (!p->is_active) {
 
			int i = p->index;
 
			memset(p, 0, sizeof(Player));
 
			p->index = i;
 
			return p;