Jump to content

Create a strategy with default of 50%


Recommended Posts

I wan to create a custom strategy. However the default value for this strategy should be 50% and the level of you administration building should limit your deviation from that value.

If I create a strategy with
hasFactorSlider = True
    factorSliderDefault = 0.5
  factorSliderSteps = 20

when I try to adjust it to 45% I am told that the max value is 25%

Edited by tomf
Link to comment
Share on other sites

Yup, even the default value has to fall within the admin building limits.  Stuff like this is what made me decide to drop the sliders completely in Strategia.  Anyway, I don't see any way to do what you're doing without breaking it up into different strategies (one for the positive side, one for the negative side).  Not sure if that is something that would mesh well with what you're trying to do.

Link to comment
Share on other sites

Ok, It's a little complicated but I have got what I need

Step 1: install Sarbian's CustomBarnKit

Step 2: create a CustomBarnKitConfig

@CUSTOMBARNKIT
{
    @ADMINISTRATION
    {
	    @strategyCommitRange = 1, 1, 1
    }
}

Step 3: create a custom strategy class overriding CanActivate(ref string reason)

class TwoSidedStrategy : Strategy
    {
        protected float[] maxCommitments = { .15f, .33f, 1f };
        protected override bool CanActivate(ref string reason)
        {
            float currentLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Administration) 
                * ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.Administration);

            Log("Current level is " + currentLevel);
            float commitDiff = Math.Abs(factor - FactorSliderDefault);
            float maxCommitDif = maxCommitments[Math.Min(maxCommitments.Length, (int)currentLevel)];
            if (commitDiff>maxCommitDif+1e-4f)//small epsilon for float maths
            {
                reason = "Cannot set this level of commitment";
                return false;
            }
            return true;
        }        
    }

Step 4 : create3 a strategy using your new class

STRATEGY
{
	name = TwoSidedStrategy
	hasFactorSlider = True
	factorSliderDefault = 0.5
    factorSliderSteps = 20
....

Exercise for the reader : create OneSidedStrategy to have the default values and a module manager config to make every other strategy use it.

Edited by tomf
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...