Skip to content

Commit

Permalink
Merge pull request #12 from kbatbouta/development-cctv-turret
Browse files Browse the repository at this point in the history
Development cctv turret
  • Loading branch information
kbatbouta authored Dec 10, 2022
2 parents 4c4cc86 + df08b82 commit 8357cc2
Show file tree
Hide file tree
Showing 47 changed files with 1,099 additions and 144 deletions.
Binary file modified 1.4/Assemblies/CombatAI.dll
Binary file not shown.
13 changes: 13 additions & 0 deletions 1.4/Defs/Misc/Designation_categories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<DesignationCategoryDef>
<defName>Intelligences</defName>
<label>Intelligences</label>
<description>Automated Camera and Intels building can be found here.</description>
<order>454</order>
<specialDesignatorClasses>
<li>Designator_Cancel</li>
<li>Designator_Deconstruct</li>
</specialDesignatorClasses>
</DesignationCategoryDef>
</Defs>
519 changes: 458 additions & 61 deletions 1.4/Defs/ThingDef_Buildings/Buildings_Security.xml

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions 1.4/Defs/ThingDef_Research/Cai5000_ResearchDefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>

<ResearchProjectDef>
<defName>TribalCCTV</defName>
<label>Animal Warning System</label>
<description>A Trained parrot in the nest.</description>
<baseCost>450</baseCost>
<techLevel>Medieval</techLevel>
<researchViewX>0</researchViewX>
<researchViewY>1</researchViewY>
<tab>cai5000</tab>
</ResearchProjectDef>

<ResearchProjectDef>
<defName>IndustrialCCTV</defName>
<label>Automated Camera System</label>
<description>An automated camera keep sight of an area.</description>
<baseCost>600</baseCost>
<techLevel>Industrial</techLevel>
<prerequisites>
<li>TribalCCTV</li>
</prerequisites>
<researchViewX>1</researchViewX>
<researchViewY>1</researchViewY>
<tab>cai5000</tab>
</ResearchProjectDef>

<ResearchProjectDef>
<defName>SpacerCCTV</defName>
<label>Advanced Light Sensor</label>
<description>New version of automated camera for</description>
<baseCost>1850</baseCost>
<requiredResearchBuilding>HiTechResearchBench</requiredResearchBuilding>
<requiredResearchFacilities>
<li>MultiAnalyzer</li>
</requiredResearchFacilities>
<techLevel>Spacer</techLevel>
<prerequisites>
<li>MicroelectronicsBasics</li>
<li>IndustrialCCTV</li>
</prerequisites>
<researchViewX>2</researchViewX>
<researchViewY>1</researchViewY>
<tab>cai5000</tab>
</ResearchProjectDef>

