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

Efficiency now a configurable option #37

Merged
merged 3 commits into from Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified GameData/Workshop/Plugins/Workshop.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions GameData/Workshop/Readme.txt
Expand Up @@ -15,6 +15,13 @@ Current Features

Revision History

1.0.7
- Radial drill fix courtesy of RealGecko.
- Added Workshop options to KSP's Settings->Game Difficulty screen.
- You can enable/disable experience-based efficiency bonus (default on).
- You can enable/disable stupidity effects on experience-based efficiency bonus (default off).
- Workshop pause/play and trashcan buttons now use the same textures as the recycler.

1.0.5
- Fixed ModuleManager patch issues.
- Smart and experienced engineer types now improve construction and recycling efficiency.
Expand Down
2 changes: 1 addition & 1 deletion GameData/Workshop/Workshop.version
Expand Up @@ -10,7 +10,7 @@
"VERSION":{
"MAJOR":1,
"MINOR":0,
"PATCH":5,
"PATCH":7,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
35 changes: 13 additions & 22 deletions Source/Workshop/Workshop/OSEModuleWorkshop.cs
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using KSP.IO;

using KIS;

Expand Down Expand Up @@ -74,6 +75,10 @@ public class OseModuleWorkshop : PartModule

protected float adjustedProductivity = 1.0f;

private Texture2D _pauseTexture;
private Texture2D _playTexture;
private Texture2D _binTexture;

[KSPEvent(guiName = "Open Workbench", guiActive = true)]
public void ContextMenuOpenWorkbench()
{
Expand Down Expand Up @@ -103,6 +108,9 @@ public void ContextMenuOpenWorkbench()
public OseModuleWorkshop()
{
_queue = new WorkshopQueue();
_pauseTexture = WorkshopUtils.LoadTexture("Workshop/Assets/icon_pause");
_playTexture = WorkshopUtils.LoadTexture("Workshop/Assets/icon_play");
_binTexture = WorkshopUtils.LoadTexture("Workshop/Assets/icon_bin");
}

public override void OnStart(StartState state)
Expand Down Expand Up @@ -303,25 +311,8 @@ public override void OnUpdate()

private void UpdateProductivity()
{
int crewCount = this.part.protoModuleCrew.Count;
ProtoCrewMember worker;

if (_processedItem != null && UseSpecializationBonus)
{
if (crewCount == 0)
return;

//Set initial productivity
adjustedProductivity = ProductivityFactor;

//Find all crews with the build skill and adjust productivity based upon their skill
for (int index = 0; index < crewCount; index++)
{
worker = this.part.protoModuleCrew[index];
if (worker.HasEffect(ExperienceEffect))
adjustedProductivity += worker.experienceTrait.CrewMemberExperienceLevel() * SpecialistEfficiencyFactor * (1 - worker.stupidity);
}
}
adjustedProductivity = WorkshopUtils.GetProductivityBonus(this.part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor);
}

private void ProcessItem()
Expand Down Expand Up @@ -742,16 +733,16 @@ private void DrawWindowContents(int windowId)
GUI.Label(new Rect(250, 620, 280, 50), " " + progress.ToString("0.0") + " / 100");

//Pause/resume production
string buttonLabel = "||";
Texture2D buttonTexture = _pauseTexture;
if (manufacturingPaused || _processedItem == null)
buttonLabel = ">";
if (GUI.Button(new Rect(530, 620, 50, 50), buttonLabel) && _processedItem != null)
buttonTexture = _playTexture;
if (GUI.Button(new Rect(530, 620, 50, 50), buttonTexture) && _processedItem != null)
{
manufacturingPaused = !manufacturingPaused;
}

//Cancel production
if (GUI.Button(new Rect(580, 620, 50, 50), "X"))
if (GUI.Button(new Rect(580, 620, 50, 50), _binTexture))
{
if (_confirmDelete)
{
Expand Down
19 changes: 1 addition & 18 deletions Source/Workshop/Workshop/OseModuleRecycler.cs
Expand Up @@ -163,25 +163,8 @@ public override void OnSave(ConfigNode node)

private void UpdateProductivity()
{
int crewCount = this.part.protoModuleCrew.Count;
ProtoCrewMember worker;

if (_processedItem != null && UseSpecializationBonus)
{
if (crewCount == 0)
return;

//Set initial productivity
adjustedProductivity = ProductivityFactor;

//Find all crews with the build skill and adjust productivity based upon their skill
for (int index = 0; index < crewCount; index++)
{
worker = this.part.protoModuleCrew[index];
if (worker.HasEffect(ExperienceEffect))
adjustedProductivity += worker.experienceTrait.CrewMemberExperienceLevel() * SpecialistEfficiencyFactor * (1 - worker.stupidity);
}
}
adjustedProductivity = WorkshopUtils.GetProductivityBonus(this.part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor);
}

public override void OnUpdate()
Expand Down
1 change: 1 addition & 0 deletions Source/Workshop/Workshop/Workshop.csproj
Expand Up @@ -68,6 +68,7 @@
<Compile Include="Recipes\WorkshopResource.cs" />
<Compile Include="WorkshopBlacklistItemsDatabase.cs" />
<Compile Include="WorkshopBlacklistItemsLoader.cs" />
<Compile Include="WorkshopOptions.cs" />
<Compile Include="WorkshopSettings.cs" />
<Compile Include="WorkshopStyles.cs" />
<Compile Include="OseAddonEditorFilter.cs" />
Expand Down
95 changes: 95 additions & 0 deletions Source/Workshop/Workshop/WorkshopOptions.cs
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP.IO;

namespace Workshop
{
public class WorkshopOptions : GameParameters.CustomParameterNode
{
[GameParameters.CustomParameterUI("Experience affects efficiency", toolTip = "If enabled, then engineering skills can improve efficiency.", autoPersistance = true)]
public bool enableEfficiency = true;

[GameParameters.CustomParameterUI("Stupidity affects efficiency", toolTip = "If enabled, stupidity affects efficiency; the lower the better.", autoPersistance = true)]
public bool stupidityAffectsEfficiency = false;

public static bool EfficiencyEnabled
{
get
{
WorkshopOptions options = HighLogic.CurrentGame.Parameters.CustomParams<WorkshopOptions>();
return options.enableEfficiency;
}
}

public static bool StupidityAffectsEfficiency
{
get
{
WorkshopOptions options = HighLogic.CurrentGame.Parameters.CustomParams<WorkshopOptions>();
return options.stupidityAffectsEfficiency;
}
}

#region CustomParameterNode
public override string Section
{
get
{
return "Workshop";
}
}

public override string Title
{
get
{
return "Efficiency";
}
}

public override int SectionOrder
{
get
{
return 0;
}
}

public override void SetDifficultyPreset(GameParameters.Preset preset)
{
base.SetDifficultyPreset(preset);
}

public override GameParameters.GameMode GameMode
{
get
{
return GameParameters.GameMode.ANY;
}
}

public override bool HasPresets
{
get
{
return false;
}
}

public override bool Enabled(System.Reflection.MemberInfo member, GameParameters parameters)
{
Game.Modes gameMode = HighLogic.CurrentGame.Mode;

if (member.Name == "stupidityAffectsEfficiency" && enableEfficiency)
return true;
else if (member.Name == "stupidityAffectsEfficiency")
return false;

return base.Enabled(member, parameters);
}
#endregion
}
}
46 changes: 46 additions & 0 deletions Source/Workshop/Workshop/WorkshopUtils.cs
Expand Up @@ -14,6 +14,52 @@ namespace Workshop

public class WorkshopUtils
{
public static float GetProductivityBonus(Part part, string ExperienceEffect, float SpecialistEfficiencyFactor, float ProductivityFactor)
{
float adjustedProductivity = ProductivityFactor;

try
{
int crewCount = part.protoModuleCrew.Count;
if (crewCount == 0)
return ProductivityFactor;

ProtoCrewMember worker;
GameParameters.AdvancedParams advancedParams = HighLogic.CurrentGame.Parameters.CustomParams<GameParameters.AdvancedParams>();
float productivityBonus = 1.0f;

//Find all crews with the build skill and adjust productivity based upon their skill
for (int index = 0; index < crewCount; index++)
{
worker = part.protoModuleCrew[index];

//Adjust productivity if efficiency is enabled
if (WorkshopOptions.EfficiencyEnabled)
{
if (worker.HasEffect(ExperienceEffect))
{
if (advancedParams.EnableKerbalExperience)
productivityBonus = worker.experienceTrait.CrewMemberExperienceLevel() * SpecialistEfficiencyFactor;
else
productivityBonus = 5.0f * SpecialistEfficiencyFactor;
}

//Adjust for stupidity
if (WorkshopOptions.StupidityAffectsEfficiency)
productivityBonus *= (1 - worker.stupidity);

adjustedProductivity += productivityBonus;
}
}
}
catch (Exception ex)
{
Debug.Log("[Workshop] Error encountered while trying to calculate productivity bonus: " + ex);
}

return adjustedProductivity;
}

public static float GetPackedPartVolume(AvailablePart part)
{
var moduleKisItem = KISWrapper.GetKisItem(part.partPrefab);
Expand Down