Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special Engine and ModuleManager Intake Patch for Season 2 Round 2 #11

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a96934b
Rolling spawning (sliders for controlling the maximum number of craft…
BrettRyland Sep 8, 2020
97ba75f
Use user-set altitude and other settings for remote orchestration spa…
josuenos Sep 9, 2020
464439f
Fix death counts in logged scores for vessels that have run out of li…
BrettRyland Sep 9, 2020
e0f3ee4
Merge branch 'dev' into rolling-spawning
BrettRyland Sep 9, 2020
ae44d6e
Adjust DeathOrder for continuous spawn to avoid '<vessel> killed by <…
BrettRyland Sep 9, 2020
2d8389e
Don't clean up SpaceObjects in RemoveDebris as it is a source of null…
BrettRyland Sep 9, 2020
c739849
Merge branch 'rolling-spawning' into dev
BrettRyland Sep 9, 2020
73a5f5e
Also set the nextUpdateTick, gracePeriod and decisionTick in Competit…
BrettRyland Sep 9, 2020
75f0925
Clear the pilotActions dictionary to avoid '<pilot> is Dead' when
BrettRyland Sep 9, 2020
237ea12
Start tilted 10° outwards when spawning in the air.
BrettRyland Sep 9, 2020
a564929
Extra setting REMOTE_LOGGING_VISIBLE in the settings.cfg file only to…
BrettRyland Sep 9, 2020
94182b7
Store the competition distance. Automatically dump scores when leavin…
BrettRyland Sep 10, 2020
9839c2c
Trigger result logging on scene change from BDACompetitionMode. Missi…
BrettRyland Sep 10, 2020
4ecb9e5
Don't kill space objects during spawning as killing comets causes nul…
BrettRyland Sep 10, 2020
c9c8236
Fix craft not responding to multiple missile threats
josuenos Sep 10, 2020
233197e
Support scoring for hits and damage in/out
agoodman Sep 11, 2020
2338785
Fixed stats clearing bug
agoodman Sep 11, 2020
b7b5a78
Merge commit 'refs/pull/62/head' of github.com:BrettRyland/BDArmory i…
BrettRyland Sep 11, 2020
2bc4ff2
Make sure both attacker and target are in the scores datastructure be…
BrettRyland Sep 11, 2020
9dfc7e8
Implement clean-kill tracking separately from kill tracking.
BrettRyland Sep 11, 2020
db5c861
Only count clean kills, give assists for regular kills.
BrettRyland Sep 11, 2020
eec0f54
Log competition start as well as starting competition.
BrettRyland Sep 11, 2020
6b39aa7
Adjust vessel switcher window's display of dead vessels to reflect cl…
BrettRyland Sep 11, 2020
5ddade6
Include damage from bullet explosions in ScoreService.
BrettRyland Sep 11, 2020
8eb4387
Only do that if remote loggin is enabled.
BrettRyland Sep 11, 2020
b2ac2bd
Include VesselSpawnerField.cs
BrettRyland Sep 11, 2020
ae4ac12
Interesting Vessel Spawn locations with separate cfg file.
BrettRyland Sep 11, 2020
8d3adbf
And the VesselSpawnerField.cs file.
BrettRyland Sep 11, 2020
dade348
Merge branch 'dev' into spawning
BrettRyland Sep 11, 2020
a170b37
Proper log message for when no locations are found.
BrettRyland Sep 11, 2020
c730790
Update the default insteresting spawn locations.
BrettRyland Sep 11, 2020
c9b4ffd
Temporarily set REMOTE_LOGGING_VISIBLE to true so Scott doesn't have …
BrettRyland Sep 11, 2020
9550c4a
Ignore vesselnaming line to force reset
agoodman Sep 13, 2020
6726187
Ignore vesselnaming line to force reset
agoodman Sep 13, 2020
2e608ba
Merge pull request #48 from BrettRyland/dev
josuenos Sep 13, 2020
d705e6d
Add special liquid-fuel-only engine and ModuleManager patch for air i…
josuenos Sep 13, 2020
653a6c5
Switch teams immediately when doing mass team switches. This avoids t…
BrettRyland Sep 13, 2020
56b3bbc
Merge pull request #49 from BrettRyland/master
josuenos Sep 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions BDArmory.Core/BDAPersistantSettingsField.cs
Expand Up @@ -107,15 +107,14 @@ public static object ParseValue(Type type, string value)
}
else if (type == typeof(Vector2d))
{
char[] charsToTrim = { '(', ')' };
char[] charsToTrim = { '(', ')', ' ' };
string[] strings = value.Trim(charsToTrim).Split(',');
double x = double.Parse(strings[0]);
double y = double.Parse(strings[1]);
return new Vector2d(x, y);
}
Debug.LogError("[BDArmory]: BDAPersistantSettingsField to parse settings field of type " + type +
" and value " + value);


