From bacc7f3d79115397314caa47b37257e8df9750af Mon Sep 17 00:00:00 2001 From: drNovikov Date: Sun, 6 Sep 2015 23:58:41 +0300 Subject: [PATCH 01/18] Changed HullClassifier to MyRadioAntenna instead of MyBeacon --- .gitignore | 1 + Data/BlockCategories.sbc | 30 ++++++++-------- Data/CubeBlocks.sbc | 34 +++++++++---------- Data/Prefabs/GCSpawnShip.sbc | 2 +- .../GardenConquest/Blocks/GridEnforcer.cs | 4 +-- .../GardenConquest/Blocks/HullClassifier.cs | 4 +-- .../GardenConquest/Core/CommandProcessor.cs | 2 +- .../GardenConquest/Records/ControlPoint.cs | 12 +++---- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 6a68ce6..dba7722 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ +*.bak \ No newline at end of file diff --git a/Data/BlockCategories.sbc b/Data/BlockCategories.sbc index 8419bd2..43cb498 100644 --- a/Data/BlockCategories.sbc +++ b/Data/BlockCategories.sbc @@ -9,21 +9,21 @@ Hull Classifiers Hull Classifiers - Beacon/GCUnlicensedHullClassifier - Beacon/GCWorkerHullClassifier - Beacon/GCFoundryHullClassifier - Beacon/GCScoutHullClassifier - Beacon/GCFighterHullClassifier - Beacon/GCGunshipHullClassifier - Beacon/GCCorvetteHullClassifier - Beacon/GCFrigateHullClassifier - Beacon/GCDestroyerHullClassifier - Beacon/GCCruiserHullClassifier - Beacon/GCHeavyCruiserHullClassifier - Beacon/GCBattleshipHullClassifier - Beacon/GCOutpostHullClassifier - Beacon/GCInstallationHullClassifier - Beacon/GCFortressHullClassifier + RadioAntenna/GCUnlicensedHullClassifier + RadioAntenna/GCWorkerHullClassifier + RadioAntenna/GCFoundryHullClassifier + RadioAntenna/GCScoutHullClassifier + RadioAntenna/GCFighterHullClassifier + RadioAntenna/GCGunshipHullClassifier + RadioAntenna/GCCorvetteHullClassifier + RadioAntenna/GCFrigateHullClassifier + RadioAntenna/GCDestroyerHullClassifier + RadioAntenna/GCCruiserHullClassifier + RadioAntenna/GCHeavyCruiserHullClassifier + RadioAntenna/GCBattleshipHullClassifier + RadioAntenna/GCOutpostHullClassifier + RadioAntenna/GCInstallationHullClassifier + RadioAntenna/GCFortressHullClassifier diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 5675102..9eb92ba 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -6,7 +6,7 @@ - Beacon + RadioAntenna GCUnlicensedHullClassifier Unlicensed Hull Classifier @@ -47,7 +47,7 @@ - Beacon + RadioAntenna GCUnlicensedHullClassifierSmall Unlicensed Hull Classifier @@ -82,7 +82,7 @@ - Beacon + RadioAntenna GCWorkerHullClassifier Worker Hull Classifier @@ -124,7 +124,7 @@ - Beacon + RadioAntenna GCWorkerHullClassifierSmall Worker Hull Classifier @@ -156,7 +156,7 @@ - Beacon + RadioAntenna GCFoundryHullClassifier Foundry Hull Classifier @@ -203,7 +203,7 @@ - Beacon + RadioAntenna GCScoutHullClassifier Scout Hull Classifier @@ -235,7 +235,7 @@ - Beacon + RadioAntenna GCFighterHullClassifier Fighter Hull Classifier @@ -267,7 +267,7 @@ - Beacon + RadioAntenna GCGunshipHullClassifier Gunship Hull Classifier @@ -303,7 +303,7 @@ - Beacon + RadioAntenna GCCorvetteHullClassifier Corvette Hull Classifier @@ -346,7 +346,7 @@ - Beacon + RadioAntenna GCFrigateHullClassifier Frigate Hull Classifier @@ -389,7 +389,7 @@ - Beacon + RadioAntenna GCDestroyerHullClassifier Destroyer Hull Classifier @@ -432,7 +432,7 @@ - Beacon + RadioAntenna GCCruiserHullClassifier Cruiser Hull Classifier @@ -475,7 +475,7 @@ - Beacon + RadioAntenna GCHeavyCruiserHullClassifier Heavy Cruiser Hull Classifier @@ -518,7 +518,7 @@ - Beacon + RadioAntenna GCBattleshipHullClassifier Battleship Hull Classifier @@ -565,7 +565,7 @@ - Beacon + RadioAntenna GCOutpostHullClassifier Outpost Hull Classifier @@ -608,7 +608,7 @@ - Beacon + RadioAntenna GCInstallationHullClassifier Installation Hull Classifier @@ -651,7 +651,7 @@ - Beacon + RadioAntenna GCFortressHullClassifier Fortress Hull Classifier diff --git a/Data/Prefabs/GCSpawnShip.sbc b/Data/Prefabs/GCSpawnShip.sbc index 355cf5b..dc14ee1 100644 --- a/Data/Prefabs/GCSpawnShip.sbc +++ b/Data/Prefabs/GCSpawnShip.sbc @@ -1180,7 +1180,7 @@ people will try to kill you. 10 0 - + GCUnlicensedHullClassifier 200619511763221591 diff --git a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs index 70e7de9..640dd0f 100644 --- a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs +++ b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs @@ -244,7 +244,7 @@ public override void Init(MyObjectBuilder_EntityBase objectBuilder) { } // We need to only turn on our rule checking after startup. Otherwise, if - // a beacon is destroyed and then the server restarts, all but the first + // a antenna is destroyed and then the server restarts, all but the first // 25 blocks will be deleted on startup. m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; @@ -975,7 +975,7 @@ private void removeExtraClassifiers(int removeCount = 100) { /// The cleanest way to do that would be making Hull Classifiers a logic component /// so we can track isWorking there and make sure it's closed when they are /// This would require the ge to be able to find the HullClassifier component on - /// an added beacon, which seems like it might be possible, but also might not + /// an added antenna, which seems like it might be possible, but also might not /// private List findWorstClassifiers(uint removeCount = 0) { List worstClassifiers = new List(); diff --git a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs index 050c1d3..d0ead71 100644 --- a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs +++ b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs @@ -63,7 +63,7 @@ private static HullClass.CLASS HullClassFromSubTypeString(String subTypeString) /// public static bool isClassifierBlock(IMySlimBlock block) { IMyCubeBlock fatblock = block.FatBlock; - if (fatblock != null && fatblock is Ingame.IMyBeacon) { + if (fatblock != null && fatblock is Ingame.IMyRadioAntenna) { String subTypeName = fatblock.BlockDefinition.SubtypeName; if (subTypeName.Contains(SHARED_SUBTYPE)) return true; @@ -98,4 +98,4 @@ public HullClassifier(IMySlimBlock block) { #endregion } -} +} \ No newline at end of file diff --git a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs index 7ab7562..fbdd565 100644 --- a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs +++ b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs @@ -267,7 +267,7 @@ private String helpCPsText() { "In order to control the CP, your fleet must " + "have the most ships in that area that:\n" + - "* have a powered, broadcasting Hull Classifier beacon\n" + + "* have a powered, broadcasting Hull Classifier antenna\n" + "* have a broadcast range on the classifier at least as large " + " as the ship's distance to the CP. (This is to prevent players " + "from hiding while capturing a CP. If someone stands in the " + diff --git a/Data/Scripts/GardenConquest/Records/ControlPoint.cs b/Data/Scripts/GardenConquest/Records/ControlPoint.cs index 0ebfa95..f493c5f 100644 --- a/Data/Scripts/GardenConquest/Records/ControlPoint.cs +++ b/Data/Scripts/GardenConquest/Records/ControlPoint.cs @@ -207,19 +207,19 @@ private Dictionary nearbySubfleets() { "nearbySubfleets", Logger.severity.ERROR); continue; } - InGame.IMyBeacon beacon = classifier.FatBlock as InGame.IMyBeacon; - if (beacon == null) { - log("Classifier could not be referenced as beacon", + InGame.IMyRadioAntenna antenna = classifier.FatBlock as InGame.IMyRadioAntenna; + if (antenna == null) { + log("Classifier could not be referenced as antenna", "nearbySubfleets", Logger.severity.ERROR); continue; } - if (!beacon.IsWorking) { - log("Classifier beacon not working but grid was classified", + if (!antenna.IsWorking) { + log("Classifier antenna not working but grid was classified", "nearbySubfleets", Logger.severity.ERROR); continue; } - if (beacon.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) { + if (antenna.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) { log("Classifier range too small, skipping", "nearbySubfleets"); // TODO notify pilot continue; From 66ddb81d7a3dc1d34eaad7bee5bf09c0b89fd5e4 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Mon, 7 Sep 2015 00:12:54 +0300 Subject: [PATCH 02/18] Changed HullClassifier mount points so they cover the whole surface --- Data/CubeBlocks.sbc | 96 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 9eb92ba..42ebff4 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -30,10 +30,10 @@ - - - - + + + + @@ -107,10 +107,10 @@ - - - - + + + + @@ -181,10 +181,10 @@ - - - - + + + + @@ -328,10 +328,10 @@ - - - - + + + + @@ -371,10 +371,10 @@ - - - - + + + + @@ -414,10 +414,10 @@ - - - - + + + + @@ -457,10 +457,10 @@ - - - - + + + + @@ -500,10 +500,10 @@ - - - - + + + + @@ -543,10 +543,10 @@ - - - - + + + + @@ -590,10 +590,10 @@ - - - - + + + + @@ -633,10 +633,10 @@ - - - - + + + + @@ -676,10 +676,10 @@ - - - - + + + + From eaa9d073d818d97cda08af6ac3e677984e407180 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Mon, 7 Sep 2015 04:25:56 +0300 Subject: [PATCH 03/18] Bacon surfaces made fully mountable --- Data/CubeBlocks.sbc | 80 +++++++++++++++++++ .../GardenConquest/Blocks/HullClassifier.cs | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 42ebff4..d085f86 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -2,6 +2,86 @@ + + + + + Beacon + LargeBlockBeacon + + DisplayName_Block_Beacon + Textures\GUI\Icons\Cubes\beacon.dds + Large + TriangleMesh + + + Models\Cubes\Large\beacon.mwm + + + + + + + + + + + + + + + + + + + + + + + + + Beacon + Light + 50 + 214 + ParticleElectrical + + + + + Beacon + SmallBlockBeacon + + DisplayName_Block_Beacon + Textures\GUI\Icons\Cubes\beacon.dds + Small + TriangleMesh + + + Models\Cubes\Small\beacon.mwm + + + + + + + + + + + + Beacon + Z + Y + Light + 15 + 214 + ParticleElectrical + + + + + diff --git a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs index d0ead71..d5c017e 100644 --- a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs +++ b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs @@ -98,4 +98,4 @@ public HullClassifier(IMySlimBlock block) { #endregion } -} \ No newline at end of file +} From 36137ad0985a63260fc4a8789f0211623973f997 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Tue, 8 Sep 2015 23:09:17 +0300 Subject: [PATCH 04/18] Beacon and Hull Classifiers mount points reverted to vanilla --- .gitignore | 2 +- Data/CubeBlocks.sbc | 176 ++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 129 deletions(-) diff --git a/.gitignore b/.gitignore index dba7722..e1837c0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ -*.bak \ No newline at end of file +*.bak diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index d085f86..9eb92ba 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -2,86 +2,6 @@ - - - - - Beacon - LargeBlockBeacon - - DisplayName_Block_Beacon - Textures\GUI\Icons\Cubes\beacon.dds - Large - TriangleMesh - - - Models\Cubes\Large\beacon.mwm - - - - - - - - - - - - - - - - - - - - - - - - - Beacon - Light - 50 - 214 - ParticleElectrical - - - - - Beacon - SmallBlockBeacon - - DisplayName_Block_Beacon - Textures\GUI\Icons\Cubes\beacon.dds - Small - TriangleMesh - - - Models\Cubes\Small\beacon.mwm - - - - - - - - - - - - Beacon - Z - Y - Light - 15 - 214 - ParticleElectrical - - - - - @@ -110,10 +30,10 @@ - - - - + + + + @@ -187,10 +107,10 @@ - - - - + + + + @@ -261,10 +181,10 @@ - - - - + + + + @@ -408,10 +328,10 @@ - - - - + + + + @@ -451,10 +371,10 @@ - - - - + + + + @@ -494,10 +414,10 @@ - - - - + + + + @@ -537,10 +457,10 @@ - - - - + + + + @@ -580,10 +500,10 @@ - - - - + + + + @@ -623,10 +543,10 @@ - - - - + + + + @@ -670,10 +590,10 @@ - - - - + + + + @@ -713,10 +633,10 @@ - - - - + + + + @@ -756,10 +676,10 @@ - - - - + + + + From 7b4298070a4e4cfd81bb863edcce11b039479ab3 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Tue, 8 Sep 2015 23:20:25 +0300 Subject: [PATCH 05/18] Fixed a typo in a comment --- Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs index 640dd0f..eb32cba 100644 --- a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs +++ b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs @@ -244,7 +244,7 @@ public override void Init(MyObjectBuilder_EntityBase objectBuilder) { } // We need to only turn on our rule checking after startup. Otherwise, if - // a antenna is destroyed and then the server restarts, all but the first + // an antenna is destroyed and then the server restarts, all but the first // 25 blocks will be deleted on startup. m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; From 9820af1c96d7a34e4a419202cb874c6e073434c1 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Wed, 9 Sep 2015 17:50:47 +0300 Subject: [PATCH 06/18] Removed my *.bak from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e1837c0..6a68ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ -*.bak From 5b0d57b6868e03633f1a7823d9a4900b39696717 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Sun, 20 Sep 2015 15:27:02 +0300 Subject: [PATCH 07/18] "/gc fleet stop" enables thrusters, enables gyroscopes, sets gyro power to 100%, disables gyro overrides The "/gc fleet stop" command enables thrusters, also enables gyroscopes, sets their power to 100%, and disables their overrides. This was added because the command failed to stop ships on the server if their thrusters were turned off. --- .../GardenConquest/Messaging/RequestProcessor.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs b/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs index 5440ada..738d87d 100644 --- a/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs +++ b/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs @@ -137,7 +137,7 @@ private void processStopGridRequest(StopGridRequest req) { // Get all thrusters, spaceballs, artificial masses, and cockpits Func selectBlocks = b => - b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController); + b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMyGyro || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController); gridToStop.GetBlocks(fatBlocks, selectBlocks); // Can the player interact with this grid? If they can, stop the ship by enabling dampeners, turning off @@ -146,7 +146,14 @@ private void processStopGridRequest(StopGridRequest req) { foreach (IMySlimBlock block in fatBlocks) { // Thruster if (block.FatBlock is IMyThrust) { - Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0); + (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(true); + Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0); + } + // Gyroscope + if (block.FatBlock is IMyGyro) { + (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(true); + Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Power", 1); + Interfaces.TerminalPropertyExtensions.SetValueBool(block.FatBlock as InGame.IMyGyro, "Override", false); } // Spaceball else if (block.FatBlock is IMySpaceBall) { From dd2d4d1badcc89647413258287ad4f6925bc3174 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Thu, 8 Oct 2015 10:45:42 +0300 Subject: [PATCH 08/18] Added ResourceSinkGroup to hull classifier definitions Added Utility to every Hull Classifier definition --- Data/CubeBlocks.sbc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 9eb92ba..d57d258 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -11,6 +11,7 @@ Unlicensed Hull Classifier Textures\Icons\unlicensed-1-128.dds + Utility Large TriangleMesh @@ -52,6 +53,7 @@ Unlicensed Hull Classifier Textures\Icons\unlicensed-1-128.dds + Utility Small TriangleMesh @@ -87,6 +89,7 @@ Worker Hull Classifier Textures\Icons\utility-1-128.dds + Utility Large TriangleMesh @@ -129,6 +132,7 @@ Worker Hull Classifier Textures\Icons\utility-1-128.dds + Utility Small TriangleMesh @@ -161,6 +165,7 @@ Foundry Hull Classifier Textures\Icons\utility-2-128.dds + Utility Large TriangleMesh @@ -208,6 +213,7 @@ Scout Hull Classifier Textures\Icons\strikecraft-1-128.dds + Utility Small TriangleMesh @@ -240,6 +246,7 @@ Fighter Hull Classifier Textures\Icons\strikecraft-2-128.dds + Utility Small TriangleMesh @@ -272,6 +279,7 @@ Gunship Hull Classifier Textures\Icons\strikecraft-3-128.dds + Utility Small TriangleMesh @@ -308,6 +316,7 @@ Corvette Hull Classifier Textures\Icons\corvette-1-128.dds + Utility Large TriangleMesh @@ -351,6 +360,7 @@ Frigate Hull Classifier Textures\Icons\frigate-1-128.dds + Utility Large TriangleMesh @@ -394,6 +404,7 @@ Destroyer Hull Classifier Textures\Icons\capital-1-128.dds + Utility Large TriangleMesh @@ -437,6 +448,7 @@ Cruiser Hull Classifier Textures\Icons\capital-2-128.dds + Utility Large TriangleMesh @@ -480,6 +492,7 @@ Heavy Cruiser Hull Classifier Textures\Icons\supercapital-1-128.dds + Utility Large TriangleMesh @@ -523,6 +536,7 @@ Battleship Hull Classifier Textures\Icons\supercapital-2-128.dds + Utility Large TriangleMesh @@ -570,6 +584,7 @@ Outpost Hull Classifier Textures\Icons\station-1-128.dds + Utility Large TriangleMesh @@ -613,6 +628,7 @@ Installation Hull Classifier Textures\Icons\station-2-128.dds + Utility Large TriangleMesh @@ -656,6 +672,7 @@ Fortress Hull Classifier Textures\Icons\station-3-128.dds + Utility Large TriangleMesh From e6d5a3813d6d68ed3b489a7884eeecad8af499cc Mon Sep 17 00:00:00 2001 From: Zach Risher Date: Mon, 20 Jul 2015 19:53:38 -0700 Subject: [PATCH 09/18] cp round reward imprvs and fixes --- .../GardenConquest/Blocks/GridEnforcer.cs | 11 +- Data/Scripts/GardenConquest/Constants.cs | 2 +- .../GardenConquest/Core/Core_Server.cs | 371 ++++-------------- .../Extensions/GridExtensions.cs | 107 +++-- .../IMyPlayerCollectionExtensions.cs | 42 ++ .../Extensions/PlayerExtensions.cs | 5 + .../GardenConquest/GardenConquest.csproj | 3 +- Data/Scripts/GardenConquest/GridSorter.cs | 41 -- .../PhysicalObjects/ShipLicense.cs | 18 + .../GardenConquest/Records/ControlPoint.cs | 222 +++++++++++ .../GardenConquest/Records/DerelictTimer.cs | 4 +- .../GardenConquest/Records/GridOwner.cs | 3 +- 12 files changed, 455 insertions(+), 374 deletions(-) create mode 100644 Data/Scripts/GardenConquest/Extensions/IMyPlayerCollectionExtensions.cs delete mode 100644 Data/Scripts/GardenConquest/GridSorter.cs create mode 100644 Data/Scripts/GardenConquest/PhysicalObjects/ShipLicense.cs diff --git a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs index bf4fd3d..70e7de9 100644 --- a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs +++ b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs @@ -122,6 +122,7 @@ public struct VIOLATION { public GridOwner Owner { get { return m_Owner; } } public HullClass.CLASS Class { get { return m_EffectiveClass; } } + public int CaptureMultiplier { get { return m_EffectiveRules.CaptureMultiplier; } } private List BigOwners { get { try { return m_Grid.BigOwners; } catch { @@ -507,7 +508,7 @@ private void blockAdded(IMySlimBlock added) { private void updateProjectorsWith(IMySlimBlock block) { - log("", "updateBlockCountsWith"); + log("", "updateProjectorsWith"); InGame.IMyProjector projector = block.FatBlock as InGame.IMyProjector; if (projector != null) { @@ -569,9 +570,9 @@ private VIOLATION_TYPE incrementBlockCount() { log("", "incrementTotalBlocks"); m_BlockCount++; //log("new count " + m_BlockCount, "incrementTotalBlocks"); - log("m_EffectiveRules: ", "incrementTotalBlocks"); - log("m_EffectiveRules.DisplayName " + m_EffectiveRules.DisplayName, "incrementTotalBlocks"); - log("m_EffectiveRules.MaxBlocks " + m_EffectiveRules.MaxBlocks, "incrementTotalBlocks"); + //log("m_EffectiveRules: ", "incrementTotalBlocks"); + //log("m_EffectiveRules.DisplayName " + m_EffectiveRules.DisplayName, "incrementTotalBlocks"); + //log("m_EffectiveRules.MaxBlocks " + m_EffectiveRules.MaxBlocks, "incrementTotalBlocks"); if (m_BlockCount > m_EffectiveRules.MaxBlocks) { return VIOLATION_TYPE.TOTAL_BLOCKS; @@ -599,7 +600,7 @@ private bool helpsClassifyUnclassified(IMySlimBlock block) { /// Returns the violated limits if any /// private List updateBlockTypeCountsWith(IMySlimBlock block) { - log("", "updateBlockCountsWith"); + log("", "updateBlockTypeCountsWith"); List violated_types = new List(); BlockType[] types = s_Settings.BlockTypes; diff --git a/Data/Scripts/GardenConquest/Constants.cs b/Data/Scripts/GardenConquest/Constants.cs index 7b8464d..f42d2de 100644 --- a/Data/Scripts/GardenConquest/Constants.cs +++ b/Data/Scripts/GardenConquest/Constants.cs @@ -33,7 +33,7 @@ public static class Constants { /// /// Current Version of Garden Conquest /// - public const String Version = "1.0.9.2"; + public const String Version = "1.0.9.4"; /// /// Notification duration diff --git a/Data/Scripts/GardenConquest/Core/Core_Server.cs b/Data/Scripts/GardenConquest/Core/Core_Server.cs index 0b52008..b0d100e 100644 --- a/Data/Scripts/GardenConquest/Core/Core_Server.cs +++ b/Data/Scripts/GardenConquest/Core/Core_Server.cs @@ -35,19 +35,13 @@ class Core_Server : Core_Base { #region Class Members private bool m_Initialized = false; - private CommandProcessor m_CmdProc = null; - private MyTimer m_RoundTimer = null; - private MyTimer m_SaveTimer = null; - private RequestProcessor m_MailMan = null; - private ResponseProcessor m_LocalReceiver = null; - + private CommandProcessor m_CmdProc; + private MyTimer m_RoundTimer; + private MyTimer m_SaveTimer; + private RequestProcessor m_MailMan; + private ResponseProcessor m_LocalReceiver; private bool m_RoundEnded = false; - //private Object m_SyncObject = new Object(); - private static readonly int INGAME_PLACEMENT_MAX_DISTANCE = 60; - private static MyObjectBuilder_Component s_TokenBuilder = null; - private static VRage.ObjectBuilders.SerializableDefinitionId? s_TokenDef = null; - private static IComparer s_Sorter = null; private static ConquestSettings s_Settings; private static bool s_DelayedSettingWrite = false; @@ -65,17 +59,12 @@ public override void initialize() { s_Logger = new Logger("Conquest Core", "Server"); log("Conquest core (Server) started"); - s_TokenBuilder = new MyObjectBuilder_Component() { SubtypeName = "ShipLicense" }; - s_TokenDef = new VRage.ObjectBuilders.SerializableDefinitionId( - typeof(MyObjectBuilder_InventoryItem), "ShipLicense"); - s_Sorter = new GridSorter(); - s_Settings = ConquestSettings.getInstance(); s_DelayedSettingWrite = s_Settings.WriteFailed; // Start round timer m_RoundTimer = new MyTimer(s_Settings.CPPeriod * 1000, roundEnd); m_RoundTimer.Start(); - log("Round timer started"); + log("Round timer started with " + s_Settings.CPPeriod + " seconds"); // Start save timer m_SaveTimer = new MyTimer(Constants.SaveInterval * 1000, saveTimer); @@ -98,6 +87,7 @@ public override void initialize() { GridEnforcer.OnCleanupViolation += eventCleanupViolation; GridEnforcer.OnCleanupTimerStart += eventCleanupTimerStart; GridEnforcer.OnCleanupTimerEnd += eventCleanupTimerEnd; + ControlPoint.OnRewardsDistributed += notifyPlayersOfCPResults; m_Initialized = true; } @@ -109,6 +99,7 @@ public override void unloadData() { GridEnforcer.OnCleanupViolation -= eventCleanupViolation; GridEnforcer.OnCleanupTimerStart -= eventCleanupTimerStart; GridEnforcer.OnCleanupTimerEnd -= eventCleanupTimerEnd; + ControlPoint.OnRewardsDistributed -= notifyPlayersOfCPResults; if (m_LocalReceiver != null) { m_MailMan.localMsgSent -= m_LocalReceiver.incomming; @@ -120,17 +111,23 @@ public override void unloadData() { if (!MyAPIGateway.Utilities.IsDedicated) m_CmdProc.shutdown(); + m_RoundTimer.Dispose(); + m_RoundTimer = null; + m_SaveTimer.Dispose(); + m_SaveTimer = null; + s_Logger = null; } public override void updateBeforeSimulation() { try { - //lock (m_SyncObject) { if (m_RoundEnded) { - distributeRewards(); + log("Round ended, distributing CP Rewards", "updateBeforeSimulation"); + foreach (ControlPoint cp in s_Settings.ControlPoints) { + cp.distributeRewards(); + } m_RoundEnded = false; } - //} if (s_DelayedSettingWrite) { log("Settings Write was delayed, trying again", "updateBeforeSimulation"); s_Settings.writeSettings(); @@ -154,7 +151,7 @@ public void eventPlacementViolation(GridEnforcer ge, GridEnforcer.VIOLATION_TYPE // Check for players within the vicinity of the grid, since there's no // built-in way to tell who just placed the block - List players = getPlayersNearGrid(ge.Grid); + List players = ge.Grid.getPlayerIDsWithinPlacementRadius(); if (players.Count <= 0) return; @@ -215,7 +212,7 @@ public void eventCleanupViolation(GridEnforcer ge, List Destinations.Add(ge.Owner.PlayerID); message += "Your "; } else { - List nearbyPlayers = getPlayersNearGrid(ge.Grid); + List nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius(); if (nearbyPlayers.Count > 0) { destType = BaseResponse.DEST_TYPE.PLAYER; Destinations = nearbyPlayers; @@ -279,7 +276,7 @@ public void eventCleanupTimerStart(GridEnforcer ge, int secondsRemaining) { message += "Your "; } else { - List nearbyPlayers = getPlayersNearGrid(ge.Grid); + List nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius(); if (nearbyPlayers.Count > 0) { destType = BaseResponse.DEST_TYPE.PLAYER; Destinations = nearbyPlayers; @@ -337,7 +334,7 @@ public void eventCleanupTimerEnd(GridEnforcer ge, DerelictTimer.COMPLETION c) { message += "Your "; } else { - List nearbyPlayers = getPlayersNearGrid(ge.Grid); + List nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius(); if (nearbyPlayers.Count > 0) { destType = BaseResponse.DEST_TYPE.PLAYER; Destinations = nearbyPlayers; @@ -370,6 +367,48 @@ public void eventCleanupTimerEnd(GridEnforcer ge, DerelictTimer.COMPLETION c) { m_MailMan.send(noti); } + /// + /// Notify players within the CP whether they won, lost, or tied + /// + public void notifyPlayersOfCPResults(int rewardsDistributed, + List winningFleetIds, List nearbyPlayers, ControlPoint cp) { + bool tie = (winningFleetIds.Count > 1); + long winningFleetId = 0; + if (!tie) winningFleetId = winningFleetIds.First(); + + var winningPlayers = new List(); + var tiedPlayers = new List(); + var losingPlayers = new List(); + + foreach (IMyPlayer player in nearbyPlayers) { + long fleetID = player.FleetID(); + + if (!tie && fleetID == winningFleetId) { + winningPlayers.Add(player.PlayerID); + } else if (tie && winningFleetIds.Contains(fleetID)) { + tiedPlayers.Add(player.PlayerID); + } else { + losingPlayers.Add(player.PlayerID); + } + } + + if (winningPlayers.Count > 0) { + notifyPlayers(String.Format( + "You control {0} and received {1} licenses.", + cp.Name, rewardsDistributed), + winningPlayers, MyFontEnum.Green); + } + if (tiedPlayers.Count > 0) { + notifyPlayers(String.Format( + "You tied for control of {0} and received no licenses.", + cp.Name), tiedPlayers, MyFontEnum.Red); + } + if (losingPlayers.Count > 0) { + notifyPlayers("Someone else controls " + cp.Name, + losingPlayers, MyFontEnum.Red); + } + } + #endregion #region Class Timer Events @@ -378,9 +417,7 @@ public void eventCleanupTimerEnd(GridEnforcer ge, DerelictTimer.COMPLETION c) { /// private void roundEnd() { log("hit", "roundEnd"); - //lock (m_SyncObject) { - m_RoundEnded = true; - //} + m_RoundEnded = true; } private void saveTimer() { @@ -388,280 +425,16 @@ private void saveTimer() { StateTracker.getInstance().saveState(); } - /// - /// Called at the end of a round. Distributes rewards to winning factions. - /// - private void distributeRewards() { - log("Timer triggered", "roundEnd"); - - try { - if (!m_Initialized) - return; - - // Check each CP in turn - Dictionary totalTokens = new Dictionary(); - foreach (ControlPoint cp in s_Settings.ControlPoints) { - log("Processing control point " + cp.Name, "roundEnd"); - - // Get a list of all grids within this CPs sphere of influence - List gridsInSOI = getGridsInCPRadius(cp); - log("Found " + gridsInSOI.Count + " grids in CP SOI", "roundEnd"); - - // Group all of the grids in the SOI into their factions - // This will only return grids which conform to the rules which make them valid - // for counting. All other grids discarded. - Dictionary> allFactionGrids = - groupFactionGrids(gridsInSOI, cp.Position); - log("After aggregation there are " + allFactionGrids.Count + " factions present", "roundEnd"); - foreach (KeyValuePair> entry in allFactionGrids) { - log("Grids for faction " + entry.Key, "roundEnd"); - foreach (FACGRID grid in entry.Value) { - log("\t" + grid.grid.Name, "roundEnd"); - } - } - - // Now that we have an aggregation of grids for factions - // in the SOI, we can decide who wins - long greatestFaction = -1; - int greatestTotal = -1; - bool tie = false; - foreach (KeyValuePair> entry in allFactionGrids) { - int weightedTotal = 0; - foreach (FACGRID fg in entry.Value) { - weightedTotal += - s_Settings.HullRules[(int)fg.hullClass].CaptureMultiplier; - } - - if (weightedTotal >= greatestTotal) { - tie = weightedTotal == greatestTotal; - - greatestFaction = entry.Key; - greatestTotal = weightedTotal; - } - } - - log("Faction with most grids: " + greatestFaction, "roundEnd"); - log("Number of (weighted) grids: " + greatestTotal, "roundEnd"); - log("Tie? " + tie, "roundEnd"); - - // If we have a tie, nobody gets the tokens - // If we don't, award tokens to the faction with the most ships in the SOI - if (greatestFaction != -1 && !tie) { - // Deposit order: - // 1. Largest station (by block count) - // 2. If no stations, largest (by block count) large ship with cargo - // 3. Otherwise largest (by block count) small ship with cargo - - // Sort the list by these rules ^ - log("Sorting list of grids", "roundEnd"); - List grids = allFactionGrids[greatestFaction]; - grids.Sort(s_Sorter); - - //foreach (FACGRID g in grids) { - // log(g.grid.EntityId + " " + g.gtype + " " + g.blockCount); - //} - - // Go through the sorted list and find the first ship with a cargo container - // with space. If the faction has no free cargo container they are S.O.L. - log("Looking for valid container", "roundEnd"); - InGame.IMyCargoContainer container = null; - foreach (FACGRID grid in grids) { - container = grid.grid.getAvailableCargo(s_TokenDef, cp.TokensPerPeriod); - if (container != null) - break; - } - - if (container != null) { - // Award the tokens - log("Found a ship to put tokens in", "roundEnd"); - ((container as Interfaces.IMyInventoryOwner).GetInventory(0) - as IMyInventory).AddItems( - cp.TokensPerPeriod, - s_TokenBuilder); - - // Track totals - if (totalTokens.ContainsKey(greatestFaction)) { - totalTokens[greatestFaction] += cp.TokensPerPeriod; - } else { - totalTokens.Add(greatestFaction, cp.TokensPerPeriod); - } - } - } - } - - // Anounce round ended - log("Sending message", "roundEnd"); - NotificationResponse endedMessage = new NotificationResponse() { - NotificationText = "Conquest Round Ended", - Time = Constants.NotificationMillis, - Font = MyFontEnum.White, - Destination = null, - DestType = BaseResponse.DEST_TYPE.EVERYONE - }; - m_MailMan.send(endedMessage); - - // Report round results - // For every faction that got rewards, tell them - NotificationResponse rewardMessage = new NotificationResponse() { - NotificationText = "", - Time = Constants.NotificationMillis, - Font = MyFontEnum.White, - Destination = new List() { 0 }, - DestType = BaseResponse.DEST_TYPE.FACTION - }; - foreach (KeyValuePair entry in totalTokens) { - rewardMessage.NotificationText = "Your faction has been awarded " + - entry.Value + " licenses"; - rewardMessage.Destination[0] = entry.Key; - m_MailMan.send(endedMessage); - } - - - } catch (Exception e) { - log("An exception occured: " + e, "roundEnd", Logger.severity.ERROR); - } - } - #endregion - #region Class Helpers - - - /// - /// Returns a list of players near a grid. Used to send messages - /// - /// - /// - private List getPlayersNearGrid(IMyCubeGrid grid) { - log("Getting players near grid " + grid.DisplayName); - - Vector3 gridPos = grid.GetPosition(); - VRageMath.Vector3 gridSize = grid.LocalAABB.Size; - float gridMaxLength = - Math.Max(gridSize.X, Math.Max(gridSize.Y, gridSize.Z)); - int maxDistFromGrid = (int)gridMaxLength + INGAME_PLACEMENT_MAX_DISTANCE; - - List allPlayers = new List(); - MyAPIGateway.Players.GetPlayers(allPlayers); - - float pDistFromGrid = 0.0f; - List nearbyPlayerIds = new List(); - foreach (IMyPlayer p in allPlayers) - { - pDistFromGrid = VRageMath.Vector3.Distance(p.GetPosition(), gridPos); - if (pDistFromGrid < maxDistFromGrid) { - nearbyPlayerIds.Add((long)p.PlayerID); - } - } - - log(nearbyPlayerIds.Count + " Nearby players: " + String.Join(" ,", nearbyPlayerIds)); - return nearbyPlayerIds; - } - - /// - /// Returns a list of grids in the vicinity of the CP - /// - /// Control point to check - /// - private List getGridsInCPRadius(ControlPoint cp) { - // Get all ents within the radius - VRageMath.BoundingSphereD bounds = - new VRageMath.BoundingSphereD(cp.Position, (double)cp.Radius); - List ents = - MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds); - - // Get only the ships/stations - List grids = new List(); - foreach (IMyEntity e in ents) { - if (e is IMyCubeGrid) - grids.Add(e as IMyCubeGrid); - } - - return grids; - } - - /// - /// Separates a list of grids by their fleet. Also discards invalid grids. - /// - /// Grids to aggregate - /// The position of the CP - /// - private Dictionary> groupFactionGrids(List grids, VRageMath.Vector3D cpPos) { - Dictionary> result = new Dictionary>(); - - foreach (IMyCubeGrid grid in grids) { - // GridEnforcer - GridEnforcer ge = grid.Components.Get() as GridEnforcer; - if (ge == null) { - log("No grid enforcer on grid " + grid.EntityId, - "groupFactionGrids", Logger.severity.ERROR); - continue; - } - - // Owner - ge.reevaluateOwnership(); - - if (ge.Owner.OwnerType == GridOwner.OWNER_TYPE.UNOWNED) { - log("Grid " + grid.EntityId + " is unowned, skipping", - "groupFactionGrids"); - continue; - } - - // Fleet - long fleetID = ge.Owner.FleetID; - if (ge.SupportedByFleet) { - log("Grid " + grid.DisplayName + " belongs to fleet " + fleetID, - "groupFactionGrids"); - } else { - log("Grid " + grid.DisplayName + " is unsupported by its fleet " + fleetID + - ", skipping.", "groupFactionGrids"); - continue; - } - - // Hull Classifier conditions for the grid to count: - // 1. Must have a hull classifier - HullClassifier classifier = ge.Classifier; - if (classifier == null) { - log("Grid has no classifier, skipping", "groupFactionGrids"); - continue; - } - - // 2. HC must be working - InGame.IMyBeacon beacon = classifier.FatBlock as InGame.IMyBeacon; - if (beacon == null || !beacon.IsWorking) { - log("Classifier beacon not working, skipping", "groupFactionGrids"); - continue; - } - - // 3. HC must have a beacon radius greater than the distance to the grid - if (beacon.Radius < VRageMath.Vector3.Distance(cpPos, grid.GetPosition())) { - log("Classifier range too small, skipping", "groupFactionGrids"); - continue; - } - - // The grid can be counted - List blocks = new List(); - grid.GetBlocks(blocks); - - FACGRID fg = new FACGRID(); - fg.grid = grid; - fg.blockCount = blocks.Count; - fg.gtype = Utility.getGridType(grid); - fg.hullClass = ge.Class; - - List gridsOfCurrent = null; - if (result.ContainsKey(fleetID)) { - gridsOfCurrent = result[fleetID]; - } else { - gridsOfCurrent = new List(); - result.Add(fleetID, gridsOfCurrent); - } - gridsOfCurrent.Add(fg); - } - - return result; + public void notifyPlayers(String msg, List playerIDs, MyFontEnum color) { + m_MailMan.send(new NotificationResponse() { + NotificationText = msg, + Time = Constants.NotificationMillis, + Font = color, + Destination = playerIDs, + DestType = BaseResponse.DEST_TYPE.PLAYER + }); } - - #endregion } } diff --git a/Data/Scripts/GardenConquest/Extensions/GridExtensions.cs b/Data/Scripts/GardenConquest/Extensions/GridExtensions.cs index 2800351..1500462 100644 --- a/Data/Scripts/GardenConquest/Extensions/GridExtensions.cs +++ b/Data/Scripts/GardenConquest/Extensions/GridExtensions.cs @@ -9,6 +9,7 @@ using VRage.ModAPI; using VRage.ObjectBuilders; using VRage.Components; +using VRageMath; using Sandbox.Definitions; using Sandbox.ModAPI; using InGame = Sandbox.ModAPI.Ingame; @@ -21,35 +22,90 @@ namespace GardenConquest.Extensions { /// public static class GridExtensions { + private static readonly float INGAME_PLACEMENT_MAX_DISTANCE = 60f; + + private static Logger s_Logger = new Logger("IMyCubeGrid", "Static"); + /// - /// Gets the first available non-empty cargo container on a grid. - /// If optional parameters given, first cargo which can fit that volume. + /// Attempts to place count of a physical object in inventory of grid + /// Will place as many of the object as possible in each inventory until + /// nothing remains to place. Returns number remaining to place. /// - /// Optional: Builder definition - /// Optional: Number of items - /// - public static InGame.IMyCargoContainer getAvailableCargo(this IMyCubeGrid grid, VRage.ObjectBuilders.SerializableDefinitionId? def = null, int count = 1) { - List containers = new List(); - grid.GetBlocks(containers, x => x.FatBlock != null && x.FatBlock is InGame.IMyCargoContainer); - + public static int placeInCargo(this IMyCubeGrid grid, + SerializableDefinitionId def, MyObjectBuilder_Component builder, + int count) { + + if (count <= 0) return 0; + int remaining = count; + + var containers = new List(); + grid.GetBlocks(containers, x => + x.FatBlock != null && + x.FatBlock as Interfaces.IMyInventoryOwner != null + ); if (containers.Count == 0) - return null; - - if (def == null) { - // Don't care about fit, just return the first one - return containers[0].FatBlock as InGame.IMyCargoContainer; - } else { - foreach (IMySlimBlock block in containers) { - InGame.IMyCargoContainer c = block.FatBlock as InGame.IMyCargoContainer; - Interfaces.IMyInventoryOwner invo = c as Interfaces.IMyInventoryOwner; - Interfaces.IMyInventory inv = invo.GetInventory(0); - - // TODO: check for fit - return c; + return remaining; + + foreach (IMySlimBlock block in containers) { + if (remaining == 0) break; + + var inventoryOwner = block.FatBlock as Interfaces.IMyInventoryOwner; + var inventory = inventoryOwner.GetInventory(0) as IMyInventory; + + if (inventory == null) { + // log error, invOwner existed but not inventory>? + continue; + } + + if (inventory.CanItemsBeAdded((VRage.MyFixedPoint)remaining, def)) { + // Add all the items if it has enough space + inventory.AddItems(remaining, builder); + remaining = 0; + } else { + // Add them incrementally if there's some space + // I would prefer to do some math to tell how many we can add, + // instead of just continually looping through with 1. + // But the logic to get the volume of a component + // is surprisingly complex without access to the Adapter + // and we'd need to check the inventory's supported types + while (remaining > 0 && inventory.CanItemsBeAdded((VRage.MyFixedPoint)1, def)) { + inventory.AddItems(1, builder); + remaining--; + } } } - return null; + return remaining; + } + + /// + /// Returns a list of players near a grid. Used to send messages + /// + /// + /// + public static List getPlayersWithinPlacementRadius(this IMyCubeGrid self) { + log("Getting players near grid " + self.DisplayName); + + VRageMath.Vector3 gridSize = self.LocalAABB.Size; + float gridMaxLength = Math.Max(gridSize.X, Math.Max(gridSize.Y, gridSize.Z)); + float maxDistFromGrid = gridMaxLength + INGAME_PLACEMENT_MAX_DISTANCE; + + return self.getPlayersWithin(maxDistFromGrid); + } + + public static List getPlayerIDsWithinPlacementRadius(this IMyCubeGrid self) { + return getPlayersWithinPlacementRadius(self).ConvertAll(x => x.PlayerID); + } + /// + /// Returns a list of players within radius of grid + /// + /// + /// + public static List getPlayersWithin(this IMyCubeGrid self, float radius) { + log("Getting players near grid " + self.DisplayName); + + Vector3 position = self.GetPosition(); + return MyAPIGateway.Players.getPlayersNearPoint(position, radius); } /// @@ -128,6 +184,11 @@ public static bool canInteractWith(this IMyCubeGrid grid, long playerID) { return false; } + + private static void log(String message, String method = null, Logger.severity level = Logger.severity.DEBUG) { + s_Logger.log(level, method, message); + } + } } diff --git a/Data/Scripts/GardenConquest/Extensions/IMyPlayerCollectionExtensions.cs b/Data/Scripts/GardenConquest/Extensions/IMyPlayerCollectionExtensions.cs new file mode 100644 index 0000000..086023a --- /dev/null +++ b/Data/Scripts/GardenConquest/Extensions/IMyPlayerCollectionExtensions.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Sandbox.ModAPI; +using VRageMath; + +namespace GardenConquest.Extensions { + + /// + /// Helper functions for SE Player Collection + /// + public static class IMyPlayerCollectionExtensions { + + private static Logger s_Logger = new Logger("IMyPlayerCollection", "Static"); + + public static List getPlayersNearPoint(this IMyPlayerCollection self, Vector3D point, float radius) { + log("Getting players within " + radius + " of " + point, "getPlayersNearPoint"); + + var allPlayers = new List(); + self.GetPlayers(allPlayers); + + float distanceFromPoint = 0.0f; + var nearbyPlayers = new List(); + foreach (IMyPlayer player in allPlayers) { + distanceFromPoint = VRageMath.Vector3.Distance(player.GetPosition(), point); + if (distanceFromPoint < radius) { + nearbyPlayers.Add(player); + } + } + + log(nearbyPlayers.Count + " Nearby players.", "getPlayersNearPoint"); + return nearbyPlayers; + } + + private static void log(String message, String method = null, Logger.severity level = Logger.severity.DEBUG) { + s_Logger.log(level, method, message); + } + + } +} + diff --git a/Data/Scripts/GardenConquest/Extensions/PlayerExtensions.cs b/Data/Scripts/GardenConquest/Extensions/PlayerExtensions.cs index 76a3b08..24e9501 100644 --- a/Data/Scripts/GardenConquest/Extensions/PlayerExtensions.cs +++ b/Data/Scripts/GardenConquest/Extensions/PlayerExtensions.cs @@ -13,6 +13,7 @@ using Interfaces = Sandbox.ModAPI.Interfaces; using GardenConquest; +using GardenConquest.Records; namespace GardenConquest.Extensions { @@ -58,6 +59,10 @@ public static bool IsHost(this IMyPlayer player) { return false; } + public static long FleetID(this IMyPlayer player) { + return GridOwner.ownerFromPlayerID(player.PlayerID).FleetID; + } + } } diff --git a/Data/Scripts/GardenConquest/GardenConquest.csproj b/Data/Scripts/GardenConquest/GardenConquest.csproj index 9aeb27f..3ae8168 100644 --- a/Data/Scripts/GardenConquest/GardenConquest.csproj +++ b/Data/Scripts/GardenConquest/GardenConquest.csproj @@ -60,6 +60,7 @@ + @@ -84,7 +85,6 @@ - @@ -94,6 +94,7 @@ + diff --git a/Data/Scripts/GardenConquest/GridSorter.cs b/Data/Scripts/GardenConquest/GridSorter.cs deleted file mode 100644 index 1a3713e..0000000 --- a/Data/Scripts/GardenConquest/GridSorter.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Sandbox.ModAPI; - -using GardenConquest.Records; - -namespace GardenConquest { - public struct FACGRID { - public IMyCubeGrid grid; - public long blockCount; - public Utility.GRIDTYPE gtype; - public HullClass.CLASS hullClass; - } - - public class GridSorter : IComparer { - /// - /// Compares by grid size and then block count - /// - /// - /// - /// - public int Compare(FACGRID a, FACGRID b) { - if ((int)a.gtype < (int)b.gtype) { - return -1; - } else if ((int)a.gtype > (int)b.gtype) { - return 1; - } else { - if (a.blockCount > b.blockCount) - return -1; - else if (a.blockCount < b.blockCount) - return 1; - else - return 0; - } - } - } -} diff --git a/Data/Scripts/GardenConquest/PhysicalObjects/ShipLicense.cs b/Data/Scripts/GardenConquest/PhysicalObjects/ShipLicense.cs new file mode 100644 index 0000000..0cdb824 --- /dev/null +++ b/Data/Scripts/GardenConquest/PhysicalObjects/ShipLicense.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using Sandbox.Common.ObjectBuilders; +using VRage.ObjectBuilders; + +namespace GardenConquest.PhysicalObjects { + class ShipLicense { + public static MyObjectBuilder_Component Builder = + new MyObjectBuilder_Component() { SubtypeName = "ShipLicense" }; + + public static SerializableDefinitionId Definition = + new VRage.ObjectBuilders.SerializableDefinitionId( + typeof(MyObjectBuilder_InventoryItem), "ShipLicense" + ); + } +} diff --git a/Data/Scripts/GardenConquest/Records/ControlPoint.cs b/Data/Scripts/GardenConquest/Records/ControlPoint.cs index 6648da5..0ebfa95 100644 --- a/Data/Scripts/GardenConquest/Records/ControlPoint.cs +++ b/Data/Scripts/GardenConquest/Records/ControlPoint.cs @@ -6,15 +6,49 @@ using System.Xml.Serialization; using Sandbox.Common; +using Sandbox.Common.Components; using Sandbox.Common.ObjectBuilders; using Sandbox.Definitions; using Sandbox.ModAPI; +using InGame = Sandbox.ModAPI.Ingame; +using VRage.ModAPI; +using GardenConquest.Blocks; using GardenConquest.Extensions; +using GardenConquest.PhysicalObjects; namespace GardenConquest.Records { [XmlType("CP")] public class ControlPoint { + + public class Subfleet { + public long ID = 0; + public List Enforcers = new List(); + public int TotalValue = 0; + } + + #region Static + + private static Logger s_Logger = new Logger("ControlPoint", "Static"); + + private static void log(String message, String method = null, Logger.severity level = Logger.severity.DEBUG) { + s_Logger.log(level, method, message); + } + + private static Action, List, ControlPoint> actionDistributeRewards; + public static event Action, List, ControlPoint> OnRewardsDistributed { + add { actionDistributeRewards += value; } + remove { actionDistributeRewards -= value; } + } + private static void notifyRewardsDistributed(int distributed, List winningFleets, + List nearbyPlayers, ControlPoint cp) { + if (actionDistributeRewards != null) + actionDistributeRewards(distributed, winningFleets, nearbyPlayers, cp); + } + + #endregion + #region Instance Members + [XmlElement("Name")] public String Name { get; set; } [XmlElement("Position")] @@ -24,6 +58,10 @@ public class ControlPoint { [XmlElement("Reward")] public int TokensPerPeriod { get; set; } + #endregion + + #region Serialization + public void serialize(VRage.ByteStream stream) { stream.addLong((long)Position.X); stream.addLong((long)Position.Y); @@ -48,5 +86,189 @@ public static ControlPoint deserialize(VRage.ByteStream stream) { return result; } + + #endregion + #region Reward Distribution + + /// + /// Called at the end of a round. Distributes rewards to winning factions. + /// + public void distributeRewards() { + if (!Utility.isServer()) return; + + log("Distributing rewards for CP " + Name, "distributeRewards"); + + // group nearby grids into their corresponding fleets + Dictionary subfleets = nearbySubfleets(); + + // if there are no grids, nothing to do + if (subfleets.Keys.Count == 0) return; + + // determine which subfleet won + List winningSubfleets = winningSubfleetIDs(subfleets); + + log("Winning fleets: " + String.Join(",", winningSubfleets.ToArray()), "distributeRewards"); + + // distribute rewards + int remainingReward = TokensPerPeriod; + //var rewardsByFleet = new Dictionary(); + if (winningSubfleets.Count == 1) { + long winningFleetID = winningSubfleets.First(); + Subfleet winningFleet = subfleets[winningFleetID]; + + // Place them in grids in order of decreasing multiplier + winningFleet.Enforcers.Sort((a, b) => + (int)a.CaptureMultiplier.CompareTo((int)b.CaptureMultiplier)); + + foreach (GridEnforcer ge in winningFleet.Enforcers) { + if (remainingReward > 0) { + log(String.Format("Attempting to place {0} licenses in {1}", remainingReward, ge.Grid.DisplayName), "distributeRewards"); + remainingReward = ge.Grid.placeInCargo( + ShipLicense.Definition, + ShipLicense.Builder, + remainingReward); + } + else { + break; + } + } + } + + log("Unplaced reward: " + remainingReward, "distributeRewards"); + + // notify players + notifyRewardsDistributed(TokensPerPeriod - remainingReward, winningSubfleets, nearbyPlayers(), this); + } + + /// + /// Find all players within the CP + /// + private List nearbyPlayers() { + return MyAPIGateway.Players.getPlayersNearPoint(Position, Radius); + } + + /// + /// Group grids in the CP into subfleets + /// + private Dictionary nearbySubfleets() { + var foundSubfleets = new Dictionary(); + log("Grouping nearby grids into Subfleets.", "nearbySubfleets"); + + VRageMath.BoundingSphereD bounds = new VRageMath.BoundingSphereD(Position, (double)Radius); + List entitiesInBounds = MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds); + + foreach (IMyEntity e in entitiesInBounds) { + + // Is it a grid? + IMyCubeGrid grid = e as IMyCubeGrid; + if (grid == null) continue; + + // does it have a GE? + GridEnforcer ge = grid.Components.Get() as GridEnforcer; + if (ge == null) { + log("Failed to retrieve GridEnforcer for grid " + grid.EntityId, + "nearbySubfleets", Logger.severity.ERROR); + continue; + } + + // Is it classified? + if (ge.Class == HullClass.CLASS.UNCLASSIFIED) { + continue; + } + + + // There are no hooks to check if someone changed factions, + // so reevaluate here to make sure info is up to date for fleet groups + ge.reevaluateOwnership(); + + /* + if (ge.Owner.OwnerType == GridOwner.OWNER_TYPE.UNOWNED) { + log("Grid " + grid.EntityId + " is unowned, skipping", + "nearbySubfleets"); + continue; + } + */ + + // We could check here if the grid is supported by its fleet, + // or more generally if it's violation any rules + // But we should notify players, b/c that could be confusing + /* + if (!ge.SupportedByFleet) { + log("Grid " + grid.DisplayName + " is unsupported by its fleet, skipping.", + "getRoundWinner"); + continue; + } + */ + + // Is its Hull Classifier broadcasting far enough? + HullClassifier classifier = ge.Classifier; + if (classifier == null) { + log("Grid has no classifier but was classified", + "nearbySubfleets", Logger.severity.ERROR); + continue; + } + InGame.IMyBeacon beacon = classifier.FatBlock as InGame.IMyBeacon; + if (beacon == null) { + log("Classifier could not be referenced as beacon", + "nearbySubfleets", Logger.severity.ERROR); + continue; + } + if (!beacon.IsWorking) { + log("Classifier beacon not working but grid was classified", + "nearbySubfleets", Logger.severity.ERROR); + continue; + } + + if (beacon.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) { + log("Classifier range too small, skipping", "nearbySubfleets"); + // TODO notify pilot + continue; + } + + // Grid passed all tests! + long fleetID = ge.Owner.FleetID; + log("Grid '" + ge.Grid.DisplayName + "'passed all tests, including in fleet " + fleetID, "nearbySubfleets"); + if (!foundSubfleets.ContainsKey(fleetID)) { + foundSubfleets[fleetID] = new Subfleet { + ID = fleetID, + Enforcers = new List() { ge }, + TotalValue = ge.CaptureMultiplier, + }; + } else { + foundSubfleets[fleetID].Enforcers.Add(ge); + foundSubfleets[fleetID].TotalValue += ge.CaptureMultiplier; + } + } + + return foundSubfleets; + } + + /// + /// Return the FleetIDs for each winning subfleet in subfleets + /// + private List winningSubfleetIDs(Dictionary subfleets) { + var winningSubfleets = new List(); + int winningFleetValue = 0; + int currentValue; + + foreach (KeyValuePair entry in subfleets) { + currentValue = entry.Value.TotalValue; + if (currentValue == winningFleetValue) { + // tie + winningSubfleets.Add(entry.Key); + } + else if (currentValue > winningFleetValue) { + // new winner + winningSubfleets.Clear(); + winningSubfleets.Add(entry.Key); + winningFleetValue = currentValue; + } + } + + return winningSubfleets; + } + + #endregion + } } diff --git a/Data/Scripts/GardenConquest/Records/DerelictTimer.cs b/Data/Scripts/GardenConquest/Records/DerelictTimer.cs index 56eace2..4bb050e 100644 --- a/Data/Scripts/GardenConquest/Records/DerelictTimer.cs +++ b/Data/Scripts/GardenConquest/Records/DerelictTimer.cs @@ -145,7 +145,7 @@ public bool cancel() { StateTracker.getInstance().removeDerelictTimer(m_TimerInfo.GridID); - m_Timer.Stop(); + m_Timer.Dispose(); m_Timer = null; m_TimerInfo = null; @@ -165,7 +165,7 @@ private void timerExpired() { StateTracker.getInstance().removeDerelictTimer(m_TimerInfo.GridID); - m_Timer.Stop(); + m_Timer.Dispose(); m_Timer = null; CompletedPhase = m_TimerInfo.Phase; diff --git a/Data/Scripts/GardenConquest/Records/GridOwner.cs b/Data/Scripts/GardenConquest/Records/GridOwner.cs index 3203779..d36894f 100644 --- a/Data/Scripts/GardenConquest/Records/GridOwner.cs +++ b/Data/Scripts/GardenConquest/Records/GridOwner.cs @@ -251,8 +251,7 @@ public FactionFleet getFleet() { log("null state, probably initing", "getFleet"); } - log("failed to load fleet from state tracker", - "getFleet", Logger.severity.WARNING); + log("failed to load fleet from state tracker", "getFleet"); m_StateLoaded = false; if (m_Fleet == null) { From 444b575687ca9cbe31b7e388d7e626d5c361dedf Mon Sep 17 00:00:00 2001 From: Zach Risher Date: Thu, 6 Aug 2015 20:58:42 -0700 Subject: [PATCH 10/18] add ability to show/hide CP GPS markers --- Data/Scripts/GardenConquest/Constants.cs | 2 +- .../GardenConquest/Core/CommandProcessor.cs | 45 ++++++++++++------- .../Messaging/ResponseProcessor.cs | 32 +++++++++++-- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Data/Scripts/GardenConquest/Constants.cs b/Data/Scripts/GardenConquest/Constants.cs index f42d2de..0d49e6a 100644 --- a/Data/Scripts/GardenConquest/Constants.cs +++ b/Data/Scripts/GardenConquest/Constants.cs @@ -33,7 +33,7 @@ public static class Constants { /// /// Current Version of Garden Conquest /// - public const String Version = "1.0.9.4"; + public const String Version = "1.0.9.5"; /// /// Notification duration diff --git a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs index 6eba9c4..7ab7562 100644 --- a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs +++ b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs @@ -24,23 +24,21 @@ class CommandProcessor { private static Logger s_Logger = null; private static string s_HelpText = - " ----- Garden Conquest V" + Constants.Version + " ------ \n\n" + + " ----- Garden Conquest V" + Constants.Version + " ------ \n" + "Garden Conquest is a new, open source, Conquest-type mod. " + "It introduces ship classes and control points for " + "combat-focused servers.\n\n" + - "If you're new to GC, check out the help subtopics below.\n\n" + "Chat Commands:\n" + "/gc help - Show this screen\n" + - "/gc help [category] - Show help for a category:\n" + - " classes - Ship Classes and their limits\n" + - " classifiers - Hull Classifier blocks\n" + - " cps - Control Points\n" + - " licenses - Ship License components\n" + - "/gc fleet - Information on your fleet \n" + - "/gc fleet [command] - Commands for your fleet\n" + - " stop [class] [id] - Stops your ship, given class and ID\n" + - //"/gc fleet remove \"Ship Name\"- Disown a ship"; - "/gc violations - Your fleet's current rule violations, if any"; + "/gc help classes - Ship Classes and their limits\n" + + "/gc help classifiers - Hull Classifier blocks\n" + + "/gc help licenses - Ship License components\n" + + "/gc cps - Info on Control Points\n" + + "/gc cps hide - Hide the CP GPS markers\n" + + "/gc cps show - Show the CP GPS markers\n" + + "/gc fleet - Info on your fleet \n" + + "/gc fleet stop [Class] [N] - Stop your Nth ship of class Class\n" + + "/gc violations - Your fleet's current rule violations, if any\n"; private static string s_HelpClassesText; private static string s_HelpClassifiersText; @@ -91,12 +89,10 @@ public void handleChatCommand(string messageText, ref bool sendToOthers) { switch (cmd[1].ToLower()) { case "about": case "help": - if (numCommands == 1) + if (numCommands == 1) { Utility.showDialog("Help", s_HelpText, "Close"); - else - { - switch (cmd[2].ToLower()) - { + } else { + switch (cmd[2].ToLower()) { case "classes": Utility.showDialog("Help - Classes", helpClassesText(), "Close"); break; @@ -113,6 +109,21 @@ public void handleChatCommand(string messageText, ref bool sendToOthers) { } break; + case "cps": + if (numCommands == 1) { + Utility.showDialog("Help - Control Points", helpCPsText(), "Close"); + } else if (numCommands == 2) { + switch (cmd[2].ToLower()) { + case "show": + m_MailMan.addCPGPS(); + break; + case "hide": + m_MailMan.removeCPGPS(); + break; + } + } + break; + case "fleet": if (numCommands == 1) { m_MailMan.requestFleet(); diff --git a/Data/Scripts/GardenConquest/Messaging/ResponseProcessor.cs b/Data/Scripts/GardenConquest/Messaging/ResponseProcessor.cs index e1ea9a4..3906571 100644 --- a/Data/Scripts/GardenConquest/Messaging/ResponseProcessor.cs +++ b/Data/Scripts/GardenConquest/Messaging/ResponseProcessor.cs @@ -28,6 +28,8 @@ public class ResponseProcessor { private List[] m_UnsupportedGrids; private ConquestSettings.SETTINGS m_ServerSettings; + private List m_ServerCPGPS = new List(); + private bool m_ServerCPGPSAdded = false; private bool m_Registered = false; public ConquestSettings.SETTINGS ServerSettings { @@ -241,12 +243,15 @@ private void processSettingsResponse(SettingsResponse resp) { log("Adding CP GPS", "processSettingsResponse"); foreach (Records.ControlPoint cp in ServerSettings.ControlPoints) { - IMyGps gps = MyAPIGateway.Session.GPS.Create( - cp.Name, "GardenConquest Control Point", + m_ServerCPGPS.Add(MyAPIGateway.Session.GPS.Create( + cp.Name, + "GardenConquest Control Point", new VRageMath.Vector3D(cp.Position.X, cp.Position.Y, cp.Position.Z), - true, true); - MyAPIGateway.Session.GPS.AddLocalGps(gps); + true, true + )); } + + addCPGPS(); } private void processFleetResponse(FleetResponse resp) { @@ -346,6 +351,25 @@ private string buildFleetInfoTitle(GridOwner.OWNER_TYPE ownerType) { return fleetInfoTitle; } + public void addCPGPS() { + foreach (IMyGps gps in m_ServerCPGPS) { + MyAPIGateway.Session.GPS.AddLocalGps(gps); + } + + m_ServerCPGPSAdded = true; + } + + public void removeCPGPS() { + if (!m_ServerCPGPSAdded) + return; + + foreach (IMyGps gps in m_ServerCPGPS) { + MyAPIGateway.Session.GPS.RemoveLocalGps(gps.Hash); + } + + m_ServerCPGPSAdded = false; + } + #endregion private static void log(String message, String method = null, Logger.severity level = Logger.severity.DEBUG) { From eb49dc699290edc934effec7d441c762ccb455f0 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Sun, 6 Sep 2015 23:58:41 +0300 Subject: [PATCH 11/18] Changed HullClassifier to MyRadioAntenna instead of MyBeacon --- .gitignore | 1 + Data/BlockCategories.sbc | 30 ++++++++-------- Data/CubeBlocks.sbc | 34 +++++++++---------- Data/Prefabs/GCSpawnShip.sbc | 2 +- .../GardenConquest/Blocks/GridEnforcer.cs | 4 +-- .../GardenConquest/Blocks/HullClassifier.cs | 4 +-- .../GardenConquest/Core/CommandProcessor.cs | 2 +- .../GardenConquest/Records/ControlPoint.cs | 12 +++---- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 6a68ce6..dba7722 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ +*.bak \ No newline at end of file diff --git a/Data/BlockCategories.sbc b/Data/BlockCategories.sbc index 8419bd2..43cb498 100644 --- a/Data/BlockCategories.sbc +++ b/Data/BlockCategories.sbc @@ -9,21 +9,21 @@ Hull Classifiers Hull Classifiers - Beacon/GCUnlicensedHullClassifier - Beacon/GCWorkerHullClassifier - Beacon/GCFoundryHullClassifier - Beacon/GCScoutHullClassifier - Beacon/GCFighterHullClassifier - Beacon/GCGunshipHullClassifier - Beacon/GCCorvetteHullClassifier - Beacon/GCFrigateHullClassifier - Beacon/GCDestroyerHullClassifier - Beacon/GCCruiserHullClassifier - Beacon/GCHeavyCruiserHullClassifier - Beacon/GCBattleshipHullClassifier - Beacon/GCOutpostHullClassifier - Beacon/GCInstallationHullClassifier - Beacon/GCFortressHullClassifier + RadioAntenna/GCUnlicensedHullClassifier + RadioAntenna/GCWorkerHullClassifier + RadioAntenna/GCFoundryHullClassifier + RadioAntenna/GCScoutHullClassifier + RadioAntenna/GCFighterHullClassifier + RadioAntenna/GCGunshipHullClassifier + RadioAntenna/GCCorvetteHullClassifier + RadioAntenna/GCFrigateHullClassifier + RadioAntenna/GCDestroyerHullClassifier + RadioAntenna/GCCruiserHullClassifier + RadioAntenna/GCHeavyCruiserHullClassifier + RadioAntenna/GCBattleshipHullClassifier + RadioAntenna/GCOutpostHullClassifier + RadioAntenna/GCInstallationHullClassifier + RadioAntenna/GCFortressHullClassifier diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 5675102..9eb92ba 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -6,7 +6,7 @@ - Beacon + RadioAntenna GCUnlicensedHullClassifier Unlicensed Hull Classifier @@ -47,7 +47,7 @@ - Beacon + RadioAntenna GCUnlicensedHullClassifierSmall Unlicensed Hull Classifier @@ -82,7 +82,7 @@ - Beacon + RadioAntenna GCWorkerHullClassifier Worker Hull Classifier @@ -124,7 +124,7 @@ - Beacon + RadioAntenna GCWorkerHullClassifierSmall Worker Hull Classifier @@ -156,7 +156,7 @@ - Beacon + RadioAntenna GCFoundryHullClassifier Foundry Hull Classifier @@ -203,7 +203,7 @@ - Beacon + RadioAntenna GCScoutHullClassifier Scout Hull Classifier @@ -235,7 +235,7 @@ - Beacon + RadioAntenna GCFighterHullClassifier Fighter Hull Classifier @@ -267,7 +267,7 @@ - Beacon + RadioAntenna GCGunshipHullClassifier Gunship Hull Classifier @@ -303,7 +303,7 @@ - Beacon + RadioAntenna GCCorvetteHullClassifier Corvette Hull Classifier @@ -346,7 +346,7 @@ - Beacon + RadioAntenna GCFrigateHullClassifier Frigate Hull Classifier @@ -389,7 +389,7 @@ - Beacon + RadioAntenna GCDestroyerHullClassifier Destroyer Hull Classifier @@ -432,7 +432,7 @@ - Beacon + RadioAntenna GCCruiserHullClassifier Cruiser Hull Classifier @@ -475,7 +475,7 @@ - Beacon + RadioAntenna GCHeavyCruiserHullClassifier Heavy Cruiser Hull Classifier @@ -518,7 +518,7 @@ - Beacon + RadioAntenna GCBattleshipHullClassifier Battleship Hull Classifier @@ -565,7 +565,7 @@ - Beacon + RadioAntenna GCOutpostHullClassifier Outpost Hull Classifier @@ -608,7 +608,7 @@ - Beacon + RadioAntenna GCInstallationHullClassifier Installation Hull Classifier @@ -651,7 +651,7 @@ - Beacon + RadioAntenna GCFortressHullClassifier Fortress Hull Classifier diff --git a/Data/Prefabs/GCSpawnShip.sbc b/Data/Prefabs/GCSpawnShip.sbc index 355cf5b..dc14ee1 100644 --- a/Data/Prefabs/GCSpawnShip.sbc +++ b/Data/Prefabs/GCSpawnShip.sbc @@ -1180,7 +1180,7 @@ people will try to kill you. 10 0 - + GCUnlicensedHullClassifier 200619511763221591 diff --git a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs index 70e7de9..640dd0f 100644 --- a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs +++ b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs @@ -244,7 +244,7 @@ public override void Init(MyObjectBuilder_EntityBase objectBuilder) { } // We need to only turn on our rule checking after startup. Otherwise, if - // a beacon is destroyed and then the server restarts, all but the first + // a antenna is destroyed and then the server restarts, all but the first // 25 blocks will be deleted on startup. m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; @@ -975,7 +975,7 @@ private void removeExtraClassifiers(int removeCount = 100) { /// The cleanest way to do that would be making Hull Classifiers a logic component /// so we can track isWorking there and make sure it's closed when they are /// This would require the ge to be able to find the HullClassifier component on - /// an added beacon, which seems like it might be possible, but also might not + /// an added antenna, which seems like it might be possible, but also might not /// private List findWorstClassifiers(uint removeCount = 0) { List worstClassifiers = new List(); diff --git a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs index 050c1d3..d0ead71 100644 --- a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs +++ b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs @@ -63,7 +63,7 @@ private static HullClass.CLASS HullClassFromSubTypeString(String subTypeString) /// public static bool isClassifierBlock(IMySlimBlock block) { IMyCubeBlock fatblock = block.FatBlock; - if (fatblock != null && fatblock is Ingame.IMyBeacon) { + if (fatblock != null && fatblock is Ingame.IMyRadioAntenna) { String subTypeName = fatblock.BlockDefinition.SubtypeName; if (subTypeName.Contains(SHARED_SUBTYPE)) return true; @@ -98,4 +98,4 @@ public HullClassifier(IMySlimBlock block) { #endregion } -} +} \ No newline at end of file diff --git a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs index 7ab7562..fbdd565 100644 --- a/Data/Scripts/GardenConquest/Core/CommandProcessor.cs +++ b/Data/Scripts/GardenConquest/Core/CommandProcessor.cs @@ -267,7 +267,7 @@ private String helpCPsText() { "In order to control the CP, your fleet must " + "have the most ships in that area that:\n" + - "* have a powered, broadcasting Hull Classifier beacon\n" + + "* have a powered, broadcasting Hull Classifier antenna\n" + "* have a broadcast range on the classifier at least as large " + " as the ship's distance to the CP. (This is to prevent players " + "from hiding while capturing a CP. If someone stands in the " + diff --git a/Data/Scripts/GardenConquest/Records/ControlPoint.cs b/Data/Scripts/GardenConquest/Records/ControlPoint.cs index 0ebfa95..f493c5f 100644 --- a/Data/Scripts/GardenConquest/Records/ControlPoint.cs +++ b/Data/Scripts/GardenConquest/Records/ControlPoint.cs @@ -207,19 +207,19 @@ private Dictionary nearbySubfleets() { "nearbySubfleets", Logger.severity.ERROR); continue; } - InGame.IMyBeacon beacon = classifier.FatBlock as InGame.IMyBeacon; - if (beacon == null) { - log("Classifier could not be referenced as beacon", + InGame.IMyRadioAntenna antenna = classifier.FatBlock as InGame.IMyRadioAntenna; + if (antenna == null) { + log("Classifier could not be referenced as antenna", "nearbySubfleets", Logger.severity.ERROR); continue; } - if (!beacon.IsWorking) { - log("Classifier beacon not working but grid was classified", + if (!antenna.IsWorking) { + log("Classifier antenna not working but grid was classified", "nearbySubfleets", Logger.severity.ERROR); continue; } - if (beacon.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) { + if (antenna.Radius < VRageMath.Vector3.Distance(Position, grid.GetPosition())) { log("Classifier range too small, skipping", "nearbySubfleets"); // TODO notify pilot continue; From 37b4173d61352b25e00fbb43c29a3ea9a6d07656 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Mon, 7 Sep 2015 00:12:54 +0300 Subject: [PATCH 12/18] Changed HullClassifier mount points so they cover the whole surface --- Data/CubeBlocks.sbc | 96 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 9eb92ba..42ebff4 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -30,10 +30,10 @@ - - - - + + + + @@ -107,10 +107,10 @@ - - - - + + + + @@ -181,10 +181,10 @@ - - - - + + + + @@ -328,10 +328,10 @@ - - - - + + + + @@ -371,10 +371,10 @@ - - - - + + + + @@ -414,10 +414,10 @@ - - - - + + + + @@ -457,10 +457,10 @@ - - - - + + + + @@ -500,10 +500,10 @@ - - - - + + + + @@ -543,10 +543,10 @@ - - - - + + + + @@ -590,10 +590,10 @@ - - - - + + + + @@ -633,10 +633,10 @@ - - - - + + + + @@ -676,10 +676,10 @@ - - - - + + + + From 7c473fe6f22afea210d8459a86a648111f599af4 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Mon, 7 Sep 2015 04:25:56 +0300 Subject: [PATCH 13/18] Bacon surfaces made fully mountable --- Data/CubeBlocks.sbc | 80 +++++++++++++++++++ .../GardenConquest/Blocks/HullClassifier.cs | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 42ebff4..d085f86 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -2,6 +2,86 @@ + + + + + Beacon + LargeBlockBeacon + + DisplayName_Block_Beacon + Textures\GUI\Icons\Cubes\beacon.dds + Large + TriangleMesh + + + Models\Cubes\Large\beacon.mwm + + + + + + + + + + + + + + + + + + + + + + + + + Beacon + Light + 50 + 214 + ParticleElectrical + + + + + Beacon + SmallBlockBeacon + + DisplayName_Block_Beacon + Textures\GUI\Icons\Cubes\beacon.dds + Small + TriangleMesh + + + Models\Cubes\Small\beacon.mwm + + + + + + + + + + + + Beacon + Z + Y + Light + 15 + 214 + ParticleElectrical + + + + + diff --git a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs index d0ead71..d5c017e 100644 --- a/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs +++ b/Data/Scripts/GardenConquest/Blocks/HullClassifier.cs @@ -98,4 +98,4 @@ public HullClassifier(IMySlimBlock block) { #endregion } -} \ No newline at end of file +} From 28a15f9bdca7d8e9822f1eed80b4cf385a32129a Mon Sep 17 00:00:00 2001 From: drNovikov Date: Tue, 8 Sep 2015 23:09:17 +0300 Subject: [PATCH 14/18] Beacon and Hull Classifiers mount points reverted to vanilla --- .gitignore | 2 +- Data/CubeBlocks.sbc | 176 ++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 129 deletions(-) diff --git a/.gitignore b/.gitignore index dba7722..e1837c0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ -*.bak \ No newline at end of file +*.bak diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index d085f86..9eb92ba 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -2,86 +2,6 @@ - - - - - Beacon - LargeBlockBeacon - - DisplayName_Block_Beacon - Textures\GUI\Icons\Cubes\beacon.dds - Large - TriangleMesh - - - Models\Cubes\Large\beacon.mwm - - - - - - - - - - - - - - - - - - - - - - - - - Beacon - Light - 50 - 214 - ParticleElectrical - - - - - Beacon - SmallBlockBeacon - - DisplayName_Block_Beacon - Textures\GUI\Icons\Cubes\beacon.dds - Small - TriangleMesh - - - Models\Cubes\Small\beacon.mwm - - - - - - - - - - - - Beacon - Z - Y - Light - 15 - 214 - ParticleElectrical - - - - - @@ -110,10 +30,10 @@ - - - - + + + + @@ -187,10 +107,10 @@ - - - - + + + + @@ -261,10 +181,10 @@ - - - - + + + + @@ -408,10 +328,10 @@ - - - - + + + + @@ -451,10 +371,10 @@ - - - - + + + + @@ -494,10 +414,10 @@ - - - - + + + + @@ -537,10 +457,10 @@ - - - - + + + + @@ -580,10 +500,10 @@ - - - - + + + + @@ -623,10 +543,10 @@ - - - - + + + + @@ -670,10 +590,10 @@ - - - - + + + + @@ -713,10 +633,10 @@ - - - - + + + + @@ -756,10 +676,10 @@ - - - - + + + + From 0bca8bc3d8bb60c8230deb6e32a725475ebe1833 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Tue, 8 Sep 2015 23:20:25 +0300 Subject: [PATCH 15/18] Fixed a typo in a comment --- Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs index 640dd0f..eb32cba 100644 --- a/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs +++ b/Data/Scripts/GardenConquest/Blocks/GridEnforcer.cs @@ -244,7 +244,7 @@ public override void Init(MyObjectBuilder_EntityBase objectBuilder) { } // We need to only turn on our rule checking after startup. Otherwise, if - // a antenna is destroyed and then the server restarts, all but the first + // an antenna is destroyed and then the server restarts, all but the first // 25 blocks will be deleted on startup. m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; From 5edd8b5b08642150e4d1a7f33dd58e46a9bd88c6 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Wed, 9 Sep 2015 17:50:47 +0300 Subject: [PATCH 16/18] Removed my *.bak from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e1837c0..6a68ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ Data/Scripts/GardenConquest/GardenConquest.v11.suo modinfo.sbmi GardenConquestTests/bin/ GardenConquestTests/obj/ -*.bak From 327dbc4f5cdcb63e025930f9a926ca703bbb2cbb Mon Sep 17 00:00:00 2001 From: drNovikov Date: Sun, 20 Sep 2015 15:27:02 +0300 Subject: [PATCH 17/18] "/gc fleet stop" enables thrusters, enables gyroscopes, sets gyro power to 100%, disables gyro overrides The "/gc fleet stop" command enables thrusters, also enables gyroscopes, sets their power to 100%, and disables their overrides. This was added because the command failed to stop ships on the server if their thrusters were turned off. --- .../GardenConquest/Messaging/RequestProcessor.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs b/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs index 5440ada..738d87d 100644 --- a/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs +++ b/Data/Scripts/GardenConquest/Messaging/RequestProcessor.cs @@ -137,7 +137,7 @@ private void processStopGridRequest(StopGridRequest req) { // Get all thrusters, spaceballs, artificial masses, and cockpits Func selectBlocks = b => - b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController); + b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMyGyro || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController); gridToStop.GetBlocks(fatBlocks, selectBlocks); // Can the player interact with this grid? If they can, stop the ship by enabling dampeners, turning off @@ -146,7 +146,14 @@ private void processStopGridRequest(StopGridRequest req) { foreach (IMySlimBlock block in fatBlocks) { // Thruster if (block.FatBlock is IMyThrust) { - Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0); + (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(true); + Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0); + } + // Gyroscope + if (block.FatBlock is IMyGyro) { + (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(true); + Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Power", 1); + Interfaces.TerminalPropertyExtensions.SetValueBool(block.FatBlock as InGame.IMyGyro, "Override", false); } // Spaceball else if (block.FatBlock is IMySpaceBall) { From f67dfb14bca1ae399a75c685b900269bcaab94b7 Mon Sep 17 00:00:00 2001 From: drNovikov Date: Thu, 8 Oct 2015 10:45:42 +0300 Subject: [PATCH 18/18] Added ResourceSinkGroup to hull classifier definitions Added Utility to every Hull Classifier definition --- Data/CubeBlocks.sbc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Data/CubeBlocks.sbc b/Data/CubeBlocks.sbc index 9eb92ba..d57d258 100644 --- a/Data/CubeBlocks.sbc +++ b/Data/CubeBlocks.sbc @@ -11,6 +11,7 @@ Unlicensed Hull Classifier Textures\Icons\unlicensed-1-128.dds + Utility Large TriangleMesh @@ -52,6 +53,7 @@ Unlicensed Hull Classifier Textures\Icons\unlicensed-1-128.dds + Utility Small TriangleMesh @@ -87,6 +89,7 @@ Worker Hull Classifier Textures\Icons\utility-1-128.dds + Utility Large TriangleMesh @@ -129,6 +132,7 @@ Worker Hull Classifier Textures\Icons\utility-1-128.dds + Utility Small TriangleMesh @@ -161,6 +165,7 @@ Foundry Hull Classifier Textures\Icons\utility-2-128.dds + Utility Large TriangleMesh @@ -208,6 +213,7 @@ Scout Hull Classifier Textures\Icons\strikecraft-1-128.dds + Utility Small TriangleMesh @@ -240,6 +246,7 @@ Fighter Hull Classifier Textures\Icons\strikecraft-2-128.dds + Utility Small TriangleMesh @@ -272,6 +279,7 @@ Gunship Hull Classifier Textures\Icons\strikecraft-3-128.dds + Utility Small TriangleMesh @@ -308,6 +316,7 @@ Corvette Hull Classifier Textures\Icons\corvette-1-128.dds + Utility Large TriangleMesh @@ -351,6 +360,7 @@ Frigate Hull Classifier Textures\Icons\frigate-1-128.dds + Utility Large TriangleMesh @@ -394,6 +404,7 @@ Destroyer Hull Classifier Textures\Icons\capital-1-128.dds + Utility Large TriangleMesh @@ -437,6 +448,7 @@ Cruiser Hull Classifier Textures\Icons\capital-2-128.dds + Utility Large TriangleMesh @@ -480,6 +492,7 @@ Heavy Cruiser Hull Classifier Textures\Icons\supercapital-1-128.dds + Utility Large TriangleMesh @@ -523,6 +536,7 @@ Battleship Hull Classifier Textures\Icons\supercapital-2-128.dds + Utility Large TriangleMesh @@ -570,6 +584,7 @@ Outpost Hull Classifier Textures\Icons\station-1-128.dds + Utility Large TriangleMesh @@ -613,6 +628,7 @@ Installation Hull Classifier Textures\Icons\station-2-128.dds + Utility Large TriangleMesh @@ -656,6 +672,7 @@ Fortress Hull Classifier Textures\Icons\station-3-128.dds + Utility Large TriangleMesh