public override bool CanSpawn(Team team, int clientId, out Vector2 spawnPos) { if (team == Team.Spectators || World.Paused) { spawnPos = Vector2.Zero; return(false); } var eval = new SpawnEval(); if (IsTeamplay()) { eval.FriendlyTeam = team; EvaluateSpawnType(eval, SpawnPos[1 + ((int)team & 1)]); if (!eval.Got) { EvaluateSpawnType(eval, SpawnPos[0]); if (!eval.Got) { EvaluateSpawnType(eval, SpawnPos[1 + (((int)team + 1) & 1)]); } } } else { EvaluateSpawnType(eval, SpawnPos[0]); EvaluateSpawnType(eval, SpawnPos[1]); EvaluateSpawnType(eval, SpawnPos[2]); } spawnPos = eval.Position; return(eval.Got); }
public virtual bool CanSpawn(Team team, int clientId, out Vector2 spawnPos) { if (team == Team.SPECTATORS) { spawnPos = Vector2.zero; return(false); } var eval = new SpawnEval(); if (IsTeamplay()) { eval.FriendlyTeam = team; EvaluateSpawnType(eval, SpawnPos[1 + ((int)team & 1)]); if (!eval.Got) { EvaluateSpawnType(eval, SpawnPos[0]); if (!eval.Got) { EvaluateSpawnType(eval, SpawnPos[1 + (((int)team + 1) & 1)]); } } } else { EvaluateSpawnType(eval, SpawnPos[0]); EvaluateSpawnType(eval, SpawnPos[1]); EvaluateSpawnType(eval, SpawnPos[2]); } spawnPos = eval.Pos; return(eval.Got); }
protected virtual void EvaluateSpawnType(SpawnEval eval, IList <Vector2> spawnPos) { for (var i = 0; i < spawnPos.Count; i++) { var positions = new[] { new Vector2(0.0f, 0.0f), new Vector2(-32.0f, 0.0f), new Vector2(0.0f, -32.0f), new Vector2(32.0f, 0.0f), new Vector2(0.0f, 32.0f) }; // start, left, up, right, down var result = -1; var characters = GameContext.World .FindEntities <Character>(spawnPos[i], 64f) .ToArray(); for (var index = 0; index < 5 && result == -1; ++index) { result = index; for (var c = 0; c < characters.Length; c++) { if (GameContext.Collision.IsTileSolid(spawnPos[i] + positions[index]) || Math.Distance(characters[c].Position, spawnPos[i] + positions[index]) <= characters[c].ProximityRadius) { result = -1; break; } } if (result == -1) { continue; } var p = spawnPos[i] + positions[index]; var s = EvaluateSpawnPos(eval, p); if (!eval.Got || eval.Score > s) { eval.Got = true; eval.Score = s; eval.Pos = p; } } } }
protected virtual float EvaluateSpawnPos(SpawnEval eval, Vector2 pos) { var score = 0f; foreach (var character in BaseCharacter.Entities) { var scoremod = 1f; if (eval.FriendlyTeam != Team.Spectators && character.Player.Team == eval.FriendlyTeam) { scoremod = 0.5f; } var d = MathHelper.Distance(pos, character.Position); score += scoremod * (System.Math.Abs(d) < 0.00001 ? 1000000000.0f : 1.0f / d); } return(score); }
protected virtual float EvaluateSpawnPos(SpawnEval eval, Vector2 pos) { var score = 0f; foreach (var character in GameContext.World.GetEntities <Character>()) { var scoremod = 1f; if (eval.FriendlyTeam != Team.SPECTATORS && character.Player.Team == eval.FriendlyTeam) { scoremod = 0.5f; } var d = Math.Distance(pos, character.Position); score += scoremod * (System.Math.Abs(d) < 0.00001 ? 1000000000.0f : 1.0f / d); } return(score); }