1[
EntityEditorProps(
category:
"GameScripted/Generators", description:
"Road Generator - use this instead of RoadGeneratorEntity", visible:
false, dynamicBox:
true)]
6class SCR_RoadGeneratorEntity : RoadGeneratorEntity
13 protected float m_fMeasurementStep;
15 [
Attribute(defvalue: MAX_POSSIBLE_ANGLE.ToString(),
category:
"Debug",
desc:
"(degrees) Maximum acceptable absolute slope for the road.\nPercent to degree formula: Math.Atan2(7 / 100, 1) * Math.RAD2DEG == 4.00", uiwidget:
UIWidgets.Slider,
params:
"0 90 0.01")]
18 [
Attribute(defvalue: MAX_POSSIBLE_ANGLE.ToString(),
category:
"Debug",
desc:
"(degrees) Maximum acceptable absolute slope for the roadside compared to its middle (checks both sides)", uiwidget:
UIWidgets.Slider,
params:
"0 90 0.01")]
21 [
Attribute(defvalue:
"1",
category:
"Debug",
desc:
"Check road roll angle per side (middle to left and middle to right), otherwise from left to right")]
26 protected static const float MAX_POSSIBLE_ANGLE = 90;
31 protected void CheckSlopes(
bool printDebugLink)
34 if (!worldEditorAPI || worldEditorAPI.UndoOrRedoIsRestoring())
42 BaseWorld world = worldEditorAPI.GetWorld();
46 IEntitySource thisSource = worldEditorAPI.EntityToSource(
this);
54 ShapeEntity shapeEntity = ShapeEntity.Cast(worldEditorAPI.SourceToEntity(parentSource));
57 if (!shapeNextPointHelper)
59 Print(
"Cannot check road generator slope with invalid shape at " +
Debug.GetEntityLinkString(shapeEntity),
LogLevel.WARNING);
64 if (shapeLength <= 0.02)
67 float measurementStep;
68 if (shapeLength <= m_fMeasurementStep)
69 measurementStep = shapeLength - 0.01;
71 measurementStep = m_fMeasurementStep;
76 bool checkSides = thisSource.Get(
"RoadWidth", roadWidth) && roadWidth > 0;
77 if (!checkSides && !checkSlope)
80 float halfRoadWidth = 0.5 * roadWidth;
84 vector prevPoint = shapeEntity.CoordToParent(shapeNextPointHelper.
GetAnchorPoints()[0]);
85 prevPoint[1] = world.GetSurfaceY(prevPoint[0], prevPoint[2]);
87 while (shapeNextPointHelper.
GetNextPoint(measurementStep, currPoint, xzMode:
true))
89 currPoint = shapeEntity.CoordToParent(currPoint);
90 currPoint[1] = world.GetSurfaceY(currPoint[0], currPoint[2]);
94 float angle = Math.Atan2(currPoint[1] - prevPoint[1], measurementStep) * Math.RAD2DEG;
117 vector rightVector = (vector.Up * shapeEntity.VectorToParent(currDir)) * halfRoadWidth;
118 vector leftPoint = currPoint - rightVector;
119 vector rightPoint = currPoint + rightVector;
121 vector leftRightPoints[2] = { leftPoint, rightPoint };
125 foreach (vector sidePoint : leftRightPoints)
127 sidePoint[1] = world.GetSurfaceY(sidePoint[0], sidePoint[2]);
128 float angle = Math.Atan2(currPoint[1] - sidePoint[1], halfRoadWidth) * Math.RAD2DEG;
148 foreach (
int i, vector sidePoint : leftRightPoints)
150 leftRightPoints[i][1] = world.GetSurfaceY(sidePoint[0], sidePoint[2]);
153 float angle = Math.Atan2(leftRightPoints[0][1] - leftRightPoints[1][1], roadWidth) * Math.RAD2DEG;
172 prevPoint = currPoint;
175 if (printDebugLink && hasIssues)
176 Print(
"[SCR_RoadGeneratorEntity.CheckSlope] shape has slope issue " +
Debug.GetEntityLinkString(shapeEntity),
LogLevel.WARNING);
180 protected int GetGradientColour(
float value01)
191 r = 255 * (2 * value01);
197 g = 255 * (1 - 2 * (value01 - 0.5));
200 return (0xFF << 24) | (r << 16) | (g << 8);
204 override event protected void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
206 super.OnShapeChangedInternal(shapeEntitySrc, shapeEntity, mins, maxes);
212 override bool _WB_OnKeyChanged(BaseContainer src,
string key, BaseContainerList ownerContainers,
IEntity parent)
214 bool result = super._WB_OnKeyChanged(src, key, ownerContainers, parent);
222 override event void _WB_OnInit(inout vector mat[4], IEntitySource src)
224 super._WB_OnInit(mat, src);
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref SCR_DebugShapeManager m_DebugShapeManager
enum EVehicleType IEntity
Shape AddLine(vector from, vector to, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
static SCR_ShapeNextPointHelper CreateFromShape(notnull ShapeEntity shapeEntity, bool reverse=false)
array< vector > GetAnchorPoints()
vector GetCurrentDirection()
bool GetNextPoint(float distance, out vector result, int anchorLimit=-1, bool straightLine=true, bool doNotMove=false, bool xzMode=false)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array< vector > mins, array< vector > maxes)