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) 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) if (path.Count > 1 && entity.IsControlled && !State.IsInTransit)
{ {
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
evnt.Formation = entity; evnt.Formation = entity;
evnt.TargetZone = Zone.GetZoneId(path[1]); 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(); BattleLog.Instance = new BattleLog();
} }
public void OnSceneLoadDoneAll()
{
Planet.SetupPlanetPathfinding();
BoltLog.Info("Setup planet pathfinding.");
}
public void OnSceneLoadLocalDone() public void OnSceneLoadLocalDone()
{ {
if(SpawnAIPlayer) 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) public override void SceneLoadLocalDone(string scene)
{ {
GameOptions.ApplyOptions(); 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 PathfindingGraph<Zone> pathfindingGraph;
public static PathfindingGraph<Zone> PlanetPathfindingGraph;
public Zone GetMainZone(ZoneType type) public Zone GetMainZone(ZoneType type)
{ {
if (GetZones(type) == null) return null; if (GetZones(type) == null) return null;
@ -124,9 +126,22 @@ namespace GWConquest
indicatorUI = text.GetComponent<PlanetIndicatorUI>(); indicatorUI = text.GetComponent<PlanetIndicatorUI>();
indicatorUI.SetPlanet(this); 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) 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>(); objects = districts.Cast<object>();
if(CurrentPlanet.InTransitFormations.Count > 0)
if(CurrentPlanet.InTransitFormations.Count(f => f.Player == Player.CurrentPlayer) > 0)
{ {
objects = objects.Append(CurrentPlanet); objects = objects.Append(CurrentPlanet);
} }
@ -113,7 +113,7 @@ namespace GWConquest
else if(panel == SpacePanel) else if(panel == SpacePanel)
{ {
IEnumerable<Formation> fleets = CurrentPlanet.GetMainZone(ZoneType.Space).Formations; 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); 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) if(Type == ObjectType.Planet)
{ {
return Planet.InTransitFormations;
return Planet.InTransitFormations.Where(f => f.Player == Player.CurrentPlayer);
} }
else if(Type == ObjectType.District) 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 { else {
return Formation.SubFormations; return Formation.SubFormations;


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

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


Loading…
Cancel
Save