Skip to content

Commit

Permalink
v0.11.3
Browse files Browse the repository at this point in the history
[adds]
+ RestrictedPlacement_Comp now ticks (normal(1:250) and rare(1:1)) and destoys the Thing if it's support disappears, an alert is also thrown to the player

[changes]
+ PlaceWorker_WallAttachment should only work as intended on natural and man-made walls (use edifice AND graphic linker to validate)
  • Loading branch information
ForsakenShell committed Jul 9, 2015
1 parent 8c06254 commit 6f4b756
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CommunityCoreLibrary.sln
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Global
$30.inheritsScope = text/plain
$30.scope = text/plain
description = RimWorld Alpha 11 Community Core Library
version = 0.11.1
version = 0.11.3
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 7 additions & 8 deletions CommunityCoreLibrary.userprefs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Properties StartupItem="CommunityCoreLibrary.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
<MonoDevelop.Ide.Workbench ActiveDocument="ThingComps\CompNeighbourlyGrower.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Properties\AssemblyInfo.cs">
<Files>
<File FileName="ThingComps\CompColoredLight.cs" Line="310" Column="2" />
<File FileName="StaticClasses\ThingGroup.cs" Line="19" Column="38" />
<File FileName="GizmoCommands\CommandGroupOfTouchingThingsByLinker.cs" Line="22" Column="1" />
<File FileName="GizmoCommands\CommandGroupOfTouchingThingsByDef.cs" Line="26" Column="75" />
<File FileName="GizmoCommands\CommandGroupOfTouchingThingsByThingComp.cs" Line="14" Column="18" />
<File FileName="GizmoCommands\CommandGroupOfDefOrThingCompInRoom.cs" Line="48" Column="24" />
<File FileName="ThingComps\CompNeighbourlyGrower.cs" Line="23" Column="1" />
<File FileName="Defs\AdvancedResearchDef.cs" Line="11" Column="1" />
<File FileName="Alerts\Alert_PlaceWorker_Restriction.cs" Line="45" Column="42" />
<File FileName="ThingComps\RestrictedPlacement_Comp.cs" Line="55" Column="10" />
<File FileName="PlaceWorkers\PlaceWorker_OnlyOnThing.cs" Line="37" Column="1" />
<File FileName="PlaceWorkers\PlaceWorker_OnlyOnSurface.cs" Line="33" Column="68" />
<File FileName="Properties\AssemblyInfo.cs" Line="8" Column="38" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
91 changes: 91 additions & 0 deletions DLL_Project/Alerts/Alert_PlaceWorker_Restriction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
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
{
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() );
}
}

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()
{
if( PlaceWorker_Restriction_Alert_Data.AlertPlayer == true )
{
base.AlertActiveUpdate();
PlaceWorker_Restriction_Alert_Data.Cooldown();
}
}

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

}
}

