Opened 7 years ago

Closed 7 years ago

#4485 closed defect (fixed)

Map ambush infinite loop

Reported by: elexis Owned by:
Priority: Must Have Milestone: Alpha 22
Component: Maps Keywords:
Cc: _kali Patch:

Description

In this map generation the map loading dialog got stuck at 22%.

start {"settings":{"PlayerData":[{"Name":"elexis4","Civ":"athen","Color":{"r":150,"g":20,"b":20},"AI":"","AIDiff":3,"Team":0},{"Name":"Hannibal_Barca (1585)","Civ":"mace","Color":{"r":64,"g":64,"b":64},"AI":"","AIDiff":3,"Team":0},{"Name":"fpre (1564)","Civ":"pers","Color":{"r":50,"g":165,"b":5},"AI":"","AIDiff":3,"Team":0},{"Name":"siole","Civ":"iber","Color":{"r":230,"g":230,"b":75},"AI":"","AIDiff":3,"Team":0},{"Name":"maxticatrix (1330)","Civ":"rome","Color":{"r":50,"g":170,"b":170},"AI":"","AIDiff":3,"Team":1},{"Name":"JeanClaude (1757)","Civ":"spart","Color":{"r":160,"g":80,"b":200},"AI":"","AIDiff":3,"Team":1},{"Name":"Grugnas (1513)","Civ":"mace","Color":{"r":235,"g":120,"b":20},"AI":"","AIDiff":3,"Team":1},{"Name":"JorgeGijon (1512)","Civ":"ptol","Color":{"r":46,"g":46,"b":200},"AI":"","AIDiff":3,"Team":1}],"CheatsEnabled":false,"CircularMap":true,"Size":320,"GameType":"conquest","VictoryScripts":["scripts/TriggerHelper.js","scripts/ConquestCommon.js","scripts/Conquest.js"],"WonderDuration":35,"PopulationCap":150,"Ceasefire":0,"StartingResources":300,"RatingEnabled":true,"LockTeams":true,"LastManStanding":false,"Name":"Ambush","Script":"ambush.js","Description":"High bluffs overlook the terrain below. Bountiful resources await on the cliffs, but beware of enemies planning an ambush.","BaseTerrain":["medit_sea_depths"],"BaseHeight":2,"Preview":"ambush.png","Keywords":["new"],"DisabledTemplates":["structures/ptol_lighthouse"],"TriggerScripts":["scripts/TriggerHelper.js","scripts/ConquestCommon.js","scripts/Conquest.js"],"mapType":"random","Seed":2125765714,"AISeed":2990578177},"map":"maps/random/ambush","mapType":"random","mapPath":"maps/random/","mapFilter":"default","gameSpeed":1,"script":"ambush.js","matchID":"ECDDD1C0481584C0","timestamp":"1485975802","engine_version":"0.0.21","mods":["mod","public","fpremod"]}

Change History (2)

comment:1 by elexis, 7 years ago

Cc: _kali added

The map instance placed 7 civic centers randomly, didn't have any space remaining for the last one and tried forever to find a suitable position.

/**
 * Chose arbitrary starting locations.
 */
function placeRandom(playerIDs)
{
	var players = [];
	var placed = [];

	for (var i = 0; i < g_MapInfo.numPlayers; ++i)
	{
		var attempts = 0;
		var playerAngle = randFloat(0, TWO_PI);
		var distance = randFloat(0, 0.42);
		var x = 0.5 + distance * cos(playerAngle);
		var z = 0.5 + distance * sin(playerAngle);

		var tooClose = false;
		for (var j = 0; j < placed.length; ++j)
		{
			var sep = getDistance(x, z, placed[j].x, placed[j].z);
			if (sep < 0.25)
			{
				tooClose = true;
				break;
			}
		}

		if (tooClose)
		{
			--i;
			++attempts;

			// Reset if we're in what looks like an infinite loop
			if (attempts > 100)
			{
				players = [];
				placed = [];
				i = -1;
				attempts = 0;
			}

			continue;
		}

		players[i] = {
			"id": playerIDs[i],
			"angle": playerAngle,
			"x": x,
			"z": z
		};

		placed.push(players[i]);
	}

	// Create the bases
	for (var i = 0; i < g_MapInfo.numPlayers; ++i)
		createBase(players[i]);

	return players;
}

Created https://code.wildfiregames.com/D118 as it was trivial to fix, the attempts variable needs to be defined outside of the loop.

comment:2 by elexis, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.