[A13] Modular Solar Panels (1.11)

Started by Kirid, March 11, 2014, 09:29:52 AM

Previous topic - Next topic

Kirid


This adds single solar panels that are placed similar to walls.
Charge, health, and metal cost are close if not equal to the same fraction of a regular solar (1/16).
Colonists can walk on them and build floors underneath.

How to install:
- Unzip the contents and place them in your RimWorld/Mods folder.
- Activate the mod in the mod menu in the game.
Notes:
Thanks to Abrexus for a new texture and code help.
I give my permission to include this in any modpacks. Contact me if you plan to use or alter the code or art. Please give me credit in either case.
Changelog:
Released
1.1: Cleaned redundant code
     Panels no longer connect to walls
     Floors can be placed underneath                         
1.2: Updated for Alpha 3
1.3: Dll added - Now change charge depending on light level.
1.4: Updated for Alpha 5
1.5: Updated for Alpha 6
1.6: Updated for Alpha 7
     New texture and charge bar
1.7: Updated for Alpha 8
1.7.1: Changed fillpercent from 1 to 0.025
     Added mod menu picture
     Now requires research
1.8: Updated for Alpha 9
1.9: Updated for Alpha 10
     Changed texture
     Added slight pathing cost
1.9NoBars: Removed charge bar (Optional)
1.10: Updated to Alpha 11
     No change for Alpha 12
1.11: Updated to Alpha 13
1.11.1: Readded Building_Base
     Removed component breakdown



[attachment deleted by admin - too old]
You can't rollerskate in a muffalo herd

Agthor


Kilroy232

Cool concept, and I really like that you put a good amount of thought into the distribution of resources needed and power output. having said that is it possible to make it so that they do not produce power during the night?

Vas

I like the concept, I haven't tested yet but I do know of one issue this might present, which is having a hard time repairing small solar panels in the center of a group.  EG if you build a 4x4 grid, the 2x2 in the middle, can't be repaired anymore.  You can't reach them.

Also that issue of producing power during the night that someone else just mentioned, though I believe that would be an easy fix, I think.  Not sure.
Click to see my steam. I'm a lazy modder who takes long breaks and everyone seems to hate.

Darker

#4
Why don't you use solar panel class to enforce solar panel behavior? Like this:


   <thingClass>Building_PowerPlantSolar</thingClass>



Edit: actually, that would cause nasty things to render on the screen. Nevemind.
Please... Throw human readable errors on savefile parsing failure!!!
Rim world editor Editor on GIT

JackQW

#5
He could write his own C# mod for this...