Debug.LogError("[BDArmory]: BDAPersistantSettingsField to parse settings field of type " + type + " and value " + value);
return null;
}
}
Expand Down
4 changes: 4 additions & 0 deletions BDArmory.Core/BDArmorySettings.cs
Expand Up @@ -72,15 +72,19 @@ public class BDArmorySettings
[BDAPersistantSettingsField] public static int CAMERA_SWITCH_FREQUENCY = 3; // Controls the minimum time between automated camera switches
[BDAPersistantSettingsField] public static float OUT_OF_AMMO_KILL_TIME = -1f; // Out of ammo kill timer for continuous spawn mode.
[BDAPersistantSettingsField] public static bool DEBUG_RAMMING_LOGGING = false; // Controls whether ramming logging debug information is printed to the Debug.Log
[BDAPersistantSettingsField] public static bool REMOTE_LOGGING_VISIBLE = true; // Show/hide the remote orchestration toggle
[BDAPersistantSettingsField] public static bool REMOTE_LOGGING_ENABLED = false; // Enable/disable remote orchestration
[BDAPersistantSettingsField] public static string COMPETITION_HASH = ""; // Competition hash used for orchestration
[BDAPersistantSettingsField] public static int COMPETITION_DURATION = 5; // Competition duration in minutes
[BDAPersistantSettingsField] public static float COMPETITION_DISTANCE = 1000; // Competition distance.
[BDAPersistantSettingsField] public static float VESSEL_SWITCHER_WINDOW_WIDTH = 500f;
[BDAPersistantSettingsField] public static bool VESSEL_SWITCHER_WINDOW_SORTING = false;
[BDAPersistantSettingsField] public static Vector2d VESSEL_SPAWN_GEOCOORDS = new Vector2d(0.05096, -74.8016); // Spawning coordinates on a planetary body.
[BDAPersistantSettingsField] public static float VESSEL_SPAWN_ALTITUDE = 5f; // Spawning altitude above the surface.
[BDAPersistantSettingsField] public static float VESSEL_SPAWN_DISTANCE = 20f; // Scale factor for the size of the spawning circle.
[BDAPersistantSettingsField] public static float VESSEL_SPAWN_EASE_IN_SPEED = 1f; // Rate to limit "falling" during spawning.
[BDAPersistantSettingsField] public static int VESSEL_SPAWN_CONCURRENT_VESSELS = 0; // Maximum number of vessels to spawn in concurrently (continuous spawning mode).
[BDAPersistantSettingsField] public static int VESSEL_SPAWN_LIVES_PER_VESSEL = 0; // Maximum number of times to spawn a vessel (continuous spawning mode).
[BDAPersistantSettingsField] public static bool DISABLE_KILL_TIMER = false; //disables the kill timers.
[BDAPersistantSettingsField] public static float REMOTE_ORCHESTRATION_WINDOW_WIDTH = 200f;
[BDAPersistantSettingsField] public static bool RUNWAY_PROJECT = true; // Enable/disable Runway Project specific enhancements. FIXME Default to true for now. Later, default to false for official BDArmory release.
Expand Down
7 changes: 7 additions & 0 deletions BDArmory/BDArmory.csproj
Expand Up @@ -234,6 +234,7 @@
<Compile Include="UI\IBDWMModule.cs" />
<Compile Include="UI\KrakensbaneDebug.cs" />
<Compile Include="UI\VesselSpawner.cs" />
<Compile Include="UI\VesselSpawnerField.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BDArmory.Core\BDArmory.Core.csproj">
Expand Down Expand Up @@ -284,6 +285,7 @@
<None Include="Distribution\GameData\BDArmory\Localization\UI\en-us.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\000000_HitpointModule.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\000000_HitpointModule_PartFixes.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\000000_IntakeModule_PartFixes.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\10_bdac_stealth.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\Armor_CVE.cfg" />
<None Include="Distribution\GameData\BDArmory\MMPatches\BDA_Armor.cfg" />
Expand Down Expand Up @@ -402,6 +404,8 @@
<None Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\Sounds\m230loop.ogg" />
<None Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\Sounds\m230loopEnd.ogg" />
<None Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\Sounds\m230shot.ogg" />
<None Include="Distribution\GameData\BDArmory\Parts\ManleyDrive\manley_drive.cfg" />
<None Include="Distribution\GameData\BDArmory\Parts\ManleyDrive\SSME.mu" />
<None Include="Distribution\GameData\BDArmory\Parts\maverick\maverickMissile.cfg" />
<None Include="Distribution\GameData\BDArmory\Parts\maverick\model.mu" />
<None Include="Distribution\GameData\BDArmory\Parts\missileTurret\missileTurret.cfg" />
Expand Down Expand Up @@ -607,6 +611,9 @@
<Content Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\muzzle.png" />
<Content Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\smoke.png" />
<Content Include="Distribution\GameData\BDArmory\Parts\m230ChainGun\texture.png" />
<Content Include="Distribution\GameData\BDArmory\Parts\ManleyDrive\SSME.dds" />
<Content Include="Distribution\GameData\BDArmory\Parts\ManleyDrive\SSME_GLOW.dds" />
<Content Include="Distribution\GameData\BDArmory\Parts\ManleyDrive\SSME_NRM.dds" />
<Content Include="Distribution\GameData\BDArmory\Parts\maverick\texture.png" />
<Content Include="Distribution\GameData\BDArmory\Parts\missileTurret\tex_detectionRadar.png" />
<Content Include="Distribution\GameData\BDArmory\Parts\missileTurret\tex_lockingTurret.png" />
Expand Down
8 changes: 5 additions & 3 deletions BDArmory/Bullets/PooledBullet.cs
Expand Up @@ -544,15 +544,17 @@ private void ApplyDamage(Part hitPart, RaycastHit hit, float multiplier, float p
var aName = this.sourceVessel.GetName();
var tName = hitPart.vessel.GetName();

if (aName != tName)
if (aName != tName && BDACompetitionMode.Instance.Scores.ContainsKey(aName) && BDACompetitionMode.Instance.Scores.ContainsKey(tName))
{
//Debug.Log("[BDArmory]: Weapon from " + aName + " damaged " + tName);

if (BDArmorySettings.REMOTE_LOGGING_ENABLED)
{
BDAScoreService.Instance.TrackHit(aName, tName, bullet.name, distanceTraveled);
BDAScoreService.Instance.TrackDamage(aName, tName, damage);
}

// update scoring structure on attacker
if (BDACompetitionMode.Instance.Scores.ContainsKey(aName))
{
var aData = BDACompetitionMode.Instance.Scores[aName];
aData.Score += 1;
Expand All @@ -565,8 +567,8 @@ private void ApplyDamage(Part hitPart, RaycastHit hit, float multiplier, float p
}

}

// update scoring structure on the defender.
if (BDACompetitionMode.Instance.Scores.ContainsKey(tName))
{
var tData = BDACompetitionMode.Instance.Scores[tName];
tData.lastPersonWhoHitMe = aName;
Expand Down
5 changes: 4 additions & 1 deletion BDArmory/Competition/BDAScoreClient.cs
Expand Up @@ -320,7 +320,10 @@ private void SaveCraftFile(VesselModel vessel, byte[] bytes)
// load the file and modify its vessel name to match the player
string[] lines = File.ReadAllLines(filename);
string pattern = ".*ship = (.+)";
string[] modifiedLines = lines.Select(e => Regex.Replace(e, pattern, "ship = " + p.name)).ToArray();
string[] modifiedLines = lines
.Select(e => Regex.Replace(e, pattern, "ship = " + p.name))
.Where(e => !e.Contains("VESSELNAMING"))
.ToArray();
File.WriteAllLines(filename, modifiedLines);
Debug.Log(string.Format("[BDAScoreClient] Saved craft for player {0}", p.name));
}
Expand Down
5 changes: 4 additions & 1 deletion BDArmory/Competition/BDAScoreModels.cs
Expand Up @@ -186,7 +186,10 @@ public class RecordModel
public int competition_id;
public int vessel_id;
public int heat_id;
public int hits;
public int hits_out;
public int hits_in;
public double dmg_out;
public double dmg_in;
public int assists;
public int kills;
public int deaths;
Expand Down
130 changes: 97 additions & 33 deletions BDArmory/Competition/BDAScoreService.cs
Expand Up @@ -20,6 +20,10 @@ public class BDAScoreService : MonoBehaviour
private HashSet<string> activePlayers = new HashSet<string>();
public Dictionary<string, Dictionary<string, double>> timeOfLastHitOnTarget = new Dictionary<string, Dictionary<string, double>>();
public Dictionary<string, Dictionary<string, int>> hitsOnTarget = new Dictionary<string, Dictionary<string, int>>();
public Dictionary<string, int> hitsOut = new Dictionary<string, int>();
public Dictionary<string, int> hitsIn = new Dictionary<string, int>();
public Dictionary<string, double> damageOut = new Dictionary<string, double>();
public Dictionary<string, double> damageIn = new Dictionary<string, double>();
public Dictionary<string, Dictionary<string, int>> killsOnTarget = new Dictionary<string, Dictionary<string, int>>();
public Dictionary<string, int> assists = new Dictionary<string, int>();
public Dictionary<string, int> deaths = new Dictionary<string, int>();
Expand Down Expand Up @@ -232,36 +236,30 @@ private IEnumerator ExecuteHeat(string hash, HeatModel model)
// orchestrate the match
activePlayers.Clear();
hitsOnTarget.Clear();
hitsOut.Clear();
hitsIn.Clear();
damageOut.Clear();
damageIn.Clear();
killsOnTarget.Clear();
deaths.Clear();
assists.Clear();
longestHitDistance.Clear();
longestHitWeapon.Clear();

status = StatusType.SpawningVessels;
spawner.SpawnAllVesselsOnce(BDArmorySettings.VESSEL_SPAWN_GEOCOORDS, 5f, 10f, 1f, true, hash); // FIXME If geo-coords are included in the heat model, then use those instead. Also, altitude, spawn distance factor and ease-in speed.
spawner.SpawnAllVesselsOnce(BDArmorySettings.VESSEL_SPAWN_GEOCOORDS, BDArmorySettings.VESSEL_SPAWN_ALTITUDE, BDArmorySettings.VESSEL_SPAWN_DISTANCE, BDArmorySettings.VESSEL_SPAWN_EASE_IN_SPEED, true, hash);
while (spawner.vesselsSpawning)
yield return new WaitForFixedUpdate();
if (!spawner.vesselSpawnSuccess)
{
Debug.Log("[BDAScoreService] Vessel spawning failed."); // FIXME Now what?
yield break;
}
// if (CompetitionHub != null) // Example of how to spawn extra vessels from another folder.
// {
// spawner.SpawnAllVesselsOnce(BDArmorySettings.VESSEL_SPAWN_GEOCOORDS, 1, false, hash+"/"+hubCraftPath);
// while (spawner.vesselsSpawning)
// yield return new WaitForFixedUpdate();
// if (!spawner.vesselSpawnSuccess)
// {
// Debug.Log("[BDAScoreService] Vessel spawning failed for CompetitionHub."); // FIXME Now what?
// yield break;
// }
// }
yield return new WaitForFixedUpdate();

status = StatusType.RunningHeat;
// NOTE: runs in separate coroutine
BDACompetitionMode.Instance.StartCompetitionMode(1000);
BDACompetitionMode.Instance.StartCompetitionMode(BDArmorySettings.COMPETITION_DISTANCE);

// start timer coroutine for the duration specified in settings UI
var duration = Core.BDArmorySettings.COMPETITION_DURATION * 60f;
Expand All @@ -281,13 +279,6 @@ private IEnumerator ExecuteHeat(string hash, HeatModel model)
// stop competition
BDACompetitionMode.Instance.StopCompetition();
BDACompetitionMode.Instance.LogResults("for BDAScoreService"); // Make sure the results are dumped to the log.

// status = StatusType.RemovingVessels;
// // remove all spawned vehicles // Note: Vessel and debris clean-up happens during vessel spawning (also the currently focussed vessel doesn't get killed when telling it to Die...)
// foreach (Vessel v in FlightGlobals.Vessels.Where(e => !e.vesselName.Equals("CompetitionHub")))
// {
// v.Die();
// }
}

private IEnumerator SendScores(string hash, HeatModel heat)
Expand Down Expand Up @@ -321,7 +312,10 @@ private List<RecordModel> BuildRecords(string hash, HeatModel heat)
record.vessel_id = vessel.id;
record.competition_id = int.Parse(hash);
record.heat_id = heat.id;
record.hits = ComputeTotalHits(player.name);
record.hits_out = ComputeTotalHitsOut(player.name);
record.hits_in = ComputeTotalHitsIn(player.name);
record.dmg_out = ComputeTotalDamageOut(player.name);
record.dmg_in = ComputeTotalDamageIn(player.name);
record.kills = ComputeTotalKills(player.name);
record.deaths = ComputeTotalDeaths(player.name);
record.assists = ComputeTotalAssists(player.name);
Expand All @@ -336,12 +330,42 @@ private List<RecordModel> BuildRecords(string hash, HeatModel heat)
return results;
}

