Browse Source

Pathfinding für Planeten

bolt_update
laurids 3 years ago
parent
commit
26609d1d40
8 changed files with 629 additions and 451 deletions
  1. +585
    -433
      Assets/GWConquest/Scenes/GalaxyMap.unity
  2. +13
    -12
      Assets/GWConquest/Scripts/Formation.cs
  3. +7
    -0
      Assets/GWConquest/Scripts/GameManager.cs
  4. +2
    -0
      Assets/GWConquest/Scripts/GlobalCallbacks.cs
  5. +15
    -0
      Assets/GWConquest/Scripts/Planet.cs
  6. +2
    -2
      Assets/GWConquest/Scripts/UI/TransportUI.cs
  7. +2
    -2
      Assets/GWConquest/Scripts/UI/TransportUIElement.cs
  8. +3
    -2
      Assets/GWConquest/Textures/UI/kreiswichs3.png.meta

+ 585
- 433
Assets/GWConquest/Scenes/GalaxyMap.unity
File diff suppressed because it is too large
View File


+ 13
- 12
Assets/GWConquest/Scripts/Formation.cs View File

@ -133,18 +133,20 @@ namespace GWConquest
public void TryMoveToPlanet(Planet planet)
{
if(entity.IsControlled && !State.IsInTransit
&& currentZone.planet.IsConnectedTo(planet))
if(currentZone.zoneType == ZoneType.Space)
{
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
evnt.Formation = entity;
evnt.TargetZone = Zone.GetZoneId(planet.GetMainZone(ZoneType.Space));
evnt.Send();
}
else
{
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2}) to planet {3}",
this, entity.IsControlled, State.IsInTransit, planet);
var targetZone = planet.GetMainZone(ZoneType.Space);
var shortestPath = Planet.PlanetPathfindingGraph.FindShortestPath(this, currentZone, targetZone);
if(shortestPath != null)
{
StartMovingOnPath(shortestPath.zones);
}
else
{
BoltLog.Warn("No path found between {0} and {1}", currentZone.planet, planet);
}
}
}
@ -152,7 +154,6 @@ namespace GWConquest
{
if (path.Count > 1 && entity.IsControlled && !State.IsInTransit)
{
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
evnt.Formation = entity;
evnt.TargetZone = Zone.GetZoneId(path[1]);


+ 7
- 0
Assets/GWConquest/Scripts/GameManager.cs View File

@ -58,6 +58,12 @@ namespace GWConquest
BattleLog.Instance = new BattleLog();
}
public void OnSceneLoadDoneAll()
{
Planet.SetupPlanetPathfinding();
BoltLog.Info("Setup planet pathfinding.");
}
public void OnSceneLoadLocalDone()
{
if(SpawnAIPlayer)
@ -77,6 +83,7 @@ namespace GWConquest
}
BoltLog.Info("Scene load done.");
}
}

+ 2
- 0
Assets/GWConquest/Scripts/GlobalCallbacks.cs View File

@ -16,6 +16,8 @@ namespace GWConquest
public override void SceneLoadLocalDone(string scene)
{
GameOptions.ApplyOptions();
GameManager.Instance.OnSceneLoadDoneAll();
}
}
}

+ 15
- 0
Assets/GWConquest/Scripts/Planet.cs View File

@ -65,6 +65,8 @@ namespace GWConquest
public PathfindingGraph<Zone> pathfindingGraph;
public static PathfindingGraph<Zone> PlanetPathfindingGraph;
public Zone GetMainZone(ZoneType type)
{
if (GetZones(type) == null) return null;
@ -124,9 +126,22 @@ namespace GWConquest
indicatorUI = text.GetComponent<PlanetIndicatorUI>();
indicatorUI.SetPlanet(this);
}
Debug.LogFormat("Planet {0} loaded", planetName);
}
}
public static void SetupPlanetPathfinding()
{
var spaceZones = AllPlanets.Select((p,i) => p.GetMainZone(ZoneType.Space));
PlanetPathfindingGraph = new PathfindingGraph<Zone>(spaceZones);
foreach(PlanetConnection conn in FindObjectsOfType<PlanetConnection>())
{
float connLength = Vector3.Distance(conn.planet1.transform.position, conn.planet2.transform.position);
PlanetPathfindingGraph.AddConnection(conn.planet1.GetMainZone(ZoneType.Space), conn.planet2.GetMainZone(ZoneType.Space), connLength);
}
}
public IEnumerable<Formation> GetAllFormations(ZoneType zoneType)


+ 2
- 2
Assets/GWConquest/Scripts/UI/TransportUI.cs View File

@ -104,7 +104,7 @@ namespace GWConquest
objects = districts.Cast<object>();
if(CurrentPlanet.InTransitFormations.Count > 0)
if(CurrentPlanet.InTransitFormations.Count(f => f.Player == Player.CurrentPlayer) > 0)
{
objects = objects.Append(CurrentPlanet);
}
@ -113,7 +113,7 @@ namespace GWConquest
else if(panel == SpacePanel)
{
IEnumerable<Formation> fleets = CurrentPlanet.GetMainZone(ZoneType.Space).Formations;
fleets = fleets.Where(f => f.ZoneType == ZoneType.Space);
fleets = fleets.Where(f => f.Player == Player.CurrentPlayer && f.ZoneType == ZoneType.Space);
itemStacks = fleets.SelectMany(f => f.AllItems);


+ 2
- 2
Assets/GWConquest/Scripts/UI/TransportUIElement.cs View File

@ -82,11 +82,11 @@ namespace GWConquest
{
if(Type == ObjectType.Planet)
{
return Planet.InTransitFormations;
return Planet.InTransitFormations.Where(f => f.Player == Player.CurrentPlayer);
}
else if(Type == ObjectType.District)
{
return District.Zone.Formations.Where(f => !f.IsEmbarked);
return District.Zone.Formations.Where(f => f.Player == Player.CurrentPlayer && !f.IsEmbarked);
}
else {
return Formation.SubFormations;


+ 3
- 2
Assets/GWConquest/Textures/UI/kreiswichs3.png.meta View File

@ -3,10 +3,10 @@ guid: 9d02af9561347c349986baae6fb1fa27
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
@ -57,6 +57,7 @@ TextureImporter:
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform


Loading…
Cancel
Save