Skip to content

Commit

Permalink
Merge branch 'eesast:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shangfengh authored Dec 16, 2023
2 parents 2ba252c + 9ff40a2 commit 6050248
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
2 changes: 2 additions & 0 deletions logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace GameClass.GameObj.Areas;

public class Construction : Immovable
{
public AtomicLong TeamID { get; } = new(long.MaxValue);
public LongInTheVariableRange HP { get; } = new LongInTheVariableRange(0, GameData.CommunityHP);
public override bool IsRigid => constructionType == ConstructionType.Community;
public override ShapeType Shape => ShapeType.Square;
Expand All @@ -23,6 +24,7 @@ public bool Construct(int constructSpeed, ConstructionType constructionType, Shi
}
if (this.constructionType == ConstructionType.Null || this.HP == 0)
{
this.TeamID.SetReturnOri(ship.TeamID);
this.constructionType = constructionType;
switch (constructionType)
{
Expand Down
6 changes: 2 additions & 4 deletions logic/GameClass/GameObj/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Team(Home home)
public const long invalidTeamID = long.MaxValue;
public const long noneTeamID = long.MinValue;
private readonly List<Ship> shipList = new(GameData.MaxShipNum);
private readonly Dictionary<uint, XY> birthPointList = [];
public Dictionary<uint, XY> BirthPointList => birthPointList;
private readonly List<XY> birthPointList = new();
public List<XY> BirthPointList => birthPointList;
private Home home = home;
public AtomicLong Money { get; } = new AtomicLong(0);
public AtomicLong Score { get; } = new AtomicLong(0);
Expand Down Expand Up @@ -116,7 +116,5 @@ public long[] GetShipIDs()
}
return shipIDs;
}
public void UpdateBirthPoint()
{ }
}
}
63 changes: 60 additions & 3 deletions logic/Gaming/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Gaming
{
public partial class Game
{
public struct ShipInitInfo(long teamID, long playerID, uint birthPoint, ShipType shipType)
public struct ShipInitInfo(long teamID, long playerID, XY birthPoint, ShipType shipType)
{
public long teamID = teamID;
public long playerID = playerID;
public uint birthPoint = birthPoint;
public XY birthPoint = birthPoint;
public ShipType shipType = shipType;
}
private readonly List<Team> teamList;
Expand All @@ -27,7 +27,25 @@ public long AddShip(ShipInitInfo shipInitInfo)
return GameObj.invalidID;
}
// 由于BirthPoint实质上是可变且每支队伍不同的,所以暂时把它放到Team里?
XY pos = teamList[(int)shipInitInfo.teamID].BirthPointList[shipInitInfo.birthPoint];
XY pos = shipInitInfo.birthPoint;
bool validBirthPoint = false;
foreach (XY birthPoint in teamList[(int)shipInitInfo.teamID].BirthPointList)
{
if (GameData.ApproachToInteract(pos, birthPoint) && pos != birthPoint)
{
validBirthPoint = true;
break;
}
}
if (gameMap.ProtoGameMap[pos.x, pos.y] != (uint)PlaceType.Null &&
gameMap.ProtoGameMap[pos.x, pos.y] != (uint)PlaceType.Shadow)
{
validBirthPoint = false;
}
if (!validBirthPoint)
{
return GameObj.invalidID;
}
Ship? newShip = shipManager.AddShip(pos, shipInitInfo.teamID, shipInitInfo.playerID, shipInitInfo.shipType);
if (newShip == null)
{
Expand Down Expand Up @@ -128,6 +146,44 @@ public long GetTeamScore(long teamID)
return -1;
return teamList[(int)teamID].Score;
}
public void UpdateBirthPoint()
{
foreach (Construction construction in gameMap.GameObjDict[GameObjType.Construction].Cast<Construction>())
{
if (construction.ConstructionType == ConstructionType.Community)
{
bool exist = false;
foreach (XY birthPoint in teamList[(int)construction.TeamID].BirthPointList)
{
if (construction.Position == birthPoint)
{
exist = true;
break;
}
}
if (!exist)
{
teamList[(int)construction.TeamID].BirthPointList.Add(construction.Position);
}
}
}
foreach (Team team in teamList)
{
foreach (XY birthPoint in team.BirthPointList)
{
foreach (Construction construction in gameMap.GameObjDict[GameObjType.Construction].Cast<Construction>())
{
if (construction.Position == birthPoint)
{
if (construction.ConstructionType != ConstructionType.Community || construction.TeamID != team.TeamID)
{
team.BirthPointList.Remove(birthPoint);
}
}
}
}
}
}
public Game(uint[,] mapResource, int numOfTeam)
{
gameMap = new(mapResource);
Expand All @@ -141,6 +197,7 @@ public Game(uint[,] mapResource, int numOfTeam)
if (gameObj.Type == GameObjType.Home)
{
teamList.Add(new Team((Home)gameObj));
teamList.Last().BirthPointList.Add(gameObj.Position);
}
if (teamList.Count == numOfTeam)
{
Expand Down
6 changes: 3 additions & 3 deletions logic/Preparation/Utility/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static class GameData
public const int TolerancesLength = 3;
public const int AdjustLength = 3;

public const int MaxShipNum = 8; // 最大舰船数量
public const int MaxCivilShipNum = 3; // 最大民用舰船数量
public const int MaxWarShipNum = 4; // 最大军用舰船数量
public const int MaxShipNum = 4; // 最大舰船数量
public const int MaxCivilShipNum = 2; // 最大民用舰船数量
public const int MaxWarShipNum = 2; // 最大军用舰船数量
public const int MaxFlagShipNum = 1; // 最大旗舰数量

public const int NumOfPosGridPerCell = 1000; // 每格的【坐标单位】数
Expand Down

0 comments on commit 6050248

Please sign in to comment.