Fillablebarrequest, solarpanels bar to large [solved]

Started by sulusdacor, November 17, 2016, 10:13:59 AM

Previous topic - Next topic

sulusdacor

hey,
was trying to get solarpanels with other poweroutput in the game. i got the power i wanted and all seems to work fine. the only problem is, that the bar which shows the power is to large. it tried the same code with the 1700 from vanilla and it looks just right. so not sure what the problem in the code is. was just copypasting the vanilla stuff basicly.

dll:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// ----------------------------------------------------------------------
// These are RimWorld-specific usings. Activate/Deactivate what you need:
// ----------------------------------------------------------------------
using UnityEngine;         // Always needed
//using VerseBase;         // Material/Graphics handling functions are found here
using Verse;               // RimWorld universal objects are here (like 'Building')
//using Verse.AI;          // Needed when you do something with the AI
//using Verse.Sound;       // Needed when you do something with Sound
//using Verse.Noise;       // Needed when you do something with Noises
using RimWorld;            // RimWorld specific functions are found here (like 'Building_Battery')
//using RimWorld.Planet;   // RimWorld specific functions for world creation
//using RimWorld.SquadAI;  // RimWorld specific functions for squad brains

namespace sd_power
{
[StaticConstructorOnStartup]
public class sd_power_CompAdvPowerPlantSolar : CompPowerPlantSolar
{
private const float FullSunPower = 3400f;

private const float NightPower = 0f;

private static readonly Vector2 BarSize = new Vector2(2.3f, 0.14f);

private static readonly Material PowerPlantSolarBarFilledMat = SolidColorMaterials.SimpleSolidColorMaterial(new Color(0.5f, 0.475f, 0.1f));

private static readonly Material PowerPlantSolarBarUnfilledMat = SolidColorMaterials.SimpleSolidColorMaterial(new Color(0.15f, 0.15f, 0.15f));

protected override float DesiredPowerOutput
{
get
{
return Mathf.Lerp(sd_power_CompAdvPowerPlantSolar.NightPower, sd_power_CompAdvPowerPlantSolar.FullSunPower, SkyManager.CurSkyGlow) * this.RoofedPowerOutputFactor;
}
}

private float RoofedPowerOutputFactor
{
get
{
int num = 0;
int num2 = 0;
foreach (IntVec3 current in this.parent.OccupiedRect())
{
num++;
if (Find.RoofGrid.Roofed(current))
{
num2++;
}
}
return (float)(num - num2) / (float)num;
}
}

public override void PostDraw()
{
base.PostDraw();
GenDraw.FillableBarRequest fillableBarRequest = default(GenDraw.FillableBarRequest);
fillableBarRequest.center = this.parent.DrawPos + Vector3.up * 0.1f;
fillableBarRequest.size = sd_power_CompAdvPowerPlantSolar.BarSize;
fillableBarRequest.fillPercent = (base.PowerOutput / sd_power_CompAdvPowerPlantSolar.FullSunPower) * 0.5f;
fillableBarRequest.filledMat = sd_power_CompAdvPowerPlantSolar.PowerPlantSolarBarFilledMat;
fillableBarRequest.unfilledMat = sd_power_CompAdvPowerPlantSolar.PowerPlantSolarBarUnfilledMat;
fillableBarRequest.margin = 0.15f;
Rot4 rotation = this.parent.Rotation;
rotation.Rotate(RotationDirection.Clockwise);
fillableBarRequest.rotation = rotation;
GenDraw.DrawFillableBar(fillableBarRequest);
}
}
}

xml:
<!--================================= adv solar =================================-->
 
  <ThingDef ParentName="BuildingBase">
    <defName>sd_advanced_solar_generator</defName>
    <label>advanced solar generator</label>
    <thingClass>Building</thingClass>
    <graphicData>
      <texPath>Things/Building/Power/SolarCollector</texPath>
      <graphicClass>Graphic_Single</graphicClass>
      <drawSize>(4,4)</drawSize>
      <damageData>
        <rect>(0,0.6,4,2.8)</rect>
      </damageData>
    </graphicData>
    <altitudeLayer>Building</altitudeLayer>
    <passability>PassThroughOnly</passability>
    <pathCost>70</pathCost>
    <fillPercent>0.5</fillPercent>
    <castEdgeShadows>true</castEdgeShadows>
    <statBases>
      <MaxHitPoints>500</MaxHitPoints>
      <WorkToMake>4000</WorkToMake>
      <Flammability>1.0</Flammability>
    </statBases>
    <tickerType>Normal</tickerType>
    <description>Produces electricity from sunlight. Does not work in the dark.</description>
    <size>(4,4)</size>
    <building>
      <ignoreNeedsPower>true</ignoreNeedsPower>
    </building>
    <costList>
      <Steel>100</Steel>
      <Component>3</Component>
    </costList>
    <comps>
      <li Class="CompProperties_Power">
        <compClass>sd_power.sd_power_CompAdvPowerPlantSolar</compClass>
        <basePowerConsumption>-1</basePowerConsumption>
        <transmitsPower>true</transmitsPower>
      </li>
      <li Class="CompProperties_Breakdownable"/>
    </comps>
    <terrainAffordanceNeeded>Light</terrainAffordanceNeeded>
    <designationCategory>Power</designationCategory>
    <staticSunShadowHeight>0.20</staticSunShadowHeight>
    <constructEffect>ConstructMetal</constructEffect>
    <researchPrerequisites>
      <li>sd_adv_powergen_research_adv_solar</li>
    </researchPrerequisites>
  </ThingDef>


so yeah, was tryining around a bunch and don't seem to find what i did wrong and its driving me crazy^^. would appreciate some help if someone got a hint for me. thx for reading ;)

edit: forgot to mention the xml is just vanilla solar panel with other name and the comp i defined in the dll. nothing different there.

RawCode

private static readonly Vector2 BarSize = new Vector2(2.3f, 0.14f);

sulusdacor

sry was a bit to vage with my problem. what happens is this:

left side is vanilla, right side is my problem. i assume the fillpercent was determined by the line:
fillableBarRequest.fillPercent = base.PowerOutput / sd_power_CompAdvPowerPlantSolar.FullSunPower;
(the vanilla version)
thats why i added the  * 0.5f  in the top were i postet the dll first. but does nothing.

i assume somehow the game takes my new max power and throws it in the vanilla draw process. but i have no idea why and how to fix this.

skullywag

#3
I handled this by setting the fullsunpower myself for the stuff the solar was made from, not the best but it works:

https://github.com/Skullywag/SolarsStuffed/blob/master/Source/SolarsStuffed/CompPowerPlantSolar.cs

Basically you dont need the 0.5 looking at it, why would you add that?
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

sulusdacor

#4
oh yeah i saw your mod and looked over it. but the code basicly seemd like the vanilla and the stuff decisions i thought as the must have for the idea of the mod. i just wanted to use one build material, kinda why i looked over that part and set the fullsunpower at the start as the constant.

but i found my mistake by checking your file^^. it's super stupid and i probably should have found that myself before..... just used CompPowerPlant as the parent for my class and not CompPowerPlantSolar completly fixed it and all works fine. still a bit confused, since i thought with override it would use my own draw process. but okay it works, what matters in the end =)

thx for the help you two.

edit: and the 0.5 was from when i realized the bar was way to large. was just me throwing numbers in to fix the thing^^ kinda new to the dll code stuff. but try to slowly work my way up hill with small additions like this one to my old mods, which need assemblies.