</Defs>
7 changes: 7 additions & 0 deletions 1.4/Defs/ThingDef_Research/Cai5000_Researchtab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<ResearchTabDef>
<defName>cai5000</defName>
<label>CombatAI5000</label>
</ResearchTabDef>
</Defs>
2 changes: 2 additions & 0 deletions 1.4/Languages/English/Keyed/Translations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<CombatAI.Open>Open</CombatAI.Open>
<CombatAI.Hide>Hide</CombatAI.Hide>
<CombatAI.Expand>Hide</CombatAI.Expand>
<CombatAI.PlaceWorker.WallMounted>Needs to be mounted to a wall or a solid structure.
</CombatAI.PlaceWorker.WallMounted>
<CombatAI.Preparing>Preparing Combat AI</CombatAI.Preparing>
<CombatAI.Settings.Basic>Basic Settings</CombatAI.Settings.Basic>
<CombatAI.Settings.Basic.FogOfWar>[BETA] Fog of war</CombatAI.Settings.Basic.FogOfWar>
Expand Down
Binary file modified 1.4/Textures/Isma/Buildings/CCTV/cctv_pole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1.4/Textures/Isma/Buildings/CCTV/cctv_poleADV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1.4/Textures/Isma/Buildings/CCTV/cctvicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Source/Rule56/AvoidanceTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace CombatAI
{
public class AvoidanceTracker : MapComponent
{
private readonly HashSet<IntVec3> _drawnCells = new HashSet<IntVec3>();
private readonly List<Pawn> _removalList = new List<Pawn>();
private readonly AsyncActions asyncActions;
private readonly IBuckets<IBucketablePawn> buckets;
private readonly CellFlooder flooder;
private readonly HashSet<IntVec3> _drawnCells = new HashSet<IntVec3>();

public IHeatGrid affliction_dmg;
public IHeatGrid affliction_pen;
Expand Down
21 changes: 21 additions & 0 deletions Source/Rule56/CCTV/CCTVTopAnimator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CombatAI.Comps;
namespace CombatAI
{
public abstract class CCTVTopAnimator
{
public ThingComp_CCTVTop comp;

public CCTVTopAnimator(ThingComp_CCTVTop comp)
{
this.comp = comp;
}

public abstract float CurRotation
{
get;
set;
}

public abstract void Tick();
}
}
49 changes: 49 additions & 0 deletions Source/Rule56/CCTV/CCTVTopAnimator_Periodic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using CombatAI.Comps;
using Verse;
namespace CombatAI
{
public class CCTVTopAnimator_Periodic : CCTVTopAnimator
{
private bool idleTurnClockwise;
private int ticksUntilIdleTurn;

public CCTVTopAnimator_Periodic(ThingComp_CCTVTop comp) : base(comp)
{
}

/// <summary>
/// Current turret top rotation.
/// </summary>
public override float CurRotation
{
get;
set;
}

public override void Tick()
{
if (ticksUntilIdleTurn > 0)
{
ticksUntilIdleTurn--;
if (ticksUntilIdleTurn <= 0)
{
idleTurnClockwise = !idleTurnClockwise;
}
return;
}
if (idleTurnClockwise)
{
CurRotation += 0.26f;
}
else
{
CurRotation -= 0.26f;
}
if (Math.Abs(CurRotation) > 60)
{
ticksUntilIdleTurn = Rand.RangeInclusive(30, 100);
}
}
}
}
57 changes: 57 additions & 0 deletions Source/Rule56/CCTV/PlaceWorker_WallCCTV.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using CombatAI.R;
using UnityEngine;
using Verse;
namespace CombatAI
{
public class PlaceWorker_WallCCTV : PlaceWorker
{
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null)
{
Map map = Find.CurrentMap;
if (rot == Rot4.North || rot == Rot4.South)
{
GenDraw.DrawFieldEdges(new List<IntVec3>
{
center
}, !center.Impassable(map) ? Color.white : Color.red);
IntVec3 wall = center + IntVec3.North.RotatedBy(rot);
GenDraw.DrawFieldEdges(new List<IntVec3>
{
wall
}, wall.Impassable(map) ? Color.blue : Color.red);
}
else
{
GenDraw.DrawFieldEdges(new List<IntVec3>
{
center
}, !center.Impassable(map) ? Color.white : Color.red);
IntVec3 wall = center + IntVec3.South.RotatedBy(rot);
GenDraw.DrawFieldEdges(new List<IntVec3>
{
wall
}, wall.Impassable(map) ? Color.blue : Color.red);
}
}

public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
{
if (rot == Rot4.North || rot == Rot4.South)
{
if (center.Impassable(map) || !(center + IntVec3.North.RotatedBy(rot)).Impassable(map))
{
return Keyed.CombatAI_PlaceWorker_WallMounted;
}
}
else
{
if (center.Impassable(map) || !(center + IntVec3.South.RotatedBy(rot)).Impassable(map))
{
return Keyed.CombatAI_PlaceWorker_WallMounted;
}
}
return true;
}
}
}
110 changes: 110 additions & 0 deletions Source/Rule56/CCTV/WallCCTVTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Collections.Generic;
using CombatAI.Comps;
using Verse;
namespace CombatAI
{
public class WallCCTVTracker : MapComponent
{
private static readonly List<Thing> _destroyList = new List<Thing>();
private readonly FlagArray grid;
private readonly CellIndices indices;

public WallCCTVTracker(Map map) : base(map)
{
indices = map.cellIndices;
grid = new FlagArray(indices.NumGridCells);
}

public void Register(Thing thing)
{
if (thing == null || !thing.Spawned)
{
return;
}
ThingComp_CCTVTop top = thing.GetComp_Fast<ThingComp_CCTVTop>();
if (top != null && top.Props.wallMounted)
{
Rot4 rot = thing.Rotation;
IntVec3 center = thing.Position;
IntVec3 wall;
if (rot == Rot4.North || rot == Rot4.South)
{
wall = center + IntVec3.North.RotatedBy(rot);
}
else
{
wall = center + IntVec3.South.RotatedBy(rot);
}
if (wall.InBounds(map))
{
grid.Set(indices.CellToIndex(wall), true);
}
}
}

public void Register(ThingComp_CCTVTop top)
{
if (top != null && top.Props.wallMounted && top.parent.Spawned)
{
Rot4 rot = top.parent.Rotation;
IntVec3 center = top.parent.Position;
IntVec3 wall;
if (rot == Rot4.North || rot == Rot4.South)
{
wall = center + IntVec3.North.RotatedBy(rot);
}
else
{
wall = center + IntVec3.South.RotatedBy(rot);
}
if (wall.InBounds(map))
{
grid.Set(indices.CellToIndex(wall), true);
}
}
}

public void Notify_CellChanged(IntVec3 cell)
{
if (cell.InBounds(map) && grid.Get(indices.CellToIndex(cell)) && !cell.Impassable(map))
{
grid.Set(indices.CellToIndex(cell), false);
for (int i = 0; i < 8; i++)
{
IntVec3 loc = cell + GenAdj.AdjacentCells[i];
_destroyList.Clear();
if (loc.InBounds(map))
{
foreach (Thing thing in loc.GetThingList(map))
{
ThingComp_CCTVTop top = thing.GetComp_Fast<ThingComp_CCTVTop>();
if (top != null && top.Props.wallMounted)
{
Rot4 rot = thing.Rotation;
IntVec3 center = thing.Position;
IntVec3 wall;
if (rot == Rot4.North || rot == Rot4.South)
{
wall = center + IntVec3.North.RotatedBy(rot);
}
else
{
wall = center + IntVec3.South.RotatedBy(rot);
}
if (wall.InBounds(map) && wall == cell)
{
_destroyList.Add(thing);
}
}
}
}
for (int j = 0; j < _destroyList.Count; j++)
{
_destroyList[j].Destroy(DestroyMode.Deconstruct);
}
}
_destroyList.Clear();
}
}
}
}
32 changes: 32 additions & 0 deletions Source/Rule56/Comps/CompProperties_CCTVTop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using UnityEngine;
using Verse;
namespace CombatAI.Comps
{
public class CompProperties_CCTVTop : CompProperties_Sighter
{
public Type animator;
[Unsaved(allowLoading: false)]
public float baseWidth;
public float fieldOfView;
public GraphicData graphicData;
[Unsaved(allowLoading: false)]
public Material turretTopMat;
public bool wallMounted;

public CompProperties_CCTVTop()
{
compClass = typeof(ThingComp_CCTVTop);
}

public override void ResolveReferences(ThingDef parentDef)
{
base.ResolveReferences(parentDef);
baseWidth = Mathf.Sin(0.5f * fieldOfView * Mathf.PI / 180f) * radius * 2;
LongEventHandler.ExecuteWhenFinished(delegate
{
turretTopMat = MaterialPool.MatFrom(graphicData.texPath);
});
}
}
}
3 changes: 0 additions & 3 deletions Source/Rule56/Comps/CompProperties_Sighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ namespace CombatAI.Comps
{
public class CompProperties_Sighter : CompProperties
{

public bool mannable;

public bool powered;
public int radius;

public int? radiusNight;

public CompProperties_Sighter()
Expand Down
Loading

0 comments on commit 8357cc2

Please sign in to comment.