-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started to add cities, improved civ implementation
- Loading branch information
Showing
58 changed files
with
872 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
namespace Progression.Engine.Core.City | ||
using System; | ||
using Progression.Engine.Core.World; | ||
using Progression.Engine.Core.World.Features.Base; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class City | ||
{ | ||
public City(Tile tile, string name, Civilization.Civilization owner) | ||
{ | ||
Tile = tile; | ||
Name = name; | ||
Owner = owner; | ||
} | ||
public Tile Tile{ get; private set; } | ||
public string Name { get; private set; } | ||
public Civilization.Civilization Owner { get; private set; } | ||
|
||
public void SetOwner(Civilization.Civilization owner, bool remoteUpdate = false) | ||
{ | ||
Owner = owner; | ||
if (!remoteUpdate)Tile.World.ScheduleUpdate(new CityOwnerUpdate(this, owner)); | ||
} | ||
public void SetName(string name, bool remoteUpdate = false) | ||
{ | ||
Name = name; | ||
if (!remoteUpdate)Tile.World.ScheduleUpdate(new CityNameUpdate(this, name)); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Progression.Engine.Core.World.Features.Base; | ||
using Progression.Util.Keys; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class CityFeature : IFeature<CityFeature> { | ||
public CityFeature(CityFeatureResolver resolver) | ||
{ | ||
Resolver = resolver; | ||
} | ||
|
||
|
||
public Key Key => Resolver.CityKey; | ||
public string Name => "City"; | ||
public CityFeatureResolver Resolver { get; } | ||
|
||
IFeatureResolver IFeature.Resolver => Resolver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Progression.Engine.Core.World; | ||
using Progression.Engine.Core.World.Features.Base; | ||
using Progression.Resource; | ||
using Progression.Util.Generics; | ||
using Progression.Util.Keys; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class CityFeatureResolver : IFeatureResolver<CityFeature> | ||
{ | ||
public CityFeatureResolver(WorldType worldType, Key key) | ||
{ | ||
WorldType = worldType; | ||
Key = key; | ||
CityKey = new Key(Key, "CityFeature"); | ||
DummyFeature = new CityFeature(this); | ||
} | ||
public CityFeature DummyFeature { get; } | ||
public WorldType WorldType { get; } | ||
public DataIdentifier DataIdentifier { get; private set; } | ||
|
||
|
||
public Key Key { get; } | ||
public Key CityKey { get; } | ||
|
||
public DataIdentifier[] GenerateIdentifiers() | ||
{ | ||
DataIdentifier = new DataIdentifier(this, DummyFeature, 0, 1, WorldType); | ||
return new[] {DataIdentifier}; | ||
} | ||
|
||
public DataIdentifier GetIdentifier(int index) => index == 0 ? DataIdentifier : throw new IndexOutOfRangeException($"{index} > 0"); | ||
|
||
#region Hidden | ||
|
||
public void Freeze(FeatureWorld fw) | ||
{ | ||
FeatureWorld = fw; | ||
} | ||
|
||
public int Count => 1; | ||
public FeatureWorld FeatureWorld { get; private set; } | ||
public IEnumerator<CityFeature> GetEnumerator() => new SingleItemEnumerator<CityFeature>(DummyFeature); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
IFeature IFeatureResolver.Get(int index) => Get(index); | ||
|
||
public CityFeature Get(int index) => DummyFeature; | ||
|
||
|
||
IEnumerable<IKeyNameable> IResourceable.GetResourceables() => new BaseTypeEnumerableWrapper<CityFeature,IKeyNameable>(this); | ||
IEnumerable<CityFeature> IResourceable<CityFeature>.GetResourceables() => this; | ||
public bool IsFrozen => true; | ||
#endregion | ||
|
||
public bool HasCity(Tile tile) | ||
{ | ||
return tile[DataIdentifier] == 1; | ||
} | ||
|
||
public void AddCity(City city, bool remoteUpdate = false) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Progression.Engine.Core.World; | ||
using Progression.Util.Keys; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class CityManager | ||
{ | ||
private readonly Dictionary<Coordinate, City> _cities; | ||
|
||
public CityManager(CityFeatureResolver resolver) | ||
{ | ||
Resolver = resolver; | ||
_cities = new Dictionary<Coordinate, City>(); | ||
} | ||
|
||
public CityFeatureResolver Resolver { get; } | ||
|
||
public bool HasCity(Tile tile) | ||
{ | ||
return Resolver.HasCity(tile); | ||
} | ||
|
||
public City GetCity(Tile tile) | ||
{ | ||
if (_cities.TryGetValue(tile.Coordinate, out var result)) throw new ArgumentException("No city on this tile"); | ||
return result; | ||
} | ||
|
||
public void AddCity(City city, bool founded, bool remoteUpdate = false) | ||
{ | ||
if (HasCity(city.Tile)) throw new ArgumentException("There is already a city"); | ||
_cities.Add(city.Tile.Coordinate, city); | ||
if (!remoteUpdate) city.Tile.World.ScheduleUpdate(new AddCityUpdate(city.Tile.Coordinate, city.Name, city.Owner, founded)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Progression.Engine.Core.World; | ||
using Progression.Engine.Core.World.Threading; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class AddCityUpdate : TileUpdateBase | ||
{ | ||
public AddCityUpdate(Coordinate coordinate, string name, Civilization.Civilization owner, bool justFounded) : base(coordinate) | ||
{ | ||
Owner = owner; | ||
JustFounded = justFounded; | ||
Name = name; | ||
} | ||
|
||
public string Name { get; } | ||
public Civilization.Civilization Owner { get; } | ||
public bool JustFounded { get; } | ||
public override void Execute(WorldInterface @on) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Progression.Engine.Core.World.Threading; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class CityNameUpdate : CityUpdateBase | ||
{ | ||
public CityNameUpdate(City city, string newName) : base(city) | ||
{ | ||
NewName = newName; | ||
} | ||
|
||
public string NewName { get; } | ||
public override void Execute(WorldInterface @on) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Progression.Engine.Core.World.Threading; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public class CityOwnerUpdate : CityUpdateBase | ||
{ | ||
public CityOwnerUpdate(City city, Civilization.Civilization newOwner) : base(city) | ||
{ | ||
NewOwner = newOwner; | ||
} | ||
|
||
public Civilization.Civilization NewOwner { get; } | ||
|
||
public override void Execute(WorldInterface @on) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Progression.Engine.Core.World.Threading; | ||
|
||
namespace Progression.Engine.Core.City | ||
{ | ||
public abstract class CityUpdateBase : WorldUpdateBase | ||
{ | ||
public CityUpdateBase(City city) | ||
{ | ||
City = city; | ||
} | ||
|
||
public City City { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Progression.Engine.Core.World; | ||
|
||
namespace Progression.Engine.Core.Civilization | ||
{ | ||
public class CivilisationManager | ||
{ | ||
public CivilisationManager(CivilizationRegister register) | ||
{ | ||
Register = register; | ||
} | ||
public CivilizationRegister Register { get; } | ||
|
||
|
||
public Vision GetVision(Tile tile, Civilization civ) => Register.Resolver.GetVision(tile, civ); | ||
|
||
public void SetVision(Tile tile, Civilization civ, Vision vision) => Register.Resolver.SetVision(tile, civ, vision); | ||
|
||
public Civilization GetOwner(Tile tile) => Register.Resolver.GetOwner(tile); | ||
|
||
public int GetLastMapUpdate(Tile tile) => Register.Resolver.GetLastMapUpdate(tile); | ||
|
||
public void SetOwner(Tile tile, Civilization civ) => Register.Resolver.SetOwner(tile, civ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.