Skip to content

Commit 9ca58a4

Browse files
committed
ctf bug fixes, vision cutoff improvements, end game vision, ladder placement improvements
1 parent 991a962 commit 9ca58a4

28 files changed

+462
-174
lines changed

Assets/Scripts/BlockmapFramework/Base/Chunk.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void DrawMeshes()
199199

200200
pm_GenerateProcEntityMeshes.Begin();
201201
foreach (BatchEntityMesh mesh in ProceduralEntityMeshes.Values) GameObject.Destroy(mesh.gameObject);
202-
ProceduralEntityMeshes = ProceduralEntityMeshGenerator.GenerateMeshes(this);
202+
ProceduralEntityMeshes = BatchEntityMeshGenerator.GenerateMeshes(this);
203203
pm_GenerateProcEntityMeshes.End();
204204

205205
// Chunk position
@@ -247,11 +247,11 @@ public void ShowTileBlending(bool show)
247247
}
248248
public void SetVisionCutoffAltitude(int value)
249249
{
250-
foreach (AirNodeMesh mesh in AirNodeMeshes.Values) mesh.gameObject.SetActive(value == -1 || mesh.Altitude < value);
251-
foreach (FenceMesh mesh in FenceMeshes.Values) mesh.gameObject.SetActive(value == -1 || mesh.Altitude < value);
252-
foreach (WallMesh mesh in WallMeshes.Values) mesh.gameObject.SetActive(value == -1 || mesh.Altitude < value);
253-
foreach (BatchEntityMesh mesh in ProceduralEntityMeshes.Values) mesh.gameObject.SetActive(value == -1 || mesh.Altitude < value);
254-
foreach (Entity e in Entities.Where(e => e.MeshObject != null && e.OriginNode.Type != NodeType.Ground)) e.MeshObject.SetActive(value == -1 || e.MinAltitude < value);
250+
foreach (AirNodeMesh mesh in AirNodeMeshes.Values) mesh.Renderer.enabled = (value == -1 || mesh.Altitude < value);
251+
foreach (FenceMesh mesh in FenceMeshes.Values) mesh.Renderer.enabled = (value == -1 || mesh.Altitude < value);
252+
foreach (WallMesh mesh in WallMeshes.Values) mesh.Renderer.enabled = (value == -1 || mesh.Altitude < value);
253+
foreach (BatchEntityMesh mesh in ProceduralEntityMeshes.Values) mesh.Renderer.enabled = (value == -1 || mesh.Altitude < value);
254+
foreach (Entity e in Entities.Where(e => e.IsStandaloneEntity && e.OriginNode.Type != NodeType.Ground)) e.MeshRenderer.enabled = (value == -1 || e.MinAltitude < value);
255255
}
256256

257257
public void DrawZoneBorders(Actor actor)

Assets/Scripts/BlockmapFramework/Base/Def/EntityDef.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class EntityDef : Def
2424
/// <summary>
2525
/// Definitions of how this entity affects the vision of other entities.
2626
/// </summary>
27-
public EntityVisionImpactProperties VisionImpact { get; init; } = new EntityVisionImpactProperties();
27+
public EntityVisionImpactProperties VisionImpactProperties { get; init; } = new EntityVisionImpactProperties();
2828

2929
/// <summary>
3030
/// Components that add custom behaviour to this entity.
@@ -56,11 +56,39 @@ public class EntityDef : Def
5656
/// </summary>
5757
public bool VariableHeight { get; init; } = false;
5858

