public World(GraphicsDevice device, int Seed) { this.Entities = new List <MapEntity>(); this._deadEntities = new List <MapEntity>(); this.Terrain = new Terrain.Terrain(Interfaces.WorldPosition.Stride, Seed); // ModelEffect = new BasicEffect(device); }
private bool RocketCollidedWithPlanet(Terrain.Terrain planet, List <PointF> corners) { foreach (var corner in corners) { if (PointCalculator.Distance(corner, planet.Location) < planet.Diameter) { return(true); } } return(false); }
public void Show(Terrain.Terrain terrain) { TerrainNameText.text = terrain.DisplayName; HitPercentageText.text = "Hit: " + terrain.HitPercentageBoost + "%"; DefenseText.text = "Def: " + terrain.DefenseBoost + "%"; MovementCostText.text = "Move: " + terrain.MovementCost; transform.position = new Vector2(terrain.transform.position.x, terrain.transform.position.y + 1); if (!transform.gameObject.activeSelf) { transform.gameObject.SetActive(true); } }
/// <summary> /// Update the information panels (e.g. character/terrain) based on the current position. /// </summary> private void UpdateInformationPanels() { Character character = GameManager.CurrentLevel.GetCharacter(transform.position); if (character != null) { GameManager.CharacterInformationPanel.Show(character); } else { GameManager.CharacterInformationPanel.Hide(); } Terrain.Terrain terrain = GameManager.CurrentLevel.GetTerrain(transform.position); GameManager.TerrainInformationPanel.Show(terrain); }
public void SetTerrain(Transform transform, float x, float y) { if (IsOutOfBounds(x, y)) { Debug.LogErrorFormat("Position is out of bounds: ({0},{1})", x, y); return; } Terrain.Terrain terrain = TerrainMap[(int)x, (int)y]; if (terrain) { Destroy(terrain.gameObject); } TerrainMap[(int)x, (int)y] = Create <Terrain.Terrain>(transform); }
/// <summary> /// Calculate the damage done by the attack Character with the specified weapon and the defense Character /// /// </summary> /// <param name="attackCharacter"></param> /// <param name="attackWeapon"></param> /// <param name="defenseCharacter"></param> /// <returns></returns> public int CalculateDamage(Weapon attackWeapon, Character defenseCharacter, Weapon defenseWeapon) { Terrain.Terrain terrain = GameManager.CurrentLevel.GetTerrain(defenseCharacter.transform.position); int damage = attackWeapon.CalculateDamage(this, defenseCharacter, defenseWeapon) - terrain.DefenseBoost; if (attackWeapon is StrengthWeapon) { damage += Strength - defenseCharacter.Defense; } else if (attackWeapon is Items.Weapons.Attackable.Magic.Magic) { damage += Magic - defenseCharacter.Resistance; } else { Debug.LogErrorFormat("Unknown weapon type: {0}", attackWeapon.GetType().Name); } return(Mathf.Max(damage, 0)); }
private HashSet <Vector2> CalculateMovablePositions(float x, float y, int remainingMoves) { HashSet <Vector2> movableSpaces = new HashSet <Vector2>(); Character character = GameManager.CurrentLevel.GetCharacter(x, y); Terrain.Terrain terrain = GameManager.CurrentLevel.GetTerrain(x, y); remainingMoves -= CalculateMovementCost(x, y); if (remainingMoves < 0 || GameManager.CurrentLevel.IsOutOfBounds(x, y) || !terrain.IsPassable(this, x, y) || (character != null && !character.Player.Equals(Player))) { return(movableSpaces); } _ = movableSpaces.Add(new Vector2(x, y)); movableSpaces.UnionWith(CalculateMovablePositions(x - 1, y, remainingMoves)); movableSpaces.UnionWith(CalculateMovablePositions(x + 1, y, remainingMoves)); movableSpaces.UnionWith(CalculateMovablePositions(x, y - 1, remainingMoves)); movableSpaces.UnionWith(CalculateMovablePositions(x, y + 1, remainingMoves)); return(movableSpaces); }
/// <summary> /// Calculates the cost for this character to move to the given position. /// </summary> /// <param name="position">The position for which to determine the cost</param> /// <returns>The cost for this character to move to the given position</returns> protected virtual int CalculateMovementCost(float x, float y) { int cost; if (GameManager.CurrentLevel.IsOutOfBounds(x, y)) { cost = int.MaxValue; } else if (transform.position.x == x && transform.position.y == y) { cost = 0; } else { Terrain.Terrain terrain = GameManager.CurrentLevel.GetTerrain(x, y); cost = terrain.MovementCost; } return(cost); }
public Tank(Vector3 initialPosition, Terrain.Terrain terrain, string scenePath) { var loader = new TgcSceneLoader { MeshFactory = new MeshShaderFactory() }; var scene = loader.loadSceneFromFile(scenePath); this.mesh = (MeshShader) scene.Meshes[0]; this.loadShader(); this.terrain = terrain; missilesShooted = new List<Missile>(); this.boundingSphere = new TgcBoundingSphere(this.mesh.BoundingBox.calculateBoxCenter(), this.mesh.BoundingBox.calculateBoxRadius()*3); this.mesh.AutoTransformEnable = this.mesh.AutoUpdateBoundingBox = false; this.translationMatrix = Matrix.Identity; this.Position = initialPosition; this.setTranslationMatrix(initialPosition); this.totalSpeed = 0f; this.totalRotationSpeed = 100f; this.forwardVector = new Vector3(0, 0, -1); }
protected override Scene3D LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions) { switch (contentManager.SageGame) { case SageGame.Ra3: case SageGame.Ra3Uprising: case SageGame.Cnc4: // TODO break; default: contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini"); break; } var mapFile = MapFile.FromFileSystemEntry(entry); var heightMap = new HeightMap(mapFile.HeightMapData); var indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(contentManager.GraphicsDevice)); var tileDataTexture = AddDisposable(CreateTileDataTexture( contentManager.GraphicsDevice, mapFile, heightMap)); var cliffDetailsBuffer = AddDisposable(CreateCliffDetails( contentManager.GraphicsDevice, mapFile)); CreateTextures( contentManager, mapFile.BlendTileData, out var textureArray, out var textureDetails); var textureDetailsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticStructuredBuffer(textureDetails)); var terrainMaterial = AddDisposable(new TerrainMaterial(contentManager, contentManager.EffectLibrary.Terrain)); terrainMaterial.SetTileData(tileDataTexture); terrainMaterial.SetCliffDetails(cliffDetailsBuffer); terrainMaterial.SetTextureDetails(textureDetailsBuffer); terrainMaterial.SetTextureArray(textureArray); var terrainPatches = CreatePatches( contentManager.GraphicsDevice, heightMap, mapFile.BlendTileData, terrainMaterial, indexBufferCache); var cloudTextureName = mapFile.EnvironmentData?.CloudTexture ?? "tscloudmed.dds"; var cloudTexture = contentManager.Load <Texture>(Path.Combine("Art", "Textures", cloudTextureName)); var macroTextureName = mapFile.EnvironmentData?.MacroTexture ?? "tsnoiseurb.dds"; var macroTexture = contentManager.Load <Texture>(Path.Combine("Art", "Textures", macroTextureName)); var materialConstantsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer( new TerrainMaterial.TerrainMaterialConstants { MapBorderWidth = new Vector2(mapFile.HeightMapData.BorderWidth, mapFile.HeightMapData.BorderWidth) * HeightMap.HorizontalScale, MapSize = new Vector2(mapFile.HeightMapData.Width, mapFile.HeightMapData.Height) * HeightMap.HorizontalScale, IsMacroTextureStretched = false // TODO: This must be one of the EnvironmentData unknown values. }, BufferUsage.UniformBuffer)); terrainMaterial.SetMaterialConstants(materialConstantsBuffer); var terrain = new Terrain.Terrain( heightMap, terrainPatches, cloudTexture, macroTexture, contentManager.SolidWhiteTexture); var players = Player.FromMapData(mapFile.SidesList.Players, contentManager).ToArray(); var teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items) .Select(team => Team.FromMapData(team, players)) .ToArray(); LoadObjects( contentManager, heightMap, mapFile.ObjectsList.Objects, teams, out var waypoints, out var gameObjects); var lighting = new WorldLighting( mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(), mapFile.GlobalLighting.Time); var waypointPaths = new WaypointPathCollection(mapFile.WaypointsList.WaypointPaths .Select(path => { var start = waypoints[path.StartWaypointID]; var end = waypoints[path.EndWaypointID]; return(new Settings.WaypointPath(start, end)); })); // TODO: Don't hardcode this. // Perhaps add one ScriptComponent for the neutral player, // and one for the active player. var scriptList = mapFile.GetPlayerScriptsList().ScriptLists[0]; var mapScripts = CreateScripts(scriptList); var cameraController = new RtsCameraController(contentManager) { TerrainPosition = terrain.HeightMap.GetPosition( terrain.HeightMap.Width / 2, terrain.HeightMap.Height / 2) }; contentManager.GraphicsDevice.WaitForIdle(); return(new Scene3D( game, cameraController, mapFile, terrain, mapScripts, gameObjects, waypoints, waypointPaths, lighting, players, teams)); }
protected override Scene3D LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions) { switch (contentManager.SageGame) { case SageGame.Ra3: case SageGame.Ra3Uprising: case SageGame.Cnc4: // TODO break; default: contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini"); contentManager.IniDataContext.LoadIniFile(@"Data\INI\Roads.ini"); break; } var mapFile = MapFile.FromFileSystemEntry(entry); var heightMap = new HeightMap(mapFile.HeightMapData); var indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(contentManager.GraphicsDevice)); var tileDataTexture = AddDisposable(CreateTileDataTexture( contentManager.GraphicsDevice, mapFile, heightMap)); var cliffDetailsBuffer = AddDisposable(CreateCliffDetails( contentManager.GraphicsDevice, mapFile)); CreateTextures( contentManager, mapFile.BlendTileData, out var textureArray, out var textureDetails); var textureDetailsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticStructuredBuffer(textureDetails)); var terrainPipeline = contentManager.ShaderResources.Terrain.Pipeline; Texture LoadTexture(string name) { var texture = contentManager.Load <Texture>(Path.Combine("Art", "Textures", name), fallbackToPlaceholder: false); if (texture == null) { texture = contentManager.Load <Texture>(Path.Combine("Art", "CompiledTextures", name.Substring(0, 2), name)); } return(texture); } var materialConstantsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer( new TerrainShaderResources.TerrainMaterialConstants { MapBorderWidth = new Vector2(mapFile.HeightMapData.BorderWidth, mapFile.HeightMapData.BorderWidth) * HeightMap.HorizontalScale, MapSize = new Vector2(mapFile.HeightMapData.Width, mapFile.HeightMapData.Height) * HeightMap.HorizontalScale, IsMacroTextureStretched = false // TODO: This must be one of the EnvironmentData unknown values. }, BufferUsage.UniformBuffer)); var macroTexture = LoadTexture(mapFile.EnvironmentData?.MacroTexture ?? "tsnoiseurb.dds"); var materialResourceSet = AddDisposable(contentManager.ShaderResources.Terrain.CreateMaterialResourceSet( materialConstantsBuffer, tileDataTexture, cliffDetailsBuffer ?? contentManager.GetNullStructuredBuffer(TerrainShaderResources.CliffInfo.Size), textureDetailsBuffer, textureArray, macroTexture)); var terrainPatches = CreatePatches( contentManager.GraphicsDevice, heightMap, mapFile.BlendTileData, indexBufferCache, materialResourceSet); var cloudTexture = LoadTexture(mapFile.EnvironmentData?.CloudTexture ?? "tscloudmed.dds"); cloudTexture.Name = "Cloud texture"; var cloudResourceLayout = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateResourceLayout( new ResourceLayoutDescription( new ResourceLayoutElementDescription("Global_CloudTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment)))); var cloudResourceSet = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateResourceSet( new ResourceSetDescription( cloudResourceLayout, cloudTexture))); cloudResourceSet.Name = "Cloud resource set"; var terrain = new Terrain.Terrain( heightMap, terrainPatches, contentManager.ShaderResources.Terrain.ShaderSet, terrainPipeline, cloudResourceSet); var players = Player.FromMapData(mapFile.SidesList.Players, contentManager).ToArray(); var teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items) .Select(team => Team.FromMapData(team, players)) .ToArray(); LoadObjects( contentManager, heightMap, mapFile.ObjectsList.Objects, teams, out var waypoints, out var gameObjects, out var roads, out var bridges); var waterAreas = new List <WaterArea>(); if (mapFile.PolygonTriggers != null) { foreach (var polygonTrigger in mapFile.PolygonTriggers.Triggers) { switch (polygonTrigger.TriggerType) { case PolygonTriggerType.Water: case PolygonTriggerType.River: // TODO: Handle this differently. Water texture should be animated "downstream". case PolygonTriggerType.WaterAndRiver: if (WaterArea.TryCreate(contentManager, polygonTrigger, out var waterArea)) { waterAreas.Add(AddDisposable(waterArea)); } break; } } } var lighting = new WorldLighting( mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(), mapFile.GlobalLighting.Time); var waypointPaths = new WaypointPathCollection(mapFile.WaypointsList.WaypointPaths .Select(path => { var start = waypoints[path.StartWaypointID]; var end = waypoints[path.EndWaypointID]; return(new Settings.WaypointPath(start, end)); })); // TODO: Don't hardcode this. // Perhaps add one ScriptComponent for the neutral player, // and one for the active player. var scriptList = mapFile.GetPlayerScriptsList().ScriptLists[0]; var mapScripts = CreateScripts(scriptList); var cameraController = new RtsCameraController(contentManager) { TerrainPosition = terrain.HeightMap.GetPosition( terrain.HeightMap.Width / 2, terrain.HeightMap.Height / 2) }; contentManager.GraphicsDevice.WaitForIdle(); return(new Scene3D( game, game.InputMessageBuffer, () => game.Viewport, cameraController, mapFile, terrain, waterAreas.ToArray(), roads, bridges, mapScripts, gameObjects, waypoints, waypointPaths, lighting, players, teams)); }
protected override void Init() { CharacterMap = new Character[1, 1]; TerrainMap = new Terrain.Terrain[2, 2]; }
internal World(Terrain.Terrain terrain) { Terrain = terrain; }
/// <summary> /// Initialize the terrain map and characters. Should only be called by Level.Init(GameManager,Player,Player) /// </summary> protected override void Init() { TerrainMap = new Terrain.Terrain[4, 4]; CharacterMap = new Character[4, 4]; TerrainMap[0, 0] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[0, 1] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[0, 2] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[0, 3] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[1, 0] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[1, 1] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[1, 2] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[1, 3] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[2, 0] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[2, 1] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[2, 2] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[2, 3] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[3, 0] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[3, 1] = Create <Terrain.Terrain>(GameManager.GrassTerrain); TerrainMap[3, 2] = Create <Terrain.Terrain>(GameManager.WallTerrain); TerrainMap[3, 3] = Create <Terrain.Terrain>(GameManager.ForrestTerrain); CharacterMap[0, 0] = Create <Character>(GameManager.KnightPrefab); CharacterMap[0, 0].Player = AiPlayer; CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].Items.Add(IronSword.Create()); CharacterMap[0, 0].AddProficiency(new Proficiency(typeof(Sword), Proficiency.Rank.E)); CharacterMap[0, 1] = Create <Character>(GameManager.KnightPrefab); CharacterMap[0, 1].Player = AiPlayer; CharacterMap[0, 1].Items.Add(IronSword.Create()); CharacterMap[0, 2] = Create <Character>(GameManager.KnightPrefab); CharacterMap[0, 2].Player = AiPlayer; CharacterMap[0, 2].Items.Add(IronSword.Create()); CharacterMap[0, 3] = Create <Character>(GameManager.KnightPrefab); CharacterMap[0, 3].Player = AiPlayer; CharacterMap[0, 3].Items.Add(IronSword.Create()); CharacterMap[2, 3] = Create <Character>(GameManager.KnightPrefab); CharacterMap[2, 3].Player = AiPlayer; CharacterMap[2, 3].Items.Add(IronSword.Create()); CharacterMap[1, 2] = Create <Character>(GameManager.WizardPrefab); CharacterMap[1, 2].Player = AiPlayer; CharacterMap[1, 2].Items.Add(IronSword.Create()); CharacterMap[1, 2].Items.Add(Incinerate.Create()); CharacterMap[2, 2] = Create <Character>(GameManager.WizardPrefab); CharacterMap[2, 2].Player = HumanPlayer; CharacterMap[2, 2].Items.Add(IronSword.Create()); CharacterMap[2, 2].Items.Add(Fire.Create()); CharacterMap[2, 2].AddProficiency(new Proficiency(typeof(FireMagic), Proficiency.Rank.E)); CharacterMap[2, 2].AddProficiency(new Proficiency(typeof(HealingStaff), Proficiency.Rank.E)); CharacterMap[2, 1] = Create <Character>(GameManager.WizardPrefab); CharacterMap[2, 1].Player = HumanPlayer; CharacterMap[2, 1].CurrentHp = 10; CharacterMap[2, 1].AddProficiency(new Proficiency(typeof(HealingStaff), Proficiency.Rank.E)); CharacterMap[2, 1].Items.Add(Fire.Create()); CharacterMap[2, 1].AddProficiency(new Proficiency(typeof(FireMagic), Proficiency.Rank.E)); CharacterMap[3, 3] = Create <Character>(GameManager.KnightPrefab); CharacterMap[3, 3].Player = AiPlayer; CharacterMap[3, 3].Items.Add(IronAxe.Create()); StartPosition = new Vector2(0, 0); }
protected override Scene LoadEntry(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions) { contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini"); var mapFile = MapFile.FromFileSystemEntry(entry); var result = new Scene(); result.MapFile = mapFile; result.Settings.LightingConfigurations = mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(); result.Settings.TimeOfDay = mapFile.GlobalLighting.Time; var heightMap = new HeightMap(mapFile.HeightMapData); result.HeightMap = heightMap; var indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(contentManager.GraphicsDevice)); var tileDataTexture = AddDisposable(CreateTileDataTexture( contentManager.GraphicsDevice, mapFile, heightMap)); var cliffDetailsBuffer = AddDisposable(CreateCliffDetails( contentManager.GraphicsDevice, mapFile)); CreateTextures( contentManager, mapFile.BlendTileData, out var textureArray, out var textureDetails); var textureDetailsBuffer = AddDisposable(Buffer <TextureInfo> .CreateStatic( contentManager.GraphicsDevice, textureDetails, BufferBindFlags.ShaderResource)); var terrainMaterial = new TerrainMaterial(contentManager.EffectLibrary.Terrain); terrainMaterial.SetTileData(tileDataTexture); terrainMaterial.SetCliffDetails(cliffDetailsBuffer); terrainMaterial.SetTextureDetails(textureDetailsBuffer); terrainMaterial.SetTextureArray(textureArray); var terrainPatches = CreatePatches( contentManager.GraphicsDevice, heightMap, mapFile.BlendTileData, terrainMaterial, indexBufferCache); var terrain = new Terrain.Terrain(heightMap, terrainPatches); var world = new World(terrain); result.Scene3D = new Scene3D(world); var objectsEntity = new Entity(); result.Entities.Add(objectsEntity); LoadObjects( contentManager, objectsEntity, heightMap, mapFile.ObjectsList.Objects, result.Settings); foreach (var team in mapFile.SidesList.Teams ?? mapFile.Teams.Items) { var name = (string)team.Properties["teamName"].Value; var owner = (string)team.Properties["teamOwner"].Value; var isSingleton = (bool)team.Properties["teamIsSingleton"].Value; // TODO } var waypointPaths = mapFile.WaypointsList.WaypointPaths.Select(path => { var start = result.Settings.Waypoints[path.StartWaypointID]; var end = result.Settings.Waypoints[path.EndWaypointID]; return(new Settings.WaypointPath(start, end)); }).ToList(); result.Settings.WaypointPaths = new WaypointPathCollection(waypointPaths); var scriptsEntity = new Entity(); result.Entities.Add(scriptsEntity); // TODO: Don't hardcode this. // Perhaps add one ScriptComponent for the neutral player, // and one for the active player. var scriptList = (mapFile.SidesList.PlayerScripts ?? mapFile.PlayerScriptsList).ScriptLists[0]; AddScripts(scriptsEntity, scriptList, result.Settings); return(result); }
/// <summary> /// Construct the world. /// </summary> /// <param name="terrain">The terrain within the simulation, already instantiated.</param> public World(Terrain.Terrain terrain) { this.Terrain = terrain; }