Skip to content

Commit

Permalink
Merge pull request #10 from SerTheGreat/Dev
Browse files Browse the repository at this point in the history
v 0.3.2 prepare
  • Loading branch information
SerTheGreat committed Apr 3, 2016
2 parents 37d92a8 + 88a35b1 commit b695bb2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
65 changes: 38 additions & 27 deletions G-Effects/G-Effects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ protected void Start()
RenderingManager.AddToPostDrawQueue(3, new Callback(drawGEffects));
GameEvents.onGamePause.Add(onPause);
GameEvents.onGameUnpause.Add(onUnPause);
GameEvents.onCrewKilled.Add(onCrewKilled);
GameEvents.onCrash.Add(onCrewKilled);
GameEvents.onCrashSplashdown.Add(onCrewKilled);
//GameEvents.onCrewKilled.Add(onCrewKilled);
GameEvents.onVesselChange.Add(onVesselChange);
PORTRAIT_AGENT.Start();
}
Expand All @@ -87,7 +89,9 @@ protected void OnDestroy() {
RenderingManager.RemoveFromPostDrawQueue(3, new Callback(drawGEffects));
GameEvents.onGamePause.Remove(onPause);
GameEvents.onGameUnpause.Remove(onUnPause);
GameEvents.onCrewKilled.Remove(onCrewKilled);
GameEvents.onCrash.Remove(onCrewKilled);
GameEvents.onCrashSplashdown.Remove(onCrewKilled);
//GameEvents.onCrewKilled.Remove(onCrewKilled);
GameEvents.onVesselChange.Remove(onVesselChange);
PORTRAIT_AGENT.OnDestroy();
}
Expand All @@ -103,21 +107,25 @@ protected void FixedUpdate() {
}

void onPause() {
paused = true;
gAudio.pauseAllSounds(true);
}

void onUnPause() {
paused = false;
gAudio.pauseAllSounds(false);
}

void onCrewKilled(EventReport eventReport) {
resetValues();
gAudio.stopAllSounds();
gAudio.removeFilters();
}

void onVesselChange(Vessel vessel) {
resetValues();
gAudio.stopAllSounds();
gAudio.removeFilters();
}

void resetValues() {
Expand Down Expand Up @@ -170,30 +178,30 @@ public void Update() {
commander = bestCommander(commander, crewMember);
}
}
}
}//!!(Collision)(referencePart.currentCollisions.ToArray()[0]).
if (commander == null) { //if there's still no commander in the vessel then control lock must be removed because it is probably a probe core that has control at the moment
InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
}

bool isIVA = CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA;

playEffects = (commander != null) &&
(!conf.IVAOnly || isIVA) &&
!MapView.MapIsEnabled;

greyOutAllowed = isIVA && conf.IVAGreyout || !isIVA && conf.mainCamGreyout;
flightCameraFilter.setBypass(isIVA || !playEffects);
internalCameraFilter.setBypass(!isIVA || !playEffects);
gAudio.setAudioEnabled(playEffects);
PORTRAIT_AGENT.enableText(!playEffects);

