diff --git a/logic/GameClass/GameObj/Areas/Construction.cs b/logic/GameClass/GameObj/Areas/Construction.cs index 39070846..9c8bf3ee 100644 --- a/logic/GameClass/GameObj/Areas/Construction.cs +++ b/logic/GameClass/GameObj/Areas/Construction.cs @@ -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; @@ -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) { diff --git a/logic/GameClass/GameObj/Team.cs b/logic/GameClass/GameObj/Team.cs index 66470e9f..c594911a 100644 --- a/logic/GameClass/GameObj/Team.cs +++ b/logic/GameClass/GameObj/Team.cs @@ -12,8 +12,8 @@ public class Team(Home home) public const long invalidTeamID = long.MaxValue; public const long noneTeamID = long.MinValue; private readonly List shipList = new(GameData.MaxShipNum); - private readonly Dictionary birthPointList = []; - public Dictionary BirthPointList => birthPointList; + private readonly List birthPointList = new(); + public List BirthPointList => birthPointList; private Home home = home; public AtomicLong Money { get; } = new AtomicLong(0); public AtomicLong Score { get; } = new AtomicLong(0); @@ -116,7 +116,5 @@ public long[] GetShipIDs() } return shipIDs; } - public void UpdateBirthPoint() - { } } } diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index 1905401a..9386d843 100644 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -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 teamList; @@ -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) { @@ -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()) + { + 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()) + { + 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); @@ -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) { diff --git a/logic/Preparation/Utility/GameData.cs b/logic/Preparation/Utility/GameData.cs index 8af558da..34f83fc3 100644 --- a/logic/Preparation/Utility/GameData.cs +++ b/logic/Preparation/Utility/GameData.cs @@ -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; // 每格的【坐标单位】数