Skip to content

Commit

Permalink
Merge pull request #5 from RimWorldCCLTeam/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
ForsakenShell committed Aug 16, 2015
2 parents 03acb18 + 4e9d46e commit 7a6188e
Show file tree
Hide file tree
Showing 133 changed files with 4,717 additions and 2,447 deletions.
56 changes: 18 additions & 38 deletions DLL_Project/Alerts/Alert_NeedBatteries.cs
Original file line number Diff line number Diff line change
@@ -1,67 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;

namespace CommunityCoreLibrary
{

public class Alert_NeedBatteries : RimWorld.Alert_NeedBatteries
{
private bool CheckBuilding( Building b )

static bool CheckThing( Thing thing )
{
// Only check for power traders
var p = b.TryGetComp<CompPowerTrader>();
if( p == null )
return false;
var p = thing.TryGetComp< CompPowerTrader >();

// Only check for power traders
// That are connected to a power network
if( p.PowerNet == null )
return false;

// Which aren't powered on
if( p.PowerOn == true )
return false;

// Which want to be powered on
if( p.DesirePowerOn == false )
return false;
// But want to be powered on
return
( p != null )&&
( p.PowerNet != null )&&
( !p.PowerOn )&&
( p.DesirePowerOn );

/*
// Batteries on network, don't worry about it for now
if( p.PowerNet.CurrentStoredEnergy() >= 1 )
return false;
// Where the network power is too low
var netEnergy = p.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick;
if( netEnergy > -p.EnergyOutputPerTick )
return false;
*/

// And return this building is under powered
return true;
}

public override AlertReport Report
public override AlertReport Report
{
get
{
// Check for individual power trader which is low
var powerTraders = Find.ListerBuildings.allBuildingsColonist.FindAll( b => CheckBuilding( b ) == true );
var powerTraders = Find.ListerBuildings.allBuildingsColonist.FindAll( CheckThing );
if( ( powerTraders != null )&&
( powerTraders.Count > 0 ) )
{
return AlertReport.CulpritIs( powerTraders.RandomElement() );
}

// All trader's good
return (AlertReport) false;
// All power trader's good
return AlertReport.Inactive;
}
}

}
}

}
76 changes: 19 additions & 57 deletions DLL_Project/Alerts/Alert_PlaceWorker_Restriction.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;

using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;

namespace CommunityCoreLibrary
{

public static class PlaceWorker_Restriction_Alert_Data
{
private static List< Thing > destroyedThings;
public static List< Thing > DestroyedThings
{
get{ return destroyedThings; }
}

private static int cooldownTicks;

public static bool AlertPlayer
{
get{ return ( destroyedThings.Count > 0 ); }
}

static PlaceWorker_Restriction_Alert_Data()
{
destroyedThings = new List<Thing>();
cooldownTicks = 0;
}

public static void Cooldown( int ticks = 1 )
{
cooldownTicks -= ticks;
if( ( cooldownTicks <= 0 )&&
( destroyedThings.Count > 0 ) )
destroyedThings.Clear();
}

public static void Add( Thing thing )
{
destroyedThings.Add( thing );
cooldownTicks = 250;
}

}

public class Alert_PlaceWorker_Restriction : Alert_Critical
{
public override AlertReport Report

public override AlertReport Report
{
get
{
// Alert the player if something got destroyed
if( PlaceWorker_Restriction_Alert_Data.AlertPlayer == false )
return false;

// Return the first or default instance as the culprit
return AlertReport.CulpritIs( PlaceWorker_Restriction_Alert_Data.DestroyedThings.FirstOrDefault() );
// Alert the player that something got destroyed
return !PlaceWorker_Restriction_Alert_Data.AlertPlayer
? AlertReport.Inactive
: AlertReport.CulpritIs( PlaceWorker_Restriction_Alert_Data.DestroyedThings.RandomElement() );
}
}

public override string FullExplanation{
get{
public override string FullExplanation
{
get
{
var msg = new StringBuilder();
msg.AppendLine( "AlertPlaceWorkerRestrictionSupportRemovedDesc".Translate() );
foreach( var t in PlaceWorker_Restriction_Alert_Data.DestroyedThings )
{
msg.AppendLine( " " + t.def.defName );
}
return msg.ToString();
}
}
public override void AlertActiveUpdate()

public override void AlertActiveUpdate()
{
if( PlaceWorker_Restriction_Alert_Data.AlertPlayer == true )
if( PlaceWorker_Restriction_Alert_Data.AlertPlayer )
{
base.AlertActiveUpdate();
PlaceWorker_Restriction_Alert_Data.Cooldown();
}
}

public Alert_PlaceWorker_Restriction()
public Alert_PlaceWorker_Restriction()
{
this.baseLabel = "AlertPlaceWorkerRestrictionSupportRemovedLabel".Translate();
baseLabel = "AlertPlaceWorkerRestrictionSupportRemovedLabel".Translate();
}

}
}

}
48 changes: 26 additions & 22 deletions DLL_Project/Buildings/Building_Hydroponic.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RimWorld;
using UnityEngine;
using RimWorld;
using Verse;
using Verse.AI;

namespace CommunityCoreLibrary
{

public class Building_Hydroponic : Building_PlantGrower
{
private CompPowerTrader compPower{
get { return this.TryGetComp<CompPowerTrader>(); }
}
private List<ThingComp> comps{
get { return this.AllComps; }

CompPowerTrader CompPowerTrader
{
get
{
return this.TryGetComp< CompPowerTrader >();
}
}

public override void TickRare()
public override void TickRare()
{
// Building_PlantGrower does not call base.TickRare() so we have to do it here
for (int index = 0; index < this.comps.Count; ++index)
this.comps[index].CompTickRare();

if (this.compPower == null || this.compPower.PowerOn)
// Building_PlantGrower does not call base.TickRare() so do it here
for( int i = 0; i < AllComps.Count; ++i )
{
AllComps[ i ].CompTickRare();
}

if( ( CompPowerTrader == null )||
( CompPowerTrader.PowerOn ) )
{
return;
foreach (Thing thing in this.PlantsOnMe)
thing.TakeDamage(new DamageInfo(DamageDefOf.Rotting, 4, (Thing) null, new BodyPartDamageInfo?(), (ThingDef) null));
}

foreach( var plant in PlantsOnMe )
{
plant.TakeDamage( new DamageInfo( DamageDefOf.Rotting, 4, (Thing) null, new BodyPartDamageInfo?(), (ThingDef) null ) );
}
}

}
}

}
Loading

0 comments on commit 7a6188e

Please sign in to comment.