private int ComputeTotalHits(string playerName)
private int ComputeTotalHitsOut(string playerName)
{
int result = 0;
if (hitsOut.ContainsKey(playerName))
{
result = hitsOut[playerName];
}
return result;
}

private int ComputeTotalHitsIn(string playerName)
{
int result = 0;
if (hitsOnTarget.ContainsKey(playerName))
if (hitsIn.ContainsKey(playerName))
{
result = hitsIn[playerName];
}
return result;
}

private double ComputeTotalDamageOut(string playerName)
{
double result = 0;
if (damageOut.ContainsKey(playerName))
{
result = damageOut[playerName];
}
return result;
}

private double ComputeTotalDamageIn(string playerName)
{
double result = 0;
if (damageIn.ContainsKey(playerName))
{
result = hitsOnTarget[playerName].Values.Sum();
result = damageIn[playerName];
}
return result;
}
Expand Down Expand Up @@ -376,9 +400,33 @@ private int ComputeTotalAssists(string playerName)
return result;
}

public void TrackDamage(string attacker, string target, double damage)
{
Debug.Log(string.Format("[BDAScoreService] TrackDamage by {0} on {1} for {2}hp", target, attacker, damage));
double now = Planetarium.GetUniversalTime();
activePlayers.Add(attacker);
activePlayers.Add(target);
if (damageOut.ContainsKey(attacker))
{
damageOut[attacker] += damage;
}
else
{
damageOut.Add(attacker, damage);
}
if (damageIn.ContainsKey(target))
{
damageIn[target] += damage;
}
else
{
damageIn.Add(target, damage);
}
}

