public virtual Snapshot GenerateSnapshot() { var snapshot = SnapshotUtils.GenerateGroundSnapshot(this.WorldSize, this.GetHeight); foreach (var t in Towers) { snapshot.AddEntity(SymbolicTowerTemplate.CreateSymbolicTowerEntityTemplate(t.pos.ToCoordinates(), t.height, t.radius, t.side)); } foreach (var f in Fields) { snapshot.AddEntity(FieldTemplate.CreateFieldEntityTemplate(f.pos.ToCoordinates(), f.range, f.highest, f.materialType, f.seeds)); } foreach (var u in Units) { var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, u.type, SnapshotUtils.GroundCoordinates(u.pos.x, u.pos.y, u.pos.z, this.IsBuilding(u.type) == false), u.rotate.ToCompressedQuaternion()); if (u.attachments != null) { foreach (var attach in u.attachments) { attach.AddComponent(template); } } snapshot.AddEntity(template); } return(snapshot); }
private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units) { foreach (var u in units) { var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.type); snapshot.AddEntity(template); } }
private static void AddCubeGrid(Snapshot snapshot, int cubeCount, GetSnapshotHeight ground = null) { // Calculate grid size var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount)); if (gridLength % 2 == 1) // To make sure nothing is in (0, 0) { gridLength += 1; } var cubesToSpawn = cubeCount; for (var x = -gridLength + 1; x <= gridLength - 1; x += 2) { for (var z = -gridLength + 1; z <= gridLength - 1; z += 2) { // Leave the centre empty if (x == 0 && z == 0) { continue; } // Exit when we've hit our cube limit if (cubesToSpawn-- <= 0) { return; } UnitSide side = x < 0 ? UnitSide.A : UnitSide.B; int nx; if (x < 0) { nx = x - 3; } else { nx = x + 3; } double pos_x = nx * scale; double pos_z = z * scale; var entityTemplate = BaseUnitTemplate.CreateBaseUnitEntityTemplate(side, GroundCoordinates(pos_x, pos_z, ground), UnitType.Soldier); snapshot.AddEntity(entityTemplate); } } AddDefaultUnits(snapshot, ground); }
private static void AddDefaultUnits(Snapshot snapshot, int cubeCount, TerrainCollider ground = null) { var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount)); var len = gridLength * scale; var templateA = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3, 0, ground), UnitType.Stronghold); var templateB = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3, 0, ground), UnitType.Stronghold); snapshot.AddEntity(templateA); snapshot.AddEntity(templateB); var templateCa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 2, 0, ground), UnitType.Commander); var templateCb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 2, 0, ground), UnitType.Commander); snapshot.AddEntity(templateCa); snapshot.AddEntity(templateCb); }
private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units) { foreach (var u in units) { var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, u.type, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.rotate.ToCompressedQuaternion()); if (u.attachments != null) { foreach (var attach in u.attachments) { attach.AddComponent(template); } } snapshot.AddEntity(template); //if (u.type == UnitType.HeadQuarter) //{ // template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, new Coordinates(u.pos.x, FixedParams.StrategyHeight, u.pos.z), UnitType.ArmyCloud); //} } }
private static void AddDefaultUnits(Snapshot snapshot, GetSnapshotHeight ground = null) { var gridLength = (int)Math.Ceiling(Math.Sqrt(16)); var len = gridLength * scale; var templateA = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3, 0, ground), UnitType.Stronghold); var templateB = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3, 0, ground), UnitType.Stronghold); snapshot.AddEntity(templateA); snapshot.AddEntity(templateB); var templateCa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 2, 0, ground), UnitType.Commander); var templateCb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 2, 0, ground), UnitType.Commander); snapshot.AddEntity(templateCa); snapshot.AddEntity(templateCb); var templateHa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3.5, 0, ground), UnitType.HeadQuarter); var templateHb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3.5, 0, ground), UnitType.HeadQuarter); snapshot.AddEntity(templateHa); snapshot.AddEntity(templateHb); }
private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response) { if (!ReferenceEquals(this, response.Context)) { // This response was not for a command from this behaviour. return; } if (response.StatusCode != StatusCode.Success) { logDispatcher.HandleLog(LogType.Error, new LogEvent("ReserveEntityIds failed.") .WithField("Reason", response.Message)); return; } var location = transformReader.Data.Location; var unitEntityTemplate = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, new Coordinates(location.X, location.Y + 2, location.Z), UnitType.Soldier); var expectedEntityId = response.FirstEntityId.Value; worldCommandSender.SendCreateEntityCommand( new WorldCommands.CreateEntity.Request(unitEntityTemplate, expectedEntityId), OnEntityCreated); }