Skip to content

Commit

Permalink
started to add cities, improved civ implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sirati committed Jan 27, 2019
1 parent 16166f8 commit ed3b124
Show file tree
Hide file tree
Showing 58 changed files with 872 additions and 336 deletions.
2 changes: 1 addition & 1 deletion NativeTerminalLauncher/NativeTerminalLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Progression.CCL</RootNamespace>
<AssemblyName>NativeTerminalLauncher</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
2 changes: 1 addition & 1 deletion Networking/Networking.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Progression.IO</RootNamespace>
<AssemblyName>Networking</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
27 changes: 26 additions & 1 deletion ProgressionCore/City/City.cs
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));
}


}
}
19 changes: 19 additions & 0 deletions ProgressionCore/City/CityFeature.cs
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;
}
}
69 changes: 69 additions & 0 deletions ProgressionCore/City/CityFeatureResolver.cs
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)
{

}
}
}
38 changes: 38 additions & 0 deletions ProgressionCore/City/CityManager.cs
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));
}
}
}
23 changes: 23 additions & 0 deletions ProgressionCore/City/Updates/AddCityUpdate.cs
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();
}
}
}
18 changes: 18 additions & 0 deletions ProgressionCore/City/Updates/CityNameUpdate.cs
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();
}
}
}
19 changes: 19 additions & 0 deletions ProgressionCore/City/Updates/CityOwnerUpdate.cs
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();
}
}
}
14 changes: 14 additions & 0 deletions ProgressionCore/City/Updates/CityUpdateBase.cs
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; }
}
}
24 changes: 24 additions & 0 deletions ProgressionCore/Civilization/CivilisationManager.cs
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);
}
}
26 changes: 13 additions & 13 deletions ProgressionCore/Civilization/Civilization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public class Civilization : IFeature<Civilization>, IWorldHolder
public IPuppetLevel PuppetLevel => _puppetLevel;


public Civilization(string name, CivilizationManager manager)
public Civilization(string name, CivilizationRegister register)
{
Name = name;
Manager = manager;
Key = new Key(manager.Key, name);
Register = register;
Key = new Key(register.Key, name);
Index = -1; //this is done to avoid to make this civ not equal another civ with index 0
Index = Manager.FreeIndex;
Manager.AddCivilisation(this);
Index = Register.FreeIndex;
Register.AddCivilisation(this);
}

IFeatureResolver IFeature.Resolver => Manager.Resolver;
IFeatureResolver IFeature.Resolver => Register.Resolver;

public virtual void AddPuppet(Civilization civ, IPuppetLevel puppetLevel)
{
Expand All @@ -46,24 +46,24 @@ public virtual void MakeIndependent()
public string Name { get; }
public Key Key { get; }
public int Index { get; }
public CivilizationManager Manager { get; }
public CivilizationRegister Register { get; }


public Vision GetVision(Tile tile)
{
return Manager.GetVision(tile, this);
return tile.World.CivilisationManager.GetVision(tile, this);
}

public int GetLastMapUpdate(Tile tile) => Manager.GetLastMapUpdate(tile);
public int GetLastMapUpdate(Tile tile) => tile.World.CivilisationManager.GetLastMapUpdate(tile);

public bool IsOwning(Tile tile)
{
return Manager.GetOwnerId(tile) == Index;
return tile.World.CivilisationManager.Register.Resolver.GetOwnerId(tile) == Index;
}

public void Own(Tile tile)
{
Manager.SetOwner(tile, this);
tile.World.CivilisationManager.SetOwner(tile, this);
}


Expand All @@ -72,7 +72,7 @@ public void Own(Tile tile)

protected bool Equals(Civilization other)
{
return Index!=-1 && Index == other.Index && Equals(Manager, other.Manager);
return Index!=-1 && Index == other.Index && Equals(Register, other.Register);
}

public override bool Equals(object obj)
Expand All @@ -87,6 +87,6 @@ public override bool Equals(object obj)

#endregion

public byte WorldType => Manager.WorldTypePlayerId;
public byte WorldType => Register.Resolver.WorldTypePlayerId;
}
}
Loading

0 comments on commit ed3b124

Please sign in to comment.