public void TrackHit(string attacker, string target, string weaponName, double hitDistance)
{
Debug.Log(string.Format("[BDAScoreService] TrackHit {0} by {1} with {2} at {3}m", target, attacker, weaponName, hitDistance));
Debug.Log(string.Format("[BDAScoreService] TrackHit by {0} on {1} with {2} at {3}m", target, attacker, weaponName, hitDistance));
double now = Planetarium.GetUniversalTime();
activePlayers.Add(attacker);
activePlayers.Add(target);
Expand All @@ -399,9 +447,25 @@ public void TrackHit(string attacker, string target, string weaponName, double h
newHits.Add(target, 1);
hitsOnTarget.Add(attacker, newHits);
}
if (hitsOut.ContainsKey(attacker))
{
++hitsOut[attacker];
}
else
{
hitsOut.Add(attacker, 1);
}
if (hitsIn.ContainsKey(target))
{
++hitsIn[target];
}
else
{
hitsIn.Add(target, 1);
}
if (!longestHitDistance.ContainsKey(attacker) || hitDistance > longestHitDistance[attacker])
{
Debug.Log(string.Format("[BDACompetitionMode] Tracked hit for {0} with {1} at {2}", attacker, weaponName, hitDistance));
Debug.Log(string.Format("[BDACompetitionMode] Tracked longest hit for {0} with {1} at {2}m", attacker, weaponName, hitDistance));
if (longestHitDistance.ContainsKey(attacker))
{
longestHitWeapon[attacker] = weaponName;
Expand Down Expand Up @@ -432,16 +496,17 @@ public void TrackHit(string attacker, string target, string weaponName, double h
}
}

private void ComputeAssists(string target)
public void ComputeAssists(string target, string killer = "", double timeLimit = 30)
{
var now = Planetarium.GetUniversalTime();
var thresholdTime = now - 30; // anyone who hit this target within the last 30sec
var thresholdTime = now - timeLimit; // anyone who hit this target within the last 30sec

foreach (var attacker in timeOfLastHitOnTarget.Keys)
{
if( timeOfLastHitOnTarget[attacker].ContainsKey(target) && timeOfLastHitOnTarget[attacker][target] > thresholdTime)
if (attacker == killer) continue; // Don't award assists to the killer.
if (timeOfLastHitOnTarget[attacker].ContainsKey(target) && timeOfLastHitOnTarget[attacker][target] > thresholdTime)
{
if( assists.ContainsKey(attacker) )
if (assists.ContainsKey(attacker))
{
++assists[attacker];
}
Expand Down Expand Up @@ -487,12 +552,11 @@ public void TrackKill(string attacker, string target)
activePlayers.Add(target);

IncrementKill(attacker, target);
IncrementDeath(target);
ComputeAssists(target);
ComputeAssists(target, attacker, 30);
}

private void IncrementKill(string attacker, string target)
{
{
// increment kill counter
if (killsOnTarget.ContainsKey(attacker))
{
Expand Down