//Calcualte g-effects for each crew member
foreach (ProtoCrewMember crewMember in vessel.GetVesselCrew()) {

if ( isRosterDead(crewMember)) {
continue;
}

bool isIVA = CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA;

playEffects =
crewMember.Equals(commander) &&
(!conf.IVAOnly || isIVA) &&
!MapView.MapIsEnabled;

greyOutAllowed = isIVA && conf.IVAGreyout || !isIVA && conf.mainCamGreyout;
flightCameraFilter.setBypass(isIVA || !playEffects);
internalCameraFilter.setBypass(!isIVA || !playEffects);
gAudio.setAudioEnabled(playEffects);
PORTRAIT_AGENT.enableText(!playEffects);
KerbalGState gState;
if (!kerbalGDict.TryGetValue(crewMember.name, out gState)) {
gState = new KerbalGState(conf);
Expand Down Expand Up @@ -228,14 +236,14 @@ public void Update() {

double rebCompensation = conf.gResistance * kerbalModifier - conf.deltaGTolerance * conf.deltaGTolerance / kerbalModifier; //this is calculated so the rebound is in equilibrium with cumulativeG at the very point of G threshold
gState.cumulativeG += Math.Sign(downwardG-1+forwardG) * rebCompensation + (Math.Abs(downwardG-1)*(downwardG-1) + Math.Abs(forwardG) * forwardG) / kerbalModifier;

gAudio.stopBreath();
gState.resetBreath();

if (gState.isGLocCondition()) {
loseConsciousness(crewMember, gState, crewMember.Equals(commander), playEffects);
gAudio.stopHeartBeats();
} else {
} else if (crewMember.Equals(commander)) {
//Positive and frontal G sound effects
if( ((downwardG > conf.positiveThreshold) || (forwardG > conf.positiveThreshold)) && (gState.cumulativeG > 0.1 * conf.MAX_CUMULATIVE_G)) {
//gData.needBreath = Mathf.Max(gData.needBreath, (gData.cumulativeG > 0.6 * conf.MAX_CUMULATIVE_G) ? (int)(MAX_BREATHS * gData.getSeverity() - 1) : 0);
Expand Down Expand Up @@ -267,7 +275,9 @@ public void Update() {
}
}

gAudio.applyFilters(1 - gState.gLocFadeAmount / MAX_GLOC_FADE);
if (crewMember.Equals(commander)) {
gAudio.applyFilters(1 - gState.gLocFadeAmount / MAX_GLOC_FADE);
}
writeDebug("crew=" + crewMember.name + " cumulativeG=" + gState.cumulativeG);

//If out of danger then stop negative G sound effects
Expand All @@ -293,7 +303,7 @@ public void Update() {

//Damps acceleration peak if it is detected for the current frame.
//Most likely the peaks are caused by imperfect physics and need to be damped for not causing unnatural effects on crew.
//(Acceleration of a kerbal going EVA is 572G)
//(Acceleration of a kerbal going EVA is about 44G)
Vector3d dampAcceleration(Vector3d current_acc, Vector3d prev_acc) {
double magnitude = (current_acc - prev_acc).magnitude;
if ((current_acc - prev_acc).magnitude > conf.gDampingThreshold * G_CONST) {
Expand All @@ -318,10 +328,10 @@ ProtoCrewMember bestCommander(ProtoCrewMember current, ProtoCrewMember candidate

priorities.TryGetValue(current.experienceTrait.Title.ToLower(), out current_pr);
priorities.TryGetValue(candidate.experienceTrait.Title.ToLower(), out candidate_pr);
if (current_pr > candidate_pr) { //return the one with the highest priority
return current;
} else if (candidate_pr > current_pr) {
if (candidate_pr > current_pr) { //return the one with the highest priority
return candidate;
} else if (current_pr > candidate_pr) {
return current;
} else { //or the one with the highest experience
if (candidate.experienceLevel > current.experienceLevel) {
return candidate;
Expand All @@ -338,15 +348,15 @@ void loseConsciousness(ProtoCrewMember crewMember, KerbalGState kerbalGData, boo
if (kerbalGData.gLocFadeAmount > MAX_GLOC_FADE) {
kerbalGData.gLocFadeAmount = MAX_GLOC_FADE;
if (isCommander) {
if (outputAllowed && (conf.gLocScreenWarning != null) && (conf.gLocScreenWarning.Length > 0) ) {
ScreenMessages.PostScreenMessage(conf.gLocScreenWarning);
}
Vessel vessel = crewMember.KerbalRef.InVessel;
if (!hasProbeCore(vessel)) {
vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);
}
InputLockManager.SetControlLock(ControlTypes.ALL_SHIP_CONTROLS, CONTROL_LOCK_ID);
}
if ( outputAllowed && (conf.gLocScreenWarning != null) && (conf.gLocScreenWarning.Length > 0) ) {
ScreenMessages.PostScreenMessage(conf.gLocScreenWarning);
}
}
}

Expand Down Expand Up @@ -375,7 +385,7 @@ bool isRosterDead(ProtoCrewMember crewMember) {

void doGreyout(KerbalGState gState) {
if (gState.cumulativeG > 0) {
float greyout = Mathf.Pow(Mathf.Clamp(gState.getSeverity() / 0.4f, 0f, 1.0f), 2); //Severity is divided by a percent of the total blackout at which greyout should be complete
float greyout = Mathf.Pow(Mathf.Clamp(gState.getSeverity() / 0.5f, 0f, 1.0f), 2); //Severity is divided by a percent of the total blackout at which greyout should be complete
flightCameraFilter.setMagnitude(greyout);
internalCameraFilter.setMagnitude(greyout);
} else {
Expand All @@ -386,11 +396,12 @@ void doGreyout(KerbalGState gState) {

void drawGEffects()
{
KerbalGState kerbalGData;
if (!playEffects) {
return;
}

KerbalGState kerbalGData;
//KerbalGState kerbalGData;
if ((commander == null) || !kerbalGDict.TryGetValue(commander.name, out kerbalGData)) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions G-Effects/PortraitAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ private void drawLabels()
if (pText.alphaBlendMode == 0) {
GUI.color = new Color(0,0,0,0f);
} else if (pText.alphaBlendMode == 1) {
GUI.color = new Color(0,0,0,0.8f);
GUI.color = new Color(0,0,0,0.85f);
} else {
GUI.color = new Color(0,0,0,1f);
}
GUI.DrawTexture(new Rect(screenPos.x, screenPos.y, manager.AvatarSize - 1, manager.AvatarSize), blackTexture, ScaleMode.ScaleToFit, true);
GUI.DrawTexture(new Rect(leftOffset, screenPos.y, manager.AvatarSize - 1, manager.AvatarSize), blackTexture, ScaleMode.ScaleToFit, true);
}
/*foreach (Font f in Resources.FindObjectsOfTypeAll (typeof (Font))) {
ScreenMessages.PostScreenMessage(f.name);
}*/
if (!(pText.blinkFreq > 0) || ((long)(Planetarium.GetUniversalTime() * 1000f) % (1000 / pText.blinkFreq) < (1000 / pText.blinkFreq) / 2) ){
printLabel(pText.text, pText.leftOffset, pText.topOffset, pText.textColor);
printLabel(pText.text, leftOffset + pText.leftOffset, pText.topOffset, pText.textColor);
}

}
Expand All @@ -201,7 +201,7 @@ private void printLabel(string text, float leftOffset, float topOffset, Color co
string[] lines = text.Split('\n');
for (int i=0; i < lines.Length; i++) {
float lineOffset = (i - lines.Length / 2) * LINE_HEIGHT;
Rect r = new Rect(screenPos.x + leftOffset, screenPos.y + manager.AvatarSize / 2 + topOffset + lineOffset, manager.AvatarSize, LINE_HEIGHT);
Rect r = new Rect(leftOffset, screenPos.y + manager.AvatarSize / 2 + topOffset + lineOffset, manager.AvatarSize, LINE_HEIGHT);
GUI.color = color;
GUI.Label(r, lines[i], centeredLabelStyle);
}
Expand Down
4 changes: 2 additions & 2 deletions G-Effects/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.1")]
[assembly: AssemblyFileVersion("0.3.1")]
[assembly: AssemblyVersion("0.3.2")]
[assembly: AssemblyFileVersion("0.3.2")]
Binary file modified GameData/G-Effects/Plugins/G-Effects.dll
Binary file not shown.

0 comments on commit b695bb2

Please sign in to comment.