Code (C#) Select

using System;
using System.Reflection;
using UnityEngine;

public static class Reflect<T> { // basic reflection helper
const BindingFlags staticField =
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Static |
BindingFlags.GetField |
BindingFlags.GetProperty;
public static TResult GetStatic<TResult>(string name) {
return (TResult)typeof(T).InvokeMember(name, staticField, null, null, null);
}
}


public class Building_PowerPlantSimpleSolar : Building_PowerPlant {
    readonly float FullSunPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("FullSunPower");
    readonly float NightPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("NightPower");
   
    public override void Tick() {
        base.Tick();

        powerComp.powerOutput =
Find.RoofGrid.Roofed(Position)
? NightPower
: Mathf.Lerp(NightPower, FullSunPower, SkyManager.curSkyGlowPercent);
    }
}


Then it'd be...

<thingClass>Building_PowerPlantSimpleSolar</thingClass>

Darker

Please... Throw human readable errors on savefile parsing failure!!!
Rim world editor Editor on GIT

Kirid

Quote from: Vas on March 11, 2014, 05:39:53 PM
I like the concept, I haven't tested yet but I do know of one issue this might present, which is having a hard time repairing small solar panels in the center of a group.  EG if you build a 4x4 grid, the 2x2 in the middle, can't be repaired anymore.  You can't reach them.

I had this problem while I was testing them, they are currently set to standable, so no problem.

As for making them work at night As said,<thingClass>Building_PowerPlantSolar</thingClass> makes nasty power bars to appear, and I would fix it if it wasn't a class file.

Quote from: JackQW on March 11, 2014, 06:17:38 PM
He could write his own C# mod for this...

Then it'd be...

<thingClass>Building_PowerPlantSimpleSolar</thingClass>

Have you tested that and does it work?

On the other hand, I'd like to fix it connecting to walls, I thought maybe changing the Altas art for the wall to something more like a sandbagwall might fix it?
You can't rollerskate in a muffalo herd

JackQW

Nah I didn't want to go through all the project setup stuff to make a seperate one, I was investigating with other bits of craziness...


It might work though. Do you know how to create your own project, and throw that in? I'd be happy to help. :)

If you really want me to, I can make the project and add it to your mod, then send it to you... but then you'd have nothing much to do on your own. :P

Kirid

Heh, I dont know how to write or inject a file like that. I might work on somethng else and let this mod rest until alpha 3, not much more I can do to it without alot of effort.
You can't rollerskate in a muffalo herd

JackQW

Code (build.cmd) Select

set _64=
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set _64=64
set tools=%WinDir%\Microsoft.NET\Framework%_64%\v2.0.50727\
for /f "usebackq delims=." %%n in (`dir /a /b "..\..\..\*.exe"`) do set refs=..\..\..\%%~n_Data\Managed
%tools%csc.exe /nologo /noconfig /target:library /out:..\Assemblies\Mod.dll Mod.cs /nostdlib /lib:%refs% /r:"mscorlib.dll" /r:"System.dll" /r:"System.Core.dll" /r:"System.Security.dll" /r:"System.Configuration.dll" /r:"System.Xml.dll" /r:"System.Xml.Linq.dll" /r:"UnityEngine.dll" /r:"UnityScript.Lang.dll" /r:"Mono.Posix.dll" /r:"Mono.Security.dll" /r:"Boo.Lang.dll" /r:"Assembly-UnityScript-firstpass.dll" /r:"Assembly-CSharp-firstpass.dll" /r:"Assembly-CSharp.dll"

Code (Mod.cs) Select

using System;
using System.Reflection;
using UnityEngine;

public static class Reflect<T> { // basic reflection helper
const BindingFlags staticField =
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Static |
BindingFlags.GetField |
BindingFlags.GetProperty;
public static TResult GetStatic<TResult>(string name) {
return (TResult)typeof(T).InvokeMember(name, staticField, null, null, null);
}
}


public class Building_PowerPlantSimpleSolar : Building_PowerPlant {
    readonly float FullSunPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("FullSunPower");
    readonly float NightPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("NightPower");
   
    public override void Tick() {
        base.Tick();

        powerComp.powerOutput =
Find.RoofGrid.Roofed(Position)
? NightPower
: Mathf.Lerp(NightPower, FullSunPower, SkyManager.curSkyGlowPercent);
    }
}


Attached above as a zip file.

Extract to <RimWorldGameDir>\Mods\ModSolar\Source (create the Source folder).
Create a folder <RimWorldGameDir>\Mods\ModSolar\Assemblies


This is a single-file style somewhat auto-config mod for you...
You still have to change the Xml, and you can play with the C# Mod.cs file...

[attachment deleted by admin: too old]

Kirid

If I define <thingClass>Building_PowerPlantSimpleSolar</thingClass> I get an error.
<thingClass>Building_PowerPlant</thingClass> seems to work without error.
But they still have <eType>Wall</eType>, which is BuildingComplex on a regular solar.

In short.. they still dont react to day/night.

with a regular panel
<compClass>CompPowerTrader</compClass>
<basePowerConsumption>-1</basePowerConsumption>
and mine need
<basePowerConsumption>-106</basePowerConsumption>
in order to match the power created, which leaves me to believe that the charge of the regular solar is from the class file, which I dont know how to find.
Mod solars are modeled like geyser generators, a set constant output. Its may be too wonkey of a building to easily edit.
Its still defined as a wall for the most part, except that it creates power, and we're trying to make it function like a regular solar. Its a bit of a mashup building

also Mods\ModSolar\Assemblies stays empty?

Thank you JackQW! You can help me as long as you are willing and able, this is a pretty awesome learning experience for me.
You can't rollerskate in a muffalo herd

JackQW

#12
You have to run build.cmd
It'll run the .NET v2 (v3.5) framework compiler on Mod.cs, referencing the managed (Mono) libraries in the game directory, and build Mod.dll in the Assemblies folder.

If you run it by double clicking, it'll all happen very fast... add "pause" on a new line to the end to make it stay open.
If it still closes too fast, you have to open a command prompt, and enter "cd /d C:\PathToModFolderHere\", then "build", and paste the output in a reply.

Kirid

You can't rollerskate in a muffalo herd

JackQW

#14
^ Edited post, sorry.

You should see output like this;

X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
_64=
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>if
"AMD64" == "AMD64" set _64=64
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
tools=C:\Windows\Microsoft.NET\Framework64\v2.0.50727\
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>for
/F "usebackq delims=." %n in (`dir /a /b "..\..\..\*.exe"`) do set refs=..\..\.
.\%~n_Data\Managed
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
refs=..\..\..\RimWorld376WinDev_Data\Managed
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>C:\
Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe /nologo /noconfig /target:l
ibrary /out:..\Assemblies\Mod.dll Mod.cs /nostdlib /lib:..\..\..\RimWorld376WinD
ev_Data\Managed /r:"mscorlib.dll" /r:"System.dll" /r:"System.Core.dll" /r:"Syste
m.Security.dll" /r:"System.Configuration.dll" /r:"System.Xml.dll" /r:"System.Xml
.Linq.dll" /r:"UnityEngine.dll" /r:"UnityScript.Lang.dll" /r:"Mono.Posix.dll" /r
:"Mono.Security.dll" /r:"Boo.Lang.dll" /r:"Assembly-UnityScript-firstpass.dll" /
r:"Assembly-CSharp-firstpass.dll" /r:"Assembly-CSharp.dll"
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>pau
se
Press any key to continue . . .