4 changes: 3 additions & 1 deletion DLL_Project/CommunityCoreLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<ReleaseVersion>0.11.1</ReleaseVersion>
<ReleaseVersion>0.11.3</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -83,6 +83,7 @@
<Compile Include="Commands\CommandGroupOfTouchingThingsByLinker.cs" />
<Compile Include="Commands\CommandGroupOfTouchingThingsByThingComp.cs" />
<Compile Include="Defs\AdvancedResearchDefExtensions.cs" />
<Compile Include="Alerts\Alert_PlaceWorker_Restriction.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand All @@ -102,5 +103,6 @@
<Folder Include="Defs\" />
<Folder Include="StaticClasses\" />
<Folder Include="Commands\" />
<Folder Include="Alerts\" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions DLL_Project/PlaceWorkers/PlaceWorker_OnlyOnSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class PlaceWorker_OnlyOnSurface : PlaceWorker
public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec3 loc, Rot4 rot )
{
bool placementOk = false;
List<Thing> allThings = Find.ThingGrid.ThingsListAt( loc );
foreach( Thing curThing in allThings )
foreach( Thing curThing in loc.GetThingList() )
{
if( curThing.def.surfaceType != SurfaceType.None )
{
Expand Down
4 changes: 3 additions & 1 deletion DLL_Project/PlaceWorkers/PlaceWorker_WallAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public override AcceptanceReport AllowsPlacing( BuildableDef checkingDef, IntVec
{
return false;
}
if( c.GetEdifice() == null )
Building support = c.GetEdifice();
if( ( support == null )||
( ( support.def.graphicData.linkFlags & ( LinkFlags.Rock | LinkFlags.Wall ) ) == 0 ) )
{
return "MessagePlacementAgainstSupport".Translate();
}
Expand Down
4 changes: 2 additions & 2 deletions DLL_Project/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.1.0")]
[assembly: AssemblyFileVersion("0.11.1.0")]
[assembly: AssemblyVersion("0.11.3.0")]
[assembly: AssemblyFileVersion("0.11.3.0")]
92 changes: 92 additions & 0 deletions DLL_Project/ThingComps/RestrictedPlacement_Comp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,105 @@ namespace CommunityCoreLibrary

public class RestrictedPlacement_Comp : ThingComp
{
private static int tickCount;

private RestrictedPlacement_Properties Restrictions
{
get
{
return (RestrictedPlacement_Properties)props;
}
}

private List<PlaceWorker> PlaceWorkers
{
get
{
return parent.def.PlaceWorkers;
}
}

// Make sure things stagger their checks to prevent lag spikes
public override void PostExposeData() {
tickCount = parent.GetHashCode() % 250;
}
public override void PostSpawnSetup() {
tickCount = parent.GetHashCode() % 250;
}

// Tick for checks
public override void CompTick() {
DoChecks( 1 );
}
public override void CompTickRare() {
DoChecks( 250 );
}

// Oops! We shouldn't be allowed!
public void DestroyParent()
{
PlaceWorker_Restriction_Alert_Data.Add( parent );
parent.Destroy( DestroyMode.Kill );
}

public void DoChecks( int ticks )
{ // This function maintains validation of the placement restrictions and
// destroys the parent thing if the requirements have changed for certain things
tickCount -= ticks;
if( tickCount >= 0 )
return;
tickCount = 250;

// Check for a roof
if( ( PlaceWorkers.FindIndex( p => p.GetType() == typeof( PlaceWorker_OnlyUnderRoof ) ) >= 0 )&&
( Find.RoofGrid.Roofed( parent.Position ) == false ) ) {
DestroyParent();
return;
}

// Check wall support
if( PlaceWorkers.FindIndex( p => p.GetType() == typeof( PlaceWorker_WallAttachment ) ) >= 0 ) {
IntVec3 c = parent.Position + parent.Rotation.FacingCell * -1;
Building support = c.GetEdifice();
if( ( support == null )||
( ( support.def.graphicData.linkFlags & ( LinkFlags.Rock | LinkFlags.Wall ) ) == 0 ) ) {
DestroyParent();
return;
}
}

// Check surface
if( PlaceWorkers.FindIndex( p => p.GetType() == typeof( PlaceWorker_OnlyOnSurface ) ) >= 0 ) {
bool foundThing = false;
foreach( Thing t in parent.Position.GetThingList() ) {
if( t.def.surfaceType != SurfaceType.None ) {
foundThing = true;
break;
}
}
if( foundThing == false ) {
DestroyParent();
return;
}
}

// Check on thing
if( PlaceWorkers.FindIndex( p => p.GetType() == typeof( PlaceWorker_OnlyOnThing ) ) >= 0 ) {
bool foundThing = false;
foreach( Thing t in parent.Position.GetThingList() ){
if( ( Restrictions.RestrictedThing.Find( r => r == t.def ) != null )&&
( t.Position == parent.Position ) ) {
foundThing = true;
break;
}
}
if( foundThing == false ) {
DestroyParent();
return;
}
}

}
}
}

2 changes: 1 addition & 1 deletion _Mod/Community Core Library/About/About.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>Community Core Library v0.11.2</name>
<name>Community Core Library v0.11.3</name>
<author>1000101</author>
<url>https://ludeon.com/forums/index.php?topic=14172.0</url>
<targetVersion>RimWorld Alpha 11b</targetVersion>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<MessagePlacementCountRestricted>Can not have more than: </MessagePlacementCountRestricted>
<MessagePlacementNotOn>You can not place that on </MessagePlacementNotOn>
<MessagePlacementNotHere>You can not place that here!</MessagePlacementNotHere>

<AlertPlaceWorkerRestrictionSupportRemovedLabel>A support was removed!</AlertPlaceWorkerRestrictionSupportRemovedLabel>
<AlertPlaceWorkerRestrictionSupportRemovedDesc>Something has been destroyed because it's support has been removed or destroyed!\n\nThe following things have been destroyed because their supports are missing:</AlertPlaceWorkerRestrictionSupportRemovedDesc>

</LanguageData>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,48 @@
<filthLeaving>BuildingRubble</filthLeaving>
</ThingDef>

<ThingDef ParentName="BuildingBase">
<defName>RestrictedUnderRoof</defName>
<label>restricted under roof test</label>
<thingClass>Building</thingClass>
<graphicData>
<texPath>Things/Building/Furniture/LampStanding</texPath>
<graphicClass>Graphic_Single</graphicClass>
<shadowInfo>
<basewidth>0.3</basewidth>
<baseHeight>0.3</baseHeight>
<tallness>0.6</tallness>
<offset>(0,0,-0.1)</offset>
</shadowInfo>
</graphicData>
<altitudeLayer>Waist</altitudeLayer>
<passability>PassThroughOnly</passability>
<statBases>
<MaxHitPoints>50</MaxHitPoints>
<WorkToMake>115</WorkToMake>
<Flammability>1.0</Flammability>
</statBases>
<selectable>true</selectable>
<description>Restricted to being under a roof</description>
<costList>
<Steel>1</Steel>
</costList>
<leaveResourcesWhenKilled>false</leaveResourcesWhenKilled>
<soundImpactDefault>BulletImpactMetal</soundImpactDefault>
<comps>
<li Class="CommunityCoreLibrary.RestrictedPlacement_Properties">
<compClass>CommunityCoreLibrary.RestrictedPlacement_Comp</compClass>
</li>
</comps>
<placeWorkers>
<!-- This restriction needs a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_OnlyUnderRoof</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
<rotatable>false</rotatable>
<designationHotKey/>
</ThingDef>

<ThingDef ParentName="BuildingBase">
<defName>RestrictedCountTest</defName>
<label>restricted count test</label>
Expand Down Expand Up @@ -48,6 +90,7 @@
</li>
</comps>
<placeWorkers>
<!-- This restriction does not need a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_RestrictedCount</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
Expand Down Expand Up @@ -94,6 +137,7 @@
</comps>
<terrainAffordanceNeeded>Any</terrainAffordanceNeeded>
<placeWorkers>
<!-- This restriction does not need a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_NotOnTerrain</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
Expand Down Expand Up @@ -140,6 +184,7 @@
</comps>
<terrainAffordanceNeeded>Any</terrainAffordanceNeeded>
<placeWorkers>
<!-- This restriction does not need a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_OnlyOnTerrain</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
Expand Down Expand Up @@ -191,6 +236,7 @@
</comps>
<terrainAffordanceNeeded>Heavy</terrainAffordanceNeeded>
<placeWorkers>
<!-- This restriction does not need a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_NotOnThing</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
Expand Down Expand Up @@ -241,7 +287,9 @@
</li>
</comps>
<terrainAffordanceNeeded>Heavy</terrainAffordanceNeeded>
<tickerType>Rare</tickerType>
<placeWorkers>
<!-- This restriction needs a ticker to maintain -->
<li>CommunityCoreLibrary.PlaceWorker_OnlyOnThing</li>
</placeWorkers>
<designationCategory>Furniture</designationCategory>
Expand Down

0 comments on commit 6f4b756

Please sign in to comment.