59+
/// <summary>
60+
/// Creates a new EntityDef.
61+
/// </summary>
62+
public EntityDef() { }
63+
64+
/// <summary>
65+
/// Creates a deep copy of another EntityDef.
66+
/// </summary>
67+
public EntityDef(EntityDef orig)
68+
{
69+
// Base Def
70+
DefName = orig.DefName;
71+
Label = orig.Label;
72+
Description = orig.Description;
73+
UiPreviewSprite = orig.UiPreviewSprite;
74+
75+
// EntityDef
76+
EntityClass = orig.EntityClass;
77+
RenderProperties = new EntityRenderProperties(orig.RenderProperties);
78+
VisionImpactProperties = new EntityVisionImpactProperties(orig.VisionImpactProperties);
79+
Components = orig.Components.Select(c => c.Clone()).ToList();
80+
VisionRange = orig.VisionRange;
81+
Dimensions = new Vector3Int(orig.Dimensions.x, orig.Dimensions.y, orig.Dimensions.z);
82+
Impassable = orig.Impassable;
83+
RequiresFlatTerrain = orig.RequiresFlatTerrain;
84+
VariableHeight = orig.VariableHeight;
85+
}
86+
5987
public override bool Validate()
6088
{
6189
if (RenderProperties.RenderType == EntityRenderType.StandaloneModel && RenderProperties.Model == null) ThrowValidationError("Model cannot be null in an EntityDef with RenderType = StandaloneModel.");
6290
if (RenderProperties.RenderType == EntityRenderType.Batch && (Dimensions.x > 1 || Dimensions.z > 1)) ThrowValidationError("x and z dimensions must be 1 for batch-rendered entities.");
63-
if (VisionImpact.VisionColliderType == VisionColliderType.BlockPerNode && VisionImpact.VisionBlockHeights.Any(x => x.Value > Dimensions.y)) ThrowValidationError("The height of a vision collider cannot be higher than the height of the entity.");
91+
if (VisionImpactProperties.VisionColliderType == VisionColliderType.BlockPerNode && VisionImpactProperties.VisionBlockHeights.Any(x => x.Value > Dimensions.y)) ThrowValidationError("The height of a vision collider cannot be higher than the height of the entity.");
6492

6593
foreach (CompProperties props in Components)
6694
if(!props.Validate(this))

Assets/Scripts/BlockmapFramework/Base/Wall.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class Wall : WorldDatabaseObject, IClimbable, IVisionTarget, ISaveAndLoad
5656
public float Width => Shape.Width;
5757

5858
// GameObject
59+
public WallMesh Mesh { get; private set; }
5960
public GameObject VisionColliderObject;
6061

6162

@@ -145,6 +146,11 @@ private Vector3 GetVisionColliderCenter()
145146

146147
#region Actions
147148

149+
public void SetMesh(WallMesh mesh)
150+
{
151+
Mesh = mesh;
152+
}
153+
148154
public void AddZone(Zone z)
149155
{
150156
Zones.Add(z);

Assets/Scripts/BlockmapFramework/Base/World.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ private void UpdateHoveredObjects()
376376
{
377377
GroundNode hitNode = GetGroundNode(HoveredWorldCoordinates);
378378

379-
if (hitNode != null && hitNode.IsExploredBy(ActiveVisionActor))
379+
if (hitNode != null && hitNode.IsExploredBy(ActiveVisionActor) && hitNode.Mesh.Renderer.enabled)
380380
{
381381
newHoveredGroundNode = hitNode;
382382
newHoveredNode = hitNode;
@@ -391,7 +391,7 @@ private void UpdateHoveredObjects()
391391
{
392392
AirNode hitNode = GetAirNodeFromRaycastHit(hit);
393393

394-
if (hitNode != null && hitNode.IsExploredBy(ActiveVisionActor))
394+
if (hitNode != null && hitNode.IsExploredBy(ActiveVisionActor) && hitNode.Mesh.Renderer.enabled)
395395
{
396396
newHoveredAirNode = hitNode;
397397
newHoveredNode = hitNode;
@@ -428,7 +428,7 @@ private void UpdateHoveredObjects()
428428
{
429429
Fence hitFence = GetFenceFromRaycastHit(hit);
430430

431-
if (hitFence != null && hitFence.Node.IsExploredBy(ActiveVisionActor))
431+
if (hitFence != null && hitFence.Node.IsExploredBy(ActiveVisionActor) && objectHit.GetComponent<MeshRenderer>().enabled)
432432
{
433433
newHoveredFence = hitFence;
434434
HoveredWorldCoordinates = hitFence.Node.WorldCoordinates;
@@ -442,7 +442,7 @@ private void UpdateHoveredObjects()
442442
{
443443
Wall hitWall = GetWallFromRaycastHit(hit);
444444

445-
if (hitWall != null && hitWall.IsExploredBy(ActiveVisionActor))
445+
if (hitWall != null && hitWall.IsExploredBy(ActiveVisionActor) && hitWall.Mesh.Renderer.enabled)
446446
{
447447
newHoveredWall = hitWall;
448448
HoveredWorldCoordinates = hitWall.WorldCoordinates;
@@ -456,7 +456,7 @@ private void UpdateHoveredObjects()
456456
{
457457
Entity hitEntity = (Entity)objectHit.GetComponent<WorldObjectCollider>().Object;
458458

459-
if(hitEntity != null && hitEntity.IsExploredBy(ActiveVisionActor))
459+
if(hitEntity != null && hitEntity.IsExploredBy(ActiveVisionActor) && hitEntity.MeshRenderer.enabled)
460460
{
461461
newHoveredEntity = hitEntity;
462462
newHoveredChunk = hitEntity.Chunk;
@@ -469,7 +469,7 @@ private void UpdateHoveredObjects()
469469
{
470470
Entity hitEntity = GetBatchEntityFromRaycastHit(hit);
471471

472-
if (hitEntity != null && hitEntity.IsExploredBy(ActiveVisionActor))
472+
if (hitEntity != null && hitEntity.IsExploredBy(ActiveVisionActor) && hitEntity.BatchEntityMesh.Renderer.enabled)
473473
{
474474
newHoveredEntity = hitEntity;
475475
newHoveredChunk = hitEntity.Chunk;
@@ -1200,6 +1200,8 @@ public void RemoveAirNode(AirNode node, bool updateWorld)
12001200

12011201
public bool CanSpawnEntity(EntityDef def, BlockmapNode node, Direction rotation, int height = -1, bool forceHeadspaceRecalc = false)
12021202
{
1203+
if (def == null) throw new System.Exception($"Cannot check if entity is spawnable because EntityDef is null");
1204+
12031205
HashSet<BlockmapNode> occupiedNodes = EntityManager.GetOccupiedNodes(def, this, node, rotation, height); // get nodes that would be occupied when placing the entity on the given node
12041206

12051207
// Terrain below entity is not fully connected and therefore occupiedNodes is null
@@ -1610,6 +1612,7 @@ public List<BlockmapNode> GetPossibleLadderTargetNodes(BlockmapNode source, Dire
16101612

16111613
return possibleTargetNodes;
16121614
}
1615+
public bool CanBuildLadder(BlockmapNode from, Direction side, BlockmapNode to) => GetPossibleLadderTargetNodes(from, side).Contains(to);
16131616
public void BuildLadder(BlockmapNode from, BlockmapNode to, Direction side, bool updateWorld)
16141617
{
16151618
SpawnEntity(EntityDefOf.Ladder, from, side, Gaia, preInit: e => ((Ladder)e).PreInit(to), isMirrored: false, updateWorld: updateWorld);

Assets/Scripts/BlockmapFramework/Defs/GlobalEntityDefs.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static class GlobalEntityDefs
4141
StandaloneRenderFunction = Door.GenerateDoorMesh,
4242
GetWorldPositionFunction = Door.GetWorldPosition,
4343
},
44-
VisionImpact = new EntityVisionImpactProperties()
44+
VisionImpactProperties = new EntityVisionImpactProperties()
4545
{
4646
VisionColliderType = VisionColliderType.CustomImplementation,
4747
}
@@ -61,7 +61,7 @@ public static class GlobalEntityDefs
6161
StandaloneRenderFunction = LadderMeshGenerator.GenerateLadderMesh,
6262
GetWorldPositionFunction = Ladder.GetLadderWorldPosition,
6363
},
64-
VisionImpact = new EntityVisionImpactProperties()
64+
VisionImpactProperties = new EntityVisionImpactProperties()
6565
{
6666
BlocksVision = false,
6767
},
@@ -125,7 +125,7 @@ public static class GlobalEntityDefs
125125
RenderType = EntityRenderType.StandaloneModel,
126126
Model = Resources.Load<GameObject>(BlenderImportBasePath + "car/car1_fbx"),
127127
},
128-
VisionImpact = new EntityVisionImpactProperties()
128+
VisionImpactProperties = new EntityVisionImpactProperties()
129129
{
130130
VisionColliderType = VisionColliderType.BlockPerNode,
131131
VisionBlockHeights = new Dictionary<Vector2Int, int>()
@@ -149,7 +149,7 @@ public static class GlobalEntityDefs
149149
RenderType = EntityRenderType.StandaloneModel,
150150
Model = Resources.Load<GameObject>(BlenderImportBasePath + "car/car2_fbx"),
151151
},
152-
VisionImpact = new EntityVisionImpactProperties()
152+
VisionImpactProperties = new EntityVisionImpactProperties()
153153
{
154154
VisionColliderType = VisionColliderType.BlockPerNode,
155155
VisionBlockHeights = new Dictionary<Vector2Int, int>()
@@ -173,7 +173,7 @@ public static class GlobalEntityDefs
173173
RenderType = EntityRenderType.StandaloneModel,
174174
Model = Resources.Load<GameObject>(BlenderImportBasePath + "car/car3_fbx"),
175175
},
176-
VisionImpact = new EntityVisionImpactProperties()
176+
VisionImpactProperties = new EntityVisionImpactProperties()
177177
{
178178
VisionColliderType = VisionColliderType.BlockPerNode,
179179
VisionBlockHeights = new Dictionary<Vector2Int, int>()

Assets/Scripts/BlockmapFramework/Defs/GlobalSurfaceDefs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static class GlobalSurfaceDefs
127127
DefName = "DirtPath",
128128
Label = "dith path",
129129
Description = "A foresty dirt path",
130-
MovementSpeedModifier = 0.8f,
130+
MovementSpeedModifier = 0.85f,
131131
RenderProperties = new SurfaceRenderProperties()
132132
{
133133
Type = SurfaceRenderType.Default_Blend,

Assets/Scripts/BlockmapFramework/Entity/CompProperties.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public abstract class CompProperties
1212
{
1313
public Type CompClass { get; init; } = null;
1414

15+
/// <summary>
16+
/// Creates a deep copy of an existing CompProperties
17+
/// </summary>
18+
public abstract CompProperties Clone();
19+
1520
public virtual bool Validate(EntityDef parent)
1621
{
1722
return true;

Assets/Scripts/BlockmapFramework/Entity/Components/CompProperties_Movement.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,18 @@ public override bool Validate(EntityDef parent)
4242

4343
return base.Validate(parent);
4444
}
45+
46+
public override CompProperties Clone()
47+
{
48+
return new CompProperties_Movement()
49+
{
50+
CompClass = this.CompClass,
51+
MovementSpeed = this.MovementSpeed,
52+
CanSwim = this.CanSwim,
53+
ClimbingSkill = this.ClimbingSkill,
54+
MaxHopUpDistance = this.MaxHopUpDistance,
55+
MaxHopDownDistance = this.MaxHopDownDistance
56+
};
57+
}
4558
}
4659
}

Assets/Scripts/BlockmapFramework/Entity/Entity.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ public class Entity : WorldDatabaseObject, IVisionTarget, ISaveAndLoadable
100100
/// The MeshRenderer that renders standalone entities.
101101
/// <br/>Null for entities that are not standalone.
102102
/// </summary>
103-
private MeshRenderer MeshRenderer;
103+
public MeshRenderer MeshRenderer { get; private set; }
104+
105+
/// <summary>
106+
/// The BatchEntityMesh that this entity belongs to.
107+
/// <br/>Null for entities that are not batch entities.
108+
/// </summary>
109+
public BatchEntityMesh BatchEntityMesh { get; private set; }
104110

105111
/// <summary>
106112
/// The collider that is used for hovering and selecting the entity with the cursor.
@@ -291,7 +297,7 @@ protected virtual void CreateVisionCollider()
291297
VisionColliderObject.transform.SetParent(Wrapper.transform);
292298
if (MeshObject != null) VisionColliderObject.transform.localScale = MeshObject.transform.localScale;
293299

294-
if (Def.VisionImpact.VisionColliderType == VisionColliderType.FullBox) // Create a single box collider with the bounds of the whole entity
300+
if (Def.VisionImpactProperties.VisionColliderType == VisionColliderType.FullBox) // Create a single box collider with the bounds of the whole entity
295301
{
296302
BoxCollider collider = VisionColliderObject.AddComponent<BoxCollider>();
297303
if (MeshObject != null) collider.size = new Vector3(Dimensions.x / MeshObject.transform.localScale.x, (Dimensions.y * World.NodeHeight) / MeshObject.transform.localScale.y, Dimensions.z / MeshObject.transform.localScale.z);
@@ -301,15 +307,15 @@ protected virtual void CreateVisionCollider()
301307
WorldObjectCollider evc = VisionColliderObject.AddComponent<WorldObjectCollider>();
302308
evc.Object = this;
303309
}
304-
else if (Def.VisionImpact.VisionColliderType == VisionColliderType.MeshCollider) // Create a vision collider that is the same as the entitys mesh collider
310+
else if (Def.VisionImpactProperties.VisionColliderType == VisionColliderType.MeshCollider) // Create a vision collider that is the same as the entitys mesh collider
305311
{
306312
MeshCollider collider = VisionColliderObject.AddComponent<MeshCollider>();
307313
collider.sharedMesh = MeshCollider.sharedMesh;
308314

309315
WorldObjectCollider evc = VisionColliderObject.AddComponent<WorldObjectCollider>();
310316
evc.Object = this;
311317
}
312-
else if(Def.VisionImpact.VisionColliderType == VisionColliderType.BlockPerNode) // Create a box collider per node, each one with its own height
318+
else if(Def.VisionImpactProperties.VisionColliderType == VisionColliderType.BlockPerNode) // Create a box collider per node, each one with its own height
313319
{
314320
for (int x = 0; x < Dimensions.x; x++)
315321
{
@@ -323,7 +329,7 @@ protected virtual void CreateVisionCollider()
323329
BoxCollider collider = perNodeColliderObject.AddComponent<BoxCollider>();
324330

325331
float height = Dimensions.y; // default height
326-
if (Def.VisionImpact.VisionBlockHeights.TryGetValue(localCoords, out int overwrittenHeight)) height = overwrittenHeight; // overwritten height
332+
if (Def.VisionImpactProperties.VisionBlockHeights.TryGetValue(localCoords, out int overwrittenHeight)) height = overwrittenHeight; // overwritten height
327333

328334
if (MeshObject != null) collider.size = new Vector3(1f / MeshObject.transform.localScale.x, (height * World.NodeHeight) / MeshObject.transform.localScale.y, 1f / MeshObject.transform.localScale.z);
329335
collider.center = new Vector3((Dimensions.x / 2f) - x - 0.5f, collider.size.y / 2, (Dimensions.z / 2f) - y - 0.5f);
@@ -334,7 +340,7 @@ protected virtual void CreateVisionCollider()
334340
}
335341
}
336342
}
337-
else if(Def.VisionImpact.VisionColliderType == VisionColliderType.CustomImplementation)
343+
else if(Def.VisionImpactProperties.VisionColliderType == VisionColliderType.CustomImplementation)
338344
{
339345
throw new System.NotImplementedException($"No custom implementation found. CreateVisionCollider() seems to not be overriden for entity with DefName={Def.DefName}.");
340346
}
@@ -581,6 +587,11 @@ public void ShowTextures(bool show)
581587
MeshRenderer.materials[i].SetFloat("_UseTextures", show ? 1 : 0);
582588
}
583589

590+
public void SetBatchEntityMesh(BatchEntityMesh mesh)
591+
{
592+
BatchEntityMesh = mesh;
593+
}
594+
584595
#endregion
585596

586597
#region Getters
@@ -590,7 +601,7 @@ public void ShowTextures(bool show)
590601
public virtual string Description => Def.Description;
591602

592603
public virtual float VisionRange => Def.VisionRange;
593-
public virtual bool BlocksVision() => Def.VisionImpact.BlocksVision;
604+
public virtual bool BlocksVision() => Def.VisionImpactProperties.BlocksVision;
594605
public virtual bool BlocksVision(WorldObjectCollider collider) => BlocksVision();
595606
public virtual bool RequiresFlatTerrain => Def.RequiresFlatTerrain;
596607
public virtual Vector3Int Dimensions => Def.VariableHeight ? new Vector3Int(Def.Dimensions.x, overrideHeight, Def.Dimensions.z) : Def.Dimensions;

Assets/Scripts/BlockmapFramework/Entity/EntityRenderProperties.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,24 @@ public class EntityRenderProperties
4545
/// <br/>Parameters are: EntityDef, World, TargetNode, TargetRotation, IsMirrored.
4646
/// </summary>
4747
public System.Func<EntityDef, World, BlockmapNode, Direction, bool, Vector3> GetWorldPositionFunction { get; init; } = EntityManager.GetWorldPosition;
48+
49+
/// <summary>
50+
/// Creates new EntityRenderPropertes
51+
/// </summary>
52+
public EntityRenderProperties() { }
53+
54+
/// <summary>
55+
/// Creates a deep copy of existing EntityRenderPropertes.
56+
/// </summary>
57+
public EntityRenderProperties(EntityRenderProperties orig)
58+
{
59+
RenderType = orig.RenderType;
60+
Model = orig.Model;
61+
ModelScale = orig.ModelScale;
62+
PlayerColorMaterialIndex = orig.PlayerColorMaterialIndex;
63+
BatchRenderFunction = orig.BatchRenderFunction;
64+
StandaloneRenderFunction = orig.StandaloneRenderFunction;
65+
GetWorldPositionFunction = orig.GetWorldPositionFunction;
66+
}
4867
}
4968
}

0 commit comments

Comments
 (0)